Skip to content

Commit 561766e

Browse files
committed
fix: comments
Signed-off-by: Uroš Marolt <uros@marolt.me>
1 parent dee16ec commit 561766e

4 files changed

Lines changed: 35 additions & 14 deletions

File tree

services/apps/packages_worker/src/deps-dev/activities/bqExportToGcs.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,9 @@ export async function bqExportToGcs(input: BqExportToGcsInput): Promise<BqExport
196196
// M4: explicit location to avoid cross-region error when account default != US
197197
const [dryRunJob] = await bigquery.createQueryJob({ query: sql, dryRun: true, location: 'US' })
198198
const dryRunBytes = Number(dryRunJob.metadata.statistics.totalBytesProcessed ?? 0)
199-
log.info({ jobKind, dryRunBytes, maxBytesGb }, 'BQ dry-run complete')
199+
// Log the effective ceiling (env override may differ from the default maxBytesGb) and the
200+
// computed byte ceiling, so ops can see what the abort decision is actually compared against.
201+
log.info({ jobKind, dryRunBytes, maxBytesGb, effectiveMaxBytesGb, ceiling }, 'BQ dry-run complete')
200202
if (dryRunBytes > ceiling) {
201203
throw new Error(
202204
`BQ dry-run for ${jobKind} reports ${dryRunBytes} bytes > ceiling ${ceiling} — aborting`,

services/apps/packages_worker/src/deps-dev/activities/checkEdgeSnapshotQuality.ts

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,13 @@ import { assertSnapshotDate } from '../queries/depsSql'
2222
// produced by the resolution pipeline and were unaffected, so they are not probed here.
2323

2424
export interface CheckEdgeSnapshotQualityInput {
25-
snapshotDate: string // YYYY-MM-DD — the resolved BQ partition date being ingested
25+
snapshotDate: string // YYYY-MM-DD — the BQ partition the incremental diff reads (ignored when fullScan)
2626
ecosystems: string[]
27+
// Probe the SAME source the ingest reads, so the guard validates the snapshot that actually gets
28+
// ingested. Full/fill scan the *Latest views (newest snapshot, no date filter) → probe *Latest.
29+
// Incremental reads the `snapshotDate` partition → probe that partition. Without this, a full run
30+
// with an older --snapshot-date would validate a stale partition while ingesting a corrupt *Latest.
31+
fullScan: boolean
2732
}
2833

2934
export interface CanaryStat {
@@ -99,8 +104,6 @@ export async function checkEdgeSnapshotQuality(
99104
return { ok: true, canaries: [] }
100105
}
101106

102-
assertSnapshotDate(input.snapshotDate)
103-
104107
// Group canaries by system into `(System = x AND Name IN (...))` predicates so the filter prunes
105108
// on the (System, Name, Version) clustering — keeps the probe in the single-GB / pennies range.
106109
const bySystem = new Map<string, string[]>()
@@ -116,6 +119,22 @@ export async function checkEdgeSnapshotQuality(
116119
)
117120
.join('\n OR ')
118121

122+
// Probe the same source the ingest reads (see fullScan): full/fill scan the *Latest view (newest
123+
// snapshot, no date filter); incremental reads the `snapshotDate` partition. The date is only
124+
// interpolated (and validated) on the partition path; *Latest needs no date.
125+
let edgesTable: string
126+
let snapshotFilter: string
127+
if (input.fullScan) {
128+
edgesTable = 'bigquery-public-data.deps_dev_v1.DependencyGraphEdgesLatest'
129+
snapshotFilter = ''
130+
} else {
131+
assertSnapshotDate(input.snapshotDate)
132+
edgesTable = 'bigquery-public-data.deps_dev_v1.DependencyGraphEdges'
133+
snapshotFilter = `e.SnapshotAt >= TIMESTAMP('${input.snapshotDate}')
134+
AND e.SnapshotAt < TIMESTAMP(DATE_ADD(DATE '${input.snapshotDate}', INTERVAL 1 DAY))
135+
AND `
136+
}
137+
119138
// Direct edges only (From = graph root), matching what the ingest reads. %T formats NULLs
120139
// as the literal "NULL" so COUNT(DISTINCT ...) isn't nulled out by unresolved To.Version.
121140
const query = `
@@ -124,10 +143,8 @@ export async function checkEdgeSnapshotQuality(
124143
e.Name AS name,
125144
COUNT(*) AS row_count,
126145
COUNT(DISTINCT FORMAT('%T|%T|%T', e.From.Version, e.To.Name, e.To.Version)) AS edge_count
127-
FROM \`bigquery-public-data.deps_dev_v1.DependencyGraphEdges\` e
128-
WHERE e.SnapshotAt >= TIMESTAMP('${input.snapshotDate}')
129-
AND e.SnapshotAt < TIMESTAMP(DATE_ADD(DATE '${input.snapshotDate}', INTERVAL 1 DAY))
130-
AND e.From.Name = e.Name AND e.From.Version = e.Version
146+
FROM \`${edgesTable}\` e
147+
WHERE ${snapshotFilter}e.From.Name = e.Name AND e.From.Version = e.Version
131148
AND (
132149
${systemPredicates}
133150
)

services/apps/packages_worker/src/deps-dev/workflows/ingestDependencies.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -224,14 +224,17 @@ export async function ingestDependencies(opts: {
224224
const isFill = opts.fillConstraints === true
225225
// Fill mode forces Option A — Option B selects NULL for version_constraint, making the fill a no-op.
226226
const tableOption = isFill ? 'A' : (opts.depsTableOption ?? 'A')
227+
// Full/fill scan the *Latest views; incremental reads the `today` partition. Drives both the SQL
228+
// source below and which source the guard probes — they must match.
229+
const fullScan = opts.syncMode === 'full' || isFill
227230

228231
// Guard against corrupt deps.dev resolved-graph snapshots BEFORE the (multi-hour) export.
229232
// Skip when reusing a prior export — we're re-importing already-validated parquet, not
230233
// scanning the live snapshot. Both full (*Latest = newest snapshot) and incremental can hit
231234
// a bad snapshot, so the guard runs for both. Probes only resolved-graph ecosystems; a clean
232235
// GO/NUGET-only run finds no canaries and passes through.
233236
if (!opts.reuseExports) {
234-
const guard = await checkEdgeSnapshotQuality({ snapshotDate: opts.today, ecosystems })
237+
const guard = await checkEdgeSnapshotQuality({ snapshotDate: opts.today, ecosystems, fullScan })
235238
if (!guard.ok) {
236239
throw ApplicationFailure.nonRetryable(
237240
`edge snapshot quality guard failed for ${opts.today}: ${guard.reason}. ` +
@@ -241,10 +244,9 @@ export async function ingestDependencies(opts: {
241244
}
242245
}
243246
// Fill mode always uses full SQL — needs all rows to find which have NULL version_constraint in DB.
244-
const sql =
245-
opts.syncMode === 'full' || isFill
246-
? buildDepsFullSql(ecosystems, tableOption)
247-
: buildDepsIncrementalSql(opts.today, opts.watermark ?? '', ecosystems, tableOption)
247+
const sql = fullScan
248+
? buildDepsFullSql(ecosystems, tableOption)
249+
: buildDepsIncrementalSql(opts.today, opts.watermark ?? '', ecosystems, tableOption)
248250

249251
const exportResult = await bqExportToGcs({
250252
jobKind: 'package_dependencies',

services/apps/packages_worker/src/deps-dev/workflows/ingestDependentCounts.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ interface VariantConfig {
6464
// When true, buildSql returns a multi-statement BQ script (the GO/NUGET exact reverse transitive
6565
// closure) that ends by creating TEMP TABLE _export_data, rather than a single SELECT. The export
6666
// activity then appends only EXPORT DATA and enforces the byte ceiling via maximumBytesBilled
67-
// instead of a dry-run. See ADR-0004. Left unset (single-SELECT) until the closure SQL lands.
67+
// instead of a dry-run. See ADR-0004. Unset (single-SELECT) for the edges variant; set for GO/NUGET.
6868
isScript?: boolean
6969
}
7070

0 commit comments

Comments
 (0)