From 87d76b18e93c3339de6e1bd73ff30b99d3c72d90 Mon Sep 17 00:00:00 2001 From: Karl Persson <23356117+kalleep@users.noreply.github.com> Date: Thu, 22 May 2025 16:22:06 +0200 Subject: [PATCH] update: export properties so that they can be read from yaml file (#2053) --- internal/collector/update/update.go | 30 ++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/internal/collector/update/update.go b/internal/collector/update/update.go index 63fd62c5..49077a70 100644 --- a/internal/collector/update/update.go +++ b/internal/collector/update/update.go @@ -39,14 +39,14 @@ import ( const Name = "update" type Config struct { - online bool `yaml:"online"` - scrapeInterval time.Duration `yaml:"scrape_interval"` + Online bool `yaml:"online"` + ScrapeInterval time.Duration `yaml:"scrape_interval"` } //nolint:gochecknoglobals var ConfigDefaults = Config{ - online: false, - scrapeInterval: 6 * time.Hour, + Online: false, + ScrapeInterval: 6 * time.Hour, } var ( @@ -92,29 +92,29 @@ func NewWithFlags(app *kingpin.Application) *Collector { app.Flag( "collector.updates.online", "Deprecated: Please use collector.update.online instead", - ).Default(strconv.FormatBool(ConfigDefaults.online)).BoolVar(&online) + ).Default(strconv.FormatBool(ConfigDefaults.Online)).BoolVar(&online) app.Flag( "collector.updates.scrape-interval", "Deprecated: Please use collector.update.scrape-interval instead", - ).Default(ConfigDefaults.scrapeInterval.String()).DurationVar(&scrapeInterval) + ).Default(ConfigDefaults.ScrapeInterval.String()).DurationVar(&scrapeInterval) app.Flag( "collector.update.online", "Whether to search for updates online.", - ).Default(strconv.FormatBool(ConfigDefaults.online)).BoolVar(&c.config.online) + ).Default(strconv.FormatBool(ConfigDefaults.Online)).BoolVar(&c.config.Online) app.Flag( "collector.update.scrape-interval", "Define the interval of scraping Windows Update information.", - ).Default(ConfigDefaults.scrapeInterval.String()).DurationVar(&c.config.scrapeInterval) + ).Default(ConfigDefaults.ScrapeInterval.String()).DurationVar(&c.config.ScrapeInterval) app.Action(func(*kingpin.ParseContext) error { // Use deprecated flags only if new ones weren't explicitly set if online { // If the new flag is set, ignore the old one - if !c.config.online { - c.config.online = online + if !c.config.Online { + c.config.Online = online } slog.Warn("Warning: --collector.updates.online is deprecated, use --collector.update.online instead.", @@ -122,10 +122,10 @@ func NewWithFlags(app *kingpin.Application) *Collector { ) } - if scrapeInterval != ConfigDefaults.scrapeInterval { + if scrapeInterval != ConfigDefaults.ScrapeInterval { // If the new flag is set, ignore the old one - if c.config.scrapeInterval != scrapeInterval { - c.config.scrapeInterval = scrapeInterval + if c.config.ScrapeInterval != scrapeInterval { + c.config.ScrapeInterval = scrapeInterval } slog.Warn("Warning: --collector.updates.scrape-interval is deprecated, use --collector.update.scrape-interval instead.", @@ -153,7 +153,7 @@ func (c *Collector) Build(logger *slog.Logger, _ *mi.Session) error { ctx, cancel := context.WithCancel(context.Background()) initErrCh := make(chan error, 1) - go c.scheduleUpdateStatus(ctx, logger, initErrCh, c.config.online) + go c.scheduleUpdateStatus(ctx, logger, initErrCh, c.config.Online) c.ctxCancelFn = cancel @@ -312,7 +312,7 @@ func (c *Collector) scheduleUpdateStatus(ctx context.Context, logger *slog.Logge c.mu.Unlock() select { - case <-time.After(c.config.scrapeInterval): + case <-time.After(c.config.ScrapeInterval): case <-ctx.Done(): return }