Skip to content

Commit

Permalink
Merge pull request #591 from metrico/fix/traceql_cluster
Browse files Browse the repository at this point in the history
fix traceql requests on cluster
  • Loading branch information
akvlad authored Oct 23, 2024
2 parents 7b5edd6 + 60ef80b commit 3360e4f
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions traceql/clickhouse_transpiler/traces_data.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const { standardBuilder } = require('./shared')
* @type {ProcessFn}
*/
const processFn = (sel, ctx) => {
const _in = ctx.isCluster ? 'global in' : 'in'
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())
Expand All @@ -17,18 +18,18 @@ const processFn = (sel, ctx) => {
.with(withMain, withTraceIds, withTraceIdsSpanIds)
.select(
[new Sql.Raw('lower(hex(traces.trace_id))'), 'trace_id'],
[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(`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'],
[new Sql.Raw(`groupArrayIf(base64Encode(traces.payload), (traces.trace_id, traces.span_id) IN ${new Sql.WithReference(withTraceIdsSpanIds)})`), 'payload'],
[new Sql.Raw(`groupArrayIf(traces.payload_type, (traces.trace_id, traces.span_id) IN ${new Sql.WithReference(withTraceIdsSpanIds)})`), 'payload_type']
[new Sql.Raw(`groupArrayIf(base64Encode(traces.payload), (traces.trace_id, traces.span_id) ${_in} ${new Sql.WithReference(withTraceIdsSpanIds)})`), 'payload'],
[new Sql.Raw(`groupArrayIf(traces.payload_type, (traces.trace_id, traces.span_id) ${_in} ${new Sql.WithReference(withTraceIdsSpanIds)})`), 'payload_type']
).from([table, 'traces']).where(Sql.And(
new Sql.In(new Sql.Raw('traces.trace_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

0 comments on commit 3360e4f

Please sign in to comment.