Skip to content

Commit 9cbe6fb

Browse files
authored
[k8sattributes] update to latest semconv (open-telemetry#44700)
<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue. Ex. Adding a feature - Explain what this achieves.--> #### Description Related to open-telemetry#22095. This PR verifies the analysis of open-telemetry/semantic-conventions#3120 which only identifies `container.image.tag` as a breaking change. For now I changed that to use a local reference and added a todo to handle this later. The rest of attributes can be referenced directly from the latest semconv. The `container.image.tag` transition will be handled by open-telemetry#44589. <!-- Issue number (e.g. open-telemetry#1234) or full URL to issue, if applicable. --> #### Link to tracking issue Fixes open-telemetry#44696 <!--Describe what testing was performed and which tests were added.--> #### Testing <!--Describe the documentation added.--> #### Documentation <!--Please delete paragraphs that you did not use before submitting.--> Signed-off-by: ChrsMark <[email protected]>
1 parent 9029734 commit 9cbe6fb

File tree

11 files changed

+61
-39
lines changed

11 files changed

+61
-39
lines changed
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: enhancement
5+
6+
# The name of the component, or a single word describing the area of concern, (e.g. receiver/filelog)
7+
component: processor/k8sattributes
8+
9+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
10+
note: Updates semconv version to v1.37.0
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: [44696]
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:
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: []

processor/k8sattributesprocessor/config.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
"regexp"
1010
"time"
1111

12-
conventions "go.opentelemetry.io/otel/semconv/v1.6.1"
12+
conventions "go.opentelemetry.io/otel/semconv/v1.37.0"
1313

1414
"github.com/open-telemetry/opentelemetry-collector-contrib/internal/k8sconfig"
1515
"github.com/open-telemetry/opentelemetry-collector-contrib/processor/k8sattributesprocessor/internal/kube"
@@ -90,10 +90,10 @@ func (cfg *Config) Validate() error {
9090
string(conventions.K8SCronJobNameKey), string(conventions.K8SCronJobUIDKey),
9191
string(conventions.K8SNodeNameKey), string(conventions.K8SNodeUIDKey),
9292
string(conventions.K8SContainerNameKey), string(conventions.ContainerIDKey),
93-
string(conventions.ContainerImageNameKey), string(conventions.ContainerImageTagKey),
93+
string(conventions.ContainerImageNameKey), containerImageTag,
9494
string(conventions.ServiceNamespaceKey), string(conventions.ServiceNameKey),
9595
string(conventions.ServiceVersionKey), string(conventions.ServiceInstanceIDKey),
96-
containerImageRepoDigests, clusterUID:
96+
string(conventions.ContainerImageRepoDigestsKey), string(conventions.K8SClusterUIDKey):
9797
default:
9898
return fmt.Errorf("\"%s\" is not a supported metadata field", field)
9999
}

processor/k8sattributesprocessor/internal/kube/client.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import (
1717
"go.opentelemetry.io/collector/component"
1818
"go.opentelemetry.io/collector/featuregate"
1919
"go.opentelemetry.io/otel/attribute"
20-
conventions "go.opentelemetry.io/otel/semconv/v1.6.1"
20+
conventions "go.opentelemetry.io/otel/semconv/v1.37.0"
2121
"go.uber.org/zap"
2222
apps_v1 "k8s.io/api/apps/v1"
2323
batch_v1 "k8s.io/api/batch/v1"
@@ -913,12 +913,12 @@ func (c *WatchClient) extractPodAttributes(pod *api_v1.Pod) map[string]string {
913913
}
914914

915915
if c.Rules.Node {
916-
tags[tagNodeName] = pod.Spec.NodeName
916+
tags[string(conventions.K8SNodeNameKey)] = pod.Spec.NodeName
917917
}
918918

919919
if c.Rules.ClusterUID {
920920
if val, ok := c.Namespaces["kube-system"]; ok {
921-
tags[tagClusterUID] = val.NamespaceUID
921+
tags[string(conventions.K8SClusterUIDKey)] = val.NamespaceUID
922922
} else {
923923
c.logger.Debug("unable to find kube-system namespace, cluster uid will not be available")
924924
}

processor/k8sattributesprocessor/internal/kube/client_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import (
1515
"github.com/stretchr/testify/require"
1616
"go.opentelemetry.io/collector/component/componenttest"
1717
"go.opentelemetry.io/collector/featuregate"
18-
conventions "go.opentelemetry.io/otel/semconv/v1.6.1"
18+
conventions "go.opentelemetry.io/otel/semconv/v1.37.0"
1919
"go.uber.org/zap"
2020
"go.uber.org/zap/zapcore"
2121
"go.uber.org/zap/zaptest/observer"

processor/k8sattributesprocessor/internal/kube/kube.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,8 @@ import (
1919
const (
2020
podNodeField = "spec.nodeName"
2121
ignoreAnnotation string = "opentelemetry.io/k8s-processor/ignore"
22-
tagNodeName = "k8s.node.name"
2322
tagStartTime = "k8s.pod.start_time"
2423
tagHostName = "k8s.pod.hostname"
25-
tagClusterUID = "k8s.cluster.uid"
2624
// MetadataFromPod is used to specify to extract metadata/labels/annotations from pod
2725
MetadataFromPod = "pod"
2826
// MetadataFromNamespace is used to specify to extract metadata/labels/annotations from namespace

processor/k8sattributesprocessor/options.go

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
"strings"
1111
"time"
1212

13-
conventions "go.opentelemetry.io/otel/semconv/v1.6.1"
13+
conventions "go.opentelemetry.io/otel/semconv/v1.37.0"
1414
"k8s.io/apimachinery/pkg/selection"
1515

1616
"github.com/open-telemetry/opentelemetry-collector-contrib/internal/k8sconfig"
@@ -26,12 +26,9 @@ const (
2626
metadataPodIP = "k8s.pod.ip"
2727
metadataPodStartTime = "k8s.pod.start_time"
2828
specPodHostName = "k8s.pod.hostname"
29-
// TODO: use k8s.cluster.uid, container.image.repo_digests
30-
// from semconv when available,
31-
// replace clusterUID with string(conventions.K8SClusterUIDKey)
32-
// replace containerRepoDigests with string(conventions.ContainerImageRepoDigestsKey)
33-
clusterUID = "k8s.cluster.uid"
34-
containerImageRepoDigests = "container.image.repo_digests"
29+
30+
// TODO: Should be migrated to https://github.com/open-telemetry/semantic-conventions/blob/v1.38.0/model/container/registry.yaml#L48-L57
31+
containerImageTag = "container.image.tag"
3532
)
3633

3734
// option represents a configuration option that can be passes.
@@ -60,7 +57,7 @@ func withPassthrough() option {
6057
func enabledAttributes() (attributes []string) {
6158
defaultConfig := metadata.DefaultResourceAttributesConfig()
6259
if defaultConfig.K8sClusterUID.Enabled {
63-
attributes = append(attributes, clusterUID)
60+
attributes = append(attributes, string(conventions.K8SClusterUIDKey))
6461
}
6562
if defaultConfig.ContainerID.Enabled {
6663
attributes = append(attributes, string(conventions.ContainerIDKey))
@@ -69,10 +66,10 @@ func enabledAttributes() (attributes []string) {
6966
attributes = append(attributes, string(conventions.ContainerImageNameKey))
7067
}
7168
if defaultConfig.ContainerImageRepoDigests.Enabled {
72-
attributes = append(attributes, containerImageRepoDigests)
69+
attributes = append(attributes, string(conventions.ContainerImageRepoDigestsKey))
7370
}
7471
if defaultConfig.ContainerImageTag.Enabled {
75-
attributes = append(attributes, string(conventions.ContainerImageTagKey))
72+
attributes = append(attributes, containerImageTag)
7673
}
7774
if defaultConfig.K8sContainerName.Enabled {
7875
attributes = append(attributes, string(conventions.K8SContainerNameKey))
@@ -204,11 +201,11 @@ func withExtractMetadata(fields ...string) option {
204201
p.rules.ContainerID = true
205202
case string(conventions.ContainerImageNameKey):
206203
p.rules.ContainerImageName = true
207-
case containerImageRepoDigests:
204+
case string(conventions.ContainerImageRepoDigestsKey):
208205
p.rules.ContainerImageRepoDigests = true
209-
case string(conventions.ContainerImageTagKey):
206+
case containerImageTag:
210207
p.rules.ContainerImageTag = true
211-
case clusterUID:
208+
case string(conventions.K8SClusterUIDKey):
212209
p.rules.ClusterUID = true
213210
case string(conventions.ServiceNamespaceKey):
214211
p.rules.ServiceNamespace = true

processor/k8sattributesprocessor/options_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
"github.com/stretchr/testify/assert"
1111
"github.com/stretchr/testify/require"
1212
"go.opentelemetry.io/collector/featuregate"
13-
conventions "go.opentelemetry.io/otel/semconv/v1.6.1"
13+
conventions "go.opentelemetry.io/otel/semconv/v1.37.0"
1414
"k8s.io/apimachinery/pkg/selection"
1515

1616
"github.com/open-telemetry/opentelemetry-collector-contrib/internal/k8sconfig"
@@ -66,7 +66,7 @@ func TestEnabledAttributes(t *testing.T) {
6666
string(conventions.K8SDeploymentNameKey),
6767
string(conventions.K8SNodeNameKey),
6868
string(conventions.ContainerImageNameKey),
69-
string(conventions.ContainerImageTagKey),
69+
containerImageTag,
7070
}
7171
assert.ElementsMatch(t, expected, enabledAttributes())
7272
}

processor/k8sattributesprocessor/pod_association.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99

1010
"go.opentelemetry.io/collector/client"
1111
"go.opentelemetry.io/collector/pdata/pcommon"
12-
conventions "go.opentelemetry.io/otel/semconv/v1.6.1"
12+
conventions "go.opentelemetry.io/otel/semconv/v1.37.0"
1313

1414
"github.com/open-telemetry/opentelemetry-collector-contrib/internal/coreinternal/clientutil"
1515
"github.com/open-telemetry/opentelemetry-collector-contrib/processor/k8sattributesprocessor/internal/kube"

processor/k8sattributesprocessor/pod_association_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
"github.com/stretchr/testify/require"
1212
"go.opentelemetry.io/collector/client"
1313
"go.opentelemetry.io/collector/pdata/pcommon"
14-
conventions "go.opentelemetry.io/otel/semconv/v1.6.1"
14+
conventions "go.opentelemetry.io/otel/semconv/v1.37.0"
1515

1616
"github.com/open-telemetry/opentelemetry-collector-contrib/processor/k8sattributesprocessor/internal/kube"
1717
)

processor/k8sattributesprocessor/processor.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import (
1616
"go.opentelemetry.io/collector/pdata/pmetric"
1717
"go.opentelemetry.io/collector/pdata/pprofile"
1818
"go.opentelemetry.io/collector/pdata/ptrace"
19-
conventions "go.opentelemetry.io/otel/semconv/v1.8.0"
19+
conventions "go.opentelemetry.io/otel/semconv/v1.37.0"
2020
"go.uber.org/zap"
2121

2222
"github.com/open-telemetry/opentelemetry-collector-contrib/internal/k8sconfig"
@@ -311,7 +311,7 @@ func (kp *kubernetesprocessor) addContainerAttributes(attrs pcommon.Map, pod *ku
311311
setResourceAttribute(attrs, string(conventions.ContainerImageNameKey), containerSpec.ImageName)
312312
}
313313
if containerSpec.ImageTag != "" {
314-
setResourceAttribute(attrs, string(conventions.ContainerImageTagKey), containerSpec.ImageTag)
314+
setResourceAttribute(attrs, containerImageTag, containerSpec.ImageTag)
315315
}
316316
if containerSpec.ServiceInstanceID != "" {
317317
setResourceAttribute(attrs, string(conventions.ServiceInstanceIDKey), containerSpec.ServiceInstanceID)
@@ -342,8 +342,8 @@ func (kp *kubernetesprocessor) addContainerAttributes(attrs pcommon.Map, pod *ku
342342
if _, found := attrs.Get(string(conventions.ContainerIDKey)); !found && containerStatus.ContainerID != "" {
343343
attrs.PutStr(string(conventions.ContainerIDKey), containerStatus.ContainerID)
344344
}
345-
if _, found := attrs.Get(containerImageRepoDigests); !found && containerStatus.ImageRepoDigest != "" {
346-
attrs.PutEmptySlice(containerImageRepoDigests).AppendEmpty().SetStr(containerStatus.ImageRepoDigest)
345+
if _, found := attrs.Get(string(conventions.ContainerImageRepoDigestsKey)); !found && containerStatus.ImageRepoDigest != "" {
346+
attrs.PutEmptySlice(string(conventions.ContainerImageRepoDigestsKey)).AppendEmpty().SetStr(containerStatus.ImageRepoDigest)
347347
}
348348
}
349349
}

0 commit comments

Comments
 (0)