From 325fdf03f642e8cc6dcf9bd0437c2258f7175e9a Mon Sep 17 00:00:00 2001 From: alanprot Date: Wed, 16 Apr 2025 12:15:34 -0700 Subject: [PATCH] Create a noOpInterner in case string interning is disabled Signed-off-by: alanprot --- pkg/ingester/ingester.go | 2 +- pkg/util/strings.go | 11 ++++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/pkg/ingester/ingester.go b/pkg/ingester/ingester.go index d34fbb98649..4425055eef5 100644 --- a/pkg/ingester/ingester.go +++ b/pkg/ingester/ingester.go @@ -2386,7 +2386,7 @@ func (i *Ingester) createTSDB(userID string) (*userTSDB, error) { instanceLimitsFn: i.getInstanceLimits, instanceSeriesCount: &i.TSDBState.seriesCount, - interner: util.NewLruInterner(), + interner: util.NewLruInterner(i.cfg.LabelsStringInterningEnabled), labelsStringInterningEnabled: i.cfg.LabelsStringInterningEnabled, blockRetentionPeriod: i.cfg.BlocksStorageConfig.TSDB.Retention.Milliseconds(), diff --git a/pkg/util/strings.go b/pkg/util/strings.go index a61e622e101..4965dc52a5e 100644 --- a/pkg/util/strings.go +++ b/pkg/util/strings.go @@ -157,12 +157,21 @@ type Interner interface { // NewLruInterner returns a new Interner to be used to intern strings. // The interner will use a LRU cache to return the deduplicated strings -func NewLruInterner() Interner { +func NewLruInterner(enabled bool) Interner { + if !enabled { + return &noOpInterner{} + } return &pool{ lru: expirable.NewLRU[string, string](maxInternerLruCacheSize, nil, internerLruCacheTTL), } } +type noOpInterner struct{} + +func (n noOpInterner) Intern(s string) string { + return s +} + type pool struct { lru *expirable.LRU[string, string] }