From e45cf085a6c49bd8d2aab6f65b02d81842ca093e Mon Sep 17 00:00:00 2001 From: Andrew Kroh Date: Wed, 13 Oct 2021 00:05:33 -0400 Subject: [PATCH] Remove common.Float (#28376) Remove deprecated common.Float from 8.0. Relates #28279 Relates #28280 --- CHANGELOG-developer.next.asciidoc | 5 +---- libbeat/common/event.go | 14 -------------- libbeat/common/event_test.go | 16 ---------------- libbeat/conditions/range.go | 3 +-- 4 files changed, 2 insertions(+), 36 deletions(-) diff --git a/CHANGELOG-developer.next.asciidoc b/CHANGELOG-developer.next.asciidoc index 7583be5c550..59e831cc0a1 100644 --- a/CHANGELOG-developer.next.asciidoc +++ b/CHANGELOG-developer.next.asciidoc @@ -55,6 +55,7 @@ The list below covers the major changes between 7.0.0-rc2 and master only. - Remove `NumCPU` as clients should update the CPU count on the fly in case of config changes in a VM. {pull}23154[23154] - Remove Metricbeat EventFetcher and EventsFetcher interface. Use the reporter interface instead. {pull}25093[25093] - Update Darwin build image to a debian 10 base that increases the MacOS SDK and minimum supported version used in build to 10.14. {issue}24193[24193] +- Removed the `common.Float` type. {issue}28279[28279] {pull}28280[28280] {pull}28376[28376] ==== Bugfixes @@ -124,7 +125,3 @@ The list below covers the major changes between 7.0.0-rc2 and master only. -- The `enable_idempotent` config is a boolean setting to enable or disable the output support Idempotent. {pull}28095[28095] - Introduce `libbeat/beat.Beat.OutputConfigReloader` {pull}28048[28048] - Update Go version to 1.17.1. {pull}27543[27543] - -==== Deprecated - -- Deprecated the `common.Float` type. {issue}28279[28279] {pull}28280[28280] diff --git a/libbeat/common/event.go b/libbeat/common/event.go index 0d2a312166e..d96b7620a95 100644 --- a/libbeat/common/event.go +++ b/libbeat/common/event.go @@ -31,15 +31,6 @@ import ( "github.com/elastic/beats/v7/libbeat/logp" ) -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 type EventConverter interface { Convert(m MapStr) MapStr @@ -306,11 +297,6 @@ func joinKeys(keys ...string) string { return strings.Join(keys, ".") } -// Defines the marshal of the Float type -func (f Float) MarshalJSON() ([]byte, error) { - return []byte(fmt.Sprintf("%.6f", f)), nil -} - // DeDot a string by replacing all . with _ // This helps when sending data to Elasticsearch to prevent object and key collisions. func DeDot(s string) string { diff --git a/libbeat/common/event_test.go b/libbeat/common/event_test.go index e9c493cb5de..ec116187b64 100644 --- a/libbeat/common/event_test.go +++ b/libbeat/common/event_test.go @@ -396,22 +396,6 @@ func TestMarshalUnmarshalArray(t *testing.T) { } } -func TestMarshalFloatValues(t *testing.T) { - assert := assert.New(t) - - var f float64 - - f = 5 - - a := MapStr{ - "f": Float(f), - } - - b, err := json.Marshal(a) - assert.Nil(err) - assert.Equal(string(b), "{\"f\":5.000000}") -} - func TestNormalizeTime(t *testing.T) { ny, err := time.LoadLocation("America/New_York") if err != nil { diff --git a/libbeat/conditions/range.go b/libbeat/conditions/range.go index 063a98e3152..86c50370b59 100644 --- a/libbeat/conditions/range.go +++ b/libbeat/conditions/range.go @@ -22,7 +22,6 @@ import ( "reflect" "strings" - "github.com/elastic/beats/v7/libbeat/common" "github.com/elastic/beats/v7/libbeat/logp" ) @@ -129,7 +128,7 @@ func (c Range) Check(event ValuesMap) bool { return false } - case float64, float32, common.Float: + case float64, float32: floatValue := reflect.ValueOf(value).Float() if !checkValue(floatValue, rangeValue) {