Skip to content

Commit

Permalink
fix: small improvement in traceql
Browse files Browse the repository at this point in the history
  • Loading branch information
akvlad committed May 2, 2024
1 parent 76635fe commit 58b2f8f
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 6 deletions.
2 changes: 1 addition & 1 deletion traceql/clickhouse_transpiler/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const { standardBuilder } = require('./shared')
*/
module.exports = standardBuilder((sel, ctx) => {
return (new Sql.Select()).select(['trace_id', 'trace_id'],
[new Sql.Raw('lower(hex(span_id))'), 'span_id'],
[new Sql.Raw('span_id'), 'span_id'],
[new Sql.Raw('any(duration)'), 'duration'],
[new Sql.Raw('any(timestamp_ns)'), 'timestamp_ns'])
.from([ctx.tracesAttrsTable, 'traces_idx'])
Expand Down
2 changes: 1 addition & 1 deletion traceql/clickhouse_transpiler/traces_data.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const processFn = (sel, ctx) => {
.with(withMain, withTraceIds)
.select(
[new Sql.Raw('lower(hex(traces.trace_id))'), 'trace_id'],
[new Sql.Raw('any(index_grouped.span_id)'), 'span_id'],
[new Sql.Raw('arrayMap(x -> lower(hex(x)), any(index_grouped.span_id))'), 'span_id'],
[new Sql.Raw('any(index_grouped.duration)'), 'duration'],
[new Sql.Raw('any(index_grouped.timestamp_ns)'), 'timestamp_ns'],
[new Sql.Raw('min(traces.timestamp_ns)'), 'start_time_unix_nano'],
Expand Down
7 changes: 3 additions & 4 deletions traceql/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,9 @@ async function processComplexResult (ctx, script, complexity) {
let traces = []
for (let i = 0; i < maxFilter; i++) {
ctx.randomFilter = [maxFilter, i]
let sql = planner(ctx)
let response = await rawRequest(sql + ' FORMAT JSON', null, DATABASE_NAME())
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) =>
acc === 0 ? row.start_time_unix_nano : Math.min(acc, row.start_time_unix_nano), 0
Expand All @@ -73,8 +74,6 @@ async function processComplexResult (ctx, script, complexity) {
ctx.randomFilter = [maxFilter, i]
}
ctx.cachedTraceIds = response.data.data.map(row => row.trace_id)
sql = planner(ctx)
response = await rawRequest(sql + ' FORMAT JSON', null, DATABASE_NAME())
traces = response.data.data.map(row => ({
traceID: row.trace_id,
rootServiceName: row.root_service_name,
Expand Down

0 comments on commit 58b2f8f

Please sign in to comment.