Skip to content

Commit

Permalink
debug
Browse files Browse the repository at this point in the history
  • Loading branch information
akvlad committed May 20, 2024
1 parent e8054d0 commit 22358f4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
13 changes: 8 additions & 5 deletions traceql/clickhouse_transpiler/traces_data.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,26 @@ const processFn = (sel, ctx) => {
const table = !ctx.isCluster ? ctx.tracesTable : ctx.tracesDistTable
const withMain = new Sql.With('index_grouped', sel)
const withTraceIds = new Sql.With('trace_ids', (new Sql.Select())
.select('trace_id')
.from(new Sql.WithReference(withMain)))
const withTraceIdsSpanIds = new Sql.With('trace_span_ids', (new Sql.Select())
.select('trace_id', 'span_id')
.from(new Sql.WithReference(withMain))
.join('span_id', 'array'))
return (new Sql.Select())
.with(withMain, withTraceIds)
.with(withMain, withTraceIds, withTraceIdsSpanIds)
.select(
[new Sql.Raw('lower(hex(traces.trace_id))'), 'trace_id'],
[new Sql.Raw('arrayMap(x -> lower(hex(x)), groupArray(traces.span_id))'), 'span_id'],
[new Sql.Raw('groupArray(traces.duration_ns)'), 'duration'],
[new Sql.Raw('groupArray(traces.timestamp_ns)'), 'timestamp_ns'],
[new Sql.Raw(`arrayMap(x -> lower(hex(x)), groupArrayIf(traces.span_id, (traces.trace_id, traces.span_id) IN ${new Sql.WithReference(withTraceIdsSpanIds)}))`), 'span_id'],
[new Sql.Raw(`groupArrayIf(traces.duration_ns, (traces.trace_id, traces.span_id) IN ${new Sql.WithReference(withTraceIdsSpanIds)})`), 'duration'],
[new Sql.Raw(`groupArrayIf(traces.timestamp_ns, (traces.trace_id, traces.span_id) IN ${new Sql.WithReference(withTraceIdsSpanIds)})`), 'timestamp_ns'],
[new Sql.Raw('min(traces.timestamp_ns)'), 'start_time_unix_nano'],
[new Sql.Raw(
'toFloat64(max(traces.timestamp_ns + traces.duration_ns) - min(traces.timestamp_ns)) / 1000000'
), 'duration_ms'],
[new Sql.Raw('argMin(traces.name, traces.timestamp_ns)', 'root_service_name'), 'root_service_name']
).from([table, 'traces']).where(Sql.And(
new Sql.In(new Sql.Raw('(traces.trace_id, traces.span_id)'), 'in', new Sql.WithReference(withTraceIds))
new Sql.In(new Sql.Raw('traces.trace_id'), 'in', new Sql.WithReference(withTraceIds))
)).groupBy('traces.trace_id')
.orderBy(['start_time_unix_nano', 'desc'])
}
Expand Down
14 changes: 11 additions & 3 deletions traceql/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,19 @@ const search = async (query, limit, from, to) => {
}
const scrpit = parser.ParseScript(query)
const complexity = await evaluateComplexity(ctx, scrpit.rootToken)
let res = []
if (complexity > 10000000) {
return await processComplexResult(ctx, scrpit.rootToken, complexity)
res = await processComplexResult(ctx, scrpit.rootToken, complexity)
} else {
res = await processSmallResult(ctx, scrpit.rootToken)
}
return await processSmallResult(ctx, scrpit.rootToken)
res.forEach(t =>
t.spanSets.forEach(
ss => ss.spans.sort(
(a, b) => b.startTimeUnixNano.localeCompare(a.startTimeUnixNano))
)
)
return res
}

/**
Expand Down Expand Up @@ -59,7 +68,6 @@ async function processComplexResult (ctx, script, complexity) {
for (let i = 0; i < maxFilter; i++) {
ctx.randomFilter = [maxFilter, i]
const sql = planner(ctx)
console.log(sql.toString())
const response = await rawRequest(sql + ' FORMAT JSON', null, DATABASE_NAME())
if (response.data.data.length === parseInt(ctx.limit)) {
const minStart = response.data.data.reduce((acc, row) =>
Expand Down

0 comments on commit 22358f4

Please sign in to comment.