⚠ This page is served via a proxy. Original site: https://github.com
This service does not collect credentials or authentication data.
Skip to content
Merged
Show file tree
Hide file tree
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
23 changes: 23 additions & 0 deletions pkg/ingester/active_queried_series.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,15 @@ import (
"github.com/go-kit/log/level"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
"github.com/prometheus/prometheus/util/zeropool"

"github.com/cortexproject/cortex/pkg/util/services"
)

var (
queriedSeriesHashesPool zeropool.Pool[[]uint64]
)

// ActiveQueriedSeries tracks unique queried series using time-windowed HyperLogLog.
// It maintains multiple HyperLogLog sketches in a circular buffer, one per time window.
// It can track up to the maximum configured window duration and query for specific window durations.
Expand Down Expand Up @@ -439,6 +444,8 @@ func (m *ActiveQueriedSeriesService) processUpdates(ctx context.Context) {
}
// Process the update synchronously
update.activeQueriedSeries.UpdateSeriesBatch(update.hashes, update.now)
// Return the slice to the pool after processing
putQueriedSeriesHashesSlice(update.hashes)
}
}
}
Expand All @@ -463,5 +470,21 @@ func (m *ActiveQueriedSeriesService) UpdateSeriesBatch(activeQueriedSeries *Acti
// This is acceptable as we're using probabilistic data structures (HLL)
m.droppedUpdatesTotal.Inc()
level.Warn(m.logger).Log("msg", "active queried series update channel full, dropping batch", "batch_size", len(hashes), "user", userID)
// Return the slice to the pool since we're dropping the update
putQueriedSeriesHashesSlice(hashes)
}
}

func getQueriedSeriesHashesSlice() []uint64 {
if p := queriedSeriesHashesPool.Get(); p != nil {
return p
}

return make([]uint64, 0, 1024) // Pre-allocate with reasonable capacity
}

func putQueriedSeriesHashesSlice(p []uint64) {
if p != nil {
queriedSeriesHashesPool.Put(p[:0])
}
}
2 changes: 1 addition & 1 deletion pkg/ingester/ingester.go
Original file line number Diff line number Diff line change
Expand Up @@ -2616,7 +2616,7 @@ func (i *Ingester) queryStreamChunks(ctx context.Context, userID string, db *use
if db.activeQueriedSeries != nil {
sampled = db.activeQueriedSeries.SampleRequest()
if sampled {
queriedSeriesHashes = make([]uint64, 0, 1024) // Pre-allocate with reasonable capacity
queriedSeriesHashes = getQueriedSeriesHashesSlice()
}
}

Expand Down
Loading