Add file name to group.

Signed-off-by: Goutham Veeramachaneni <cs14btech11014@iith.ac.in>
This commit is contained in:
Goutham Veeramachaneni 2017-06-14 15:18:39 +05:30
parent e893c89333
commit 8cca666cf2
No known key found for this signature in database
GPG key ID: F1C217E8E9023CAD
2 changed files with 9 additions and 5 deletions

View file

@ -128,6 +128,7 @@ type Rule interface {
// Group is a set of rules that have a logical relation. // Group is a set of rules that have a logical relation.
type Group struct { type Group struct {
name string name string
file string
interval time.Duration interval time.Duration
rules []Rule rules []Rule
seriesInPreviousEval []map[string]labels.Labels // One per Rule. seriesInPreviousEval []map[string]labels.Labels // One per Rule.
@ -138,7 +139,7 @@ type Group struct {
} }
// NewGroup makes a new Group with the given name, options, and rules. // NewGroup makes a new Group with the given name, options, and rules.
func NewGroup(name string, interval time.Duration, rules []Rule, opts *ManagerOptions) *Group { func NewGroup(name, file string, interval time.Duration, rules []Rule, opts *ManagerOptions) *Group {
return &Group{ return &Group{
name: name, name: name,
interval: interval, interval: interval,
@ -201,7 +202,10 @@ func (g *Group) stop() {
} }
func (g *Group) fingerprint() model.Fingerprint { func (g *Group) fingerprint() model.Fingerprint {
l := model.LabelSet{"name": model.LabelValue(g.name)} l := model.LabelSet{
"name": model.LabelValue(g.name),
"filename": model.LabelValue(g.file),
}
return l.Fingerprint() return l.Fingerprint()
} }
@ -545,8 +549,8 @@ func (m *Manager) loadGroups(interval time.Duration, filenames ...string) (map[s
)) ))
} }
// Groups need not be unique across filenames. // Group names need not be unique across filenames.
groups[rg.Name+";"+fn] = NewGroup(rg.Name, itv, rules, m.opts) groups[rg.Name+";"+fn] = NewGroup(rg.Name, fn, itv, rules, m.opts)
} }
} }

View file

@ -172,7 +172,7 @@ func TestStaleness(t *testing.T) {
t.Fatal(err) t.Fatal(err)
} }
rule := NewRecordingRule("a_plus_one", expr, labels.Labels{}) rule := NewRecordingRule("a_plus_one", expr, labels.Labels{})
group := NewGroup("default", time.Second, []Rule{rule}, opts) group := NewGroup("default", "", time.Second, []Rule{rule}, opts)
// A time series that has two samples and then goes stale. // A time series that has two samples and then goes stale.
app, _ := storage.Appender() app, _ := storage.Appender()