Skip to content

Commit 6ed3a38

Browse files
committed
fix(webapp,clickhouse): pre-cap history keeps its truthful gap in the combined chart
The config-gauge back-fill exists to cover leading buckets with no samples, but it also overwrote sampled history from before a combined cap existed, showing a cap that was never in force. The cap series now carries a sampled guard column and the back-fill skips sampled buckets. Also corrects the renumbered migration's pre-044 comment.
1 parent 5bab9e1 commit 6ed3a38

3 files changed

Lines changed: 15 additions & 4 deletions

File tree

apps/webapp/app/components/queues/QueueMetricCards.tsx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,12 @@ type QueueMetricChartProps = {
102102
* are config values that existed all along, so carry the first value backward instead.
103103
*/
104104
carryBackfill?: string[];
105+
/**
106+
* Column that marks a bucket as genuinely sampled. When set, carryBackfill only
107+
* overwrites buckets where this column is absent or zero, so history from before
108+
* a config value existed keeps its truthful gap instead of inheriting the value.
109+
*/
110+
carryBackfillGuard?: string;
105111
/** Show the series legend below the chart (use for multi-series charts). */
106112
showLegend?: boolean;
107113
/**
@@ -141,6 +147,7 @@ export function QueueMetricChart({
141147
defaultPeriod,
142148
warningOverlay,
143149
carryBackfill,
150+
carryBackfillGuard,
144151
thresholdStroke,
145152
onHasDataChange,
146153
minBucketSeconds,
@@ -174,12 +181,15 @@ export function QueueMetricChart({
174181
const first = points.findIndex((p) => toNumber(p[key]) > 0);
175182
if (first > 0) {
176183
const value = points[first]![key]!;
177-
for (let i = 0; i < first; i++) points[i]![key] = value;
184+
for (let i = 0; i < first; i++) {
185+
if (carryBackfillGuard && toNumber(points[i]![carryBackfillGuard]) > 0) continue;
186+
points[i]![key] = value;
187+
}
178188
}
179189
}
180190
}
181191
return points;
182-
}, [rows, series, carryBackfill, sampleCountColumn]);
192+
}, [rows, series, carryBackfill, carryBackfillGuard, sampleCountColumn]);
183193

184194
const chartConfig = useMemo(() => {
185195
const cfg: ChartConfig = {};

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -499,7 +499,7 @@ function OverviewCharts({
499499
}
500500
showLegend
501501
className="aspect-[2/1]"
502-
query={`SELECT timeBucket() AS t, max(max_total_running) AS running, least(nullIf(max(max_total_limit), 0), max(max_env_limit)) AS cap\nFROM concurrency_metrics\nGROUP BY t\nORDER BY t`}
502+
query={`SELECT timeBucket() AS t, max(max_total_running) AS running, least(nullIf(max(max_total_limit), 0), max(max_env_limit)) AS cap, max(max_env_limit) AS sampled\nFROM concurrency_metrics\nGROUP BY t\nORDER BY t`}
503503
fillGaps
504504
minBucketSeconds={SYNCED_CHART_MIN_BUCKET_SECONDS}
505505
ids={ids}
@@ -515,6 +515,7 @@ function OverviewCharts({
515515
aboveColor: "var(--color-warning)",
516516
}}
517517
carryBackfill={["cap"]}
518+
carryBackfillGuard="sampled"
518519
/>
519520
) : null}
520521
<QueueDetailChartCard

internal-packages/clickhouse/schema/044_add_queue_metrics_total_concurrency.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ ALTER TABLE trigger_dev.queue_metrics_5m_v1 DROP COLUMN IF EXISTS max_total_runn
109109
ALTER TABLE trigger_dev.queue_metrics_v1 DROP COLUMN IF EXISTS max_total_running, DROP COLUMN IF EXISTS max_total_limit;
110110
ALTER TABLE trigger_dev.queue_metrics_raw_v1 DROP COLUMN IF EXISTS total_running, DROP COLUMN IF EXISTS total_limit;
111111

112-
-- Recreate the pre-042 materialized views (the definitions from 036) so ingestion keeps
112+
-- Recreate the pre-044 materialized views (the definitions from 036) so ingestion keeps
113113
-- feeding every aggregate table after a rollback.
114114
CREATE MATERIALIZED VIEW IF NOT EXISTS trigger_dev.queue_metrics_mv_v1
115115
TO trigger_dev.queue_metrics_v1 AS

0 commit comments

Comments
 (0)