From f4105d2e69fd560ba52344587b3f69473433d23b Mon Sep 17 00:00:00 2001 From: Pablo Baeyens Date: Wed, 6 Jul 2022 12:49:18 +0200 Subject: [PATCH] [exporter/datadog] Remove deprecated configuration features This includes both the environment variable detection as well as the deprecated settings. --- exporter/datadogexporter/config.go | 142 +------------- exporter/datadogexporter/config_test.go | 62 +----- .../datadogexporter/config_warn_envvars.go | 169 ---------------- .../config_warning_deprecated.go | 67 +------ .../config_warning_deprecated_test.go | 110 ----------- exporter/datadogexporter/example/config.yaml | 83 +------- exporter/datadogexporter/factory.go | 56 +----- exporter/datadogexporter/factory_test.go | 184 +++--------------- exporter/datadogexporter/hostmetadata.go | 20 +- exporter/datadogexporter/hostmetadata_test.go | 90 --------- exporter/datadogexporter/metrics_exporter.go | 8 - exporter/datadogexporter/testdata/config.yaml | 23 --- .../datadogexporter/traces_exporter_test.go | 6 - 13 files changed, 48 insertions(+), 972 deletions(-) delete mode 100644 exporter/datadogexporter/config_warn_envvars.go delete mode 100644 exporter/datadogexporter/config_warning_deprecated_test.go delete mode 100644 exporter/datadogexporter/hostmetadata_test.go diff --git a/exporter/datadogexporter/config.go b/exporter/datadogexporter/config.go index 08c4d71354e6..ece6372c63a7 100644 --- a/exporter/datadogexporter/config.go +++ b/exporter/datadogexporter/config.go @@ -18,7 +18,6 @@ import ( "encoding" "errors" "fmt" - "os" "regexp" "strings" @@ -26,10 +25,7 @@ import ( "go.opentelemetry.io/collector/config/confignet" "go.opentelemetry.io/collector/confmap" "go.opentelemetry.io/collector/exporter/exporterhelper" - "go.opentelemetry.io/collector/service/featuregate" - "go.uber.org/zap" - "github.com/open-telemetry/opentelemetry-collector-contrib/exporter/datadogexporter/internal/metadata" "github.com/open-telemetry/opentelemetry-collector-contrib/exporter/datadogexporter/internal/metadata/valid" ) @@ -47,12 +43,9 @@ const ( type APIConfig struct { // Key is the Datadog API key to associate your Agent's data with your organization. // Create a new API key here: https://app.datadoghq.com/account/settings - // - // It can also be set through the `DD_API_KEY` environment variable (Deprecated: [v0.47.0] set environment variable explicitly on configuration instead). Key string `mapstructure:"key"` // Site is the site of the Datadog intake to send data to. - // It can also be set through the `DD_SITE` environment variable (Deprecated: [v0.47.0] set environment variable explicitly on configuration instead). // The default value is "datadoghq.com". Site string `mapstructure:"site"` @@ -63,22 +56,11 @@ type APIConfig struct { // MetricsConfig defines the metrics exporter specific configuration options type MetricsConfig struct { - // Quantiles states whether to report quantiles from summary metrics. - // By default, the minimum, maximum and average are reported. - // Deprecated: [v0.50.0] Use `metrics::summaries::mode` (SummaryConfig.Mode) instead. - Quantiles bool `mapstructure:"report_quantiles"` - - // SendMonotonic states whether to report cumulative monotonic metrics as counters - // or gauges - // Deprecated: [v0.48.0] Use `metrics::sums::cumulative_monotonic_mode` (SumConfig.CumulativeMonotonicMode) instead. - SendMonotonic bool `mapstructure:"send_monotonic_counter"` - // DeltaTTL defines the time that previous points of a cumulative monotonic // metric are kept in memory to calculate deltas DeltaTTL int64 `mapstructure:"delta_ttl"` // TCPAddr.Endpoint is the host of the Datadog intake server to send metrics to. - // It can also be set through the `DD_URL` environment variable (Deprecated: [v0.47.0] set environment variable explicitly on configuration instead).. // If unset, the value is obtained from the Site. confignet.TCPAddr `mapstructure:",squash"` @@ -224,12 +206,6 @@ type MetricsExporterConfig struct { // resource attributes into metric labels, which are then converted into tags ResourceAttributesAsTags bool `mapstructure:"resource_attributes_as_tags"` - // Deprecated: [0.54.0] Use InstrumentationScopeMetadataAsTags instead in favor of https://github.com/open-telemetry/opentelemetry-proto/releases/tag/v0.15.0 - // Both must not be enabled at the same time. - // InstrumentationLibraryMetadataAsTags, if set to true, adds the name and version of the - // instrumentation library that created a metric to the metric tags - InstrumentationLibraryMetadataAsTags bool `mapstructure:"instrumentation_library_metadata_as_tags"` - // InstrumentationScopeMetadataAsTags, if set to true, adds the name and version of the // instrumentation scope that created a metric to the metric tags InstrumentationScopeMetadataAsTags bool `mapstructure:"instrumentation_scope_metadata_as_tags"` @@ -238,16 +214,9 @@ type MetricsExporterConfig struct { // TracesConfig defines the traces exporter specific configuration options type TracesConfig struct { // TCPAddr.Endpoint is the host of the Datadog intake server to send traces to. - // It can also be set through the `DD_APM_URL` environment variable (Deprecated: [v0.47.0] set environment variable explicitly on configuration instead). // If unset, the value is obtained from the Site. confignet.TCPAddr `mapstructure:",squash"` - // SampleRate is the rate at which to sample this event. Default is 1, - // meaning no sampling. If you want to send one event out of every 250 - // times Send() is called, you would specify 250 here. - // Deprecated: [v0.50.0] Not used anywhere. - SampleRate uint `mapstructure:"sample_rate"` - // ignored resources // A blacklist of regular expressions can be provided to disable certain traces based on their resource name // all entries must be surrounded by double quotes and separated by commas. @@ -272,54 +241,8 @@ type TracesConfig struct { // It is embedded in the configuration type TagsConfig struct { // Hostname is the host name for unified service tagging. - // It can also be set through the `DD_HOST` environment variable (Deprecated: [v0.47.0] set environment variable explicitly on configuration instead). // If unset, it is determined automatically. - // See https://docs.datadoghq.com/agent/faq/how-datadog-agent-determines-the-hostname - // for more details. Hostname string `mapstructure:"hostname"` - - // Env is the environment for unified service tagging. - // Deprecated: [v0.49.0] Set `deployment.environment` semconv instead, see https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/9016 for details. - // This option will be removed in v0.52.0. - // It can also be set through the `DD_ENV` environment variable (Deprecated: [v0.47.0] set environment variable explicitly on configuration instead). - Env string `mapstructure:"env"` - - // Service is the service for unified service tagging. - // Deprecated: [v0.49.0] Set `service.name` semconv instead, see https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/8781 for details. - // This option will be removed in v0.52.0. - // It can also be set through the `DD_SERVICE` environment variable (Deprecated: [v0.47.0] set environment variable explicitly on configuration instead). - Service string `mapstructure:"service"` - - // Version is the version for unified service tagging. - // Deprecated: [v0.49.0] Set `service.version` semconv instead, see https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/8783 for details. - // This option will be removed in v0.52.0. - // It can also be set through the `DD_VERSION` environment variable (Deprecated: [v0.47.0] set environment variable explicitly on configuration instead). - Version string `mapstructure:"version"` - - // EnvVarTags is the list of space-separated tags passed by the `DD_TAGS` environment variable - // Superseded by Tags if the latter is set. - // Should not be set in the user-provided config. - // - // Deprecated: [v0.47.0] Use `host_metadata::tags` HostMetadataConfig.Tags instead. - EnvVarTags string `mapstructure:"envvartags"` - - // Tags is the list of default tags to add to every metric or trace. - // Deprecated: [v0.49.0] Use `host_metadata::tags` (HostMetadataConfig.Tags) - Tags []string `mapstructure:"tags"` -} - -// getHostTags gets the host tags extracted from the configuration -func (t *TagsConfig) getHostTags() []string { - tags := t.Tags - - if len(tags) == 0 { - tags = strings.Split(t.EnvVarTags, " ") - } - - if t.Env != "none" { - tags = append(tags, fmt.Sprintf("env:%s", t.Env)) - } - return tags } // HostnameSource is the source for the hostname of host metadata. @@ -414,13 +337,6 @@ type Config struct { // HostMetadata defines the host metadata specific configuration HostMetadata HostMetadataConfig `mapstructure:"host_metadata"` - // SendMetadata defines whether to send host metadata - // This is undocumented and only used for unit testing. - // - // This can't be disabled if `only_metadata` is true. - // Deprecated: [v0.49.0] Use `host_metadata::enabled` (HostMetadata.Enabled) instead. - SendMetadata bool `mapstructure:"send_metadata"` - // OnlyMetadata defines whether to only send metadata // This is useful for agent-collector setups, so that // metadata about a host is sent to the backend even @@ -429,25 +345,6 @@ type Config struct { // This flag is incompatible with disabling host metadata, // `use_resource_metadata`, or `host_metadata::hostname_source != first_resource` OnlyMetadata bool `mapstructure:"only_metadata"` - - // UseResourceMetadata defines whether to use resource attributes - // for completing host metadata (such as the hostname or host tags). - // - // By default this is true: the first resource attribute getting to - // the exporter will be used for host metadata. - // Disable this in the Collector if you are using an agent-collector setup. - // Deprecated: [v0.49.0] Use `host_metadata::hostname_source` (HostMetadata.HostnameSource) instead. - UseResourceMetadata bool `mapstructure:"use_resource_metadata"` - - // warnings stores non-fatal configuration errors. - warnings []error -} - -// logWarnings logs warning messages that were generated on unmarshaling. -func (c *Config) logWarnings(logger *zap.Logger) { - for _, err := range c.warnings { - logger.Warn(fmt.Sprintf("%v", err)) - } } var _ config.Exporter = (*Config)(nil) @@ -510,46 +407,11 @@ func (c *Config) Unmarshal(configMap *confmap.Conf) error { c.API.Key = strings.TrimSpace(c.API.Key) // If an endpoint is not explicitly set, override it based on the site. - // TODO (#8396) Remove DD_URL check. - if !configMap.IsSet("metrics::endpoint") && os.Getenv("DD_URL") == "" { + if !configMap.IsSet("metrics::endpoint") { c.Metrics.TCPAddr.Endpoint = fmt.Sprintf("https://api.%s", c.API.Site) } - // TODO (#8396) Remove DD_APM_URL check. - if !configMap.IsSet("traces::endpoint") && os.Getenv("DD_APM_URL") == "" { + if !configMap.IsSet("traces::endpoint") { c.Traces.TCPAddr.Endpoint = fmt.Sprintf("https://trace.agent.%s", c.API.Site) } - - // Add deprecation warnings for deprecated settings. - renamingWarnings, err := handleRenamedSettings(configMap, c) - if err != nil { - return err - } - c.warnings = append(c.warnings, renamingWarnings...) - - // Add warnings about autodetected environment variables. - c.warnings = append(c.warnings, warnUseOfEnvVars(configMap, c)...) - - deprecationTemplate := "%q has been deprecated and will be removed in %s or later. See https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/%d" - if c.Service != "" { - c.warnings = append(c.warnings, fmt.Errorf(deprecationTemplate, "service", "v0.52.0", 8781)) - } - if c.Version != "" { - c.warnings = append(c.warnings, fmt.Errorf(deprecationTemplate, "version", "v0.52.0", 8783)) - } - if configMap.IsSet("env") { - c.warnings = append(c.warnings, fmt.Errorf(deprecationTemplate, "env", "v0.52.0", 9016)) - } - if c.Traces.SampleRate != 0 { - c.warnings = append(c.warnings, fmt.Errorf(deprecationTemplate, "traces.sample_rate", "v0.52.0", 9771)) - } - - const settingName = "host_metadata::hostname_source" - if !configMap.IsSet(settingName) && !featuregate.GetRegistry().IsEnabled(metadata.HostnamePreviewFeatureGate) { - c.warnings = append(c.warnings, fmt.Errorf( - "%q will change its default value on a future version. Use the %q feature gate to preview this and other hostname changes", - settingName, - metadata.HostnamePreviewFeatureGate, - )) - } return nil } diff --git a/exporter/datadogexporter/config_test.go b/exporter/datadogexporter/config_test.go index cb79e10acbaa..22968b74ebe7 100644 --- a/exporter/datadogexporter/config_test.go +++ b/exporter/datadogexporter/config_test.go @@ -21,63 +21,6 @@ import ( "go.opentelemetry.io/collector/confmap" ) -func TestHostTagsTagsConfig(t *testing.T) { - tc := TagsConfig{ - Hostname: "customhost", - Env: "customenv", - // Service and version should be only used for traces - Service: "customservice", - Version: "customversion", - Tags: []string{"key1:val1", "key2:val2"}, - } - - assert.ElementsMatch(t, - []string{ - "env:customenv", - "key1:val1", - "key2:val2", - }, - tc.getHostTags(), - ) - - tc = TagsConfig{ - Hostname: "customhost", - Env: "customenv", - // Service and version should be only used for traces - Service: "customservice", - Version: "customversion", - Tags: []string{"key1:val1", "key2:val2"}, - EnvVarTags: "key3:val3 key4:val4", - } - - assert.ElementsMatch(t, - []string{ - "env:customenv", - "key1:val1", - "key2:val2", - }, - tc.getHostTags(), - ) - - tc = TagsConfig{ - Hostname: "customhost", - Env: "customenv", - // Service and version should be only used for traces - Service: "customservice", - Version: "customversion", - EnvVarTags: "key3:val3 key4:val4", - } - - assert.ElementsMatch(t, - []string{ - "env:customenv", - "key3:val3", - "key4:val4", - }, - tc.getHostTags(), - ) -} - func TestValidate(t *testing.T) { tests := []struct { @@ -103,7 +46,7 @@ func TestValidate(t *testing.T) { cfg: &Config{ API: APIConfig{Key: "notnull"}, OnlyMetadata: true, - SendMetadata: false, + HostMetadata: HostMetadataConfig{Enabled: false}, }, err: errNoMetadata.Error(), }, @@ -222,9 +165,10 @@ func TestUnmarshal(t *testing.T) { }, } + f := NewFactory() for _, testInstance := range tests { t.Run(testInstance.name, func(t *testing.T) { - cfg := futureDefaultConfig() + cfg := f.CreateDefaultConfig().(*Config) err := cfg.Unmarshal(testInstance.configMap) if err != nil || testInstance.err != "" { assert.EqualError(t, err, testInstance.err) diff --git a/exporter/datadogexporter/config_warn_envvars.go b/exporter/datadogexporter/config_warn_envvars.go deleted file mode 100644 index 02d7be1ed2df..000000000000 --- a/exporter/datadogexporter/config_warn_envvars.go +++ /dev/null @@ -1,169 +0,0 @@ -// 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 datadogexporter // import "github.com/open-telemetry/opentelemetry-collector-contrib/exporter/datadogexporter" - -import ( - "fmt" - "time" - - "go.opentelemetry.io/collector/config" - "go.opentelemetry.io/collector/config/confignet" - "go.opentelemetry.io/collector/confmap" - "go.opentelemetry.io/collector/exporter/exporterhelper" -) - -// futureDefaultConfig returns the future default config we will use from v0.50 onwards. -func futureDefaultConfig() *Config { - return &Config{ - ExporterSettings: config.NewExporterSettings(config.NewComponentID("datadog")), - TimeoutSettings: exporterhelper.TimeoutSettings{ - Timeout: 15 * time.Second, - }, - API: APIConfig{ - Site: "datadoghq.com", - }, - TagsConfig: TagsConfig{ - Env: "none", - }, - RetrySettings: exporterhelper.NewDefaultRetrySettings(), - QueueSettings: exporterhelper.NewDefaultQueueSettings(), - Metrics: MetricsConfig{ - TCPAddr: confignet.TCPAddr{ - Endpoint: "https://api.datadoghq.com", - }, - SendMonotonic: true, - DeltaTTL: 3600, - Quantiles: true, - ExporterConfig: MetricsExporterConfig{ - ResourceAttributesAsTags: false, - InstrumentationLibraryMetadataAsTags: false, - InstrumentationScopeMetadataAsTags: false, - }, - HistConfig: HistogramConfig{ - Mode: "distributions", - SendCountSum: false, - }, - SumConfig: SumConfig{ - CumulativeMonotonicMode: CumulativeMonotonicSumModeToDelta, - }, - SummaryConfig: SummaryConfig{ - Mode: SummaryModeGauges, - }, - }, - Traces: TracesConfig{ - TCPAddr: confignet.TCPAddr{ - Endpoint: "https://trace.agent.datadoghq.com", - }, - IgnoreResources: []string{}, - }, - HostMetadata: HostMetadataConfig{ - Enabled: true, - HostnameSource: HostnameSourceFirstResource, - }, - SendMetadata: true, - UseResourceMetadata: true, - } -} - -// errUsedEnvVar constructs an error instructing users not to rely on -// the automatic environment variable detection and set the environment variable -// explicitly on configuration instead. -func errUsedEnvVar(settingName, envVarName string) error { - return fmt.Errorf( - "%q will not default to %q's value in a future minor version. Set %s: ${%s} to remove this warning", - settingName, - envVarName, - settingName, - envVarName, - ) -} - -// tagsDiffer checks if the host tags from each configuration are different. -func tagsDiffer(cfgTags []string, futureTags []string) bool { - if len(cfgTags) != len(futureTags) { - return true - } - - oldCfgSet := map[string]struct{}{} - for _, tag := range cfgTags { - oldCfgSet[tag] = struct{}{} - } - - for _, tag := range futureTags { - if _, ok := oldCfgSet[tag]; !ok { - // tag is in old but not new - return true - } - } - - return false -} - -// warnUseOfEnvVars returns warnings related to automatic environment variable detection. -// Right now, we automatically get the value for e.g. the API key from DD_API_KEY, even if -// the user is not doing `api.key: ${DD_API_KEY}`. We are going to remove this functionality. -func warnUseOfEnvVars(configMap *confmap.Conf, cfg *Config) (warnings []error) { - // We don't see the raw YAML contents from our exporter so, to compare with the new default, - // we unmarshal the config map on the future default config and compare the two structs. - // Any differences will be due to the change in default configuration. - futureCfg := futureDefaultConfig() - err := configMap.UnmarshalExact(futureCfg) - - errIssue := fmt.Errorf("see github.com/open-telemetry/opentelemetry-collector-contrib/issues/8396 for more details") - - if err != nil { - // This should never happen, since unmarshaling passed with the original config. - // If it happens, report the error and instruct users to check the issue. - return []error{ - fmt.Errorf("failed to determine usage of env variable defaults: %w", err), - errIssue, - } - } - - // We could probably do this with reflection but I don't want to risk - // an accidental panic so we check each field manually. - if cfg.API.Key != futureCfg.API.Key { - warnings = append(warnings, errUsedEnvVar("api.key", "DD_API_KEY")) - } - if cfg.API.Site != futureCfg.API.Site { - warnings = append(warnings, errUsedEnvVar("api.site", "DD_SITE")) - } - if cfg.Hostname != futureCfg.Hostname { - warnings = append(warnings, errUsedEnvVar("hostname", "DD_HOST")) - } - if cfg.Env != futureCfg.Env { - warnings = append(warnings, errUsedEnvVar("env", "DD_ENV")) - } - if cfg.Service != futureCfg.Service { - warnings = append(warnings, errUsedEnvVar("service", "DD_SERVICE")) - } - if cfg.Version != futureCfg.Version { - warnings = append(warnings, errUsedEnvVar("version", "DD_VERSION")) - } - if cfg.Metrics.Endpoint != futureCfg.Metrics.Endpoint { - warnings = append(warnings, errUsedEnvVar("metrics.endpoint", "DD_URL")) - } - if cfg.Traces.Endpoint != futureCfg.Traces.Endpoint { - warnings = append(warnings, errUsedEnvVar("traces.endpoint", "DD_APM_URL")) - } - if tagsDiffer(cfg.getHostTags(), futureCfg.getHostTags()) { - warnings = append(warnings, fmt.Errorf("\"tags\" will not default to \"DD_TAGS\"'s value in a future minor version. Use 'env' configuration source instead to remove this warning")) - } - - if len(warnings) > 0 { - warnings = append(warnings, errIssue) - } - return -} diff --git a/exporter/datadogexporter/config_warning_deprecated.go b/exporter/datadogexporter/config_warning_deprecated.go index 9eda5299dd1c..8665584e0900 100644 --- a/exporter/datadogexporter/config_warning_deprecated.go +++ b/exporter/datadogexporter/config_warning_deprecated.go @@ -31,77 +31,44 @@ type renameError struct { 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 but not yet removed. -var renamedSettings = []renameError{ +// List of settings that have been removed, but for which we keep a custom error. +var removedSettings = []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 - } - }, }, { oldName: "tags", newName: "host_metadata::tags", oldRemovedIn: "v0.52.0", issueNumber: 9099, - updateFn: func(c *Config) { - c.HostMetadata.Tags = c.Tags - }, }, { oldName: "send_metadata", newName: "host_metadata::enabled", oldRemovedIn: "v0.52.0", issueNumber: 9099, - updateFn: func(c *Config) { - c.HostMetadata.Enabled = c.SendMetadata - }, }, { oldName: "use_resource_metadata", newName: "host_metadata::hostname_source", oldRemovedIn: "v0.52.0", issueNumber: 9099, - updateFn: func(c *Config) { - if c.UseResourceMetadata { - c.HostMetadata.HostnameSource = HostnameSourceFirstResource - } else { - c.HostMetadata.HostnameSource = HostnameSourceConfigOrSystem - } - }, }, { oldName: "metrics::report_quantiles", newName: "metrics::summaries::mode", oldRemovedIn: "v0.53.0", issueNumber: 8845, - updateFn: func(c *Config) { - if c.Metrics.Quantiles { - c.Metrics.SummaryConfig.Mode = SummaryModeGauges - } else { - c.Metrics.SummaryConfig.Mode = SummaryModeNoQuantiles - } - }, }, } -// 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( @@ -126,36 +93,6 @@ func (e renameError) RemovedErr(configMap *confmap.Conf) error { 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 *confmap.Conf) (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 *confmap.Conf, 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 -} - func handleRemovedSettings(configMap *confmap.Conf) (err error) { for _, removed := range removedSettings { err = multierr.Append(err, removed.RemovedErr(configMap)) diff --git a/exporter/datadogexporter/config_warning_deprecated_test.go b/exporter/datadogexporter/config_warning_deprecated_test.go deleted file mode 100644 index d010ff732b38..000000000000 --- a/exporter/datadogexporter/config_warning_deprecated_test.go +++ /dev/null @@ -1,110 +0,0 @@ -// 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 datadogexporter // import "github.com/open-telemetry/opentelemetry-collector-contrib/exporter/datadogexporter" - -import ( - "testing" - - "github.com/open-telemetry/opentelemetry-collector-contrib/exporter/datadogexporter/internal/metadata" - - "github.com/stretchr/testify/assert" - "go.opentelemetry.io/collector/confmap" - "go.opentelemetry.io/collector/service/featuregate" -) - -func TestDeprecationSendMonotonic(t *testing.T) { - // Override 'exporter.datadog.hostname.preview' feature flag value to remove warning - featuregate.GetRegistry().Apply(map[string]bool{metadata.HostnamePreviewFeatureGate: true}) - defer featuregate.GetRegistry().Apply(map[string]bool{metadata.HostnamePreviewFeatureGate: false}) - - tests := []struct { - name string - cfgMap *confmap.Conf - expectedMode CumulativeMonotonicSumMode - warnings []string - err string - }{ - { - name: "both metrics::send_monotonic and new metrics::sums::cumulative_monotonic_mode", - cfgMap: confmap.NewFromStringMap(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: confmap.NewFromStringMap(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 or later. See github.com/open-telemetry/opentelemetry-collector-contrib/issues/8489", - }, - }, - { - name: "metrics::send_monotonic set to false", - cfgMap: confmap.NewFromStringMap(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 or later. See github.com/open-telemetry/opentelemetry-collector-contrib/issues/8489", - }, - }, - { - name: "metrics::send_monotonic and metrics::sums::cumulative_monotonic_mode unset", - cfgMap: confmap.NewFromStringMap(map[string]interface{}{}), - expectedMode: CumulativeMonotonicSumModeToDelta, - }, - { - name: "metrics::sums::cumulative_monotonic_mode set", - cfgMap: confmap.NewFromStringMap(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) - } - }) - } - -} diff --git a/exporter/datadogexporter/example/config.yaml b/exporter/datadogexporter/example/config.yaml index c80e57343edc..1c965fb54f34 100644 --- a/exporter/datadogexporter/example/config.yaml +++ b/exporter/datadogexporter/example/config.yaml @@ -8,56 +8,10 @@ exporters: datadog: ## @param hostname - string - optional ## A custom hostname. - ## If unset it will be determined from the `DD_HOST` environment variable (Deprecated: [v0.47.0] set environment variable explicitly on configuration instead). - ## If both this and `DD_HOST` are unset, this will be determined automatically if possible. + ## If unset, this will be determined automatically if possible. # # hostname: customhostname - ## @param env - string - optional - ## The environment for unified service tagging. - ## Deprecated: [v0.49.0] Set `deployment.environment` semconv instead, see https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/9016 for details. - ## This option will be removed in v0.52.0. - ## If unset it will be determined from the `DD_ENV` environment variable (Deprecated: [v0.47.0] set environment variable explicitly on configuration instead). - # - # env: prod - - ## @param service - string - optional - ## The service for unified service tagging. - ## Deprecated: [v0.49.0] Set `service.name` semconv instead, see https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/8781 for details. - ## This option will be removed in v0.52.0. - ## If unset it will be determined from the `DD_SERVICE` environment variable (Deprecated: [v0.47.0] set environment variable explicitly on configuration instead). - # - # service: myservice - - ## @param version - string - optional - ## The version for unified service tagging. - ## Deprecated: [v0.49.0] Set `service.version` semconv instead, see https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/8783 for details. - ## This option will be removed in v0.52.0. - ## If unset it will be determined from the `DD_VERSION` environment variable (Deprecated: [v0.47.0] set environment variable explicitly on configuration instead). - # - # version: myversion - - ## @param tags - list of strings - optional - default: [] - ## The list of tags to send as host tags. - ## Deprecated: [v0.49.0] Use `host_metadata::tags` instead. - ## This option will be removed in v0.52.0. - ## If unset it will be determined from the `DD_TAGS` environment variable, specified - ## as a list of space-separated strings (Deprecated: [v0.47.0] use 'env' config source instead). - # - # tags: [] - - ## @params send_metadata - boolean - optional - default: true - ## Deprecated: [v0.49.0] Use `host_metadata::enabled` instead. - ## This option will be removed in v0.52.0. - # - # send_metadata: true - - ## @params use_resource_metadata - boolean - optional - default: true - ## Deprecated: [v0.49.0] Use `host_metadata::hostname_source` instead. - ## This option will be removed in v0.52.0. - # - # use_resource_metadata: true - ## @param only_metadata - boolean - optional - default: false ## Whether to send only metadata. This is useful for agent-collector ## setups, so that metadata about a host is sent to the backend even @@ -72,14 +26,12 @@ exporters: ## @ param key - string - required ## The Datadog API key to associate your Agent's data with your organization. ## Create a new API key here: https://app.datadoghq.com/account/settings - ## If unset it will be determined from the `DD_API_KEY` environment variable (Deprecated: [v0.47.0] set environment variable explicitly on configuration instead). # key: "" ## @param site - string - optional - default: datadoghq.com ## The site of the Datadog intake to send Agent data to. ## Set to 'datadoghq.eu' to send data to the EU site. - ## If unset it will be determined from the `DD_SITE` environment variable (Deprecated: [v0.47.0] set environment variable explicitly on configuration instead). # # site: datadoghq.com @@ -98,20 +50,6 @@ exporters: ## Metric exporter specific configuration. # # metrics: - ## @param send_monotonic_counter - boolean - optional - default: true - ## Deprecated: [v0.48.0] Use `metrics::sums::cumulative_monotonic_mode` instead. - ## Whether to report monotonic metrics as counters or gauges (raw value). - ## See https://docs.datadoghq.com/integrations/guide/prometheus-metrics/#counter - ## for further details - # - # send_monotonic_counter: true - - ## @param report_quantiles - boolean - optional - default: true - ## Deprecated: [v0.50.0] Use `metrics::summaries::mode` instead. - ## Whether to report quantiles for summary metrics. - # - # report_quantiles: true - ## @param - delta_ttl - integer - optional - default: 3600 ## The amount of time (in seconds) that values are kept in memory for ## calculating deltas for cumulative monotonic metrics. @@ -120,8 +58,7 @@ exporters: ## @param endpoint - string - optional ## The host of the Datadog intake server to send metrics to. - ## If unset it will be determined from the `DD_URL` environment variable (Deprecated: [v0.47.0] set environment variable explicitly on configuration instead). - ## If both this and `DD_URL` are unset, the value is obtained through the `site` parameter in the `api` section. + ## If unset, the value is obtained through the `site` parameter in the `api` section. # # endpoint: https://api.datadoghq.com @@ -132,14 +69,6 @@ exporters: # # resource_attributes_as_tags: false - ## Deprecated: [0.54.0] use instrumentation_scope_metadata_as_tags instead in favor of - ## https://github.com/open-telemetry/opentelemetry-proto/releases/tag/v0.15.0 - ## Both must not be enabled at the same time. - ## @param instrumentation_library_metadata_as_tags - string - optional - default: false - ## Set to true to add metadata about the instrumentation library that created a metric. - # - # instrumentation_library_metadata_as_tags: false - ## @param instrumentation_scope_metadata_as_tags - string - optional - default: false ## Set to true to add metadata about the instrumentation scope that created a metric. # @@ -185,15 +114,9 @@ exporters: ## Trace exporter specific configuration. # # traces: - ## @param max_events_per_second - integer - optional - default: 200 - ## Maximum number of APM Analytics events per second to sample. - # - # max_events_per_second: 200 - ## @param endpoint - string - optional ## The host of the Datadog intake server to send traces to. - ## If unset it will be determined from the `DD_APM_URL` environment variable (Deprecated: [v0.47.0] set environment variable explicitly on configuration instead). - ## If both this and `DD_APM_URL` are unset, the value is obtained through the `site` parameter in the `api` section. + ## If unset, the value is obtained through the `site` parameter in the `api` section. # # endpoint: https://api.datadoghq.com diff --git a/exporter/datadogexporter/factory.go b/exporter/datadogexporter/factory.go index a999c2e3e34e..53df76016906 100644 --- a/exporter/datadogexporter/factory.go +++ b/exporter/datadogexporter/factory.go @@ -17,7 +17,6 @@ package datadogexporter // import "github.com/open-telemetry/opentelemetry-colle import ( "context" "fmt" - "os" "sync" "time" @@ -80,28 +79,7 @@ func defaulttimeoutSettings() exporterhelper.TimeoutSettings { } // createDefaultConfig creates the default exporter configuration -// TODO (#8396): Remove `os.Getenv` everywhere. func (f *factory) createDefaultConfig() config.Exporter { - env := os.Getenv("DD_ENV") - if env == "" { - env = "none" - } - - site := os.Getenv("DD_SITE") - if site == "" { - site = "datadoghq.com" - } - - metricsEndpoint := os.Getenv("DD_URL") - if metricsEndpoint == "" { - metricsEndpoint = fmt.Sprintf("https://api.%s", site) - } - - tracesEndpoint := os.Getenv("DD_APM_URL") - if tracesEndpoint == "" { - tracesEndpoint = fmt.Sprintf("https://trace.agent.%s", site) - } - hostnameSource := HostnameSourceFirstResource if f.registry.IsEnabled(metadata.HostnamePreviewFeatureGate) { hostnameSource = HostnameSourceConfigOrSystem @@ -114,29 +92,17 @@ func (f *factory) createDefaultConfig() config.Exporter { QueueSettings: exporterhelper.NewDefaultQueueSettings(), API: APIConfig{ - Key: os.Getenv("DD_API_KEY"), // Must be set if using API - Site: site, - }, - - TagsConfig: TagsConfig{ - Hostname: os.Getenv("DD_HOST"), - Env: env, - Service: os.Getenv("DD_SERVICE"), - Version: os.Getenv("DD_VERSION"), - EnvVarTags: os.Getenv("DD_TAGS"), // Only taken into account if Tags is not set + Site: "datadoghq.com", }, Metrics: MetricsConfig{ TCPAddr: confignet.TCPAddr{ - Endpoint: metricsEndpoint, + Endpoint: "https://api.datadoghq.com", }, - SendMonotonic: true, - DeltaTTL: 3600, - Quantiles: true, + DeltaTTL: 3600, ExporterConfig: MetricsExporterConfig{ - ResourceAttributesAsTags: false, - InstrumentationLibraryMetadataAsTags: false, - InstrumentationScopeMetadataAsTags: false, + ResourceAttributesAsTags: false, + InstrumentationScopeMetadataAsTags: false, }, HistConfig: HistogramConfig{ Mode: "distributions", @@ -152,7 +118,7 @@ func (f *factory) createDefaultConfig() config.Exporter { Traces: TracesConfig{ TCPAddr: confignet.TCPAddr{ - Endpoint: tracesEndpoint, + Endpoint: "https://trace.agent.datadoghq.com", }, IgnoreResources: []string{}, }, @@ -161,20 +127,16 @@ func (f *factory) createDefaultConfig() config.Exporter { Enabled: true, HostnameSource: hostnameSource, }, - - SendMetadata: true, - UseResourceMetadata: true, } } // checkAndCastConfig checks the configuration type and its warnings, and casts it to // the Datadog Config struct. -func checkAndCastConfig(set component.ExporterCreateSettings, c config.Exporter) *Config { +func checkAndCastConfig(c config.Exporter) *Config { cfg, ok := c.(*Config) if !ok { panic("programming error: config structure is not of type *datadogexporter.Config") } - cfg.logWarnings(set.Logger) return cfg } @@ -184,7 +146,7 @@ func (f *factory) createMetricsExporter( set component.ExporterCreateSettings, c config.Exporter, ) (component.MetricsExporter, error) { - cfg := checkAndCastConfig(set, c) + cfg := checkAndCastConfig(c) hostProvider, err := f.SourceProvider(set.TelemetrySettings, cfg.Hostname) if err != nil { @@ -243,7 +205,7 @@ func (f *factory) createTracesExporter( set component.ExporterCreateSettings, c config.Exporter, ) (component.TracesExporter, error) { - cfg := checkAndCastConfig(set, c) + cfg := checkAndCastConfig(c) var ( pusher consumer.ConsumeTracesFunc diff --git a/exporter/datadogexporter/factory_test.go b/exporter/datadogexporter/factory_test.go index 8a135c4e1f29..54dc44e5d7cb 100644 --- a/exporter/datadogexporter/factory_test.go +++ b/exporter/datadogexporter/factory_test.go @@ -35,21 +35,9 @@ import ( // Test that the factory creates the default configuration func TestCreateDefaultConfig(t *testing.T) { - t.Setenv("DD_API_KEY", "API_KEY") - t.Setenv("DD_SITE", "SITE") - t.Setenv("DD_URL", "URL") - t.Setenv("DD_APM_URL", "APM_URL") - t.Setenv("DD_HOST", "HOST") - t.Setenv("DD_ENV", "ENV") - t.Setenv("DD_SERVICE", "SERVICE") - t.Setenv("DD_VERSION", "VERSION") - t.Setenv("DD_TAGS", "TAGS") - factory := NewFactory() cfg := factory.CreateDefaultConfig() - // Note: the default configuration created by CreateDefaultConfig - // still has the unresolved environment variables. assert.Equal(t, &Config{ ExporterSettings: config.NewExporterSettings(config.NewComponentID(typeStr)), TimeoutSettings: defaulttimeoutSettings(), @@ -57,18 +45,14 @@ func TestCreateDefaultConfig(t *testing.T) { QueueSettings: exporterhelper.NewDefaultQueueSettings(), API: APIConfig{ - Key: "API_KEY", - Site: "SITE", - FailOnInvalidKey: false, + Site: "datadoghq.com", }, Metrics: MetricsConfig{ TCPAddr: confignet.TCPAddr{ - Endpoint: "URL", + Endpoint: "https://api.datadoghq.com", }, - DeltaTTL: 3600, - SendMonotonic: true, - Quantiles: true, + DeltaTTL: 3600, HistConfig: HistogramConfig{ Mode: "distributions", SendCountSum: false, @@ -83,27 +67,16 @@ func TestCreateDefaultConfig(t *testing.T) { Traces: TracesConfig{ TCPAddr: confignet.TCPAddr{ - Endpoint: "APM_URL", + Endpoint: "https://trace.agent.datadoghq.com", }, IgnoreResources: []string{}, }, - TagsConfig: TagsConfig{ - Hostname: "HOST", - Env: "ENV", - Service: "SERVICE", - Version: "VERSION", - EnvVarTags: "TAGS", - }, - HostMetadata: HostMetadataConfig{ Enabled: true, HostnameSource: HostnameSourceFirstResource, }, - - SendMetadata: true, - OnlyMetadata: false, - UseResourceMetadata: true, + OnlyMetadata: false, }, cfg, "failed to create default config") assert.NoError(t, configtest.CheckConfigStruct(cfg)) @@ -127,12 +100,7 @@ func TestLoadConfig(t *testing.T) { assert.Equal(t, exporterhelper.NewDefaultRetrySettings(), apiConfig.RetrySettings) assert.Equal(t, exporterhelper.NewDefaultQueueSettings(), apiConfig.QueueSettings) assert.Equal(t, TagsConfig{ - Hostname: "customhostname", - Env: "prod", - Service: "myservice", - Version: "myversion", - EnvVarTags: "", - Tags: []string{"example:tag"}, + Hostname: "customhostname", }, apiConfig.TagsConfig) assert.Equal(t, APIConfig{ Key: "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", @@ -143,9 +111,7 @@ func TestLoadConfig(t *testing.T) { TCPAddr: confignet.TCPAddr{ Endpoint: "https://api.datadoghq.eu", }, - DeltaTTL: 3600, - SendMonotonic: true, - Quantiles: true, + DeltaTTL: 3600, HistConfig: HistogramConfig{ Mode: "distributions", SendCountSum: false, @@ -168,9 +134,7 @@ func TestLoadConfig(t *testing.T) { SpanNameAsResourceName: true, IgnoreResources: []string{}, }, apiConfig.Traces) - assert.True(t, apiConfig.SendMetadata) assert.False(t, apiConfig.OnlyMetadata) - assert.True(t, apiConfig.UseResourceMetadata) defaultConfig := cfg.Exporters[config.NewComponentIDWithName(typeStr, "default")].(*Config) assert.Equal(t, &Config{ @@ -178,15 +142,6 @@ func TestLoadConfig(t *testing.T) { TimeoutSettings: defaulttimeoutSettings(), RetrySettings: exporterhelper.NewDefaultRetrySettings(), QueueSettings: exporterhelper.NewDefaultQueueSettings(), - - TagsConfig: TagsConfig{ - Hostname: "", - Env: "none", - Service: "", - Version: "", - EnvVarTags: "", - }, - API: APIConfig{ Key: "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", Site: "datadoghq.com", @@ -197,9 +152,7 @@ func TestLoadConfig(t *testing.T) { TCPAddr: confignet.TCPAddr{ Endpoint: "https://api.datadoghq.com", }, - SendMonotonic: true, - DeltaTTL: 3600, - Quantiles: true, + DeltaTTL: 3600, HistConfig: HistogramConfig{ Mode: "distributions", SendCountSum: false, @@ -224,67 +177,30 @@ func TestLoadConfig(t *testing.T) { HostnameSource: HostnameSourceFirstResource, }, - SendMetadata: true, - OnlyMetadata: false, - UseResourceMetadata: true, + OnlyMetadata: false, }, defaultConfig) - hostMetadataConfig := cfg.Exporters[config.NewComponentIDWithName(typeStr, "hostmetadata")].(*Config) - - assert.Equal(t, HostMetadataConfig{ - Enabled: true, - HostnameSource: HostnameSourceConfigOrSystem, - Tags: []string{"example:one"}, - }, hostMetadataConfig.HostMetadata) -} - -// TestLoadConfigEnvVariables tests that the loading configuration takes into account -// environment variables for default values -func TestLoadConfigEnvVariables(t *testing.T) { - t.Setenv("DD_API_KEY", "replacedapikey") - t.Setenv("DD_HOST", "testhost") - t.Setenv("DD_SITE", "datadoghq.test") - t.Setenv("DD_TAGS", "envexample:tag envexample2:tag") - t.Setenv("DD_URL", "https://api.datadoghq.com") - t.Setenv("DD_APM_URL", "https://trace.agent.datadoghq.com") - t.Setenv("DD_APM_MAX_TPS", "15") - - factories, err := componenttest.NopFactories() - assert.NoError(t, err) - - factory := NewFactory() - factories.Exporters[typeStr] = factory - cfg, err := servicetest.LoadConfigAndValidate(filepath.Join("testdata", "config.yaml"), factories) - - require.NoError(t, err) - require.NotNil(t, cfg) - - apiConfig := cfg.Exporters[config.NewComponentIDWithName(typeStr, "api2")].(*Config) + api2Config := cfg.Exporters[config.NewComponentIDWithName(typeStr, "api2")].(*Config) // Check that settings with env variables get overridden when explicitly set in config - assert.Equal(t, config.NewExporterSettings(config.NewComponentIDWithName(typeStr, "api2")), apiConfig.ExporterSettings) - assert.Equal(t, defaulttimeoutSettings(), apiConfig.TimeoutSettings) - assert.Equal(t, exporterhelper.NewDefaultRetrySettings(), apiConfig.RetrySettings) - assert.Equal(t, exporterhelper.NewDefaultQueueSettings(), apiConfig.QueueSettings) - assert.Equal(t, TagsConfig{ - Hostname: "customhostname", - Env: "none", - EnvVarTags: "envexample:tag envexample2:tag", - }, apiConfig.TagsConfig) - assert.Equal(t, - APIConfig{ + assert.Equal(t, &Config{ + ExporterSettings: config.NewExporterSettings(config.NewComponentIDWithName(typeStr, "api2")), + TimeoutSettings: defaulttimeoutSettings(), + RetrySettings: exporterhelper.NewDefaultRetrySettings(), + QueueSettings: exporterhelper.NewDefaultQueueSettings(), + TagsConfig: TagsConfig{ + Hostname: "customhostname", + }, + API: APIConfig{ Key: "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", Site: "datadoghq.eu", FailOnInvalidKey: false, - }, apiConfig.API) - assert.Equal(t, - MetricsConfig{ + }, + Metrics: MetricsConfig{ TCPAddr: confignet.TCPAddr{ Endpoint: "https://api.datadoghq.test", }, - SendMonotonic: true, - Quantiles: false, - DeltaTTL: 3600, + DeltaTTL: 3600, HistConfig: HistogramConfig{ Mode: "distributions", SendCountSum: false, @@ -293,11 +209,10 @@ func TestLoadConfigEnvVariables(t *testing.T) { CumulativeMonotonicMode: CumulativeMonotonicSumModeToDelta, }, SummaryConfig: SummaryConfig{ - Mode: SummaryModeNoQuantiles, + Mode: SummaryModeGauges, }, - }, apiConfig.Metrics) - assert.Equal(t, - TracesConfig{ + }, + Traces: TracesConfig{ TCPAddr: confignet.TCPAddr{ Endpoint: "https://trace.agent.datadoghq.test", }, @@ -306,56 +221,13 @@ func TestLoadConfigEnvVariables(t *testing.T) { "old_name4": "new_name4", }, IgnoreResources: []string{}, - }, apiConfig.Traces) - assert.Equal(t, - HostMetadataConfig{ + }, + HostMetadata: HostMetadataConfig{ Enabled: true, HostnameSource: HostnameSourceFirstResource, Tags: []string{"example:tag"}, - }, apiConfig.HostMetadata) - - defaultConfig := cfg.Exporters[config.NewComponentIDWithName(typeStr, "default")].(*Config) - - // Check that settings with env variables get taken into account when - // no settings are given. - assert.Equal(t, config.NewExporterSettings(config.NewComponentIDWithName(typeStr, "default")), defaultConfig.ExporterSettings) - assert.Equal(t, defaulttimeoutSettings(), defaultConfig.TimeoutSettings) - assert.Equal(t, exporterhelper.NewDefaultRetrySettings(), defaultConfig.RetrySettings) - assert.Equal(t, exporterhelper.NewDefaultQueueSettings(), defaultConfig.QueueSettings) - assert.Equal(t, TagsConfig{ - Hostname: "testhost", - Env: "none", - EnvVarTags: "envexample:tag envexample2:tag", - }, defaultConfig.TagsConfig) - assert.Equal(t, APIConfig{ - Key: "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", - Site: "datadoghq.test", - FailOnInvalidKey: false, - }, defaultConfig.API) - assert.Equal(t, MetricsConfig{ - TCPAddr: confignet.TCPAddr{ - Endpoint: "https://api.datadoghq.com", - }, - SendMonotonic: true, - DeltaTTL: 3600, - Quantiles: true, - HistConfig: HistogramConfig{ - Mode: "distributions", - SendCountSum: false, - }, - SumConfig: SumConfig{ - CumulativeMonotonicMode: CumulativeMonotonicSumModeToDelta, - }, - SummaryConfig: SummaryConfig{ - Mode: SummaryModeGauges, - }, - }, defaultConfig.Metrics) - assert.Equal(t, TracesConfig{ - TCPAddr: confignet.TCPAddr{ - Endpoint: "https://trace.agent.datadoghq.com", }, - IgnoreResources: []string{}, - }, defaultConfig.Traces) + }, api2Config) } func TestOverrideEndpoints(t *testing.T) { diff --git a/exporter/datadogexporter/hostmetadata.go b/exporter/datadogexporter/hostmetadata.go index 79d483d28882..ca0b308b5f1d 100644 --- a/exporter/datadogexporter/hostmetadata.go +++ b/exporter/datadogexporter/hostmetadata.go @@ -15,32 +15,14 @@ package datadogexporter // import "github.com/open-telemetry/opentelemetry-collector-contrib/exporter/datadogexporter" import ( - "fmt" - "strings" - "github.com/open-telemetry/opentelemetry-collector-contrib/exporter/datadogexporter/internal/metadata" ) -// getHostTags gets the host tags extracted from the configuration. -func getHostTags(c *Config) []string { - tags := c.HostMetadata.Tags - - if len(tags) == 0 { - //lint:ignore SA1019 Will be removed when environment variable detection is removed - tags = strings.Split(c.EnvVarTags, " ") //nolint - } - - if c.Env != "none" { - tags = append(tags, fmt.Sprintf("env:%s", c.Env)) - } - return tags -} - // newMetadataConfigfromConfig creates a new metadata pusher config from the main func newMetadataConfigfromConfig(cfg *Config) metadata.PusherConfig { return metadata.PusherConfig{ ConfigHostname: cfg.Hostname, - ConfigTags: getHostTags(cfg), + ConfigTags: cfg.HostMetadata.Tags, MetricsEndpoint: cfg.Metrics.Endpoint, APIKey: cfg.API.Key, UseResourceMetadata: cfg.HostMetadata.HostnameSource == HostnameSourceFirstResource, diff --git a/exporter/datadogexporter/hostmetadata_test.go b/exporter/datadogexporter/hostmetadata_test.go deleted file mode 100644 index d26df485836b..000000000000 --- a/exporter/datadogexporter/hostmetadata_test.go +++ /dev/null @@ -1,90 +0,0 @@ -// 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 datadogexporter // import "github.com/open-telemetry/opentelemetry-collector-contrib/exporter/datadogexporter" - -import ( - "testing" - - "github.com/stretchr/testify/assert" -) - -func TestHostTags(t *testing.T) { - c := Config{ - TagsConfig: TagsConfig{ - Hostname: "customhost", - Env: "customenv", - // Service and version should be only used for traces - Service: "customservice", - Version: "customversion", - }, - - HostMetadata: HostMetadataConfig{ - Tags: []string{"key1:val1", "key2:val2"}, - }, - } - - assert.ElementsMatch(t, - []string{ - "env:customenv", - "key1:val1", - "key2:val2", - }, - getHostTags(&c), - ) - - c = Config{ - TagsConfig: TagsConfig{ - Hostname: "customhost", - Env: "customenv", - // Service and version should be only used for traces - Service: "customservice", - Version: "customversion", - EnvVarTags: "key3:val3 key4:val4", - }, - - HostMetadata: HostMetadataConfig{ - Tags: []string{"key1:val1", "key2:val2"}, - }, - } - - assert.ElementsMatch(t, - []string{ - "env:customenv", - "key1:val1", - "key2:val2", - }, - getHostTags(&c), - ) - - c = Config{ - TagsConfig: TagsConfig{ - Hostname: "customhost", - Env: "customenv", - // Service and version should be only used for traces - Service: "customservice", - Version: "customversion", - EnvVarTags: "key3:val3 key4:val4", - }, - } - - assert.ElementsMatch(t, - []string{ - "env:customenv", - "key3:val3", - "key4:val4", - }, - getHostTags(&c), - ) -} diff --git a/exporter/datadogexporter/metrics_exporter.go b/exporter/datadogexporter/metrics_exporter.go index e0c0b853dbbe..95dc5c4518fb 100644 --- a/exporter/datadogexporter/metrics_exporter.go +++ b/exporter/datadogexporter/metrics_exporter.go @@ -72,18 +72,10 @@ func translatorFromConfig(logger *zap.Logger, cfg *Config, sourceProvider source options = append(options, translator.WithResourceAttributesAsTags()) } - if cfg.Metrics.ExporterConfig.InstrumentationScopeMetadataAsTags && cfg.Metrics.ExporterConfig.InstrumentationLibraryMetadataAsTags { // nolint SA1019 - return nil, fmt.Errorf("cannot use both instrumentation_library_metadata_as_tags(deprecated) and instrumentation_scope_metadata_as_tags") - } - if cfg.Metrics.ExporterConfig.InstrumentationScopeMetadataAsTags { options = append(options, translator.WithInstrumentationScopeMetadataAsTags()) } - if cfg.Metrics.ExporterConfig.InstrumentationLibraryMetadataAsTags { // nolint SA1019 - options = append(options, translator.WithInstrumentationLibraryMetadataAsTags()) - } - options = append(options, translator.WithHistogramMode(translator.HistogramMode(cfg.Metrics.HistConfig.Mode))) var numberMode translator.NumberMode diff --git a/exporter/datadogexporter/testdata/config.yaml b/exporter/datadogexporter/testdata/config.yaml index 72b5c8992d0e..b4174eda63e2 100644 --- a/exporter/datadogexporter/testdata/config.yaml +++ b/exporter/datadogexporter/testdata/config.yaml @@ -7,17 +7,6 @@ processors: exporters: datadog/api: hostname: customhostname - # Deprecated; kept here to avoid regressions. - env: prod - # Deprecated; kept here to avoid regressions. - service: myservice - # Deprecated; kept here to avoid regressions. - version: myversion - - # Deprecated; kept here to avoid regressions. - tags: - - example:tag - api: key: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa site: datadoghq.eu @@ -43,8 +32,6 @@ exporters: metrics: endpoint: https://api.datadoghq.test - # Deprecated; kept here to avoid regressions - report_quantiles: false traces: span_name_remappings: @@ -59,16 +46,6 @@ exporters: # Suppress warning related to `exporter.datadog.hostname.preview` feature gate hostname_source: first_resource - datadog/hostmetadata: - api: - key: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa - # Deprecated; kept here to test rename system - tags: [example:one] - # Deprecated; kept here to test rename system - send_metadata: true - # Deprecated; kept here to test rename system - use_resource_metadata: false - service: pipelines: metrics: diff --git a/exporter/datadogexporter/traces_exporter_test.go b/exporter/datadogexporter/traces_exporter_test.go index 04847e28a10a..6f68fbcef31b 100644 --- a/exporter/datadogexporter/traces_exporter_test.go +++ b/exporter/datadogexporter/traces_exporter_test.go @@ -136,8 +136,6 @@ func TestTracesSource(t *testing.T) { }, TagsConfig: TagsConfig{ Hostname: "fallbackHostname", - Env: "test_env", - Tags: []string{"key:val"}, }, Metrics: MetricsConfig{ TCPAddr: confignet.TCPAddr{Endpoint: metricsServer.URL}, @@ -246,8 +244,6 @@ func TestTraceExporter(t *testing.T) { }, TagsConfig: TagsConfig{ Hostname: "test-host", - Env: "test_env", - Tags: []string{"key:val"}, }, Metrics: MetricsConfig{ TCPAddr: confignet.TCPAddr{ @@ -300,8 +296,6 @@ func TestPushTraceData(t *testing.T) { }, TagsConfig: TagsConfig{ Hostname: "test-host", - Env: "test_env", - Tags: []string{"key:val"}, }, Metrics: MetricsConfig{ TCPAddr: confignet.TCPAddr{Endpoint: server.URL},