mirror of
https://github.com/elastic/logstash.git
synced 2025-04-24 22:57:16 -04:00
- Move search's Directory querying to be synchronous
This commit is contained in:
parent
e1839d359d
commit
405a813f68
1 changed files with 23 additions and 12 deletions
|
@ -25,9 +25,9 @@ class SearchClient < LogStash::Net::MessageClient
|
||||||
attr_reader :responding
|
attr_reader :responding
|
||||||
attr_reader :results
|
attr_reader :results
|
||||||
|
|
||||||
def initialize(opts)
|
def initialize(opts={})
|
||||||
@log_type = opts[:log_type]
|
#@log_type = opts[:log_type]
|
||||||
@query = opts[:query]
|
#@query = opts[:query]
|
||||||
@indexers = Array.new
|
@indexers = Array.new
|
||||||
@responding = Array.new
|
@responding = Array.new
|
||||||
@hits = 0
|
@hits = 0
|
||||||
|
@ -40,8 +40,12 @@ class SearchClient < LogStash::Net::MessageClient
|
||||||
def start
|
def start
|
||||||
# find our indexers
|
# find our indexers
|
||||||
msg = LogStash::Net::Messages::DirectoryRequest.new
|
msg = LogStash::Net::Messages::DirectoryRequest.new
|
||||||
sendmsg("logstash-directory", msg)
|
op = sendmsg("logstash-directory", msg) do |response|
|
||||||
run
|
DirectoryResponseHandler(response)
|
||||||
|
:finished
|
||||||
|
end
|
||||||
|
|
||||||
|
op.wait_until_finished
|
||||||
end
|
end
|
||||||
|
|
||||||
def SearchResponseHandler(msg)
|
def SearchResponseHandler(msg)
|
||||||
|
@ -65,13 +69,16 @@ class SearchClient < LogStash::Net::MessageClient
|
||||||
end
|
end
|
||||||
|
|
||||||
def DirectoryResponseHandler(msg)
|
def DirectoryResponseHandler(msg)
|
||||||
hits_msg = LogStash::Net::Messages::SearchHitsRequest.new
|
|
||||||
hits_msg.log_type = @log_type
|
|
||||||
hits_msg.query = @query
|
|
||||||
search_msg = LogStash::Net::Messages::SearchRequest.new
|
|
||||||
search_msg.log_type = @log_type
|
|
||||||
search_msg.query = @query
|
|
||||||
@indexers = msg.indexers
|
@indexers = msg.indexers
|
||||||
|
end
|
||||||
|
|
||||||
|
def search(log_type, query)
|
||||||
|
hits_msg = LogStash::Net::Messages::SearchHitsRequest.new
|
||||||
|
hits_msg.log_type = log_type
|
||||||
|
hits_msg.query = query
|
||||||
|
search_msg = LogStash::Net::Messages::SearchRequest.new
|
||||||
|
search_msg.log_type = log_type
|
||||||
|
search_msg.query = query
|
||||||
@indexers.each do |i|
|
@indexers.each do |i|
|
||||||
sendmsg(i, hits_msg)
|
sendmsg(i, hits_msg)
|
||||||
sendmsg(i, search_msg)
|
sendmsg(i, search_msg)
|
||||||
|
@ -80,7 +87,11 @@ class SearchClient < LogStash::Net::MessageClient
|
||||||
end
|
end
|
||||||
|
|
||||||
def main(args)
|
def main(args)
|
||||||
client = SearchClient.new(:log_type => args[0], :query => args[1])
|
client = SearchClient.new()
|
||||||
|
client.search(args[0], args[1])
|
||||||
|
|
||||||
|
# Wait for the client to decide it's done.
|
||||||
|
client.run
|
||||||
|
|
||||||
# Collate & print results.
|
# Collate & print results.
|
||||||
puts "Hits: #{client.hits}"
|
puts "Hits: #{client.hits}"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue