From 58b2f8f6be0ad90d2acc39740d857042643bd792 Mon Sep 17 00:00:00 2001 From: akvlad Date: Thu, 2 May 2024 14:51:10 +0300 Subject: [PATCH] fix: small improvement in traceql --- traceql/clickhouse_transpiler/init.js | 2 +- traceql/clickhouse_transpiler/traces_data.js | 2 +- traceql/index.js | 7 +++---- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/traceql/clickhouse_transpiler/init.js b/traceql/clickhouse_transpiler/init.js index c8a6a902..5d3cf131 100644 --- a/traceql/clickhouse_transpiler/init.js +++ b/traceql/clickhouse_transpiler/init.js @@ -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']) diff --git a/traceql/clickhouse_transpiler/traces_data.js b/traceql/clickhouse_transpiler/traces_data.js index f99928ef..f686e622 100644 --- a/traceql/clickhouse_transpiler/traces_data.js +++ b/traceql/clickhouse_transpiler/traces_data.js @@ -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'], diff --git a/traceql/index.js b/traceql/index.js index 3e8293e6..2c297dcc 100644 --- a/traceql/index.js +++ b/traceql/index.js @@ -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 @@ -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,