From 36106a0aef2f2ac1b63a1ee7de09ff8e5a70f7d3 Mon Sep 17 00:00:00 2001 From: Andrej Krejcir Date: Tue, 23 Jan 2024 16:39:46 +0100 Subject: [PATCH] chore: metrics: Make a global variable private Made "recordRulesDescList" variable private. Signed-off-by: Andrej Krejcir --- pkg/monitoring/rules/rules.go | 20 ++++++++++++------- tools/metricsdocs/metricsdocs.go | 2 +- .../metrics_collector.go | 2 +- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/pkg/monitoring/rules/rules.go b/pkg/monitoring/rules/rules.go index 8622931b7..a08b6b9fd 100644 --- a/pkg/monitoring/rules/rules.go +++ b/pkg/monitoring/rules/rules.go @@ -30,8 +30,8 @@ type RecordRulesDesc struct { Type string } -// RecordRulesDescList lists all SSP Operator Prometheus Record Rules -var RecordRulesDescList = []RecordRulesDesc{ +// recordRulesDescList lists all SSP Operator Prometheus Record Rules +var recordRulesDescList = []RecordRulesDesc{ { Name: "kubevirt_ssp_operator_up", Expr: intstr.FromString("sum(up{pod=~'ssp-operator.*'}) OR on() vector(0)"), @@ -65,13 +65,19 @@ var RecordRulesDescList = []RecordRulesDesc{ } func RecordRules() []promv1.Rule { - var recordRules []promv1.Rule - - for _, rrd := range RecordRulesDescList { - recordRules = append(recordRules, promv1.Rule{Record: rrd.Name, Expr: rrd.Expr}) + result := make([]promv1.Rule, 0, len(recordRulesDescList)) + for _, rrd := range recordRulesDescList { + result = append(result, promv1.Rule{Record: rrd.Name, Expr: rrd.Expr}) } + return result +} - return recordRules +func RecordRulesWithDescriptions() []RecordRulesDesc { + result := make([]RecordRulesDesc, 0, len(recordRulesDescList)) + for _, rrd := range recordRulesDescList { + result = append(result, rrd) + } + return result } func AlertRules(runbookURLTemplate string) []promv1.Rule { diff --git a/tools/metricsdocs/metricsdocs.go b/tools/metricsdocs/metricsdocs.go index cf3735afc..323b72368 100644 --- a/tools/metricsdocs/metricsdocs.go +++ b/tools/metricsdocs/metricsdocs.go @@ -30,7 +30,7 @@ const ( ) func main() { - metricsList := recordRulesDescToMetricList(rules.RecordRulesDescList) + metricsList := recordRulesDescToMetricList(rules.RecordRulesWithDescriptions()) sspMetrics.SetupMetrics() validatorMetrics.SetupMetrics() diff --git a/tools/prom-metrics-collector/metrics_collector.go b/tools/prom-metrics-collector/metrics_collector.go index b4e3c38e3..a0c852f58 100644 --- a/tools/prom-metrics-collector/metrics_collector.go +++ b/tools/prom-metrics-collector/metrics_collector.go @@ -14,7 +14,7 @@ var excludedMetrics = map[string]struct{}{} func readMetrics() []*dto.MetricFamily { var metricFamilies []*dto.MetricFamily - sspMetrics := rules.RecordRulesDescList + sspMetrics := rules.RecordRulesWithDescriptions() for _, metric := range sspMetrics { if _, isExcludedMetric := excludedMetrics[metric.Name]; !isExcludedMetric {