Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions .chloggen/k8sattributes_upgratesemconv.yaml
Original file line number Diff line number Diff line change
@@ -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: []
6 changes: 3 additions & 3 deletions processor/k8sattributesprocessor/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
}
Expand Down
6 changes: 3 additions & 3 deletions processor/k8sattributesprocessor/internal/kube/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 0 additions & 2 deletions processor/k8sattributesprocessor/internal/kube/kube.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 10 additions & 13 deletions processor/k8sattributesprocessor/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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.
Expand Down Expand Up @@ -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))
Expand All @@ -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))
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions processor/k8sattributesprocessor/options_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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())
}
Expand Down
2 changes: 1 addition & 1 deletion processor/k8sattributesprocessor/pod_association.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion processor/k8sattributesprocessor/pod_association_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down
8 changes: 4 additions & 4 deletions processor/k8sattributesprocessor/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
}
}
}
Expand Down
18 changes: 9 additions & 9 deletions processor/k8sattributesprocessor/processor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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",
},
Expand Down Expand Up @@ -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",
},
},
{
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
},
},
{
Expand Down Expand Up @@ -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"},
},
},
{
Expand Down Expand Up @@ -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",
},
},
{
Expand Down