diff --git a/app/vmctl/time.go b/app/vmctl/time.go index 43dd7588d..55652475c 100644 --- a/app/vmctl/time.go +++ b/app/vmctl/time.go @@ -2,6 +2,7 @@ package main import ( "fmt" + "math" "time" "github.com/VictoriaMetrics/VictoriaMetrics/lib/promutils" @@ -18,7 +19,7 @@ func parseTime(s string) (time.Time, error) { if err != nil { return time.Time{}, fmt.Errorf("cannot parse %s: %w", s, err) } - msecs := int64(secs * 1e3) + msecs := int64(math.Round(secs * 1e3)) if msecs < minTimeMsecs { msecs = 0 } diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index a7c498ec5..2b788d4d9 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -40,6 +40,7 @@ See also [LTS releases](https://docs.victoriametrics.com/LTS-releases.html). * BUGFIX: fix the misleading error `0ms is out of allowed range [0 ...` when passing `step=0` to [/api/v1/query](https://docs.victoriametrics.com/keyconcepts/#instant-query) or [/api/v1/query_range](https://docs.victoriametrics.com/keyconcepts/#range-query). See [this issue](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/5795). +* BUGFIX: [Single-node VictoriaMetrics](https://docs.victoriametrics.com/) and `vmselect` in [VictoriaMetrics cluster](https://docs.victoriametrics.com/cluster-victoriametrics/): fixed floating-point error when parsing time in RFC3339 format. See [this issue](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/5801) for details. * BUGFIX: [vmalert](https://docs.victoriametrics.com/#vmalert): consistently sort groups by name and filename on `/groups` page in UI. This should prevent non-deterministic sorting for groups with identical names. ## [v1.98.0](https://github.com/VictoriaMetrics/VictoriaMetrics/releases/tag/v1.98.0) diff --git a/lib/httputils/time.go b/lib/httputils/time.go index e55591251..0ad156575 100644 --- a/lib/httputils/time.go +++ b/lib/httputils/time.go @@ -32,7 +32,7 @@ func GetTime(r *http.Request, argKey string, defaultMs int64) (int64, error) { if err != nil { return 0, fmt.Errorf("cannot parse %s=%s: %w", argKey, argValue, err) } - msecs := int64(secs * 1e3) + msecs := int64(math.Round(secs * 1e3)) if msecs < minTimeMsecs { msecs = 0 } diff --git a/lib/httputils/time_test.go b/lib/httputils/time_test.go index 949b3e47d..73667e719 100644 --- a/lib/httputils/time_test.go +++ b/lib/httputils/time_test.go @@ -47,6 +47,7 @@ func TestGetTimeSuccess(t *testing.T) { f("2019-02-02T01:01:00", 1549069260000) f("2019-02-02T01:01:01", 1549069261000) f("2019-07-07T20:01:02Z", 1562529662000) + f("2020-02-21T16:07:49.433Z", 1582301269433) f("2019-07-07T20:47:40+03:00", 1562521660000) f("-292273086-05-16T16:47:06Z", minTimeMsecs) f("292277025-08-18T07:12:54.999999999Z", maxTimeMsecs)