Skip to content

Commit be0da30

Browse files
authored
Merge branch 'main' into main
2 parents 429713f + eb5b6cb commit be0da30

File tree

7 files changed

+53
-7
lines changed

7 files changed

+53
-7
lines changed

.chloggen/ddog-deprecate-cfg.yaml

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: deprecation
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: "Deprecate config `host_metadata::first_resource`"
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: [39069]
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: "Opt in to https://docs.datadoghq.com/opentelemetry/mapping/host_metadata/ instead. Its behavior is more predictable and provides more flexibility."
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/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ const (
134134
// hostname-like attributes, it will fallback to 'config_or_system' behavior (see below).
135135
//
136136
// Do not use this hostname source if receiving data from multiple hosts.
137-
HostnameSourceFirstResource HostnameSource = datadogconfig.HostnameSourceFirstResource
137+
HostnameSourceFirstResource HostnameSource = datadogconfig.HostnameSourceFirstResource //nolint:staticcheck
138138

139139
// Deprecated: [v0.110.0] Use `datadogconfig.HostnameSource` instead.
140140
// HostnameSourceConfigOrSystem picks the host metadata hostname from the 'hostname' setting,

exporter/datadogexporter/factory.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,9 @@ func (f *factory) createMetricsExporter(
319319
// Start the hostmetadata pusher once.
320320
// It sends the hostmetadata for the host where the collector is running.
321321
if cfg.HostMetadata.Enabled {
322+
if cfg.HostMetadata.HostnameSource == datadogconfig.HostnameSourceFirstResource { //nolint:staticcheck
323+
set.Logger.Warn("first_resource has no effect when serializer exporter is used for exporting metrics")
324+
}
322325
f.onceMetadata.Do(func() {
323326
attrs := pcommon.NewMap()
324327
go hostmetadata.RunPusher(ctx, set, pcfg, hostProvider, attrs, metadataReporter)

exporter/datadogexporter/metrics_exporter_test.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ func TestNewExporter(t *testing.T) {
6363
HostMetadata: HostMetadataConfig{
6464
Enabled: true,
6565
ReporterPeriod: 30 * time.Minute,
66-
HostnameSource: HostnameSourceFirstResource,
6766
},
6867
}
6968
cfg.HostMetadata.SetSourceTimeout(50 * time.Millisecond)
@@ -86,7 +85,7 @@ func TestNewExporter(t *testing.T) {
8685
err = exp.ConsumeMetrics(context.Background(), testMetrics)
8786
require.NoError(t, err)
8887
recvMetadata := <-server.MetadataChan
89-
assert.Equal(t, "custom-hostname", recvMetadata.InternalHostname)
88+
assert.NotEmpty(t, recvMetadata.InternalHostname)
9089
}
9190

9291
func TestNewExporter_Serializer(t *testing.T) {
@@ -115,7 +114,6 @@ func TestNewExporter_Serializer(t *testing.T) {
115114
HostMetadata: HostMetadataConfig{
116115
Enabled: true,
117116
ReporterPeriod: 30 * time.Minute,
118-
HostnameSource: HostnameSourceFirstResource,
119117
},
120118
}
121119
cfg.HostMetadata.SetSourceTimeout(50 * time.Millisecond)
@@ -501,7 +499,6 @@ func Test_metricsExporter_PushMetricsData(t *testing.T) {
501499
}
502500

503501
func TestNewExporter_Zorkian(t *testing.T) {
504-
t.Skip("skipping test, see https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/39064")
505502
if isMetricExportV2Enabled() {
506503
require.NoError(t, enableZorkianMetricExport())
507504
defer require.NoError(t, enableNativeMetricExport())
@@ -529,7 +526,6 @@ func TestNewExporter_Zorkian(t *testing.T) {
529526
HostMetadata: HostMetadataConfig{
530527
Enabled: true,
531528
ReporterPeriod: 30 * time.Minute,
532-
HostnameSource: HostnameSourceFirstResource,
533529
},
534530
}
535531
params := exportertest.NewNopSettings(metadata.Type)
@@ -550,7 +546,7 @@ func TestNewExporter_Zorkian(t *testing.T) {
550546
err = exp.ConsumeMetrics(context.Background(), testMetrics)
551547
require.NoError(t, err)
552548
recvMetadata := <-server.MetadataChan
553-
assert.Equal(t, "custom-hostname", recvMetadata.InternalHostname)
549+
assert.NotEmpty(t, recvMetadata.InternalHostname)
554550
}
555551

556552
func Test_metricsExporter_PushMetricsData_Zorkian(t *testing.T) {

pkg/datadog/config/config.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,10 @@ func (c *Config) Unmarshal(configMap *confmap.Conf) error {
274274
}
275275
c.warnings = append(c.warnings, renamingWarnings...)
276276

277+
if c.HostMetadata.HostnameSource == HostnameSourceFirstResource {
278+
c.warnings = append(c.warnings, errors.New("first_resource is deprecated, opt in to https://docs.datadoghq.com/opentelemetry/mapping/host_metadata/ instead"))
279+
}
280+
277281
c.API.Key = configopaque.String(strings.TrimSpace(string(c.API.Key)))
278282

279283
// If an endpoint is not explicitly set, override it based on the site.

pkg/datadog/config/config_warnings_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"testing"
88

99
"github.com/stretchr/testify/assert"
10+
"github.com/stretchr/testify/require"
1011
"go.opentelemetry.io/collector/confmap"
1112
)
1213

@@ -167,3 +168,16 @@ func TestPeerTags(t *testing.T) {
167168
})
168169
}
169170
}
171+
172+
func TestDeprecateHostnameSourceFirstResource(t *testing.T) {
173+
cfg := CreateDefaultConfig().(*Config)
174+
cfgMap := confmap.NewFromStringMap(map[string]any{
175+
"host_metadata": map[string]any{
176+
"hostname_source": "first_resource",
177+
},
178+
})
179+
err := cfgMap.Unmarshal(cfg)
180+
require.NoError(t, err)
181+
assert.Len(t, cfg.warnings, 1)
182+
assert.ErrorContains(t, cfg.warnings[0], "first_resource is deprecated, opt in to https://docs.datadoghq.com/opentelemetry/mapping/host_metadata/ instead")
183+
}

pkg/datadog/config/host.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ import (
1313
type HostnameSource string
1414

1515
const (
16+
// Deprecated: [v0.124.0] opt in to https://docs.datadoghq.com/opentelemetry/mapping/host_metadata/ instead
17+
//
1618
// HostnameSourceFirstResource picks the host metadata hostname from the resource
1719
// attributes on the first OTLP payload that gets to the exporter. If it is lacking any
1820
// hostname-like attributes, it will fallback to 'config_or_system' behavior (see below).

0 commit comments

Comments
 (0)