graphite parser, handle multiple templates empty filter
Previously, the graphite parser would simply overwrite any template that had an identical filter to a previous template. This included the empty filter. Now we will still overwrite, but first we will sort to make sure that the most "specific" template always matches. closes #1731
This commit is contained in:
@@ -747,6 +747,48 @@ func TestApplyTemplateGreedyField(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestApplyTemplateOverSpecific(t *testing.T) {
|
||||
p, err := NewGraphiteParser(
|
||||
".",
|
||||
[]string{
|
||||
"measurement.host.metric.metric.metric",
|
||||
},
|
||||
nil,
|
||||
)
|
||||
assert.NoError(t, err)
|
||||
|
||||
measurement, tags, _, err := p.ApplyTemplate("net.server001.a.b 2")
|
||||
assert.Equal(t, "net", measurement)
|
||||
assert.Equal(t,
|
||||
map[string]string{"host": "server001", "metric": "a.b"},
|
||||
tags)
|
||||
}
|
||||
|
||||
func TestApplyTemplateMostSpecificTemplate(t *testing.T) {
|
||||
p, err := NewGraphiteParser(
|
||||
".",
|
||||
[]string{
|
||||
"measurement.host.metric",
|
||||
"measurement.host.metric.metric.metric",
|
||||
"measurement.host.metric.metric",
|
||||
},
|
||||
nil,
|
||||
)
|
||||
assert.NoError(t, err)
|
||||
|
||||
measurement, tags, _, err := p.ApplyTemplate("net.server001.a.b.c 2")
|
||||
assert.Equal(t, "net", measurement)
|
||||
assert.Equal(t,
|
||||
map[string]string{"host": "server001", "metric": "a.b.c"},
|
||||
tags)
|
||||
|
||||
measurement, tags, _, err = p.ApplyTemplate("net.server001.a.b 2")
|
||||
assert.Equal(t, "net", measurement)
|
||||
assert.Equal(t,
|
||||
map[string]string{"host": "server001", "metric": "a.b"},
|
||||
tags)
|
||||
}
|
||||
|
||||
// Test Helpers
|
||||
func errstr(err error) string {
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user