Skip to content

Commit

Permalink
Minor: Small fixes for add_kubernetes_metadata (#7466)
Browse files Browse the repository at this point in the history
* When we fail to build an indexer or matcher we should not add them to
the execution.

* Empty() predicates should be behind a mutex
  • Loading branch information
ph authored and exekias committed Jun 28, 2018
1 parent 7b4e4cb commit b4c0f69
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ https://github.com/elastic/beats/compare/v6.2.3...master[Check the HEAD diff]
- Allow index-pattern only setup when setup.dashboards.only_index=true. {pull}7285[7285]
- Fix duplicating dynamic_fields in template when overwriting the template. {pull}7352[7352]
- Fix a panic on the Dissect processor when we have data remaining after the last delimiter. {pull}7449[7449]
- When we fail to build a Kubernetes' indexer or matcher we produce a warning but we don't add them to the execution. {pull}7466[7466]

*Auditbeat*

Expand Down
5 changes: 4 additions & 1 deletion libbeat/processors/add_kubernetes_metadata/indexers.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ type Indexers struct {
// IndexerConstructor builds a new indexer from its settings
type IndexerConstructor func(config common.Config, metaGen kubernetes.MetaGenerator) (Indexer, error)

// NewIndexers builds indexers object
// NewIndexers builds indexers object
func NewIndexers(configs PluginConfig, metaGen kubernetes.MetaGenerator) *Indexers {
indexers := []Indexer{}
for _, pluginConfigs := range configs {
Expand All @@ -74,6 +74,7 @@ func NewIndexers(configs PluginConfig, metaGen kubernetes.MetaGenerator) *Indexe
indexer, err := indexFunc(pluginConfig, metaGen)
if err != nil {
logp.Warn("Unable to initialize indexing plugin %s due to error %v", name, err)
continue
}

indexers = append(indexers, indexer)
Expand Down Expand Up @@ -113,6 +114,8 @@ func (i *Indexers) GetMetadata(pod *kubernetes.Pod) []MetadataIndex {

// Empty returns true if indexers list is empty
func (i *Indexers) Empty() bool {
i.RLock()
defer i.RUnlock()
if len(i.indexers) == 0 {
return true
}
Expand Down
3 changes: 3 additions & 0 deletions libbeat/processors/add_kubernetes_metadata/matchers.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ func NewMatchers(configs PluginConfig) *Matchers {
matcher, err := matchFunc(pluginConfig)
if err != nil {
logp.Warn("Unable to initialize matcher plugin %s due to error %v", name, err)
continue
}

matchers = append(matchers, matcher)
Expand Down Expand Up @@ -89,6 +90,8 @@ func (m *Matchers) MetadataIndex(event common.MapStr) string {
}

func (m *Matchers) Empty() bool {
m.RLock()
defer m.RUnlock()
if len(m.matchers) == 0 {
return true
}
Expand Down

0 comments on commit b4c0f69

Please sign in to comment.