diff --git a/app/vmselect/prometheus/prometheus.go b/app/vmselect/prometheus/prometheus.go index 67a2a955c2..7e37c54dbd 100644 --- a/app/vmselect/prometheus/prometheus.go +++ b/app/vmselect/prometheus/prometheus.go @@ -562,8 +562,11 @@ func getTime(r *http.Request, argKey string, defaultValue int64) (int64, error) secs = float64(t.UnixNano()) / 1e9 } msecs := int64(secs * 1e3) - if msecs < minTimeMsecs || msecs > maxTimeMsecs { - return 0, fmt.Errorf("%q=%dms is out of allowed range [%d ... %d]", argKey, msecs, minTimeMsecs, maxTimeMsecs) + if msecs < minTimeMsecs { + msecs = 0 + } + if msecs > maxTimeMsecs { + msecs = maxTimeMsecs } return msecs, nil } @@ -577,7 +580,7 @@ var ( const ( // These values prevent from overflow when storing msec-precision time in int64. - minTimeMsecs = int64(-1<<63) / 1e6 + minTimeMsecs = 0 // use 0 instead of `int64(-1<<63) / 1e6` because the storage engine doesn't actually support negative time maxTimeMsecs = int64(1<<63-1) / 1e6 ) diff --git a/app/vmselect/prometheus/prometheus_test.go b/app/vmselect/prometheus/prometheus_test.go index 0717dc535d..3bdf42d8f5 100644 --- a/app/vmselect/prometheus/prometheus_test.go +++ b/app/vmselect/prometheus/prometheus_test.go @@ -37,10 +37,12 @@ func TestGetTimeSuccess(t *testing.T) { f("2019-07-07T20:01:02Z", 1562529662000) f("2019-07-07T20:47:40+03:00", 1562521660000) - f("-292273086-05-16T16:47:06Z", -9223372036854) - f("292277025-08-18T07:12:54.999999999Z", 9223372036854) + f("-292273086-05-16T16:47:06Z", minTimeMsecs) + f("292277025-08-18T07:12:54.999999999Z", maxTimeMsecs) f("1562529662.324", 1562529662324) - f("-9223372036.854", -9223372036854) + f("-9223372036.854", minTimeMsecs) + f("-9223372036.855", minTimeMsecs) + f("9223372036.855", maxTimeMsecs) } func TestGetTimeError(t *testing.T) { @@ -73,6 +75,4 @@ func TestGetTimeError(t *testing.T) { f("2019-07-07T20:47:40+03:00123") f("-292273086-05-16T16:47:07Z") f("292277025-08-18T07:12:54.999999998Z") - f("-9223372036.855") - f("9223372036.855") }