Skip to content

Commit

Permalink
pkg/loki: unmarshal module name from YAML (grafana#1260)
Browse files Browse the repository at this point in the history
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 grafana#1259.
  • Loading branch information
rfratto authored Nov 13, 2019
1 parent 1d3b0be commit a1901e2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion cmd/loki/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
9 changes: 9 additions & 0 deletions pkg/loki/modules.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit a1901e2

Please sign in to comment.