Skip to content

Commit 6f94150

Browse files
d3flexp-se
authored andcommitted
fix(benchmarks): ensure all required families are present before extraction
The `getMetrics` already uses a guard before move on to extractFromMetricFamilies checking for a single family cluster `controller_runtime_reconcile_total`. However this can't vouch for the existence of the other metric families in `mfs`. To make sure that the `extractFromMetricFamilies` does not panic due to the empty maps, extend the guard with checks to all the metricFamilies. Expect only to fail with timeout in case that the map is not ready eventually. This likely does not have any other significant overhead for the benchmark results. Signed-off-by: Ioannis Bonatakis <ybonatakis@suse.com>
1 parent d7a17a3 commit 6f94150

1 file changed

Lines changed: 22 additions & 2 deletions

File tree

benchmarks/record/record.go

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,24 @@ func Metrics(experiment *gm.Experiment, suffix string) {
233233
}
234234
}
235235

236+
// requiredMetricFamilies lists every metric family that
237+
// extractFromMetricFamilies dereferences unconditionally. Some of these are
238+
// lazily created, e.g. rest_client_requests_total only appears after the
239+
// controller's first API request, so a scrape taken too early may miss them.
240+
var requiredMetricFamilies = []string{
241+
"controller_runtime_reconcile_total",
242+
"rest_client_requests_total",
243+
"controller_runtime_reconcile_time_seconds",
244+
"workqueue_adds_total",
245+
"workqueue_queue_duration_seconds",
246+
"workqueue_retries_total",
247+
"workqueue_work_duration_seconds",
248+
"go_gc_duration_seconds",
249+
"process_cpu_seconds_total",
250+
"process_network_receive_bytes_total",
251+
"process_network_transmit_bytes_total",
252+
}
253+
236254
func getMetrics(res map[string]float64, url string, controllers ...string) {
237255
var (
238256
mfs map[string]*dto.MetricFamily
@@ -256,8 +274,10 @@ func getMetrics(res map[string]float64, url string, controllers ...string) {
256274
return err
257275
}
258276

259-
if _, ok := mfs["controller_runtime_reconcile_total"]; !ok {
260-
return errors.New("controller_runtime_reconcile_total not found")
277+
for _, name := range requiredMetricFamilies {
278+
if _, ok := mfs[name]; !ok {
279+
return errors.New(name + " not found")
280+
}
261281
}
262282

263283
return nil

0 commit comments

Comments
 (0)