createChunkedResponseHandler creates a mock handler for chunked responses.
(t *testing.T, queries []*prompb.Query)
| 961 | |
| 962 | // createChunkedResponseHandler creates a mock handler for chunked responses. |
| 963 | func 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. |
| 1011 | func createSampledResponseHandler(t *testing.T, queries []*prompb.Query) http.HandlerFunc { |
nothing calls this directly
no test coverage detected
searching dependent graphs…