mirror of
https://github.com/prometheus/prometheus.git
synced 2026-05-28 04:02:21 -04:00
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
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:
commit
3b9caf6564
2 changed files with 45 additions and 2 deletions
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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{
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in a new issue