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

Merged
Original file line number Diff line number Diff line change
@@ -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: []
5 changes: 5 additions & 0 deletions exporter/datadogexporter/examples/collector.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,11 @@ exporters:
#
# tags: ["team:infra", "<TAG_KEY>:<TAG_VALUE>"]

## @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.
#
Expand Down
4 changes: 1 addition & 3 deletions exporter/datadogexporter/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,6 @@ func enableZorkianMetricExport() error {
return featuregate.GlobalRegistry().Set(metricExportNativeClientFeatureGate.ID(), false)
}

const metadataReporterPeriod = 30 * time.Minute
mx-psi marked this conversation as resolved.
Show resolved Hide resolved

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))
Expand Down Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions exporter/datadogexporter/factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions exporter/datadogexporter/hostmetadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@ func newMetadataConfigfromConfig(cfg *Config) hostmetadata.PusherConfig {
InsecureSkipVerify: cfg.TLSSetting.InsecureSkipVerify,
ClientConfig: cfg.ClientConfig,
RetrySettings: cfg.BackOffConfig,
ReporterPeriod: cfg.HostMetadata.ReporterPeriod,
}
}
4 changes: 4 additions & 0 deletions exporter/datadogexporter/internal/hostmetadata/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand All @@ -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
}
6 changes: 6 additions & 0 deletions exporter/datadogexporter/logs_exporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,9 @@ func TestLogsExporter(t *testing.T) {
Endpoint: server.URL,
},
},
HostMetadata: HostMetadataConfig{
ReporterPeriod: 30 * time.Minute,
},
mx-psi marked this conversation as resolved.
Show resolved Hide resolved
}

params := exportertest.NewNopSettings()
Expand Down Expand Up @@ -595,6 +598,9 @@ func TestLogsAgentExporter(t *testing.T) {
CompressionLevel: 6,
BatchWait: 1,
},
HostMetadata: HostMetadataConfig{
ReporterPeriod: 30 * time.Minute,
},
}
params := exportertest.NewNopSettings()
f := NewFactory()
Expand Down
7 changes: 6 additions & 1 deletion exporter/datadogexporter/metrics_exporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -437,6 +439,9 @@ func TestNewExporter_Zorkian(t *testing.T) {
CumulativeMonotonicMode: CumulativeMonotonicSumModeToDelta,
},
},
HostMetadata: HostMetadataConfig{
ReporterPeriod: 30 * time.Minute,
},
}
params := exportertest.NewNopSettings()
f := NewFactory()
Expand Down
17 changes: 15 additions & 2 deletions exporter/datadogexporter/traces_exporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,9 @@ func TestTracesSource(t *testing.T) {
IgnoreResources: []string{},
},
},
HostMetadata: HostMetadataConfig{
ReporterPeriod: 30 * time.Minute,
},
}

assert := assert.New(t)
Expand Down Expand Up @@ -267,6 +270,9 @@ func TestTraceExporter(t *testing.T) {
},
TraceBuffer: 2,
},
HostMetadata: HostMetadataConfig{
ReporterPeriod: 30 * time.Minute,
},
}
cfg.Traces.SetFlushInterval(0.1)

Expand All @@ -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()
Expand Down Expand Up @@ -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,
},
}

Expand Down Expand Up @@ -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)

Expand Down
5 changes: 5 additions & 0 deletions pkg/datadog/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Copy link
Contributor

Choose a reason for hiding this comment

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

We would like to prevent users from accidentally spamming the backend by setting the reporter period too low. The Agent currently has a minimum of 5 minutes, so unless you believe there to be strong use cases for even lower values, I think we should do the same here.

Suggested change
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")

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, that makes sense, we can go with minimum 5 minutes. It's already very good like this. Thank you!

}

return nil
}

Expand Down Expand Up @@ -340,6 +344,7 @@ func CreateDefaultConfig() component.Config {
HostMetadata: HostMetadataConfig{
Enabled: true,
HostnameSource: HostnameSourceConfigOrSystem,
ReporterPeriod: 30 * time.Minute,
},
}
}
Loading