-
Notifications
You must be signed in to change notification settings - Fork 306
Remove empty event action params #464
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -321,6 +321,53 @@ | |
end | ||
end | ||
|
||
describe "remove empty params from action params" do | ||
let(:options) { {"parent" => "%{myparent}", "document_id" => "%{myid}"} } | ||
subject(:eso) {LogStash::Outputs::ElasticSearch.new(options)} | ||
|
||
let(:event_full) { LogStash::Event.new("message" => "blah", "myid" => "mytestid", "myparent" => "mytestparent") } | ||
let(:event_partial_missing) { LogStash::Event.new("message" => "blah") } | ||
let(:event_partial_empty) { LogStash::Event.new("message" => "blah", "myid" => "", "myparent" => "") } | ||
|
||
context "when remove_empty_action_params enabled" do | ||
let(:options) { super.merge("remove_empty_action_params" => true) } | ||
|
||
it "should interpolate the requested id and parent values" do | ||
params = eso.event_action_params(event_full) | ||
expect(params).to include(:_id => "mytestid", :parent => "mytestparent") | ||
end | ||
|
||
it "should interpolate the requested id and parent values and leave them as is (sprintf behavior, not sure if correct one) when they missing" do | ||
params = eso.event_action_params(event_partial_missing) | ||
expect(params).to include(:_id => "%{myid}", :parent => "%{myparent}") | ||
end | ||
|
||
it "should not interpolate the requested id and parent values and remove them when they are empty" do | ||
params = eso.event_action_params(event_partial_empty) | ||
expect(params).not_to include(:_id, :parent) | ||
end | ||
end | ||
|
||
context "when remove_empty_action_params disabled" do | ||
let(:options) { super.merge("remove_empty_action_params" => false) } | ||
|
||
it "should interpolate the requested id and parent values" do | ||
params = eso.event_action_params(event_full) | ||
expect(params).to include({:_id => "mytestid", :parent => "mytestparent"}) | ||
end | ||
|
||
it "should interpolate the requested id and parent values and leave them as is (sprintf behavior, not sure if correct one) when they missing" do | ||
params = eso.event_action_params(event_partial_missing) | ||
expect(params).to include(:_id => "%{myid}", :parent => "%{myparent}") | ||
end | ||
|
||
it "should interpolate the requested id and parent values and leave them as is (sprintf behavior, not sure if correct one) when they empty" do | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This just repeats the previous test. I think you wanted to test that this should interpolate the requested id and parent values. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeas, those are two identical tests, just to see the actual difference in behavior what happens when proposed remove_empty_action_params param set to true and to false. |
||
params = eso.event_action_params(event_partial_missing) | ||
expect(params).to include(:_id => "%{myid}", :parent => "%{myparent}") | ||
end | ||
end | ||
end | ||
|
||
describe "sleep interval calculation" do | ||
let(:retry_max_interval) { 64 } | ||
subject(:eso) { LogStash::Outputs::ElasticSearch.new("retry_max_interval" => retry_max_interval) } | ||
|
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.
This behavior isn't great, but I don't know what else we can do here. I think this should be documented in the option docs.