Skip to content

Commit

Permalink
change error handling, clean up log messages
Browse files Browse the repository at this point in the history
  • Loading branch information
fearful-symmetry committed Oct 2, 2023
1 parent ffb85e1 commit 4bb819c
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 5 deletions.
2 changes: 2 additions & 0 deletions libbeat/idxmgmt/index_support.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,8 @@ func (m *indexManager) VerifySetup(loadTemplate, loadLifecycle LoadMode) (bool,
if !templateComponent.load {
warn += "Template loading not enabled.\n"
}
// remove last newline so we don't get weird formatting when this is printed to the console
warn = strings.TrimSuffix(warn, "\n")
return warn == "", warn
}

Expand Down
5 changes: 3 additions & 2 deletions libbeat/idxmgmt/lifecycle/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,9 @@ type LifecycleConfig struct {
// RawConfig half-unpacks the policy config, allowing us to tell if a user has explicitly
// enabled a given config value
type RawConfig struct {
ILM *config.C `config:"setup.ilm"`
DSL *config.C `config:"setup.dsl"`
ILM *config.C `config:"setup.ilm"`
DSL *config.C `config:"setup.dsl"`
TemplateName string `config:"setup.template.name"`
}

// DefaultILMPolicy defines the default policy to be used if no custom policy is
Expand Down
13 changes: 11 additions & 2 deletions libbeat/idxmgmt/lifecycle/es_client_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"net/http"

"github.com/elastic/beats/v7/libbeat/beat"
"github.com/elastic/elastic-agent-libs/logp"
"github.com/elastic/elastic-agent-libs/mapstr"
)

Expand All @@ -41,11 +42,11 @@ type ESClientHandler struct {
// NewESClientHandler initializes and returns an ESClientHandler
func NewESClientHandler(c ESClient, info beat.Info, cfg RawConfig) (*ESClientHandler, error) {
if !cfg.DSL.Enabled() && cfg.ILM.Enabled() && c.IsServerless() {
return nil, fmt.Errorf("ILM is enabled but %s is connected to a serverless instance; ILM isn't supported on Serverless Elasticsearch", info.Beat)
return nil, fmt.Errorf("ILM is enabled/configured but %s is connected to a serverless instance; ILM isn't supported on Serverless Elasticsearch. Configure DSL or set setup.ilm.enabled to false", info.Beat)
}

if !cfg.ILM.Enabled() && cfg.DSL.Enabled() && !c.IsServerless() {
return nil, fmt.Errorf("DSL is enabled but %s is connected to a stateful instance; DSL is only supported on Serverless Elasticsearch", info.Beat)
return nil, fmt.Errorf("DSL is enabled/configured but %s is connected to a stateful instance; DSL is only supported on Serverless Elasticsearch. Configure ILM or set setup.dsl.enabled to false", info.Beat)
}

if cfg.ILM.Enabled() && cfg.DSL.Enabled() {
Expand Down Expand Up @@ -79,6 +80,14 @@ func NewESClientHandler(c ESClient, info beat.Info, cfg RawConfig) (*ESClientHan
if name == "" && lifecycleCfg.Enabled {
return nil, errors.New("could not generate usable policy name from config. Check setup.*.policy_name fields")
}
// deal with conflicts between policy name and template name
// under serverless, it doesn't make sense to have a policy name that differs from the template name
// if the user has set both to different values, throw a warning, as overwrite operations will probably fail
if c.IsServerless() {
if cfg.TemplateName != "" && cfg.TemplateName != name {
logp.L().Warnf("policy name is %s but template name is %s; under serverless, non-default template and policy names should be the same. Updates & overwrites may not work.")
}
}

// set defaults
defaultPolicy := DefaultILMPolicy
Expand Down
2 changes: 1 addition & 1 deletion libbeat/template/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ func (l *ESLoader) Load(config TemplateConfig, info beat.Info, fields []byte, mi
}
if dataStreamExist {
l.log.Infof("Data stream with name %q already exists.", templateName)
// for serverless, we can update the lifetimes safely
// for serverless, we can update the lifecycle policy safely
// Note that updating the lifecycle will delete older documents
// if the policy requires it; i.e, changing the data_retention from 10d to 7d
// will delete the documents older than 7 days.
Expand Down

0 comments on commit 4bb819c

Please sign in to comment.