Skip to content

Commit 986d76f

Browse files
authored
Feat: always check ES license (#1005)
1 parent 5cff49a commit 986d76f

File tree

6 files changed

+47
-50
lines changed

6 files changed

+47
-50
lines changed

.travis.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,3 @@ env:
99
- DISTRIBUTION=default INTEGRATION=true ELASTIC_STACK_VERSION=7.x SNAPSHOT=true
1010
- DISTRIBUTION=default INTEGRATION=true ELASTIC_STACK_VERSION=8.x SNAPSHOT=true
1111
- DISTRIBUTION=default SECURE_INTEGRATION=true INTEGRATION=true ELASTIC_STACK_VERSION=7.x
12-
- DISTRIBUTION=oss INTEGRATION=true ELASTIC_STACK_VERSION=7.10.2 # since 7.11 no OSS artifact

CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1-
## 10.9.0
1+
## 11.0.0
22
- Feat: Data stream support [#988](https://github.com/logstash-plugins/logstash-output-elasticsearch/pull/988)
33
- Refactor: reviewed logging format + restored ES (initial) setup error logging
4+
- Feat: always check ES license [#1005](https://github.com/logstash-plugins/logstash-output-elasticsearch/pull/1005)
5+
6+
Since Elasticsearch no longer provides an OSS artifact the plugin will no longer skip the license check on OSS Logstash.
47

58
## 10.8.6
69
- Fixed an issue where a single over-size event being rejected by Elasticsearch would cause the entire entire batch to be retried indefinitely. The oversize event will still be retried on its own and logging has been improved to include payload sizes in this situation [#972](https://github.com/logstash-plugins/logstash-output-elasticsearch/pull/972)

lib/logstash/outputs/elasticsearch/license_checker.rb

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,41 +7,38 @@ def initialize(logger)
77

88
# Figure out if the provided license is appropriate or not
99
# The appropriate_license? methods is the method called from LogStash::Outputs::ElasticSearch::HttpClient::Pool#healthcheck!
10+
# @param pool
1011
# @param url [LogStash::Util::SafeURI] ES node URL
11-
# @param license [Hash] ES node deserialized licence document
1212
# @return [Boolean] true if provided license is deemed appropriate
1313
def appropriate_license?(pool, url)
14-
return true if oss?
15-
1614
license = pool.get_license(url)
17-
if valid_es_license?(license)
15+
case license_status(license)
16+
when 'active'
1817
true
19-
else
20-
# As this version is to be shipped with Logstash 7.x we won't mark the connection as unlicensed
21-
#
22-
# @logger.error("Cannot connect to the Elasticsearch cluster configured in the Elasticsearch output. Logstash requires the default distribution of Elasticsearch. Please update to the default distribution of Elasticsearch for full access to all free features, or switch to the OSS distribution of Logstash.", :url => url.sanitized.to_s)
23-
# meta[:state] = :unlicensed
24-
#
25-
# Instead we'll log a deprecation warning and mark it as alive:
26-
#
27-
log_license_deprecation_warn(url)
18+
when nil
19+
warn_no_license(url)
20+
false
21+
else # 'invalid', 'expired'
22+
warn_invalid_license(url, license)
2823
true
2924
end
3025
end
3126

32-
# Note that oss? could be private but is used by the Pool specs
33-
def oss?
34-
LogStash::OSS
27+
def license_status(license)
28+
license.fetch("license", {}).fetch("status", nil)
3529
end
3630

37-
# Note that valid_es_license? could be private but is used by the Pool specs
38-
def valid_es_license?(license)
39-
license.fetch("license", {}).fetch("status", nil) == "active"
31+
private
32+
33+
def warn_no_license(url)
34+
@logger.error("Connecting to an OSS distribution of Elasticsearch is no longer supported, " +
35+
"please upgrade to the default distribution of Elasticsearch", url: url.sanitized.to_s)
4036
end
4137

42-
# Note that log_license_deprecation_warn could be private but is used by the Pool specs
43-
def log_license_deprecation_warn(url)
44-
@logger.warn("DEPRECATION WARNING: Connecting to an OSS distribution of Elasticsearch using the default distribution of Logstash will stop working in Logstash 8.0.0. Please upgrade to the default distribution of Elasticsearch, or use the OSS distribution of Logstash", :url => url.sanitized.to_s)
38+
def warn_invalid_license(url, license)
39+
@logger.warn("WARNING: Current Elasticsearch license is not active, " +
40+
"please check Elasticsearch's licensing information", url: url.sanitized.to_s, license: license)
4541
end
42+
4643
end
4744
end; end; end

logstash-output-elasticsearch.gemspec

Lines changed: 1 addition & 1 deletion
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 = '10.9.0'
3+
s.version = '11.0.0'
44

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

spec/unit/outputs/elasticsearch/http_client/pool_spec.rb

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
let(:options) { {:resurrect_delay => 2, :url_normalizer => proc {|u| u}} } # Shorten the delay a bit to speed up tests
1010
let(:es_node_versions) { [ "0.0.0" ] }
1111
let(:oss) { true }
12-
let(:valid_license) { true }
12+
let(:license_status) { 'active' }
1313

1414
subject { described_class.new(logger, adapter, initial_urls, options) }
1515

@@ -26,8 +26,7 @@
2626
allow(::Manticore::Client).to receive(:new).and_return(manticore_double)
2727

2828
allow(subject).to receive(:get_es_version).with(any_args).and_return(*es_node_versions)
29-
allow(subject.license_checker).to receive(:oss?).and_return(oss)
30-
allow(subject.license_checker).to receive(:valid_es_license?).and_return(valid_license)
29+
allow(subject.license_checker).to receive(:license_status).and_return(license_status)
3130
end
3231

3332
after do
@@ -283,29 +282,44 @@
283282
let(:oss) { false }
284283

285284
context "if ES doesn't return a valid license" do
286-
let(:valid_license) { false }
285+
let(:license_status) { nil }
287286

288-
it "marks the url as active" do
287+
it "marks the url as dead" do
289288
subject.update_initial_urls
290-
expect(subject.alive_urls_count).to eq(1)
289+
expect(subject.alive_urls_count).to eq(0)
291290
end
292291

293292
it "logs a warning" do
294-
expect(subject.license_checker).to receive(:log_license_deprecation_warn).once
293+
expect(subject.license_checker).to receive(:warn_no_license).once.and_call_original
295294
subject.update_initial_urls
296295
end
297296
end
298297

299298
context "if ES returns a valid license" do
300-
let(:valid_license) { true }
299+
let(:license_status) { 'active' }
301300

302301
it "marks the url as active" do
303302
subject.update_initial_urls
304303
expect(subject.alive_urls_count).to eq(1)
305304
end
306305

307306
it "does not log a warning" do
308-
expect(subject.license_checker).to_not receive(:log_license_deprecation_warn)
307+
expect(subject.license_checker).to_not receive(:warn_no_license)
308+
expect(subject.license_checker).to_not receive(:warn_invalid_license)
309+
subject.update_initial_urls
310+
end
311+
end
312+
313+
context "if ES returns an invalid license" do
314+
let(:license_status) { 'invalid' }
315+
316+
it "marks the url as active" do
317+
subject.update_initial_urls
318+
expect(subject.alive_urls_count).to eq(1)
319+
end
320+
321+
it "logs a warning" do
322+
expect(subject.license_checker).to receive(:warn_invalid_license).and_call_original
309323
subject.update_initial_urls
310324
end
311325
end

spec/unit/outputs/license_check_spec.rb

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,6 @@
1414
end
1515
end
1616

17-
context "LicenseChecker API required by Pool specs" do
18-
subject { described_class }
19-
20-
it "defines the oss? method" do
21-
expect(subject.instance_methods).to include(:oss?)
22-
end
23-
24-
it "defines the valid_es_license? method" do
25-
expect(subject.instance_methods).to include(:valid_es_license?)
26-
end
27-
28-
it "defines the log_license_deprecation_warn method" do
29-
expect(subject.instance_methods).to include(:log_license_deprecation_warn)
30-
end
31-
end
32-
3317
context "Pool class API required by the LicenseChecker" do
3418
subject { LogStash::Outputs::ElasticSearch::HttpClient::Pool }
3519

0 commit comments

Comments
 (0)