From 79ae581e139e9e5d190a82040ab2fd6682199215 Mon Sep 17 00:00:00 2001 From: Andrew Kroh Date: Thu, 7 Oct 2021 09:30:36 -0400 Subject: [PATCH 1/2] Deprecate common.Float (#28280) Deprecate common.Float and stop using it during event normalization within the publishing pipeline. common.Float has not been used for its original purpose since ~2017 when marshaling to JSON was handled by go-structform. This will fix processors that did not previously handle common.Float in type assertions. Fixes #28279 (cherry picked from commit b891ce2054583b2af3c3e1b4d0e2b64901ff612b) --- CHANGELOG-developer.next.asciidoc | 4 ++++ CHANGELOG.next.asciidoc | 2 ++ libbeat/common/event.go | 12 +++++++----- libbeat/common/event_test.go | 2 +- 4 files changed, 14 insertions(+), 6 deletions(-) diff --git a/CHANGELOG-developer.next.asciidoc b/CHANGELOG-developer.next.asciidoc index 4b89ac3260a..1e932cb263f 100644 --- a/CHANGELOG-developer.next.asciidoc +++ b/CHANGELOG-developer.next.asciidoc @@ -115,3 +115,7 @@ The list below covers the major changes between 7.0.0-rc2 and master only. - Update to go-concert 0.2.0 {pull}27162[27162] - Update Go version to 1.16.5. {issue}26182[26182] {pull}26186[26186] - Introduce `libbeat/beat.Beat.OutputConfigReloader` {pull}28048[28048] + +==== Deprecated + +- Deprecated the `common.Float` type. {issue}28279[28279] {pull}28280[28280] diff --git a/CHANGELOG.next.asciidoc b/CHANGELOG.next.asciidoc index e541ae57874..3d8b3b475ba 100644 --- a/CHANGELOG.next.asciidoc +++ b/CHANGELOG.next.asciidoc @@ -136,6 +136,8 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha2...master[Check the HEAD d - Preserve annotations in a kubernetes namespace metadata {pull}27045[27045] - Allow conditional processing in `decode_xml` and `decode_xml_wineventlog`. {pull}27159[27159] - Fix build constraint that caused issues with doc builds. {pull}27381[27381] +- Beats dashboards use custom index when `setup.dashboards.index` is set. {issue}21232[21232] {pull}27901[27901] +- Fix handling of float data types within processors. {issue}28279[28279] {pull}28280[28280] *Auditbeat* diff --git a/libbeat/common/event.go b/libbeat/common/event.go index f68cf33cc87..0d2a312166e 100644 --- a/libbeat/common/event.go +++ b/libbeat/common/event.go @@ -33,6 +33,11 @@ import ( var textMarshalerType = reflect.TypeOf((*encoding.TextMarshaler)(nil)).Elem() +// Float is a float64 wrapper that implements the encoding/json Marshaler +// interface to add a decimal point to all float values. +// +// Deprecated: This type should no longer be used and the Marshaler interface +// is not consulted while marshaling to JSON in libbeat outputs. type Float float64 // EventConverter is used to convert MapStr objects for publishing @@ -208,10 +213,7 @@ func (e *GenericEventConverter) normalizeValue(value interface{}, keys ...string } return tmp, nil - case float64: - return Float(value.(float64)), nil - case float32: - return Float(value.(float32)), nil + case float32, float64: case []float32, []float64: case complex64, complex128: case []complex64, []complex128: @@ -238,7 +240,7 @@ func (e *GenericEventConverter) normalizeValue(value interface{}, keys ...string case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64: return v.Uint() &^ (1 << 63), nil case reflect.Float32, reflect.Float64: - return Float(v.Float()), nil + return v.Float(), nil case reflect.Complex64, reflect.Complex128: return v.Complex(), nil case reflect.String: diff --git a/libbeat/common/event_test.go b/libbeat/common/event_test.go index c9d3a36e0c9..e9c493cb5de 100644 --- a/libbeat/common/event_test.go +++ b/libbeat/common/event_test.go @@ -267,7 +267,7 @@ func TestNormalizeValue(t *testing.T) { } checkDelta := func(t *testing.T, a, b interface{}) { - assert.InDelta(t, a, float64(b.(Float)), 0.000001) + assert.InDelta(t, a, b, 0.000001) } var nilStringPtr *string From 65c8111117d04099eb0297c7adbce2e7518e0e1f Mon Sep 17 00:00:00 2001 From: Andrew Kroh Date: Thu, 7 Oct 2021 09:34:18 -0400 Subject: [PATCH 2/2] Update CHANGELOG.next.asciidoc --- CHANGELOG.next.asciidoc | 1 - 1 file changed, 1 deletion(-) diff --git a/CHANGELOG.next.asciidoc b/CHANGELOG.next.asciidoc index 3d8b3b475ba..395fd67b0a6 100644 --- a/CHANGELOG.next.asciidoc +++ b/CHANGELOG.next.asciidoc @@ -136,7 +136,6 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha2...master[Check the HEAD d - Preserve annotations in a kubernetes namespace metadata {pull}27045[27045] - Allow conditional processing in `decode_xml` and `decode_xml_wineventlog`. {pull}27159[27159] - Fix build constraint that caused issues with doc builds. {pull}27381[27381] -- Beats dashboards use custom index when `setup.dashboards.index` is set. {issue}21232[21232] {pull}27901[27901] - Fix handling of float data types within processors. {issue}28279[28279] {pull}28280[28280] *Auditbeat*