Skip to content

Commit

Permalink
[exporter/datadog] Add empty removedSettings list (#9090)
Browse files Browse the repository at this point in the history
  • Loading branch information
mx-psi authored Apr 13, 2022
1 parent 90c1af7 commit 6cb401f
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
4 changes: 4 additions & 0 deletions exporter/datadogexporter/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,10 @@ func (c *Config) Validate() error {
}

func (c *Config) Unmarshal(configMap *config.Map) error {
if err := handleRemovedSettings(configMap); err != nil {
return err
}

err := configMap.UnmarshalExact(c)
if err != nil {
return err
Expand Down
25 changes: 24 additions & 1 deletion exporter/datadogexporter/config/warning_deprecated.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ type renameError struct {
issueNumber uint
}

// List of settings that are deprecated.
// List of settings that are deprecated but not yet removed.
var renamedSettings = []renameError{
{
oldName: "metrics::send_monotonic_counter",
Expand Down Expand Up @@ -86,6 +86,9 @@ var renamedSettings = []renameError{
},
}

// List of settings that have been removed, but for which we keep a custom error.
var removedSettings = []renameError{}

// Error implements the error interface.
func (e renameError) Error() string {
return fmt.Sprintf(
Expand All @@ -97,6 +100,19 @@ func (e renameError) Error() string {
)
}

// RemovedErr returns an error describing that the old name was removed in favor of the new name.
func (e renameError) RemovedErr(configMap *config.Map) error {
if configMap.IsSet(e.oldName) {
return fmt.Errorf(
"%q was removed in favor of %q. See github.com/open-telemetry/opentelemetry-collector-contrib/issues/%d",
e.oldName,
e.newName,
e.issueNumber,
)
}
return nil
}

// Check if the deprecated option is being used.
// Error out if both the old and new options are being used.
func (e renameError) Check(configMap *config.Map) (bool, error) {
Expand Down Expand Up @@ -126,3 +142,10 @@ func handleRenamedSettings(configMap *config.Map, cfg *Config) (warnings []error
}
return
}

func handleRemovedSettings(configMap *config.Map) (err error) {
for _, removed := range removedSettings {
err = multierr.Append(err, removed.RemovedErr(configMap))
}
return
}

0 comments on commit 6cb401f

Please sign in to comment.