Skip to content

Commit e8e526a

Browse files
committed
feat(telemetry): label direct publication timing
1 parent 278af58 commit e8e526a

2 files changed

Lines changed: 60 additions & 1 deletion

File tree

‎dashboard/exact-review-queue.ts‎

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2277,6 +2277,8 @@ export class ExactReviewQueue {
22772277
dispatcher: state.dispatcher,
22782278
publication: stats.lanes.publication,
22792279
batches: this.batchStore.observability(now).batches,
2280+
directPublicationEnabled: exactReviewDirectPublicationEnabled(this.env),
2281+
legacyStateRepoBatchEnabled: exactReviewPublicationBatchingEnabled(this.env),
22802282
maxConcurrentBatches: exactReviewPublicationBatchMaxConcurrent(this.env),
22812283
});
22822284
return json({
@@ -4292,7 +4294,7 @@ export class ExactReviewQueue {
42924294
if (!leaseOwner) return json({ error: "invalid_lease_owner" }, 400);
42934295
if (!claimId) return json({ error: "invalid_claim_id" }, 400);
42944296
const dispatch = exactReviewPublicationBatchDispatchMetadata(body);
4295-
if (body.dispatch_id !== undefined && !dispatch) {
4297+
if ((body.dispatch_id !== undefined || body.dispatched_at !== undefined) && !dispatch) {
42964298
return json({ error: "invalid_batch_dispatch_metadata" }, 400);
42974299
}
42984300
const runner = exactReviewPublicationBatchRunnerMetadata(body);
@@ -10274,6 +10276,8 @@ function exactReviewReservationClaimObservability({
1027410276
dispatcher,
1027510277
publication,
1027610278
batches,
10279+
directPublicationEnabled,
10280+
legacyStateRepoBatchEnabled,
1027710281
maxConcurrentBatches,
1027810282
}) {
1027910283
const reservationToClaimDelays = batches.flatMap((batch) =>
@@ -10372,6 +10376,22 @@ function exactReviewReservationClaimObservability({
1037210376
return {
1037310377
schema_version: 1,
1037410378
generated_at: new Date(now).toISOString(),
10379+
// Direct publication never enters a publication batch unless it falls back.
10380+
// Keep its canonical Durable Object path distinct from the batch-only
10381+
// timestamps below so dashboards do not infer state-writer latency for a
10382+
// direct publication.
10383+
publication_paths: {
10384+
cloudflare_canonical_direct: {
10385+
enabled: directPublicationEnabled,
10386+
reservation_to_claim: "not_applicable",
10387+
state_writer_timing: "not_applicable",
10388+
},
10389+
legacy_state_repo_batch: {
10390+
enabled: legacyStateRepoBatchEnabled,
10391+
reservation_to_claim: "tracked",
10392+
state_writer_timing: "tracked",
10393+
},
10394+
},
1037510395
queue_slots: {
1037610396
pending,
1037710397
unassigned_pending: unassignedPending,
@@ -10384,6 +10404,7 @@ function exactReviewReservationClaimObservability({
1038410404
alerts,
1038510405
batches: batches.map((batch) => ({
1038610406
batch_id: batch.batchId,
10407+
publication_path: "legacy_state_repo_batch",
1038710408
state: batch.state,
1038810409
configured_batch_size: batch.configuredBatchSize,
1038910410
claimed_at: new Date(batch.createdAt).toISOString(),

‎test/exact-review-publication-batches.test.ts‎

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1868,6 +1868,29 @@ test("batch protocol routes require the shared internal signature", async () =>
18681868
assert.equal(forwardedPath, "/publication-batches/claim");
18691869
});
18701870

1871+
test("batch claims reject partial dispatch metadata", async () => {
1872+
const queue = new ExactReviewQueue(
1873+
{ storage: new TestStorage() },
1874+
{ EXACT_REVIEW_PUBLICATION_BATCHING_ENABLED: "1" },
1875+
);
1876+
for (const body of [
1877+
{
1878+
claim_id: "partial-dispatch-id",
1879+
lease_owner: "worker-partial",
1880+
dispatch_id: "publication-batch-dispatch:partial",
1881+
},
1882+
{
1883+
claim_id: "partial-dispatch-time",
1884+
lease_owner: "worker-partial",
1885+
dispatched_at: "2026-07-26T08:00:00.000Z",
1886+
},
1887+
]) {
1888+
const response = await queue.fetch(batchRequest("/publication-batches/claim", body));
1889+
assert.equal(response.status, 400);
1890+
assert.equal((await response.json()).error, "invalid_batch_dispatch_metadata");
1891+
}
1892+
});
1893+
18711894
test("publication batch observability always retains active leases beside bounded history", () => {
18721895
const storage = new TestStorage();
18731896
const batches = new ExactReviewPublicationBatchStore(storage);
@@ -2029,6 +2052,7 @@ test("reservation-to-claim observability traces one batch without exposing lease
20292052
batch_id: claim.batch.batch_id,
20302053
lease_owner: "worker-secret-not-public",
20312054
state_commit_sha: "a".repeat(40),
2055+
failure_fingerprint: "failure-body-secret-not-public",
20322056
state_writer: {
20332057
schema_version: 1,
20342058
operation_id: `batch:${claim.batch.batch_id}`,
@@ -2065,10 +2089,23 @@ test("reservation-to-claim observability traces one batch without exposing lease
20652089

20662090
const stats = await (await queue.fetch(new Request("https://queue/stats"))).json();
20672091
const observability = stats.reservation_claim_observability;
2092+
assert.deepEqual(observability.publication_paths, {
2093+
cloudflare_canonical_direct: {
2094+
enabled: true,
2095+
reservation_to_claim: "not_applicable",
2096+
state_writer_timing: "not_applicable",
2097+
},
2098+
legacy_state_repo_batch: {
2099+
enabled: true,
2100+
reservation_to_claim: "tracked",
2101+
state_writer_timing: "tracked",
2102+
},
2103+
});
20682104
const batch = observability.batches.find(
20692105
(entry: { batch_id: string }) => entry.batch_id === claim.batch.batch_id,
20702106
);
20712107
assert.ok(batch, JSON.stringify(observability));
2108+
assert.equal(batch.publication_path, "legacy_state_repo_batch");
20722109
assert.equal(batch.dispatch.id, "publication-batch-dispatch:trace-729");
20732110
assert.equal(batch.workflow.run_id, "92729");
20742111
assert.equal(batch.workflow.run_attempt, 3);
@@ -2088,6 +2125,7 @@ test("reservation-to-claim observability traces one batch without exposing lease
20882125
);
20892126
assert.match(JSON.stringify(observability), /publication-batch-dispatch:trace-729/);
20902127
assert.doesNotMatch(JSON.stringify(observability), /worker-secret-not-public/);
2128+
assert.doesNotMatch(JSON.stringify(observability), /failure-body-secret-not-public/);
20912129
} finally {
20922130
Date.now = originalNow;
20932131
}

0 commit comments

Comments
 (0)