MCPcopy Index your code
hub / github.com/cortexproject/cortex / RangeQueryHandler

Method RangeQueryHandler

pkg/api/queryapi/query_api.go:57–152  ·  view source on GitHub ↗
(r *http.Request)

Source from the content-addressed store, hash-verified

55}
56
57func (q *QueryAPI) RangeQueryHandler(r *http.Request) (result apiFuncResult) {
58 // TODO(Sungjin1212): Change to emit basic error (not gRPC)
59 start, err := util.ParseTime(r.FormValue("start"))
60 if err != nil {
61 return invalidParamError(err, "start")
62 }
63 end, err := util.ParseTime(r.FormValue("end"))
64 if err != nil {
65 return invalidParamError(err, "end")
66 }
67 if end < start {
68 return invalidParamError(ErrEndBeforeStart, "end")
69 }
70
71 step, err := util.ParseDurationMs(r.FormValue("step"))
72 if err != nil {
73 return invalidParamError(err, "step")
74 }
75
76 if step <= 0 {
77 return invalidParamError(ErrNegativeStep, "step")
78 }
79
80 // For safety, limit the number of returned points per timeseries.
81 // This is sufficient for 60s resolution for a week or 1h resolution for a year.
82 if (end-start)/step > 11000 {
83 return apiFuncResult{nil, &apiError{errorBadData, ErrStepTooSmall}, nil, nil}
84 }
85
86 ctx := r.Context()
87 if to := r.FormValue("timeout"); to != "" {
88 var cancel context.CancelFunc
89 timeout, err := util.ParseDurationMs(to)
90 if err != nil {
91 return invalidParamError(err, "timeout")
92 }
93
94 ctx, cancel = context.WithTimeout(ctx, convertMsToDuration(timeout))
95 defer cancel()
96 }
97
98 opts, err := extractQueryOpts(r)
99 if err != nil {
100 return apiFuncResult{nil, &apiError{errorBadData, err}, nil, nil}
101 }
102
103 ctx = engine.AddEngineTypeToContext(ctx, r)
104 ctx = querier.AddBlockStoreTypeToContext(ctx, r.Header.Get(querier.BlockStoreTypeHeader))
105
106 var qry promql.Query
107 startTime := convertMsToTime(start)
108 endTime := convertMsToTime(end)
109 stepDuration := convertMsToDuration(step)
110
111 byteLP := []byte(r.PostFormValue("plan"))
112 if len(byteLP) != 0 {
113 logicalPlan, err := distributed_execution.Unmarshal(byteLP)
114 if err != nil {

Callers

nothing calls this directly

Calls 15

ParseTimeFunction · 0.92
ParseDurationMsFunction · 0.92
AddEngineTypeToContextFunction · 0.92
UnmarshalFunction · 0.92
invalidParamErrorFunction · 0.85
convertMsToDurationFunction · 0.85
extractQueryOptsFunction · 0.85
convertMsToTimeFunction · 0.85
returnAPIErrorFunction · 0.85
NewRangeQueryMethod · 0.80
TypeMethod · 0.80

Tested by

no test coverage detected