diff --git a/.chloggen/k8sattributes_upgratesemconv.yaml b/.chloggen/k8sattributes_upgratesemconv.yaml new file mode 100644 index 0000000000000..076274d9504ac --- /dev/null +++ b/.chloggen/k8sattributes_upgratesemconv.yaml @@ -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. receiver/filelog) +component: processor/k8sattributes + +# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). +note: Updates semconv version to v1.37.0 + +# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists. +issues: [44696] + +# (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: [] diff --git a/processor/k8sattributesprocessor/config.go b/processor/k8sattributesprocessor/config.go index 730f14034ddd2..a6777d3817b10 100644 --- a/processor/k8sattributesprocessor/config.go +++ b/processor/k8sattributesprocessor/config.go @@ -9,7 +9,7 @@ import ( "regexp" "time" - conventions "go.opentelemetry.io/otel/semconv/v1.6.1" + conventions "go.opentelemetry.io/otel/semconv/v1.37.0" "github.com/open-telemetry/opentelemetry-collector-contrib/internal/k8sconfig" "github.com/open-telemetry/opentelemetry-collector-contrib/processor/k8sattributesprocessor/internal/kube" @@ -90,10 +90,10 @@ func (cfg *Config) Validate() error { string(conventions.K8SCronJobNameKey), string(conventions.K8SCronJobUIDKey), string(conventions.K8SNodeNameKey), string(conventions.K8SNodeUIDKey), string(conventions.K8SContainerNameKey), string(conventions.ContainerIDKey), - string(conventions.ContainerImageNameKey), string(conventions.ContainerImageTagKey), + string(conventions.ContainerImageNameKey), containerImageTag, string(conventions.ServiceNamespaceKey), string(conventions.ServiceNameKey), string(conventions.ServiceVersionKey), string(conventions.ServiceInstanceIDKey), - containerImageRepoDigests, clusterUID: + string(conventions.ContainerImageRepoDigestsKey), string(conventions.K8SClusterUIDKey): default: return fmt.Errorf("\"%s\" is not a supported metadata field", field) } diff --git a/processor/k8sattributesprocessor/internal/kube/client.go b/processor/k8sattributesprocessor/internal/kube/client.go index a1929d49e3cfc..0fd05ba949e36 100644 --- a/processor/k8sattributesprocessor/internal/kube/client.go +++ b/processor/k8sattributesprocessor/internal/kube/client.go @@ -17,7 +17,7 @@ import ( "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/featuregate" "go.opentelemetry.io/otel/attribute" - conventions "go.opentelemetry.io/otel/semconv/v1.6.1" + conventions "go.opentelemetry.io/otel/semconv/v1.37.0" "go.uber.org/zap" apps_v1 "k8s.io/api/apps/v1" batch_v1 "k8s.io/api/batch/v1" @@ -913,12 +913,12 @@ func (c *WatchClient) extractPodAttributes(pod *api_v1.Pod) map[string]string { } if c.Rules.Node { - tags[tagNodeName] = pod.Spec.NodeName + tags[string(conventions.K8SNodeNameKey)] = pod.Spec.NodeName } if c.Rules.ClusterUID { if val, ok := c.Namespaces["kube-system"]; ok { - tags[tagClusterUID] = val.NamespaceUID + tags[string(conventions.K8SClusterUIDKey)] = val.NamespaceUID } else { c.logger.Debug("unable to find kube-system namespace, cluster uid will not be available") } diff --git a/processor/k8sattributesprocessor/internal/kube/client_test.go b/processor/k8sattributesprocessor/internal/kube/client_test.go index 4d836fca9f63c..d48e9c66e955e 100644 --- a/processor/k8sattributesprocessor/internal/kube/client_test.go +++ b/processor/k8sattributesprocessor/internal/kube/client_test.go @@ -15,7 +15,7 @@ import ( "github.com/stretchr/testify/require" "go.opentelemetry.io/collector/component/componenttest" "go.opentelemetry.io/collector/featuregate" - conventions "go.opentelemetry.io/otel/semconv/v1.6.1" + conventions "go.opentelemetry.io/otel/semconv/v1.37.0" "go.uber.org/zap" "go.uber.org/zap/zapcore" "go.uber.org/zap/zaptest/observer" diff --git a/processor/k8sattributesprocessor/internal/kube/kube.go b/processor/k8sattributesprocessor/internal/kube/kube.go index 7afa865852bd9..ef2ccf0989c44 100644 --- a/processor/k8sattributesprocessor/internal/kube/kube.go +++ b/processor/k8sattributesprocessor/internal/kube/kube.go @@ -19,10 +19,8 @@ import ( const ( podNodeField = "spec.nodeName" ignoreAnnotation string = "opentelemetry.io/k8s-processor/ignore" - tagNodeName = "k8s.node.name" tagStartTime = "k8s.pod.start_time" tagHostName = "k8s.pod.hostname" - tagClusterUID = "k8s.cluster.uid" // MetadataFromPod is used to specify to extract metadata/labels/annotations from pod MetadataFromPod = "pod" // MetadataFromNamespace is used to specify to extract metadata/labels/annotations from namespace diff --git a/processor/k8sattributesprocessor/options.go b/processor/k8sattributesprocessor/options.go index 7867fbb5c8998..c709f79307970 100644 --- a/processor/k8sattributesprocessor/options.go +++ b/processor/k8sattributesprocessor/options.go @@ -10,7 +10,7 @@ import ( "strings" "time" - conventions "go.opentelemetry.io/otel/semconv/v1.6.1" + conventions "go.opentelemetry.io/otel/semconv/v1.37.0" "k8s.io/apimachinery/pkg/selection" "github.com/open-telemetry/opentelemetry-collector-contrib/internal/k8sconfig" @@ -26,12 +26,9 @@ const ( metadataPodIP = "k8s.pod.ip" metadataPodStartTime = "k8s.pod.start_time" specPodHostName = "k8s.pod.hostname" - // TODO: use k8s.cluster.uid, container.image.repo_digests - // from semconv when available, - // replace clusterUID with string(conventions.K8SClusterUIDKey) - // replace containerRepoDigests with string(conventions.ContainerImageRepoDigestsKey) - clusterUID = "k8s.cluster.uid" - containerImageRepoDigests = "container.image.repo_digests" + + // TODO: Should be migrated to https://github.com/open-telemetry/semantic-conventions/blob/v1.38.0/model/container/registry.yaml#L48-L57 + containerImageTag = "container.image.tag" ) // option represents a configuration option that can be passes. @@ -60,7 +57,7 @@ func withPassthrough() option { func enabledAttributes() (attributes []string) { defaultConfig := metadata.DefaultResourceAttributesConfig() if defaultConfig.K8sClusterUID.Enabled { - attributes = append(attributes, clusterUID) + attributes = append(attributes, string(conventions.K8SClusterUIDKey)) } if defaultConfig.ContainerID.Enabled { attributes = append(attributes, string(conventions.ContainerIDKey)) @@ -69,10 +66,10 @@ func enabledAttributes() (attributes []string) { attributes = append(attributes, string(conventions.ContainerImageNameKey)) } if defaultConfig.ContainerImageRepoDigests.Enabled { - attributes = append(attributes, containerImageRepoDigests) + attributes = append(attributes, string(conventions.ContainerImageRepoDigestsKey)) } if defaultConfig.ContainerImageTag.Enabled { - attributes = append(attributes, string(conventions.ContainerImageTagKey)) + attributes = append(attributes, containerImageTag) } if defaultConfig.K8sContainerName.Enabled { attributes = append(attributes, string(conventions.K8SContainerNameKey)) @@ -204,11 +201,11 @@ func withExtractMetadata(fields ...string) option { p.rules.ContainerID = true case string(conventions.ContainerImageNameKey): p.rules.ContainerImageName = true - case containerImageRepoDigests: + case string(conventions.ContainerImageRepoDigestsKey): p.rules.ContainerImageRepoDigests = true - case string(conventions.ContainerImageTagKey): + case containerImageTag: p.rules.ContainerImageTag = true - case clusterUID: + case string(conventions.K8SClusterUIDKey): p.rules.ClusterUID = true case string(conventions.ServiceNamespaceKey): p.rules.ServiceNamespace = true diff --git a/processor/k8sattributesprocessor/options_test.go b/processor/k8sattributesprocessor/options_test.go index 4b0a8fc9594dd..cb4beb61fc2c5 100644 --- a/processor/k8sattributesprocessor/options_test.go +++ b/processor/k8sattributesprocessor/options_test.go @@ -10,7 +10,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "go.opentelemetry.io/collector/featuregate" - conventions "go.opentelemetry.io/otel/semconv/v1.6.1" + conventions "go.opentelemetry.io/otel/semconv/v1.37.0" "k8s.io/apimachinery/pkg/selection" "github.com/open-telemetry/opentelemetry-collector-contrib/internal/k8sconfig" @@ -66,7 +66,7 @@ func TestEnabledAttributes(t *testing.T) { string(conventions.K8SDeploymentNameKey), string(conventions.K8SNodeNameKey), string(conventions.ContainerImageNameKey), - string(conventions.ContainerImageTagKey), + containerImageTag, } assert.ElementsMatch(t, expected, enabledAttributes()) } diff --git a/processor/k8sattributesprocessor/pod_association.go b/processor/k8sattributesprocessor/pod_association.go index c83a9e08d1b12..eb00212d13ab1 100644 --- a/processor/k8sattributesprocessor/pod_association.go +++ b/processor/k8sattributesprocessor/pod_association.go @@ -9,7 +9,7 @@ import ( "go.opentelemetry.io/collector/client" "go.opentelemetry.io/collector/pdata/pcommon" - conventions "go.opentelemetry.io/otel/semconv/v1.6.1" + conventions "go.opentelemetry.io/otel/semconv/v1.37.0" "github.com/open-telemetry/opentelemetry-collector-contrib/internal/coreinternal/clientutil" "github.com/open-telemetry/opentelemetry-collector-contrib/processor/k8sattributesprocessor/internal/kube" diff --git a/processor/k8sattributesprocessor/pod_association_test.go b/processor/k8sattributesprocessor/pod_association_test.go index ead78baaa1e1a..aa25fa2b128be 100644 --- a/processor/k8sattributesprocessor/pod_association_test.go +++ b/processor/k8sattributesprocessor/pod_association_test.go @@ -11,7 +11,7 @@ import ( "github.com/stretchr/testify/require" "go.opentelemetry.io/collector/client" "go.opentelemetry.io/collector/pdata/pcommon" - conventions "go.opentelemetry.io/otel/semconv/v1.6.1" + conventions "go.opentelemetry.io/otel/semconv/v1.37.0" "github.com/open-telemetry/opentelemetry-collector-contrib/processor/k8sattributesprocessor/internal/kube" ) diff --git a/processor/k8sattributesprocessor/processor.go b/processor/k8sattributesprocessor/processor.go index bd4f101e02be4..fad75176f3693 100644 --- a/processor/k8sattributesprocessor/processor.go +++ b/processor/k8sattributesprocessor/processor.go @@ -16,7 +16,7 @@ import ( "go.opentelemetry.io/collector/pdata/pmetric" "go.opentelemetry.io/collector/pdata/pprofile" "go.opentelemetry.io/collector/pdata/ptrace" - conventions "go.opentelemetry.io/otel/semconv/v1.8.0" + conventions "go.opentelemetry.io/otel/semconv/v1.37.0" "go.uber.org/zap" "github.com/open-telemetry/opentelemetry-collector-contrib/internal/k8sconfig" @@ -311,7 +311,7 @@ func (kp *kubernetesprocessor) addContainerAttributes(attrs pcommon.Map, pod *ku setResourceAttribute(attrs, string(conventions.ContainerImageNameKey), containerSpec.ImageName) } if containerSpec.ImageTag != "" { - setResourceAttribute(attrs, string(conventions.ContainerImageTagKey), containerSpec.ImageTag) + setResourceAttribute(attrs, containerImageTag, containerSpec.ImageTag) } if containerSpec.ServiceInstanceID != "" { setResourceAttribute(attrs, string(conventions.ServiceInstanceIDKey), containerSpec.ServiceInstanceID) @@ -342,8 +342,8 @@ func (kp *kubernetesprocessor) addContainerAttributes(attrs pcommon.Map, pod *ku if _, found := attrs.Get(string(conventions.ContainerIDKey)); !found && containerStatus.ContainerID != "" { attrs.PutStr(string(conventions.ContainerIDKey), containerStatus.ContainerID) } - if _, found := attrs.Get(containerImageRepoDigests); !found && containerStatus.ImageRepoDigest != "" { - attrs.PutEmptySlice(containerImageRepoDigests).AppendEmpty().SetStr(containerStatus.ImageRepoDigest) + if _, found := attrs.Get(string(conventions.ContainerImageRepoDigestsKey)); !found && containerStatus.ImageRepoDigest != "" { + attrs.PutEmptySlice(string(conventions.ContainerImageRepoDigestsKey)).AppendEmpty().SetStr(containerStatus.ImageRepoDigest) } } } diff --git a/processor/k8sattributesprocessor/processor_test.go b/processor/k8sattributesprocessor/processor_test.go index e2a09bb91a187..9ff1c99c36394 100644 --- a/processor/k8sattributesprocessor/processor_test.go +++ b/processor/k8sattributesprocessor/processor_test.go @@ -27,7 +27,7 @@ import ( "go.opentelemetry.io/collector/processor" "go.opentelemetry.io/collector/processor/processortest" "go.opentelemetry.io/collector/processor/xprocessor" - conventions "go.opentelemetry.io/otel/semconv/v1.8.0" + conventions "go.opentelemetry.io/otel/semconv/v1.37.0" "github.com/open-telemetry/opentelemetry-collector-contrib/internal/k8sconfig" "github.com/open-telemetry/opentelemetry-collector-contrib/processor/k8sattributesprocessor/internal/kube" @@ -1112,7 +1112,7 @@ func TestProcessorAddContainerAttributes(t *testing.T) { string(conventions.K8SPodUIDKey): "19f651bc-73e4-410f-b3e9-f0241679d3b8", string(conventions.K8SContainerNameKey): "app", string(conventions.ContainerImageNameKey): "test/app", - string(conventions.ContainerImageTagKey): "1.0.1", + containerImageTag: "1.0.1", string(conventions.ServiceInstanceIDKey): "instance-1", string(conventions.ServiceVersionKey): "1.0.1", }, @@ -1151,7 +1151,7 @@ func TestProcessorAddContainerAttributes(t *testing.T) { string(conventions.ContainerIDKey): "767dc30d4fece77038e8ec2585a33471944d0b754659af7aa7e101181418f0dd", string(conventions.K8SContainerNameKey): "app", string(conventions.ContainerImageNameKey): "test/app", - string(conventions.ContainerImageTagKey): "1.0.1", + containerImageTag: "1.0.1", }, }, { @@ -1196,7 +1196,7 @@ func TestProcessorAddContainerAttributes(t *testing.T) { string(conventions.ContainerIDKey): "767dc30d4fece77038e8ec2585a33471944d0b754659af7aa7e101181418f0dd", string(conventions.K8SContainerNameKey): "app", string(conventions.ContainerImageNameKey): "test/app", - string(conventions.ContainerImageTagKey): "1.0.1", + containerImageTag: "1.0.1", string(conventions.ServiceInstanceIDKey): "explicit-instance", string(conventions.ServiceVersionKey): "explicit-version", string(conventions.ServiceNameKey): "explicit-name", @@ -1235,7 +1235,7 @@ func TestProcessorAddContainerAttributes(t *testing.T) { string(conventions.K8SPodUIDKey): "19f651bc-73e4-410f-b3e9-f0241679d3b8", string(conventions.K8SContainerNameKey): "app", string(conventions.ContainerImageNameKey): "test/app", - string(conventions.ContainerImageTagKey): "1.0.1", + containerImageTag: "1.0.1", }, }, { @@ -1314,9 +1314,9 @@ func TestProcessorAddContainerAttributes(t *testing.T) { withContainerName("app"), }, wantAttrs: map[string]any{ - kube.K8sIPLabelName: "1.1.1.1", - string(conventions.K8SContainerNameKey): "app", - containerImageRepoDigests: []string{"docker.io/otel/collector:1.2.3@sha256:deadbeef02"}, + kube.K8sIPLabelName: "1.1.1.1", + string(conventions.K8SContainerNameKey): "app", + string(conventions.ContainerImageRepoDigestsKey): []string{"docker.io/otel/collector:1.2.3@sha256:deadbeef02"}, }, }, { @@ -1407,7 +1407,7 @@ func TestProcessorAddContainerAttributes(t *testing.T) { string(conventions.K8SPodUIDKey): "19f651bc-73e4-410f-b3e9-f0241679d3b8", string(conventions.K8SContainerNameKey): "app", string(conventions.ContainerImageNameKey): "test/app", - string(conventions.ContainerImageTagKey): "1.0.1", + containerImageTag: "1.0.1", }, }, {