-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Refactor collectors to use config structs #2812
base: master
Are you sure you want to change the base?
Conversation
Add a new pattern to allow moving the flag handling out of the collector package and into a separate package. This allows collector package users to create their own config or flag handling. Signed-off-by: Ben Kochie <superq@gmail.com>
} | ||
err = c.compileIncludeFlags(flagsInclude, bugsInclude) | ||
err = c.compileIncludeFlags(c.config.CPU.FlagsInclude, c.config.CPU.BugsInclude) | ||
if err != nil { | ||
return nil, fmt.Errorf("fail to compile --collector.cpu.info.flags-include and --collector.cpu.info.bugs-include, the values of them must be regular expressions: %w", 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.
Global statement about error messages referencing flags, might not need to change this for this initial push but since these can come from any source we should change to a more generic name.
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.
Yeah, i couldn't come with an elegant solution for now. We can change it later 👍
Merging config changes to the working branch
…r into refactor_collectors
…r into refactor_collectors
…les." This reverts commit a372120.
(This is a continuation of the initial work done here.)
The PR refactors node exporter to decouple collectors' config from kingpin flags. This allows that
the exporter can be embedded in other libraries and run multiple instances of it by removing the global state
that avoids that. Example here.
The definition of config params has been moved to structs in a central config struct (
NodeCollectorConfig
incollector/config.go
) that gathers all config params for all the collectors. The registration of kingpin has been move toflags.go
where all the flags are parsed to populate the main collector config.Some of the logic to support deprecated old flags (i.e
UnitIncludeSet
) has been moved from global vars to part of the collectorsconfig struct. Extra refactors in
collector.go
were needed to remove the global state.Addionally, we could refactor (in a separated PR):
flags.go
and move them to be exportable.Related: grafana/alloy#548