logstash-output-elasticsearch 12.0.1-java → 12.0.3-java
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/docs/index.asciidoc +18 -8
- data/lib/logstash/outputs/elasticsearch/data_stream_support.rb +0 -1
- data/lib/logstash/outputs/elasticsearch/http_client/manticore_adapter.rb +1 -4
- data/lib/logstash/outputs/elasticsearch/http_client/pool.rb +17 -20
- data/lib/logstash/outputs/elasticsearch/http_client.rb +25 -24
- data/lib/logstash/outputs/elasticsearch/ilm.rb +1 -11
- data/lib/logstash/outputs/elasticsearch/template_manager.rb +1 -1
- data/lib/logstash/outputs/elasticsearch.rb +10 -45
- data/logstash-output-elasticsearch.gemspec +1 -1
- data/spec/es_spec_helper.rb +35 -27
- data/spec/integration/outputs/compressed_indexing_spec.rb +5 -5
- data/spec/integration/outputs/delete_spec.rb +4 -4
- data/spec/integration/outputs/ilm_spec.rb +18 -12
- data/spec/integration/outputs/index_spec.rb +7 -7
- data/spec/integration/outputs/index_version_spec.rb +7 -7
- data/spec/integration/outputs/no_es_on_startup_spec.rb +1 -1
- data/spec/integration/outputs/painless_update_spec.rb +11 -10
- data/spec/integration/outputs/parent_spec.rb +2 -3
- data/spec/integration/outputs/retry_spec.rb +2 -10
- data/spec/integration/outputs/sniffer_spec.rb +5 -40
- data/spec/integration/outputs/unsupported_actions_spec.rb +15 -10
- data/spec/integration/outputs/update_spec.rb +11 -9
- data/spec/spec_helper.rb +8 -0
- data/spec/unit/outputs/elasticsearch/data_stream_support_spec.rb +0 -23
- data/spec/unit/outputs/elasticsearch/http_client/pool_spec.rb +12 -54
- data/spec/unit/outputs/elasticsearch/template_manager_spec.rb +3 -8
- data/spec/unit/outputs/elasticsearch_spec.rb +15 -17
- data/spec/unit/outputs/error_whitelist_spec.rb +0 -1
- metadata +2 -12
- data/lib/logstash/outputs/elasticsearch/templates/ecs-disabled/elasticsearch-6x.json +0 -45
- data/lib/logstash/outputs/elasticsearch/templates/ecs-v1/elasticsearch-6x.json +0 -3695
- data/spec/fixtures/_nodes/6x.json +0 -81
- data/spec/fixtures/template-with-policy-es6x.json +0 -48
- data/spec/support/elasticsearch/api/actions/get_alias.rb +0 -18
- data/spec/support/elasticsearch/api/actions/put_alias.rb +0 -24
@@ -102,7 +102,7 @@ shared_examples_for 'an ILM disabled Logstash' do
|
|
102
102
|
it 'should not install the default policy' do
|
103
103
|
subject.register
|
104
104
|
sleep(1)
|
105
|
-
expect{get_policy(@es, LogStash::Outputs::ElasticSearch::DEFAULT_POLICY)}.to raise_error(
|
105
|
+
expect{get_policy(@es, LogStash::Outputs::ElasticSearch::DEFAULT_POLICY)}.to raise_error(get_expected_error_class)
|
106
106
|
end
|
107
107
|
|
108
108
|
it 'should not write the ILM settings into the template' do
|
@@ -282,12 +282,12 @@ describe 'Elasticsearch has index lifecycle management enabled', :integration =>
|
|
282
282
|
subject.register
|
283
283
|
sleep(1)
|
284
284
|
expect(@es.indices.exists_alias(name: "logstash")).to be_truthy
|
285
|
-
expect(@es.get_alias(name: "logstash")).to include("logstash-000001")
|
285
|
+
expect(@es.indices.get_alias(name: "logstash")).to include("logstash-000001")
|
286
286
|
end
|
287
287
|
end
|
288
288
|
|
289
289
|
it 'should install it if it is not present' do
|
290
|
-
expect{get_policy(@es, LogStash::Outputs::ElasticSearch::DEFAULT_POLICY)}.to raise_error(
|
290
|
+
expect{get_policy(@es, LogStash::Outputs::ElasticSearch::DEFAULT_POLICY)}.to raise_error(get_expected_error_class)
|
291
291
|
subject.register
|
292
292
|
sleep(1)
|
293
293
|
expect{get_policy(@es, LogStash::Outputs::ElasticSearch::DEFAULT_POLICY)}.not_to raise_error
|
@@ -298,7 +298,7 @@ describe 'Elasticsearch has index lifecycle management enabled', :integration =>
|
|
298
298
|
subject.register
|
299
299
|
sleep(1)
|
300
300
|
expect(@es.indices.exists_alias(name: "logstash")).to be_truthy
|
301
|
-
expect(@es.get_alias(name: "logstash")).to include("logstash-#{todays_date}-000001")
|
301
|
+
expect(@es.indices.get_alias(name: "logstash")).to include("logstash-#{todays_date}-000001")
|
302
302
|
end
|
303
303
|
|
304
304
|
it 'should ingest into a single index' do
|
@@ -340,14 +340,14 @@ describe 'Elasticsearch has index lifecycle management enabled', :integration =>
|
|
340
340
|
let (:policy) { small_max_doc_policy }
|
341
341
|
|
342
342
|
before do
|
343
|
-
expect{get_policy(@es, LogStash::Outputs::ElasticSearch::DEFAULT_POLICY)}.to raise_error(
|
343
|
+
expect{get_policy(@es, LogStash::Outputs::ElasticSearch::DEFAULT_POLICY)}.to raise_error(get_expected_error_class)
|
344
344
|
put_policy(@es,ilm_policy_name, policy)
|
345
345
|
end
|
346
346
|
|
347
347
|
it 'should not install the default policy if it is not used' do
|
348
348
|
subject.register
|
349
349
|
sleep(1)
|
350
|
-
expect{get_policy(@es, LogStash::Outputs::ElasticSearch::DEFAULT_POLICY)}.to raise_error(
|
350
|
+
expect{get_policy(@es, LogStash::Outputs::ElasticSearch::DEFAULT_POLICY)}.to raise_error(get_expected_error_class)
|
351
351
|
end
|
352
352
|
end
|
353
353
|
|
@@ -357,14 +357,14 @@ describe 'Elasticsearch has index lifecycle management enabled', :integration =>
|
|
357
357
|
let (:policy) { max_age_policy("1d") }
|
358
358
|
|
359
359
|
before do
|
360
|
-
expect{get_policy(@es, LogStash::Outputs::ElasticSearch::DEFAULT_POLICY)}.to raise_error(
|
360
|
+
expect{get_policy(@es, LogStash::Outputs::ElasticSearch::DEFAULT_POLICY)}.to raise_error(get_expected_error_class)
|
361
361
|
put_policy(@es,ilm_policy_name, policy)
|
362
362
|
end
|
363
363
|
|
364
364
|
it 'should not install the default policy if it is not used' do
|
365
365
|
subject.register
|
366
366
|
sleep(1)
|
367
|
-
expect{get_policy(@es, LogStash::Outputs::ElasticSearch::DEFAULT_POLICY)}.to raise_error(
|
367
|
+
expect{get_policy(@es, LogStash::Outputs::ElasticSearch::DEFAULT_POLICY)}.to raise_error(get_expected_error_class)
|
368
368
|
end
|
369
369
|
end
|
370
370
|
|
@@ -374,7 +374,7 @@ describe 'Elasticsearch has index lifecycle management enabled', :integration =>
|
|
374
374
|
subject.register
|
375
375
|
sleep(1)
|
376
376
|
expect(@es.indices.exists_alias(name: expected_index)).to be_truthy
|
377
|
-
expect(@es.get_alias(name: expected_index)).to include("#{expected_index}-#{todays_date}-000001")
|
377
|
+
expect(@es.indices.get_alias(name: expected_index)).to include("#{expected_index}-#{todays_date}-000001")
|
378
378
|
end
|
379
379
|
|
380
380
|
it 'should write the ILM settings into the template' do
|
@@ -443,17 +443,18 @@ describe 'Elasticsearch has index lifecycle management enabled', :integration =>
|
|
443
443
|
subject.register
|
444
444
|
sleep(1)
|
445
445
|
expect(@es.indices.exists_alias(name: ilm_rollover_alias)).to be_truthy
|
446
|
-
expect(@es.get_alias(name: ilm_rollover_alias)).to include("#{ilm_rollover_alias}-#{todays_date}-000001")
|
446
|
+
expect(@es.indices.get_alias(name: ilm_rollover_alias)).to include("#{ilm_rollover_alias}-#{todays_date}-000001")
|
447
447
|
end
|
448
448
|
|
449
449
|
context 'when the custom rollover alias already exists' do
|
450
450
|
it 'should ignore the already exists error' do
|
451
451
|
expect(@es.indices.exists_alias(name: ilm_rollover_alias)).to be_falsey
|
452
|
-
|
452
|
+
@es.indices.create(index: "#{ilm_rollover_alias}-#{todays_date}-000001")
|
453
|
+
@es.indices.put_alias(name: ilm_rollover_alias, index: "#{ilm_rollover_alias}-#{todays_date}-000001")
|
453
454
|
expect(@es.indices.exists_alias(name: ilm_rollover_alias)).to be_truthy
|
454
455
|
subject.register
|
455
456
|
sleep(1)
|
456
|
-
expect(@es.get_alias(name: ilm_rollover_alias)).to include("#{ilm_rollover_alias}-#{todays_date}-000001")
|
457
|
+
expect(@es.indices.get_alias(name: ilm_rollover_alias)).to include("#{ilm_rollover_alias}-#{todays_date}-000001")
|
457
458
|
end
|
458
459
|
|
459
460
|
end
|
@@ -532,3 +533,8 @@ describe 'Elasticsearch has index lifecycle management enabled', :integration =>
|
|
532
533
|
end
|
533
534
|
|
534
535
|
end
|
536
|
+
|
537
|
+
def get_expected_error_class
|
538
|
+
return Elastic::Transport::Transport::Errors::NotFound if elastic_ruby_v8_client_available?
|
539
|
+
Elasticsearch::Transport::Transport::Errors::NotFound
|
540
|
+
end
|
@@ -13,7 +13,7 @@ describe "TARGET_BULK_BYTES", :integration => true do
|
|
13
13
|
}
|
14
14
|
}
|
15
15
|
let(:index) { 10.times.collect { rand(10).to_s }.join("") }
|
16
|
-
let(:type) {
|
16
|
+
let(:type) { "_doc" }
|
17
17
|
|
18
18
|
subject { LogStash::Outputs::ElasticSearch.new(config) }
|
19
19
|
|
@@ -82,7 +82,7 @@ describe "indexing with sprintf resolution", :integration => true do
|
|
82
82
|
let(:message) { "Hello from #{__FILE__}" }
|
83
83
|
let(:event) { LogStash::Event.new("message" => message, "type" => type) }
|
84
84
|
let (:index) { "%{[index_name]}_dynamic" }
|
85
|
-
let(:type) {
|
85
|
+
let(:type) { "_doc" }
|
86
86
|
let(:event_count) { 1 }
|
87
87
|
let(:user) { "simpleuser" }
|
88
88
|
let(:password) { "abc123" }
|
@@ -151,7 +151,7 @@ describe "indexing" do
|
|
151
151
|
let(:message) { "Hello from #{__FILE__}" }
|
152
152
|
let(:event) { LogStash::Event.new("message" => message, "type" => type) }
|
153
153
|
let(:index) { 10.times.collect { rand(10).to_s }.join("") }
|
154
|
-
let(:type) {
|
154
|
+
let(:type) { "_doc" }
|
155
155
|
let(:event_count) { 1 + rand(2) }
|
156
156
|
let(:config) { "not implemented" }
|
157
157
|
let(:events) { event_count.times.map { event }.to_a }
|
@@ -204,10 +204,10 @@ describe "indexing" do
|
|
204
204
|
result["hits"]["hits"].each do |doc|
|
205
205
|
expect(doc["_source"]["message"]).to eq(message)
|
206
206
|
|
207
|
-
if ESHelper.es_version_satisfies?("
|
208
|
-
expect(doc["_type"]).to eq(type)
|
209
|
-
else
|
207
|
+
if ESHelper.es_version_satisfies?(">= 8")
|
210
208
|
expect(doc).not_to include("_type")
|
209
|
+
else
|
210
|
+
expect(doc["_type"]).to eq(type)
|
211
211
|
end
|
212
212
|
expect(doc["_index"]).to eq(index)
|
213
213
|
end
|
@@ -346,7 +346,7 @@ describe "indexing" do
|
|
346
346
|
end
|
347
347
|
|
348
348
|
describe "an indexer with no type value set (default to doc)", :integration => true do
|
349
|
-
let(:type) {
|
349
|
+
let(:type) { "_doc" }
|
350
350
|
let(:config) {
|
351
351
|
{
|
352
352
|
"hosts" => get_host_port,
|
@@ -36,11 +36,11 @@ describe "Versioned indexing", :integration => true do
|
|
36
36
|
|
37
37
|
it "should default to ES version" do
|
38
38
|
subject.multi_receive([LogStash::Event.new("my_id" => "123", "message" => "foo")])
|
39
|
-
r = es.get(:index => 'logstash-index', :
|
39
|
+
r = es.get(:index => 'logstash-index', :id => '123', :refresh => true)
|
40
40
|
expect(r["_version"]).to eq(1)
|
41
41
|
expect(r["_source"]["message"]).to eq('foo')
|
42
42
|
subject.multi_receive([LogStash::Event.new("my_id" => "123", "message" => "foobar")])
|
43
|
-
r2 = es.get(:index => 'logstash-index', :
|
43
|
+
r2 = es.get(:index => 'logstash-index', :id => '123', :refresh => true)
|
44
44
|
expect(r2["_version"]).to eq(2)
|
45
45
|
expect(r2["_source"]["message"]).to eq('foobar')
|
46
46
|
end
|
@@ -63,7 +63,7 @@ describe "Versioned indexing", :integration => true do
|
|
63
63
|
it "should respect the external version" do
|
64
64
|
id = "ev1"
|
65
65
|
subject.multi_receive([LogStash::Event.new("my_id" => id, "my_version" => "99", "message" => "foo")])
|
66
|
-
r = es.get(:index => 'logstash-index', :
|
66
|
+
r = es.get(:index => 'logstash-index', :id => id, :refresh => true)
|
67
67
|
expect(r["_version"]).to eq(99)
|
68
68
|
expect(r["_source"]["message"]).to eq('foo')
|
69
69
|
end
|
@@ -71,12 +71,12 @@ describe "Versioned indexing", :integration => true do
|
|
71
71
|
it "should ignore non-monotonic external version updates" do
|
72
72
|
id = "ev2"
|
73
73
|
subject.multi_receive([LogStash::Event.new("my_id" => id, "my_version" => "99", "message" => "foo")])
|
74
|
-
r = es.get(:index => 'logstash-index', :
|
74
|
+
r = es.get(:index => 'logstash-index', :id => id, :refresh => true)
|
75
75
|
expect(r["_version"]).to eq(99)
|
76
76
|
expect(r["_source"]["message"]).to eq('foo')
|
77
77
|
|
78
78
|
subject.multi_receive([LogStash::Event.new("my_id" => id, "my_version" => "98", "message" => "foo")])
|
79
|
-
r2 = es.get(:index => 'logstash-index', :
|
79
|
+
r2 = es.get(:index => 'logstash-index', :id => id, :refresh => true)
|
80
80
|
expect(r2["_version"]).to eq(99)
|
81
81
|
expect(r2["_source"]["message"]).to eq('foo')
|
82
82
|
end
|
@@ -84,12 +84,12 @@ describe "Versioned indexing", :integration => true do
|
|
84
84
|
it "should commit monotonic external version updates" do
|
85
85
|
id = "ev3"
|
86
86
|
subject.multi_receive([LogStash::Event.new("my_id" => id, "my_version" => "99", "message" => "foo")])
|
87
|
-
r = es.get(:index => 'logstash-index', :
|
87
|
+
r = es.get(:index => 'logstash-index', :id => id, :refresh => true)
|
88
88
|
expect(r["_version"]).to eq(99)
|
89
89
|
expect(r["_source"]["message"]).to eq('foo')
|
90
90
|
|
91
91
|
subject.multi_receive([LogStash::Event.new("my_id" => id, "my_version" => "100", "message" => "foo")])
|
92
|
-
r2 = es.get(:index => 'logstash-index', :
|
92
|
+
r2 = es.get(:index => 'logstash-index', :id => id, :refresh => true)
|
93
93
|
expect(r2["_version"]).to eq(100)
|
94
94
|
expect(r2["_source"]["message"]).to eq('foo')
|
95
95
|
end
|
@@ -74,5 +74,5 @@ describe "elasticsearch is down on startup", :integration => true do
|
|
74
74
|
expect(r).to have_hits(2)
|
75
75
|
expect(subject.plugin_metadata.get(:cluster_uuid)).not_to be_empty
|
76
76
|
expect(subject.plugin_metadata.get(:cluster_uuid)).not_to eq("_na_")
|
77
|
-
end
|
77
|
+
end
|
78
78
|
end
|
@@ -22,11 +22,12 @@ describe "Update actions using painless scripts", :integration => true, :update_
|
|
22
22
|
# This can fail if there are no indexes, ignore failure.
|
23
23
|
@es.indices.delete(:index => "*") rescue nil
|
24
24
|
@es.index(
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
25
|
+
{
|
26
|
+
:index => 'logstash-update',
|
27
|
+
:id => '123',
|
28
|
+
:body => { :message => 'Test', :counter => 1 },
|
29
|
+
:refresh => true
|
30
|
+
})
|
30
31
|
@es.indices.refresh
|
31
32
|
end
|
32
33
|
|
@@ -46,7 +47,7 @@ describe "Update actions using painless scripts", :integration => true, :update_
|
|
46
47
|
subject = get_es_output(plugin_parameters)
|
47
48
|
subject.register
|
48
49
|
subject.multi_receive([LogStash::Event.new("count" => 4 )])
|
49
|
-
r = @es.get(:index => 'logstash-update', :
|
50
|
+
r = @es.get(:index => 'logstash-update', :id => "123", :refresh => true)
|
50
51
|
expect(r["_source"]["counter"]).to eq(5)
|
51
52
|
end
|
52
53
|
end
|
@@ -57,7 +58,7 @@ describe "Update actions using painless scripts", :integration => true, :update_
|
|
57
58
|
subject = get_es_output({ 'document_id' => "456", 'upsert' => '{"message": "upsert message"}' })
|
58
59
|
subject.register
|
59
60
|
subject.multi_receive([LogStash::Event.new("message" => "sample message here")])
|
60
|
-
r = @es.get(:index => 'logstash-update', :
|
61
|
+
r = @es.get(:index => 'logstash-update', :id => "456", :refresh => true)
|
61
62
|
expect(r["_source"]["message"]).to eq('upsert message')
|
62
63
|
end
|
63
64
|
|
@@ -65,7 +66,7 @@ describe "Update actions using painless scripts", :integration => true, :update_
|
|
65
66
|
subject = get_es_output({ 'document_id' => "456", 'doc_as_upsert' => true })
|
66
67
|
subject.register
|
67
68
|
subject.multi_receive([LogStash::Event.new("message" => "sample message here")])
|
68
|
-
r = @es.get(:index => 'logstash-update', :
|
69
|
+
r = @es.get(:index => 'logstash-update', :id => "456", :refresh => true)
|
69
70
|
expect(r["_source"]["message"]).to eq('sample message here')
|
70
71
|
end
|
71
72
|
|
@@ -82,7 +83,7 @@ describe "Update actions using painless scripts", :integration => true, :update_
|
|
82
83
|
subject.register
|
83
84
|
|
84
85
|
subject.multi_receive([LogStash::Event.new("message" => "sample message here")])
|
85
|
-
r = @es.get(:index => 'logstash-update', :
|
86
|
+
r = @es.get(:index => 'logstash-update', :id => "456", :refresh => true)
|
86
87
|
expect(r["_source"]["message"]).to eq('upsert message')
|
87
88
|
end
|
88
89
|
|
@@ -91,7 +92,7 @@ describe "Update actions using painless scripts", :integration => true, :update_
|
|
91
92
|
subject.register
|
92
93
|
subject.multi_receive([LogStash::Event.new("counter" => 1)])
|
93
94
|
@es.indices.refresh
|
94
|
-
r = @es.get(:index => 'logstash-update', :
|
95
|
+
r = @es.get(:index => 'logstash-update', :id => "456", :refresh => true)
|
95
96
|
expect(r["_source"]["counter"]).to eq(1)
|
96
97
|
end
|
97
98
|
end
|
@@ -6,7 +6,7 @@ describe "join type field", :integration => true do
|
|
6
6
|
shared_examples "a join field based parent indexer" do
|
7
7
|
let(:index) { 10.times.collect { rand(10).to_s }.join("") }
|
8
8
|
|
9
|
-
let(:type) {
|
9
|
+
let(:type) { "_doc" }
|
10
10
|
|
11
11
|
let(:event_count) { 10000 + rand(500) }
|
12
12
|
let(:parent) { "not_implemented" }
|
@@ -33,8 +33,7 @@ describe "join type field", :integration => true do
|
|
33
33
|
}
|
34
34
|
}
|
35
35
|
|
36
|
-
mapping =
|
37
|
-
: { "mappings" => properties}
|
36
|
+
mapping = { "mappings" => properties}
|
38
37
|
|
39
38
|
Manticore.put("#{index_url}", {:body => mapping.to_json, :headers => default_headers}).call
|
40
39
|
pdoc = { "message" => "ohayo", join_field => parent_relation }
|
@@ -5,19 +5,11 @@ describe "failures in bulk class expected behavior", :integration => true do
|
|
5
5
|
let(:template) { '{"template" : "not important, will be updated by :index"}' }
|
6
6
|
let(:event1) { LogStash::Event.new("somevalue" => 100, "@timestamp" => "2014-11-17T20:37:17.223Z", "@metadata" => {"retry_count" => 0}) }
|
7
7
|
let(:action1) do
|
8
|
-
|
9
|
-
ESHelper.action_for_version(["index", {:_id=>nil, routing_field_name =>nil, :_index=>"logstash-2014.11.17", :_type=> doc_type }, event1.to_hash])
|
10
|
-
else
|
11
|
-
ESHelper.action_for_version(["index", {:_id=>nil, routing_field_name =>nil, :_index=>"logstash-2014.11.17" }, event1.to_hash])
|
12
|
-
end
|
8
|
+
ESHelper.action_for_version(["index", {:_id=>nil, routing_field_name =>nil, :_index=>"logstash-2014.11.17" }, event1.to_hash])
|
13
9
|
end
|
14
10
|
let(:event2) { LogStash::Event.new("geoip" => { "location" => [ 0.0, 0.0] }, "@timestamp" => "2014-11-17T20:37:17.223Z", "@metadata" => {"retry_count" => 0}) }
|
15
11
|
let(:action2) do
|
16
|
-
|
17
|
-
ESHelper.action_for_version(["index", {:_id=>nil, routing_field_name =>nil, :_index=>"logstash-2014.11.17", :_type=> doc_type }, event2.to_hash])
|
18
|
-
else
|
19
|
-
ESHelper.action_for_version(["index", {:_id=>nil, routing_field_name =>nil, :_index=>"logstash-2014.11.17" }, event2.to_hash])
|
20
|
-
end
|
12
|
+
ESHelper.action_for_version(["index", {:_id=>nil, routing_field_name =>nil, :_index=>"logstash-2014.11.17" }, event2.to_hash])
|
21
13
|
end
|
22
14
|
let(:invalid_event) { LogStash::Event.new("geoip" => { "location" => "notlatlon" }, "@timestamp" => "2014-11-17T20:37:17.223Z") }
|
23
15
|
|
@@ -33,48 +33,13 @@ describe "pool sniffer", :integration => true do
|
|
33
33
|
|
34
34
|
expect(uris.size).to eq(1)
|
35
35
|
end
|
36
|
-
|
37
|
-
it "should return the correct sniff URL" do
|
38
|
-
if ESHelper.es_version_satisfies?("<7")
|
39
|
-
# We do a more thorough check on these versions because we can more reliably guess the ip
|
40
|
-
uris = subject.check_sniff
|
41
|
-
|
42
|
-
expect(uris).to include(::LogStash::Util::SafeURI.new("//#{es_ip}:#{es_port}"))
|
43
|
-
else
|
44
|
-
# ES 1.x (and ES 7.x) returned the public hostname by default. This is hard to approximate
|
45
|
-
# so for ES1.x and 7.x we don't check the *exact* hostname
|
46
|
-
skip
|
47
|
-
end
|
48
|
-
end
|
49
36
|
end
|
50
37
|
end
|
51
38
|
|
52
|
-
|
53
|
-
describe("Complex sniff parsing ES 7x") do
|
54
|
-
before(:each) do
|
55
|
-
response_double = double("_nodes/http", body: File.read("spec/fixtures/_nodes/7x.json"))
|
56
|
-
allow(subject).to receive(:perform_request).and_return([nil, { version: "7.0" }, response_double])
|
57
|
-
subject.start
|
58
|
-
end
|
59
|
-
|
60
|
-
context "with mixed master-only, data-only, and data + master nodes" do
|
61
|
-
it "should execute a sniff without error" do
|
62
|
-
expect { subject.check_sniff }.not_to raise_error
|
63
|
-
end
|
64
|
-
|
65
|
-
it "should return the correct sniff URLs" do
|
66
|
-
# ie. with the master-only node, and with the node name correctly set.
|
67
|
-
uris = subject.check_sniff
|
68
|
-
|
69
|
-
expect(uris).to include(::LogStash::Util::SafeURI.new("//dev-masterdata:9201"), ::LogStash::Util::SafeURI.new("//dev-data:9202"))
|
70
|
-
end
|
71
|
-
end
|
72
|
-
end
|
73
|
-
end
|
74
|
-
describe("Complex sniff parsing ES") do
|
39
|
+
describe("Complex sniff parsing") do
|
75
40
|
before(:each) do
|
76
|
-
response_double = double("_nodes/http", body: File.read("spec/fixtures/_nodes/
|
77
|
-
allow(subject).to receive(:perform_request).and_return([nil, { version: "
|
41
|
+
response_double = double("_nodes/http", body: File.read("spec/fixtures/_nodes/7x.json"))
|
42
|
+
allow(subject).to receive(:perform_request).and_return([nil, { version: "7.0" }, response_double])
|
78
43
|
subject.start
|
79
44
|
end
|
80
45
|
|
@@ -84,10 +49,10 @@ describe "pool sniffer", :integration => true do
|
|
84
49
|
end
|
85
50
|
|
86
51
|
it "should return the correct sniff URLs" do
|
87
|
-
# ie.
|
52
|
+
# ie. with the master-only node, and with the node name correctly set.
|
88
53
|
uris = subject.check_sniff
|
89
54
|
|
90
|
-
expect(uris).to include(::LogStash::Util::SafeURI.new("//
|
55
|
+
expect(uris).to include(::LogStash::Util::SafeURI.new("//dev-masterdata:9201"), ::LogStash::Util::SafeURI.new("//dev-data:9202"))
|
91
56
|
end
|
92
57
|
end
|
93
58
|
end
|
@@ -27,16 +27,21 @@ describe "Unsupported actions testing...", :integration => true do
|
|
27
27
|
@es.indices.delete(:index => "*") rescue nil
|
28
28
|
# index single doc for update purpose
|
29
29
|
@es.index(
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
30
|
+
{
|
31
|
+
:index => INDEX,
|
32
|
+
:id => '2',
|
33
|
+
:body => { :message => 'Test to doc indexing', :counter => 1 },
|
34
|
+
:refresh => true
|
35
|
+
}
|
34
36
|
)
|
37
|
+
|
35
38
|
@es.index(
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
39
|
+
{
|
40
|
+
:index => INDEX,
|
41
|
+
:id => '3',
|
42
|
+
:body => { :message => 'Test to doc deletion', :counter => 2 },
|
43
|
+
:refresh => true
|
44
|
+
}
|
40
45
|
)
|
41
46
|
@es.indices.refresh
|
42
47
|
end
|
@@ -63,12 +68,12 @@ describe "Unsupported actions testing...", :integration => true do
|
|
63
68
|
rejected_events = events.select { |event| !index_or_update.call(event) }
|
64
69
|
|
65
70
|
indexed_events.each do |event|
|
66
|
-
response = @es.get(:index => INDEX, :
|
71
|
+
response = @es.get(:index => INDEX, :id => event.get("doc_id"), :refresh => true)
|
67
72
|
expect(response['_source']['message']).to eq(event.get("message"))
|
68
73
|
end
|
69
74
|
|
70
75
|
rejected_events.each do |event|
|
71
|
-
expect {@es.get(:index => INDEX, :
|
76
|
+
expect {@es.get(:index => INDEX, :id => event.get("doc_id"), :refresh => true)}.to raise_error(get_expected_error_class)
|
72
77
|
end
|
73
78
|
end
|
74
79
|
end
|
@@ -22,10 +22,12 @@ describe "Update actions without scripts", :integration => true do
|
|
22
22
|
# This can fail if there are no indexes, ignore failure.
|
23
23
|
@es.indices.delete(:index => "*") rescue nil
|
24
24
|
@es.index(
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
25
|
+
{
|
26
|
+
:index => 'logstash-update',
|
27
|
+
:id => '123',
|
28
|
+
:body => { :message => 'Test', :counter => 1 },
|
29
|
+
:refresh => true
|
30
|
+
}
|
29
31
|
)
|
30
32
|
@es.indices.refresh
|
31
33
|
end
|
@@ -40,14 +42,14 @@ describe "Update actions without scripts", :integration => true do
|
|
40
42
|
subject = get_es_output({ 'document_id' => "456" } )
|
41
43
|
subject.register
|
42
44
|
subject.multi_receive([LogStash::Event.new("message" => "sample message here")])
|
43
|
-
expect {@es.get(:index => 'logstash-update', :
|
45
|
+
expect {@es.get(:index => 'logstash-update', :id => '456', :refresh => true)}.to raise_error(get_expected_error_class)
|
44
46
|
end
|
45
47
|
|
46
48
|
it "should update existing document" do
|
47
49
|
subject = get_es_output({ 'document_id' => "123" })
|
48
50
|
subject.register
|
49
51
|
subject.multi_receive([LogStash::Event.new("message" => "updated message here")])
|
50
|
-
r = @es.get(:index => 'logstash-update', :
|
52
|
+
r = @es.get(:index => 'logstash-update', :id => '123', :refresh => true)
|
51
53
|
expect(r["_source"]["message"]).to eq('updated message here')
|
52
54
|
end
|
53
55
|
|
@@ -57,7 +59,7 @@ describe "Update actions without scripts", :integration => true do
|
|
57
59
|
subject = get_es_output({ 'document_id' => "123" })
|
58
60
|
subject.register
|
59
61
|
subject.multi_receive([LogStash::Event.new("data" => "updated message here", "message" => "foo")])
|
60
|
-
r = @es.get(:index => 'logstash-update', :
|
62
|
+
r = @es.get(:index => 'logstash-update', :id => '123', :refresh => true)
|
61
63
|
expect(r["_source"]["data"]).to eq('updated message here')
|
62
64
|
expect(r["_source"]["message"]).to eq('foo')
|
63
65
|
end
|
@@ -94,7 +96,7 @@ describe "Update actions without scripts", :integration => true do
|
|
94
96
|
subject = get_es_output({ 'document_id' => "456", 'upsert' => '{"message": "upsert message"}' })
|
95
97
|
subject.register
|
96
98
|
subject.multi_receive([LogStash::Event.new("message" => "sample message here")])
|
97
|
-
r = @es.get(:index => 'logstash-update', :
|
99
|
+
r = @es.get(:index => 'logstash-update', :id => '456', :refresh => true)
|
98
100
|
expect(r["_source"]["message"]).to eq('upsert message')
|
99
101
|
end
|
100
102
|
|
@@ -102,7 +104,7 @@ describe "Update actions without scripts", :integration => true do
|
|
102
104
|
subject = get_es_output({ 'document_id' => "456", 'doc_as_upsert' => true })
|
103
105
|
subject.register
|
104
106
|
subject.multi_receive([LogStash::Event.new("message" => "sample message here")])
|
105
|
-
r = @es.get(:index => 'logstash-update', :
|
107
|
+
r = @es.get(:index => 'logstash-update', :id => '456', :refresh => true)
|
106
108
|
expect(r["_source"]["message"]).to eq('sample message here')
|
107
109
|
end
|
108
110
|
|
data/spec/spec_helper.rb
CHANGED
@@ -8,3 +8,11 @@ end
|
|
8
8
|
RSpec.configure do |config|
|
9
9
|
config.include LogStash::Outputs::ElasticSearch::SpecHelper
|
10
10
|
end
|
11
|
+
|
12
|
+
# remove once plugin starts consuming elasticsearch-ruby v8 client
|
13
|
+
def elastic_ruby_v8_client_available?
|
14
|
+
Elasticsearch::Transport
|
15
|
+
false
|
16
|
+
rescue NameError # NameError: uninitialized constant Elasticsearch::Transport if Elastic Ruby client is not available
|
17
|
+
true
|
18
|
+
end
|
@@ -286,29 +286,6 @@ describe LogStash::Outputs::ElasticSearch::DataStreamSupport do
|
|
286
286
|
end
|
287
287
|
|
288
288
|
end
|
289
|
-
|
290
|
-
context 'non-compatible ES' do
|
291
|
-
|
292
|
-
let(:es_version) { '6.8.11' }
|
293
|
-
|
294
|
-
it "prints an error (from after_successful_connection thread) on LS 7.x" do
|
295
|
-
change_constant :LOGSTASH_VERSION, '7.12.0' do
|
296
|
-
expect( subject.logger ).to receive(:error).with(/Elasticsearch version does not support data streams/,
|
297
|
-
{:es_version=>"6.8.11"})
|
298
|
-
stub_plugin_register!
|
299
|
-
end
|
300
|
-
end
|
301
|
-
|
302
|
-
it "prints an error (from after_successful_connection thread) on LS 8.0" do
|
303
|
-
change_constant :LOGSTASH_VERSION, '8.0.5' do
|
304
|
-
expect( subject.logger ).to receive(:error).with(/Elasticsearch version does not support data streams/,
|
305
|
-
{:es_version=>"6.8.11"})
|
306
|
-
stub_plugin_register!
|
307
|
-
end
|
308
|
-
end
|
309
|
-
|
310
|
-
end
|
311
|
-
|
312
289
|
end
|
313
290
|
|
314
291
|
describe "auto routing" do
|
@@ -203,29 +203,6 @@ describe LogStash::Outputs::ElasticSearch::HttpClient::Pool do
|
|
203
203
|
let(:ip_address) { "192.168.1.0"}
|
204
204
|
let(:port) { 9200 }
|
205
205
|
|
206
|
-
context 'in Elasticsearch 1.x format' do
|
207
|
-
context 'with host and ip address' do
|
208
|
-
let(:publish_address) { "inet[#{host}/#{ip_address}:#{port}]"}
|
209
|
-
it 'should correctly extract the host' do
|
210
|
-
expect(subject.address_str_to_uri(publish_address)).to eq (LogStash::Util::SafeURI.new("#{host}:#{port}"))
|
211
|
-
end
|
212
|
-
end
|
213
|
-
context 'with ip address' do
|
214
|
-
let(:publish_address) { "inet[/#{ip_address}:#{port}]"}
|
215
|
-
it 'should correctly extract the ip address' do
|
216
|
-
expect(subject.address_str_to_uri(publish_address)).to eq (LogStash::Util::SafeURI.new("#{ip_address}:#{port}"))
|
217
|
-
end
|
218
|
-
end
|
219
|
-
end
|
220
|
-
|
221
|
-
context 'in Elasticsearch 2.x-6.x format' do
|
222
|
-
let(:publish_address) { "#{ip_address}:#{port}"}
|
223
|
-
it 'should correctly extract the ip address' do
|
224
|
-
expect(subject.address_str_to_uri(publish_address)).to eq (LogStash::Util::SafeURI.new("//#{ip_address}:#{port}"))
|
225
|
-
end
|
226
|
-
end
|
227
|
-
|
228
|
-
context 'in Elasticsearch 7.x'
|
229
206
|
context 'with host and ip address' do
|
230
207
|
let(:publish_address) { "#{host}/#{ip_address}:#{port}"}
|
231
208
|
it 'should correctly extract the host' do
|
@@ -367,14 +344,19 @@ describe LogStash::Outputs::ElasticSearch::HttpClient::Pool do
|
|
367
344
|
|
368
345
|
let(:root_response) { MockResponse.new(200, {"tagline" => "You Know, for Search",
|
369
346
|
"version" => {
|
370
|
-
"number" => '
|
371
|
-
"build_flavor" => 'default'}
|
372
|
-
}) }
|
373
|
-
let(:root_response2) { MockResponse.new(200, {"tagline" => "You Know, for Search",
|
374
|
-
"version" => {
|
375
|
-
"number" => '6.0.0',
|
347
|
+
"number" => '7.0.0',
|
376
348
|
"build_flavor" => 'default'}
|
377
349
|
}) }
|
350
|
+
let(:root_response2) { MockResponse.new(200,
|
351
|
+
{
|
352
|
+
"tagline" => "You Know, for Search",
|
353
|
+
"version" => {
|
354
|
+
"number" => '8.0.0',
|
355
|
+
"build_flavor" => 'default'
|
356
|
+
}
|
357
|
+
},
|
358
|
+
{ "x-elastic-product" => "Elasticsearch" }
|
359
|
+
) }
|
378
360
|
|
379
361
|
context "if there are nodes with multiple major versions" do
|
380
362
|
before(:each) do
|
@@ -383,7 +365,7 @@ describe LogStash::Outputs::ElasticSearch::HttpClient::Pool do
|
|
383
365
|
end
|
384
366
|
|
385
367
|
it "picks the largest major version" do
|
386
|
-
expect(subject.maximum_seen_major_version).to eq(
|
368
|
+
expect(subject.maximum_seen_major_version).to eq(8)
|
387
369
|
end
|
388
370
|
end
|
389
371
|
end
|
@@ -542,30 +524,6 @@ describe "#elasticsearch?" do
|
|
542
524
|
end
|
543
525
|
end
|
544
526
|
|
545
|
-
context "when connecting to a cluster with version < 6.0.0" do
|
546
|
-
it "should fail" do
|
547
|
-
resp = MockResponse.new(200, {"version" => { "number" => "5.0.0" }})
|
548
|
-
expect(subject.send(:elasticsearch?, resp)).to be false
|
549
|
-
end
|
550
|
-
end
|
551
|
-
|
552
|
-
context "when connecting to a cluster with version in [6.0.0..7.0.0)" do
|
553
|
-
it "must be successful with valid 'tagline'" do
|
554
|
-
resp = MockResponse.new(200, {"version" => {"number" => "6.5.0"}, "tagline" => "You Know, for Search"} )
|
555
|
-
expect(subject.send(:elasticsearch?, resp)).to be true
|
556
|
-
end
|
557
|
-
|
558
|
-
it "should fail if invalid 'tagline'" do
|
559
|
-
resp = MockResponse.new(200, {"version" => {"number" => "6.5.0"}, "tagline" => "You don't know"} )
|
560
|
-
expect(subject.send(:elasticsearch?, resp)).to be false
|
561
|
-
end
|
562
|
-
|
563
|
-
it "should fail if 'tagline' is not present" do
|
564
|
-
resp = MockResponse.new(200, {"version" => {"number" => "6.5.0"}} )
|
565
|
-
expect(subject.send(:elasticsearch?, resp)).to be false
|
566
|
-
end
|
567
|
-
end
|
568
|
-
|
569
527
|
context "when connecting to a cluster with version in [7.0.0..7.14.0)" do
|
570
528
|
it "must be successful is 'build_flavor' is 'default' and tagline is correct" do
|
571
529
|
resp = MockResponse.new(200, {"version": {"number": "7.5.0", "build_flavor": "default"}, "tagline": "You Know, for Search"} )
|