From ed19ee03ae4833f4c618c914486818acf7c8ba9f Mon Sep 17 00:00:00 2001 From: liorbond Date: Tue, 23 Aug 2022 03:20:57 +0300 Subject: [PATCH 1/2] fix: proper error when parsing telemetry configuration (#12981) 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 c24c439728ac9fd8917d6a30e25d0b08a11bcc8b) # Conflicts: # server/start.go --- server/config/config.go | 17 ++++++++++++----- server/start.go | 21 +++++++++++++++++++++ 2 files changed, 33 insertions(+), 5 deletions(-) diff --git a/server/config/config.go b/server/config/config.go index f17e70f11832..56751552ea85 100644 --- a/server/config/config.go +++ b/server/config/config.go @@ -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)}) } @@ -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. diff --git a/server/start.go b/server/start.go index ff5922e07051..ec5d72a51f91 100644 --- a/server/start.go +++ b/server/start.go @@ -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 { @@ -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 " + From b47665fd57efb9c8d0d119f7940edb780faa4330 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Tue, 23 Aug 2022 12:49:26 +0200 Subject: [PATCH 2/2] updates --- CHANGELOG.md | 1 + server/start.go | 19 +------------------ 2 files changed, 2 insertions(+), 18 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f514f8896d6b..46dabfd75cc9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -39,6 +39,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### Improvements +* [#12981](https://github.com/cosmos/cosmos-sdk/pull/12981) Return proper error when parsing telemetry configuration. * [#12886](https://github.com/cosmos/cosmos-sdk/pull/12886) Amortize cost of processing cache KV store. * [#12970](https://github.com/cosmos/cosmos-sdk/pull/12970) Bump Tendermint to `v0.34.21` and IAVL to `v0.19.1`. * [#12693](https://github.com/cosmos/cosmos-sdk/pull/12693) Make sure the order of each node is consistent when emitting proto events. diff --git a/server/start.go b/server/start.go index ec5d72a51f91..a20f73f32978 100644 --- a/server/start.go +++ b/server/start.go @@ -185,19 +185,6 @@ 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 { @@ -255,15 +242,11 @@ func startInProcess(ctx *Context, clientCtx client.Context, appCreator types.App return err } -<<<<<<< HEAD - config := config.GetConfig(ctx.Viper) -======= - config, err := serverconfig.GetConfig(ctx.Viper) + config, err := config.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 " +