(b *testing.B)
| 165 | } |
| 166 | |
| 167 | func 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 | } |
nothing calls this directly
no test coverage detected
searching dependent graphs…