MCPcopy
hub / github.com/prometheus/prometheus / TestBlockBaseQuerierSearchLabelValues

Function TestBlockBaseQuerierSearchLabelValues

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

Source from the content-addressed store, hash-verified

4252}
4253
4254func TestBlockBaseQuerierSearchLabelValues(t *testing.T) {
4255 ctx := t.Context()
4256 q := newBlockBaseQuerierForSearch(t,
4257 labels.FromStrings("env", "prod"),
4258 labels.FromStrings("env", "dev"),
4259 labels.FromStrings("env", "staging"),
4260 )
4261
4262 t.Run("no filter returns all values", func(t *testing.T) {
4263 rs := q.SearchLabelValues(ctx, "env", nil)
4264 got := collectSearchResultSet(t, rs)
4265 gotValues := make([]string, len(got))
4266 for i, r := range got {
4267 gotValues[i] = r.Value
4268 require.Equal(t, 1.0, r.Score)
4269 }
4270 slices.Sort(gotValues)
4271 require.Equal(t, []string{"dev", "prod", "staging"}, gotValues)
4272 })
4273
4274 t.Run("filter selects matching values", func(t *testing.T) {
4275 rs := q.SearchLabelValues(ctx, "env", &storage.SearchHints{Filter: prefixFilter{"p"}})
4276 got := collectSearchResultSet(t, rs)
4277 require.Len(t, got, 1)
4278 require.Equal(t, "prod", got[0].Value)
4279 })
4280
4281 t.Run("limit is applied after filtering", func(t *testing.T) {
4282 rs := q.SearchLabelValues(ctx, "env", &storage.SearchHints{
4283 Filter: prefixFilter{"p"},
4284 Limit: 1,
4285 })
4286 got := collectSearchResultSet(t, rs)
4287 require.Equal(t, []storage.SearchResult{{Value: "prod", Score: 1.0}}, got)
4288 })
4289
4290 t.Run("limit is applied", func(t *testing.T) {
4291 rs := q.SearchLabelValues(ctx, "env", &storage.SearchHints{Limit: 2})
4292 got := collectSearchResultSet(t, rs)
4293 require.Len(t, got, 2)
4294 })
4295
4296 t.Run("unknown label name returns empty", func(t *testing.T) {
4297 rs := q.SearchLabelValues(ctx, "unknown", nil)
4298 got := collectSearchResultSet(t, rs)
4299 require.Empty(t, got)
4300 })
4301
4302 t.Run("OrderByValueDesc returns values in reverse alphabetical order", func(t *testing.T) {
4303 rs := q.SearchLabelValues(ctx, "env", &storage.SearchHints{
4304 OrderBy: storage.OrderByValueDesc,
4305 })
4306 got := collectSearchResultSet(t, rs)
4307 gotValues := make([]string, len(got))
4308 for i, r := range got {
4309 gotValues[i] = r.Value
4310 require.Equal(t, 1.0, r.Score)
4311 }

Callers

nothing calls this directly

Calls 8

FromStringsFunction · 0.92
collectSearchResultSetFunction · 0.85
RunMethod · 0.65
SearchLabelValuesMethod · 0.65
LenMethod · 0.65
ContextMethod · 0.45
SortMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…