chadtmiller.com/monolith
An atproto PDS
0
0
The metrics check waits for the last write's commit, not a quiet second
harness/checks/operations.mjs+15−6
| @@ -182,12 +182,13 @@ const bytesUnder = (dir) => readdirSync(dir, { recursive: true }).reduce((n, f) | ||
function subscribe() { | ||
const ws = new WebSocket(`${cand.url.replace(/^http/, 'ws')}/xrpc/com.atproto.sync.subscribeRepos?cursor=0`) | ||
ws.binaryType = 'arraybuffer' | ||
const sub = { ws, seqs: [], last: now() } | ||
const sub = { ws, seqs: [], revs: new Set(), last: now() } | ||
ws.onmessage = (m) => { | ||
sub.last = now() | ||
try { | ||
const [, body] = cborDecodeMulti(new Uint8Array(m.data)) | ||
if (typeof body?.seq === 'number') sub.seqs.push(body.seq) | ||
if (typeof body?.rev === 'string') sub.revs.add(`${body.repo}@${body.rev}`) | ||
} catch {} | ||
} | ||
ws.onerror = () => {} | ||
| @@ -312,7 +313,8 @@ async function traceContext() { | ||
} | ||
| ||
/// An account of the run's own on the server, and a record whose text the | ||
/// log must not hold. | ||
/// log must not hold: answers that record's commit, as its account's DID, | ||
/// `@` and its rev, the last write before the metrics are read. | ||
async function canary() { | ||
const ip = '198.51.100.9' | ||
const front = `opscanary${SEED}` | ||
| @@ -330,17 +332,24 @@ async function canary() { | ||
noteSecret(text) | ||
const wrote = await post('com.atproto.repo.createRecord', { repo: made.body.did, collection: 'com.example.note', record: { $type: 'com.example.note', text } }, { authorization: `Bearer ${made.body.accessJwt}` }) | ||
if (wrote.status !== 200) await broke('createRecord', { canary: true }, 200, wrote) | ||
return `${made.body.did}@${wrote.body?.commit?.rev}` | ||
} | ||
| ||
/// The metrics: the format, each family as the spec gives it, and each held | ||
/// to the log of this start and to what the harness sees | ||
/// (spec/OPERATIONS.md, "Metrics"). | ||
async function checkMetrics(before) { | ||
async function checkMetrics(before, last) { | ||
// The firehose: one more subscriber while the harness has one open, and | ||
// the seq of the last event it is sent. | ||
// the seq of the last event it is sent. It has been sent them all once it | ||
// has the last write's commit, `last`, and nothing for a second after: a | ||
// quiet second alone says nothing, as a replay from cursor 0 may pause for | ||
// longer between two accounts' events. | ||
const base = gauge(await scrape('before subscribing'), 'pds_firehose_subscribers') | ||
const sub = subscribe() | ||
if (!(await sub.opened)) await broke('firehose', { cursor: 0 }, 'a subscription', 'none') | ||
for (const until = now() + 120000; !sub.revs.has(last); await wait(100)) { | ||
if (now() > until) await broke('firehose', { cursor: 0, commit: last }, 'the commit of the last write, within 120 s', `${sub.seqs.length} events, the last of seq ${Math.max(0, ...sub.seqs)}`) | ||
} | ||
while (now() - sub.last < 1000) await wait(100) | ||
const during = await scrape('while subscribed') | ||
const seq = Math.max(0, ...sub.seqs) | ||
| @@ -706,8 +715,8 @@ export async function checkOperations() { | ||
if (ops('traceContext')) await traceContext() | ||
if (ops('metrics')) { | ||
const before = await scrape('before the canary record') | ||
await canary() | ||
await checkMetrics(before) | ||
const last = await canary() | ||
await checkMetrics(before, last) | ||
} | ||
if (ops('log') || ops('lifecycle')) await outageLogged() | ||
if (ops('lifecycle')) await lifecycle() | ||