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",