Skip to content

Commit

Permalink
Fluent-bit only supports Lua 5.1
Browse files Browse the repository at this point in the history
  • Loading branch information
quentinmit committed Apr 8, 2022
1 parent 51b86e9 commit f03f58a
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
7 changes: 5 additions & 2 deletions confgenerator/logging_modify_fields.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
Match p1.sample_logs
Name lua
call process
script 3a94b231d99baac9194545a8222cd9c8.lua
script 11707260be42e8aa17deb8c0f15d2568.lua

[FILTER]
Match p1.sample_logs
Expand Down

0 comments on commit f03f58a

Please sign in to comment.