Skip to main content

DFE Expression Language -- CEL

DFE uses CEL (Common Expression Language) for conditions across the Python engine, the Rust services and the CLI. CEL is not Turing-complete: no loops, no recursion, no side effects, so every expression terminates. An expression is compiled once and evaluated against every row.

LanguagePackageNotes
RustcelNative implementation, through scalo::expression
Pythoncommon-expression-languagePyO3 bindings, through scalo.expression

scalo-rs's Cargo.toml and scalo-py's pyproject.toml carry the versions.

References:


CEL does not replace these:

SystemReason
@directive: body DSL (@source, @generated, etc.)Schema metadata -- column mapping instructions, not boolean conditions
ClickHouse SQL in @generated expressionsRuns in ClickHouse, not our evaluator
Hunt SQL queries / rule_rewriterClickHouse-native SQL
Duration strings ("1h", "30m")Simple config values, not expressions

The DFE expression profile​

DFE uses a subset of CEL. Expressions outside this profile are rejected at validation time.

Allowed operations:

CategoryOperationsExamples
Comparison==, !=, <, <=, >, >=severity == "critical"
Logical&&, ||, !amount > 1000 && !is_test
Membershipinstatus in ["active", "pending"]
Arithmetic+, -, *, /, %price * quantity
Ternary? :is_admin ? 95 : 50

Allowed functions:

FunctionPurposeExample
contains()Substring checkmessage.contains("error")
startsWith()Prefix checkpath.startsWith("/api/")
endsWith()Suffix checkfile.endsWith(".log")
matches()Regex match. A hunt rule's filter takes it. An alert condition takes it only when the config cascade sets expression.allow_regex: truehostname.matches("^web-[0-9]+$")
size()Length of string or listsize(tags) > 0
has()Field existencehas(event.user_id)
int()Cast to integerint(port_str) == 443
double()Cast to floatdouble(score_str) > 0.5
string()Cast to stringstring(code) == "200"
bool()Cast to booleanbool(enabled)

Rejected at validation:

FeatureReason
map(), filter(), exists(), all()Per-element iteration -- unpredictable performance on large lists
timestamp(), duration()ClickHouse handles time natively -- no need to duplicate
MacrosComplexity with no benefit for DFE use cases

Supported types:

CEL TypePythonRustClickHouse
intinti64Int64
doublefloatf64Float64
stringstrStringString
boolboolboolBool
listlistVec<Value>Array
mapdictHashMap<String, Value>--
nullNoneOption::NoneNullable

Where DFE uses it​

An alert trigger:

alerts:
triggers:
- when: "result_count >= 10"

A trigger sees result_count, the rows the fire wrote, and nothing else. A trigger on a row field never fires.

A source selects its records with when, a CEL condition, in place of match. The receiver evaluates it against every inbound record under its CEL Fast profile, so regex, iteration and time functions are refused at save. See source-definition.md.

when: "data_stream.dataset == 'cisco_ios.log' && agent.type == 'filebeat'"

A computed column in the loader:

columns:
risk_label:
expr: '@computed: risk_score > 80 ? "high" : risk_score > 40 ? "medium" : "low"'

CEL expressions can be mechanically converted to ClickHouse WHERE clauses for query pushdown:

CELClickHouse SQL
severity == "critical"severity = 'critical'
amount > 10000 && !is_testamount > 10000 AND NOT is_test
status in ["active", "pending"]status IN ('active', 'pending')
message.contains("error")position(message, 'error') > 0
path.startsWith("/api/")startsWith(path, '/api/')
hostname.matches("^web-[0-9]+$")match(hostname, '^web-[0-9]+$')
has(user_id)user_id IS NOT NULL
size(tags) > 0length(tags) > 0

This enables expressions written once in YAML to work both as in-memory evaluation (Rust/Python) and as ClickHouse query filters.


Where it is implemented​

Two scalo wrappers enforce the DFE profile: scalo-py's for the engine and scalo-rs's for the loader and receiver.

Figure 1. L4 Detail -- CEL implementations. Up: Data plane.

scalo-py wraps common-expression-language and scalo-rs the cel crate. Both enforce the same allowed operators, functions and types. In the engine the callers are hunts/alert.py, the rule filters and source routing. In dfe-loader it is src/transform/computed.rs, and in dfe-receiver the filter validation in src/config/mod.rs.

scalo-py's names (scalo.expression):

compile_expression(expr) -> Program # Parse + validate + compile
evaluate(expr, data) -> Any # One-shot convenience (compile + execute)
validate(expr) -> list[str] # Syntax + profile check, returns errors for UI
transpile_to_clickhouse(expr) -> str # The SQL pushdown above