-
Notifications
You must be signed in to change notification settings - Fork 306
Validate the action before sending the bulk request to ES. #1080
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
Validate the action before sending the bulk request to ES. #1080
Conversation
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.
We have an ordering problem, since the per-event responses must be emitted in the same order as the actions we received.
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.
Sorry to chime in, I saw this while working on #1084, and had similar problem in pre-validate a condition (in my case the sprintf
of the index
is fully resolved) and in case send to DLQ.
…rement non retriable metric.
5c57e56
to
ad889cd
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.
The changes you proposed seems good to me.
Left a couple of notes on test's expectations, if should be re-enabled plus a concern about the eventuality to log something in case a mapping error happens.
it "rejects unsupported actions" do | ||
event_result = subject.send(:safe_interpolation_map_events, events) | ||
expect(event_result.successful_events.size).to be == 2 | ||
# expect(logger_stub).to have_received(:warn).with(a_string_including "Could not index event to Elasticsearch because its action is not supported.") |
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.
Should be re-enabled to check also the failed ones?
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.
Yup, added in new commits.
@logger.error("Can't map some events, needs to be handled by DLQ #{events_mapped.failed_events}") | ||
send_failed_resolutions_to_dlq(events_mapped.failed_events) | ||
unless events_mapped.event_mapping_errors.empty? | ||
handle_event_mapping_errors(events_mapped.event_mapping_errors) |
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.
If dlq is enabled then no log lines are logged. I think that any mapping error, that route events to DLQ, should be clearly highlighted into the logs, so a warn
log line should be present to eventually understand what's happening.
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.
To avoid flooding I would like to log a single INFO for the batch if the DLQ is enabled (including the quantity of events from the batch), or to defer to the per-event WARN if there is no DLQ and we need to drop the event. Users who have the DLQ enabled should already be in a position to monitor its growth.
@logger.error("Can't map some events, needs to be handled by DLQ #{events_mapped.failed_events}") | ||
send_failed_resolutions_to_dlq(events_mapped.failed_events) | ||
unless events_mapped.event_mapping_errors.empty? | ||
handle_event_mapping_errors(events_mapped.event_mapping_errors) |
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.
To avoid flooding I would like to log a single INFO for the batch if the DLQ is enabled (including the quantity of events from the batch), or to defer to the per-event WARN if there is no DLQ and we need to drop the event. Users who have the DLQ enabled should already be in a position to monitor its growth.
detail_message = message + ", " + action.to_s | ||
handle_dlq_status(action.event, :warn, detail_message) |
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 would prefer a rephrase of this, so that event_mapping_errors
was either an array of event
/message
tuples or an array of objects that have event
/message
properties, since action
in this code is somewhat ambiguous and can mean either a String action or an action-tuple as prepared for a bulk request.
When we are building this array, we already have access to the event and an object that has the message (the exception), and when we are raising the exception we have access to the event
. We could either create a specialized struct, or can embed the event into the exception that we are already handling.
Additionally, we have everything we need to produce our detail_message
when populating the array (or even when throwing the relevant exception that leads to an entry in the array), so I would rather pull that up.
Set to bugfix version, accept detailed overview about the change. Co-authored-by: Ry Biesemeyer <yaauie@users.noreply.github.com>
… Event is considered. Giving a noti to users when DQL enabled and failed events sent to it.
]} | ||
it "rejects unsupported actions" do | ||
event_result = subject.send(:safe_interpolation_map_events, events) | ||
expect(event_result.successful_events.size).to be == 3 |
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.
@yaauie , I really liked the idea of having rspec-collection_matchers
when unit tests check agains collections sizes. I understood more about use cases after taking a look at this thread.
However, in order to use collection_matchers
, we need to onboard it with LS-core (add gem "rspec-collection_matchers", :group => :development
in Gemfile.template
file).
Let me know your thoughts if I can add it to plugin level dependency.
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 could go either way -- the failure scenario reads "clear enough" for these specs.
The normal way of adding the dependency would be to declare a development dependency in this project's gemspec, not in Logstash core.
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.
Left one follow-up on the collections expectations. Feel free to either chase it down or merge as-is.
…es in the test cases.
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 🎉
What this PR does?
Plugin receives
400 Validation Failed: 1: no requests added
exception when requesting unsupported bulk action.This PR introduces a validation check on action before sending bulk request to ES.
Closes #1079
Test
Manual testing
index
,create
,update
,delete
]Unit testing
rspec spec/unit/outputs/elasticsearch_spec.rb
Logs