Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[exporter/datadog] Add configurable reporter_period for host metadata #36451

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

NassimBtk
Copy link

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:

Configuration updates:

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] [2] [3] [4]
  • pkg/datadog/config/config_test.go: Added test cases to validate the reporter_period configuration. [1] [2]

Link to tracking issue

Fixes #36450

Testing

Documentation

- 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 open-telemetry#36450
@@ -79,8 +79,6 @@ func enableZorkianMetricExport() error {
return featuregate.GlobalRegistry().Set(metricExportNativeClientFeatureGate.ID(), false)
}

const metadataReporterPeriod = 30 * time.Minute
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I asked the same question about this last year.. #24290 (comment)

@mx-psi is this a requirement from backend etc.?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, in my testing, I set the period to 2 minutes and observed no issues with the Datadog backend. By default, the period is set to 30 minutes, but users can adjust it to a shorter interval if they need more frequent updates.

@@ -230,6 +230,9 @@ func TestLogsExporter(t *testing.T) {
Endpoint: server.URL,
},
},
HostMetadata: HostMetadataConfig{
ReporterPeriod: 30 * time.Minute,
},
Copy link
Contributor

@jade-guiton-dd jade-guiton-dd Nov 21, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are 8 places where you add a HostMetadataConfig without Enabled: true. My understanding is that when creating the config struct manually, the default config is not taken into account, and this will set Enabled: false, making the whole section have no effect. Could you confirm whether sending host metadata is actually required in those tests? If no, you can probably forgo setting the HostMetadata field altogether.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are correct that when creating the config struct manually, the default config isn't built, and Enabled defaults to false. However, it's not the entire section that has no effect.

In the test, there's a call to exp, err := f.CreateLogs(ctx, params, cfg), which creates the logs exporter via func (f *factory) createLogsExporter. This will call func (f *factory) Reporter, which instantiates the reporter with inframetadata.NewReporter(params.Logger, pusher, pcfg.ReporterPeriod).

At this point, if pcfg.ReporterPeriod isn't initialized from the HostMetadataConfig, it defaults to 0. This causes a panic in the internal reporter of inframetadata because we can't initialize its time ticker time.NewTicker(period) with a period equal to 0.

So, even though Enabled is false, we still need to initialize ReporterPeriod to prevent a runtime panic. Removing the HostMetadata field altogether would lead to an uninitialized ReporterPeriod, causing the issue.

Now, you might wonder what the purpose of Enabled is. In fact, it's used later during the consumption of logs, as seen here: datadogexporter/logs_exporter.go#L104.

I hope this clarifies why we included the HostMetadataConfig without explicitly setting Enabled: true.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, thank you for the detailed explanation. In other words, it seems to me that Enabled: false disables the calls to Reporter.ConsumeX, so no host data is recorded from incoming signals, but it doesn't disable the creation of a Reporter in the first place, or the call to Reporter.Run, which periodically pushes that empty data to the backend, so a non-zero ReporterPeriod is still needed for the corresponding Ticker.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[exporter/datadog] Add Configurable Reporter Period for Host Metadata
4 participants