From d3ec226e03598001ec9fea9d436e7200d94ae893 Mon Sep 17 00:00:00 2001 From: Kushal Shukla Date: Wed, 13 Nov 2024 01:16:08 +0530 Subject: [PATCH] Modified the query way ! added absolute and current time pluse changed loadgen start and end time! Signed-off-by: Kushal Shukla --- .../prombench/benchmark/6_loadgen.yaml | 21 +++++++++- tools/load-generator/main.go | 38 ++++++++++++++----- 2 files changed, 47 insertions(+), 12 deletions(-) diff --git a/prombench/manifests/prombench/benchmark/6_loadgen.yaml b/prombench/manifests/prombench/benchmark/6_loadgen.yaml index b9b04552b..dac0e572d 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: @@ -142,6 +142,21 @@ 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 @@ -162,6 +177,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..b9499a24e 100644 --- a/tools/load-generator/main.go +++ b/tools/load-generator/main.go @@ -107,7 +107,7 @@ func NewQuerier(groupID int, target, prNumber string, qg QueryGroup) *Querier { start := durationSeconds(qg.Start) end := durationSeconds(qg.End) - nodePort := 30198 + nodePort := 30742 url := fmt.Sprintf("http://%s:%d/%s/prometheus-%s/api/v1/query", domainName, nodePort, prNumber, target) if qtype == "range" { url = fmt.Sprintf("http://%s:%d/%s/prometheus-%s/api/v1/query_range", domainName, nodePort, prNumber, target) @@ -154,12 +154,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,7 +174,7 @@ 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) @@ -178,21 +183,18 @@ func (q *Querier) query(expr string, timeMode string) { 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) } @@ -200,6 +202,22 @@ func (q *Querier) query(expr string, timeMode string) { req.URL.RawQuery = qParams.Encode() resp, err := http.DefaultClient.Do(req) + if err != nil { + fmt.Println(err) + } + if q.qtype == "range" && timeMode == "absolute" { + fmt.Println("absolute second time checking !!") + body, err := io.ReadAll(resp.Body) + if err != nil { + log.Fatal(err) + } + defer resp.Body.Close() + + // Print the body content as a string + fmt.Println(string(body), "Hi from body side!!!") + + } + if err != nil { log.Printf("Error querying Prometheus: %v", err) queryFailCount.WithLabelValues(q.target, q.name, expr, q.qtype).Inc()