Skip to content

Commit b891ce2

Browse files
authored
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
1 parent 9806f91 commit b891ce2

4 files changed

Lines changed: 13 additions & 6 deletions

File tree

CHANGELOG-developer.next.asciidoc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,3 +122,7 @@ The list below covers the major changes between 7.0.0-rc2 and master only.
122122
- Update to go-concert 0.2.0 {pull}27162[27162]
123123
- Update Go version to 1.16.5. {issue}26182[26182] {pull}26186[26186]
124124
- Introduce `libbeat/beat.Beat.OutputConfigReloader` {pull}28048[28048]
125+
126+
==== Deprecated
127+
128+
- Deprecated the `common.Float` type. {issue}28279[28279] {pull}28280[28280]

CHANGELOG.next.asciidoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha2...master[Check the HEAD d
210210
- Periodic metrics in logs will now report `libbeat.output.events.active` and `beat.memstats.rss`
211211
as gauges (rather than counters). {pull}22877[22877]
212212
- Beats dashboards use custom index when `setup.dashboards.index` is set. {issue}21232[21232] {pull}27901[27901]
213+
- Fix handling of float data types within processors. {issue}28279[28279] {pull}28280[28280]
213214

214215
*Auditbeat*
215216

libbeat/common/event.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ import (
3333

3434
var textMarshalerType = reflect.TypeOf((*encoding.TextMarshaler)(nil)).Elem()
3535

36+
// Float is a float64 wrapper that implements the encoding/json Marshaler
37+
// interface to add a decimal point to all float values.
38+
//
39+
// Deprecated: This type should no longer be used and the Marshaler interface
40+
// is not consulted while marshaling to JSON in libbeat outputs.
3641
type Float float64
3742

3843
// EventConverter is used to convert MapStr objects for publishing
@@ -208,10 +213,7 @@ func (e *GenericEventConverter) normalizeValue(value interface{}, keys ...string
208213
}
209214
return tmp, nil
210215

211-
case float64:
212-
return Float(value.(float64)), nil
213-
case float32:
214-
return Float(value.(float32)), nil
216+
case float32, float64:
215217
case []float32, []float64:
216218
case complex64, complex128:
217219
case []complex64, []complex128:
@@ -238,7 +240,7 @@ func (e *GenericEventConverter) normalizeValue(value interface{}, keys ...string
238240
case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
239241
return v.Uint() &^ (1 << 63), nil
240242
case reflect.Float32, reflect.Float64:
241-
return Float(v.Float()), nil
243+
return v.Float(), nil
242244
case reflect.Complex64, reflect.Complex128:
243245
return v.Complex(), nil
244246
case reflect.String:

libbeat/common/event_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ func TestNormalizeValue(t *testing.T) {
267267
}
268268

269269
checkDelta := func(t *testing.T, a, b interface{}) {
270-
assert.InDelta(t, a, float64(b.(Float)), 0.000001)
270+
assert.InDelta(t, a, b, 0.000001)
271271
}
272272

273273
var nilStringPtr *string

0 commit comments

Comments
 (0)