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

Make @metadata accessible via beat.Event accessor methods #10761

Merged

Conversation

andrewkroh
Copy link
Member

@andrewkroh andrewkroh commented Feb 14, 2019

This implements a TODO from the beat.Event struct that makes it possible to put/get/delete
@metadata values via the accessor methods.

@andrewkroh andrewkroh requested a review from a team as a code owner February 14, 2019 23:08
@andrewkroh andrewkroh force-pushed the feature/libbeat/beat-event-metadata branch from ded73db to 3454bb8 Compare February 14, 2019 23:09
This implements a TODO from the beat.Event struct that makes it possible to put/get/delete
@metadata values via the accessor methods.
@andrewkroh andrewkroh force-pushed the feature/libbeat/beat-event-metadata branch from 3454bb8 to dc5a091 Compare February 20, 2019 14:21
@andrewkroh andrewkroh requested review from ph and kvch February 20, 2019 15:14
return e.Fields.Delete(key)
}

func metadataKey(key string) (string, bool) {
if !strings.HasPrefix(key, "@metadata") {
Copy link
Contributor

@kvch kvch Feb 20, 2019

Choose a reason for hiding this comment

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

I am wondering if it would be safer to check for "@metadata."? What if an event includes the key "@metadata2.keyname and wants to delete @metadata2? If I understand correctly so far, it means that Meta gets deleted.

Copy link
Member Author

Choose a reason for hiding this comment

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

I added a test case to show that Delete(@metadataSpecial) doesn't cause Meta to be deleted.

The reason it checks for @metadata is to allow for operations like Put(@metadata, map[string]interface{}{x: y}) and Get(@metadata). When it finds that @metadata as the prefix it then checks to see if the next character is a . so in effect it is checking for @metadata..

@andrewkroh andrewkroh merged commit 2b7d9fe into elastic:master Feb 20, 2019
# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants