diff --git a/app/vmalert/datasource/vm.go b/app/vmalert/datasource/vm.go index 46fe851385..cf6a43d3ef 100644 --- a/app/vmalert/datasource/vm.go +++ b/app/vmalert/datasource/vm.go @@ -55,7 +55,7 @@ type keyValue struct { // Clone makes clone of VMStorage, shares http client. func (s *VMStorage) Clone() *VMStorage { - return &VMStorage{ + ns := &VMStorage{ c: s.c, authCfg: s.authCfg, datasourceURL: s.datasourceURL, @@ -65,20 +65,35 @@ func (s *VMStorage) Clone() *VMStorage { dataSourceType: s.dataSourceType, evaluationInterval: s.evaluationInterval, - extraParams: s.extraParams, - extraHeaders: s.extraHeaders, + + // init map so it can be populated below + extraParams: url.Values{}, debug: s.debug, } + if len(s.extraHeaders) > 0 { + ns.extraHeaders = make([]keyValue, len(s.extraHeaders)) + copy(ns.extraHeaders, s.extraHeaders) + } + for k, v := range s.extraParams { + ns.extraParams[k] = v + } + + return ns } // ApplyParams - changes given querier params. func (s *VMStorage) ApplyParams(params QuerierParams) *VMStorage { s.dataSourceType = toDatasourceType(params.DataSourceType) s.evaluationInterval = params.EvaluationInterval - for k, vl := range params.QueryParams { - for _, v := range vl { // custom query params are prior to default ones - s.extraParams.Set(k, v) + if params.QueryParams != nil { + if s.extraParams == nil { + s.extraParams = url.Values{} + } + for k, vl := range params.QueryParams { + for _, v := range vl { // custom query params are prior to default ones + s.extraParams.Set(k, v) + } } } if params.Headers != nil { @@ -106,6 +121,7 @@ func NewVMStorage(baseURL string, authCfg *promauth.Config, lookBack time.Durati lookBack: lookBack, queryStep: queryStep, dataSourceType: datasourcePrometheus, + extraParams: url.Values{}, } } diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index ff29769f61..797e1cc529 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -24,6 +24,9 @@ The following tip changes can be tested by building VictoriaMetrics components f ## tip +* BUGFIX: [vmalert](https://docs.victoriametrics.com/vmalert.html): fix nil map assignment panic in runtime introduced in this [change](https://github.com/VictoriaMetrics/VictoriaMetrics/pull/4341). + + ## [v1.91.1](https://github.com/VictoriaMetrics/VictoriaMetrics/releases/tag/v1.91.1) Released at 2023-06-01