Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 15 additions & 7 deletions internal/component/prometheus/scrape/scrape.go
Original file line number Diff line number Diff line change
Expand Up @@ -464,16 +464,29 @@ func (c *Component) Update(args component.Arguments) error {
c.mut.Lock()
defer c.mut.Unlock()

// Always store the latest targets and schedule a reload, even if the rest
// of the update fails. This ensures the component scrapes the correct set
// of targets when running with a partially-updated config.
c.args.Targets = newArgs.Targets
defer func() {
select {
case c.reloadTargets <- struct{}{}:
default:
}
}()

// Some fields are not updateable at runtime - only allow them when Update()
// is called for the first time from New().
if !c.firstUpdateDone {
c.firstUpdateDone = true
} else {
if c.args.ScrapeNativeHistograms != newArgs.ScrapeNativeHistograms {
return fmt.Errorf("scrape_native_histograms cannot be updated at runtime")
level.Warn(c.opts.Logger).Log("msg", "scrape_native_histograms cannot be changed at runtime; the component will continue using the original setting until Alloy is restarted", "current", c.args.ScrapeNativeHistograms, "requested", newArgs.ScrapeNativeHistograms)
newArgs.ScrapeNativeHistograms = c.args.ScrapeNativeHistograms
}
if c.args.ExtraMetrics != newArgs.ExtraMetrics {
return fmt.Errorf("extra_metrics cannot be updated at runtime")
level.Warn(c.opts.Logger).Log("msg", "extra_metrics cannot be changed at runtime; the component will continue using the original setting until Alloy is restarted", "current", c.args.ExtraMetrics, "requested", newArgs.ExtraMetrics)
newArgs.ExtraMetrics = c.args.ExtraMetrics
}
}

Expand All @@ -493,11 +506,6 @@ func (c *Component) Update(args component.Arguments) error {
}
level.Debug(c.opts.Logger).Log("msg", "scrape config was updated")

select {
case c.reloadTargets <- struct{}{}:
default:
}

return nil
}

Expand Down
Loading
Loading