From 0e35fc9538727f8c2ea4ae88cda9ab2223435010 Mon Sep 17 00:00:00 2001 From: Roman Khavronenko Date: Thu, 23 Sep 2021 17:55:59 +0300 Subject: [PATCH] app/vmalert: remove unnecessary `omitempty` tag for `interval` param (#1649) `omitempty` tag resulted into skipping this param on marshaling, which was used as a checksum for groups configuration. Since on config reload checksums are compared before applying changes, any change to `interval` only didn't trigger config reload. https://github.com/VictoriaMetrics/VictoriaMetrics/issues/1641 Signed-off-by: hagen1778 --- app/vmalert/config/config.go | 2 +- app/vmalert/config/config_test.go | 33 +++++++++++++++++++++++++++++-- app/vmalert/group.go | 3 +++ 3 files changed, 35 insertions(+), 3 deletions(-) diff --git a/app/vmalert/config/config.go b/app/vmalert/config/config.go index 8a21cc90bb..ce873ccf7d 100644 --- a/app/vmalert/config/config.go +++ b/app/vmalert/config/config.go @@ -24,7 +24,7 @@ type Group struct { Type datasource.Type `yaml:"type,omitempty"` File string Name string `yaml:"name"` - Interval utils.PromDuration `yaml:"interval,omitempty"` + Interval utils.PromDuration `yaml:"interval"` Rules []Rule `yaml:"rules"` Concurrency int `yaml:"concurrency"` // ExtraFilterLabels is a list label filters applied to every rule diff --git a/app/vmalert/config/config_test.go b/app/vmalert/config/config_test.go index bb7f1e4a5f..5a2bbea94b 100644 --- a/app/vmalert/config/config_test.go +++ b/app/vmalert/config/config_test.go @@ -436,7 +436,7 @@ rules: `) }) - t.Run("Ok, `for` must change cs", func(t *testing.T) { + t.Run("`for` change", func(t *testing.T) { f(t, ` name: TestGroup rules: @@ -450,5 +450,34 @@ rules: expr: sum by(job) (up == 1) `) }) - + t.Run("`interval` change", func(t *testing.T) { + f(t, ` +name: TestGroup +interval: 2s +rules: + - alert: ExampleAlertWithFor + expr: sum by(job) (up == 1) +`, ` +name: TestGroup +interval: 4s +rules: + - alert: ExampleAlertWithFor + expr: sum by(job) (up == 1) +`) + }) + t.Run("`concurrency` change", func(t *testing.T) { + f(t, ` +name: TestGroup +concurrency: 2 +rules: + - alert: ExampleAlertWithFor + expr: sum by(job) (up == 1) +`, ` +name: TestGroup +concurrency: 16 +rules: + - alert: ExampleAlertWithFor + expr: sum by(job) (up == 1) +`) + }) } diff --git a/app/vmalert/group.go b/app/vmalert/group.go index 1e5e8c8acd..e80b1e6e89 100644 --- a/app/vmalert/group.go +++ b/app/vmalert/group.go @@ -190,6 +190,9 @@ func (g *Group) updateWith(newGroup *Group) error { for _, nr := range rulesRegistry { newRules = append(newRules, nr) } + // note that g.Interval is not updated here + // so the value can be compared later in + // group.Start function g.Type = newGroup.Type g.Concurrency = newGroup.Concurrency g.ExtraFilterLabels = newGroup.ExtraFilterLabels