From 4e9798d0e6d8361fd5755c1ecc43b0b048b2c105 Mon Sep 17 00:00:00 2001 From: Cameron Sparr Date: Fri, 29 Apr 2016 16:12:15 -0600 Subject: [PATCH] agent and tags configs sometimes not applied closes #1090 --- CHANGELOG.md | 1 + internal/config/config.go | 38 ++++++++++++++++++++++++++++---------- 2 files changed, 29 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index deca82235..ad2207a43 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -87,6 +87,7 @@ based on _prefix_ in addition to globs. This means that a filter like - [#1118](https://github.com/influxdata/telegraf/pull/1118): Sanitize Counter names for `win_perf_counters` input. - [#1125](https://github.com/influxdata/telegraf/pull/1125): Wrap all exec command runners with a timeout, so hung os processes don't halt Telegraf. - [#1113](https://github.com/influxdata/telegraf/pull/1113): Set MaxRetry and RequiredAcks defaults in Kafka output. +- [#1090](https://github.com/influxdata/telegraf/issues/1090): [agent] and [global_tags] config sometimes not getting applied. ## v0.12.1 [2016-04-14] diff --git a/internal/config/config.go b/internal/config/config.go index d580796fa..daaaa10fc 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -446,6 +446,33 @@ func (c *Config) LoadConfig(path string) error { return fmt.Errorf("Error parsing %s, %s", path, err) } + // Parse tags tables first: + for _, tableName := range []string{"tags", "global_tags"} { + if val, ok := tbl.Fields[tableName]; ok { + subTable, ok := val.(*ast.Table) + if !ok { + return fmt.Errorf("%s: invalid configuration", path) + } + if err = config.UnmarshalTable(subTable, c.Tags); err != nil { + log.Printf("Could not parse [global_tags] config\n") + return fmt.Errorf("Error parsing %s, %s", path, err) + } + } + } + + // Parse agent table: + if val, ok := tbl.Fields["agent"]; ok { + subTable, ok := val.(*ast.Table) + if !ok { + return fmt.Errorf("%s: invalid configuration", path) + } + if err = config.UnmarshalTable(subTable, c.Agent); err != nil { + log.Printf("Could not parse [agent] config\n") + return fmt.Errorf("Error parsing %s, %s", path, err) + } + } + + // Parse all the rest of the plugins: for name, val := range tbl.Fields { subTable, ok := val.(*ast.Table) if !ok { @@ -453,16 +480,7 @@ func (c *Config) LoadConfig(path string) error { } switch name { - case "agent": - if err = config.UnmarshalTable(subTable, c.Agent); err != nil { - log.Printf("Could not parse [agent] config\n") - return fmt.Errorf("Error parsing %s, %s", path, err) - } - case "global_tags", "tags": - if err = config.UnmarshalTable(subTable, c.Tags); err != nil { - log.Printf("Could not parse [global_tags] config\n") - return fmt.Errorf("Error parsing %s, %s", path, err) - } + case "agent", "global_tags", "tags": case "outputs": for pluginName, pluginVal := range subTable.Fields { switch pluginSubTable := pluginVal.(type) {