Skip to content

Commit 1416ee6

Browse files
committed
refactor(clickhouse,webapp): use the stored quantile list in all merge calls
Short parameter lists on quantilesMerge and quantilesTDigestMerge do execute (the state layout is parameter independent, verified on both ClickHouse versions we run), but they rely on undocumented leniency and make the result-array indexes mean different quantiles per call site. Every merge now uses the stored four-quantile list with indexes re-pointed accordingly; returned values are unchanged.
1 parent c8af713 commit 1416ee6

4 files changed

Lines changed: 6 additions & 6 deletions

File tree

apps/webapp/app/presenters/v3/BuiltInDashboards.server.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -712,7 +712,7 @@ const queuesDashboard: BuiltInDashboard = {
712712
},
713713
"wait-pct": {
714714
title: "Scheduling delay p50/p95/p99 (ms)",
715-
query: `SELECT timeBucket() AS t,\n round(quantilesTDigestMerge(0.5, 0.95, 0.99)(wait_quantiles)[1]) AS p50,\n round(quantilesTDigestMerge(0.5, 0.95, 0.99)(wait_quantiles)[2]) AS p95,\n round(quantilesTDigestMerge(0.5, 0.95, 0.99)(wait_quantiles)[3]) AS p99\nFROM env_metrics\nGROUP BY t\nORDER BY t`,
715+
query: `SELECT timeBucket() AS t,\n round(quantilesTDigestMerge(0.5, 0.9, 0.95, 0.99)(wait_quantiles)[1]) AS p50,\n round(quantilesTDigestMerge(0.5, 0.9, 0.95, 0.99)(wait_quantiles)[3]) AS p95,\n round(quantilesTDigestMerge(0.5, 0.9, 0.95, 0.99)(wait_quantiles)[4]) AS p99\nFROM env_metrics\nGROUP BY t\nORDER BY t`,
716716
display: {
717717
type: "chart",
718718
chartType: "line",

apps/webapp/app/routes/_app.orgs.$organizationSlug.projects.$projectParam.env.$envParam.queues/route.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1353,7 +1353,7 @@ const QUEUE_HEADER_TILES: QueueHeaderTile[] = [
13531353
id: "p95",
13541354
label: "Scheduling delay p95",
13551355
color: "#F59E0B",
1356-
query: `SELECT timeBucket() AS t,\n round(quantilesTDigestMerge(0.5, 0.95, 0.99)(wait_quantiles)[2]) AS p95\nFROM env_metrics\nGROUP BY t\nORDER BY t`,
1356+
query: `SELECT timeBucket() AS t,\n round(quantilesTDigestMerge(0.5, 0.9, 0.95, 0.99)(wait_quantiles)[3]) AS p95\nFROM env_metrics\nGROUP BY t\nORDER BY t`,
13571357
formatValue: formatWaitMs,
13581358
derive: (rows) => {
13591359
const sparkline = rows.map((r) => tileNumber(r.p95));

apps/webapp/app/routes/_app.orgs.$organizationSlug.projects.$projectParam.env.$envParam.queues_.$queueParam/route.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ export default function Page() {
148148
/>
149149
<QueueDetailChartCard
150150
title="Scheduling delay"
151-
query={`SELECT timeBucket() AS t,\n round(quantilesMerge(0.5, 0.95, 0.99)(wait_quantiles)[1]) AS p50,\n round(quantilesMerge(0.5, 0.95, 0.99)(wait_quantiles)[2]) AS p95,\n round(quantilesMerge(0.5, 0.95, 0.99)(wait_quantiles)[3]) AS p99\nFROM queue_metrics\nGROUP BY t\nORDER BY t`}
151+
query={`SELECT timeBucket() AS t,\n round(quantilesMerge(0.5, 0.9, 0.95, 0.99)(wait_quantiles)[1]) AS p50,\n round(quantilesMerge(0.5, 0.9, 0.95, 0.99)(wait_quantiles)[3]) AS p95,\n round(quantilesMerge(0.5, 0.9, 0.95, 0.99)(wait_quantiles)[4]) AS p99\nFROM queue_metrics\nGROUP BY t\nORDER BY t`}
152152
fillGaps
153153
ids={ids}
154154
timeRange={timeRange}
@@ -288,7 +288,7 @@ function QueueStats({
288288
}) {
289289
// One scalar query feeds the CH-derived stats; the "now" counts come from the loader (live).
290290
const { rows, showLoading } = useQueueMetric(
291-
`SELECT max(max_limit) AS lim, max(max_queued) AS peak_queued, deltaSumTimestampMerge(started_delta) AS started,\n round(quantilesMerge(0.5, 0.95, 0.99)(wait_quantiles)[2]) AS worst_p95\nFROM queue_metrics`,
291+
`SELECT max(max_limit) AS lim, max(max_queued) AS peak_queued, deltaSumTimestampMerge(started_delta) AS started,\n round(quantilesMerge(0.5, 0.9, 0.95, 0.99)(wait_quantiles)[3]) AS worst_p95\nFROM queue_metrics`,
292292
{ ids, timeRange, queueName }
293293
);
294294
const row = rows[0];

internal-packages/clickhouse/src/queueMetrics.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ export function getQueueListMetricsSummary(reader: ClickhouseReader) {
6262
name: "getQueueListMetricsSummary",
6363
query: `SELECT
6464
queue_name,
65-
round(quantilesMerge(0.5, 0.95)(wait_quantiles)[1]) AS p50_wait_ms,
66-
round(quantilesMerge(0.5, 0.95)(wait_quantiles)[2]) AS p95_wait_ms,
65+
round(quantilesMerge(0.5, 0.9, 0.95, 0.99)(wait_quantiles)[1]) AS p50_wait_ms,
66+
round(quantilesMerge(0.5, 0.9, 0.95, 0.99)(wait_quantiles)[3]) AS p95_wait_ms,
6767
max(max_queued) AS peak_queued,
6868
deltaSumTimestampMerge(started_delta) AS started_count
6969
FROM trigger_dev.queue_metrics_v1

0 commit comments

Comments
 (0)