From e96f7a9b1240e3eee9ccebf5f3e8b1844ac52f3a Mon Sep 17 00:00:00 2001 From: Cameron Sparr Date: Mon, 10 Oct 2016 15:35:15 +0100 Subject: [PATCH] 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 --- CHANGELOG.md | 1 + docs/DATA_FORMATS_INPUT.md | 10 +++ plugins/parsers/graphite/parser.go | 81 +++++++++++++++++++------ plugins/parsers/graphite/parser_test.go | 42 +++++++++++++ 4 files changed, 114 insertions(+), 20 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8a054d392..b65c68c3b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -58,6 +58,7 @@ continue sending logs to /var/log/telegraf/telegraf.log. - [#1854](https://github.com/influxdata/telegraf/pull/1853): SQL Server waitstats truncation bug. - [#1810](https://github.com/influxdata/telegraf/issues/1810): Fix logparser common log format: numbers in ident. - [#1793](https://github.com/influxdata/telegraf/pull/1793): Fix JSON Serialization in OpenTSDB output. +- [#1731](https://github.com/influxdata/telegraf/issues/1731): Fix Graphite template ordering, use most specific. ## v1.0.1 [2016-09-26] diff --git a/docs/DATA_FORMATS_INPUT.md b/docs/DATA_FORMATS_INPUT.md index 2e3a479ac..c14752d9c 100644 --- a/docs/DATA_FORMATS_INPUT.md +++ b/docs/DATA_FORMATS_INPUT.md @@ -232,6 +232,16 @@ us.west.cpu.load 100 => cpu.load,region=us.west value=100 ``` +Multiple templates can also be specified, but these should be differentiated +using _filters_ (see below for more details) + +```toml +templates = [ + "*.*.* region.region.measurement", # <- all 3-part measurements will match this one. + "*.*.*.* region.region.host.measurement", # <- all 4-part measurements will match this one. +] +``` + #### Field Templates: The field keyword tells Telegraf to give the metric that field name. diff --git a/plugins/parsers/graphite/parser.go b/plugins/parsers/graphite/parser.go index d371274df..4a3c21df9 100644 --- a/plugins/parsers/graphite/parser.go +++ b/plugins/parsers/graphite/parser.go @@ -57,38 +57,34 @@ func NewGraphiteParser( defaultTemplate, _ := NewTemplate("measurement*", nil, p.Separator) matcher.AddDefaultTemplate(defaultTemplate) + tmplts := parsedTemplates{} for _, pattern := range p.Templates { - template := pattern - filter := "" + tmplt := parsedTemplate{} + tmplt.template = pattern // Format is [filter]