From abb3a62f04c4563f80db1fc8c0dd726ece62c1c0 Mon Sep 17 00:00:00 2001 From: Bryan Boreham Date: Fri, 24 Nov 2023 18:08:56 +0000 Subject: [PATCH] scraping: re-use symbol table for scrape loops One symbol table for all loops in the same scrape pool, i.e. from the same job. Signed-off-by: Bryan Boreham --- scrape/scrape.go | 6 +++++- scrape/scrape_test.go | 5 ++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/scrape/scrape.go b/scrape/scrape.go index 9b295a349c..072f5f47be 100644 --- a/scrape/scrape.go +++ b/scrape/scrape.go @@ -163,6 +163,7 @@ func newScrapePool(cfg *config.ScrapeConfig, app storage.Appendable, offsetSeed func(l labels.Labels) labels.Labels { return mutateReportSampleLabels(l, opts.target) }, func(ctx context.Context) storage.Appender { return app.Appender(ctx) }, cache, + sp.symbolTable, offsetSeed, opts.honorTimestamps, opts.trackTimestampsStaleness, @@ -809,6 +810,7 @@ type scrapeLoop struct { enableCTZeroIngestion bool appender func(ctx context.Context) storage.Appender + symbolTable *labels.SymbolTable sampleMutator labelsMutator reportSampleMutator labelsMutator @@ -1088,6 +1090,7 @@ func newScrapeLoop(ctx context.Context, reportSampleMutator labelsMutator, appender func(ctx context.Context) storage.Appender, cache *scrapeCache, + symbolTable *labels.SymbolTable, offsetSeed uint64, honorTimestamps bool, trackTimestampsStaleness bool, @@ -1133,6 +1136,7 @@ func newScrapeLoop(ctx context.Context, buffers: buffers, cache: cache, appender: appender, + symbolTable: symbolTable, sampleMutator: sampleMutator, reportSampleMutator: reportSampleMutator, stopped: make(chan struct{}), @@ -1431,7 +1435,7 @@ type appendErrors struct { } func (sl *scrapeLoop) append(app storage.Appender, b []byte, contentType string, ts time.Time) (total, added, seriesAdded int, err error) { - p, err := textparse.New(b, contentType, sl.scrapeClassicHistograms) + p, err := textparse.New(b, contentType, sl.scrapeClassicHistograms, sl.symbolTable) if err != nil { level.Debug(sl.l).Log( "msg", "Invalid content type on scrape, using prometheus parser as fallback.", diff --git a/scrape/scrape_test.go b/scrape/scrape_test.go index eefa7be66f..67f22f1491 100644 --- a/scrape/scrape_test.go +++ b/scrape/scrape_test.go @@ -660,6 +660,7 @@ func newBasicScrapeLoop(t testing.TB, ctx context.Context, scraper scraper, app nopMutator, app, nil, + nil, 0, true, false, @@ -800,6 +801,7 @@ func TestScrapeLoopRun(t *testing.T) { nopMutator, app, nil, + nil, 0, true, false, @@ -942,6 +944,7 @@ func TestScrapeLoopMetadata(t *testing.T) { nopMutator, func(ctx context.Context) storage.Appender { return nopAppender{} }, cache, + labels.NewSymbolTable(), 0, true, false, @@ -1470,7 +1473,7 @@ func TestScrapeLoopAppendCacheEntryButErrNotFound(t *testing.T) { fakeRef := storage.SeriesRef(1) expValue := float64(1) metric := []byte(`metric{n="1"} 1`) - p, warning := textparse.New(metric, "", false) + p, warning := textparse.New(metric, "", false, labels.NewSymbolTable()) require.NoError(t, warning) var lset labels.Labels