logstash-output-elasticsearch 11.0.1-java → 11.0.5-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +12 -0
  3. data/docs/index.asciidoc +12 -12
  4. data/lib/logstash/outputs/elasticsearch/http_client/pool.rb +2 -28
  5. data/lib/logstash/outputs/elasticsearch/http_client.rb +4 -0
  6. data/lib/logstash/outputs/elasticsearch/ilm.rb +2 -33
  7. data/lib/logstash/outputs/elasticsearch/license_checker.rb +12 -6
  8. data/lib/logstash/outputs/elasticsearch/template_manager.rb +1 -1
  9. data/lib/logstash/outputs/elasticsearch/templates/ecs-v1/elasticsearch-8x.json +1 -0
  10. data/lib/logstash/outputs/elasticsearch.rb +3 -14
  11. data/lib/logstash/plugin_mixins/elasticsearch/common.rb +5 -1
  12. data/logstash-output-elasticsearch.gemspec +2 -2
  13. data/spec/es_spec_helper.rb +4 -6
  14. data/spec/fixtures/_nodes/{5x_6x.json → 6x.json} +5 -5
  15. data/spec/integration/outputs/compressed_indexing_spec.rb +47 -46
  16. data/spec/integration/outputs/delete_spec.rb +49 -51
  17. data/spec/integration/outputs/ilm_spec.rb +230 -246
  18. data/spec/integration/outputs/index_spec.rb +5 -2
  19. data/spec/integration/outputs/index_version_spec.rb +78 -82
  20. data/spec/integration/outputs/ingest_pipeline_spec.rb +58 -60
  21. data/spec/integration/outputs/no_es_on_startup_spec.rb +14 -0
  22. data/spec/integration/outputs/painless_update_spec.rb +74 -164
  23. data/spec/integration/outputs/parent_spec.rb +67 -75
  24. data/spec/integration/outputs/retry_spec.rb +2 -2
  25. data/spec/integration/outputs/sniffer_spec.rb +15 -53
  26. data/spec/integration/outputs/templates_spec.rb +79 -81
  27. data/spec/integration/outputs/update_spec.rb +99 -101
  28. data/spec/spec_helper.rb +1 -5
  29. data/spec/unit/outputs/elasticsearch/data_stream_support_spec.rb +0 -14
  30. data/spec/unit/outputs/elasticsearch/http_client/pool_spec.rb +30 -37
  31. data/spec/unit/outputs/elasticsearch/template_manager_spec.rb +9 -9
  32. data/spec/unit/outputs/elasticsearch_spec.rb +2 -8
  33. data/spec/unit/outputs/error_whitelist_spec.rb +1 -0
  34. metadata +8 -22
  35. data/lib/logstash/outputs/elasticsearch/templates/ecs-disabled/elasticsearch-2x.json +0 -95
  36. data/lib/logstash/outputs/elasticsearch/templates/ecs-disabled/elasticsearch-5x.json +0 -46
  37. data/spec/fixtures/_nodes/2x_1x.json +0 -27
  38. data/spec/fixtures/scripts/groovy/scripted_update.groovy +0 -2
  39. data/spec/fixtures/scripts/groovy/scripted_update_nested.groovy +0 -2
  40. data/spec/fixtures/scripts/groovy/scripted_upsert.groovy +0 -2
  41. data/spec/integration/outputs/groovy_update_spec.rb +0 -150
  42. data/spec/integration/outputs/templates_5x_spec.rb +0 -98
@@ -2,64 +2,62 @@ require_relative "../../../spec/es_spec_helper"
2
2
  require "logstash/outputs/elasticsearch"
3
3
 
4
4
 
5
- if ESHelper.es_version_satisfies?(">= 2")
6
- describe "Versioned delete", :integration => true do
7
- require "logstash/outputs/elasticsearch"
5
+ describe "Versioned delete", :integration => true do
6
+ require "logstash/outputs/elasticsearch"
7
+
8
+ let(:es) { get_client }
9
+
10
+ before :each do
11
+ # Delete all templates first.
12
+ # Clean ES of data before we start.
13
+ es.indices.delete_template(:name => "*")
14
+ # This can fail if there are no indexes, ignore failure.
15
+ es.indices.delete(:index => "*") rescue nil
16
+ es.indices.refresh
17
+ end
8
18
 
9
- let(:es) { get_client }
19
+ context "when delete only" do
20
+ subject { LogStash::Outputs::ElasticSearch.new(settings) }
10
21
 
11
- before :each do
12
- # Delete all templates first.
13
- # Clean ES of data before we start.
14
- es.indices.delete_template(:name => "*")
15
- # This can fail if there are no indexes, ignore failure.
16
- es.indices.delete(:index => "*") rescue nil
17
- es.indices.refresh
22
+ before do
23
+ subject.register
18
24
  end
19
25
 
20
- context "when delete only" do
21
- subject { LogStash::Outputs::ElasticSearch.new(settings) }
22
-
23
- before do
24
- subject.register
25
- end
26
-
27
- let(:settings) do
28
- {
29
- "manage_template" => true,
30
- "index" => "logstash-delete",
31
- "template_overwrite" => true,
32
- "hosts" => get_host_port(),
33
- "document_id" => "%{my_id}",
34
- "version" => "%{my_version}",
35
- "version_type" => "external",
36
- "action" => "%{my_action}"
37
- }
38
- end
39
-
40
- it "should ignore non-monotonic external version updates" do
41
- id = "ev2"
42
- subject.multi_receive([LogStash::Event.new("my_id" => id, "my_action" => "index", "message" => "foo", "my_version" => 99)])
43
- r = es.get(:index => 'logstash-delete', :type => doc_type, :id => id, :refresh => true)
44
- expect(r['_version']).to eq(99)
45
- expect(r['_source']['message']).to eq('foo')
26
+ let(:settings) do
27
+ {
28
+ "manage_template" => true,
29
+ "index" => "logstash-delete",
30
+ "template_overwrite" => true,
31
+ "hosts" => get_host_port(),
32
+ "document_id" => "%{my_id}",
33
+ "version" => "%{my_version}",
34
+ "version_type" => "external",
35
+ "action" => "%{my_action}"
36
+ }
37
+ end
46
38
 
47
- subject.multi_receive([LogStash::Event.new("my_id" => id, "my_action" => "delete", "message" => "foo", "my_version" => 98)])
48
- r2 = es.get(:index => 'logstash-delete', :type => doc_type, :id => id, :refresh => true)
49
- expect(r2['_version']).to eq(99)
50
- expect(r2['_source']['message']).to eq('foo')
51
- end
39
+ it "should ignore non-monotonic external version updates" do
40
+ id = "ev2"
41
+ subject.multi_receive([LogStash::Event.new("my_id" => id, "my_action" => "index", "message" => "foo", "my_version" => 99)])
42
+ r = es.get(:index => 'logstash-delete', :type => doc_type, :id => id, :refresh => true)
43
+ expect(r['_version']).to eq(99)
44
+ expect(r['_source']['message']).to eq('foo')
45
+
46
+ subject.multi_receive([LogStash::Event.new("my_id" => id, "my_action" => "delete", "message" => "foo", "my_version" => 98)])
47
+ r2 = es.get(:index => 'logstash-delete', :type => doc_type, :id => id, :refresh => true)
48
+ expect(r2['_version']).to eq(99)
49
+ expect(r2['_source']['message']).to eq('foo')
50
+ end
52
51
 
53
- it "should commit monotonic external version updates" do
54
- id = "ev3"
55
- subject.multi_receive([LogStash::Event.new("my_id" => id, "my_action" => "index", "message" => "foo", "my_version" => 99)])
56
- r = es.get(:index => 'logstash-delete', :type => doc_type, :id => id, :refresh => true)
57
- expect(r['_version']).to eq(99)
58
- expect(r['_source']['message']).to eq('foo')
52
+ it "should commit monotonic external version updates" do
53
+ id = "ev3"
54
+ subject.multi_receive([LogStash::Event.new("my_id" => id, "my_action" => "index", "message" => "foo", "my_version" => 99)])
55
+ r = es.get(:index => 'logstash-delete', :type => doc_type, :id => id, :refresh => true)
56
+ expect(r['_version']).to eq(99)
57
+ expect(r['_source']['message']).to eq('foo')
59
58
 
60
- subject.multi_receive([LogStash::Event.new("my_id" => id, "my_action" => "delete", "message" => "foo", "my_version" => 100)])
61
- expect { es.get(:index => 'logstash-delete', :type => doc_type, :id => id, :refresh => true) }.to raise_error(Elasticsearch::Transport::Transport::Errors::NotFound)
62
- end
59
+ subject.multi_receive([LogStash::Event.new("my_id" => id, "my_action" => "delete", "message" => "foo", "my_version" => 100)])
60
+ expect { es.get(:index => 'logstash-delete', :type => doc_type, :id => id, :refresh => true) }.to raise_error(Elasticsearch::Transport::Transport::Errors::NotFound)
63
61
  end
64
62
  end
65
63
  end
@@ -111,9 +111,7 @@ shared_examples_for 'an ILM disabled Logstash' do
111
111
 
112
112
  template = get_template(@es, "logstash")
113
113
  expect(template).to have_index_pattern("logstash-*")
114
- if ESHelper.es_version_satisfies?(">= 2")
115
- expect(get_template_settings(template)['index']['lifecycle']).to be_nil
116
- end
114
+ expect(get_template_settings(template)['index']['lifecycle']).to be_nil
117
115
  end
118
116
 
119
117
  context 'with an existing policy that will roll over' do
@@ -163,9 +161,7 @@ shared_examples_for 'an ILM disabled Logstash' do
163
161
 
164
162
  template = get_template(@es, template_name)
165
163
  expect(template).to have_index_pattern("logstash-*")
166
- if ESHelper.es_version_satisfies?(">= 2")
167
- expect(get_template_settings(template)['index']['lifecycle']).to be_nil
168
- end
164
+ expect(get_template_settings(template)['index']['lifecycle']).to be_nil
169
165
  end
170
166
  end
171
167
  end
@@ -231,319 +227,307 @@ shared_examples_for 'an Elasticsearch instance that does not support index lifec
231
227
 
232
228
  end
233
229
 
234
- if ESHelper.es_version_satisfies?("<= 6.5")
235
- describe 'Pre-ILM versions of Elasticsearch', :integration => true do
236
- it_behaves_like 'an Elasticsearch instance that does not support index lifecycle management'
237
- end
238
- end
239
-
240
- if ESHelper.es_version_satisfies?(">= 6.6")
241
- describe 'OSS Elasticsearch', :distribution => 'oss', :integration => true do
242
- it_behaves_like 'an Elasticsearch instance that does not support index lifecycle management'
243
- end
230
+ describe 'Elasticsearch has index lifecycle management enabled', :integration => true do
244
231
 
245
- describe 'Elasticsearch has index lifecycle management enabled', :distribution => 'xpack', :integration => true do
232
+ DEFAULT_INTERVAL = '600s'
246
233
 
247
- DEFAULT_INTERVAL = '600s'
234
+ let (:ilm_enabled) { true }
248
235
 
249
- let (:ilm_enabled) { true }
250
-
251
- let (:settings) {
252
- {
253
- "ilm_enabled" => ilm_enabled,
254
- "hosts" => "#{get_host_port()}"
255
- }
236
+ let (:settings) {
237
+ {
238
+ "ilm_enabled" => ilm_enabled,
239
+ "hosts" => "#{get_host_port()}"
256
240
  }
257
- let (:small_max_doc_policy) { max_docs_policy(3) }
258
- let (:large_max_doc_policy) { max_docs_policy(1000000) }
259
- let (:expected_index) { elasticsearch_output_plugin.default_ilm_rollover_alias }
260
-
261
- subject(:elasticsearch_output_plugin) { LogStash::Outputs::ElasticSearch.new(settings) }
262
-
263
- before :each do
264
- # Delete all templates first.
265
- require "elasticsearch"
266
-
267
- # Clean ES of data before we start.
268
- @es = get_client
269
- clean(@es)
270
- # Set the poll interval for lifecycle management to be short so changes get picked up in time.
271
- set_cluster_settings(@es, {
272
- "persistent" => {
273
- "indices.lifecycle.poll_interval" => "1s"
274
- }
275
- })
276
- end
241
+ }
242
+ let (:small_max_doc_policy) { max_docs_policy(3) }
243
+ let (:large_max_doc_policy) { max_docs_policy(1000000) }
244
+ let (:expected_index) { elasticsearch_output_plugin.default_ilm_rollover_alias }
277
245
 
278
- after :each do
279
- # Set poll interval back to default
280
- set_cluster_settings(@es, {
281
- "persistent" => {
282
- "indices.lifecycle.poll_interval" => DEFAULT_INTERVAL
283
- }
284
- })
285
- clean(@es)
286
- end
246
+ subject(:elasticsearch_output_plugin) { LogStash::Outputs::ElasticSearch.new(settings) }
287
247
 
288
- context 'with ilm enabled' do
289
- let (:ilm_enabled) { true }
248
+ before :each do
249
+ # Delete all templates first.
250
+ require "elasticsearch"
290
251
 
291
- context 'when using the default policy' do
292
- context 'with a custom pattern' do
293
- let (:settings) { super().merge("ilm_pattern" => "000001")}
294
- it 'should create a rollover alias' do
295
- expect(@es.indices.exists_alias(name: "logstash")).to be_falsey
296
- subject.register
297
- sleep(1)
298
- expect(@es.indices.exists_alias(name: "logstash")).to be_truthy
299
- expect(@es.get_alias(name: "logstash")).to include("logstash-000001")
300
- end
301
- end
252
+ # Clean ES of data before we start.
253
+ @es = get_client
254
+ clean(@es)
255
+ # Set the poll interval for lifecycle management to be short so changes get picked up in time.
256
+ set_cluster_settings(@es, {
257
+ "persistent" => {
258
+ "indices.lifecycle.poll_interval" => "1s"
259
+ }
260
+ })
261
+ end
302
262
 
303
- it 'should install it if it is not present' do
304
- expect{get_policy(@es, LogStash::Outputs::ElasticSearch::DEFAULT_POLICY)}.to raise_error(Elasticsearch::Transport::Transport::Errors::NotFound)
305
- subject.register
306
- sleep(1)
307
- expect{get_policy(@es, LogStash::Outputs::ElasticSearch::DEFAULT_POLICY)}.not_to raise_error
308
- end
263
+ after :each do
264
+ # Set poll interval back to default
265
+ set_cluster_settings(@es, {
266
+ "persistent" => {
267
+ "indices.lifecycle.poll_interval" => DEFAULT_INTERVAL
268
+ }
269
+ })
270
+ clean(@es)
271
+ end
272
+
273
+ context 'with ilm enabled' do
274
+ let (:ilm_enabled) { true }
309
275
 
310
- it 'should create the default rollover alias' do
276
+ context 'when using the default policy' do
277
+ context 'with a custom pattern' do
278
+ let (:settings) { super().merge("ilm_pattern" => "000001")}
279
+ it 'should create a rollover alias' do
311
280
  expect(@es.indices.exists_alias(name: "logstash")).to be_falsey
312
281
  subject.register
313
282
  sleep(1)
314
283
  expect(@es.indices.exists_alias(name: "logstash")).to be_truthy
315
- expect(@es.get_alias(name: "logstash")).to include("logstash-#{todays_date}-000001")
284
+ expect(@es.get_alias(name: "logstash")).to include("logstash-000001")
316
285
  end
286
+ end
317
287
 
318
- it 'should ingest into a single index' do
319
- subject.register
320
- subject.multi_receive([
321
- LogStash::Event.new("message" => "sample message here"),
322
- LogStash::Event.new("somemessage" => { "message" => "sample nested message here" }),
323
- LogStash::Event.new("somevalue" => 100),
324
- ])
325
-
326
- sleep(6)
327
-
328
- subject.multi_receive([
329
- LogStash::Event.new("country" => "us"),
330
- LogStash::Event.new("country" => "at"),
331
- LogStash::Event.new("geoip" => { "location" => [ 0.0, 0.0 ] })
332
- ])
333
-
334
- @es.indices.refresh
335
-
336
- # Wait or fail until everything's indexed.
337
- Stud::try(20.times) do
338
- r = @es.search(index: "logstash-*")
339
- expect(r).to have_hits(6)
340
- end
341
- indexes_written = @es.search(index: "logstash-*")['hits']['hits'].each_with_object(Hash.new(0)) do |x, res|
342
- index_written = x['_index']
343
- res[index_written] += 1
344
- end
345
-
346
- expect(indexes_written.count).to eq(1)
347
- expect(indexes_written["logstash-#{todays_date}-000001"]).to eq(6)
348
- end
288
+ it 'should install it if it is not present' do
289
+ expect{get_policy(@es, LogStash::Outputs::ElasticSearch::DEFAULT_POLICY)}.to raise_error(Elasticsearch::Transport::Transport::Errors::NotFound)
290
+ subject.register
291
+ sleep(1)
292
+ expect{get_policy(@es, LogStash::Outputs::ElasticSearch::DEFAULT_POLICY)}.not_to raise_error
349
293
  end
350
294
 
351
- context 'when not using the default policy' do
352
- let (:ilm_policy_name) {"logstash-policy-small"}
353
- let (:settings) { super().merge("ilm_policy" => ilm_policy_name)}
354
- let (:policy) { small_max_doc_policy }
295
+ it 'should create the default rollover alias' do
296
+ expect(@es.indices.exists_alias(name: "logstash")).to be_falsey
297
+ subject.register
298
+ sleep(1)
299
+ expect(@es.indices.exists_alias(name: "logstash")).to be_truthy
300
+ expect(@es.get_alias(name: "logstash")).to include("logstash-#{todays_date}-000001")
301
+ end
355
302
 
356
- before do
357
- expect{get_policy(@es, LogStash::Outputs::ElasticSearch::DEFAULT_POLICY)}.to raise_error(Elasticsearch::Transport::Transport::Errors::NotFound)
358
- put_policy(@es,ilm_policy_name, policy)
359
- end
303
+ it 'should ingest into a single index' do
304
+ subject.register
305
+ subject.multi_receive([
306
+ LogStash::Event.new("message" => "sample message here"),
307
+ LogStash::Event.new("somemessage" => { "message" => "sample nested message here" }),
308
+ LogStash::Event.new("somevalue" => 100),
309
+ ])
360
310
 
361
- it 'should not install the default policy if it is not used' do
362
- subject.register
363
- sleep(1)
364
- expect{get_policy(@es, LogStash::Outputs::ElasticSearch::DEFAULT_POLICY)}.to raise_error(Elasticsearch::Transport::Transport::Errors::NotFound)
311
+ sleep(6)
312
+
313
+ subject.multi_receive([
314
+ LogStash::Event.new("country" => "us"),
315
+ LogStash::Event.new("country" => "at"),
316
+ LogStash::Event.new("geoip" => { "location" => [ 0.0, 0.0 ] })
317
+ ])
318
+
319
+ @es.indices.refresh
320
+
321
+ # Wait or fail until everything's indexed.
322
+ Stud::try(20.times) do
323
+ r = @es.search(index: "logstash-*")
324
+ expect(r).to have_hits(6)
325
+ end
326
+ indexes_written = @es.search(index: "logstash-*")['hits']['hits'].each_with_object(Hash.new(0)) do |x, res|
327
+ index_written = x['_index']
328
+ res[index_written] += 1
365
329
  end
330
+
331
+ expect(indexes_written.count).to eq(1)
332
+ expect(indexes_written["logstash-#{todays_date}-000001"]).to eq(6)
366
333
  end
334
+ end
367
335
 
368
- context 'when using a time based policy' do
369
- let (:ilm_policy_name) {"logstash-policy-time"}
370
- let (:settings) { super().merge("ilm_policy" => ilm_policy_name)}
371
- let (:policy) { max_age_policy("1d") }
336
+ context 'when not using the default policy' do
337
+ let (:ilm_policy_name) {"logstash-policy-small"}
338
+ let (:settings) { super().merge("ilm_policy" => ilm_policy_name)}
339
+ let (:policy) { small_max_doc_policy }
372
340
 
373
- before do
374
- expect{get_policy(@es, LogStash::Outputs::ElasticSearch::DEFAULT_POLICY)}.to raise_error(Elasticsearch::Transport::Transport::Errors::NotFound)
375
- put_policy(@es,ilm_policy_name, policy)
376
- end
341
+ before do
342
+ expect{get_policy(@es, LogStash::Outputs::ElasticSearch::DEFAULT_POLICY)}.to raise_error(Elasticsearch::Transport::Transport::Errors::NotFound)
343
+ put_policy(@es,ilm_policy_name, policy)
344
+ end
377
345
 
378
- it 'should not install the default policy if it is not used' do
379
- subject.register
380
- sleep(1)
381
- expect{get_policy(@es, LogStash::Outputs::ElasticSearch::DEFAULT_POLICY)}.to raise_error(Elasticsearch::Transport::Transport::Errors::NotFound)
382
- end
346
+ it 'should not install the default policy if it is not used' do
347
+ subject.register
348
+ sleep(1)
349
+ expect{get_policy(@es, LogStash::Outputs::ElasticSearch::DEFAULT_POLICY)}.to raise_error(Elasticsearch::Transport::Transport::Errors::NotFound)
383
350
  end
351
+ end
384
352
 
385
- context 'with the default template' do
386
- it 'should create the rollover alias' do
387
- expect(@es.indices.exists_alias(name: expected_index)).to be_falsey
388
- subject.register
389
- sleep(1)
390
- expect(@es.indices.exists_alias(name: expected_index)).to be_truthy
391
- expect(@es.get_alias(name: expected_index)).to include("#{expected_index}-#{todays_date}-000001")
392
- end
353
+ context 'when using a time based policy' do
354
+ let (:ilm_policy_name) {"logstash-policy-time"}
355
+ let (:settings) { super().merge("ilm_policy" => ilm_policy_name)}
356
+ let (:policy) { max_age_policy("1d") }
393
357
 
394
- it 'should write the ILM settings into the template' do
395
- subject.register
396
- sleep(1)
358
+ before do
359
+ expect{get_policy(@es, LogStash::Outputs::ElasticSearch::DEFAULT_POLICY)}.to raise_error(Elasticsearch::Transport::Transport::Errors::NotFound)
360
+ put_policy(@es,ilm_policy_name, policy)
361
+ end
397
362
 
398
- template = get_template(@es, "logstash")
399
- expect(template).to have_index_pattern("logstash-*")
400
- expect(get_template_settings(template)['index']['lifecycle']['name']).to eq("logstash-policy")
401
- expect(get_template_settings(template)['index']['lifecycle']['rollover_alias']).to eq("logstash")
402
- end
363
+ it 'should not install the default policy if it is not used' do
364
+ subject.register
365
+ sleep(1)
366
+ expect{get_policy(@es, LogStash::Outputs::ElasticSearch::DEFAULT_POLICY)}.to raise_error(Elasticsearch::Transport::Transport::Errors::NotFound)
367
+ end
368
+ end
403
369
 
404
- it_behaves_like 'an ILM enabled Logstash'
370
+ context 'with the default template' do
371
+ it 'should create the rollover alias' do
372
+ expect(@es.indices.exists_alias(name: expected_index)).to be_falsey
373
+ subject.register
374
+ sleep(1)
375
+ expect(@es.indices.exists_alias(name: expected_index)).to be_truthy
376
+ expect(@es.get_alias(name: expected_index)).to include("#{expected_index}-#{todays_date}-000001")
405
377
  end
406
378
 
407
- context 'with a set index and a custom index pattern' do
408
- if ESHelper.es_version_satisfies?(">= 8.0")
409
- let (:template) { "spec/fixtures/template-with-policy-es8x.json" }
410
- elsif ESHelper.es_version_satisfies?(">= 7.0")
411
- let (:template) { "spec/fixtures/template-with-policy-es7x.json" }
412
- else
413
- let (:template) { "spec/fixtures/template-with-policy-es6x.json" }
414
- end
379
+ it 'should write the ILM settings into the template' do
380
+ subject.register
381
+ sleep(1)
415
382
 
416
- let (:settings) { super().merge("template" => template,
417
- "index" => "overwrite-4")}
383
+ template = get_template(@es, "logstash")
384
+ expect(template).to have_index_pattern("logstash-*")
385
+ expect(get_template_settings(template)['index']['lifecycle']['name']).to eq("logstash-policy")
386
+ expect(get_template_settings(template)['index']['lifecycle']['rollover_alias']).to eq("logstash")
387
+ end
418
388
 
419
- it 'should not overwrite the index patterns' do
420
- subject.register
421
- sleep(1)
389
+ it_behaves_like 'an ILM enabled Logstash'
390
+ end
422
391
 
423
- template = get_template(@es, "logstash")
424
- expect(template).to have_index_pattern("overwrite-*")
425
- end
392
+ context 'with a set index and a custom index pattern' do
393
+ if ESHelper.es_version_satisfies?(">= 8.0")
394
+ let (:template) { "spec/fixtures/template-with-policy-es8x.json" }
395
+ elsif ESHelper.es_version_satisfies?(">= 7.0")
396
+ let (:template) { "spec/fixtures/template-with-policy-es7x.json" }
397
+ else
398
+ let (:template) { "spec/fixtures/template-with-policy-es6x.json" }
426
399
  end
427
400
 
401
+ let (:settings) { super().merge("template" => template,
402
+ "index" => "overwrite-4")}
428
403
 
429
- context 'with a custom template' do
430
- let (:ilm_rollover_alias) { "logstash_the_cat_in_the_hat" }
431
- let (:index) { ilm_rollover_alias }
432
- let(:expected_index) { index }
433
- let (:settings) { super().merge("ilm_policy" => ilm_policy_name,
434
- "template" => template,
435
- "ilm_rollover_alias" => ilm_rollover_alias)}
404
+ it 'should not overwrite the index patterns' do
405
+ subject.register
406
+ sleep(1)
436
407
 
408
+ template = get_template(@es, "logstash")
409
+ expect(template).to have_index_pattern("overwrite-*")
410
+ end
411
+ end
437
412
 
438
- if ESHelper.es_version_satisfies?(">= 8.0")
439
- let (:template) { "spec/fixtures/template-with-policy-es8x.json" }
440
- elsif ESHelper.es_version_satisfies?(">= 7.0")
441
- let (:template) { "spec/fixtures/template-with-policy-es7x.json" }
442
- else
443
- let (:template) { "spec/fixtures/template-with-policy-es6x.json" }
444
- end
445
- let (:ilm_enabled) { true }
446
- let (:ilm_policy_name) { "logstash-policy-custom-policy" }
447
- let (:policy) { small_max_doc_policy }
448
413
 
449
- before :each do
450
- put_policy(@es,ilm_policy_name, policy)
451
- end
414
+ context 'with a custom template' do
415
+ let (:ilm_rollover_alias) { "logstash_the_cat_in_the_hat" }
416
+ let (:index) { ilm_rollover_alias }
417
+ let(:expected_index) { index }
418
+ let (:settings) { super().merge("ilm_policy" => ilm_policy_name,
419
+ "template" => template,
420
+ "ilm_rollover_alias" => ilm_rollover_alias)}
452
421
 
453
- it_behaves_like 'an ILM enabled Logstash'
454
422
 
455
- it 'should create the rollover alias' do
423
+ if ESHelper.es_version_satisfies?(">= 8.0")
424
+ let (:template) { "spec/fixtures/template-with-policy-es8x.json" }
425
+ elsif ESHelper.es_version_satisfies?(">= 7.0")
426
+ let (:template) { "spec/fixtures/template-with-policy-es7x.json" }
427
+ else
428
+ let (:template) { "spec/fixtures/template-with-policy-es6x.json" }
429
+ end
430
+ let (:ilm_enabled) { true }
431
+ let (:ilm_policy_name) { "logstash-policy-custom-policy" }
432
+ let (:policy) { small_max_doc_policy }
433
+
434
+ before :each do
435
+ put_policy(@es,ilm_policy_name, policy)
436
+ end
437
+
438
+ it_behaves_like 'an ILM enabled Logstash'
439
+
440
+ it 'should create the rollover alias' do
441
+ expect(@es.indices.exists_alias(name: ilm_rollover_alias)).to be_falsey
442
+ subject.register
443
+ sleep(1)
444
+ expect(@es.indices.exists_alias(name: ilm_rollover_alias)).to be_truthy
445
+ expect(@es.get_alias(name: ilm_rollover_alias)).to include("#{ilm_rollover_alias}-#{todays_date}-000001")
446
+ end
447
+
448
+ context 'when the custom rollover alias already exists' do
449
+ it 'should ignore the already exists error' do
456
450
  expect(@es.indices.exists_alias(name: ilm_rollover_alias)).to be_falsey
451
+ put_alias(@es, "#{ilm_rollover_alias}-#{todays_date}-000001", ilm_rollover_alias)
452
+ expect(@es.indices.exists_alias(name: ilm_rollover_alias)).to be_truthy
457
453
  subject.register
458
454
  sleep(1)
459
- expect(@es.indices.exists_alias(name: ilm_rollover_alias)).to be_truthy
460
455
  expect(@es.get_alias(name: ilm_rollover_alias)).to include("#{ilm_rollover_alias}-#{todays_date}-000001")
461
456
  end
462
457
 
463
- context 'when the custom rollover alias already exists' do
464
- it 'should ignore the already exists error' do
465
- expect(@es.indices.exists_alias(name: ilm_rollover_alias)).to be_falsey
466
- put_alias(@es, "#{ilm_rollover_alias}-#{todays_date}-000001", ilm_rollover_alias)
467
- expect(@es.indices.exists_alias(name: ilm_rollover_alias)).to be_truthy
468
- subject.register
469
- sleep(1)
470
- expect(@es.get_alias(name: ilm_rollover_alias)).to include("#{ilm_rollover_alias}-#{todays_date}-000001")
471
- end
458
+ end
472
459
 
473
- end
460
+ it 'should write the ILM settings into the template' do
461
+ subject.register
462
+ sleep(1)
463
+
464
+ template = get_template(@es, ilm_rollover_alias)
465
+ expect(template).to have_index_pattern("#{ilm_rollover_alias}-*")
466
+ expect(get_template_settings(template)['index']['lifecycle']['name']).to eq(ilm_policy_name)
467
+ expect(get_template_settings(template)['index']['lifecycle']['rollover_alias']).to eq(ilm_rollover_alias)
468
+ end
469
+
470
+ context 'with a different template_name' do
471
+ let (:template_name) { "logstash_custom_template_name" }
472
+ let (:settings) { super().merge('template_name' => template_name)}
473
+
474
+ it_behaves_like 'an ILM enabled Logstash'
474
475
 
475
476
  it 'should write the ILM settings into the template' do
476
477
  subject.register
477
478
  sleep(1)
478
-
479
- template = get_template(@es, ilm_rollover_alias)
479
+ template = get_template(@es, template_name)
480
480
  expect(template).to have_index_pattern("#{ilm_rollover_alias}-*")
481
481
  expect(get_template_settings(template)['index']['lifecycle']['name']).to eq(ilm_policy_name)
482
482
  expect(get_template_settings(template)['index']['lifecycle']['rollover_alias']).to eq(ilm_rollover_alias)
483
483
  end
484
-
485
- context 'with a different template_name' do
486
- let (:template_name) { "logstash_custom_template_name" }
487
- let (:settings) { super().merge('template_name' => template_name)}
488
-
489
- it_behaves_like 'an ILM enabled Logstash'
490
-
491
- it 'should write the ILM settings into the template' do
492
- subject.register
493
- sleep(1)
494
- template = get_template(@es, template_name)
495
- expect(template).to have_index_pattern("#{ilm_rollover_alias}-*")
496
- expect(get_template_settings(template)['index']['lifecycle']['name']).to eq(ilm_policy_name)
497
- expect(get_template_settings(template)['index']['lifecycle']['rollover_alias']).to eq(ilm_rollover_alias)
498
- end
499
- end
500
-
501
484
  end
485
+
502
486
  end
487
+ end
503
488
 
504
- context 'when ilm_enabled is set to "auto"' do
505
- let (:ilm_enabled) { 'auto' }
489
+ context 'when ilm_enabled is set to "auto"' do
490
+ let (:ilm_enabled) { 'auto' }
506
491
 
507
- if ESHelper.es_version_satisfies?(">=7.0")
508
- context 'when Elasticsearch is version 7 or above' do
509
- it_behaves_like 'an ILM enabled Logstash'
510
- end
492
+ if ESHelper.es_version_satisfies?(">=7.0")
493
+ context 'when Elasticsearch is version 7 or above' do
494
+ it_behaves_like 'an ILM enabled Logstash'
511
495
  end
496
+ end
512
497
 
513
- if ESHelper.es_version_satisfies?('< 7.0')
514
- context 'when Elasticsearch is version 7 or below' do
515
- it_behaves_like 'an ILM disabled Logstash'
516
- end
498
+ if ESHelper.es_version_satisfies?('< 7.0')
499
+ context 'when Elasticsearch is version 7 or below' do
500
+ it_behaves_like 'an ILM disabled Logstash'
517
501
  end
518
502
  end
503
+ end
519
504
 
520
- context 'when ilm_enabled is the default' do
521
- let (:settings) { super().tap{|x|x.delete('ilm_enabled')}}
505
+ context 'when ilm_enabled is the default' do
506
+ let (:settings) { super().tap{|x|x.delete('ilm_enabled')}}
522
507
 
523
- if ESHelper.es_version_satisfies?(">=7.0")
524
- context 'when Elasticsearch is version 7 or above' do
525
- it_behaves_like 'an ILM enabled Logstash'
526
- end
508
+ if ESHelper.es_version_satisfies?(">=7.0")
509
+ context 'when Elasticsearch is version 7 or above' do
510
+ it_behaves_like 'an ILM enabled Logstash'
527
511
  end
512
+ end
528
513
 
529
- if ESHelper.es_version_satisfies?('< 7.0')
530
- context 'when Elasticsearch is version 7 or below' do
531
- it_behaves_like 'an ILM disabled Logstash'
532
- end
514
+ if ESHelper.es_version_satisfies?('< 7.0')
515
+ context 'when Elasticsearch is version 7 or below' do
516
+ it_behaves_like 'an ILM disabled Logstash'
533
517
  end
534
518
  end
519
+ end
535
520
 
536
- context 'with ilm disabled' do
537
- let (:settings) { super().merge('ilm_enabled' => false )}
538
-
539
- it_behaves_like 'an ILM disabled Logstash'
540
- end
521
+ context 'with ilm disabled' do
522
+ let (:settings) { super().merge('ilm_enabled' => false )}
541
523
 
542
- context 'with ilm disabled using a string' do
543
- let (:settings) { super().merge('ilm_enabled' => 'false' )}
524
+ it_behaves_like 'an ILM disabled Logstash'
525
+ end
544
526
 
545
- it_behaves_like 'an ILM disabled Logstash'
546
- end
527
+ context 'with ilm disabled using a string' do
528
+ let (:settings) { super().merge('ilm_enabled' => 'false' )}
547
529
 
530
+ it_behaves_like 'an ILM disabled Logstash'
548
531
  end
549
- end
532
+
533
+ end