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

merge into existing target, new tests and DRYing #69

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions lib/logstash/filters/kv.rb
Original file line number Diff line number Diff line change
Expand Up @@ -411,8 +411,10 @@ def filter(event)
return if kv.empty?

Choose a reason for hiding this comment

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

If you fancy, removing this line should satisfy #11 too.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good point. my concern is with BWC but we could make this a major version bump in that respect and have better consistency in the plugin behaviour.


if @target
@logger.debug? && @logger.debug("Overwriting existing target field", :target => @target)
event.set(@target, kv)
@logger.debug? && @logger.debug("Merging into existing target field", :target => @target)
t = event.get(@target)
t = {} unless t.is_a?(Hash)
Copy link

@guyboertje guyboertje Aug 17, 2018

Choose a reason for hiding this comment

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

Consider that if t is a scalar or array, it just goes away, this becomes a "if target is a hash: merge, otherwise overwrite" operation.

I think this is a very uncommon edge case that can be covered by updating the docs to advise the user, that if they want to keep the value at target, they should stash the value at target and add it back to the new target hash at the key of their choosing. If we support #11 then the "add back" will not fail because target is always a hash.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, that was my reasoning: if t is anything else than a hash then drop it. Thanks for mentioning #11 - this is also a legitimate concern indeed. Also looking at the add_field behaviour, it will turn the value into an array if the field exists, so we do try to avoid loosing values.

event.set(@target, t.merge(kv))
else
kv.each{|k, v| event.set(k, v)}
end
Expand Down
Loading