logstash-output-elasticsearch-test 11.16.0-x86_64-linux
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.md +649 -0
- data/CONTRIBUTORS +34 -0
- data/Gemfile +16 -0
- data/LICENSE +202 -0
- data/NOTICE.TXT +5 -0
- data/README.md +106 -0
- data/docs/index.asciidoc +1369 -0
- data/lib/logstash/outputs/elasticsearch/data_stream_support.rb +282 -0
- data/lib/logstash/outputs/elasticsearch/default-ilm-policy.json +14 -0
- data/lib/logstash/outputs/elasticsearch/http_client/manticore_adapter.rb +155 -0
- data/lib/logstash/outputs/elasticsearch/http_client/pool.rb +534 -0
- data/lib/logstash/outputs/elasticsearch/http_client.rb +497 -0
- data/lib/logstash/outputs/elasticsearch/http_client_builder.rb +201 -0
- data/lib/logstash/outputs/elasticsearch/ilm.rb +92 -0
- data/lib/logstash/outputs/elasticsearch/license_checker.rb +52 -0
- data/lib/logstash/outputs/elasticsearch/template_manager.rb +131 -0
- data/lib/logstash/outputs/elasticsearch/templates/ecs-disabled/elasticsearch-6x.json +45 -0
- data/lib/logstash/outputs/elasticsearch/templates/ecs-disabled/elasticsearch-7x.json +44 -0
- data/lib/logstash/outputs/elasticsearch/templates/ecs-disabled/elasticsearch-8x.json +50 -0
- data/lib/logstash/outputs/elasticsearch.rb +699 -0
- data/lib/logstash/plugin_mixins/elasticsearch/api_configs.rb +237 -0
- data/lib/logstash/plugin_mixins/elasticsearch/common.rb +409 -0
- data/lib/logstash/plugin_mixins/elasticsearch/noop_license_checker.rb +9 -0
- data/logstash-output-elasticsearch.gemspec +40 -0
- data/spec/es_spec_helper.rb +225 -0
- data/spec/fixtures/_nodes/6x.json +81 -0
- data/spec/fixtures/_nodes/7x.json +92 -0
- data/spec/fixtures/htpasswd +2 -0
- data/spec/fixtures/license_check/active.json +16 -0
- data/spec/fixtures/license_check/inactive.json +5 -0
- data/spec/fixtures/nginx_reverse_proxy.conf +22 -0
- data/spec/fixtures/scripts/painless/scripted_update.painless +2 -0
- data/spec/fixtures/scripts/painless/scripted_update_nested.painless +1 -0
- data/spec/fixtures/scripts/painless/scripted_upsert.painless +1 -0
- data/spec/fixtures/template-with-policy-es6x.json +48 -0
- data/spec/fixtures/template-with-policy-es7x.json +45 -0
- data/spec/fixtures/template-with-policy-es8x.json +50 -0
- data/spec/fixtures/test_certs/ca.crt +29 -0
- data/spec/fixtures/test_certs/ca.der.sha256 +1 -0
- data/spec/fixtures/test_certs/ca.key +51 -0
- data/spec/fixtures/test_certs/renew.sh +13 -0
- data/spec/fixtures/test_certs/test.crt +30 -0
- data/spec/fixtures/test_certs/test.der.sha256 +1 -0
- data/spec/fixtures/test_certs/test.key +51 -0
- data/spec/fixtures/test_certs/test.p12 +0 -0
- data/spec/fixtures/test_certs/test_invalid.crt +36 -0
- data/spec/fixtures/test_certs/test_invalid.key +51 -0
- data/spec/fixtures/test_certs/test_invalid.p12 +0 -0
- data/spec/fixtures/test_certs/test_self_signed.crt +32 -0
- data/spec/fixtures/test_certs/test_self_signed.key +54 -0
- data/spec/fixtures/test_certs/test_self_signed.p12 +0 -0
- data/spec/integration/outputs/compressed_indexing_spec.rb +70 -0
- data/spec/integration/outputs/create_spec.rb +67 -0
- data/spec/integration/outputs/data_stream_spec.rb +68 -0
- data/spec/integration/outputs/delete_spec.rb +63 -0
- data/spec/integration/outputs/ilm_spec.rb +534 -0
- data/spec/integration/outputs/index_spec.rb +421 -0
- data/spec/integration/outputs/index_version_spec.rb +98 -0
- data/spec/integration/outputs/ingest_pipeline_spec.rb +75 -0
- data/spec/integration/outputs/metrics_spec.rb +66 -0
- data/spec/integration/outputs/no_es_on_startup_spec.rb +78 -0
- data/spec/integration/outputs/painless_update_spec.rb +99 -0
- data/spec/integration/outputs/parent_spec.rb +94 -0
- data/spec/integration/outputs/retry_spec.rb +182 -0
- data/spec/integration/outputs/routing_spec.rb +61 -0
- data/spec/integration/outputs/sniffer_spec.rb +94 -0
- data/spec/integration/outputs/templates_spec.rb +133 -0
- data/spec/integration/outputs/unsupported_actions_spec.rb +75 -0
- data/spec/integration/outputs/update_spec.rb +114 -0
- data/spec/spec_helper.rb +10 -0
- data/spec/support/elasticsearch/api/actions/delete_ilm_policy.rb +19 -0
- data/spec/support/elasticsearch/api/actions/get_alias.rb +18 -0
- data/spec/support/elasticsearch/api/actions/get_ilm_policy.rb +18 -0
- data/spec/support/elasticsearch/api/actions/put_alias.rb +24 -0
- data/spec/support/elasticsearch/api/actions/put_ilm_policy.rb +25 -0
- data/spec/unit/http_client_builder_spec.rb +185 -0
- data/spec/unit/outputs/elasticsearch/data_stream_support_spec.rb +612 -0
- data/spec/unit/outputs/elasticsearch/http_client/manticore_adapter_spec.rb +151 -0
- data/spec/unit/outputs/elasticsearch/http_client/pool_spec.rb +501 -0
- data/spec/unit/outputs/elasticsearch/http_client_spec.rb +339 -0
- data/spec/unit/outputs/elasticsearch/template_manager_spec.rb +189 -0
- data/spec/unit/outputs/elasticsearch_proxy_spec.rb +103 -0
- data/spec/unit/outputs/elasticsearch_spec.rb +1573 -0
- data/spec/unit/outputs/elasticsearch_ssl_spec.rb +197 -0
- data/spec/unit/outputs/error_whitelist_spec.rb +56 -0
- data/spec/unit/outputs/license_check_spec.rb +57 -0
- metadata +423 -0
@@ -0,0 +1,534 @@
|
|
1
|
+
require_relative "../../../spec/es_spec_helper"
|
2
|
+
|
3
|
+
shared_examples_for 'an ILM enabled Logstash' do
|
4
|
+
|
5
|
+
context 'with a policy with a maximum number of documents' do
|
6
|
+
let (:policy) { small_max_doc_policy }
|
7
|
+
let (:ilm_policy_name) { "logstash-policy-custom"}
|
8
|
+
let (:settings) { super().merge("ilm_policy" => ilm_policy_name)}
|
9
|
+
|
10
|
+
it 'should rollover when the policy max docs is reached' do
|
11
|
+
put_policy(@es, ilm_policy_name, policy)
|
12
|
+
subject.register
|
13
|
+
|
14
|
+
subject.multi_receive([
|
15
|
+
LogStash::Event.new("message" => "sample message here"),
|
16
|
+
LogStash::Event.new("somemessage" => { "message" => "sample nested message here" }),
|
17
|
+
LogStash::Event.new("somevalue" => 100),
|
18
|
+
])
|
19
|
+
|
20
|
+
sleep(6)
|
21
|
+
|
22
|
+
subject.multi_receive([
|
23
|
+
LogStash::Event.new("country" => "us"),
|
24
|
+
LogStash::Event.new("country" => "at"),
|
25
|
+
LogStash::Event.new("geoip" => { "location" => [ 0.0, 0.0 ] })
|
26
|
+
])
|
27
|
+
|
28
|
+
sleep(6)
|
29
|
+
|
30
|
+
subject.multi_receive([
|
31
|
+
LogStash::Event.new("country" => "uk"),
|
32
|
+
LogStash::Event.new("country" => "fr"),
|
33
|
+
LogStash::Event.new("geoip" => { "location" => [ 0.1, 1.0 ] })
|
34
|
+
])
|
35
|
+
|
36
|
+
@es.indices.refresh
|
37
|
+
|
38
|
+
# Wait or fail until everything's indexed.
|
39
|
+
Stud::try(20.times) do
|
40
|
+
r = @es.search(index: "#{expected_index}-*")
|
41
|
+
expect(r).to have_hits(9)
|
42
|
+
end
|
43
|
+
indexes_written = @es.search(index: "#{expected_index}-*")['hits']['hits'].each_with_object(Hash.new(0)) do |x, res|
|
44
|
+
index_written = x['_index']
|
45
|
+
res[index_written] += 1
|
46
|
+
end
|
47
|
+
expect(indexes_written.count).to eq(3)
|
48
|
+
expect(indexes_written["#{expected_index}-#{todays_date}-000001"]).to eq(3)
|
49
|
+
expect(indexes_written["#{expected_index}-#{todays_date}-000002"]).to eq(3)
|
50
|
+
expect(indexes_written["#{expected_index}-#{todays_date}-000003"]).to eq(3)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
context 'with a policy where the maximum number of documents is not reached' do
|
55
|
+
let (:policy) { large_max_doc_policy }
|
56
|
+
let (:ilm_policy_name) { "logstash-policy-custom-policy"}
|
57
|
+
let (:settings) { super().merge("ilm_policy" => ilm_policy_name)}
|
58
|
+
|
59
|
+
it 'should ingest into a single index when max docs is not reached' do
|
60
|
+
put_policy(@es,ilm_policy_name, policy)
|
61
|
+
subject.register
|
62
|
+
|
63
|
+
subject.multi_receive([
|
64
|
+
LogStash::Event.new("message" => "sample message here"),
|
65
|
+
LogStash::Event.new("somemessage" => { "message" => "sample nested message here" }),
|
66
|
+
LogStash::Event.new("somevalue" => 100),
|
67
|
+
])
|
68
|
+
|
69
|
+
sleep(6)
|
70
|
+
|
71
|
+
subject.multi_receive([
|
72
|
+
LogStash::Event.new("country" => "us"),
|
73
|
+
LogStash::Event.new("country" => "at"),
|
74
|
+
LogStash::Event.new("geoip" => { "location" => [ 0.0, 0.0 ] })
|
75
|
+
])
|
76
|
+
|
77
|
+
@es.indices.refresh
|
78
|
+
|
79
|
+
# Wait or fail until everything's indexed.
|
80
|
+
Stud::try(20.times) do
|
81
|
+
r = @es.search(index: "#{expected_index}-*")
|
82
|
+
expect(r).to have_hits(6)
|
83
|
+
end
|
84
|
+
indexes_written = @es.search(index: "#{expected_index}-*")['hits']['hits'].each_with_object(Hash.new(0)) do |x, res|
|
85
|
+
index_written = x['_index']
|
86
|
+
res[index_written] += 1
|
87
|
+
end
|
88
|
+
expect(indexes_written.count).to eq(1)
|
89
|
+
expect(indexes_written["#{expected_index}-#{todays_date}-000001"]).to eq(6)
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
shared_examples_for 'an ILM disabled Logstash' do
|
95
|
+
it 'should not create a rollover alias' do
|
96
|
+
expect(@es.indices.exists_alias(name: "logstash")).to be_falsey
|
97
|
+
subject.register
|
98
|
+
sleep(1)
|
99
|
+
expect(@es.indices.exists_alias(name: "logstash")).to be_falsey
|
100
|
+
end
|
101
|
+
|
102
|
+
it 'should not install the default policy' do
|
103
|
+
subject.register
|
104
|
+
sleep(1)
|
105
|
+
expect{get_policy(@es, LogStash::Outputs::ElasticSearch::DEFAULT_POLICY)}.to raise_error(Elasticsearch::Transport::Transport::Errors::NotFound)
|
106
|
+
end
|
107
|
+
|
108
|
+
it 'should not write the ILM settings into the template' do
|
109
|
+
subject.register
|
110
|
+
sleep(1)
|
111
|
+
|
112
|
+
template = get_template(@es, "logstash")
|
113
|
+
expect(template).to have_index_pattern("logstash-*")
|
114
|
+
expect(get_template_settings(template)['index']['lifecycle']).to be_nil
|
115
|
+
end
|
116
|
+
|
117
|
+
context 'with an existing policy that will roll over' do
|
118
|
+
let (:policy) { small_max_doc_policy }
|
119
|
+
let (:ilm_policy_name) { "logstash-policy-3_docs"}
|
120
|
+
let (:settings) { super().merge("ilm_policy" => ilm_policy_name)}
|
121
|
+
|
122
|
+
it 'should not roll over indices' do
|
123
|
+
subject.register
|
124
|
+
subject.multi_receive([
|
125
|
+
LogStash::Event.new("message" => "sample message here"),
|
126
|
+
LogStash::Event.new("somemessage" => { "message" => "sample nested message here" }),
|
127
|
+
LogStash::Event.new("somevalue" => 100),
|
128
|
+
])
|
129
|
+
|
130
|
+
sleep(6)
|
131
|
+
|
132
|
+
subject.multi_receive([
|
133
|
+
LogStash::Event.new("country" => "us"),
|
134
|
+
LogStash::Event.new("country" => "at"),
|
135
|
+
LogStash::Event.new("geoip" => { "location" => [ 0.0, 0.0 ] })
|
136
|
+
])
|
137
|
+
|
138
|
+
@es.indices.refresh
|
139
|
+
|
140
|
+
# Wait or fail until everything's indexed.
|
141
|
+
Stud::try(20.times) do
|
142
|
+
r = @es.search(index: 'logstash-*')
|
143
|
+
expect(r).to have_hits(6)
|
144
|
+
end
|
145
|
+
indexes_written = @es.search(index: 'logstash-*')['hits']['hits'].each_with_object(Hash.new(0)) do |x, res|
|
146
|
+
index_written = x['_index']
|
147
|
+
res[index_written] += 1
|
148
|
+
end
|
149
|
+
expect(indexes_written.count).to eq(1)
|
150
|
+
expect(indexes_written.values.first).to eq(6)
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
context 'with a custom template name' do
|
155
|
+
let (:template_name) { "logstash_custom_template_name" }
|
156
|
+
let (:settings) { super().merge('template_name' => template_name)}
|
157
|
+
|
158
|
+
it 'should not write the ILM settings into the template' do
|
159
|
+
subject.register
|
160
|
+
sleep(1)
|
161
|
+
|
162
|
+
template = get_template(@es, template_name)
|
163
|
+
expect(template).to have_index_pattern("logstash-*")
|
164
|
+
expect(get_template_settings(template)['index']['lifecycle']).to be_nil
|
165
|
+
end
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
169
|
+
shared_examples_for 'an Elasticsearch instance that does not support index lifecycle management' do
|
170
|
+
require "logstash/outputs/elasticsearch"
|
171
|
+
|
172
|
+
let (:ilm_enabled) { false }
|
173
|
+
let (:settings) {
|
174
|
+
{
|
175
|
+
"hosts" => "#{get_host_port()}"
|
176
|
+
}
|
177
|
+
}
|
178
|
+
|
179
|
+
before :each do
|
180
|
+
require "elasticsearch"
|
181
|
+
|
182
|
+
# Clean ES of data before we start.
|
183
|
+
@es = get_client
|
184
|
+
clean(@es)
|
185
|
+
end
|
186
|
+
|
187
|
+
after :each do
|
188
|
+
clean(@es)
|
189
|
+
end
|
190
|
+
|
191
|
+
subject { LogStash::Outputs::ElasticSearch.new(settings) }
|
192
|
+
|
193
|
+
context 'when ilm is enabled in Logstash' do
|
194
|
+
let (:settings) { super().merge!({ 'ilm_enabled' => true }) }
|
195
|
+
|
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)
|
200
|
+
expect do
|
201
|
+
begin
|
202
|
+
subject.register
|
203
|
+
finish_register.call
|
204
|
+
sleep(1.5) # wait_for_successful_connection (for the thread to raise)
|
205
|
+
ensure
|
206
|
+
subject.send :stop_after_successful_connection_thread
|
207
|
+
end
|
208
|
+
end.to raise_error(LogStash::ConfigurationError)
|
209
|
+
end
|
210
|
+
end
|
211
|
+
|
212
|
+
context 'when ilm is disabled in Logstash' do
|
213
|
+
let (:settings) { super().merge!({ 'ilm_enabled' => false }) }
|
214
|
+
|
215
|
+
it_behaves_like 'an ILM disabled Logstash'
|
216
|
+
end
|
217
|
+
|
218
|
+
context 'when ilm is set to auto in Logstash' do
|
219
|
+
let (:settings) { super().merge!({ 'ilm_enabled' => 'auto' }) }
|
220
|
+
|
221
|
+
it_behaves_like 'an ILM disabled Logstash'
|
222
|
+
end
|
223
|
+
|
224
|
+
context 'when ilm is not set in Logstash' do
|
225
|
+
it_behaves_like 'an ILM disabled Logstash'
|
226
|
+
end
|
227
|
+
|
228
|
+
end
|
229
|
+
|
230
|
+
describe 'Elasticsearch has index lifecycle management enabled', :integration => true do
|
231
|
+
|
232
|
+
DEFAULT_INTERVAL = '600s'
|
233
|
+
|
234
|
+
let (:ilm_enabled) { true }
|
235
|
+
|
236
|
+
let (:settings) {
|
237
|
+
{
|
238
|
+
"ilm_enabled" => ilm_enabled,
|
239
|
+
"hosts" => "#{get_host_port()}",
|
240
|
+
"ecs_compatibility" => "disabled", # specs are tightly tied to non-ECS defaults
|
241
|
+
}
|
242
|
+
}
|
243
|
+
let (:small_max_doc_policy) { max_docs_policy(3) }
|
244
|
+
let (:large_max_doc_policy) { max_docs_policy(1000000) }
|
245
|
+
let (:expected_index) { elasticsearch_output_plugin.default_ilm_rollover_alias }
|
246
|
+
|
247
|
+
subject(:elasticsearch_output_plugin) { LogStash::Outputs::ElasticSearch.new(settings) }
|
248
|
+
|
249
|
+
before :each do
|
250
|
+
# Delete all templates first.
|
251
|
+
require "elasticsearch"
|
252
|
+
|
253
|
+
# Clean ES of data before we start.
|
254
|
+
@es = get_client
|
255
|
+
clean(@es)
|
256
|
+
# Set the poll interval for lifecycle management to be short so changes get picked up in time.
|
257
|
+
set_cluster_settings(@es, {
|
258
|
+
"persistent" => {
|
259
|
+
"indices.lifecycle.poll_interval" => "1s"
|
260
|
+
}
|
261
|
+
})
|
262
|
+
end
|
263
|
+
|
264
|
+
after :each do
|
265
|
+
# Set poll interval back to default
|
266
|
+
set_cluster_settings(@es, {
|
267
|
+
"persistent" => {
|
268
|
+
"indices.lifecycle.poll_interval" => DEFAULT_INTERVAL
|
269
|
+
}
|
270
|
+
})
|
271
|
+
clean(@es)
|
272
|
+
end
|
273
|
+
|
274
|
+
context 'with ilm enabled' do
|
275
|
+
let (:ilm_enabled) { true }
|
276
|
+
|
277
|
+
context 'when using the default policy' do
|
278
|
+
context 'with a custom pattern' do
|
279
|
+
let (:settings) { super().merge("ilm_pattern" => "000001")}
|
280
|
+
it 'should create a rollover alias' do
|
281
|
+
expect(@es.indices.exists_alias(name: "logstash")).to be_falsey
|
282
|
+
subject.register
|
283
|
+
sleep(1)
|
284
|
+
expect(@es.indices.exists_alias(name: "logstash")).to be_truthy
|
285
|
+
expect(@es.get_alias(name: "logstash")).to include("logstash-000001")
|
286
|
+
end
|
287
|
+
end
|
288
|
+
|
289
|
+
it 'should install it if it is not present' do
|
290
|
+
expect{get_policy(@es, LogStash::Outputs::ElasticSearch::DEFAULT_POLICY)}.to raise_error(Elasticsearch::Transport::Transport::Errors::NotFound)
|
291
|
+
subject.register
|
292
|
+
sleep(1)
|
293
|
+
expect{get_policy(@es, LogStash::Outputs::ElasticSearch::DEFAULT_POLICY)}.not_to raise_error
|
294
|
+
end
|
295
|
+
|
296
|
+
it 'should create the default rollover alias' do
|
297
|
+
expect(@es.indices.exists_alias(name: "logstash")).to be_falsey
|
298
|
+
subject.register
|
299
|
+
sleep(1)
|
300
|
+
expect(@es.indices.exists_alias(name: "logstash")).to be_truthy
|
301
|
+
expect(@es.get_alias(name: "logstash")).to include("logstash-#{todays_date}-000001")
|
302
|
+
end
|
303
|
+
|
304
|
+
it 'should ingest into a single index' do
|
305
|
+
subject.register
|
306
|
+
subject.multi_receive([
|
307
|
+
LogStash::Event.new("message" => "sample message here"),
|
308
|
+
LogStash::Event.new("somemessage" => { "message" => "sample nested message here" }),
|
309
|
+
LogStash::Event.new("somevalue" => 100),
|
310
|
+
])
|
311
|
+
|
312
|
+
sleep(6)
|
313
|
+
|
314
|
+
subject.multi_receive([
|
315
|
+
LogStash::Event.new("country" => "us"),
|
316
|
+
LogStash::Event.new("country" => "at"),
|
317
|
+
LogStash::Event.new("geoip" => { "location" => [ 0.0, 0.0 ] })
|
318
|
+
])
|
319
|
+
|
320
|
+
@es.indices.refresh
|
321
|
+
|
322
|
+
# Wait or fail until everything's indexed.
|
323
|
+
Stud::try(20.times) do
|
324
|
+
r = @es.search(index: "logstash-*")
|
325
|
+
expect(r).to have_hits(6)
|
326
|
+
end
|
327
|
+
indexes_written = @es.search(index: "logstash-*")['hits']['hits'].each_with_object(Hash.new(0)) do |x, res|
|
328
|
+
index_written = x['_index']
|
329
|
+
res[index_written] += 1
|
330
|
+
end
|
331
|
+
|
332
|
+
expect(indexes_written.count).to eq(1)
|
333
|
+
expect(indexes_written["logstash-#{todays_date}-000001"]).to eq(6)
|
334
|
+
end
|
335
|
+
end
|
336
|
+
|
337
|
+
context 'when not using the default policy' do
|
338
|
+
let (:ilm_policy_name) {"logstash-policy-small"}
|
339
|
+
let (:settings) { super().merge("ilm_policy" => ilm_policy_name)}
|
340
|
+
let (:policy) { small_max_doc_policy }
|
341
|
+
|
342
|
+
before do
|
343
|
+
expect{get_policy(@es, LogStash::Outputs::ElasticSearch::DEFAULT_POLICY)}.to raise_error(Elasticsearch::Transport::Transport::Errors::NotFound)
|
344
|
+
put_policy(@es,ilm_policy_name, policy)
|
345
|
+
end
|
346
|
+
|
347
|
+
it 'should not install the default policy if it is not used' do
|
348
|
+
subject.register
|
349
|
+
sleep(1)
|
350
|
+
expect{get_policy(@es, LogStash::Outputs::ElasticSearch::DEFAULT_POLICY)}.to raise_error(Elasticsearch::Transport::Transport::Errors::NotFound)
|
351
|
+
end
|
352
|
+
end
|
353
|
+
|
354
|
+
context 'when using a time based policy' do
|
355
|
+
let (:ilm_policy_name) {"logstash-policy-time"}
|
356
|
+
let (:settings) { super().merge("ilm_policy" => ilm_policy_name)}
|
357
|
+
let (:policy) { max_age_policy("1d") }
|
358
|
+
|
359
|
+
before do
|
360
|
+
expect{get_policy(@es, LogStash::Outputs::ElasticSearch::DEFAULT_POLICY)}.to raise_error(Elasticsearch::Transport::Transport::Errors::NotFound)
|
361
|
+
put_policy(@es,ilm_policy_name, policy)
|
362
|
+
end
|
363
|
+
|
364
|
+
it 'should not install the default policy if it is not used' do
|
365
|
+
subject.register
|
366
|
+
sleep(1)
|
367
|
+
expect{get_policy(@es, LogStash::Outputs::ElasticSearch::DEFAULT_POLICY)}.to raise_error(Elasticsearch::Transport::Transport::Errors::NotFound)
|
368
|
+
end
|
369
|
+
end
|
370
|
+
|
371
|
+
context 'with the default template' do
|
372
|
+
it 'should create the rollover alias' do
|
373
|
+
expect(@es.indices.exists_alias(name: expected_index)).to be_falsey
|
374
|
+
subject.register
|
375
|
+
sleep(1)
|
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")
|
378
|
+
end
|
379
|
+
|
380
|
+
it 'should write the ILM settings into the template' do
|
381
|
+
subject.register
|
382
|
+
sleep(1)
|
383
|
+
|
384
|
+
template = get_template(@es, "logstash")
|
385
|
+
expect(template).to have_index_pattern("logstash-*")
|
386
|
+
expect(get_template_settings(template)['index']['lifecycle']['name']).to eq("logstash-policy")
|
387
|
+
expect(get_template_settings(template)['index']['lifecycle']['rollover_alias']).to eq("logstash")
|
388
|
+
end
|
389
|
+
|
390
|
+
it_behaves_like 'an ILM enabled Logstash'
|
391
|
+
end
|
392
|
+
|
393
|
+
context 'with a set index and a custom index pattern' do
|
394
|
+
if ESHelper.es_version_satisfies?(">= 8.0")
|
395
|
+
let (:template) { "spec/fixtures/template-with-policy-es8x.json" }
|
396
|
+
elsif ESHelper.es_version_satisfies?(">= 7.0")
|
397
|
+
let (:template) { "spec/fixtures/template-with-policy-es7x.json" }
|
398
|
+
else
|
399
|
+
let (:template) { "spec/fixtures/template-with-policy-es6x.json" }
|
400
|
+
end
|
401
|
+
|
402
|
+
let (:settings) { super().merge("template" => template,
|
403
|
+
"index" => "overwrite-4")}
|
404
|
+
|
405
|
+
it 'should not overwrite the index patterns' do
|
406
|
+
subject.register
|
407
|
+
sleep(1)
|
408
|
+
|
409
|
+
template = get_template(@es, "logstash")
|
410
|
+
expect(template).to have_index_pattern("overwrite-*")
|
411
|
+
end
|
412
|
+
end
|
413
|
+
|
414
|
+
|
415
|
+
context 'with a custom template' do
|
416
|
+
let (:ilm_rollover_alias) { "logstash_the_cat_in_the_hat" }
|
417
|
+
let (:index) { ilm_rollover_alias }
|
418
|
+
let(:expected_index) { index }
|
419
|
+
let (:settings) { super().merge("ilm_policy" => ilm_policy_name,
|
420
|
+
"template" => template,
|
421
|
+
"ilm_rollover_alias" => ilm_rollover_alias)}
|
422
|
+
|
423
|
+
|
424
|
+
if ESHelper.es_version_satisfies?(">= 8.0")
|
425
|
+
let (:template) { "spec/fixtures/template-with-policy-es8x.json" }
|
426
|
+
elsif ESHelper.es_version_satisfies?(">= 7.0")
|
427
|
+
let (:template) { "spec/fixtures/template-with-policy-es7x.json" }
|
428
|
+
else
|
429
|
+
let (:template) { "spec/fixtures/template-with-policy-es6x.json" }
|
430
|
+
end
|
431
|
+
let (:ilm_enabled) { true }
|
432
|
+
let (:ilm_policy_name) { "logstash-policy-custom-policy" }
|
433
|
+
let (:policy) { small_max_doc_policy }
|
434
|
+
|
435
|
+
before :each do
|
436
|
+
put_policy(@es,ilm_policy_name, policy)
|
437
|
+
end
|
438
|
+
|
439
|
+
it_behaves_like 'an ILM enabled Logstash'
|
440
|
+
|
441
|
+
it 'should create the rollover alias' do
|
442
|
+
expect(@es.indices.exists_alias(name: ilm_rollover_alias)).to be_falsey
|
443
|
+
subject.register
|
444
|
+
sleep(1)
|
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")
|
447
|
+
end
|
448
|
+
|
449
|
+
context 'when the custom rollover alias already exists' do
|
450
|
+
it 'should ignore the already exists error' do
|
451
|
+
expect(@es.indices.exists_alias(name: ilm_rollover_alias)).to be_falsey
|
452
|
+
put_alias(@es, "#{ilm_rollover_alias}-#{todays_date}-000001", ilm_rollover_alias)
|
453
|
+
expect(@es.indices.exists_alias(name: ilm_rollover_alias)).to be_truthy
|
454
|
+
subject.register
|
455
|
+
sleep(1)
|
456
|
+
expect(@es.get_alias(name: ilm_rollover_alias)).to include("#{ilm_rollover_alias}-#{todays_date}-000001")
|
457
|
+
end
|
458
|
+
|
459
|
+
end
|
460
|
+
|
461
|
+
it 'should write the ILM settings into the template' do
|
462
|
+
subject.register
|
463
|
+
sleep(1)
|
464
|
+
|
465
|
+
template = get_template(@es, ilm_rollover_alias)
|
466
|
+
expect(template).to have_index_pattern("#{ilm_rollover_alias}-*")
|
467
|
+
expect(get_template_settings(template)['index']['lifecycle']['name']).to eq(ilm_policy_name)
|
468
|
+
expect(get_template_settings(template)['index']['lifecycle']['rollover_alias']).to eq(ilm_rollover_alias)
|
469
|
+
end
|
470
|
+
|
471
|
+
context 'with a different template_name' do
|
472
|
+
let (:template_name) { "logstash_custom_template_name" }
|
473
|
+
let (:settings) { super().merge('template_name' => template_name)}
|
474
|
+
|
475
|
+
it_behaves_like 'an ILM enabled Logstash'
|
476
|
+
|
477
|
+
it 'should write the ILM settings into the template' do
|
478
|
+
subject.register
|
479
|
+
sleep(1)
|
480
|
+
template = get_template(@es, template_name)
|
481
|
+
expect(template).to have_index_pattern("#{ilm_rollover_alias}-*")
|
482
|
+
expect(get_template_settings(template)['index']['lifecycle']['name']).to eq(ilm_policy_name)
|
483
|
+
expect(get_template_settings(template)['index']['lifecycle']['rollover_alias']).to eq(ilm_rollover_alias)
|
484
|
+
end
|
485
|
+
end
|
486
|
+
|
487
|
+
end
|
488
|
+
end
|
489
|
+
|
490
|
+
context 'when ilm_enabled is set to "auto"' do
|
491
|
+
let (:ilm_enabled) { 'auto' }
|
492
|
+
|
493
|
+
if ESHelper.es_version_satisfies?(">=7.0")
|
494
|
+
context 'when Elasticsearch is version 7 or above' do
|
495
|
+
it_behaves_like 'an ILM enabled Logstash'
|
496
|
+
end
|
497
|
+
end
|
498
|
+
|
499
|
+
if ESHelper.es_version_satisfies?('< 7.0')
|
500
|
+
context 'when Elasticsearch is version 7 or below' do
|
501
|
+
it_behaves_like 'an ILM disabled Logstash'
|
502
|
+
end
|
503
|
+
end
|
504
|
+
end
|
505
|
+
|
506
|
+
context 'when ilm_enabled is the default' do
|
507
|
+
let (:settings) { super().tap{|x|x.delete('ilm_enabled')}}
|
508
|
+
|
509
|
+
if ESHelper.es_version_satisfies?(">=7.0")
|
510
|
+
context 'when Elasticsearch is version 7 or above' do
|
511
|
+
it_behaves_like 'an ILM enabled Logstash'
|
512
|
+
end
|
513
|
+
end
|
514
|
+
|
515
|
+
if ESHelper.es_version_satisfies?('< 7.0')
|
516
|
+
context 'when Elasticsearch is version 7 or below' do
|
517
|
+
it_behaves_like 'an ILM disabled Logstash'
|
518
|
+
end
|
519
|
+
end
|
520
|
+
end
|
521
|
+
|
522
|
+
context 'with ilm disabled' do
|
523
|
+
let (:settings) { super().merge('ilm_enabled' => false )}
|
524
|
+
|
525
|
+
it_behaves_like 'an ILM disabled Logstash'
|
526
|
+
end
|
527
|
+
|
528
|
+
context 'with ilm disabled using a string' do
|
529
|
+
let (:settings) { super().merge('ilm_enabled' => 'false' )}
|
530
|
+
|
531
|
+
it_behaves_like 'an ILM disabled Logstash'
|
532
|
+
end
|
533
|
+
|
534
|
+
end
|