logstash-output-elasticsearch 10.8.6-java → 11.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 +17 -0
- data/docs/index.asciidoc +132 -22
- data/lib/logstash/outputs/elasticsearch.rb +125 -64
- data/lib/logstash/outputs/elasticsearch/data_stream_support.rb +233 -0
- data/lib/logstash/outputs/elasticsearch/http_client.rb +9 -7
- data/lib/logstash/outputs/elasticsearch/http_client/pool.rb +49 -62
- data/lib/logstash/outputs/elasticsearch/ilm.rb +13 -45
- data/lib/logstash/outputs/elasticsearch/license_checker.rb +26 -23
- data/lib/logstash/outputs/elasticsearch/template_manager.rb +4 -6
- data/lib/logstash/outputs/elasticsearch/templates/ecs-v1/elasticsearch-8x.json +1 -0
- data/lib/logstash/plugin_mixins/elasticsearch/api_configs.rb +157 -153
- data/lib/logstash/plugin_mixins/elasticsearch/common.rb +71 -58
- data/logstash-output-elasticsearch.gemspec +3 -3
- data/spec/es_spec_helper.rb +7 -12
- data/spec/fixtures/_nodes/{5x_6x.json → 6x.json} +5 -5
- data/spec/integration/outputs/compressed_indexing_spec.rb +47 -46
- data/spec/integration/outputs/data_stream_spec.rb +61 -0
- data/spec/integration/outputs/delete_spec.rb +49 -51
- data/spec/integration/outputs/ilm_spec.rb +236 -248
- data/spec/integration/outputs/index_spec.rb +5 -2
- data/spec/integration/outputs/index_version_spec.rb +78 -82
- data/spec/integration/outputs/ingest_pipeline_spec.rb +58 -58
- data/spec/integration/outputs/painless_update_spec.rb +74 -164
- data/spec/integration/outputs/parent_spec.rb +67 -75
- data/spec/integration/outputs/retry_spec.rb +6 -6
- data/spec/integration/outputs/sniffer_spec.rb +15 -54
- data/spec/integration/outputs/templates_spec.rb +79 -81
- data/spec/integration/outputs/update_spec.rb +99 -101
- data/spec/spec_helper.rb +10 -0
- data/spec/unit/outputs/elasticsearch/data_stream_support_spec.rb +528 -0
- data/spec/unit/outputs/elasticsearch/http_client/manticore_adapter_spec.rb +1 -0
- data/spec/unit/outputs/elasticsearch/http_client/pool_spec.rb +36 -29
- data/spec/unit/outputs/elasticsearch/http_client_spec.rb +2 -3
- data/spec/unit/outputs/elasticsearch/template_manager_spec.rb +10 -12
- data/spec/unit/outputs/elasticsearch_proxy_spec.rb +1 -2
- data/spec/unit/outputs/elasticsearch_spec.rb +176 -41
- data/spec/unit/outputs/elasticsearch_ssl_spec.rb +1 -2
- data/spec/unit/outputs/error_whitelist_spec.rb +3 -2
- data/spec/unit/outputs/license_check_spec.rb +0 -16
- metadata +29 -36
- data/lib/logstash/outputs/elasticsearch/templates/ecs-disabled/elasticsearch-2x.json +0 -95
- data/lib/logstash/outputs/elasticsearch/templates/ecs-disabled/elasticsearch-5x.json +0 -46
- data/spec/fixtures/_nodes/2x_1x.json +0 -27
- data/spec/fixtures/scripts/groovy/scripted_update.groovy +0 -2
- data/spec/fixtures/scripts/groovy/scripted_update_nested.groovy +0 -2
- data/spec/fixtures/scripts/groovy/scripted_upsert.groovy +0 -2
- data/spec/integration/outputs/groovy_update_spec.rb +0 -150
- data/spec/integration/outputs/templates_5x_spec.rb +0 -98
@@ -0,0 +1,61 @@
|
|
1
|
+
require_relative "../../../spec/es_spec_helper"
|
2
|
+
require "logstash/outputs/elasticsearch"
|
3
|
+
|
4
|
+
describe "data streams", :integration => true do
|
5
|
+
|
6
|
+
let(:ds_name) { "logs-#{ds_dataset}-default" }
|
7
|
+
let(:ds_dataset) { 'integration_test' }
|
8
|
+
|
9
|
+
let(:options) do
|
10
|
+
{ "data_stream" => 'true', "data_stream_dataset" => ds_dataset, "hosts" => get_host_port() }
|
11
|
+
end
|
12
|
+
|
13
|
+
subject { LogStash::Outputs::ElasticSearch.new(options) }
|
14
|
+
|
15
|
+
before :each do
|
16
|
+
@es = get_client
|
17
|
+
@es.delete_by_query(index: ".ds-#{ds_name}-*", expand_wildcards: :all, body: { query: { match_all: {} } }) rescue nil
|
18
|
+
|
19
|
+
es_version = @es.info['version']['number']
|
20
|
+
if Gem::Version.create(es_version) < Gem::Version.create('7.9.0')
|
21
|
+
skip "ES version #{es_version} does not support data-streams"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
it "creates a new document" do
|
26
|
+
subject.register
|
27
|
+
subject.multi_receive([LogStash::Event.new("message" => "MSG 111")])
|
28
|
+
|
29
|
+
@es.indices.refresh
|
30
|
+
|
31
|
+
Stud::try(3.times) do
|
32
|
+
r = @es.search(index: ds_name)
|
33
|
+
|
34
|
+
expect( r['hits']['total']['value'] ).to eq 1
|
35
|
+
doc = r['hits']['hits'].first
|
36
|
+
expect( doc['_source'] ).to include "message"=>"MSG 111"
|
37
|
+
expect( doc['_source'] ).to include "data_stream"=>{"dataset"=>ds_dataset, "type"=>"logs", "namespace"=>"default"}
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
context "with document_id" do
|
42
|
+
|
43
|
+
let(:document_id) { '1234567890' }
|
44
|
+
let(:options) { super().merge("document_id" => document_id) }
|
45
|
+
|
46
|
+
it "creates a new document" do
|
47
|
+
subject.register
|
48
|
+
subject.multi_receive([LogStash::Event.new("message" => "foo")])
|
49
|
+
|
50
|
+
@es.indices.refresh
|
51
|
+
|
52
|
+
Stud::try(3.times) do
|
53
|
+
r = @es.search(index: ds_name, body: { query: { match: { _id: document_id } } })
|
54
|
+
expect( r['hits']['total']['value'] ).to eq 1
|
55
|
+
doc = r['hits']['hits'].first
|
56
|
+
expect( doc['_source'] ).to include "message"=>"foo"
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
end
|
@@ -2,64 +2,62 @@ require_relative "../../../spec/es_spec_helper"
|
|
2
2
|
require "logstash/outputs/elasticsearch"
|
3
3
|
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
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
|
-
|
19
|
+
context "when delete only" do
|
20
|
+
subject { LogStash::Outputs::ElasticSearch.new(settings) }
|
10
21
|
|
11
|
-
before
|
12
|
-
|
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
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
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
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
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
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
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
|
-
|
61
|
-
|
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
|
-
|
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
|
-
|
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
|
@@ -198,12 +194,16 @@ shared_examples_for 'an Elasticsearch instance that does not support index lifec
|
|
198
194
|
let (:settings) { super().merge!({ 'ilm_enabled' => true }) }
|
199
195
|
|
200
196
|
it 'should raise a configuration error' do
|
197
|
+
# TODO should be refactored not to rely on plugin internals
|
198
|
+
finish_register = subject.method(:finish_register)
|
199
|
+
expect(subject).to receive(:finish_register)
|
201
200
|
expect do
|
202
201
|
begin
|
203
202
|
subject.register
|
204
|
-
|
203
|
+
finish_register.call
|
204
|
+
sleep(1.5) # wait_for_successful_connection (for the thread to raise)
|
205
205
|
ensure
|
206
|
-
subject.
|
206
|
+
subject.send :stop_after_successful_connection_thread
|
207
207
|
end
|
208
208
|
end.to raise_error(LogStash::ConfigurationError)
|
209
209
|
end
|
@@ -227,319 +227,307 @@ shared_examples_for 'an Elasticsearch instance that does not support index lifec
|
|
227
227
|
|
228
228
|
end
|
229
229
|
|
230
|
-
|
231
|
-
describe 'Pre-ILM versions of Elasticsearch', :integration => true do
|
232
|
-
it_behaves_like 'an Elasticsearch instance that does not support index lifecycle management'
|
233
|
-
end
|
234
|
-
end
|
230
|
+
describe 'Elasticsearch has index lifecycle management enabled', :integration => true do
|
235
231
|
|
236
|
-
|
237
|
-
describe 'OSS Elasticsearch', :distribution => 'oss', :integration => true do
|
238
|
-
it_behaves_like 'an Elasticsearch instance that does not support index lifecycle management'
|
239
|
-
end
|
232
|
+
DEFAULT_INTERVAL = '600s'
|
240
233
|
|
241
|
-
|
234
|
+
let (:ilm_enabled) { true }
|
242
235
|
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
let (:settings) {
|
248
|
-
{
|
249
|
-
"ilm_enabled" => ilm_enabled,
|
250
|
-
"hosts" => "#{get_host_port()}"
|
251
|
-
}
|
236
|
+
let (:settings) {
|
237
|
+
{
|
238
|
+
"ilm_enabled" => ilm_enabled,
|
239
|
+
"hosts" => "#{get_host_port()}"
|
252
240
|
}
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
subject(:elasticsearch_output_plugin) { LogStash::Outputs::ElasticSearch.new(settings) }
|
258
|
-
|
259
|
-
before :each do
|
260
|
-
# Delete all templates first.
|
261
|
-
require "elasticsearch"
|
262
|
-
|
263
|
-
# Clean ES of data before we start.
|
264
|
-
@es = get_client
|
265
|
-
clean(@es)
|
266
|
-
# Set the poll interval for lifecycle management to be short so changes get picked up in time.
|
267
|
-
set_cluster_settings(@es, {
|
268
|
-
"persistent" => {
|
269
|
-
"indices.lifecycle.poll_interval" => "1s"
|
270
|
-
}
|
271
|
-
})
|
272
|
-
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 }
|
273
245
|
|
274
|
-
|
275
|
-
# Set poll interval back to default
|
276
|
-
set_cluster_settings(@es, {
|
277
|
-
"persistent" => {
|
278
|
-
"indices.lifecycle.poll_interval" => DEFAULT_INTERVAL
|
279
|
-
}
|
280
|
-
})
|
281
|
-
clean(@es)
|
282
|
-
end
|
246
|
+
subject(:elasticsearch_output_plugin) { LogStash::Outputs::ElasticSearch.new(settings) }
|
283
247
|
|
284
|
-
|
285
|
-
|
248
|
+
before :each do
|
249
|
+
# Delete all templates first.
|
250
|
+
require "elasticsearch"
|
286
251
|
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
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
|
298
262
|
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
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 }
|
305
275
|
|
306
|
-
|
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
|
307
280
|
expect(@es.indices.exists_alias(name: "logstash")).to be_falsey
|
308
281
|
subject.register
|
309
282
|
sleep(1)
|
310
283
|
expect(@es.indices.exists_alias(name: "logstash")).to be_truthy
|
311
|
-
expect(@es.get_alias(name: "logstash")).to include("logstash
|
284
|
+
expect(@es.get_alias(name: "logstash")).to include("logstash-000001")
|
312
285
|
end
|
286
|
+
end
|
313
287
|
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
LogStash::Event.new("somevalue" => 100),
|
320
|
-
])
|
321
|
-
|
322
|
-
sleep(6)
|
323
|
-
|
324
|
-
subject.multi_receive([
|
325
|
-
LogStash::Event.new("country" => "us"),
|
326
|
-
LogStash::Event.new("country" => "at"),
|
327
|
-
LogStash::Event.new("geoip" => { "location" => [ 0.0, 0.0 ] })
|
328
|
-
])
|
329
|
-
|
330
|
-
@es.indices.refresh
|
331
|
-
|
332
|
-
# Wait or fail until everything's indexed.
|
333
|
-
Stud::try(20.times) do
|
334
|
-
r = @es.search(index: "logstash-*")
|
335
|
-
expect(r).to have_hits(6)
|
336
|
-
end
|
337
|
-
indexes_written = @es.search(index: "logstash-*")['hits']['hits'].each_with_object(Hash.new(0)) do |x, res|
|
338
|
-
index_written = x['_index']
|
339
|
-
res[index_written] += 1
|
340
|
-
end
|
341
|
-
|
342
|
-
expect(indexes_written.count).to eq(1)
|
343
|
-
expect(indexes_written["logstash-#{todays_date}-000001"]).to eq(6)
|
344
|
-
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
|
345
293
|
end
|
346
294
|
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
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
|
351
302
|
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
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
|
+
])
|
356
310
|
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
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
|
361
329
|
end
|
330
|
+
|
331
|
+
expect(indexes_written.count).to eq(1)
|
332
|
+
expect(indexes_written["logstash-#{todays_date}-000001"]).to eq(6)
|
362
333
|
end
|
334
|
+
end
|
363
335
|
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
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 }
|
368
340
|
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
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
|
373
345
|
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
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)
|
379
350
|
end
|
351
|
+
end
|
380
352
|
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
sleep(1)
|
386
|
-
expect(@es.indices.exists_alias(name: expected_index)).to be_truthy
|
387
|
-
expect(@es.get_alias(name: expected_index)).to include("#{expected_index}-#{todays_date}-000001")
|
388
|
-
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") }
|
389
357
|
|
390
|
-
|
391
|
-
|
392
|
-
|
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
|
393
362
|
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
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
|
399
369
|
|
400
|
-
|
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")
|
401
377
|
end
|
402
378
|
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
elsif ESHelper.es_version_satisfies?(">= 7.0")
|
407
|
-
let (:template) { "spec/fixtures/template-with-policy-es7x.json" }
|
408
|
-
else
|
409
|
-
let (:template) { "spec/fixtures/template-with-policy-es6x.json" }
|
410
|
-
end
|
379
|
+
it 'should write the ILM settings into the template' do
|
380
|
+
subject.register
|
381
|
+
sleep(1)
|
411
382
|
|
412
|
-
|
413
|
-
|
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
|
414
388
|
|
415
|
-
|
416
|
-
|
417
|
-
sleep(1)
|
389
|
+
it_behaves_like 'an ILM enabled Logstash'
|
390
|
+
end
|
418
391
|
|
419
|
-
|
420
|
-
|
421
|
-
|
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" }
|
422
399
|
end
|
423
400
|
|
401
|
+
let (:settings) { super().merge("template" => template,
|
402
|
+
"index" => "overwrite-4")}
|
424
403
|
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
let(:expected_index) { index }
|
429
|
-
let (:settings) { super().merge("ilm_policy" => ilm_policy_name,
|
430
|
-
"template" => template,
|
431
|
-
"ilm_rollover_alias" => ilm_rollover_alias)}
|
404
|
+
it 'should not overwrite the index patterns' do
|
405
|
+
subject.register
|
406
|
+
sleep(1)
|
432
407
|
|
408
|
+
template = get_template(@es, "logstash")
|
409
|
+
expect(template).to have_index_pattern("overwrite-*")
|
410
|
+
end
|
411
|
+
end
|
433
412
|
|
434
|
-
if ESHelper.es_version_satisfies?(">= 8.0")
|
435
|
-
let (:template) { "spec/fixtures/template-with-policy-es8x.json" }
|
436
|
-
elsif ESHelper.es_version_satisfies?(">= 7.0")
|
437
|
-
let (:template) { "spec/fixtures/template-with-policy-es7x.json" }
|
438
|
-
else
|
439
|
-
let (:template) { "spec/fixtures/template-with-policy-es6x.json" }
|
440
|
-
end
|
441
|
-
let (:ilm_enabled) { true }
|
442
|
-
let (:ilm_policy_name) { "logstash-policy-custom-policy" }
|
443
|
-
let (:policy) { small_max_doc_policy }
|
444
413
|
|
445
|
-
|
446
|
-
|
447
|
-
|
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)}
|
448
421
|
|
449
|
-
it_behaves_like 'an ILM enabled Logstash'
|
450
422
|
|
451
|
-
|
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
|
452
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
|
453
453
|
subject.register
|
454
454
|
sleep(1)
|
455
|
-
expect(@es.indices.exists_alias(name: ilm_rollover_alias)).to be_truthy
|
456
455
|
expect(@es.get_alias(name: ilm_rollover_alias)).to include("#{ilm_rollover_alias}-#{todays_date}-000001")
|
457
456
|
end
|
458
457
|
|
459
|
-
|
460
|
-
it 'should ignore the already exists error' do
|
461
|
-
expect(@es.indices.exists_alias(name: ilm_rollover_alias)).to be_falsey
|
462
|
-
put_alias(@es, "#{ilm_rollover_alias}-#{todays_date}-000001", ilm_rollover_alias)
|
463
|
-
expect(@es.indices.exists_alias(name: ilm_rollover_alias)).to be_truthy
|
464
|
-
subject.register
|
465
|
-
sleep(1)
|
466
|
-
expect(@es.get_alias(name: ilm_rollover_alias)).to include("#{ilm_rollover_alias}-#{todays_date}-000001")
|
467
|
-
end
|
458
|
+
end
|
468
459
|
|
469
|
-
|
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'
|
470
475
|
|
471
476
|
it 'should write the ILM settings into the template' do
|
472
477
|
subject.register
|
473
478
|
sleep(1)
|
474
|
-
|
475
|
-
template = get_template(@es, ilm_rollover_alias)
|
479
|
+
template = get_template(@es, template_name)
|
476
480
|
expect(template).to have_index_pattern("#{ilm_rollover_alias}-*")
|
477
481
|
expect(get_template_settings(template)['index']['lifecycle']['name']).to eq(ilm_policy_name)
|
478
482
|
expect(get_template_settings(template)['index']['lifecycle']['rollover_alias']).to eq(ilm_rollover_alias)
|
479
483
|
end
|
480
|
-
|
481
|
-
context 'with a different template_name' do
|
482
|
-
let (:template_name) { "logstash_custom_template_name" }
|
483
|
-
let (:settings) { super().merge('template_name' => template_name)}
|
484
|
-
|
485
|
-
it_behaves_like 'an ILM enabled Logstash'
|
486
|
-
|
487
|
-
it 'should write the ILM settings into the template' do
|
488
|
-
subject.register
|
489
|
-
sleep(1)
|
490
|
-
template = get_template(@es, template_name)
|
491
|
-
expect(template).to have_index_pattern("#{ilm_rollover_alias}-*")
|
492
|
-
expect(get_template_settings(template)['index']['lifecycle']['name']).to eq(ilm_policy_name)
|
493
|
-
expect(get_template_settings(template)['index']['lifecycle']['rollover_alias']).to eq(ilm_rollover_alias)
|
494
|
-
end
|
495
|
-
end
|
496
|
-
|
497
484
|
end
|
485
|
+
|
498
486
|
end
|
487
|
+
end
|
499
488
|
|
500
|
-
|
501
|
-
|
489
|
+
context 'when ilm_enabled is set to "auto"' do
|
490
|
+
let (:ilm_enabled) { 'auto' }
|
502
491
|
|
503
|
-
|
504
|
-
|
505
|
-
|
506
|
-
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'
|
507
495
|
end
|
496
|
+
end
|
508
497
|
|
509
|
-
|
510
|
-
|
511
|
-
|
512
|
-
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'
|
513
501
|
end
|
514
502
|
end
|
503
|
+
end
|
515
504
|
|
516
|
-
|
517
|
-
|
505
|
+
context 'when ilm_enabled is the default' do
|
506
|
+
let (:settings) { super().tap{|x|x.delete('ilm_enabled')}}
|
518
507
|
|
519
|
-
|
520
|
-
|
521
|
-
|
522
|
-
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'
|
523
511
|
end
|
512
|
+
end
|
524
513
|
|
525
|
-
|
526
|
-
|
527
|
-
|
528
|
-
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'
|
529
517
|
end
|
530
518
|
end
|
519
|
+
end
|
531
520
|
|
532
|
-
|
533
|
-
|
534
|
-
|
535
|
-
it_behaves_like 'an ILM disabled Logstash'
|
536
|
-
end
|
521
|
+
context 'with ilm disabled' do
|
522
|
+
let (:settings) { super().merge('ilm_enabled' => false )}
|
537
523
|
|
538
|
-
|
539
|
-
|
524
|
+
it_behaves_like 'an ILM disabled Logstash'
|
525
|
+
end
|
540
526
|
|
541
|
-
|
542
|
-
|
527
|
+
context 'with ilm disabled using a string' do
|
528
|
+
let (:settings) { super().merge('ilm_enabled' => 'false' )}
|
543
529
|
|
530
|
+
it_behaves_like 'an ILM disabled Logstash'
|
544
531
|
end
|
545
|
-
|
532
|
+
|
533
|
+
end
|