Skip to content

Commit 36650a7

Browse files
committed
fix(webapp): freshness-guard the Queues env live blocks so a cached/quiet-env gauge can't briefly show a stale Queued/Running count on nav-back (TRI-12068)
1 parent a8aa2c4 commit 36650a7

1 file changed

Lines changed: 18 additions & 4 deletions

File tree

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

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

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,10 @@ const QUEUE_METRICS_DEFAULT_PERIOD = "1d";
121121
const QUEUE_LIVE_BLOCKS_PERIOD = "15m";
122122
const QUEUE_LIVE_BLOCKS_QUERY =
123123
"SELECT timeBucket() AS t, max(max_env_queued) AS env_queued, max(max_env_running) AS env_running FROM env_metrics GROUP BY t ORDER BY t";
124+
// Trust the ClickHouse gauge only while its newest bucket is this recent; otherwise fall back to
125+
// the loader's Redis-exact live values (matches LIVE_GAUGE_FRESH_MS on the queue detail page / run
126+
// inspector).
127+
const LIVE_GAUGE_FRESH_MS = 90_000;
124128

125129
export const meta: MetaFunction = () => {
126130
return [
@@ -408,11 +412,21 @@ function QueuesWithMetricsView() {
408412
});
409413
const lastLiveBlockRow =
410414
liveBlockRows.length > 0 ? liveBlockRows[liveBlockRows.length - 1] : null;
411-
const envQueuedLive = lastLiveBlockRow
412-
? tileNumber(lastLiveBlockRow.env_queued)
415+
// Only trust the gauge while its newest bucket is fresh. A row painted from the hook's cache on
416+
// client-side nav-back (responseCache), or a quiet env whose latest bucket is minutes old, must
417+
// not override the loader's Redis-exact live values with a stale count.
418+
const lastLiveBucketMs = lastLiveBlockRow ? tileTimeToMs(lastLiveBlockRow.t) : NaN;
419+
const freshLiveBlockRow =
420+
lastLiveBlockRow &&
421+
Number.isFinite(lastLiveBucketMs) &&
422+
Date.now() - lastLiveBucketMs < LIVE_GAUGE_FRESH_MS
423+
? lastLiveBlockRow
424+
: null;
425+
const envQueuedLive = freshLiveBlockRow
426+
? tileNumber(freshLiveBlockRow.env_queued)
413427
: environment.queued;
414-
const envRunningLive = lastLiveBlockRow
415-
? tileNumber(lastLiveBlockRow.env_running)
428+
const envRunningLive = freshLiveBlockRow
429+
? tileNumber(freshLiveBlockRow.env_running)
416430
: environment.running;
417431

418432
// Allocation summary tiles. The presenter computes the env-wide allocated total (sum of

0 commit comments

Comments
 (0)