MCPcopy
hub / github.com/prometheus/prometheus / TestSampledReadEndpoint

Function TestSampledReadEndpoint

storage/remote/read_handler_test.go:39–165  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

37)
38
39func TestSampledReadEndpoint(t *testing.T) {
40 store := promqltest.LoadedStorage(t, `
41 load 1m
42 test_metric1{foo="bar",baz="qux"} 1
43 `)
44 defer store.Close()
45
46 addNativeHistogramsToTestSuite(t, store, 1)
47
48 h := NewReadHandler(nil, nil, store, func() config.Config {
49 return config.Config{
50 GlobalConfig: config.GlobalConfig{
51 // We expect external labels to be added, with the source labels honored.
52 ExternalLabels: labels.FromStrings("b", "c", "baz", "a", "d", "e"),
53 },
54 }
55 }, 1e6, 1, 0)
56
57 // Encode the request.
58 matcher1, err := labels.NewMatcher(labels.MatchEqual, "__name__", "test_metric1")
59 require.NoError(t, err)
60
61 matcher2, err := labels.NewMatcher(labels.MatchEqual, "d", "e")
62 require.NoError(t, err)
63
64 matcher3, err := labels.NewMatcher(labels.MatchEqual, "__name__", "test_histogram_metric1")
65 require.NoError(t, err)
66
67 matcher4, err := labels.NewMatcher(labels.MatchEqual, "__name__", "test_nhcb_metric1")
68 require.NoError(t, err)
69
70 query1, err := ToQuery(0, 1, []*labels.Matcher{matcher1, matcher2}, &storage.SelectHints{Step: 0, Func: "avg"})
71 require.NoError(t, err)
72
73 query2, err := ToQuery(0, 1, []*labels.Matcher{matcher3, matcher2}, &storage.SelectHints{Step: 0, Func: "avg"})
74 require.NoError(t, err)
75
76 query3, err := ToQuery(0, 1, []*labels.Matcher{matcher4, matcher2}, &storage.SelectHints{Step: 0, Func: "avg"})
77 require.NoError(t, err)
78
79 req := &prompb.ReadRequest{Queries: []*prompb.Query{query1, query2, query3}}
80 data, err := proto.Marshal(req)
81 require.NoError(t, err)
82
83 compressed := snappy.Encode(nil, data)
84 request, err := http.NewRequest(http.MethodPost, "", bytes.NewBuffer(compressed))
85 require.NoError(t, err)
86
87 recorder := httptest.NewRecorder()
88 h.ServeHTTP(recorder, request)
89
90 require.Equal(t, 2, recorder.Code/100)
91
92 require.Equal(t, "application/x-protobuf", recorder.Result().Header.Get("Content-Type"))
93 require.Equal(t, "snappy", recorder.Result().Header.Get("Content-Encoding"))
94
95 // Decode the response.
96 compressed, err = io.ReadAll(recorder.Result().Body)

Callers

nothing calls this directly

Calls 15

LoadedStorageFunction · 0.92
FromStringsFunction · 0.92
NewMatcherFunction · 0.92
FromFloatHistogramFunction · 0.92
NewReadHandlerFunction · 0.85
ToQueryFunction · 0.85
DecodeMethod · 0.80
CloseMethod · 0.65
EncodeMethod · 0.65
GetMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…