feat: added sidecar to turn logs into metrics and forward remaining logs MAPCO-11460 - #59
Conversation
…nt and resource limits - step 1
638b63b to
ce005a9
Compare
fluentbit.lua.call becomes fluentbit.lua.calls.allRecords and fluentbit.lua.calls.forwardedOnly, both empty by default. Each non-empty call renders its own lua filter against the same mounted script, so a field the script computes at allRecords — which runs after the exclude grep but ahead of log_to_metrics and the forwarding grep — can be an add_label or value_field accessor in accessLog.metrics.filters. forwardedOnly keeps the hook's existing position, where decoration-only logic pays for Lua on the shipped subset only. Enabling the hook without naming an entry point mounts a script nothing calls, so it fails the render instead. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
fluentbit.lua.configMap.name/key mount a ConfigMap the operator maintains outside the release at the same /fluent-bit/scripts/custom.lua the filters name, so nothing downstream of the mount changes. It is an alternative to the inline fluentbit.lua.script, not an addition: nginx.fluentbit.luaSource decides which of the two is in play — and fails the render on both, neither, or a named ConfigMap without a key — so the ConfigMap key, the volume and the mount all branch on one answer. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
syncush
left a comment
There was a problem hiding this comment.
Summary & Overall Impressions
Great work on this PR! The architecture for the Fluent Bit log-processing sidecar is very clean and well thought out:
- Clean separation between stdout logging (human-readable or JSON) and internal syslog log forwarding.
- Safe helper functions using
deepCopyto prevent mutating shared.Values. - Comprehensive local test harness (
test/local) with Docker Compose,otel-collector, andlgtmstacks for local verification.
Here are a few observations and recommendations for improvement:
1. Nginx Error Log Regex Parser (helm/config/fluent-bit.yaml)
In helm/config/fluent-bit.yaml:
regex: '^(?:(?<time>\d{4}/\d{2}/\d{2} \d{2}:\d{2}:\d{2}) )?\[(?<level>\w+)\] (?<pid>\d+)#\d+:(?: \*\d+)? (?<message>.*?)(?:, client: (?<client>[^,]+), server: (?<server>[^,]*), request: "(?<request>[^"]*)".*)?$'Observation:
The tail fields (, client: ..., server: ..., request: ...) are currently enclosed in a single contiguous optional non-capturing group.
In Nginx, errors that occur before a request line is negotiated (e.g. SSL handshake failures, early connection drops, TLS alert errors, client timeouts during connect) log client: and server: but omit request:. Because request: is missing in those lines, the entire optional group fails to match, and the client and server fields are not extracted into attributes (they remain trapped inside the lazy message field).
Suggested Fix:
Split each optional field into its own sequential optional group so client and server are extracted even when request is absent:
- regex: '^(?:(?<time>\d{4}/\d{2}/\d{2} \d{2}:\d{2}:\d{2}) )?\[(?<level>\w+)\] (?<pid>\d+)#\d+:(?: \*\d+)? (?<message>.*?)(?:, client: (?<client>[^,]+), server: (?<server>[^,]*), request: "(?<request>[^"]*)".*)?$'
+ regex: '^(?:(?<time>\d{4}/\d{2}/\d{2} \d{2}:\d{2}:\d{2}) )?\[(?<level>\w+)\] (?<pid>\d+)#\d+:(?: \*\d+)? (?<message>.*?)(?:, client: (?<client>[^,]+))?(?:, server: (?<server>[^,]+))?(?:, request: "(?<request>[^"]*)")?.*$'2. ConfigMap Multi-line Readability (helm/templates/fluentbit-configmap.yaml)
In helm/templates/fluentbit-configmap.yaml:
data:
fluent-bit.yaml: {{ tpl (.Files.Get "config/fluent-bit.yaml") . | quote }}
metadata.lua: {{ tpl (.Files.Get "config/metadata.lua") . | quote }}Observation:
Using quote renders multi-line files as single escaped strings with \n. While valid Kubernetes YAML, it makes inspection via kubectl get configmap <name> -o yaml harder to read and debug.
Suggested Fix:
Using standard YAML block scalars (|) keeps the rendered files nicely formatted:
data:
- fluent-bit.yaml: {{ tpl (.Files.Get "config/fluent-bit.yaml") . | quote }}
+ fluent-bit.yaml: |
+ {{- tpl (.Files.Get "config/fluent-bit.yaml") . | nindent 4 }}
# Chart-owned Lua; fluent-bit.lua below is the operator's, on its own key and mount.
- metadata.lua: {{ tpl (.Files.Get "config/metadata.lua") . | quote }}
+ metadata.lua: |
+ {{- tpl (.Files.Get "config/metadata.lua") . | nindent 4 }}3. JSON Decode Guard Note (helm/config/fluent-bit.yaml)
The grep filter guard:
- name: grep
match: nginx.access
regex: "$Attributes['http.response.status_code'] ."This is a great safeguard against sidecar crashes caused by log_to_metrics on missing fields. Just worth keeping in mind that any access log line that fails JSON parsing will be dropped rather than forwarded to Loki.
|
Plus you are missing MAPCO-# in your title, add the workflow |
|
🎫 Related Jira Issue: MAPCO-11460 |
No description provided.