Skip to content
New issue

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

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

Already on GitHub? # to your account

Populate ecs fields by pod and container metricsets #30181

Merged

Conversation

MichaelKatsoulis
Copy link
Contributor

@MichaelKatsoulis MichaelKatsoulis commented Feb 3, 2022

What does this PR do?

After new container ECS fields get GA (elastic/ecs#1747) kubernetes module need to start populating those fields.

The new fields are

  1. container.cpu.usage
  2. container.memory.usage
  3. container.network.egress.bytes
  4. container.network.ingress.bytes

These fields map to kubernetes fields:

  1. kubernetes.container.cpu.usage.node.pct by container metricset
  2. kubernetes.container.memory.usage.node.pct by container metricset
  3. kubernetes.pod.network.tx.bytes by pod metricset
  4. kubernetes.pod.network.rx.bytes by pod metricset

respectively.

Why is it important?

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.

How to test this PR locally

Related issues

Screenshots

container fields 1

container fields 2

mappings 1

mappings 2

@botelastic botelastic bot added the needs_team Indicates that the issue/PR needs a Team:* label label Feb 3, 2022
@MichaelKatsoulis MichaelKatsoulis self-assigned this Feb 3, 2022
@MichaelKatsoulis MichaelKatsoulis marked this pull request as draft February 3, 2022 12:03
@mergify
Copy link
Contributor

mergify bot commented Feb 3, 2022

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 Feb 3, 2022
@MichaelKatsoulis MichaelKatsoulis added Team:Cloudnative-Monitoring Label for the Cloud Native Monitoring team and removed backport-skip Skip notification from the automated backport with mergify labels Feb 3, 2022
@botelastic botelastic bot removed the needs_team Indicates that the issue/PR needs a Team:* label label Feb 3, 2022
@mergify mergify bot added the backport-skip Skip notification from the automated backport with mergify label Feb 3, 2022
@elasticmachine
Copy link
Collaborator

elasticmachine commented Feb 3, 2022

💚 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: 2022-03-29T09:46:14.435+0000

  • Duration: 52 min 39 sec

Test stats 🧪

Test Results
Failed 0
Passed 3517
Skipped 877
Total 4394

💚 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!)

// Enrich event with container ECS fields
containerEcsFields := ecsfields(event)
if len(containerEcsFields) != 0 {
e.RootFields = common.MapStr{
Copy link
Member

Choose a reason for hiding this comment

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

This will override any existing RootFields right? event variable will already have RootFields coming from

e.RootFields = metaFieldsMapStr

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 check in 0a0a543

@MichaelKatsoulis
Copy link
Contributor Author

@ChrsMark I added some units tests as well

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.

I wonder if we should wait until elastic/ecs#1747 is settled down before moving on with this. wdyt?

@MichaelKatsoulis
Copy link
Contributor Author

I wonder if we should wait until elastic/ecs#1747 is settled down before moving on with this. wdyt?

Yes. I will move it as blocked and wait.

@MichaelKatsoulis MichaelKatsoulis marked this pull request as ready for review March 28, 2022 16:59
@@ -114,28 +114,28 @@ func eventMapping(content []byte, perfMetrics *util.PerfMetricsCache) ([]common.
}

if container.StartTime != "" {
containerEvent.Put("start_time", container.StartTime)
_, _ = containerEvent.Put("start_time", container.StartTime)
Copy link
Contributor

Choose a reason for hiding this comment

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

should we maybe add proper handling of errors here, as a debug messages?
not in this PR, but at least create a ticket for that

Copy link
Member

Choose a reason for hiding this comment

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

+1

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.

Left some comments.

containerEcsFields := ecsfields(event)
if len(containerEcsFields) != 0 {
if e.RootFields != nil {
e.RootFields.DeepUpdate(common.MapStr{
Copy link
Member

Choose a reason for hiding this comment

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

RootFields can already contain container key here so this is why using DeepUpdate right? Can you also add a comment about this so as to prevent any unwanted changes in the future if someone oversee the fact of the preexisting container key?

@@ -114,28 +114,28 @@ func eventMapping(content []byte, perfMetrics *util.PerfMetricsCache) ([]common.
}

if container.StartTime != "" {
containerEvent.Put("start_time", container.StartTime)
_, _ = containerEvent.Put("start_time", container.StartTime)
Copy link
Member

Choose a reason for hiding this comment

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

+1

}

if nodeCores > 0 {
containerEvent.Put("cpu.usage.node.pct", float64(container.CPU.UsageNanoCores)/1e9/nodeCores)
_, _ = containerEvent.Put("cpu.usage.node.pct", float64(container.CPU.UsageNanoCores)/1e9/nodeCores)
Copy link
Member

Choose a reason for hiding this comment

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

Too many unhandled errors. Wondering if we should actually handle them properly.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We don't want to do anything specific here. Just continue to the next fields

Copy link
Member

Choose a reason for hiding this comment

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

Still don't like this format with unhandled errors but if you feel it's ok you can ship it.

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 don't either. It is like this in most of the beats modules. If we want to handle it somehow(log something), let's do it in subsequent pr, so we can make the FF for now

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.

Let's see how we can improve the code style in follow-ups.

@MichaelKatsoulis MichaelKatsoulis requested review from a team as code owners March 29, 2022 09:45
@MichaelKatsoulis MichaelKatsoulis removed request for a team March 29, 2022 09:46
@MichaelKatsoulis MichaelKatsoulis merged commit 9e0c0fb into elastic:main Mar 29, 2022
emilioalvap pushed a commit to emilioalvap/beats that referenced this pull request Apr 6, 2022
* Populate ecs fields by pod and container metricsets
* Update changelog
kush-elastic pushed a commit to kush-elastic/beats that referenced this pull request May 2, 2022
* Populate ecs fields by pod and container metricsets
* Update changelog
chrisberkhout pushed a commit that referenced this pull request Jun 1, 2023
* Populate ecs fields by pod and container metricsets
* Update changelog
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
backport-skip Skip notification from the automated backport with mergify Team:Cloudnative-Monitoring Label for the Cloud Native Monitoring team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants