From f03f58a40352661e3f32cfe76a1c841bc60b085b Mon Sep 17 00:00:00 2001 From: Quentin Smith Date: Fri, 8 Apr 2022 15:49:12 -0400 Subject: [PATCH] Fluent-bit only supports Lua 5.1 --- confgenerator/logging_modify_fields.go | 7 +++++-- ...9c8.lua => golden_11707260be42e8aa17deb8c0f15d2568.lua} | 4 ++-- .../golden_fluent_bit_main.conf | 2 +- 3 files changed, 8 insertions(+), 5 deletions(-) rename confgenerator/testdata/valid/linux/logging-processor_modify_fields/{golden_3a94b231d99baac9194545a8222cd9c8.lua => golden_11707260be42e8aa17deb8c0f15d2568.lua} (96%) diff --git a/confgenerator/logging_modify_fields.go b/confgenerator/logging_modify_fields.go index 26c5ba1ba6..b97fa2fcdf 100644 --- a/confgenerator/logging_modify_fields.go +++ b/confgenerator/logging_modify_fields.go @@ -155,9 +155,12 @@ function process(tag, timestamp, record) var conv string switch field.Type { case "integer": - conv = "math.tointeger" + // Fluent-bit currently targets Lua 5.1, which uses the same type for numbers and integers. + // When converting back to msgpack, if a number can be represented as an integer, fluent-bit does so, otherwise it uses a float. + // If fluent-bit ever supports Lua 5.3, we can switch this to math.tointeger and use proper integers. + conv = "math.floor(tonumber(v))" case "float": - conv = "tonumber" + conv = "tonumber(v)" } if conv != "" { // Leave existing string value if not convertible diff --git a/confgenerator/testdata/valid/linux/logging-processor_modify_fields/golden_3a94b231d99baac9194545a8222cd9c8.lua b/confgenerator/testdata/valid/linux/logging-processor_modify_fields/golden_11707260be42e8aa17deb8c0f15d2568.lua similarity index 96% rename from confgenerator/testdata/valid/linux/logging-processor_modify_fields/golden_3a94b231d99baac9194545a8222cd9c8.lua rename to confgenerator/testdata/valid/linux/logging-processor_modify_fields/golden_11707260be42e8aa17deb8c0f15d2568.lua index 648ff44a29..e3061b6963 100644 --- a/confgenerator/testdata/valid/linux/logging-processor_modify_fields/golden_3a94b231d99baac9194545a8222cd9c8.lua +++ b/confgenerator/testdata/valid/linux/logging-processor_modify_fields/golden_11707260be42e8aa17deb8c0f15d2568.lua @@ -35,7 +35,7 @@ record["default"] = value end)(v) local v = __field_2; -local v2 = tonumber(v) +local v2 = tonumber(v)(v) if v2 ~= fail then v = v2 end (function(value) @@ -47,7 +47,7 @@ record["hello"] = value end)(v) local v = __field_3; -local v2 = math.tointeger(v) +local v2 = math.floor(tonumber(v))(v) if v2 ~= fail then v = v2 end (function(value) diff --git a/confgenerator/testdata/valid/linux/logging-processor_modify_fields/golden_fluent_bit_main.conf b/confgenerator/testdata/valid/linux/logging-processor_modify_fields/golden_fluent_bit_main.conf index 63c98f015b..f787caf555 100644 --- a/confgenerator/testdata/valid/linux/logging-processor_modify_fields/golden_fluent_bit_main.conf +++ b/confgenerator/testdata/valid/linux/logging-processor_modify_fields/golden_fluent_bit_main.conf @@ -69,7 +69,7 @@ Match p1.sample_logs Name lua call process - script 3a94b231d99baac9194545a8222cd9c8.lua + script 11707260be42e8aa17deb8c0f15d2568.lua [FILTER] Match p1.sample_logs