From 3b9c228205227f39bc45ff93ccf033c5c77f2aca Mon Sep 17 00:00:00 2001 From: matthewhudsonedb Date: Mon, 6 Jan 2025 16:23:58 +1100 Subject: [PATCH] fix: Fix loki ruler generator url left parameter url encoding --- pkg/ruler/base/ruler.go | 6 +++--- pkg/ruler/base/ruler_test.go | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/pkg/ruler/base/ruler.go b/pkg/ruler/base/ruler.go index adb1a7c136def..4e466810570b1 100644 --- a/pkg/ruler/base/ruler.go +++ b/pkg/ruler/base/ruler.go @@ -407,9 +407,9 @@ func grafanaLinkForExpression(expr, datasourceUID string) string { } marshaledExpression, _ := json.Marshal(exprStruct) - escapedExpression := url.QueryEscape(string(marshaledExpression)) - str := `/explore?left={"queries":[%s]}` - return fmt.Sprintf(str, escapedExpression) + params := url.Values{} + params.Set("left", fmt.Sprintf(`{"queries":[%s]}`, marshaledExpression)) + return `/explore?` + params.Encode() } // SendAlerts implements a rules.NotifyFunc for a Notifier. diff --git a/pkg/ruler/base/ruler_test.go b/pkg/ruler/base/ruler_test.go index bdb437ed9279d..c97a83d15df30 100644 --- a/pkg/ruler/base/ruler_test.go +++ b/pkg/ruler/base/ruler_test.go @@ -1733,7 +1733,7 @@ func TestSendAlerts(t *testing.T) { Annotations: []labels.Label{{Name: "a2", Value: "v2"}}, StartsAt: time.Unix(2, 0), EndsAt: time.Unix(3, 0), - GeneratorURL: fmt.Sprintf("http://localhost:8080/explore?left={\"queries\":[%s]}", escapedExpression), + GeneratorURL: fmt.Sprintf("http://localhost:8080/explore?left=%7B%22queries%22%3A%5B%s%5D%7D", escapedExpression), }, }, }, @@ -1753,7 +1753,7 @@ func TestSendAlerts(t *testing.T) { Annotations: []labels.Label{{Name: "a2", Value: "v2"}}, StartsAt: time.Unix(2, 0), EndsAt: time.Unix(4, 0), - GeneratorURL: fmt.Sprintf("http://localhost:8080/explore?left={\"queries\":[%s]}", escapedExpression), + GeneratorURL: fmt.Sprintf("http://localhost:8080/explore?left=%7B%22queries%22%3A%5B%s%5D%7D", escapedExpression), }, }, },