Skip to content

Commit fa5dd6f

Browse files
committed
Move ExtractQueryOpts
Signed-off-by: SungJin1212 <[email protected]>
1 parent 0c8b043 commit fa5dd6f

File tree

3 files changed

+19
-16
lines changed

3 files changed

+19
-16
lines changed

pkg/api/query/handler.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ func (q *QueryAPI) RangeQueryHandler(r *http.Request) (result apiFuncResult) {
9393
defer cancel()
9494
}
9595

96-
opts, err := api.ExtractQueryOpts(r)
96+
opts, err := ExtractQueryOpts(r)
9797
if err != nil {
9898
return apiFuncResult{nil, &apiError{errorBadData, err}, nil, nil}
9999
}
@@ -147,7 +147,7 @@ func (q *QueryAPI) InstantQueryHandler(r *http.Request) (result apiFuncResult) {
147147
defer cancel()
148148
}
149149

150-
opts, err := api.ExtractQueryOpts(r)
150+
opts, err := ExtractQueryOpts(r)
151151
if err != nil {
152152
return apiFuncResult{nil, &apiError{errorBadData, err}, nil, nil}
153153
}

pkg/api/query/util.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,12 @@ import (
55
"errors"
66
"fmt"
77
"net/http"
8+
"time"
89

910
"github.com/prometheus/prometheus/promql"
1011
"github.com/prometheus/prometheus/util/annotations"
12+
13+
"github.com/cortexproject/cortex/pkg/util/api"
1114
)
1215

1316
const (
@@ -79,3 +82,17 @@ func invalidParamError(err error, parameter string) apiFuncResult {
7982
errorBadData, fmt.Errorf("invalid parameter %q: %w", parameter, err),
8083
}, nil, nil}
8184
}
85+
86+
func ExtractQueryOpts(r *http.Request) (promql.QueryOpts, error) {
87+
var duration time.Duration
88+
89+
if strDuration := r.FormValue("lookback_delta"); strDuration != "" {
90+
parsedDuration, err := api.ParseDuration(strDuration)
91+
if err != nil {
92+
return nil, fmt.Errorf("error parsing lookback delta duration: %w", err)
93+
}
94+
duration = parsedDuration
95+
}
96+
97+
return promql.NewPrometheusQueryOpts(r.FormValue("stats") == "all", duration), nil
98+
}

pkg/util/api/parse.go

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -39,20 +39,6 @@ var (
3939
maxTimeFormatted = MaxTime.Format(time.RFC3339Nano)
4040
)
4141

42-
func ExtractQueryOpts(r *http.Request) (promql.QueryOpts, error) {
43-
var duration time.Duration
44-
45-
if strDuration := r.FormValue("lookback_delta"); strDuration != "" {
46-
parsedDuration, err := ParseDuration(strDuration)
47-
if err != nil {
48-
return nil, fmt.Errorf("error parsing lookback delta duration: %w", err)
49-
}
50-
duration = parsedDuration
51-
}
52-
53-
return promql.NewPrometheusQueryOpts(r.FormValue("stats") == "all", duration), nil
54-
}
55-
5642
func ParseTime(s string) (time.Time, error) {
5743
if t, err := strconv.ParseFloat(s, 64); err == nil {
5844
s, ns := math.Modf(t)

0 commit comments

Comments
 (0)