diff --git a/app/vmalert/config/config.go b/app/vmalert/config/config.go index ce873ccf7d..0cf23210dc 100644 --- a/app/vmalert/config/config.go +++ b/app/vmalert/config/config.go @@ -76,9 +76,6 @@ func (g *Group) Validate(validateAnnotations, validateExpressions bool) error { if g.Name == "" { return fmt.Errorf("group name must be set") } - if len(g.Rules) == 0 { - return fmt.Errorf("group %q can't contain no rules", g.Name) - } uniqueRules := map[uint64]struct{}{} for _, r := range g.Rules { diff --git a/app/vmalert/config/config_test.go b/app/vmalert/config/config_test.go index 5a2bbea94b..92f0ad1e4c 100644 --- a/app/vmalert/config/config_test.go +++ b/app/vmalert/config/config_test.go @@ -95,10 +95,6 @@ func TestGroup_Validate(t *testing.T) { group: &Group{}, expErr: "group name must be set", }, - { - group: &Group{Name: "test"}, - expErr: "contain no rules", - }, { group: &Group{Name: "test", Rules: []Rule{ diff --git a/app/vmalert/config/testdata/rules4-good.rules b/app/vmalert/config/testdata/rules4-good.rules new file mode 100644 index 0000000000..3894742cf0 --- /dev/null +++ b/app/vmalert/config/testdata/rules4-good.rules @@ -0,0 +1,8 @@ +groups: + - name: TestEmptyRules + interval: 2s + concurrency: 2 + rules: + + - name: TestNoRules + type: prometheus \ No newline at end of file diff --git a/app/vmalert/group.go b/app/vmalert/group.go index 47fab99d27..7fbc07b7b6 100644 --- a/app/vmalert/group.go +++ b/app/vmalert/group.go @@ -283,14 +283,15 @@ func (g *Group) start(ctx context.Context, nts []notifier.Notifier, rw *remotewr case <-t.C: g.metrics.iterationTotal.Inc() iterationStart := time.Now() - resolveDuration := getResolveDuration(g.Interval) - errs := e.execConcurrently(ctx, g.Rules, g.Concurrency, resolveDuration) - for err := range errs { - if err != nil { - logger.Errorf("group %q: %s", g.Name, err) + if len(g.Rules) > 0 { + resolveDuration := getResolveDuration(g.Interval) + errs := e.execConcurrently(ctx, g.Rules, g.Concurrency, resolveDuration) + for err := range errs { + if err != nil { + logger.Errorf("group %q: %s", g.Name, err) + } } } - g.metrics.iterationDuration.UpdateDuration(iterationStart) } }