From 3bd167e37c8cfbcd7ffb8f30a064e2cba8807f56 Mon Sep 17 00:00:00 2001 From: mackjmr Date: Fri, 21 Apr 2023 14:34:25 +0200 Subject: [PATCH] pkg/otlp/{attributes,metrics}: Remove deprecated hostname preview functions. The deprecated functions have been removed/replaced in the agent ([PR1](https://github.com/DataDog/datadog-agent/pull/16159), [PR2](https://github.com/DataDog/datadog-agent/pull/16541)) and the collector ([PR1](https://github.com/open-telemetry/opentelemetry-collector-contrib/pull/20286), [PR2](https://github.com/open-telemetry/opentelemetry-collector-contrib/pull/20872)). --- ...hostname-preview-functions-attributes.yaml | 23 +++ ...ed-hostname-preview-functions-metrics.yaml | 16 ++ pkg/otlp/attributes/azure/azure.go | 29 --- pkg/otlp/attributes/azure/azure_test.go | 53 ------ pkg/otlp/attributes/ec2/ec2.go | 18 -- pkg/otlp/attributes/ec2/ec2_test.go | 15 -- pkg/otlp/attributes/gcp/gcp.go | 56 +----- pkg/otlp/attributes/gcp/gcp_test.go | 68 ------- pkg/otlp/attributes/source.go | 62 ++----- pkg/otlp/attributes/source_test.go | 167 +----------------- pkg/otlp/metrics/config.go | 9 - 11 files changed, 61 insertions(+), 455 deletions(-) create mode 100755 .chloggen/mackjmr_remove-deprecated-hostname-preview-functions-attributes.yaml create mode 100644 .chloggen/mackjmr_remove-deprecated-hostname-preview-functions-metrics.yaml diff --git a/.chloggen/mackjmr_remove-deprecated-hostname-preview-functions-attributes.yaml b/.chloggen/mackjmr_remove-deprecated-hostname-preview-functions-attributes.yaml new file mode 100755 index 00000000..90e4328f --- /dev/null +++ b/.chloggen/mackjmr_remove-deprecated-hostname-preview-functions-attributes.yaml @@ -0,0 +1,23 @@ +# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' +change_type: breaking + +# The name of the component (e.g. pkg/quantile) +component: pkg/otlp/attributes + +# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). +note: Removed deprecated functions which use preview rules parameter. + +# The PR related to this change +issues: [] + +# (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: | + Full list of removed functions can be found below. + - [pkg/otlp/attributes] SourceFromAttributes (=> Replaced by SourceFromAttrs) + - [pkg/otlp/attributes/azure] HostnameFromAttributes (=> Replaced by HostnameFromAttrs) + - [pkg/otlp/attributes/azure] HostInfoFromAttributes (No replacement) + - [pkg/otlp/attributes/ec2] HostnameFromAttributes (=> Replaced by HostnameFromAttrs) + - [pkg/otlp/attributes/gcp] HostnameFromAttributes (=> Replaced by HostnameFromAttrs) + - [pkg/otlp/attributes/gcp] HostInfoFromAttributes (=> Replaced by HostInfoFromAttrs) diff --git a/.chloggen/mackjmr_remove-deprecated-hostname-preview-functions-metrics.yaml b/.chloggen/mackjmr_remove-deprecated-hostname-preview-functions-metrics.yaml new file mode 100644 index 00000000..01d30f06 --- /dev/null +++ b/.chloggen/mackjmr_remove-deprecated-hostname-preview-functions-metrics.yaml @@ -0,0 +1,16 @@ +# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' +change_type: breaking + +# The name of the component (e.g. pkg/quantile) +component: pkg/otlp/metrics + +# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). +note: Removed deprecated function WithPreviewHostnameFromAttributes. + +# The PR related to this change +issues: [] + +# (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: \ No newline at end of file diff --git a/pkg/otlp/attributes/azure/azure.go b/pkg/otlp/attributes/azure/azure.go index 1426f6ee..1b52838e 100644 --- a/pkg/otlp/attributes/azure/azure.go +++ b/pkg/otlp/attributes/azure/azure.go @@ -31,20 +31,6 @@ type HostInfo struct { HostAliases []string } -// HostInfoFromAttributes gets Azure host info from attributes following OpenTelemetry -// semantic conventions. -// Deprecated: AttributeHostID will be used as the hostname once the preview rule is stable. -func HostInfoFromAttributes(attrs pcommon.Map, usePreviewRules bool) (hostInfo *HostInfo) { - hostInfo = &HostInfo{} - - // Add Azure VM ID as a host alias if available for compatibility with Azure integration - if vmID, ok := attrs.Get(conventions.AttributeHostID); ok && !usePreviewRules { - hostInfo.HostAliases = append(hostInfo.HostAliases, vmID.Str()) - } - - return -} - // HostnameFromAttrs gets the Azure hostname from attributes. func HostnameFromAttrs(attrs pcommon.Map) (string, bool) { if vmID, ok := attrs.Get(conventions.AttributeHostID); ok { @@ -58,21 +44,6 @@ func HostnameFromAttrs(attrs pcommon.Map) (string, bool) { return "", false } -// HostnameFromAttributes gets the Azure hostname from attributes. -// Deprecated: HostnameFromAttributes is deprecated in favor of HostnameFromAttrs which removes parameter -// usePreviewRules. -func HostnameFromAttributes(attrs pcommon.Map, usePreviewRules bool) (string, bool) { - if vmID, ok := attrs.Get(conventions.AttributeHostID); usePreviewRules && ok { - return vmID.Str(), true - } - - if hostname, ok := attrs.Get(conventions.AttributeHostName); ok { - return hostname.Str(), true - } - - return "", false -} - // ClusterNameFromAttributes gets the Azure cluster name from attributes func ClusterNameFromAttributes(attrs pcommon.Map) (string, bool) { // Get cluster name from resource group from pkg/util/cloudprovider/azure:GetClusterName diff --git a/pkg/otlp/attributes/azure/azure_test.go b/pkg/otlp/attributes/azure/azure_test.go index 7389a114..e0df9515 100644 --- a/pkg/otlp/attributes/azure/azure_test.go +++ b/pkg/otlp/attributes/azure/azure_test.go @@ -17,7 +17,6 @@ import ( "testing" "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" "go.opentelemetry.io/collector/pdata/pcommon" conventions "go.opentelemetry.io/collector/semconv/v1.6.1" @@ -38,58 +37,6 @@ var ( testEmpty = testutils.NewAttributeMap(map[string]string{}) ) -func TestHostInfoFromAttributes(t *testing.T) { - tests := []struct { - name string - attrs pcommon.Map - usePreview bool - - ok bool - hostname string - aliases []string - }{ - { - name: "all attributes", - attrs: testAttrs, - - ok: true, - hostname: testHostname, - aliases: []string{testVMID}, - }, - { - name: "empty", - attrs: testEmpty, - }, - { - name: "all attributes with preview", - attrs: testAttrs, - usePreview: true, - - ok: true, - hostname: testVMID, - }, - { - name: "empty with preview", - attrs: testEmpty, - usePreview: true, - }, - } - - for _, testInstance := range tests { - t.Run(testInstance.name, func(t *testing.T) { - hostInfo := HostInfoFromAttributes(testInstance.attrs, testInstance.usePreview) - require.NotNil(t, hostInfo) - assert.ElementsMatch(t, testInstance.aliases, hostInfo.HostAliases) - hostname, ok := HostnameFromAttributes(testInstance.attrs, testInstance.usePreview) - - assert.Equal(t, testInstance.ok, ok) - if testInstance.ok || ok { - assert.Equal(t, testInstance.hostname, hostname) - } - }) - } -} - func TestClusterNameFromAttributes(t *testing.T) { cluster, ok := ClusterNameFromAttributes(testutils.NewAttributeMap(map[string]string{ AttributeResourceGroupName: "MC_aks-kenafeh_aks-kenafeh-eu_westeurope", diff --git a/pkg/otlp/attributes/ec2/ec2.go b/pkg/otlp/attributes/ec2/ec2.go index 67e96d8f..1aa80649 100644 --- a/pkg/otlp/attributes/ec2/ec2.go +++ b/pkg/otlp/attributes/ec2/ec2.go @@ -46,24 +46,6 @@ func isDefaultHostname(hostname string) bool { return false } -// HostnameFromAttributes gets a valid hostname from labels if -// available. -// Deprecated: HostnameFromAttributes is deprecated in favor of -// HostnameFromAttrs which removes parameter usePreviewRules. -func HostnameFromAttributes(attrs pcommon.Map, usePreviewRules bool) (string, bool) { - hostName, ok := attrs.Get(conventions.AttributeHostName) - // With hostname preview rules, return the EC2 instance id always. - if !usePreviewRules && ok && !isDefaultHostname(hostName.Str()) { - return hostName.Str(), true - } - - if hostID, ok := attrs.Get(conventions.AttributeHostID); ok { - return hostID.Str(), true - } - - return "", false -} - // HostnameFromAttrs gets a valid hostname from labels // if available func HostnameFromAttrs(attrs pcommon.Map) (string, bool) { diff --git a/pkg/otlp/attributes/ec2/ec2_test.go b/pkg/otlp/attributes/ec2/ec2_test.go index bee1d8fe..6bc36459 100644 --- a/pkg/otlp/attributes/ec2/ec2_test.go +++ b/pkg/otlp/attributes/ec2/ec2_test.go @@ -38,21 +38,6 @@ func TestDefaultHostname(t *testing.T) { assert.False(t, isDefaultHostname(customHost)) } -func TestHostnameFromAttributes(t *testing.T) { - attrs := testutils.NewAttributeMap(map[string]string{ - conventions.AttributeCloudProvider: conventions.AttributeCloudProviderAWS, - conventions.AttributeHostID: testInstanceID, - conventions.AttributeHostName: testIP, - }) - hostname, ok := HostnameFromAttributes(attrs, false) - assert.True(t, ok) - assert.Equal(t, hostname, testInstanceID) - - hostname, ok = HostnameFromAttributes(attrs, true) - assert.True(t, ok) - assert.Equal(t, hostname, testInstanceID) -} - func TestHostnameFromAttrs(t *testing.T) { t.Run("host id", func(t *testing.T) { attrs := testutils.NewAttributeMap(map[string]string{ diff --git a/pkg/otlp/attributes/gcp/gcp.go b/pkg/otlp/attributes/gcp/gcp.go index 9c62a156..81b9cdfd 100644 --- a/pkg/otlp/attributes/gcp/gcp.go +++ b/pkg/otlp/attributes/gcp/gcp.go @@ -28,7 +28,9 @@ type HostInfo struct { GCPTags []string } -func getGCPIntegrationHostname(attrs pcommon.Map) (string, bool) { +// HostnameFromAttrs gets the GCP Integration hostname from attributes +// if available. +func HostnameFromAttrs(attrs pcommon.Map) (string, bool) { hostName, ok := attrs.Get(conventions.AttributeHostName) if !ok { // We need the hostname. @@ -52,58 +54,6 @@ func getGCPIntegrationHostname(attrs pcommon.Map) (string, bool) { return alias, true } -// HostnameFromAttributes gets a valid hostname from labels -// if available. -// Deprecated: HostnameFromAttributes is deprecated in favor of -// HostnameFromAttrs which removes parameter usePreviewRules. -func HostnameFromAttributes(attrs pcommon.Map, usePreviewRules bool) (string, bool) { - if usePreviewRules { - return getGCPIntegrationHostname(attrs) - } - - if hostName, ok := attrs.Get(conventions.AttributeHostName); ok { - return hostName.Str(), true - } - - return "", false -} - -// HostnameFromAttrs gets a valid hostname from labels -// if available. -func HostnameFromAttrs(attrs pcommon.Map) (string, bool) { - return getGCPIntegrationHostname(attrs) -} - -// HostInfoFromAttributes gets GCP host info from attributes following -// OpenTelemetry semantic conventions. -// Deprecated: HostInfoFromAttributes is deprecated in favor of -// HostInfoFromAttrs which removes parameter usePreviewRules. -func HostInfoFromAttributes(attrs pcommon.Map, usePreviewRules bool) (hostInfo *HostInfo) { - hostInfo = &HostInfo{} - - if hostID, ok := attrs.Get(conventions.AttributeHostID); ok { - hostInfo.GCPTags = append(hostInfo.GCPTags, fmt.Sprintf("instance-id:%s", hostID.Str())) - } - - if cloudZone, ok := attrs.Get(conventions.AttributeCloudAvailabilityZone); ok { - hostInfo.GCPTags = append(hostInfo.GCPTags, fmt.Sprintf("zone:%s", cloudZone.Str())) - } - - if hostType, ok := attrs.Get(conventions.AttributeHostType); ok { - hostInfo.GCPTags = append(hostInfo.GCPTags, fmt.Sprintf("instance-type:%s", hostType.Str())) - } - - if cloudAccount, ok := attrs.Get(conventions.AttributeCloudAccountID); ok { - hostInfo.GCPTags = append(hostInfo.GCPTags, fmt.Sprintf("project:%s", cloudAccount.Str())) - } - - if alias, ok := getGCPIntegrationHostname(attrs); ok && !usePreviewRules { - hostInfo.HostAliases = append(hostInfo.HostAliases, alias) - } - - return -} - // HostInfoFromAttrs gets GCP host info from attributes following // OpenTelemetry semantic conventions func HostInfoFromAttrs(attrs pcommon.Map) (hostInfo *HostInfo) { diff --git a/pkg/otlp/attributes/gcp/gcp_test.go b/pkg/otlp/attributes/gcp/gcp_test.go index 1a23f1f7..8936390b 100644 --- a/pkg/otlp/attributes/gcp/gcp_test.go +++ b/pkg/otlp/attributes/gcp/gcp_test.go @@ -57,74 +57,6 @@ var ( testGCPIntegrationBadHostname = fmt.Sprintf("%s.%s", testBadHostname, testCloudAccount) ) -func TestInfoFromAttributes(t *testing.T) { - tags := []string{"instance-id:hostID", "zone:zone", "instance-type:machineType", "project:projectID"} - tests := []struct { - name string - attrs pcommon.Map - usePreview bool - - ok bool - hostname string - hostAliases []string - gcpTags []string - }{ - { - name: "no preview", - attrs: testFullMap, - ok: true, - hostname: testHostname, - hostAliases: []string{testGCPIntegrationHostname}, - gcpTags: tags, - }, - { - name: "no hostname, no preview", - attrs: testutils.NewAttributeMap(map[string]string{}), - }, - { - name: "preview", - attrs: testFullMap, - usePreview: true, - ok: true, - hostname: testGCPIntegrationHostname, - gcpTags: tags, - }, - { - name: "bad hostname, no preview", - attrs: testFullBadMap, - ok: true, - hostname: testBadHostname, - hostAliases: []string{testGCPIntegrationBadHostname}, - gcpTags: tags, - }, - { - name: "bad hostname, preview", - attrs: testFullBadMap, - usePreview: true, - ok: true, - hostname: testGCPIntegrationBadHostname, - gcpTags: tags, - }, - { - name: "no hostname, preview", - attrs: testutils.NewAttributeMap(map[string]string{}), - usePreview: true, - }, - } - - for _, testInstance := range tests { - t.Run(testInstance.name, func(t *testing.T) { - hostname, ok := HostnameFromAttributes(testInstance.attrs, testInstance.usePreview) - assert.Equal(t, testInstance.ok, ok) - assert.Equal(t, testInstance.hostname, hostname) - - hostInfo := HostInfoFromAttributes(testInstance.attrs, testInstance.usePreview) - assert.ElementsMatch(t, testInstance.hostAliases, hostInfo.HostAliases) - assert.ElementsMatch(t, testInstance.gcpTags, hostInfo.GCPTags) - }) - } -} - func TestInfoFromAttrs(t *testing.T) { tags := []string{"instance-id:hostID", "zone:zone", "instance-type:machineType", "project:projectID"} tests := []struct { diff --git a/pkg/otlp/attributes/source.go b/pkg/otlp/attributes/source.go index b22971d3..4cba3b53 100644 --- a/pkg/otlp/attributes/source.go +++ b/pkg/otlp/attributes/source.go @@ -50,18 +50,16 @@ func getClusterName(attrs pcommon.Map) (string, bool) { // // 1. a custom Datadog hostname provided by the "datadog.host.name" attribute // -// 2. the Kubernetes node name (and cluster name if available), +// 2. cloud provider specific hostname for AWS, Azure or GCP, // -// 3. cloud provider specific hostname for AWS or GCP +// 3. the Kubernetes node name (and cluster name if available), // -// 4. the container ID, +// 4. the cloud provider host ID and // -// 5. the cloud provider host ID and -// -// 6. the host.name attribute. +// 5. the host.name attribute. // // It returns a boolean value indicated if any name was found -func hostnameFromAttributes(attrs pcommon.Map, usePreviewRules bool) (string, bool) { +func hostnameFromAttributes(attrs pcommon.Map) (string, bool) { // Check if the host is localhost or 0.0.0.0, if so discard it. // We don't do the more strict validation done for metadata, // to avoid breaking users existing invalid-but-accepted hostnames. @@ -74,7 +72,7 @@ func hostnameFromAttributes(attrs pcommon.Map, usePreviewRules bool) (string, bo "ip6-localhost": {}, } - candidateHost, ok := unsanitizedHostnameFromAttributes(attrs, usePreviewRules) + candidateHost, ok := unsanitizedHostnameFromAttributes(attrs) if _, invalid := invalidHosts[candidateHost]; invalid { return "", false } @@ -93,7 +91,7 @@ func k8sHostnameFromAttributes(attrs pcommon.Map) (string, bool) { return node.Str(), true } -func unsanitizedHostnameFromAttributes(attrs pcommon.Map, usePreviewRules bool) (string, bool) { +func unsanitizedHostnameFromAttributes(attrs pcommon.Map) (string, bool) { // Custom hostname: useful for overriding in k8s/cloud envs if customHostname, ok := attrs.Get(AttributeDatadogHostname); ok { return customHostname.Str(), true @@ -104,28 +102,19 @@ func unsanitizedHostnameFromAttributes(attrs pcommon.Map, usePreviewRules bool) return "", false } - // Kubernetes: node-cluster if cluster name is available, else node - k8sName, k8sOk := k8sHostnameFromAttributes(attrs) - - // If not using the preview rules, return the Kubernetes node name - // before cloud provider names to preserve the current behavior. - if !usePreviewRules && k8sOk { - return k8sName, true - } - cloudProvider, ok := attrs.Get(conventions.AttributeCloudProvider) switch { case ok && cloudProvider.Str() == conventions.AttributeCloudProviderAWS: - return ec2.HostnameFromAttributes(attrs, usePreviewRules) + return ec2.HostnameFromAttrs(attrs) case ok && cloudProvider.Str() == conventions.AttributeCloudProviderGCP: - return gcp.HostnameFromAttributes(attrs, usePreviewRules) + return gcp.HostnameFromAttrs(attrs) case ok && cloudProvider.Str() == conventions.AttributeCloudProviderAzure: - return azure.HostnameFromAttributes(attrs, usePreviewRules) + return azure.HostnameFromAttrs(attrs) } - // If using the preview rules, the cloud provider names take precedence. - // This is to report the same hostname as Datadog cloud integrations. - if usePreviewRules && k8sOk { + // Kubernetes: node-cluster if cluster name is available, else node + k8sName, k8sOk := k8sHostnameFromAttributes(attrs) + if k8sOk { return k8sName, true } @@ -139,32 +128,9 @@ func unsanitizedHostnameFromAttributes(attrs pcommon.Map, usePreviewRules bool) return hostName.Str(), true } - if !usePreviewRules { - // container id (e.g. from Docker) - if containerID, ok := attrs.Get(conventions.AttributeContainerID); ok { - return containerID.Str(), true - } - } - return "", false } -// SourceFromAttributes gets a telemetry signal source from its attributes. -// Deprecated: SourceFromAttributes is deprecated in favor of SourceFromAttrs which removes parameter usePreviewRules. -func SourceFromAttributes(attrs pcommon.Map, usePreviewRules bool) (source.Source, bool) { - if launchType, ok := attrs.Get(conventions.AttributeAWSECSLaunchtype); ok && launchType.Str() == conventions.AttributeAWSECSLaunchtypeFargate { - if taskARN, ok := attrs.Get(conventions.AttributeAWSECSTaskARN); ok { - return source.Source{Kind: source.AWSECSFargateKind, Identifier: taskARN.Str()}, true - } - } - - if host, ok := hostnameFromAttributes(attrs, usePreviewRules); ok { - return source.Source{Kind: source.HostnameKind, Identifier: host}, true - } - - return source.Source{}, false -} - // SourceFromAttrs gets a telemetry signal source from its attributes. func SourceFromAttrs(attrs pcommon.Map) (source.Source, bool) { if launchType, ok := attrs.Get(conventions.AttributeAWSECSLaunchtype); ok && launchType.Str() == conventions.AttributeAWSECSLaunchtypeFargate { @@ -173,7 +139,7 @@ func SourceFromAttrs(attrs pcommon.Map) (source.Source, bool) { } } - if host, ok := hostnameFromAttributes(attrs, true); ok { + if host, ok := hostnameFromAttributes(attrs); ok { return source.Source{Kind: source.HostnameKind, Identifier: host}, true } diff --git a/pkg/otlp/attributes/source_test.go b/pkg/otlp/attributes/source_test.go index 14b22692..1df856e3 100644 --- a/pkg/otlp/attributes/source_test.go +++ b/pkg/otlp/attributes/source_test.go @@ -38,151 +38,6 @@ const ( testGCPIntegrationHostname = testHostName + "." + testCloudAccount ) -func TestSourceFromAttributes(t *testing.T) { - tests := []struct { - name string - attrs pcommon.Map - usePreview bool - - ok bool - src source.Source - }{ - { - name: "custom hostname", - attrs: testutils.NewAttributeMap(map[string]string{ - AttributeDatadogHostname: testCustomName, - AttributeK8sNodeName: testNodeName, - conventions.AttributeK8SClusterName: testClusterName, - conventions.AttributeContainerID: testContainerID, - conventions.AttributeHostID: testHostID, - conventions.AttributeHostName: testHostName, - }), - ok: true, - src: source.Source{Kind: source.HostnameKind, Identifier: testCustomName}, - }, - { - name: "container ID", - attrs: testutils.NewAttributeMap(map[string]string{ - conventions.AttributeContainerID: testContainerID, - }), - ok: true, - src: source.Source{Kind: source.HostnameKind, Identifier: testContainerID}, - }, - { - name: "container ID, preview", - attrs: testutils.NewAttributeMap(map[string]string{ - conventions.AttributeContainerID: testContainerID, - }), - usePreview: true, - }, - { - name: "AWS EC2", - attrs: testutils.NewAttributeMap(map[string]string{ - conventions.AttributeCloudProvider: conventions.AttributeCloudProviderAWS, - conventions.AttributeHostID: testHostID, - conventions.AttributeHostName: testHostName, - }), - ok: true, - src: source.Source{Kind: source.HostnameKind, Identifier: testHostName}, - }, - { - name: "AWS EC2, preview", - attrs: testutils.NewAttributeMap(map[string]string{ - conventions.AttributeCloudProvider: conventions.AttributeCloudProviderAWS, - conventions.AttributeHostID: testHostID, - conventions.AttributeHostName: testHostName, - }), - ok: true, - src: source.Source{Kind: source.HostnameKind, Identifier: testHostID}, - usePreview: true, - }, - { - name: "ECS Fargate", - attrs: testutils.NewAttributeMap(map[string]string{ - conventions.AttributeCloudProvider: conventions.AttributeCloudProviderAWS, - conventions.AttributeCloudPlatform: conventions.AttributeCloudPlatformAWSECS, - conventions.AttributeAWSECSTaskARN: "example-task-ARN", - conventions.AttributeAWSECSTaskFamily: "example-task-family", - conventions.AttributeAWSECSTaskRevision: "example-task-revision", - conventions.AttributeAWSECSLaunchtype: conventions.AttributeAWSECSLaunchtypeFargate, - }), - ok: true, - src: source.Source{Kind: source.AWSECSFargateKind, Identifier: "example-task-ARN"}, - }, - { - name: "GCP", - attrs: testutils.NewAttributeMap(map[string]string{ - conventions.AttributeCloudProvider: conventions.AttributeCloudProviderGCP, - conventions.AttributeHostID: testHostID, - conventions.AttributeHostName: testGCPHostname, - }), - ok: true, - src: source.Source{Kind: source.HostnameKind, Identifier: testGCPHostname}, - }, - { - name: "GCP, preview", - attrs: testutils.NewAttributeMap(map[string]string{ - conventions.AttributeCloudProvider: conventions.AttributeCloudProviderGCP, - conventions.AttributeHostID: testHostID, - conventions.AttributeHostName: testGCPHostname, - conventions.AttributeCloudAccountID: testCloudAccount, - }), - usePreview: true, - ok: true, - src: source.Source{Kind: source.HostnameKind, Identifier: testGCPIntegrationHostname}, - }, - { - name: "azure", - attrs: testutils.NewAttributeMap(map[string]string{ - conventions.AttributeCloudProvider: conventions.AttributeCloudProviderAzure, - conventions.AttributeHostID: testHostID, - conventions.AttributeHostName: testHostName, - }), - ok: true, - src: source.Source{Kind: source.HostnameKind, Identifier: testHostName}, - }, - { - name: "azure, preview", - attrs: testutils.NewAttributeMap(map[string]string{ - conventions.AttributeCloudProvider: conventions.AttributeCloudProviderAzure, - conventions.AttributeHostID: testHostID, - conventions.AttributeHostName: testHostName, - }), - usePreview: true, - ok: true, - src: source.Source{Kind: source.HostnameKind, Identifier: testHostID}, - }, - { - name: "host id v. hostname", - attrs: testutils.NewAttributeMap(map[string]string{ - conventions.AttributeHostID: testHostID, - conventions.AttributeHostName: testHostName, - }), - ok: true, - src: source.Source{Kind: source.HostnameKind, Identifier: testHostID}, - }, - { - name: "no hostname", - attrs: testutils.NewAttributeMap(map[string]string{}), - }, - { - name: "localhost", - attrs: testutils.NewAttributeMap(map[string]string{ - AttributeDatadogHostname: "127.0.0.1", - }), - }, - } - - for _, testInstance := range tests { - t.Run(testInstance.name, func(t *testing.T) { - source, ok := SourceFromAttributes(testInstance.attrs, testInstance.usePreview) - assert.Equal(t, testInstance.ok, ok) - assert.Equal(t, testInstance.src, source) - }) - - } -} - func TestSourceFromAttrs(t *testing.T) { tests := []struct { name string @@ -335,7 +190,7 @@ func TestHostnameKubernetes(t *testing.T) { conventions.AttributeHostID: testHostID, conventions.AttributeHostName: testHostName, }) - hostname, ok := hostnameFromAttributes(attrs, false) + hostname, ok := hostnameFromAttributes(attrs) assert.True(t, ok) assert.Equal(t, hostname, "nodeName-clusterName") @@ -346,23 +201,11 @@ func TestHostnameKubernetes(t *testing.T) { conventions.AttributeHostID: testHostID, conventions.AttributeHostName: testHostName, }) - hostname, ok = hostnameFromAttributes(attrs, false) - assert.True(t, ok) - assert.Equal(t, hostname, "nodeName") - - // Node name, no cluster name, AWS EC2, no preview - attrs = testutils.NewAttributeMap(map[string]string{ - AttributeK8sNodeName: testNodeName, - conventions.AttributeContainerID: testContainerID, - conventions.AttributeHostID: testHostID, - conventions.AttributeHostName: testHostName, - conventions.AttributeCloudProvider: conventions.AttributeCloudProviderAWS, - }) - hostname, ok = hostnameFromAttributes(attrs, false) + hostname, ok = hostnameFromAttributes(attrs) assert.True(t, ok) assert.Equal(t, hostname, "nodeName") - // Node name, no cluster name, AWS EC2, preview + // Node name, no cluster name, AWS EC2 attrs = testutils.NewAttributeMap(map[string]string{ AttributeK8sNodeName: testNodeName, conventions.AttributeContainerID: testContainerID, @@ -370,7 +213,7 @@ func TestHostnameKubernetes(t *testing.T) { conventions.AttributeHostName: testHostName, conventions.AttributeCloudProvider: conventions.AttributeCloudProviderAWS, }) - hostname, ok = hostnameFromAttributes(attrs, true) + hostname, ok = hostnameFromAttributes(attrs) assert.True(t, ok) assert.Equal(t, hostname, testHostID) @@ -381,7 +224,7 @@ func TestHostnameKubernetes(t *testing.T) { conventions.AttributeHostID: testHostID, conventions.AttributeHostName: testHostName, }) - hostname, ok = hostnameFromAttributes(attrs, false) + hostname, ok = hostnameFromAttributes(attrs) assert.True(t, ok) // cluster name gets ignored, fallback to next option assert.Equal(t, hostname, testHostID) diff --git a/pkg/otlp/metrics/config.go b/pkg/otlp/metrics/config.go index 62d81089..51fa8b04 100644 --- a/pkg/otlp/metrics/config.go +++ b/pkg/otlp/metrics/config.go @@ -68,15 +68,6 @@ func WithFallbackSourceProvider(provider source.Provider) TranslatorOption { } } -// WithPreviewHostnameFromAttributes enables the preview hostname algorithm. -// -// Deprecated: The hostname preview is always enabled. This is a no-op. -func WithPreviewHostnameFromAttributes() TranslatorOption { - return func(t *translatorConfig) error { - return nil - } -} - // WithQuantiles enables quantiles exporting for summary metrics. func WithQuantiles() TranslatorOption { return func(t *translatorConfig) error {