mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-11-21 14:44:00 +00:00
vmalert: prodvide more details on duplicates (#3136)
Now vmalert will print the following messages on dupliсates: ``` "recording rule \"record\"; expr: \"up == 1\"; labels: summary={{ value|query }}" is a duplicate within the group "test" "alerting rule \"alert\"; expr: \"up == 1\"; labels: description={{ value|query }}" is a duplicate within the group "test" ``` https://github.com/VictoriaMetrics/VictoriaMetrics/issues/3127 Signed-off-by: hagen1778 <roman@victoriametrics.com>
This commit is contained in:
parent
336007182c
commit
74e81d31a7
1 changed files with 27 additions and 1 deletions
|
@ -77,7 +77,7 @@ func (g *Group) Validate(validateTplFn ValidateTplFn, validateExpressions bool)
|
|||
ruleName = r.Alert
|
||||
}
|
||||
if _, ok := uniqueRules[r.ID]; ok {
|
||||
return fmt.Errorf("rule %q duplicate", ruleName)
|
||||
return fmt.Errorf("%q is a duplicate within the group %q", r.String(), g.Name)
|
||||
}
|
||||
uniqueRules[r.ID] = struct{}{}
|
||||
if err := r.Validate(); err != nil {
|
||||
|
@ -137,6 +137,32 @@ func (r *Rule) Name() string {
|
|||
return r.Alert
|
||||
}
|
||||
|
||||
// String implements Stringer interface
|
||||
func (r *Rule) String() string {
|
||||
ruleType := "recording"
|
||||
if r.Alert != "" {
|
||||
ruleType = "alerting"
|
||||
}
|
||||
b := strings.Builder{}
|
||||
b.WriteString(fmt.Sprintf("%s rule %q", ruleType, r.Name()))
|
||||
b.WriteString(fmt.Sprintf("; expr: %q", r.Expr))
|
||||
|
||||
kv := sortMap(r.Labels)
|
||||
for i := range kv {
|
||||
if i == 0 {
|
||||
b.WriteString("; labels:")
|
||||
}
|
||||
b.WriteString(" ")
|
||||
b.WriteString(kv[i].key)
|
||||
b.WriteString("=")
|
||||
b.WriteString(kv[i].value)
|
||||
if i < len(kv)-1 {
|
||||
b.WriteString(",")
|
||||
}
|
||||
}
|
||||
return b.String()
|
||||
}
|
||||
|
||||
// HashRule hashes significant Rule fields into
|
||||
// unique hash that supposed to define Rule uniqueness
|
||||
func HashRule(r Rule) uint64 {
|
||||
|
|
Loading…
Reference in a new issue