diff --git a/app/vmalert/datasource/vm.go b/app/vmalert/datasource/vm.go index 2210b8e18..31c43e256 100644 --- a/app/vmalert/datasource/vm.go +++ b/app/vmalert/datasource/vm.go @@ -62,6 +62,7 @@ func (s *VMStorage) Clone() *VMStorage { queryStep: s.queryStep, appendTypePrefix: s.appendTypePrefix, dataSourceType: s.dataSourceType, + extraParams: s.extraParams, } } @@ -69,7 +70,16 @@ func (s *VMStorage) Clone() *VMStorage { func (s *VMStorage) ApplyParams(params QuerierParams) *VMStorage { s.dataSourceType = toDatasourceType(params.DataSourceType) s.evaluationInterval = params.EvaluationInterval - s.extraParams = params.QueryParams + if len(params.QueryParams) != 0 { + for k, vl := range params.QueryParams { + if s.extraParams.Has(k) { + s.extraParams.Del(k) + } + for _, v := range vl { + s.extraParams.Add(k, v) + } + } + } s.debug = params.Debug if params.Headers != nil { for key, value := range params.Headers { diff --git a/app/vmalert/datasource/vm_test.go b/app/vmalert/datasource/vm_test.go index 3ae1bf173..3df8805c2 100644 --- a/app/vmalert/datasource/vm_test.go +++ b/app/vmalert/datasource/vm_test.go @@ -378,6 +378,9 @@ func TestRequestParams(t *testing.T) { } query := "up" timestamp := time.Date(2001, 2, 3, 4, 5, 6, 0, time.UTC) + storage := VMStorage{ + extraParams: url.Values{"round_digits": {"10"}}, + } testCases := []struct { name string queryRange bool @@ -574,6 +577,17 @@ func TestRequestParams(t *testing.T) { checkEqualString(t, exp, r.URL.RawQuery) }, }, + { + "custom params overrides the original params", + false, + storage.Clone().ApplyParams(QuerierParams{ + QueryParams: url.Values{"round_digits": {"2"}}, + }), + func(t *testing.T, r *http.Request) { + exp := fmt.Sprintf("query=%s&round_digits=2&time=%d", query, timestamp.Unix()) + checkEqualString(t, exp, r.URL.RawQuery) + }, + }, { "graphite extra params", false,