Skip to content

feat: added sidecar to turn logs into metrics and forward remaining logs MAPCO-11460 - #59

Merged
syncush merged 22 commits into
masterfrom
metrics-sidecar
Aug 25, 2026
Merged

feat: added sidecar to turn logs into metrics and forward remaining logs MAPCO-11460#59
syncush merged 22 commits into
masterfrom
metrics-sidecar

Conversation

@CptSchnitz

Copy link
Copy Markdown
Contributor

No description provided.

@CptSchnitz
CptSchnitz requested a review from shimoncohen August 6, 2026 10:19
shimoncohen

This comment was marked as duplicate.

Comment thread helm/config/nginx.conf Outdated
CptSchnitz and others added 4 commits August 12, 2026 11:24
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 syncush left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 deepCopy to prevent mutating shared .Values.
  • Comprehensive local test harness (test/local) with Docker Compose, otel-collector, and lgtm stacks 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.

@syncush

syncush commented Aug 16, 2026

Copy link
Copy Markdown

Plus you are missing MAPCO-# in your title, add the workflow

@CptSchnitz CptSchnitz changed the title feat: added sidecar to turn logs into metrics and forward remaining logs feat: added sidecar to turn logs into metrics and forward remaining logs MAPCO-11460 Aug 18, 2026
@github-actions

github-actions Bot commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

🎫 Related Jira Issue: MAPCO-11460

@CptSchnitz
CptSchnitz requested a review from shimoncohen August 18, 2026 12:49
@ronenkapelian
ronenkapelian removed the request for review from shimoncohen August 25, 2026 06:08
@syncush
syncush merged commit 6a93be1 into master Aug 25, 2026
4 checks passed
@syncush
syncush deleted the metrics-sidecar branch August 25, 2026 08:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants