Skip to content

Commit

Permalink
Change run_id log resource attribute to `k8s.container.restart_coun…
Browse files Browse the repository at this point in the history
…t` (#5572)

Change name of the attribute according to agreement in open-telemetry/opentelemetry-specification#1945. It's better if the actual change  can be merged before the next release to avoid breaking changes in k8sattributes processor.
  • Loading branch information
dmitryax authored Oct 6, 2021
1 parent 7fecacb commit 4c03611
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 22 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

## 💡 Enhancements 💡

- `k8sattributes` processor: add container metadata enrichment (#5467)
- `k8sattributes` processor: add container metadata enrichment (#5467, #5572)

## v0.36.0

Expand Down
2 changes: 1 addition & 1 deletion examples/kubernetes/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Switch to this directory and run following command: `kubectl apply -n <namespace
Kubernetes logs are being stored in `/var/log/pods`.
Path to container logs is constructed using following pattern:

`/var/log/pods/<namespace>_<pod_name>_<pod_uid>/<container>/<run_id>.log`
`/var/log/pods/<namespace>_<pod_name>_<pod_uid>/<container>/<restart_count>.log`

You can use it to manage from which containers do you want to include and exclude logs.

Expand Down
4 changes: 2 additions & 2 deletions examples/kubernetes/otel-collector-config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ receivers:
# Extract metadata from file path
- type: regex_parser
id: extract_metadata_from_filepath
regex: '^.*\/(?P<namespace>[^_]+)_(?P<pod_name>[^_]+)_(?P<uid>[a-f0-9\-]{36})\/(?P<container_name>[^\._]+)\/(?P<run_id>\d+)\.log$'
regex: '^.*\/(?P<namespace>[^_]+)_(?P<pod_name>[^_]+)_(?P<uid>[a-f0-9\-]{36})\/(?P<container_name>[^\._]+)\/(?P<restart_count>\d+)\.log$'
parse_from: $$attributes["file.path"]
# Move out attributes to Attributes
- type: metadata
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions examples/kubernetes/otel-collector.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ data:
# Extract metadata from file path
- type: regex_parser
id: extract_metadata_from_filepath
regex: '^.*\/(?P<namespace>[^_]+)_(?P<pod_name>[^_]+)_(?P<uid>[a-f0-9\-]{36})\/(?P<container_name>[^\._]+)\/(?P<run_id>\d+)\.log$'
regex: '^.*\/(?P<namespace>[^_]+)_(?P<pod_name>[^_]+)_(?P<uid>[a-f0-9\-]{36})\/(?P<container_name>[^\._]+)\/(?P<restart_count>\d+)\.log$'
parse_from: $$attributes["file.path"]
# Move out attributes to Attributes
- type: metadata
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions processor/k8sattributesprocessor/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion processor/k8sattributesprocessor/kube/kube.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
6 changes: 3 additions & 3 deletions processor/k8sattributesprocessor/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
8 changes: 4 additions & 4 deletions processor/k8sattributesprocessor/processor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down Expand Up @@ -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",
},
},
Expand All @@ -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",
},
},
{
Expand All @@ -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",
},
},
Expand Down
10 changes: 5 additions & 5 deletions testbed/datasenders/k8s.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ func NewKubernetesContainerWriter() *FileLogK8sWriter {
# Extract metadata from file path
- type: regex_parser
id: extract_metadata_from_filepath
regex: '^.*\/(?P<namespace>[^_]+)_(?P<pod_name>[^_]+)_(?P<uid>[a-f0-9\-]{36})\/(?P<container_name>[^\._]+)\/(?P<run_id>\d+)\.log$'
regex: '^.*\/(?P<namespace>[^_]+)_(?P<pod_name>[^_]+)_(?P<uid>[a-f0-9\-]{36})\/(?P<container_name>[^\._]+)\/(?P<restart_count>\d+)\.log$'
parse_from: $$attributes.file_path
# Move out attributes to Attributes
- type: metadata
Expand All @@ -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
Expand Down Expand Up @@ -249,7 +249,7 @@ func NewKubernetesCRIContainerdWriter() *FileLogK8sWriter {
# Extract metadata from file path
- type: regex_parser
id: extract_metadata_from_filepath
regex: '^.*\/(?P<namespace>[^_]+)_(?P<pod_name>[^_]+)_(?P<uid>[a-f0-9\-]{36})\/(?P<container_name>[^\._]+)\/(?P<run_id>\d+)\.log$'
regex: '^.*\/(?P<namespace>[^_]+)_(?P<pod_name>[^_]+)_(?P<uid>[a-f0-9\-]{36})\/(?P<container_name>[^\._]+)\/(?P<restart_count>\d+)\.log$'
parse_from: $$attributes.file_path
# Move out attributes to Attributes
- type: metadata
Expand All @@ -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
Expand Down Expand Up @@ -291,7 +291,7 @@ func NewKubernetesCRIContainerdNoAttributesOpsWriter() *FileLogK8sWriter {
# Extract metadata from file path
- type: regex_parser
id: extract_metadata_from_filepath
regex: '^.*\/(?P<namespace>[^_]+)_(?P<pod_name>[^_]+)_(?P<uid>[a-f0-9\-]{36})\/(?P<container_name>[^\._]+)\/(?P<run_id>\d+)\.log$'
regex: '^.*\/(?P<namespace>[^_]+)_(?P<pod_name>[^_]+)_(?P<uid>[a-f0-9\-]{36})\/(?P<container_name>[^\._]+)\/(?P<restart_count>\d+)\.log$'
parse_from: $$attributes.file_path
`)
}
Expand Down

0 comments on commit 4c03611

Please sign in to comment.