Repository navigation
Commit 2ce4da9
feat(node): graceful shutdown + Prometheus metrics endpoint (#22)
* feat(db): versioned schema migrations with idempotent backfill
Replace the inline &str SQL array that re-runs on every node startup with a
versioned migration system. Each migration is recorded in a new
schema_migrations table and applied at most once per node, inside a single
transaction.
For nodes upgrading from a pre-migration-versioning build, the canonical
`repos` table is used as a signal to mark v1 as already applied without
re-running its ~140 statements — so existing operators see zero behavior
change on first restart after this commit.
Closes the gap called out in docs/OSS-READINESS-AUDIT.md:78.
- Adds Db::migration_status() returning applied (version, name, applied_at)
- Adds 6 unit tests validating the static migration catalogue
(versions strictly increasing, names distinct, bodies non-empty, v1
name locked to initial_schema)
- cargo fmt + clippy -D warnings + cargo test --workspace all clean
* fix(db): make legacy migration backfill safe and lock-guarded
Address two robustness gaps in the v1 migration runner on the live network:
- Remove the "repos table present => v1 complete" backfill short-circuit.
It assumed every existing node already had the full current schema; a node
that was behind would be marked v1-applied while still missing newer tables
or columns. Every v1 statement is idempotent (CREATE TABLE/INDEX IF NOT
EXISTS, ADD COLUMN IF NOT EXISTS), so legacy installs now simply run v1 once:
existing objects are no-ops, missing ones get created.
- Guard the whole runner with a Postgres advisory lock so two instances
against the same database (blue/green or rolling deploy) can't race to apply
the same migration and trip the schema_migrations primary key. The lock is
released explicitly, and automatically if the connection drops.
Also document that per-migration transactions preclude CREATE INDEX
CONCURRENTLY in future migrations.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
* feat(node): graceful shutdown + Prometheus metrics endpoint
Two operational-safety changes that the live network needs:
1) Graceful shutdown. A process-wide tokio::sync::watch::Sender<bool>
in AppState is flipped on SIGINT (all platforms) or SIGTERM (Unix).
Every long-lived loop now selects on the shutdown arm:
* axum server (with_graceful_shutdown — drains in-flight)
* libp2p swarm (drops Swarm, closes connections)
* gossip task (exits between peer announces)
* sync worker (exits between batches)
* operator heartbeat loop
* rate-limit cleanup loop
* peer-count metrics poller
* the deferred DID-record publish task
New GITLAWB_SHUTDOWN_GRACE_SECS (default 30s) controls how long
axum waits for in-flight requests before returning.
2) Prometheus /metrics endpoint. New metrics module exposes:
* gitlawb_info{version, did} (constant gauge = 1)
* gitlawb_pushes_total{repo} (counter)
* gitlawb_fetches_total{repo} (counter)
* gitlawb_auth_successes_total{route} (counter, helper)
* gitlawb_auth_failures_total{route,reason} (counter, helper)
* gitlawb_sync_queue_processed_total{status} (counter)
* gitlawb_webhook_deliveries_total{result} (counter)
* gitlawb_pack_size_bytes (histogram)
* gitlawb_peers_connected (gauge)
Opt-in via GITLAWB_METRICS_ADDR (e.g. 127.0.0.1:9091). The endpoint
is on a separate listener so the public port stays unexposed;
bind to localhost or a private interface.
3) Metric instrumentation hooks in api/repos.rs (push/fetch),
webhooks.rs (delivery outcomes), and sync.rs (per-item status).
The auth helpers are defined but not yet wired — that's a
focused follow-up.
Tests:
* 3 new metrics::tests::* — encode returns valid prometheus text,
record_* helpers are no-ops before init(), encode() errors if
init() was never called.
* cargo fmt + clippy -D warnings + cargo test --workspace all clean.
Closes the metrics and graceful-shutdown gaps in
docs/OSS-READINESS-AUDIT.md:131 and docs/MAINTAINER-ROADMAP.md:35.
---------
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>1 parent 927e4d0 commit 2ce4da9
12 files changed
Lines changed: 771 additions & 63 deletions
File tree
- crates/gitlawb-node
- src
- api
- auth
- p2p
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
51 | 51 | | |
52 | 52 | | |
53 | 53 | | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
54 | 58 | | |
55 | 59 | | |
56 | 60 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
366 | 366 | | |
367 | 367 | | |
368 | 368 | | |
369 | | - | |
| 369 | + | |
| 370 | + | |
370 | 371 | | |
371 | 372 | | |
372 | 373 | | |
| |||
377 | 378 | | |
378 | 379 | | |
379 | 380 | | |
380 | | - | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
381 | 385 | | |
382 | 386 | | |
383 | 387 | | |
| |||
451 | 455 | | |
452 | 456 | | |
453 | 457 | | |
| 458 | + | |
454 | 459 | | |
455 | 460 | | |
456 | 461 | | |
| |||
465 | 470 | | |
466 | 471 | | |
467 | 472 | | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
468 | 478 | | |
469 | 479 | | |
470 | 480 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
502 | 502 | | |
503 | 503 | | |
504 | 504 | | |
| 505 | + | |
505 | 506 | | |
506 | 507 | | |
507 | 508 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
131 | 131 | | |
132 | 132 | | |
133 | 133 | | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
134 | 147 | | |
135 | 148 | | |
136 | 149 | | |
| |||
0 commit comments