Skip to content

Commit

Permalink
chore: metrics: Make a global variable private
Browse files Browse the repository at this point in the history
Made "recordRulesDescList" variable private.

Signed-off-by: Andrej Krejcir <[email protected]>
  • Loading branch information
akrejcir committed Jan 23, 2024
1 parent fbf89bd commit 36106a0
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
20 changes: 13 additions & 7 deletions pkg/monitoring/rules/rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)"),
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion tools/metricsdocs/metricsdocs.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const (
)

func main() {
metricsList := recordRulesDescToMetricList(rules.RecordRulesDescList)
metricsList := recordRulesDescToMetricList(rules.RecordRulesWithDescriptions())

sspMetrics.SetupMetrics()
validatorMetrics.SetupMetrics()
Expand Down
2 changes: 1 addition & 1 deletion tools/prom-metrics-collector/metrics_collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 36106a0

Please sign in to comment.