Skip to content

Commit

Permalink
[7.x](backport #28280) [libbeat] Deprecate common.Float (#28309)
Browse files Browse the repository at this point in the history
* 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 b891ce2)

* Update CHANGELOG.next.asciidoc

Co-authored-by: Andrew Kroh <andrew.kroh@elastic.co>
  • Loading branch information
mergify[bot] and andrewkroh committed Oct 13, 2021
1 parent e6e2ca9 commit efae215
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 6 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG-developer.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -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]
1 change: 1 addition & 0 deletions CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ 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]
- Fix handling of float data types within processors. {issue}28279[28279] {pull}28280[28280]

*Auditbeat*

Expand Down
12 changes: 7 additions & 5 deletions libbeat/common/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion libbeat/common/event_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit efae215

Please sign in to comment.