From bf1b7b16049c5ad1330b9f5950c77e1d91cb9f63 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Bombeck?= Date: Sun, 17 May 2026 17:24:52 +0200 Subject: [PATCH] chore(drain): per-user COMPLETE log line for the cumulative drain MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit drainPerSampleCumulative emitted a [drain] START line per user but nothing on completion — an operator scanning the worker log had to infer per-user finish times from the next user's START line. Add a per-user COMPLETE line that carries the bucketsCollapsed / perSampleRowsDeleted / dailyRowsUpserted deltas the user contributed so START / COMPLETE pair cleanly in the worker log. --- .../drain-per-sample-cumulative.ts | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/lib/measurements/drain-per-sample-cumulative.ts b/src/lib/measurements/drain-per-sample-cumulative.ts index 22561456a..f48c19c8e 100644 --- a/src/lib/measurements/drain-per-sample-cumulative.ts +++ b/src/lib/measurements/drain-per-sample-cumulative.ts @@ -310,6 +310,13 @@ export async function drainPerSampleCumulative( const tz = user.timezone && user.timezone.length > 0 ? user.timezone : "Europe/Berlin"; log(`[drain] user=${user.id} tz=${tz}${dryRun ? " (dry-run)" : ""}`); + // v1.4.38 — per-user counters that mirror the existing aggregate + // totals. Lets the per-user COMPLETE log line carry useful + // numbers without re-walking the summary list later. + const beforeBucketsCollapsed = summary.totals.bucketsCollapsed; + const beforePerSampleDeleted = summary.totals.perSampleRowsDeleted; + const beforeDailyUpserted = summary.totals.dailyRowsUpserted; + for (const type of CUMULATIVE_HK_TYPES) { const hkIdentifier = hkIdentifierForType(type); if (!hkIdentifier) continue; @@ -417,6 +424,22 @@ export async function drainPerSampleCumulative( } } } + + // v1.4.38 — per-user COMPLETE log line. Mirrors the START line on + // line 311 so an operator scanning the worker log can pair + // "drain started for user X" with "drain finished for user X" + // without scrolling through every per-type bucket. Counts are + // computed as the delta against the snapshot taken before the + // per-type loop started. + const userBucketsCollapsed = + summary.totals.bucketsCollapsed - beforeBucketsCollapsed; + const userPerSampleDeleted = + summary.totals.perSampleRowsDeleted - beforePerSampleDeleted; + const userDailyUpserted = + summary.totals.dailyRowsUpserted - beforeDailyUpserted; + log( + `[drain] user=${user.id} complete bucketsCollapsed=${userBucketsCollapsed} perSampleRowsDeleted=${userPerSampleDeleted} dailyRowsUpserted=${userDailyUpserted}${dryRun ? " (dry-run)" : ""}`, + ); } log(