Skip to content

Commit

Permalink
fix: proper error when parsing telemetry configuration (#12981)
Browse files Browse the repository at this point in the history
When parsing `telemetry.global-labels` config the code assumes that the type will be an array.  I saw an issue where someone edited the configuration in the wrong way and got the following error:
![photo_2022-08-21_08-02-21](https://user-images.githubusercontent.com/22855163/185793842-c5759a54-1860-4dd1-bdb4-b94f4dab3c16.jpg)
Instead, I suggest here to print a proper error log to indicate what the issue is.

(cherry picked from commit c24c439)

# Conflicts:
#	server/start.go
  • Loading branch information
liorbond authored and mergify[bot] committed Aug 23, 2022
1 parent 03b8d0b commit ed19ee0
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 5 deletions.
17 changes: 12 additions & 5 deletions server/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,11 +249,18 @@ func DefaultConfig() *Config {
}

// GetConfig returns a fully parsed Config object.
func GetConfig(v *viper.Viper) Config {
globalLabelsRaw := v.Get("telemetry.global-labels").([]interface{})
func GetConfig(v *viper.Viper) (Config, error) {
globalLabelsRaw, ok := v.Get("telemetry.global-labels").([]interface{})
if !ok {
return Config{}, fmt.Errorf("failed to parse global-labels config")
}

globalLabels := make([][]string, 0, len(globalLabelsRaw))
for _, glr := range globalLabelsRaw {
labelsRaw := glr.([]interface{})
for idx, glr := range globalLabelsRaw {
labelsRaw, ok := glr.([]interface{})
if !ok {
return Config{}, fmt.Errorf("failed to parse global label number %d from config", idx)
}
if len(labelsRaw) == 2 {
globalLabels = append(globalLabels, []string{labelsRaw[0].(string), labelsRaw[1].(string)})
}
Expand Down Expand Up @@ -313,7 +320,7 @@ func GetConfig(v *viper.Viper) Config {
SnapshotInterval: v.GetUint64("state-sync.snapshot-interval"),
SnapshotKeepRecent: v.GetUint32("state-sync.snapshot-keep-recent"),
},
}
}, nil
}

// ValidateBasic returns an error if min-gas-prices field is empty in BaseConfig. Otherwise, it returns nil.
Expand Down
21 changes: 21 additions & 0 deletions server/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,19 @@ func startStandAlone(ctx *Context, appCreator types.AppCreator) error {
}

app := appCreator(ctx.Logger, db, traceWriter, ctx.Viper)
<<<<<<< HEAD
=======

config, err := serverconfig.GetConfig(ctx.Viper)
if err != nil {
return err
}

_, err = startTelemetry(config)
if err != nil {
return err
}
>>>>>>> c24c43972 (fix: proper error when parsing telemetry configuration (#12981))

svr, err := server.NewServer(addr, transport, app)
if err != nil {
Expand Down Expand Up @@ -242,7 +255,15 @@ func startInProcess(ctx *Context, clientCtx client.Context, appCreator types.App
return err
}

<<<<<<< HEAD
config := config.GetConfig(ctx.Viper)
=======
config, err := serverconfig.GetConfig(ctx.Viper)
if err != nil {
return err
}

>>>>>>> c24c43972 (fix: proper error when parsing telemetry configuration (#12981))
if err := config.ValidateBasic(); err != nil {
ctx.Logger.Error("WARNING: The minimum-gas-prices config in app.toml is set to the empty string. " +
"This defaults to 0 in the current version, but will error in the next version " +
Expand Down

0 comments on commit ed19ee0

Please sign in to comment.