-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Adding query APIs for metricsets and modules from metricbeat registry #4102
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ import ( | |
"fmt" | ||
"sort" | ||
"strings" | ||
"sync" | ||
|
||
"github.com/elastic/beats/libbeat/logp" | ||
) | ||
|
@@ -46,6 +47,8 @@ type metricSetFactoryInfo struct { | |
// Register contains the factory functions for creating new Modules and new | ||
// MetricSets. | ||
type Register struct { | ||
//Lock to control concurrent read/writes | ||
sync.RWMutex | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think embedding the mutex is not a good choice here because the methods will be become part of This reminds me, can you add to the godoc for |
||
// A map of module name to ModuleFactory. | ||
modules map[string]ModuleFactory | ||
// A map of module name to nested map of MetricSet name to metricSetFactoryInfo. | ||
|
@@ -144,9 +147,42 @@ func (r *Register) metricSetFactory(module, name string) (MetricSetFactory, Host | |
return info.factory, info.hostParser, nil | ||
} | ||
|
||
//Modules returns the list of module names that are registered | ||
func (r *Register) Modules() []string { | ||
r.RLock() | ||
defer r.RUnlock() | ||
|
||
modules := []string{} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Change this to |
||
for module := range r.modules { | ||
modules = append(modules, module) | ||
} | ||
|
||
return modules | ||
} | ||
|
||
//MetricSets returns the list of metricsets registered for a given module | ||
func (r *Register) MetricSets(module string) []string { | ||
r.RLock() | ||
defer r.RUnlock() | ||
|
||
metricsets := []string{} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Declare this as |
||
|
||
sets, ok := r.metricSets[module] | ||
if ok { | ||
for name := range sets { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Once it reaches this point, it can allocate the slice with the |
||
metricsets = append(metricsets, name) | ||
} | ||
} | ||
|
||
return metricsets | ||
} | ||
|
||
// String return a string representation of the registered ModuleFactory's and | ||
// MetricSetFactory's. | ||
func (r Register) String() string { | ||
func (r *Register) String() string { | ||
r.RLock() | ||
defer r.RUnlock() | ||
|
||
var modules []string | ||
for module := range r.modules { | ||
modules = append(modules, module) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment needs a space after the
//
.