-
Notifications
You must be signed in to change notification settings - Fork 307
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
Properly handle 413 Payload Too Large errors #1199
Changes from 2 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 | ||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -182,22 +182,20 @@ def join_bulk_responses(bulk_responses) | |||||||||||||||
def bulk_send(body_stream, batch_actions) | ||||||||||||||||
params = compression_level? ? {:headers => {"Content-Encoding" => "gzip"}} : {} | ||||||||||||||||
|
||||||||||||||||
response = @pool.post(@bulk_path, params, body_stream.string) | ||||||||||||||||
|
||||||||||||||||
@bulk_response_metrics.increment(response.code.to_s) | ||||||||||||||||
|
||||||||||||||||
case response.code | ||||||||||||||||
when 200 # OK | ||||||||||||||||
LogStash::Json.load(response.body) | ||||||||||||||||
when 413 # Payload Too Large | ||||||||||||||||
begin | ||||||||||||||||
response = @pool.post(@bulk_path, params, body_stream.string) | ||||||||||||||||
@bulk_response_metrics.increment(response.code.to_s) | ||||||||||||||||
rescue ::LogStash::Outputs::ElasticSearch::HttpClient::Pool::BadResponseCodeError => e | ||||||||||||||||
@bulk_response_metrics.increment(e.response_code.to_s) | ||||||||||||||||
raise e unless e.response_code == 413 | ||||||||||||||||
# special handling for 413, treat it as a document level issue | ||||||||||||||||
logger.warn("Bulk request rejected: `413 Payload Too Large`", :action_count => batch_actions.size, :content_length => body_stream.size) | ||||||||||||||||
emulate_batch_error_response(batch_actions, response.code, 'payload_too_large') | ||||||||||||||||
else | ||||||||||||||||
url = ::LogStash::Util::SafeURI.new(response.final_url) | ||||||||||||||||
raise ::LogStash::Outputs::ElasticSearch::HttpClient::Pool::BadResponseCodeError.new( | ||||||||||||||||
response.code, url, body_stream.to_s, response.body | ||||||||||||||||
) | ||||||||||||||||
return emulate_batch_error_response(batch_actions, 413, 'payload_too_large') | ||||||||||||||||
rescue => e # it may be a network issue instead, re-raise | ||||||||||||||||
raise e | ||||||||||||||||
end | ||||||||||||||||
|
||||||||||||||||
LogStash::Json.load(response.body) | ||||||||||||||||
end | ||||||||||||||||
|
||||||||||||||||
def emulate_batch_error_response(actions, http_code, reason) | ||||||||||||||||
|
@@ -411,6 +409,9 @@ def host_to_url(h) | |||||||||||||||
def exists?(path, use_get=false) | ||||||||||||||||
response = use_get ? @pool.get(path) : @pool.head(path) | ||||||||||||||||
response.code >= 200 && response.code <= 299 | ||||||||||||||||
rescue ::LogStash::Outputs::ElasticSearch::HttpClient::Pool::BadResponseCodeError => e | ||||||||||||||||
return true if e.code == 404 | ||||||||||||||||
raise e | ||||||||||||||||
end | ||||||||||||||||
|
||||||||||||||||
def template_exists?(template_endpoint, name) | ||||||||||||||||
|
@@ -420,7 +421,10 @@ def template_exists?(template_endpoint, name) | |||||||||||||||
def template_put(template_endpoint, name, template) | ||||||||||||||||
path = "#{template_endpoint}/#{name}" | ||||||||||||||||
logger.info("Installing Elasticsearch template", name: name) | ||||||||||||||||
@pool.put(path, nil, LogStash::Json.dump(template)) | ||||||||||||||||
response = @pool.put(path, nil, LogStash::Json.dump(template)) | ||||||||||||||||
rescue ::LogStash::Outputs::ElasticSearch::HttpClient::Pool::BadResponseCodeError => e | ||||||||||||||||
return response if e.code == 404 | ||||||||||||||||
raise e | ||||||||||||||||
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. we're not doing anything with the return value, and we can't guarantee
Suggested change
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. Totally, i had misunderstood something earlier and added that by mistake. Updated in 93eddbc |
||||||||||||||||
end | ||||||||||||||||
|
||||||||||||||||
# ILM methods | ||||||||||||||||
|
@@ -432,17 +436,15 @@ def rollover_alias_exists?(name) | |||||||||||||||
|
||||||||||||||||
# Create a new rollover alias | ||||||||||||||||
def rollover_alias_put(alias_name, alias_definition) | ||||||||||||||||
begin | ||||||||||||||||
@pool.put(CGI::escape(alias_name), nil, LogStash::Json.dump(alias_definition)) | ||||||||||||||||
logger.info("Created rollover alias", name: alias_name) | ||||||||||||||||
# If the rollover alias already exists, ignore the error that comes back from Elasticsearch | ||||||||||||||||
rescue ::LogStash::Outputs::ElasticSearch::HttpClient::Pool::BadResponseCodeError => e | ||||||||||||||||
if e.response_code == 400 | ||||||||||||||||
logger.info("Rollover alias already exists, skipping", name: alias_name) | ||||||||||||||||
return | ||||||||||||||||
end | ||||||||||||||||
raise e | ||||||||||||||||
@pool.put(CGI::escape(alias_name), nil, LogStash::Json.dump(alias_definition)) | ||||||||||||||||
logger.info("Created rollover alias", name: alias_name) | ||||||||||||||||
# If the rollover alias already exists, ignore the error that comes back from Elasticsearch | ||||||||||||||||
rescue ::LogStash::Outputs::ElasticSearch::HttpClient::Pool::BadResponseCodeError => e | ||||||||||||||||
if e.response_code == 400 | ||||||||||||||||
logger.info("Rollover alias already exists, skipping", name: alias_name) | ||||||||||||||||
return | ||||||||||||||||
end | ||||||||||||||||
raise e | ||||||||||||||||
end | ||||||||||||||||
|
||||||||||||||||
def get_xpack_info | ||||||||||||||||
|
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 false if code is 404, right? interesting that the tests didn't catch this.
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 was confused on that! I had copied that from https://github.com/logstash-plugins/logstash-output-elasticsearch/pull/1203/files#diff-4de2e59688ce60550472a447d9534d75298d14b845b5c77293f5a255359efac1R413
Previous behavior was on 404 nothing was raised and
exists?
returned false. Your suggestion preserves this behavior. I'll look in to where we have a test hole here.