From 762ad188b7ecdd5bae65bb525e5eca393c4a86d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Alvarez=20Pi=C3=B1eiro?= <95703246+emilioalvap@users.noreply.github.com> Date: Thu, 26 Jan 2023 18:24:21 +0100 Subject: [PATCH] Marshal heartbeat duration as int64,string to prevent int64 -> float conversion (#34280) * Add test initial state and build tag * Keep int64 precision on marshal * Add changelog --- CHANGELOG.next.asciidoc | 1 + heartbeat/monitors/wrappers/monitorstate/esloader_test.go | 3 +++ heartbeat/monitors/wrappers/monitorstate/monitorstate.go | 2 +- 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.next.asciidoc b/CHANGELOG.next.asciidoc index 4083d570f14c..186c094ceece 100644 --- a/CHANGELOG.next.asciidoc +++ b/CHANGELOG.next.asciidoc @@ -86,6 +86,7 @@ https://github.com/elastic/beats/compare/v8.2.0\...main[Check the HEAD diff] - Fix handling of long UDP messages in UDP input. {issue}33836[33836] {pull}33837[33837] - Fix browser monitor summary reporting as up when monitor is down. {issue}33374[33374] {pull}33819[33819] - Fix beat capabilities on Docker image. {pull}33584[33584] +- Fix serialization of state duration to avoid scientific notation. {pull}34280[34280] *Heartbeat* diff --git a/heartbeat/monitors/wrappers/monitorstate/esloader_test.go b/heartbeat/monitors/wrappers/monitorstate/esloader_test.go index c7bacf901945..d2730178ed01 100644 --- a/heartbeat/monitors/wrappers/monitorstate/esloader_test.go +++ b/heartbeat/monitors/wrappers/monitorstate/esloader_test.go @@ -16,6 +16,7 @@ // under the License. //go:build integration +// +build integration package monitorstate @@ -126,6 +127,8 @@ func (etc *esTestContext) createTestMonitorStateInES(t *testing.T, s StateStatus } initState := newMonitorState(sf, s, 0, true) + // Test int64 is un/marshalled correctly + initState.DurationMs = 3e9 etc.setInitialState(t, sf, initState) return sf } diff --git a/heartbeat/monitors/wrappers/monitorstate/monitorstate.go b/heartbeat/monitors/wrappers/monitorstate/monitorstate.go index 1e274d9d093d..2b5046d7dd39 100644 --- a/heartbeat/monitors/wrappers/monitorstate/monitorstate.go +++ b/heartbeat/monitors/wrappers/monitorstate/monitorstate.go @@ -60,7 +60,7 @@ type State struct { ID string `json:"id"` // StartedAt is the start time of the state, should be the same for a given state ID StartedAt time.Time `json:"started_at"` - DurationMs int64 `json:"duration_ms"` + DurationMs int64 `json:"duration_ms,string"` Status StateStatus `json:"status"` Checks int `json:"checks"` Up int `json:"up"`