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 <bjboreham@gmail.com>
This commit is contained in:
Bryan Boreham 2023-11-24 18:08:56 +00:00
parent 0403d098e1
commit abb3a62f04
2 changed files with 9 additions and 2 deletions

View file

@ -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(l labels.Labels) labels.Labels { return mutateReportSampleLabels(l, opts.target) },
func(ctx context.Context) storage.Appender { return app.Appender(ctx) }, func(ctx context.Context) storage.Appender { return app.Appender(ctx) },
cache, cache,
sp.symbolTable,
offsetSeed, offsetSeed,
opts.honorTimestamps, opts.honorTimestamps,
opts.trackTimestampsStaleness, opts.trackTimestampsStaleness,
@ -809,6 +810,7 @@ type scrapeLoop struct {
enableCTZeroIngestion bool enableCTZeroIngestion bool
appender func(ctx context.Context) storage.Appender appender func(ctx context.Context) storage.Appender
symbolTable *labels.SymbolTable
sampleMutator labelsMutator sampleMutator labelsMutator
reportSampleMutator labelsMutator reportSampleMutator labelsMutator
@ -1088,6 +1090,7 @@ func newScrapeLoop(ctx context.Context,
reportSampleMutator labelsMutator, reportSampleMutator labelsMutator,
appender func(ctx context.Context) storage.Appender, appender func(ctx context.Context) storage.Appender,
cache *scrapeCache, cache *scrapeCache,
symbolTable *labels.SymbolTable,
offsetSeed uint64, offsetSeed uint64,
honorTimestamps bool, honorTimestamps bool,
trackTimestampsStaleness bool, trackTimestampsStaleness bool,
@ -1133,6 +1136,7 @@ func newScrapeLoop(ctx context.Context,
buffers: buffers, buffers: buffers,
cache: cache, cache: cache,
appender: appender, appender: appender,
symbolTable: symbolTable,
sampleMutator: sampleMutator, sampleMutator: sampleMutator,
reportSampleMutator: reportSampleMutator, reportSampleMutator: reportSampleMutator,
stopped: make(chan struct{}), 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) { 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 { if err != nil {
level.Debug(sl.l).Log( level.Debug(sl.l).Log(
"msg", "Invalid content type on scrape, using prometheus parser as fallback.", "msg", "Invalid content type on scrape, using prometheus parser as fallback.",

View file

@ -660,6 +660,7 @@ func newBasicScrapeLoop(t testing.TB, ctx context.Context, scraper scraper, app
nopMutator, nopMutator,
app, app,
nil, nil,
nil,
0, 0,
true, true,
false, false,
@ -800,6 +801,7 @@ func TestScrapeLoopRun(t *testing.T) {
nopMutator, nopMutator,
app, app,
nil, nil,
nil,
0, 0,
true, true,
false, false,
@ -942,6 +944,7 @@ func TestScrapeLoopMetadata(t *testing.T) {
nopMutator, nopMutator,
func(ctx context.Context) storage.Appender { return nopAppender{} }, func(ctx context.Context) storage.Appender { return nopAppender{} },
cache, cache,
labels.NewSymbolTable(),
0, 0,
true, true,
false, false,
@ -1470,7 +1473,7 @@ func TestScrapeLoopAppendCacheEntryButErrNotFound(t *testing.T) {
fakeRef := storage.SeriesRef(1) fakeRef := storage.SeriesRef(1)
expValue := float64(1) expValue := float64(1)
metric := []byte(`metric{n="1"} 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) require.NoError(t, warning)
var lset labels.Labels var lset labels.Labels