Skip to content

Commit

Permalink
Move supportedLevels out of Validate method
Browse files Browse the repository at this point in the history
  • Loading branch information
mx-psi committed Oct 24, 2022
1 parent 7174071 commit 3ef6fc7
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions exporter/loggingexporter/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@ import (
"go.opentelemetry.io/collector/confmap"
)

var (
// supportedLevels in this exporter's configuration.
// configtelemetry.LevelNone and other future values are not supported.
supportedLevels map[configtelemetry.Level]struct{} = map[configtelemetry.Level]struct{}{
configtelemetry.LevelBasic: {},
configtelemetry.LevelNormal: {},
configtelemetry.LevelDetailed: {},
}
)

// Config defines configuration for logging exporter.
type Config struct {
config.ExporterSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct
Expand Down Expand Up @@ -89,14 +99,6 @@ func (cfg *Config) Unmarshal(conf *confmap.Conf) error {

// Validate checks if the exporter configuration is valid
func (cfg *Config) Validate() error {
// Supported configtelemetry.Level values for this exporter.
// configtelemetry.LevelNone and future values are not supported.
supportedLevels := map[configtelemetry.Level]struct{}{
configtelemetry.LevelBasic: {},
configtelemetry.LevelNormal: {},
configtelemetry.LevelDetailed: {},
}

if _, ok := supportedLevels[cfg.Verbosity]; !ok {
return fmt.Errorf("verbosity level %q is not supported", cfg.Verbosity)
}
Expand Down

0 comments on commit 3ef6fc7

Please sign in to comment.