Skip to content

Commit

Permalink
Modified the query way ! added absolute and current time pluse change…
Browse files Browse the repository at this point in the history
…d loadgen

start and end time!
Signed-off-by: Kushal Shukla <[email protected]>
  • Loading branch information
kushalShukla-web committed Nov 12, 2024
1 parent fb07a8f commit d3ec226
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 12 deletions.
21 changes: 19 additions & 2 deletions prombench/manifests/prombench/benchmark/6_loadgen.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ data:
- name: simple_range
interval: 10s
type: range
start: 2h
start: 4h
end: 1h
step: 15s
queries:
Expand All @@ -31,7 +31,7 @@ data:
- name: aggr_range
interval: 30s
type: range
start: 1h
start: 4h
end: 0h
step: 15s
queries:
Expand Down Expand Up @@ -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
Expand All @@ -162,6 +177,8 @@ spec:
- name: config-volume
configMap:
name: prometheus-loadgen
- name: key
emptyDir: {}
nodeSelector:
node-name: nodes-{{ .PR_NUMBER }}
isolation: none
Expand Down
38 changes: 28 additions & 10 deletions tools/load-generator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -178,28 +183,41 @@ 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)
}
}
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!!!")

}

Check failure on line 219 in tools/load-generator/main.go

View workflow job for this annotation

GitHub Actions / lint

unnecessary trailing newline (whitespace)

if err != nil {
log.Printf("Error querying Prometheus: %v", err)
queryFailCount.WithLabelValues(q.target, q.name, expr, q.qtype).Inc()
Expand Down

0 comments on commit d3ec226

Please sign in to comment.