8000 Reload all scrape pools concurrently by prymitive · Pull Request #16595 · prometheus/prometheus · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Reload all scrape pools concurrently #16595

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

Merged
merged 2 commits into from
Jun 9, 2025
Merged
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
58 changes: 38 additions & 20 deletions scrape/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
config_util "github.com/prometheus/common/config"
"github.com/prometheus/common/model"
"github.com/prometheus/common/promslog"
"go.uber.org/atomic"

"github.com/prometheus/prometheus/config"
"github.com/prometheus/prometheus/discovery/targetgroup"
Expand Down Expand Up @@ -284,29 +285,46 @@ func (m *Manager) ApplyConfig(cfg *config.Config) error {
}

// Cleanup and reload pool if the configuration has changed.
var failed bool
for name, sp := range m.scrapePools {
switch cfg, ok := m.scrapeConfigs[name]; {
case !ok:
sp.stop()
delete(m.scrapePools, name)
case !reflect.DeepEqual(sp.config, cfg):
err := sp.reload(cfg)
if err != nil {
m.logger.Error("error reloading scrape pool", "err", err, "scrape_pool", name)
failed = true
}
fallthrough
case ok:
if l, ok := m.scrapeFailureLoggers[cfg.ScrapeFailureLogFile]; ok {
sp.SetScrapeFailureLogger(l)
} else {
sp.logger.Error("No logger found. This is a bug in Prometheus that should be reported upstream.", "scrape_pool", name)
var (
failed atomic.Bool
wg sync.WaitGroup
toDelete sync.Map // Stores the list of names of pools to delete.
)
for poolName, pool := range m.scrapePools {
wg.Add(1)
cfg, ok := m.scrapeConfigs[poolName]
// Reload each scrape pool in a dedicated goroutine so we don't have to wait a long time
// if we have a lot of scrape pools to update.
go func(name string, sp *scrapePool, cfg *config.ScrapeConfig, ok bool) {
defer wg.Done()
switch {
case !ok:
sp.stop()
toDelete.Store(name, struct{}{})
case !reflect.DeepEqual(sp.config, cfg):
err := sp.reload(cfg)
if err != nil {
m.logger.Error("error reloading scrape pool", "err", err, "scrape_pool", name)
failed.Store(true)
}
fallthrough
case ok:
if l, ok := m.scrapeFailureLoggers[cfg.ScrapeFailureLogFile]; ok {
sp.SetScrapeFailureLogger(l)
} else {
sp.logger.Error("No logger found. This is a bug in Prometheus that should be reported upstream.", "scrape_pool", name)
}
}
}
}(poolName, pool, cfg, ok)
}
wg.Wait()

toDelete.Range(func(name, _ any) bool {
delete(m.scrapePools, name.(string))
return true
})

if failed {
if failed.Load() {
return errors.New("failed to apply the new configuration")
}
return nil
Expand Down
Loading
0