From 78dd259c5eb3d17979ed742317f1643e3411c159 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Mierzwa?= Date: Wed, 13 Apr 2022 15:15:54 +0100 Subject: [PATCH] fix(backend): escape filters --- CHANGELOG.md | 1 + cmd/karma/alert_history.go | 6 +++--- demo/generator.py | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1794707ec..88bf5eb93 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ ### Fixed - Correctly set filter history. +- Correctly escape label values when quering Prometheus for alert history. ## v0.101 diff --git a/cmd/karma/alert_history.go b/cmd/karma/alert_history.go index 1f4b8fd9e..a27e1a5f4 100644 --- a/cmd/karma/alert_history.go +++ b/cmd/karma/alert_history.go @@ -313,13 +313,13 @@ func countAlerts(uri string, timeout time.Duration, transport http.RoundTripper, Step: time.Hour, } - lv := []string{} + lv := model.LabelSet{} for k, v := range labels { if slices.StringInSlice(names, k) { - lv = append(lv, fmt.Sprintf(`%s="%s"`, k, v)) + lv[model.LabelName(k)] = model.LabelValue(v) } } - q := fmt.Sprintf("changes(ALERTS_FOR_STATE{%s}[1h])", strings.Join(lv, ",")) + q := fmt.Sprintf("changes(ALERTS_FOR_STATE{%s}[1h])", lv) log.Debug(). Str("uri", uri). Interface("labels", labels). diff --git a/demo/generator.py b/demo/generator.py index 1af23d437..51194bacb 100755 --- a/demo/generator.py +++ b/demo/generator.py @@ -569,7 +569,7 @@ def alerts(self): cluster="staging", job="textfile_exporter", region="SA", - device="Device {} (main)".format(i % 2), + device='Device {} (main) "quoted"'.format(i % 2), regex="^device{}(.+)bar\\$".format(i), address="10.0.0.1{}".format(i), pod="my-pod",