Browse Source

Bugfix: Avoid divide-by-zero panic on query_range?step=0

pull/1896/head
Anders Daljord Morken 8 years ago
parent
commit
e9885ecb94
  1. 5
      web/api/v1/api.go
  2. 11
      web/api/v1/api_test.go

5
web/api/v1/api.go

@ -187,6 +187,11 @@ func (api *API) queryRange(r *http.Request) (interface{}, *apiError) {
return nil, &apiError{errorBadData, err} return nil, &apiError{errorBadData, err}
} }
if step <= 0 {
err := errors.New("zero or negative query resolution step widths are not accepted. Try a positive integer")
return nil, &apiError{errorBadData, err}
}
// For safety, limit the number of returned points per timeseries. // For safety, limit the number of returned points per timeseries.
// This is sufficient for 60s resolution for a week or 1h resolution for a year. // This is sufficient for 60s resolution for a week or 1h resolution for a year.
if end.Sub(start)/step > 11000 { if end.Sub(start)/step > 11000 {

11
web/api/v1/api_test.go

@ -187,6 +187,17 @@ func TestEndpoints(t *testing.T) {
}, },
errType: errorBadData, errType: errorBadData,
}, },
// Invalid step
{
endpoint: api.queryRange,
query: url.Values{
"query": []string{"time()"},
"start": []string{"1"},
"end": []string{"2"},
"step": []string{"0"},
},
errType: errorBadData,
},
{ {
endpoint: api.labelValues, endpoint: api.labelValues,
params: map[string]string{ params: map[string]string{

Loading…
Cancel
Save