Merge pull request #5182 from flisky/master
Graphite: prefer more specific template over default template when possiblepull/5387/merge
commit
4002733695
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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: "_",
|
||||
|
|
Loading…
Reference in New Issue