From fe7cdff9e4747f8940d97c790dec9910aff2fff0 Mon Sep 17 00:00:00 2001 From: Nassim Boutekedjiret Date: Tue, 19 Nov 2024 17:32:15 +0100 Subject: [PATCH 1/5] [exporter/datadog] Add configurable `reporter_period` for host metadata - Introduced a `reporter_period` field in `HostMetadataConfig` to allow customization of the metadata reporting interval. - Default value set to 30 minutes for backward compatibility. - Updated `pkg/datadog/config/host.go` to support the new `reporter_period` field. - Validated `reporter_period` in `pkg/datadog/config/config.go` to ensure positive durations. - Passed `reporter_period` to the metadata pusher in `exporter/datadogexporter/internal/hostmetadata/config.go`. - Modified `exporter/datadogexporter/hostmetadata.go` and `factory.go` to integrate `reporter_period` into the reporter logic. - Removed hardcoded constant for metadata reporting interval in favor of the configurable value. Fixes #36450 --- .../datadogexporter/examples/collector.yaml | 5 ++ exporter/datadogexporter/factory.go | 4 +- exporter/datadogexporter/factory_test.go | 1 + exporter/datadogexporter/hostmetadata.go | 1 + .../internal/hostmetadata/config.go | 4 + .../datadogexporter/logs_exporter_test.go | 6 ++ .../datadogexporter/metrics_exporter_test.go | 7 +- .../datadogexporter/traces_exporter_test.go | 17 +++- pkg/datadog/config/config.go | 5 ++ pkg/datadog/config/config_test.go | 85 ++++++++++++++++++- pkg/datadog/config/host.go | 3 + pkg/datadog/config/testdata/config.yaml | 6 ++ 12 files changed, 136 insertions(+), 8 deletions(-) diff --git a/exporter/datadogexporter/examples/collector.yaml b/exporter/datadogexporter/examples/collector.yaml index ba1a9080aaf9..711d8b22eda5 100644 --- a/exporter/datadogexporter/examples/collector.yaml +++ b/exporter/datadogexporter/examples/collector.yaml @@ -449,6 +449,11 @@ exporters: # # tags: ["team:infra", ":"] + ## @param reporter_period - duration - optional - default: 30m + ## The period at which the host metadata reporter sends host metadata to Datadog. + ## The default is 30 minutes. + # reporter_period: 30m + ## @param logs - custom object - optional ## Logs exporter specific configuration. # diff --git a/exporter/datadogexporter/factory.go b/exporter/datadogexporter/factory.go index 9ec9eba241f0..3ba017623954 100644 --- a/exporter/datadogexporter/factory.go +++ b/exporter/datadogexporter/factory.go @@ -79,8 +79,6 @@ func enableZorkianMetricExport() error { return featuregate.GlobalRegistry().Set(metricExportNativeClientFeatureGate.ID(), false) } -const metadataReporterPeriod = 30 * time.Minute - func consumeResource(metadataReporter *inframetadata.Reporter, res pcommon.Resource, logger *zap.Logger) { if err := metadataReporter.ConsumeResource(res); err != nil { logger.Warn("failed to consume resource for host metadata", zap.Error(err), zap.Any("resource", res)) @@ -124,7 +122,7 @@ func (f *factory) AttributesTranslator(set component.TelemetrySettings) (*attrib func (f *factory) Reporter(params exporter.Settings, pcfg hostmetadata.PusherConfig) (*inframetadata.Reporter, error) { f.onceReporter.Do(func() { pusher := hostmetadata.NewPusher(params, pcfg) - f.reporter, f.reporterErr = inframetadata.NewReporter(params.Logger, pusher, metadataReporterPeriod) + f.reporter, f.reporterErr = inframetadata.NewReporter(params.Logger, pusher, pcfg.ReporterPeriod) if f.reporterErr == nil { go func() { if err := f.reporter.Run(context.Background()); err != nil { diff --git a/exporter/datadogexporter/factory_test.go b/exporter/datadogexporter/factory_test.go index dbbe53b183c4..8fefd791fa63 100644 --- a/exporter/datadogexporter/factory_test.go +++ b/exporter/datadogexporter/factory_test.go @@ -308,6 +308,7 @@ func TestOnlyMetadata(t *testing.T) { HostMetadata: HostMetadataConfig{ Enabled: true, HostnameSource: HostnameSourceFirstResource, + ReporterPeriod: 30 * time.Minute, }, } cfg.HostMetadata.SetSourceTimeout(50 * time.Millisecond) diff --git a/exporter/datadogexporter/hostmetadata.go b/exporter/datadogexporter/hostmetadata.go index 1338bed2fb54..ead1696a4498 100644 --- a/exporter/datadogexporter/hostmetadata.go +++ b/exporter/datadogexporter/hostmetadata.go @@ -18,5 +18,6 @@ func newMetadataConfigfromConfig(cfg *Config) hostmetadata.PusherConfig { InsecureSkipVerify: cfg.TLSSetting.InsecureSkipVerify, ClientConfig: cfg.ClientConfig, RetrySettings: cfg.BackOffConfig, + ReporterPeriod: cfg.HostMetadata.ReporterPeriod, } } diff --git a/exporter/datadogexporter/internal/hostmetadata/config.go b/exporter/datadogexporter/internal/hostmetadata/config.go index d5c4a3e34160..ad99d4f5bc18 100644 --- a/exporter/datadogexporter/internal/hostmetadata/config.go +++ b/exporter/datadogexporter/internal/hostmetadata/config.go @@ -4,6 +4,8 @@ package hostmetadata // import "github.com/open-telemetry/opentelemetry-collector-contrib/exporter/datadogexporter/internal/hostmetadata" import ( + "time" + "go.opentelemetry.io/collector/config/confighttp" "go.opentelemetry.io/collector/config/configretry" ) @@ -26,4 +28,6 @@ type PusherConfig struct { ClientConfig confighttp.ClientConfig // RetrySettings of exporter. RetrySettings configretry.BackOffConfig + // ReporterPeriod is the period of the reporter goroutine. + ReporterPeriod time.Duration } diff --git a/exporter/datadogexporter/logs_exporter_test.go b/exporter/datadogexporter/logs_exporter_test.go index 941561890853..a2837353def9 100644 --- a/exporter/datadogexporter/logs_exporter_test.go +++ b/exporter/datadogexporter/logs_exporter_test.go @@ -230,6 +230,9 @@ func TestLogsExporter(t *testing.T) { Endpoint: server.URL, }, }, + HostMetadata: HostMetadataConfig{ + ReporterPeriod: 30 * time.Minute, + }, } params := exportertest.NewNopSettings() @@ -595,6 +598,9 @@ func TestLogsAgentExporter(t *testing.T) { CompressionLevel: 6, BatchWait: 1, }, + HostMetadata: HostMetadataConfig{ + ReporterPeriod: 30 * time.Minute, + }, } params := exportertest.NewNopSettings() f := NewFactory() diff --git a/exporter/datadogexporter/metrics_exporter_test.go b/exporter/datadogexporter/metrics_exporter_test.go index a31373256630..379e25842208 100644 --- a/exporter/datadogexporter/metrics_exporter_test.go +++ b/exporter/datadogexporter/metrics_exporter_test.go @@ -58,7 +58,9 @@ func TestNewExporter(t *testing.T) { CumulativeMonotonicMode: CumulativeMonotonicSumModeToDelta, }, }, - HostMetadata: HostMetadataConfig{}, + HostMetadata: HostMetadataConfig{ + ReporterPeriod: 30 * time.Minute, + }, } cfg.HostMetadata.SetSourceTimeout(50 * time.Millisecond) params := exportertest.NewNopSettings() @@ -437,6 +439,9 @@ func TestNewExporter_Zorkian(t *testing.T) { CumulativeMonotonicMode: CumulativeMonotonicSumModeToDelta, }, }, + HostMetadata: HostMetadataConfig{ + ReporterPeriod: 30 * time.Minute, + }, } params := exportertest.NewNopSettings() f := NewFactory() diff --git a/exporter/datadogexporter/traces_exporter_test.go b/exporter/datadogexporter/traces_exporter_test.go index 725a32a8f8a4..68aff8b3e1ea 100644 --- a/exporter/datadogexporter/traces_exporter_test.go +++ b/exporter/datadogexporter/traces_exporter_test.go @@ -145,6 +145,9 @@ func TestTracesSource(t *testing.T) { IgnoreResources: []string{}, }, }, + HostMetadata: HostMetadataConfig{ + ReporterPeriod: 30 * time.Minute, + }, } assert := assert.New(t) @@ -267,6 +270,9 @@ func TestTraceExporter(t *testing.T) { }, TraceBuffer: 2, }, + HostMetadata: HostMetadataConfig{ + ReporterPeriod: 30 * time.Minute, + }, } cfg.Traces.SetFlushInterval(0.1) @@ -292,7 +298,11 @@ func TestNewTracesExporter(t *testing.T) { metricsServer := testutil.DatadogServerMock() defer metricsServer.Close() - cfg := &Config{} + cfg := &Config{ + HostMetadata: HostMetadataConfig{ + ReporterPeriod: 30 * time.Minute, + }, + } cfg.API.Key = "ddog_32_characters_long_api_key1" cfg.Metrics.TCPAddrConfig.Endpoint = metricsServer.URL params := exportertest.NewNopSettings() @@ -320,10 +330,10 @@ func TestPushTraceData(t *testing.T) { Traces: TracesConfig{ TCPAddrConfig: confignet.TCPAddrConfig{Endpoint: server.URL}, }, - HostMetadata: HostMetadataConfig{ Enabled: true, HostnameSource: HostnameSourceFirstResource, + ReporterPeriod: 30 * time.Minute, }, } @@ -358,6 +368,9 @@ func TestPushTraceData_NewEnvConvention(t *testing.T) { Traces: TracesConfig{ TCPAddrConfig: confignet.TCPAddrConfig{Endpoint: server.URL}, }, + HostMetadata: HostMetadataConfig{ + ReporterPeriod: 30 * time.Minute, + }, } cfg.Traces.SetFlushInterval(0.1) diff --git a/pkg/datadog/config/config.go b/pkg/datadog/config/config.go index 60542c785993..a243e3c4f67b 100644 --- a/pkg/datadog/config/config.go +++ b/pkg/datadog/config/config.go @@ -133,6 +133,10 @@ func (c *Config) Validate() error { return err } + if (c.HostMetadata.ReporterPeriod <= 0) { + return errors.New("reporter_period must be a positive duration") + } + return nil } @@ -340,6 +344,7 @@ func CreateDefaultConfig() component.Config { HostMetadata: HostMetadataConfig{ Enabled: true, HostnameSource: HostnameSourceConfigOrSystem, + ReporterPeriod: 30 * time.Minute, }, } } diff --git a/pkg/datadog/config/config_test.go b/pkg/datadog/config/config_test.go index d19d51826922..3035b6fdab74 100644 --- a/pkg/datadog/config/config_test.go +++ b/pkg/datadog/config/config_test.go @@ -39,7 +39,9 @@ func TestValidate(t *testing.T) { }{ { name: "no api::key", - cfg: &Config{}, + cfg: &Config{ + HostMetadata: HostMetadataConfig{Enabled: true, ReporterPeriod: 10 * time.Minute}, + }, err: ErrUnsetAPIKey.Error(), }, { @@ -47,6 +49,7 @@ func TestValidate(t *testing.T) { cfg: &Config{ API: APIConfig{Key: "notnull"}, TagsConfig: TagsConfig{Hostname: "invalid_host"}, + HostMetadata: HostMetadataConfig{Enabled: true, ReporterPeriod: 10 * time.Minute}, }, err: "hostname field is invalid: invalid_host is not RFC1123 compliant", }, @@ -55,7 +58,7 @@ func TestValidate(t *testing.T) { cfg: &Config{ API: APIConfig{Key: "notnull"}, OnlyMetadata: true, - HostMetadata: HostMetadataConfig{Enabled: false}, + HostMetadata: HostMetadataConfig{Enabled: true, ReporterPeriod: 10 * time.Minute}, }, err: ErrNoMetadata.Error(), }, @@ -64,6 +67,7 @@ func TestValidate(t *testing.T) { cfg: &Config{ API: APIConfig{Key: "notnull"}, Traces: TracesExporterConfig{TracesConfig: TracesConfig{SpanNameRemappings: map[string]string{"old.opentelemetryspan.name": "updated.name"}}}, + HostMetadata: HostMetadataConfig{Enabled: true, ReporterPeriod: 10 * time.Minute}, }, }, { @@ -71,6 +75,7 @@ func TestValidate(t *testing.T) { cfg: &Config{ API: APIConfig{Key: "notnull"}, Traces: TracesExporterConfig{TracesConfig: TracesConfig{SpanNameRemappings: map[string]string{"oldname": ""}}}, + HostMetadata: HostMetadataConfig{Enabled: true, ReporterPeriod: 10 * time.Minute}, }, err: "'' is not valid value for span name remapping", }, @@ -79,6 +84,8 @@ func TestValidate(t *testing.T) { cfg: &Config{ API: APIConfig{Key: "notnull"}, Traces: TracesExporterConfig{TracesConfig: TracesConfig{SpanNameRemappings: map[string]string{"": "newname"}}}, + HostMetadata: HostMetadataConfig{Enabled: true, ReporterPeriod: 10 * time.Minute}, + }, err: "'' is not valid key for span name remapping", }, @@ -87,6 +94,7 @@ func TestValidate(t *testing.T) { cfg: &Config{ API: APIConfig{Key: "notnull"}, Traces: TracesExporterConfig{TracesConfig: TracesConfig{IgnoreResources: []string{"[123]"}}}, + HostMetadata: HostMetadataConfig{Enabled: true, ReporterPeriod: 10 * time.Minute}, }, }, { @@ -94,6 +102,7 @@ func TestValidate(t *testing.T) { cfg: &Config{ API: APIConfig{Key: "notnull"}, Traces: TracesExporterConfig{TracesConfig: TracesConfig{IgnoreResources: []string{"[123"}}}, + HostMetadata: HostMetadataConfig{Enabled: true, ReporterPeriod: 10 * time.Minute}, }, err: "'[123' is not valid resource filter regular expression", }, @@ -107,6 +116,7 @@ func TestValidate(t *testing.T) { SendAggregations: false, }, }, + HostMetadata: HostMetadataConfig{Enabled: true, ReporterPeriod: 10 * time.Minute}, }, err: "'nobuckets' mode and `send_aggregation_metrics` set to false will send no histogram metrics", }, @@ -119,6 +129,7 @@ func TestValidate(t *testing.T) { InsecureSkipVerify: true, }, }, + HostMetadata: HostMetadataConfig{Enabled: true, ReporterPeriod: 10 * time.Minute}, }, }, { @@ -126,6 +137,7 @@ func TestValidate(t *testing.T) { cfg: &Config{ API: APIConfig{Key: "notnull"}, Traces: TracesExporterConfig{TraceBuffer: 10}, + HostMetadata: HostMetadataConfig{Enabled: true, ReporterPeriod: 10 * time.Minute}, }, }, { @@ -137,6 +149,7 @@ func TestValidate(t *testing.T) { PeerTags: []string{"tag1", "tag2"}, }, }, + HostMetadata: HostMetadataConfig{Enabled: true, ReporterPeriod: 10 * time.Minute}, }, }, { @@ -154,6 +167,7 @@ func TestValidate(t *testing.T) { DisableKeepAlives: true, TLSSetting: configtls.ClientConfig{InsecureSkipVerify: true}, }, + HostMetadata: HostMetadataConfig{Enabled: true, ReporterPeriod: 10 * time.Minute}, }, }, @@ -169,9 +183,18 @@ func TestValidate(t *testing.T) { HTTP2ReadIdleTimeout: 250, HTTP2PingTimeout: 200, }, + HostMetadata: HostMetadataConfig{Enabled: true, ReporterPeriod: 10 * time.Minute}, }, err: "these confighttp client configs are currently not respected by Datadog exporter: auth, endpoint, compression, headers, http2_read_idle_timeout, http2_ping_timeout", }, + { + name: "Invalid reporter_period", + cfg: &Config{ + API: APIConfig{Key: "notnull"}, + HostMetadata: HostMetadataConfig{Enabled: true, ReporterPeriod: 0}, + }, + err: "reporter_period must be a positive duration", + }, } for _, testInstance := range tests { t.Run(testInstance.name, func(t *testing.T) { @@ -426,6 +449,7 @@ func TestCreateDefaultConfig(t *testing.T) { HostMetadata: HostMetadataConfig{ Enabled: true, HostnameSource: HostnameSourceConfigOrSystem, + ReporterPeriod: 30 * time.Minute, }, OnlyMetadata: false, }, cfg, "failed to create default config") @@ -494,6 +518,7 @@ func TestLoadConfig(t *testing.T) { HostMetadata: HostMetadataConfig{ Enabled: true, HostnameSource: HostnameSourceConfigOrSystem, + ReporterPeriod: 30 * time.Minute, }, OnlyMetadata: false, }, @@ -555,6 +580,7 @@ func TestLoadConfig(t *testing.T) { HostMetadata: HostMetadataConfig{ Enabled: true, HostnameSource: HostnameSourceConfigOrSystem, + ReporterPeriod: 30 * time.Minute, }, }, }, @@ -613,9 +639,64 @@ func TestLoadConfig(t *testing.T) { Enabled: true, HostnameSource: HostnameSourceConfigOrSystem, Tags: []string{"example:tag"}, + ReporterPeriod: 30 * time.Minute, }, }, }, + { + id: component.NewIDWithName(ddtype, "customReporterPeriod"), + expected: &Config{ + ClientConfig: defaultClientConfig(), + BackOffConfig: configretry.NewDefaultBackOffConfig(), + QueueSettings: exporterhelper.NewDefaultQueueConfig(), + API: APIConfig{ + Key: "key", + Site: "datadoghq.com", + FailOnInvalidKey: false, + }, + + Metrics: MetricsConfig{ + TCPAddrConfig: confignet.TCPAddrConfig{ + Endpoint: "https://api.datadoghq.com", + }, + DeltaTTL: 3600, + HistConfig: HistogramConfig{ + Mode: "distributions", + SendAggregations: false, + }, + SumConfig: SumConfig{ + CumulativeMonotonicMode: CumulativeMonotonicSumModeToDelta, + InitialCumulativeMonotonicMode: InitialValueModeAuto, + }, + SummaryConfig: SummaryConfig{ + Mode: SummaryModeGauges, + }, + }, + + Traces: TracesExporterConfig{ + TCPAddrConfig: confignet.TCPAddrConfig{ + Endpoint: "https://trace.agent.datadoghq.com", + }, + TracesConfig: TracesConfig{ + IgnoreResources: []string{}, + }, + }, + Logs: LogsConfig{ + TCPAddrConfig: confignet.TCPAddrConfig{ + Endpoint: "https://http-intake.logs.datadoghq.com", + }, + UseCompression: true, + CompressionLevel: 6, + BatchWait: 5, + }, + HostMetadata: HostMetadataConfig{ + Enabled: true, + HostnameSource: HostnameSourceConfigOrSystem, + ReporterPeriod: 10 * time.Minute, + }, + OnlyMetadata: false, + }, + }, } for _, tt := range tests { diff --git a/pkg/datadog/config/host.go b/pkg/datadog/config/host.go index 06e3161fdcc7..4d481aa005c8 100644 --- a/pkg/datadog/config/host.go +++ b/pkg/datadog/config/host.go @@ -74,6 +74,9 @@ type HostMetadataConfig struct { // If unset, or set to zero duration, there will be no timeout applied. // Default is no timeout. sourceTimeout time.Duration + + // ReporterPeriod is the period at which the host metadata reporter will run. + ReporterPeriod time.Duration `mapstructure:"reporter_period"` } // SetSourceTimeout sets the timeout to fetch from each provider - for example AWS IMDS. diff --git a/pkg/datadog/config/testdata/config.yaml b/pkg/datadog/config/testdata/config.yaml index 10fea4ec91c0..e1002550cab9 100644 --- a/pkg/datadog/config/testdata/config.yaml +++ b/pkg/datadog/config/testdata/config.yaml @@ -38,3 +38,9 @@ datadog/default: api: key: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +datadog/customReporterPeriod: + api: + key: key + host_metadata: + enabled: true + reporter_period: 10m From 5588e25a73abf4a227aa24a1e813b92abc031a73 Mon Sep 17 00:00:00 2001 From: Nassim Boutekedjiret Date: Tue, 19 Nov 2024 17:59:51 +0100 Subject: [PATCH 2/5] [exporter/datadog] Add configurable `reporter_period` for host metadata - Added a changelog entry --- ...ble-reporter-period-for-host-metadata.yaml | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 .chloggen/add-configurable-reporter-period-for-host-metadata.yaml diff --git a/.chloggen/add-configurable-reporter-period-for-host-metadata.yaml b/.chloggen/add-configurable-reporter-period-for-host-metadata.yaml new file mode 100644 index 000000000000..5c10536872ad --- /dev/null +++ b/.chloggen/add-configurable-reporter-period-for-host-metadata.yaml @@ -0,0 +1,27 @@ +# Use this changelog template to create an entry for release notes. + +# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' +change_type: enhancement + +# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver) +component: datadogexporter + +# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). +note: Add a configurable `reporter_period` parameter to the Datadog exporter’s host metadata configuration to allow users to specify the frequency at which host metadata is sent to Datadog. + +# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists. +issues: [36450] + +# (Optional) One or more lines of additional information to render under the primary note. +# These lines will be padded with 2 spaces and then inserted directly into the document. +# Use pipe (|) for multiline entries. +subtext: + +# If your change doesn't affect end users or the exported elements of any package, +# you should instead start your pull request title with [chore] or use the "Skip Changelog" label. +# Optional: The change log or logs in which this entry should be included. +# e.g. '[user]' or '[user, api]' +# Include 'user' if the change is relevant to end users. +# Include 'api' if there is a change to a library API. +# Default: '[user]' +change_logs: [] From d141124b2e5152a0d7bec5ead56e3c1cd3590cf8 Mon Sep 17 00:00:00 2001 From: Nassim Boutekedjiret Date: Tue, 19 Nov 2024 22:13:53 +0100 Subject: [PATCH 3/5] [exporter/datadog] Add configurable `reporter_period` for host metadata - Fixed formatting --- pkg/datadog/config/config.go | 2 +- pkg/datadog/config/config_test.go | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pkg/datadog/config/config.go b/pkg/datadog/config/config.go index a243e3c4f67b..a1e6597312c6 100644 --- a/pkg/datadog/config/config.go +++ b/pkg/datadog/config/config.go @@ -133,7 +133,7 @@ func (c *Config) Validate() error { return err } - if (c.HostMetadata.ReporterPeriod <= 0) { + if c.HostMetadata.ReporterPeriod <= 0 { return errors.New("reporter_period must be a positive duration") } diff --git a/pkg/datadog/config/config_test.go b/pkg/datadog/config/config_test.go index 3035b6fdab74..c40dcb4642a2 100644 --- a/pkg/datadog/config/config_test.go +++ b/pkg/datadog/config/config_test.go @@ -39,10 +39,10 @@ func TestValidate(t *testing.T) { }{ { name: "no api::key", - cfg: &Config{ + cfg: &Config{ HostMetadata: HostMetadataConfig{Enabled: true, ReporterPeriod: 10 * time.Minute}, }, - err: ErrUnsetAPIKey.Error(), + err: ErrUnsetAPIKey.Error(), }, { name: "invalid hostname", From 88aa1fbe2582436807518ee38fa08b640bfdb9f8 Mon Sep 17 00:00:00 2001 From: Nassim Boutekedjiret Date: Wed, 20 Nov 2024 00:25:56 +0100 Subject: [PATCH 4/5] [exporter/datadog] Add configurable `reporter_period` for host metadata - make gofmt --- pkg/datadog/config/config_test.go | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/pkg/datadog/config/config_test.go b/pkg/datadog/config/config_test.go index c40dcb4642a2..2d7cde743c54 100644 --- a/pkg/datadog/config/config_test.go +++ b/pkg/datadog/config/config_test.go @@ -47,8 +47,8 @@ func TestValidate(t *testing.T) { { name: "invalid hostname", cfg: &Config{ - API: APIConfig{Key: "notnull"}, - TagsConfig: TagsConfig{Hostname: "invalid_host"}, + API: APIConfig{Key: "notnull"}, + TagsConfig: TagsConfig{Hostname: "invalid_host"}, HostMetadata: HostMetadataConfig{Enabled: true, ReporterPeriod: 10 * time.Minute}, }, err: "hostname field is invalid: invalid_host is not RFC1123 compliant", @@ -65,16 +65,16 @@ func TestValidate(t *testing.T) { { name: "span name remapping valid", cfg: &Config{ - API: APIConfig{Key: "notnull"}, - Traces: TracesExporterConfig{TracesConfig: TracesConfig{SpanNameRemappings: map[string]string{"old.opentelemetryspan.name": "updated.name"}}}, + API: APIConfig{Key: "notnull"}, + Traces: TracesExporterConfig{TracesConfig: TracesConfig{SpanNameRemappings: map[string]string{"old.opentelemetryspan.name": "updated.name"}}}, HostMetadata: HostMetadataConfig{Enabled: true, ReporterPeriod: 10 * time.Minute}, }, }, { name: "span name remapping empty val", cfg: &Config{ - API: APIConfig{Key: "notnull"}, - Traces: TracesExporterConfig{TracesConfig: TracesConfig{SpanNameRemappings: map[string]string{"oldname": ""}}}, + API: APIConfig{Key: "notnull"}, + Traces: TracesExporterConfig{TracesConfig: TracesConfig{SpanNameRemappings: map[string]string{"oldname": ""}}}, HostMetadata: HostMetadataConfig{Enabled: true, ReporterPeriod: 10 * time.Minute}, }, err: "'' is not valid value for span name remapping", @@ -82,26 +82,25 @@ func TestValidate(t *testing.T) { { name: "span name remapping empty key", cfg: &Config{ - API: APIConfig{Key: "notnull"}, - Traces: TracesExporterConfig{TracesConfig: TracesConfig{SpanNameRemappings: map[string]string{"": "newname"}}}, + API: APIConfig{Key: "notnull"}, + Traces: TracesExporterConfig{TracesConfig: TracesConfig{SpanNameRemappings: map[string]string{"": "newname"}}}, HostMetadata: HostMetadataConfig{Enabled: true, ReporterPeriod: 10 * time.Minute}, - }, err: "'' is not valid key for span name remapping", }, { name: "ignore resources valid", cfg: &Config{ - API: APIConfig{Key: "notnull"}, - Traces: TracesExporterConfig{TracesConfig: TracesConfig{IgnoreResources: []string{"[123]"}}}, + API: APIConfig{Key: "notnull"}, + Traces: TracesExporterConfig{TracesConfig: TracesConfig{IgnoreResources: []string{"[123]"}}}, HostMetadata: HostMetadataConfig{Enabled: true, ReporterPeriod: 10 * time.Minute}, }, }, { name: "ignore resources missing bracket", cfg: &Config{ - API: APIConfig{Key: "notnull"}, - Traces: TracesExporterConfig{TracesConfig: TracesConfig{IgnoreResources: []string{"[123"}}}, + API: APIConfig{Key: "notnull"}, + Traces: TracesExporterConfig{TracesConfig: TracesConfig{IgnoreResources: []string{"[123"}}}, HostMetadata: HostMetadataConfig{Enabled: true, ReporterPeriod: 10 * time.Minute}, }, err: "'[123' is not valid resource filter regular expression", @@ -135,8 +134,8 @@ func TestValidate(t *testing.T) { { name: "With trace_buffer", cfg: &Config{ - API: APIConfig{Key: "notnull"}, - Traces: TracesExporterConfig{TraceBuffer: 10}, + API: APIConfig{Key: "notnull"}, + Traces: TracesExporterConfig{TraceBuffer: 10}, HostMetadata: HostMetadataConfig{Enabled: true, ReporterPeriod: 10 * time.Minute}, }, }, @@ -190,7 +189,7 @@ func TestValidate(t *testing.T) { { name: "Invalid reporter_period", cfg: &Config{ - API: APIConfig{Key: "notnull"}, + API: APIConfig{Key: "notnull"}, HostMetadata: HostMetadataConfig{Enabled: true, ReporterPeriod: 0}, }, err: "reporter_period must be a positive duration", From 2bbe04bf720914e2cba1cc2d63e82bad6d3d8117 Mon Sep 17 00:00:00 2001 From: Nassim Boutekedjiret Date: Mon, 2 Dec 2024 18:59:58 +0100 Subject: [PATCH 5/5] [exporter/datadog] Add configurable `reporter_period` for host metadata * Minimum reporter_period 5-minutes as suggested by @jade-guiton-dd --- pkg/datadog/config/config.go | 4 ++-- pkg/datadog/config/config_test.go | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/pkg/datadog/config/config.go b/pkg/datadog/config/config.go index a1e6597312c6..c1b40bd7cef0 100644 --- a/pkg/datadog/config/config.go +++ b/pkg/datadog/config/config.go @@ -133,8 +133,8 @@ func (c *Config) Validate() error { return err } - if c.HostMetadata.ReporterPeriod <= 0 { - return errors.New("reporter_period must be a positive duration") + if c.HostMetadata.ReporterPeriod < 5*time.Minute { + return errors.New("reporter_period must be 5 minutes or higher") } return nil diff --git a/pkg/datadog/config/config_test.go b/pkg/datadog/config/config_test.go index 2d7cde743c54..a76b2b5a5b9b 100644 --- a/pkg/datadog/config/config_test.go +++ b/pkg/datadog/config/config_test.go @@ -190,9 +190,9 @@ func TestValidate(t *testing.T) { name: "Invalid reporter_period", cfg: &Config{ API: APIConfig{Key: "notnull"}, - HostMetadata: HostMetadataConfig{Enabled: true, ReporterPeriod: 0}, + HostMetadata: HostMetadataConfig{Enabled: true, ReporterPeriod: 4 * time.Minute}, }, - err: "reporter_period must be a positive duration", + err: "reporter_period must be 5 minutes or higher", }, } for _, testInstance := range tests {