mirror of
https://github.com/prometheus/prometheus.git
synced 2025-03-05 20:59:13 -08:00
scraping: reset symbol table periodically
Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
This commit is contained in:
parent
4e748b9cd8
commit
5f50d974c9
|
@ -528,6 +528,7 @@ scrape_configs:
|
||||||
config: cfg1.ScrapeConfigs[0],
|
config: cfg1.ScrapeConfigs[0],
|
||||||
client: http.DefaultClient,
|
client: http.DefaultClient,
|
||||||
metrics: scrapeManager.metrics,
|
metrics: scrapeManager.metrics,
|
||||||
|
symbolTable: labels.NewSymbolTable(),
|
||||||
}
|
}
|
||||||
scrapeManager.scrapePools = map[string]*scrapePool{
|
scrapeManager.scrapePools = map[string]*scrapePool{
|
||||||
"job1": sp,
|
"job1": sp,
|
||||||
|
|
|
@ -74,6 +74,8 @@ type scrapePool struct {
|
||||||
loops map[uint64]loop
|
loops map[uint64]loop
|
||||||
|
|
||||||
symbolTable *labels.SymbolTable
|
symbolTable *labels.SymbolTable
|
||||||
|
lastSymbolTableCheck time.Time
|
||||||
|
initialSymbolTableLen int
|
||||||
|
|
||||||
targetMtx sync.Mutex
|
targetMtx sync.Mutex
|
||||||
// activeTargets and loops must always be synchronized to have the same
|
// activeTargets and loops must always be synchronized to have the same
|
||||||
|
@ -138,7 +140,8 @@ func newScrapePool(cfg *config.ScrapeConfig, app storage.Appendable, offsetSeed
|
||||||
client: client,
|
client: client,
|
||||||
activeTargets: map[uint64]*Target{},
|
activeTargets: map[uint64]*Target{},
|
||||||
loops: map[uint64]loop{},
|
loops: map[uint64]loop{},
|
||||||
symbolTable: labels.NewSymbolTable(), // TODO: clean this out from time to time.
|
symbolTable: labels.NewSymbolTable(),
|
||||||
|
lastSymbolTableCheck: time.Now(),
|
||||||
logger: logger,
|
logger: logger,
|
||||||
metrics: metrics,
|
metrics: metrics,
|
||||||
httpOpts: options.HTTPClientOptions,
|
httpOpts: options.HTTPClientOptions,
|
||||||
|
@ -352,6 +355,21 @@ func (sp *scrapePool) reload(cfg *config.ScrapeConfig) error {
|
||||||
sp.metrics.targetReloadIntervalLength.WithLabelValues(interval.String()).Observe(
|
sp.metrics.targetReloadIntervalLength.WithLabelValues(interval.String()).Observe(
|
||||||
time.Since(start).Seconds(),
|
time.Since(start).Seconds(),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Here we take steps to clear out the symbol table if it has grown a lot.
|
||||||
|
// After waiting some time for things to settle, we take the size of the symbol-table.
|
||||||
|
// If, after some more time, the table has grown to twice that size, we start a new one.
|
||||||
|
const minTimeToCleanSymbolTable = 5 * time.Minute
|
||||||
|
if time.Since(sp.lastSymbolTableCheck) > minTimeToCleanSymbolTable {
|
||||||
|
if sp.initialSymbolTableLen == 0 {
|
||||||
|
sp.initialSymbolTableLen = sp.symbolTable.Len()
|
||||||
|
} else if sp.symbolTable.Len() > 2*sp.initialSymbolTableLen {
|
||||||
|
sp.symbolTable = labels.NewSymbolTable()
|
||||||
|
sp.initialSymbolTableLen = 0
|
||||||
|
}
|
||||||
|
sp.lastSymbolTableCheck = time.Now()
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -279,6 +279,7 @@ func TestScrapePoolReload(t *testing.T) {
|
||||||
logger: nil,
|
logger: nil,
|
||||||
client: http.DefaultClient,
|
client: http.DefaultClient,
|
||||||
metrics: newTestScrapeMetrics(t),
|
metrics: newTestScrapeMetrics(t),
|
||||||
|
symbolTable: labels.NewSymbolTable(),
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reloading a scrape pool with a new scrape configuration must stop all scrape
|
// Reloading a scrape pool with a new scrape configuration must stop all scrape
|
||||||
|
@ -361,6 +362,7 @@ func TestScrapePoolReloadPreserveRelabeledIntervalTimeout(t *testing.T) {
|
||||||
logger: nil,
|
logger: nil,
|
||||||
client: http.DefaultClient,
|
client: http.DefaultClient,
|
||||||
metrics: newTestScrapeMetrics(t),
|
metrics: newTestScrapeMetrics(t),
|
||||||
|
symbolTable: labels.NewSymbolTable(),
|
||||||
}
|
}
|
||||||
|
|
||||||
err := sp.reload(reloadCfg)
|
err := sp.reload(reloadCfg)
|
||||||
|
@ -391,6 +393,7 @@ func TestScrapePoolTargetLimit(t *testing.T) {
|
||||||
logger: log.NewNopLogger(),
|
logger: log.NewNopLogger(),
|
||||||
client: http.DefaultClient,
|
client: http.DefaultClient,
|
||||||
metrics: newTestScrapeMetrics(t),
|
metrics: newTestScrapeMetrics(t),
|
||||||
|
symbolTable: labels.NewSymbolTable(),
|
||||||
}
|
}
|
||||||
|
|
||||||
tgs := []*targetgroup.Group{}
|
tgs := []*targetgroup.Group{}
|
||||||
|
@ -623,6 +626,7 @@ func TestScrapePoolScrapeLoopsStarted(t *testing.T) {
|
||||||
logger: nil,
|
logger: nil,
|
||||||
client: http.DefaultClient,
|
client: http.DefaultClient,
|
||||||
metrics: newTestScrapeMetrics(t),
|
metrics: newTestScrapeMetrics(t),
|
||||||
|
symbolTable: labels.NewSymbolTable(),
|
||||||
}
|
}
|
||||||
|
|
||||||
tgs := []*targetgroup.Group{
|
tgs := []*targetgroup.Group{
|
||||||
|
@ -660,7 +664,7 @@ func newBasicScrapeLoop(t testing.TB, ctx context.Context, scraper scraper, app
|
||||||
nopMutator,
|
nopMutator,
|
||||||
app,
|
app,
|
||||||
nil,
|
nil,
|
||||||
nil,
|
labels.NewSymbolTable(),
|
||||||
0,
|
0,
|
||||||
true,
|
true,
|
||||||
false,
|
false,
|
||||||
|
|
Loading…
Reference in a new issue