Merge pull request #5182 from flisky/master

Graphite: prefer more specific template over default template when possible
pull/5387/merge
Jason Wilder 2016-02-08 12:08:43 -07:00
commit 4002733695
2 changed files with 26 additions and 0 deletions

View File

@ -313,6 +313,11 @@ func (n *node) insert(values []string, template *template) {
n.children = append(n.children, newNode)
sort.Sort(&n.children)
// Inherit template if value is wildcard
if values[0] == "*" {
newNode.template = n.template
}
// Now insert the rest of the tree into the new element
newNode.insert(values[1:], template)
}

View File

@ -602,6 +602,27 @@ func TestApplyTemplateSpecific(t *testing.T) {
}
}
// Test that most specific template is N/A
func TestApplyTemplateSpecificIsNA(t *testing.T) {
o := graphite.Options{
Separator: "_",
Templates: []string{
"current.* measurement.service",
"current.*.*.test measurement.measurement.service",
},
}
p, err := graphite.NewParserWithOptions(o)
if err != nil {
t.Fatalf("unexpected error creating parser, got %v", err)
}
measurement, _, _, _ := p.ApplyTemplate("current.users.facebook")
if measurement != "current" {
t.Errorf("Parser.ApplyTemplate unexpected result. got %s, exp %s",
measurement, "current")
}
}
func TestApplyTemplateTags(t *testing.T) {
o := graphite.Options{
Separator: "_",