From 3aec9c2cf17b2d46666026e4a9167a943a7ee391 Mon Sep 17 00:00:00 2001 From: j-gourdon Date: Mon, 11 Apr 2022 14:36:27 +0200 Subject: [PATCH] Fix: panic when max-length metrics are excluded --- exporter_queue.go | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/exporter_queue.go b/exporter_queue.go index 4fc9305..e46973a 100644 --- a/exporter_queue.go +++ b/exporter_queue.go @@ -215,11 +215,16 @@ func (e exporterQueue) Collect(ctx context.Context, ch chan<- prometheus.Metric) } e.stateMetric.WithLabelValues(append(labelValues, state)...).Set(1) - if f := collectLowerMetric("arguments.x-max-length", "effective_policy_definition.max-length", queue); f >= 0 { - limitsGaugeVec["max-length"].WithLabelValues(labelValues...).Set(f) + if _, ok := limitsGaugeVec["max-length"]; ok { + if f := collectLowerMetric("arguments.x-max-length", "effective_policy_definition.max-length", queue); f >= 0 { + limitsGaugeVec["max-length"].WithLabelValues(labelValues...).Set(f) + } } - if f := collectLowerMetric("arguments.x-max-length-bytes", "effective_policy_definition.max-length-bytes", queue); f >= 0 { - limitsGaugeVec["max-length-bytes"].WithLabelValues(labelValues...).Set(f) + + if _, ok := limitsGaugeVec["max-length-bytes"]; ok { + if f := collectLowerMetric("arguments.x-max-length-bytes", "effective_policy_definition.max-length-bytes", queue); f >= 0 { + limitsGaugeVec["max-length-bytes"].WithLabelValues(labelValues...).Set(f) + } } }