Skip to content

Commit

Permalink
common/flags: Fix parsing of metrics.labels, if provided in config .yml
Browse files Browse the repository at this point in the history
  • Loading branch information
matevz committed May 12, 2020
1 parent cdcc044 commit dcd76c4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
1 change: 1 addition & 0 deletions .changelog/2905.bugfix.md
@@ -0,0 +1 @@
common/flags: Fix parsing of metrics.labels, if provided in config .yml
16 changes: 10 additions & 6 deletions go/oasis-node/cmd/common/flags/flags.go
Expand Up @@ -94,15 +94,19 @@ func DryRun() bool {

// GetStringMapString is a drop-in replacement for viper.GetStringMapString due to https://github.com/spf13/viper/issues/608.
func GetStringMapString(key string) map[string]string {
labels := map[string]string{}
val := viper.GetString(key)

// viper.GetString() wraps the string inside [] parenthesis, unwrap it.
if len(val) < 2 {
// Use original GetStringMapString, if it works (e.g. for yaml-based configs).
labels := viper.GetStringMapString(key)
if len(labels) != 0 {
return labels
}
val = val[1 : len(val)-1]

// Otherwise, take string and parse it manually.
val := viper.GetString(key)
// viper.GetString() wraps the string inside [] parenthesis, unwrap it.
if len(val) >= 2 && val[0] == '[' && val[len(val)-1] == ']' {
val = val[1 : len(val)-1]
}
// Assume format key1=value1,key2=value2,...
for _, lPair := range strings.Split(val, ",") {
kv := strings.Split(lPair, "=")
if len(kv) != 2 || kv[0] == "" {
Expand Down

0 comments on commit dcd76c4

Please sign in to comment.