MCPcopy
hub / github.com/prometheus/prometheus / createChunkedResponseHandler

Function createChunkedResponseHandler

storage/remote/client_test.go:963–1008  ·  view source on GitHub ↗

createChunkedResponseHandler creates a mock handler for chunked responses.

(t *testing.T, queries []*prompb.Query)

Source from the content-addressed store, hash-verified

961
962// createChunkedResponseHandler creates a mock handler for chunked responses.
963func createChunkedResponseHandler(t *testing.T, queries []*prompb.Query) http.HandlerFunc {
964 return http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
965 w.Header().Set("Content-Type", "application/x-streamed-protobuf; proto=prometheus.ChunkedReadResponse")
966
967 flusher, ok := w.(http.Flusher)
968 require.True(t, ok)
969
970 cw := NewChunkedWriter(w, flusher)
971
972 // For each query, simulate multiple chunks
973 for queryIndex := range queries {
974 chunks := buildTestChunks(t) // Creates 3 chunks with 5 samples each
975 for chunkIndex, chunk := range chunks {
976 // Create unique labels for each series in each query
977 var labels []prompb.Label
978 if queryIndex == 0 {
979 labels = []prompb.Label{
980 {Name: "job", Value: "prometheus"},
981 {Name: "instance", Value: fmt.Sprintf("localhost:%d", 9090+chunkIndex)},
982 }
983 } else {
984 labels = []prompb.Label{
985 {Name: "job", Value: "node_exporter"},
986 {Name: "instance", Value: fmt.Sprintf("localhost:%d", 9100+chunkIndex)},
987 }
988 }
989
990 cSeries := prompb.ChunkedSeries{
991 Labels: labels,
992 Chunks: []prompb.Chunk{chunk},
993 }
994
995 readResp := prompb.ChunkedReadResponse{
996 ChunkedSeries: []*prompb.ChunkedSeries{&cSeries},
997 QueryIndex: int64(queryIndex),
998 }
999
1000 b, err := proto.Marshal(&readResp)
1001 require.NoError(t, err)
1002
1003 _, err = cw.Write(b)
1004 require.NoError(t, err)
1005 }
1006 }
1007 })
1008}
1009
1010// createSampledResponseHandler creates a mock handler for sampled responses.
1011func createSampledResponseHandler(t *testing.T, queries []*prompb.Query) http.HandlerFunc {

Callers

nothing calls this directly

Calls 6

WriteMethod · 0.95
NewChunkedWriterFunction · 0.85
buildTestChunksFunction · 0.85
HeaderMethod · 0.80
SetMethod · 0.65
MarshalMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…