Skip to content

Commit

Permalink
chore(RHTAPWATCH-741): Add recording rules for exporter
Browse files Browse the repository at this point in the history
Add recording rules to translate the components existing
metrics to expose availability.

Signed-off-by: Homaja Marisetty <[email protected]>
  • Loading branch information
hmariset committed Feb 19, 2024
1 parent 5fcf3f7 commit ad6c682
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 4 deletions.
7 changes: 3 additions & 4 deletions exporters/dsexporter/dsexporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client/config"
)

const service = "grafana"
const check = "prometheus-appstudio-ds"
var allDataSources = GetDataSources

Expand All @@ -26,10 +25,10 @@ type CustomCollector struct {
func NewCustomCollector() *CustomCollector {
return &CustomCollector{
konfluxUp: prometheus.NewGaugeVec(prometheus.GaugeOpts{
Name: "konflux_up",
Name: "grafana_ds_up",
Help: "Availability of the Konflux default grafana datasource",
},
[]string{"service", "check"}),
[]string{"check"}),
}
}

Expand All @@ -53,7 +52,7 @@ func (e *CustomCollector) Collect(ch chan<- prometheus.Metric) {
}
}

e.konfluxUp.WithLabelValues(service, check).Set(availability)
e.konfluxUp.WithLabelValues(check).Set(availability)
e.konfluxUp.Collect(ch)
}

Expand Down
7 changes: 7 additions & 0 deletions rhobs/recording/exporter_recording_rules.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Metric format needed
# grafana_ds_up(check=prometheus-appstudio-ds) -> konflux_up(service=grafana, check=prometheus-appstudio-ds)
groups:
- name: exporter
rules:
- record: konflux_up
expr: label_replace(grafana_ds_up, "service", "grafana", "__name__", "(.+)")
25 changes: 25 additions & 0 deletions test/promql/tests/recording/exporter_recording_rules_test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
evaluation_interval: 1m

rule_files:
- ../../../../rhobs/recording/exporter_recording_rules.yml

tests:
- interval: 1m
name: DSExporterTest
input_series:
- series: "grafana_ds_up{check='appstudio-ds'}"
values: "1 1 1 1 1"
- series: "grafana_ds_up{check='github'}"
values: "0 0 0 0 0"
- series: "grafana_ds_up{other_label='sso'}"
values: "0 1 0 1 0"
promql_expr_test:
- expr: konflux_up
eval_time: 5m
exp_samples:
- labels: konflux_up{service='grafana', check='appstudio-ds'}
value: 1
- labels: konflux_up{service='grafana', check='github'}
value: 0
- labels: konflux_up{service='grafana', other_label='sso'}
value: 0

0 comments on commit ad6c682

Please sign in to comment.