Add Lua functions to reassemble partial cri-o logs

This commit is contained in:
Stefan Reimer 2020-09-08 13:12:21 +01:00
parent 6b1b02a743
commit e09935a819
1 changed files with 25 additions and 0 deletions

View File

@ -234,6 +234,12 @@ fluent-bit:
DB.Sync Normal
filters: |
[FILTER]
Name lua
Match kube.*
script /fluent-bit/etc/functions.lua
call reassemble_cri_logs
[FILTER]
Name kubernetes
Match kube.*
@ -290,6 +296,25 @@ fluent-bit:
end
end
local reassemble_state = {}
function reassemble_cri_logs(tag, timestamp, record)
-- IMPORTANT: reassemble_key must be unique for each parser stream
-- otherwise entries from different sources will get mixed up.
-- Either make sure that your parser tags satisfy this or construct
-- reassemble_key some other way
local reassemble_key = tag
-- if partial line, accumulate
if record.logtag == 'P' then
reassemble_state[reassemble_key] = reassemble_state[reassemble_key] or "" .. record.message
return -1, 0, 0
end
-- otherwise it's a full line, concatenate with accumulated partial lines if any
record.message = reassemble_state[reassemble_key] or "" .. record.message
reassemble_state[reassemble_key] = nil
return 1, timestamp, record
end
serviceMonitor:
enabled: true
namespace: monitoring