mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2025-03-21 15:45:01 +00:00
vmalert: allow groups with empty rules for compatibility reasons (#1742)
Prometheus allows to have groups with no rules, so we should support it in vmalert as well for compatibility reasons. It is also allowed to hot-reload empty groups by adding or removing rules. Signed-off-by: hagen1778 <roman@victoriametrics.com>
This commit is contained in:
parent
2d7d67372f
commit
5321127add
4 changed files with 15 additions and 13 deletions
|
@ -76,9 +76,6 @@ func (g *Group) Validate(validateAnnotations, validateExpressions bool) error {
|
||||||
if g.Name == "" {
|
if g.Name == "" {
|
||||||
return fmt.Errorf("group name must be set")
|
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{}{}
|
uniqueRules := map[uint64]struct{}{}
|
||||||
for _, r := range g.Rules {
|
for _, r := range g.Rules {
|
||||||
|
|
|
@ -95,10 +95,6 @@ func TestGroup_Validate(t *testing.T) {
|
||||||
group: &Group{},
|
group: &Group{},
|
||||||
expErr: "group name must be set",
|
expErr: "group name must be set",
|
||||||
},
|
},
|
||||||
{
|
|
||||||
group: &Group{Name: "test"},
|
|
||||||
expErr: "contain no rules",
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
group: &Group{Name: "test",
|
group: &Group{Name: "test",
|
||||||
Rules: []Rule{
|
Rules: []Rule{
|
||||||
|
|
8
app/vmalert/config/testdata/rules4-good.rules
vendored
Normal file
8
app/vmalert/config/testdata/rules4-good.rules
vendored
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
groups:
|
||||||
|
- name: TestEmptyRules
|
||||||
|
interval: 2s
|
||||||
|
concurrency: 2
|
||||||
|
rules:
|
||||||
|
|
||||||
|
- name: TestNoRules
|
||||||
|
type: prometheus
|
|
@ -283,14 +283,15 @@ func (g *Group) start(ctx context.Context, nts []notifier.Notifier, rw *remotewr
|
||||||
case <-t.C:
|
case <-t.C:
|
||||||
g.metrics.iterationTotal.Inc()
|
g.metrics.iterationTotal.Inc()
|
||||||
iterationStart := time.Now()
|
iterationStart := time.Now()
|
||||||
resolveDuration := getResolveDuration(g.Interval)
|
if len(g.Rules) > 0 {
|
||||||
errs := e.execConcurrently(ctx, g.Rules, g.Concurrency, resolveDuration)
|
resolveDuration := getResolveDuration(g.Interval)
|
||||||
for err := range errs {
|
errs := e.execConcurrently(ctx, g.Rules, g.Concurrency, resolveDuration)
|
||||||
if err != nil {
|
for err := range errs {
|
||||||
logger.Errorf("group %q: %s", g.Name, err)
|
if err != nil {
|
||||||
|
logger.Errorf("group %q: %s", g.Name, err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
g.metrics.iterationDuration.UpdateDuration(iterationStart)
|
g.metrics.iterationDuration.UpdateDuration(iterationStart)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue