mirror of
https://github.com/prometheus/prometheus.git
synced 2025-01-12 06:17:27 -08:00
Make sure groups are unique in a single file
Signed-off-by: Goutham Veeramachaneni <cs14btech11014@iith.ac.in>
This commit is contained in:
parent
cea1e99f78
commit
a48a018368
|
@ -16,7 +16,7 @@ type Error struct {
|
|||
}
|
||||
|
||||
func (err *Error) Error() string {
|
||||
return errors.Wrapf(err, "group %q, rule %d", err.Group, err.Rule).Error()
|
||||
return errors.Wrapf(err.Err, "group %q, rule %d", err.Group, err.Rule).Error()
|
||||
}
|
||||
|
||||
// RuleGroups is a set of rule groups that are typically exposed in a file.
|
||||
|
@ -30,7 +30,18 @@ func (g *RuleGroups) Validate() (errs []error) {
|
|||
if g.Version != 1 {
|
||||
errs = append(errs, errors.Errorf("invalid rule group version %d", g.Version))
|
||||
}
|
||||
set := map[string]struct{}{}
|
||||
|
||||
for _, g := range g.Groups {
|
||||
if _, ok := set[g.Name]; ok {
|
||||
errs = append(
|
||||
errs,
|
||||
errors.Errorf("groupname: \"%s\" is repeated in the same file", g.Name),
|
||||
)
|
||||
}
|
||||
|
||||
set[g.Name] = struct{}{}
|
||||
|
||||
for i, r := range g.Rules {
|
||||
for _, err := range r.Validate() {
|
||||
errs = append(errs, &Error{
|
||||
|
|
|
@ -26,6 +26,7 @@ import (
|
|||
"github.com/prometheus/client_golang/prometheus"
|
||||
"github.com/prometheus/common/log"
|
||||
"github.com/prometheus/common/model"
|
||||
"github.com/prometheus/tsdb"
|
||||
"golang.org/x/net/context"
|
||||
|
||||
"github.com/prometheus/prometheus/config"
|
||||
|
@ -501,10 +502,9 @@ func (m *Manager) loadGroups(interval time.Duration, filenames ...string) (map[s
|
|||
groups := make(map[string]*Group)
|
||||
|
||||
for _, fn := range filenames {
|
||||
rgs, err := rulefmt.ParseFile(fn)
|
||||
if err != nil {
|
||||
// TODO(gouthamve): Use multi-error?
|
||||
return nil, err[0]
|
||||
rgs, errs := rulefmt.ParseFile(fn)
|
||||
if errs != nil {
|
||||
return nil, tsdb.MultiError(errs)
|
||||
}
|
||||
|
||||
for _, rg := range rgs.Groups {
|
||||
|
@ -547,7 +547,8 @@ func (m *Manager) loadGroups(interval time.Duration, filenames ...string) (map[s
|
|||
))
|
||||
}
|
||||
|
||||
groups[rg.Name] = NewGroup(rg.Name, itv, rules, m.opts)
|
||||
// Groups need not be unique across filenames.
|
||||
groups[rg.Name+";"+fn] = NewGroup(rg.Name, itv, rules, m.opts)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue