-
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
New processor: copy_fields #11303
New processor: copy_fields #11303
Conversation
a65f82e
to
30cfee1
Compare
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.
Needs a changelog entry.
c7fc1c2
to
fe47eba
Compare
libbeat/_meta/config.reference.yml
Outdated
# - from: message | ||
# to: message_copied | ||
# fail_on_error: false | ||
# ignore_missing: true |
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.
Seems like this is exactly the opposite to what we have in the defaults in the code for fail_on_error and ignore_missing. Is that on purpose?
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.
No. Thanks for finding it.
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 think this is still missing?
}, | ||
"copy number from fieldname with dot to dotted message.copied": { | ||
FromTo: fromTo{ | ||
From: "message.original", |
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.
What happens if you copy message.original
to message
? Will it fail?
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 set message.original
as a single key containing a dot, so it does not lead to an error when someone wants to manipulate the submaps under message
. It is a different key.
If the test input was different e.g. the key message
was already present
Input: common.MapStr{
"message": common.MapStr{
"original": 42,
},
}
It would fail and tell the user to drop the field message
first, before attempting to copy stuff.
This is a more realistic test case, so I am adding it also.
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.
Interesting, good to know. Could you add a test case for both and one of them would fail. The reason I'm asking also for the failing one is because in case we change the behaviour of the above in the future, we will know that it has an impact.
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.
The test with the description "copy number from hierarchical message.original to top level message which fails"
will fail if the behaviour changes, as the new field would show up in the output. I have also added a new test case which demonstrates what happens when the key contains a dot and is present as a top level key in the fields. If MapStr
is changed one of the tests will fail.
Failing test in Travis is unrelated. |
err := f.copyField(field.From, field.To, event.Fields) | ||
if err != nil && f.config.FailOnError { | ||
errMsg := fmt.Errorf("Failed to copy fields in copy_fields processor: %s", err) | ||
logp.Debug("copy_fields", errMsg.Error()) |
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 we have a selector for logger? I like what @andrewkroh's did in the script processor, see
Tag string `config:"tag"` // Processor ID for debug and metrics. |
And
logName = "processor.javascript" |
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.
TBH in case of this simple processor, I don't see the added value of letting a user set a debug selector. I doubt that users would need to filter for a specific copy processor in their logs, or if they have to, I think messages let then identify the processor easily.
If we want to let user set a selector, it would be much better to let them configure it for all processors. There are other processors which would benefit more from having such setting than this one. What if I open an issue and implement the functionality for all processors in a follow up PR?
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 am OK with a followup PR.
f4579e3
to
4d3c2f5
Compare
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.
@kvch small issue with the changelog but LGTM
CHANGELOG.next.asciidoc
Outdated
@@ -257,6 +257,9 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha2...master[Check the HEAD d | |||
- Add ip fields to default_field in Elasticsearch template. {pull}11035[11035] | |||
- Gracefully shut down on SIGHUP {pull}10704[10704] | |||
- Add `script` processor that supports using Javascript to process events. {pull}10850[10850] {pull}11260[11260] | |||
- Add `script` processor that supports using Javascript to process events. {pull}10850[10850] | |||
- New processor: `copy_fields`. {pull}11303[11303] | |||
- Add error.message to events when `fail_on_error` is set in `rename` and `copy_fields` processors. {pull}11303[11303] |
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.
problems with the rebase?
@kvch Can you please make sure this new processor gets added to the documentation. |
A new processor is introduced as part of support for keeping orignal messages. Options and naming follows the convention of other processors. ### `copy_fields` This processor copies one field to another. Example configuration is below: ```yaml processors: - copy_fields: fields: - from: message to: event.original fail_on_error: false ignore_missing: true ```
@kvch can you add the docs when you have a minute? I was just looking for this functionality and couldn't find it. |
@kvch or @ruflin @dedemorton |
@zez3 Please open an issue to report Beats documentation problems. Comments on old PRs are likely to get lost. Thanks! |
@zez3 Also...forgot to mention that you can ask questions and search for answers in the discuss forum. |
@dedemorton I've opened a new 33088 Issue |
Thanks for creating the issue! I've added it to our project queue. |
A new processor is introduced as part of support for keeping orignal messages. Options and naming follows the convention of other processors.
copy_fields
This processor copies one field to another. Example configuration is below:
Blocks #11297