-
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
Enhance add_kubernetes_metadata matcher #28868
Enhance add_kubernetes_metadata matcher #28868
Conversation
…og/pods' for resource_type: pod Signed-off-by: Tetiana Kravchenko <tetiana.kravchenko@elastic.co>
This pull request does not have a backport label. Could you fix it @tetianakravchenko? 🙏
NOTE: |
💚 Build Succeeded
Expand to view the summary
Build stats
Test stats 🧪
💚 Flaky test reportTests succeeded. 🤖 GitHub commentsTo re-run your PR in the CI, just comment with:
|
Pinging @elastic/integrations (Team:Integrations) |
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.
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") |
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.
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.
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 mean event
instead of source
? this error might only occur in case event
map does not contain log.file.path
(=source
) key
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.
Yeap my wrong, event
is what I was thinking about. Logging the whole event
would be helpful.
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.
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.
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.
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, |
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.
Wondering if we should prevent this from happening by validating the configuration. wdyt?
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.
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 ?
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.
Yes, in
func (k *kubeAnnotatorConfig) Validate() error { |
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.
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 will give it a try
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.
libbeat/processors/add_kubernetes_metadata/docs/indexers_and_matchers.asciidoc
Outdated
Show resolved
Hide resolved
libbeat/processors/add_kubernetes_metadata/docs/indexers_and_matchers.asciidoc
Outdated
Show resolved
Hide resolved
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) |
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.
Maybe log the podUID[2] here instead of the array
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.
thank you for pointing it out! fixed: e8ab1fe
This pull request is now in conflicts. Could you fix it? 🙏
|
Signed-off-by: Tetiana Kravchenko <tetiana.kravchenko@elastic.co>
Signed-off-by: Tetiana Kravchenko <tetiana.kravchenko@elastic.co>
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.
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 { |
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.
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.
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.
Signed-off-by: Tetiana Kravchenko <tetiana.kravchenko@elastic.co>
Signed-off-by: Tetiana Kravchenko <tetiana.kravchenko@elastic.co>
Hi @tetianakravchenko any plans to backport this to 8.0 and 7.17? |
@Mergifyio backport 7.17 |
@Mergifyio backport 8.0 |
❌ No backport have been created
|
❌ No backport have been created
|
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. |
Hi @luigibk, I will take care of this today |
* 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)
* 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)
…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
…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
Signed-off-by: Tetiana Kravchenko tetiana.kravchenko@elastic.co
What does this PR do?
add_kubernetes_metadata
matcher;/var/log/pods/
forresource_type: pod
Why is it important?
to improve understanding on how
add_kubernetes_metadata
works and which logs_path are supported for available resource_typeChecklist
CHANGELOG.next.asciidoc
orCHANGELOG-developer.next.asciidoc
.Author's Checklist
How to test this PR locally
Related issues
Use cases
Screenshots
Logs