Skip to content

Commit 91b2de5

Browse files
authored
add license check as a criteria of connection check (logstash-plugins#1035)
This commit fixes post-register action when Elasticsearch status change from unhealthy to healthy The connection is classified as alive when it passed `/` and `/_license` check Fixed: logstash-plugins#1034
1 parent 0862069 commit 91b2de5

File tree

7 files changed

+29
-2
lines changed

7 files changed

+29
-2
lines changed

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
## 11.0.5
2+
- Fixed running post-register action when Elasticsearch status change from unhealthy to healthy [#1035](https://github.com/logstash-plugins/logstash-output-elasticsearch/pull/1035)
3+
14
## 11.0.4
25
- [DOC] Clarify that `http_compression` applies to _requests_, and remove noise about _response_ decompression [#1000](https://github.com/logstash-plugins/logstash-output-elasticsearch/pull/1000)
36

lib/logstash/outputs/elasticsearch/http_client.rb

+4
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,10 @@ def maximum_seen_major_version
9292
@pool.maximum_seen_major_version
9393
end
9494

95+
def alive_urls_count
96+
@pool.alive_urls_count
97+
end
98+
9599
def bulk(actions)
96100
@action_count ||= 0
97101
@action_count += actions.size

lib/logstash/plugin_mixins/elasticsearch/common.rb

+5-1
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,12 @@ def maximum_seen_major_version
128128
client.maximum_seen_major_version
129129
end
130130

131+
def alive_urls_count
132+
client.alive_urls_count
133+
end
134+
131135
def successful_connection?
132-
!!maximum_seen_major_version
136+
!!maximum_seen_major_version && alive_urls_count > 0
133137
end
134138

135139
# launch a thread that waits for an initial successful connection to the ES cluster to call the given block

logstash-output-elasticsearch.gemspec

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Gem::Specification.new do |s|
22
s.name = 'logstash-output-elasticsearch'
3-
s.version = '11.0.4'
3+
s.version = '11.0.5'
44

55
s.licenses = ['apache-2.0']
66
s.summary = "Stores logs in Elasticsearch"

spec/integration/outputs/no_es_on_startup_spec.rb

+14
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,18 @@
5555
expect(r).to have_hits(2)
5656
end
5757

58+
it 'should get cluster_uuid when Elasticsearch recovers from license check failure' do
59+
allow_any_instance_of(LogStash::Outputs::ElasticSearch::HttpClient::Pool).to receive(:get_license).with(instance_of(LogStash::Util::SafeURI)).and_raise(::LogStash::Outputs::ElasticSearch::HttpClient::Pool::HostUnreachableError.new(StandardError.new, "big fail"))
60+
subject.register
61+
Thread.new do
62+
sleep 4
63+
allow_any_instance_of(LogStash::Outputs::ElasticSearch::HttpClient::Pool).to receive(:get_license).with(instance_of(LogStash::Util::SafeURI)).and_call_original
64+
end
65+
subject.multi_receive([event1, event2])
66+
@es.indices.refresh
67+
r = @es.search(index: 'logstash-*')
68+
expect(r).to have_hits(2)
69+
expect(subject.plugin_metadata.get(:cluster_uuid)).not_to be_empty
70+
expect(subject.plugin_metadata.get(:cluster_uuid)).not_to eq("_na_")
71+
end if ESHelper.es_version_satisfies?(">=7")
5872
end

spec/unit/outputs/elasticsearch_spec.rb

+1
Original file line numberDiff line numberDiff line change
@@ -934,6 +934,7 @@
934934
allow(subject).to receive(:last_es_version).and_return es_version
935935
# make successful_connection? return true:
936936
allow(subject).to receive(:maximum_seen_major_version).and_return Integer(es_version.split('.').first)
937+
allow(subject).to receive(:alive_urls_count).and_return Integer(1)
937938
allow(subject).to receive(:stop_after_successful_connection_thread)
938939
end
939940

spec/unit/outputs/error_whitelist_spec.rb

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
before :each do
1313
allow(subject.logger).to receive(:warn)
1414
allow(subject).to receive(:maximum_seen_major_version).and_return(0)
15+
allow(subject).to receive(:alive_urls_count).and_return(1)
1516
allow(subject).to receive(:finish_register)
1617

1718
subject.register

0 commit comments

Comments
 (0)