-
Notifications
You must be signed in to change notification settings - Fork 306
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
Use integration metadata to create ES actions (part 2) #1158
Use integration metadata to create ES actions (part 2) #1158
Conversation
8714d88
to
64a6ef5
Compare
64a6ef5
to
ed367e4
Compare
@@ -557,9 +554,30 @@ def common_event_params(event) | |||
# } | |||
params[:pipeline] = target_pipeline unless (target_pipeline.nil? || target_pipeline.empty?) | |||
|
|||
params[:version] = resolve_version(event, event_version) | |||
params[:version_type] = resolve_version_type(event, event_version_type) | |||
|
|||
params |
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 issues raised elsewhere could likely be resolved by leaning on Hash#compact
, which is available since Ruby 2.4 (and therefore on all Logstash 7+):
params | |
params.compact |
@@ -557,9 +554,30 @@ def common_event_params(event) | |||
# } | |||
params[:pipeline] = target_pipeline unless (target_pipeline.nil? || target_pipeline.empty?) | |||
|
|||
params[:version] = resolve_version(event, event_version) | |||
params[:version_type] = resolve_version_type(event, event_version_type) |
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.
alternate approaches to Hash#compact
to avoid storing nil values:
-
use a local variable:
Suggested changeparams[:version_type] = resolve_version_type(event, event_version_type) resolved_version_type = resolve_version_type(event, event_version_type) params[:version_type] = resolved_version_type unless resolved_version_type.nil? -
rely on safe-descent
&.
withObject#tap
:Suggested changeparams[:version_type] = resolve_version_type(event, event_version_type) resolve_version_type(event, event_version_type)&.tap { |resolved| params.store(:version_type, resolved) }
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's @yaauie to have provided also this alternative, I've opted for the one-liner compact
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.
routing => nil
is expected in some tests:
https://app.travis-ci.com/github/logstash-plugins/logstash-output-elasticsearch/jobs/613384063#L4748
This comes from the fixture
ESHelper.action_for_version(["index", {:_id=>nil, routing_field_name =>nil, :_index=>"logstash-2014.11.17", :_type=> doc_type }, event1.to_hash]) | |
else | |
ESHelper.action_for_version(["index", {:_id=>nil, routing_field_name =>nil, :_index=>"logstash-2014.11.17" }, event1.to_hash]) | |
end | |
end | |
let(:event2) { LogStash::Event.new("geoip" => { "location" => [ 0.0, 0.0] }, "@timestamp" => "2014-11-17T20:37:17.223Z", "@metadata" => {"retry_count" => 0}) } | |
let(:action2) do | |
if ESHelper.es_version_satisfies?("< 7") | |
ESHelper.action_for_version(["index", {:_id=>nil, routing_field_name =>nil, :_index=>"logstash-2014.11.17", :_type=> doc_type }, event2.to_hash]) | |
else | |
ESHelper.action_for_version(["index", {:_id=>nil, routing_field_name =>nil, :_index=>"logstash-2014.11.17" }, event2.to_hash]) |
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've reverted the behaviour only for routing
with commit e91210c
Adding `version => nil` is a change in behaviour because, actually it's never added, so this commit respect the existing logic, do not add event's keys that are empty Co-authored-by: Ry Biesemeyer <[email protected]>
… commit rollback the changes to satisfy that condition
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 👍🏼
Release notes
Added support for propagating event processing metadata when this output is downstream of an Elastic Integration Filter and configured without explicit
version
,version_type
, orrouting
directivesWhat does this PR do?
Change the creation of actions that are passed down to Elasticsearch to use also the metadata fields set by an integration.
The interested fields are
version
,version_type
androuting
, the field values are taken verbatim without placeholders resolution.The version, version_type and routing that are configured in the plugin settings have precedence on the integration ones because manifest an explicit choice made by the user.
Why is it important/What is the impact to the user?
This PR complete the fix related to interoperability issue with Agent's integrations (started with #1155), where some metadata valued by integration has to be used down to Elasticsearch.
Checklist
[ ] I have made corresponding changes to the documentation[ ] I have made corresponding change to the default configuration files (and/or docker env variables)Author's Checklist
How to test this PR locally
Please refer to the same flow used in #1155
Related issues