Skip to content

Commit

Permalink
pkg/otlp/{attributes,metrics}: Remove deprecated hostname preview fun…
Browse files Browse the repository at this point in the history
…ctions. (#55)

* pkg/otlp/{attributes,metrics}: Remove deprecated hostname preview functions.

The deprecated functions have been removed/replaced in the agent ([PR1](DataDog/datadog-agent#16159), [PR2](DataDog/datadog-agent#16541)) and the collector ([PR1](open-telemetry/opentelemetry-collector-contrib#20286), [PR2](open-telemetry/opentelemetry-collector-contrib#20872)).

* add issue # to changelog

* add missing line
  • Loading branch information
mackjmr authored Apr 24, 2023
1 parent 37a6383 commit be76739
Show file tree
Hide file tree
Showing 11 changed files with 61 additions and 455 deletions.
Original file line number Diff line number Diff line change
@@ -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: [55]

# (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)
Original file line number Diff line number Diff line change
@@ -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: [55]

# (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:
29 changes: 0 additions & 29 deletions pkg/otlp/attributes/azure/azure.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
Expand Down
53 changes: 0 additions & 53 deletions pkg/otlp/attributes/azure/azure_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -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",
Expand Down
18 changes: 0 additions & 18 deletions pkg/otlp/attributes/ec2/ec2.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
15 changes: 0 additions & 15 deletions pkg/otlp/attributes/ec2/ec2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
56 changes: 3 additions & 53 deletions pkg/otlp/attributes/gcp/gcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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) {
Expand Down
68 changes: 0 additions & 68 deletions pkg/otlp/attributes/gcp/gcp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Loading

0 comments on commit be76739

Please sign in to comment.