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

[exporter/datadog] Add empty removedSettings list #9090

Merged
merged 1 commit into from
Apr 13, 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
4 changes: 4 additions & 0 deletions exporter/datadogexporter/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,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 All @@ -55,6 +55,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 @@ -66,6 +69,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 @@ -95,3 +111,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
}