Skip to content

Commit

Permalink
Move default index name creation to indexSupport
Browse files Browse the repository at this point in the history
  • Loading branch information
urso committed Jan 31, 2019
1 parent b7c0aa7 commit 5dbe4c1
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 17 deletions.
2 changes: 1 addition & 1 deletion libbeat/idxmgmt/idxmgmt.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ type Supporter interface {
// The defaultIndex string is interpreted as format string. It is used
// as default index if the configuration provided does not define an index or
// has no default fallback if all indices are guarded by conditionals.
BuildSelector(defaultIndex string, cfg *common.Config) (outputs.IndexSelector, error)
BuildSelector(cfg *common.Config) (outputs.IndexSelector, error)

// Manager creates a new manager that can be used to execute the required steps
// for initializing an index, ILM policies, and write aliases.
Expand Down
2 changes: 1 addition & 1 deletion libbeat/idxmgmt/idxmgmt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ func TestDefaultSupport_BuildSelector(t *testing.T) {
im, err := factory(nil, info, common.MustNewConfigFrom(test.imCfg))
require.NoError(t, err)

sel, err := im.BuildSelector("", common.MustNewConfigFrom(test.cfg))
sel, err := im.BuildSelector(common.MustNewConfigFrom(test.cfg))
require.NoError(t, err)

meta := test.meta
Expand Down
33 changes: 19 additions & 14 deletions libbeat/idxmgmt/std.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,12 @@ import (
)

type indexSupport struct {
log *logp.Logger
ilm ilm.Supporter
info beat.Info
migration bool
templateCfg template.TemplateConfig
log *logp.Logger
ilm ilm.Supporter
info beat.Info
migration bool
templateCfg template.TemplateConfig
defaultIndex string

st indexState
}
Expand Down Expand Up @@ -84,11 +85,12 @@ func newIndexSupport(
}

return &indexSupport{
log: log,
ilm: ilm,
info: info,
templateCfg: tmplCfg,
migration: migration,
log: log,
ilm: ilm,
info: info,
templateCfg: tmplCfg,
migration: migration,
defaultIndex: fmt.Sprintf("%v-%v-%%{+yyyy.MM.dd}", info.IndexPrefix, info.Version),
}, nil
}

Expand Down Expand Up @@ -132,7 +134,7 @@ func (s *indexSupport) Manager(
}
}

func (s *indexSupport) BuildSelector(defaultIndex string, cfg *common.Config) (outputs.IndexSelector, error) {
func (s *indexSupport) BuildSelector(cfg *common.Config) (outputs.IndexSelector, error) {
var err error
log := s.log

Expand All @@ -155,9 +157,6 @@ func (s *indexSupport) BuildSelector(defaultIndex string, cfg *common.Config) (o
return nil, err
}
}
if indexName == "" {
indexName = defaultIndex
}

var alias string
mode := s.ilm.Mode()
Expand All @@ -169,6 +168,12 @@ func (s *indexSupport) BuildSelector(defaultIndex string, cfg *common.Config) (o
indexName = alias
}

// no index name configuration found yet -> define default index name based on
// beat.Info provided to the indexSupport on during setup.
if indexName == "" {
indexName = s.defaultIndex
}

selCfg.SetString("index", -1, indexName)
buildSettings := outil.Settings{
Key: "index",
Expand Down
2 changes: 1 addition & 1 deletion libbeat/outputs/output_reg.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ type IndexManager interface {
// the outputs configuration.
// The defaultIndex is interpreted as format string and used as default fallback
// if no index is configured or all indices are guarded using conditionals.
BuildSelector(defaultIndex string, cfg *common.Config) (IndexSelector, error)
BuildSelector(cfg *common.Config) (IndexSelector, error)
}

// IndexSelector is used to find the index name an event shall be indexed to.
Expand Down

0 comments on commit 5dbe4c1

Please sign in to comment.