Skip to content

Commit a468a99

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

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
@@ -94,7 +94,7 @@ func (q *QueryAPI) RangeQueryHandler(r *http.Request) (result apiFuncResult) {
9494
defer cancel()
9595
}
9696

97-
opts, err := api.ExtractQueryOpts(r)
97+
opts, err := ExtractQueryOpts(r)
9898
if err != nil {
9999
return apiFuncResult{nil, &apiError{errorBadData, err}, nil, nil}
100100
}
@@ -149,7 +149,7 @@ func (q *QueryAPI) InstantQueryHandler(r *http.Request) (result apiFuncResult) {
149149
defer cancel()
150150
}
151151

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

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)