From ce3ec3ff2ec590aee0604bd6905f7d57dfc2a813 Mon Sep 17 00:00:00 2001 From: Alexander Marshalov <_@marshalov.org> Date: Thu, 22 Feb 2024 10:20:54 +0100 Subject: [PATCH] [lib/httputils] fixed floating-point error when parsing time in RFC3339 format (#5814) * [lib/promutils, lib/httputils] fixed floating-point error when parsing time in RFC3339 format (#5801) * fixed tests * fixed test * Revert "fixed test" This reverts commit 8a29764806bda7c3853a0b12b6b9704c71e5c65a. * Revert "fixed tests" This reverts commit 9ce13d1042caaaafcec33b4c97846cfafa27ce0f. * Revert "[lib/promutils, lib/httputils] fixed floating-point error when parsing time in RFC3339 format (#5801)" This reverts commit a7a04bd4 * [lib/httputils] fixed floating-point error when parsing time in RFC3339 format (#5801) --------- Co-authored-by: Nikolay --- app/vmctl/time.go | 3 ++- docs/CHANGELOG.md | 1 + lib/httputils/time.go | 2 +- lib/httputils/time_test.go | 1 + 4 files changed, 5 insertions(+), 2 deletions(-) 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)