diff --git a/app/vmalert/datasource/vm_graphite_api.go b/app/vmalert/datasource/vm_graphite_api.go index 4ad5c2a6c..bb4acfeca 100644 --- a/app/vmalert/datasource/vm_graphite_api.go +++ b/app/vmalert/datasource/vm_graphite_api.go @@ -54,6 +54,16 @@ func (s *VMStorage) setGraphiteReqParams(r *http.Request, query string, timestam } r.URL.Path += graphitePath q := r.URL.Query() + from := "-5min" + if s.lookBack > 0 { + lookBack := timestamp.Add(-s.lookBack) + from = strconv.FormatInt(lookBack.Unix(), 10) + } + q.Set("from", from) + q.Set("format", "json") + q.Set("target", query) + q.Set("until", "now") + for k, vs := range s.extraParams { if q.Has(k) { // extraParams are prior to params in URL q.Del(k) @@ -62,14 +72,6 @@ func (s *VMStorage) setGraphiteReqParams(r *http.Request, query string, timestam q.Add(k, v) } } - q.Set("format", "json") - q.Set("target", query) - from := "-5min" - if s.lookBack > 0 { - lookBack := timestamp.Add(-s.lookBack) - from = strconv.FormatInt(lookBack.Unix(), 10) - } - q.Set("from", from) - q.Set("until", "now") + r.URL.RawQuery = q.Encode() } diff --git a/app/vmalert/datasource/vm_test.go b/app/vmalert/datasource/vm_test.go index 5011d300a..68c2f6e8f 100644 --- a/app/vmalert/datasource/vm_test.go +++ b/app/vmalert/datasource/vm_test.go @@ -611,6 +611,20 @@ func TestRequestParams(t *testing.T) { checkEqualString(t, exp, r.URL.RawQuery) }, }, + { + "graphite extra params allows to override from", + false, + &VMStorage{ + dataSourceType: datasourceGraphite, + extraParams: url.Values{ + "from": {"-10m"}, + }, + }, + func(t *testing.T, r *http.Request) { + exp := fmt.Sprintf("format=json&from=-10m&target=%s&until=now", query) + checkEqualString(t, exp, r.URL.RawQuery) + }, + }, } for _, tc := range testCases { diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 5b2db0cbe..e9bfc2b1d 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -47,6 +47,7 @@ The following `tip` changes can be tested by building VictoriaMetrics components * FEATUTE: [vmalert](https://docs.victoriametrics.com/vmalert.html): allow disabling of `step` param attached to [instant queries](https://docs.victoriametrics.com/keyConcepts.html#instant-query). This might be useful for using vmalert with datasources that to not support this param, unlike VictoriaMetrics. See [this issue](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/4573) for details. * FEATUTE: [vmalert](https://docs.victoriametrics.com/vmalert.html): support option for "blackholing" alerting notifications if `-notifier.blackhole` cmd-line flag is set. Enable this flag if you want vmalert to evaluate alerting rules without sending any notifications to external receivers (eg. alertmanager). See [this issue](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/4122) for details. Thanks to @venkatbvc for [the pull request](https://github.com/VictoriaMetrics/VictoriaMetrics/pull/4639). * FEATURE: [vmalert](https://docs.victoriametrics.com/vmalert.html): add unit test for alerting and recording rules, see more [details](https://docs.victoriametrics.com/vmalert.html#unit-testing-for-rules) here. Thanks to @Haleygo for [the pull request](https://github.com/VictoriaMetrics/VictoriaMetrics/pull/4596). +* FEATURE: [vmalert](https://docs.victoriametrics.com/vmalert.html): allow overriding default GET params for rules with `graphite` datasource type, in the same way as it happens for `prometheus` type. See [this issue](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/4685). * FEATURE: [vmauth](https://docs.victoriametrics.com/vmauth.html): expose `vmauth_user_request_duration_seconds` and `vmauth_unauthorized_user_request_duration_seconds` summary metrics for measuring requests latency per user. * FEATURE: [vmbackup](https://docs.victoriametrics.com/vmbackup.html): show backup progress percentage in log during backup uploading. See [this issue](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/4460). * FEATURE: [vmrestore](https://docs.victoriametrics.com/vmrestore.html): show restoring progress percentage in log during backup downloading. See [this issue](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/4460).