diff --git a/prombench/manifests/prombench/benchmark/6_loadgen.yaml b/prombench/manifests/prombench/benchmark/6_loadgen.yaml index b9b04552b..0bc5f7303 100644 --- a/prombench/manifests/prombench/benchmark/6_loadgen.yaml +++ b/prombench/manifests/prombench/benchmark/6_loadgen.yaml @@ -10,7 +10,7 @@ data: - name: simple_range interval: 10s type: range - start: 2h + start: 4h end: 1h step: 15s queries: @@ -31,7 +31,7 @@ data: - name: aggr_range interval: 30s type: range - start: 1h + start: 4h end: 0h step: 15s queries: @@ -85,21 +85,6 @@ spec: app: loadgen-scaler spec: serviceAccountName: loadgen-scaler - initContainers: - - name: download-key - image: kushalshukla/builder - imagePullPolicy: Always - command: [ "/download-key/key.sh" ] - env: - - name: PR_NUMBER - value: "{{ .PR_NUMBER }}" - - name: GITHUB_ORG - value: "{{ .GITHUB_ORG }}" - - name: GITHUB_REPO - value: "{{ .GITHUB_REPO }}" - volumeMounts: - - name: key - mountPath: /config containers: - name: prom-load-generator image: docker.io/prominfra/scaler:master @@ -120,8 +105,6 @@ spec: - name: webserver-config-volume configMap: name: fake-webserver-config-for-scaler - - name: key - emptyDir: {} nodeSelector: node-name: nodes-{{ .PR_NUMBER }} isolation: none @@ -142,9 +125,24 @@ spec: labels: app: loadgen-querier spec: + initContainers: + - name: download-key + image: kushalshukla/builder + imagePullPolicy: Always + command: [ "/download-key/key.sh" ] + env: + - name: PR_NUMBER + value: "{{ .PR_NUMBER }}" + - name: GITHUB_ORG + value: "{{ .GITHUB_ORG }}" + - name: GITHUB_REPO + value: "{{ .GITHUB_REPO }}" + volumeMounts: + - name: key + mountPath: /config containers: - name: prom-load-generator - image: docker.io/prominfra/load-generator:master + image: kushalshukla/load-generator imagePullPolicy: Always args: - "prombench-{{ .PR_NUMBER }}" @@ -155,6 +153,8 @@ spec: volumeMounts: - name: config-volume mountPath: /etc/loadgen + - name: key + mountPath: /config ports: - name: loadgen-port containerPort: 8080 @@ -162,6 +162,8 @@ spec: - name: config-volume configMap: name: prometheus-loadgen + - name: key + emptyDir: {} nodeSelector: node-name: nodes-{{ .PR_NUMBER }} isolation: none diff --git a/tools/load-generator/main.go b/tools/load-generator/main.go index 2cf0f34d0..125ca4d80 100644 --- a/tools/load-generator/main.go +++ b/tools/load-generator/main.go @@ -107,10 +107,9 @@ func NewQuerier(groupID int, target, prNumber string, qg QueryGroup) *Querier { start := durationSeconds(qg.Start) end := durationSeconds(qg.End) - nodePort := 30198 - url := fmt.Sprintf("http://%s:%d/%s/prometheus-%s/api/v1/query", domainName, nodePort, prNumber, target) + url := fmt.Sprintf("http://%s/%s/prometheus-%s/api/v1/query", domainName, prNumber, target) if qtype == "range" { - url = fmt.Sprintf("http://%s:%d/%s/prometheus-%s/api/v1/query_range", domainName, nodePort, prNumber, target) + url = fmt.Sprintf("http://%s/%s/prometheus-%s/api/v1/query_range", domainName, prNumber, target) } return &Querier{ @@ -137,13 +136,13 @@ func loadKeyConfig() (*KeyConfig, error) { data, err := os.ReadFile(filePath) if err != nil { - return nil, fmt.Errorf("error reading file: %v", err) + return nil, fmt.Errorf("error reading file: %w", err) } var keyConfig KeyConfig err = yaml.Unmarshal(data, &keyConfig) if err != nil { - return nil, fmt.Errorf("error parsing YAML: %v", err) + return nil, fmt.Errorf("error parsing YAML: %w", err) } return &keyConfig, nil @@ -154,12 +153,17 @@ func (q *Querier) run(wg *sync.WaitGroup) { fmt.Printf("Running querier %s %s for %s\n", q.target, q.name, q.url) time.Sleep(20 * time.Second) + keyConfig, err := loadKeyConfig() + fmt.Println(err, "Hi from err") + for { start := time.Now() for _, query := range q.queries { - q.query(query.Expr, "current") - q.query(query.Expr, "absolute") + q.query(query.Expr, "current", nil) + if err == nil { + q.query(query.Expr, "absolute", keyConfig) + } } wait := q.interval - time.Since(start) @@ -169,30 +173,29 @@ func (q *Querier) run(wg *sync.WaitGroup) { } } -func (q *Querier) query(expr string, timeMode string) { +func (q *Querier) query(expr string, timeMode string, keyConfig *KeyConfig) { queryCount.WithLabelValues(q.target, q.name, expr, q.qtype).Inc() start := time.Now() + req, err := http.NewRequest("GET", q.url, nil) if err != nil { log.Printf("Error creating request: %v", err) queryFailCount.WithLabelValues(q.target, q.name, expr, q.qtype).Inc() return } - keyConfig, err := loadKeyConfig() - if err != nil { - timeMode = "current" - } + qParams := req.URL.Query() qParams.Set("query", expr) if q.qtype == "range" { if timeMode == "current" { + fmt.Println("range , current blocks") qParams.Set("start", fmt.Sprintf("%d", int64(time.Now().Add(-q.start).Unix()))) qParams.Set("end", fmt.Sprintf("%d", int64(time.Now().Add(-q.end).Unix()))) qParams.Set("step", q.step) } else { - startTime := time.Unix(0, keyConfig.MinTime*int64(time.Millisecond)) + fmt.Println("range , absolute blocks") endTime := time.Unix(0, keyConfig.MaxTime*int64(time.Millisecond)) - qParams.Set("start", fmt.Sprintf("%d", int64(startTime.Add(-q.start).Unix()))) + qParams.Set("start", fmt.Sprintf("%d", int64(endTime.Add(-q.start).Unix()))) qParams.Set("end", fmt.Sprintf("%d", int64(endTime.Add(-q.end).Unix()))) qParams.Set("step", q.step) }