mirror of
https://github.com/prometheus/prometheus.git
synced 2025-01-13 06:47:28 -08:00
Added rule name to rule error for easier debugging (#3549)
This commit is contained in:
parent
30b4439bbd
commit
59d4c539d1
|
@ -28,11 +28,12 @@ import (
|
|||
type Error struct {
|
||||
Group string
|
||||
Rule int
|
||||
RuleName string
|
||||
Err error
|
||||
}
|
||||
|
||||
func (err *Error) Error() string {
|
||||
return errors.Wrapf(err.Err, "group %q, rule %d", err.Group, err.Rule).Error()
|
||||
return errors.Wrapf(err.Err, "group %q, rule %d, %q", err.Group, err.Rule, err.RuleName).Error()
|
||||
}
|
||||
|
||||
// RuleGroups is a set of rule groups that are typically exposed in a file.
|
||||
|
@ -67,9 +68,16 @@ func (g *RuleGroups) Validate() (errs []error) {
|
|||
|
||||
for i, r := range g.Rules {
|
||||
for _, err := range r.Validate() {
|
||||
var ruleName string
|
||||
if r.Alert != "" {
|
||||
ruleName = r.Alert
|
||||
} else {
|
||||
ruleName = r.Record
|
||||
}
|
||||
errs = append(errs, &Error{
|
||||
Group: g.Name,
|
||||
Rule: i,
|
||||
RuleName: ruleName,
|
||||
Err: err,
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue