Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
acaed9c
test(grid): add the TraceQL grid suite with seed, cases, oracle and s…
44YHC Oct 12, 2026
b6fa2c6
test(traceql): take the spss=3 spansets in the search snapshots
44YHC Oct 12, 2026
fd56274
test(grid): hand-check the TraceQL span lists and cover the {} trace …
44YHC Oct 12, 2026
f1a5d6d
test(grid): cover trace-level && and || in the TraceQL grid
44YHC Oct 12, 2026
dd992e0
test(grid): cover one-hop structural operators in the TraceQL grid
44YHC Oct 12, 2026
89891b2
test(grid): cover {} as an operand of &&
44YHC Oct 12, 2026
0614d73
test(grid): cover transitive structural operators in the TraceQL grid
44YHC Oct 12, 2026
fb3e2dc
test(grid): tidy the TraceQL oracle docs and candidate-trace lookups
44YHC Oct 12, 2026
54f5c4a
test(grid): cover TraceQL metrics over structural expressions
44YHC Oct 12, 2026
7048eb7
test(grid): match each metrics exemplar to one result span
44YHC Oct 12, 2026
06a2792
test(grid): cover structure-aware TraceQL autocomplete
44YHC Oct 12, 2026
58bf4ab
test(grid): cover the autocomplete time range and state case rules
44YHC Oct 12, 2026
1469bdc
test(grid): clarify the autocomplete range case note
44YHC Oct 12, 2026
eeeafb3
test(grid): cover TraceQL scalar filters and pipelines
44YHC Oct 12, 2026
a1aa652
test(e2e): expect spanset aggregate attributes in TraceQL search snap…
44YHC Oct 12, 2026
084151e
test(grid): cover TraceQL field expressions and the nil rule
44YHC Oct 12, 2026
47637d8
test(grid): name the oracle comparison reader
44YHC Oct 12, 2026
29b3167
test(grid): cover TraceQL pre-stage narrowing
44YHC Oct 13, 2026
1062b4b
test(grid): cover && and || after a narrowing stage
44YHC Oct 13, 2026
8d898e8
test(grid): cover TraceQL by() and coalesce()
44YHC Oct 13, 2026
630bff8
test(grid): check by() expressions read the span and cover coalesce()…
44YHC Oct 13, 2026
0a751d9
test(grid): cover TraceQL select(), sample and exemplars hints
44YHC Oct 13, 2026
31cfefa
test(grid): share the selected span name key and list every intrinsic…
44YHC Oct 13, 2026
48914b6
style(grid): break the scalar-filter pipeline literal across lines
44YHC Oct 20, 2026
eca318b
test(grid): skip unresolved traces in the oracle instead of expecting…
44YHC Nov 6, 2026
ceaf063
test(grid): add parent cycle fixtures and pin every operator on them
44YHC Nov 6, 2026
981a463
test(grid): pin chain9 under << and &>>
44YHC Nov 6, 2026
6229d3a
test(traceql): leave the search metrics block out of the response sna…
44YHC Nov 6, 2026
c220c32
test(traceql): keep grid seed slots inside the attribute indexes' TTL
44YHC Nov 8, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
750 changes: 120 additions & 630 deletions __snapshots__/e2e.test.js.snap

Large diffs are not rendered by default.

77 changes: 77 additions & 0 deletions e2e.grid.traceql.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
// TraceQL grid suite: every case in grid/traceql/cases.json must return the
// traces, spans and matched counts the oracle computes from the seed. Cases
// with `pushes` run between that many seed batches landing and the next push.
// Metrics cases run on the whole seed and must return the oracle's series.
// Autocomplete cases must suggest the keys or values of the oracle's result
// spans.
const { _it, testID } = require('./common')
const seed = require('./grid/traceql/seed')
const oracle = require('./grid/traceql/oracle')
const { metrics } = require('./grid/traceql/metrics')
const { autocomplete } = require('./grid/traceql/autocomplete')
const { runs, metricsRuns, autocompleteRuns } = require('./grid/traceql/cases')
const { fromResponse, diff, names, fromMetricsResponse, metricsDiff, fromAutocompleteResponse, autocompleteDiff } = require('./grid/traceql/compare')
const client = require('./grid/traceql/client')

const TEST_ID = `${testID}_grid_traceql`
const PREFIX = ('7ace' + BigInt(testID.substring(2)).toString(16)).padEnd(24, '0').substring(0, 24)
const SLOT = Number(BigInt(testID.substring(2)) % BigInt(seed.SLOTS))
const { from: FROM } = seed.window(Date.now(), SLOT)
const SPANS = oracle.dataset(FROM, PREFIX, TEST_ID)
const NAMES = names(seed.ids(PREFIX))
const BATCHES = seed.zipkinBatches(FROM, PREFIX, TEST_ID)
const RUNS = runs(FROM)
const METRICS = metricsRuns(FROM)
const AUTOCOMPLETE = autocompleteRuns(FROM)

const seeded = (pushes) => pushes === BATCHES.length ? 'grid traceql: seed' : `grid traceql: seed ${pushes} of ${BATCHES.length} pushes`

const check = async (run) => {
const got = fromResponse(await client.search(run), NAMES)
return diff(got, oracle.search(run.ast, SPANS, run))
}

const checkMetrics = async (run) => {
const got = fromMetricsResponse(await client.metrics(run), run.kind)
return metricsDiff(got, metrics(run.ast, SPANS, run), { kind: run.kind, step: run.step, from: FROM, names: NAMES })
}

const checkAutocomplete = async (run) => {
const got = fromAutocompleteResponse(await client.autocomplete(run), run.tag === undefined)
return autocompleteDiff(got, autocomplete(run.ast, SPANS, run))
}

let prev
for (let pushes = 1; pushes <= BATCHES.length; pushes++) {
const step = seeded(pushes)
const cases = RUNS.filter(r => (r.pushes || BATCHES.length) === pushes)
_it(step, async () => {
await client.push(BATCHES.slice(pushes - 1, pushes))
// Every landed span is readable from the spans table ({}) and the attribute index.
const probes = RUNS.filter(r => r.id === 'all_spss_100' || r.id === 'suite').map(r => ({ ...r, pushes }))
const ready = await client.waitFor(async () => {
for (const run of probes) {
if ((await check(run)).length) return false
}
return true
})
expect(ready).toBe(true)
}, prev && [prev])
for (const run of cases) {
_it(`grid traceql: ${run.name}`, async () => {
expect(await check(run)).toEqual([])
}, [step])
}
for (const run of AUTOCOMPLETE.filter(r => (r.pushes || BATCHES.length) === pushes)) {
_it(`grid traceql autocomplete: ${run.name}`, async () => {
expect(await checkAutocomplete(run)).toEqual([])
}, [step])
}
prev = step
}

for (const run of METRICS) {
_it(`grid traceql metrics: ${run.name}`, async () => {
expect(await checkMetrics(run)).toEqual([])
}, [seeded(BATCHES.length)])
}
1 change: 1 addition & 0 deletions e2e.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ require('./e2e.otlp.pprof')
require('./e2e.otlp')
require('./e2e.grid.prom')
require('./e2e.grid.logql')
require('./e2e.grid.traceql')

const checkAlertConfig = async () => {
try {
Expand Down
1 change: 1 addition & 0 deletions e2e.traceql.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ const _itShouldTraceQL = (name, q, conf) => {
s.startTimeUnixNano = (BigInt(s.startTimeUnixNano) - (BigInt(start) * 1000000n)).toString()
}))
})
delete res.data.metrics
expect(res.data).toMatchSnapshot()
}, ['traceql: initialize'])
}
Expand Down
92 changes: 92 additions & 0 deletions grid/traceql/ast.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
// JSON AST of the TraceQL grid cases and its canonical printer; the
// self-check holds each case's query equal to print(ast).
//
// query {pipeline: [element], metrics?, hints?: [[key, value]]}; element spanset
// | {scalarFilter: {op, lhs: scalar, rhs: scalar}} | {groupBy: field} | {coalesce: true} | {select: [field]}
// spanset {selector: field|null} | {spansetOp, lhs, rhs} | {paren: spanset} | {pipeline: [element]}
// scalar {agg, attr?, arg?: field} | {num} | {dur}
// field {attr} | {str} | {num} | {dur} | {enum} | {bool} | {nil: true} | {op, lhs, rhs} | {unary, expr} | {paren}
// A field tree is grouped as gigapipe groups the printed query; print adds no parentheses.
// metrics {fn, attr?, q?, by?: [label]} | {fn: 'compare', compare: {filter: field|null, count?}}

const printField = (f) => {
if (f.attr !== undefined) return f.attr
if (f.str !== undefined) return JSON.stringify(f.str)
if (f.num !== undefined) return String(f.num)
if (f.dur !== undefined) return f.dur
if (f.enum !== undefined) return f.enum
if (f.bool !== undefined) return String(f.bool)
if (f.nil !== undefined) return 'nil'
if (f.paren !== undefined) return `(${printField(f.paren)})`
if (f.op !== undefined) return `${printField(f.lhs)} ${f.op} ${printField(f.rhs)}`
if (f.unary !== undefined) return `${f.unary}${printField(f.expr)}`
throw new Error(`ast: unknown field node ${JSON.stringify(f)}`)
}

const isLeaf = (f) => f.op === undefined && f.unary === undefined && f.paren === undefined

// canonicalField prints a field expression the way gigapipe names an
// aggregate or a by() stage: parentheses as written are dropped, and operands other than
// attributes and literals are parenthesised.
const canonicalField = (f) => {
if (f.paren !== undefined) return canonicalField(f.paren)
const wrap = (x) => {
while (x.paren !== undefined) x = x.paren
return isLeaf(x) ? printField(x) : `(${canonicalField(x)})`
}
if (f.op !== undefined) {
if (f.rhs.nil !== undefined) return `${wrap(f.lhs)} ${f.op} nil`
if (f.lhs.nil !== undefined) return `${wrap(f.rhs)} ${f.op} nil`
return `${wrap(f.lhs)} ${f.op} ${wrap(f.rhs)}`
}
if (f.unary !== undefined) return `${f.unary}${wrap(f.expr)}`
return printField(f)
}

const printScalar = (x) => {
if (x.agg !== undefined) return `${x.agg}(${x.arg ? printField(x.arg) : x.attr || ''})`
if (x.num !== undefined) return String(x.num)
if (x.dur !== undefined) return x.dur
throw new Error(`ast: unknown scalar node ${JSON.stringify(x)}`)
}

const printSpanset = (s) => {
if (s.selector !== undefined) return s.selector === null ? '{}' : `{ ${printField(s.selector)} }`
if (s.spansetOp !== undefined) return `${printSpanset(s.lhs)} ${s.spansetOp} ${printSpanset(s.rhs)}`
if (s.paren !== undefined) return `(${printSpanset(s.paren)})`
if (s.pipeline !== undefined) return printPipeline(s.pipeline)
throw new Error(`ast: unknown spanset node ${JSON.stringify(s)}`)
}

const printElement = (e) => {
if (e.groupBy !== undefined) return `by(${printField(e.groupBy)})`
if (e.coalesce !== undefined) return 'coalesce()'
if (e.select !== undefined) return `select(${e.select.map(printField).join(', ')})`
if (e.scalarFilter === undefined) return printSpanset(e)
const f = e.scalarFilter
return `${printScalar(f.lhs)} ${f.op} ${printScalar(f.rhs)}`
}

const printPipeline = (elements) => elements.map(printElement).join(' | ')

const printMetrics = (m) => {
let args = m.attr || ''
if (m.q !== undefined) args += `, ${m.q}`
if (m.compare) {
args = printSpanset({ selector: m.compare.filter })
if (m.compare.count !== undefined) args += `, ${m.compare.count}`
}
const by = m.by ? ` by (${m.by.join(', ')})` : ''
return `${m.fn}(${args})${by}`
}

const printHints = (hints) => ` with(${hints.map(([k, v]) => `${k}=${v}`).join(', ')})`

const print = (query) => printPipeline(query.pipeline) +
(query.metrics ? ` | ${printMetrics(query.metrics)}` : '') +
(query.hints ? printHints(query.hints) : '')

// canonicalScalar is an aggregate's canonical form, which names its value.
const canonicalScalar = (x) => x.arg ? `${x.agg}(${canonicalField(x.arg)})` : printScalar(x)

module.exports = { print, printField, printScalar, printSpanset, canonicalField, canonicalScalar }
58 changes: 58 additions & 0 deletions grid/traceql/autocomplete.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// Reference evaluator for tags v2 and values v2 in the grid: the attribute
// keys or values of the oracle's result spans, which are exactly the spans
// search returns. A query that selects every span reads every key or value
// of the dates in range, so its result is a superset of the seed's.

const oracle = require('./oracle')

// selectsEverySpan reports whether a query has no selector or is a lone `{}`.
const selectsEverySpan = (query) => {
if (query.pipeline.length === 0) return true
if (query.pipeline.length > 1) return false
let expr = query.pipeline[0]
while (expr.paren !== undefined) expr = expr.paren
return expr.selector === null
}

// TAG_KEYS maps tag names the API rewrites to their attribute key.
const TAG_KEYS = { status: 'otel.status_code' }

// tagKey is the attribute key of a values v2 tag, without its scope.
const tagKey = (tag) => TAG_KEYS[tag] || tag.replace(/^span\./, '').replace(/^\./, '').replace(/^resource\./, '')

// suggestions returns the sorted distinct keys of spans' attributes, or the
// values of tag when it is set.
const suggestions = (spans, tag) => {
const out = new Set()
for (const s of spans) {
if (tag === undefined) {
Object.keys(s.attrs).forEach(k => out.add(k))
continue
}
const v = s.attrs[tagKey(tag)]
if (v !== undefined) out.add(v)
}
return [...out].sort()
}

/**
* autocomplete returns the expected tags v2 or values v2 result:
* {values: [string], superset: boolean}, or the error result of
* oracle.resultSpans(). values are sorted and cut to limit.
* @param query {Object} the case AST
* @param all {Object[]} from oracle.dataset()
* @param opts {{from: number, to: number, tag?: string, limit?: number, rounds?: number, pushes?: number}}
*/
const autocomplete = (query, all, opts) => {
const { from, to, tag, limit, pushes } = opts
if (selectsEverySpan(query)) {
const spans = all.filter(s => s.start > from && s.start <= to && (pushes === undefined || s.push < pushes))
return { values: suggestions(spans, tag), superset: true }
}
const found = oracle.resultSpans(query.pipeline, all, opts)
if (found.error) return found
const values = suggestions(found, tag)
return { values: limit ? values.slice(0, limit) : values, superset: false }
}

module.exports = { autocomplete, selectsEverySpan }
74 changes: 74 additions & 0 deletions grid/traceql/cases.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
// Expands grid/traceql/cases.json into runs. A case's range is ms relative to
// FROM and defaults to the seed window; a metrics case's step is in seconds.

const { WINDOW } = require('./seed')
const file = require('./cases.json')

/**
* runs returns one run per case:
* {id, name, note, query, ast, from, to, limit, spss, pushes}, times in ms.
* pushes, when set, is how many seed batches have landed when the case runs.
* @param from {number} FROM in ms
*/
const runs = (from) => file.cases.map(c => {
const range = c.range || { from: 0, to: WINDOW }
return {
id: c.id,
name: `${c.id}: ${c.query}`,
note: c.note,
query: c.query,
ast: c.ast,
from: from + range.from,
to: from + range.to,
limit: c.limit || file.defaults.limit,
spss: c.spss,
pushes: c.pushes
}
})

/**
* metricsRuns returns one run per metrics case:
* {id, name, note, query, ast, from, to, step, instant, kind}, times in ms.
* kind is 'range', 'instant' or 'compare'.
* @param from {number} FROM in ms
*/
const metricsRuns = (from) => file.metrics.map(c => {
const range = c.range || { from: 0, to: WINDOW }
const compare = c.ast.metrics.fn === 'compare'
return {
id: c.id,
name: `${c.id}: ${c.instant ? 'instant ' : ''}${c.query}`,
note: c.note,
query: c.query,
ast: c.ast,
from: from + range.from,
to: from + range.to,
step: (c.step || file.defaults.step) * 1000,
instant: !!c.instant,
kind: compare ? 'compare' : c.instant ? 'instant' : 'range'
}
})

/**
* autocompleteRuns returns one run per autocomplete case:
* {id, name, note, query, ast, from, to, tag, limit, pushes}, times in ms.
* tag is unset for tags v2 and the tag for values v2.
* @param from {number} FROM in ms
*/
const autocompleteRuns = (from) => file.autocomplete.map(c => {
const range = c.range || { from: 0, to: WINDOW }
return {
id: c.id,
name: `${c.id}: ${c.tag === undefined ? 'tags' : `values of ${c.tag}`} for ${c.query || '(no query)'}`,
note: c.note,
query: c.query,
ast: c.ast,
from: from + range.from,
to: from + range.to,
tag: c.tag,
limit: c.limit,
pushes: c.pushes
}
})

module.exports = { runs, metricsRuns, autocompleteRuns }
Loading