MCPcopy
hub / github.com/prometheus/prometheus / BenchmarkStreamReadEndpoint

Function BenchmarkStreamReadEndpoint

storage/remote/read_handler_test.go:167–228  ·  view source on GitHub ↗
(b *testing.B)

Source from the content-addressed store, hash-verified

165}
166
167func BenchmarkStreamReadEndpoint(b *testing.B) {
168 store := promqltest.LoadedStorage(b, `
169 load 1m
170 test_metric1{foo="bar1",baz="qux"} 0+100x119
171 test_metric1{foo="bar2",baz="qux"} 0+100x120
172 test_metric1{foo="bar3",baz="qux"} 0+100x240
173 `)
174
175 b.Cleanup(func() { store.Close() })
176
177 api := NewReadHandler(nil, nil, store, func() config.Config {
178 return config.Config{}
179 },
180 0, 1, 0,
181 )
182
183 matcher, err := labels.NewMatcher(labels.MatchEqual, "__name__", "test_metric1")
184 require.NoError(b, err)
185
186 query, err := ToQuery(0, 14400001, []*labels.Matcher{matcher}, &storage.SelectHints{
187 Step: 1,
188 Func: "sum",
189 Start: 0,
190 End: 14400001,
191 })
192 require.NoError(b, err)
193
194 req := &prompb.ReadRequest{
195 Queries: []*prompb.Query{query},
196 AcceptedResponseTypes: []prompb.ReadRequest_ResponseType{prompb.ReadRequest_STREAMED_XOR_CHUNKS},
197 }
198 data, err := proto.Marshal(req)
199 require.NoError(b, err)
200
201 b.ReportAllocs()
202
203 for b.Loop() {
204 compressed := snappy.Encode(nil, data)
205 request, err := http.NewRequest(http.MethodPost, "", bytes.NewBuffer(compressed))
206 require.NoError(b, err)
207
208 recorder := httptest.NewRecorder()
209 api.ServeHTTP(recorder, request)
210
211 require.Equal(b, 2, recorder.Code/100)
212
213 var results []*prompb.ChunkedReadResponse
214 stream := NewChunkedReader(recorder.Result().Body, config.DefaultChunkedReadLimit, nil)
215
216 for {
217 res := &prompb.ChunkedReadResponse{}
218 err := stream.NextProto(res)
219 if errors.Is(err, io.EOF) {
220 break
221 }
222 require.NoError(b, err)
223 results = append(results, res)
224 }

Callers

nothing calls this directly

Calls 12

NextProtoMethod · 0.95
LoadedStorageFunction · 0.92
NewMatcherFunction · 0.92
NewReadHandlerFunction · 0.85
ToQueryFunction · 0.85
NewChunkedReaderFunction · 0.85
CloseMethod · 0.65
EncodeMethod · 0.65
LenMethod · 0.65
MarshalMethod · 0.45
ServeHTTPMethod · 0.45
IsMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…