Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(RHTAPWATCH-741): Add recording rules for exporter #205

Merged
merged 1 commit into from
Feb 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ kustomize:
check-and-test:
$(CMD) -t rhtap -d rhobs/alerting/data_plane -y -p --tests-dir test/promql/tests/data_plane
$(CMD) -t rhtap -d rhobs/alerting/control_plane -y -p --tests-dir test/promql/tests/control_plane
$(CMD) -t rhtap -d rhobs/recording -y -p --tests-dir test/promql/tests/recording

.PHONY: install_pipenv
install_pipenv:
Expand Down
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
15 changes: 15 additions & 0 deletions rhobs/recording/exporter_recording_rules.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Metric format needed
# grafana_ds_up(check=prometheus-appstudio-ds) -> konflux_up(service=grafana, check=prometheus-appstudio-ds)
apiVersion: monitoring.coreos.com/v1
kind: PrometheusRule
metadata:
name: rhtap-exporter-label-replace
labels:
tenant: rhtap
spec:
groups:
- name: exporter
interval: 1m
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
yftacherzog marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
evaluation_interval: 1m

rule_files:
- exporter_recording_rules.yml

tests:
- interval: 1m
name: DSExporterTest
input_series:
hmariset marked this conversation as resolved.
Show resolved Hide resolved
- 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