Skip to content

Commit

Permalink
fix(backend): workaround viper map key parsing
Browse files Browse the repository at this point in the history
This is a workaround until this issue is fixed upstream.

Fixes #507
  • Loading branch information
prymitive committed Mar 13, 2019
1 parent 743a4a1 commit 2c8b89b
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package config
import (
"bufio"
"bytes"
"io/ioutil"
"os"
"strings"
"time"
Expand Down Expand Up @@ -184,6 +185,28 @@ func (config *configSchema) Read() {
log.Fatalf("Invalid grid.sorting.order value '%s', allowed options: disabled, startsAt, label", config.Grid.Sorting.Order)
}

// FIXME workaround for https://github.com/prymitive/karma/issues/507
// until https://github.com/spf13/viper/pull/635 is merged
// read in raw config file if it's used and override maps where keys are label
// names so we can't enforce parsed config key names
if v.ConfigFileUsed() != "" {
raw := configSchema{}

var rawConfigFile []byte
rawConfigFile, err = ioutil.ReadFile(v.ConfigFileUsed())
if err != nil {
log.Fatal(err)
}

err = yaml.Unmarshal(rawConfigFile, &raw)
if err != nil {
log.Fatal(err)
}

config.Labels.Color.Custom = raw.Labels.Color.Custom
config.Grid.Sorting.CustomValues.Labels = raw.Grid.Sorting.CustomValues.Labels
}

// accept single Alertmanager server from flag/env if nothing is set yet
if len(config.Alertmanager.Servers) == 0 && v.GetString("alertmanager.uri") != "" {
log.Info("Using simple config with a single Alertmanager server")
Expand Down

0 comments on commit 2c8b89b

Please sign in to comment.