Skip to content

Commit

Permalink
feat: add range support to agg metric volume queries
Browse files Browse the repository at this point in the history
  • Loading branch information
trevorwhitney committed Oct 7, 2024
1 parent 0e97b99 commit b24af03
Showing 1 changed file with 36 additions and 22 deletions.
58 changes: 36 additions & 22 deletions pkg/querier/queryrange/roundtrip.go
Original file line number Diff line number Diff line change
Expand Up @@ -1207,15 +1207,33 @@ func aggMetricsVolumeHandler(
return nil, httpgrpc.Errorf(http.StatusBadRequest, "%s", err.Error())
}

lokiReq := &LokiInstantRequest{
Query: expr.String(),
Limit: 1000,
Direction: logproto.BACKWARD,
TimeTs: r.GetEnd().UTC(),
Path: "/loki/api/v1/query",
Plan: &plan.QueryPlan{
AST: expr,
},
var lokiReq base.Request
if r.GetStep() <= 0 {
lokiReq = &LokiInstantRequest{
Query: expr.String(),
Limit: 1000,
Direction: logproto.BACKWARD,
TimeTs: r.GetEnd().UTC(),
Path: "/loki/api/v1/query",
Plan: &plan.QueryPlan{
AST: expr,
},
CachingOptions: r.GetCachingOptions(),
}
} else {
lokiReq = &LokiRequest{
Query: expr.String(),
Limit: 1000,
Step: r.GetStep(),
StartTs: r.GetStart().UTC(),
EndTs: r.GetEnd().UTC(),
Direction: logproto.BACKWARD,
Path: "/loki/api/v1/query_range",
Plan: &plan.QueryPlan{
AST: expr,
},
CachingOptions: r.GetCachingOptions(),
}
}

resp, err := logHandler.Do(ctx, lokiReq)
Expand All @@ -1232,7 +1250,7 @@ func aggMetricsVolumeHandler(
sortableResult := make([]sortableSampleStream, 0, len(result))
resultType := loghttp.ResultTypeVector

// sort the response to match the index volume respsone
// sort the response to match the index volume respsone
for _, stream := range result {
if resultType == loghttp.ResultTypeVector && len(stream.Samples) > 1 {
resultType = loghttp.ResultTypeMatrix
Expand Down Expand Up @@ -1262,19 +1280,15 @@ func aggMetricsVolumeHandler(
})
}





return &LokiPromResponse{
Response: &base.PrometheusResponse{
Status: loghttp.QueryStatusSuccess,
Data: base.PrometheusData{
ResultType: resultType,
Result: respStreams,
},
Headers: re.Response.Headers,
},
Response: &base.PrometheusResponse{
Status: loghttp.QueryStatusSuccess,
Data: base.PrometheusData{
ResultType: resultType,
Result: respStreams,
},
Headers: re.Response.Headers,
},
Statistics: re.Statistics,
}, nil
}
Expand Down

0 comments on commit b24af03

Please sign in to comment.