Skip to content

Commit

Permalink
app/vmalert: fix datasource.roundDigits Parameter (#4341)
Browse files Browse the repository at this point in the history
app/vmalert: fix querybuild clone and extraParams merge logic

See #4340

(cherry picked from commit 20dc3db)
Signed-off-by: hagen1778 <roman@victoriametrics.com>
  • Loading branch information
gsakun authored and hagen1778 committed Jun 5, 2023
1 parent 6be9416 commit 67ab0d4
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
12 changes: 11 additions & 1 deletion app/vmalert/datasource/vm.go
Expand Up @@ -36,6 +36,7 @@ func (s *VMStorage) Clone() *VMStorage {
queryStep: s.queryStep,
appendTypePrefix: s.appendTypePrefix,
dataSourceType: s.dataSourceType,
extraParams: s.extraParams,
}
}

Expand All @@ -45,7 +46,16 @@ func (s *VMStorage) ApplyParams(params QuerierParams) *VMStorage {
s.dataSourceType = *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)
}
}
}
return s
}

Expand Down
14 changes: 14 additions & 0 deletions app/vmalert/datasource/vm_test.go
Expand Up @@ -257,6 +257,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
Expand Down Expand Up @@ -453,6 +456,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,
Expand Down

0 comments on commit 67ab0d4

Please sign in to comment.