Skip to content

Commit

Permalink
Merge branch 'kubernetes:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
hakuna-matatah authored Aug 1, 2023
2 parents 5eff2d7 + 0d70e67 commit 4e6854b
Show file tree
Hide file tree
Showing 14 changed files with 119 additions and 30 deletions.
30 changes: 23 additions & 7 deletions clusterloader2/pkg/measurement/common/generic_query_measurement.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ type GenericQuery struct {
Name string
Query string
Threshold *float64
LowerBound bool
RequireSamples bool
}

Expand Down Expand Up @@ -132,6 +133,26 @@ func getOrCreate(dataItems map[string]*measurementutil.DataItem, key, unit strin
return dataItem
}

func (g *genericQueryGatherer) validateSample(q GenericQuery, val float64) error {
thresholdMsg := "none"
if q.Threshold != nil {
thresholdMsg = fmt.Sprintf("%v (upper bound)", *q.Threshold)
if q.LowerBound {
thresholdMsg = fmt.Sprintf("%v (lower bound)", *q.Threshold)
}
}
klog.V(2).Infof("metric: %v: %v, value: %v, threshold: %v", g.MetricName, q.Name, val, thresholdMsg)
if q.Threshold != nil {
if q.LowerBound && val < *q.Threshold {
return errors.NewMetricViolationError(q.Name, fmt.Sprintf("sample below threshold: want: greater or equal than %v, got: %v", *q.Threshold, val))
}
if !q.LowerBound && val > *q.Threshold {
return errors.NewMetricViolationError(q.Name, fmt.Sprintf("sample above threshold: want: less or equal than %v, got: %v", *q.Threshold, val))
}
}
return nil
}

func (g *genericQueryGatherer) Gather(executor QueryExecutor, startTime, endTime time.Time, config *measurement.Config) ([]measurement.Summary, error) {
var errs []error
dataItems := map[string]*measurementutil.DataItem{}
Expand Down Expand Up @@ -161,13 +182,8 @@ func (g *genericQueryGatherer) Gather(executor QueryExecutor, startTime, endTime
dataItem.Data[q.Name] = val
}

thresholdMsg := "none"
if q.Threshold != nil {
thresholdMsg = fmt.Sprintf("%v", *q.Threshold)
}
klog.V(2).Infof("metric: %v: %v, value: %v, threshold: %v", g.MetricName, q.Name, val, thresholdMsg)
if q.Threshold != nil && val > *q.Threshold {
errs = append(errs, errors.NewMetricViolationError(q.Name, fmt.Sprintf("sample above threshold: want: less or equal than %v, got: %v", *q.Threshold, val)))
if err := g.validateSample(q, val); err != nil {
errs = append(errs, err)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ func TestGather(t *testing.T) {
},
},
samples: map[string][]*model.Sample{
"below-threshold-query[1m]": {{Value: model.SampleValue(7)}},
"no-threshold-query[1m]": {{Value: model.SampleValue(120)}},
"placeholder-a[1m] + placeholder-b[1m]": {{Value: model.SampleValue(5)}},
"below-threshold-query[60s]": {{Value: model.SampleValue(7)}},
"no-threshold-query[60s]": {{Value: model.SampleValue(120)}},
"placeholder-a[60s] + placeholder-b[60s]": {{Value: model.SampleValue(5)}},
},
wantDataItems: []measurementutil.DataItem{
{
Expand Down Expand Up @@ -132,7 +132,7 @@ func TestGather(t *testing.T) {
},
},
samples: map[string][]*model.Sample{
"many-samples-query[1m]": {
"many-samples-query[60s]": {
{Value: model.SampleValue(1)},
{Value: model.SampleValue(2)},
},
Expand Down Expand Up @@ -163,7 +163,7 @@ func TestGather(t *testing.T) {
},
},
samples: map[string][]*model.Sample{
"above-threshold-query[1m]": {{Value: model.SampleValue(123)}},
"above-threshold-query[60s]": {{Value: model.SampleValue(123)}},
},
wantErr: "sample above threshold: want: less or equal than 60, got: 123",
wantDataItems: []measurementutil.DataItem{
Expand All @@ -175,6 +175,61 @@ func TestGather(t *testing.T) {
},
},
},
{
desc: "sample above lower bound",
params: map[string]interface{}{
"metricName": "below-threshold",
"metricVersion": "v1",
"unit": "ms",
"queries": []map[string]interface{}{
{
"name": "above-threshold",
"query": "above-threshold-query[%v]",
"threshold": 60,
"lowerBound": true,
},
},
},
samples: map[string][]*model.Sample{
"above-threshold-query[60s]": {{Value: model.SampleValue(74)}},
},
wantDataItems: []measurementutil.DataItem{
{
Unit: "ms",
Data: map[string]float64{
"above-threshold": 74.0,
},
},
},
},
{
desc: "sample below lower bound",
params: map[string]interface{}{
"metricName": "below-threshold",
"metricVersion": "v1",
"unit": "ms",
"queries": []map[string]interface{}{
{
"name": "below-threshold",
"query": "below-threshold-query[%v]",
"threshold": 60,
"lowerBound": true,
},
},
},
samples: map[string][]*model.Sample{
"below-threshold-query[60s]": {{Value: model.SampleValue(42)}},
},
wantErr: "sample below threshold: want: greater or equal than 60, got: 42",
wantDataItems: []measurementutil.DataItem{
{
Unit: "ms",
Data: map[string]float64{
"below-threshold": 42.0,
},
},
},
},
{
desc: "missing field metricName",
params: map[string]interface{}{
Expand Down Expand Up @@ -221,7 +276,7 @@ func TestGather(t *testing.T) {
},
},
samples: map[string][]*model.Sample{
"query-perc99[1m]": {
"query-perc99[60s]": {
{
Metric: model.Metric{
model.LabelName("d1"): model.LabelValue("d1-val1"),
Expand All @@ -238,7 +293,7 @@ func TestGather(t *testing.T) {
Value: model.SampleValue(2),
},
},
"query-perc90[1m]": {
"query-perc90[60s]": {
{
Metric: model.Metric{
model.LabelName("d1"): model.LabelValue("d1-val1"),
Expand Down Expand Up @@ -316,7 +371,7 @@ func TestGather(t *testing.T) {
},
},
samples: map[string][]*model.Sample{
"query-perc99[1m]": {
"query-perc99[60s]": {
{
Metric: model.Metric{
model.LabelName("d1"): model.LabelValue("d1-val1"),
Expand Down
5 changes: 1 addition & 4 deletions clusterloader2/pkg/measurement/util/prometheus.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,5 @@ func (qr *promResponseData) UnmarshalJSON(b []byte) error {

// ToPrometheusTime returns prometheus string representation of given time.
func ToPrometheusTime(t time.Duration) string {
if t < time.Minute {
return fmt.Sprintf("%ds", int64(t)/int64(time.Second))
}
return fmt.Sprintf("%dm", int64(t)/int64(time.Minute))
return fmt.Sprintf("%ds", int64(t)/int64(time.Second))
}
6 changes: 4 additions & 2 deletions clusterloader2/testing/request-benchmark/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
{{$benchmarkReplicas := DefaultParam .CL2_BENCHMARK_PODS 1}}

{{$inflight := DefaultParam .CL2_BENCHMARK_INFLIGHT 10}}
{{$qps := DefaultParam .CL2_BENCHMARK_QPS -1}}
{{$uri := DefaultParam .CL2_BENCHMARK_URI ""}} # URI example: /api/v1/namespaces/%namespace%/pods

name: Request benchmark
Expand All @@ -13,7 +14,7 @@ namespace:
tuningSets:
- name: Sequence
parallelismLimitedLoad:
parallelismLimit: 1
parallelismLimit: 10
steps:
- name: Setup permissions
phases:
Expand Down Expand Up @@ -43,7 +44,7 @@ steps:
objectBundle:
- basename: {{$configMapGroup}}
objectTemplatePath: configmap.yaml
params:
templateFillMap:
bytes: {{$configMapBytes}}
group: {{$configMapGroup}}
- module:
Expand All @@ -56,6 +57,7 @@ steps:
replicas: {{$benchmarkReplicas}}
inflight: {{$inflight}}
uri: {{$uri}}
qps: {{$qps}}
- module:
path: modules/measurements.yaml
params:
Expand Down
4 changes: 2 additions & 2 deletions clusterloader2/testing/request-benchmark/configmap.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{{$bytes := DefaultParam .bytes 0}}
{{$bytes := .bytes}}
{{$group := DefaultParam .group .Name}}

apiVersion: v1
Expand All @@ -8,4 +8,4 @@ metadata:
labels:
group: {{$group}}
data:
key: "{{range $i := Loop $bytes}}{{RandIntRange 0 9}}{{end}}"
key: "{{RandData $bytes}}"
1 change: 1 addition & 0 deletions clusterloader2/testing/request-benchmark/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ spec:
- --inflight={{.Inflight}}
- --namespace={{.Namespace}}
- --uri={{.Uri}}
- --qps={{.QPS}}
resources:
requests:
cpu: {{$cpu}}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{{$replicas := DefaultParam .replicas 0}}
{{$inflight := DefaultParam .inflight 0}}
{{$uri := DefaultParam .uri "/"}}
{{$qps := DefaultParam .qps -1}}

steps:
- name: Creating WaitForControlledPodsRunning measurement
Expand Down Expand Up @@ -28,6 +29,7 @@ steps:
Replicas: {{$replicas}}
Inflight: {{$inflight}}
Uri: {{$uri}}
QPS: {{$qps}}
- name: Waiting for WaitForControlledPodsRunning gather
measurements:
- Identifier: WaitForBenchmarkDeployment
Expand Down
12 changes: 12 additions & 0 deletions clusterloader2/testing/request-benchmark/modules/measurements.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ steps:
duration: 1m
- name: "Starting measurement - {{.name}}"
measurements:
- Identifier: APIResponsivenessPrometheusSimple
Method: APIResponsivenessPrometheus
Params:
action: start
enableViolations: false
useSimpleLatencyQuery: true
- Identifier: ContainerCPU-{{.name}}
Method: GenericPrometheusQuery
Params:
Expand Down Expand Up @@ -49,3 +55,9 @@ steps:
query: quantile_over_time(0.90, sum by (container) (rate(container_cpu_usage_seconds_total[1m]))[%v:])
- name: Perc50
query: quantile_over_time(0.50, sum by (container) (rate(container_cpu_usage_seconds_total[1m]))[%v:])
- Identifier: APIResponsivenessPrometheusSimple
Method: APIResponsivenessPrometheus
Params:
action: gather
enableViolations: false
useSimpleLatencyQuery: true
3 changes: 2 additions & 1 deletion clusterloader2/testing/watch-list/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ steps:
min: 1
max: 1
basename: watch-list
replicasPerNamespace: 2
# TODO(p0lyn0mial): bring back 2 replicas
replicasPerNamespace: 1
tuningSet: Uniform10qps
objectBundle:
- basename: watch-list-secret
Expand Down
3 changes: 2 additions & 1 deletion clusterloader2/testing/watch-list/job.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,6 @@ spec:
memory: "16Gi"
cpu: "6"
command: [ "watch-list" ]
args: [ "--alsologtostderr=true", "--v=4", "--timeout={{.Duration}}", "--count=16", "--namespace=watch-list-1", "--enableWatchListFeature={{.EnableWatchListFeature}}"]
# TODO(p0lyn0mial): bring back 16 informers
args: [ "--alsologtostderr=true", "--v=4", "--timeout={{.Duration}}", "--count=6", "--namespace=watch-list-1", "--enableWatchListFeature={{.EnableWatchListFeature}}"]
restartPolicy: Never
2 changes: 1 addition & 1 deletion golang/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
.PHONY: build-go build push

export GCS_BUCKET?=k8s-infra-scale-golang-builds
export GO_COMPILER_PKG?=go1.18.5.linux-amd64.tar.gz
export GO_COMPILER_PKG?=go1.20.6.linux-amd64.tar.gz
export GO_COMPILER_URL?=https://dl.google.com/go/$(GO_COMPILER_PKG)
export ROOT_DIR?=/home/prow/go/src

Expand Down
2 changes: 1 addition & 1 deletion util-images/request-benchmark/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
PROJECT ?= k8s-testimages
IMG = gcr.io/$(PROJECT)/perf-tests-util/request-benchmark
TAG = v0.0.5
TAG = v0.0.6

all: build push

Expand Down
5 changes: 3 additions & 2 deletions util-images/request-benchmark/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,14 @@ func (c *Client) TimedRequest(ctx context.Context, request *rest.Request) Respon
}
}

func GetClient() (*Client, error) {
func GetClient(qps float32) (*Client, error) {
config, err := getConfig()
if err != nil {
return nil, err
}

config.QPS = -1 // Disable rate limiter
config.QPS = qps
config.Burst = 10

client, err := kubernetes.NewForConfig(config)
return (*Client)(client), err
Expand Down
3 changes: 2 additions & 1 deletion util-images/request-benchmark/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,15 @@ var (
namespace = flag.String("namespace", "", "Replace %namespace% in URI with provided namespace")
URI = flag.String("uri", "", "Request URI")
verb = flag.String("verb", "GET", "A verb to be used in requests.")
qps = flag.Float64("qps", -1, "The qps limit for all requests")
)

func init() {
flag.Parse()
}

func main() {
client, err := GetClient()
client, err := GetClient(float32(*qps))
if err != nil {
panic(err)
}
Expand Down

0 comments on commit 4e6854b

Please sign in to comment.