Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,9 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha2...master[Check the HEAD d
- Fix panic due to unhandled DeletedFinalStateUnknown in k8s OnDelete {pull}23419[23419]
- Fix error loop with runaway CPU use when the Kafka output encounters some connection errors {pull}23484[23484]
- Allow configuring credential_profile_name and shared_credential_file when using role_arn. {pull}24174[24174]
- Fix issue discovering docker containers and metadata after reconnections {pull}24318[24318]
Comment thread
urso marked this conversation as resolved.
Outdated
- Fix ILM setup log reporting that a policy or an alias was created, even though the creation of any resource was disabled. {issue}24046[24046] {pull}24480[24480]
- Fix ILM alias not being created if `setup.ilm.check_exists: false` and `setup.ilm.overwrite: true` has been configured. {pull}24480[24480]

*Auditbeat*

Expand Down
25 changes: 24 additions & 1 deletion libbeat/idxmgmt/ilm/ilm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,27 @@ func TestDefaultSupport_Manager_EnsureAlias(t *testing.T) {
},
fail: ErrRequestFailed,
},
"overwrite non-existent": {
calls: []onCall{
onCreateAlias(alias).Return(nil),
},
fail: nil,
cfg: map[string]interface{}{"check_exists": false, "overwrite": true},
},
"try overwrite existing": {
calls: []onCall{
onCreateAlias(alias).Return(errOf(ErrAliasAlreadyExists)),
},
fail: nil, // we detect that that the alias exists, and call it a day.
cfg: map[string]interface{}{"check_exists": false, "overwrite": true},
},
"fail to overwrite": {
calls: []onCall{
onCreateAlias(alias).Return(errOf(ErrAliasCreateFailed)),
},
fail: ErrAliasCreateFailed,
cfg: map[string]interface{}{"check_exists": false, "overwrite": true},
},
}

for name, test := range cases {
Expand Down Expand Up @@ -283,12 +304,14 @@ func TestDefaultSupport_Manager_EnsurePolicy(t *testing.T) {
},
},
"policy already exists": {
create: false,
calls: []onCall{
onHasILMPolicy(testPolicy.Name).Return(true, nil),
},
},
"overwrite existing": {
"overwrite": {

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test was wrong. When overwrite is enabled we ignore checkExists and always attempt to create the resource. The mock as configured checks that: HasPolicy will not be called, ILMPolicy will be created and indicates success.

overwrite: true,
create: true,
calls: []onCall{
onCreateILMPolicy(testPolicy).Return(nil),
},
Expand Down
71 changes: 52 additions & 19 deletions libbeat/idxmgmt/ilm/std.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,42 +103,75 @@ func (m *stdManager) CheckEnabled() (bool, error) {
}

func (m *stdManager) EnsureAlias() error {
if !m.checkExists {
return nil
}
log := m.log
overwrite := m.Overwrite()

b, err := m.client.HasAlias(m.alias.Name)
if err != nil {
return err
var exists bool
if m.checkExists && !overwrite {
var err error
exists, err = m.client.HasAlias(m.alias.Name)
if err != nil {
return err
}
}
if b {

switch {
case exists && !overwrite:
log.Infof("Index Alias %v exists already", m.alias.Name)
return nil
}

// This always assume it's a date pattern by sourrounding it by <...>
return m.client.CreateAlias(m.alias)
case !exists || overwrite:
err := m.client.CreateAlias(m.alias)
if err != nil {
if ErrReason(err) != ErrAliasAlreadyExists {
log.Errorf("Index Alias %v setup failed: %v", m.alias.Name, err)
return err
}
log.Infof("Index Alias %v exists already", m.alias.Name)
return nil
}

log.Info("Index Alias %v successfully created", m.alias.Name)
return nil

default:
m.log.Infof("ILM index alias not created: exists=%v, overwrite=%v", exists, overwrite)
return nil
}
}

func (m *stdManager) EnsurePolicy(overwrite bool) (bool, error) {
log := m.log
overwrite = overwrite || m.Overwrite()

exists := true
var exists bool
if m.checkExists && !overwrite {
b, err := m.client.HasILMPolicy(m.policy.Name)
var err error
exists, err = m.client.HasILMPolicy(m.policy.Name)
if err != nil {
return false, err
}
exists = b
}

if !exists || overwrite {
return !exists, m.client.CreateILMPolicy(m.policy)
}
switch {
case exists && !overwrite:
log.Infof("ILM policy %v exists already", m.policy)
return false, nil

case !exists || overwrite:
err := m.client.CreateILMPolicy(m.policy)
if err != nil {
log.Errorf("ILM policy %v creation failed: %v", m.policy, err)
return false, err
}

log.Infof("do not generate ilm policy: exists=%v, overwrite=%v",
exists, overwrite)
return false, nil
log.Infof("ILM policy %v successfully created", m.policy)
return true, err

default:
log.Infof("ILM policy not created: exists=%v, overwrite=%v", exists, overwrite)
return false, nil
}
}

func (c *infoCache) Valid() bool {
Expand Down
12 changes: 3 additions & 9 deletions libbeat/idxmgmt/std.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,6 @@ func (m *indexManager) Setup(loadTemplate, loadILM LoadMode) error {
if err != nil {
return err
}
log.Info("ILM policy successfully loaded.")

// The template should be updated if a new policy is created.
if policyCreated && templateComponent.enabled {
Expand Down Expand Up @@ -299,14 +298,9 @@ func (m *indexManager) Setup(loadTemplate, loadILM LoadMode) error {
}

if ilmComponent.load {
// ensure alias is created after the template is created
if err := m.ilm.EnsureAlias(); err != nil {
if ilm.ErrReason(err) != ilm.ErrAliasAlreadyExists {
return err
}
log.Info("Write alias exists already")
} else {
log.Info("Write alias successfully generated.")
err := m.ilm.EnsureAlias()
if err != nil {
return err
}
}

Expand Down