Skip to content

Commit 8fe2078

Browse files
committed
Rename write alias to rollover alias for consistency with beats
1 parent 892c34a commit 8fe2078

File tree

5 files changed

+45
-48
lines changed

5 files changed

+45
-48
lines changed

lib/logstash/outputs/elasticsearch/common.rb

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -368,8 +368,9 @@ def dlq_enabled?
368368

369369
def setup_ilm
370370
return unless ilm_enabled?
371-
# As soon as the template is loaded, check for existence of write alias:
372-
maybe_create_write_alias
371+
logger.info("Using Index lifecycle management - this feature is currently in beta.")
372+
# As soon as the template is loaded, check for existence of rollover alias:
373+
maybe_create_rollover_alias
373374
maybe_create_ilm_policy
374375
end
375376

@@ -403,9 +404,9 @@ def verify_ilm
403404
end
404405

405406
def verify_ilm_config
406-
# Overwrite the index with the write alias.
407-
@logger.warn "Overwriting index name with rollover alias #{@ilm_write_alias}" if @index != LogStash::Outputs::ElasticSearch::CommonConfigs::DEFAULT_INDEX_NAME
408-
@index = @ilm_write_alias
407+
# Overwrite the index with the rollover alias.
408+
@logger.warn "Overwriting index name with rollover alias #{@ilm_rollover_alias}" if @index != LogStash::Outputs::ElasticSearch::CommonConfigs::DEFAULT_INDEX_NAME
409+
@index = @ilm_rollover_alias
409410
verify_ilm_policy unless ilm_policy_default?
410411
end
411412

@@ -427,18 +428,18 @@ def maybe_create_ilm_policy
427428
end
428429
end
429430

430-
def maybe_create_write_alias
431-
client.write_alias_put(write_alias_target, write_alias_payload) unless client.write_alias_exists?(ilm_write_alias)
431+
def maybe_create_rollover_alias
432+
client.rollover_alias_put(rollover_alias_target, rollover_alias_payload) unless client.rollover_alias_exists?(ilm_rollover_alias)
432433
end
433434

434-
def write_alias_target
435-
"<#{ilm_write_alias}-#{ilm_pattern}>"
435+
def rollover_alias_target
436+
"<#{ilm_rollover_alias}-#{ilm_pattern}>"
436437
end
437438

438-
def write_alias_payload
439+
def rollover_alias_payload
439440
{
440441
"aliases" => {
441-
ilm_write_alias =>{
442+
ilm_rollover_alias =>{
442443
"is_write_index" => true
443444
}
444445
}

lib/logstash/outputs/elasticsearch/common_configs.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -141,21 +141,21 @@ def self.included(mod)
141141

142142

143143
# -----
144-
# ILM configurations
144+
# ILM configurations (beta)
145145
# -----
146146
# Flag for enabling Index Lifecycle Management integration.
147147
mod.config :ilm_enabled, :validate => :boolean, :default => false
148148

149-
# Write alias used for indexing data. If write alias doesn't exist, Logstash will create it and map it to the relevant index
150-
mod.config :ilm_write_alias, :validate => :string, :default => 'logstash'
149+
# Rollover alias used for indexing data. If rollover alias doesn't exist, Logstash will create it and map it to the relevant index
150+
mod.config :ilm_rollover_alias, :validate => :string, :default => 'logstash'
151151

152152
# appends “{now/d}-000001” by default for new index creation, subsequent rollover indices will increment based on this pattern i.e. “000002”
153+
# {now/d} is date math, and will insert the appropriate value automatically.
153154
mod.config :ilm_pattern, :validate => :string, :default => '{now/d}-000001'
154155

155156
# ILM policy to use, if undefined the default policy will be used.
156157
mod.config :ilm_policy, :validate => :string, :default => 'logstash-policy'
157158

158-
159159
end
160160
end
161161
end end end

lib/logstash/outputs/elasticsearch/http_client.rb

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -354,28 +354,24 @@ def template_put(name, template)
354354

355355
# ILM methods
356356

357-
# check whether write alias already exists
358-
def write_alias_exists?(name)
357+
# check whether rollover alias already exists
358+
def rollover_alias_exists?(name)
359359
exists?(name)
360360
end
361361

362-
# Create a new write alias
363-
def write_alias_put(alias_name, alias_definition)
364-
logger.info("Creating write alias #{alias_name}")
362+
# Create a new rollover alias
363+
def rollover_alias_put(alias_name, alias_definition)
364+
logger.info("Creating rollover alias #{alias_name}")
365365
begin
366366
@pool.put(CGI::escape(alias_name), nil, LogStash::Json.dump(alias_definition))
367367
# If the rollover alias already exists, ignore the error that comes back from Elasticsearch
368368
#
369369
rescue ::LogStash::Outputs::ElasticSearch::HttpClient::Pool::BadResponseCodeError => e
370-
if e.response_code == 400 && e.response_body
371-
error_body = LogStash::Json.load(e.response_bod)
372-
if error_body['error'] && error_body['error']['root_cause'] &&
373-
error_body['error']['root_cause'][0] && error_body['error']['root_cause'][0]['type'] == 'resource_already_exists_exception'
374-
logger.info("Write Alias #{alias_name} already exists. Skipping")
370+
if e.response_code == 400
371+
logger.info("Rollover Alias #{alias_name} already exists. Skipping")
375372
return
376-
end
377373
end
378-
raise e
374+
raise e
379375
end
380376
end
381377

lib/logstash/outputs/elasticsearch/template_manager.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,16 @@ def self.install(client, template_name, template, template_overwrite)
2525
def self.add_ilm_settings_to_template(plugin, template)
2626
# Include ilm settings in template:
2727
plugin.logger.info("Overwriting template name and pattern as ILM is enabled.")
28-
template['template'] = "#{plugin.ilm_write_alias}-*"
28+
template['template'] = "#{plugin.ilm_rollover_alias}-*"
2929
if template['settings'] && (template['settings']['index.lifecycle.name'] || template['settings']['index.lifecycle.rollover_alias'])
3030
plugin.logger.info("Overwriting index lifecycle name and rollover alias as ILM is enabled.")
3131
end
32-
template['settings'].update({ 'index.lifecycle.name' => plugin.ilm_policy, 'index.lifecycle.rollover_alias' => plugin.ilm_write_alias})
32+
template['settings'].update({ 'index.lifecycle.name' => plugin.ilm_policy, 'index.lifecycle.rollover_alias' => plugin.ilm_rollover_alias})
3333
end
3434

3535
# TODO: Verify this is ok
3636
def self.template_name(plugin)
37-
plugin.ilm_enabled? ? plugin.ilm_write_alias : plugin.template_name
37+
plugin.ilm_enabled? ? plugin.ilm_rollover_alias : plugin.template_name
3838
end
3939

4040
def self.default_template_path(es_major_version)

spec/integration/outputs/ilm_spec.rb

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@
258258
context 'when using the default policy' do
259259
context 'with a custom pattern' do
260260
let (:settings) { super.merge("ilm_pattern" => "000001")}
261-
it 'should create a write alias' do
261+
it 'should create a rollover alias' do
262262
expect(@es.indices.exists_alias(index: "logstash")).to be_falsey
263263
subject.register
264264
sleep(1)
@@ -275,7 +275,7 @@
275275
expect{get_policy(@es, LogStash::Outputs::ElasticSearch::DEFAULT_POLICY)}.not_to raise_error
276276
end
277277

278-
it 'should create the default write alias' do
278+
it 'should create the default rollover alias' do
279279
expect(@es.indices.exists_alias(index: "logstash")).to be_falsey
280280
subject.register
281281
sleep(1)
@@ -376,7 +376,7 @@
376376
context 'with the default template' do
377377
let(:expected_index) { "logstash" }
378378

379-
it 'should create the write alias' do
379+
it 'should create the rollover alias' do
380380
expect(@es.indices.exists_alias(index: expected_index)).to be_falsey
381381
subject.register
382382
sleep(1)
@@ -396,13 +396,13 @@
396396
end
397397

398398
context 'with a custom template' do
399-
let (:ilm_write_alias) { "custom" }
400-
let (:index) { ilm_write_alias }
399+
let (:ilm_rollover_alias) { "custom" }
400+
let (:index) { ilm_rollover_alias }
401401
let(:expected_index) { index }
402402
let (:settings) { super.merge("ilm_policy" => ilm_policy_name,
403403
"template" => template,
404404
"template_name" => template_name,
405-
"ilm_write_alias" => ilm_write_alias)}
405+
"ilm_rollover_alias" => ilm_rollover_alias)}
406406
let (:template_name) { "custom" }
407407

408408
if ESHelper.es_version_satisfies?(">= 7.0")
@@ -418,32 +418,32 @@
418418
put_policy(@es,ilm_policy_name, policy)
419419
end
420420

421-
it 'should create the write alias' do
422-
expect(@es.indices.exists_alias(index: ilm_write_alias)).to be_falsey
421+
it 'should create the rollover alias' do
422+
expect(@es.indices.exists_alias(index: ilm_rollover_alias)).to be_falsey
423423
subject.register
424424
sleep(1)
425-
expect(@es.indices.exists_alias(index: ilm_write_alias)).to be_truthy
426-
expect(@es.get_alias(name: ilm_write_alias)).to include("#{ilm_write_alias}-#{todays_date}-000001")
425+
expect(@es.indices.exists_alias(index: ilm_rollover_alias)).to be_truthy
426+
expect(@es.get_alias(name: ilm_rollover_alias)).to include("#{ilm_rollover_alias}-#{todays_date}-000001")
427427
end
428428

429-
context 'when the custom write alias already exists' do
429+
context 'when the custom rollover alias already exists' do
430430
it 'should ignore the already exists error' do
431-
expect(@es.indices.exists_alias(index: ilm_write_alias)).to be_falsey
432-
put_alias(@es, "#{ilm_write_alias}-#{todays_date}-000001", ilm_write_alias)
433-
expect(@es.indices.exists_alias(index: ilm_write_alias)).to be_truthy
431+
expect(@es.indices.exists_alias(index: ilm_rollover_alias)).to be_falsey
432+
put_alias(@es, "#{ilm_rollover_alias}-#{todays_date}-000001", ilm_rollover_alias)
433+
expect(@es.indices.exists_alias(index: ilm_rollover_alias)).to be_truthy
434434
subject.register
435435
sleep(1)
436-
expect(@es.get_alias(name: ilm_write_alias)).to include("#{ilm_write_alias}-#{todays_date}-000001")
436+
expect(@es.get_alias(name: ilm_rollover_alias)).to include("#{ilm_rollover_alias}-#{todays_date}-000001")
437437
end
438438

439439
end
440440

441441
it 'should write the ILM settings into the template' do
442442
subject.register
443443
sleep(1)
444-
expect(@es.indices.get_template(name: template_name)[template_name]["index_patterns"]).to eq(["#{ilm_write_alias}-*"])
444+
expect(@es.indices.get_template(name: template_name)[template_name]["index_patterns"]).to eq(["#{ilm_rollover_alias}-*"])
445445
expect(@es.indices.get_template(name: template_name)[template_name]["settings"]['index']['lifecycle']['name']).to eq(ilm_policy_name)
446-
expect(@es.indices.get_template(name: template_name)[template_name]["settings"]['index']['lifecycle']['rollover_alias']).to eq(ilm_write_alias)
446+
expect(@es.indices.get_template(name: template_name)[template_name]["settings"]['index']['lifecycle']['rollover_alias']).to eq(ilm_rollover_alias)
447447
end
448448

449449
it_behaves_like 'an ILM enabled Logstash'
@@ -453,7 +453,7 @@
453453
context 'with ilm disabled' do
454454
let (:ilm_enabled) { false }
455455

456-
it 'should not create a write alias' do
456+
it 'should not create a rollover alias' do
457457
expect(@es.get_alias).to be_empty
458458
subject.register
459459
sleep(1)

0 commit comments

Comments
 (0)