Merge pull request #18569 from roidelapluie/roidelapluie/labelnames-limit
Some checks are pending
buf.build / lint and publish (push) Waiting to run
CI / Go tests (push) Waiting to run
CI / More Go tests (push) Waiting to run
CI / Go tests for Prometheus upgrades and downgrades (push) Waiting to run
CI / Go tests with previous Go version (push) Waiting to run
CI / UI tests (push) Waiting to run
CI / Go tests on Windows (push) Waiting to run
CI / Mixins tests (push) Waiting to run
CI / Compliance testing (push) Waiting to run
CI / Build Prometheus for common architectures (push) Waiting to run
CI / Build Prometheus for all architectures (push) Waiting to run
CI / Report status of build Prometheus for all architectures (push) Blocked by required conditions
CI / Check generated parser (push) Waiting to run
CI / golangci-lint (push) Waiting to run
CI / fuzzing (push) Waiting to run
CI / codeql (push) Waiting to run
CI / Publish main branch artifacts (push) Blocked by required conditions
CI / Publish release artefacts (push) Blocked by required conditions
CI / Publish UI on npm Registry (push) Blocked by required conditions
govulncheck / Run govulncheck (push) Waiting to run
Scorecards supply-chain security / Scorecards analysis (push) Waiting to run

tsdb: apply LabelNames limit from LabelHints in blockBaseQuerier
This commit is contained in:
Julien 2026-04-23 12:28:19 +02:00 committed by GitHub
commit 3b9caf6564
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 45 additions and 2 deletions

View file

@ -81,9 +81,17 @@ func (q *blockBaseQuerier) LabelValues(ctx context.Context, name string, hints *
return res, nil, err
}
func (q *blockBaseQuerier) LabelNames(ctx context.Context, _ *storage.LabelHints, matchers ...*labels.Matcher) ([]string, annotations.Annotations, error) {
func (q *blockBaseQuerier) LabelNames(ctx context.Context, hints *storage.LabelHints, matchers ...*labels.Matcher) ([]string, annotations.Annotations, error) {
res, err := q.index.LabelNames(ctx, matchers...)
return res, nil, err
if err != nil {
return nil, nil, err
}
if hints != nil && hints.Limit > 0 && len(res) > hints.Limit {
res = res[:hints.Limit]
}
return res, nil, nil
}
func (q *blockBaseQuerier) Close() error {

View file

@ -418,6 +418,41 @@ func TestBlockQuerier(t *testing.T) {
}
}
func TestBlockBaseQuerier_LabelNamesLimit(t *testing.T) {
ix := newMockIndex()
ls := labels.FromStrings("aaa", "1", "bbb", "2", "ccc", "3")
require.NoError(t, ix.AddSeries(1, ls))
ls.Range(func(lbl labels.Label) {
require.NoError(t, ix.WritePostings(lbl.Name, lbl.Value, index.NewListPostings([]storage.SeriesRef{1})))
})
q := &blockBaseQuerier{index: ix, chunks: mockChunkReader(nil), tombstones: tombstones.NewMemTombstones()}
t.Run("no limit", func(t *testing.T) {
names, _, err := q.LabelNames(context.Background(), nil)
require.NoError(t, err)
require.Equal(t, []string{"aaa", "bbb", "ccc"}, names)
})
t.Run("limit applied", func(t *testing.T) {
names, _, err := q.LabelNames(context.Background(), &storage.LabelHints{Limit: 2})
require.NoError(t, err)
require.Equal(t, []string{"aaa", "bbb"}, names)
})
t.Run("limit larger than result", func(t *testing.T) {
names, _, err := q.LabelNames(context.Background(), &storage.LabelHints{Limit: 10})
require.NoError(t, err)
require.Equal(t, []string{"aaa", "bbb", "ccc"}, names)
})
t.Run("zero limit means no limit", func(t *testing.T) {
names, _, err := q.LabelNames(context.Background(), &storage.LabelHints{Limit: 0})
require.NoError(t, err)
require.Equal(t, []string{"aaa", "bbb", "ccc"}, names)
})
}
func TestBlockQuerier_AgainstHeadWithOpenChunks(t *testing.T) {
for _, c := range []blockQuerierTestCase{
{