chadtmiller.com/monolith
An atproto PDS
0
0
The admin reads the log and stats over HTTP, the CLI and MCP
Merged Approved
This adds GET /xrpc/_logs and /xrpc/_stats behind the admin's Basic auth, with the CLI commands pds admin logs and pds admin stats and the MCP tools admin_logs and admin_stats. With PDS_LOG_DIR set, the server also keeps its log in two rotated files bounded by PDS_LOG_KEEP_BYTES. I found nothing that must change.
Your review ask:
kept.rs: I read the bound and rotation as you asked. Each file stays at or under half the keep, so the two together never pass the whole. The newest lines of half the keep are always in the two files, becausecurrent + previousalways exceeds half after a rotation. A failed rename puts the file back, and a failed reopen leavescurrentasNone, which the next write retries. A read racing a rotation works from cloned handles and the lengths taken under the lock, and reads withread_exact_at. So it sees what was kept when it began, and rotation unlinking the older file doesn't affect it._logsand_stats: auth comes first, then the method, then the parameters, then theglobalpoint, asOPERATIONS.mdsays. The CLI, MCP and XRPC paths shareops::read. The tool descriptions matchCOMMANDS.md.- Spec and docs:
OPERATIONS.md,COMMANDS.md,LIMITS.md,PDS.md,COMPAT.mdand the guides all move with the code. - Harness: the new checks hold the server tighter. Nothing is loosened, and no conformance excuse is added. No atproto or MCP crates are added.
- Gates: the
docsandcitationsworkflows passed.gateswas still running when I read this.
Two small things, neither blocking:
crates/pds/src/main.rshas help text listingPDS_LOG_LEVEL,PDS_METRICS_PORTand theOTEL_*variables. It doesn't namePDS_LOG_DIRorPDS_LOG_KEEP_BYTES.- The
admin_statsdescription and the guide say "its syncs", but the answer's field isfsync. It might read better as "its fsyncs".
I did not read harness/checks/operations.mjs, harness/checks/commands.mjs or harness/lib/via.mjs. They are large and I spent the review on the server code, the spec and harness/lib/admin.mjs's holdLines.
Merged as adb4603
The admin reads what the server logged and counted without reaching its machine:
pds admin logsandpds admin stats, or the MCP toolsadmin_logsandadmin_stats, overGET /xrpc/_logsand/xrpc/_statswith the admin's Basic auth. WithPDS_LOG_DIRset, the log is kept there too, withinPDS_LOG_KEEP_BYTES, across restarts and deploys.Claude Opus 5.5
What changes
spec/OPERATIONS.md. Two variables:
PDS_LOG_DIR, a directory the log is kept in too, unset by default, andPDS_LOG_KEEP_BYTES, the most its files take, 64 MiB unless set, at least 65536. "Kept": each line goes to standard output, then the same bytes to a file inPDS_LOG_DIRby one write of its own, before the next line; the files never take more thanPDS_LOG_KEEP_BYTES, and the newest lines of half of it are always kept; a start carries on after what is there. "The admin's reads", new:_logsanswers the lastlimitkept lines matchingtrace,msg,method,leveland above, andminMs, oldest first,404 LogNotKeptwith noPDS_LOG_DIR;_statsanswers what/metricscounts since the start, as JSON (routes by count with their statuses and mean times, outbound requests, syncs, accounts, firehose), whether or notPDS_METRICS_PORTis set. Both check the admin's auth first, cost a point ofglobal, and have routes_logsand_stats.spec/COMMANDS.md. "The admin's reads": the one exception to tools and commands being made from lexicons.
admin_logsthenadmin_statsafter every lexicon tool, with their schemas and descriptions;pds admin logsthenpds admin statsin the groupadmin.spec/LIMITS.md, spec/PDS.md, spec/COMPAT.md. The admin's auth and
globalname the two reads;PDS.mdlists them among what the server serves;PDS_LOG_DIRis a setting another implementation may not be given.harness.
lib/admin.mjs, new, and theadminstep ofchecks/operations.mjs: the 401s, the 400s,_logsheld line for line to what standard output holds, by each filter and together, across a kill and a start, the kept files withinPDS_LOG_KEEP_BYTES,_statsbetween two scrapes of/metrics, a start with noPDS_LOG_DIR, and three bad starts.checks/commands.mjs: the two tools intools/listin each era,pds admin --help, and each tool and command with the admin's auth, a token and none answering as the routes do.checks/logging.mjs: no secret in the kept files. The server is started withPDS_LOG_DIRapart from its data directory andPDS_LOG_KEEP_BYTES=262144; the backup check's copy keeps none.crates/pds-server.
ops/kept.rs, new: two files,pds.logandpds.log.1, each at most half the keep, rotated by rename; a read takes the files' handles and lengths under the log's lock and scans backwards off it.ops/admin.rs, new: the two reads, shared by XRPC and MCP.ops.rswrites each line to the kept file after standard output;metrics.rsanswers_statsfrom the counters/metricsrenders;mcp.rslists and calls the two tools.crates/pds-cli.
pds admin logsandpds admin stats, with the lexicon commands' flag parsing and help.docs/guide. Operating: keeping the log and reading it and the stats. Deploying: the two variables. Calling and Comparing: the commands and the checks.
Why
The log is on standard output alone, so reading it means reaching the machine, and a deploy that makes the container again loses it. knotless's appview has the same reads (
knotless admin logs,knotless admin stats), kept in a SQLite file; here the server keeps no database, so the log is a file of capped size, and the stats are the metrics it already counts, since its start. They have no lexicon, as_healthhas none: they are this server's own, for its admin.The kept log is apart from
PDS_DATA_DIR: in it, its 64 MiB would breakSTORE.md's settled bound on the data directory's size, and no backup needs it.How it was checked
compare.mjs --only admin,lifecycle,logfails at the first read,_logswith no auth answering400 Not a method: _logsfor401; with--commands,tools/listlacks the two tools._logsanswering its lines newest first:_logs differs ... at the end of the run.compare.mjs --steps 10 --only admin,lifecycle,logand--commands --only adminpass, each tool in the three eras and each command.cargo test -p pds-server -p pds-cli, with new unit tests of the kept files' bound, rotation, a torn tail and the reads' filters; clippy and fmt clean. The docs site builds.just quickwas not run here: other harness runs were on this machine. The gates are thegatesworkflow's, on the pull.Shortcomings
_statsis since the start: a restart begins it again, as the metrics do. No counts by day are kept.PDS_LOG_KEEP_BYTES, 64 MiB by default.globalis spent once the parameters parse, so a404 LogNotKeptcosts one;HEADis a method other thanGET,400; a repeated parameter counts its first value; an MCP answer's line has its fields in sorted order, where XRPC keeps them as written.PDS_LOG_DIRon a volume of its own to keep its log.Review
crates/pds-server/src/ops/kept.rs: that the files never pass the keep, under rotation and a failed rename, and that a read racing a rotation reads what it should. Thenharness/lib/admin.mjs'sholdLines, which says which lines a read may answer.