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

feat(query-splitting): Query splitting api #13846

Draft
wants to merge 11 commits into
base: main
Choose a base branch
from
44 changes: 44 additions & 0 deletions pkg/loghttp/query_plan.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package loghttp

import (
"net/http"

"github.com/grafana/loki/v3/pkg/logproto"
"github.com/pkg/errors"
)

func ParseQueryPlanRequest(r *http.Request) (*logproto.QueryPlanRequest, error) {
req := &logproto.QueryPlanRequest{}

req.Query = query(r)
start, end, err := bounds(r)
if err != nil {
return nil, err
}

req.Start = start
req.End = end
dir, err := direction(r)
if err != nil {
return nil, err
}
req.Direction = dir
b, err := buckets(r)
if err != nil {
return nil, err
}
req.Buckets = b
req.Strategy = r.Form.Get("strategy")
return req, nil
}

func buckets(r *http.Request) (uint32, error) {
b, err := parseInt(r.Form.Get("buckets"), 1)
if err != nil {
return 0, err
}
if b <= 0 {
return 0, errors.New("buckets must be a positive value")
}
return uint32(b), nil
}
31 changes: 31 additions & 0 deletions pkg/logproto/compat.go
Original file line number Diff line number Diff line change
Expand Up @@ -588,3 +588,34 @@ func (m *DetectedLabelsRequest) LogToSpan(sp opentracing.Span) {
}
sp.LogFields(fields...)
}


func (m *QueryPlanRequest) GetCachingOptions() (res definitions.CachingOptions) { return }

func (m *QueryPlanRequest) WithStartEnd(start, end time.Time) definitions.Request {
clone := *m
clone.Start = start
clone.End = end
return &clone
}

func (m *QueryPlanRequest) WithStartEndForCache(start, end time.Time) resultscache.Request {
return m.WithStartEnd(start, end).(resultscache.Request)
}

func (m *QueryPlanRequest) WithQuery(query string) definitions.Request {
clone := *m
clone.Query = query
return &clone
}

func (m *QueryPlanRequest) LogToSpan(sp opentracing.Span) {
fields := []otlog.Field{
otlog.String("query", m.GetQuery()),
otlog.String("start", m.Start.String()),
otlog.String("end", m.End.String()),
}
sp.LogFields(fields...)
}

func (m *QueryPlanRequest) GetStep() int64 { return 0 }
Loading