grippo 0.2.2

Parse, match and scrub data faster and more efficiently.
Documentation
# grippo

Parse, match and scrub data faster and more efficiently.

<!-- BADGES:START -->
[![Build Status](https://github.com/hyperi-io/grippo-rs/actions/workflows/ci.yml/badge.svg)](https://github.com/hyperi-io/grippo-rs/actions)
[![Crates.io](https://img.shields.io/crates/v/grippo?logo=rust)](https://crates.io/crates/grippo)
[![Rust Version](https://img.shields.io/crates/msrv/grippo?logo=rust)](Cargo.toml)
[![License](https://img.shields.io/badge/license-Apache--2.0-green)](https://www.apache.org/licenses/LICENSE-2.0)
<!-- BADGES:END -->

grippo is a Rust library for parsing, matching, filtering and scrubbing data from any source: logs, events, JSON, XML, or a format you compose yourself. It tells you how each rule will run before you run it. Built for at-scale *speed* and *efficiency*.

## Primitives, and what they cost

grippo is built from typed primitives, one per sub-pattern: a literal, an IPv4 address, a timestamp, a run of non-space. Each matches one thing and nothing else, so it doesn't carry a general engine's machinery.

Compose them. `compose` joins primitives into a parser with no pattern text:

```rust
use grippo::compose::{field, literal, until};

let parser = literal("<")
    .then(field("NONNEGINT").named("pri"))
    .then(literal(">"))
    .then(until(" ").named("host"))
    .then(field("GREEDYDATA").named("msg"))
    .build("compose:pri")?;
```

That's the route to take for a new format. A composed parser runs on the same steps as the grok pattern it mirrors, gives the same fields, and costs no more.

Every matcher and parser reports a worst-case tier: `Fixed`, `Byte`, `Literal`, `LiteralSet`, `Field`, `Regex` or `Backtracking`, cheapest first. Most also report a cost in ns, measured on our bench host. A build can reject any pattern below the tier you set, so a slow rule fails when it loads.

[docs/compose.md](docs/compose.md) has the parts, and [docs/field.md](docs/field.md) the scanners.

## Grok and regex

Most rules are written as grok or regex today. grippo runs each pattern on the cheapest tier that gives the same answer, and stops there. The regex engine runs only for a pattern nothing cheaper can take. On our rule corpus that's 35 of 2,445 grok patterns (29 Nov 2026).

```mermaid
---
config:
  theme: base
  look: neo
  fontFamily: Inter, -apple-system, Segoe UI, Roboto, Helvetica, Arial, sans-serif
  flowchart:
    curve: linear
    nodeSpacing: 40
    rankSpacing: 64
    padding: 18
    wrappingWidth: 280
    htmlLabels: true
  elk:
    preset: modelOrder
  themeVariables:
    fontSize: 15px
    lineColor: "#64748B"
    primaryTextColor: "#0F172A"
    nodeBorder: "#334155"
    clusterBorder: "#0072B2"
    edgeLabelBackground: "#FFFFFF"
  themeCSS: >-
    p{margin:0}
    .node[data-look] rect,.node[data-look] path,.node[data-look] polygon,.node[data-look] .outer-path{filter:drop-shadow(0 1px 2px rgba(15,23,42,.10)) drop-shadow(0 6px 14px rgba(15,23,42,.10))}
    .node rect{rx:10px;ry:10px}
    .cluster rect{rx:16px;ry:16px}
    .node .label div{min-width:150px}
    .node.decision .label div{min-width:0}
    .cluster[data-look] rect{filter:none}
    .nodeLabel{line-height:1.35}
    .nodeLabel b{font-weight:600;font-size:15px;letter-spacing:-0.01em}
    .nodeLabel span{font-size:12.5px;font-weight:400;color:#334155}
    .cluster-label span.nodeLabel{display:inline-block;background:#FFFFFF;color:#0B2A3F;border:1.5px solid #0072B2;border-radius:999px;padding:2px 12px;font-size:11.5px;font-weight:700;letter-spacing:.09em;text-transform:uppercase}
    .flowchart-link{stroke-width:1.75px}
    .labelBkg{background:transparent!important}
    span.edgeLabel{display:inline-block;background:#FFFFFF!important;color:#1E293B;border:1px solid #94A3B8;border-radius:999px;padding:2px 10px;font-size:12px;font-weight:500}
    span.edgeLabel p{background:transparent!important}
    .label-icon{width:20px;height:20px;vertical-align:-4px;margin-right:6px}
    .icon-shape path[stroke-width="0"][fill="none"]{fill:#FFFFFF;stroke:#FFFFFF;stroke-width:12px;stroke-linejoin:round}
    .icon-shape p{background:transparent!important;color:#0F172A}
    .ingest .label-icon{color:#0E8A7D}
    .xform .label-icon{color:#7B4FB0}
    .load .label-icon{color:#0072B2}
    .bus .label-icon{color:#A8517F}
    .store .label-icon{color:#00785A}
    .ui .label-icon{color:#D9480F}
    .ext .label-icon{color:#64748B}
---
flowchart LR
  accTitle: L4 Detail -- Where a pattern runs
  accDescr: A pattern runs on the first tier that can answer it. One byte or a set of literals is a scan, with no engine. A grok or regex pattern that lowers runs on the field scanners, as native steps or generated code. Only a pattern neither can take falls back to the regex engine, and backtracking runs only when a build turns it on.
  lit{"<b>Byte or literals?</b>"}
  scan("<b>Byte or literal scan</b><br/><span>memchr, aho-corasick</span>")
  lowers{"<b>Lowers?</b>"}
  steps("<b>Field scanners</b><br/><span>native steps or generated code</span>")
  regex("<b>Regex engine, fallback</b><br/><span>regex-automata</span>")
  back("<b>Backtracking</b><br/><span>fancy-regex, opt-in</span>")
  lit -->|"yes"| scan
  lit -->|"no"| lowers
  lowers -->|"yes"| steps
  lowers -->|"no"| regex
  regex -.->|"lookaround, backrefs"| back
  class regex,back ext
  class lit,lowers decision
  class scan,steps part
  %% merrow:begin
  classDef ingest fill:#FFFFFF,stroke:#0E8A7D,stroke-width:3px,color:#0F172A
  classDef xform fill:#FFFFFF,stroke:#7B4FB0,stroke-width:3px,color:#0F172A
  classDef load fill:#FFFFFF,stroke:#0072B2,stroke-width:3px,color:#0F172A
  classDef bus fill:#FFFFFF,stroke:#A8517F,stroke-width:3px,color:#0F172A
  classDef store fill:#FFFFFF,stroke:#00785A,stroke-width:3px,color:#0F172A
  classDef ui fill:#FFFFFF,stroke:#D9480F,stroke-width:3px,color:#0F172A
  classDef ext fill:#F4F6F8,stroke:#94A3B8,stroke-width:1.5px,stroke-dasharray:5 4,color:#0F172A
  classDef decision fill:#FFFFFF,stroke:#9A6700,stroke-width:3px,color:#0F172A
  classDef error fill:#FFFFFF,stroke:#C2410C,stroke-width:3px,color:#0F172A
  classDef control fill:#FFFFFF,stroke:#334155,stroke-width:3px,color:#0F172A
  classDef part fill:#FFFFFF,stroke:#94A3B8,stroke-width:1.5px,color:#0F172A
  %% merrow:end
```

*Figure 1. L4 Detail -- Where a pattern runs.* Up: [L3 Components -- grippo](docs/architecture.md).

- `strmatch` takes a regex or a glob, and answers one that is a byte, a literal or a fixed list of literals with a byte scan, a literal search or one literal-set automaton. No regex engine runs unless you ask for groups, and then only on a hit.
- `grok` lowers a grok pattern or a plain regex onto the `field` scanners. A pattern with no `%{...}` is a regex, and its named groups are the fields. `%{IPV4}`, `%{TIMESTAMP_ISO8601}`, `\d+`, `[^ ]+` and the rest each run on a scanner exact to the regex. `grok!` compiles a fixed pattern into calls to them when your crate builds.
- Anything else falls back to the regex engine, regex-automata, with the same answer. `tier()` and `Grok::explain()` say which tier a pattern landed on and why, and a build can reject anything that falls back.

So porting a rule set needs no rewrite (though we do recommend you do that if you have time, it pays off).

Compiled stock grok patterns on our bench host (28 Nov 2026), against a DFA in front of PCRE2-JIT:

| Line | grippo | DFA + PCRE2-JIT | PCRE2-JIT alone |
| --- | --- | --- | --- |
| access log, hit | 326 ns | 621 ns | 253 ns |
| syslog, hit | 166 ns | 554 ns | 148 ns |
| access log, late miss | 118 ns | 178 ns | 3,758 ns |

PCRE2-JIT alone is quicker on a hit, but it pays heavily on a line that fails late, which is why it gets a DFA in front. Your mileage will vary with your data, so measure on your own lines before you plan capacity.

[docs/grok.md](docs/grok.md) and [docs/strmatch.md](docs/strmatch.md) have the detail. [docs/performance.md](docs/performance.md) has the method, the misses and the firewall line.

## Formats and nesting

Stock parsers for syslog, CEF, LEEF, NDJSON, GELF, XML, CSV, key=value and logfmt, dissect, CRI, web access logs, URIs, query strings, Prometheus text and AWS load balancer, S3 and VPC flow logs, each behind a `parse-*` feature. Each is a layer, and layers nest. A chain is written as `syslog > cef`: the syslog parser hands its message to the CEF parser without copying it, and both write fields to your sink. A value is copied only when it has to be unescaped. INI, `.properties`, `.env`, YAML, TOML, HTTP, MessagePack, protobuf and OTLP run on maintained crates, because they don't need our speed. Decoders (base64, hex, gzip, zlib, zstd, snappy) are layers that hand on the bytes they decode: `ndjson > field("payload"):base64 > gzip > ndjson`.

```sh
cargo add grippo --features parse-syslog,parse-cef
```

```rust
use grippo::format::register_stock;
use grippo::parse::{Fields, ParsePlan, Parsers, Status};

fn main() {
    let mut parsers = Parsers::new();
    register_stock(&mut parsers).unwrap();
    let plan = ParsePlan::chain("syslog > cef", &parsers).unwrap();
    let mut state = plan.source_state();
    let line =
        b"<13>Nov  6 08:01:02 fw01 CEF:0|Acme|Wall|1|100|blocked|7|src=10.1.2.3 act=deny";
    let mut out = Fields::new();
    let outcome = plan.parse(line, &mut state, &mut out);
    assert_eq!((outcome.status, outcome.layers), (Status::Parsed, 2));
    let get = |n: &str| {
        out.get(n)
            .map(|v| String::from_utf8_lossy(&v.bytes).into_owned())
    };
    assert_eq!(get("hostname").as_deref(), Some("fw01"));
    assert_eq!(get("cef.device_vendor").as_deref(), Some("Acme"));
    assert_eq!(get("cef.act").as_deref(), Some("deny"));
}
```

Build the plan once per source. The parsers you name are the ones that run, and a chain naming one your build left out fails when it compiles, with the feature to turn on. `full` turns on every format and decoder. Detection is opt-in, a hop at a time:

| Chain | What runs |
| --- | --- |
| `syslog > auto` | syslog, then the parser the message's content names |
| `auto*` | Detect the record, then every body and value below it |
| `ndjson > field("event"):cef` | JSON, then the value it wrote as `event`, as CEF |

[docs/parse.md](docs/parse.md) has chains and sinks, [docs/formats.md](docs/formats.md) each format, and [docs/xml.md](docs/xml.md) XML to JSON records as the bytes arrive.

## CEL filters

`expr` runs CEL filter expressions as grippo checks, with no CEL interpreter. The record can be raw JSON, a text line, or the fields a parser chain wrote, so a filter reads straight off the layers above. The result is the one cel 0.14.5 gives, errors included: our tests run 4,096 generated filters through cel as well and compare.

```rust
use grippo::expr::{Outcome, Program};

let p = Program::compile(r#"event.dns.type == "query" || event.dns.type == "answer""#)?;
assert_eq!(p.eval(br#"{"event":{"dns":{"type":"answer"}}}"#), Outcome::True);
```

Lowered filters run 21 to 75 times as fast as cel's interpreter on small records. A filter outside the subset is refused when it compiles, so you know before it runs. [docs/expr.md](docs/expr.md) has the subset and the figures.

## Scrub

`scrub` finds secrets, credentials and PII, and masks or hashes each. Secrets use gitleaks' rules plus your own, and credentials are found by field name and in `key=value` text. PII is email addresses, card numbers, IBANs, phone numbers (with `scrub-phone`) and Australian ABN, ACN, TFN and Medicare numbers, each confirmed by its own check such as Luhn. It works on any record grippo reads, through any chain of layers in the stock formats, and writes each masked value back into the layer it came from, escaped for that format. It runs over every layer, or the one you scope it to. A find inside a decoded layer is an error.

You get the record back rewritten in place, or as a new copy when anything changed, and a report counting finds by rule that never holds a value. Build one `Scrubber` and share it across threads. [docs/scrub.md](docs/scrub.md) has the rules, the scope and the report.

## Build it right or it runs slow

Add grippo to a default build and it runs slower than our figures. Cargo never applies a dependency's build config to your binary, so these go in YOUR workspace:

```toml
# .cargo/config.toml
[target.x86_64-unknown-linux-gnu]
rustflags = ["-C", "target-cpu=x86-64-v3", "-C", "target-feature=+pclmulqdq"]

# Cargo.toml
[profile.release]
lto = "fat"
codegen-units = 1
```

- Without the CPU flags, sonic-rs and other crates in the tree fall back to plain loops, with no warning. aarch64 needs no flags.
- Then a profile-guided build (PGO), and BOLT on top. PGO alone took 8-28% off grok parsing. PGO and BOLT together took 300 JSON lines from 321 to 269 us.
- v3 needs Haswell (2013), Excavator (2015) or newer. On an older CPU the binary crashes with SIGILL.

[docs/build-optimisation.md](docs/build-optimisation.md) has the full recipe.

## Documentation

- API reference: <https://docs.rs/grippo>
- [docs/architecture.md](docs/architecture.md): the parts and how a record moves through them.
- [docs/parse.md](docs/parse.md), [docs/formats.md](docs/formats.md), [docs/grok.md](docs/grok.md), [docs/strmatch.md](docs/strmatch.md) and [docs/field.md](docs/field.md): parsers and primitives.
- [docs/record.md](docs/record.md): the record a filter or scrub reads, from JSON, text, XML or parser fields.
- [docs/expr.md](docs/expr.md), [docs/scrub.md](docs/scrub.md) and [docs/xml.md](docs/xml.md): CEL filters, redaction and XML.
- [docs/async.md](docs/async.md): threads, tokio and what to share.
- [docs/performance.md](docs/performance.md): every bench, its numbers and what they decided.

The default features are `strmatch` and `parse`. Each stock format, grok, scrub and XML sits behind its feature flag, so a build holds just what it uses. [docs/feature-flags.md](docs/feature-flags.md) has the full list.

## Help, contributing and licence

A bug or a question goes in an [issue](https://github.com/hyperi-io/grippo-rs/issues). [CONTRIBUTING.md](CONTRIBUTING.md) has how to work in this repo and the commands that test a change. Security reports follow [SECURITY.md](SECURITY.md).

[Apache-2.0](LICENSE). Third-party attributions are in [NOTICE](NOTICE).

---

"If you want to spot an at scale amateur, look for a grok or regex on the hot path" - this crate helps you solve that problem.

You need your grippo in the wet.