Skip to content
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

Allow specifying default metricsets #5675

Merged
merged 1 commit into from
Nov 26, 2017

Conversation

andrewkroh
Copy link
Member

This is useful for modules containing a single metricset where you don't need the granularity of multiple metricsets. If metricsets isn't found in the config then the default MetricSets will be instantiated. If no defaults are defined for a module then an error is shown to the user (as was the case before this change when no metricsets were configured).

func init() {
	mb.Registry.MustAddMetricSet(moduleName, metricsetName, New,
		mb.DefaultMetricSet(),
		mb.WithHostParser(parse.EmptyHostParser),
	)
}

@andrewkroh
Copy link
Member Author

andrewkroh commented Nov 21, 2017

This will be used by Auditbeat to simplify the configuration. It's part of the work for #5422.

This is useful for modules containing a single metricset where you don't need the granularity of multiple metricsets. If `metricsets` isn't found in the config then the default MetricSets will be instantiated. If no defaults are defined for a module then an error is shown to the user (as was the case before this change when no `metricsets` were configured).

```
func init() {
	mb.Registry.MustAddMetricSet(moduleName, metricsetName, New,
		mb.DefaultMetricSet(),
		mb.WithHostParser(parse.EmptyHostParser),
	)
}
```
@andrewkroh andrewkroh force-pushed the feature/mb/default-metricsets branch from aa0db29 to d910ced Compare November 21, 2017 22:23
@@ -94,7 +115,28 @@ func (r *Register) AddModule(name string, factory ModuleFactory) error {
// HostParser function for parsing the 'host' configuration data. An error is
// returned if any parameter is empty or nil or if a factory has already been
// registered under the name.
//
// Use MustAddMetricSet for new code.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does that mean we need to update all existing metricsets?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

UPDATE: Just read your comment again in the PR and does not seem to be the case.

@ruflin
Copy link
Contributor

ruflin commented Nov 22, 2017

@andrewkroh Does this need a review label?

@andrewkroh
Copy link
Member Author

@ruflin Yeah, I had forgotten to add it when I opened the PR.

@andrewkroh
Copy link
Member Author

The test failures on jenkins-windows are for filebeat and libbeat and appear to be unrelated.

Copy link
Contributor

@ruflin ruflin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

I assume if two metricsets are defined as default in a module, both are loaded?

// addMetricSet registers a new MetricSetFactory. An error is returned if any
// parameter is empty or nil or if a factory has already been registered under
// the name.
func (r *Register) addMetricSet(module, name string, factory MetricSetFactory, options ...MetricSetOption) error {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like that we now have options instead of the more specific hostParser 👍

@@ -146,20 +190,47 @@ func (r *Register) metricSetFactory(module, name string) (MetricSetFactory, Host
module = strings.ToLower(module)
name = strings.ToLower(name)

modules, exists := r.metricSets[module]
metricSets, exists := r.metricSets[module]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch

func (r *Register) MetricSets(module string) []string {
r.lock.RLock()
defer r.lock.RUnlock()

var metricsets []string

sets, ok := r.metricSets[module]
sets, ok := r.metricSets[strings.ToLower(module)]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we should add a test somewhere to make sure this is not missing in other parts of the code.

@ruflin ruflin merged commit 08a5f21 into elastic:master Nov 26, 2017
@andrewkroh
Copy link
Member Author

I assume if two metricsets are defined as default in a module, both are loaded?

That's correct, there can be more than one metricset marked as default.

@andrewkroh andrewkroh mentioned this pull request Dec 18, 2017
9 tasks
@andrewkroh andrewkroh deleted the feature/mb/default-metricsets branch January 17, 2018 16:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants