Skip to content

Commit 39d1541

Browse files
authored
Remove auto option from setup.ilm.enabled and set the default value to true (#28671)
1 parent 71204c2 commit 39d1541

14 files changed

Lines changed: 78 additions & 196 deletions

CHANGELOG.next.asciidoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha2...master[Check the HEAD d
2727
- Enable IMDSv2 support for `add_cloud_metadata` processor on AWS. {issue}22101[22101] {pull}28285[28285]
2828
- Update kubernetes.namespace from keyword to group field and add name, labels, annotations, uuid as its fields {pull}27917[27917]
2929
- Previously, RE2 and thus Golang had a bug where `(|a)*` matched more characters than `(|a)+`. To stay consistent with PCRE, the bug was fixed. Configurations that rely on the old, buggy behaviour has to be adjusted. See more about Golang bug: https://github.com/golang/go/issues/46123 {pull}27543[27543]
30+
- Remove `auto` from the available options of `setup.ilm.enabled` and set the default value to `true`. {pull}28671[28671]
3031

3132
*Auditbeat*
3233

libbeat/docs/shared-ilm.asciidoc

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ Example configuration:
2626

2727
["source","yaml",subs="attributes"]
2828
----
29-
setup.ilm.enabled: auto
29+
setup.ilm.enabled: true
3030
setup.ilm.rollover_alias: "{beatname_lc}"
3131
setup.ilm.pattern: "{now/d}-000001" <1>
3232
----
@@ -47,10 +47,7 @@ You can specify the following settings in the `setup.ilm` section of the
4747
==== `setup.ilm.enabled`
4848

4949
Enables or disables index lifecycle management on any new indices created by
50-
{beatname_uc}. Valid values are `true`, `false`, and `auto`. When `auto` (the
51-
default) is specified on version 7.0 and later, {beatname_uc} automatically uses
52-
index lifecycle management if the feature is enabled in {es} and has the
53-
required license; otherwise, {beatname_uc} creates daily indices.
50+
{beatname_uc}. Valid values are `true` and `false`.
5451

5552
[float]
5653
[[setup-ilm-rollover_alias-option]]

libbeat/idxmgmt/ilm/client_handler.go

Lines changed: 16 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import (
2828

2929
// ClientHandler defines the interface between a remote service and the Manager.
3030
type ClientHandler interface {
31-
CheckILMEnabled(Mode) (bool, error)
31+
CheckILMEnabled(bool) (bool, error)
3232

3333
HasAlias(name string) (bool, error)
3434
CreateAlias(alias Alias) error
@@ -92,40 +92,29 @@ func NewFileClientHandler(c FileClient) *FileClientHandler {
9292
}
9393

9494
// CheckILMEnabled indicates whether or not ILM is supported for the configured mode and ES instance.
95-
func (h *ESClientHandler) CheckILMEnabled(mode Mode) (bool, error) {
96-
if mode == ModeDisabled {
95+
func (h *ESClientHandler) CheckILMEnabled(enabled bool) (bool, error) {
96+
if !enabled {
9797
return false, nil
9898
}
9999

100-
avail, probe := checkILMVersion(mode, h.client.GetVersion())
101-
if !avail {
102-
if mode == ModeEnabled {
103-
ver := h.client.GetVersion()
104-
return false, errf(ErrESVersionNotSupported,
105-
"Elasticsearch %v does not support ILM", ver.String())
106-
}
107-
return false, nil
108-
}
109-
110-
if !probe {
111-
// version potentially supports ILM, but mode + version indicates that we
112-
// want to disable ILM support.
113-
return false, nil
100+
ver := h.client.GetVersion()
101+
if !checkILMVersion(h.client.GetVersion()) {
102+
return false, errf(ErrESVersionNotSupported, "Elasticsearch %v does not support ILM", ver.String())
114103
}
115104

116-
avail, enabled, err := h.checkILMSupport()
105+
avail, enabledILM, err := h.checkILMSupport()
117106
if err != nil {
118107
return false, err
119108
}
120109

121110
if !avail {
122-
if mode == ModeEnabled {
111+
if enabledILM {
123112
return false, errOf(ErrESVersionNotSupported)
124113
}
125114
return false, nil
126115
}
127116

128-
if !enabled && mode == ModeEnabled {
117+
if !enabledILM && enabled {
129118
return false, errOf(ErrESILMDisabled)
130119
}
131120
return enabled, nil
@@ -244,18 +233,14 @@ func (h *ESClientHandler) queryFeatures(to interface{}) (int, error) {
244233
}
245234

246235
// CheckILMEnabled indicates whether or not ILM is supported for the configured mode and client version.
247-
func (h *FileClientHandler) CheckILMEnabled(mode Mode) (bool, error) {
248-
if mode == ModeDisabled {
249-
return false, nil
250-
}
251-
avail, probe := checkILMVersion(mode, h.client.GetVersion())
252-
if avail {
253-
return probe, nil
254-
}
255-
if mode != ModeEnabled {
236+
func (h *FileClientHandler) CheckILMEnabled(enabled bool) (bool, error) {
237+
if !enabled {
256238
return false, nil
257239
}
258240
version := h.client.GetVersion()
241+
if checkILMVersion(version) {
242+
return enabled, nil
243+
}
259244
return false, errf(ErrESVersionNotSupported,
260245
"Elasticsearch %v does not support ILM", version.String())
261246
}
@@ -287,11 +272,6 @@ func (h *FileClientHandler) HasAlias(name string) (bool, error) {
287272
// avail: indicates whether version supports ILM
288273
// probe: in case version potentially supports ILM, check the combination of mode + version
289274
// to indicate whether or not ILM support should be enabled or disabled
290-
func checkILMVersion(mode Mode, ver common.Version) (avail, probe bool) {
291-
avail = !ver.LessThan(esMinILMVersion)
292-
if avail {
293-
probe = (mode == ModeEnabled) ||
294-
(mode == ModeAuto && !ver.LessThan(esMinDefaultILMVersion))
295-
}
296-
return avail, probe
275+
func checkILMVersion(ver common.Version) (avail bool) {
276+
return !ver.LessThan(esMinILMVersion)
297277
}

libbeat/idxmgmt/ilm/client_handler_integration_test.go

Lines changed: 13 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -48,21 +48,14 @@ const (
4848
func TestESClientHandler_CheckILMEnabled(t *testing.T) {
4949
t.Run("no ilm if disabled", func(t *testing.T) {
5050
h := newESClientHandler(t)
51-
b, err := h.CheckILMEnabled(ilm.ModeDisabled)
51+
b, err := h.CheckILMEnabled(false)
5252
assert.NoError(t, err)
5353
assert.False(t, b)
5454
})
5555

56-
t.Run("with ilm if auto", func(t *testing.T) {
57-
h := newESClientHandler(t)
58-
b, err := h.CheckILMEnabled(ilm.ModeAuto)
59-
assert.NoError(t, err)
60-
assert.True(t, b)
61-
})
62-
6356
t.Run("with ilm if enabled", func(t *testing.T) {
6457
h := newESClientHandler(t)
65-
b, err := h.CheckILMEnabled(ilm.ModeEnabled)
58+
b, err := h.CheckILMEnabled(true)
6659
assert.NoError(t, err)
6760
assert.True(t, b)
6861
})
@@ -268,38 +261,29 @@ func getEnv(name, def string) string {
268261

269262
func TestFileClientHandler_CheckILMEnabled(t *testing.T) {
270263
for name, test := range map[string]struct {
271-
m ilm.Mode
272-
version string
273-
enabled bool
274-
err bool
264+
enabled bool
265+
version string
266+
ilmEnabled bool
267+
err bool
275268
}{
276269
"ilm enabled": {
277-
m: ilm.ModeEnabled,
278-
enabled: true,
279-
},
280-
"ilm auto": {
281-
m: ilm.ModeAuto,
282-
enabled: true,
270+
enabled: true,
271+
ilmEnabled: true,
283272
},
284273
"ilm disabled": {
285-
m: ilm.ModeDisabled,
286-
enabled: false,
274+
enabled: false,
275+
ilmEnabled: false,
287276
},
288277
"ilm enabled, version too old": {
289-
m: ilm.ModeEnabled,
278+
enabled: true,
290279
version: "5.0.0",
291280
err: true,
292281
},
293-
"ilm auto, version too old": {
294-
m: ilm.ModeAuto,
295-
version: "5.0.0",
296-
enabled: false,
297-
},
298282
} {
299283
t.Run(name, func(t *testing.T) {
300284
h := ilm.NewFileClientHandler(newMockClient(test.version))
301-
b, err := h.CheckILMEnabled(test.m)
302-
assert.Equal(t, test.enabled, b)
285+
b, err := h.CheckILMEnabled(test.enabled)
286+
assert.Equal(t, test.ilmEnabled, b)
303287
if test.err {
304288
assert.Error(t, err)
305289
} else {

libbeat/idxmgmt/ilm/config.go

Lines changed: 3 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ package ilm
1919

2020
import (
2121
"fmt"
22-
"strconv"
23-
"strings"
2422

2523
"github.com/elastic/beats/v7/libbeat/beat"
2624
"github.com/elastic/beats/v7/libbeat/common"
@@ -29,7 +27,7 @@ import (
2927

3028
// Config is used for unpacking a common.Config.
3129
type Config struct {
32-
Mode Mode `config:"enabled"`
30+
Enabled bool `config:"enabled"`
3331
PolicyName fmtstr.EventFormatString `config:"policy_name"`
3432
PolicyFile string `config:"policy_file"`
3533
RolloverAlias fmtstr.EventFormatString `config:"rollover_alias"`
@@ -44,20 +42,6 @@ type Config struct {
4442
Overwrite bool `config:"overwrite"`
4543
}
4644

47-
//Mode is used for enumerating the ilm mode.
48-
type Mode uint8
49-
50-
const (
51-
//ModeAuto enum 'auto'
52-
ModeAuto Mode = iota
53-
54-
//ModeEnabled enum 'true'
55-
ModeEnabled
56-
57-
//ModeDisabled enum 'false'
58-
ModeDisabled
59-
)
60-
6145
const ilmDefaultPattern = "{now/d}-000001"
6246

6347
// DefaultPolicy defines the default policy to be used if no custom policy is
@@ -79,31 +63,9 @@ var DefaultPolicy = common.MapStr{
7963
},
8064
}
8165

82-
//Unpack creates enumeration value true, false or auto
83-
func (m *Mode) Unpack(in string) error {
84-
in = strings.ToLower(in)
85-
86-
if in == "auto" {
87-
*m = ModeAuto
88-
return nil
89-
}
90-
91-
b, err := strconv.ParseBool(in)
92-
if err != nil {
93-
return fmt.Errorf("ilm.enabled` mode '%v' is invalid (try auto, true, false)", in)
94-
}
95-
96-
if b {
97-
*m = ModeEnabled
98-
} else {
99-
*m = ModeDisabled
100-
}
101-
return nil
102-
}
103-
10466
//Validate verifies that expected config options are given and valid
10567
func (cfg *Config) Validate() error {
106-
if cfg.RolloverAlias.IsEmpty() && cfg.Mode != ModeDisabled {
68+
if cfg.RolloverAlias.IsEmpty() && cfg.Enabled {
10769
return fmt.Errorf("rollover_alias must be set when ILM is not disabled")
10870
}
10971
return nil
@@ -115,7 +77,7 @@ func defaultConfig(info beat.Info) Config {
11577
policyFmt := fmtstr.MustCompileEvent(info.Beat)
11678

11779
return Config{
118-
Mode: ModeAuto,
80+
Enabled: true,
11981
PolicyName: *policyFmt,
12082
RolloverAlias: *aliasFmt,
12183
Pattern: ilmDefaultPattern,

libbeat/idxmgmt/ilm/ilm.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ type SupportFactory func(*logp.Logger, beat.Info, *common.Config) (Supporter, er
3737
// write alias a manager instance must be generated.
3838
type Supporter interface {
3939
// Query settings
40-
Mode() Mode
40+
Enabled() bool
4141
Alias() Alias
4242
Policy() Policy
4343
Overwrite() bool
@@ -82,7 +82,7 @@ func DefaultSupport(log *logp.Logger, info beat.Info, config *common.Config) (Su
8282
}
8383
}
8484

85-
if cfg.Mode == ModeDisabled {
85+
if !cfg.Enabled {
8686
return NewNoopSupport(info, config)
8787
}
8888

@@ -137,7 +137,7 @@ func StdSupport(log *logp.Logger, info beat.Info, config *common.Config) (Suppor
137137
policy.Body = body
138138
}
139139

140-
return NewStdSupport(log, cfg.Mode, alias, policy, cfg.Overwrite, cfg.CheckExists), nil
140+
return NewStdSupport(log, cfg.Enabled, alias, policy, cfg.Overwrite, cfg.CheckExists), nil
141141
}
142142

143143
// NoopSupport configures a new noop ILM support implementation,

0 commit comments

Comments
 (0)