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

pull/1896/head
Anders Daljord Morken 8 years ago
parent 6bfd30269a
commit e9885ecb94

@ -187,6 +187,11 @@ func (api *API) queryRange(r *http.Request) (interface{}, *apiError) {
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.
// This is sufficient for 60s resolution for a week or 1h resolution for a year.
if end.Sub(start)/step > 11000 {

@ -187,6 +187,17 @@ func TestEndpoints(t *testing.T) {
},
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,
params: map[string]string{

Loading…
Cancel
Save