-
Notifications
You must be signed in to change notification settings - Fork 86
Add robustness around scrolling #128
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
Merged
colinsurprenant
merged 2 commits into
logstash-plugins:master
from
colinsurprenant:clear_scroll
Jun 2, 2020
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -204,9 +204,12 @@ def register | |
|
|
||
| transport_options[:proxy] = @proxy.to_s if @proxy && [email protected]?('') | ||
|
|
||
| @client = Elasticsearch::Client.new(:hosts => hosts, :transport_options => transport_options, | ||
| :transport_class => ::Elasticsearch::Transport::Transport::HTTP::Manticore, | ||
| :ssl => ssl_options) | ||
| @client = Elasticsearch::Client.new( | ||
| :hosts => hosts, | ||
| :transport_options => transport_options, | ||
| :transport_class => ::Elasticsearch::Transport::Transport::HTTP::Manticore, | ||
| :ssl => ssl_options | ||
| ) | ||
| end | ||
|
|
||
| ## | ||
|
|
@@ -266,25 +269,41 @@ def do_run_slice(output_queue, slice_id=nil) | |
| slice_options = @options.merge(:body => LogStash::Json.dump(slice_query) ) | ||
|
|
||
| logger.info("Slice starting", slice_id: slice_id, slices: @slices) unless slice_id.nil? | ||
| r = search_request(slice_options) | ||
|
|
||
| r['hits']['hits'].each { |hit| push_hit(hit, output_queue) } | ||
| logger.debug("Slice progress", slice_id: slice_id, slices: @slices) unless slice_id.nil? | ||
|
|
||
| has_hits = r['hits']['hits'].any? | ||
| scroll_id = nil | ||
| begin | ||
| r = search_request(slice_options) | ||
|
|
||
| while has_hits && r['_scroll_id'] && !stop? | ||
| r = process_next_scroll(output_queue, r['_scroll_id']) | ||
| r['hits']['hits'].each { |hit| push_hit(hit, output_queue) } | ||
| logger.debug("Slice progress", slice_id: slice_id, slices: @slices) unless slice_id.nil? | ||
| has_hits = r['has_hits'] | ||
|
|
||
| has_hits = r['hits']['hits'].any? | ||
| scroll_id = r['_scroll_id'] | ||
|
|
||
| while has_hits && scroll_id && !stop? | ||
| has_hits, scroll_id = process_next_scroll(output_queue, scroll_id) | ||
| logger.debug("Slice progress", slice_id: slice_id, slices: @slices) if logger.debug? && slice_id | ||
| end | ||
| logger.info("Slice complete", slice_id: slice_id, slices: @slices) unless slice_id.nil? | ||
| ensure | ||
| clear_scroll(scroll_id) | ||
| end | ||
| logger.info("Slice complete", slice_id: slice_id, slices: @slices) unless slice_id.nil? | ||
| end | ||
|
|
||
| ## | ||
| # @param output_queue [#<<] | ||
| # @param scroll_id [String]: a scroll id to resume | ||
| # @return [Array(Boolean,String)]: a tuple representing whether the response | ||
| # | ||
| def process_next_scroll(output_queue, scroll_id) | ||
colinsurprenant marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| r = scroll_request(scroll_id) | ||
| r['hits']['hits'].each { |hit| push_hit(hit, output_queue) } | ||
| {'has_hits' => r['hits']['hits'].any?, '_scroll_id' => r['_scroll_id']} | ||
| [r['hits']['hits'].any?, r['_scroll_id']] | ||
colinsurprenant marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| rescue => e | ||
| # this will typically be triggered by a scroll timeout | ||
| logger.error("Scroll request error, aborting scroll", error: e.inspect) | ||
| # return no hits and original scroll_id so we can try to clear it | ||
| [false, scroll_id] | ||
| end | ||
|
|
||
| def push_hit(hit, output_queue) | ||
|
|
@@ -313,16 +332,21 @@ def push_hit(hit, output_queue) | |
| output_queue << event | ||
| end | ||
|
|
||
| def clear_scroll(scroll_id) | ||
| @client.clear_scroll(scroll_id: scroll_id) if scroll_id | ||
| rescue => e | ||
| # ignore & log any clear_scroll errors | ||
| logger.warn("Ignoring clear_scroll exception", message: e.message) | ||
| end | ||
|
|
||
| def scroll_request scroll_id | ||
| client.scroll(:body => { :scroll_id => scroll_id }, :scroll => @scroll) | ||
| @client.scroll(:body => { :scroll_id => scroll_id }, :scroll => @scroll) | ||
| end | ||
|
|
||
| def search_request(options) | ||
| client.search(options) | ||
| @client.search(options) | ||
| end | ||
|
|
||
| attr_reader :client | ||
|
|
||
| def hosts_default?(hosts) | ||
| hosts.nil? || ( hosts.is_a?(Array) && hosts.empty? ) | ||
| end | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.