Skip to content

Commit 2163398

Browse files
committed
Refactor scale test to include framework queries
1 parent b886385 commit 2163398

File tree

2 files changed

+167
-197
lines changed

2 files changed

+167
-197
lines changed

tests/framework/queries.go

Lines changed: 140 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -59,18 +59,39 @@ func GetReloadCount(promInstance PrometheusInstance, ngfPodName string) (float64
5959
)
6060
}
6161

62-
//func getReloadErrsCount(promInstance PrometheusInstance, ngfPodName string, startTime time.Time) float64 {
63-
// return getFirstValueOfVector(
64-
// fmt.Sprintf(
65-
// `nginx_gateway_fabric_nginx_reload_errors_total{pod="%[1]s"}`+
66-
// ` - `+
67-
// `nginx_gateway_fabric_nginx_reload_errors_total{pod="%[1]s"} @ %d`,
68-
// ngfPodName,
69-
// startTime.Unix(),
70-
// ),
71-
// promInstance,
72-
// )
73-
//}
62+
func GetReloadCountWithStartTime(
63+
promInstance PrometheusInstance,
64+
ngfPodName string,
65+
startTime time.Time,
66+
) (float64, error) {
67+
return getFirstValueOfVector(
68+
fmt.Sprintf(
69+
`nginx_gateway_fabric_nginx_reloads_total{pod="%[1]s"}`+
70+
` - `+
71+
`nginx_gateway_fabric_nginx_reloads_total{pod="%[1]s"} @ %d`,
72+
ngfPodName,
73+
startTime.Unix(),
74+
),
75+
promInstance,
76+
)
77+
}
78+
79+
func GetReloadErrsCountWithStartTime(
80+
promInstance PrometheusInstance,
81+
ngfPodName string,
82+
startTime time.Time,
83+
) (float64, error) {
84+
return getFirstValueOfVector(
85+
fmt.Sprintf(
86+
`nginx_gateway_fabric_nginx_reload_errors_total{pod="%[1]s"}`+
87+
` - `+
88+
`nginx_gateway_fabric_nginx_reload_errors_total{pod="%[1]s"} @ %d`,
89+
ngfPodName,
90+
startTime.Unix(),
91+
),
92+
promInstance,
93+
)
94+
}
7495

7596
func GetReloadAvgTime(promInstance PrometheusInstance, ngfPodName string) (float64, error) {
7697
return getFirstValueOfVector(
@@ -84,6 +105,27 @@ func GetReloadAvgTime(promInstance PrometheusInstance, ngfPodName string) (float
84105
)
85106
}
86107

108+
func GetReloadAvgTimeWithStartTime(
109+
promInstance PrometheusInstance,
110+
ngfPodName string,
111+
startTime time.Time,
112+
) (float64, error) {
113+
return getFirstValueOfVector(
114+
fmt.Sprintf(
115+
`(nginx_gateway_fabric_nginx_reloads_milliseconds_sum{pod="%[1]s"}`+
116+
` - `+
117+
`nginx_gateway_fabric_nginx_reloads_milliseconds_sum{pod="%[1]s"} @ %[2]d)`+
118+
` / `+
119+
`(nginx_gateway_fabric_nginx_reloads_total{pod="%[1]s"}`+
120+
` - `+
121+
`nginx_gateway_fabric_nginx_reloads_total{pod="%[1]s"} @ %[2]d)`,
122+
ngfPodName,
123+
startTime.Unix(),
124+
),
125+
promInstance,
126+
)
127+
}
128+
87129
func GetReloadBuckets(promInstance PrometheusInstance, ngfPodName string) ([]Bucket, error) {
88130
return getBuckets(
89131
fmt.Sprintf(
@@ -94,6 +136,23 @@ func GetReloadBuckets(promInstance PrometheusInstance, ngfPodName string) ([]Buc
94136
)
95137
}
96138

139+
func GetReloadBucketsWithStartTime(
140+
promInstance PrometheusInstance,
141+
ngfPodName string,
142+
startTime time.Time,
143+
) ([]Bucket, error) {
144+
return getBuckets(
145+
fmt.Sprintf(
146+
`nginx_gateway_fabric_nginx_reloads_milliseconds_bucket{pod="%[1]s"}`+
147+
` - `+
148+
`nginx_gateway_fabric_nginx_reloads_milliseconds_bucket{pod="%[1]s"} @ %d`,
149+
ngfPodName,
150+
startTime.Unix(),
151+
),
152+
promInstance,
153+
)
154+
}
155+
97156
func GetEventsCount(promInstance PrometheusInstance, ngfPodName string) (float64, error) {
98157
return getFirstValueOfVector(
99158
fmt.Sprintf(
@@ -104,6 +163,23 @@ func GetEventsCount(promInstance PrometheusInstance, ngfPodName string) (float64
104163
)
105164
}
106165

166+
func GetEventsCountWithStartTime(
167+
promInstance PrometheusInstance,
168+
ngfPodName string,
169+
startTime time.Time,
170+
) (float64, error) {
171+
return getFirstValueOfVector(
172+
fmt.Sprintf(
173+
`nginx_gateway_fabric_event_batch_processing_milliseconds_count{pod="%[1]s"}`+
174+
` - `+
175+
`nginx_gateway_fabric_event_batch_processing_milliseconds_count{pod="%[1]s"} @ %d`,
176+
ngfPodName,
177+
startTime.Unix(),
178+
),
179+
promInstance,
180+
)
181+
}
182+
107183
func GetEventsAvgTime(promInstance PrometheusInstance, ngfPodName string) (float64, error) {
108184
return getFirstValueOfVector(
109185
fmt.Sprintf(
@@ -116,6 +192,27 @@ func GetEventsAvgTime(promInstance PrometheusInstance, ngfPodName string) (float
116192
)
117193
}
118194

195+
func GetEventsAvgTimeWithStartTime(
196+
promInstance PrometheusInstance,
197+
ngfPodName string,
198+
startTime time.Time,
199+
) (float64, error) {
200+
return getFirstValueOfVector(
201+
fmt.Sprintf(
202+
`(nginx_gateway_fabric_event_batch_processing_milliseconds_sum{pod="%[1]s"}`+
203+
` - `+
204+
`nginx_gateway_fabric_event_batch_processing_milliseconds_sum{pod="%[1]s"} @ %[2]d)`+
205+
` / `+
206+
`(nginx_gateway_fabric_event_batch_processing_milliseconds_count{pod="%[1]s"}`+
207+
` - `+
208+
`nginx_gateway_fabric_event_batch_processing_milliseconds_count{pod="%[1]s"} @ %[2]d)`,
209+
ngfPodName,
210+
startTime.Unix(),
211+
),
212+
promInstance,
213+
)
214+
}
215+
119216
func GetEventsBuckets(promInstance PrometheusInstance, ngfPodName string) ([]Bucket, error) {
120217
return getBuckets(
121218
fmt.Sprintf(
@@ -126,6 +223,23 @@ func GetEventsBuckets(promInstance PrometheusInstance, ngfPodName string) ([]Buc
126223
)
127224
}
128225

226+
func GetEventsBucketsWithStartTime(
227+
promInstance PrometheusInstance,
228+
ngfPodName string,
229+
startTime time.Time,
230+
) ([]Bucket, error) {
231+
return getBuckets(
232+
fmt.Sprintf(
233+
`nginx_gateway_fabric_event_batch_processing_milliseconds_bucket{pod="%[1]s"}`+
234+
` - `+
235+
`nginx_gateway_fabric_event_batch_processing_milliseconds_bucket{pod="%[1]s"} @ %d`,
236+
ngfPodName,
237+
startTime.Unix(),
238+
),
239+
promInstance,
240+
)
241+
}
242+
129243
func CreateMetricExistChecker(
130244
promInstance PrometheusInstance,
131245
query string,
@@ -175,20 +289,20 @@ func CreateEndTimeFinder(
175289
}
176290
}
177291

178-
//func createResponseChecker(url, address string, requestTimeout time.Duration) func() error {
179-
// return func() error {
180-
// status, _, err := Get(url, address, requestTimeout)
181-
// if err != nil {
182-
// return fmt.Errorf("bad response: %w", err)
183-
// }
184-
//
185-
// if status != 200 {
186-
// return fmt.Errorf("unexpected status code: %d", status)
187-
// }
188-
//
189-
// return nil
190-
// }
191-
//}
292+
func CreateResponseChecker(url, address string, requestTimeout time.Duration) func() error {
293+
return func() error {
294+
status, _, err := Get(url, address, requestTimeout)
295+
if err != nil {
296+
return fmt.Errorf("bad response: %w", err)
297+
}
298+
299+
if status != 200 {
300+
return fmt.Errorf("unexpected status code: %d", status)
301+
}
302+
303+
return nil
304+
}
305+
}
192306

193307
type Bucket struct {
194308
Le string

0 commit comments

Comments
 (0)