-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add baseline rf1 querier implementation (#13639)
Co-authored-by: Cyril Tovena <[email protected]>
- Loading branch information
1 parent
7ed63ea
commit 3a99b69
Showing
8 changed files
with
1,496 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
package querierrf1 | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"net/http" | ||
|
||
"github.com/grafana/loki/v3/pkg/loghttp" | ||
"github.com/grafana/loki/v3/pkg/logproto" | ||
"github.com/grafana/loki/v3/pkg/querier/queryrange" | ||
"github.com/grafana/loki/v3/pkg/querier/queryrange/queryrangebase" | ||
) | ||
|
||
type Handler struct { | ||
api *QuerierAPI | ||
} | ||
|
||
func NewQuerierHandler(api *QuerierAPI) *Handler { | ||
return &Handler{ | ||
api: api, | ||
} | ||
} | ||
|
||
func (h *Handler) Do(ctx context.Context, req queryrangebase.Request) (queryrangebase.Response, error) { | ||
|
||
switch concrete := req.(type) { | ||
case *queryrange.LokiRequest: | ||
res, err := h.api.RangeQueryHandler(ctx, concrete) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
params, err := queryrange.ParamsFromRequest(req) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return queryrange.ResultToResponse(res, params) | ||
case *queryrange.LokiInstantRequest: | ||
res, err := h.api.InstantQueryHandler(ctx, concrete) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
params, err := queryrange.ParamsFromRequest(req) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return queryrange.ResultToResponse(res, params) | ||
case *queryrange.LokiSeriesRequest: | ||
request := &logproto.SeriesRequest{ | ||
Start: concrete.StartTs, | ||
End: concrete.EndTs, | ||
Groups: concrete.Match, | ||
Shards: concrete.Shards, | ||
} | ||
result, statResult, err := h.api.SeriesHandler(ctx, request) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return &queryrange.LokiSeriesResponse{ | ||
Status: "success", | ||
Version: uint32(loghttp.VersionV1), | ||
Data: result.Series, | ||
Statistics: statResult, | ||
}, nil | ||
case *queryrange.LabelRequest: | ||
res, err := h.api.LabelHandler(ctx, &concrete.LabelRequest) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return &queryrange.LokiLabelNamesResponse{ | ||
Status: "success", | ||
Version: uint32(loghttp.VersionV1), | ||
Data: res.Values, | ||
}, nil | ||
case *logproto.IndexStatsRequest: | ||
request := loghttp.NewRangeQueryWithDefaults() | ||
request.Start = concrete.From.Time() | ||
request.End = concrete.Through.Time() | ||
request.Query = concrete.GetQuery() | ||
request.UpdateStep() | ||
|
||
result, err := h.api.IndexStatsHandler(ctx, request) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return &queryrange.IndexStatsResponse{Response: result}, nil | ||
case *logproto.ShardsRequest: | ||
request := loghttp.NewRangeQueryWithDefaults() | ||
request.Start = concrete.From.Time() | ||
request.End = concrete.Through.Time() | ||
request.Query = concrete.GetQuery() | ||
request.UpdateStep() | ||
result, err := h.api.IndexShardsHandler(ctx, request, concrete.TargetBytesPerShard) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return &queryrange.ShardsResponse{Response: result}, nil | ||
|
||
case *logproto.VolumeRequest: | ||
result, err := h.api.VolumeHandler(ctx, concrete) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return &queryrange.VolumeResponse{Response: result}, nil | ||
case *queryrange.DetectedFieldsRequest: | ||
result, err := h.api.DetectedFieldsHandler(ctx, &concrete.DetectedFieldsRequest) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return &queryrange.DetectedFieldsResponse{ | ||
Response: result, | ||
}, nil | ||
case *logproto.QueryPatternsRequest: | ||
result, err := h.api.PatternsHandler(ctx, concrete) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return &queryrange.QueryPatternsResponse{ | ||
Response: result, | ||
}, nil | ||
case *queryrange.DetectedLabelsRequest: | ||
result, err := h.api.DetectedLabelsHandler(ctx, &concrete.DetectedLabelsRequest) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return &queryrange.DetectedLabelsResponse{Response: result}, nil | ||
case *logproto.QuerySamplesRequest: | ||
result, err := h.api.SamplesHandler(ctx, concrete) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return &queryrange.QuerySamplesResponse{ | ||
Response: result, | ||
}, nil | ||
default: | ||
return nil, fmt.Errorf("unsupported query type %T", req) | ||
} | ||
} | ||
|
||
func NewQuerierHTTPHandler(h *Handler) http.Handler { | ||
return queryrange.NewSerializeHTTPHandler(h, queryrange.DefaultCodec) | ||
} |
Oops, something went wrong.