-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[exporter/datadog] Add
metrics::sums::cumulative_monotonic_mode
set…
…ting; deprecate `metrics::send_monotonic_counter` (#8490) * [exporter/datadog] Add `metrics::sums::cumulative_monotonic_mode` setting; deprecate `metrics::send_monotonic_counter` * Add CHANGELOG entries for this change * [exporter/datadog] Update documentation * [exporter/datadog] Add unit tests for renaming error * Fix formatting * [exporter/datadog] Minor copyedit on error message * [exporter/datadog] Fix comment * Address review comments
- Loading branch information
Showing
11 changed files
with
315 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package config // import "github.com/open-telemetry/opentelemetry-collector-contrib/exporter/datadogexporter/config" | ||
|
||
import ( | ||
"fmt" | ||
|
||
"go.opentelemetry.io/collector/config" | ||
"go.uber.org/multierr" | ||
) | ||
|
||
var _ error = (*renameError)(nil) | ||
|
||
// renameError is an error related to a renamed setting. | ||
type renameError struct { | ||
// oldName of the configuration option. | ||
oldName string | ||
// newName of the configuration option. | ||
newName string | ||
// oldRemovedIn is the version where the old config option will be removed. | ||
oldRemovedIn string | ||
// updateFn updates the configuration to map the old value into the new one. | ||
// It must only be called when the old value is set and is not the default. | ||
updateFn func(*Config) | ||
// issueNumber on opentelemetry-collector-contrib for tracking | ||
issueNumber uint | ||
} | ||
|
||
// List of settings that are deprecated. | ||
var renamedSettings = []renameError{ | ||
{ | ||
oldName: "metrics::send_monotonic_counter", | ||
newName: "metrics::sums::cumulative_monotonic_mode", | ||
oldRemovedIn: "v0.50.0", | ||
issueNumber: 8489, | ||
updateFn: func(c *Config) { | ||
if c.Metrics.SendMonotonic { | ||
c.Metrics.SumConfig.CumulativeMonotonicMode = CumulativeMonotonicSumModeToDelta | ||
} else { | ||
c.Metrics.SumConfig.CumulativeMonotonicMode = CumulativeMonotonicSumModeRawValue | ||
} | ||
}, | ||
}, | ||
} | ||
|
||
// Error implements the error interface. | ||
func (e renameError) Error() string { | ||
return fmt.Sprintf( | ||
"%q has been deprecated in favor of %q and will be removed in %s. See github.com/open-telemetry/opentelemetry-collector-contrib/issues/%d", | ||
e.oldName, | ||
e.newName, | ||
e.oldRemovedIn, | ||
e.issueNumber, | ||
) | ||
} | ||
|
||
// 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) { | ||
if configMap.IsSet(e.oldName) && configMap.IsSet(e.newName) { | ||
return false, fmt.Errorf("%q and %q can't be both set at the same time: use %q only instead", e.oldName, e.newName, e.newName) | ||
} | ||
return configMap.IsSet(e.oldName), nil | ||
} | ||
|
||
// UpdateCfg to move the old configuration value into the new one. | ||
func (e renameError) UpdateCfg(cfg *Config) { | ||
e.updateFn(cfg) | ||
} | ||
|
||
// handleRenamedSettings for a given configuration map. | ||
// Error out if any pair of old-new options are set at the same time. | ||
func handleRenamedSettings(configMap *config.Map, cfg *Config) (warnings []error, err error) { | ||
for _, renaming := range renamedSettings { | ||
isOldNameUsed, errCheck := renaming.Check(configMap) | ||
err = multierr.Append(err, errCheck) | ||
|
||
if errCheck == nil && isOldNameUsed { | ||
warnings = append(warnings, renaming) | ||
// only update config if old name is in use | ||
renaming.UpdateCfg(cfg) | ||
} | ||
} | ||
return | ||
} |
103 changes: 103 additions & 0 deletions
103
exporter/datadogexporter/config/warning_deprecated_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package config // import "github.com/open-telemetry/opentelemetry-collector-contrib/exporter/datadogexporter/config" | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"go.opentelemetry.io/collector/config" | ||
) | ||
|
||
func TestDeprecationSendMonotonic(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
cfgMap *config.Map | ||
expectedMode CumulativeMonotonicSumMode | ||
warnings []string | ||
err string | ||
}{ | ||
{ | ||
name: "both metrics::send_monotonic and new metrics::sums::cumulative_monotonic_mode", | ||
cfgMap: config.NewMapFromStringMap(map[string]interface{}{ | ||
"metrics": map[string]interface{}{ | ||
"send_monotonic_counter": true, | ||
"sums": map[string]interface{}{ | ||
"cumulative_monotonic_mode": "to_delta", | ||
}, | ||
}, | ||
}), | ||
err: "\"metrics::send_monotonic_counter\" and \"metrics::sums::cumulative_monotonic_mode\" can't be both set at the same time: use \"metrics::sums::cumulative_monotonic_mode\" only instead", | ||
}, | ||
{ | ||
name: "metrics::send_monotonic set to true", | ||
cfgMap: config.NewMapFromStringMap(map[string]interface{}{ | ||
"metrics": map[string]interface{}{ | ||
"send_monotonic_counter": true, | ||
}, | ||
}), | ||
expectedMode: CumulativeMonotonicSumModeToDelta, | ||
warnings: []string{ | ||
"\"metrics::send_monotonic_counter\" has been deprecated in favor of \"metrics::sums::cumulative_monotonic_mode\" and will be removed in v0.50.0. See github.com/open-telemetry/opentelemetry-collector-contrib/issues/8489", | ||
}, | ||
}, | ||
{ | ||
name: "metrics::send_monotonic set to false", | ||
cfgMap: config.NewMapFromStringMap(map[string]interface{}{ | ||
"metrics": map[string]interface{}{ | ||
"send_monotonic_counter": false, | ||
}, | ||
}), | ||
expectedMode: CumulativeMonotonicSumModeRawValue, | ||
warnings: []string{ | ||
"\"metrics::send_monotonic_counter\" has been deprecated in favor of \"metrics::sums::cumulative_monotonic_mode\" and will be removed in v0.50.0. See github.com/open-telemetry/opentelemetry-collector-contrib/issues/8489", | ||
}, | ||
}, | ||
{ | ||
name: "metrics::send_monotonic and metrics::sums::cumulative_monotonic_mode unset", | ||
cfgMap: config.NewMapFromStringMap(map[string]interface{}{}), | ||
expectedMode: CumulativeMonotonicSumModeToDelta, | ||
}, | ||
{ | ||
name: "metrics::sums::cumulative_monotonic_mode set", | ||
cfgMap: config.NewMapFromStringMap(map[string]interface{}{ | ||
"metrics": map[string]interface{}{ | ||
"sums": map[string]interface{}{ | ||
"cumulative_monotonic_mode": "raw_value", | ||
}, | ||
}, | ||
}), | ||
expectedMode: CumulativeMonotonicSumModeRawValue, | ||
}, | ||
} | ||
|
||
for _, testInstance := range tests { | ||
t.Run(testInstance.name, func(t *testing.T) { | ||
cfg := futureDefaultConfig() | ||
err := cfg.Unmarshal(testInstance.cfgMap) | ||
if err != nil || testInstance.err != "" { | ||
assert.EqualError(t, err, testInstance.err) | ||
} else { | ||
assert.Equal(t, testInstance.expectedMode, cfg.Metrics.SumConfig.CumulativeMonotonicMode) | ||
var warningStr []string | ||
for _, warning := range cfg.warnings { | ||
warningStr = append(warningStr, warning.Error()) | ||
} | ||
assert.ElementsMatch(t, testInstance.warnings, warningStr) | ||
} | ||
}) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.