MCPcopy
hub / github.com/prometheus/prometheus / TestBlockBaseQuerier_LabelNamesLimit

Function TestBlockBaseQuerier_LabelNamesLimit

tsdb/querier_test.go:421–454  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

419}
420
421func TestBlockBaseQuerier_LabelNamesLimit(t *testing.T) {
422 ix := newMockIndex()
423 ls := labels.FromStrings("aaa", "1", "bbb", "2", "ccc", "3")
424 require.NoError(t, ix.AddSeries(1, ls))
425 ls.Range(func(lbl labels.Label) {
426 require.NoError(t, ix.WritePostings(lbl.Name, lbl.Value, index.NewListPostings([]storage.SeriesRef{1})))
427 })
428
429 q := &blockBaseQuerier{index: ix, chunks: mockChunkReader(nil), tombstones: tombstones.NewMemTombstones()}
430
431 t.Run("no limit", func(t *testing.T) {
432 names, _, err := q.LabelNames(context.Background(), nil)
433 require.NoError(t, err)
434 require.Equal(t, []string{"aaa", "bbb", "ccc"}, names)
435 })
436
437 t.Run("limit applied", func(t *testing.T) {
438 names, _, err := q.LabelNames(context.Background(), &storage.LabelHints{Limit: 2})
439 require.NoError(t, err)
440 require.Equal(t, []string{"aaa", "bbb"}, names)
441 })
442
443 t.Run("limit larger than result", func(t *testing.T) {
444 names, _, err := q.LabelNames(context.Background(), &storage.LabelHints{Limit: 10})
445 require.NoError(t, err)
446 require.Equal(t, []string{"aaa", "bbb", "ccc"}, names)
447 })
448
449 t.Run("zero limit means no limit", func(t *testing.T) {
450 names, _, err := q.LabelNames(context.Background(), &storage.LabelHints{Limit: 0})
451 require.NoError(t, err)
452 require.Equal(t, []string{"aaa", "bbb", "ccc"}, names)
453 })
454}
455
456func TestBlockQuerier_AgainstHeadWithOpenChunks(t *testing.T) {
457 for _, c := range []blockQuerierTestCase{

Callers

nothing calls this directly

Calls 10

LabelNamesMethod · 0.95
FromStringsFunction · 0.92
NewListPostingsFunction · 0.92
NewMemTombstonesFunction · 0.92
mockChunkReaderTypeAlias · 0.85
WritePostingsMethod · 0.80
newMockIndexFunction · 0.70
AddSeriesMethod · 0.65
RangeMethod · 0.65
RunMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…