diff --git a/CHANGELOG.md b/CHANGELOG.md index 845822a669bb..62c3a31bc48e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,7 +13,7 @@ ## 💡 Enhancements 💡 -- `k8sattributes` processor: add container metadata enrichment (#5467) +- `k8sattributes` processor: add container metadata enrichment (#5467, #5572) ## v0.36.0 diff --git a/examples/kubernetes/README.md b/examples/kubernetes/README.md index 3aba4248c4f1..dec70d63c596 100644 --- a/examples/kubernetes/README.md +++ b/examples/kubernetes/README.md @@ -13,7 +13,7 @@ Switch to this directory and run following command: `kubectl apply -n __//.log` +`/var/log/pods/__//.log` You can use it to manage from which containers do you want to include and exclude logs. diff --git a/examples/kubernetes/otel-collector-config.yml b/examples/kubernetes/otel-collector-config.yml index e220634ef77f..684ce7aecba6 100644 --- a/examples/kubernetes/otel-collector-config.yml +++ b/examples/kubernetes/otel-collector-config.yml @@ -46,7 +46,7 @@ receivers: # Extract metadata from file path - type: regex_parser id: extract_metadata_from_filepath - regex: '^.*\/(?P[^_]+)_(?P[^_]+)_(?P[a-f0-9\-]{36})\/(?P[^\._]+)\/(?P\d+)\.log$' + regex: '^.*\/(?P[^_]+)_(?P[^_]+)_(?P[a-f0-9\-]{36})\/(?P[^\._]+)\/(?P\d+)\.log$' parse_from: $$attributes["file.path"] # Move out attributes to Attributes - type: metadata @@ -55,7 +55,7 @@ receivers: k8s.container.name: 'EXPR($.container_name)' k8s.namespace.name: 'EXPR($.namespace)' k8s.pod.name: 'EXPR($.pod_name)' - run_id: 'EXPR($.run_id)' + k8s.container.restart_count: 'EXPR($.restart_count)' k8s.pod.uid: 'EXPR($.uid)' # Clean up log body - type: restructure diff --git a/examples/kubernetes/otel-collector.yaml b/examples/kubernetes/otel-collector.yaml index 45097e3266cc..410bb2b707bf 100644 --- a/examples/kubernetes/otel-collector.yaml +++ b/examples/kubernetes/otel-collector.yaml @@ -53,7 +53,7 @@ data: # Extract metadata from file path - type: regex_parser id: extract_metadata_from_filepath - regex: '^.*\/(?P[^_]+)_(?P[^_]+)_(?P[a-f0-9\-]{36})\/(?P[^\._]+)\/(?P\d+)\.log$' + regex: '^.*\/(?P[^_]+)_(?P[^_]+)_(?P[a-f0-9\-]{36})\/(?P[^\._]+)\/(?P\d+)\.log$' parse_from: $$attributes["file.path"] # Move out attributes to Attributes - type: metadata @@ -62,7 +62,7 @@ data: k8s.container.name: 'EXPR($.container_name)' k8s.namespace.name: 'EXPR($.namespace)' k8s.pod.name: 'EXPR($.pod_name)' - run_id: 'EXPR($.run_id)' + k8s.container.restart_count: 'EXPR($.restart_count)' k8s.pod.uid: 'EXPR($.uid)' # Clean up log body - type: restructure diff --git a/processor/k8sattributesprocessor/doc.go b/processor/k8sattributesprocessor/doc.go index af78455787f4..b0810d465b97 100644 --- a/processor/k8sattributesprocessor/doc.go +++ b/processor/k8sattributesprocessor/doc.go @@ -55,12 +55,12 @@ // so likely it won't be set as an attribute. // The following container level attributes require additional attributes to identify a particular container in a pod: -// 1. Container spec attributes - will be set only if container identifying attribute `container.name` is set +// 1. Container spec attributes - will be set only if container identifying attribute `k8s.container.name` is set // as a resource attribute (similar to all other attributes, pod has to be identified as well): // - container.image.name // - container.image.tag -// 2. Container status attributes - in addition to pod identifier and `container.name` attribute, these attributes -// require identifier of a particular container run set as `run_id` in resource attributes: +// 2. Container status attributes - in addition to pod identifier and `k8s.container.name` attribute, these attributes +// require identifier of a particular container run set as `k8s.container.restart_count` in resource attributes: // - container.id //The k8sattributesprocessor can be used for automatic tagging of spans, metrics and logs with k8s labels and annotations from pods and namespaces. diff --git a/processor/k8sattributesprocessor/kube/kube.go b/processor/k8sattributesprocessor/kube/kube.go index 80b938177b59..77d8692e7924 100644 --- a/processor/k8sattributesprocessor/kube/kube.go +++ b/processor/k8sattributesprocessor/kube/kube.go @@ -82,7 +82,7 @@ type Container struct { ImageName string ImageTag string - // Statuses is a map of container run_id (restart count) attribute to ContainerStatus struct. + // Statuses is a map of container k8s.container.restart_count attribute to ContainerStatus struct. Statuses map[int]ContainerStatus } diff --git a/processor/k8sattributesprocessor/processor.go b/processor/k8sattributesprocessor/processor.go index 86eb5495d994..b7f14db48d6d 100644 --- a/processor/k8sattributesprocessor/processor.go +++ b/processor/k8sattributesprocessor/processor.go @@ -32,9 +32,9 @@ const ( k8sIPLabelName string = "k8s.pod.ip" clientIPLabelName string = "ip" - // TODO: update the label to semantic convention defined in this PR: + // TODO: Use semantic convention defined in this PR: // /~https://github.com/open-telemetry/opentelemetry-specification/pull/1945 - k8sContainerRunIDLabelName string = "run_id" + k8sContainerRestartCountAttrName string = "k8s.container.restart_count" ) type kubernetesprocessor struct { @@ -153,7 +153,7 @@ func (kp *kubernetesprocessor) addContainerAttributes(attrs pdata.AttributeMap, attrs.InsertString(conventions.AttributeContainerImageTag, containerSpec.ImageTag) } - runIDAttr, ok := attrs.Get(k8sContainerRunIDLabelName) + runIDAttr, ok := attrs.Get(k8sContainerRestartCountAttrName) if ok { runID, err := intFromAttribute(runIDAttr) if err == nil { diff --git a/processor/k8sattributesprocessor/processor_test.go b/processor/k8sattributesprocessor/processor_test.go index b4cc44d7f8a6..a6ff9c3b5751 100644 --- a/processor/k8sattributesprocessor/processor_test.go +++ b/processor/k8sattributesprocessor/processor_test.go @@ -291,7 +291,7 @@ func withContainerName(containerName string) generateResourceFunc { func withContainerRunID(containerRunID string) generateResourceFunc { return func(res pdata.Resource) { - res.Attributes().InsertString(k8sContainerRunIDLabelName, containerRunID) + res.Attributes().InsertString(k8sContainerRestartCountAttrName, containerRunID) } } @@ -722,7 +722,7 @@ func TestProcessorAddContainerAttributes(t *testing.T) { wantAttrs: map[string]string{ k8sIPLabelName: "1.1.1.1", conventions.AttributeK8SContainerName: "app", - k8sContainerRunIDLabelName: "1", + k8sContainerRestartCountAttrName: "1", conventions.AttributeContainerID: "6a7f1a598b5dafec9c193f8f8d63f6e5839b8b0acd2fe780f94285e26c05580e", }, }, @@ -749,7 +749,7 @@ func TestProcessorAddContainerAttributes(t *testing.T) { wantAttrs: map[string]string{ k8sIPLabelName: "1.1.1.1", conventions.AttributeK8SContainerName: "new-app", - k8sContainerRunIDLabelName: "0", + k8sContainerRestartCountAttrName: "0", }, }, { @@ -774,7 +774,7 @@ func TestProcessorAddContainerAttributes(t *testing.T) { wantAttrs: map[string]string{ k8sIPLabelName: "1.1.1.1", conventions.AttributeK8SContainerName: "app", - k8sContainerRunIDLabelName: "1", + k8sContainerRestartCountAttrName: "1", conventions.AttributeContainerImageName: "test/app", }, }, diff --git a/testbed/datasenders/k8s.go b/testbed/datasenders/k8s.go index 85fef483bc02..e518d8a2da0a 100644 --- a/testbed/datasenders/k8s.go +++ b/testbed/datasenders/k8s.go @@ -207,7 +207,7 @@ func NewKubernetesContainerWriter() *FileLogK8sWriter { # Extract metadata from file path - type: regex_parser id: extract_metadata_from_filepath - regex: '^.*\/(?P[^_]+)_(?P[^_]+)_(?P[a-f0-9\-]{36})\/(?P[^\._]+)\/(?P\d+)\.log$' + regex: '^.*\/(?P[^_]+)_(?P[^_]+)_(?P[a-f0-9\-]{36})\/(?P[^\._]+)\/(?P\d+)\.log$' parse_from: $$attributes.file_path # Move out attributes to Attributes - type: metadata @@ -216,7 +216,7 @@ func NewKubernetesContainerWriter() *FileLogK8sWriter { k8s.container.name: 'EXPR($.container_name)' k8s.namespace.name: 'EXPR($.namespace)' k8s.pod.name: 'EXPR($.pod_name)' - run_id: 'EXPR($.run_id)' + k8s.container.restart_count: 'EXPR($.restart_count)' k8s.pod.uid: 'EXPR($.uid)' # Clean up log body - type: restructure @@ -249,7 +249,7 @@ func NewKubernetesCRIContainerdWriter() *FileLogK8sWriter { # Extract metadata from file path - type: regex_parser id: extract_metadata_from_filepath - regex: '^.*\/(?P[^_]+)_(?P[^_]+)_(?P[a-f0-9\-]{36})\/(?P[^\._]+)\/(?P\d+)\.log$' + regex: '^.*\/(?P[^_]+)_(?P[^_]+)_(?P[a-f0-9\-]{36})\/(?P[^\._]+)\/(?P\d+)\.log$' parse_from: $$attributes.file_path # Move out attributes to Attributes - type: metadata @@ -258,7 +258,7 @@ func NewKubernetesCRIContainerdWriter() *FileLogK8sWriter { k8s.container.name: 'EXPR($.container_name)' k8s.namespace.name: 'EXPR($.namespace)' k8s.pod.name: 'EXPR($.pod_name)' - run_id: 'EXPR($.run_id)' + k8s.container.restart_count: 'EXPR($.restart_count)' k8s.pod.uid: 'EXPR($.uid)' # Clean up log body - type: restructure @@ -291,7 +291,7 @@ func NewKubernetesCRIContainerdNoAttributesOpsWriter() *FileLogK8sWriter { # Extract metadata from file path - type: regex_parser id: extract_metadata_from_filepath - regex: '^.*\/(?P[^_]+)_(?P[^_]+)_(?P[a-f0-9\-]{36})\/(?P[^\._]+)\/(?P\d+)\.log$' + regex: '^.*\/(?P[^_]+)_(?P[^_]+)_(?P[a-f0-9\-]{36})\/(?P[^\._]+)\/(?P\d+)\.log$' parse_from: $$attributes.file_path `) }