Skip to content

Commit

Permalink
Limit the default time window for label name and label value APIs
Browse files Browse the repository at this point in the history
Signed-off-by: Kemal Akkoyun <kakkoyun@gmail.com>
  • Loading branch information
kakkoyun committed Sep 9, 2020
1 parent eee604f commit bbf36a1
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions pkg/api/query/v1.go
Original file line number Diff line number Diff line change
Expand Up @@ -421,11 +421,13 @@ func (qapi *QueryAPI) labelValues(r *http.Request) (interface{}, []error, *api.A
return nil, nil, &api.ApiError{Typ: api.ErrorBadData, Err: errors.Errorf("invalid label name: %q", name)}
}

start, err := parseTimeParam(r, "start", minTime)
// If start and end time not specified, we get the last 2h window.
now := time.Now()
start, err := parseTimeParam(r, "start", now.Add(-2*time.Hour))
if err != nil {
return nil, nil, &api.ApiError{Typ: api.ErrorBadData, Err: err}
}
end, err := parseTimeParam(r, "end", maxTime)
end, err := parseTimeParam(r, "end", now)
if err != nil {
return nil, nil, &api.ApiError{Typ: api.ErrorBadData, Err: err}
}
Expand Down Expand Up @@ -582,11 +584,13 @@ func parseDuration(s string) (time.Duration, error) {
func (qapi *QueryAPI) labelNames(r *http.Request) (interface{}, []error, *api.ApiError) {
ctx := r.Context()

start, err := parseTimeParam(r, "start", minTime)
// If start and end time not specified, we get the last 2h window.
now := time.Now()
start, err := parseTimeParam(r, "start", now.Add(-2*time.Hour))
if err != nil {
return nil, nil, &api.ApiError{Typ: api.ErrorBadData, Err: err}
}
end, err := parseTimeParam(r, "end", maxTime)
end, err := parseTimeParam(r, "end", now)
if err != nil {
return nil, nil, &api.ApiError{Typ: api.ErrorBadData, Err: err}
}
Expand Down

0 comments on commit bbf36a1

Please sign in to comment.