Skip to content

Lesson 5 of 13 · 13m

Parsing Is Where Pipelines Die

Grok's CPU cost, JSON logs that aren't, and why enriching at ingest fossilizes stale threat intel into the permanent record.

Parsing is where pipelines die, and they die in two ways: regexes that cost more than the events they parse, and enrichments that fossilize stale intelligence into the record.

Grok is regex, and regex is CPU

Logstash/ingest-pipeline grok patterns are regular expressions with named captures. A hand-rolled grok against a long unstructured line can dominate index throughput — Logstash deployments have been measured spending most CPU in grok, not in indexing. The alternatives exist for a reason: dissect splits on literal delimiters and is dramatically cheaper for fixed-format lines; kv handles key=value streams without a pattern at all. The discipline: profile the pipeline on real traffic, and write grok only for genuinely free-form text. A pattern with alternation and optional groups that can match empty strings is a catastrophic-backtracking candidate waiting for one malformed line. One malformed log line pinning an ingest worker for seconds is a throughput cliff that looks, from the outside, exactly like the source going quiet.

JSON logs look easier and carry their own trap: producers emit valid JSON until they hit an error path, then write a bare stack trace line into the same file. A parser that assumes "every line is one JSON object" drops exactly the lines that matter — the errors. Handle the multiline and the not-JSON case in the parser, or lose them silently. The same goes for timestamps inside JSON: ts, timestamp, time, @t — producers are inconsistent, and the field your parser picks becomes @timestamp downstream.

Enrichment is a join against a moving table

The three standard enrichments:

  • GeoIP — MaxMind GeoLite2. Since December 2019 the free database requires a license account; pipelines that hard-coded the old public download URL broke on that date. IP-to-country data also drifts as blocks are reallocated.
  • Asset inventory — joining host to a CMDB row: owner, criticality, tier. This is what turns "powershell.exe on WEB01" into "powershell.exe on the payment-tier web server" — and it's only as good as the CMDB's freshness. A server re-purposed last quarter keeps its old enrichment until someone updates the source of truth.
  • Threat intel — IOC lists joined against IPs, domains, hashes.

The trap is when you join. Enrich at ingest and the event permanently records "IP 203.0.113.5 = benign" even after that IP lands on an abuse list next week. The intel moved; the stored event didn't. Query-time enrichment against current intel — or scheduled re-enrichment of recent windows — is the honest approach. An IOC's useful life is measured in days; the event's retention is measured in years. Joining them once, forever, is how investigations conclude "that traffic was fine" about traffic that wasn't. The MOVEit exploitation wave in May–June 2023 (CVE-2023-34362) produced infrastructure lists that changed daily; an ingest-time join stamped a verdict that was obsolete before the weekend.

The discipline that holds

Order the pipeline: extract first, enrich second, alert last — a detection rule running before enrichment fires on unannotated data. Emit a parse-failure counter per source: events that reached the index unparseable are invisible to every rule, and a spike in that counter is the only signal that a source changed format. And write the parser test before the parser: one real line from the source, committed to version control, run in CI. Sources change format without notice — a firmware update, a vendor schema bump — and the parse-failure counter is the only thing that tells you.

The schema-version bump nobody ships notes for

Vendors bump their log schemas quietly — a new field position in a CSV export, a renamed key in a JSON line, a syslog message whose middle changed. The parse-failure counter catches total breakage; the subtler failure is a field that still parses but now holds different semantics — same name, different units. Diff a sample of parsed events against last quarter's field histogram when you suspect drift; values change before formats do.

Was this lesson helpful?

Sign in to rate

Keep reading

Related articles from the SudoSecurity blog.