-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
[metricbeat] Change behavior of Registry.Modules() to make it more consistant. #12972
Conversation
@jsoriano I wonder if this works for lightweight modules? |
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. |
As secondary sources (as light modules) cannot register modules, I didn't modify
We should also check that |
Interesting. I just noticed that |
Also @jsoriano so, |
Light modules are only included in licensed metricbeat, on it modules are loaded from the |
@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 |
Okay, finally figured out how this works with light modules. |
Alright. Now we're properly grabbing modules from Secondary sources. I tested it with |
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.
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.
jenkins, test this |
Looks like there's an (unrelated) filebeat test that's still failing. |
metricbeat/mb/registry.go
Outdated
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")) |
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.
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)
.
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.
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.
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.
Not sure why I ended-up doing this, I was probably looking for something like logp.Err
😬
jenkins, test this |
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. |
Alright, took @jsoriano 's advice, since it trims down a few lines of code. |
ca85217
to
08d44a7
Compare
jenkins, test this |
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.
LGTM.
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 ininit()
. 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 themetricSet
dict. The idea of just augmenting the data fromr.modules
and de-duplicating the list was @andrewkroh 's, out of an abundance of caution.