From e082c3dd27e6f99a9bf1ac406f59cf006e833b5c Mon Sep 17 00:00:00 2001 From: Roman Khavronenko Date: Thu, 1 Jun 2023 11:38:48 +0200 Subject: [PATCH] app/vmalert: follow-up after 7a9ae9de0d2221cf7759e49ebcde0a06508b0f68 (#4381) https://github.com/VictoriaMetrics/VictoriaMetrics/pull/4341/commits/7a9ae9de0d2221cf7759e49ebcde0a06508b0f68 Signed-off-by: hagen1778 (cherry picked from commit eccecdf177115297fa1dc4d42d38e23de9a9f2cb) --- app/vmalert/Makefile | 1 + app/vmalert/datasource/vm.go | 25 +++++++++++++------------ 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/app/vmalert/Makefile b/app/vmalert/Makefile index aed0abed3..f113f65ce 100644 --- a/app/vmalert/Makefile +++ b/app/vmalert/Makefile @@ -73,6 +73,7 @@ test-vmalert: go test -v -race -cover ./app/vmalert/notifier go test -v -race -cover ./app/vmalert/config go test -v -race -cover ./app/vmalert/remotewrite + go test -v -race -cover ./app/vmalert/utils run-vmalert: vmalert ./bin/vmalert -rule=app/vmalert/config/testdata/rules/rules2-good.rules \ diff --git a/app/vmalert/datasource/vm.go b/app/vmalert/datasource/vm.go index 6c43ef74e..99d39ee13 100644 --- a/app/vmalert/datasource/vm.go +++ b/app/vmalert/datasource/vm.go @@ -28,6 +28,7 @@ func toDatasourceType(s string) datasourceType { } // VMStorage represents vmstorage entity with ability to read and write metrics +// WARN: when adding a new field, remember to update Clone() method. type VMStorage struct { c *http.Client authCfg *promauth.Config @@ -57,11 +58,16 @@ func (s *VMStorage) Clone() *VMStorage { c: s.c, authCfg: s.authCfg, datasourceURL: s.datasourceURL, + appendTypePrefix: s.appendTypePrefix, lookBack: s.lookBack, queryStep: s.queryStep, - appendTypePrefix: s.appendTypePrefix, - dataSourceType: s.dataSourceType, - extraParams: s.extraParams, + + dataSourceType: s.dataSourceType, + evaluationInterval: s.evaluationInterval, + extraParams: s.extraParams, + extraHeaders: s.extraHeaders, + + debug: s.debug, } } @@ -69,23 +75,18 @@ func (s *VMStorage) Clone() *VMStorage { func (s *VMStorage) ApplyParams(params QuerierParams) *VMStorage { s.dataSourceType = toDatasourceType(params.DataSourceType) s.evaluationInterval = params.EvaluationInterval - 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) - } + for k, vl := range params.QueryParams { + for _, v := range vl { // custom query params are prior to default ones + s.extraParams.Set(k, v) } } - s.debug = params.Debug if params.Headers != nil { for key, value := range params.Headers { kv := keyValue{key: key, value: value} s.extraHeaders = append(s.extraHeaders, kv) } } + s.debug = params.Debug return s }