diff --git a/libbeat/idxmgmt/idxmgmt.go b/libbeat/idxmgmt/idxmgmt.go index 489fb7d2a5be..4cd3fbe93e34 100644 --- a/libbeat/idxmgmt/idxmgmt.go +++ b/libbeat/idxmgmt/idxmgmt.go @@ -126,7 +126,7 @@ func MakeDefaultSupport(ilmSupport lifecycle.SupportFactory) SupportFactory { } // consider lifecycles enabled if the user has explicitly enabled them, - // or if no `enabled`` setting has been set by the user, thus reverting to a default of enabled. + // or if no `enabled` setting has been set by the user, thus reverting to a default of enabled. enabled := false if cfg.Lifecycle.DSL.Enabled() || cfg.Lifecycle.ILM.Enabled() { enabled = true diff --git a/libbeat/idxmgmt/lifecycle/client_handler.go b/libbeat/idxmgmt/lifecycle/client_handler.go index cbf83e710b1b..12d860cef8bc 100644 --- a/libbeat/idxmgmt/lifecycle/client_handler.go +++ b/libbeat/idxmgmt/lifecycle/client_handler.go @@ -82,7 +82,7 @@ func checkILMEnabled(enabled bool, c VersionCheckerClient) (bool, error) { ver := c.GetVersion() if ver.LessThan(esMinDefaultILMVersion) { - return false, errf(ErrESVersionNotSupported, "Elasticsearch %v does not support ILM", ver.String()) + return false, fmt.Errorf("%w: Elasticsearch %v does not support ILM", ErrESVersionNotSupported, ver.String()) } return true, nil } @@ -100,12 +100,12 @@ func createPolicy(cfg Config, info beat.Info, defaultPolicy mapstr.M) (Policy, e if path := cfg.PolicyFile; path != "" { contents, err := os.ReadFile(path) if err != nil { - return Policy{}, fmt.Errorf("failed to read policy file '%v': %w", path, err) + return Policy{}, fmt.Errorf("failed to read policy file '%s': %w", path, err) } var body map[string]interface{} if err := json.Unmarshal(contents, &body); err != nil { - return Policy{}, fmt.Errorf("failed to decode policy file '%v': %w", path, err) + return Policy{}, fmt.Errorf("failed to decode policy file '%s': %w", path, err) } policy.Body = body diff --git a/libbeat/idxmgmt/lifecycle/config.go b/libbeat/idxmgmt/lifecycle/config.go index eb3b7ac062d8..e8f2e703de01 100644 --- a/libbeat/idxmgmt/lifecycle/config.go +++ b/libbeat/idxmgmt/lifecycle/config.go @@ -48,7 +48,7 @@ type LifecycleConfig struct { } // RawConfig half-unpacks the policy config, allowing us to tell if a user has explicitly -// enabled a given config value +// enabled a given config value type RawConfig struct { ILM *config.C `config:"setup.ilm"` DSL *config.C `config:"setup.dsl"` diff --git a/libbeat/idxmgmt/lifecycle/error.go b/libbeat/idxmgmt/lifecycle/error.go index 4f819bf8d066..6568b909bbbf 100644 --- a/libbeat/idxmgmt/lifecycle/error.go +++ b/libbeat/idxmgmt/lifecycle/error.go @@ -19,17 +19,8 @@ package lifecycle import ( "errors" - "fmt" ) -// Error indicates an error + reason describing the last error. -// The Reason() method returns a sentinal error value for comparison. -type Error struct { - reason error - cause error - message string -} - var ( ErrESVersionNotSupported = errors.New("ILM is not supported by the Elasticsearch version in use") ErrILMCheckRequestFailed = errors.New("request checking for ILM availability failed") @@ -38,38 +29,3 @@ var ( ErrRequestFailed = errors.New("request failed") ErrOpNotAvailable = errors.New("operation not available, no lifecycle manager is enabled") ) - -func errOf(reason error) error { - return &Error{reason: reason} -} - -func errf(reason error, msg string, vs ...interface{}) error { - return wrapErrf(nil, reason, msg, vs...) -} - -func wrapErrf(cause, reason error, msg string, vs ...interface{}) error { - return &Error{ - cause: cause, - reason: reason, - message: fmt.Sprintf(msg, vs...), - } -} - -// Cause returns the errors cause, if present. -func (e *Error) Cause() error { return e.cause } - -// Reason returns a sentinal error value define within the ilm package. -func (e *Error) Reason() error { return e.reason } - -// Error returns the formatted error string. -func (e *Error) Error() string { - msg := e.message - if e.message == "" { - msg = e.reason.Error() - } - - if e.cause != nil { - return fmt.Sprintf("%v: %+v", msg, e.cause) - } - return msg -} diff --git a/libbeat/idxmgmt/lifecycle/es_client_handler.go b/libbeat/idxmgmt/lifecycle/es_client_handler.go index 5126f4167be4..3d0acc84f401 100644 --- a/libbeat/idxmgmt/lifecycle/es_client_handler.go +++ b/libbeat/idxmgmt/lifecycle/es_client_handler.go @@ -94,7 +94,7 @@ func NewESClientHandler(c ESClient, info beat.Info, cfg RawConfig) (*ESClientHan if lifecycleCfg.Enabled { // these are-enabled checks should happen elsewhere, but check again here just in case policy, err = createPolicy(lifecycleCfg, info, defaultPolicy) if err != nil { - return nil, fmt.Errorf("error creating DSL policy: %w", err) + return nil, fmt.Errorf("error creating a lifecycle policy: %w", err) } } @@ -126,8 +126,8 @@ func (h *ESClientHandler) IsElasticsearch() bool { func (h *ESClientHandler) HasPolicy() (bool, error) { status, b, err := h.client.Request("GET", h.putPath, "", nil, nil) if err != nil && status != 404 { - return false, wrapErrf(err, ErrRequestFailed, - "failed to check for policy name '%v': (status=%v) %s", h.name, status, b) + return false, fmt.Errorf("%w: failed to check for policy name '%v': (status=%v) (err=%w) %s", + ErrRequestFailed, h.name, status, err, b) } return status == 200, nil } diff --git a/libbeat/idxmgmt/lifecycle/ilm_test.go b/libbeat/idxmgmt/lifecycle/ilm_test.go index 8d935a3f7309..24df5ae7bbe3 100644 --- a/libbeat/idxmgmt/lifecycle/ilm_test.go +++ b/libbeat/idxmgmt/lifecycle/ilm_test.go @@ -36,16 +36,7 @@ func TestDefaultSupport_Init(t *testing.T) { s := tmp.(*stdSupport) assert := assert.New(t) - assert.Equal(true, s.Enabled()) - }) - - t.Run("with custom alias config with fieldref", func(t *testing.T) { - tmp, err := DefaultSupport(nil, info, true) - require.NoError(t, err) - - s := tmp.(*stdSupport) - assert := assert.New(t) - assert.Equal(true, s.Enabled()) + assert.True(s.Enabled()) }) } diff --git a/libbeat/idxmgmt/lifecycle/noop_manager.go b/libbeat/idxmgmt/lifecycle/noop_manager.go index 6d83ea9a510b..6311d0dd2bbc 100644 --- a/libbeat/idxmgmt/lifecycle/noop_manager.go +++ b/libbeat/idxmgmt/lifecycle/noop_manager.go @@ -46,7 +46,7 @@ func (*noopSupport) Manager(_ ClientHandler) Manager { return (*noopManager)(nil func (*noopManager) CheckEnabled() (bool, error) { return false, nil } // EnsurePolicy no-op -func (*noopManager) EnsurePolicy(_ bool) (bool, error) { return false, errOf(ErrOpNotAvailable) } +func (*noopManager) EnsurePolicy(_ bool) (bool, error) { return false, ErrOpNotAvailable } // Policyname no-op func (*noopManager) PolicyName() string { return "" } diff --git a/libbeat/idxmgmt/std_test.go b/libbeat/idxmgmt/std_test.go index 697556b4cd1e..ecc42dc6ee96 100644 --- a/libbeat/idxmgmt/std_test.go +++ b/libbeat/idxmgmt/std_test.go @@ -268,7 +268,6 @@ func TestIndexManager_VerifySetup(t *testing.T) { require.NoError(t, err) manager := support.Manager(clientHandler, nil) ok, warn := manager.VerifySetup(setup.loadTmpl, setup.loadILM) - t.Logf("%s", warn) assert.Equal(t, setup.ok, ok) assert.Contains(t, warn, setup.warn) clientHandler.assertInvariants(t)