diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc index 653b82e8aeb..a64f47ae462 100644 --- a/CHANGELOG.asciidoc +++ b/CHANGELOG.asciidoc @@ -59,6 +59,7 @@ https://github.com/elastic/beats/compare/v6.0.0-beta2...master[Check the HEAD di - Fix documentation links in README.md files. {pull}5710[5710] - Fix logstash output debug message. {pull}5799{5799] - Fix isolation of modules when merging local and global field settings. {issue}5795[5795] +- Fix panic when Events containing a float32 value are normalized. {pull}6129[6129] *Auditbeat* diff --git a/libbeat/common/event.go b/libbeat/common/event.go index c91abcd5415..c42e0172617 100644 --- a/libbeat/common/event.go +++ b/libbeat/common/event.go @@ -152,8 +152,10 @@ func normalizeValue(value interface{}, keys ...string) (interface{}, []error) { case []int, []int8, []int16, []int32, []int64: case uint, uint8, uint16, uint32, uint64: case []uint, []uint8, []uint16, []uint32, []uint64: - case float32, float64: + case float64: return Float(value.(float64)), nil + case float32: + return Float(value.(float32)), nil case []float32, []float64: case complex64, complex128: case []complex64, []complex128: diff --git a/libbeat/common/event_test.go b/libbeat/common/event_test.go index 0ddceb046c1..24b0e040c16 100644 --- a/libbeat/common/event_test.go +++ b/libbeat/common/event_test.go @@ -237,6 +237,23 @@ func TestNormalizeValue(t *testing.T) { assert.Equal(t, test.out, out, "Test case %v", i) } + + var floatTests = []struct { + in interface{} + out interface{} + }{ + {float32(1), float64(1)}, + {float64(1), float64(1)}, + } + + for i, test := range floatTests { + out, err := normalizeValue(test.in) + if err != nil { + t.Error(err) + continue + } + assert.InDelta(t, test.out, float64(out.(Float)), 0.000001, "(approximate) Test case %v", i) + } } func TestNormalizeMapError(t *testing.T) {