Skip to content

Commit 7bea99c

Browse files
fix: Fix loki ruler generator url left parameter url encoding
1 parent 74885a2 commit 7bea99c

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

pkg/ruler/base/ruler.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -407,9 +407,9 @@ func grafanaLinkForExpression(expr, datasourceUID string) string {
407407
}
408408

409409
marshaledExpression, _ := json.Marshal(exprStruct)
410-
escapedExpression := url.QueryEscape(string(marshaledExpression))
411-
str := `/explore?left={"queries":[%s]}`
412-
return fmt.Sprintf(str, escapedExpression)
410+
params := url.Values{}
411+
params.Set("left", fmt.Sprintf(`{"queries":[%s]}`, marshaledExpression))
412+
return `/explore?` + params.Encode()
413413
}
414414

415415
// SendAlerts implements a rules.NotifyFunc for a Notifier.

pkg/ruler/base/ruler_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -1733,7 +1733,7 @@ func TestSendAlerts(t *testing.T) {
17331733
Annotations: []labels.Label{{Name: "a2", Value: "v2"}},
17341734
StartsAt: time.Unix(2, 0),
17351735
EndsAt: time.Unix(3, 0),
1736-
GeneratorURL: fmt.Sprintf("http://localhost:8080/explore?left={\"queries\":[%s]}", escapedExpression),
1736+
GeneratorURL: fmt.Sprintf("http://localhost:8080/explore?left=%%7B%%22queries%%22%%3A%%5B%s%%5D%%7D", escapedExpression),
17371737
},
17381738
},
17391739
},
@@ -1753,7 +1753,7 @@ func TestSendAlerts(t *testing.T) {
17531753
Annotations: []labels.Label{{Name: "a2", Value: "v2"}},
17541754
StartsAt: time.Unix(2, 0),
17551755
EndsAt: time.Unix(4, 0),
1756-
GeneratorURL: fmt.Sprintf("http://localhost:8080/explore?left={\"queries\":[%s]}", escapedExpression),
1756+
GeneratorURL: fmt.Sprintf("http://localhost:8080/explore?left=%%7B%%22queries%%22%%3A%%5B%s%%5D%%7D", escapedExpression),
17571757
},
17581758
},
17591759
},

0 commit comments

Comments
 (0)