Skip to content

Commit

Permalink
fix: Fix loki ruler generator url left parameter url encoding
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewhudsonedb committed Jan 9, 2025
1 parent 74885a2 commit 7bea99c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
6 changes: 3 additions & 3 deletions pkg/ruler/base/ruler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions pkg/ruler/base/ruler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
},
},
},
Expand All @@ -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),
},
},
},
Expand Down

0 comments on commit 7bea99c

Please sign in to comment.