Skip to content

Commit c04401b

Browse files
authored
fix case when aggregation returns an error (#204)
1 parent a878179 commit c04401b

File tree

4 files changed

+18
-5
lines changed

4 files changed

+18
-5
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
## 4.20.2
2+
- fix case when aggregation returns an error [#204](https://github.com/logstash-plugins/logstash-input-elasticsearch/pull/204)
3+
14
## 4.20.1
25
- Fix license header [#203](https://github.com/logstash-plugins/logstash-input-elasticsearch/pull/203)
36

lib/logstash/inputs/elasticsearch/aggregation.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,15 @@ def retryable(job_name, &block)
3030
error_details = {:message => e.message, :cause => e.cause}
3131
error_details[:backtrace] = e.backtrace if logger.debug?
3232
logger.error("Tried #{job_name} unsuccessfully", error_details)
33+
false
3334
end
3435

3536
def do_run(output_queue)
3637
logger.info("Aggregation starting")
3738
r = retryable(AGGREGATION_JOB) do
3839
@client.search(@agg_options)
3940
end
40-
@plugin.push_hit(r, output_queue, 'aggregations')
41+
@plugin.push_hit(r, output_queue, 'aggregations') if r
4142
end
4243
end
4344
end

logstash-input-elasticsearch.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Gem::Specification.new do |s|
22

33
s.name = 'logstash-input-elasticsearch'
4-
s.version = '4.20.1'
4+
s.version = '4.20.2'
55
s.licenses = ['Apache License (2.0)']
66
s.summary = "Reads query results from an Elasticsearch cluster"
77
s.description = "This gem is a Logstash plugin required to be installed on top of the Logstash core pipeline using $LS_HOME/bin/logstash-plugin install gemname. This gem is not a stand-alone program"

spec/inputs/elasticsearch_spec.rb

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1071,24 +1071,33 @@ def wait_receive_request
10711071
}
10721072
end
10731073

1074+
let(:client) { Elasticsearch::Client.new }
10741075
before(:each) do
1075-
client = Elasticsearch::Client.new
1076-
10771076
expect(Elasticsearch::Client).to receive(:new).with(any_args).and_return(client)
1078-
expect(client).to receive(:search).with(any_args).and_return(mock_response)
10791077
expect(client).to receive(:ping)
10801078
end
10811079

10821080
before { plugin.register }
10831081

10841082
it 'creates the events from the aggregations' do
1083+
expect(client).to receive(:search).with(any_args).and_return(mock_response)
10851084
plugin.run queue
10861085
event = queue.pop
10871086

10881087
expect(event).to be_a(LogStash::Event)
10891088
expect(event.get("[total_counter][value]")).to eql 10
10901089
expect(event.get("[empty_counter][value]")).to eql 5
10911090
end
1091+
1092+
context "when there's an exception" do
1093+
before(:each) do
1094+
allow(client).to receive(:search).and_raise RuntimeError
1095+
end
1096+
it 'produces no events' do
1097+
plugin.run queue
1098+
expect(queue).to be_empty
1099+
end
1100+
end
10921101
end
10931102

10941103
context "retries" do

0 commit comments

Comments
 (0)