Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix traceql requests on cluster #591

Merged
merged 1 commit into from
Oct 23, 2024
Merged
Changes from all commits
Commits
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
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
Loading