|
120 | 120 | res[index_written] += 1 |
121 | 121 | end |
122 | 122 | expect(indexes_written.count).to eq(3) |
123 | | - expect(indexes_written["#{ilm_write_alias}-000001"]).to eq(3) |
124 | | - expect(indexes_written["#{ilm_write_alias}-000002"]).to eq(3) |
125 | | - expect(indexes_written["#{ilm_write_alias}-000003"]).to eq(3) |
| 123 | + expect(indexes_written["#{expected_index}-000001"]).to eq(3) |
| 124 | + expect(indexes_written["#{expected_index}-000002"]).to eq(3) |
| 125 | + expect(indexes_written["#{expected_index}-000003"]).to eq(3) |
126 | 126 | end |
127 | 127 | end |
128 | 128 |
|
|
161 | 161 | res[index_written] += 1 |
162 | 162 | end |
163 | 163 | expect(indexes_written.count).to eq(1) |
164 | | - expect(indexes_written["#{ilm_write_alias}-000001"]).to eq(6) |
| 164 | + expect(indexes_written["#{expected_index}-000001"]).to eq(6) |
165 | 165 | end |
166 | 166 | end |
167 | 167 | end |
|
182 | 182 | DEFAULT_INTERVAL = '600s' |
183 | 183 |
|
184 | 184 | require "logstash/outputs/elasticsearch" |
185 | | - let (:ilm_write_alias) { "the_write_alias" } |
186 | | - let (:index) { ilm_write_alias } |
187 | 185 | let (:ilm_enabled) { true } |
188 | 186 |
|
189 | 187 | let (:settings) { |
190 | 188 | { |
191 | | - "index" => index, |
192 | 189 | "ilm_enabled" => ilm_enabled, |
193 | | - "ilm_write_alias" => ilm_write_alias, |
194 | | - "manage_template" => true, |
195 | | - "template_name" => ilm_write_alias, |
196 | | - "template_overwrite" => true, |
197 | 190 | "hosts" => "#{get_host_port()}" |
198 | 191 | } |
199 | 192 | } |
|
260 | 253 | context 'with ilm enabled' do |
261 | 254 | let (:ilm_enabled) { true } |
262 | 255 |
|
| 256 | + |
263 | 257 | context 'when using the default policy' do |
264 | 258 | it 'should install it if it is not present' do |
265 | 259 | expect{get_policy(@es, LogStash::Outputs::ElasticSearch::DEFAULT_POLICY)}.to raise_error(Elasticsearch::Transport::Transport::Errors::NotFound) |
266 | 260 | subject.register |
267 | 261 | sleep(1) |
268 | 262 | expect{get_policy(@es, LogStash::Outputs::ElasticSearch::DEFAULT_POLICY)}.not_to raise_error |
269 | 263 | end |
270 | | - end |
271 | 264 |
|
| 265 | + it 'should create the default write alias' do |
| 266 | + |
| 267 | + expect(@es.indices.exists_alias(index: "logstash")).to be_falsey |
| 268 | + subject.register |
| 269 | + sleep(1) |
| 270 | + expect(@es.indices.exists_alias(index: "logstash")).to be_truthy |
| 271 | + expect(@es.get_alias(name: "logstash")).to include("logstash-000001") |
| 272 | + end |
| 273 | + |
| 274 | + it 'should ingest into a single index' do |
| 275 | + subject.register |
| 276 | + |
| 277 | + subject.multi_receive([ |
| 278 | + LogStash::Event.new("message" => "sample message here"), |
| 279 | + LogStash::Event.new("somemessage" => { "message" => "sample nested message here" }), |
| 280 | + LogStash::Event.new("somevalue" => 100), |
| 281 | + ]) |
| 282 | + |
| 283 | + sleep(6) |
| 284 | + |
| 285 | + subject.multi_receive([ |
| 286 | + LogStash::Event.new("country" => "us"), |
| 287 | + LogStash::Event.new("country" => "at"), |
| 288 | + LogStash::Event.new("geoip" => { "location" => [ 0.0, 0.0 ] }) |
| 289 | + ]) |
| 290 | + |
| 291 | + @es.indices.refresh |
| 292 | + |
| 293 | + # Wait or fail until everything's indexed. |
| 294 | + Stud::try(20.times) do |
| 295 | + r = @es.search |
| 296 | + expect(r["hits"]["total"]).to eq(6) |
| 297 | + end |
| 298 | + indexes_written = @es.search['hits']['hits'].each_with_object(Hash.new(0)) do |x, res| |
| 299 | + index_written = x['_index'] |
| 300 | + res[index_written] += 1 |
| 301 | + end |
| 302 | + |
| 303 | + expect(indexes_written.count).to eq(1) |
| 304 | + expect(indexes_written["logstash-000001"]).to eq(6) |
| 305 | + end |
| 306 | + end |
272 | 307 |
|
273 | 308 | context 'when not using the default policy' do |
274 | 309 | let (:ilm_policy_name) {"new_one"} |
|
299 | 334 | end |
300 | 335 |
|
301 | 336 | context 'with the default template' do |
| 337 | + let(:expected_index) { "logstash" } |
302 | 338 |
|
303 | | - it 'should write the write alias' do |
304 | | - expect(@es.indices.exists_alias(index: ilm_write_alias)).to be_falsey |
| 339 | + it 'should create the write alias' do |
| 340 | + expect(@es.indices.exists_alias(index: expected_index)).to be_falsey |
305 | 341 | subject.register |
306 | 342 | sleep(1) |
307 | | - expect(@es.indices.exists_alias(index: ilm_write_alias)).to be_truthy |
| 343 | + expect(@es.indices.exists_alias(index: expected_index)).to be_truthy |
| 344 | + expect(@es.get_alias(name: expected_index)).to include("#{expected_index}-000001") |
| 345 | + end |
| 346 | + |
| 347 | + it 'should write the ILM settings into the template' do |
| 348 | + subject.register |
| 349 | + sleep(1) |
| 350 | + expect(@es.indices.get_template(name: "logstash")["logstash"]["index_patterns"]).to eq(["logstash-*"]) |
| 351 | + expect(@es.indices.get_template(name: "logstash")["logstash"]["settings"]['index']['lifecycle']['name']).to eq("logstash-policy") |
| 352 | + expect(@es.indices.get_template(name: "logstash")["logstash"]["settings"]['index']['lifecycle']['rollover_alias']).to eq("logstash") |
308 | 353 | end |
309 | 354 |
|
310 | 355 | it_behaves_like 'an ILM enabled Logstash' |
|
313 | 358 | context 'with a custom template' do |
314 | 359 | let (:ilm_write_alias) { "custom" } |
315 | 360 | let (:index) { ilm_write_alias } |
| 361 | + let(:expected_index) { index } |
| 362 | + let (:settings) { super.merge("ilm_policy" => ilm_policy_name, |
| 363 | + "template" => template, |
| 364 | + "template_name" => template_name, |
| 365 | + "ilm_write_alias" => ilm_write_alias)} |
316 | 366 | let (:template_name) { "custom" } |
| 367 | + |
317 | 368 | if ESHelper.es_version_satisfies?(">= 7.0") |
318 | 369 | let (:template) { "spec/fixtures/template-with-policy-es7x.json" } |
319 | 370 | else |
320 | 371 | let (:template) { "spec/fixtures/template-with-policy-es6x.json" } |
321 | 372 | end |
322 | 373 | let (:ilm_enabled) { true } |
323 | 374 | let (:ilm_policy_name) { "custom-policy" } |
324 | | - let (:settings) { super.merge("ilm_policy" => ilm_policy_name, "template" => template)} |
| 375 | + |
325 | 376 |
|
326 | 377 | before :each do |
327 | 378 | put_policy(@es,ilm_policy_name, policy) |
328 | 379 | end |
329 | | - it 'should write the write alias' do |
| 380 | + it 'should create the write alias' do |
330 | 381 | expect(@es.indices.exists_alias(index: ilm_write_alias)).to be_falsey |
331 | 382 | subject.register |
332 | 383 | sleep(1) |
333 | 384 | expect(@es.indices.exists_alias(index: ilm_write_alias)).to be_truthy |
| 385 | + expect(@es.get_alias(name: ilm_write_alias)).to include("#{ilm_write_alias}-000001") |
| 386 | + end |
| 387 | + |
| 388 | + it 'should write the ILM settings into the template' do |
| 389 | + subject.register |
| 390 | + sleep(1) |
| 391 | + expect(@es.indices.get_template(name: template_name)[template_name]["index_patterns"]).to eq(["#{ilm_write_alias}-*"]) |
| 392 | + expect(@es.indices.get_template(name: template_name)[template_name]["settings"]['index']['lifecycle']['name']).to eq(ilm_policy_name) |
| 393 | + expect(@es.indices.get_template(name: template_name)[template_name]["settings"]['index']['lifecycle']['rollover_alias']).to eq(ilm_write_alias) |
334 | 394 | end |
335 | 395 |
|
336 | 396 | it_behaves_like 'an ILM enabled Logstash' |
|
340 | 400 | context 'with ilm disabled' do |
341 | 401 | let (:ilm_enabled) { false } |
342 | 402 |
|
343 | | - it 'should not write the write alias' do |
344 | | - expect(@es.indices.exists_alias(index: ilm_write_alias)).to be_falsey |
| 403 | + it 'should not create a write alias' do |
| 404 | + expect(@es.get_alias).to be_empty |
345 | 405 | subject.register |
346 | 406 | sleep(1) |
347 | | - expect(@es.indices.exists_alias(index: ilm_write_alias)).to be_falsey |
| 407 | + expect(@es.get_alias).to be_empty |
348 | 408 | end |
349 | 409 |
|
350 | 410 | it 'should not install the default policy' do |
|
353 | 413 | expect{get_policy(@es, LogStash::Outputs::ElasticSearch::DEFAULT_POLICY)}.to raise_error(Elasticsearch::Transport::Transport::Errors::NotFound) |
354 | 414 | end |
355 | 415 |
|
| 416 | + it 'should write the ILM settings into the template' do |
| 417 | + subject.register |
| 418 | + sleep(1) |
| 419 | + expect(@es.indices.get_template(name: "logstash")["logstash"]["index_patterns"]).to eq(["logstash-*"]) |
| 420 | + expect(@es.indices.get_template(name: "logstash")["logstash"]["settings"]['index']['lifecycle']).to be_nil |
| 421 | + |
| 422 | + end |
| 423 | + |
| 424 | + |
356 | 425 | context 'with an existing policy that will roll over' do |
357 | 426 | let (:policy) { small_max_doc_policy } |
358 | 427 | let (:ilm_policy_name) { "3_docs"} |
|
387 | 456 | res[index_written] += 1 |
388 | 457 | end |
389 | 458 | expect(indexes_written.count).to eq(1) |
390 | | - expect(indexes_written["#{index}"]).to eq(6) |
| 459 | + expect(indexes_written.values.first).to eq(6) |
391 | 460 | end |
392 | 461 | end |
393 | 462 | end |
|
0 commit comments