Skip to main content

Parsers and processors

Grok runs on compiled regex at almost every call site. Three whole-pattern forms take a native path instead, and the composite builder and DFA fallback in dfe-parse are built but not called by any transform. This page covers that dispatch, every ingest processor the transforms use, and how far the Painless matchers reach. The step these run in is Transform, and the libraries are performance.md.

grok_cache::native_form recognises whole-pattern forms and rejects a near-miss rather than guessing at one: a pattern with literal text around its captures stays on the regex.

A grok call site in a native form skips the regex, and every other site runs its compiled regex.

Figure 1. L4 Detail -- Grok dispatch. Up: L4 Detail -- Transform.

PatternPathNative against regex
^%{IPV4:f}$dfe_parse::ip::parse_ipv429 ns against 214 ns
^%{IPV4:a}:%{PORT:p}$the two chained47 ns against 208 ns
%{GREEDYDATA:f}, anchored or notsplit_once('\n')11 ns against 1,098 ns

The timings come from cargo bench -p dfe-runtime --bench grok. The third form reaches no parser: line_anchored makes it (?m)^.*$ because joni anchors to lines, so it captures the first line and the native form is a newline scan. Count the sites from the generated tree (cached_grok! and cached_grok_mapped!) rather than from a figure written here.

^%{DATA:f}$ is excluded although it reads the same: %{DATA} is the lazy .*?, and on a \r\n line ending greedy keeps the \r in the capture where lazy stops before it. Every dispatched form has an equivalence test running both paths over the same inputs, because the native path is an optimisation over the regex and never a replacement for it.

dfe-parse holds more than the dispatch uses. Layer 1 is native parsers for 15 common grok patterns, in ip.rs, network.rs, numeric.rs, string.rs and timestamp.rs:

Grok patternRust parserTechnique
%{IPV4}parse_ipv4()Octet validation, direct byte scan
%{IPV6}parse_ipv6()Colon-group parser
%{IPORHOST}parse_ip_or_host()Try IP first, fall back to hostname
%{INT}parse_int::<T>()Direct digit scan, generic over type
%{NUMBER}parse_number()Integer or float with optional exponent
%{WORD}take_word()Byte-level alphanumeric scan
%{GREEDYDATA}take_greedy()Returns the remaining slice
%{TIMESTAMP_ISO8601}parse_iso8601()Fixed-position field extraction
%{SYSLOGTIMESTAMP}parse_syslog_timestamp()Month lookup table and digit parse
%{LOGLEVEL}parse_loglevel()Case-insensitive keyword match
%{QUOTEDSTRING}take_quoted()memchr for the quote, handles escapes
%{HOSTNAME}parse_hostname()Label-dot-label (RFC 1123)
%{MAC}parse_mac()Fixed 6-group hex parse
%{URI}parse_uri()scheme://authority/path?query#fragment
%{UUID}parse_uuid()Fixed 8-4-4-4-12 hex pattern

Every parser takes &str and returns ParseResult<'_, T>, the remaining input and the parsed value, following the winnow and nom convention:

pub type ParseResult<'a, T> = Result<(&'a str, T), ParseError>;

Layer 2, composite.rs, chains Layer 1 parsers with literal separators. Layer 3, dfa.rs, wraps regex_automata::meta::Regex and returns named captures. Both are built and tested in dfe-parse, and no transform calls either.

// Grok: %{IPORHOST:source_ip}:%{INT:source_port} -> %{IPORHOST:dest_ip}:%{INT:dest_port}
let parser = CompositeParser::builder()
.capture("source_ip", parse_ip_or_host)
.literal(":")
.capture("source_port", parse_int::<u16>)
.literal(" -> ")
.capture("dest_ip", parse_ip_or_host)
.literal(":")
.capture("dest_port", parse_int::<u16>)
.build();

Processor taxonomy​

Every processor the transforms use, and the code the generator emits for it.

ProcessorWeightCode pattern
set, append, remove, renameSimpleevent.set, event.append, event.remove, event.rename
uppercase, lowercase, trimSimpleRead the string, write it back changed
convertSimpleconvert_value to string, integer, long, float, double, boolean or ip
dropSimpleReturns TransformResult::Drop
splitSimpleSplits a string into an array
joinSimplejoin_values(value, sep), None on a non-array
uri_partsSimpleScheme, host, port, path and query components
dot_expanderSimpledot_expand(event, path, field)
failSimpleReturns a TransformError with the message
terminateSimpleStops the pipeline and keeps the document
urldecodeSimpleurl_decode, form-encoded so + is a space
sortSimplesort_values, an error on anything with no natural order
html_stripSimplehtml_strip
grokMediumcached_grok!, one compiled pattern per call site, on regex or fancy-regex
dissectMediumTokenizer-based split
jsonMediumcodegen_api::parse_json_str, on serde_json
kvMediumKey-value split with configurable delimiters
csvMediumThe csv crate, with the processor's separator and quote
foreachMediumEach element bound to _ingest._value, the inner processor run, the list rebuilt
dateMediumparse_date_out against the formats the processor names
gsubMediumA cached regex replace_all
script (Painless)ComplexA matched runner, or counted and skipped. See below
geoipComplexenrichment::geoip
user_agentComplexenrichment::user_agent
community_idComplexenrichment::community_id
registered_domainComplexcodegen_api::registered_domain_lookup, a psl lookup against Mozilla's Public Suffix List
network_directionComplexCIDR-based internal and external classification
fingerprintComplexfingerprint_default (SHA-1, base64, NUL before each value), or fingerprint_with for a salt and SHA-256, SHA-512 or MurmurHash3. Any other method fails
pipeline (nested)ComplexInlined into the caller, not a call. rg -l "Begin nested pipeline" lists the modules

Not implemented, and used by no shipped pipeline: bytes, cef, date_index_name, enrich, geo_grid, inference, redact, reroute and set_security_user.

Painless coverage​

A script the runtime cannot execute is skipped rather than failing the event, so the skips are counted, or they would look like a script that did nothing. painless_exec lives in crates/dfe-painless/src/plan.rs and is re-exported through crates/dfe-runtime/src/codegen_api.rs. It resolves a hand-written runner from crates/dfe-painless/src/bespoke/ first, then the params patterns in params.rs, then the known_patterns ladder in common.rs, and records the outcome through crates/dfe-painless/src/stats.rs. The service exports the outcome as painless_handled_total and painless_unhandled_total.

A generated call site holds no script. The generator resolves the dispatch and emits compiled_painless! with the script's hash and that plan as JSON, plus the normalised text where a bound runner still reads it. The runtime looks bespoke runners up by the hash, and the counters key each script by it.

crates/dfe-transforms/tests/painless_binding.rs reads every plan out of the generated tree and asks what it binds to, which says a script is claimed but not that the runner writes anything. The two counters say what ran on live traffic. A pattern can match a script statically and decline at run time, which reads as covered everywhere except those counters.