Log aggregation pipelines

Intermediate · 10 min

Get logs off every machine into one searchable store: collect, parse, filter, redact, label and ship them with an agent like Fluent Bit.

Before thisRunning services with systemdThe Linux server from an operator's seatMetrics with Prometheus

TechWorld with Nana · 10 min

Log aggregation pipelines

The player loads from youtube-nocookie.com when you press play. Nothing reaches YouTube before that.

Taught by TechWorld with NanaReport a problem with this video
Not started
Set this lesson's status

What you'll learn

  • Logs on the machine that wrote them are lost when the machine or container goes away, and are hard to search across fifty instances. A pipeline ships them to one store as they are written.
  • Every log pipeline has the same stages: input, parse, filter, enrich, and output, usually run by an agent on each node, with buffering so a slow backend doesn't lose data.
  • Parse at the edge into structured fields. A consistent shape across services, with the same names for timestamp, level and service, is what makes cross-service queries possible.
  • Redact secrets and personal data in the pipeline before they reach the store, because a log store is widely readable and kept for a long time.
  • Index few labels. Loki indexes only labels and greps the rest, so a label like request_id multiplies streams and cost, just as high-cardinality labels do in Prometheus.

The problem: logs live where they were written

On one server, logs are a file or the systemd journal, and journalctl or grep is enough. Now run the same service on fifty containers that come and go with autoscaling. A customer says checkout failed at 09:14. Which container served them? It may already be gone, and its logs with it. Even if all fifty still exist, nobody is going to SSH into each one.

A log aggregation pipeline fixes this by moving every log line, as it is written, to one central store you can search. The system design view explains why logs matter alongside metrics. On the application side, the backend roadmap’s structured logging lesson is about writing logs that are worth shipping. This lesson is the plumbing in between.

The stages

Every log pipeline, whatever the product, has the same stages. Think of a mail sorting office: collect from the boxes, read the addresses, throw out junk, stamp, and send to the right depot.

  1. Input: read from files (tailing /var/log/...), the systemd journal, container stdout, or a network port.
  2. Parse: turn a line of text into fields. JSON logs are already structured. Plain text needs a regex or a known format.
  3. Filter: drop what nobody will read, such as debug lines in production or health-check noise.
  4. Enrich and redact: add context the app doesn’t know (host, region, pod, service) and remove what must not leave the machine (passwords, tokens, card numbers).
  5. Output: send to the store, with buffering and retries so a slow or down backend causes delay, not loss.

An agent runs these stages on every node. Common choices are Fluent Bit (v5.2.1 when I checked), Vector, Grafana Alloy, or the OpenTelemetry Collector, which the next lesson covers. The store is Elasticsearch or OpenSearch with full-text indexing, Grafana Loki, or a cloud service such as CloudWatch Logs, Azure Monitor Logs or Google Cloud Logging.

A worked example: a pipeline in jq

I don’t have Fluent Bit here, but every stage is something jq and sed can do, so I built a toy pipeline in Bash. There are two sources. A web service writes JSON lines, including a debug line and an error that carelessly logs a card number. A worker writes plain text in a different timestamp format:

2026-11-27 09:14:02,700 WARNING retrying job 5521 (attempt 2)
2026-11-27 09:14:03,020 ERROR job 5521 failed: upstream timeout

The script parses the worker lines with a regex into the same fields as the web logs, normalizes WARNING to warn, adds service and host to everything, drops debug, masks the card number and sorts by timestamp:

$ ./pipeline.sh
{"ts":"2026-11-27T09:14:02.118Z","level":"info","msg":"request","path":"/cart","status":200,"ms":41,"service":"shop-web","host":"web-7"}
{"ts":"2026-11-27T09:14:02.700Z","level":"warn","msg":"retrying job 5521 (attempt 2)","service":"shop-worker","host":"web-7"}
{"ts":"2026-11-27T09:14:03.004Z","level":"error","msg":"payment failed","path":"/checkout","status":502,"ms":3012,"card":"****1111","service":"shop-web","host":"web-7"}
{"ts":"2026-11-27T09:14:03.020Z","level":"error","msg":"job 5521 failed: upstream timeout","service":"shop-worker","host":"web-7"}
{"ts":"2026-11-27T09:14:03.990Z","level":"info","msg":"request","path":"/checkout","status":200,"ms":388,"service":"shop-web","host":"web-7"}

Once both services share one shape, the timeline reads across them. The payment failed at 03.004 and the worker’s job failed 16 ms later with an upstream timeout. That is two symptoms of one problem, visible only because the logs sit side by side.

There is one bug I had to choose to accept. The worker’s timestamps have no time zone, and my regex simply labels them Z (UTC). If that worker actually logs local time, every event is misplaced by hours. Real pipelines need the source time zone set explicitly, and the better fix is making every service log in UTC.

The same pipeline in Fluent Bit

Here is a Fluent Bit configuration doing the same job, in its YAML format. I wrote it from the Fluent Bit documentation and did not run it, because Fluent Bit and Loki are not installed here:

pipeline:
  inputs:
    - name: tail
      path: /var/log/shop/web.log
      parser: json
      tag: shop.web
  filters:
    - name: grep
      match: "shop.*"
      exclude: level debug
    - name: record_modifier
      match: "shop.*"
      record: host ${HOSTNAME}
  outputs:
    - name: loki
      match: "shop.*"
      host: loki.internal
      labels: service=shop-web, env=prod

Note the labels line. Loki indexes only labels and stores the log text compressed, searching it by brute force at query time. That keeps it cheap, but it means labels must be few and low-cardinality, such as service, env and level. Putting request_id or user_id in labels creates a new stream per value. Keep those as fields in the log line and filter on them in the query.

About the video

“Fluent Bit explained | Fluent Bit vs Fluentd” is from TechWorld with Nana, published April 2021, 9 minutes 58 seconds. It was sponsored by the CNCF, which hosts Fluent Bit. Its chapters cover why log data matters, the challenges of logging in general and in Kubernetes, how Fluent Bit works, and how it compares with Fluentd. That matches this lesson’s pipeline stages. It is from 2021, Fluent Bit has had several major releases since, and the YAML config format above is newer than the video. English is judged from the title, description and channel. Grafana’s “Intro to Logging” covers log types and common problems from the Loki side.

Where this fits

Metrics and logs each have their own agent so far. OpenTelemetry offers one standard and one collector for metrics, logs and traces together: OpenTelemetry and the collector.

Check yourself

  1. 01Why not just SSH into the machine and read the log file?

    With many instances you don't know which one has the relevant line, containers and autoscaled VMs delete their logs when they go away, and you cannot correlate events across services by hand.

  2. 02Where in the pipeline should you remove card numbers and tokens from logs, and why there?

    In the collecting agent, before shipping. Once the data reaches the central store it is copied, indexed and retained, and many people can read it.

  3. 03Two services log timestamps in different formats and time zones. What should the pipeline do?

    Parse both into one format, normally UTC ISO 8601, so events from both services sort and correlate correctly.

  4. 04What is the difference between Fluent Bit and Fluentd?

    Both are CNCF log processors from the same family. Fluent Bit is a small C program suited to running on every node, and Fluentd is a heavier Ruby-based aggregator with a large plugin ecosystem. Many setups use Fluent Bit on the nodes and send to Fluentd or a store.

Go deeper

Notes

Private to you

Esc
↑↓ navigate↵ open? shortcuts

Keyboard shortcuts

Press Esc to close

Anywhere

⌘K
Search and commands
/
Search
?
This sheet
Esc
Close

Reading a lesson

J
Next lesson
K
Previous lesson
B
Bookmark