-
Notifications
You must be signed in to change notification settings - Fork 455
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
[query] Take bounds into account for list endpoints #3110
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -176,6 +176,35 @@ func parseTagCompletionQueries(r *http.Request) ([]string, error) { | |
return queries, nil | ||
} | ||
|
||
// ParseStartAndEnd parses start and end params from the request. | ||
func ParseStartAndEnd( | ||
r *http.Request, | ||
parseOpts xpromql.ParseOptions, | ||
) (time.Time, time.Time, error) { | ||
if err := r.ParseForm(); err != nil { | ||
return time.Time{}, time.Time{}, xerrors.NewInvalidParamsError(err) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. will this propagate as a 400? |
||
} | ||
|
||
start, err := util.ParseTimeStringWithDefault(r.FormValue("start"), | ||
time.Unix(0, 0)) | ||
if err != nil { | ||
return time.Time{}, time.Time{}, xerrors.NewInvalidParamsError(err) | ||
} | ||
|
||
end, err := util.ParseTimeStringWithDefault(r.FormValue("end"), | ||
parseOpts.NowFn()()) | ||
if err != nil { | ||
return time.Time{}, time.Time{}, xerrors.NewInvalidParamsError(err) | ||
} | ||
|
||
if start.After(end) { | ||
err := fmt.Errorf("start %v must be after end %v", start, end) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. before end |
||
return time.Time{}, time.Time{}, xerrors.NewInvalidParamsError(err) | ||
} | ||
|
||
return start, end, nil | ||
} | ||
|
||
// ParseSeriesMatchQuery parses all params from the GET request. | ||
func ParseSeriesMatchQuery( | ||
r *http.Request, | ||
|
@@ -188,16 +217,9 @@ func ParseSeriesMatchQuery( | |
return nil, xerrors.NewInvalidParamsError(errors.ErrInvalidMatchers) | ||
} | ||
|
||
start, err := util.ParseTimeStringWithDefault(r.FormValue("start"), | ||
time.Unix(0, 0)) | ||
if err != nil { | ||
return nil, xerrors.NewInvalidParamsError(err) | ||
} | ||
|
||
end, err := util.ParseTimeStringWithDefault(r.FormValue("end"), | ||
time.Now()) | ||
start, end, err := ParseStartAndEnd(r, parseOpts) | ||
if err != nil { | ||
return nil, xerrors.NewInvalidParamsError(err) | ||
return nil, err | ||
} | ||
|
||
queries := make([]*storage.FetchQuery, len(matcherValues)) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,8 +44,8 @@ import ( | |
) | ||
|
||
type tagValuesMatcher struct { | ||
now time.Time | ||
filterTag string | ||
start, end time.Time | ||
filterTag string | ||
} | ||
|
||
func (m *tagValuesMatcher) String() string { return "tag values query" } | ||
|
@@ -55,11 +55,11 @@ func (m *tagValuesMatcher) Matches(x interface{}) bool { | |
return false | ||
} | ||
|
||
if !q.Start.Equal(time.Time{}) { | ||
if !q.Start.Equal(m.start) { | ||
return false | ||
} | ||
|
||
if !q.End.Equal(m.now) { | ||
if !q.End.Equal(m.end) { | ||
return false | ||
} | ||
|
||
|
@@ -123,7 +123,7 @@ func TestTagValues(t *testing.T) { | |
url := fmt.Sprintf("/label/{%s}/values", NameReplace) | ||
|
||
for _, tt := range names { | ||
path := fmt.Sprintf("/label/%s/values", tt.name) | ||
path := fmt.Sprintf("/label/%s/values?start=100", tt.name) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can we have a case with an end too? |
||
req, err := http.NewRequest("GET", path, nil) | ||
if err != nil { | ||
t.Fatal(err) | ||
|
@@ -132,7 +132,8 @@ func TestTagValues(t *testing.T) { | |
rr := httptest.NewRecorder() | ||
router := mux.NewRouter() | ||
matcher := &tagValuesMatcher{ | ||
now: now, | ||
start: time.Unix(100, 0), | ||
end: now, | ||
filterTag: tt.name, | ||
} | ||
|
||
|
@@ -146,7 +147,7 @@ func TestTagValues(t *testing.T) { | |
}, | ||
Metadata: block.ResultMetadata{ | ||
Exhaustive: false, | ||
Warnings: []block.Warning{block.Warning{Name: "foo", Message: "bar"}}, | ||
Warnings: []block.Warning{{Name: "foo", Message: "bar"}}, | ||
}, | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why does this need the whole
parseOpts
instead of only theNowFn()
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Figured this was cleaner than building a new
parseOpts
on each query; can go that route if preferred