update: export properties so that they can be read from yaml file (#2054)

This commit is contained in:
Karl Persson
2025-05-22 16:33:56 +02:00
committed by GitHub
parent 1e24d7b2c9
commit 93940569fa

View File

@@ -37,14 +37,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 (
@@ -85,12 +85,12 @@ func NewWithFlags(app *kingpin.Application) *Collector {
app.Flag(
"collector.updates.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.updates.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)
return c
}
@@ -109,7 +109,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
@@ -268,7 +268,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
}