Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change run_id log resource attribute to k8s.container.restart_count #5572

Merged
merged 2 commits into from
Oct 6, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,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
2 changes: 1 addition & 1 deletion processor/k8sattributesprocessor/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
// - container.image.name
// - container.image.tag
// 2. Container status attributes - in addition to pod identifier and `container.name` attribute, these attributes
codeboten marked this conversation as resolved.
Show resolved Hide resolved
// require identifier of a particular container run set as `run_id` in resource 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