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

Populate container.id field in container metricset #29560

Conversation

MichaelKatsoulis
Copy link
Contributor

@MichaelKatsoulis MichaelKatsoulis commented Dec 21, 2021

What does this PR do?

This PR adds container.id and container.runtime fields in events generated by kubernetes container Metricset.

Why is it important?

Container.id is a unique identifier for a Kubernetes container and is very important to be part in all kubernetes events.

Checklist

  • My code follows the style guidelines of this project
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have made corresponding change to the default configuration files
  • I have added tests that prove my fix is effective or that my feature works
  • I have added an entry in CHANGELOG.next.asciidoc or CHANGELOG-developer.next.asciidoc.

Author's Checklist

  • [ ]

How to test this PR locally

Related issues

Use cases

Screenshots

container id

Logs

@botelastic botelastic bot added the needs_team Indicates that the issue/PR needs a Team:* label label Dec 21, 2021
@mergify
Copy link
Contributor

mergify bot commented Dec 21, 2021

This pull request does not have a backport label. Could you fix it @MichaelKatsoulis? 🙏
To fixup this pull request, you need to add the backport labels for the needed
branches, such as:

  • backport-v./d./d./d is the label to automatically backport to the 7./d branch. /d is the digit

NOTE: backport-skip has been added to this pull request.

@mergify mergify bot added the backport-skip Skip notification from the automated backport with mergify label Dec 21, 2021
@MichaelKatsoulis MichaelKatsoulis added enhancement and removed backport-skip Skip notification from the automated backport with mergify labels Dec 21, 2021
@mergify mergify bot added the backport-skip Skip notification from the automated backport with mergify label Dec 21, 2021
@MichaelKatsoulis MichaelKatsoulis added backport-v8.1.0 Automated backport with mergify and removed backport-skip Skip notification from the automated backport with mergify labels Dec 21, 2021
@elasticmachine
Copy link
Collaborator

elasticmachine commented Dec 21, 2021

💚 Build Succeeded

the below badges are clickable and redirect to their specific view in the CI or DOCS
Pipeline View Test View Changes Artifacts preview preview

Expand to view the summary

Build stats

  • Start Time: 2021-12-21T12:26:39.041+0000

  • Duration: 88 min 50 sec

  • Commit: 5ea9a23

Test stats 🧪

Test Results
Failed 0
Passed 9356
Skipped 2421
Total 11777

💚 Flaky test report

Tests succeeded.

🤖 GitHub comments

To re-run your PR in the CI, just comment with:

  • /test : Re-trigger the build.

  • /package : Generate the packages and run the E2E tests.

  • /beats-tester : Run the installation tests with beats-tester.

  • run elasticsearch-ci/docs : Re-trigger the docs validation. (use unformatted text in the comment!)

@MichaelKatsoulis MichaelKatsoulis self-assigned this Dec 21, 2021
Copy link
Member

@ChrsMark ChrsMark left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really useful addition! Left some comments.

@@ -134,3 +136,6 @@ type Summary struct {
} `json:"volume"`
} `json:"pods"`
}

// PodContainerStatus data
type PodContainerStatus = v1.ContainerStatus
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right. It is not needed

// copy to ECS fields the kubernetes.container.image, kubernetes.container.name
containerFields := common.MapStr{}
if containerID, ok := event["id"]; ok {
cID := (containerID).(string)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: This block could be a helper function.

@@ -215,7 +223,11 @@ func NewContainerMetadataEnricher(

id := join(pod.GetObjectMeta().GetNamespace(), pod.GetObjectMeta().GetName(), container.Name)
m[id] = meta
if s, ok := statuses[container.Name]; ok {
PerfMetrics.ContainerID.SetStringVal(cuid, s.ContainerID)
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wondering if we could avoid using the cache for this and use meta directly.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I will do this! Good catch

@MichaelKatsoulis
Copy link
Contributor Author

@ChrsMark I added the container.id and container.runtime in the meta fields

Copy link
Member

@ChrsMark ChrsMark left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀

if s, ok := statuses[container.Name]; ok {
split := strings.Index(s.ContainerID, "://")
if split != -1 {
meta.Put("container.id", s.ContainerID[split+3:])
Copy link
Contributor

@tetianakravchenko tetianakravchenko Dec 21, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you please add a comment with an example of statuses[container.Name] value, that could explain why those offset is used

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a comment in 755b1f2

@mtojek mtojek added the Team:Integrations Label for the Integrations team label Dec 21, 2021
@elasticmachine
Copy link
Collaborator

Pinging @elastic/integrations (Team:Integrations)

@botelastic botelastic bot removed the needs_team Indicates that the issue/PR needs a Team:* label label Dec 21, 2021
@mergify
Copy link
Contributor

mergify bot commented Dec 21, 2021

This pull request is now in conflicts. Could you fix it? 🙏
To fixup this pull request, you can check out it locally. See documentation: https://help.github.com/articles/checking-out-pull-requests-locally/

git fetch upstream
git checkout -b add-container.id-field-container-metricset upstream/add-container.id-field-container-metricset
git merge upstream/master
git push upstream add-container.id-field-container-metricset

@MichaelKatsoulis MichaelKatsoulis merged commit 5648bc1 into elastic:master Dec 21, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport-v8.1.0 Automated backport with mergify enhancement Team:Integrations Label for the Integrations team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants