From 89aa7507696f25ce1fbdc5e23eb936ea831fb0bf Mon Sep 17 00:00:00 2001 From: Robert Fratto Date: Wed, 13 Nov 2019 11:58:09 -0500 Subject: [PATCH] pkg/loki: unmarshal module name from YAML The module name field in the config could not be unmarshalled from a string, causing parsing the config to crash. This commit also changes the error message when the config could not be parsed to print directly to stderr, as the logger won't be initialized at the point where parsing the config fails, leading to no output in the console. Fixes #1259. --- cmd/loki/main.go | 2 +- pkg/loki/modules.go | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/cmd/loki/main.go b/cmd/loki/main.go index abea6d2751af5..73368fb43942e 100644 --- a/cmd/loki/main.go +++ b/cmd/loki/main.go @@ -27,7 +27,7 @@ func main() { var config loki.Config if err := cfg.Parse(&config); err != nil { - level.Error(util.Logger).Log("msg", "parsing config", "error", err) + fmt.Fprintf(os.Stderr, "failed parsing config: %v\n", err) os.Exit(1) } if *printVersion { diff --git a/pkg/loki/modules.go b/pkg/loki/modules.go index 8b059fccee35d..cee38c635a49f 100644 --- a/pkg/loki/modules.go +++ b/pkg/loki/modules.go @@ -42,6 +42,15 @@ const ( All ) +func (m *moduleName) UnmarshalYAML(unmarshal func(interface{}) error) error { + var val string + if err := unmarshal(&val); err != nil { + return err + } + + return m.Set(val) +} + func (m moduleName) String() string { switch m { case Ring: