Expressions
Conditions and values in SREInsights are JEXL expressions, such as status == 200 && json.queue.depth < 1000. This page covers the syntax, where expressions appear, the names each place can read, and every transform.
Syntax
Section titled “Syntax”| Write | Means |
|---|---|
json.status, headers["content-type"], rows[0].id |
Read a field, a key with odd characters, an item by index. |
items[.status == "down"] |
The items for which the condition holds. |
value|round(2), rows|length |
A transform: the value on the left, optional arguments in parentheses. Transforms chain: hits|pluck('host')|unique|length. |
+ - * / % ^, // |
Arithmetic; // divides and rounds down. + joins strings. |
== != > >= < <= |
Comparison. |
&&, ||, ! |
And, or, not. a || b gives b when a is falsy. |
"x" in list, "err" in text |
Membership in a list, or text inside a string. |
a ? b : c, a ?: b |
Conditional; a ?: b gives b when a is falsy. |
"text", 'text', 42, true, null, [1, 2], { a: 1 } |
Literals. |
Things to know:
- A missing field is
undefined, not an error:json.data.items == nullis true whendatais missing. - Arrays have no
.length. Writerows|length. - An empty list is truthy. Test
rows|length > 0, notrows. - There is no
??operator. Usea || bora ?: b. - An expression is at most 2,000 characters (500 in alert rules).
- An expression that doesn’t parse, or uses an unknown transform, makes the run
error:The expression `…` failed: ….
Where expressions appear
Section titled “Where expressions appear”| Place | Field | Sees |
|---|---|---|
| A check’s assertion | assert.expression |
The check’s result, params, trigger |
| A check’s recorded number | value |
The same |
PromQL with perSeries |
assert.expression |
value, labels of one series, params, trigger |
| Flow steps | branch condition, outputs[].expr, assert, set, compare.values, poll.until |
Step outputs by id, steps, vars, params, trigger, meta, and output where noted |
| A flow’s own verdict | assert.expression, value |
Step outputs by id, steps, vars, params, trigger, meta |
| Templates in flow steps | ${…} in any config string |
The same as flow steps |
| Templates in single checks | ${params.…}, ${trigger.…} in settings |
params and trigger only |
| Alert rules | count rule breach.expression, threshold rule value |
status, durationMs, output (no transforms) |
| Syncs | fields[].value, lookups[].input, keep[].if, key |
col, found, row, tab, sheet, lookups, fields |
A value is turned into a number: numbers stay, true and false become 1 and 0, numeric text is read as a number, and anything else is stored as null.
Checks
Section titled “Checks”Each check type’s result fields are listed in Check types. In short:
| Type | Names |
|---|---|
http |
status, ok, headers, body, json, text, durationMs, certificate |
postgres, mysql |
rows, rowCount, first, fields, durationMs |
mongodb |
documents, count, first, durationMs |
redis |
result, info (for INFO), durationMs |
elasticsearch |
count, hits, aggregations, took, durationMs |
promql |
per series: value, labels; otherwise series, resultType, durationMs |
dynatrace |
problems, count, complete, durationMs |
script |
exitCode, data, stdout, stderr, durationMs |
integration |
the action’s result, such as count, issues, ok, and durationMs |
Every check also sees params (the run’s parameter values) and trigger (type, name, body, receivedAt; null when the run carries none).
status == 200 && json.items|map('status')|includes('down') == falsefirst.lag_seconds|number < 60certificate == null || (certificate.valid && certificate.daysLeft > 14)info.memory.maxmemory == 0 || info.memory.used_memory / info.memory.maxmemory < 0.9| Name | What it is |
|---|---|
<step id>, steps.<step id> |
An earlier step’s output, such as login.json.token. |
vars.<name> |
Saved values from outputs and set steps. |
params.<name> |
Parameter values. |
trigger |
How the run started; trigger.body is a webhook’s JSON body. |
meta.startedAt |
When the flow started. |
output |
The current step’s result, in outputs, branch conditions and poll.until. |
A step that failed with continueOnError has the output { failed: true, error }, so a branch can test output.failed. See Flow steps.
Templates
Section titled “Templates”In flow steps, ${…} holds an expression. A string that is exactly one template keeps the value’s type; otherwise the value is inserted as text, objects as JSON.
{ "url": "/orders/${vars.orderId}", "headers": { "authorization": "Bearer ${vars.token}" }, "params": ["${vars.limit}"] }In single checks only ${params.…} and ${trigger.…} render, always as text, such as "url": "https://api.example.com/${params.env}/health". Any other ${…} stays as written.
Alert rules
Section titled “Alert rules”Rule expressions read a stored result:
| Name | What it is |
|---|---|
status |
The run’s status: ok, failed, timeout or error. |
durationMs |
How long the run took. |
output |
The stored result, such as output.value, output.statusCode, output.rowCount, output.count, output.certificate.daysLeft. |
The stored result is smaller than what a check’s own expression saw (rows and hits are cut to about 12 KB), and an http result has statusCode rather than status. Each type’s stored fields are in Check types.
For PromQL checks with perSeries, a rule is evaluated per series, and output is { value, labels } of that series. See Alert rules.
Sync expressions run on the runner, one row at a time. SREInsights checks their syntax when a sync is saved.
| Name | What it is |
|---|---|
col.<column> |
The mapped cell’s text, trimmed. "" when the column wasn’t found. |
found.<column> |
Whether the tab has that column. |
row.number, row.first |
The sheet’s row number, and the row’s first cell. |
tab.name, tab.gid, tab.index |
The tab. |
sheet.id, sheet.id12, sheet.title |
The spreadsheet; id12 is the first 12 characters of its id. |
lookups.<name> |
A lookup’s result for this row. |
fields.<name> |
A field computed earlier in the list. |
See Sync spec.
Transforms
Section titled “Transforms”These work everywhere except alert rules.
| Transform | What it does | Example |
|---|---|---|
length |
Items in a list, characters in a string, keys in an object; 0 otherwise. | rows|length > 0 |
includes(x) |
Whether a string contains x, or a list has the item x. |
text|includes('"sid"') |
trim |
A string without surrounding spaces. | col.name|trim |
lower |
A string in lower case. | json.status|lower == "ok" |
upper |
A string in upper case. | labels.env|upper |
number |
A number from a number, true/false (1/0) or numeric text; NaN otherwise. |
first.lag_seconds|number > 30 |
string |
Text; objects as JSON, null as "". |
output.json.id|string |
json |
The value as JSON text. | labels|json |
parseJson |
Parses JSON text; undefined when it isn’t JSON. |
(stdout|parseJson).ok |
keys |
An object’s keys. | aggregations|keys|length |
values |
An object’s values. | info.keyspace|values|length |
first |
A list’s first item. | hits|first |
last |
A list’s last item. | datapoints|last |
sum |
The sum of a list’s numbers (others are skipped). | rows|pluck('n')|sum |
avg |
Their average; NaN for none. |
datapoints|pluck('value')|avg < 80 |
min |
The smallest; NaN for none. |
rows|pluck('free_gb')|min > 10 |
max |
The largest; NaN for none. |
series|pluck('value')|max |
round(digits) |
Rounds; digits defaults to 0. |
avg|round(2) |
abs |
The absolute value. | changePercent|abs < 30 |
split(sep) |
Splits a string; sep defaults to ,. |
headers["x-servers"]|split(',')|length |
join(sep) |
Joins a list; sep defaults to ,. |
issues|pluck('id')|join(', ') |
pluck(path) |
The value at a dotted path in each item. | hits|pluck('host.name')|unique |
map(path) |
The same as pluck. |
body.items|map('status')|includes('down') |
unique |
A list without repeats. | problems|pluck('title')|unique|length |
since |
Milliseconds since an ISO date. | first.updated_at|since > 600000 |
startsWith(s) |
Whether a string starts with s. |
headers.server|startsWith('nginx') |
endsWith(s) |
Whether a string ends with s. |
headers.location|endsWith('/login') |
matches(pattern) |
Whether a string matches a regular expression. | text|matches('^v[0-9]+') |
NaN compares false both ways: x|avg > 80 and x|avg <= 80 are both false for an empty list.
Sync-only transforms
Section titled “Sync-only transforms”These work only in sync expressions, next to the transforms above.
| Transform | What it does | Example |
|---|---|---|
url |
A typed link as a full http(s) URL, adding https:// when it has no scheme; null when it isn’t a web address. |
col.link|url |
pageUrl |
A page as Google indexes it: https, lower-cased host, no query or fragment; null otherwise. |
col.page|pageUrl |
host |
The host, lower-cased, without www.. |
col.site|host |
netloc |
The host exactly as written, www. and port included. |
col.site|netloc |
date(formats…) |
A date in one of the formats given (%d, %m, %Y, %y, as Python’s strptime), as YYYY-MM-DD; null when none fits. Default format %Y-%m-%d. |
col.date|date('%m/%d/%Y', '%d.%m.%Y') |
int |
Whole digits as a number; null otherwise ("4.2" and "" too). |
col.qty|int |
digits |
Whether the value is all digits. | col.number|digits |
slug |
The last part of a URL’s path, with - as spaces. |
col.url|slug |