From be85d8a71e0c4ab0dadc37da30b474ad792913ec Mon Sep 17 00:00:00 2001 From: Ravi Kumar Date: Tue, 23 Jul 2019 19:02:26 +0900 Subject: [PATCH] Allow quoted keys in yaml config Fix grok_exporter failure to start when the keys in the yaml config file are quoted. --- config/config.go | 2 +- config/config_test.go | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/config/config.go b/config/config.go index 9ab9b2b3..148a5cf2 100644 --- a/config/config.go +++ b/config/config.go @@ -48,7 +48,7 @@ func LoadConfigString(content []byte) (*v2.Config, string, error) { } func findVersion(content string) (int, string, error) { - versionExpr := regexp.MustCompile(`global:\s*config_version:[\t\f ]*(\S+)`) + versionExpr := regexp.MustCompile(`"?global"?:\s*"?config_version"?:[\t\f ]*(\S+)`) versionInfo := versionExpr.FindStringSubmatch(content) if len(versionInfo) == 2 { version, err := strconv.Atoi(strings.TrimSpace(versionInfo[1])) diff --git a/config/config_test.go b/config/config_test.go index 3cc7c1aa..21fea237 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -42,6 +42,8 @@ func TestVersionDetection(t *testing.T) { expectVersion(t, exampleConfig, 2, false) expectVersion(t, strings.Replace(exampleConfig, "config_version: 2", "config_version: 1", 1), 1, false) expectVersion(t, strings.Replace(exampleConfig, "config_version: 2", "config_version:", 1), 1, true) + expectVersion(t, strings.Replace(exampleConfig, "config_version: 2", "\"config_version\": 2", 1), 2, false) + expectVersion(t, strings.Replace(exampleConfig, "global", "\"global\"", 1), 2, false) expectVersion(t, strings.Replace(exampleConfig, "config_version: 2", "", 1), 1, true) _, _, err := findVersion(strings.Replace(exampleConfig, "config_version: 2", "config_version: a", 1)) if err == nil {