Skip to content

Commit

Permalink
[metricbeat] Change behavior of Registry.Modules() to make it more co…
Browse files Browse the repository at this point in the history
…nsistant. (#12972)

* change behavior of Registry.Modules()
  • Loading branch information
fearful-symmetry authored Jul 29, 2019
1 parent 298bba2 commit 04e8706
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions metricbeat/mb/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -300,9 +300,33 @@ func (r *Register) Modules() []string {
r.lock.RLock()
defer r.lock.RUnlock()

modules := make([]string, 0, len(r.modules))
var dups = map[string]bool{}

// For the sake of compatibility, grab modules the old way as well, right from the modules map
for module := range r.modules {
modules = append(modules, module)
dups[module] = true
}

// List also modules from secondary sources
if source := r.secondarySource; source != nil {
sourceModules, err := source.Modules()
if err != nil {
logp.L().Errorf("failed to get modules from secondary source: %s", err)
} else {
for _, module := range sourceModules {
dups[module] = true
}
}
}

// Grab a more comprehensive list from the metricset keys, then reduce and merge
for mod := range r.metricSets {
dups[mod] = true
}

modules := make([]string, 0, len(dups))
for mod := range dups {
modules = append(modules, mod)
}

return modules
Expand Down

0 comments on commit 04e8706

Please sign in to comment.