New Lua function to nest entries into kube.<namespace>.*

This commit is contained in:
Stefan Reimer 2020-10-07 09:09:24 -07:00
parent cb3c6a93ba
commit a951e7d9a0
2 changed files with 23 additions and 7 deletions

View File

@ -2,7 +2,7 @@ apiVersion: v2
name: kubezero-logging name: kubezero-logging
description: KubeZero Umbrella Chart for complete EFK stack description: KubeZero Umbrella Chart for complete EFK stack
type: application type: application
version: 0.4.0 version: 0.4.1
appVersion: 1.2.1 appVersion: 1.2.1
home: https://kubezero.com home: https://kubezero.com
icon: https://cdn.zero-downtime.net/assets/kubezero/logo-small-64.png icon: https://cdn.zero-downtime.net/assets/kubezero/logo-small-64.png

View File

@ -238,6 +238,12 @@ fluent-bit:
Emitter_Name kube_tag_rewriter Emitter_Name kube_tag_rewriter
Rule logtag F kube.$kubernetes['namespace_name'].$kubernetes['container_name'] false Rule logtag F kube.$kubernetes['namespace_name'].$kubernetes['container_name'] false
[FILTER]
Name lua
Match kube.*
script /fluent-bit/etc/functions.lua
call nest_k8s_ns
`
service: | service: |
[SERVICE] [SERVICE]
Flush 1 Flush 1
@ -253,22 +259,32 @@ fluent-bit:
local reassemble_state = {} local reassemble_state = {}
function reassemble_cri_logs(tag, timestamp, record) 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 local reassemble_key = tag
-- if partial line, accumulate
if record.logtag == 'P' then if record.logtag == 'P' then
reassemble_state[reassemble_key] = reassemble_state[reassemble_key] or "" .. record.log reassemble_state[reassemble_key] = reassemble_state[reassemble_key] or "" .. record.log
return -1, 0, 0 return -1, 0, 0
end end
-- otherwise it's a full line, concatenate with accumulated partial lines if any
record.log = reassemble_state[reassemble_key] or "" .. (record.log or "") record.log = reassemble_state[reassemble_key] or "" .. (record.log or "")
reassemble_state[reassemble_key] = nil reassemble_state[reassemble_key] = nil
return 1, timestamp, record return 1, timestamp, record
end end
function nest_k8s_ns(tag, timestamp, record)
if not record['kubernetes']['namespace_name'] then
return 0, 0, 0
end
new_record = {}
for key, val in pairs(record) do
if key == 'kube' then
new_record[key] = {}
new_record[key][record['kubernetes']['namespace_name']] = record[key]
else
new_record[key] = record[key]
end
end
return 1, timestamp, new_record
end
serviceMonitor: serviceMonitor:
enabled: true enabled: true
namespace: monitoring namespace: monitoring