Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Streaming remote read #1735

Merged
merged 8 commits into from
Apr 29, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
addressed PR feedback
  • Loading branch information
ortuman committed Apr 28, 2022
commit bbca0c79ed7ae62fdbafb265ef814e6df8d6203a
59 changes: 34 additions & 25 deletions pkg/querier/remote_read.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,31 +128,7 @@ func remoteReadStreamedXORChunks(
w.Header().Set("Content-Type", "application/x-streamed-protobuf; proto=prometheus.ChunkedReadResponse")

for i, qr := range req.Queries {
if err := func() error {
from, to, matchers, err := client.FromQueryRequest(qr)
if err != nil {
return err
}

querier, err := q.ChunkQuerier(ctx, int64(from), int64(to))
if err != nil {
return err
}

params := &storage.SelectHints{
Start: int64(from),
End: int64(to),
}

return streamChunkedReadResponses(
prom_remote.NewChunkedWriter(w, f),
// The streaming API has to provide the series sorted.
querier.Select(true, params, matchers...),
i,
maxBytesInFrame,
)

}(); err != nil {
if err := processReadStreamedQueryRequest(ctx, i, qr, q, w, f, maxBytesInFrame); err != nil {
level.Error(logger).Log("msg", "error streaming remote read response", "err", err)
http.Error(w, err.Error(), http.StatusInternalServerError)
return
Expand All @@ -161,6 +137,39 @@ func remoteReadStreamedXORChunks(
w.WriteHeader(http.StatusOK)
}

func processReadStreamedQueryRequest(
ctx context.Context,
idx int,
queryReq *client.QueryRequest,
q storage.ChunkQueryable,
w http.ResponseWriter,
f http.Flusher,
maxBytesInFrame int,
) error {
from, to, matchers, err := client.FromQueryRequest(queryReq)
if err != nil {
return err
}

querier, err := q.ChunkQuerier(ctx, int64(from), int64(to))
if err != nil {
return err
}

params := &storage.SelectHints{
Start: int64(from),
End: int64(to),
}

return streamChunkedReadResponses(
prom_remote.NewChunkedWriter(w, f),
// The streaming API has to provide the series sorted.
querier.Select(true, params, matchers...),
idx,
maxBytesInFrame,
)
}

func seriesSetToQueryResponse(s storage.SeriesSet) (*client.QueryResponse, error) {
result := &client.QueryResponse{}

Expand Down