mirror of
https://github.com/prometheus-community/windows_exporter
synced 2024-12-18 04:24:35 +00:00
fix: fail, if unknown collector is defined in enabled list (#1693)
This commit is contained in:
parent
332b0a8a1c
commit
92b7e445e1
@ -188,7 +188,11 @@ func run() int {
|
|||||||
}
|
}
|
||||||
|
|
||||||
enabledCollectorList := utils.ExpandEnabledCollectors(*enabledCollectors)
|
enabledCollectorList := utils.ExpandEnabledCollectors(*enabledCollectors)
|
||||||
collectors.Enable(enabledCollectorList)
|
if err := collectors.Enable(enabledCollectorList); err != nil {
|
||||||
|
logger.Error(err.Error())
|
||||||
|
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
// Initialize collectors before loading
|
// Initialize collectors before loading
|
||||||
if err = collectors.Build(logger); err != nil {
|
if err = collectors.Build(logger); err != nil {
|
||||||
|
@ -168,12 +168,20 @@ func (c *MetricCollectors) SetPerfCounterQuery(logger *slog.Logger) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Enable removes all collectors that not enabledCollectors.
|
// Enable removes all collectors that not enabledCollectors.
|
||||||
func (c *MetricCollectors) Enable(enabledCollectors []string) {
|
func (c *MetricCollectors) Enable(enabledCollectors []string) error {
|
||||||
|
for _, name := range enabledCollectors {
|
||||||
|
if _, ok := c.Collectors[name]; !ok {
|
||||||
|
return fmt.Errorf("unknown collector %s", name)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for name := range c.Collectors {
|
for name := range c.Collectors {
|
||||||
if !slices.Contains(enabledCollectors, name) {
|
if !slices.Contains(enabledCollectors, name) {
|
||||||
delete(c.Collectors, name)
|
delete(c.Collectors, name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Build To be called by the exporter for collector initialization.
|
// Build To be called by the exporter for collector initialization.
|
||||||
|
Loading…
Reference in New Issue
Block a user