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

Enhance add_kubernetes_metadata matcher #28868

Conversation

tetianakravchenko
Copy link
Contributor

@tetianakravchenko tetianakravchenko commented Nov 8, 2021

Signed-off-by: Tetiana Kravchenko tetiana.kravchenko@elastic.co

What does this PR do?

  • add documentation for add_kubernetes_metadata matcher;
  • support /var/log/pods/ for resource_type: pod

Why is it important?

to improve understanding on how add_kubernetes_metadata works and which logs_path are supported for available resource_type

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

Logs

…og/pods' for resource_type: pod

Signed-off-by: Tetiana Kravchenko <tetiana.kravchenko@elastic.co>
@botelastic botelastic bot added the needs_team Indicates that the issue/PR needs a Team:* label label Nov 8, 2021
@mergify
Copy link
Contributor

mergify bot commented Nov 8, 2021

This pull request does not have a backport label. Could you fix it @tetianakravchenko? 🙏
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 Nov 8, 2021
@elasticmachine
Copy link
Collaborator

elasticmachine commented Nov 8, 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-11-09T17:12:54.731+0000

  • Duration: 120 min 56 sec

  • Commit: de58076

Test stats 🧪

Test Results
Failed 0
Passed 54222
Skipped 5345
Total 59567

💚 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.

@mtojek mtojek added the Team:Integrations Label for the Integrations team label Nov 8, 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 Nov 8, 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.

Great work in breaking this into pieces @tetianakravchenko , I left some comments/suggestions but in general it looks good!

source := value.(string)
f.logger.Debugf("Incoming log.file.path value: %s", source)
if err != nil {
f.logger.Errorf("Error extracting log.file.path from the event")
Copy link
Member

Choose a reason for hiding this comment

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

We may still need to log source here so as to have a more clear view of how the event that is related to this error looks like.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

do you mean event instead of source? this error might only occur in case event map does not contain log.file.path(=source) key

Copy link
Member

Choose a reason for hiding this comment

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

Yeap my wrong, event is what I was thinking about. Logging the whole event would be helpful.

Copy link
Member

Choose a reason for hiding this comment

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

Also maybe just a debug message would be enough, since ERRORs would flood a basic case when the processor for some reason does not work.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed: e8ab1fe

}

f.logger.Error("Error extracting container id - source value contains matcher's logs_path, however it is too short to contain a Docker container ID.")
f.logger.Error(`Error extracting pod uid - source value does not contains matcher's logs_path,
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 should prevent this from happening by validating the configuration. wdyt?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

could you please elaborate on this? do you mean do smth similar to other processors. like - https://github.com/elastic/beats/blob/master/libbeat/processors/add_kubernetes_metadata/config.go ?

Copy link
Member

Choose a reason for hiding this comment

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

Yes, in

func (k *kubeAnnotatorConfig) Validate() error {
we can check if matchers' config is valid too so as to warn the users early on and avoid initialising the processor in case the config is not supported. I see that the matcher's config part is a map so not sure how much mangling this change would require but it should be doable. Let me know what you think.

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 will give it a try

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ChrsMark please have a look - ab3c821, let me know wdyt, are there any better ways maybe?

tetianakravchenko and others added 3 commits November 8, 2021 15:08
Co-authored-by: Chris Mark <chrismarkou92@gmail.com>
Signed-off-by: Tetiana Kravchenko <tetiana.kravchenko@elastic.co>
…vchenko/beats into 28629-add_kubernetes_metadata
if len(pathDirs) > podUIDPos {
podUID := strings.Split(pathDirs[podUIDPos], "_")
if len(podUID) > 2 {
f.logger.Debugf("Using pod uid: %s", podUID)
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe log the podUID[2] here instead of the array

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thank you for pointing it out! fixed: e8ab1fe

@mergify
Copy link
Contributor

mergify bot commented Nov 9, 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 28629-add_kubernetes_metadata upstream/28629-add_kubernetes_metadata
git merge upstream/master
git push upstream 28629-add_kubernetes_metadata

Signed-off-by: Tetiana Kravchenko <tetiana.kravchenko@elastic.co>
Signed-off-by: Tetiana Kravchenko <tetiana.kravchenko@elastic.co>
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.

LGTM! Thanks for adding test cases too! Only one minor comment.

@@ -69,5 +69,34 @@ func (k *kubeAnnotatorConfig) Validate() error {
k.Host = ""
}

for _, matcher := range k.Matchers {
Copy link
Member

Choose a reason for hiding this comment

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

Looks good! I would suggest adding a comment here explaining why we perform such checks and that it's because we are taking an opinionated approach on what paths we support.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Signed-off-by: Tetiana Kravchenko <tetiana.kravchenko@elastic.co>
Signed-off-by: Tetiana Kravchenko <tetiana.kravchenko@elastic.co>
@luigibk
Copy link

luigibk commented Feb 21, 2022

Hi @tetianakravchenko any plans to backport this to 8.0 and 7.17?

@tetianakravchenko
Copy link
Contributor Author

@Mergifyio backport 7.17

@tetianakravchenko
Copy link
Contributor Author

@Mergifyio backport 8.0

@mergify
Copy link
Contributor

mergify bot commented Feb 21, 2022

backport 7.17

❌ No backport have been created

  • Backport to branch 7.17 failed: Git reported the following error:
fatal: couldn't find remote ref master

@mergify
Copy link
Contributor

mergify bot commented Feb 21, 2022

backport 8.0

❌ No backport have been created

  • Backport to branch 8.0 failed: Git reported the following error:
fatal: couldn't find remote ref master

@luigibk
Copy link

luigibk commented Feb 22, 2022

Hi @tetianakravchenko thanks for the quick reply, mergify returned an error as I think there might be an issue with how it is configured as it's looking for a master branch, whereas it's named main in this repo.

@tetianakravchenko
Copy link
Contributor Author

Hi @luigibk, I will take care of this today

tetianakravchenko added a commit to tetianakravchenko/beats that referenced this pull request Feb 22, 2022
* add documentation for add_kubernetes_metadata matcher; support 'var/log/pods' for resource_type: pod

Signed-off-by: Tetiana Kravchenko <tetiana.kravchenko@elastic.co>

* Apply suggestions from code review

Co-authored-by: Chris Mark <chrismarkou92@gmail.com>

* add record to CHANGELOG.next.asciidoc

Signed-off-by: Tetiana Kravchenko <tetiana.kravchenko@elastic.co>

* address comments: log pod id instead of array; log event

Signed-off-by: Tetiana Kravchenko <tetiana.kravchenko@elastic.co>

* add validation for logs_path matchers config

Signed-off-by: Tetiana Kravchenko <tetiana.kravchenko@elastic.co>

* add comment for the config validation check

Signed-off-by: Tetiana Kravchenko <tetiana.kravchenko@elastic.co>

* set different sourcePath for windows in tests

Signed-off-by: Tetiana Kravchenko <tetiana.kravchenko@elastic.co>

Co-authored-by: Chris Mark <chrismarkou92@gmail.com>
(cherry picked from commit ac8275f)
tetianakravchenko added a commit to tetianakravchenko/beats that referenced this pull request Feb 22, 2022
* add documentation for add_kubernetes_metadata matcher; support 'var/log/pods' for resource_type: pod

Signed-off-by: Tetiana Kravchenko <tetiana.kravchenko@elastic.co>

* Apply suggestions from code review

Co-authored-by: Chris Mark <chrismarkou92@gmail.com>

* add record to CHANGELOG.next.asciidoc

Signed-off-by: Tetiana Kravchenko <tetiana.kravchenko@elastic.co>

* address comments: log pod id instead of array; log event

Signed-off-by: Tetiana Kravchenko <tetiana.kravchenko@elastic.co>

* add validation for logs_path matchers config

Signed-off-by: Tetiana Kravchenko <tetiana.kravchenko@elastic.co>

* add comment for the config validation check

Signed-off-by: Tetiana Kravchenko <tetiana.kravchenko@elastic.co>

* set different sourcePath for windows in tests

Signed-off-by: Tetiana Kravchenko <tetiana.kravchenko@elastic.co>

Co-authored-by: Chris Mark <chrismarkou92@gmail.com>
(cherry picked from commit ac8275f)
tetianakravchenko added a commit that referenced this pull request Feb 23, 2022
…30526)

* Enhance add_kubernetes_metadata matcher (#28868)

* add documentation for add_kubernetes_metadata matcher; support 'var/log/pods' for resource_type: pod

Signed-off-by: Tetiana Kravchenko <tetiana.kravchenko@elastic.co>

* Apply suggestions from code review

Co-authored-by: Chris Mark <chrismarkou92@gmail.com>

* add record to CHANGELOG.next.asciidoc

Signed-off-by: Tetiana Kravchenko <tetiana.kravchenko@elastic.co>

* address comments: log pod id instead of array; log event

Signed-off-by: Tetiana Kravchenko <tetiana.kravchenko@elastic.co>

* add validation for logs_path matchers config

Signed-off-by: Tetiana Kravchenko <tetiana.kravchenko@elastic.co>

* add comment for the config validation check

Signed-off-by: Tetiana Kravchenko <tetiana.kravchenko@elastic.co>

* set different sourcePath for windows in tests

Signed-off-by: Tetiana Kravchenko <tetiana.kravchenko@elastic.co>

Co-authored-by: Chris Mark <chrismarkou92@gmail.com>
(cherry picked from commit ac8275f)

* Update CHANGELOG.next.asciidoc
tetianakravchenko added a commit that referenced this pull request Feb 23, 2022
…30527)

* Enhance add_kubernetes_metadata matcher (#28868)

* add documentation for add_kubernetes_metadata matcher; support 'var/log/pods' for resource_type: pod

Signed-off-by: Tetiana Kravchenko <tetiana.kravchenko@elastic.co>

* Apply suggestions from code review

Co-authored-by: Chris Mark <chrismarkou92@gmail.com>

* add record to CHANGELOG.next.asciidoc

Signed-off-by: Tetiana Kravchenko <tetiana.kravchenko@elastic.co>

* address comments: log pod id instead of array; log event

Signed-off-by: Tetiana Kravchenko <tetiana.kravchenko@elastic.co>

* add validation for logs_path matchers config

Signed-off-by: Tetiana Kravchenko <tetiana.kravchenko@elastic.co>

* add comment for the config validation check

Signed-off-by: Tetiana Kravchenko <tetiana.kravchenko@elastic.co>

* set different sourcePath for windows in tests

Signed-off-by: Tetiana Kravchenko <tetiana.kravchenko@elastic.co>

Co-authored-by: Chris Mark <chrismarkou92@gmail.com>
(cherry picked from commit ac8275f)

* Update CHANGELOG.next.asciidoc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport-skip Skip notification from the automated backport with mergify enhancement Team:Integrations Label for the Integrations team v7.17.1 v8.0.1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

add_kubernetes_metadata needs to respect logs_path setting
6 participants