fix: Fix loki ruler generator url left parameter url encoding (#15601)

The generate URL `left` parameter is not URL encoded. The double quotes in str variable around "queries" break hyperlinking.
pull/15669/head
matthewhudsonedb 1 year ago committed by GitHub
parent 74885a20c7
commit e347eb7c80
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 6
      pkg/ruler/base/ruler.go
  2. 4
      pkg/ruler/base/ruler_test.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.

@ -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),
},
},
},

Loading…
Cancel
Save