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 14, 2024
1 parent fb07a8f commit 01a5662
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 34 deletions.
42 changes: 22 additions & 20 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 @@ -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
Expand All @@ -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
Expand All @@ -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 }}"
Expand All @@ -155,13 +153,17 @@ spec:
volumeMounts:
- name: config-volume
mountPath: /etc/loadgen
- name: key
mountPath: /config
ports:
- name: loadgen-port
containerPort: 8080
volumes:
- name: config-volume
configMap:
name: prometheus-loadgen
- name: key
emptyDir: {}
nodeSelector:
node-name: nodes-{{ .PR_NUMBER }}
isolation: none
Expand Down
31 changes: 17 additions & 14 deletions tools/load-generator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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
Expand All @@ -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)
Expand All @@ -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)
}
Expand Down

0 comments on commit 01a5662

Please sign in to comment.