Skip to content

Commit

Permalink
Added rule name to rule error for easier debugging (prometheus#3549)
Browse files Browse the repository at this point in the history
  • Loading branch information
Conor Broderick authored and brian-brazil committed Dec 6, 2017
1 parent 30b4439 commit 59d4c53
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions pkg/rulefmt/rulefmt.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,14 @@ import (

// Error represents semantical errors on parsing rule groups.
type Error struct {
Group string
Rule int
Err error
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.
Expand Down Expand Up @@ -67,10 +68,17 @@ 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,
Err: err,
Group: g.Name,
Rule: i,
RuleName: ruleName,
Err: err,
})
}
}
Expand Down

0 comments on commit 59d4c53

Please sign in to comment.