mirror of
https://github.com/elastic/logstash.git
synced 2025-04-24 22:57:16 -04:00
- More histogram work.
- Have LogStash::Search::ElasticSearch#histogram yield an error if one occurs - /api/histogram reports an error now if 'q' param is missing
This commit is contained in:
parent
e8f43c15d2
commit
d674dd475e
3 changed files with 22 additions and 6 deletions
|
@ -122,14 +122,22 @@ class LogStash::Search::ElasticSearch < LogStash::Search::Base
|
||||||
result.duration = Time.now - start_time
|
result.duration = Time.now - start_time
|
||||||
|
|
||||||
@logger.info(["Got search results",
|
@logger.info(["Got search results",
|
||||||
{ :query => query.query_string, :duration => data["duration"],
|
{ :query => query.query_string, :duration => data["duration"] }])
|
||||||
:results => data["hits"]["hits"].size }])
|
|
||||||
if req.response_header.status != 200
|
if req.response_header.status != 200
|
||||||
result.error_message = data["error"] || req.inspect
|
result.error_message = data["error"] || req.inspect
|
||||||
@error = data["error"] || req.inspect
|
@error = data["error"] || req.inspect
|
||||||
end
|
end
|
||||||
|
|
||||||
data["facets"]["amazingpants"]["entries"].each do |entry|
|
entries = data["facets"]["amazingpants"]["entries"] rescue nil
|
||||||
|
|
||||||
|
if entries.nil? or !data["error"].nil?
|
||||||
|
# Use the error message if any, otherwise, return the whole
|
||||||
|
# data object as json as the error message for debugging later.
|
||||||
|
result.error_message = (data["error"] rescue false) || data.to_json
|
||||||
|
yield result
|
||||||
|
next
|
||||||
|
end
|
||||||
|
entries.each do |entry|
|
||||||
# entry is a hash of keys 'total', 'mean', 'count', and 'key'
|
# entry is a hash of keys 'total', 'mean', 'count', and 'key'
|
||||||
hist_entry = LogStash::Search::FacetResult::Histogram.new
|
hist_entry = LogStash::Search::FacetResult::Histogram.new
|
||||||
hist_entry.key = entry["key"]
|
hist_entry.key = entry["key"]
|
||||||
|
|
|
@ -9,8 +9,8 @@ class LogStash::Search::FacetResult::Histogram < LogStash::Search::FacetResult::
|
||||||
attr_accessor :total
|
attr_accessor :total
|
||||||
attr_accessor :count
|
attr_accessor :count
|
||||||
|
|
||||||
|
# sometimes a parent call to to_json calls us with args?
|
||||||
def to_json(*args)
|
def to_json(*args)
|
||||||
p :to_json => args
|
|
||||||
return {
|
return {
|
||||||
"key" => @key,
|
"key" => @key,
|
||||||
"mean" => @mean,
|
"mean" => @mean,
|
||||||
|
|
|
@ -163,6 +163,11 @@ class LogStash::Web::Server < Sinatra::Base
|
||||||
|
|
||||||
aget '/api/histogram' do
|
aget '/api/histogram' do
|
||||||
headers({"Content-Type" => "text/plain" })
|
headers({"Content-Type" => "text/plain" })
|
||||||
|
if params[:q].nil?
|
||||||
|
status 500
|
||||||
|
body({ "error" => "No query given (missing 'q' parameter)" }.to_json)
|
||||||
|
next
|
||||||
|
end
|
||||||
format = (params[:format] or "json")
|
format = (params[:format] or "json")
|
||||||
field = (params[:field] or "@timestamp")
|
field = (params[:field] or "@timestamp")
|
||||||
interval = (params[:interval] or 3600 * 1000)
|
interval = (params[:interval] or 3600 * 1000)
|
||||||
|
@ -175,15 +180,18 @@ class LogStash::Web::Server < Sinatra::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
begin
|
begin
|
||||||
p results.results.class
|
|
||||||
a = results.results.to_json
|
a = results.results.to_json
|
||||||
rescue => e
|
rescue => e
|
||||||
|
status 500
|
||||||
|
body e.inspect
|
||||||
|
p :exception => e
|
||||||
p e
|
p e
|
||||||
raise e
|
raise e
|
||||||
end
|
end
|
||||||
|
status 200
|
||||||
body a
|
body a
|
||||||
end # @backend.search
|
end # @backend.search
|
||||||
end # apost '/api/search'
|
end # aget '/api/histogram'
|
||||||
|
|
||||||
aget '/*' do
|
aget '/*' do
|
||||||
status 404 if @error
|
status 404 if @error
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue