-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
Fix container enricher with correct container ids for pods with multiple containers #34516
Fix container enricher with correct container ids for pods with multiple containers #34516
Conversation
This pull request does not have a backport label.
To fixup this pull request, you need to add the backport labels for the needed
|
I think we also need a test for that, because we missed this case. |
@@ -314,14 +315,15 @@ func NewContainerMetadataEnricher( | |||
// which is in the form of <container.runtime>://<container.id> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you think is time to allign here also with kube_state container.id where container.runtime is not splitted?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, that is another issue right? Good if we can fix them both.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That would be a breaking change. For state_container metricset as far as I see, the container.id is the same form.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed. So it is time maybe to test here both container.ids and align them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does fixing mean? I prefer the splitted container.id
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch! Make sure you add the proper backports for it. Being a bugfix we need to backport it to the versions that the bug exists.
@@ -293,6 +293,7 @@ func NewContainerMetadataEnricher( | |||
podStore, _ := nodeStore.AddPodStore(podId) | |||
|
|||
for _, container := range append(pod.Spec.Containers, pod.Spec.InitContainers...) { | |||
cmeta := mapstr.M{} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍🏼
The addition of container.id ecs fields was introduced in 8.1. So We need to backport till that version |
@@ -293,6 +293,7 @@ func NewContainerMetadataEnricher( | |||
podStore, _ := nodeStore.AddPodStore(podId) | |||
|
|||
for _, container := range append(pod.Spec.Containers, pod.Spec.InitContainers...) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know we have a for here, but just doublehcecking if we can make a test wit 3 containers. In case we miss sth and compare with kube_state.container dataset
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can reassure you it works because I tested it!
We don't have metricset tests currently that test the enrichers. All the tests we have in the container metricset just test the |
In order not to delay fix, please merge this. But make sure you add a new story for this in backlog |
Maybe we need to isolate the enricher's functionalities in smaller functions and that would make it easier for writing unit tests for them. |
Yes we need to rethink the code to make it testable. I will open an issue for adding tests. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we need a changelog here since it is a bugfix. Make sure you include both issues as you nicely do in the PR's description.
…ple containers (#34516) * Fix container enricher with correct container ids for pods with multiple containers * Align kubernetes.container.id with ecs container.id (cherry picked from commit 4ac4973) # Conflicts: # metricbeat/module/kubernetes/state_container/_meta/test/ksm.v1.3.0.expected # metricbeat/module/kubernetes/state_container/_meta/test/ksm.v1.8.0.expected # metricbeat/module/kubernetes/state_container/_meta/test/ksm.v2.0.0.expected # metricbeat/module/kubernetes/state_container/_meta/test/ksm.v2.7.0.expected # metricbeat/module/kubernetes/state_container/_meta/testdata/ksm.v2.4.2.plain-expected.json # metricbeat/module/kubernetes/state_container/_meta/testdata/ksm.v2.5.0.plain-expected.json # metricbeat/module/kubernetes/state_container/_meta/testdata/ksm.v2.6.0.plain-expected.json # metricbeat/module/kubernetes/state_container/_meta/testdata/ksm.v2.7.0.plain-expected.json # metricbeat/module/kubernetes/state_container/state_container.go # metricbeat/module/kubernetes/util/kubernetes.go
…ple containers (#34516) * Fix container enricher with correct container ids for pods with multiple containers * Align kubernetes.container.id with ecs container.id (cherry picked from commit 4ac4973) # Conflicts: # metricbeat/module/kubernetes/state_container/_meta/test/ksm.v1.3.0.expected # metricbeat/module/kubernetes/state_container/_meta/test/ksm.v1.8.0.expected # metricbeat/module/kubernetes/state_container/_meta/test/ksm.v2.0.0.expected # metricbeat/module/kubernetes/state_container/_meta/test/ksm.v2.7.0.expected # metricbeat/module/kubernetes/state_container/_meta/testdata/ksm.v2.4.2.plain-expected.json # metricbeat/module/kubernetes/state_container/_meta/testdata/ksm.v2.5.0.plain-expected.json # metricbeat/module/kubernetes/state_container/_meta/testdata/ksm.v2.6.0.plain-expected.json # metricbeat/module/kubernetes/state_container/_meta/testdata/ksm.v2.7.0.plain-expected.json
…ple containers (#34516) * Fix container enricher with correct container ids for pods with multiple containers * Align kubernetes.container.id with ecs container.id (cherry picked from commit 4ac4973) # Conflicts: # metricbeat/module/kubernetes/state_container/_meta/test/ksm.v1.3.0.expected # metricbeat/module/kubernetes/state_container/_meta/test/ksm.v1.8.0.expected # metricbeat/module/kubernetes/state_container/_meta/test/ksm.v2.0.0.expected # metricbeat/module/kubernetes/state_container/_meta/test/ksm.v2.7.0.expected # metricbeat/module/kubernetes/state_container/_meta/testdata/ksm.v2.4.2.plain-expected.json # metricbeat/module/kubernetes/state_container/_meta/testdata/ksm.v2.5.0.plain-expected.json # metricbeat/module/kubernetes/state_container/_meta/testdata/ksm.v2.6.0.plain-expected.json # metricbeat/module/kubernetes/state_container/_meta/testdata/ksm.v2.7.0.plain-expected.json
…ple containers (#34516) * Fix container enricher with correct container ids for pods with multiple containers * Align kubernetes.container.id with ecs container.id (cherry picked from commit 4ac4973) # Conflicts: # metricbeat/module/kubernetes/state_container/_meta/test/ksm.v1.3.0.expected # metricbeat/module/kubernetes/state_container/_meta/test/ksm.v1.8.0.expected # metricbeat/module/kubernetes/state_container/_meta/test/ksm.v2.0.0.expected # metricbeat/module/kubernetes/state_container/_meta/test/ksm.v2.7.0.expected # metricbeat/module/kubernetes/state_container/_meta/testdata/ksm.v2.4.2.plain-expected.json # metricbeat/module/kubernetes/state_container/_meta/testdata/ksm.v2.5.0.plain-expected.json # metricbeat/module/kubernetes/state_container/_meta/testdata/ksm.v2.6.0.plain-expected.json # metricbeat/module/kubernetes/state_container/_meta/testdata/ksm.v2.7.0.plain-expected.json
…ple containers (#34516) (#34538) * Fix container enricher with correct container ids for pods with multiple containers * Align kubernetes.container.id with ecs container.id (cherry picked from commit 4ac4973) Co-authored-by: Michael Katsoulis <[email protected]>
…ids for pods with multiple containers (#34537) * Fix container enricher with correct container ids for pods with multiple containers (#34516) --------- Co-authored-by: Michael Katsoulis <[email protected]>
@Mergifyio backport 8.2 |
✅ Backports have been created
|
…ple containers (#34516) * Fix container enricher with correct container ids for pods with multiple containers * Align kubernetes.container.id with ecs container.id (cherry picked from commit 4ac4973) # Conflicts: # metricbeat/module/kubernetes/state_container/_meta/test/ksm.v1.3.0.expected # metricbeat/module/kubernetes/state_container/_meta/test/ksm.v1.8.0.expected # metricbeat/module/kubernetes/state_container/_meta/test/ksm.v2.0.0.expected # metricbeat/module/kubernetes/state_container/_meta/test/ksm.v2.7.0.expected # metricbeat/module/kubernetes/state_container/_meta/testdata/ksm.v2.4.2.plain-expected.json # metricbeat/module/kubernetes/state_container/_meta/testdata/ksm.v2.5.0.plain-expected.json # metricbeat/module/kubernetes/state_container/_meta/testdata/ksm.v2.6.0.plain-expected.json # metricbeat/module/kubernetes/state_container/_meta/testdata/ksm.v2.7.0.plain-expected.json # metricbeat/module/kubernetes/state_container/state_container.go # metricbeat/module/kubernetes/util/kubernetes.go
@Mergifyio backport 8.1 |
…ple containers (#34516) * Fix container enricher with correct container ids for pods with multiple containers * Align kubernetes.container.id with ecs container.id (cherry picked from commit 4ac4973) # Conflicts: # metricbeat/module/kubernetes/state_container/_meta/test/ksm.v1.3.0.expected # metricbeat/module/kubernetes/state_container/_meta/test/ksm.v1.8.0.expected # metricbeat/module/kubernetes/state_container/_meta/test/ksm.v2.0.0.expected # metricbeat/module/kubernetes/state_container/_meta/test/ksm.v2.7.0.expected # metricbeat/module/kubernetes/state_container/_meta/testdata/ksm.v2.4.2.plain-expected.json # metricbeat/module/kubernetes/state_container/_meta/testdata/ksm.v2.5.0.plain-expected.json # metricbeat/module/kubernetes/state_container/_meta/testdata/ksm.v2.6.0.plain-expected.json # metricbeat/module/kubernetes/state_container/_meta/testdata/ksm.v2.7.0.plain-expected.json # metricbeat/module/kubernetes/state_container/state_container.go # metricbeat/module/kubernetes/util/kubernetes.go
✅ Backports have been created
|
…ids for pods with multiple containers (#34536) * Fix container enricher with correct container ids for pods with multiple containers (#34516) --------- Co-authored-by: Michael Katsoulis <[email protected]>
…ids for pods with multiple containers (#34535) * Fix container enricher with correct container ids for pods with multiple containers (#34516) --------- Co-authored-by: Michael Katsoulis <[email protected]>
…ids for pods with multiple containers (#34534) * Fix container enricher with correct container ids for pods with multiple containers (#34516) --------- Co-authored-by: Michael Katsoulis <[email protected]>
…ple containers (#34516) * Fix container enricher with correct container ids for pods with multiple containers * Align kubernetes.container.id with ecs container.id
What does this PR do?
This PR fixes a bug in NewContainerMetadataEnricher used by Kubernetes module's container metricset.
In case a pod consists of more than one container, the ecs field
container.id
was the same for all containers.This was happening because the
meta
struct used for both containers was the same and thecontainer.id
value was getting overwritten.Also this PR aligns
kubernetes.container.id
andcontainer.id
ofstate_container
metricset.So far
kubernetes.container.id
was not splitted and contained both the runtime and the id (containerd://99781780c8d2eaa7a0333e158c49969b20cdf067f7b00d8b93022b508ee09724
)On the other hand
container.id
was splitted to99781780c8d2eaa7a0333e158c49969b20cdf067f7b00d8b93022b508ee09724
leading to confusion.Now on it will be splitted in all cases.
Why is it important?
This was leading to errors and containers not found.
Issue https://github.com/elastic/observability-dev/issues/4012
Checklist
CHANGELOG.next.asciidoc
orCHANGELOG-developer.next.asciidoc
.How to test this PR locally
To test this locally just create an elastic-stack and deploy default kubernetes metricbeat.
Deploy a pod in the k8s cluster with two containers and then in Kibana for that specific pod.name and container metricset, observe the container.ids of the different container names of that pod.
Issues
Screenshots
Before the fix:
After the fix:
Logs