Skip to content

Commit 101ec6e

Browse files
NassimBtksbylica-splunk
authored andcommitted
[exporter/datadog] Add configurable reporter_period for host metadata (open-telemetry#36451)
<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue. Ex. Adding a feature - Explain what this achieves.--> #### Description This pull request introduces a new configurable parameter `reporter_period` for the Datadog exporter’s host metadata configuration. This enhancement allows users to specify the frequency at which host metadata is sent to Datadog. The changes span multiple files and include updates to configuration, factory methods, and test cases. Enhancements to Datadog exporter: * [`.chloggen/add-configurable-reporter-period-for-host-metadata.yaml`](diffhunk://#diff-e3e3c57c49d2a921abc8470bccafabf4d632b0dc142eb3e95b3b6fac57107a11R1-R27): Added a changelog entry for the new `reporter_period` parameter. * [`exporter/datadogexporter/examples/collector.yaml`](diffhunk://#diff-766be9823b8ec8b8de17e2c6c785d9f93e13b5a7e84ff441040077ab5e726a79R452-R456): Added documentation for the new `reporter_period` parameter in the example configuration file. * [`exporter/datadogexporter/factory.go`](diffhunk://#diff-c9e9f39ffda08a2af74c0d54d37f21e14cdb95c4136cdbe238de6be2bfe31389L127-R125): Updated the factory to use the `reporter_period` from the configuration instead of a hardcoded value. Configuration updates: * [`exporter/datadogexporter/internal/hostmetadata/config.go`](diffhunk://#diff-0c9f0862d61390add366aca3e30834a1e01f16a3865ef9aca61831cad3459f53R31-R32): Added `ReporterPeriod` to the `PusherConfig` struct. * [`pkg/datadog/config/config.go`](diffhunk://#diff-747858d4c8fea28a92227df09f17ebee01df63dad04812ac5d30a392c9970b73R136-R139): Added validation for the `reporter_period` to ensure it is a positive duration and set a default value. [[1]](diffhunk://#diff-747858d4c8fea28a92227df09f17ebee01df63dad04812ac5d30a392c9970b73R136-R139) [[2]](diffhunk://#diff-747858d4c8fea28a92227df09f17ebee01df63dad04812ac5d30a392c9970b73R347) Test case updates: * `exporter/datadogexporter/factory_test.go`, `exporter/datadogexporter/logs_exporter_test.go`, `exporter/datadogexporter/metrics_exporter_test.go`, `exporter/datadogexporter/traces_exporter_test.go`: Updated test cases to include the new `reporter_period` parameter. [[1]](diffhunk://#diff-c50b6d1f06d62a58b6422f3218526437c16554faa2b7fc8eee1d32c021f00ca4R311) [[2]](diffhunk://#diff-94f5b0119d06dbcfee20cd9b99a104ef208e027c166c463321670a5197e83714R233-R235) [[3]](diffhunk://#diff-005adb1774d2a402bdd7adf3b6aa150117bf6b3c0bb634bf2c68c6b33f0ce1b5L61-R63) [[4]](diffhunk://#diff-c19daad040b7310787c0012e5c660dc18a07ba16036d0eaa31a0e18c551d0ef3R148-R150) * [`pkg/datadog/config/config_test.go`](diffhunk://#diff-d3a3c19e78bbac07597c6210b4d051f4678df2752e06c82d0f040c52207c5970R97-R105): Added test cases to validate the `reporter_period` configuration. [[1]](diffhunk://#diff-d3a3c19e78bbac07597c6210b4d051f4678df2752e06c82d0f040c52207c5970R97-R105) [[2]](diffhunk://#diff-d3a3c19e78bbac07597c6210b4d051f4678df2752e06c82d0f040c52207c5970R186-R197) <!-- Issue number (e.g. open-telemetry#1234) or full URL to issue, if applicable. --> #### Link to tracking issue Fixes open-telemetry#36450 <!--Describe what testing was performed and which tests were added.--> #### Testing <!--Describe the documentation added.--> #### Documentation <!--Please delete paragraphs that you did not use before submitting.-->
1 parent 58e3435 commit 101ec6e

File tree

13 files changed

+177
-23
lines changed

13 files changed

+177
-23
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Use this changelog template to create an entry for release notes.
2+
3+
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
4+
change_type: enhancement
5+
6+
# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
7+
component: datadogexporter
8+
9+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
10+
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.
11+
12+
# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
13+
issues: [36450]
14+
15+
# (Optional) One or more lines of additional information to render under the primary note.
16+
# These lines will be padded with 2 spaces and then inserted directly into the document.
17+
# Use pipe (|) for multiline entries.
18+
subtext:
19+
20+
# If your change doesn't affect end users or the exported elements of any package,
21+
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
22+
# Optional: The change log or logs in which this entry should be included.
23+
# e.g. '[user]' or '[user, api]'
24+
# Include 'user' if the change is relevant to end users.
25+
# Include 'api' if there is a change to a library API.
26+
# Default: '[user]'
27+
change_logs: []

exporter/datadogexporter/examples/collector.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,11 @@ exporters:
449449
#
450450
# tags: ["team:infra", "<TAG_KEY>:<TAG_VALUE>"]
451451

452+
## @param reporter_period - duration - optional - default: 30m
453+
## The period at which the host metadata reporter sends host metadata to Datadog.
454+
## The default is 30 minutes.
455+
# reporter_period: 30m
456+
452457
## @param logs - custom object - optional
453458
## Logs exporter specific configuration.
454459
#

exporter/datadogexporter/factory.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,6 @@ func enableZorkianMetricExport() error {
7979
return featuregate.GlobalRegistry().Set(metricExportNativeClientFeatureGate.ID(), false)
8080
}
8181

82-
const metadataReporterPeriod = 30 * time.Minute
83-
8482
func consumeResource(metadataReporter *inframetadata.Reporter, res pcommon.Resource, logger *zap.Logger) {
8583
if err := metadataReporter.ConsumeResource(res); err != nil {
8684
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
124122
func (f *factory) Reporter(params exporter.Settings, pcfg hostmetadata.PusherConfig) (*inframetadata.Reporter, error) {
125123
f.onceReporter.Do(func() {
126124
pusher := hostmetadata.NewPusher(params, pcfg)
127-
f.reporter, f.reporterErr = inframetadata.NewReporter(params.Logger, pusher, metadataReporterPeriod)
125+
f.reporter, f.reporterErr = inframetadata.NewReporter(params.Logger, pusher, pcfg.ReporterPeriod)
128126
if f.reporterErr == nil {
129127
go func() {
130128
if err := f.reporter.Run(context.Background()); err != nil {

exporter/datadogexporter/factory_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,7 @@ func TestOnlyMetadata(t *testing.T) {
308308
HostMetadata: HostMetadataConfig{
309309
Enabled: true,
310310
HostnameSource: HostnameSourceFirstResource,
311+
ReporterPeriod: 30 * time.Minute,
311312
},
312313
}
313314
cfg.HostMetadata.SetSourceTimeout(50 * time.Millisecond)

exporter/datadogexporter/hostmetadata.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,6 @@ func newMetadataConfigfromConfig(cfg *Config) hostmetadata.PusherConfig {
1818
InsecureSkipVerify: cfg.TLSSetting.InsecureSkipVerify,
1919
ClientConfig: cfg.ClientConfig,
2020
RetrySettings: cfg.BackOffConfig,
21+
ReporterPeriod: cfg.HostMetadata.ReporterPeriod,
2122
}
2223
}

exporter/datadogexporter/internal/hostmetadata/config.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
package hostmetadata // import "github.com/open-telemetry/opentelemetry-collector-contrib/exporter/datadogexporter/internal/hostmetadata"
55

66
import (
7+
"time"
8+
79
"go.opentelemetry.io/collector/config/confighttp"
810
"go.opentelemetry.io/collector/config/configretry"
911
)
@@ -26,4 +28,6 @@ type PusherConfig struct {
2628
ClientConfig confighttp.ClientConfig
2729
// RetrySettings of exporter.
2830
RetrySettings configretry.BackOffConfig
31+
// ReporterPeriod is the period of the reporter goroutine.
32+
ReporterPeriod time.Duration
2933
}

exporter/datadogexporter/logs_exporter_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,9 @@ func TestLogsExporter(t *testing.T) {
230230
Endpoint: server.URL,
231231
},
232232
},
233+
HostMetadata: HostMetadataConfig{
234+
ReporterPeriod: 30 * time.Minute,
235+
},
233236
}
234237

235238
params := exportertest.NewNopSettings()
@@ -595,6 +598,9 @@ func TestLogsAgentExporter(t *testing.T) {
595598
CompressionLevel: 6,
596599
BatchWait: 1,
597600
},
601+
HostMetadata: HostMetadataConfig{
602+
ReporterPeriod: 30 * time.Minute,
603+
},
598604
}
599605
params := exportertest.NewNopSettings()
600606
f := NewFactory()

exporter/datadogexporter/metrics_exporter_test.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,9 @@ func TestNewExporter(t *testing.T) {
5858
CumulativeMonotonicMode: CumulativeMonotonicSumModeToDelta,
5959
},
6060
},
61-
HostMetadata: HostMetadataConfig{},
61+
HostMetadata: HostMetadataConfig{
62+
ReporterPeriod: 30 * time.Minute,
63+
},
6264
}
6365
cfg.HostMetadata.SetSourceTimeout(50 * time.Millisecond)
6466
params := exportertest.NewNopSettings()
@@ -437,6 +439,9 @@ func TestNewExporter_Zorkian(t *testing.T) {
437439
CumulativeMonotonicMode: CumulativeMonotonicSumModeToDelta,
438440
},
439441
},
442+
HostMetadata: HostMetadataConfig{
443+
ReporterPeriod: 30 * time.Minute,
444+
},
440445
}
441446
params := exportertest.NewNopSettings()
442447
f := NewFactory()

exporter/datadogexporter/traces_exporter_test.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,9 @@ func TestTracesSource(t *testing.T) {
145145
IgnoreResources: []string{},
146146
},
147147
},
148+
HostMetadata: HostMetadataConfig{
149+
ReporterPeriod: 30 * time.Minute,
150+
},
148151
}
149152

150153
assert := assert.New(t)
@@ -267,6 +270,9 @@ func TestTraceExporter(t *testing.T) {
267270
},
268271
TraceBuffer: 2,
269272
},
273+
HostMetadata: HostMetadataConfig{
274+
ReporterPeriod: 30 * time.Minute,
275+
},
270276
}
271277
cfg.Traces.SetFlushInterval(0.1)
272278

@@ -292,7 +298,11 @@ func TestNewTracesExporter(t *testing.T) {
292298
metricsServer := testutil.DatadogServerMock()
293299
defer metricsServer.Close()
294300

295-
cfg := &Config{}
301+
cfg := &Config{
302+
HostMetadata: HostMetadataConfig{
303+
ReporterPeriod: 30 * time.Minute,
304+
},
305+
}
296306
cfg.API.Key = "ddog_32_characters_long_api_key1"
297307
cfg.Metrics.TCPAddrConfig.Endpoint = metricsServer.URL
298308
params := exportertest.NewNopSettings()
@@ -320,10 +330,10 @@ func TestPushTraceData(t *testing.T) {
320330
Traces: TracesConfig{
321331
TCPAddrConfig: confignet.TCPAddrConfig{Endpoint: server.URL},
322332
},
323-
324333
HostMetadata: HostMetadataConfig{
325334
Enabled: true,
326335
HostnameSource: HostnameSourceFirstResource,
336+
ReporterPeriod: 30 * time.Minute,
327337
},
328338
}
329339

@@ -358,6 +368,9 @@ func TestPushTraceData_NewEnvConvention(t *testing.T) {
358368
Traces: TracesConfig{
359369
TCPAddrConfig: confignet.TCPAddrConfig{Endpoint: server.URL},
360370
},
371+
HostMetadata: HostMetadataConfig{
372+
ReporterPeriod: 30 * time.Minute,
373+
},
361374
}
362375
cfg.Traces.SetFlushInterval(0.1)
363376

pkg/datadog/config/config.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,10 @@ func (c *Config) Validate() error {
133133
return err
134134
}
135135

136+
if c.HostMetadata.ReporterPeriod < 5*time.Minute {
137+
return errors.New("reporter_period must be 5 minutes or higher")
138+
}
139+
136140
return nil
137141
}
138142

@@ -340,6 +344,7 @@ func CreateDefaultConfig() component.Config {
340344
HostMetadata: HostMetadataConfig{
341345
Enabled: true,
342346
HostnameSource: HostnameSourceConfigOrSystem,
347+
ReporterPeriod: 30 * time.Minute,
343348
},
344349
}
345350
}

0 commit comments

Comments
 (0)