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

[metricbeat] Change behavior of Registry.Modules() to make it more consistant. #12972

Merged

Conversation

fearful-symmetry
Copy link
Contributor

@fearful-symmetry fearful-symmetry commented Jul 18, 2019

This came out of both #12648 and a discussion between @andrewkroh and I.

The mb.Registry.Modules() function is currently a tad weird. It'll only report modules that have been explicitly registered in init(). Not all modules do this. However, by nature of how metricsets are initialized, all metricsets are stored in the registry.

This means that as it stands, you can use the registry to access all metricsets, but not all modules. This changes that, so Modules() returns a complete list, using the keys of the metricSet dict. The idea of just augmenting the data from r.modules and de-duplicating the list was @andrewkroh 's, out of an abundance of caution.

@fearful-symmetry fearful-symmetry added Metricbeat Metricbeat Team:Integrations Label for the Integrations team labels Jul 18, 2019
@fearful-symmetry fearful-symmetry requested review from a team July 18, 2019 18:50
@fearful-symmetry fearful-symmetry self-assigned this Jul 18, 2019
@exekias
Copy link
Contributor

exekias commented Jul 19, 2019

@jsoriano I wonder if this works for lightweight modules?

@exekias exekias added the review label Jul 19, 2019
@fearful-symmetry
Copy link
Contributor Author

So, the new cockroachdb module is in xpack, and the registry doesn't even know it exists. The lone metricset doesn't get registered at all, so this part of the code can't see it.

@jsoriano
Copy link
Member

As secondary sources (as light modules) cannot register modules, I didn't modify mb.Registry.Modules(). If we are listing now all modules (registered and non-registered ones), we should also list modules in the secondary source to keep consistency. I think all the needed pieces are there, we should add something like this:

if source := r.secondarySource; source != nil {
    sourceModules, err := source.Modules()
    .... check error and append modules ...
}

We should also check that mb.Registry.String() doesn't report duplicates now.

@fearful-symmetry
Copy link
Contributor Author

Interesting. I just noticed that MetricSets() will look for data in secondary modules, but Modules() won't.

@fearful-symmetry
Copy link
Contributor Author

Also @jsoriano so, MetricSets() is checking secondary sources, but it can't seem to see cockroachdb. Do you know how data makes its way into secondarySource ?

@jsoriano
Copy link
Member

jsoriano commented Jul 19, 2019

Also @jsoriano so, MetricSets() is checking secondary sources, but it can't seem to see cockroachdb. Do you know how data makes its way into secondarySource ?

Light modules are only included in licensed metricbeat, on it modules are loaded from the module directory under path.home. If you build and run from x-pack/metricbeat it should find it. You may need to add --strict.perms=false.

@fearful-symmetry
Copy link
Contributor Author

@jsoriano I mean, where in the source do light modules get registered? "normal" x-pack modules get registered just fine. I just need to make a skeleton program capable of listing all modules.

@jsoriano
Copy link
Member

@jsoriano I mean, where in the source do light modules get registered? "normal" x-pack modules get registered just fine. I just need to make a skeleton program capable of listing all modules.

Oh, light modules are not registered, they are "lazily" loaded when required. To list available modules in a secondary source you should call its Modules() method.

@fearful-symmetry
Copy link
Contributor Author

Okay, finally figured out how this works with light modules.

@fearful-symmetry
Copy link
Contributor Author

Alright. Now we're properly grabbing modules from Secondary sources. I tested it with SetSecondarySources() and it works.

Copy link
Member

@jsoriano jsoriano left a comment

Choose a reason for hiding this comment

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

It looks good to me, I have added some minor comments.
My main doubt is if we want to do this. I like it, but I am not sure if there was a reason in the past to don't do it.
I'd like to see more opinions about this before merging.

metricbeat/mb/registry.go Outdated Show resolved Hide resolved
metricbeat/mb/registry.go Outdated Show resolved Hide resolved
metricbeat/mb/registry.go Outdated Show resolved Hide resolved
@fearful-symmetry
Copy link
Contributor Author

jenkins, test this

@fearful-symmetry
Copy link
Contributor Author

Yah @jsoriano, as I mentioned in the initial PR, this is mostly a way to get #12648 to work, so we can use mage to get a list of all known modules & default metricsets.

@fearful-symmetry
Copy link
Contributor Author

Looks like there's an (unrelated) filebeat test that's still failing.

if source := r.secondarySource; source != nil {
sourceModules, err := source.Modules()
if err != nil {
logp.Error(errors.Wrap(err, "failed to get modules from secondary source"))
Copy link
Member

Choose a reason for hiding this comment

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

I'm pretty sure this isn't what you want. Error a field type that can be used with structured logging to optionally specify type information.

I think you want either logp.L().Error(errors.Wrap(...)) or logp.L().Errorw("Failure getting module list from secondary source", "error", err) or logp.L().Errorf("Kaboom! error: %v", err).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Bah, that code was all over registry.go so I just copied it. Thinking I should make a separate PR to fix it that can be backported.

Copy link
Member

Choose a reason for hiding this comment

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

Not sure why I ended-up doing this, I was probably looking for something like logp.Err 😬

@fearful-symmetry fearful-symmetry requested review from andrewkroh, jsoriano and a team July 23, 2019 14:11
metricbeat/mb/registry.go Outdated Show resolved Hide resolved
@fearful-symmetry
Copy link
Contributor Author

jenkins, test this

@fearful-symmetry
Copy link
Contributor Author

Alright, now we're checking for dupes in in secondary sources. Not sure how much of the checks are necessary, but the whole module registration thing seems open enough that it can't hurt to be careful.

@fearful-symmetry
Copy link
Contributor Author

Alright, took @jsoriano 's advice, since it trims down a few lines of code.

metricbeat/mb/registry.go Outdated Show resolved Hide resolved
@fearful-symmetry fearful-symmetry force-pushed the registry-modules-list-fix branch from ca85217 to 08d44a7 Compare July 25, 2019 18:35
@fearful-symmetry
Copy link
Contributor Author

jenkins, test this

Copy link
Member

@andrewkroh andrewkroh left a comment

Choose a reason for hiding this comment

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

LGTM.

@fearful-symmetry fearful-symmetry merged commit 04e8706 into elastic:master Jul 29, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Metricbeat Metricbeat review Team:Integrations Label for the Integrations team v7.4.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants