Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: proper error when parsing telemetry configuration (backport #12981) #12998

Merged
merged 2 commits into from
Aug 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
* [#12969](https://github.com/cosmos/cosmos-sdk/pull/12969) Bump Tendermint to `v0.34.21` and IAVL to `v0.19.1`.
* [#12886](https://github.com/cosmos/cosmos-sdk/pull/12886) Amortize cost of processing cache KV store.
* (events) [#12850](https://github.com/cosmos/cosmos-sdk/pull/12850) Add a new `fee_payer` attribute to the `tx` event that is emitted from the `DeductFeeDecorator` AnteHandler decorator.
Expand Down
17 changes: 12 additions & 5 deletions server/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,11 +287,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 @@ -356,7 +363,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
14 changes: 12 additions & 2 deletions server/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,13 @@ func startStandAlone(ctx *Context, appCreator types.AppCreator) error {
}

app := appCreator(ctx.Logger, db, traceWriter, ctx.Viper)
_, err = startTelemetry(serverconfig.GetConfig(ctx.Viper))

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

_, err = startTelemetry(config)
if err != nil {
return err
}
Expand Down Expand Up @@ -272,7 +278,11 @@ func startInProcess(ctx *Context, clientCtx client.Context, appCreator types.App
return err
}

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

if err := config.ValidateBasic(); err != nil {
return err
}
Expand Down