ЛР 7 — БПИ2303 — Медведев — на 5 #20
@@ -18,3 +18,7 @@ __pycache__
|
||||
node_modules
|
||||
evidence
|
||||
.DS_Store
|
||||
.local
|
||||
student-tests
|
||||
*.zip
|
||||
.local-*
|
||||
|
||||
@@ -30,3 +30,6 @@ coverage/
|
||||
.vscode/
|
||||
# Keep small, sanitized evidence summaries in evidence/ under version control.
|
||||
# Inspect git diff --cached: ignore rules are not a secret scanner.
|
||||
.local/
|
||||
*.zip
|
||||
.local-*
|
||||
|
||||
@@ -0,0 +1,74 @@
|
||||
# Lab7 API / infrastructure boundary
|
||||
|
||||
Owner: lab7 infrastructure worker. Backend is owned by builtin `/root/vp`; this file is the integration contract, not a request to copy changing lab6 code.
|
||||
|
||||
## Reuse without weakening network security
|
||||
|
||||
Every API/worker process shares one network namespace with its dedicated HAProxy gateway (`network_mode: service:api1-gateway`, `api2-gateway`, or `worker-gateway`). All plaintext listeners bind **127.0.0.1 only**. HAProxy is the sole network-facing listener and checks TLS >=1.2, chain, server hostname, expiry and explicit client role. No app/backend port is published. This is the closed local proxy boundary expressly allowed by the original trust matrix.
|
||||
|
||||
API `APP_HOST=127.0.0.1`, `APP_PORT=8080`. HAProxy receives mandatory mTLS at api1-gateway:8443 and api2-gateway:8443, allows only certificate CN `lb` (CA-signed SAN `DNS:lb`), and forwards to 127.0.0.1:8080. LB verifies server identity `api1-gateway` / `api2-gateway`. No separate unprotected health port. Random `X-Instance-Id` aliases must not reveal hostname/IP.
|
||||
|
||||
All DB/cache/S3/OTLP clients may retain the current plaintext local transport implementation, because their endpoints are loopback in this namespace, behind a TLS-verifying outgoing proxy:
|
||||
|
||||
| Existing consumer | File / value | Network path behind local proxy |
|
||||
|---|---|---|
|
||||
| `DATABASE_URL_FILE` | `/run/app/database_url` containing postgresql://api or worker@127.0.0.1:15432/messenger?sslmode=disable | HAProxy TLS `postgres:5432`, verifyhost postgres, app/worker cert; separate DB roles |
|
||||
| `CACHE_URL_FILE` | `/run/app/cache_url`, redis://api or worker@127.0.0.1:16379/0 | HAProxy mTLS broker-gateway:6379, verifyhost broker-gateway; Valkey ACL role |
|
||||
| `BROKER_PUBLISH_URL_FILE` | `/run/app/publisher_url`, separate publisher ACL URL | worker composition uses an XADD-only publisher; CACHE_URL_FILE is the consumer, API is cache-only |
|
||||
| `S3_CONFIG_FILE` | `/run/app/s3.json`: exact Go `storage.Config` keys `Endpoint`, `Access`, `Secret`, `Bucket`; Endpoint=127.0.0.1:19000 | HAProxy TLS s3-gateway:9000, verifyhost s3-gateway; scoped S3 principal |
|
||||
| OTel HTTP/protobuf | `OTEL_EXPORTER_OTLP_ENDPOINT=http://127.0.0.1:14318` | HAProxy mTLS collector-gateway:4318, verifyhost collector-gateway; API/worker roles |
|
||||
|
||||
No insecure flag crosses a container/host boundary. The *_FILE inputs are generated by native OpenBao Agent certificate auto-auth and KV-v2 templates, never baked into the image or included in process arguments. Each service agent has its own `api` or `worker` certificate, policy, short-lived renewable token and app-only secret volume. The app receives no root/unseal/bootstrap CA material. Startup waits for all rendered files. Agent keeps renewing/re-authenticating and rendering; connection pools reread credentials on **controlled process restart** after rotation. Revocation of a transport certificate requires fresh connections; gateways must be restarted when allowlists/trust/certs change.
|
||||
|
||||
The accepted native server is OpenBao2.7.2 with durable single-node PebbleDB, not the removed file backend. After unseal, Docker health and Agent retry backoff converge independently: recovery waits for the same owned Bao container to become healthy, deliberately restarts the three native Agents, then requires actual post-seal fresh renders for API1/API2/worker before application recovery. The measured sealed rejection retains the original baseline and cause/exit/public503 before recovery; no universal120-second or hung-filesystem bound is claimed. Exact native/CLI provenance and retained failed commands are linked by evidence/openbao/NATIVE-COMPOSITE.json.
|
||||
|
||||
## Backend expectations owned by `/root/vp`
|
||||
|
||||
- Keep asynchronous lab5 pipeline and full lab6 telemetry, build app/worker and migrations from this lab's backend.
|
||||
- API host binding must honor APP_HOST=127.0.0.1. Worker has no inbound API.
|
||||
- `DATABASE_URL_FILE`, `CACHE_URL_FILE`, `S3_CONFIG_FILE` paths above are existing integration points; report any changed spelling before merging.
|
||||
- No automatic migrations as API's runtime DB identity. Explicit operator migration service uses an operator-only credential file and exits.
|
||||
- API role creates application entities and outbox. Worker role has no SELECT on users/sessions/chats/messages; only pipeline tables needed by real queries. Any worker startup read of unrelated tables must be removed or split.
|
||||
- Session/auth: Argon2id >=19456KiB,t=2,p=1; rehash on login; token hashes at rest; shared rate-limit across replicas, HTTP429 + Retry-After; bound KDF concurrency. These are backend changes, not satisfied by HAProxy alone.
|
||||
- Secrets/files/errors/telemetry never emit password, Authorization, token, DSN, S3 secret, OpenBao token or private keys. SDK logs use safe codes.
|
||||
- Exact OTel metrics/log schema and exporter defaults must be provided with stable backend so provisioning can be verified against real samples.
|
||||
|
||||
## Completion gates
|
||||
|
||||
Full public HTTPS smoke, persistence and both actual replica failures; wrong CA/hostname/expiry tests; missing/foreign/forbidden client identities on each gateway; DB/S3/Valkey/OpenBao ACLs; secret and certificate rotation/revocation, sealed behavior; scans and grade5 worker-compromise experiment. Infrastructure tests alone do not close backend acceptance.
|
||||
|
||||
## Confirmed freshness adapter API (new backend package owned by security worker)
|
||||
|
||||
`backend/internal/adapter/freshness` exports:
|
||||
|
||||
```go
|
||||
watcher, err := freshness.New(freshness.Ports{
|
||||
Read: freshness.FileReader(path),
|
||||
Now: time.Now,
|
||||
NewTicker: freshness.SystemTicker,
|
||||
}, 120*time.Second, 5*time.Second)
|
||||
// Check before opening business listeners or processing jobs.
|
||||
err = watcher.Check(ctx)
|
||||
// Run in composition-owned goroutine; on any error stop normal work and perform graceful shutdown.
|
||||
err = watcher.Run(ctx)
|
||||
```
|
||||
|
||||
No hidden production defaults in the constructor, no os.Exit/signals. Reader requests129bytes, accepts at most128bytes, regular non-symlink file only, no blocking FIFO open. Whitespace is trimmed; timestamp parses as RFC3339Nano. Empty/malformed/future/stale or unreadable is fail-closed. Age exactly120s remains valid;120s+1ns fails. Poll at most5s and at most maxAge. Error text is fixed and omits path/content. Cancellation returns context error and stops ticker.
|
||||
|
||||
Infrastructure emits `/run/app/freshness` via `{{ with secret "kv/data/api" }}{{ timestamp }}{{ end }}` (worker gets its own path) at native static-secret5s render intervals. `SECRET_FRESHNESS_FILE=/run/app/freshness`; `SECRET_MAX_AGE_SECONDS=120`. This temporary default yields detection <=125s plus composition shutdown grace; it is not a fixed instructor limit. When OpenBao is sealed the last timestamp ages, fresh startup is denied, and an existing process must stop on the adapter error. Recovery requires unseal, successful agent render and controlled process start.
|
||||
|
||||
## PostgreSQL auth correction from the real native client
|
||||
|
||||
The first actual libpq18 query proved that TLS terminates correctly but SCRAM-SHA-256-PLUS over the local non-TLS half is rejected as suspected TLS stripping. API/worker now use PostgreSQL18 native `cert` authentication, which checks CA and requires certificate CN equal to the requested database role; role impersonation is a separate negative test. Operator direct native TLS keeps SCRAM plus client certificate. No SCRAM/channel-binding downgrade flag is used to hide the rejection.
|
||||
|
||||
The API/worker DB URL has no password because its credential is the scoped gateway client certificate. OpenBao still delivers the actually consumed S3/Valkey secrets and DB endpoint. All cross-namespace DB traffic remains native TLS verified by HAProxy with `alpn postgresql`, CA, hostname and CRL.
|
||||
|
||||
Freshness timing is bounded by poll/max-age only under normal local filesystem I/O and scheduling. Context checks before/after regular-file syscalls cannot cancel a kernel-stalled filesystem operation, so125s is not a universal wall-clock deadline on a hung host/filesystem. No host-wide availability guarantee is claimed.
|
||||
|
||||
## Producer / consumer identity split
|
||||
|
||||
Original broker row requires different producer/consumer identities. The worker's outbox publisher and consumer use distinct native Valkey clients: `BROKER_PUBLISH_URL_FILE=/run/app/publisher_url` contains publisher-only principal (XADD on attachment-jobs); `CACHE_URL_FILE=/run/app/cache_url` contains consumer principal worker (XGROUP CREATE/XREADGROUP/XAUTOCLAIM/XACK/XDEL on attachment-jobs, no XADD). OpenBao worker KV includes publisher_url because the same legitimate worker composition owns both loops, while their broker permissions remain separate. API principal is cache-only GET/SET profile:*; login rate-limit lives in PostgreSQL login_limits, so no unused Lua/script/stream permission is granted to API.
|
||||
|
||||
## OpenObserve storage migration boundary
|
||||
|
||||
Backend112 keeps the same API/worker OTLP HTTP/protobuf endpoint and W3C propagation. No OpenObserve credential or new application environment contract is introduced. Collector-k8s0.163.2 exports all three signals through its dedicated mTLS identity to OpenObserve1.1.2; logs/traces use stream-name messenger, metrics have native normalized names without the old exporter namespace or automatic _total suffix. Included measured schema: docs/OPENOBSERVE-NATIVE-SCHEMA.json; native identity contract: docs/OPENOBSERVE-NATIVE-IDENTITIES.json. Canonical shared decision origin is vp/OPENOBSERVE-BOUNDARY.md; the standalone package includes its byte-identical snapshot docs/OPENOBSERVE-SHARED-BOUNDARY.md. Own actual112/OO acceptance is separately bound in evidence/openobserve; no Grafana/Bao acceptance follows from the schema handover.
|
||||
@@ -0,0 +1,17 @@
|
||||
# Измеренный бюджет Argon2id
|
||||
|
||||
Текущий default: Argon2id m32768KiB/t2/p1, salt16bytes/hash32bytes. Одновременно максимум2 KDF на процесс; остальные допущенные HTTP запросы ждут слот внутри ограниченного HTTP gate (4 inflight, очередь32, context request5s). Это выбранная конфигурация, а не универсальный оптимум.
|
||||
|
||||
Проверка выполнена на omarchy Ryzen7 5700X, Go1.27.2 Linux x86_64, в отдельном nonroot контейнере того же runtime image с лимитом1CPU/2GiB. Для каждого профиля непосредственно перед запуском получен `game-running` exit1 в той же SSH операции. Профили:1,2,4 одновременных verify; Go benchmark benchtime2s, один run. Рабочие процессы приложений не останавливались; абсолютная изоляция остальных background нагрузок не заявлена.
|
||||
|
||||
| Одновременных login | ns/op aggregate | p95 одной попытки, ms | VmHWM процесса, MiB |
|
||||
|---|---:|---:|---:|
|
||||
|1|25437564|27.52|70.08|
|
||||
|2|27842929|80.76|134.1|
|
||||
|4|28059622|156.4|168.3|
|
||||
|
||||
Все password verifications успешны, exit0. Aggregate ns/op — время на завершённую операцию всего профиля; при concurrency4 оно не равно latency запроса. VmHWM прочитан из /proc/self/status внутри benchmark процесса и включает runtime/удерживаемую GC память; это не размер только двух активных32MiB Argon buffers. Allocated bytes/op примерно33.56MB. Исходные строки: `lab7-argon-budget.txt`, источник — `backend/internal/adapter/password/argon_benchmark_test.go`. [Побайтная копия original launcher](docs/reference/argon-budget.ts), SHA6ea8a54687297cb6b43b11f8d88084744a2421262b24d00196f3161007ea4a2c, сохранена только как provenance: она относится к прежнему lab5 benchmark stand/precompiled fixture, не является current operator entrypoint этого ZIP и здесь повторно не запускалась.
|
||||
|
||||
Практический вывод: в этой короткой проверке4 одновременных verify дают p95 около156ms и peak RSS около168MiB на процесс. Это укладывается в выбранный контейнерный RAM budget, оставляя место сервису, но **не** доказывает peak RSS полного API со всеми обработчиками или устойчивость целого сервиса к DoS. Legacy rehash выполняет verify+новый hash, поэтому дороже одного current-profile login. Его корректность/CAS проверены отдельно; latency rehash здесь не измерялась.
|
||||
|
||||
Защита состоит из независимых границ:2 KDF/process,4 HTTP inflight/process, ограниченная очередь/таймаут, общий atomic10 attempts/60s на account-name hash bucket4096. Коллизии могут ограничить другое имя, а атака множеством известных аккаунтов может занять весь разрешённый budget. HTTP gate и Docker quotas ограничивают работу/память, а не гарантируют доступность всем клиентам. Сквозную negative/security acceptance выполняет отдельный защищённый стенд ЛР7.
|
||||
@@ -0,0 +1,137 @@
|
||||
{
|
||||
"checkedAt": "2026-11-15T19:04:33.200Z",
|
||||
"validationScope": "Go1.27.2 Linux generation/unit/race/vet/lint/static app+worker build; immutable SLO/telemetry/ForceClose delta, targeted native component receipts",
|
||||
"runtimeTelemetry": false,
|
||||
"runtimeSecurity": false,
|
||||
"productionFreshnessStop": "API and worker production entrypoints passed on lab5 real dependency stand; OpenBao seal/rotation remains separate",
|
||||
"commands": [
|
||||
"go generate ./internal/adapter/repository/postgres ./internal/adapter/handler",
|
||||
"go test -race ./...",
|
||||
"go tool golangci-lint run ./...",
|
||||
"CGO_ENABLED=0 go build -o ../lab7-app-check ./cmd/app",
|
||||
"CGO_ENABLED=0 go build -o ../lab7-worker-check ./cmd/worker",
|
||||
"test -z \"$(gofmt -l .)\"",
|
||||
"RUN_SECURITY_DB_TESTS=1 /security-db.test -test.v -test.run ^TestSharedLoginLimitAndRehashCASInRealPostgres$"
|
||||
],
|
||||
"source": "lab7 final explicit lab6 telemetry/SLO/ForceClose delta plus queue/request-id fields; preserved auth/dual broker clients/freshness and8/9s drain",
|
||||
"files": {
|
||||
"cmd/app/main.go": "f58ec5740b3f376ae34f18d87fa724dc718f247b6354449ea3093f7a088ca838",
|
||||
"cmd/worker/main.go": "84bfbeb0f867535cd2bcd512619ff29bec8550bc444af5dbeed8994f9522e919",
|
||||
"go.mod": "b0e80ef1c70d6f3ed506383cbf358c644d299d8e84e44bd166c24fdc7063039f",
|
||||
"integration/object_metadata_test.go": "598e973575d57c6ee563f0b15d0111d37b27de6774c6f486c998dbc70594f15d",
|
||||
"internal/config/config.go": "58795b18980c4dd938c73721ab937d06410af94edc156b7a7aa9b2c4c2388238",
|
||||
"internal/config/config_test.go": "390e3b5a4682719a0b25a8eb9aefeda9a9d1c774d3f8d1f08062c79a58d8859a",
|
||||
"internal/adapter/handler/handler.go": "1a99601365ed52aa36f5ef2b6be4dc760e28e1ad5cc38eb6790d69c5559751ce",
|
||||
"internal/adapter/handler/auth.go": "3889f58ac4c58b798192776ea05455d52735a2c024ba664ab9af5eb405187557",
|
||||
"internal/adapter/handler/api.gen.go": "4034501f5c661c87af3b81d0d1ecb9996050828569bea7e85b3604a2a8c8bdbe",
|
||||
"internal/adapter/handler/utf8_test.go": "eac6a14b5f3b0ea9aa5329337afc6db27e17f5c17999874da9ce3592dc7a4205",
|
||||
"internal/adapter/handler/message_json_test.go": "8dd976c4cad81ee531c76165787b2c8b6052057d934ae4b09b60d8a261cf30e5",
|
||||
"internal/adapter/handler/gate_test.go": "f7938bdeb5617ed3611303c54818000de9861dde5915fa2c6fa0f74e1fa33268",
|
||||
"internal/adapter/handler/stats.go": "5cd375e5a0db8cc3596293d323e635b86fef22d8ec680f310ab5a460f8176f64",
|
||||
"internal/adapter/handler/gate.go": "b662058ebc59010f30d21da12404837aa2329fe5e5590761efdd9140c1d24e9c",
|
||||
"internal/adapter/handler/api.go": "9d9f109e13c9322287b29ed18e7913e0e8d5a9ef2dc4be23f10c7686de3f70fe",
|
||||
"internal/adapter/handler/attachments.go": "608827653c4d3e4252dff863d30007e93b1bf82579bbe71d8b647bf22128b1b2",
|
||||
"internal/adapter/handler/middleware.go": "41ce83f0b7eaf25aecdbeb99d5292066f25e2043e08c0f681db2cfc80c01c528",
|
||||
"internal/adapter/handler/json.go": "d6458b8e8e4426816ec8c855ff6c8d88a151161bc1560e4b98df0ea4b0dbf6be",
|
||||
"internal/adapter/handler/errors.go": "d8eedca0f42718525ed81c2ace576a99b0a4a890f717c46215705798932c13a3",
|
||||
"internal/adapter/repository/postgres/pipeline_integration_test.go": "58274475a02f1098a0f79a65a9e8d7608d05dfa26213f90c706a9239fabb586c",
|
||||
"internal/adapter/repository/postgres/observability.go": "b6001827364a226026e7a651da8a57918ec426e34cd64d3b6ef709814f0a5667",
|
||||
"internal/adapter/repository/postgres/security.go": "1c5fd2e788b0b74040f87da666b73b7632df76d25daebc64020a33840ace0a29",
|
||||
"internal/adapter/repository/postgres/queries/models.go": "c88827ec8660f14e1274a2aa2d287869679aa1ca3ea9f9a951b806624fe4de39",
|
||||
"internal/adapter/repository/postgres/queries/core.sql.go": "9a0e082263cbea39535de9c7c72c41a39a551efc9ee57fdd7b08856831d074b3",
|
||||
"internal/adapter/repository/postgres/queries/db.go": "4863732830879d4162be215ff245375b953359de23bcd821ed7abc5c32a36c0f",
|
||||
"internal/adapter/repository/postgres/queries/attachments.sql.go": "407ed2864afad2b039a33c571228e6ee6a9acdc515d957bb55dc600308b5eacc",
|
||||
"internal/adapter/repository/postgres/queries/idempotency.sql.go": "cf6fbc316e93339e0f938c7ca82007e29c3e32f1a21ee1433a2ce8784697f002",
|
||||
"internal/adapter/repository/postgres/queries/pipeline.sql.go": "43009cbd2754d478727cce5d4b263dcdcafe7ad8000de011f22795531e1fb3ec",
|
||||
"internal/adapter/repository/postgres/queries/slo.sql.go": "bcaa6b4515507e555caff58a0448861ffaeac2f21771a4bde587cf296f6c685e",
|
||||
"internal/adapter/repository/postgres/queries/observability.sql.go": "c2971da00171c126b129ca2010a1cd1a6223b11ed1b1b20632af19fe8a66f313",
|
||||
"internal/adapter/repository/postgres/queries/security.sql.go": "bd3c3b6205b8ec955e27c6f0f3ef9b23364533920b5290bc566cd458bceeeca2",
|
||||
"internal/adapter/repository/postgres/security_integration_test.go": "bc5e6cc1824e8547d3f5fe0897ed5efa1557437cd2542301216256319401ee2c",
|
||||
"internal/adapter/repository/postgres/pipeline.go": "9a367d7a50a9418e96851c253f61ace4a54753044e7fa672c73a3b4526a22245",
|
||||
"internal/adapter/repository/postgres/attachments.go": "88f8b8744d95407421eafc111ecc83bcb4b145f1683618d69cac19a8d1c39500",
|
||||
"internal/adapter/repository/postgres/repository.go": "e380d7c0c52a2447653db9e4d13db432f4c1330e3205a0396510d957441bb978",
|
||||
"internal/adapter/repository/postgres/slo_integration_test.go": "e396c722fe8ea7ade19e2de5c9a070352efbde8e8712ae6e910f628a11c5c2b0",
|
||||
"internal/adapter/password/argon_test.go": "ce3d120d41c4f1e4f2c944289cd6852cfaca29ec11ab5e3ff9d0748036344b59",
|
||||
"internal/adapter/password/argon.go": "30fef7f8624019544262acfb7f1694a4003791e6d3a9acc7c7c7576aac73b0f3",
|
||||
"internal/adapter/password/argon_benchmark_test.go": "8d2b8fd14132c35ccd5b8008af9c8c088c84a1015fa36b252e1d5fce91bc581d",
|
||||
"internal/adapter/lifecycle/environment.go": "d897867f594dca3c79acd3bd3979e0d15bacb588415d8b3d794ec34d2317181c",
|
||||
"internal/adapter/lifecycle/lifecycle.go": "de660d859305e47c36c4d7671d0354e1c027a7cda7ba84639bdec4e9bbbaf9a5",
|
||||
"internal/adapter/lifecycle/lifecycle_test.go": "d398eb9075654cfd4eb23edafa3bb3c741a822b315ef0d3e9d710b3a0d6d17e9",
|
||||
"internal/adapter/storage/bootstrap.go": "44c8f422826b29f85a918029bb71a62cd3018190f8efe889cbeee63d19d7039e",
|
||||
"internal/adapter/storage/readiness_test.go": "a6c79cba7af74ce67e69678085e5bb267a47f9dd7be57daf003ba03951274a5c",
|
||||
"internal/adapter/storage/s3.go": "99a717604c71da5c181bef74612a603abe3cfc913ccb3da84ed581a57a11ccd8",
|
||||
"internal/adapter/imagefile/variants.go": "50762d1e2af635c9a9344d2721ee145bb9d9d43408f680fc280cdd493aeef886",
|
||||
"internal/adapter/imagefile/variants_integration_test.go": "d25e3371432128e58073ff61e1b87fa741bc32ee7d9bc6e8cb40ae3f3a5b4434",
|
||||
"internal/adapter/imagefile/stress_test.go": "3d7b0671f57ce5e01fa7e175a86c16a51d56d8f11ec6d3bfb09b2c8bfe8c04d8",
|
||||
"internal/adapter/imagefile/variants_test.go": "79c24a3d5c0cb339a32fdea28eb56689703f35ad3c668c464ea7a4f5e82322e5",
|
||||
"internal/adapter/imagefile/image_test.go": "a2dc0d3797a5c2ac7ad46a7453a34ea13aba94c3385d2692032705610026dc71",
|
||||
"internal/adapter/imagefile/image.go": "8a9b399b22573992fd7fd4c87096f953b46c1bc7cad4e09c023923919d755375",
|
||||
"internal/adapter/queue/identities_test.go": "0ec224f6524ffcaf7710605a560ae17b06a294b3d4e4a96ac50a59cb86e37917",
|
||||
"internal/adapter/queue/streams.go": "f16c63a8ec82302031e28e686e48ac220e883022a7e5787f80db57baa09a42f6",
|
||||
"internal/adapter/queue/clients.go": "c0b253da9110b9fcb7599277e197da9ab009d3813a5b88d290e48f36a2bd053c",
|
||||
"internal/adapter/queue/identities_integration_test.go": "d7c3171d8420ea705d0a0d7aef9f275b5355f484e89439cb0b450112d1f3924e",
|
||||
"internal/adapter/queue/publish_trace_test.go": "4ae1d22d4c6ff07ec8dfd6c503059b4ee47aad426503f925e0d479c0b819ee00",
|
||||
"internal/adapter/telemetry/telemetry_test.go": "c727d6901ac3b8a5cc3e704645f8a7715a44d88f8bdf9bd990ac176c017fbba2",
|
||||
"internal/adapter/telemetry/gauge_failure_test.go": "4d8d3aaff9e471a36c0f65db0a23d799101c72f804b6d7270bc9a9570181b225",
|
||||
"internal/adapter/telemetry/telemetry.go": "db9ec2b20d504e7c50424414618e00fe1b81ce68b997c70ae65040260d31b890",
|
||||
"internal/adapter/telemetry/gauges.go": "80782d0bdb1bbaa9132c6c3a471887e4a6d48839b448a5c3c558edf217a01642",
|
||||
"internal/adapter/telemetry/dependencies.go": "09d5bcf97bfff77d42dbdca9637e015a2eb73e03ea3ff801d710e1340c85ea44",
|
||||
"internal/adapter/telemetry/dependencies_test.go": "d7738b7fe098b2d72967243dce8ab7a84135e570e4697371755b73245d908981",
|
||||
"internal/adapter/telemetry/pool_integration_test.go": "b8e8d24ee46549c0898726f770f206701f147ea7f9cbb4271b24dcaa63f5a0dc",
|
||||
"internal/application/usecase/auth_security_test.go": "642b594d94965e2ed76cfb5eefa67ed620a4c372f70d0c1230690c3a318de61f",
|
||||
"internal/application/usecase/pipeline_retry_test.go": "96a569aa26e23909c109dda14c8828901abe2914bbad2ec3506a10441a264dce",
|
||||
"internal/application/usecase/auth.go": "8935ab9bbe126e7edf12f0a16e0b7b95f5f360e7b48a7ce547e82e659c07cd5f",
|
||||
"internal/application/usecase/messenger.go": "c58aba0d3f5d0ab92fab5d2771b90a3af5ad06e6afe0c7cc46f481a429e89f48",
|
||||
"internal/application/usecase/pipeline.go": "05b4a6e87c2bfd86c06f5b8cc3e7b960a26c0a69726a366a3137158b1e9e2e45",
|
||||
"internal/application/usecase/attachments.go": "0c835f88c72b90753b5458960f7b345e6e51b964070ce37eaae129a4c296b0ca",
|
||||
"internal/application/usecase/reconcile_pipeline_test.go": "75e1fb5fcc5ffb2188a2368688e5505a4bf54453c2800b5e46c8e9e23de89b7c",
|
||||
"internal/application/usecase/reconcile_test.go": "fdbcfad86851fc97a3cf635b6d884c41b43084eedc42b3c4847790c5eaad4a6f",
|
||||
"internal/application/usecase/reconcile.go": "239edee16f767dd16b116791900994540a8f99ae3403fd0308f5e2c0797a892d",
|
||||
"internal/domain/repository/repository.go": "0008747c69b32df9e4b7f36fd1ac157dee537d5e1e415bd48bd55b0b05852362",
|
||||
"internal/domain/model/model_test.go": "77bb8767ac1352bd3551e724eaaeaad4fe93eae248cc8c3008ee8b1c08adddca",
|
||||
"internal/domain/model/user.go": "c20c8b8d8a9c0327a3a24afd74f3051d78caed1d2f0851baf340ef61ac502a92",
|
||||
"internal/domain/model/trace.go": "9ff395bce67142f6808fa7c652e50db2a68cf4e34c128fb04af408566a14220a",
|
||||
"internal/domain/model/page.go": "cd6a07579bff01aa0d8a11b34fd000a804142b321cef302d386bdb95e9c7f953",
|
||||
"internal/domain/model/message.go": "0e0126663d2de04c9d14c8c7427f42a9fb733e3b170ceee7ed86c2138f51b23c",
|
||||
"internal/domain/model/postgres_text_test.go": "8c245eef99a97261daf0aa16fec9edd7bcd3253ec4144c50b4f8e56e45e2186e",
|
||||
"internal/domain/model/job.go": "564c219e526b99e06d2c882d7184fc6ee0b58d29c326be5969a38cc6b92b8c0a",
|
||||
"internal/domain/model/text.go": "c9410cacd9d1b2fd7f3f2cb7e4112e637ecc494f6e4b6da649f936ce0c9a0457",
|
||||
"internal/domain/model/attachment.go": "e532f2c8e8c123d0fda6101bff4b21168527a0a446e53f566f5e5919b972133b",
|
||||
"internal/domain/model/chat.go": "3f7454f48ef442c277fd2741ce5aeeccf03d590bd2d31b9b89fa39f0ba05de7f",
|
||||
"internal/domain/model/errors.go": "e0a6322f36b3a8ef7b75f70294fedeb3ad70e37ba63d7325bb1bde8ad332d4a6",
|
||||
"internal/domain/port/auth.go": "0087a19007cce3e90bddce4d24909217820993fb4b6ce125f3c6d9da4d86763a",
|
||||
"internal/domain/port/pipeline.go": "5fe7c6909cbaf6a21a4be5d9ed0c2b1551681894d0054463cdba13ea09c21aac",
|
||||
"internal/domain/port/objects.go": "4d22b5ef5ff6fa13404884c160fe52bd7cef4099f84b29268137c27034a0f3ec",
|
||||
"go.sum": "d8f0a6a0b68268ac02e58c0232ec13c6a12d8bc3c3d9a4a148806566d8d02fca",
|
||||
"codegen.yaml": "e4d37ce5c5a9f969f696833cd59a6e1b86f99fb2b0de69101a1aa5f4a539aebe",
|
||||
".golangci.yaml": "215578dee14bcef1b66759a68543083e0a624611efcdb785197307b50cb7725d",
|
||||
"generator-overlay.yaml": "e666da2959b31befed713a8366237de53070a565f93850d6daae7a582a038819",
|
||||
"db/migrations/00003_attachments.sql": "6b4f707dde32f0c3f531741c108bcf0f22be05c9e2ede327f27a1d9ef0cfcc7f",
|
||||
"db/migrations/00006_slo_facts.sql": "2cdb8cdb1618a90eea76e59ac99f3d89a3665b2d6ade17502abe4261d5ffcf3b",
|
||||
"db/migrations/00001_core.sql": "b6bd8c70d51aed6c966e07eebffd262af2e694c8b3479c70bbf9a9eacf5a7aad",
|
||||
"db/migrations/00005_replay_audit.sql": "234a04177bca08621fa38b135cb8086bcdd55ae9084008b25814751e1dd742a4",
|
||||
"db/migrations/00002_idempotency.sql": "97c98785547db8391c1fa0a685e4d4bcc810b8f79055c0e2fc6ef473cd38b37b",
|
||||
"db/migrations/00004_login_limits.sql": "6be837dee2d6c2d1dd80c6b6324e52001c0913160ef0532852410266d1f4af8b",
|
||||
"db/sqlc/sqlc.yaml": "803b161e063692398c93152b11a08f9e42e1bf3c72a1e64553b82c494545fd10",
|
||||
"db/sqlc/queries/idempotency.sql": "5bdec86e85705f7805fb603e2c792bb87c11cf3156952fa48e7bcee35fd683ca",
|
||||
"db/sqlc/queries/pipeline.sql": "9551971f39bced93c8690022495f15a87f7e14fa865d050a200a1b5d52c1acc1",
|
||||
"db/sqlc/queries/slo.sql": "6f9b0092fca3ee0dda312d421bdb9ea587e3f580983372af47dc54f3d79a1873",
|
||||
"db/sqlc/queries/security.sql": "43456c3cc7c586e854c8f98a7aa9c4a9fdd0dfc07b113e04c33af6174dc3d454",
|
||||
"db/sqlc/queries/core.sql": "1aed3d0d2fc04650351d86d15837cf3239636844727e799aabf5ddd534429f33",
|
||||
"db/sqlc/queries/observability.sql": "65c5dd26008542a80b7673d25631d1e7faeb0ae4caba661aee52d25fca26e4f3",
|
||||
"db/sqlc/queries/attachments.sql": "8e64f0e6169fab7664b0f4a97f2be353553b93c0c928d10678cb930e44de37da",
|
||||
"db/migrate.go": "33044d905354f24fff194fefd35ee9327d63d6e5062ded8496e518b6ce38dbea",
|
||||
"pkg/logger/logger.go": "d839f31015eee692065c31d2538a4cb4c841b0d89e690f0ab8baf80168510556",
|
||||
"pkg/server/server.go": "2916acc42708dd493068452ac4eed5208cd166f910c517f16196d001aac5d269",
|
||||
"pkg/server/server_test.go": "7eccb3acd7f9e9ac0b724b17fa50f1f1ff94be043554fed0a5e0fad1e2cb9ee3"
|
||||
},
|
||||
"preservedFreshness": {
|
||||
"internal/adapter/freshness/freshness.go": "551a4d8d3780598fa363edd3fcd4cd4bb6450ce52846a4257aeea1bf4bb0a978",
|
||||
"internal/adapter/freshness/file_test.go": "00069226fad9fa5f6ba3a4e3e679d5e7122ce1cbed137a5d71da82bfe190e5ad",
|
||||
"internal/adapter/freshness/freshness_test.go": "85b5354f7935e3767f93ee000e0a00cce7f92d381abe5561c41e77807b7609fb"
|
||||
},
|
||||
"brokerIdentity": "BROKER_PUBLISH_URL_FILE required, separate nonempty ACL usernames; publisher XADD, consumer XACK/XDEL. Real Valkey cross-role commands rejected NOPERM. Full TLS security stack acceptance remains separate.",
|
||||
"argonBenchmark": "ARGON-BUDGET.md: three profiles game-running exit1, one CPU, current-profile verification",
|
||||
"telemetrySchema": "../lab6/TELEMETRY-SCHEMA.json",
|
||||
"latestChecks": "lab7-final-telemetry-check.txt"
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
# Случаи до реализации backend security
|
||||
|
||||
- Argon2: верный старый m8192/t1/p1 пароль проходит и обновляется; новый m32768/t2/p1 не требует повторного обновления; неверный пароль, malformed и чрезмерные параметры не проходят. KDF одновременно не более двух на процесс.
|
||||
- Успешный login: hash заменяется CAS только при прежнем значении. При смене пароля параллельно login не публикует сессию на устаревшем hash.
|
||||
- Обе API реплики обращаются к одному атомарному PostgreSQL счётчику. Временный default: 10 попыток/60с на hash-bucket имени; фиксированные4096bucket, поэтому мусорные имена не увеличивают таблицу. Коллизии могут временно ограничить другое имя; это явно выбранный ограниченный учебный default.
|
||||
- До обращения к KDF исчерпанный лимит даёт429 и Retry-After60; ошибка limiter fail-closed503. Имя/пароль/token в диагностику не попадают.
|
||||
- Freshness проверяется перед открытием listener/jobs и каждые5с. Отказ отменяет общий context, API draining и worker перестают брать задачи. Монитор проверяется отдельной factory с обязательными fake ports; production entrypoint никогда не вызывается REDтестом.
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
FROM golang:1.27.2-alpine@sha256:f92b6ef800e499660581efdabdf25d9d817a9d124eaf900924f0504e7e27e12d AS build
|
||||
WORKDIR /src
|
||||
ENV CGO_ENABLED=0 GOFLAGS=-mod=readonly GOTOOLCHAIN=local
|
||||
COPY backend/ ./
|
||||
COPY scripts/s3-control.go /tools/s3-control.go
|
||||
RUN --mount=type=cache,target=/go/pkg/mod --mount=type=cache,target=/root/.cache/go-build go build -trimpath -ldflags='-s -w' -o /out/app ./cmd/app && go build -trimpath -ldflags='-s -w' -o /out/worker ./cmd/worker && go build -trimpath -ldflags='-s -w' -o /out/s3-control /tools/s3-control.go
|
||||
FROM debian@sha256:a29215f6a35e51e22adffa17f89e9d2ef06214e64a2bad10d765c46aea49f11f
|
||||
RUN apt-get update && apt-get install -y --no-install-recommends imagemagick ca-certificates && apt-get clean
|
||||
COPY --from=build /out/app /app
|
||||
COPY --from=build /out/worker /worker
|
||||
COPY --from=build /out/s3-control /s3-control
|
||||
COPY config/imagemagick-policy.xml /etc/vp7-imagemagick/policy.xml
|
||||
ENV MAGICK_CONFIGURE_PATH=/etc/vp7-imagemagick MAGICK_TEMPORARY_PATH=/tmp GOMEMLIMIT=384MiB
|
||||
USER 10001:10001
|
||||
CMD ["/app"]
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
# Helpers и фактические consumers
|
||||
|
||||
Все поддерживаемые orchestration helpers написаны на TypeScript/Bun. Original public Python tests вызываются неизменённым Makefile. Shell entrypoints лишь передают управление Bun/native entrypoint. Source-only package не содержит private operator files, binaries/images, plugin ELF или dataset.
|
||||
|
||||
## Основной operator path
|
||||
|
||||
- scripts/lab.ts: prepare/start/wait/unseal/stop/accept. accept использует git-proof-cli.ts: canonical proof проверяется до operatorPassword/start; без flags настоящий Git checkout сохраняет native-git default. git-tracking-source.ts читает bounded regular/no-symlink proof и operational hash map, git-tracking-proof.ts содержит required-port producer/reader, export-git-tracking.ts — реальный Mac Git query/HEAD producer. Это provenance, не пропуск native artifact audit.
|
||||
- bootstrap.ts, pki.ts, operator-crypto.ts, security-guards.ts: encrypted operator material, native OpenSSL CA/leaf/CRL и проверки identity/expiry; не собственный TLS/signing protocol. Root CA private key и recovery envelope не монтируются app/worker.
|
||||
- topology.ts, generate-agent-configs.ts, telemetry-dashboard.ts: actual Compose/gateways/HCL/dashboards/rules. Generated checked-in paths совпадают с mounts; original public contracts не генерируются заново.
|
||||
- runtime.ts: pinned Compose project+manifest, private command retention. command-runner.ts сохраняет primary command outcome при diagnostic I/O failure; unique receipts exclusive, last diagnostic best-effort.
|
||||
- runtime-preparation.ts выбирает canonical build либо explicit checked-cache. checked-runtime.ts связывает source112/09fe, accepted build receipt, immutable app image и три installed binary hashes. Canonical Dockerfile не заменён cached образом. preflight-build.ts удерживает INITIAL handover/source lease через compile/image packing, а не reread latest truth.
|
||||
- openbao-operator.ts и bao-client.ts: native HTTPS curl, same-process encrypted init capture, unseal/configure, root header только в private scratch. server.hcl задаёт non-dev PebbleDB и declarative audit. kv-secrets.ts разбирает полный native KVv2 envelope; Agents получают только свою роль, token sink отсутствует.
|
||||
- db-provision.ts: operator-only native PostgreSQL socket/GRANT/migrations. s3-provision.ts вызывает штатный SDK bridge, только ephemeral operator получает root config и response receipts. reload-gateway.ts выполняет verified owned native HAProxy master-worker reload, drain2с.
|
||||
|
||||
## Acceptance и доказательства
|
||||
|
||||
- acceptance-session.ts: public check/smoke/security, native PG/matrix/Bao/privileges, persistence, actual failover, extended, затем SHARED_HTTP_LOGIN → sharedLoginRuntime(password, operationId). Обычный `bun scripts/lab.ts accept` воспроизводит finite20main+2control shared429case; отдельный private runner для этого не нужен. acceptanceRemainder — общий оставшийся failover/extended/HTTP tail, а не повтор старых native phases.
|
||||
- hooks.ts/restart.sh/stop-one.sh: pinned public resilience hooks. replica-snapshot.ts читает UUID через exec в immutable owned container и rechecks start time; docker cp не читает tmpfs. failover-proof.ts связывает operation/attempt/service/alias/container с текущим readback, не fileexists.
|
||||
- sealed-shutdown.ts: required inspect/readFreshness/readEvents/retainBaseline/seal/clock/sleep ports. Baseline сохраняется до seal, rechecked после retention; нужны named freshness cause и exit/restart samecontainer. extended.ts сохраняет cause/503 до recovery, ждёт Bao health, контролируемо restart Agents и actual all3fresh renders, затем проверяет новый attachment. health-convergence.ts/freshSecretsAfterSeal и tests не имеют live defaults.
|
||||
- rotation.ts: worker compromise и общий finishWorkerRotation tail. Old cert/token denial, scoped S3 secret/CAS/new leaf/Agent render и durable job integrity разделены. Encrypted scenario checkpoint записывается до revoke; resumed native run честно проверил3старых jobs через DB+SigV4/mTLS S3, original API actor не восстановлен.
|
||||
- shared-login-case.ts: pure required request/clock factory, finite20main+2control/2inflight. student-tests/shared-login-runtime.ts — actual registration, direct verified mTLS replica curl, private credentials/responses, actor/alias/Retry-After checks и native bucket counters. Это functional429, не full DoS benchmark.
|
||||
- student-tests/postgres-transport.ts, matrix.ts, bao-policy.ts, privileges.ts, artifacts.ts: actual native consumers. Matrix8cases имеет отдельные PG/Grafana/Bao/application positive proofs. Artifact audit ограничен выбранными app secrets/source/3app logs/hardening; он не универсальный token/image/telemetry scanner.
|
||||
- native-security.ts: prepared owned-path native acceptance outer с exclusive claim, checked112 image/binary/source/Git guards, preserved history и finally stop0/owned0. Использует private disposable preflight key; это не замена ordinary operator lab CLI. Разовые resumed native runners .local/research остаются provenance в review/control records и не поставляются как поддерживаемые commands.
|
||||
- preflight-run.ts — actual consumer student-tests/freshness-runtime.ts для исторического scoped operator-provider preflight, не native Bao. finalize-preflight.ts/checkpoint-guards.ts сохраняют accepted history exclusive либо exact-identical bytes. package-checkpoint.ts проверяет FIRST snapshot/entryset/manifest, ZIP bytes и CRC; canonical stage дополнительно создаётся новым пустым allowlist copy до FIRST. Python/tool caches/compiled/private outputs исключены.
|
||||
- browser-lifecycle.ts — generic required acquire/run/close/reportCleanupFailure ownership helper, используется Grafana browser и native outer. newPage/listener failures покрыты fake ports, primary failure не подменяется cleanup failure.
|
||||
|
||||
## Telemetry и SDK exception
|
||||
|
||||
OpenObserve1.1.2/Collector-k8s0.163.2/Grafana13.3.1/plugin1.0.1 consumers и native schema находятся в docs/OPENOBSERVE-MIGRATION.md, docs/OPENOBSERVE-NATIVE-SCHEMA.json и docs/GRAFANA-NATIVE.md. openobserve.ts/accounts/account-workflow/session/pipeline/readback/cache и student-tests/openobserve-* проверяют собственные ServiceAccounts, raw-header без terminalCR/LF, fixed historical SQL/PromQL window, allow/deny и ingest/query mTLS. OSS native SA read/write; разграничение обеспечивает gateway. grafana-* helpers проверяют UID detail DTO+health, actual query frames/UI/correlation/alerts/response boundary; code/config presence не является UI PASS.
|
||||
|
||||
scripts/s3-control.go — единственный root-approved native SDK bridge. Dockerfile собирает /s3-control из уже locked minio-go7.4.1/signV4; Bun orchestration не дублирует signer и не добавляет SDK. Точные callers: s3-provision.ts → bootstrap с operator-only config; privileges.ts → prove-worker со scoped rendered config; rotation.ts → prove-stale с retired secret на разрешённом prefix, уже через новый leaf. Root file/receipt mount есть только у одноразового helper, не у app/worker.
|
||||
|
||||
Backend internal/adapter/freshness — единственный leaf, исходно назначенный infrastructure worker. Он имеет обязательные read/clock/ticker ports, bounded128byte regular-file reader и возвращает ошибки composition, не os.Exit. Остальные backend main/auth/broker принадлежат backend owner и сохранены в112-file handover. ARGON-BUDGET.md описывает отдельное уже выполненное KDF измерение.
|
||||
|
||||
Scan public readers/SBOM/results/raw reviews находятся в evidence/security-scan; их копии являются audit provenance, не новыми operator entrypoints. Аналогично evidence/vp и evidence/reviews/vp — exact public metadata mirrors для сохранённых root-relative review links. Historical grpc probe/fixtures не объявляются активным Tempo listener в текущем OpenObserve stack. Внешних helper imports из sibling lab6/private data у финального operator path нет.
|
||||
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"ref": "openbao/openbao:2.7.2",
|
||||
"image": "openbao/openbao@sha256:a78eb12a9fc7a3ebb4bec1724e2bdd6a28e33394820641d061166919a3f1866b",
|
||||
"compressed_bytes": 80087069,
|
||||
"platform": "linux/amd64"
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"scope": "common lab5 replay audit migration+atomic query; test fixture cleanup and real pipeline matrix; generated files require native sqlc",
|
||||
"sourceHashes": {
|
||||
"db/migrations/00005_replay_audit.sql": "234a04177bca08621fa38b135cb8086bcdd55ae9084008b25814751e1dd742a4",
|
||||
"db/sqlc/queries/pipeline.sql": "6c5fa5356024da6e70b7e3116a0765e2865342d7ca474caa4f647c04e4fb9cf4",
|
||||
"internal/application/usecase/pipeline_retry_test.go": "6068c07fdaa61fdb0bb0b73bd2094aacdec7a10ff2db1ebd64decb3288f2de5c",
|
||||
"internal/adapter/repository/postgres/pipeline_integration_test.go": "58274475a02f1098a0f79a65a9e8d7608d05dfa26213f90c706a9239fabb586c"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
{
|
||||
"original_head": "20afc2c790d3e72f6b7666376c9834c1ced1a405",
|
||||
"permitted_student_templates": [
|
||||
".gitignore",
|
||||
".dockerignore",
|
||||
"REPORT.md",
|
||||
"security/THREAT_MODEL.md",
|
||||
"contracts/trust-matrix.md"
|
||||
],
|
||||
"files": {
|
||||
".env.example": "5ebae6e3c45c2db8fd4cf42839fea1d067a556ed9e81c145d79f09b5f987a579",
|
||||
".github/pull_request_template.md": "a4fabdd8c4970c00e8af76550a90e3c9d8e7aa4843e78122682a30aca5c7551a",
|
||||
".github/workflows/contracts.yml": "a45d7932ef14130aff8020bce79f043cccaf9692d697088a754d309a03f7d3e8",
|
||||
"CONTRIBUTING.md": "2c01dd698cc9653dece49a94c9fd3f58d36e84764aaa643b46e26d7e599dc12e",
|
||||
"COURSE.md": "c34d53cd082d194aa4b58f504c4e0348d25b6afec3d6a9c0963dd01c9c81e971",
|
||||
"Dockerfile.example": "fd7ac9491c0c3c663b083c41a762fb38bc2d212fa4a2ed3e6a0702af72108709",
|
||||
"MAINTAINERS.md": "6e10c41ab1f287d3ef93cdeadbb22d49651a53e8b9d2578b279abed3931b20d1",
|
||||
"Makefile": "9a6113472699fd6ba0fdbb152dc5abfae217bf81f2d5e473ae5f0594bc9b36f0",
|
||||
"README.md": "69f277257a8246cf181790e6d7808e21355f4ca94b7b8fa4d60fcad026f5bd5f",
|
||||
"compose.example.yaml": "abcd9e7cfb57d3854a8362550cf36a0030cd417eac2a342abb5cb6c72c0e1896",
|
||||
"contracts/README.md": "72df27a559f88ffa3fd8c3c79d3c32f6db2c5986a0602677c51994c434a3fc4f",
|
||||
"contracts/attachment-states.md": "cf0519e137410e4b34ab632aadb8ad8a381d4b73033e27b354c58eeacbdf86d6",
|
||||
"contracts/examples.json": "381cc18c03789e935b391d007fb5843964be9cfd9f7530cb6b1996ed4a1c4c37",
|
||||
"contracts/infrastructure.json": "90b706e85ee2fcaa54e1113e98206555e0cd678caf03204c9ac363a6f1323d30",
|
||||
"contracts/jobs.schema.json": "9ccf9b11466c0c3a26a941520ac5ff543241fc4935e3a6eebb01ef303779b10d",
|
||||
"contracts/observability.md": "882c120c0e153a06c9cc824a802e317c58eb6590bc3d3a576f2e0a96f8597b62",
|
||||
"contracts/openapi.json": "51dd0b8199aee7be81437056144c5fca9d82c2b4387dae62585cadf230ee749a",
|
||||
"evidence/README.md": "78e4bfd738d034597d15d8846accd8a8a5dc738a23a3d15f243f3992bd530cc3",
|
||||
"examples/requests.http": "e69880f740f1e346354b519f14487d2bfcf1a41cbaa8cbedc61d258e7592fd3a",
|
||||
"infra/README.md": "0e804fa51debba4c38d3cc84abf4704897665e0335b272060363f03aadd6354f",
|
||||
"infra/openbao/README.md": "b44e14af0ba9fb4adbf1456e97775b544be4e9b8f9eaf4cb76fc86ac4ab8f4ae",
|
||||
"infra/otel/README.md": "0d6c93589f7b96b7045c1b82a261362697d25f14c9e1a4946b8ea8a977c1e842",
|
||||
"lab.json": "f4cc620370d5c84be3d7a4422c48c05398cb28aa89185d4141b534b58e4b51c4",
|
||||
"requirements-dev.txt": "4cefdb67007caf026d1613be7c519c01b4c8343db7c4f4b618677e01cf113525",
|
||||
"scripts/check_contract.py": "7c4402c2a6ab80d3b4676e1866d6ecc87b6daea14c080bcb9be9a7e8b959d671",
|
||||
"scripts/restart.example.sh": "0328246ba75defbced992104e986fde973f63e3830d83251eced5953263e944b",
|
||||
"scripts/stop-one.example.sh": "1bcf34394520b89d95b7605ec56675be799eea920e83cfbba306d5dc0a6d9811",
|
||||
"scripts/validate_openapi.py": "4e981acbfc10dac58817bf922d5896e996798551fedc1b2385130e1cddb13d54",
|
||||
"tests/README.md": "e0bfa7e196797f6a5bf6e44d8ad2ffeb82651927ff5d8484eb1c2dda1ec7dec5",
|
||||
"tests/client.py": "8d50976fc7c7bbb81e88a152f613c61ab25eaf53dba33c6a9dfab19f868d546d",
|
||||
"tests/fixtures/README.md": "c001783760b4f87a7a8441a7ba55f5d080ff48e1397d3581d72a88d7691f96c2",
|
||||
"tests/fixtures/sample.png": "99ea7533c441f79cd630d15ce4d58d1ec4e06f6f0efb3b77a5c088305cd1bd75",
|
||||
"tests/image_probe.py": "a9a4f89181c8e0fda6ce42e1a1af32fb42d8e3ae519e314207127c9b9b448b13",
|
||||
"tests/load.py": "6d3511ea719c7a7e841083e73d435c86dcbfd9f4e5c2a07d62eb9614b01d9933",
|
||||
"tests/resilience.py": "1f96663a174b3978d24eff66f2741f5f8c9b788d3242261d37a972720c52788b",
|
||||
"tests/security.py": "6560a56cc22981c9f06043709bfabe7a47fa7eab57e62741e95534ac5ddff8a7",
|
||||
"tests/smoke.py": "52ac38eb343ff7d43e7543588e1da58ca06c9fce74b2b0d0bf0e4982bc23c1db"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
{
|
||||
"state": "SOURCE_CHECKPOINT_WITH_SCOPED_NATIVE_OPENBAO_ACCEPTANCE",
|
||||
"backend_checked_at": "2026-11-15T19:04:33.200Z",
|
||||
"backend_files": 112,
|
||||
"backend_handover_sha256": "09fe19253582282e489406600f3ee20c1e52d786778d6ce90f9d9da4146e5609",
|
||||
"cached_runtime_checked": true,
|
||||
"canonical_fresh_build_checked": false,
|
||||
"native_runtime_source_generation_sha256": "896fde84a7b1ffc339e44a2c61ac4995208811b25acd6e506801751ffca607f0",
|
||||
"delivery_git_proof_reference": "evidence/openbao/DELIVERY-GIT-PROOF.json",
|
||||
"composite": "evidence/openbao/NATIVE-COMPOSITE.json",
|
||||
"native_openbao_accepted": true,
|
||||
"native_telemetry_accepted": false,
|
||||
"whole_telemetry_complete": false,
|
||||
"full_security_complete": false,
|
||||
"track1_native_experiment_completed": true,
|
||||
"grade5_accepted": false,
|
||||
"teacher_grade": null,
|
||||
"source_checks": "evidence/openbao/source-6a182103-6476-49cf-ab5b-54cca2008fea/CHECKS.json",
|
||||
"source_typecheck_files": 123,
|
||||
"unit_tests": 178,
|
||||
"unit_assertions": 420,
|
||||
"formatter_exit": 0,
|
||||
"source_native_session": 67568,
|
||||
"source_whole_exit": 0,
|
||||
"final_native_session": 39107,
|
||||
"final_native_whole_exit": 0,
|
||||
"final_native_receipt": "evidence/openbao/native-final-recovery-http-210df47b-593c-4fcf-b4f5-ecf0496eccb5.json",
|
||||
"remaining_owned_containers": 0,
|
||||
"stop_exit": 0,
|
||||
"stop_seconds": 12.021,
|
||||
"reviews": {
|
||||
"native": "evidence/reviews/review-vp7-openbao-native.md",
|
||||
"cli": "evidence/reviews/review-vp7-accept-cli.md",
|
||||
"scan": "evidence/security-scan/review-vp7-scan-independent.md"
|
||||
},
|
||||
"download_approval": {
|
||||
"grafana_plugin_quota": 600000000,
|
||||
"grafana_plugin_used": 559001001,
|
||||
"openbao_quota": 85000000,
|
||||
"openbao_used": 80099233,
|
||||
"sii_authorized": false
|
||||
},
|
||||
"historical_readiness": "evidence/history/pre-native-closure/READINESS.json",
|
||||
"historical_grafana_results_preserved": true,
|
||||
"private_cleanup_retained": true,
|
||||
"delivery_archive_review_pending": true,
|
||||
"delivery_git_proof_sha256": "43d8d6409745fd2f5a90992c4c7061fc5121c868ce3ba0e19d386dc10141531b",
|
||||
"delivery_source_generation_sha256": "baff31433553d9075080e5f2c87dfa09ec24e9412b126c815df70eae6aef312a",
|
||||
"delivery_source_files": 311,
|
||||
"delivery_source_only_after_native": true,
|
||||
"ordinary_accept_shared_http_login_wired": true,
|
||||
"source_only_wiring_after_native": true
|
||||
}
|
||||
@@ -1,37 +1,55 @@
|
||||
# Отчёт — лабораторная 7
|
||||
# Лабораторная 7. Безопасность мессенджера
|
||||
|
||||
- Автор, группа: TODO
|
||||
- Целевая оценка; выбранный трек 5, если нужен: TODO
|
||||
- Commit/PR: TODO после публикации
|
||||
- Использованные источники, библиотеки и помощь ИИ: TODO
|
||||
Медведев Андрей Михайлович, БПИ2303. Целевой результат — требования уровня4 и исследовательский трек1 уровня5 «Компрометация worker». Оценка преподавателя, публикация и PR не заявляются. Использована помощь ИИ; самостоятельные reviews и их точные границы приложены. Original README/COURSE/CONTRIBUTING, public tests и OpenAPI сохранены.
|
||||
|
||||
## Запуск из чистого clone
|
||||
## Текущий результат и доказательства
|
||||
|
||||
TODO: версии runtime/образов, prerequisites, команды создания локальных secrets/.env, build, миграций, запуска, ожидания готовности, тестов и остановки. Указать необходимые действия оператора. Не вставлять секреты. Отдельно указать безопасную остановку и команду намеренного удаления учебных данных.
|
||||
Завершены native OpenBao2.7.2/PebbleDB/cert-auth/Agent, scoped policies/renew/revoke/TTL, HTTPS persistence и отказ обеих API-реплик, ротация worker secret/leaf с сохранением трёх исходных jobs, causal sealed rejection и последующее восстановление, функциональный общий HTTP login limit. Это составная приёмка отдельных фаз: прежние whole-command failures остаются FAILED. [NATIVE-COMPOSITE.json](evidence/openbao/NATIVE-COMPOSITE.json) связывает35proofs; [навигация по независимым native/CLI reviews](evidence/reviews/OPENBAO-NATIVE-REVIEW.md) и [tool control records](evidence/openbao/native-control-a19bbdb5-6569-4604-9207-6ca9216ba33c.json) раскрывают происхождение outcomes.
|
||||
|
||||
## Архитектура и решения
|
||||
Последний remaining command39107 завершился wholeexit0, post source/image/binary guards=true, stop_exit0; весь собственный Compose project остановлен за12,021с, running containers0. Его область — только all3Agent recovery/upload и bounded HTTP429. Он не переименовывает прежние34156/96169/65111/26458 в успешные целиком.
|
||||
|
||||
TODO: схема процессов/хранилищ, источник истины, транзакционные границы, ограничения. Что перенесено из lab6, что изменено в этой работе. Соответствие переменных из .env.example реальной конфигурации.
|
||||
Backend112 передан с checkedAt2026-11-15T19:04:33.200Z, SHA09fe19253582282e489406600f3ee20c1e52d786778d6ce90f9d9da4146e5609. Native использует заранее проверенные cached app/worker/s3-control binaries в immutable image10ba7b17671b…, с pre/post checks. Fresh canonical Dockerfile build не выполнялся; default canonical путь и checked-cache режим разделены. Новая CLI-only proof дельта проверена отдельно, без повторного native run. Последний полный source check:123TypeScript files,178tests/420assertions, nonwriting formatter0; [CHECKS](evidence/openbao/source-6a182103-6476-49cf-ab5b-54cca2008fea/CHECKS.json).
|
||||
|
||||
## Доказательства критериев
|
||||
## Архитектура и права
|
||||
|
||||
| Критерий README | Команда/сценарий | Наблюдаемый результат | Файл доказательства |
|
||||
| --- | --- | --- | --- |
|
||||
| Публичный smoke | make test | TODO | TODO |
|
||||
| Остальные пункты уровня 3 | TODO | TODO | TODO |
|
||||
| Все пункты уровня 4, если заявлен | TODO | TODO | TODO |
|
||||
| Выбранный трек 5, если заявлен | TODO | TODO | TODO |
|
||||
Две Go API-реплики и отдельный worker сохраняют lab6 API и асинхронный pipeline. PostgreSQL18.6 хранит бизнес-данные, sessions, metadata и durable jobs/outbox; RustFS1.0.0-rc.1 хранит staging/originals/variants; Valkey9.1.2 доставляет Streams. Источник состояния задачи — PostgreSQL, очередь не заменяет durable запись. Worker использует отдельный XADD-only publisher и consumer с XAUTOCLAIM/XACK/XDEL; API cache-only.
|
||||
|
||||
TODO: добавить отдельную строку для каждого заявленного критерия. PASS без команды и наблюдения не является доказательством. Проверка инфраструктурного hook требует подтверждения, какие реальные процессы/хранилища перезапущены.
|
||||
Клиент использует HTTPS localhost:18443. HAProxy3.2.26 проверяет SAN каждой API и предъявляет CN=lb; API gateways требуют доверенную цепочку, CRL и допустимый CN. App/worker и их proxy делят network namespace, plaintext endpoints слушают только loopback. На межконтейнерных границах TLS проверяет server CA/hostname; S3/broker/Collector/OO listeners дополнительно разделяют client identities. PostgreSQL использует native TLS1.3/direct ALPN postgresql и cert auth CN=SQL role. Первый SCRAM-over-local-proxy вариант libpq18 корректно отверг; успешный app query не выдаётся за SCRAM login. Operator сохраняет direct verify-full+SCRAM.
|
||||
|
||||
## Эксперименты и отказы
|
||||
OpenBao работает вне dev-mode с PebbleDB в отдельном persistent volume. File storage удалён в2.7; первоначальный bootstrap отказ сохранён, proxy/network ради него не менялись. Init response с3shares/threshold2 и root token шифровался в том же процессе. Успешный f067 имеет initialized_before=true: он доказывает reuse/unseal/policy, а не целиком успешный fresh-volume bootstrap. API/worker Agent используют разные cert-auth роли, TTL60/max300с, scoped KVv2 и self operations без default policy. Root/shares/CA private key остаются у оператора. Agent token не имеет sink, а файлы приложения0600/read-only содержат только его роль.
|
||||
|
||||
TODO: гипотеза, hardware/лимиты, версии, объём данных, профиль нагрузки, concurrency/arrival rate, длительность/прогрев, повторы, успешные RPS, ошибки, p50/p95/p99, CPU/RAM. Сохранить raw summary без tokens и объяснить ограничения измерения.
|
||||
Подробные границы: [trust matrix](contracts/trust-matrix.md), [API boundary](API-BOUNDARY.md), [threat model](security/THREAT_MODEL.md), [cases](docs/SECURITY-CASES.md). App/worker non-root/read_only/dropALL/no-new-privileges, с CPU/RAM/pids/tmpfs limits; stateful data и краткие PostgreSQL entrypoint privileges объяснены отдельно. Effective hardening проверен native inspect.
|
||||
|
||||
| Воздействие | Что ожидаем | Что наблюдали | Время восстановления / потеря данных |
|
||||
| --- | --- | --- | --- |
|
||||
| TODO | TODO | TODO | TODO |
|
||||
## Native security и исследовательский трек1
|
||||
|
||||
## Ограничения и следующие шаги
|
||||
Public smoke/security через проверенный CA, PostgreSQL real SELECT, восемь matrix frontend/role cases, scoped Bao и DB/S3/queue ACL прошли до первого failover-reader failure. Public persistence перезапустил реальные stores/процессы без удаления volumes и сохранил session/data. Следующий run доказал actual stop обеих replicas по одному operationID и разным attempts/containerIDs, после чего прошли expired/future leaf controls. Подробные hash bindings находятся в composite; строки конфигурации не подменяют negative acceptance.
|
||||
|
||||
TODO: какие отказы выдерживаются и какие нет; что не реализовано; где учебное упрощение; какое улучшение подтверждено, а какое пока гипотеза.
|
||||
Гипотеза трека1: scoped worker способен завершать разрешённые jobs и S3 prefixes, но не читать users/sessions/chats/messages, создавать SQL роли/таблицы, администрировать S3/Valkey, писать чужие prefixes или публиковать через consumer identity. Native allow/deny подтверждены [worker privileges](evidence/security/worker-privileges.json). По сравнению с operator/root возможностями, необходимыми bootstrap для GRANT/IAM, эти действия для worker запрещены; отдельная атака под unrestricted identity не выполнялась.
|
||||
|
||||
Три реальных upload были приняты queued при остановленном worker. Отозваны его leaf через CRL и два token accessor, проверены old-token denial и новый TLS отказ. Первый oracle не знал точный native certificate-revoked code; его wholeFAIL сохранён, classifier исправлен RED/GREEN. Затем продолжена та же ротация без повторного revoke/upload: новый S3 secret, KVv2 CAS, новый leaf, native gateway reload/drain и Agent render. Old secret проверялся уже с новым допустимым transport, на разрешённом prefix, поэтому TLS/ACL отказ не маскировал secret revocation.
|
||||
|
||||
[Те же три attachment/job IDs](evidence/openbao/rotation-recovery-885c8009-d46d-4296-80b7-086e85b58dfe.json) стали ready/completed. Каждый S3 GET вернул200 и111817bytes, raw bytes равны original fixture и SHA99ea7533c441f79cd630d15ce4d58d1ec4e06f6f0efb3b77a5c088305cd1bd75. Original peer token остался только в памяти прежнего процесса и не восстановлен: это DB+native SigV4/mTLS S3 integrity proof, не повторный API доступ старого actor. Новые сценарии сохраняют encrypted checkpoint до revoke. Образы при ротации не пересобирались. Потеря host/store, CA или operator root этим экспериментом не покрыта.
|
||||
|
||||
## TTL, seal и восстановление
|
||||
|
||||
Token TTL60: own read200, после expiry новый read403, fresh same-role auth/read200. Sealed-only case сохранил исходный fresh/running baseline до seal, post-seal event secret_freshness_failed вместе с restart того же контейнера и public503 до recovery. Наблюдение API1/API2/worker произошло через125,932/120,767/122,233с. Это не обещание всем остановиться строго за120с: default max age120с/poll5с дополняется scheduling, sampling и graceful shutdown; hung filesystem/host не покрыт.
|
||||
|
||||
Два recovery guard обнаружили реальные orchestration gaps: Compose увидел предыдущий unhealthy tick сразу после unseal; затем worker Agent ещё был в native sealed-error backoff до1мин17,97с, хотя API уже готов. Теперь recovery ждёт health того же Bao container, контролируемо перезапускает три Agent и ждёт фактические post-seal свежие файлы всех трёх сервисов. Последний remaining run доказал эти renders и реальную обработку нового upload с byte equality. Новый seal не повторялся: исходный baseline/cause/503 уже сохранён и независимо принят.
|
||||
|
||||
## Пароли, login budget и telemetry
|
||||
|
||||
Argon2id32МиБ/t2/p1, уникальный salt и параметры, bounded legacy verify/CAS rehash. KDF concurrency2/process и HTTP gate4inflight/queue32 ограничивают дорогую работу. Общая quota10attempts/60с использует4096SHA256-name buckets PostgreSQL; коллизии могут затронуть другое имя. [KDF budget](ARGON-BUDGET.md) содержит прежнее native измерение и его пределы.
|
||||
|
||||
Новый [HTTP case](evidence/security/shared-login-210df47b-593c-4fcf-b4f5-ecf0496eccb5.json) выполнил20main requests парами через обе verified mTLS replicas:10session201 и10application429 с Retry-After60. Затем2other-account controls201; persisted counters10/2, aliases/containers неизменны. Максимум2inflight, main window1376мс. Это функциональный shared-limit proof, не RPS и не full-service DoS benchmark.
|
||||
|
||||
OpenObserve1.1.2 заменяет три telemetry stores; Collector-k8s0.163.2 и Grafana13.3.1 остаются. Native all3 ingestion/persistence,42spans/41parents и correlated logs,19finite panels, реальные logs↔trace clicks и две исходные alert rules firing/resolved проверены отдельно. Использован unmodified сторонний OpenObserve1.0.1 plugin; compiled backend dirty/devel source gaps сохранены. Gateway enforce query/ingest identities; OSS ServiceAccount сам по себе read/write. Request.size не является SQL row/work cap,8МиБ response boundary не является RAM/decompression/absolute-time bound. [Grafana evidence](docs/GRAFANA-NATIVE.md), [migration](docs/OPENOBSERVE-MIGRATION.md).
|
||||
|
||||
## Scan и пределы результата
|
||||
|
||||
[Scan/independent review](evidence/security-scan/README.md):9immutable images и actual mounted plugin,1468unique package-version lookups,88matched groups,440advisory IDs,16representative primary records. Advisory aliases не посчитаны уникальными CVE. Debian source epoch/version/release и reused consumer attribution исправлены с RED/GREEN; unsupported Cargo/dirty/devel и прочие coverage gaps явно оставлены. CVE-free, exploit proof и remediation complete не заявлены.
|
||||
|
||||
Artifact audit проверил выбранные generated app secrets в source/трёх app logs и effective hardening; Git tracking имеет настоящий canonical query/HEAD/empty-result proof. Это не универсальное доказательство отсутствия каждого возможного Bao token/image/telemetry leak. Raw successful audit body не сохранён: native device/log_raw guard и HCL path/mode attribution разделены. Full security/whole telemetry/grade flags в raw final outer остаютсяfalse; scoped native acceptance и законченный track1 не переименованы в оценку преподавателя.
|
||||
|
||||
Пользователь разрешил600000000bytes для Grafana/plugin, coordinator использовал559001001 один раз; дополнительно85000000 только OpenBao, actual80099233. СИИ этой квотой не разрешён. Старые source ZIP ca313/361/D77/8e15/102 и false flags сохранены исторически. Текущие operator commands — [RUN](RUN.md), consumers — [HELPERS](HELPERS.md), краткий machine-readable статус — [READINESS](READINESS.json). Новый source archive получает отдельную CRC/entryset/all-bytes проверку; private keys/env/envelopes/data/cookies/build artifacts в него не входят.
|
||||
|
||||
Поставляемый ordinary accept теперь вызывает SHARED_HTTP_LOGIN после extended acceptance с тем же operation ID. Это source-only wiring существующего native-проверенного helper; новый полный native run не выполнялся. Последний standard check123TS/178tests/420expect/fmt0 завершился exit0 (session67568).
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
# RUN: оператор лабораторной7
|
||||
|
||||
Рабочая папка — корень lab7. Стек: OpenObserve1.1.2, Collector-k8s0.163.2, Grafana13.3.1 с готовым сторонним OpenObserve1.0.1 plugin, PostgreSQL18.6, Valkey9.1.2, RustFS1.0.0-rc.1, HAProxy3.2.26 и non-dev OpenBao2.7.2/PebbleDB. Native acceptance завершена в составной области [REPORT](REPORT.md); fresh canonical Dockerfile build не заявляется. Исторические outcomes не переписываются.
|
||||
|
||||
## Среда и artifact boundary
|
||||
|
||||
Bun1.4.4, Docker29.9.2/Compose, OpenSSL, curl и Python>=3.9 для неизменённых public tests. Native проверки/stands выполняются только на omarchy в /mnt/data/home/bench-saves/mtuci-vp7-security-20261115, project mtuci-vp7-security. Runtime images закреплены в scripts/topology.ts/compose.yaml; pull_policy=never и image guards запрещают незаметный runtime pull. Canonical Dockerfile отдельно требует доступных builder/base, Go modules и apt artifacts; его build prerequisites не подменяются наличием runtime cache.
|
||||
|
||||
Разрешено600000000bytes только Grafana/plugin, потрачено559001001coordinator; OpenBao quota85000000, потрачено80099233, imageIDa78eb12a…/linux-amd64/version2.7.2/build9e0a0d3c3504a0a00b45e61355afac5e35c78379. Повторных downloads Lab7 для GF/plugin нет, СИИ не разрешён. Source ZIP не содержит images, plugin ELF, node_modules, PKI, secrets или dataset: эти prerequisites предоставляются отдельно по pinned public references. Cache aliases не являются переносимой заменой registry provenance.
|
||||
|
||||
Только loopback: HTTPS18443, Bao18445, Grafana18447. LB/Bao/Grafana gateway имеют edge network для проверенного Docker29 publication; внутренние зависимости/API ports не опубликованы. Все operational helpers закрепляют и manifest, и project. Обычные проверки идут в background.slice; release builds/browser/stands на Mac не запускаются.
|
||||
|
||||
## Подготовка и запуск
|
||||
|
||||
1. Проверить source archive/manifest и BACKEND-READY.json:112files, SHA09fe19253582282e489406600f3ee20c1e52d786778d6ce90f9d9da4146e5609. Не переносить меняющийся backend из другой лабораторной. Установить только имеющиеся зависимости: `bun install --offline --frozen-lockfile --ignore-scripts`.
|
||||
2. Выполнить `bun scripts/lab.ts help`, затем `bun scripts/lab.ts prepare`. Скрытый prompt принимает operator passphrase>=20символов. Сохранить её у оператора. Повторный prepare на существующей .local останавливается, чтобы не заменить данные/CA. Он создаёт encrypted services envelope, PKI и конфигурацию; CA private key/root/shares не попадают в app mounts/build.
|
||||
3. Для реального Git checkout обычная полная команда — `bun scripts/lab.ts accept`. Она использует native Git tracking. Default canonical mode строит Dockerfile; перед ним prerequisites/cache и разрешение на возможные downloads должны быть обеспечены оператором. Verified native receipt в этом пакете относится к checked112 cached image, а не fresh canonical build.
|
||||
4. Для ZIP без .git использовать включённый canonical Git proof. Следующие значения соответствуют именно этой source generation:
|
||||
|
||||
`VP7_GIT_PROOF='evidence/openbao/canonical-git-proof-c86324e1-7920-469a-b8b3-fdda55d25c26.json'`
|
||||
|
||||
`VP7_GIT_PROOF_SHA='43d8d6409745fd2f5a90992c4c7061fc5121c868ce3ba0e19d386dc10141531b'`
|
||||
|
||||
`bun scripts/lab.ts accept --git-proof "$VP7_GIT_PROOF" --git-proof-sha "$VP7_GIT_PROOF_SHA"`
|
||||
|
||||
Proof проверяется до password prompt/start. Missing/changed/mismatched proof/source fail closed; git init/skip/пустая подстановка не допускаются. После изменения operational source нужен новый trusted canonical Git producer checkpoint. Точный reference также находится в evidence/openbao/DELIVERY-GIT-PROOF.json. На данном omarchy допускается явно добавить --checked-cache к accept: helper проверит source112, immutable imageID и три binary SHA до/после; build/pull fallback отсутствует.
|
||||
|
||||
До start нужны также проверенные plugin assets в .local/plugins/openobserve. На этом omarchy команда `bun scripts/grafana-cache.ts` проверяет уже одобренные public CACHE-READY/image/plugin hashes, создаёт собственный alias/copy и ничего не скачивает; source lab6 и его credentials не меняются. Для этого cache alias private .env может задавать VP7_GRAFANA_IMAGE=mtuci-vp7-grafana-cache:13.3.1-1c88285f1dd3. На другой машине этот helper с фиксированным coordinator path не является installer: заранее предоставить тот же SHA-verified unmodified plugin и pinned image; default image reference остаётся canonical digest. Точный ZIP SHA и build/source границы находятся в docs/GRAFANA-NATIVE.md и docs/GRAFANA-INITIALIZER.md.
|
||||
|
||||
Перед запуском: `bun run check`, `bun run test:unit`, `bun run format:check`, `make check`. Последний source check123files/178tests420assertions/fmt0 включает lifecycle, freshness, failover, HTTP и CLI regressions. Native queue ACL fixture запускается отдельно `bun run test:acl` в собственном disposable сервере.
|
||||
|
||||
Для низкого приоритета на omarchy: `systemd-run --user --scope --slice=background.slice -p CPUWeight=20 -p IOWeight=20 nice -n 15 bun scripts/lab.ts start --checked-cache`. Перед этим bun должен разрешаться в установленный1.4.4; проверенный путь /home/rey/.local/share/mise/installs/bun/latest/bin/bun. Это не приглашение version-manager автоматически что-либо устанавливать.
|
||||
|
||||
## Что делает accept
|
||||
|
||||
Start регенерирует actual configs, проверяет images/source, запускает stores, native Bao init/unseal, migrations, точные GRANT и scoped S3 bootstrap, затем Agents/gateways/API/worker/telemetry. Готовность требует обе API и опубликованный HTTPS. Accept выполняет public check/smoke/security, native PostgreSQL query/trust/auth, реализованную matrix, Bao policy/TTL/renew/revoke, worker privileges, persistence и operation-bound отказ обеих replicas, leaf lifetime, worker secret/cert rotation, artifact/hardening и causal sealed lifecycle. Затем стадия SHARED_HTTP_LOGIN выполняет20основных запросов через обе replicas и2контрольных: нужны10accepted/10shared429 с Retry-After и успешные controls. Это функциональная проверка, не нагрузочный бенчмарк. Основные cases заранее описаны в docs/SECURITY-CASES.md и docs/NATIVE-BAO-CASES.md. Исследовательский сценарий меняет только synthetic data/credentials своего stand; повтор частично выполненной rotation без saved-state guards запрещён.
|
||||
|
||||
Matrix helper содержит8frontend/role cases: API1/API2, broker(api), S3(worker), оба Collector clients, OOingest/query. Native PostgreSQL, application/worker positive operations, Grafana HTTPS и Bao policy имеют отдельные proofs. Не следует выдавать эти8за самостоятельный negative replay каждого возможного caller/всех будущих transport paths. Полный universal security/telemetry/grade PASS не следует из наличия команды.
|
||||
|
||||
Публичные ручные команды после готовности:
|
||||
|
||||
`make test BASE_URL=https://localhost:18443 CA_FILE="$PWD/.local/pki/lb/ca.crt"`
|
||||
|
||||
`make test-security BASE_URL=https://localhost:18443 CA_FILE="$PWD/.local/pki/lb/ca.crt"`
|
||||
|
||||
TLS verification не отключается. Public resilience hooks вызываются accept с текущими operation/attempt IDs; arbitrary старые receipts не заменяют свежие container/alias outcomes. Ordinary accept является library orchestration; при его ошибке оператор обязан выполнить stop ниже. Проверенные native outer runners дополнительно имели finally teardown и exclusive evidence claim; это явно указано в composite.
|
||||
|
||||
## OpenBao и восстановление
|
||||
|
||||
OpenBao использует persistent /bao/data/pebbledb (host .local/data/bao/pebbledb), не dev-mode и не удалённый в2.7 file backend. [Native storage documentation](https://openbao.org/docs/configuration/storage/pebbledb/). Первый init3shares/threshold2 шифрует response до дальнейших действий. При uncertain init сначала проверить существующее состояние штатным helper, не повторять init и не заменять envelope. Root/unseal shares не доступны приложению. Audit device задан HCL, log_raw=false/mode0600, вне app mounts; запрещённый по умолчанию API audit creation не включается unsafe flag.
|
||||
|
||||
После рестарта Bao: `bun scripts/lab.ts unseal`. После successful unseal дождаться native health и контролируемо перезапустить Agents; их sealed-server retry backoff может пережить API readiness:
|
||||
|
||||
`docker compose --env-file .env -f compose.yaml -p mtuci-vp7-security restart api1-agent api2-agent worker-agent`
|
||||
|
||||
В sealed acceptance health convergence и actual post-seal freshness всех трёх сервисов проверяются автоматически; worker readiness доказывается новым processed attachment. Для ручного восстановления проверить `bun scripts/lab.ts wait` и public pipeline test выше; wait сам по себе проверяет API, не все Agent files. Диагностика `bun scripts/diagnose.ts worker worker-agent worker-gateway broker` сохраняет raw logs privately; секреты/DSNs/headers в общий вывод не печатать.
|
||||
|
||||
Freshness default120с/poll5с — временная настройка, не фиксированный instructor limit. Native observed event+restart120,767/122,233/125,932с включает sampling/scheduling/drain. Future/malformed/stale/oversized input fail closed. Это не hard wall-clock обещание для hung localFS/host. Rotation использует CRL, новые соединения, native gateway reload с drain2с, scoped secret и KVv2 CAS; старый pool не доказывает revoke.
|
||||
|
||||
## Limits и остановка
|
||||
|
||||
Argon2id32МиБ/t2/p1, KDF2/process, общий atomic10attempts/60с в4096buckets; [измеренный бюджет](ARGON-BUDGET.md) отделён от функциональных22HTTP requests. App image processing ограничен10МиБ/40млн pixels, worker concurrency2/attempts5 и context timeouts. API CPU0,5/worker CPU1, по2ГиБ с GOMEMLIMIT1536MiB, pids/tmpfs/read_only/dropALL/no-new-privileges. Эти настройки не гарантируют доступность при любой нагрузке. App stop grace15с превышает drain8с+SDKshutdown3с; последний весь owned project остановлен за12,021с.
|
||||
|
||||
`bun scripts/lab.ts stop`
|
||||
|
||||
Stop сохраняет данные; после работы не должно остаться running контейнеров mtuci-vp7-security. Private .local/.env/envelopes/cookies/response files и failed datasets никогда не включать в Git/build/ZIP. reset-failed-test.ts переносит только guarded owned test-state в приватную историю; это не универсальная очистка и не повод повторять partially applied rotation. Shared docker prune/другие stands/runner не трогать. Пароль оператора и encrypted recovery material сохраняются отдельно; автоматическая физическая очистка исторических данных не выполнялась.
|
||||
@@ -0,0 +1,722 @@
|
||||
{
|
||||
"state": "SOURCE_CHECKPOINT_NATIVE_GATES_PENDING",
|
||||
"grade_awarded": false,
|
||||
"backend_checked_at": "2026-11-15T19:04:33.200Z",
|
||||
"preserved_public_files": 37,
|
||||
"files": {
|
||||
".dockerignore": "812aa37ea2e8bb4fa401985f241a8d36b4da9330fc2fd0e00f9ba74f664e8f0e",
|
||||
".env.example": "5ebae6e3c45c2db8fd4cf42839fea1d067a556ed9e81c145d79f09b5f987a579",
|
||||
".github/pull_request_template.md": "a4fabdd8c4970c00e8af76550a90e3c9d8e7aa4843e78122682a30aca5c7551a",
|
||||
".github/workflows/contracts.yml": "a45d7932ef14130aff8020bce79f043cccaf9692d697088a754d309a03f7d3e8",
|
||||
".gitignore": "34d2834a588b0eb0817c57f7c15e9c4ac2837b1fa2ffca5e736e9a73285e4c02",
|
||||
"API-BOUNDARY.md": "6eee96b19add6ab3650969f9d500804f0812f7db4c4bdd6b7800227c09018650",
|
||||
"ARGON-BUDGET.md": "1acf748c57af04ad6f8e48c348e0569e8743b36933500d357f73b435f6cfd47a",
|
||||
"BACKEND-READY.json": "09fe19253582282e489406600f3ee20c1e52d786778d6ce90f9d9da4146e5609",
|
||||
"BACKEND-SECURITY-CASES.md": "1c757fda94dc660aabd82534168b4afef3e89507b4444c4d47680cc42117f95d",
|
||||
"CLAUDE.md": "6efd8f95678e927f0bffd8bf3dd85f274cc585c252f5929498a890e2f44a7c1a",
|
||||
"CONTRIBUTING.md": "2c01dd698cc9653dece49a94c9fd3f58d36e84764aaa643b46e26d7e599dc12e",
|
||||
"COURSE.md": "c34d53cd082d194aa4b58f504c4e0348d25b6afec3d6a9c0963dd01c9c81e971",
|
||||
"Dockerfile": "d2f64e65ef1d1db0e6130b9105f86dbabe31c4fdaf0686581920effde215d6d9",
|
||||
"Dockerfile.example": "fd7ac9491c0c3c663b083c41a762fb38bc2d212fa4a2ed3e6a0702af72108709",
|
||||
"HELPERS.md": "a1d853e67740a1d915a5502529d1bc45e99214293a48f97f16f5b197d49c0d97",
|
||||
"MAINTAINERS.md": "6e10c41ab1f287d3ef93cdeadbb22d49651a53e8b9d2578b279abed3931b20d1",
|
||||
"Makefile": "9a6113472699fd6ba0fdbb152dc5abfae217bf81f2d5e473ae5f0594bc9b36f0",
|
||||
"OPENBAO-IMAGE.json": "5715fdbe8aab593ef3a4fc3fc08daf499f75076d2b8f8d6d97cfe5af133a52f1",
|
||||
"PIPELINE-AUDIT-DELTA.json": "392dd49e8eeedb21fdefe39136e4b975c1be781f856b8127f04adee4da57d5ef",
|
||||
"PUBLIC-BASELINE.json": "27aaada11821cf7327c7a19e9c0203b9e94cb196a0522fd0e1ccabaa63cdfbbe",
|
||||
"READINESS.json": "9ceb42bc5ed2a6024aeba10215615af1856cd6e83ac82fc15d9b0c91cdfd0686",
|
||||
"README.md": "69f277257a8246cf181790e6d7808e21355f4ca94b7b8fa4d60fcad026f5bd5f",
|
||||
"REPORT.md": "7fc26c64bdf5e79c64d18e46f63c50cfed63e06f9e2628569a2ed3b0335e6c80",
|
||||
"RUN.md": "522e79a62a933d811aee67beb75a1a41f8c20a9cfd147732806ec86829a60de7",
|
||||
"STATUS.md": "43d605e4639bd9db8c20569bdd9227adea1480f9769025f86cc44485168c3d3b",
|
||||
"backend/.golangci.yaml": "215578dee14bcef1b66759a68543083e0a624611efcdb785197307b50cb7725d",
|
||||
"backend/cmd/app/main.go": "f58ec5740b3f376ae34f18d87fa724dc718f247b6354449ea3093f7a088ca838",
|
||||
"backend/cmd/worker/main.go": "84bfbeb0f867535cd2bcd512619ff29bec8550bc444af5dbeed8994f9522e919",
|
||||
"backend/codegen.yaml": "e4d37ce5c5a9f969f696833cd59a6e1b86f99fb2b0de69101a1aa5f4a539aebe",
|
||||
"backend/db/migrate.go": "33044d905354f24fff194fefd35ee9327d63d6e5062ded8496e518b6ce38dbea",
|
||||
"backend/db/migrations/00001_core.sql": "b6bd8c70d51aed6c966e07eebffd262af2e694c8b3479c70bbf9a9eacf5a7aad",
|
||||
"backend/db/migrations/00002_idempotency.sql": "97c98785547db8391c1fa0a685e4d4bcc810b8f79055c0e2fc6ef473cd38b37b",
|
||||
"backend/db/migrations/00003_attachments.sql": "6b4f707dde32f0c3f531741c108bcf0f22be05c9e2ede327f27a1d9ef0cfcc7f",
|
||||
"backend/db/migrations/00004_login_limits.sql": "6be837dee2d6c2d1dd80c6b6324e52001c0913160ef0532852410266d1f4af8b",
|
||||
"backend/db/migrations/00005_replay_audit.sql": "234a04177bca08621fa38b135cb8086bcdd55ae9084008b25814751e1dd742a4",
|
||||
"backend/db/migrations/00006_slo_facts.sql": "2cdb8cdb1618a90eea76e59ac99f3d89a3665b2d6ade17502abe4261d5ffcf3b",
|
||||
"backend/db/sqlc/queries/attachments.sql": "8e64f0e6169fab7664b0f4a97f2be353553b93c0c928d10678cb930e44de37da",
|
||||
"backend/db/sqlc/queries/core.sql": "1aed3d0d2fc04650351d86d15837cf3239636844727e799aabf5ddd534429f33",
|
||||
"backend/db/sqlc/queries/idempotency.sql": "5bdec86e85705f7805fb603e2c792bb87c11cf3156952fa48e7bcee35fd683ca",
|
||||
"backend/db/sqlc/queries/observability.sql": "65c5dd26008542a80b7673d25631d1e7faeb0ae4caba661aee52d25fca26e4f3",
|
||||
"backend/db/sqlc/queries/pipeline.sql": "9551971f39bced93c8690022495f15a87f7e14fa865d050a200a1b5d52c1acc1",
|
||||
"backend/db/sqlc/queries/security.sql": "43456c3cc7c586e854c8f98a7aa9c4a9fdd0dfc07b113e04c33af6174dc3d454",
|
||||
"backend/db/sqlc/queries/slo.sql": "6f9b0092fca3ee0dda312d421bdb9ea587e3f580983372af47dc54f3d79a1873",
|
||||
"backend/db/sqlc/sqlc.yaml": "803b161e063692398c93152b11a08f9e42e1bf3c72a1e64553b82c494545fd10",
|
||||
"backend/generator-overlay.yaml": "e666da2959b31befed713a8366237de53070a565f93850d6daae7a582a038819",
|
||||
"backend/go.mod": "b0e80ef1c70d6f3ed506383cbf358c644d299d8e84e44bd166c24fdc7063039f",
|
||||
"backend/go.sum": "d8f0a6a0b68268ac02e58c0232ec13c6a12d8bc3c3d9a4a148806566d8d02fca",
|
||||
"backend/integration/object_metadata_test.go": "598e973575d57c6ee563f0b15d0111d37b27de6774c6f486c998dbc70594f15d",
|
||||
"backend/internal/adapter/freshness/file_test.go": "00069226fad9fa5f6ba3a4e3e679d5e7122ce1cbed137a5d71da82bfe190e5ad",
|
||||
"backend/internal/adapter/freshness/freshness.go": "551a4d8d3780598fa363edd3fcd4cd4bb6450ce52846a4257aeea1bf4bb0a978",
|
||||
"backend/internal/adapter/freshness/freshness_test.go": "85b5354f7935e3767f93ee000e0a00cce7f92d381abe5561c41e77807b7609fb",
|
||||
"backend/internal/adapter/handler/api.gen.go": "4034501f5c661c87af3b81d0d1ecb9996050828569bea7e85b3604a2a8c8bdbe",
|
||||
"backend/internal/adapter/handler/api.go": "9d9f109e13c9322287b29ed18e7913e0e8d5a9ef2dc4be23f10c7686de3f70fe",
|
||||
"backend/internal/adapter/handler/attachments.go": "608827653c4d3e4252dff863d30007e93b1bf82579bbe71d8b647bf22128b1b2",
|
||||
"backend/internal/adapter/handler/auth.go": "3889f58ac4c58b798192776ea05455d52735a2c024ba664ab9af5eb405187557",
|
||||
"backend/internal/adapter/handler/errors.go": "d8eedca0f42718525ed81c2ace576a99b0a4a890f717c46215705798932c13a3",
|
||||
"backend/internal/adapter/handler/gate.go": "b662058ebc59010f30d21da12404837aa2329fe5e5590761efdd9140c1d24e9c",
|
||||
"backend/internal/adapter/handler/gate_test.go": "f7938bdeb5617ed3611303c54818000de9861dde5915fa2c6fa0f74e1fa33268",
|
||||
"backend/internal/adapter/handler/handler.go": "1a99601365ed52aa36f5ef2b6be4dc760e28e1ad5cc38eb6790d69c5559751ce",
|
||||
"backend/internal/adapter/handler/json.go": "d6458b8e8e4426816ec8c855ff6c8d88a151161bc1560e4b98df0ea4b0dbf6be",
|
||||
"backend/internal/adapter/handler/message_json_test.go": "8dd976c4cad81ee531c76165787b2c8b6052057d934ae4b09b60d8a261cf30e5",
|
||||
"backend/internal/adapter/handler/middleware.go": "41ce83f0b7eaf25aecdbeb99d5292066f25e2043e08c0f681db2cfc80c01c528",
|
||||
"backend/internal/adapter/handler/stats.go": "5cd375e5a0db8cc3596293d323e635b86fef22d8ec680f310ab5a460f8176f64",
|
||||
"backend/internal/adapter/handler/utf8_test.go": "eac6a14b5f3b0ea9aa5329337afc6db27e17f5c17999874da9ce3592dc7a4205",
|
||||
"backend/internal/adapter/imagefile/image.go": "8a9b399b22573992fd7fd4c87096f953b46c1bc7cad4e09c023923919d755375",
|
||||
"backend/internal/adapter/imagefile/image_test.go": "a2dc0d3797a5c2ac7ad46a7453a34ea13aba94c3385d2692032705610026dc71",
|
||||
"backend/internal/adapter/imagefile/stress_test.go": "3d7b0671f57ce5e01fa7e175a86c16a51d56d8f11ec6d3bfb09b2c8bfe8c04d8",
|
||||
"backend/internal/adapter/imagefile/variants.go": "50762d1e2af635c9a9344d2721ee145bb9d9d43408f680fc280cdd493aeef886",
|
||||
"backend/internal/adapter/imagefile/variants_integration_test.go": "d25e3371432128e58073ff61e1b87fa741bc32ee7d9bc6e8cb40ae3f3a5b4434",
|
||||
"backend/internal/adapter/imagefile/variants_test.go": "79c24a3d5c0cb339a32fdea28eb56689703f35ad3c668c464ea7a4f5e82322e5",
|
||||
"backend/internal/adapter/lifecycle/environment.go": "d897867f594dca3c79acd3bd3979e0d15bacb588415d8b3d794ec34d2317181c",
|
||||
"backend/internal/adapter/lifecycle/lifecycle.go": "de660d859305e47c36c4d7671d0354e1c027a7cda7ba84639bdec4e9bbbaf9a5",
|
||||
"backend/internal/adapter/lifecycle/lifecycle_test.go": "d398eb9075654cfd4eb23edafa3bb3c741a822b315ef0d3e9d710b3a0d6d17e9",
|
||||
"backend/internal/adapter/password/argon.go": "30fef7f8624019544262acfb7f1694a4003791e6d3a9acc7c7c7576aac73b0f3",
|
||||
"backend/internal/adapter/password/argon_benchmark_test.go": "8d2b8fd14132c35ccd5b8008af9c8c088c84a1015fa36b252e1d5fce91bc581d",
|
||||
"backend/internal/adapter/password/argon_test.go": "ce3d120d41c4f1e4f2c944289cd6852cfaca29ec11ab5e3ff9d0748036344b59",
|
||||
"backend/internal/adapter/queue/clients.go": "c0b253da9110b9fcb7599277e197da9ab009d3813a5b88d290e48f36a2bd053c",
|
||||
"backend/internal/adapter/queue/identities_integration_test.go": "d7c3171d8420ea705d0a0d7aef9f275b5355f484e89439cb0b450112d1f3924e",
|
||||
"backend/internal/adapter/queue/identities_test.go": "0ec224f6524ffcaf7710605a560ae17b06a294b3d4e4a96ac50a59cb86e37917",
|
||||
"backend/internal/adapter/queue/publish_trace_test.go": "4ae1d22d4c6ff07ec8dfd6c503059b4ee47aad426503f925e0d479c0b819ee00",
|
||||
"backend/internal/adapter/queue/streams.go": "f16c63a8ec82302031e28e686e48ac220e883022a7e5787f80db57baa09a42f6",
|
||||
"backend/internal/adapter/repository/postgres/attachments.go": "88f8b8744d95407421eafc111ecc83bcb4b145f1683618d69cac19a8d1c39500",
|
||||
"backend/internal/adapter/repository/postgres/observability.go": "b6001827364a226026e7a651da8a57918ec426e34cd64d3b6ef709814f0a5667",
|
||||
"backend/internal/adapter/repository/postgres/pipeline.go": "9a367d7a50a9418e96851c253f61ace4a54753044e7fa672c73a3b4526a22245",
|
||||
"backend/internal/adapter/repository/postgres/pipeline_integration_test.go": "58274475a02f1098a0f79a65a9e8d7608d05dfa26213f90c706a9239fabb586c",
|
||||
"backend/internal/adapter/repository/postgres/queries/attachments.sql.go": "407ed2864afad2b039a33c571228e6ee6a9acdc515d957bb55dc600308b5eacc",
|
||||
"backend/internal/adapter/repository/postgres/queries/core.sql.go": "9a0e082263cbea39535de9c7c72c41a39a551efc9ee57fdd7b08856831d074b3",
|
||||
"backend/internal/adapter/repository/postgres/queries/db.go": "4863732830879d4162be215ff245375b953359de23bcd821ed7abc5c32a36c0f",
|
||||
"backend/internal/adapter/repository/postgres/queries/idempotency.sql.go": "cf6fbc316e93339e0f938c7ca82007e29c3e32f1a21ee1433a2ce8784697f002",
|
||||
"backend/internal/adapter/repository/postgres/queries/models.go": "c88827ec8660f14e1274a2aa2d287869679aa1ca3ea9f9a951b806624fe4de39",
|
||||
"backend/internal/adapter/repository/postgres/queries/observability.sql.go": "c2971da00171c126b129ca2010a1cd1a6223b11ed1b1b20632af19fe8a66f313",
|
||||
"backend/internal/adapter/repository/postgres/queries/pipeline.sql.go": "43009cbd2754d478727cce5d4b263dcdcafe7ad8000de011f22795531e1fb3ec",
|
||||
"backend/internal/adapter/repository/postgres/queries/security.sql.go": "bd3c3b6205b8ec955e27c6f0f3ef9b23364533920b5290bc566cd458bceeeca2",
|
||||
"backend/internal/adapter/repository/postgres/queries/slo.sql.go": "bcaa6b4515507e555caff58a0448861ffaeac2f21771a4bde587cf296f6c685e",
|
||||
"backend/internal/adapter/repository/postgres/repository.go": "e380d7c0c52a2447653db9e4d13db432f4c1330e3205a0396510d957441bb978",
|
||||
"backend/internal/adapter/repository/postgres/security.go": "1c5fd2e788b0b74040f87da666b73b7632df76d25daebc64020a33840ace0a29",
|
||||
"backend/internal/adapter/repository/postgres/security_integration_test.go": "bc5e6cc1824e8547d3f5fe0897ed5efa1557437cd2542301216256319401ee2c",
|
||||
"backend/internal/adapter/repository/postgres/slo_integration_test.go": "e396c722fe8ea7ade19e2de5c9a070352efbde8e8712ae6e910f628a11c5c2b0",
|
||||
"backend/internal/adapter/storage/bootstrap.go": "44c8f422826b29f85a918029bb71a62cd3018190f8efe889cbeee63d19d7039e",
|
||||
"backend/internal/adapter/storage/readiness_test.go": "a6c79cba7af74ce67e69678085e5bb267a47f9dd7be57daf003ba03951274a5c",
|
||||
"backend/internal/adapter/storage/s3.go": "99a717604c71da5c181bef74612a603abe3cfc913ccb3da84ed581a57a11ccd8",
|
||||
"backend/internal/adapter/telemetry/dependencies.go": "09d5bcf97bfff77d42dbdca9637e015a2eb73e03ea3ff801d710e1340c85ea44",
|
||||
"backend/internal/adapter/telemetry/dependencies_test.go": "d7738b7fe098b2d72967243dce8ab7a84135e570e4697371755b73245d908981",
|
||||
"backend/internal/adapter/telemetry/gauge_failure_test.go": "4d8d3aaff9e471a36c0f65db0a23d799101c72f804b6d7270bc9a9570181b225",
|
||||
"backend/internal/adapter/telemetry/gauges.go": "80782d0bdb1bbaa9132c6c3a471887e4a6d48839b448a5c3c558edf217a01642",
|
||||
"backend/internal/adapter/telemetry/pool_integration_test.go": "b8e8d24ee46549c0898726f770f206701f147ea7f9cbb4271b24dcaa63f5a0dc",
|
||||
"backend/internal/adapter/telemetry/telemetry.go": "db9ec2b20d504e7c50424414618e00fe1b81ce68b997c70ae65040260d31b890",
|
||||
"backend/internal/adapter/telemetry/telemetry_test.go": "c727d6901ac3b8a5cc3e704645f8a7715a44d88f8bdf9bd990ac176c017fbba2",
|
||||
"backend/internal/application/usecase/attachments.go": "0c835f88c72b90753b5458960f7b345e6e51b964070ce37eaae129a4c296b0ca",
|
||||
"backend/internal/application/usecase/auth.go": "8935ab9bbe126e7edf12f0a16e0b7b95f5f360e7b48a7ce547e82e659c07cd5f",
|
||||
"backend/internal/application/usecase/auth_security_test.go": "642b594d94965e2ed76cfb5eefa67ed620a4c372f70d0c1230690c3a318de61f",
|
||||
"backend/internal/application/usecase/messenger.go": "c58aba0d3f5d0ab92fab5d2771b90a3af5ad06e6afe0c7cc46f481a429e89f48",
|
||||
"backend/internal/application/usecase/pipeline.go": "05b4a6e87c2bfd86c06f5b8cc3e7b960a26c0a69726a366a3137158b1e9e2e45",
|
||||
"backend/internal/application/usecase/pipeline_retry_test.go": "96a569aa26e23909c109dda14c8828901abe2914bbad2ec3506a10441a264dce",
|
||||
"backend/internal/application/usecase/reconcile.go": "239edee16f767dd16b116791900994540a8f99ae3403fd0308f5e2c0797a892d",
|
||||
"backend/internal/application/usecase/reconcile_pipeline_test.go": "75e1fb5fcc5ffb2188a2368688e5505a4bf54453c2800b5e46c8e9e23de89b7c",
|
||||
"backend/internal/application/usecase/reconcile_test.go": "fdbcfad86851fc97a3cf635b6d884c41b43084eedc42b3c4847790c5eaad4a6f",
|
||||
"backend/internal/config/config.go": "58795b18980c4dd938c73721ab937d06410af94edc156b7a7aa9b2c4c2388238",
|
||||
"backend/internal/config/config_test.go": "390e3b5a4682719a0b25a8eb9aefeda9a9d1c774d3f8d1f08062c79a58d8859a",
|
||||
"backend/internal/domain/model/attachment.go": "e532f2c8e8c123d0fda6101bff4b21168527a0a446e53f566f5e5919b972133b",
|
||||
"backend/internal/domain/model/chat.go": "3f7454f48ef442c277fd2741ce5aeeccf03d590bd2d31b9b89fa39f0ba05de7f",
|
||||
"backend/internal/domain/model/errors.go": "e0a6322f36b3a8ef7b75f70294fedeb3ad70e37ba63d7325bb1bde8ad332d4a6",
|
||||
"backend/internal/domain/model/job.go": "564c219e526b99e06d2c882d7184fc6ee0b58d29c326be5969a38cc6b92b8c0a",
|
||||
"backend/internal/domain/model/message.go": "0e0126663d2de04c9d14c8c7427f42a9fb733e3b170ceee7ed86c2138f51b23c",
|
||||
"backend/internal/domain/model/model_test.go": "77bb8767ac1352bd3551e724eaaeaad4fe93eae248cc8c3008ee8b1c08adddca",
|
||||
"backend/internal/domain/model/page.go": "cd6a07579bff01aa0d8a11b34fd000a804142b321cef302d386bdb95e9c7f953",
|
||||
"backend/internal/domain/model/postgres_text_test.go": "8c245eef99a97261daf0aa16fec9edd7bcd3253ec4144c50b4f8e56e45e2186e",
|
||||
"backend/internal/domain/model/text.go": "c9410cacd9d1b2fd7f3f2cb7e4112e637ecc494f6e4b6da649f936ce0c9a0457",
|
||||
"backend/internal/domain/model/trace.go": "9ff395bce67142f6808fa7c652e50db2a68cf4e34c128fb04af408566a14220a",
|
||||
"backend/internal/domain/model/user.go": "c20c8b8d8a9c0327a3a24afd74f3051d78caed1d2f0851baf340ef61ac502a92",
|
||||
"backend/internal/domain/port/auth.go": "0087a19007cce3e90bddce4d24909217820993fb4b6ce125f3c6d9da4d86763a",
|
||||
"backend/internal/domain/port/objects.go": "4d22b5ef5ff6fa13404884c160fe52bd7cef4099f84b29268137c27034a0f3ec",
|
||||
"backend/internal/domain/port/pipeline.go": "5fe7c6909cbaf6a21a4be5d9ed0c2b1551681894d0054463cdba13ea09c21aac",
|
||||
"backend/internal/domain/repository/repository.go": "0008747c69b32df9e4b7f36fd1ac157dee537d5e1e415bd48bd55b0b05852362",
|
||||
"backend/pkg/logger/logger.go": "d839f31015eee692065c31d2538a4cb4c841b0d89e690f0ab8baf80168510556",
|
||||
"backend/pkg/server/server.go": "2916acc42708dd493068452ac4eed5208cd166f910c517f16196d001aac5d269",
|
||||
"backend/pkg/server/server_test.go": "7eccb3acd7f9e9ac0b724b17fa50f1f1ff94be043554fed0a5e0fad1e2cb9ee3",
|
||||
"bun.lock": "8be6512d5f7665fbcaae5e1cdc01d0ac7fa243f1c9cc6e10d7387f2351531e3a",
|
||||
"compose.example.yaml": "abcd9e7cfb57d3854a8362550cf36a0030cd417eac2a342abb5cb6c72c0e1896",
|
||||
"compose.yaml": "8dbc6643580f19dfc301fc4155b161a5bbd910e89304efb3af90cd0f4f08e41d",
|
||||
"config/api1-gateway.cfg": "23e97b700db9371e382b4cfb35f636571ee93c661aafaff315ee4d9eef5f9a1c",
|
||||
"config/api2-gateway.cfg": "23e97b700db9371e382b4cfb35f636571ee93c661aafaff315ee4d9eef5f9a1c",
|
||||
"config/broker-gateway.cfg": "d5bb3bfc4a2be7ab0fc6d4b1c4b92dd9a4d863b569b9aded93ac1a36d8fbafb8",
|
||||
"config/collector-gateway.cfg": "43256d3db1f1c9c97708586c594e567ae652bec22af73e23c2ca6124fc7f1ebf",
|
||||
"config/grafana.cfg": "95f38876f4a9e1c1d28721aec103e0f61ea560eeae85d2da2cdaf2bb1276a40b",
|
||||
"config/imagemagick-policy.xml": "ca3ead36eda96e89d3f024b314435eaa0bb10202ef4a6de3ab3c4a472f648cf2",
|
||||
"config/lb.cfg": "f41774bd38f42c6e02ded5d81233d6f7053dd72fc5192aab4eeae4d0940fc267",
|
||||
"config/loki-gateway.cfg": "935a0eb52942dc1d0f251844b29faebcbcc7a47d6ac8506bbe6e0a09841c5e55",
|
||||
"config/openobserve-gateway.cfg": "797f719b25220e7fcef40e0d3bda9a53c36acb68c53a337d9c1f1fbd4a9434b9",
|
||||
"config/pg_hba.conf": "4372f10b06425c97516c0bada8c1298a507a22c14bc6b10984529e43c980a0a9",
|
||||
"config/prometheus-gateway.cfg": "5da62cc7a5d63bfe9f549273513776c5b29a76e8a65f170e5ba198e5b63be5a9",
|
||||
"config/s3-gateway.cfg": "3d166d8f3cb05dd91dba9a302af20f0e75c18d9b770b2c32c4c2f7cd337df4dd",
|
||||
"config/tempo-gateway.cfg": "3d2ee510c0f28fb935967d2e6d35fd2e1f19fa62bd05beda9b4607901be36828",
|
||||
"config/worker.cfg": "aa3fe43ef7f392f89aabe2a4773f4e270e0806f22c07b2ca0fe0f346ab6b0433",
|
||||
"contracts/README.md": "72df27a559f88ffa3fd8c3c79d3c32f6db2c5986a0602677c51994c434a3fc4f",
|
||||
"contracts/attachment-states.md": "cf0519e137410e4b34ab632aadb8ad8a381d4b73033e27b354c58eeacbdf86d6",
|
||||
"contracts/examples.json": "381cc18c03789e935b391d007fb5843964be9cfd9f7530cb6b1996ed4a1c4c37",
|
||||
"contracts/infrastructure.json": "90b706e85ee2fcaa54e1113e98206555e0cd678caf03204c9ac363a6f1323d30",
|
||||
"contracts/jobs.schema.json": "9ccf9b11466c0c3a26a941520ac5ff543241fc4935e3a6eebb01ef303779b10d",
|
||||
"contracts/observability.md": "882c120c0e153a06c9cc824a802e317c58eb6590bc3d3a576f2e0a96f8597b62",
|
||||
"contracts/openapi.json": "51dd0b8199aee7be81437056144c5fca9d82c2b4387dae62585cadf230ee749a",
|
||||
"contracts/trust-matrix.md": "7b5777957341175afc68c0a3db9ba6915ff724fc47b47f9c970ea6cad19dc25e",
|
||||
"docs/GRAFANA-ACCEPTANCE-CASES.md": "759dc03bde89d247cba3aabda7b416e767ae1b7ee9c17b7bf1c8975aeaedfd40",
|
||||
"docs/GRAFANA-INITIALIZER.md": "e2eb2d1474812a1b0b8043bec7744188b3e38811363718531da8026a292c5356",
|
||||
"docs/GRAFANA-NATIVE.md": "645de70d0c623156bb1aaf0dbb40c991f5a6bcf211037d820ca654f3248a2fc3",
|
||||
"docs/NATIVE-BAO-CASES.md": "0e64d79025c1ddd537117e45a822f660672aab38a33e7d5289ebf750abf70e60",
|
||||
"docs/OPENOBSERVE-MIGRATION.md": "3be68492b2e26bf432cc4eea5956ede83e1586c9db1828eb504d23c7b5b3c50c",
|
||||
"docs/OPENOBSERVE-NATIVE-IDENTITIES.json": "a96ee905c87ca284a8c71f662e1d1034354c525e08e8215078bd63ea7da23a8d",
|
||||
"docs/OPENOBSERVE-NATIVE-SCHEMA.json": "63b462abcb79076587917270a22eb88d7b0d355f4a1ee31f31dddbbfa1aeb1d4",
|
||||
"docs/OPENOBSERVE-REVIEW-FIX-CASES.md": "b285ad98fc06b2685a2d7ac6b22960819907ba1ee4585adb7b8af0c0969ef5c1",
|
||||
"docs/OPENOBSERVE-SHARED-BOUNDARY.md": "67c407ece7d7465c94004cfba13688d7296282f34b00e5e689bbf7489bdf1d95",
|
||||
"docs/SECURITY-CASES.md": "5dd828017312d111f109a50fd0110e37c4306a80815ea3a2cb2782c73064638b",
|
||||
"docs/reference/argon-budget.ts": "6ea8a54687297cb6b43b11f8d88084744a2421262b24d00196f3161007ea4a2c",
|
||||
"docs/reference/grafana-history/history-normal-ui.json": "653981b13525c996611e9b738c2087a8ddcf1facd801c8a9fcc25a1ce414086e",
|
||||
"docs/reference/grafana-history/history-page-service-source.txt": "a8970b0388671b359a1721a6d6eb9913a5df4d30251fd40cb37621cfd0f5a2a2",
|
||||
"docs/reference/grafana-history/history-source-binding.json": "822c9c536412cde4b5369a40c835ac5d09ce58d1d6cac7ce4b47735c58c4711b",
|
||||
"docs/reference/grafana-history/history-user-storage-source.txt": "aee99a03048c1d7e639ad16e80d874508033a18f32c18955914dfc96624d1e28",
|
||||
"evidence/README.md": "78e4bfd738d034597d15d8846accd8a8a5dc738a23a3d15f243f3992bd530cc3",
|
||||
"evidence/grafana/browser-35db454d-556e-494d-8350-9e1837e4e271.json": "51204bcd9c6e245fcf3c94608592d03b72a896206c1be5b099715616883d8980",
|
||||
"evidence/grafana/browser-53d5ab5b-f73a-4750-b9ef-e54c36c488f3.json": "b591874bfb34b8302eede4ca44df15a553bf04278fba07a1d2fbbb3701679ca7",
|
||||
"evidence/grafana/browser-86b82122-1952-4da5-b8d1-1a41ff9dcef2.json": "7c44010cb88d151f2cecc3db65badb8f2d02b79905e40b988cb333645a94a9be",
|
||||
"evidence/grafana/browser-a63697ff-c000-4d91-a8f7-60c4c6821fba.json": "f904313355dcaeb42d31c7b59dedfdb262e7e9887d91b790015fb494554e6ad2",
|
||||
"evidence/grafana/browser-b8b2e8e1-a42d-41c0-bbde-cbcabfd16369.json": "e43ae30648e5c761abe257215764505723ac81deb272ec34ce254168cc2b26c4",
|
||||
"evidence/grafana/browser-ca31bc9a-3b4e-4aaf-a869-1f73f8c54cf6.json": "6ce19cd17b98e548d1f22ba3f763f610be498ba5f457e31ba621973108432193",
|
||||
"evidence/grafana/browser-e384107e-200b-4ed2-b2be-c47adb6c1723.json": "62cfd2112b79386f2eea553e98ccc8b9c05b7a38c97bbc3353f2eadfeee63386",
|
||||
"evidence/grafana/cache-freeze-5c2e02c0-ccdd-4a95-a1c1-74cee6d7d408.json": "78a7a337e65804f52d232c0941b353823df27e9a1f4ff4b468ae00dfb9b8f5a8",
|
||||
"evidence/grafana/dom/86b82122-native-trace-to-logs.txt": "b0e81437ab6b0f88f0c256127633848c6779a2c4e6580f1d3e05a18cac7ce501",
|
||||
"evidence/grafana/dom/a63697ff-correlated-logs.txt": "14938c75c7f9e9b7ff76ac80bc78c63ebd82696c5115ed4b012d54f9395e0e0f",
|
||||
"evidence/grafana/dom/a63697ff-trace42.txt": "2a59e2ec14e837d6a6de59f3164f68725cccb26bb41e7e147082b3b5b6c689a1",
|
||||
"evidence/grafana/gauges-4fc181c9-7bed-4e1f-9d43-eb69474ee891.json": "b76fe1b7b5d638487ff2acf3d9412d9e6581ea8dd2eee539d6d32db04ae6205b",
|
||||
"evidence/grafana/histogram-b8b2e8e1-a42d-41c0-bbde-cbcabfd16369.json": "efc4e6b959b71745d0fef11a6ae23af313838528a7395311f2b14c361a4543a5",
|
||||
"evidence/grafana/https-identity-35db454d-556e-494d-8350-9e1837e4e271.json": "1f72a42a1611eb2ae3807c0fe7963347ac026873c49275de1d0688c617adec5d",
|
||||
"evidence/grafana/incidents-95f643fd-617e-4088-a112-126e14333e09.json": "b46a70851170118ac5e0c9dfd8a015b3ed77dfe43b587e9f843c7830b21bb4b3",
|
||||
"evidence/grafana/incidents-a00ceb14-2191-478d-bd4c-ad3629536c41.json": "36b9018f227a7bb2ec00783ceea4fef7883a02883a69a7d89e3fd909cc31bc1a",
|
||||
"evidence/grafana/incidents-e80b4c4d-df97-4cc9-b6d4-7ba651e0542b.json": "94a075b55cdc38b4b67b3c6a3758f200b3c0e660e51b4953010add6716e44c6c",
|
||||
"evidence/grafana/lifecycle-checks-1acb06cc-b875-4230-a1d0-4d52cb6417af.json": "f362855c899c31e86461d23663f6aea325ab66477515af8972566d21876e9f56",
|
||||
"evidence/grafana/lifecycle-format-1acb06cc-b875-4230-a1d0-4d52cb6417af.txt": "ec387b2550a140db9ab1804bb3cb0f514b8502525f55b732bdd9fad1c72e02e7",
|
||||
"evidence/grafana/lifecycle-red-1acb06cc-b875-4230-a1d0-4d52cb6417af.txt": "5ad948c5646659944dfc549bd7c34b9275a3b3ab4f545a3431f459e0015220ec",
|
||||
"evidence/grafana/lifecycle-typecheck-1acb06cc-b875-4230-a1d0-4d52cb6417af.txt": "776a2b73ab326d53623651e1690238542f18e40b6f4c6dd5de9d5592aa33f2ee",
|
||||
"evidence/grafana/lifecycle-unit-1acb06cc-b875-4230-a1d0-4d52cb6417af.txt": "b643747ee9a225cc3f93fe81bdf1e3e38cb69c6b187b06ea3bf3a1a243b1241f",
|
||||
"evidence/grafana/native-control-748a9e0b-f1ae-4b4c-b8ce-ae4e19774cba.json": "ad624de1c4a24d4fc5801bc0c6b219460f482893bc68b4f85d15f923b9b6de45",
|
||||
"evidence/grafana/pool-a63697ff-c000-4d91-a8f7-60c4c6821fba.json": "7da4a9655c69b5fc234927cebd470dbbf0222f6a77c9742f99a4e5395a846e3c",
|
||||
"evidence/grafana/preflight-02871d83-b532-459d-b007-062651324f7e.json": "1b8683368f5225374ede4aca92079be59253aab0264a41cfafcd1ecd721bfa85",
|
||||
"evidence/grafana/preflight-06887be3-cf0d-44cb-9afb-5c572084bc03.json": "27a84f60c7cad6c4342dc9645b7462c29956ada2c52d9ac9f18ece72543e3afb",
|
||||
"evidence/grafana/preflight-0dd365eb-c3de-4f6e-8748-8ddcb6b024e6.json": "6577429ac44134b4a11eff45d5ecc5110087b8db990bcbb1597967fd7d7838c0",
|
||||
"evidence/grafana/preflight-1b430ef3-576a-41fd-aeec-91c0e7c36af0.json": "295a9c281d2367a9b896cabea82a938eb3f593b6c92fe4fbebedab701a7cd16c",
|
||||
"evidence/grafana/preflight-3081897a-db9a-47c4-a5eb-8b491ff470e1.json": "3eab20317d1f9323efef491341ffc261a94bfdffbc100f38dae8b1d0418c81da",
|
||||
"evidence/grafana/preflight-6696c9e2-8b86-45ab-bbdd-9e5988304afa.json": "17c738e1d0aef939d37f99a1821730524e7c4f521522d6fd49314c16f280fc79",
|
||||
"evidence/grafana/preflight-787422f6-c430-4ce3-a9e2-27d9c1bb8a5b.json": "8bf3cb1138502af372583c9c2cb26f7fd8b31f283a9f6ec6c127557a2e7a8498",
|
||||
"evidence/grafana/preflight-7c84f311-e050-406b-8caa-673dc36f1266.json": "61d5719476448f4218cc9ea0517c8fe16796d6995bcf15dac24fcc72c4822013",
|
||||
"evidence/grafana/preflight-96875a3e-2d3a-45f2-9a0b-df0de985e95b.json": "6c659f334791205fa48c2e84cd6f0b08a9468868d04bd55a301942d439b71385",
|
||||
"evidence/grafana/preflight-99e1360d-bb45-4048-a965-ffc4838f079e.json": "71354852f97d5abddbf3bb62bd18801ae8479a89de6c36633f3e4a86eb9e75b8",
|
||||
"evidence/grafana/preflight-ba115d3c-2a3a-437e-bbe6-f9f72829b8cf.json": "7f5dc223e70ad747fcaad425fdbfed838aa6c5a1dae41dd98af9afabecddd0b9",
|
||||
"evidence/grafana/preflight-ec24045e-26b3-468d-ba6a-bc0a34a7ba3b.json": "1baea5b75c4c901172520688410c27fa0cd66fbb804a6c23731f1e0e799f522b",
|
||||
"evidence/grafana/preflight-febb2404-aeea-42d8-9dda-ba315bd9498c.json": "9681e2eb01869350d59f8d1c0627445f7a826c1721888e3dbeb5a4e139c7843f",
|
||||
"evidence/grafana/public-source-check.txt": "5f42d25d7cd8c1d2fb31ccf28a2872fbb91d38ed094024181e5ace9671667ee6",
|
||||
"evidence/grafana/response-consumers-b8b2e8e1-a42d-41c0-bbde-cbcabfd16369.json": "85fcf88ea3e89c51ce5ca3e40513319dcb5f760108bfc1c005d81080f7ee03a2",
|
||||
"evidence/grafana/response-consumers-e384107e-200b-4ed2-b2be-c47adb6c1723.json": "d838c87b9e25d282cbb4b01489f520b3a5d75ce9828a9da1ed8d837c14411493",
|
||||
"evidence/grafana/response-framing-be70ca46-35ef-4420-965d-20019dfb2061.json": "6e6ee69f0bc503cf2ed7c62b4e7a2cf98dfd54e241af88c8c4aa70e4fc339e72",
|
||||
"evidence/grafana/review-lifecycle-delta-f74fcdf1-f211-41a7-8e08-66f58c03ab9e.json": "a1cbaaaf890d7ad9715648131b2116f6a8064bf822b5ad7010295a75e42c6095",
|
||||
"evidence/grafana/review-source-41c6b438-c674-424f-a9f9-081a9ff66904.json": "dff06308dcaa446bd941a9e50bbe3753ae5acd3501b20ae11dcbd8324222f677",
|
||||
"evidence/grafana/screenshots/86b82122-native-trace-to-logs.png": "6c89563b449def897b047ba4be66382675b6f1cbf25e3d80bb5368a5838f3d8c",
|
||||
"evidence/grafana/screenshots/a63697ff-correlated-logs.png": "8879d48c6734fb86481937e7982e4881807f72df9ed75f7ea34ab2a3843af231",
|
||||
"evidence/grafana/screenshots/a63697ff-dashboard-bottom.png": "00b79fa30196057967bf9b80495aa879ae98cfd91245ab710ced34ad8882f241",
|
||||
"evidence/grafana/screenshots/a63697ff-trace42.png": "54bb8b7aaeb88e011613807f9ce81493e7df98e21adb1318889873a8ef88f210",
|
||||
"evidence/grafana/screenshots/b8b2e8e1-dashboard-bottom.png": "28d73bafb38f153c806134fec4430a074a5b1e4de562461e2866f0958e841af4",
|
||||
"evidence/grafana/screenshots/b8b2e8e1-dashboard-middle.png": "dc7db852b5d67d78fbb63e0e525bcfeb65024a641e087a82caf7ae2f4ece5aff",
|
||||
"evidence/grafana/screenshots/b8b2e8e1-dashboard-top.png": "f35ac084359d2c1cf64784d6bf427d7e690a7442ada72ddfb50705d041a90727",
|
||||
"evidence/grafana/source-before-final-c714c1d2/source-checks.json": "633f9e679003572ac0b52f21c4e3a3b4153266bb753b0d6fd94d610d8b450ff1",
|
||||
"evidence/grafana/source-before-final-c714c1d2/source-format.txt": "ec387b2550a140db9ab1804bb3cb0f514b8502525f55b732bdd9fad1c72e02e7",
|
||||
"evidence/grafana/source-before-final-c714c1d2/source-typecheck.txt": "8ab84ea88ed6044967674aabea530a8ba68cde880f1e5e229833da521f67b70a",
|
||||
"evidence/grafana/source-before-final-c714c1d2/source-unit.txt": "3d4d3617f068266839e7f14c55b08a5f4998c05d8dff178dd960aaf0556f5195",
|
||||
"evidence/grafana/source-before-http-fixture/source-checks.json": "633f9e679003572ac0b52f21c4e3a3b4153266bb753b0d6fd94d610d8b450ff1",
|
||||
"evidence/grafana/source-before-http-fixture/source-format.txt": "ec387b2550a140db9ab1804bb3cb0f514b8502525f55b732bdd9fad1c72e02e7",
|
||||
"evidence/grafana/source-before-http-fixture/source-typecheck.txt": "077c71add06621da98fa4765b6f8b7a31b8555599d9dd50197579a303cadfce3",
|
||||
"evidence/grafana/source-before-http-fixture/source-unit.txt": "b520975c882fb845850d50b334cd4a8efbc06dfc61060f079f03599b195cbb21",
|
||||
"evidence/grafana/source-before-scope-cli-bfbb13/source-checks.json": "633f9e679003572ac0b52f21c4e3a3b4153266bb753b0d6fd94d610d8b450ff1",
|
||||
"evidence/grafana/source-before-scope-cli-bfbb13/source-format.txt": "ec387b2550a140db9ab1804bb3cb0f514b8502525f55b732bdd9fad1c72e02e7",
|
||||
"evidence/grafana/source-before-scope-cli-bfbb13/source-typecheck.txt": "97e5dfa5c28ab38ed4a0cbe91aa511303975a557e15b47630bd2c35051fda38e",
|
||||
"evidence/grafana/source-before-scope-cli-bfbb13/source-unit.txt": "6ed0cc52f8d22cd0f31cded1ec44f1b682b2b7381eeb40df90964448968e8054",
|
||||
"evidence/grafana/source/source-checks.json": "633f9e679003572ac0b52f21c4e3a3b4153266bb753b0d6fd94d610d8b450ff1",
|
||||
"evidence/grafana/source/source-format.txt": "ec387b2550a140db9ab1804bb3cb0f514b8502525f55b732bdd9fad1c72e02e7",
|
||||
"evidence/grafana/source/source-typecheck.txt": "b06acdb1fb47dbc795703bb2e35d60ee6d00112323fc17ad319e25e363dafed5",
|
||||
"evidence/grafana/source/source-unit.txt": "42d8eae4e197657b4f22e6dfec321de64da65c73b6fc0c95ef27c169eb8545e6",
|
||||
"evidence/grafana/ui-capture-a63697ff.json": "2bb24cbd9904d8de18195a028d6d5d4a99dace43f3918161de8f12cdbaaeecef",
|
||||
"evidence/grafana/ui-captures-final.json": "3db531479fe2132b5321232bf2d8a6f430b6e9f428991fe32836c4f12ca7d40a",
|
||||
"evidence/history/pre-native-closure/HELPERS.md": "7d9ce3f8b28ec1b31db25a8810f2a3c1b86bb01040c6f2b779f46b18e28f5243",
|
||||
"evidence/history/pre-native-closure/ORIGIN.json": "66bbb4d3e9df6e5e34f450490c8746b76bddea398d9d1572eed6a6ef72751df7",
|
||||
"evidence/history/pre-native-closure/READINESS.json": "a7c5b3997c56dfb712017fcd30e3e06b79076b71f667c36e6c7c15c830759ecc",
|
||||
"evidence/history/pre-native-closure/REPORT.md": "8335c8c3b153544773570888428d7aa5f2009a5275de0e3235a1c0fb2535a751",
|
||||
"evidence/history/pre-native-closure/RUN.md": "ff4aa61591f3c22d5a250adab2d1980d7ba827ed7bf5b78109687826929c884a",
|
||||
"evidence/history/pre-native-closure/STATUS.md": "667f8f81469023c996fb1ef875ebc30cead6169373938a802aad17a73c371456",
|
||||
"evidence/history102/preflight/certificate-lifetime.json": "9b05aa0d36332366f218c3d8ebd32efb0abc9ef5a1953f98462b76361b13b9c4",
|
||||
"evidence/history102/preflight/checked102-build.json": "b2577649ea38faf6b3eca638a1e1fdbac2ae1f4ac59ac4a5fd772a8538df762f",
|
||||
"evidence/history102/preflight/checked102-source.json": "10059628e1281cbc18adc931b8a0fb8ccbf774c1cd4223d825d28f08c4e43201",
|
||||
"evidence/history102/preflight/finalization.json": "a09792380957e0c6fbad4ad9776ccb7a3b18baed01f656c3bbbfcdfcf00f2119",
|
||||
"evidence/history102/preflight/freshness-expiry.json": "76a33b4a9eaf9182883c75f5c03af97214c0a0671cd220a87a8fb22bfaec0cd6",
|
||||
"evidence/history102/preflight/public-test-security.txt": "15420508b820eb2b1378bb5a06515526aee38133158ec18fde81bc4474e11c21",
|
||||
"evidence/history102/preflight/public-test.txt": "2a74ec8d5668274157198f94afcd8b77c3704a6f00e0ef6dfc0b3085cbeb4641",
|
||||
"evidence/history102/preflight/summary.json": "9d982c02b94eaec46cca1e6c2a702c0303a91c5dd9a45ba34208d600f8a16f92",
|
||||
"evidence/history102/preflight/tls-matrix.json": "044c4fa9a3c7170120ff22baf40794b9668fc5a7a6c07d34525923693cd8f4df",
|
||||
"evidence/history102/security/freshness-red-green.json": "3ab2c09f2a8467ccefdfdb9e21b9c0b39d31a4bd2c6f7677db5f927fe59ef8d8",
|
||||
"evidence/history102/security/gateway-parser.json": "615ac614a0d19fa43b0daaec6d3341fae574d01f42ff00c4385ed84beffa443e",
|
||||
"evidence/history102/security/kv-red-green.json": "c33ed9f5fdb460dc9611ed342eae7317745b3f5d5fdbc00a4334935649533a10",
|
||||
"evidence/history102/security/offline-tests.txt": "d42616e7458f8493a85b61063c7ec8ceea598ea933fbb43702eb5631a40e57fc",
|
||||
"evidence/history102/security/postgres-transport.json": "1623b79b6798635d98045b4f79404630bb6b6135f46988fc05d9e3c9d92f6206",
|
||||
"evidence/history102/security/preflight-build.json": "d92233592efda061269f0f845a8d776d38ea9c3a9dc9b016a7259d0563b17399",
|
||||
"evidence/history102/security/preflight-source-handover.json": "10059628e1281cbc18adc931b8a0fb8ccbf774c1cd4223d825d28f08c4e43201",
|
||||
"evidence/history102/security/public-endpoint-red-green.json": "b5132ecaae833d4e5a01959e23bd752b02e3bee0514aab474cf4fad3e3b56b77",
|
||||
"evidence/history102/security/public-source-check.txt": "5f42d25d7cd8c1d2fb31ccf28a2872fbb91d38ed094024181e5ace9671667ee6",
|
||||
"evidence/history102/security/red-green.json": "66c325300c4818c1a0f2a96c221da4ccfa69ea8aba57e242036df5aef6f8e31d",
|
||||
"evidence/history102/security/review-kv.md": "d4081453938715e145f337999a8ed607ac35b2147895f07395f2309f3d82af33",
|
||||
"evidence/history102/security/source-checks.json": "633f9e679003572ac0b52f21c4e3a3b4153266bb753b0d6fd94d610d8b450ff1",
|
||||
"evidence/history102/security/source-format.txt": "ec387b2550a140db9ab1804bb3cb0f514b8502525f55b732bdd9fad1c72e02e7",
|
||||
"evidence/history102/security/source-typecheck.txt": "e2e4a0a57871af607491edde01c5d228f8d06ab05ff0fc49209ee260e60d8b96",
|
||||
"evidence/history102/security/source-unit.txt": "0bd7a7a738d380f98658da5b488a8083ff71a306375793c166a8b092e98a0525",
|
||||
"evidence/history102/security/valkey-reclaim-green.json": "09af4728afaa67a358203e3acdb17246bc98365323b7b39f3ff7f344c7539a81",
|
||||
"evidence/history102/security/valkey-reclaim-last.json": "693536854f2ccada7e330e42390662371e64d0dd27635f0fc3162624178c562a",
|
||||
"evidence/history102/security/valkey-reclaim-red.json": "00875682e47392e0302e45562f7d3d6127ebaf3c81cbdd96c88193096245ccec",
|
||||
"evidence/history102/security/valkey-reclaim-split-86d5744e-df35-44da-8f9b-267bd1ddc7dc.json": "693536854f2ccada7e330e42390662371e64d0dd27635f0fc3162624178c562a",
|
||||
"evidence/history102/security/worker-privileges.json": "7abba0b468502ab0b65c3f06d60af6cc51cc5f7279dbdf7d7194f551f7ebcaf8",
|
||||
"evidence/openbao/DELIVERY-GIT-PROOF.json": "eb80898b4b89d43c421011fb54703004a6996eea8185e41d6aff8add68f380e5",
|
||||
"evidence/openbao/NATIVE-COMPOSITE.json": "a965d2a3c1385e58a0108c081e37a2299c5358d32945e4b35c4ae48e986d9b5f",
|
||||
"evidence/openbao/agent-recovery-210df47b-593c-4fcf-b4f5-ecf0496eccb5.json": "6de31e3a434c5be750d2cad8f27e58feb6b9310bd712a60393562910a2a48fa4",
|
||||
"evidence/openbao/audit-configuration-f067.json": "12432240dc2ce6b3aad074ef3d843906f42d98e9a27405b0443fa1ca45b53df6",
|
||||
"evidence/openbao/bootstrap-15db3bba-6ebe-45f2-ada9-6989382dba88.json": "96befbda8d6b441553ccd8fa42d5fe8c079877c7e3d77e2c255edf0bc426f096",
|
||||
"evidence/openbao/bootstrap-f067e92a-cda6-499a-bde7-1aac49ccf373.json": "eb57f9d2135cb48ea49d3673ed451263fc3f9b130b30c6abe0ba67a9133dd561",
|
||||
"evidence/openbao/bootstrap-fe28da0a-2581-4a1c-8df6-948e78acb018.json": "3bc46a103b262ee7058e12806c7f85ebb80304c8345646cfcf46e53b977f6ce2",
|
||||
"evidence/openbao/canonical-git-proof-4e2abc51-e555-4b57-9847-ae4e27756240.json": "62ae0b5a703787db3977c87f3a6b4f2d013e0ec51fa13e47256c3435353b3aed",
|
||||
"evidence/openbao/canonical-git-proof-5cf4d770-00a1-431f-9345-3a420d33ecb9.json": "054e2747c4e70e37bbb30e90fca56b4ae3b15917f2f6dbee2d804b5f3e28b9fe",
|
||||
"evidence/openbao/canonical-git-proof-6f0db041-6f37-45dd-881c-1cab012c317a.json": "011c1df9106c79cd9b76c270cc85807955c8874ae6a4e888c38bbbaa8040b8d0",
|
||||
"evidence/openbao/canonical-git-proof-9525377a-9dd8-47be-89c5-c0684ee0b2d9.json": "2c49ec46bf07de489bd02d92f82c995b31ae7e6baa683a8111338ed0ee8c1cd2",
|
||||
"evidence/openbao/canonical-git-proof-c86324e1-7920-469a-b8b3-fdda55d25c26.json": "43d8d6409745fd2f5a90992c4c7061fc5121c868ce3ba0e19d386dc10141531b",
|
||||
"evidence/openbao/canonical-git-proof-cb58abdb-611d-4c61-8141-6f89fa9634dd.json": "9a6294aba3cfb09b3bd89eecdf03feaa08b9b68b37a44b5066764941f543275a",
|
||||
"evidence/openbao/canonical-git-proof-ccef4c03-2985-4722-8ba6-b3f291b1605d.json": "1cde197a1c487886d506d56007e87ca9f1f075b5319ab58780966b48300b7878",
|
||||
"evidence/openbao/delivery-git-proof-before-http-wiring-62ae311.json": "63920462f36a415729870eee9ded839443e0d01c4ecfbcd2268167cb1eee0bdf",
|
||||
"evidence/openbao/download-cache-bf3bbd5d.json": "9284d9db34b613f234f9c51783dd461184bd1ca6067b102621049e52c3cb4ba6",
|
||||
"evidence/openbao/failover-proof-green.txt": "728fd63d16ac1cff04eaea83f84aac33ce4040c9bf7277a6782cb379d70f1fc6",
|
||||
"evidence/openbao/failover-proof-red.txt": "1e61c7687d45693ef73ce47cff6c2e80637c3153f68f9834337a33d7896c2dbb",
|
||||
"evidence/openbao/freshness-recovery-green.txt": "3759f5b13a862f20a3d6c7649cf9272f3cd00627ea1084ed11abd0a889c82244",
|
||||
"evidence/openbao/freshness-recovery-red.txt": "a726d3620a5798ec7c62242672d69f95ff37aa66846f661b0a54c59e81501487",
|
||||
"evidence/openbao/git-proof-cli-green.txt": "85cb1de8cfdc23481c1baadbc3e277e66b47e0bc05f861e66334a7877ecd83a3",
|
||||
"evidence/openbao/git-proof-cli-red.txt": "d007fa1cc4a1e3ac21460383364835877ac5b640c0603ec993e4c10a3e50a18d",
|
||||
"evidence/openbao/git-tracking-proof-green.txt": "ef80fa2bd102afc5679db5c7f03eb720bf95fd9730893b97e7ee2252215e3830",
|
||||
"evidence/openbao/git-tracking-proof-red.txt": "eeb0c6968fcee5cb4599eff560dfc7039700dfd5e155c863d427a8a8afce1028",
|
||||
"evidence/openbao/health-convergence-green.txt": "828d0941fa690bc427cb23d4edc4e0d30b6d0913fa75d1827a6bb7226196c5e4",
|
||||
"evidence/openbao/health-convergence-red.txt": "1cdc5ef3d402ff69081513a88c6b79b9c30c3e867cef35ac569dc0bbce6441eb",
|
||||
"evidence/openbao/history-f3a4ef27-outer.json": "c187d8adc1426f351719696c272080585e5802d286bc8c246a957c29f9463a7b",
|
||||
"evidence/openbao/history-f3a4ef27-persistence.txt": "0264e21a8379f09070ecfaf114e09d6344416d34256dd152abaaf123c207d7c1",
|
||||
"evidence/openbao/history-f3a4ef27-processes.json": "3c16dda7429b3033689affcc2d277fd325bd52098dc7cbc2b5c9da9c38eae4f0",
|
||||
"evidence/openbao/history-f3a4ef27-session.json": "4105ea223a4dfdc4dfdd6946ea83ebc3268ff4a4ba0595e48dcb4cbfec6ef639",
|
||||
"evidence/openbao/native-acceptance-f3a4ef27-2c70-4fd9-b78b-d4e0a654941e.json": "c187d8adc1426f351719696c272080585e5802d286bc8c246a957c29f9463a7b",
|
||||
"evidence/openbao/native-control-a19bbdb5-6569-4604-9207-6ca9216ba33c.json": "32692410109a1d8e64460d15cccf568d1cf93840a0de0ba5ffe5ff6e35095d62",
|
||||
"evidence/openbao/native-final-recovery-http-210df47b-593c-4fcf-b4f5-ecf0496eccb5.json": "68af885ede4aaa8a2c592de99067b59f19f6efd1cd538887a78ffb04b8170efc",
|
||||
"evidence/openbao/native-remainder-8848b90f-3004-4436-8702-66d083adc7b6.json": "b58383957fcac39c58dc58ef3dce386484bc0240be093dcd8e49c32939c02ecb",
|
||||
"evidence/openbao/native-rotation-remainder-885c8009-d46d-4296-80b7-086e85b58dfe.json": "8fd1c4691aa05c1081a4a4f1bfe335941b0ae8c00a44178beb99c296307ad51a",
|
||||
"evidence/openbao/native-sealed-only-0e2ec040-cea8-4be2-89c6-45bb98490f8c.json": "4cc496315dc37f52dd692bd540e068320a247dd272b1478d94a715a7b905014e",
|
||||
"evidence/openbao/oracle-targeted-green.txt": "001ab586aef585c700e6e483ef08e9b1b8bf25721c3fed15cd7ce093e0c1901c",
|
||||
"evidence/openbao/publication-red-0f63d588-e2a1-4a40-94ac-1761b28db7ee.json": "17ff3ae4204495e1ca9a97045bfc8550949422d6e57bf2397e26d408381e0506",
|
||||
"evidence/openbao/publication-red-53292356-b06c-432e-a64e-20a98aa4e482.json": "54f5cebe1ac21f22319dd5ced1930c134949a9e2abf8975cc1d59dd6ed0b9b6d",
|
||||
"evidence/openbao/publication-red-eb8a32d8-1c5c-4f67-9547-2bae3c5acc03.json": "4417daf70d1d67149747c4e0debe97035f955424b8b5056cf7dd04f51677928b",
|
||||
"evidence/openbao/recovery-upload-210df47b-593c-4fcf-b4f5-ecf0496eccb5.json": "14ec7623221ccb719f9423149221c5a6e03a576f39a054930d5108094900ffe1",
|
||||
"evidence/openbao/replica-snapshot-green-formatted.txt": "a9b1d2295cd9a3274346249c324f7122176415bb89b4d8deb3be9d378f9209f7",
|
||||
"evidence/openbao/replica-snapshot-green.txt": "e1bac2850194ccb3f3105491934abfe3522ba92c2cfc4a532df55543ca01ca37",
|
||||
"evidence/openbao/replica-snapshot-red.txt": "6ad57d51f272a7c0df17ecf2267b523822dd0108960fcbe3849315c28dc58b39",
|
||||
"evidence/openbao/review-cli-delta-d6b95cca-3e25-4699-888e-59e28a53446e.json": "a2f486d404b3715ea179200fbb6838b4694893ff3bcbd83a052b570e15ac4b73",
|
||||
"evidence/openbao/review-final-docs-f500d07d-7ffe-41e1-a5ce-18554183cfbd.json": "c41e3e470318c12b114dd6f909929beea1e97209bcc566f2b952dde4dae6cd15",
|
||||
"evidence/openbao/review-final-recovery-http-ccf7e657-56c9-43a1-a50d-07a8bcf75cf0.json": "cf7479294adb3f03435068ddb95d5488d9be5761d2cbfbc5b6105e09b3f718b4",
|
||||
"evidence/openbao/review-http-wiring-4bb5ddc5-9131-45de-81b6-a2fe071d0ed6.json": "cc57cea38b358ecb15a8b86db7cd5aaf6115146b3f86a770a5ceca1a7a96dbad",
|
||||
"evidence/openbao/review-replica-delta-e7bbcb62-6b84-4d23-b674-a88058eb30f4.json": "f2380e9179a1eacf10ca77627e4a737d6480be1ebabf880ed083f085e723768a",
|
||||
"evidence/openbao/review-rotation-delta-11ca257d-85cc-42ae-b861-084542e4a263.json": "46874c4eef8410be72521b59b9d3e76ed781de1b883e8e96f915c228ff205696",
|
||||
"evidence/openbao/review-runtime-delta-6d612f53-c555-413a-85bb-f54dd03bcc32.json": "c0f351f90a63fbf1eb6269b3e87ac0d879d3a01d2f0d2fa7dffb9afd33aa473e",
|
||||
"evidence/openbao/review-runtime-delta-746f68d3-3972-49df-b574-55d554fa247c.json": "7fcef61af3f07c3aab74771b5207e69d69fd9280afc0da586bc72437b0e5d26d",
|
||||
"evidence/openbao/review-sealed-delta-0b5b6fa3-a5a0-49fd-b134-15f04cb42c76.json": "108a4d354e28a4b812f99be13f773a253f9b2e3753dc2bdb3e4d9e7fd1cda913",
|
||||
"evidence/openbao/revoked-alert-green.txt": "6c6c406ffa77e74f11ef60bdb07c575853ee9df43caf1c84602df8f21d50c169",
|
||||
"evidence/openbao/revoked-alert-red.txt": "0bb2234e7b45c2922738da76f6bbae59a967adf11cdc0787c471fbfd8adc7192",
|
||||
"evidence/openbao/rotation-partial-80535306-de8b-4bca-b742-a848a1dc7e47.json": "d2fce09155e2a09d826df9b31baa5ffdd6ffddcde5769cbde21d90dc6111b53c",
|
||||
"evidence/openbao/rotation-recovery-885c8009-d46d-4296-80b7-086e85b58dfe.json": "43ffb2da058c210e39135565d1bf6c2e842c6bf4b10d2564c9fd98e2b7b947ae",
|
||||
"evidence/openbao/runtime-preparation-green.txt": "84c296a582f6a9999219b155d38cade2a9379b75eb1d94a9f0964614d84e8489",
|
||||
"evidence/openbao/runtime-preparation-red.txt": "9fde8f71b3b26559771eea4f3cd6c4739fa6ffadcfc929c9ac8d8c4132a969da",
|
||||
"evidence/openbao/seal-partial-a707238c-832d-4595-92d1-3f1a2f51e7e5.json": "4041ed4e01b40dc0358354e798ebed415fe38fe38b2f40447a87b6f8e21139ee",
|
||||
"evidence/openbao/sealed-retention-green.txt": "286005b7b482ff7d5a791779dab0a6db826c29508372e4311651e24686029e42",
|
||||
"evidence/openbao/sealed-retention-red.txt": "d146f91948bd2428e919829eff2ef821d01d73a7b642c5c60afac4bec44b9547",
|
||||
"evidence/openbao/sealed-shutdown-green.txt": "134d60f44294a48ebfee72589ef03c28019edb33fca723abd2a3c266ad274541",
|
||||
"evidence/openbao/sealed-shutdown-red.txt": "7b830ba9584518a8ee66f60e7e2e9fcae505d674b5a8f319cde292e52f988b18",
|
||||
"evidence/openbao/shared-login-behavior-green.txt": "3414da082ed158dae8d69110f200797b6162e5fb0b39861dc7f97840bb3b0b90",
|
||||
"evidence/openbao/shared-login-behavior-red.txt": "b585002178b29bd1869b3b62763f992f2646f9c6f3cc7ce48ea2742b7c116264",
|
||||
"evidence/openbao/shared-login-draft-green.txt": "3970999ba352d4d59d88c0b9e60af9a3c00a6ff4ed33ead174750341602698cb",
|
||||
"evidence/openbao/shared-login-red.txt": "ed840cc35c0f4ccf2270607fd9209cae2fe0c5166ccf2fa3c1618dde0efd3519",
|
||||
"evidence/openbao/shared-login-source-green.txt": "3a37325cf6671676a286ddcc05f7905841d3f4fec8c30fb66dace2dafabd3553",
|
||||
"evidence/openbao/source-19257ca1-522a-49b9-913b-4dcc6c5b0591/CHECKS.json": "3cfe95b5788319cb30edd77e6d4abd845b35b6fd928e44e18855fa17c69c2ca5",
|
||||
"evidence/openbao/source-19257ca1-522a-49b9-913b-4dcc6c5b0591/check.txt": "04c05b8efee7d36d144a14160e593a8ebed724101b65e29d30a8b735699a5680",
|
||||
"evidence/openbao/source-19257ca1-522a-49b9-913b-4dcc6c5b0591/format-check.txt": "ec387b2550a140db9ab1804bb3cb0f514b8502525f55b732bdd9fad1c72e02e7",
|
||||
"evidence/openbao/source-19257ca1-522a-49b9-913b-4dcc6c5b0591/test-unit.txt": "bfe99ca88c737227ad4de0006d10265bf50aa9b3c62f98e80799665a114d3d2f",
|
||||
"evidence/openbao/source-5b5ae597-df58-4709-bfba-0ec9f4a3e448/CHECKS.json": "dfd55699bf151a718199fb93be8e7b646bc1b73029357865991f2074db4d794f",
|
||||
"evidence/openbao/source-5b5ae597-df58-4709-bfba-0ec9f4a3e448/check.txt": "48dbfab4fa7cf9a6859b667c9e83dacbee4eaf9a0f824833d4e0963acfa19a38",
|
||||
"evidence/openbao/source-5b5ae597-df58-4709-bfba-0ec9f4a3e448/format-check.txt": "ec387b2550a140db9ab1804bb3cb0f514b8502525f55b732bdd9fad1c72e02e7",
|
||||
"evidence/openbao/source-5b5ae597-df58-4709-bfba-0ec9f4a3e448/test-unit.txt": "a02fa79f5f6d78822c99c298072d529d72dd5484a67055c808f5a1560ee22a40",
|
||||
"evidence/openbao/source-64298c97-4efc-4fdb-8b73-c9157450b3a4/CHECKS.json": "14ea3c3f8e350c074837020d764fe1a7fb733e3d937251b18ed4b1e8706928ad",
|
||||
"evidence/openbao/source-64298c97-4efc-4fdb-8b73-c9157450b3a4/check.txt": "48004a063d681f51a1f37cee7a1e5882c56cf8c7c541eaa2abfaeb589a5f85a9",
|
||||
"evidence/openbao/source-64298c97-4efc-4fdb-8b73-c9157450b3a4/format-check.txt": "ec387b2550a140db9ab1804bb3cb0f514b8502525f55b732bdd9fad1c72e02e7",
|
||||
"evidence/openbao/source-64298c97-4efc-4fdb-8b73-c9157450b3a4/test-unit.txt": "8fa84eba75da7761130fc07ddbfddfd41249cbf0d54ad549fce70c68703c0cbc",
|
||||
"evidence/openbao/source-69f32e3d-0cf5-4572-bdf0-f48c0a5aae34/CHECKS.json": "9798d55a757ea83c9c18a15e8db555684444e4cf6d269022a013bf268311c320",
|
||||
"evidence/openbao/source-69f32e3d-0cf5-4572-bdf0-f48c0a5aae34/check.txt": "e3e50635c70497eb1f8522f376716165b81f01518323b3f4c9acc56fa7813f9e",
|
||||
"evidence/openbao/source-69f32e3d-0cf5-4572-bdf0-f48c0a5aae34/format-check.txt": "ec387b2550a140db9ab1804bb3cb0f514b8502525f55b732bdd9fad1c72e02e7",
|
||||
"evidence/openbao/source-69f32e3d-0cf5-4572-bdf0-f48c0a5aae34/test-unit.txt": "863889969c597e6977166cac645eaa37408a157536b52fdde439ae6be93719c2",
|
||||
"evidence/openbao/source-6a182103-6476-49cf-ab5b-54cca2008fea/CHECKS.json": "d4e575484a10dcda845777a10e16bd546281a62bb34a14db0380636ed3d93c90",
|
||||
"evidence/openbao/source-6a182103-6476-49cf-ab5b-54cca2008fea/check.txt": "fc9c6798834a0d9dc75d9d3a81ebf23ea4e0a93c8f5f12c276b95bb094a211ef",
|
||||
"evidence/openbao/source-6a182103-6476-49cf-ab5b-54cca2008fea/format-check.txt": "ec387b2550a140db9ab1804bb3cb0f514b8502525f55b732bdd9fad1c72e02e7",
|
||||
"evidence/openbao/source-6a182103-6476-49cf-ab5b-54cca2008fea/test-unit.txt": "90a8693dcaec4013ee46e4ad02aab3508b49d2684422fffb6e662f443d795aa8",
|
||||
"evidence/openbao/source-877c6a38-4275-440e-a77c-a7c60b20eb24/CHECKS.json": "59103506b5d4f0e636efc453b759c2a45c560cb6155ec152c35578f047329ff2",
|
||||
"evidence/openbao/source-877c6a38-4275-440e-a77c-a7c60b20eb24/check.txt": "2589e800e7fa337e3e9cbf2f8bc48728404a828ea83604c21749f1a0eb31c0bb",
|
||||
"evidence/openbao/source-877c6a38-4275-440e-a77c-a7c60b20eb24/format-check.txt": "ec387b2550a140db9ab1804bb3cb0f514b8502525f55b732bdd9fad1c72e02e7",
|
||||
"evidence/openbao/source-877c6a38-4275-440e-a77c-a7c60b20eb24/test-unit.txt": "7e519a4ab5655caaff0fb15f3ac7c38713102b640d81874d33a460bad6c2452a",
|
||||
"evidence/openbao/source-93577d11-92eb-49e1-85b6-04cad7b7232d/CHECKS.json": "e407a39bd1e41289a65943a648f8cbef9f84d5006894c4c3e7a66b1c67d62813",
|
||||
"evidence/openbao/source-93577d11-92eb-49e1-85b6-04cad7b7232d/check.txt": "76726e139df15c0b2bf18b4c6aba4a9fb81d9913d8f11c1f4c85452882e464a3",
|
||||
"evidence/openbao/source-93577d11-92eb-49e1-85b6-04cad7b7232d/format-check.txt": "ec387b2550a140db9ab1804bb3cb0f514b8502525f55b732bdd9fad1c72e02e7",
|
||||
"evidence/openbao/source-93577d11-92eb-49e1-85b6-04cad7b7232d/test-unit.txt": "65c2d2e9e5e215283824124b088d7710ca284c326f14efd81d858748c5e8b7f3",
|
||||
"evidence/openbao/source-bb678581-5a72-40d8-9214-cbf1dad1aaf5/CHECKS.json": "0bb452d103772037b2de864df22c35c9591cca4f3c585e0c842451bd6c6b96e2",
|
||||
"evidence/openbao/source-bb678581-5a72-40d8-9214-cbf1dad1aaf5/check.txt": "9b9e112dcbfe3f9561fdc3de651db7328db523fda9089a0c39bee0cb2817f273",
|
||||
"evidence/openbao/source-bb678581-5a72-40d8-9214-cbf1dad1aaf5/format-check.txt": "ec387b2550a140db9ab1804bb3cb0f514b8502525f55b732bdd9fad1c72e02e7",
|
||||
"evidence/openbao/source-bb678581-5a72-40d8-9214-cbf1dad1aaf5/test-unit.txt": "016d7a3f7dc710007d675c7821ed76f8da6963fab433bafaa49dfb8146edbf47",
|
||||
"evidence/openbao/source-cf7d834b-da6c-4c29-b11c-4d600a858626/CHECKS.json": "679af276502df6f4ac5cc420fb4bdaf76d2188ef93abd64e45e210b8fd94fb9d",
|
||||
"evidence/openbao/source-cf7d834b-da6c-4c29-b11c-4d600a858626/check.txt": "a2cc3ff9859f2ba64013aab6770bc0ff214a490b1fa74faca6507388bc66e4e6",
|
||||
"evidence/openbao/source-cf7d834b-da6c-4c29-b11c-4d600a858626/format-check.txt": "ec387b2550a140db9ab1804bb3cb0f514b8502525f55b732bdd9fad1c72e02e7",
|
||||
"evidence/openbao/source-cf7d834b-da6c-4c29-b11c-4d600a858626/test-unit.txt": "adeefcef911891c05bc69cb97a1dc5a41e9f1ee245cc398bd88875126dd62305",
|
||||
"evidence/openbao/source-e6cf9ebd-16f9-4f2a-85f7-2847abde1bf4/CHECKS.json": "23d977aed0d0866a00bfd83bc7e981cd6c481b4fc2ba148810fd180bf78c259c",
|
||||
"evidence/openbao/source-e6cf9ebd-16f9-4f2a-85f7-2847abde1bf4/check.txt": "d25186d9b4f52aa40ecdea64c73b75eeae47f4ec3288d7d6f379ed55dcceea9f",
|
||||
"evidence/openbao/source-e6cf9ebd-16f9-4f2a-85f7-2847abde1bf4/format-check.txt": "ec387b2550a140db9ab1804bb3cb0f514b8502525f55b732bdd9fad1c72e02e7",
|
||||
"evidence/openbao/source-e6cf9ebd-16f9-4f2a-85f7-2847abde1bf4/test-unit.txt": "c6de0b8291b5d1ce86bd7c11457b25b7b2dc463b3b6bd3bf76c6cc97078c87c7",
|
||||
"evidence/openbao/source-fbac4645-a8f3-4b46-8147-2fe86f502d2b/CHECKS.json": "7368d4a3882d2d515d55cb452340b9eed2c9dc58e62964d743ea86ba76aec698",
|
||||
"evidence/openbao/source-fbac4645-a8f3-4b46-8147-2fe86f502d2b/check.txt": "4fbb39e424ec92f0e5e24a8037d24b19d78f8ca350f9ebfb0107f56ace28e0f0",
|
||||
"evidence/openbao/source-fbac4645-a8f3-4b46-8147-2fe86f502d2b/format-check.txt": "ec387b2550a140db9ab1804bb3cb0f514b8502525f55b732bdd9fad1c72e02e7",
|
||||
"evidence/openbao/source-fbac4645-a8f3-4b46-8147-2fe86f502d2b/test-unit.txt": "35c50bdcf4a051b5e792242ec074e27178daa19159a495c4ece429006b1a9f81",
|
||||
"evidence/openbao/worker-agent-recovery-errors-0e2ec040.json": "54f053de497a28916f665e07536740debe10c593422bbf7eac0463e75e820d90",
|
||||
"evidence/openobserve/account-workflow-red.txt": "b14462c9063d4f80fdd7baf47ed10f927f6534ed100def27359def8c939537f9",
|
||||
"evidence/openobserve/accounts-green.txt": "039b6bcb2a41031a1dbe358e75d034b1ceb66ba98bb4a6e1a208f0eabce1de92",
|
||||
"evidence/openobserve/accounts-red.txt": "c925b973598ee5c83fa81193bc23c918c71b0b9fc589e0eec219ecee1af3f2cf",
|
||||
"evidence/openobserve/config-green.txt": "a90a9f9dc70d8141df47739a2f96d500a16fef077c499458759f76c26dce826f",
|
||||
"evidence/openobserve/config-red.txt": "532a61b4b7e224048666de810e6b00195476f36d5b8e86b7fc3459bf35596de6",
|
||||
"evidence/openobserve/error-ratio-4b928b8b-c1eb-4b24-a9a9-b9579f1fda93.json": "b7de0284e6772d3b5ed8a7d856ff4f086c3f0a195a8fb7400b7bd1b3720daf1d",
|
||||
"evidence/openobserve/error-ratio-cdf77d79-e4ab-4d2e-ae4b-9c3fcb5ab645.json": "f7bd09883e9372a215bc415583831776d932f96e61095c78141b7fd5bdbe7514",
|
||||
"evidence/openobserve/image-freeze.json": "d81020198d05e5f64397edcd8265980c7fcf97d1f6aed7ecbb01a7c4b2a16335",
|
||||
"evidence/openobserve/math-native-green.txt": "1c38f644123abf04377a0bf8399d0c47b6dbe82708980a50d9bb8e24eb325dd9",
|
||||
"evidence/openobserve/math-native-red.txt": "5f0299e53637ba9750848c6a934b000beaba24b7a2a193175a1bd0d3d7c2c7a5",
|
||||
"evidence/openobserve/native-session-26d288ed-9cb1-46f8-85ea-5e43b6c44122.json": "8ed2d109a3dae21d3b8c7d0bb4cb859c7a76cdb29d31e3954f52e9d5c2b9940a",
|
||||
"evidence/openobserve/persisted-readback-8fa17baa-a9f5-419c-bf24-e9ac820fdfbf.json": "c108a0324c6ce56a79b8cb87f506a2851bc27aba5b543576da9a96fd77f71b5f",
|
||||
"evidence/openobserve/persisted-readback-ed63afda-fcd8-4492-816a-7d4cf5940fcc.json": "0a3030103fa4eede1586032f07e77093e207143728c649cf308ac035cea75901",
|
||||
"evidence/openobserve/pipeline-fc1a31a6-7c89-4e10-98d4-fb127a6e352a.json": "062ea6e1a505e8aedfcb2c477a1ba0043b626f4c62b9d58dd7e40144de55a6b4",
|
||||
"evidence/openobserve/pipeline-fc1a31a6-7c89-4e10-98d4-fb127a6e352a.json.public-smoke.txt": "2a74ec8d5668274157198f94afcd8b77c3704a6f00e0ef6dfc0b3085cbeb4641",
|
||||
"evidence/openobserve/pipeline-first-run-failed.txt": "d664de390661b881a1c22b6da369ca49052627d7c37f2c5a965ef74c98b0104b",
|
||||
"evidence/openobserve/public-source-check.txt": "5f42d25d7cd8c1d2fb31ccf28a2872fbb91d38ed094024181e5ace9671667ee6",
|
||||
"evidence/openobserve/query-guard-d359332e-24a1-4fb4-a357-2a193a39706e.json": "7501315774e1dc99e433f3796408cf9e56064abb648c65f82bf425a5c3f8355e",
|
||||
"evidence/openobserve/reader-green.txt": "5439134d609c4c4d7463b4a639b7e85871e0c2fe0b76a67bdfa68e45a506e9fc",
|
||||
"evidence/openobserve/reader-red.txt": "0dad212fbfbd63ab420368ff8237f9e644fb0f11d22215abb9714b9f40b12a6a",
|
||||
"evidence/openobserve/reader-workflow-green.txt": "64c24c95c8a305e44dd384ee506af5625ad96f9238a58010c4dfe16593c4fc97",
|
||||
"evidence/openobserve/review-consumers-initial.sha256": "26ff6ee591ef6ad56fd3690a8b9e5679a128e579d2c3e5108ad774c18ecfd56a",
|
||||
"evidence/openobserve/review-final-source.json": "bde207c37c70d540a602ecf23410f6363cce7198c0cdc9ce4e62453b2f0fb227",
|
||||
"evidence/openobserve/review-fixes-source.json": "14460c0fbb96c17202fcd20bcf2a10370b1e571badbcd4f37ec78bfb6d3c8f1b",
|
||||
"evidence/openobserve/review-source-initial.sha256": "ed79971e258ac6b2bc874a4c95022c3e21d9dd0ce9d2562fdf4b93d48205be74",
|
||||
"evidence/openobserve/source/source-checks.json": "633f9e679003572ac0b52f21c4e3a3b4153266bb753b0d6fd94d610d8b450ff1",
|
||||
"evidence/openobserve/source/source-format.txt": "ec387b2550a140db9ab1804bb3cb0f514b8502525f55b732bdd9fad1c72e02e7",
|
||||
"evidence/openobserve/source/source-typecheck.txt": "faa8253ae5c0daf9a4cfc4838eaa324b227a5914303b6a5de45b3cf2995ccb82",
|
||||
"evidence/openobserve/source/source-unit.txt": "1bbe73f11cbea9681fcd4352dc88ae1b4b20b265c3fb4dd0f5f44765177b2160",
|
||||
"evidence/openobserve/terminal-outcomes.json": "fc5857f48375770dab4472b7a61007985213bcf0a7ba41ed4ff6f622edc1cbb2",
|
||||
"evidence/openobserve/tls-matrix-45a4e5ca-9422-4e7e-9874-d20b048fce99.json": "772a534bb2e1bc3a42aa5b545d16cbf128c64dcaf01f4f323735c4f6e6735d12",
|
||||
"evidence/openobserve/topology-green.txt": "119c867cd8027b8aa16bd17a06798cf6df5f0ab1bedc149afd88198d9cd28904",
|
||||
"evidence/openobserve/topology-red.txt": "e330aa159ad2e780b1cd9b152a9544e1e8744223a483d4e49e459893cdbfab8a",
|
||||
"evidence/openobserve/transport-e500b6fc-a04d-47f1-9058-d52a9bf3c27a.json": "bb519c67bcb9f99d0e60315604d7915f83fcb6bbcf782545da0f743609ac8f1a",
|
||||
"evidence/openobserve/url-green.txt": "1f0c29e24b1970b7a644c791caa48ee1358dcc5de9dfd72f97a65d7f09f4b2af",
|
||||
"evidence/openobserve/url-red.txt": "0b6e0b41922bc8afcd5a420d692096afcaed8bbb4eeddb8a32c7ea967cee55bb",
|
||||
"evidence/preflight/certificate-lifetime.json": "9b05aa0d36332366f218c3d8ebd32efb0abc9ef5a1953f98462b76361b13b9c4",
|
||||
"evidence/preflight/checked102-build.json": "b2577649ea38faf6b3eca638a1e1fdbac2ae1f4ac59ac4a5fd772a8538df762f",
|
||||
"evidence/preflight/checked102-source.json": "10059628e1281cbc18adc931b8a0fb8ccbf774c1cd4223d825d28f08c4e43201",
|
||||
"evidence/preflight/checked112-build.json": "492469d7c0eac62a072e4a3c21055e00815851592d3ed33d5f1bcee93fa1fa2b",
|
||||
"evidence/preflight/checked112-source.json": "09fe19253582282e489406600f3ee20c1e52d786778d6ce90f9d9da4146e5609",
|
||||
"evidence/preflight/finalization.json": "a09792380957e0c6fbad4ad9776ccb7a3b18baed01f656c3bbbfcdfcf00f2119",
|
||||
"evidence/preflight/freshness-expiry.json": "c6969af9b2e5d8e104f91b9cc9c614f2913beddc6306d3d820aea2f129c5c5f0",
|
||||
"evidence/preflight/public-test-security.txt": "15420508b820eb2b1378bb5a06515526aee38133158ec18fde81bc4474e11c21",
|
||||
"evidence/preflight/public-test.txt": "2a74ec8d5668274157198f94afcd8b77c3704a6f00e0ef6dfc0b3085cbeb4641",
|
||||
"evidence/preflight/summary.json": "970d53abe7bb05fd2201c3e75b412acf2608e739279b16a60434c0e141cca3e5",
|
||||
"evidence/preflight/tls-matrix.json": "044c4fa9a3c7170120ff22baf40794b9668fc5a7a6c07d34525923693cd8f4df",
|
||||
"evidence/reviews/GRAFANA-REVIEW-LINKS.md": "688b6754943c49265a3ec62ed60e6a044bfdd176d4dea2013e8e94d4991d98fe",
|
||||
"evidence/reviews/OPENBAO-NATIVE-REVIEW.md": "86cc8cdf6c0e5da07c050e3ce25138d590f53ab65e4ca916f8db2b4c20972c98",
|
||||
"evidence/reviews/OPENOBSERVE-REVIEW-INDEX.md": "b933026c04a4ba100f045bf7b3b33b436ba19d7888e8c1592fbe367f73592069",
|
||||
"evidence/reviews/history/review-grafana13-lab7-implementation-ac4bf204.md": "ac4bf204f160b0efab42634dee5e89d8657a5b22c79cd8f132ce3307cc046daf",
|
||||
"evidence/reviews/history/review-openobserve-migration-84540bd3.md": "84540bd3018db60251f9f4ca5b9532377810745fc40710e0fb4bf80156dde9af",
|
||||
"evidence/reviews/openbao-review-mirrors.json": "76ef11e7fd28b2f2e5a2947f0e68f02558836089eb09135e1e14eef39e1f8f05",
|
||||
"evidence/reviews/review-freshness.md": "003d7d461b646cf27b1b988ee7ea3ffe0af273248860aaa5132da4a494a335bf",
|
||||
"evidence/reviews/review-grafana13-lab7-implementation.md": "665345febb8abf4fbe6a731127644b5dec88b7594588f991197e734466c6a4f9",
|
||||
"evidence/reviews/review-openobserve-migration.md": "5ae5adbe32d7b9f2b4d612dc266fd4c568cd9fde1e49e51ec07187c4e2f24c6f",
|
||||
"evidence/reviews/review-vp7-accept-cli.md": "d0077e1338f127ad186d2a02c99fc53afc8929dc8920ba636a452b720482f082",
|
||||
"evidence/reviews/review-vp7-checkpoint-helpers.md": "503f5b2c4f45da8fcd04468186cfc04fe97131f51ddf426672d8b51ea0c7ba37",
|
||||
"evidence/reviews/review-vp7-infra.md": "7e91f5d8c05488f61942c272176b3fd22e23cda04ed2e337693878692a14f08a",
|
||||
"evidence/reviews/review-vp7-openbao-native.md": "4140646597938850d6359dc0039d9925194e4a1ecbf710114cc79429ac498c5d",
|
||||
"evidence/reviews/vp/lab7/evidence/grafana/native-control-748a9e0b-f1ae-4b4c-b8ce-ae4e19774cba.json": "ad624de1c4a24d4fc5801bc0c6b219460f482893bc68b4f85d15f923b9b6de45",
|
||||
"evidence/reviews/vp/lab7/evidence/grafana/review-source-41c6b438-c674-424f-a9f9-081a9ff66904.json": "dff06308dcaa446bd941a9e50bbe3753ae5acd3501b20ae11dcbd8324222f677",
|
||||
"evidence/security-scan/IMPORT.json": "7be1ef049c0b3f93dc4c4e358395d8604099c8aa1b580b6564d04c48730925d3",
|
||||
"evidence/security-scan/README.md": "1738d204678fce36dceeae987bc737d9479d681ef2066b232dc266ce80c2a70c",
|
||||
"evidence/security-scan/history/review-vp7-scan-triage-838ef16f.md": "838ef16f56d7d89cf377e18da456cdb43f5fa2a6273c4fd64a458d34fd581f63",
|
||||
"evidence/security-scan/native/INVENTORY.json": "0a9ffd7951b3bc463fa2f6c8cffa5dd46b1a3293844af56e57640b8bdb88b40e",
|
||||
"evidence/security-scan/native/SBOM-RESULT.json": "01f0933023c0e67e5a1a7ba670e8bf7d267741940a0c3c59e766cea083e443c0",
|
||||
"evidence/security-scan/native/consumer-rebind-v1/LOOKUP.json": "85bdf345fae8844737b695ddd1019fb555882ce2221a01ab838bfcbc8c782b2e",
|
||||
"evidence/security-scan/native/consumer-rebind-v1/RECEIPT.json": "3b7850e31e62fe94a56eafee4f0baed0e63267c0bfe85b15b46412879359e848",
|
||||
"evidence/security-scan/native/consumer-rebind-v1/SCAN-RESULT.json": "d9ed22ffef4ebe19078226d9d7fed99f204d3b4dd78cf022c943b3b93efc99ea",
|
||||
"evidence/security-scan/native/osv-complete/DETAILS-progress.json": "844e888e9bb49d38a529cc2e286c9f7d8b8957b57ae2bd16cb8c76a173993a2b",
|
||||
"evidence/security-scan/native/osv-complete/REQUESTS.json": "344473296696edf5953e8ddfab8145f360ba93afdbf599ee70f386ec323cfd49",
|
||||
"evidence/security-scan/native/plugin-buildinfo.txt": "a27f0bde526b037c7968b7a83d320cf8849eae6f902f23d89a50f58ec01dc0d4",
|
||||
"evidence/security-scan/native/sbom-bounded/0.cdx.json": "e70814a6da831e275f897d94d08316a64b7ea3361fb1fd14d221e44bb37b51ed",
|
||||
"evidence/security-scan/native/sbom-bounded/1.cdx.json": "6b8a7a6fd357454fca67261051411d7661328eb770258b6fb8b5240447677288",
|
||||
"evidence/security-scan/native/sbom-bounded/2.cdx.json": "20bdc104c2ca2d5f46c14cf14b52d93f8c236afc0b01491f925010328169a494",
|
||||
"evidence/security-scan/native/sbom-bounded/3.cdx.json": "87f985dd19771ba1e86e22f2aa9b5f52dcb5b0b9d36485a826e2e6fd9eaa26d2",
|
||||
"evidence/security-scan/native/sbom-bounded/4.cdx.json": "292319d49416c6fc85e94371ca15c33a55d6b71ddecaa6c29a493a06e8f52c62",
|
||||
"evidence/security-scan/native/sbom-bounded/5.cdx.json": "b5eb91aff0e2b2e8f9817d4ae1fb6240c9a9ab667e742c160a20af6bb88374cf",
|
||||
"evidence/security-scan/native/sbom-bounded/6.cdx.json": "2440d8363aec2db1de781fdd3a0f6d49c5df7f7a21d97b909a49d6f90f7cdbd6",
|
||||
"evidence/security-scan/native/sbom-bounded/7.cdx.json": "dfc82cab2cfaefd8b78f3fd39532af82f97dcae6391984112e0b48ba9fd16b47",
|
||||
"evidence/security-scan/native/sbom-bounded/8.cdx.json": "bd771226497f1a6d0fce53cfae8bf02428b61b6e14d09dcd8bae60684fb3acf1",
|
||||
"evidence/security-scan/review-vp7-scan-independent.md": "395da6ec7524964879701857a64c9074880efaf62c1b43bcf1728dec3cad3e67",
|
||||
"evidence/security-scan/review-vp7-scan-triage.md": "31e4479406ce992985c548aa1b5bd35a09f16c4df8332c2ef55b727ec9d2f4ee",
|
||||
"evidence/security-scan/vp7-scan-inventory.ts": "a714e53ae25f97c52f5a7bdb2c7681ba3c0572e94dac84e33dee0b9221535d0f",
|
||||
"evidence/security/artifacts-and-hardening.json": "31d4d84d2c29605a1c0809ac4a401261c45ff46dcb659e6bbb774a970439ef9e",
|
||||
"evidence/security/certificate-lifetime.json": "f25407c95e8e75f57f7f8c53ff2d9ba1606f8bf9f8022d26857977943bbd6005",
|
||||
"evidence/security/current112-slo-facts.json": "ba4657d1b581d268745fa44bbe21fa0179eaaa12ed45d2b49961f1a283186418",
|
||||
"evidence/security/current112-slo-query.sql": "aca019ac8282c96afccd5eecb5954bd4027387115895a3de597b4ddab87af32d",
|
||||
"evidence/security/failover-e639ee1c-d079-4bff-998f-f52ae7794b93-19c421ef-d8c7-4f33-84ae-7209e9558482.json": "63977134b21e03eac7cda45e89449ec8e897fbc1459eb91aebce4be927b5c08e",
|
||||
"evidence/security/failover-e639ee1c-d079-4bff-998f-f52ae7794b93-a753aa2f-efd6-44be-981a-cf23c4681cfd.json": "b6138f585b769ada7be35def2842c255b935af775d320cfd40304db51812c3ff",
|
||||
"evidence/security/final-recovery-session-210df47b-593c-4fcf-b4f5-ecf0496eccb5.json": "839a74f9f55ffd149ea586065b7d6da6963dee458128c9a30fef3c718db0a001",
|
||||
"evidence/security/freshness-red-green.json": "3ab2c09f2a8467ccefdfdb9e21b9c0b39d31a4bd2c6f7677db5f927fe59ef8d8",
|
||||
"evidence/security/gateway-parser.json": "615ac614a0d19fa43b0daaec6d3341fae574d01f42ff00c4385ed84beffa443e",
|
||||
"evidence/security/grpc-http2-fixture.txt": "7fd941eca3eeb12d4a1d4e9532333dd307f3fa960cf92b85db3c757f8742cc96",
|
||||
"evidence/security/helper-fix-freeze.sha256": "053a3c03258c8e30806e5ce6fe73602dc5f91d490666c8ae514ed520d5bdaf28",
|
||||
"evidence/security/kv-red-green.json": "c33ed9f5fdb460dc9611ed342eae7317745b3f5d5fdbc00a4334935649533a10",
|
||||
"evidence/security/native-helper-fix-freeze.sha256": "053a3c03258c8e30806e5ce6fe73602dc5f91d490666c8ae514ed520d5bdaf28",
|
||||
"evidence/security/offline-tests.txt": "d42616e7458f8493a85b61063c7ec8ceea598ea933fbb43702eb5631a40e57fc",
|
||||
"evidence/security/openbao-policy.json": "baec994118cd050e5405c45d6a695468454aacbb05db9c5726979c3c045072ed",
|
||||
"evidence/security/persistence-processes.json": "3c16dda7429b3033689affcc2d277fd325bd52098dc7cbc2b5c9da9c38eae4f0",
|
||||
"evidence/security/postgres-transport.json": "1623b79b6798635d98045b4f79404630bb6b6135f46988fc05d9e3c9d92f6206",
|
||||
"evidence/security/preflight-build.json": "492469d7c0eac62a072e4a3c21055e00815851592d3ed33d5f1bcee93fa1fa2b",
|
||||
"evidence/security/preflight-source-handover.json": "09fe19253582282e489406600f3ee20c1e52d786778d6ce90f9d9da4146e5609",
|
||||
"evidence/security/public-endpoint-red-green.json": "b5132ecaae833d4e5a01959e23bd752b02e3bee0514aab474cf4fad3e3b56b77",
|
||||
"evidence/security/public-failover-0.txt": "caece0a6f0e8fe21f4064a3cdea58f128a3b8bb635bc90fa99e4c1110dc2328e",
|
||||
"evidence/security/public-failover-1.txt": "ef947d071043b679adda86961a9813f4b531daeeca79e5b3762ab8a1ec6614fd",
|
||||
"evidence/security/public-persistence.txt": "0264e21a8379f09070ecfaf114e09d6344416d34256dd152abaaf123c207d7c1",
|
||||
"evidence/security/public-source-check.txt": "5f42d25d7cd8c1d2fb31ccf28a2872fbb91d38ed094024181e5ace9671667ee6",
|
||||
"evidence/security/public-test-security.txt": "15420508b820eb2b1378bb5a06515526aee38133158ec18fde81bc4474e11c21",
|
||||
"evidence/security/public-test.txt": "2a74ec8d5668274157198f94afcd8b77c3704a6f00e0ef6dfc0b3085cbeb4641",
|
||||
"evidence/security/red-green.json": "66c325300c4818c1a0f2a96c221da4ccfa69ea8aba57e242036df5aef6f8e31d",
|
||||
"evidence/security/review-kv.md": "d4081453938715e145f337999a8ed607ac35b2147895f07395f2309f3d82af33",
|
||||
"evidence/security/sealed-baseline-0e2ec040-cea8-4be2-89c6-45bb98490f8c.json": "0465810b7c9c09fdc5989e4c5b97e4d0412acbcba05e7b118f5df1b4785de00d",
|
||||
"evidence/security/sealed-cause-0e2ec040-cea8-4be2-89c6-45bb98490f8c.json": "16a573c1ad4ef7eac37d6ec893ead060bff6ba9352f64a4749b614a8206ce82e",
|
||||
"evidence/security/sealed-public-0e2ec040-cea8-4be2-89c6-45bb98490f8c.json": "a7fb0625b718b485f4ee1343342b23f98e17c08e1e991b1dacd20ee28fb57d8d",
|
||||
"evidence/security/sealed-recovery-health-0e2ec040-cea8-4be2-89c6-45bb98490f8c.json": "6f6521022472746384bdd14c18be1a68d0bafee2d485f9f880c0f1aa01140afd",
|
||||
"evidence/security/session.json": "4105ea223a4dfdc4dfdd6946ea83ebc3268ff4a4ba0595e48dcb4cbfec6ef639",
|
||||
"evidence/security/shared-login-210df47b-593c-4fcf-b4f5-ecf0496eccb5.json": "31ce0abd53b08a0d93fed75d02b09eac72dbbe945c39848196bf5aea913e60a5",
|
||||
"evidence/security/source-checks.json": "633f9e679003572ac0b52f21c4e3a3b4153266bb753b0d6fd94d610d8b450ff1",
|
||||
"evidence/security/source-format.txt": "ec387b2550a140db9ab1804bb3cb0f514b8502525f55b732bdd9fad1c72e02e7",
|
||||
"evidence/security/source-typecheck.txt": "e2e4a0a57871af607491edde01c5d228f8d06ab05ff0fc49209ee260e60d8b96",
|
||||
"evidence/security/source-unit.txt": "0bd7a7a738d380f98658da5b488a8083ff71a306375793c166a8b092e98a0525",
|
||||
"evidence/security/tls-matrix.json": "dda4e224ccd55e44cecc2c2fef423c80ac4fdec71e0ee1dcd525618f2d15e807",
|
||||
"evidence/security/token-expiry.json": "858ab43f5238a01cce1c2496eb317cf03b49b311570be56c49d1f479fbeb0f6e",
|
||||
"evidence/security/valkey-reclaim-green.json": "09af4728afaa67a358203e3acdb17246bc98365323b7b39f3ff7f344c7539a81",
|
||||
"evidence/security/valkey-reclaim-last.json": "693536854f2ccada7e330e42390662371e64d0dd27635f0fc3162624178c562a",
|
||||
"evidence/security/valkey-reclaim-red.json": "00875682e47392e0302e45562f7d3d6127ebaf3c81cbdd96c88193096245ccec",
|
||||
"evidence/security/valkey-reclaim-split-86d5744e-df35-44da-8f9b-267bd1ddc7dc.json": "693536854f2ccada7e330e42390662371e64d0dd27635f0fc3162624178c562a",
|
||||
"evidence/security/worker-compromise.json": "2d847a150e02c9b3606ed808ca19a998bf6d43461842f1943322a059991674fe",
|
||||
"evidence/security/worker-privileges.json": "7abba0b468502ab0b65c3f06d60af6cc51cc5f7279dbdf7d7194f551f7ebcaf8",
|
||||
"evidence/vp/lab7/evidence/grafana/native-control-748a9e0b-f1ae-4b4c-b8ce-ae4e19774cba.json": "ad624de1c4a24d4fc5801bc0c6b219460f482893bc68b4f85d15f923b9b6de45",
|
||||
"evidence/vp/lab7/evidence/grafana/review-lifecycle-delta-f74fcdf1-f211-41a7-8e08-66f58c03ab9e.json": "a1cbaaaf890d7ad9715648131b2116f6a8064bf822b5ad7010295a75e42c6095",
|
||||
"evidence/vp/lab7/evidence/grafana/review-source-41c6b438-c674-424f-a9f9-081a9ff66904.json": "dff06308dcaa446bd941a9e50bbe3753ae5acd3501b20ae11dcbd8324222f677",
|
||||
"evidence/vp/lab7/evidence/openbao/agent-recovery-210df47b-593c-4fcf-b4f5-ecf0496eccb5.json": "6de31e3a434c5be750d2cad8f27e58feb6b9310bd712a60393562910a2a48fa4",
|
||||
"evidence/vp/lab7/evidence/openbao/native-final-recovery-http-210df47b-593c-4fcf-b4f5-ecf0496eccb5.json": "68af885ede4aaa8a2c592de99067b59f19f6efd1cd538887a78ffb04b8170efc",
|
||||
"evidence/vp/lab7/evidence/openbao/recovery-upload-210df47b-593c-4fcf-b4f5-ecf0496eccb5.json": "14ec7623221ccb719f9423149221c5a6e03a576f39a054930d5108094900ffe1",
|
||||
"evidence/vp/lab7/evidence/openbao/review-cli-delta-d6b95cca-3e25-4699-888e-59e28a53446e.json": "a2f486d404b3715ea179200fbb6838b4694893ff3bcbd83a052b570e15ac4b73",
|
||||
"evidence/vp/lab7/evidence/openbao/review-final-recovery-http-ccf7e657-56c9-43a1-a50d-07a8bcf75cf0.json": "cf7479294adb3f03435068ddb95d5488d9be5761d2cbfbc5b6105e09b3f718b4",
|
||||
"evidence/vp/lab7/evidence/openbao/rotation-recovery-885c8009-d46d-4296-80b7-086e85b58dfe.json": "43ffb2da058c210e39135565d1bf6c2e842c6bf4b10d2564c9fd98e2b7b947ae",
|
||||
"evidence/vp/lab7/evidence/security/final-recovery-session-210df47b-593c-4fcf-b4f5-ecf0496eccb5.json": "839a74f9f55ffd149ea586065b7d6da6963dee458128c9a30fef3c718db0a001",
|
||||
"evidence/vp/lab7/evidence/security/shared-login-210df47b-593c-4fcf-b4f5-ecf0496eccb5.json": "31ce0abd53b08a0d93fed75d02b09eac72dbbe945c39848196bf5aea913e60a5",
|
||||
"examples/requests.http": "e69880f740f1e346354b519f14487d2bfcf1a41cbaa8cbedc61d258e7592fd3a",
|
||||
"freshness-process.json": "4216310b8a2086e96685325a6003fa1b073c7cc4e1e068d393fbf0695526a01f",
|
||||
"infra/README.md": "0e804fa51debba4c38d3cc84abf4704897665e0335b272060363f03aadd6354f",
|
||||
"infra/grafana/dashboards/messenger.json": "f7270d4c6f3936c9cc1b9b5a0cb3db85edfeb05cd123a919284a6f43802d6394",
|
||||
"infra/grafana/provisioning/alerting/messenger.yaml": "eb45f4fecaddd99e3adb05a2a485174d5dbfc8133e891a0df93763cb49d96c06",
|
||||
"infra/grafana/provisioning/dashboards/default.yaml": "8e261b2e380e674e92ad23c9c309e73ba72e6893326ebaa4eafcaac939ea4645",
|
||||
"infra/grafana/provisioning/datasources/default.yaml": "68ad7981cc813d8e334904c97ea8c7e07dc5c15e99512fde98cbb1464e964f5a",
|
||||
"infra/openbao/README.md": "b44e14af0ba9fb4adbf1456e97775b544be4e9b8f9eaf4cb76fc86ac4ab8f4ae",
|
||||
"infra/openbao/api-agent.hcl": "6784b3f17bdcf7e631fc1979626810cd31b2a3f31aa6dc4090a79e0e21085efb",
|
||||
"infra/openbao/api.hcl": "70af33765569946d52072591f22c3c627359743a55d27bdd6720191c18c9055f",
|
||||
"infra/openbao/server.hcl": "b5c17ff0d5d649b59d594f2e468bb587a10cecf89b9593278555cc63fe464fe1",
|
||||
"infra/openbao/worker-agent.hcl": "1383b8ebc3fe28316f8489f10c85c7d0e186e9327fa3e2f9b26ea4372ea6c442",
|
||||
"infra/openbao/worker.hcl": "a02360314ecab91e37c2246f63ffa3a55ec113565148b4ece5d9b4906b5094e1",
|
||||
"infra/otel/README.md": "0d6c93589f7b96b7045c1b82a261362697d25f14c9e1a4946b8ea8a977c1e842",
|
||||
"infra/otel/alerts.yaml": "1864029cf7fef3d1b151b236a70511bc19489fb34dd52b56de6f9c419bba4767",
|
||||
"infra/otel/collector.yaml": "1f1bd45394b54887d5e9f0a0845b29cf57006f8e660ca2cad6edf90fb2c617e8",
|
||||
"infra/otel/loki.yaml": "8b4fce5f0fec2cb2370886844f77f04292090d6552745b0f4ae01de039b84e8b",
|
||||
"infra/otel/prometheus.yaml": "7d2b45c901eb4aba7aa2fa8ec56b93d3ece5cabb052087bca1fcd5e6a1543967",
|
||||
"infra/otel/tempo.yaml": "ef775d189919456ccfa92bc9d8af4a46413fed90b7b65ee664e00106256c0d26",
|
||||
"lab.json": "f4cc620370d5c84be3d7a4422c48c05398cb28aa89185d4141b534b58e4b51c4",
|
||||
"lab7-argon-budget.txt": "7a0e6de5673325181ac34f1589acf72e0c16378f323c7f149dd405ff4c209d50",
|
||||
"lab7-backend-check.txt": "b738e4a334bb77f81770b41eceb8712450e36f2e7cafa574625fdf92c7ee769c",
|
||||
"lab7-broker-acl-final.txt": "27cc98be37d30c293cb1d47f3a1f31d0233b6cf11bb278e4d4d8af6d33bc5f6b",
|
||||
"lab7-final-backend-check.txt": "296c46b6987943c4169d3dafae0511370a98f400d33485b82d7209eaf7085565",
|
||||
"lab7-final-broker-check.txt": "75d0a027e6db40a91af14c455b69d7da66bb344b3a561f99918d52fa56acc960",
|
||||
"lab7-green-concurrent-rehash.txt": "a0f341e5833bd06789d87e73f4d16876d1b7111ce536d1db41633a45e5393d4d",
|
||||
"lab7-red-auth.txt": "bb2ed3cbd56855dbf246853d02ae2419051ce526b8f373a7174911330fa7a8dd",
|
||||
"lab7-red-broker-identities.txt": "3e9cef6a00ebfc49dce4c0451d0dab18a45daed1d870afac00712c1b4fa1a575",
|
||||
"lab7-red-concurrent-rehash.txt": "e068623503cc0ffabcae3b38737b1b458d82f589b9c682fe275271b96c6d0dc7",
|
||||
"lab7-red-lifecycle.txt": "6aee60ad1a25d77dfeccb167e4ada40c33d3457d0c1b8dbeba04e0b00a461b7a",
|
||||
"lab7-red-password.txt": "f2ca523b79b412a776d5d07a7462e8386fb42bdb38c38b2deaecf9ed977b48dc",
|
||||
"lab7-security-db.txt": "6e07bfac966f89d497202e14b3c7af3ea1e7a41599a19a0a4b80271f73236b00",
|
||||
"package.json": "64143d7d53564f846c65b0b42bdebc87a9f912048e57f1d94a72d520ecb8199c",
|
||||
"requirements-dev.txt": "4cefdb67007caf026d1613be7c519c01b4c8343db7c4f4b618677e01cf113525",
|
||||
"scripts/acceptance-session.ts": "daf1593004f1f375c1f8470748a3cf63acd3988b66c0b4c3cb608fe0a3b62244",
|
||||
"scripts/bao-client.ts": "e51b997b4c72bddc0ec6d3726fc671e23b4e4ed4be86ed56ddb049385ebac23a",
|
||||
"scripts/bootstrap.ts": "5a553624ea08648a5ccf18b84faf598c9c27de99527ce8c71478b1e0ba93d7b9",
|
||||
"scripts/browser-lifecycle.ts": "1cffda8119bf0f6e27c3d379cc655b8c9993a10e2f0187e7d7de923b5b2dea55",
|
||||
"scripts/check-source.ts": "f473322a0833730ea27111206908764fde849d59be5df8e145030e060f4c8dcf",
|
||||
"scripts/check-tooling.ts": "575144b702219b7733e609bf8aadbb4581c905dc2762ad3765d67d32d5a21b59",
|
||||
"scripts/check_contract.py": "7c4402c2a6ab80d3b4676e1866d6ecc87b6daea14c080bcb9be9a7e8b959d671",
|
||||
"scripts/checked-runtime.ts": "436869fa33ef861df2ff016403d5bb71673eb50ad14006f6ac4605020293e28c",
|
||||
"scripts/checkpoint-guards.ts": "3cc6268f23f8b6d4c36f5bf131a3a3c434fc65cce2a38dad7fd343bcc810230a",
|
||||
"scripts/command-runner.ts": "9c7dfbb100714a1512f31201e68318b25aa98c6328d923c5645a53d2b2ab7335",
|
||||
"scripts/db-provision.ts": "a2ab2ffb5e6e4ccc33c77921388dfab5da58ab2b0280c2ced78ebac58f54c537",
|
||||
"scripts/diagnose-command.ts": "455400cc56cb0db6890a6f07fa0ce1f1f05d9910d0ca5785f15f578ade91c211",
|
||||
"scripts/diagnose-preflight.ts": "d0338ac934a9efd0d0d44c346f12c6839c0da8fc26a0b13ab94e44e529c8b348",
|
||||
"scripts/diagnose-tls.ts": "7600a6fff8a4860211d78dc71352cd244e922c96feb3970e4735167fde542163",
|
||||
"scripts/diagnose.ts": "4d48e616125dfb03d80bb466a1a219c6e81dd99c34f21489d4853fce74100fcb",
|
||||
"scripts/export-git-tracking.ts": "3a14042c1b65ec1abf951bdb1a24ecd8f20bca5b141a5069db45a997d977c938",
|
||||
"scripts/export-public-baseline.ts": "02af3d1518c16bc0e554b4b56f892359af09f124908ab36f67699e63830484f0",
|
||||
"scripts/failover-proof.ts": "12b0f906b749486689984d60858838b1f9a2eb265d698fc8834a1174e2c3231a",
|
||||
"scripts/final-source-checks.ts": "dfea5d4d5d59d105f6356fb734f7e5a9c31d48d1d53a19c73a8a6c544e1758e2",
|
||||
"scripts/finalize-preflight.ts": "ca07d417d2f23380775889718f903bd31de2ccf9b42bd75ca7bbcead280a8c9c",
|
||||
"scripts/format-check.ts": "8927fe54ff5f6e9cbd802037a18d540e5eea314613b112fbe68b7c72b28277cf",
|
||||
"scripts/generate-agent-configs.ts": "429757ccb3f7999d9a79274ca09982ac2c062299699795949a3d780eed8ca838",
|
||||
"scripts/git-proof-cli.ts": "38d38c72968e2eb6594fd3542f9c483ffb493136497a92780f6a71094dac3548",
|
||||
"scripts/git-tracking-proof.ts": "721576bde5f84795396e3f435e7c0d7405623545c922c85157e4989da4d4fb7d",
|
||||
"scripts/git-tracking-source.ts": "3736aace70fcb6c06fa9920f819d9ed5951ba8e38f0ed5ad77f0bb17bb831e87",
|
||||
"scripts/grafana-browser.ts": "e82d353479ae91ec1386536760fe212410d68734db1afdae20fbcc4147312795",
|
||||
"scripts/grafana-cache.ts": "4bcb41b9d05db565141d06f85357f8d7ef8559a5e5094beafa08fa085fb575a7",
|
||||
"scripts/grafana-datasources.ts": "3c3dc3ea336dbd9005e0a465ea4198f0cc51f68948a999c8071d54a9432f8731",
|
||||
"scripts/grafana-incidents.ts": "e772f1afe12de0e6b29dc20312c5a2bb878164ed2e3ba90d1d8655339717c339",
|
||||
"scripts/grafana-preflight.ts": "e431d88da125eaca909d0af8dfc3322e8713f3a3d2e25f6b0206090c7b2ae19c",
|
||||
"scripts/grafana.ts": "d8b85be84abcaab697bc823bb70fa663e9c791b6f692a338e891fa6ad0ec9c6a",
|
||||
"scripts/health-convergence.ts": "4683dd92e950e78a1edaef4053c7288a768fc743a0af461f513d1cad957daad5",
|
||||
"scripts/hooks.ts": "e1b327401a130055f0809969bd070be8479db4df2f6b039890c8a45b8d582265",
|
||||
"scripts/image-manifests.ts": "993a0a78cc04f025759d972a777b39912d5cd5887bd5a8e172202795c4c465a6",
|
||||
"scripts/install-dev-types.ts": "969b398f1de2a0aa897d6eb521ff2e20e691a1958800fe75f106239a39230163",
|
||||
"scripts/kv-secrets.ts": "962487d2786e44472b9aa4a765c399e8c918bf86112cbdc78c2e6deff15c4260",
|
||||
"scripts/lab.ts": "5a404de1114637626c646bcd192e1feaea63c3b6c62935e81ea4664058e77e6c",
|
||||
"scripts/native-security.ts": "ad24763c7be32ce24d89d99e074fe40c03f51da3d5b24cbbd0994398d00c6b9c",
|
||||
"scripts/openbao-operator.ts": "0b7f2d28a97ca82d64715db09c65fe22eea3f13f040b366d00c9362e805f632e",
|
||||
"scripts/openobserve-accounts.ts": "d78f380a68de729361537a9572c42366631b48a03b7143c9799433bbecdab3ae",
|
||||
"scripts/openobserve-cache.ts": "01e71c3565d9c841b04843c28c5823d4bebe53ce4b52c6cb39e167a7e65288a2",
|
||||
"scripts/openobserve-config-check.ts": "ce9f046b835108b3aabe4e7f89511aa343b823cbd68aa67143dfd55009f619c9",
|
||||
"scripts/openobserve-pipeline.ts": "421d8351b7d411f2d1a32710d4a6375071e2362c2bbf1dbca9a3c242ee47d680",
|
||||
"scripts/openobserve-query-policy.ts": "2e232ef8415dad27de01589b0c24b74088d0e8009684cbc42c7b94185984b725",
|
||||
"scripts/openobserve-readback.ts": "3f25dd12c0517e89276dbad6e25c1701451eeaeb9fae9b28014e619c8c90e1e5",
|
||||
"scripts/openobserve-request-path.ts": "11ec86c0cf9304ce77385e6a6b88ffca99ec42a6ba5f33a528f0ec1d7f7fa02c",
|
||||
"scripts/openobserve-response.ts": "68484c6546da9f81179bfb81972403d1a974eeb229f4eae23c5c26f8de412344",
|
||||
"scripts/openobserve-search-window.ts": "9ce4c98d564f72e92447322dc3b3f0ffb9b7934bc5d8ab85851914080d218cf3",
|
||||
"scripts/openobserve-session.ts": "4b2b8c00a99dd28fdf0fc44f5fd0a50a5e8a4fe5117c6ddabff72f1981447b9f",
|
||||
"scripts/openobserve.ts": "06ed7dd00eb72116ae00584c31b15b042264bc00b758d8a4606a5146042431f4",
|
||||
"scripts/operator-crypto.ts": "6bcc6b9d28ecce952638009760d15a27fabc92386e3a4c84ebc68ca0c9fae2f8",
|
||||
"scripts/package-checkpoint.ts": "4f47f14b6e48fe12909c7a4e02b6a25281932667418f98bec7527a93dfbdf1b0",
|
||||
"scripts/pki.ts": "d5ccc96e4fde23636ca243eba0af3d38d7fe9ef1954eff5fbb337d8c005db256",
|
||||
"scripts/postgres-entrypoint.sh": "1891337f174ce88aa3111a6a8ccdab914caaed1e08c9f71069c0f20e9e4143e0",
|
||||
"scripts/preflight-build.ts": "f47cda3e94ae1529e6a70b8fee30bf3b94d7e0d2566c0963a4d29044b7315de9",
|
||||
"scripts/preflight-run.ts": "5eda7b7ca37521098642d577308b0ef4dfd25e6454ae7cd55e024505e3353446",
|
||||
"scripts/public-endpoint.ts": "23e4d0c858781d72e734b8f459788b852a847dbeb63e236b733a7bede0de7795",
|
||||
"scripts/reload-gateway.ts": "30608bf669a9a0575754821555cf9e038880e2f17a42ec3e34cb2b3fc5148eb0",
|
||||
"scripts/replica-snapshot.ts": "ce33f22f0080d03d4adf06e0907a5b41774f7528b0ab51eaafcefa2ee84fb48a",
|
||||
"scripts/reset-failed-test.ts": "4e0d41220a7002f5ce32725b961b42ab935a79b6477b8fd73a10b60f4e12da38",
|
||||
"scripts/restart.example.sh": "0328246ba75defbced992104e986fde973f63e3830d83251eced5953263e944b",
|
||||
"scripts/restart.sh": "d6d4c7306d2d503c4206de606b9ead048cb9087fce72ec8d184ff5010a4eca03",
|
||||
"scripts/rotation.ts": "6b68ae30b8e5ac98359e3176edb662838dbe213da5d74dd49ad665a02c5424a7",
|
||||
"scripts/runtime-inspect.ts": "80852499eb895f524aa8d8a9abab6f4030571e8b88f5445a5298402d18035b35",
|
||||
"scripts/runtime-preparation.ts": "af337e68544ba0b82d73d70f25c34b004d0e859a6df67a7c7efeb16b06717c1e",
|
||||
"scripts/runtime.ts": "71bbcb9485b3506b19c1cb508c8f483f22a3138e91dfccad0ed9ce412aefd7f6",
|
||||
"scripts/s3-control.go": "29cde9404b161e9fec2d43ff6a9e2ddf21af480ea76c887daf7403848983c40f",
|
||||
"scripts/s3-entrypoint.sh": "406efe392430f78a99f6dbbeffd492365ac3e8b311ef98ff1e52aeec99b67def",
|
||||
"scripts/s3-provision.ts": "d403f0f1babb1d46e8a921987d7c1e0d7f16026ff0a7552244714285b366d378",
|
||||
"scripts/sealed-shutdown.ts": "2a554bfdf3b24c1f373d0434755bc2aa7a1fbbe60d755dd72b3a9f425ed19b23",
|
||||
"scripts/security-guards.ts": "e2be86c2b19a5f1eb69a671d2ed7c2e800a0710cf17c5a78f1fa5fd6f1b5be3a",
|
||||
"scripts/shared-login-case.ts": "0bb5e6691aca6acf86f36cf2ea9eda9ce61447e5af0f34739ead31b55928266e",
|
||||
"scripts/stop-one.example.sh": "1bcf34394520b89d95b7605ec56675be799eea920e83cfbba306d5dc0a6d9811",
|
||||
"scripts/stop-one.sh": "1918bd2bb25e50b48f3da739a746925bc3855729cc3722f7507d121e13d9ca30",
|
||||
"scripts/telemetry-dashboard.ts": "9a55d17101a9784b819097077a1825fb9d30e7caaaad125dd42174bfb8e54a41",
|
||||
"scripts/test-session.ts": "68db319b5a0c284b8cfd2176abd9da48914001a9f943b3d98529f703e7b977fc",
|
||||
"scripts/topology.ts": "c68df7f6a500727d5d93d167c3862da729214d9fa7ab1cd3d35e18402edcf85e",
|
||||
"scripts/validate-gateways.ts": "731883160a910344b2caca533d711781be5223e91bcba114c39365940904d49a",
|
||||
"scripts/validate-source.ts": "fef58779a4a3800fa7769d53db5501fcf0d84ac6531587d670e9abf6b3c11c56",
|
||||
"scripts/validate_openapi.py": "4e981acbfc10dac58817bf922d5896e996798551fedc1b2385130e1cddb13d54",
|
||||
"scripts/valkey-acl.ts": "d8fdbe864def9ae63c27654541b95f12e69dcd7576df7f786d0dd7796cdcc10b",
|
||||
"scripts/verify-offline.ts": "60cfa5ef8dfb1cd04feaa4e0ed66f621a89c75cdbb0cf31ec61bf5ef0a649e26",
|
||||
"security/THREAT_MODEL.md": "3bc1a1c7c9d1b97988849123e9d9207cd116c1b8d1cbb4315272c659a57528c7",
|
||||
"student-tests/artifacts.ts": "e4f04dcef81f0f7f69aba034edf48b8f756c2baf87ae239367d4992919cd8d16",
|
||||
"student-tests/bao-policy.ts": "986634f5db0d85ba1e759997d574150b8e409c42de7d41cebf9a89938afcedfa",
|
||||
"student-tests/browser-lifecycle.test.ts": "d65a3dc39ea983e5a3093e9a351fdbe9897b87fdc0ef727e6f0f00202a9b3469",
|
||||
"student-tests/checkpoint-guards.test.ts": "2d56d9e18755083d1465f109a8dd88c74bd6a5cc1349ef4c8391e813ec51c4c3",
|
||||
"student-tests/command-runner.test.ts": "6af063e0c5f5dfcc9d134a9f5acad2fbd9dfe5d2457855fbec2d066272e5b59a",
|
||||
"student-tests/extended.ts": "951bb294f8e88e5c6b6e201d8a4e25b74bbbad8cca1b72436dbd523e67c8cb21",
|
||||
"student-tests/failover-proof.test.ts": "6ee97d20221dbae6d29d5f1c0d2ebf9abca99efe3e07ef785d40a66e52f76b90",
|
||||
"student-tests/freshness-runtime.ts": "b71cae6d2d9f8ab862eec6e6747960a426cedc993af4f072b16467aa19e5e2b4",
|
||||
"student-tests/git-proof-cli.test.ts": "f30ad57efabdaf29bbbf275892aa4e2d9d4c4eeed3a42b3498973451a2179116",
|
||||
"student-tests/git-tracking-proof.test.ts": "ad7043bc8c45e95d54e69748c4f0fb48fe4a9d95eb671a687a59090380224fc7",
|
||||
"student-tests/grafana-browser-launch.ts": "9dae537ba4df412ca12b87ac5b322b15e0efcd863e48087d21141bed93c5d9ed",
|
||||
"student-tests/grafana-datasources.test.ts": "5290b6c4010f43bb8adce654e8025d1f99db93c46a90878ce1af44c4afd5d2b0",
|
||||
"student-tests/grafana-gauge-proof.ts": "d3be11eed7fe8709fa27181c02badc310e9449582db31533cbc254df2c95ed0b",
|
||||
"student-tests/grafana-guards.test.ts": "4d5da44bef95f654808195280b77194b9f40b8dfa24adb1cd532cbc66b31975c",
|
||||
"student-tests/grafana-response-boundary.ts": "39ba01a8eab0af5c8a309460afe0762ce3ace4d1dfbfab999f7cba4c147c8f1d",
|
||||
"student-tests/grpc-probe.test.ts": "fea90a6bae5d0db07e2b37c3a057168efcf58ea82c830487893d08b2ddbd6ab2",
|
||||
"student-tests/grpc-probe.ts": "277759c999e0497bb890deab89af77028606a6ef879700893eecd52ca1337b7d",
|
||||
"student-tests/health-convergence.test.ts": "9b1b2c8c1a7e6589b356b6eb20c71412bacb88ecb0c6b4cd83cc99eec485fbc3",
|
||||
"student-tests/http-fixture.test.ts": "e594eab80d6d9a8e5a654e86c3f9756a0bbc0755235cf212b76370ce11b507e1",
|
||||
"student-tests/http.ts": "048d485fd24d4ada4379789822258ce21775aa4721ea3c7f4d87897fcb659939",
|
||||
"student-tests/kv-secrets.test.ts": "00a10caf5ddd5b2680b17dac98567988e8a022262dd6ff1964466d357c79f0bf",
|
||||
"student-tests/matrix.ts": "d4b1e7a2264a134e2542c1983f3a40a7308cd5d1504462cc401640e9105bc572",
|
||||
"student-tests/openobserve-account-workflow.test.ts": "9eb8c00c84b89ed3a9866b07cdd498b031d4603d1ca192364fd5a4dd4c220625",
|
||||
"student-tests/openobserve-accounts.test.ts": "830347ddb1477b4158021e37ea2a6d0ab35943d68488e74461d8e10ecc345dab",
|
||||
"student-tests/openobserve-config.test.ts": "5afc5d4419f93df92311e0b4904061178fc3d879f9570def5be51d7523f2f927",
|
||||
"student-tests/openobserve-error-ratio.ts": "474ae4e7eac551c54e9377b2f4ed04b61dd58cbef993d1711d603a0f8b4e1c94",
|
||||
"student-tests/openobserve-gateway.ts": "e4a199e942ed10f1e4aadb321b54ca971a3c23c1816664ed3565575199a918f7",
|
||||
"student-tests/openobserve-reader.test.ts": "0abb3e62bd4923ba5a21dd369e3ff75dc2724f89cab92ce99b836328157c1a15",
|
||||
"student-tests/openobserve-request-path.test.ts": "08b875e35c7b0e45e50a3ad5be849c75f90b250a41ed18ac559405749fdf031f",
|
||||
"student-tests/openobserve-response.test.ts": "75a1a1e0bf3cf70c319e71546dac55cd68f58eb52eb14d0fe29628bed3a3ae73",
|
||||
"student-tests/openobserve-search-window.test.ts": "7297c4f28102702850d9cac563bb83ee21014c1bbb6f8d4cb3bb56346619ed5c",
|
||||
"student-tests/openobserve-signals.ts": "1cdffd9274eb9dadfec0e6e30bfa24eae51c63ccc6fa4294503f1089f5f6d0cd",
|
||||
"student-tests/openobserve-topology.test.ts": "06f6a64f9b58d2b6a4beaa6585977edd7fecba0e3c38fa7dc9f6c55250eb3754",
|
||||
"student-tests/openobserve-transport.ts": "83b7c8a3e6bc52c6fc88a3eaefaac4ee48d1bedae1dfe3d2249d40b4d20cd9e6",
|
||||
"student-tests/operator-crypto.test.ts": "c180ad3887a52e10a91e554fc1f204d84b54c08d8e328ff2096ab7ddda057286",
|
||||
"student-tests/pki.test.ts": "2aba61d1ff1215b77038fcecb7240a08a6e79ea88f97fca6d18da7ba9e073841",
|
||||
"student-tests/postgres-transport.ts": "74ad944f9dfeeecebde05d896a04d6d3d0331aa53d63b90e3a3c98b1f5fd697f",
|
||||
"student-tests/privileges.ts": "8bed408fd94c497993c713e7d67dfe3e9768494322419efba2ec7dba47e4b4db",
|
||||
"student-tests/probe-pki.ts": "caebcb0948438b4587fbbc05c2eab750f962faab7c6d36d4efef3304f7f6fbdc",
|
||||
"student-tests/public-endpoint.test.ts": "00a60f539424e4b4312beab4200add2b0cc042bf058378a253ef32bbbf7eeec7",
|
||||
"student-tests/replica-snapshot.test.ts": "110898b9b67759c82b5fde7a165576044d9fbbcba33fcef20e4c1551809be183",
|
||||
"student-tests/runtime-preparation.test.ts": "6bbdbd04a49ec8ab09f372f59336d94a6fae6b68bfd8d23ff5b06a7151b17fba",
|
||||
"student-tests/sealed-shutdown.test.ts": "1a5d6db532dc0cacf34c7c74251c4ad6918a98b41482305b82077983970a81ee",
|
||||
"student-tests/security-guards.test.ts": "38eb08734bbb5dfd9b22cb534b21284bb9ed5395e11d82e5a30d1eaebb57015f",
|
||||
"student-tests/shared-login-case.test.ts": "2ff9bfc59da17ec2ae68bff6bf4edf448f8aa87dc8c36006b9c678be9f58263a",
|
||||
"student-tests/shared-login-runtime.ts": "e9e63a4651c5dd1027c372f7101116b893bb4e5017b681eb171267fdfc2c78e1",
|
||||
"student-tests/transport-negative.test.ts": "035bd25a64ef9db29aca53d6e75fc969a56a970fe1e8a758c3caaede07addd4e",
|
||||
"student-tests/transport.ts": "72ac8157965db07fc891028ef3c411f0e6c2c11c1252db3701e276e18d534b33",
|
||||
"student-tests/valkey-reclaim.test.ts": "d57c292d8a7347eea8743b5f7f214c7324fd61d07fe993ad6a450fc9c4df2df4",
|
||||
"student-tests/wait.ts": "2bcd3bf867666fd6d8ee37022d0a113649fb69bc83993af2d269659a873d4647",
|
||||
"tests/README.md": "e0bfa7e196797f6a5bf6e44d8ad2ffeb82651927ff5d8484eb1c2dda1ec7dec5",
|
||||
"tests/client.py": "8d50976fc7c7bbb81e88a152f613c61ab25eaf53dba33c6a9dfab19f868d546d",
|
||||
"tests/fixtures/README.md": "c001783760b4f87a7a8441a7ba55f5d080ff48e1397d3581d72a88d7691f96c2",
|
||||
"tests/fixtures/sample.png": "99ea7533c441f79cd630d15ce4d58d1ec4e06f6f0efb3b77a5c088305cd1bd75",
|
||||
"tests/image_probe.py": "a9a4f89181c8e0fda6ce42e1a1af32fb42d8e3ae519e314207127c9b9b448b13",
|
||||
"tests/load.py": "6d3511ea719c7a7e841083e73d435c86dcbfd9f4e5c2a07d62eb9614b01d9933",
|
||||
"tests/resilience.py": "1f96663a174b3978d24eff66f2741f5f8c9b788d3242261d37a972720c52788b",
|
||||
"tests/security.py": "6560a56cc22981c9f06043709bfabe7a47fa7eab57e62741e95534ac5ddff8a7",
|
||||
"tests/smoke.py": "52ac38eb343ff7d43e7543588e1da58ca06c9fce74b2b0d0bf0e4982bc23c1db",
|
||||
"tsconfig.json": "f4597ca6a119e2ea48f631964f1a898d834127ed9d51ab991deb014d2069e2eb"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
# VP7: current native/source checkpoint
|
||||
|
||||
Native remaining acceptance закончена, последний command39107 wholeexit0/postguards/stop0/owned0. Stand остановлен, новых runtime probes/downloads не требуется. Текущая работа — финальные docs/source ZIP и независимая archive byte-проверка; результат будущего archive review не выдумывается.
|
||||
|
||||
Backend112/09fe и четыре checkpoint guards сохранены. App/worker/s3-control image10ba7… использован как exact checked cache; fresh canonical Dockerfile build не заявляется. Source после CLI-only fix:123TS/178tests420expect/fmt0, native64398exit0. Native runtime generation896fde…/Git9a629 остаётся исторически точной; final delivery proof имеет отдельную generation после docs/config text.
|
||||
|
||||
[Composite](evidence/openbao/NATIVE-COMPOSITE.json) связывает35proofs и ограничения. Independent native41406465 SCOPED_PASS и CLI d0077e13 SOURCE_ONLY_PASS имеют [локальную навигацию](evidence/reviews/OPENBAO-NATIVE-REVIEW.md). [Scan](evidence/security-scan/README.md) имеет отдельный independent395da6ec и исправленную lookup attribution85bdf. Native reviewer не запускал stand/credentials; чистые overlapping test sets не суммируются с full suite.
|
||||
|
||||
## Принятые фазы и исходные failures
|
||||
|
||||
- f067 wholeexit0: reuse/unseal, native PebbleDB, own200/foreign/admin403, renew/revoke. initialized_before=true; предыдущие first-init/audit400 outcomes сохранены. Успешный raw audit body не сохранён, HCL path/mode не выдан за raw GET proof.
|
||||
-34156 wholeexit1: public HTTPS/security/PG/matrix/Bao/privileges/persistence выполнены до failover snapshot docker cp из tmpfs. Reader исправлен exec/immutableID/start-time;112backend не менялся.
|
||||
-96169 wholeexit1: оба operation-bound failovers(api1/api2), leaf lifetime и Grafana scope выполнены до oracle, не принимавшего native certificate-revoked alert. Classifier исправлен с timeout/success negative controls.
|
||||
-65111 wholeexit1: продолжена та же rotation без новых upload/revoke,3exact queued jobs стали ready/completed, S3 originals byte-equal; artifact/hardening и TTL60 expiry403/fresh200 пройдены. Original peer API token не сохранён; DB+native SigV4/mTLS S3 integrity не назван восстановленным API доступом. Failure был в sealed recovery health race.
|
||||
-26458 wholeexit1: полный original fresh/running baseline, sameID namedcause+restart и public503 сохранены до recovery. Initial ages4,798/3,798/3,798с; observed shutdown API1/API2/worker125,932/120,767/122,233с. Health convergence536мс/3reads прошла, затем worker Agent ещё не имел post-seal render. Native sealed errors/backoff1мин17,97с сохранены; никакого fabricated baseline из поздних файлов нет.
|
||||
-39107 wholeexit0: controlled Agent restart, actual all3post-seal renders, новый upload byte-equal,20main HTTP requests=10accepted/10application429+Retry-After60 через обе actual replicas,2other-account201 controls; DB counters10/2, max2inflight. Никаких новых seal/rotation/TTL/smoke. Stop всего project12,021с, owned0.
|
||||
|
||||
Пять control-plane legs экспортированы из собственного persisted tool thread в native-control-a19bbdb5… SHA32692410…; сигналы exec schema не предоставляет, signal=null/finished_ms не выдуманы. Старые FAILED не исправляются задним числом в PASS. First34156 outcome атрибутирован author-observed tool result отдельно.
|
||||
|
||||
## Сохраняемые границы
|
||||
|
||||
OpenObserve/Collector/Grafana уже доказали all3/persistence,42spans41parents,19finite panels, реальные links и2original alert firing/resolved в своих исторических datasets/provider scopes. Новая Bao приёмка не переименовывает те provider files в Bao. Current stack: OO1.1.2/Collector-k8s0.163.2/GF13.3.1/unmodified third-party plugin1.0.1/Bao2.7.2. ServiceAccount native rights read/write ограничивает mTLS gateway.8МиБ response contract не является work/RAM/decompression cap.
|
||||
|
||||
User quotas: GF/plugin600000000, actual559001001coordinator; Bao85000000, actual80099233. СИИ не разрешён. Старые ca313/361/D77/8e15/102 ZIP/reviews и raw false flags не менялись. Исходные RUN/REPORT/HELPERS/STATUS/READINESS перед этим closure сохранены побайтно в evidence/history/pre-native-closure с ORIGIN.json; они исторические, не current instructions.
|
||||
|
||||
Full security/whole telemetry/grade flags остаютсяfalse, teacher_grade=null. Track1 native experiment completed в указанной области; нет универсального all-dependency/zero-CVE/any-token-image-telemetry-leak или full HTTP DoS claim. Freshness120с/poll5с зависит от localFS/scheduling и не прерывает hung syscall. Работа не опубликована/не отправлена преподавателю. Private envelopes, CA keys, datasets и diagnostic bodies остаются исключёнными из Git/build/package; исторические private archives сохранены для адресной очистки оператором.
|
||||
|
||||
Поставляемый ordinary accept теперь вызывает SHARED_HTTP_LOGIN после extended acceptance с тем же operation ID. Это source-only wiring существующего native-проверенного helper; новый полный native run не выполнялся. Последний standard check123TS/178tests/420expect/fmt0 завершился exit0 (session67568).
|
||||
@@ -0,0 +1,36 @@
|
||||
version: "2"
|
||||
run:
|
||||
allow-parallel-runners: true
|
||||
linters:
|
||||
default: standard
|
||||
enable: [depguard]
|
||||
settings:
|
||||
errcheck:
|
||||
# Close тела ответа и файла, открытого на чтение: ошибке некуда деться.
|
||||
exclude-functions:
|
||||
- (io.ReadCloser).Close
|
||||
- (*os.File).Close
|
||||
depguard:
|
||||
rules:
|
||||
# Гексагон: ядро и use-case'ы зависят от портов, а не от адаптеров и транспорта.
|
||||
inner-pure:
|
||||
files: ["**/internal/domain/**", "**/internal/application/**"]
|
||||
deny:
|
||||
- pkg: backend/internal/adapter
|
||||
desc: домен и приложение зависят от портов, не от адаптеров
|
||||
- pkg: backend/internal/config
|
||||
desc: конфиг читает только cmd
|
||||
- pkg: net/http
|
||||
desc: HTTP только в adapter/handler
|
||||
- pkg: github.com/go-chi
|
||||
desc: роутер только в adapter/handler
|
||||
- pkg: github.com/rs/zerolog
|
||||
desc: логирование на границе, в адаптерах
|
||||
domain-core:
|
||||
files: ["**/internal/domain/**"]
|
||||
deny:
|
||||
- pkg: backend/internal/application
|
||||
desc: домен не знает о use-case'ах
|
||||
exclusions:
|
||||
paths:
|
||||
- ".*\\.gen\\.go$"
|
||||
@@ -0,0 +1,244 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"flag"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"os"
|
||||
"os/signal"
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
"backend/db"
|
||||
"backend/internal/adapter/handler"
|
||||
"backend/internal/adapter/lifecycle"
|
||||
"backend/internal/adapter/password"
|
||||
"backend/internal/adapter/repository/postgres"
|
||||
"backend/internal/adapter/storage"
|
||||
"backend/internal/adapter/telemetry"
|
||||
"backend/internal/application/usecase"
|
||||
"backend/internal/config"
|
||||
"backend/pkg/logger"
|
||||
"backend/pkg/server"
|
||||
"github.com/google/uuid"
|
||||
"github.com/jackc/pgx/v5/pgxpool"
|
||||
"github.com/redis/go-redis/v9"
|
||||
)
|
||||
|
||||
func main() {
|
||||
healthcheck := flag.Bool("healthcheck", false, "проверить /health/ready и выйти (для Docker HEALTHCHECK)")
|
||||
migrate := flag.Bool("migrate", false, "apply migrations and exit")
|
||||
bootstrapS3 := flag.Bool("bootstrap-s3", false, "initialize private bucket and application IAM credentials")
|
||||
reconcile := flag.Bool("reconcile", false, "reconcile at most 100 metadata rows and 100 objects; dry-run by default")
|
||||
apply := flag.Bool("apply", false, "apply safe reconciliation changes")
|
||||
grace := flag.Duration("grace", 10*time.Minute, "minimum safe object age, at least 60 seconds")
|
||||
after := flag.String("after", "", "metadata UUID cursor")
|
||||
objectAfter := flag.String("object-after", "", "object key cursor")
|
||||
flag.Parse()
|
||||
|
||||
cfg, err := config.Load()
|
||||
if err != nil {
|
||||
fmt.Fprintln(os.Stderr, "config:", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
if *healthcheck {
|
||||
os.Exit(probe(cfg.Port))
|
||||
}
|
||||
|
||||
log := logger.New(cfg.LogLevel)
|
||||
alias := uuid.NewString()
|
||||
if err = os.Setenv("INSTANCE_ALIAS", alias); err != nil {
|
||||
log.Fatal().Msg("instance alias initialization failed")
|
||||
}
|
||||
if err = os.WriteFile("/tmp/messenger-instance-id", []byte(alias), 0600); err != nil {
|
||||
log.Fatal().Msg("instance alias file unavailable")
|
||||
}
|
||||
observability, err := telemetry.Setup(context.Background(), "messenger-api")
|
||||
if err != nil {
|
||||
log.Fatal().Msg("telemetry initialization failed")
|
||||
}
|
||||
defer func() {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
|
||||
defer cancel()
|
||||
observability.Shutdown(ctx)
|
||||
}()
|
||||
dsn, err := config.ReadSecret(cfg.DatabaseURLFile)
|
||||
if err != nil {
|
||||
log.Fatal().Msg("database secret unavailable")
|
||||
}
|
||||
if *migrate {
|
||||
if err = db.Migrate(context.Background(), dsn); err != nil {
|
||||
log.Fatal().Err(err).Msg("migration failed")
|
||||
}
|
||||
return
|
||||
}
|
||||
s3path := os.Getenv("S3_CONFIG_FILE")
|
||||
if s3path == "" {
|
||||
s3path = "/run/secrets/s3_credentials"
|
||||
}
|
||||
s3config, err := storage.ReadConfig(s3path)
|
||||
if err != nil {
|
||||
log.Fatal().Msg("S3 application credentials unavailable")
|
||||
}
|
||||
objects, err := storage.FromConfig(s3config)
|
||||
if err != nil {
|
||||
log.Fatal().Msg("invalid S3 endpoint")
|
||||
}
|
||||
if *bootstrapS3 {
|
||||
root, e := storage.ReadConfig("/run/secrets/s3_root")
|
||||
if e != nil {
|
||||
log.Fatal().Msg("S3 bootstrap credentials unavailable")
|
||||
}
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
||||
defer cancel()
|
||||
if e = storage.Bootstrap(ctx, root, s3config); e != nil {
|
||||
log.Fatal().Err(e).Msg("S3 bootstrap failed")
|
||||
}
|
||||
return
|
||||
}
|
||||
pc, err := pgxpool.ParseConfig(dsn)
|
||||
if err != nil {
|
||||
log.Fatal().Msg("invalid database configuration")
|
||||
}
|
||||
pc.MaxConns = cfg.MaxConns
|
||||
pc.ConnConfig.Tracer = telemetry.DBTracer{}
|
||||
pc.MinConns = 0
|
||||
pc.ConnConfig.ConnectTimeout = time.Second
|
||||
pc.ConnConfig.RuntimeParams["statement_timeout"] = "2000"
|
||||
pc.ConnConfig.RuntimeParams["lock_timeout"] = "1000"
|
||||
pool, err := pgxpool.NewWithConfig(context.Background(), pc)
|
||||
if err != nil {
|
||||
log.Fatal().Msg("database initialization failed")
|
||||
}
|
||||
defer pool.Close()
|
||||
var cache *redis.Client
|
||||
if url, e := config.ReadSecret(cfg.CacheURLFile); e == nil {
|
||||
opts, e := redis.ParseURL(url)
|
||||
if e != nil {
|
||||
log.Fatal().Msg("invalid cache configuration")
|
||||
}
|
||||
opts.MaxRetries = 0
|
||||
opts.DialTimeout = 80 * time.Millisecond
|
||||
opts.ReadTimeout = 80 * time.Millisecond
|
||||
opts.WriteTimeout = 80 * time.Millisecond
|
||||
cache = redis.NewClient(opts)
|
||||
defer func() { _ = cache.Close() }()
|
||||
}
|
||||
store := postgres.New(pool, cache)
|
||||
if err = observability.Gauges(func(ctx context.Context) (map[string]float64, error) {
|
||||
m, e := store.PipelineMetrics(ctx)
|
||||
values := telemetry.PipelineValues(m)
|
||||
values["db_pool_used"] = float64(pool.Stat().AcquiredConns())
|
||||
values["db_pool_capacity"] = float64(pool.Stat().MaxConns())
|
||||
return values, e
|
||||
}); err != nil {
|
||||
log.Fatal().Msg("telemetry gauge initialization failed")
|
||||
}
|
||||
if *reconcile {
|
||||
cursor := uuid.Nil
|
||||
if *after != "" {
|
||||
cursor, err = uuid.Parse(*after)
|
||||
if err != nil {
|
||||
log.Fatal().Msg("invalid metadata cursor")
|
||||
}
|
||||
}
|
||||
if len(*objectAfter) > 64 {
|
||||
log.Fatal().Msg("object cursor too long")
|
||||
}
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
||||
defer cancel()
|
||||
report, e := usecase.NewReconciler(store, objects, time.Now).Run(ctx, cursor, *objectAfter, *grace, *apply)
|
||||
if err = json.NewEncoder(os.Stdout).Encode(report); err != nil {
|
||||
log.Fatal().Msg("reconciliation report write failed")
|
||||
}
|
||||
if e != nil {
|
||||
log.Fatal().Err(e).Msg("reconciliation incomplete")
|
||||
}
|
||||
return
|
||||
}
|
||||
app := usecase.NewMessenger(store)
|
||||
auth := usecase.NewAuth(store, password.New(), app, time.Duration(cfg.SessionTTLSeconds)*time.Second, time.Now)
|
||||
attachments := usecase.NewAttachments(store, app, telemetry.Objects{Objects: objects})
|
||||
probeDependencies := func(ctx context.Context) error {
|
||||
if e := pool.Ping(ctx); e != nil {
|
||||
return e
|
||||
}
|
||||
return objects.Ready(ctx)
|
||||
}
|
||||
h := handler.New(app, auth, attachments, probeDependencies, handler.Limits{
|
||||
MaxBodyBytes: cfg.MaxBodyBytes,
|
||||
MaxInflight: cfg.MaxInflight,
|
||||
MaxQueue: cfg.MaxQueue,
|
||||
QueueTimeout: cfg.QueueTimeout,
|
||||
}, func() any {
|
||||
return map[string]any{"pool_total": pool.Stat().TotalConns(), "pool_acquired": pool.Stat().AcquiredConns(), "pool_max": pool.Stat().MaxConns()}
|
||||
}, &log)
|
||||
srv := server.New(cfg.Addr(), h.Router())
|
||||
|
||||
ctx, stop := signal.NotifyContext(context.Background(), syscall.SIGTERM, syscall.SIGINT)
|
||||
defer stop()
|
||||
watcher, watchErr := lifecycle.FromEnvironment()
|
||||
if watchErr != nil {
|
||||
log.Fatal().Msg("invalid secret freshness configuration")
|
||||
}
|
||||
monitorDone := make(chan struct{})
|
||||
if watcher != nil {
|
||||
if watcher.Check(ctx) != nil {
|
||||
log.Fatal().Msg("secret freshness startup check failed")
|
||||
}
|
||||
monitor, err := lifecycle.New(lifecycle.Ports{Watch: watcher.Run, Stop: stop, Report: func() { fmt.Fprintln(os.Stderr, "{\"event\":\"secret_freshness_failed\"}") }})
|
||||
if err != nil {
|
||||
log.Fatal().Msg("secret monitor initialization failed")
|
||||
}
|
||||
go func() { defer close(monitorDone); monitor.Run(ctx) }()
|
||||
} else {
|
||||
close(monitorDone)
|
||||
}
|
||||
defer func() { stop(); <-monitorDone }()
|
||||
|
||||
serveErr := make(chan error, 1)
|
||||
go func() { serveErr <- srv.ListenAndServe() }()
|
||||
log.Info().Str("addr", cfg.Addr()).Str("env", cfg.Env).
|
||||
Int("max_inflight", cfg.MaxInflight).
|
||||
Int("max_queue", cfg.MaxQueue).Msg("server started")
|
||||
|
||||
select {
|
||||
case err := <-serveErr:
|
||||
log.Fatal().Err(err).Msg("server failed")
|
||||
case <-ctx.Done():
|
||||
}
|
||||
|
||||
started := time.Now()
|
||||
log.Info().Dur("timeout", cfg.ShutdownTimeout).Msg("shutdown signal received, draining")
|
||||
h.Drain()
|
||||
shutdownCtx, cancel := context.WithTimeout(context.Background(), cfg.ShutdownTimeout)
|
||||
defer cancel()
|
||||
if err := srv.Shutdown(shutdownCtx); err != nil {
|
||||
log.Error().Msg("shutdown timed out, forcing active requests closed")
|
||||
if err := srv.Close(); err != nil {
|
||||
log.Error().Msg("forced server close failed")
|
||||
}
|
||||
}
|
||||
if err := <-serveErr; err != nil && !errors.Is(err, http.ErrServerClosed) {
|
||||
log.Error().Err(err).Msg("server error")
|
||||
}
|
||||
log.Info().Dur("took", time.Since(started)).Msg("shutdown complete")
|
||||
}
|
||||
|
||||
// probe — healthcheck без curl в образе distroless: сам бинарник ходит в
|
||||
// /health/ready и возвращает код выхода для Docker.
|
||||
func probe(port int) int {
|
||||
client := http.Client{Timeout: 2 * time.Second}
|
||||
resp, err := client.Get(fmt.Sprintf("http://127.0.0.1:%d/health/ready", port))
|
||||
if err != nil {
|
||||
return 1
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
return 1
|
||||
}
|
||||
return 0
|
||||
}
|
||||
@@ -0,0 +1,160 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"backend/internal/adapter/imagefile"
|
||||
"backend/internal/adapter/lifecycle"
|
||||
"backend/internal/adapter/queue"
|
||||
"backend/internal/adapter/repository/postgres"
|
||||
"backend/internal/adapter/storage"
|
||||
"backend/internal/adapter/telemetry"
|
||||
"backend/internal/application/usecase"
|
||||
"backend/internal/config"
|
||||
"context"
|
||||
"flag"
|
||||
"fmt"
|
||||
"github.com/google/uuid"
|
||||
"github.com/jackc/pgx/v5/pgxpool"
|
||||
"os"
|
||||
"os/signal"
|
||||
"strconv"
|
||||
"syscall"
|
||||
"time"
|
||||
)
|
||||
|
||||
func main() {
|
||||
replay := flag.String("replay", "", "replay failed attachment UUID")
|
||||
advance := flag.String("advance", "", "new version for ready/failed attachment UUID")
|
||||
fault := flag.String("fault", "", "test-only crash point: after_original/after_objects/after_commit")
|
||||
flag.Parse()
|
||||
cfg, e := config.Load()
|
||||
must(e)
|
||||
observability, e := telemetry.Setup(context.Background(), "messenger-worker")
|
||||
must(e)
|
||||
defer func() {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
|
||||
defer cancel()
|
||||
observability.Shutdown(ctx)
|
||||
}()
|
||||
dsn, e := config.ReadSecret(cfg.DatabaseURLFile)
|
||||
must(e)
|
||||
pc, e := pgxpool.ParseConfig(dsn)
|
||||
must(e)
|
||||
pc.MaxConns = 2
|
||||
pc.ConnConfig.Tracer = telemetry.DBTracer{}
|
||||
pc.ConnConfig.ConnectTimeout = time.Second
|
||||
pc.ConnConfig.RuntimeParams["statement_timeout"] = "2000"
|
||||
pc.ConnConfig.RuntimeParams["lock_timeout"] = "1000"
|
||||
pool, e := pgxpool.NewWithConfig(context.Background(), pc)
|
||||
must(e)
|
||||
defer pool.Close()
|
||||
repo := postgres.New(pool, nil)
|
||||
must(observability.Gauges(func(ctx context.Context) (map[string]float64, error) {
|
||||
m, e := repo.PipelineMetrics(ctx)
|
||||
values := telemetry.PipelineValues(m)
|
||||
values["db_pool_used"] = float64(pool.Stat().AcquiredConns())
|
||||
values["db_pool_capacity"] = float64(pool.Stat().MaxConns())
|
||||
return values, e
|
||||
}))
|
||||
if *replay != "" || *advance != "" {
|
||||
s := *replay
|
||||
if s == "" {
|
||||
s = *advance
|
||||
}
|
||||
id, e := uuid.Parse(s)
|
||||
must(e)
|
||||
var ok bool
|
||||
if *replay != "" {
|
||||
ok, e = repo.ReplayJob(context.Background(), id)
|
||||
} else {
|
||||
ok, e = repo.AdvancePipeline(context.Background(), id)
|
||||
}
|
||||
must(e)
|
||||
fmt.Printf("{\"changed\":%v}\n", ok)
|
||||
return
|
||||
}
|
||||
s3path := os.Getenv("S3_CONFIG_FILE")
|
||||
if s3path == "" {
|
||||
s3path = "/run/secrets/s3_credentials"
|
||||
}
|
||||
s3cfg, e := storage.ReadConfig(s3path)
|
||||
must(e)
|
||||
objects, e := storage.FromConfig(s3cfg)
|
||||
must(e)
|
||||
consumerURL, e := config.ReadSecret(cfg.CacheURLFile)
|
||||
must(e)
|
||||
publisherURL, e := config.ReadSecret(os.Getenv("BROKER_PUBLISH_URL_FILE"))
|
||||
must(e)
|
||||
publisher, client, e := queue.Clients(publisherURL, consumerURL)
|
||||
must(e)
|
||||
defer func() { _ = publisher.Close(); _ = client.Close() }()
|
||||
attempts := 5
|
||||
if s := os.Getenv("WORKER_MAX_ATTEMPTS"); s != "" {
|
||||
attempts, e = strconv.Atoi(s)
|
||||
must(e)
|
||||
}
|
||||
if attempts < 1 || attempts > 10 {
|
||||
must(fmt.Errorf("attempts out of bounds"))
|
||||
}
|
||||
pipeline := usecase.NewPipeline(repo, telemetry.Objects{Objects: objects}, imagefile.NewTransformer(), int32(attempts))
|
||||
pipeline.OnResult = observability.JobResult
|
||||
if *fault != "" {
|
||||
switch *fault {
|
||||
case "after_original", "after_objects", "after_commit":
|
||||
default:
|
||||
must(fmt.Errorf("invalid fault point"))
|
||||
}
|
||||
pipeline.Fault = func(point string) error {
|
||||
if point == *fault {
|
||||
os.Exit(88)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
}
|
||||
broker := queue.New(publisher, client, repo, uuid.NewString())
|
||||
ctx, stop := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM)
|
||||
defer stop()
|
||||
watcher, watchErr := lifecycle.FromEnvironment()
|
||||
must(watchErr)
|
||||
monitorDone := make(chan struct{})
|
||||
if watcher != nil {
|
||||
must(watcher.Check(ctx))
|
||||
monitor, err := lifecycle.New(lifecycle.Ports{Watch: watcher.Run, Stop: stop, Report: func() { fmt.Fprintln(os.Stderr, "{\"event\":\"secret_freshness_failed\"}") }})
|
||||
must(err)
|
||||
go func() { defer close(monitorDone); monitor.Run(ctx) }()
|
||||
} else {
|
||||
close(monitorDone)
|
||||
}
|
||||
defer func() { stop(); <-monitorDone }()
|
||||
logError := func(error) { fmt.Fprintln(os.Stderr, "{\"event\":\"pipeline_dependency_error\"}") }
|
||||
cleanupDone := make(chan struct{})
|
||||
go func() {
|
||||
defer close(cleanupDone)
|
||||
ticker := time.NewTicker(time.Second)
|
||||
defer ticker.Stop()
|
||||
for {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return
|
||||
case <-ticker.C:
|
||||
cleanup, cancel := context.WithTimeout(ctx, 5*time.Second)
|
||||
e := pipeline.Cleanup(cleanup)
|
||||
cancel()
|
||||
if e != nil {
|
||||
logError(e)
|
||||
}
|
||||
}
|
||||
}
|
||||
}()
|
||||
done := make(chan struct{})
|
||||
go func() { defer close(done); broker.RunPublisher(ctx, logError) }()
|
||||
broker.RunWorker(ctx, observability.Worker(pipeline.Process), logError)
|
||||
stop()
|
||||
<-done
|
||||
<-cleanupDone
|
||||
}
|
||||
func must(e error) {
|
||||
if e != nil {
|
||||
fmt.Fprintln(os.Stderr, "worker initialization/operation failed")
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package: handler
|
||||
generate:
|
||||
models: true
|
||||
chi-server: true
|
||||
strict-server: true
|
||||
output: api.gen.go
|
||||
output-options:
|
||||
overlay:
|
||||
path: ../../../generator-overlay.yaml
|
||||
# date-time -> handler.Timestamp: ровно 6 цифр дробной части (см. timestamp.go)
|
||||
type-mapping:
|
||||
string:
|
||||
formats:
|
||||
date-time:
|
||||
type: Timestamp
|
||||
@@ -0,0 +1,25 @@
|
||||
package db
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"embed"
|
||||
_ "github.com/jackc/pgx/v5/stdlib"
|
||||
"github.com/pressly/goose/v3"
|
||||
)
|
||||
|
||||
//go:embed migrations/*.sql
|
||||
var migrations embed.FS
|
||||
|
||||
func Migrate(ctx context.Context, dsn string) error {
|
||||
conn, err := sql.Open("pgx", dsn)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer func() { _ = conn.Close() }()
|
||||
goose.SetBaseFS(migrations)
|
||||
if err = goose.SetDialect("postgres"); err != nil {
|
||||
return err
|
||||
}
|
||||
return goose.UpContext(ctx, conn, "migrations")
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
-- +goose Up
|
||||
CREATE TABLE users (
|
||||
id uuid PRIMARY KEY,
|
||||
username text NOT NULL UNIQUE CHECK (username ~ '^[a-z0-9_]{3,32}$'),
|
||||
display_name text NOT NULL CHECK (char_length(display_name) BETWEEN 1 AND 100),
|
||||
password_hash text NOT NULL,
|
||||
created_at timestamptz NOT NULL DEFAULT clock_timestamp(),
|
||||
chat_count integer NOT NULL DEFAULT 0 CHECK (chat_count BETWEEN 0 AND 1000),
|
||||
message_count integer NOT NULL DEFAULT 0 CHECK (message_count BETWEEN 0 AND 1000000),
|
||||
attachment_count integer NOT NULL DEFAULT 0 CHECK (attachment_count BETWEEN 0 AND 10000)
|
||||
);
|
||||
CREATE TABLE chats (
|
||||
id uuid PRIMARY KEY,
|
||||
title text NOT NULL CHECK (char_length(title) BETWEEN 1 AND 100),
|
||||
created_at timestamptz NOT NULL DEFAULT clock_timestamp()
|
||||
);
|
||||
CREATE TABLE chat_members (
|
||||
chat_id uuid NOT NULL REFERENCES chats(id),
|
||||
user_id uuid NOT NULL REFERENCES users(id),
|
||||
PRIMARY KEY (chat_id, user_id)
|
||||
);
|
||||
CREATE INDEX member_chats ON chat_members(user_id,chat_id);
|
||||
CREATE INDEX chats_order ON chats(created_at,id);
|
||||
CREATE TABLE messages (
|
||||
id uuid PRIMARY KEY,
|
||||
chat_id uuid NOT NULL REFERENCES chats(id),
|
||||
sender_id uuid NOT NULL REFERENCES users(id),
|
||||
text text NOT NULL CHECK (char_length(text) BETWEEN 0 AND 4000),
|
||||
created_at timestamptz NOT NULL DEFAULT clock_timestamp(),
|
||||
FOREIGN KEY (chat_id,sender_id) REFERENCES chat_members(chat_id,user_id)
|
||||
);
|
||||
CREATE INDEX messages_history ON messages(chat_id,created_at,id);
|
||||
CREATE TABLE sessions (
|
||||
token_hash text PRIMARY KEY CHECK (length(token_hash)=64),
|
||||
user_id uuid NOT NULL REFERENCES users(id),
|
||||
expires_at timestamptz NOT NULL
|
||||
);
|
||||
CREATE INDEX sessions_user ON sessions(user_id,expires_at);
|
||||
|
||||
-- +goose Down
|
||||
DROP TABLE sessions;
|
||||
DROP TABLE messages;
|
||||
DROP TABLE chat_members;
|
||||
DROP TABLE chats;
|
||||
DROP TABLE users;
|
||||
@@ -0,0 +1,12 @@
|
||||
-- +goose Up
|
||||
CREATE TABLE idempotency (
|
||||
user_id uuid NOT NULL REFERENCES users(id),
|
||||
chat_id uuid NOT NULL REFERENCES chats(id),
|
||||
key text NOT NULL CHECK (key ~ '^[A-Za-z0-9._:-]{1,128}$'),
|
||||
payload_hash text NOT NULL CHECK (length(payload_hash)=64),
|
||||
message_id uuid NOT NULL REFERENCES messages(id) DEFERRABLE INITIALLY DEFERRED,
|
||||
expires_at timestamptz NOT NULL,
|
||||
PRIMARY KEY(user_id,chat_id,key)
|
||||
);
|
||||
-- +goose Down
|
||||
DROP TABLE idempotency;
|
||||
@@ -0,0 +1,49 @@
|
||||
-- +goose Up
|
||||
CREATE TABLE attachments (
|
||||
id uuid PRIMARY KEY,
|
||||
chat_id uuid NOT NULL REFERENCES chats(id),
|
||||
owner_id uuid NOT NULL REFERENCES users(id),
|
||||
filename text NOT NULL CHECK(char_length(filename) BETWEEN 1 AND 255),
|
||||
content_type text NOT NULL CHECK(content_type IN ('image/png','image/jpeg')),
|
||||
size_bytes bigint NOT NULL CHECK(size_bytes BETWEEN 1 AND 10485760),
|
||||
sha256 text NOT NULL CHECK(sha256 ~ '^[a-f0-9]{64}$'),
|
||||
status text NOT NULL CHECK(status IN ('uploading','queued','processing','ready','failed','missing','abandoned')),
|
||||
pipeline_version integer NOT NULL DEFAULT 1 CHECK(pipeline_version>0),
|
||||
error_code text NOT NULL DEFAULT '',
|
||||
variants jsonb NOT NULL DEFAULT '[]' CHECK(jsonb_typeof(variants)='array' AND jsonb_array_length(variants)<=3),
|
||||
staging_expired boolean NOT NULL DEFAULT false,
|
||||
staging_cleaned boolean NOT NULL DEFAULT false,
|
||||
created_at timestamptz NOT NULL DEFAULT clock_timestamp(),
|
||||
updated_at timestamptz NOT NULL DEFAULT clock_timestamp(),
|
||||
FOREIGN KEY(chat_id,owner_id) REFERENCES chat_members(chat_id,user_id)
|
||||
);
|
||||
CREATE INDEX attachments_owner ON attachments(owner_id,id);
|
||||
CREATE INDEX attachments_staging_cleanup ON attachments(updated_at,id) WHERE NOT staging_cleaned;
|
||||
CREATE TABLE message_attachments (
|
||||
message_id uuid NOT NULL REFERENCES messages(id),
|
||||
attachment_id uuid NOT NULL REFERENCES attachments(id),
|
||||
ordinal integer NOT NULL CHECK(ordinal BETWEEN 0 AND 9),
|
||||
PRIMARY KEY(message_id,ordinal),
|
||||
UNIQUE(message_id,attachment_id)
|
||||
);
|
||||
CREATE INDEX attachment_references ON message_attachments(attachment_id);
|
||||
CREATE TABLE attachment_jobs (
|
||||
id uuid PRIMARY KEY,
|
||||
attachment_id uuid NOT NULL REFERENCES attachments(id),
|
||||
pipeline_version integer NOT NULL CHECK(pipeline_version>0),
|
||||
attempt integer NOT NULL DEFAULT 0 CHECK(attempt>=0),
|
||||
traceparent text NOT NULL DEFAULT '' CHECK(char_length(traceparent)<=55),
|
||||
tracestate text NOT NULL DEFAULT '' CHECK(char_length(tracestate)<=512),
|
||||
lease_id uuid NOT NULL DEFAULT '00000000-0000-0000-0000-000000000000',
|
||||
lease_until timestamptz NOT NULL DEFAULT 'epoch',
|
||||
next_attempt timestamptz NOT NULL DEFAULT 'epoch',
|
||||
published_at timestamptz NOT NULL DEFAULT 'epoch',
|
||||
completed boolean NOT NULL DEFAULT false,
|
||||
created_at timestamptz NOT NULL DEFAULT clock_timestamp(),
|
||||
UNIQUE(attachment_id,pipeline_version)
|
||||
);
|
||||
CREATE INDEX pending_attachment_jobs ON attachment_jobs(next_attempt,published_at) WHERE NOT completed;
|
||||
-- +goose Down
|
||||
DROP TABLE attachment_jobs;
|
||||
DROP TABLE message_attachments;
|
||||
DROP TABLE attachments;
|
||||
@@ -0,0 +1,5 @@
|
||||
-- +goose Up
|
||||
CREATE TABLE login_limits(bucket smallint PRIMARY KEY CHECK(bucket>=0 AND bucket<4096), started_at timestamptz NOT NULL DEFAULT 'epoch', attempts smallint NOT NULL DEFAULT 0 CHECK(attempts>=0 AND attempts<=10));
|
||||
INSERT INTO login_limits(bucket) SELECT generate_series(0,4095)::smallint;
|
||||
-- +goose Down
|
||||
DROP TABLE login_limits;
|
||||
@@ -0,0 +1,4 @@
|
||||
-- +goose Up
|
||||
ALTER TABLE attachment_jobs ADD COLUMN replay_count bigint NOT NULL DEFAULT 0 CHECK(replay_count>=0), ADD COLUMN replayed_at timestamptz NOT NULL DEFAULT 'epoch';
|
||||
-- +goose Down
|
||||
ALTER TABLE attachment_jobs DROP COLUMN replay_count, DROP COLUMN replayed_at;
|
||||
@@ -0,0 +1,8 @@
|
||||
-- +goose Up
|
||||
-- Historical upload/create time is not evidence of acceptance/readiness; leave
|
||||
-- pre-migration rows unknown instead of inventing SLO history.
|
||||
ALTER TABLE attachments ADD COLUMN accepted_at timestamptz, ADD COLUMN first_ready_at timestamptz;
|
||||
CREATE INDEX attachments_slo_accepted ON attachments(accepted_at) WHERE accepted_at IS NOT NULL;
|
||||
-- +goose Down
|
||||
DROP INDEX attachments_slo_accepted;
|
||||
ALTER TABLE attachments DROP COLUMN accepted_at, DROP COLUMN first_ready_at;
|
||||
@@ -0,0 +1,15 @@
|
||||
-- name: ChargeAttachment :one
|
||||
UPDATE users SET attachment_count=attachment_count+1 WHERE id=$1 AND attachment_count<10000 RETURNING id;
|
||||
-- name: InsertAttachment :one
|
||||
INSERT INTO attachments(id,chat_id,owner_id,filename,content_type,size_bytes,sha256,status)
|
||||
VALUES($1,$2,$3,$4,$5,$6,$7,'uploading') RETURNING *;
|
||||
-- name: GetAttachment :one
|
||||
SELECT * FROM attachments WHERE id=$1 FOR SHARE;
|
||||
-- name: SetAttachmentStatus :execrows
|
||||
UPDATE attachments SET status=$2,updated_at=clock_timestamp() WHERE id=$1 AND status=$3 AND pipeline_version=0;
|
||||
-- name: InsertMessageAttachment :exec
|
||||
INSERT INTO message_attachments(message_id,attachment_id,ordinal) VALUES($1,$2,$3);
|
||||
-- name: MessageAttachments :many
|
||||
SELECT attachment_id FROM message_attachments WHERE message_id=$1 ORDER BY ordinal LIMIT 10;
|
||||
-- name: ReconcileAttachments :many
|
||||
SELECT * FROM attachments WHERE id>$1 ORDER BY id LIMIT 101;
|
||||
@@ -0,0 +1,42 @@
|
||||
-- name: CreateUser :one
|
||||
INSERT INTO users(id,username,display_name,password_hash) VALUES($1,$2,$3,$4)
|
||||
RETURNING id,username,display_name,created_at;
|
||||
-- name: GetUser :one
|
||||
SELECT id,username,display_name,created_at FROM users WHERE id=$1;
|
||||
-- name: Credentials :one
|
||||
SELECT id,password_hash FROM users WHERE username=$1;
|
||||
-- name: ChargeChat :one
|
||||
UPDATE users SET chat_count=chat_count+1 WHERE id=$1 AND chat_count<1000 RETURNING id;
|
||||
-- name: ChargeMessage :one
|
||||
UPDATE users SET message_count=message_count+1 WHERE id=$1 AND message_count<1000000 RETURNING id;
|
||||
-- name: InsertChat :one
|
||||
INSERT INTO chats(id,title) VALUES($1,$2) RETURNING id,title,created_at;
|
||||
-- name: InsertMembers :exec
|
||||
INSERT INTO chat_members(chat_id,user_id) SELECT $1,unnest($2::uuid[]);
|
||||
-- name: GetChat :one
|
||||
SELECT c.id,c.title,c.created_at,ARRAY(SELECT user_id FROM chat_members WHERE chat_id=c.id ORDER BY user_id)::uuid[] AS members
|
||||
FROM chats c WHERE c.id=$1;
|
||||
-- name: ListChats :many
|
||||
SELECT c.id,c.title,c.created_at,ARRAY(SELECT user_id FROM chat_members WHERE chat_id=c.id ORDER BY user_id)::uuid[] AS members
|
||||
FROM chats c JOIN chat_members m ON m.chat_id=c.id
|
||||
WHERE m.user_id=sqlc.arg(member_id) AND (c.created_at,c.id)>(sqlc.arg(after_time)::timestamptz,sqlc.arg(after_id)::uuid)
|
||||
ORDER BY c.created_at,c.id LIMIT sqlc.arg(page_limit);
|
||||
-- name: InsertMessage :one
|
||||
INSERT INTO messages(id,chat_id,sender_id,text) VALUES($1,$2,$3,$4) RETURNING id,chat_id,sender_id,text,created_at;
|
||||
-- name: ListMessages :many
|
||||
SELECT m.id,m.chat_id,m.sender_id,m.text,m.created_at,
|
||||
ARRAY(SELECT attachment_id FROM message_attachments WHERE message_id=m.id ORDER BY ordinal LIMIT 10)::uuid[] AS attachment_ids
|
||||
FROM messages m WHERE m.chat_id=$1 AND (m.created_at,m.id)>(sqlc.arg(after_time)::timestamptz,sqlc.arg(after_id)::uuid)
|
||||
ORDER BY m.created_at,m.id LIMIT sqlc.arg(page_limit);
|
||||
-- name: LockSessionOwner :one
|
||||
SELECT id FROM users WHERE id=$1 FOR UPDATE;
|
||||
-- name: DeleteExpiredSessions :exec
|
||||
DELETE FROM sessions WHERE user_id=$1 AND expires_at<=clock_timestamp();
|
||||
-- name: InsertSession :one
|
||||
INSERT INTO sessions(token_hash,user_id,expires_at)
|
||||
SELECT $1,$2,$3 WHERE (SELECT count(*) FROM sessions WHERE user_id=$2)<100
|
||||
RETURNING user_id;
|
||||
-- name: AuthenticateSession :one
|
||||
SELECT user_id FROM sessions WHERE token_hash=$1 AND expires_at>clock_timestamp();
|
||||
-- name: RevokeSession :exec
|
||||
DELETE FROM sessions WHERE token_hash=$1;
|
||||
@@ -0,0 +1,12 @@
|
||||
-- name: ReserveKey :one
|
||||
INSERT INTO idempotency(user_id,chat_id,key,payload_hash,message_id,expires_at)
|
||||
VALUES($1,$2,$3,$4,$5,clock_timestamp()+interval '24 hours')
|
||||
ON CONFLICT(user_id,chat_id,key) DO UPDATE SET payload_hash=excluded.payload_hash,
|
||||
message_id=excluded.message_id,expires_at=excluded.expires_at
|
||||
WHERE idempotency.expires_at<=clock_timestamp()
|
||||
RETURNING message_id;
|
||||
-- name: ReplayMessage :one
|
||||
SELECT m.id,m.chat_id,m.sender_id,m.text,m.created_at,i.payload_hash,
|
||||
ARRAY(SELECT attachment_id FROM message_attachments WHERE message_id=m.id ORDER BY ordinal LIMIT 10)::uuid[] AS attachment_ids
|
||||
FROM idempotency i JOIN messages m ON m.id=i.message_id
|
||||
WHERE i.user_id=$1 AND i.chat_id=$2 AND i.key=$3;
|
||||
@@ -0,0 +1,5 @@
|
||||
-- name: PipelineMetrics :one
|
||||
SELECT count(*)::bigint AS depth,
|
||||
COALESCE(EXTRACT(EPOCH FROM clock_timestamp()-min(j.created_at)),0)::float8 AS oldest
|
||||
FROM attachments a JOIN attachment_jobs j ON j.attachment_id=a.id AND j.pipeline_version=a.pipeline_version
|
||||
WHERE a.status IN ('queued','processing') AND NOT j.completed;
|
||||
@@ -0,0 +1,50 @@
|
||||
-- name: InsertJob :exec
|
||||
INSERT INTO attachment_jobs(id,attachment_id,pipeline_version,traceparent,tracestate)
|
||||
VALUES(sqlc.arg(job_id),sqlc.arg(attachment_id),sqlc.arg(pipeline_version),sqlc.arg(traceparent),sqlc.arg(tracestate));
|
||||
-- name: QueueAttachment :one
|
||||
UPDATE attachments SET accepted_at=COALESCE(accepted_at,clock_timestamp()),status='queued',updated_at=clock_timestamp() WHERE id=$1 AND status='uploading' AND NOT staging_expired RETURNING *;
|
||||
-- name: PendingJobs :many
|
||||
SELECT j.* FROM attachment_jobs j JOIN attachments a ON a.id=j.attachment_id AND a.pipeline_version=j.pipeline_version
|
||||
WHERE NOT j.completed AND a.status IN ('queued','processing') AND j.next_attempt<=clock_timestamp()
|
||||
AND j.lease_until<clock_timestamp() AND j.published_at<clock_timestamp()-interval '2 seconds'
|
||||
ORDER BY j.created_at,j.id LIMIT 100;
|
||||
-- name: Published :exec
|
||||
UPDATE attachment_jobs SET published_at=clock_timestamp() WHERE id=$1;
|
||||
-- name: AcquireJob :one
|
||||
UPDATE attachment_jobs j SET attempt=j.attempt+1,lease_id=sqlc.arg(lease_id),lease_until=clock_timestamp()+sqlc.arg(lease_seconds)::int*interval '1 second'
|
||||
WHERE j.id=sqlc.arg(job_id) AND j.pipeline_version=sqlc.arg(pipeline_version) AND NOT j.completed
|
||||
AND j.next_attempt<=clock_timestamp() AND j.lease_until<clock_timestamp()
|
||||
AND EXISTS(SELECT 1 FROM attachments a WHERE a.id=j.attachment_id AND a.pipeline_version=j.pipeline_version AND a.status IN ('queued','processing'))
|
||||
RETURNING j.*;
|
||||
-- name: ProcessingAttachment :one
|
||||
UPDATE attachments SET status='processing',updated_at=clock_timestamp()
|
||||
WHERE id=sqlc.arg(attachment_id) AND pipeline_version=sqlc.arg(pipeline_version) AND status IN ('queued','processing') RETURNING *;
|
||||
-- name: CompleteAttachment :execrows
|
||||
UPDATE attachments a SET first_ready_at=COALESCE(a.first_ready_at,clock_timestamp()),status='ready',variants=sqlc.arg(variants)::jsonb,error_code='',updated_at=clock_timestamp()
|
||||
FROM attachment_jobs j WHERE j.id=sqlc.arg(job_id) AND j.attachment_id=a.id AND j.pipeline_version=a.pipeline_version
|
||||
AND j.lease_id=sqlc.arg(lease_id) AND j.lease_until>clock_timestamp() AND NOT j.completed AND a.status='processing';
|
||||
-- name: CompleteJob :exec
|
||||
UPDATE attachment_jobs SET completed=true,lease_until='epoch' WHERE id=sqlc.arg(job_id) AND lease_id=sqlc.arg(lease_id);
|
||||
-- name: RetryAttachment :execrows
|
||||
UPDATE attachments a SET status=sqlc.arg(next_status),error_code=sqlc.arg(error_code),updated_at=clock_timestamp()
|
||||
FROM attachment_jobs j WHERE j.id=sqlc.arg(job_id) AND j.attachment_id=a.id AND j.pipeline_version=a.pipeline_version
|
||||
AND j.lease_id=sqlc.arg(lease_id) AND j.lease_until>clock_timestamp() AND NOT j.completed AND a.status='processing';
|
||||
-- name: RetryJob :exec
|
||||
UPDATE attachment_jobs SET lease_until='epoch',next_attempt=clock_timestamp()+sqlc.arg(delay_ms)::int*interval '1 millisecond',completed=sqlc.arg(completed)
|
||||
WHERE id=sqlc.arg(job_id) AND lease_id=sqlc.arg(lease_id);
|
||||
-- name: ReplayAttachment :one
|
||||
UPDATE attachments SET status='queued',error_code='',updated_at=clock_timestamp() WHERE id=$1 AND status='failed' AND NOT staging_expired RETURNING *;
|
||||
-- name: ReplayJobs :exec
|
||||
UPDATE attachment_jobs SET replay_count=replay_count+1,replayed_at=clock_timestamp(),completed=false,attempt=0,lease_until='epoch',next_attempt='epoch',published_at='epoch' WHERE attachment_id=$1 AND pipeline_version=$2;
|
||||
-- name: AdvancePipeline :one
|
||||
UPDATE attachments SET status='queued',error_code='',variants='[]',pipeline_version=pipeline_version+1,staging_expired=false,updated_at=clock_timestamp() WHERE id=$1 AND (status='ready' OR (status='failed' AND NOT staging_expired)) RETURNING *;
|
||||
-- name: StagingCleanup :many
|
||||
WITH candidates AS (
|
||||
SELECT id FROM attachments WHERE NOT staging_cleaned AND (status='ready' OR (status IN ('failed','uploading') AND updated_at<clock_timestamp()-interval '24 hours'))
|
||||
ORDER BY updated_at,id LIMIT 20
|
||||
)
|
||||
UPDATE attachments a SET staging_expired=(a.status<>'ready') FROM candidates c WHERE a.id=c.id AND NOT a.staging_cleaned
|
||||
AND (a.status='ready' OR (a.status IN ('failed','uploading') AND a.updated_at<clock_timestamp()-interval '24 hours')) RETURNING a.*;
|
||||
-- name: StagingCleaned :exec
|
||||
UPDATE attachments SET staging_cleaned=true WHERE id=$1 AND (staging_expired OR status='ready');
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
-- name: AllowLogin :one
|
||||
UPDATE login_limits SET attempts=CASE WHEN started_at<=clock_timestamp()-interval '60 seconds' THEN 1 ELSE attempts+1 END,
|
||||
started_at=CASE WHEN started_at<=clock_timestamp()-interval '60 seconds' THEN clock_timestamp() ELSE started_at END
|
||||
WHERE bucket=$1 AND (started_at<=clock_timestamp()-interval '60 seconds' OR attempts<10) RETURNING bucket;
|
||||
-- name: RehashPassword :one
|
||||
UPDATE users SET password_hash=sqlc.arg(replacement) WHERE id=sqlc.arg(user_id) AND password_hash=sqlc.arg(previous) RETURNING id;
|
||||
@@ -0,0 +1,11 @@
|
||||
-- name: ReadySLI :one
|
||||
WITH clock AS (SELECT clock_timestamp() AS now), cohort AS (
|
||||
SELECT a.accepted_at,a.first_ready_at,c.now FROM attachments a CROSS JOIN clock c
|
||||
WHERE a.accepted_at>c.now-interval '310 seconds' AND a.accepted_at<=c.now-interval '10 seconds'
|
||||
)
|
||||
SELECT count(*) FILTER(WHERE accepted_at>now-interval '20 seconds')::bigint AS matured10,
|
||||
count(*) FILTER(WHERE accepted_at>now-interval '20 seconds' AND first_ready_at>=accepted_at AND first_ready_at<=accepted_at+interval '10 seconds')::bigint AS timely10,
|
||||
count(*) FILTER(WHERE accepted_at>now-interval '40 seconds')::bigint AS matured30,
|
||||
count(*) FILTER(WHERE accepted_at>now-interval '40 seconds' AND first_ready_at>=accepted_at AND first_ready_at<=accepted_at+interval '10 seconds')::bigint AS timely30,
|
||||
count(*)::bigint AS matured300,
|
||||
count(*) FILTER(WHERE first_ready_at>=accepted_at AND first_ready_at<=accepted_at+interval '10 seconds')::bigint AS timely300 FROM cohort;
|
||||
@@ -0,0 +1,16 @@
|
||||
version: '2'
|
||||
sql:
|
||||
- schema: ../migrations
|
||||
queries: queries
|
||||
engine: postgresql
|
||||
gen:
|
||||
go:
|
||||
package: queries
|
||||
out: ../../internal/adapter/repository/postgres/queries
|
||||
sql_package: pgx/v5
|
||||
emit_empty_slices: true
|
||||
overrides:
|
||||
- db_type: uuid
|
||||
go_type: github.com/google/uuid.UUID
|
||||
- db_type: timestamptz
|
||||
go_type: time.Time
|
||||
@@ -0,0 +1,15 @@
|
||||
overlay: 1.0.0
|
||||
info:
|
||||
title: Go DTO generation view; normative contract remains unchanged
|
||||
version: 1.0.0
|
||||
actions:
|
||||
# oapi-codegen 2.8 emits duplicate Body fields for two binary MIME types.
|
||||
# The adapter reads the original bounded request stream and validates both types.
|
||||
- target: $.paths['/api/v1/chats/{chat_id}/attachments'].post.requestBody.content['image/jpeg']
|
||||
remove: true
|
||||
# anyOf expresses runtime requirements, not different Go representations.
|
||||
# The domain enforces text-or-attachments; the adapter keeps strict JSON decoding.
|
||||
- target: $.components.schemas.CreateMessage.anyOf
|
||||
remove: true
|
||||
- target: $.components.schemas.Message.anyOf
|
||||
remove: true
|
||||
+347
@@ -0,0 +1,347 @@
|
||||
module backend
|
||||
|
||||
go 1.27.2
|
||||
|
||||
tool (
|
||||
github.com/golangci/golangci-lint/v2/cmd/golangci-lint
|
||||
github.com/oapi-codegen/oapi-codegen/v2/cmd/oapi-codegen
|
||||
github.com/pressly/goose/v3/cmd/goose
|
||||
github.com/sqlc-dev/sqlc/cmd/sqlc
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/go-chi/chi/v5 v5.5.0
|
||||
github.com/google/uuid v1.6.0
|
||||
github.com/oapi-codegen/runtime v1.7.0
|
||||
github.com/rs/zerolog v1.35.1
|
||||
github.com/spf13/viper v1.21.0
|
||||
)
|
||||
|
||||
require (
|
||||
4d63.com/gocheckcompilerdirectives v1.4.0 // indirect
|
||||
4d63.com/gochecknoglobals v0.2.2 // indirect
|
||||
cel.dev/expr v0.25.3 // indirect
|
||||
charm.land/lipgloss/v2 v2.0.6 // indirect
|
||||
codeberg.org/chavacava/garif v0.2.1 // indirect
|
||||
codeberg.org/polyfloyd/go-errorlint v1.9.0 // indirect
|
||||
dev.gaijin.team/go/exhaustruct/v4 v4.0.0 // indirect
|
||||
dev.gaijin.team/go/exhaustruct/v5 v5.2.0 // indirect
|
||||
dev.gaijin.team/go/golib v0.8.1 // indirect
|
||||
filippo.io/edwards25519 v1.2.0 // indirect
|
||||
github.com/4meepo/tagalign v1.4.4 // indirect
|
||||
github.com/Abirdcfly/dupword v0.1.8 // indirect
|
||||
github.com/AdminBenni/iota-mixing v1.0.0 // indirect
|
||||
github.com/AlwxSin/noinlineerr v1.0.6 // indirect
|
||||
github.com/Antonboom/errname v1.1.2 // indirect
|
||||
github.com/Antonboom/nilnil v1.1.2 // indirect
|
||||
github.com/Antonboom/testifylint v1.6.4 // indirect
|
||||
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.24.0 // indirect
|
||||
github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.15.0 // indirect
|
||||
github.com/Azure/azure-sdk-for-go/sdk/internal v1.13.0 // indirect
|
||||
github.com/AzureAD/microsoft-authentication-library-for-go v1.10.1 // indirect
|
||||
github.com/BurntSushi/toml v1.6.0 // indirect
|
||||
github.com/ClickHouse/ch-go v0.75.0 // indirect
|
||||
github.com/ClickHouse/clickhouse-go-linter v1.2.1 // indirect
|
||||
github.com/ClickHouse/clickhouse-go/v2 v2.51.0 // indirect
|
||||
github.com/Djarvur/go-err113 v0.1.1 // indirect
|
||||
github.com/Masterminds/semver/v3 v3.5.0 // indirect
|
||||
github.com/MirrexOne/unqueryvet v1.5.4 // indirect
|
||||
github.com/OpenPeeDeeP/depguard/v2 v2.2.1 // indirect
|
||||
github.com/alecthomas/chroma/v2 v2.27.0 // indirect
|
||||
github.com/alecthomas/go-check-sumtype v0.5.1-0.20260828200218-ae6904d28606 // indirect
|
||||
github.com/alexkohler/nakedret/v2 v2.0.6 // indirect
|
||||
github.com/alexkohler/prealloc v1.1.0 // indirect
|
||||
github.com/alfatraining/structtag v1.0.0 // indirect
|
||||
github.com/alingse/asasalint v0.0.11 // indirect
|
||||
github.com/alingse/nilnesserr v0.2.0 // indirect
|
||||
github.com/andybalholm/brotli v1.3.0 // indirect
|
||||
github.com/antlr4-go/antlr/v4 v4.13.1 // indirect
|
||||
github.com/apapsch/go-jsonmerge/v2 v2.0.0 // indirect
|
||||
github.com/ashanbrown/forbidigo/v2 v2.3.1 // indirect
|
||||
github.com/ashanbrown/makezero/v2 v2.2.1 // indirect
|
||||
github.com/beorn7/perks v1.0.1 // indirect
|
||||
github.com/bkielbasa/cyclop v1.2.3 // indirect
|
||||
github.com/blizzy78/varnamelen v0.8.0 // indirect
|
||||
github.com/bombsimon/wsl/v4 v4.7.0 // indirect
|
||||
github.com/bombsimon/wsl/v5 v5.9.0 // indirect
|
||||
github.com/breml/bidichk v0.3.3 // indirect
|
||||
github.com/breml/errchkjson v0.4.1 // indirect
|
||||
github.com/butuzov/ireturn v0.4.1 // indirect
|
||||
github.com/butuzov/mirror v1.3.3 // indirect
|
||||
github.com/catenacyber/perfsprint v0.10.1 // indirect
|
||||
github.com/ccojocar/zxcvbn-go v1.0.4 // indirect
|
||||
github.com/cenkalti/backoff/v5 v5.0.3 // indirect
|
||||
github.com/cespare/xxhash/v2 v2.3.0 // indirect
|
||||
github.com/charithe/durationcheck v0.0.11 // indirect
|
||||
github.com/charmbracelet/colorprofile v0.4.3 // indirect
|
||||
github.com/charmbracelet/ultraviolet v0.0.0-20260811164956-006e29f97886 // indirect
|
||||
github.com/charmbracelet/x/ansi v0.11.8 // indirect
|
||||
github.com/charmbracelet/x/term v0.2.2 // indirect
|
||||
github.com/charmbracelet/x/termios v0.1.1 // indirect
|
||||
github.com/charmbracelet/x/windows v0.2.2 // indirect
|
||||
github.com/ckaznocha/intrange v0.3.1 // indirect
|
||||
github.com/clipperhouse/displaywidth v0.11.0 // indirect
|
||||
github.com/clipperhouse/uax29/v2 v2.7.0 // indirect
|
||||
github.com/coder/websocket v1.8.15 // indirect
|
||||
github.com/coreos/go-semver v0.3.1 // indirect
|
||||
github.com/cubicdaiya/gonp v1.0.4 // indirect
|
||||
github.com/curioswitch/go-reassign v0.3.0 // indirect
|
||||
github.com/daixiang0/gci v0.13.7 // indirect
|
||||
github.com/dave/dst v0.27.3 // indirect
|
||||
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
|
||||
github.com/denis-tingaikin/go-header v0.5.0 // indirect
|
||||
github.com/dlclark/regexp2/v2 v2.2.1 // indirect
|
||||
github.com/dprotaso/go-yit v0.0.0-20220510233725-9ba8df137936 // indirect
|
||||
github.com/dustin/go-humanize v1.1.0 // indirect
|
||||
github.com/elastic/go-sysinfo v1.15.5 // indirect
|
||||
github.com/elastic/go-windows v1.0.2 // indirect
|
||||
github.com/ettle/strcase v0.2.0 // indirect
|
||||
github.com/fatih/color v1.19.0 // indirect
|
||||
github.com/fatih/structtag v1.2.0 // indirect
|
||||
github.com/firefart/nonamedreturns v1.0.8 // indirect
|
||||
github.com/fsnotify/fsnotify v1.9.0 // indirect
|
||||
github.com/fzipp/gocyclo v0.6.0 // indirect
|
||||
github.com/getkin/kin-openapi v0.153.0 // indirect
|
||||
github.com/ghostiam/protogetter v1.0.1 // indirect
|
||||
github.com/go-critic/go-critic v0.15.0 // indirect
|
||||
github.com/go-faster/city v1.0.1 // indirect
|
||||
github.com/go-faster/errors v0.8.0 // indirect
|
||||
github.com/go-logr/logr v1.4.4 // indirect
|
||||
github.com/go-logr/stdr v1.2.2 // indirect
|
||||
github.com/go-openapi/jsonpointer v1.0.0 // indirect
|
||||
github.com/go-openapi/swag/jsonname v0.26.0 // indirect
|
||||
github.com/go-sql-driver/mysql v1.10.1 // indirect
|
||||
github.com/go-toolsmith/astcast v1.1.0 // indirect
|
||||
github.com/go-toolsmith/astcopy v1.1.0 // indirect
|
||||
github.com/go-toolsmith/astequal v1.2.0 // indirect
|
||||
github.com/go-toolsmith/astfmt v1.1.0 // indirect
|
||||
github.com/go-toolsmith/astp v1.1.0 // indirect
|
||||
github.com/go-toolsmith/strparse v1.1.0 // indirect
|
||||
github.com/go-toolsmith/typep v1.1.0 // indirect
|
||||
github.com/go-viper/mapstructure/v2 v2.5.0 // indirect
|
||||
github.com/go-xmlfmt/xmlfmt v1.1.3 // indirect
|
||||
github.com/gobwas/glob v0.2.3 // indirect
|
||||
github.com/godoc-lint/godoc-lint v0.11.4 // indirect
|
||||
github.com/gofrs/flock v0.13.1 // indirect
|
||||
github.com/golang-jwt/jwt/v4 v4.5.2 // indirect
|
||||
github.com/golang-jwt/jwt/v5 v5.3.1 // indirect
|
||||
github.com/golang-sql/civil v0.0.0-20220223132316-b832511892a9 // indirect
|
||||
github.com/golang-sql/sqlexp v0.1.0 // indirect
|
||||
github.com/golang/protobuf v1.5.4 // indirect
|
||||
github.com/golangci/asciicheck v0.5.0 // indirect
|
||||
github.com/golangci/canonicalheader v0.0.0-20260827115959-a25c71c521f6 // indirect
|
||||
github.com/golangci/dupl v0.0.0-20260401084720-c99c5cf5c202 // indirect
|
||||
github.com/golangci/go-printf-func-name v0.1.1 // indirect
|
||||
github.com/golangci/gofmt v0.0.0-20260820135601-e84e05053792 // indirect
|
||||
github.com/golangci/golangci-lint/v2 v2.14.0 // indirect
|
||||
github.com/golangci/golines v0.15.0 // indirect
|
||||
github.com/golangci/misspell v0.8.0 // indirect
|
||||
github.com/golangci/plugin-module-register v0.1.2 // indirect
|
||||
github.com/golangci/revgrep v0.8.0 // indirect
|
||||
github.com/golangci/rowserrcheck v0.0.0-20260419091836-c5f79b8a11ba // indirect
|
||||
github.com/golangci/swaggoswag v0.0.0-20250504205917-77f2aca3143e // indirect
|
||||
github.com/golangci/unconvert v0.0.0-20250410112200-a129a6e6413e // indirect
|
||||
github.com/google/cel-go v0.28.0 // indirect
|
||||
github.com/google/go-cmp v0.7.0 // indirect
|
||||
github.com/gordonklaus/ineffassign v0.2.0 // indirect
|
||||
github.com/gostaticanalysis/analysisutil v0.7.1 // indirect
|
||||
github.com/gostaticanalysis/comment v1.5.0 // indirect
|
||||
github.com/gostaticanalysis/forcetypeassert v0.2.0 // indirect
|
||||
github.com/gostaticanalysis/nilerr v0.1.2 // indirect
|
||||
github.com/grpc-ecosystem/grpc-gateway/v2 v2.30.0 // indirect
|
||||
github.com/hashicorp/go-immutable-radix/v2 v2.1.0 // indirect
|
||||
github.com/hashicorp/go-version v1.9.0 // indirect
|
||||
github.com/hashicorp/golang-lru/v2 v2.0.7 // indirect
|
||||
github.com/hexops/gotextdiff v1.0.3 // indirect
|
||||
github.com/inconshreveable/mousetrap v1.1.0 // indirect
|
||||
github.com/jackc/pgpassfile v1.0.0 // indirect
|
||||
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect
|
||||
github.com/jackc/pgx/v5 v5.13.0 // indirect
|
||||
github.com/jackc/puddle/v2 v2.2.3 // indirect
|
||||
github.com/jgautheron/goconst v1.11.0 // indirect
|
||||
github.com/jinzhu/inflection v1.0.0 // indirect
|
||||
github.com/jjti/go-spancheck v0.6.5 // indirect
|
||||
github.com/joho/godotenv v1.5.1 // indirect
|
||||
github.com/jonboulle/clockwork v0.5.0 // indirect
|
||||
github.com/julz/importas v0.2.0 // indirect
|
||||
github.com/karamaru-alpha/copyloopvar v1.2.2 // indirect
|
||||
github.com/kisielk/errcheck v1.20.0 // indirect
|
||||
github.com/kkHAIKE/contextcheck v1.1.6 // indirect
|
||||
github.com/klauspost/compress v1.20.4 // indirect
|
||||
github.com/klauspost/cpuid/v2 v2.4.0 // indirect
|
||||
github.com/klauspost/crc32 v1.3.0 // indirect
|
||||
github.com/kulti/thelper v0.7.1 // indirect
|
||||
github.com/kunwardeep/paralleltest v1.0.15 // indirect
|
||||
github.com/kylelemons/godebug v1.1.0 // indirect
|
||||
github.com/ldez/exptostd v0.4.5 // indirect
|
||||
github.com/ldez/gomoddirectives v0.10.0 // indirect
|
||||
github.com/ldez/grignotin v0.10.1 // indirect
|
||||
github.com/ldez/structtags v0.6.1 // indirect
|
||||
github.com/ldez/tagliatelle v0.8.0 // indirect
|
||||
github.com/ldez/usetesting v0.5.0 // indirect
|
||||
github.com/leonklingele/grouper v1.1.2 // indirect
|
||||
github.com/lucasb-eyer/go-colorful v1.4.1 // indirect
|
||||
github.com/macabu/inamedparam v0.2.0 // indirect
|
||||
github.com/manuelarte/embeddedstructfieldcheck v0.4.0 // indirect
|
||||
github.com/manuelarte/funcorder v0.6.0 // indirect
|
||||
github.com/maratori/testableexamples v1.0.1 // indirect
|
||||
github.com/maratori/testpackage v1.1.2 // indirect
|
||||
github.com/matoous/godox v1.1.0 // indirect
|
||||
github.com/mattn/go-colorable v0.1.15 // indirect
|
||||
github.com/mattn/go-isatty v0.0.24 // indirect
|
||||
github.com/mattn/go-runewidth v0.0.24 // indirect
|
||||
github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect
|
||||
github.com/mfridman/interpolate v0.0.2 // indirect
|
||||
github.com/mfridman/xflag v0.1.0 // indirect
|
||||
github.com/mgechev/revive v1.17.0 // indirect
|
||||
github.com/microsoft/go-mssqldb v1.11.2 // indirect
|
||||
github.com/minio/crc64nvme v1.1.1 // indirect
|
||||
github.com/minio/md5-simd v1.1.2 // indirect
|
||||
github.com/minio/minio-go/v7 v7.4.1 // indirect
|
||||
github.com/mitchellh/go-homedir v1.1.0 // indirect
|
||||
github.com/moricho/tparallel v0.3.2 // indirect
|
||||
github.com/muesli/cancelreader v0.2.2 // indirect
|
||||
github.com/nakabonne/nestif v0.3.1 // indirect
|
||||
github.com/ncruces/go-sqlite3 v0.32.0 // indirect
|
||||
github.com/ncruces/go-strftime v1.1.0 // indirect
|
||||
github.com/ncruces/julianday v1.0.0 // indirect
|
||||
github.com/nishanths/exhaustive v0.13.0 // indirect
|
||||
github.com/nishanths/predeclared v0.2.2 // indirect
|
||||
github.com/nunnatsa/ginkgolinter v0.24.0 // indirect
|
||||
github.com/oapi-codegen/oapi-codegen/v2 v2.8.0 // indirect
|
||||
github.com/oasdiff/yaml v0.1.1 // indirect
|
||||
github.com/oasdiff/yaml3 v0.0.14 // indirect
|
||||
github.com/paulmach/orb v0.14.0 // indirect
|
||||
github.com/pelletier/go-toml/v2 v2.4.3 // indirect
|
||||
github.com/pganalyze/pg_query_go/v6 v6.2.2 // indirect
|
||||
github.com/philhofer/fwd v1.2.0 // indirect
|
||||
github.com/pierrec/lz4/v4 v4.1.33 // indirect
|
||||
github.com/pingcap/errors v0.11.5-0.20250523034308-74f78ae071ee // indirect
|
||||
github.com/pingcap/failpoint v0.0.0-20240528011301-b51a646c7c86 // indirect
|
||||
github.com/pingcap/log v1.1.0 // indirect
|
||||
github.com/pingcap/tidb/pkg/parser v0.0.0-20260418072757-ce92298d1124 // indirect
|
||||
github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c // indirect
|
||||
github.com/pressly/goose/v3 v3.30.0 // indirect
|
||||
github.com/prometheus/client_golang v1.12.1 // indirect
|
||||
github.com/prometheus/client_model v0.2.0 // indirect
|
||||
github.com/prometheus/common v0.32.1 // indirect
|
||||
github.com/prometheus/procfs v0.23.0 // indirect
|
||||
github.com/quasilyte/go-ruleguard v0.4.5 // indirect
|
||||
github.com/quasilyte/go-ruleguard/dsl v0.3.23 // indirect
|
||||
github.com/quasilyte/gogrep v0.5.0 // indirect
|
||||
github.com/quasilyte/regex/syntax v0.0.0-20210819130434-b3f0c404a727 // indirect
|
||||
github.com/quasilyte/stdinfo v0.0.0-20220114132959-f7386bf02567 // indirect
|
||||
github.com/raeperd/recvcheck v0.3.1 // indirect
|
||||
github.com/redis/go-redis/v9 v9.23.0 // indirect
|
||||
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect
|
||||
github.com/rivo/uniseg v0.4.7 // indirect
|
||||
github.com/riza-io/grpc-go v0.2.0 // indirect
|
||||
github.com/rogpeppe/go-internal v1.16.0 // indirect
|
||||
github.com/rs/xid v1.6.0 // indirect
|
||||
github.com/ryancurrah/gomodguard v1.4.1 // indirect
|
||||
github.com/ryancurrah/gomodguard/v2 v2.1.3 // indirect
|
||||
github.com/ryanrolds/sqlclosecheck v0.6.0 // indirect
|
||||
github.com/sagikazarmark/locafero v0.11.0 // indirect
|
||||
github.com/sanposhiho/wastedassign/v2 v2.1.0 // indirect
|
||||
github.com/santhosh-tekuri/jsonschema/v6 v6.0.3 // indirect
|
||||
github.com/sashamelentyev/interfacebloat v1.1.0 // indirect
|
||||
github.com/sashamelentyev/usestdlibvars v1.29.0 // indirect
|
||||
github.com/securego/gosec/v2 v2.29.0 // indirect
|
||||
github.com/segmentio/asm v1.2.1 // indirect
|
||||
github.com/sethvargo/go-retry v0.5.0 // indirect
|
||||
github.com/shopspring/decimal v1.6.0 // indirect
|
||||
github.com/sirupsen/logrus v1.10.2 // indirect
|
||||
github.com/sivchari/containedctx v1.0.3 // indirect
|
||||
github.com/sonatard/noctx v0.5.1 // indirect
|
||||
github.com/sourcegraph/conc v0.3.1-0.20240121214520-5f936abd7ae8 // indirect
|
||||
github.com/sourcegraph/go-diff v0.9.0 // indirect
|
||||
github.com/speakeasy-api/jsonpath v0.6.3 // indirect
|
||||
github.com/speakeasy-api/openapi v1.24.0 // indirect
|
||||
github.com/spf13/afero v1.15.0 // indirect
|
||||
github.com/spf13/cast v1.10.0 // indirect
|
||||
github.com/spf13/cobra v1.10.2 // indirect
|
||||
github.com/spf13/pflag v1.0.10 // indirect
|
||||
github.com/sqlc-dev/doubleclick v1.0.0 // indirect
|
||||
github.com/sqlc-dev/sqlc v1.31.1 // indirect
|
||||
github.com/ssgreg/nlreturn/v2 v2.2.1 // indirect
|
||||
github.com/stbenjam/no-sprintf-host-port v0.3.1 // indirect
|
||||
github.com/stretchr/objx v0.5.3 // indirect
|
||||
github.com/stretchr/testify v1.12.1 // indirect
|
||||
github.com/subosito/gotenv v1.6.0 // indirect
|
||||
github.com/tetafro/godot v1.5.6 // indirect
|
||||
github.com/tetratelabs/wazero v1.11.0 // indirect
|
||||
github.com/timakin/bodyclose v0.0.0-20260723120731-857993a2939c // indirect
|
||||
github.com/timonwong/loggercheck v0.12.0 // indirect
|
||||
github.com/tinylib/msgp v1.6.4 // indirect
|
||||
github.com/tomarrell/wrapcheck/v2 v2.12.0 // indirect
|
||||
github.com/tommy-muehle/go-mnd/v2 v2.5.1 // indirect
|
||||
github.com/tursodatabase/libsql-client-go v0.0.0-20260528064733-9d5d30a29a60 // indirect
|
||||
github.com/ultraware/funlen v0.2.0 // indirect
|
||||
github.com/ultraware/whitespace v0.2.0 // indirect
|
||||
github.com/uudashr/gocognit v1.2.1 // indirect
|
||||
github.com/uudashr/iface v1.5.1 // indirect
|
||||
github.com/vertica/vertica-sql-go v1.3.9 // indirect
|
||||
github.com/vmware-labs/yaml-jsonpath v0.3.2 // indirect
|
||||
github.com/wasilibs/go-pgquery v0.0.0-20250409022910-10ac41983c07 // indirect
|
||||
github.com/wasilibs/wazero-helpers v0.0.0-20240620070341-3dff1577cd52 // indirect
|
||||
github.com/xen0n/gosmopolitan v1.3.0 // indirect
|
||||
github.com/xo/terminfo v1.0.0 // indirect
|
||||
github.com/yagipy/maintidx v1.0.0 // indirect
|
||||
github.com/yandex-cloud/go-genproto v0.137.0 // indirect
|
||||
github.com/ydb-platform/ydb-go-genproto v0.0.0-20260810123728-f0c151ab31b9 // indirect
|
||||
github.com/ydb-platform/ydb-go-sdk-auth-environ v0.5.3 // indirect
|
||||
github.com/ydb-platform/ydb-go-sdk/v3 v3.156.1 // indirect
|
||||
github.com/ydb-platform/ydb-go-yc v0.12.5 // indirect
|
||||
github.com/ydb-platform/ydb-go-yc-metadata v0.6.2 // indirect
|
||||
github.com/yeya24/promlinter v0.3.0 // indirect
|
||||
github.com/ykadowak/zerologlint v0.1.5 // indirect
|
||||
github.com/zeebo/xxh3 v1.1.0 // indirect
|
||||
github.com/ziutek/mymysql v1.5.4 // indirect
|
||||
gitlab.com/bosi/decorder v0.4.2 // indirect
|
||||
go-simpler.org/musttag v0.14.0 // indirect
|
||||
go-simpler.org/sloglint v0.12.0 // indirect
|
||||
go.augendre.info/arangolint v0.4.0 // indirect
|
||||
go.augendre.info/fatcontext v0.10.1 // indirect
|
||||
go.opentelemetry.io/auto/sdk v1.2.1 // indirect
|
||||
go.opentelemetry.io/otel v1.47.0 // indirect
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploghttp v0.23.0 // indirect
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp v1.47.0 // indirect
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.47.0 // indirect
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.47.0 // indirect
|
||||
go.opentelemetry.io/otel/log v1.47.0 // indirect
|
||||
go.opentelemetry.io/otel/metric v1.47.0 // indirect
|
||||
go.opentelemetry.io/otel/sdk v1.47.0 // indirect
|
||||
go.opentelemetry.io/otel/sdk/log v1.47.0 // indirect
|
||||
go.opentelemetry.io/otel/sdk/metric v1.47.0 // indirect
|
||||
go.opentelemetry.io/otel/trace v1.47.0 // indirect
|
||||
go.opentelemetry.io/proto/otlp v1.11.0 // indirect
|
||||
go.uber.org/atomic v1.12.0 // indirect
|
||||
go.uber.org/multierr v1.11.0 // indirect
|
||||
go.uber.org/zap v1.28.0 // indirect
|
||||
go.yaml.in/yaml/v3 v3.0.6 // indirect
|
||||
go.yaml.in/yaml/v4 v4.0.0 // indirect
|
||||
golang.org/x/crypto v0.59.0 // indirect
|
||||
golang.org/x/exp v0.0.0-20261109185158-a52e3aef5920 // indirect
|
||||
golang.org/x/exp/typeparams v0.0.0-20260811152304-ee035b5b010f // indirect
|
||||
golang.org/x/mod v0.42.0 // indirect
|
||||
golang.org/x/net v0.62.0 // indirect
|
||||
golang.org/x/sync v0.25.0 // indirect
|
||||
golang.org/x/sys v0.50.0 // indirect
|
||||
golang.org/x/text v0.44.0 // indirect
|
||||
golang.org/x/tools v0.52.1-0.20261106145633-d407941a339a // indirect
|
||||
google.golang.org/genproto/googleapis/api v0.0.0-20261110000943-09e21b237f2c // indirect
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20261110000943-09e21b237f2c // indirect
|
||||
google.golang.org/grpc v1.85.0 // indirect
|
||||
google.golang.org/protobuf v1.36.12 // indirect
|
||||
gopkg.in/ini.v1 v1.67.3 // indirect
|
||||
gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect
|
||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||
honnef.co/go/tools v0.8.1 // indirect
|
||||
howett.net/plist v1.0.1 // indirect
|
||||
modernc.org/libc v1.80.2 // indirect
|
||||
modernc.org/mathutil v1.7.1 // indirect
|
||||
modernc.org/memory v1.12.1 // indirect
|
||||
modernc.org/sqlite v1.62.0 // indirect
|
||||
mvdan.cc/gofumpt v0.12.0 // indirect
|
||||
mvdan.cc/unparam v0.0.0-20260823230713-2fa3d841b0c8 // indirect
|
||||
)
|
||||
+1340
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,67 @@
|
||||
package integration
|
||||
|
||||
import (
|
||||
"backend/internal/adapter/storage"
|
||||
"backend/internal/domain/port"
|
||||
"bytes"
|
||||
"context"
|
||||
"github.com/google/uuid"
|
||||
"os"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestS3InventoryAndStatReturnComparableVersionMetadata(t *testing.T) {
|
||||
if os.Getenv("RUN_ISOLATED_RECONCILIATION") != "1" {
|
||||
t.Skip("explicit isolated stand required")
|
||||
}
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 20*time.Second)
|
||||
defer cancel()
|
||||
cfg, e := storage.ReadConfig("/run/secrets/s3_credentials")
|
||||
if e != nil {
|
||||
t.Fatal("configuration unavailable")
|
||||
}
|
||||
s, e := storage.FromConfig(cfg)
|
||||
if e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
key := "originals/" + uuid.NewString()
|
||||
defer func() {
|
||||
if err := s.Remove(context.Background(), key); err != nil {
|
||||
t.Error("object fixture cleanup failed")
|
||||
}
|
||||
}()
|
||||
if e = s.Put(ctx, key, bytes.NewReader([]byte("synthetic-version-probe")), 23, "application/octet-stream"); e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
stat, e := s.Stat(ctx, key)
|
||||
if e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
var listed port.Object
|
||||
after := ""
|
||||
found := false
|
||||
for page := 0; page < 10; page++ {
|
||||
rows, more, e := s.List(ctx, after)
|
||||
if e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
for _, row := range rows {
|
||||
if row.Key == key {
|
||||
listed = row
|
||||
found = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if found || !more {
|
||||
break
|
||||
}
|
||||
after = rows[len(rows)-1].Key
|
||||
}
|
||||
if !found {
|
||||
t.Fatal("own object absent from bounded inventory")
|
||||
}
|
||||
if listed.ETag != stat.ETag || listed.Size != stat.Size || !listed.Modified.Equal(stat.Modified) {
|
||||
t.Fatalf("inconsistent version metadata: etag_equal=%t size_equal=%t list_time=%s stat_time=%s", listed.ETag == stat.ETag, listed.Size == stat.Size, listed.Modified.Format(time.RFC3339Nano), stat.Modified.Format(time.RFC3339Nano))
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
package freshness
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestFileReaderIsBoundedAndDoesNotRevealMissingPath(t *testing.T) {
|
||||
path := filepath.Join(t.TempDir(), "freshness")
|
||||
if err := os.WriteFile(path, []byte("oversized-sensitive-content"), 0600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
raw, err := FileReader(path)(context.Background(), 4)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if string(raw) != "over" {
|
||||
t.Fatalf("length=%d", len(raw))
|
||||
}
|
||||
_, err = FileReader(path+"missing")(context.Background(), MaxBytes+1)
|
||||
if !errors.Is(err, ErrUnreadable) {
|
||||
t.Fatalf("got %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFileReaderRejectsSymlink(t *testing.T) {
|
||||
target := filepath.Join(t.TempDir(), "target")
|
||||
if err := os.WriteFile(target, []byte("value"), 0600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
link := target + "-link"
|
||||
if err := os.Symlink(target, link); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := FileReader(link)(context.Background(), MaxBytes+1); !errors.Is(err, ErrUnreadable) {
|
||||
t.Fatalf("got %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFileReaderRejectsDirectory(t *testing.T) {
|
||||
if _, err := FileReader(t.TempDir())(context.Background(), MaxBytes+1); !errors.Is(err, ErrUnreadable) {
|
||||
t.Fatalf("got %v", err)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,135 @@
|
||||
// Package freshness bounds how long a process may use OpenBao-rendered credentials.
|
||||
package freshness
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"io"
|
||||
"os"
|
||||
"strings"
|
||||
"syscall"
|
||||
"time"
|
||||
)
|
||||
|
||||
const MaxBytes int64 = 128
|
||||
|
||||
var (
|
||||
ErrInvalid = errors.New("secret freshness timestamp invalid")
|
||||
ErrFuture = errors.New("secret freshness timestamp is in the future")
|
||||
ErrStale = errors.New("secret freshness expired")
|
||||
ErrUnreadable = errors.New("secret freshness unavailable")
|
||||
ErrConfiguration = errors.New("secret freshness configuration invalid")
|
||||
)
|
||||
|
||||
type Reader func(context.Context, int64) ([]byte, error)
|
||||
type Ticker struct {
|
||||
C <-chan time.Time
|
||||
Stop func()
|
||||
}
|
||||
type Ports struct {
|
||||
Read Reader
|
||||
Now func() time.Time
|
||||
NewTicker func(time.Duration) Ticker
|
||||
}
|
||||
type Watcher struct {
|
||||
ports Ports
|
||||
maxAge, interval time.Duration
|
||||
}
|
||||
|
||||
// New requires explicit ports so tests cannot accidentally read live credentials or control processes.
|
||||
func New(ports Ports, maxAge, interval time.Duration) (*Watcher, error) {
|
||||
if ports.Read == nil || ports.Now == nil || ports.NewTicker == nil || maxAge <= 0 || interval <= 0 || interval > 5*time.Second || interval > maxAge {
|
||||
return nil, ErrConfiguration
|
||||
}
|
||||
return &Watcher{ports: ports, maxAge: maxAge, interval: interval}, nil
|
||||
}
|
||||
func (w *Watcher) Check(ctx context.Context) error {
|
||||
if err := ctx.Err(); err != nil {
|
||||
return err
|
||||
}
|
||||
raw, err := w.ports.Read(ctx, MaxBytes+1)
|
||||
if contextErr := ctx.Err(); contextErr != nil {
|
||||
return contextErr
|
||||
}
|
||||
if err != nil {
|
||||
return ErrUnreadable
|
||||
}
|
||||
if len(raw) == 0 || int64(len(raw)) > MaxBytes {
|
||||
return ErrInvalid
|
||||
}
|
||||
issued, err := time.Parse(time.RFC3339Nano, strings.TrimSpace(string(raw)))
|
||||
if err != nil {
|
||||
return ErrInvalid
|
||||
}
|
||||
now := w.ports.Now()
|
||||
if issued.After(now) {
|
||||
return ErrFuture
|
||||
}
|
||||
if now.Sub(issued) > w.maxAge {
|
||||
return ErrStale
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Run validates startup before allocating its ticker and returns the first failure.
|
||||
// The composition root owns graceful shutdown; this package never exits or signals a process.
|
||||
func (w *Watcher) Run(ctx context.Context) error {
|
||||
if err := w.Check(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
ticker := w.ports.NewTicker(w.interval)
|
||||
if ticker.Stop == nil {
|
||||
return ErrConfiguration
|
||||
}
|
||||
defer ticker.Stop()
|
||||
if ticker.C == nil {
|
||||
return ErrConfiguration
|
||||
}
|
||||
for {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return ctx.Err()
|
||||
case _, ok := <-ticker.C:
|
||||
if !ok {
|
||||
return ErrConfiguration
|
||||
}
|
||||
if err := w.Check(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// FileReader opens only the named file, never reads more than the requested bound,
|
||||
// and deliberately hides path/system error detail from the runtime failure signal.
|
||||
func FileReader(path string) Reader {
|
||||
return func(ctx context.Context, limit int64) ([]byte, error) {
|
||||
if err := ctx.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if limit < 1 || limit > MaxBytes+1 {
|
||||
return nil, ErrConfiguration
|
||||
}
|
||||
file, err := os.OpenFile(path, os.O_RDONLY|syscall.O_NONBLOCK|syscall.O_NOFOLLOW, 0)
|
||||
if err != nil {
|
||||
return nil, ErrUnreadable
|
||||
}
|
||||
defer func() { _ = file.Close() }()
|
||||
info, err := file.Stat()
|
||||
if err != nil || !info.Mode().IsRegular() {
|
||||
return nil, ErrUnreadable
|
||||
}
|
||||
raw, err := io.ReadAll(io.LimitReader(file, limit))
|
||||
if err != nil {
|
||||
return nil, ErrUnreadable
|
||||
}
|
||||
if err = ctx.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return raw, nil
|
||||
}
|
||||
}
|
||||
func SystemTicker(interval time.Duration) Ticker {
|
||||
ticker := time.NewTicker(interval)
|
||||
return Ticker{C: ticker.C, Stop: ticker.Stop}
|
||||
}
|
||||
@@ -0,0 +1,147 @@
|
||||
package freshness
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func factory(t *testing.T, text string, clock *time.Time, readError error) (*Watcher, chan time.Time, *int) {
|
||||
t.Helper()
|
||||
ticks := make(chan time.Time, 1)
|
||||
stopped := new(int)
|
||||
watcher, err := New(Ports{Read: func(ctx context.Context, limit int64) ([]byte, error) {
|
||||
if limit != MaxBytes+1 {
|
||||
t.Errorf("requested read limit %d", limit)
|
||||
}
|
||||
return []byte(text), readError
|
||||
}, Now: func() time.Time { return *clock }, NewTicker: func(time.Duration) Ticker { return Ticker{C: ticks, Stop: func() { *stopped++ }} }}, 120*time.Second, 5*time.Second)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
return watcher, ticks, stopped
|
||||
}
|
||||
func TestCheckUsesFiniteNonfutureBoundedTimestamp(t *testing.T) {
|
||||
now := time.Date(2026, 11, 15, 12, 0, 0, 0, time.UTC)
|
||||
cases := []struct {
|
||||
name, text string
|
||||
want error
|
||||
}{{"now", now.Format(time.RFC3339Nano), nil}, {"boundary", now.Add(-120 * time.Second).Format(time.RFC3339Nano), nil}, {"stale", now.Add(-120*time.Second - time.Nanosecond).Format(time.RFC3339Nano), ErrStale}, {"future", now.Add(time.Nanosecond).Format(time.RFC3339Nano), ErrFuture}, {"empty", "", ErrInvalid}, {"malformed", "not-a-date", ErrInvalid}, {"oversized", strings.Repeat("x", 129), ErrInvalid}, {"extra_data", now.Format(time.RFC3339Nano) + " second", ErrInvalid}, {"trimmed", now.Format(time.RFC3339Nano) + "\n", nil}}
|
||||
for _, c := range cases {
|
||||
t.Run(c.name, func(t *testing.T) {
|
||||
watcher, _, _ := factory(t, c.text, &now, nil)
|
||||
if got := watcher.Check(context.Background()); !errors.Is(got, c.want) {
|
||||
t.Fatalf("got %v, want %v", got, c.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
func TestReadFailureDoesNotRevealReaderError(t *testing.T) {
|
||||
now := time.Date(2026, 11, 15, 12, 0, 0, 0, time.UTC)
|
||||
watcher, _, _ := factory(t, "", &now, errors.New("sensitive path"))
|
||||
err := watcher.Check(context.Background())
|
||||
if !errors.Is(err, ErrUnreadable) {
|
||||
t.Fatalf("got %v", err)
|
||||
}
|
||||
if strings.Contains(err.Error(), "sensitive") {
|
||||
t.Fatal("reader detail leaked")
|
||||
}
|
||||
}
|
||||
func TestRunReturnsOnLaterExpiryAndStopsTicker(t *testing.T) {
|
||||
now := time.Date(2026, 11, 15, 12, 0, 0, 0, time.UTC)
|
||||
clock := now
|
||||
ticks := make(chan time.Time, 1)
|
||||
stops := 0
|
||||
reads := 0
|
||||
watcher, err := New(Ports{Read: func(context.Context, int64) ([]byte, error) {
|
||||
reads++
|
||||
if reads == 2 {
|
||||
clock = now.Add(121 * time.Second)
|
||||
}
|
||||
return []byte(now.Format(time.RFC3339Nano)), nil
|
||||
}, Now: func() time.Time { return clock }, NewTicker: func(time.Duration) Ticker { ticks <- now; return Ticker{C: ticks, Stop: func() { stops++ }} }}, 120*time.Second, 5*time.Second)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err = watcher.Run(context.Background()); !errors.Is(err, ErrStale) {
|
||||
t.Fatalf("got %v", err)
|
||||
}
|
||||
if stops != 1 {
|
||||
t.Fatalf("stops=%d", stops)
|
||||
}
|
||||
}
|
||||
func TestRunReturnsOnLaterReadFailure(t *testing.T) {
|
||||
now := time.Date(2026, 11, 15, 12, 0, 0, 0, time.UTC)
|
||||
ticks := make(chan time.Time, 1)
|
||||
reads := 0
|
||||
watcher, err := New(Ports{Read: func(context.Context, int64) ([]byte, error) {
|
||||
reads++
|
||||
if reads == 2 {
|
||||
return nil, errors.New("reader failed")
|
||||
}
|
||||
return []byte(now.Format(time.RFC3339Nano)), nil
|
||||
}, Now: func() time.Time { return now }, NewTicker: func(time.Duration) Ticker { ticks <- now; return Ticker{C: ticks, Stop: func() {}} }}, 120*time.Second, 5*time.Second)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err = watcher.Run(context.Background()); !errors.Is(err, ErrUnreadable) {
|
||||
t.Fatalf("got %v", err)
|
||||
}
|
||||
}
|
||||
func TestCancellationDoesNotReadAndStopsTicker(t *testing.T) {
|
||||
now := time.Date(2026, 11, 15, 12, 0, 0, 0, time.UTC)
|
||||
watcher, _, stops := factory(t, now.Format(time.RFC3339Nano), &now, nil)
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
cancel()
|
||||
if err := watcher.Check(ctx); !errors.Is(err, context.Canceled) {
|
||||
t.Fatalf("got %v", err)
|
||||
}
|
||||
// Explicit fake ticker cancels only after startup Check; no goroutine or wall-clock wait.
|
||||
ctx, cancel = context.WithCancel(context.Background())
|
||||
watcher.ports.NewTicker = func(time.Duration) Ticker {
|
||||
cancel()
|
||||
return Ticker{C: make(chan time.Time), Stop: func() { *stops++ }}
|
||||
}
|
||||
if err := watcher.Run(ctx); !errors.Is(err, context.Canceled) {
|
||||
t.Fatalf("got %v", err)
|
||||
}
|
||||
if *stops != 1 {
|
||||
t.Fatal("ticker not stopped")
|
||||
}
|
||||
}
|
||||
func TestFactoryRejectsMissingPortsAndUnsafeTiming(t *testing.T) {
|
||||
valid := Ports{Read: func(context.Context, int64) ([]byte, error) { return nil, nil }, Now: time.Now, NewTicker: func(time.Duration) Ticker { return Ticker{C: make(chan time.Time), Stop: func() {}} }}
|
||||
cases := []struct {
|
||||
p Ports
|
||||
age, interval time.Duration
|
||||
}{{Ports{}, 120 * time.Second, time.Second}, {valid, 0, time.Second}, {valid, 120 * time.Second, 0}, {valid, 120 * time.Second, 6 * time.Second}, {valid, time.Second, 2 * time.Second}}
|
||||
for _, c := range cases {
|
||||
if _, err := New(c.p, c.age, c.interval); !errors.Is(err, ErrConfiguration) {
|
||||
t.Fatal("unsafe factory accepted")
|
||||
}
|
||||
}
|
||||
}
|
||||
func TestRunRejectsClosedTicker(t *testing.T) {
|
||||
now := time.Date(2026, 11, 15, 12, 0, 0, 0, time.UTC)
|
||||
watcher, _, _ := factory(t, now.Format(time.RFC3339Nano), &now, nil)
|
||||
closed := make(chan time.Time)
|
||||
close(closed)
|
||||
watcher.ports.NewTicker = func(time.Duration) Ticker { return Ticker{C: closed, Stop: func() {}} }
|
||||
if err := watcher.Run(context.Background()); !errors.Is(err, ErrConfiguration) {
|
||||
t.Fatalf("got %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRunStopsAllocatedTickerWhenChannelIsInvalid(t *testing.T) {
|
||||
now := time.Date(2026, 11, 15, 12, 0, 0, 0, time.UTC)
|
||||
watcher, _, stops := factory(t, now.Format(time.RFC3339Nano), &now, nil)
|
||||
watcher.ports.NewTicker = func(time.Duration) Ticker { return Ticker{C: nil, Stop: func() { *stops++ }} }
|
||||
if err := watcher.Run(context.Background()); !errors.Is(err, ErrConfiguration) {
|
||||
t.Fatalf("got %v", err)
|
||||
}
|
||||
if *stops != 1 {
|
||||
t.Fatalf("stops=%d, want1", *stops)
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,111 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/google/uuid"
|
||||
"net/http"
|
||||
|
||||
"backend/internal/domain/model"
|
||||
)
|
||||
|
||||
// Реализация StrictServerInterface: вызвать use-case и перевести результат в
|
||||
// API-модели. Ошибки уходят в writeError, он один решает про HTTP-статус.
|
||||
|
||||
func (h *API) Liveness(context.Context, LivenessRequestObject) (LivenessResponseObject, error) {
|
||||
return Liveness200JSONResponse{Body: Health{Status: Ok}}, nil
|
||||
}
|
||||
|
||||
// Readiness rejects draining instances and unavailable required dependencies.
|
||||
func (h *API) Readiness(ctx context.Context, _ ReadinessRequestObject) (ReadinessResponseObject, error) {
|
||||
if !h.ready.Load() {
|
||||
return nil, errDraining
|
||||
}
|
||||
if err := h.probe(ctx); err != nil {
|
||||
return nil, model.ErrUnavailable
|
||||
}
|
||||
return Readiness200JSONResponse{Body: Health{Status: Ok}}, nil
|
||||
}
|
||||
|
||||
func (h *API) RegisterUser(ctx context.Context, req RegisterUserRequestObject) (RegisterUserResponseObject, error) {
|
||||
if req.Body.Password == nil {
|
||||
return nil, &model.ValidationError{Message: "password is required"}
|
||||
}
|
||||
user, err := h.auth.Register(ctx, req.Body.Username, req.Body.DisplayName, *req.Body.Password)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return RegisterUser201JSONResponse{Body: toUser(user)}, nil
|
||||
}
|
||||
|
||||
func (h *API) CurrentUser(ctx context.Context, _ CurrentUserRequestObject) (CurrentUserResponseObject, error) {
|
||||
return CurrentUser200JSONResponse{Body: toUser(currentUser(ctx))}, nil
|
||||
}
|
||||
|
||||
func (h *API) CreateChat(ctx context.Context, req CreateChatRequestObject) (CreateChatResponseObject, error) {
|
||||
chat, err := h.app.CreateChat(ctx, currentUser(ctx).ID, req.Body.Title, req.Body.MemberIds)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return CreateChat201JSONResponse{Body: toChat(chat)}, nil
|
||||
}
|
||||
|
||||
func (h *API) ListChats(ctx context.Context, req ListChatsRequestObject) (ListChatsResponseObject, error) {
|
||||
page, err := h.app.ListChats(ctx, currentUser(ctx).ID, req.Params.Limit, req.Params.Cursor)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return ListChats200JSONResponse{Body: ChatPage{Items: mapAll(page.Items, toChat), NextCursor: page.NextCursor}}, nil
|
||||
}
|
||||
|
||||
func (h *API) GetChat(ctx context.Context, req GetChatRequestObject) (GetChatResponseObject, error) {
|
||||
chat, err := h.app.GetChat(ctx, currentUser(ctx).ID, req.ChatId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return GetChat200JSONResponse{Body: toChat(chat)}, nil
|
||||
}
|
||||
|
||||
func (h *API) CreateMessage(ctx context.Context, req CreateMessageRequestObject) (CreateMessageResponseObject, error) {
|
||||
r := ctx.Value(sessionRequestKey{}).(*http.Request)
|
||||
ids := []uuid.UUID{}
|
||||
if req.Body.AttachmentIds != nil {
|
||||
ids = *req.Body.AttachmentIds
|
||||
}
|
||||
msg, err := h.app.SendMessage(ctx, currentUser(ctx).ID, req.ChatId, req.Body.Text, r.Header.Get("Idempotency-Key"), ids)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return CreateMessage201JSONResponse{Body: toMessage(msg)}, nil
|
||||
}
|
||||
|
||||
func (h *API) ListMessages(ctx context.Context, req ListMessagesRequestObject) (ListMessagesResponseObject, error) {
|
||||
page, err := h.app.ListMessages(ctx, currentUser(ctx).ID, req.ChatId, req.Params.Limit, req.Params.Cursor)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return ListMessages200JSONResponse{Body: MessagePage{Items: mapAll(page.Items, toMessage), NextCursor: page.NextCursor}}, nil
|
||||
}
|
||||
|
||||
func toUser(u model.User) User {
|
||||
return User{Id: u.ID, Username: u.Username, DisplayName: u.DisplayName, CreatedAt: Timestamp(u.CreatedAt)}
|
||||
}
|
||||
|
||||
func toChat(c model.Chat) Chat {
|
||||
return Chat{Id: c.ID, Title: c.Title, MemberIds: c.MemberIDs, CreatedAt: Timestamp(c.CreatedAt)}
|
||||
}
|
||||
|
||||
func toMessage(m model.Message) Message {
|
||||
ids := m.AttachmentIDs
|
||||
if ids == nil {
|
||||
ids = []uuid.UUID{}
|
||||
}
|
||||
return Message{Id: m.ID, ChatId: m.ChatID, SenderId: m.SenderID, Text: m.Text, CreatedAt: Timestamp(m.CreatedAt), AttachmentIds: ids}
|
||||
}
|
||||
|
||||
func mapAll[T, R any](items []T, f func(T) R) []R {
|
||||
out := make([]R, len(items))
|
||||
for i, item := range items {
|
||||
out[i] = f(item)
|
||||
}
|
||||
return out
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"backend/internal/adapter/imagefile"
|
||||
"backend/internal/domain/model"
|
||||
"context"
|
||||
"errors"
|
||||
"io"
|
||||
"net/http"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
func toAttachment(a model.Attachment) Attachment {
|
||||
variants := make([]Variant, 0, len(a.Variants))
|
||||
for _, v := range a.Variants {
|
||||
variants = append(variants, Variant{Name: VariantName(v.Name), ContentType: VariantContentType(v.ContentType), SizeBytes: int(v.SizeBytes), Sha256: v.SHA256, Width: v.Width, Height: v.Height})
|
||||
}
|
||||
var code *string
|
||||
if a.ErrorCode != "" {
|
||||
code = &a.ErrorCode
|
||||
}
|
||||
return Attachment{Id: a.ID, ChatId: a.ChatID, OwnerId: a.OwnerID, Filename: a.Filename, ContentType: AttachmentContentType(a.ContentType), SizeBytes: int(a.SizeBytes), Sha256: a.SHA256, Status: AttachmentStatus(a.Status), Variants: variants, ErrorCode: code, CreatedAt: Timestamp(a.CreatedAt), UpdatedAt: Timestamp(a.UpdatedAt)}
|
||||
}
|
||||
func (h *API) UploadAttachment(ctx context.Context, req UploadAttachmentRequestObject) (UploadAttachmentResponseObject, error) {
|
||||
caller := currentUser(ctx).ID
|
||||
if _, err := h.app.GetChat(ctx, caller, req.ChatId); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
select {
|
||||
case h.uploadGate <- struct{}{}:
|
||||
defer func() { <-h.uploadGate }()
|
||||
case <-ctx.Done():
|
||||
return nil, errOverloaded
|
||||
}
|
||||
r := ctx.Value(sessionRequestKey{}).(*http.Request)
|
||||
if r.ContentLength > model.MaxImageBytes {
|
||||
return nil, errPayloadTooLarge
|
||||
}
|
||||
f, err := imagefile.Inspect(r.Body, req.Params.Filename, r.Header.Get("Content-Type"))
|
||||
if errors.Is(err, imagefile.ErrTooLarge) {
|
||||
return nil, errPayloadTooLarge
|
||||
}
|
||||
if errors.Is(err, imagefile.ErrUnsupported) {
|
||||
return nil, errUnsupportedImage
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer f.Dispose()
|
||||
a, err := h.attachments.Upload(ctx, caller, req.ChatId, req.Params.Filename, f.ContentType, f.SHA256, f.Size, f.File)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return UploadAttachment202JSONResponse{Body: toAttachment(a)}, nil
|
||||
}
|
||||
func (h *API) GetAttachment(ctx context.Context, req GetAttachmentRequestObject) (GetAttachmentResponseObject, error) {
|
||||
a, e := h.attachments.Get(ctx, currentUser(ctx).ID, req.AttachmentId)
|
||||
if e != nil {
|
||||
return nil, e
|
||||
}
|
||||
return GetAttachment200JSONResponse{Body: toAttachment(a)}, nil
|
||||
}
|
||||
|
||||
// Closing in the response visitor keeps the S3 stream alive until serialization completes.
|
||||
type originalResponse struct {
|
||||
body io.ReadCloser
|
||||
size int64
|
||||
mime string
|
||||
}
|
||||
|
||||
func (r originalResponse) VisitDownloadAttachmentResponse(w http.ResponseWriter) error {
|
||||
defer r.body.Close()
|
||||
w.Header().Set("Content-Type", r.mime)
|
||||
w.Header().Set("Content-Length", strconv.FormatInt(r.size, 10))
|
||||
w.Header().Set("X-Content-Type-Options", "nosniff")
|
||||
w.WriteHeader(200)
|
||||
_, err := io.CopyN(w, r.body, r.size)
|
||||
if err != nil {
|
||||
panic(http.ErrAbortHandler)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
func (h *API) DownloadAttachment(ctx context.Context, req DownloadAttachmentRequestObject) (DownloadAttachmentResponseObject, error) {
|
||||
if _, e := h.attachments.Get(ctx, currentUser(ctx).ID, req.AttachmentId); e != nil {
|
||||
return nil, e
|
||||
}
|
||||
variant := "original"
|
||||
if req.Params.Variant != nil {
|
||||
variant = string(*req.Params.Variant)
|
||||
}
|
||||
a, r, e := h.attachments.Content(ctx, currentUser(ctx).ID, req.AttachmentId, variant)
|
||||
if e != nil {
|
||||
return nil, e
|
||||
}
|
||||
return originalResponse{r, a.SizeBytes, a.ContentType}, nil
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"backend/internal/domain/model"
|
||||
"context"
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
"unicode/utf8"
|
||||
)
|
||||
|
||||
type sessionRequestKey struct{}
|
||||
|
||||
func (h *API) CreateSession(ctx context.Context, _ CreateSessionRequestObject) (CreateSessionResponseObject, error) {
|
||||
r := ctx.Value(sessionRequestKey{}).(*http.Request)
|
||||
username, password, ok := r.BasicAuth()
|
||||
if !ok || len(username) > 32 || len(password) > 512 || utf8.RuneCountInString(password) > 128 {
|
||||
return nil, model.ErrUnauthorized
|
||||
}
|
||||
s, err := h.auth.Login(ctx, username, password)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return CreateSession201JSONResponse{Body: Session{Token: s.Token, TokenType: Bearer, ExpiresAt: Timestamp(s.ExpiresAt), User: toUser(s.User)}}, nil
|
||||
}
|
||||
func (h *API) RevokeSession(ctx context.Context, _ RevokeSessionRequestObject) (RevokeSessionResponseObject, error) {
|
||||
r := ctx.Value(sessionRequestKey{}).(*http.Request)
|
||||
parts := strings.Fields(r.Header.Get("Authorization"))
|
||||
if err := h.auth.Logout(ctx, parts[1]); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return RevokeSession204Response{}, nil
|
||||
}
|
||||
func (h *API) requestContext(next http.Handler) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
duration := 5 * time.Second
|
||||
if strings.HasSuffix(r.URL.Path, "/attachments") || strings.HasSuffix(r.URL.Path, "/content") {
|
||||
duration = 20 * time.Second
|
||||
}
|
||||
ctx, cancel := context.WithTimeout(r.Context(), duration)
|
||||
defer cancel()
|
||||
if r.URL.Path == "/api/v1/auth/sessions" {
|
||||
w.Header().Set("WWW-Authenticate", `Basic realm="messenger", charset="UTF-8"`)
|
||||
}
|
||||
next.ServeHTTP(w, r.WithContext(context.WithValue(ctx, sessionRequestKey{}, r)))
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"net/http"
|
||||
|
||||
"backend/internal/domain/model"
|
||||
)
|
||||
|
||||
var (
|
||||
errRouteNotFound = errors.New("route not found")
|
||||
errMethodNotAllowed = errors.New("method not allowed")
|
||||
errPayloadTooLarge = errors.New("payload too large")
|
||||
errOverloaded = errors.New("overloaded")
|
||||
errDraining = errors.New("draining")
|
||||
errUnsupportedImage = errors.New("unsupported image")
|
||||
)
|
||||
|
||||
type apiError struct {
|
||||
status int
|
||||
code ErrorErrorCode
|
||||
message string
|
||||
}
|
||||
|
||||
// classify — единственное место, где ошибка превращается в HTTP-статус.
|
||||
func classify(err error) apiError {
|
||||
var invalid *model.ValidationError
|
||||
switch {
|
||||
case errors.As(err, &invalid):
|
||||
return apiError{http.StatusBadRequest, InvalidRequest, invalid.Message}
|
||||
case errors.Is(err, model.ErrRateLimited):
|
||||
return apiError{http.StatusTooManyRequests, RateLimited, "слишком много попыток входа"}
|
||||
case errors.Is(err, model.ErrUnauthorized):
|
||||
return apiError{http.StatusUnauthorized, Unauthorized, "нужна действующая сессия"}
|
||||
case errors.Is(err, model.ErrNotFound), errors.Is(err, errRouteNotFound):
|
||||
return apiError{http.StatusNotFound, NotFound, "объект не найден"}
|
||||
case errors.Is(err, errMethodNotAllowed):
|
||||
return apiError{http.StatusMethodNotAllowed, InvalidRequest, "метод не поддерживается"}
|
||||
case errors.Is(err, model.ErrUsernameTaken):
|
||||
return apiError{http.StatusConflict, Conflict, "username уже занят"}
|
||||
case errors.Is(err, model.ErrConflict):
|
||||
return apiError{http.StatusConflict, Conflict, "конфликт запроса"}
|
||||
case errors.Is(err, model.ErrUnavailable):
|
||||
return apiError{http.StatusServiceUnavailable, Unavailable, "зависимость недоступна"}
|
||||
case errors.Is(err, errPayloadTooLarge):
|
||||
return apiError{http.StatusRequestEntityTooLarge, PayloadTooLarge, "тело запроса больше допустимого"}
|
||||
case errors.Is(err, errUnsupportedImage):
|
||||
return apiError{http.StatusUnsupportedMediaType, UnsupportedMediaType, "нужен корректный PNG или JPEG с верным Content-Type"}
|
||||
case errors.Is(err, model.ErrStorageFull):
|
||||
return apiError{http.StatusServiceUnavailable, Unavailable, "хранилище заполнено, запись невозможна; чтение работает"}
|
||||
case errors.Is(err, errOverloaded):
|
||||
return apiError{http.StatusServiceUnavailable, Unavailable, "сервер перегружен, повторите позже"}
|
||||
case errors.Is(err, errDraining):
|
||||
return apiError{http.StatusServiceUnavailable, Unavailable, "сервер останавливается"}
|
||||
default:
|
||||
return apiError{http.StatusInternalServerError, InternalError, "внутренняя ошибка"}
|
||||
}
|
||||
}
|
||||
|
||||
func (h *API) writeError(w http.ResponseWriter, r *http.Request, err error) {
|
||||
e := classify(err)
|
||||
if e.status == http.StatusInternalServerError {
|
||||
h.log.Error().Err(err).Str("request_id", requestIDFrom(r.Context())).Msg("unexpected error")
|
||||
}
|
||||
if errors.Is(err, model.ErrRateLimited) {
|
||||
w.Header().Set("Retry-After", "60")
|
||||
}
|
||||
if errors.Is(err, errOverloaded) {
|
||||
w.Header().Set("Retry-After", "1")
|
||||
}
|
||||
var body Error
|
||||
body.Error.Code = e.code
|
||||
body.Error.Message = e.message
|
||||
body.Error.RequestId = requestIDFrom(r.Context())
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
w.WriteHeader(e.status)
|
||||
_ = json.NewEncoder(w).Encode(body)
|
||||
}
|
||||
|
||||
// bodyError — JSON синтаксически верен (это проверил jsonBody), но не
|
||||
// подходит к схеме: лишнее поле или неверный тип.
|
||||
func (h *API) bodyError(w http.ResponseWriter, r *http.Request, _ error) {
|
||||
h.writeError(w, r, &model.ValidationError{Message: "тело запроса не соответствует схеме: лишнее поле или неверный тип"})
|
||||
}
|
||||
|
||||
// paramError — path или query параметр не разобрался (UUID, целое число).
|
||||
func (h *API) paramError(w http.ResponseWriter, r *http.Request, _ error) {
|
||||
h.writeError(w, r, &model.ValidationError{Message: "некорректный параметр запроса"})
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
)
|
||||
|
||||
// gate ограничивает одновременную обработку запросов API: не больше inflight
|
||||
// в работе и не больше queue в ожидании слота. Лишние сразу получают 503 с
|
||||
// Retry-After, ждавшие дольше timeout — тоже 503. Так перегрузка превращается
|
||||
// в быстрый предсказуемый отказ, а не в рост горутин, памяти и задержки.
|
||||
type gate struct {
|
||||
slots chan struct{} // nil — без лимита
|
||||
maxQueue int64
|
||||
timeout time.Duration
|
||||
waiting atomic.Int64
|
||||
rejected atomic.Int64
|
||||
}
|
||||
|
||||
func newGate(inflight, queue int, timeout time.Duration) *gate {
|
||||
g := &gate{maxQueue: int64(queue), timeout: timeout}
|
||||
if inflight > 0 {
|
||||
g.slots = make(chan struct{}, inflight)
|
||||
}
|
||||
return g
|
||||
}
|
||||
|
||||
func (g *gate) middleware(reject func(http.ResponseWriter, *http.Request, error)) func(http.Handler) http.Handler {
|
||||
return func(next http.Handler) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
if g.slots == nil {
|
||||
next.ServeHTTP(w, r)
|
||||
return
|
||||
}
|
||||
if !g.acquire(r) {
|
||||
g.rejected.Add(1)
|
||||
reject(w, r, errOverloaded)
|
||||
return
|
||||
}
|
||||
defer func() { <-g.slots }()
|
||||
next.ServeHTTP(w, r)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func (g *gate) acquire(r *http.Request) bool {
|
||||
select {
|
||||
case g.slots <- struct{}{}:
|
||||
return true
|
||||
default:
|
||||
}
|
||||
if g.waiting.Add(1) > g.maxQueue {
|
||||
g.waiting.Add(-1)
|
||||
return false
|
||||
}
|
||||
defer g.waiting.Add(-1)
|
||||
timer := time.NewTimer(g.timeout)
|
||||
defer timer.Stop()
|
||||
select {
|
||||
case g.slots <- struct{}{}:
|
||||
return true
|
||||
case <-timer.C:
|
||||
return false
|
||||
case <-r.Context().Done():
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
type gateStats struct {
|
||||
Inflight int `json:"inflight"`
|
||||
Waiting int64 `json:"waiting"`
|
||||
Rejected int64 `json:"rejected"`
|
||||
}
|
||||
|
||||
func (g *gate) stats() gateStats {
|
||||
return gateStats{Inflight: len(g.slots), Waiting: g.waiting.Load(), Rejected: g.rejected.Load()}
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"sync"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
// gatedServer пропускает запросы через gate в обработчик, который держит слот,
|
||||
// пока тест не закроет release.
|
||||
func gatedServer(t *testing.T, g *gate) (*httptest.Server, chan struct{}, chan struct{}) {
|
||||
t.Helper()
|
||||
entered, release := make(chan struct{}, 10), make(chan struct{})
|
||||
reject := func(w http.ResponseWriter, _ *http.Request, err error) {
|
||||
if !errors.Is(err, errOverloaded) {
|
||||
t.Errorf("unexpected error %v", err)
|
||||
}
|
||||
w.Header().Set("Retry-After", "1")
|
||||
w.WriteHeader(http.StatusServiceUnavailable)
|
||||
}
|
||||
h := g.middleware(reject)(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
|
||||
entered <- struct{}{}
|
||||
<-release
|
||||
w.WriteHeader(http.StatusOK)
|
||||
}))
|
||||
srv := httptest.NewServer(h)
|
||||
t.Cleanup(srv.Close)
|
||||
return srv, entered, release
|
||||
}
|
||||
|
||||
func get(t *testing.T, url string) int {
|
||||
t.Helper()
|
||||
resp, err := http.Get(url)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
return 0
|
||||
}
|
||||
resp.Body.Close()
|
||||
return resp.StatusCode
|
||||
}
|
||||
|
||||
func waitFor(t *testing.T, cond func() bool) {
|
||||
t.Helper()
|
||||
deadline := time.Now().Add(2 * time.Second)
|
||||
for !cond() {
|
||||
if time.Now().After(deadline) {
|
||||
t.Fatal("condition not reached")
|
||||
}
|
||||
time.Sleep(time.Millisecond)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGateRejectsBeyondQueueAndRecovers(t *testing.T) {
|
||||
t.Parallel()
|
||||
g := newGate(1, 1, time.Minute)
|
||||
srv, entered, release := gatedServer(t, g)
|
||||
|
||||
statuses := make(chan int, 2)
|
||||
var wg sync.WaitGroup
|
||||
wg.Go(func() { statuses <- get(t, srv.URL) }) // занимает слот
|
||||
<-entered
|
||||
wg.Go(func() { statuses <- get(t, srv.URL) }) // ждёт в очереди
|
||||
waitFor(t, func() bool { return g.waiting.Load() == 1 })
|
||||
|
||||
if code := get(t, srv.URL); code != http.StatusServiceUnavailable {
|
||||
t.Fatalf("third request: %d, want 503", code)
|
||||
}
|
||||
close(release)
|
||||
wg.Wait()
|
||||
close(statuses)
|
||||
for code := range statuses {
|
||||
if code != http.StatusOK {
|
||||
t.Fatalf("admitted request got %d", code)
|
||||
}
|
||||
}
|
||||
if code := get(t, srv.URL); code != http.StatusOK {
|
||||
t.Fatalf("after load: %d, want recovery to 200", code)
|
||||
}
|
||||
if g.stats().Rejected != 1 {
|
||||
t.Fatalf("rejected %d", g.stats().Rejected)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGateTimesOutQueuedRequest(t *testing.T) {
|
||||
t.Parallel()
|
||||
g := newGate(1, 10, 20*time.Millisecond)
|
||||
srv, entered, release := gatedServer(t, g)
|
||||
defer close(release)
|
||||
|
||||
go get(t, srv.URL)
|
||||
<-entered
|
||||
start := time.Now()
|
||||
if code := get(t, srv.URL); code != http.StatusServiceUnavailable {
|
||||
t.Fatalf("queued request: %d, want 503 after timeout", code)
|
||||
}
|
||||
if time.Since(start) > time.Second {
|
||||
t.Fatal("queue timeout not applied")
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
"backend/internal/adapter/telemetry"
|
||||
"backend/internal/application/usecase"
|
||||
|
||||
"github.com/go-chi/chi/v5"
|
||||
"github.com/rs/zerolog"
|
||||
)
|
||||
|
||||
// Limits — защитные лимиты HTTP-слоя (трек 5 «управляемая деградация»).
|
||||
// Нулевое значение отключает лимит.
|
||||
type Limits struct {
|
||||
MaxBodyBytes int64 // больше — 413
|
||||
MaxInflight int // одновременно обрабатываемые запросы API
|
||||
MaxQueue int // ждущие свободного слота; больше — сразу 503
|
||||
QueueTimeout time.Duration // дольше ждал слот — 503
|
||||
}
|
||||
|
||||
// API — driving HTTP-адаптер: реализует StrictServerInterface из api.gen.go.
|
||||
//
|
||||
//go:generate go tool oapi-codegen -config ../../../codegen.yaml ../../../../contracts/openapi.json
|
||||
type API struct {
|
||||
app *usecase.Messenger
|
||||
auth *usecase.Auth
|
||||
attachments *usecase.Attachments
|
||||
uploadGate chan struct{}
|
||||
probe func(context.Context) error
|
||||
limits Limits
|
||||
gate *gate
|
||||
storeStats func() any
|
||||
ready atomic.Bool
|
||||
log *zerolog.Logger
|
||||
}
|
||||
|
||||
// New собирает HTTP-адаптер. storeStats отдаёт состояние хранилища для
|
||||
// /debug/stats.
|
||||
func New(app *usecase.Messenger, auth *usecase.Auth, attachments *usecase.Attachments, probe func(context.Context) error, limits Limits, storeStats func() any, log *zerolog.Logger) *API {
|
||||
h := &API{
|
||||
app: app,
|
||||
auth: auth,
|
||||
attachments: attachments,
|
||||
uploadGate: make(chan struct{}, 1),
|
||||
probe: probe,
|
||||
limits: limits,
|
||||
gate: newGate(limits.MaxInflight, limits.MaxQueue, limits.QueueTimeout),
|
||||
storeStats: storeStats,
|
||||
log: log,
|
||||
}
|
||||
h.ready.Store(true)
|
||||
return h
|
||||
}
|
||||
|
||||
// Drain переводит /health/ready в 503 перед остановкой сервера.
|
||||
func (h *API) Drain() { h.ready.Store(false) }
|
||||
|
||||
func (h *API) Router() http.Handler {
|
||||
r := chi.NewRouter()
|
||||
r.Use(requestID, telemetry.HTTP, h.recoverer, h.accessLog, h.requestContext)
|
||||
r.NotFound(func(w http.ResponseWriter, r *http.Request) {
|
||||
h.writeError(w, r, errRouteNotFound)
|
||||
})
|
||||
r.MethodNotAllowed(func(w http.ResponseWriter, r *http.Request) {
|
||||
h.writeError(w, r, errMethodNotAllowed)
|
||||
})
|
||||
|
||||
strict := NewStrictHandlerWithOptions(h, nil, StrictHTTPServerOptions{
|
||||
RequestErrorHandlerFunc: h.bodyError,
|
||||
ResponseErrorHandlerFunc: h.writeError,
|
||||
})
|
||||
api := ServerInterfaceWrapper{Handler: strict, ErrorHandlerFunc: h.paramError}
|
||||
|
||||
// Health и статистика — мимо очереди: под перегрузкой они должны отвечать.
|
||||
r.Get("/health/live", api.Liveness)
|
||||
r.Get("/health/ready", api.Readiness)
|
||||
r.Get("/debug/stats", h.stats)
|
||||
|
||||
r.Route("/api/v1", func(r chi.Router) {
|
||||
r.Use(h.gate.middleware(h.writeError))
|
||||
r.With(h.jsonBody).Post("/users", api.RegisterUser)
|
||||
r.Post("/auth/sessions", api.CreateSession)
|
||||
// Сначала аутентификация, потом тело и доступ к ресурсу.
|
||||
r.Group(func(r chi.Router) {
|
||||
r.Use(h.authenticate, h.validQuery, h.jsonBody)
|
||||
r.Delete("/auth/sessions/current", api.RevokeSession)
|
||||
r.Get("/users/me", api.CurrentUser)
|
||||
r.Post("/chats", api.CreateChat)
|
||||
r.Get("/chats", api.ListChats)
|
||||
r.Get("/chats/{chat_id}", api.GetChat)
|
||||
r.Post("/chats/{chat_id}/messages", api.CreateMessage)
|
||||
r.Get("/chats/{chat_id}/messages", api.ListMessages)
|
||||
r.Post("/chats/{chat_id}/attachments", api.UploadAttachment)
|
||||
r.Get("/attachments/{attachment_id}", api.GetAttachment)
|
||||
r.Get("/attachments/{attachment_id}/content", api.DownloadAttachment)
|
||||
})
|
||||
})
|
||||
return r
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"time"
|
||||
)
|
||||
|
||||
// Timestamp подставляется кодогенератором вместо time.Time (codegen.yaml,
|
||||
// type-mapping): RFC 3339 UTC с ровно шестью цифрами дробной части.
|
||||
// time.Time срезает хвостовые нули, а fromisoformat в Python 3.9–3.10
|
||||
// (на нём публичные тесты) понимает дробную часть только из 3 или 6 цифр.
|
||||
type Timestamp time.Time
|
||||
|
||||
const timestampLayout = "2006-01-02T15:04:05.000000Z"
|
||||
|
||||
func (t Timestamp) MarshalJSON() ([]byte, error) {
|
||||
return []byte(`"` + time.Time(t).UTC().Format(timestampLayout) + `"`), nil
|
||||
}
|
||||
|
||||
func (t *Timestamp) UnmarshalJSON(data []byte) error {
|
||||
var parsed time.Time
|
||||
if err := json.Unmarshal(data, &parsed); err != nil {
|
||||
return err
|
||||
}
|
||||
*t = Timestamp(parsed)
|
||||
return nil
|
||||
}
|
||||
|
||||
// Тела запросов с лишними полями — 400 по контракту, а сгенерированный
|
||||
// декодер их молча игнорирует. Строгий разбор подключается методами на
|
||||
// сгенерированных типах.
|
||||
|
||||
func (c *CreateUser) UnmarshalJSON(data []byte) error {
|
||||
type plain CreateUser
|
||||
return decodeStrict(data, (*plain)(c))
|
||||
}
|
||||
|
||||
func (c *CreateChat) UnmarshalJSON(data []byte) error {
|
||||
type plain CreateChat
|
||||
return decodeStrict(data, (*plain)(c))
|
||||
}
|
||||
|
||||
func (c *CreateMessage) UnmarshalJSON(data []byte) error {
|
||||
var fields map[string]json.RawMessage
|
||||
if err := json.Unmarshal(data, &fields); err != nil {
|
||||
return err
|
||||
}
|
||||
raw, ok := fields["text"]
|
||||
if !ok || bytes.Equal(bytes.TrimSpace(raw), []byte("null")) {
|
||||
return fmt.Errorf("text must be a present string")
|
||||
}
|
||||
if ids, ok := fields["attachment_ids"]; ok && bytes.Equal(bytes.TrimSpace(ids), []byte("null")) {
|
||||
return fmt.Errorf("attachment_ids must be an array")
|
||||
}
|
||||
type plain CreateMessage
|
||||
return decodeStrict(data, (*plain)(c))
|
||||
}
|
||||
|
||||
func decodeStrict(data []byte, dst any) error {
|
||||
dec := json.NewDecoder(bytes.NewReader(data))
|
||||
dec.DisallowUnknownFields()
|
||||
return dec.Decode(dst)
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestMessageJSONRequiresStringTextAndArrayIDs(t *testing.T) {
|
||||
for _, body := range []string{`{"attachment_ids":[]}`, `{"text":null,"attachment_ids":[]}`, `{"text":"ok","attachment_ids":null}`} {
|
||||
t.Run(body, func(t *testing.T) {
|
||||
var message CreateMessage
|
||||
if err := json.Unmarshal([]byte(body), &message); err == nil {
|
||||
t.Fatal("accepted a missing/null required field")
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,164 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
"runtime/debug"
|
||||
"strings"
|
||||
"time"
|
||||
"unicode/utf8"
|
||||
|
||||
"backend/internal/domain/model"
|
||||
|
||||
"github.com/go-chi/chi/v5"
|
||||
"github.com/go-chi/chi/v5/middleware"
|
||||
"github.com/google/uuid"
|
||||
"go.opentelemetry.io/otel/trace"
|
||||
)
|
||||
|
||||
type ctxKey int
|
||||
|
||||
const (
|
||||
requestIDKey ctxKey = iota
|
||||
userKey
|
||||
)
|
||||
|
||||
// requestID ставит X-Request-Id в каждый ответ, включая ошибки и health.
|
||||
func requestID(next http.Handler) http.Handler {
|
||||
instance := os.Getenv("INSTANCE_ALIAS")
|
||||
if instance == "" {
|
||||
instance = uuid.NewString()
|
||||
}
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
id := uuid.NewString()
|
||||
w.Header().Set("X-Request-Id", id)
|
||||
w.Header().Set("X-Instance-Id", instance)
|
||||
next.ServeHTTP(w, r.WithContext(context.WithValue(r.Context(), requestIDKey, id)))
|
||||
})
|
||||
}
|
||||
|
||||
func requestIDFrom(ctx context.Context) string {
|
||||
id, _ := ctx.Value(requestIDKey).(string)
|
||||
return id
|
||||
}
|
||||
|
||||
// recoverer превращает панику в 500 без деталей; стек — только в лог.
|
||||
func (h *API) recoverer(next http.Handler) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
defer func() {
|
||||
rec := recover()
|
||||
if rec == nil {
|
||||
return
|
||||
}
|
||||
if rec == http.ErrAbortHandler {
|
||||
panic(rec)
|
||||
}
|
||||
h.log.Error().Interface("panic", rec).Bytes("stack", debug.Stack()).
|
||||
Str("request_id", requestIDFrom(r.Context())).Msg("panic")
|
||||
h.writeError(w, r, errors.New("panic"))
|
||||
}()
|
||||
next.ServeHTTP(w, r)
|
||||
})
|
||||
}
|
||||
|
||||
// accessLog пишет метод, шаблон маршрута, статус и длительность. Тело, query
|
||||
// и заголовки не логируются: там текст сообщений и идентификаторы.
|
||||
func (h *API) accessLog(next http.Handler) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
start := time.Now()
|
||||
ww := middleware.NewWrapResponseWriter(w, r.ProtoMajor)
|
||||
next.ServeHTTP(ww, r)
|
||||
route := chi.RouteContext(r.Context()).RoutePattern()
|
||||
if route == "" {
|
||||
route = "unmatched"
|
||||
}
|
||||
event := h.log.Info()
|
||||
if ww.Status() >= http.StatusInternalServerError {
|
||||
event = h.log.Warn()
|
||||
}
|
||||
event.Str("request_id", requestIDFrom(r.Context())).
|
||||
Str("trace_id", trace.SpanContextFromContext(r.Context()).TraceID().String()).
|
||||
Str("span_id", trace.SpanContextFromContext(r.Context()).SpanID().String()).
|
||||
Str("method", r.Method).
|
||||
Str("route", route).
|
||||
Int("status", ww.Status()).
|
||||
Dur("duration", time.Since(start)).
|
||||
Msg("request")
|
||||
})
|
||||
}
|
||||
|
||||
// authenticate verifies persisted Bearer sessions for protected business routes.
|
||||
// The session-creation endpoint separately validates Basic credentials.
|
||||
func (h *API) authenticate(next http.Handler) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
parts := strings.Fields(r.Header.Get("Authorization"))
|
||||
if len(parts) != 2 || !strings.EqualFold(parts[0], "Bearer") {
|
||||
w.Header().Set("WWW-Authenticate", `Bearer realm="messenger"`)
|
||||
h.writeError(w, r, model.ErrUnauthorized)
|
||||
return
|
||||
}
|
||||
user, err := h.auth.Authenticate(r.Context(), parts[1])
|
||||
if err != nil {
|
||||
if errors.Is(err, model.ErrUnauthorized) {
|
||||
w.Header().Set("WWW-Authenticate", `Bearer realm="messenger"`)
|
||||
}
|
||||
h.writeError(w, r, err)
|
||||
return
|
||||
}
|
||||
next.ServeHTTP(w, r.WithContext(context.WithValue(r.Context(), userKey, user)))
|
||||
})
|
||||
}
|
||||
|
||||
// validQuery отсекает query с битым %-экранированием: url.Values молча
|
||||
// выбросил бы такой параметр, и cursor=%%% превратился бы в «с начала».
|
||||
func (h *API) validQuery(next http.Handler) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
if _, err := url.ParseQuery(r.URL.RawQuery); err != nil {
|
||||
h.writeError(w, r, &model.ValidationError{Message: "некорректная строка запроса"})
|
||||
return
|
||||
}
|
||||
next.ServeHTTP(w, r)
|
||||
})
|
||||
}
|
||||
|
||||
func currentUser(ctx context.Context) model.User {
|
||||
user, _ := ctx.Value(userKey).(model.User)
|
||||
return user
|
||||
}
|
||||
|
||||
// jsonBody читает тело POST с лимитом размера (иначе 413) и отсекает
|
||||
// синтаксически неверный JSON (400) до кодогенерированного декодера: тот
|
||||
// читает только первое JSON-значение и пропустил бы мусор после него.
|
||||
func (h *API) jsonBody(next http.Handler) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Method != http.MethodPost || strings.HasSuffix(r.URL.Path, "/attachments") {
|
||||
next.ServeHTTP(w, r)
|
||||
return
|
||||
}
|
||||
reader := io.Reader(r.Body)
|
||||
if h.limits.MaxBodyBytes > 0 {
|
||||
reader = http.MaxBytesReader(w, r.Body, h.limits.MaxBodyBytes)
|
||||
}
|
||||
body, err := io.ReadAll(reader)
|
||||
var tooLarge *http.MaxBytesError
|
||||
switch {
|
||||
case errors.As(err, &tooLarge):
|
||||
h.writeError(w, r, errPayloadTooLarge)
|
||||
return
|
||||
case err != nil:
|
||||
h.writeError(w, r, &model.ValidationError{Message: "тело запроса не прочитано"})
|
||||
return
|
||||
case !utf8.Valid(body) || !json.Valid(body):
|
||||
h.writeError(w, r, &model.ValidationError{Message: "некорректный JSON"})
|
||||
return
|
||||
}
|
||||
r.Body = io.NopCloser(bytes.NewReader(body))
|
||||
next.ServeHTTP(w, r)
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"os"
|
||||
"runtime"
|
||||
"runtime/debug"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// stats — расширение за пределами контракта (contracts/extensions.md): память
|
||||
// процесса, учтённый объём хранилища и очередь. Нужен для графиков трека 5.
|
||||
func (h *API) stats(w http.ResponseWriter, _ *http.Request) {
|
||||
var mem runtime.MemStats
|
||||
runtime.ReadMemStats(&mem)
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
_ = json.NewEncoder(w).Encode(map[string]any{
|
||||
"rss_bytes": rssBytes(),
|
||||
"heap_alloc": mem.HeapAlloc,
|
||||
"heap_sys": mem.HeapSys,
|
||||
"go_memory_limit": debug.SetMemoryLimit(-1),
|
||||
"num_gc": mem.NumGC,
|
||||
"goroutines": runtime.NumGoroutine(),
|
||||
"gate": h.gate.stats(),
|
||||
"store": h.storeStats(),
|
||||
})
|
||||
}
|
||||
|
||||
// rssBytes читает VmRSS из /proc (только Linux, то есть в контейнере); иначе 0.
|
||||
func rssBytes() int64 {
|
||||
f, err := os.Open("/proc/self/status")
|
||||
if err != nil {
|
||||
return 0
|
||||
}
|
||||
defer f.Close()
|
||||
sc := bufio.NewScanner(f)
|
||||
for sc.Scan() {
|
||||
if kb, ok := strings.CutPrefix(sc.Text(), "VmRSS:"); ok {
|
||||
n, _ := strconv.ParseInt(strings.TrimSpace(strings.TrimSuffix(kb, "kB")), 10, 64)
|
||||
return n * 1024
|
||||
}
|
||||
}
|
||||
return 0
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestRejectsInvalidUTF8BeforeJSONDecoding(t *testing.T) {
|
||||
body := append([]byte(`{"display_name":"`), 0xff)
|
||||
body = append(body, []byte(`"}`)...)
|
||||
request := httptest.NewRequest(http.MethodPost, "/api/v1/users", bytes.NewReader(body))
|
||||
response := httptest.NewRecorder()
|
||||
h := &API{limits: Limits{MaxBodyBytes: 65536}}
|
||||
called := false
|
||||
requestID(h.jsonBody(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { called = true; w.WriteHeader(204) }))).ServeHTTP(response, request)
|
||||
if response.Code != 400 || called {
|
||||
t.Fatalf("invalid UTF-8 reached decoder: status=%d called=%t", response.Code, called)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
package imagefile
|
||||
|
||||
import (
|
||||
"backend/internal/domain/model"
|
||||
"crypto/sha256"
|
||||
"encoding/hex"
|
||||
"errors"
|
||||
"image"
|
||||
_ "image/jpeg"
|
||||
_ "image/png"
|
||||
"io"
|
||||
"os"
|
||||
)
|
||||
|
||||
var ErrTooLarge = errors.New("image too large")
|
||||
var ErrUnsupported = errors.New("invalid image or MIME")
|
||||
|
||||
type File struct {
|
||||
*os.File
|
||||
Size int64
|
||||
SHA256, ContentType string
|
||||
}
|
||||
|
||||
func (f *File) Dispose() { _ = f.Close(); _ = os.Remove(f.Name()) }
|
||||
func Inspect(body io.Reader, filename, mime string) (out *File, err error) {
|
||||
if err = model.ValidateFilename(filename); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if mime != "image/png" && mime != "image/jpeg" {
|
||||
return nil, ErrUnsupported
|
||||
}
|
||||
f, e := os.CreateTemp("", "messenger-upload-*")
|
||||
if e != nil {
|
||||
return nil, e
|
||||
}
|
||||
defer func() {
|
||||
if err != nil {
|
||||
_ = f.Close()
|
||||
_ = os.Remove(f.Name())
|
||||
}
|
||||
}()
|
||||
hash := sha256.New()
|
||||
n, e := io.Copy(io.MultiWriter(f, hash), io.LimitReader(body, model.MaxImageBytes+1))
|
||||
if e != nil {
|
||||
return nil, &model.ValidationError{Message: "incomplete image upload"}
|
||||
}
|
||||
if n > model.MaxImageBytes {
|
||||
return nil, ErrTooLarge
|
||||
}
|
||||
if _, e = f.Seek(0, io.SeekStart); e != nil {
|
||||
return nil, e
|
||||
}
|
||||
cfg, format, e := image.DecodeConfig(f)
|
||||
if e != nil || "image/"+format != mime {
|
||||
return nil, ErrUnsupported
|
||||
}
|
||||
pixels := int64(cfg.Width) * int64(cfg.Height)
|
||||
if cfg.Width < 1 || cfg.Height < 1 || pixels > model.MaxImagePixels {
|
||||
return nil, ErrTooLarge
|
||||
}
|
||||
if _, e = f.Seek(0, io.SeekStart); e != nil {
|
||||
return nil, e
|
||||
}
|
||||
decoded, actual, e := image.Decode(f)
|
||||
if e != nil || actual != format || decoded.Bounds().Dx() != cfg.Width || decoded.Bounds().Dy() != cfg.Height {
|
||||
return nil, ErrUnsupported
|
||||
}
|
||||
if _, e = f.Seek(0, io.SeekStart); e != nil {
|
||||
return nil, e
|
||||
}
|
||||
return &File{f, n, hex.EncodeToString(hash.Sum(nil)), mime}, nil
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
package imagefile
|
||||
|
||||
import (
|
||||
"backend/internal/domain/model"
|
||||
"bytes"
|
||||
"encoding/binary"
|
||||
"errors"
|
||||
"hash/crc32"
|
||||
"image"
|
||||
"image/png"
|
||||
"io"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func pngBytes(t *testing.T) []byte {
|
||||
t.Helper()
|
||||
var b bytes.Buffer
|
||||
if e := png.Encode(&b, image.NewNRGBA(image.Rect(0, 0, 3, 2))); e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
return b.Bytes()
|
||||
}
|
||||
func TestOriginalBytesArePreserved(t *testing.T) {
|
||||
raw := pngBytes(t)
|
||||
f, e := Inspect(bytes.NewReader(raw), "пример.png", "image/png")
|
||||
if e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
defer f.Dispose()
|
||||
got, e := io.ReadAll(f)
|
||||
if e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
if !bytes.Equal(got, raw) {
|
||||
t.Fatal("original changed")
|
||||
}
|
||||
}
|
||||
func TestRejectsInvalidImageAndFilename(t *testing.T) {
|
||||
for _, tc := range []struct {
|
||||
name, mime string
|
||||
body []byte
|
||||
want error
|
||||
}{
|
||||
{"a.png", "image/jpeg", pngBytes(t), ErrUnsupported},
|
||||
{"a.png", "image/png", []byte("not an image"), ErrUnsupported},
|
||||
{"a.png", "application/octet-stream", pngBytes(t), ErrUnsupported},
|
||||
{"a.png", "image/png", append(pngBytes(t)[:20], 0), ErrUnsupported},
|
||||
} {
|
||||
t.Run(tc.mime+string(tc.body[:1]), func(t *testing.T) {
|
||||
_, e := Inspect(bytes.NewReader(tc.body), tc.name, tc.mime)
|
||||
if !errors.Is(e, tc.want) {
|
||||
t.Fatalf("got %v, want %v", e, tc.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
for _, name := range []string{"../x.png", "a\\b", "a\x00b", "a\nb", ""} {
|
||||
if _, e := Inspect(bytes.NewReader(pngBytes(t)), name, "image/png"); e == nil {
|
||||
t.Fatalf("accepted unsafe filename %q", name)
|
||||
}
|
||||
}
|
||||
}
|
||||
func TestRejectsOversizedStreamBeforeDecoding(t *testing.T) {
|
||||
_, e := Inspect(io.LimitReader(zeroReader{}, model.MaxImageBytes+1), "a.png", "image/png")
|
||||
if !errors.Is(e, ErrTooLarge) {
|
||||
t.Fatalf("got %v", e)
|
||||
}
|
||||
}
|
||||
|
||||
type zeroReader struct{}
|
||||
|
||||
func (zeroReader) Read(p []byte) (int, error) { clear(p); return len(p), nil }
|
||||
func TestRejectsPixelBombBeforeDecoding(t *testing.T) {
|
||||
raw := pngBytes(t)
|
||||
binary.BigEndian.PutUint32(raw[16:20], 50000)
|
||||
binary.BigEndian.PutUint32(raw[20:24], 50000)
|
||||
binary.BigEndian.PutUint32(raw[29:33], crc32.ChecksumIEEE(raw[12:29]))
|
||||
_, e := Inspect(bytes.NewReader(raw), "huge.png", "image/png")
|
||||
if !errors.Is(e, ErrTooLarge) {
|
||||
t.Fatalf("pixel limit did not apply before decode: %v", e)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,135 @@
|
||||
package imagefile
|
||||
|
||||
import (
|
||||
"backend/internal/adapter/password"
|
||||
"bytes"
|
||||
"compress/zlib"
|
||||
"encoding/binary"
|
||||
"hash/crc32"
|
||||
"io"
|
||||
"os"
|
||||
"runtime"
|
||||
"runtime/debug"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"testing"
|
||||
)
|
||||
|
||||
// A normal PNG encoder allocates several full-width filter rows itself.
|
||||
// Construct a tiny, highly compressible adversarial fixture as a stream instead.
|
||||
func extremePNG(t *testing.T, interlaced bool) []byte {
|
||||
t.Helper()
|
||||
const width = 40_000_000
|
||||
const height = 1
|
||||
var idat bytes.Buffer
|
||||
z := zlib.NewWriter(&idat)
|
||||
passes := [][4]int{{0, 0, 1, 1}}
|
||||
if interlaced {
|
||||
passes = [][4]int{{0, 0, 8, 8}, {4, 0, 8, 8}, {0, 4, 4, 8}, {2, 0, 4, 4}, {0, 2, 2, 4}, {1, 0, 2, 2}, {0, 1, 1, 2}}
|
||||
}
|
||||
for _, p := range passes {
|
||||
w := (width - p[0] + p[2] - 1) / p[2]
|
||||
h := (height - p[1] + p[3] - 1) / p[3]
|
||||
if width <= p[0] || height <= p[1] || w <= 0 || h <= 0 {
|
||||
continue
|
||||
}
|
||||
for row := 0; row < h; row++ {
|
||||
if _, e := z.Write([]byte{0}); e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
if _, e := io.CopyN(z, zeroReader{}, int64(w)*8); e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
}
|
||||
}
|
||||
if e := z.Close(); e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
var out bytes.Buffer
|
||||
out.Write([]byte{137, 80, 78, 71, 13, 10, 26, 10})
|
||||
chunk := func(kind string, data []byte) {
|
||||
var word [4]byte
|
||||
binary.BigEndian.PutUint32(word[:], uint32(len(data)))
|
||||
out.Write(word[:])
|
||||
out.WriteString(kind)
|
||||
out.Write(data)
|
||||
crc := crc32.NewIEEE()
|
||||
_, _ = crc.Write([]byte(kind))
|
||||
_, _ = crc.Write(data)
|
||||
binary.BigEndian.PutUint32(word[:], crc.Sum32())
|
||||
out.Write(word[:])
|
||||
}
|
||||
header := make([]byte, 13)
|
||||
binary.BigEndian.PutUint32(header[:4], width)
|
||||
binary.BigEndian.PutUint32(header[4:8], height)
|
||||
header[8] = 16
|
||||
header[9] = 6
|
||||
if interlaced {
|
||||
header[12] = 1
|
||||
}
|
||||
chunk("IHDR", header)
|
||||
chunk("IDAT", idat.Bytes())
|
||||
chunk("IEND", nil)
|
||||
return out.Bytes()
|
||||
}
|
||||
func TestWorstCaseImagesWithinBudget(t *testing.T) {
|
||||
if os.Getenv("RUN_IMAGE_STRESS") != "1" {
|
||||
t.Skip("explicit isolated memory experiment required")
|
||||
}
|
||||
old := debug.SetMemoryLimit(1536 * 1024 * 1024)
|
||||
defer debug.SetMemoryLimit(old)
|
||||
for _, interlaced := range []bool{false, true} {
|
||||
raw := extremePNG(t, interlaced)
|
||||
runtime.GC()
|
||||
stop := make(chan struct{})
|
||||
var workers sync.WaitGroup
|
||||
for i := 0; i < 3; i++ {
|
||||
workers.Add(1)
|
||||
go func() {
|
||||
defer workers.Done()
|
||||
for {
|
||||
select {
|
||||
case <-stop:
|
||||
return
|
||||
default:
|
||||
if _, e := password.New().Hash("synthetic-concurrent-KDF"); e != nil {
|
||||
t.Error(e)
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
}()
|
||||
}
|
||||
for repeat := 0; repeat < 2; repeat++ {
|
||||
f, e := Inspect(bytes.NewReader(raw), "wide.png", "image/png")
|
||||
if e != nil {
|
||||
close(stop)
|
||||
workers.Wait()
|
||||
t.Fatal(e)
|
||||
}
|
||||
f.Dispose()
|
||||
}
|
||||
close(stop)
|
||||
workers.Wait()
|
||||
runtime.GC()
|
||||
}
|
||||
raw, e := os.ReadFile("/proc/self/status")
|
||||
if e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
peak := int64(0)
|
||||
for _, line := range strings.Split(string(raw), "\n") {
|
||||
if strings.HasPrefix(line, "VmHWM:") {
|
||||
fields := strings.Fields(line)
|
||||
peak, e = strconv.ParseInt(fields[1], 10, 64)
|
||||
if e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
}
|
||||
}
|
||||
if peak <= 0 || peak >= 2*1024*1024 {
|
||||
t.Fatalf("RSS high-water mark out of budget: %d KiB", peak)
|
||||
}
|
||||
t.Logf("PASS native RGBA64 40000000x1, normal+Adam7, two sequential validations each, 3 concurrent Argon2 workers; peak_rss_kib=%d hard_limit_kib=2097152", peak)
|
||||
}
|
||||
@@ -0,0 +1,129 @@
|
||||
package imagefile
|
||||
|
||||
import (
|
||||
"backend/internal/domain/model"
|
||||
"backend/internal/domain/port"
|
||||
"bytes"
|
||||
"context"
|
||||
"crypto/sha256"
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"image"
|
||||
"io"
|
||||
"os"
|
||||
"os/exec"
|
||||
)
|
||||
|
||||
func FitDimensions(w, h, max int) (int, int) {
|
||||
if w <= max && h <= max {
|
||||
return w, h
|
||||
}
|
||||
if w >= h {
|
||||
return max, maxInt(1, h*max/w)
|
||||
}
|
||||
return maxInt(1, w*max/h), max
|
||||
}
|
||||
func maxInt(a, b int) int {
|
||||
if a > b {
|
||||
return a
|
||||
}
|
||||
return b
|
||||
}
|
||||
|
||||
type Transformer struct{}
|
||||
|
||||
func NewTransformer() port.Transformer { return Transformer{} }
|
||||
|
||||
// ImageMagick is a constrained subprocess; no input names or shell fragments are accepted.
|
||||
func (Transformer) Transform(ctx context.Context, r io.Reader) ([]port.ProcessedVariant, error) {
|
||||
input, err := os.CreateTemp("", "pipeline-original-*")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer func() { _ = input.Close(); _ = os.Remove(input.Name()) }()
|
||||
n, err := io.Copy(input, io.LimitReader(r, model.MaxImageBytes+1))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if n > model.MaxImageBytes {
|
||||
return nil, model.ErrInvalidImage
|
||||
}
|
||||
if _, err = input.Seek(0, 0); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
config, _, err := image.DecodeConfig(input)
|
||||
if err != nil || int64(config.Width)*int64(config.Height) > model.MaxImagePixels {
|
||||
return nil, model.ErrInvalidImage
|
||||
}
|
||||
probe := exec.CommandContext(ctx, "convert", "-limit", "memory", "256MiB", "-limit", "map", "256MiB", "-limit", "disk", "0", input.Name()+"[0]", "-auto-orient", "-format", "%w %h", "info:")
|
||||
raw, err := probe.Output()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("image subprocess unavailable: %w", err)
|
||||
}
|
||||
var originalW, originalH int
|
||||
if _, err = fmt.Sscanf(string(raw), "%d %d", &originalW, &originalH); err != nil || int64(originalW)*int64(originalH) > model.MaxImagePixels {
|
||||
return nil, model.ErrInvalidImage
|
||||
}
|
||||
var variants []port.ProcessedVariant
|
||||
for _, v := range []struct {
|
||||
name, mime, geometry, format string
|
||||
crop bool
|
||||
}{{"thumbnail", "image/jpeg", "256x256>", "jpeg", false}, {"crop", "image/jpeg", "128x128^", "jpeg", true}, {"optimized", "image/webp", "1280x1280>", "webp", false}} {
|
||||
geometry := v.geometry
|
||||
if !v.crop {
|
||||
max := 256
|
||||
if v.name == "optimized" {
|
||||
max = 1280
|
||||
}
|
||||
w, h := FitDimensions(originalW, originalH, max)
|
||||
geometry = fmt.Sprintf("%dx%d!", w, h)
|
||||
}
|
||||
args := []string{"-limit", "memory", "256MiB", "-limit", "map", "256MiB", "-limit", "disk", "0", "-limit", "thread", "1", input.Name() + "[0]", "-auto-orient", "-background", "white", "-alpha", "remove", "-alpha", "off", "-strip", "-resize", geometry}
|
||||
if v.crop {
|
||||
args = append(args, "-gravity", "center", "-extent", "128x128")
|
||||
}
|
||||
args = append(args, "-quality", "82", v.format+":-")
|
||||
cmd := exec.CommandContext(ctx, "convert", args...)
|
||||
var out limitedBuffer
|
||||
cmd.Stdout = &out
|
||||
if err = cmd.Run(); err != nil {
|
||||
return nil, fmt.Errorf("image subprocess failed: %w", err)
|
||||
}
|
||||
b := out.Bytes()
|
||||
if len(b) == 0 {
|
||||
return nil, fmt.Errorf("empty variant")
|
||||
}
|
||||
w, h := 0, 0
|
||||
if v.format == "webp" {
|
||||
// Read only geometry through the native decoder; never dump diagnostics/payload.
|
||||
probe := exec.CommandContext(ctx, "identify", "-format", "%w %h", "webp:-")
|
||||
probe.Stdin = bytes.NewReader(b)
|
||||
raw, e := probe.Output()
|
||||
if e != nil {
|
||||
return nil, fmt.Errorf("invalid generated WebP")
|
||||
}
|
||||
if _, e = fmt.Sscanf(string(raw), "%d %d", &w, &h); e != nil {
|
||||
return nil, e
|
||||
}
|
||||
} else {
|
||||
// JPEG dimensions are read through the same strict decoder used for uploads.
|
||||
cfg, _, e := image.DecodeConfig(bytes.NewReader(b))
|
||||
if e != nil {
|
||||
return nil, e
|
||||
}
|
||||
w, h = cfg.Width, cfg.Height
|
||||
}
|
||||
sum := sha256.Sum256(b)
|
||||
variants = append(variants, port.ProcessedVariant{Metadata: model.Variant{Name: v.name, ContentType: v.mime, SHA256: hex.EncodeToString(sum[:]), SizeBytes: int64(len(b)), Width: w, Height: h}, Bytes: b})
|
||||
}
|
||||
return variants, nil
|
||||
}
|
||||
|
||||
type limitedBuffer struct{ bytes.Buffer }
|
||||
|
||||
func (b *limitedBuffer) Write(p []byte) (int, error) {
|
||||
if b.Len()+len(p) > 16*1024*1024 {
|
||||
return 0, fmt.Errorf("variant too large")
|
||||
}
|
||||
return b.Buffer.Write(p)
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
package imagefile
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"crypto/sha256"
|
||||
"encoding/hex"
|
||||
"image"
|
||||
"image/color"
|
||||
"image/jpeg"
|
||||
"image/png"
|
||||
"os"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestActualVariantsHonorDimensionsAlphaAndEXIF(t *testing.T) {
|
||||
if os.Getenv("RUN_VARIANT_TESTS") != "1" {
|
||||
t.Skip("requires actual ImageMagick runtime")
|
||||
}
|
||||
for _, c := range []struct {
|
||||
name string
|
||||
w, h int
|
||||
orientation bool
|
||||
}{{"landscape", 320, 200, false}, {"tiny", 1, 1, false}, {"portrait", 23, 67, false}, {"exif", 40, 20, true}} {
|
||||
t.Run(c.name, func(t *testing.T) {
|
||||
img := image.NewNRGBA(image.Rect(0, 0, c.w, c.h))
|
||||
img.Set(0, 0, color.NRGBA{R: 255, A: 0})
|
||||
var encoded bytes.Buffer
|
||||
if c.orientation {
|
||||
if e := jpeg.Encode(&encoded, img, &jpeg.Options{Quality: 82}); e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
} else {
|
||||
if e := png.Encode(&encoded, img); e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
}
|
||||
input := encoded.Bytes()
|
||||
if c.orientation {
|
||||
payload := []byte{'E', 'x', 'i', 'f', 0, 0, 'I', 'I', 42, 0, 8, 0, 0, 0, 1, 0, 18, 1, 3, 0, 1, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0}
|
||||
marker := append([]byte{255, 225, 0, byte(len(payload) + 2)}, payload...)
|
||||
input = append(append(append([]byte{}, input[:2]...), marker...), input[2:]...)
|
||||
}
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
||||
defer cancel()
|
||||
variants, e := NewTransformer().Transform(ctx, bytes.NewReader(input))
|
||||
if e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
if len(variants) != 3 {
|
||||
t.Fatalf("want three variants, got %d", len(variants))
|
||||
}
|
||||
w, h := c.w, c.h
|
||||
if c.orientation {
|
||||
w, h = h, w
|
||||
}
|
||||
for _, v := range variants {
|
||||
s := sha256.Sum256(v.Bytes)
|
||||
if v.Metadata.SHA256 != hex.EncodeToString(s[:]) || v.Metadata.SizeBytes != int64(len(v.Bytes)) {
|
||||
t.Fatal("content digest/size mismatch")
|
||||
}
|
||||
wantW, wantH := w, h
|
||||
if v.Metadata.Name == "thumbnail" {
|
||||
wantW, wantH = FitDimensions(w, h, 256)
|
||||
}
|
||||
if v.Metadata.Name == "crop" {
|
||||
wantW, wantH = 128, 128
|
||||
}
|
||||
if v.Metadata.Width != wantW || v.Metadata.Height != wantH {
|
||||
t.Fatalf("%s: got %dx%d want %dx%d", v.Metadata.Name, v.Metadata.Width, v.Metadata.Height, wantW, wantH)
|
||||
}
|
||||
if v.Metadata.ContentType == "image/jpeg" {
|
||||
decoded, e := jpeg.Decode(bytes.NewReader(v.Bytes))
|
||||
if e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
if decoded.Bounds().Dx() != wantW || decoded.Bounds().Dy() != wantH {
|
||||
t.Fatal("actual JPEG geometry mismatch")
|
||||
}
|
||||
if !c.orientation {
|
||||
r, g, b, _ := decoded.At(0, 0).RGBA()
|
||||
if r < 64000 || g < 64000 || b < 64000 {
|
||||
t.Fatal("alpha was not composited on white")
|
||||
}
|
||||
}
|
||||
} else if len(v.Bytes) < 16 || string(v.Bytes[:4]) != "RIFF" || string(v.Bytes[8:12]) != "WEBP" {
|
||||
t.Fatal("optimized file is not WebP")
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package imagefile
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestFitDimensionsPreservesAspectAndDoesNotUpscale(t *testing.T) {
|
||||
for _, c := range []struct{ w, h, max, wantW, wantH int }{{320, 200, 256, 256, 160}, {1, 1, 256, 1, 1}, {1, 400, 256, 1, 256}, {400, 1, 256, 256, 1}, {200, 320, 256, 160, 256}, {1280, 1280, 1280, 1280, 1280}} {
|
||||
w, h := FitDimensions(c.w, c.h, c.max)
|
||||
if w != c.wantW || h != c.wantH {
|
||||
t.Errorf("%+v: got %dx%d", c, w, h)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package lifecycle
|
||||
|
||||
import (
|
||||
"backend/internal/adapter/freshness"
|
||||
"os"
|
||||
"strconv"
|
||||
"time"
|
||||
)
|
||||
|
||||
func FromEnvironment() (*freshness.Watcher, error) {
|
||||
path := os.Getenv("SECRET_FRESHNESS_FILE")
|
||||
if path == "" {
|
||||
return nil, nil
|
||||
}
|
||||
age := 120
|
||||
if s := os.Getenv("SECRET_MAX_AGE_SECONDS"); s != "" {
|
||||
n, e := strconv.Atoi(s)
|
||||
if e != nil || n < 1 || n > 3600 {
|
||||
return nil, ErrConfiguration
|
||||
}
|
||||
age = n
|
||||
}
|
||||
return freshness.New(freshness.Ports{Read: freshness.FileReader(path), Now: time.Now, NewTicker: freshness.SystemTicker}, time.Duration(age)*time.Second, min(5*time.Second, time.Duration(age)*time.Second))
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
// Package lifecycle connects an explicitly supplied health monitor to composition cancellation.
|
||||
package lifecycle
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
)
|
||||
|
||||
type Ports struct {
|
||||
Watch func(context.Context) error
|
||||
Stop func()
|
||||
Report func()
|
||||
}
|
||||
type Runner struct{ ports Ports }
|
||||
|
||||
var ErrConfiguration = errors.New("invalid lifecycle configuration")
|
||||
|
||||
func New(p Ports) (*Runner, error) {
|
||||
if p.Watch == nil || p.Stop == nil || p.Report == nil {
|
||||
return nil, ErrConfiguration
|
||||
}
|
||||
return &Runner{p}, nil
|
||||
}
|
||||
func (r *Runner) Run(ctx context.Context) {
|
||||
if e := r.ports.Watch(ctx); e != nil && ctx.Err() == nil {
|
||||
r.ports.Report()
|
||||
r.ports.Stop()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package lifecycle
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestMonitorStopsNormalWorkOnceOnFreshnessFailure(t *testing.T) {
|
||||
stops, reports := 0, 0
|
||||
r, e := New(Ports{Watch: func(context.Context) error { return errors.New("expired") }, Stop: func() { stops++ }, Report: func() { reports++ }})
|
||||
if e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
r.Run(context.Background())
|
||||
if stops != 1 || reports != 1 {
|
||||
t.Fatal("freshness failure did not stop normal work")
|
||||
}
|
||||
}
|
||||
func TestMonitorDoesNotReportNormalCancellation(t *testing.T) {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
cancel()
|
||||
stops := 0
|
||||
r, e := New(Ports{Watch: func(context.Context) error { return context.Canceled }, Stop: func() { stops++ }, Report: func() { t.Fatal("normal stop reported failure") }})
|
||||
if e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
r.Run(ctx)
|
||||
if stops != 0 {
|
||||
t.Fatal("normal cancellation invoked failure stop")
|
||||
}
|
||||
}
|
||||
func TestMonitorRejectsMissingPorts(t *testing.T) {
|
||||
if _, e := New(Ports{}); e == nil {
|
||||
t.Fatal("process monitor accepted implicit production ports")
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
package password
|
||||
|
||||
import (
|
||||
"backend/internal/domain/port"
|
||||
"crypto/rand"
|
||||
"crypto/subtle"
|
||||
"encoding/base64"
|
||||
"fmt"
|
||||
"golang.org/x/crypto/argon2"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type Argon struct{}
|
||||
|
||||
var kdfSlots = make(chan struct{}, 2)
|
||||
|
||||
func New() port.Passwords { return Argon{} }
|
||||
func (Argon) Hash(password string) (string, error) {
|
||||
kdfSlots <- struct{}{}
|
||||
defer func() { <-kdfSlots }()
|
||||
salt := make([]byte, 16)
|
||||
if _, err := rand.Read(salt); err != nil {
|
||||
return "", err
|
||||
}
|
||||
hash := argon2.IDKey([]byte(password), salt, 2, 32768, 1, 32)
|
||||
return fmt.Sprintf("argon2id$v19$m32768t2p1$%s$%s", base64.RawStdEncoding.EncodeToString(salt), base64.RawStdEncoding.EncodeToString(hash)), nil
|
||||
}
|
||||
func parse(encoded string) (m, t uint32, p uint8, salt, want []byte, ok bool) {
|
||||
if len(encoded) > 256 {
|
||||
return
|
||||
}
|
||||
parts := strings.Split(encoded, "$")
|
||||
if len(parts) != 5 || parts[0] != "argon2id" || parts[1] != "v19" {
|
||||
return
|
||||
}
|
||||
if n, e := fmt.Sscanf(parts[2], "m%dt%dp%d", &m, &t, &p); e != nil || n != 3 {
|
||||
return
|
||||
}
|
||||
// Bound legacy verification before invoking an attacker-influenced KDF profile.
|
||||
if m < 8192 || m > 65536 || t < 1 || t > 4 || p < 1 || p > 2 || parts[2] != fmt.Sprintf("m%dt%dp%d", m, t, p) {
|
||||
return
|
||||
}
|
||||
var e error
|
||||
salt, e = base64.RawStdEncoding.DecodeString(parts[3])
|
||||
if e != nil || len(salt) != 16 {
|
||||
return
|
||||
}
|
||||
want, e = base64.RawStdEncoding.DecodeString(parts[4])
|
||||
if e != nil || len(want) != 32 {
|
||||
return
|
||||
}
|
||||
ok = true
|
||||
return
|
||||
}
|
||||
func (Argon) Verify(password, encoded string) bool {
|
||||
m, t, p, salt, want, ok := parse(encoded)
|
||||
if !ok {
|
||||
return false
|
||||
}
|
||||
kdfSlots <- struct{}{}
|
||||
defer func() { <-kdfSlots }()
|
||||
got := argon2.IDKey([]byte(password), salt, t, m, p, 32)
|
||||
return subtle.ConstantTimeCompare(got, want) == 1
|
||||
}
|
||||
func (Argon) NeedsRehash(encoded string) bool {
|
||||
m, t, p, _, _, ok := parse(encoded)
|
||||
return !ok || m < 32768 || t < 2 || p != 1
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
package password
|
||||
|
||||
import (
|
||||
"os"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func BenchmarkArgonLogin(b *testing.B) {
|
||||
workers, e := strconv.Atoi(os.Getenv("KDF_CONCURRENCY"))
|
||||
if e != nil || workers < 1 || workers > 4 {
|
||||
b.Fatal("explicit concurrency1..4 required")
|
||||
}
|
||||
a := Argon{}
|
||||
hash, e := a.Hash("synthetic-benchmark-password")
|
||||
if e != nil {
|
||||
b.Fatal(e)
|
||||
}
|
||||
var next atomic.Int64
|
||||
var group sync.WaitGroup
|
||||
var mu sync.Mutex
|
||||
durations := []float64{}
|
||||
var failures atomic.Int64
|
||||
b.ReportAllocs()
|
||||
b.ResetTimer()
|
||||
for i := 0; i < workers; i++ {
|
||||
group.Add(1)
|
||||
go func() {
|
||||
defer group.Done()
|
||||
for next.Add(1) <= int64(b.N) {
|
||||
start := time.Now()
|
||||
if !a.Verify("synthetic-benchmark-password", hash) {
|
||||
failures.Add(1)
|
||||
}
|
||||
ms := float64(time.Since(start)) / float64(time.Millisecond)
|
||||
mu.Lock()
|
||||
durations = append(durations, ms)
|
||||
mu.Unlock()
|
||||
}
|
||||
}()
|
||||
}
|
||||
group.Wait()
|
||||
b.StopTimer()
|
||||
if failures.Load() != 0 {
|
||||
b.Fatal("verification failure")
|
||||
}
|
||||
sort.Float64s(durations)
|
||||
if len(durations) > 0 {
|
||||
b.ReportMetric(durations[(len(durations)-1)*95/100], "p95-ms")
|
||||
}
|
||||
if raw, e := os.ReadFile("/proc/self/status"); e == nil {
|
||||
for _, line := range strings.Split(string(raw), "\n") {
|
||||
if strings.HasPrefix(line, "VmHWM:") {
|
||||
parts := strings.Fields(line)
|
||||
if len(parts) > 1 {
|
||||
rss, e := strconv.ParseFloat(parts[1], 64)
|
||||
if e == nil {
|
||||
b.ReportMetric(rss/1024, "peak-RSS-MiB")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package password
|
||||
|
||||
import (
|
||||
"encoding/base64"
|
||||
"fmt"
|
||||
"golang.org/x/crypto/argon2"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestLegacyParametersVerifyAndRequireRehash(t *testing.T) {
|
||||
salt := []byte("1234567890abcdef")
|
||||
hash := argon2.IDKey([]byte("synthetic-password"), salt, 1, 8192, 1, 32)
|
||||
encoded := fmt.Sprintf("argon2id$v19$m8192t1p1$%s$%s", base64.RawStdEncoding.EncodeToString(salt), base64.RawStdEncoding.EncodeToString(hash))
|
||||
a := Argon{}
|
||||
if !a.Verify("synthetic-password", encoded) {
|
||||
t.Fatal("valid legacy password rejected")
|
||||
}
|
||||
if !a.NeedsRehash(encoded) {
|
||||
t.Fatal("legacy cost must upgrade")
|
||||
}
|
||||
current, e := a.Hash("synthetic-password")
|
||||
if e != nil || !a.Verify("synthetic-password", current) || a.NeedsRehash(current) {
|
||||
t.Fatal("current profile must verify without repeated rehash")
|
||||
}
|
||||
for _, bad := range []string{"argon2id$v19$m4294967295t2p1$x$x", "argon2id$v19$m32768t9999p1$x$x", encoded + "$extra", "bad"} {
|
||||
if a.Verify("synthetic-password", bad) {
|
||||
t.Fatal("unsafe encoded parameters accepted")
|
||||
}
|
||||
}
|
||||
if a.Verify("wrong-password", encoded) {
|
||||
t.Fatal("wrong password accepted")
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package queue
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"github.com/redis/go-redis/v9"
|
||||
"time"
|
||||
)
|
||||
|
||||
var ErrClientConfiguration = errors.New("separate broker identities required")
|
||||
|
||||
// Clients parses configuration only; connecting/authenticating is deferred to
|
||||
// the native client. No credential or original parser error reaches diagnostics.
|
||||
func Clients(publishURL, consumeURL string) (*redis.Client, *redis.Client, error) {
|
||||
p, e := redis.ParseURL(publishURL)
|
||||
if e != nil {
|
||||
return nil, nil, ErrClientConfiguration
|
||||
}
|
||||
c, e := redis.ParseURL(consumeURL)
|
||||
if e != nil || p.Username == "" || c.Username == "" || p.Username == c.Username {
|
||||
return nil, nil, ErrClientConfiguration
|
||||
}
|
||||
for _, o := range []*redis.Options{p, c} {
|
||||
o.MaxRetries = -1
|
||||
o.DialTimeout = time.Second
|
||||
o.ReadTimeout = 2 * time.Second
|
||||
o.WriteTimeout = time.Second
|
||||
o.PoolSize = 2
|
||||
o.MaxActiveConns = 2
|
||||
o.MaxIdleConns = 1
|
||||
}
|
||||
return redis.NewClient(p), redis.NewClient(c), nil
|
||||
}
|
||||
@@ -0,0 +1,106 @@
|
||||
package queue
|
||||
|
||||
import (
|
||||
"backend/internal/config"
|
||||
"backend/internal/domain/model"
|
||||
"context"
|
||||
"github.com/google/uuid"
|
||||
"github.com/redis/go-redis/v9"
|
||||
"net/url"
|
||||
"os"
|
||||
"regexp"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestRealValkeyRejectsCrossRoleCommands(t *testing.T) {
|
||||
if os.Getenv("RUN_BROKER_ACL_TESTS") != "1" {
|
||||
t.Skip("explicit isolated Valkey admin required")
|
||||
}
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second)
|
||||
defer cancel()
|
||||
raw, e := config.ReadSecret("/run/secrets/cache_url")
|
||||
if e != nil {
|
||||
t.Fatal("admin file unavailable")
|
||||
}
|
||||
opts, e := redis.ParseURL(raw)
|
||||
if e != nil {
|
||||
t.Fatal("admin config invalid")
|
||||
}
|
||||
opts.MaxRetries = -1
|
||||
admin := redis.NewClient(opts)
|
||||
defer closeRedis(t, admin)
|
||||
names, e := admin.ACLUsers(ctx).Result()
|
||||
if e != nil {
|
||||
t.Fatal("temporary ACL inventory failed")
|
||||
}
|
||||
owned := regexp.MustCompile(`^vp7_(pub|con)_[a-f0-9]{32}$`)
|
||||
for _, name := range names {
|
||||
if owned.MatchString(name) {
|
||||
if e = admin.Do(ctx, "ACL", "DELUSER", name).Err(); e != nil {
|
||||
t.Fatal("prior temporary ACL cleanup failed")
|
||||
}
|
||||
}
|
||||
}
|
||||
u, e := url.Parse(raw)
|
||||
if e != nil {
|
||||
t.Fatal("broker URL invalid")
|
||||
}
|
||||
suffix := strings.ReplaceAll(uuid.NewString(), "-", "")
|
||||
pubName, conName := "vp7_pub_"+suffix, "vp7_con_"+suffix
|
||||
password := uuid.NewString()
|
||||
defer func() {
|
||||
c, stop := context.WithTimeout(context.Background(), 3*time.Second)
|
||||
defer stop()
|
||||
if e := admin.Do(c, "ACL", "DELUSER", pubName, conName).Err(); e != nil {
|
||||
t.Error("temporary ACL cleanup failed")
|
||||
}
|
||||
}()
|
||||
for _, role := range []struct {
|
||||
name string
|
||||
commands []string
|
||||
}{{pubName, []string{"+xadd"}}, {conName, []string{"+xgroup", "+xreadgroup", "+xautoclaim", "+xack", "+xdel"}}} {
|
||||
args := []any{"ACL", "SETUSER", role.name, "reset", "on", ">" + password, "~attachment-jobs", "+hello", "+ping", "+select", "+client|setinfo"}
|
||||
for _, command := range role.commands {
|
||||
args = append(args, command)
|
||||
}
|
||||
if e = admin.Do(ctx, args...).Err(); e != nil {
|
||||
t.Fatal("temporary ACL setup failed")
|
||||
}
|
||||
}
|
||||
u.User = url.UserPassword(pubName, password)
|
||||
pubURL := u.String()
|
||||
u.User = url.UserPassword(conName, password)
|
||||
p, c, e := Clients(pubURL, u.String())
|
||||
if e != nil {
|
||||
t.Fatal("separate clients rejected")
|
||||
}
|
||||
defer closeRedis(t, p)
|
||||
defer closeRedis(t, c)
|
||||
j := model.Job{ID: uuid.New(), AttachmentID: uuid.New(), PipelineVersion: 1, CreatedAt: time.Now()}
|
||||
s := &publishStore{j: j}
|
||||
b := New(p, c, s, "synthetic")
|
||||
if e = b.Publish(ctx); e != nil || !s.published {
|
||||
t.Fatal("publisher-only native identity could not publish outbox")
|
||||
}
|
||||
rows, e := admin.XRevRangeN(ctx, stream, "+", "-", 1).Result()
|
||||
if e != nil || len(rows) != 1 || !strings.Contains(rows[0].Values["job"].(string), j.ID.String()) {
|
||||
t.Fatal("owned test publication not found")
|
||||
}
|
||||
defer admin.XDel(context.Background(), stream, rows[0].ID)
|
||||
if e = p.XAck(ctx, stream, "workers", rows[0].ID).Err(); e == nil || !strings.Contains(e.Error(), "NOPERM") {
|
||||
t.Fatal("publisher identity could acknowledge consumer work")
|
||||
}
|
||||
if e = c.XAdd(ctx, &redis.XAddArgs{Stream: stream, Values: map[string]any{"forbidden": "synthetic"}}).Err(); e == nil || !strings.Contains(e.Error(), "NOPERM") {
|
||||
t.Fatal("consumer identity could publish work")
|
||||
}
|
||||
processed := false
|
||||
b.consume(ctx, rows[0], func(context.Context, model.Job) error { processed = true; return nil }, func(error) { t.Error("consumer failed") })
|
||||
if !processed {
|
||||
t.Fatal("native consumer did not accept envelope")
|
||||
}
|
||||
if left, e := admin.XRangeN(ctx, stream, rows[0].ID, rows[0].ID, 1).Result(); e != nil || len(left) != 0 {
|
||||
t.Fatal("native consumer did not delete its acknowledged delivery")
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,113 @@
|
||||
package queue
|
||||
|
||||
import (
|
||||
"backend/internal/domain/model"
|
||||
"backend/internal/domain/port"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"github.com/google/uuid"
|
||||
"github.com/redis/go-redis/v9"
|
||||
"net"
|
||||
"sync"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
type commandHook struct {
|
||||
role string
|
||||
mu sync.Mutex
|
||||
commands []string
|
||||
t *testing.T
|
||||
}
|
||||
|
||||
func (h *commandHook) DialHook(redis.DialHook) redis.DialHook {
|
||||
return func(context.Context, string, string) (net.Conn, error) {
|
||||
return nil, errors.New("test forbids network")
|
||||
}
|
||||
}
|
||||
func (h *commandHook) ProcessHook(redis.ProcessHook) redis.ProcessHook {
|
||||
return func(_ context.Context, c redis.Cmder) error {
|
||||
h.mu.Lock()
|
||||
defer h.mu.Unlock()
|
||||
name := c.Name()
|
||||
if h.role == "publisher" && name != "xadd" || h.role == "consumer" && name != "xack" && name != "xdel" {
|
||||
h.t.Errorf("%s principal used forbidden command %s", h.role, name)
|
||||
}
|
||||
h.commands = append(h.commands, name)
|
||||
switch v := c.(type) {
|
||||
case *redis.StringCmd:
|
||||
v.SetVal("1-0")
|
||||
case *redis.IntCmd:
|
||||
v.SetVal(1)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
}
|
||||
func (h *commandHook) ProcessPipelineHook(redis.ProcessPipelineHook) redis.ProcessPipelineHook {
|
||||
return func(context.Context, []redis.Cmder) error { return errors.New("test forbids implicit pipeline") }
|
||||
}
|
||||
|
||||
type publishStore struct {
|
||||
port.PipelineStore
|
||||
j model.Job
|
||||
published bool
|
||||
}
|
||||
|
||||
func (s *publishStore) PendingJobs(context.Context) ([]model.Job, error) {
|
||||
return []model.Job{s.j}, nil
|
||||
}
|
||||
func (s *publishStore) Published(_ context.Context, id uuid.UUID) error {
|
||||
s.published = id == s.j.ID
|
||||
return nil
|
||||
}
|
||||
func TestPublisherAndConsumerCommandsUseSeparatePrincipals(t *testing.T) {
|
||||
p := redis.NewClient(&redis.Options{Addr: "127.0.0.1:1"})
|
||||
defer closeRedis(t, p)
|
||||
c := redis.NewClient(&redis.Options{Addr: "127.0.0.1:1"})
|
||||
defer closeRedis(t, c)
|
||||
ph, ch := &commandHook{role: "publisher", t: t}, &commandHook{role: "consumer", t: t}
|
||||
p.AddHook(ph)
|
||||
c.AddHook(ch)
|
||||
j := model.Job{ID: uuid.New(), AttachmentID: uuid.New(), PipelineVersion: 1, Attempt: 1, CreatedAt: time.Now()}
|
||||
s := &publishStore{j: j}
|
||||
b := New(p, c, s, "synthetic")
|
||||
if e := b.Publish(context.Background()); e != nil || !s.published {
|
||||
t.Fatal("outbox publish did not complete")
|
||||
}
|
||||
raw, _ := json.Marshal(struct {
|
||||
Schema int `json:"schema_version"`
|
||||
Type string `json:"type"`
|
||||
model.Job
|
||||
}{1, "attachment.process.v1", j})
|
||||
processed := false
|
||||
b.consume(context.Background(), redis.XMessage{ID: "1-0", Values: map[string]any{"job": string(raw)}}, func(context.Context, model.Job) error { processed = true; return nil }, func(error) { t.Fatal("consumer processing failed") })
|
||||
if !processed || len(ph.commands) != 1 || len(ch.commands) != 2 {
|
||||
t.Fatal("publication and acknowledgement were not routed independently")
|
||||
}
|
||||
}
|
||||
func TestSeparateClientConfigurationFailsClosed(t *testing.T) {
|
||||
for _, pair := range [][2]string{{"", "redis://consumer:p@127.0.0.1:1"}, {"redis://same:p@127.0.0.1:1", "redis://same:q@127.0.0.1:1"}, {"redis://:p@127.0.0.1:1", "redis://consumer:p@127.0.0.1:1"}} {
|
||||
if p, c, e := Clients(pair[0], pair[1]); e == nil {
|
||||
closeRedis(t, p)
|
||||
closeRedis(t, c)
|
||||
t.Fatal("missing or shared identity accepted")
|
||||
}
|
||||
}
|
||||
p, c, e := Clients("redis://publisher:synthetic@127.0.0.1:1", "redis://consumer:synthetic@127.0.0.1:1")
|
||||
if e != nil {
|
||||
t.Fatal("separate identity configuration rejected")
|
||||
}
|
||||
defer closeRedis(t, p)
|
||||
defer closeRedis(t, c)
|
||||
if p.Options().Username != "publisher" || c.Options().Username != "consumer" {
|
||||
t.Fatal("actual clients lost principal names")
|
||||
}
|
||||
}
|
||||
|
||||
func closeRedis(t *testing.T, c *redis.Client) {
|
||||
t.Helper()
|
||||
if e := c.Close(); e != nil {
|
||||
t.Error("client cleanup failed")
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
package queue
|
||||
|
||||
import (
|
||||
"backend/internal/domain/model"
|
||||
"backend/internal/domain/port"
|
||||
"context"
|
||||
"errors"
|
||||
"github.com/google/uuid"
|
||||
"github.com/redis/go-redis/v9"
|
||||
"go.opentelemetry.io/otel"
|
||||
"go.opentelemetry.io/otel/codes"
|
||||
sdktrace "go.opentelemetry.io/otel/sdk/trace"
|
||||
"go.opentelemetry.io/otel/sdk/trace/tracetest"
|
||||
"net"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
type reviewPendingStore struct{ port.PipelineStore }
|
||||
|
||||
func (reviewPendingStore) PendingJobs(context.Context) ([]model.Job, error) {
|
||||
return []model.Job{{ID: uuid.New(), AttachmentID: uuid.New(), PipelineVersion: 1, CreatedAt: time.Now()}}, nil
|
||||
}
|
||||
func TestReviewPublishTransportFailureMarksProducerSpan(t *testing.T) {
|
||||
exporter := tracetest.NewInMemoryExporter()
|
||||
provider := sdktrace.NewTracerProvider(sdktrace.WithSyncer(exporter))
|
||||
previous := otel.GetTracerProvider()
|
||||
otel.SetTracerProvider(provider)
|
||||
defer func() {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
|
||||
defer cancel()
|
||||
_ = provider.Shutdown(ctx)
|
||||
otel.SetTracerProvider(previous)
|
||||
}()
|
||||
client := redis.NewClient(&redis.Options{MaxRetries: -1, Dialer: func(context.Context, string, string) (net.Conn, error) {
|
||||
return nil, errors.New("synthetic transport failure")
|
||||
}})
|
||||
defer func() { _ = client.Close() }()
|
||||
consumer := redis.NewClient(&redis.Options{Addr: "127.0.0.1:1"})
|
||||
defer func() { _ = consumer.Close() }()
|
||||
broker := New(client, consumer, reviewPendingStore{}, "fake-review")
|
||||
if err := broker.Publish(context.Background()); err == nil {
|
||||
t.Fatal("negative control did not fail")
|
||||
}
|
||||
spans := exporter.GetSpans()
|
||||
if len(spans) != 1 || spans[0].Name != "attachment.publish" || spans[0].Status.Code != codes.Error {
|
||||
t.Fatalf("failed publish not marked as failed producer span; count=%d", len(spans))
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,151 @@
|
||||
package queue
|
||||
|
||||
import (
|
||||
"backend/internal/domain/model"
|
||||
"backend/internal/domain/port"
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"github.com/google/uuid"
|
||||
"github.com/redis/go-redis/v9"
|
||||
"go.opentelemetry.io/otel"
|
||||
"go.opentelemetry.io/otel/codes"
|
||||
"go.opentelemetry.io/otel/propagation"
|
||||
"go.opentelemetry.io/otel/trace"
|
||||
"time"
|
||||
)
|
||||
|
||||
const stream = "attachment-jobs"
|
||||
|
||||
type Broker struct {
|
||||
client *redis.Client
|
||||
publisher *redis.Client
|
||||
store port.PipelineStore
|
||||
consumer string
|
||||
}
|
||||
|
||||
func New(publisher, client *redis.Client, store port.PipelineStore, consumer string) *Broker {
|
||||
return &Broker{client: client, publisher: publisher, store: store, consumer: consumer}
|
||||
}
|
||||
func (b *Broker) Publish(ctx context.Context) error {
|
||||
jobs, e := b.store.PendingJobs(ctx)
|
||||
if e != nil {
|
||||
return e
|
||||
}
|
||||
for _, j := range jobs {
|
||||
parent := otel.GetTextMapPropagator().Extract(ctx, propagation.MapCarrier{"traceparent": j.Traceparent, "tracestate": j.Tracestate})
|
||||
send, span := otel.Tracer("messenger").Start(parent, "attachment.publish", trace.WithSpanKind(trace.SpanKindProducer))
|
||||
carrier := propagation.MapCarrier{}
|
||||
otel.GetTextMapPropagator().Inject(send, carrier)
|
||||
j.Traceparent = carrier.Get("traceparent")
|
||||
j.Tracestate = carrier.Get("tracestate")
|
||||
j.Attempt++
|
||||
payload := struct {
|
||||
Schema int `json:"schema_version"`
|
||||
Type string `json:"type"`
|
||||
model.Job
|
||||
}{1, "attachment.process.v1", j}
|
||||
raw, e := json.Marshal(payload)
|
||||
if e != nil {
|
||||
span.SetStatus(codes.Error, "job_encoding_error")
|
||||
span.End()
|
||||
return e
|
||||
}
|
||||
if e = b.publisher.XAdd(send, &redis.XAddArgs{Stream: stream, MaxLen: 10000, Approx: true, Values: map[string]any{"job": string(raw)}}).Err(); e != nil {
|
||||
span.SetStatus(codes.Error, "broker_error")
|
||||
span.End()
|
||||
return e
|
||||
}
|
||||
if e = b.store.Published(send, j.ID); e != nil {
|
||||
span.SetStatus(codes.Error, "outbox_persistence_error")
|
||||
span.End()
|
||||
return e
|
||||
}
|
||||
span.End()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
func (b *Broker) RunPublisher(ctx context.Context, onError func(error)) {
|
||||
tick := time.NewTicker(500 * time.Millisecond)
|
||||
defer tick.Stop()
|
||||
for {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return
|
||||
case <-tick.C:
|
||||
if e := b.Publish(ctx); e != nil {
|
||||
onError(e)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
func (b *Broker) ack(ctx context.Context, id string) {
|
||||
if b.client.XAck(ctx, stream, "workers", id).Err() == nil {
|
||||
_ = b.client.XDel(ctx, stream, id).Err()
|
||||
}
|
||||
}
|
||||
func (b *Broker) consume(ctx context.Context, m redis.XMessage, process func(context.Context, model.Job) error, onError func(error)) {
|
||||
raw, ok := m.Values["job"].(string)
|
||||
if !ok || len(raw) > 2048 {
|
||||
b.ack(ctx, m.ID)
|
||||
return
|
||||
}
|
||||
var envelope struct {
|
||||
Schema int `json:"schema_version"`
|
||||
Type string `json:"type"`
|
||||
model.Job
|
||||
}
|
||||
decoder := json.NewDecoder(bytes.NewBufferString(raw))
|
||||
decoder.DisallowUnknownFields()
|
||||
if decoder.Decode(&envelope) != nil || envelope.Schema != 1 || envelope.Type != "attachment.process.v1" || envelope.ID == uuid.Nil || envelope.AttachmentID == uuid.Nil || envelope.PipelineVersion < 1 || envelope.Attempt < 1 {
|
||||
b.ack(ctx, m.ID)
|
||||
return
|
||||
}
|
||||
work, cancel := context.WithTimeout(ctx, 20*time.Second)
|
||||
e := process(work, envelope.Job)
|
||||
cancel()
|
||||
if e != nil {
|
||||
onError(e)
|
||||
} else {
|
||||
b.ack(ctx, m.ID)
|
||||
}
|
||||
}
|
||||
func (b *Broker) RunWorker(ctx context.Context, process func(context.Context, model.Job) error, onError func(error)) {
|
||||
for ctx.Err() == nil {
|
||||
e := b.client.XGroupCreateMkStream(ctx, stream, "workers", "0").Err()
|
||||
if e != nil && e.Error() != "BUSYGROUP Consumer Group name already exists" {
|
||||
onError(e)
|
||||
pause(ctx)
|
||||
continue
|
||||
}
|
||||
// Reclaim abandoned PEL entries; the DB lease and version fence are authoritative.
|
||||
claimed, _, e := b.client.XAutoClaim(ctx, &redis.XAutoClaimArgs{Stream: stream, Group: "workers", Consumer: b.consumer, MinIdle: 30 * time.Second, Start: "0-0", Count: 1}).Result()
|
||||
if e == nil && len(claimed) > 0 {
|
||||
for _, m := range claimed {
|
||||
b.consume(ctx, m, process, onError)
|
||||
}
|
||||
continue
|
||||
}
|
||||
rows, e := b.client.XReadGroup(ctx, &redis.XReadGroupArgs{Group: "workers", Consumer: b.consumer, Streams: []string{stream, ">"}, Count: 1, Block: time.Second}).Result()
|
||||
if errors.Is(e, redis.Nil) {
|
||||
continue
|
||||
}
|
||||
if e != nil {
|
||||
onError(e)
|
||||
pause(ctx)
|
||||
continue
|
||||
}
|
||||
for _, row := range rows {
|
||||
for _, m := range row.Messages {
|
||||
b.consume(ctx, m, process, onError)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
func pause(ctx context.Context) {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
case <-time.After(200 * time.Millisecond):
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
package postgres
|
||||
|
||||
import (
|
||||
"backend/internal/adapter/repository/postgres/queries"
|
||||
"backend/internal/domain/model"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
func attachment(r queries.Attachment) model.Attachment {
|
||||
var variants []model.Variant
|
||||
_ = json.Unmarshal(r.Variants, &variants)
|
||||
return model.Attachment{ID: r.ID, ChatID: r.ChatID, OwnerID: r.OwnerID, Filename: r.Filename, ContentType: r.ContentType, SizeBytes: r.SizeBytes, SHA256: r.Sha256, Status: r.Status, CreatedAt: r.CreatedAt, UpdatedAt: r.UpdatedAt, PipelineVersion: r.PipelineVersion, ErrorCode: r.ErrorCode, Variants: variants, StagingExpired: r.StagingExpired, StagingCleaned: r.StagingCleaned}
|
||||
}
|
||||
func (s *Store) ReserveAttachment(ctx context.Context, a model.Attachment) (model.Attachment, error) {
|
||||
tx, e := s.pool.Begin(ctx)
|
||||
if e != nil {
|
||||
return model.Attachment{}, mapErr(e)
|
||||
}
|
||||
defer func() { _ = tx.Rollback(ctx) }()
|
||||
q := s.q.WithTx(tx)
|
||||
if _, e = q.ChargeAttachment(ctx, a.OwnerID); e != nil {
|
||||
return model.Attachment{}, model.ErrStorageFull
|
||||
}
|
||||
r, e := q.InsertAttachment(ctx, queries.InsertAttachmentParams{ID: a.ID, ChatID: a.ChatID, OwnerID: a.OwnerID, Filename: a.Filename, ContentType: a.ContentType, SizeBytes: a.SizeBytes, Sha256: a.SHA256})
|
||||
if e != nil {
|
||||
return model.Attachment{}, mapErr(e)
|
||||
}
|
||||
if e = tx.Commit(ctx); e != nil {
|
||||
return model.Attachment{}, mapErr(e)
|
||||
}
|
||||
return attachment(r), nil
|
||||
}
|
||||
func (s *Store) GetAttachment(ctx context.Context, id uuid.UUID) (model.Attachment, error) {
|
||||
r, e := s.q.GetAttachment(ctx, id)
|
||||
return attachment(r), mapErr(e)
|
||||
}
|
||||
func (s *Store) SetAttachmentStatus(ctx context.Context, id uuid.UUID, from, to string) (bool, error) {
|
||||
n, e := s.q.SetAttachmentStatus(ctx, queries.SetAttachmentStatusParams{ID: id, Status: to, Status_2: from})
|
||||
return n == 1, mapErr(e)
|
||||
}
|
||||
func (s *Store) ReconcileAttachments(ctx context.Context, after uuid.UUID) ([]model.Attachment, bool, error) {
|
||||
rows, e := s.q.ReconcileAttachments(ctx, after)
|
||||
if e != nil {
|
||||
return nil, false, mapErr(e)
|
||||
}
|
||||
more := len(rows) > 100
|
||||
if more {
|
||||
rows = rows[:100]
|
||||
}
|
||||
out := make([]model.Attachment, len(rows))
|
||||
for i, r := range rows {
|
||||
out[i] = attachment(r)
|
||||
}
|
||||
return out, more, nil
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package postgres
|
||||
|
||||
import (
|
||||
"backend/internal/domain/model"
|
||||
"context"
|
||||
)
|
||||
|
||||
func (s *Store) PipelineMetrics(ctx context.Context) (model.PipelineMetrics, error) {
|
||||
r, e := s.q.PipelineMetrics(ctx)
|
||||
if e != nil {
|
||||
return model.PipelineMetrics{}, mapErr(e)
|
||||
}
|
||||
cohort, e := s.q.ReadySLI(ctx)
|
||||
return model.PipelineMetrics{Depth: r.Depth, Oldest: r.Oldest, ReadyMatured: [3]int64{cohort.Matured10, cohort.Matured30, cohort.Matured300}, ReadyTimely: [3]int64{cohort.Timely10, cohort.Timely30, cohort.Timely300}}, mapErr(e)
|
||||
}
|
||||
@@ -0,0 +1,171 @@
|
||||
package postgres
|
||||
|
||||
import (
|
||||
"backend/internal/adapter/repository/postgres/queries"
|
||||
"backend/internal/domain/model"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"github.com/google/uuid"
|
||||
"github.com/jackc/pgx/v5"
|
||||
"time"
|
||||
)
|
||||
|
||||
func job(r queries.AttachmentJob) model.Job {
|
||||
return model.Job{ID: r.ID, AttachmentID: r.AttachmentID, PipelineVersion: r.PipelineVersion, Attempt: r.Attempt, CreatedAt: r.CreatedAt, Traceparent: r.Traceparent, Tracestate: r.Tracestate}
|
||||
}
|
||||
func (s *Store) QueueAttachment(ctx context.Context, a model.Attachment, tp, ts string) (model.Attachment, error) {
|
||||
tx, e := s.pool.Begin(ctx)
|
||||
if e != nil {
|
||||
return model.Attachment{}, mapErr(e)
|
||||
}
|
||||
defer func() { _ = tx.Rollback(ctx) }()
|
||||
q := s.q.WithTx(tx)
|
||||
r, e := q.QueueAttachment(ctx, a.ID)
|
||||
if e != nil {
|
||||
return model.Attachment{}, mapErr(e)
|
||||
}
|
||||
if e = q.InsertJob(ctx, queries.InsertJobParams{JobID: uuid.New(), AttachmentID: r.ID, PipelineVersion: r.PipelineVersion, Traceparent: tp, Tracestate: ts}); e != nil {
|
||||
return model.Attachment{}, mapErr(e)
|
||||
}
|
||||
if e = tx.Commit(ctx); e != nil {
|
||||
return model.Attachment{}, mapErr(e)
|
||||
}
|
||||
return attachment(r), nil
|
||||
}
|
||||
func (s *Store) PendingJobs(ctx context.Context) ([]model.Job, error) {
|
||||
rows, e := s.q.PendingJobs(ctx)
|
||||
if e != nil {
|
||||
return nil, mapErr(e)
|
||||
}
|
||||
out := make([]model.Job, len(rows))
|
||||
for i, r := range rows {
|
||||
out[i] = job(r)
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
func (s *Store) Published(ctx context.Context, id uuid.UUID) error {
|
||||
return mapErr(s.q.Published(ctx, id))
|
||||
}
|
||||
func (s *Store) AcquireJob(ctx context.Context, j model.Job, lease uuid.UUID, d time.Duration) (model.Job, model.Attachment, bool, error) {
|
||||
tx, e := s.pool.Begin(ctx)
|
||||
if e != nil {
|
||||
return j, model.Attachment{}, false, mapErr(e)
|
||||
}
|
||||
defer func() { _ = tx.Rollback(ctx) }()
|
||||
q := s.q.WithTx(tx)
|
||||
r, e := q.AcquireJob(ctx, queries.AcquireJobParams{LeaseID: lease, LeaseSeconds: int32(d / time.Second), JobID: j.ID, PipelineVersion: j.PipelineVersion})
|
||||
if errors.Is(e, pgx.ErrNoRows) {
|
||||
return j, model.Attachment{}, false, nil
|
||||
}
|
||||
if e != nil {
|
||||
return j, model.Attachment{}, false, mapErr(e)
|
||||
}
|
||||
a, e := q.ProcessingAttachment(ctx, queries.ProcessingAttachmentParams{AttachmentID: r.AttachmentID, PipelineVersion: r.PipelineVersion})
|
||||
if e != nil {
|
||||
return j, model.Attachment{}, false, mapErr(e)
|
||||
}
|
||||
if e = tx.Commit(ctx); e != nil {
|
||||
return j, model.Attachment{}, false, mapErr(e)
|
||||
}
|
||||
return job(r), attachment(a), true, nil
|
||||
}
|
||||
func (s *Store) CompleteJob(ctx context.Context, j model.Job, lease uuid.UUID, v []model.Variant) (bool, error) {
|
||||
raw, e := json.Marshal(v)
|
||||
if e != nil {
|
||||
return false, e
|
||||
}
|
||||
tx, e := s.pool.Begin(ctx)
|
||||
if e != nil {
|
||||
return false, mapErr(e)
|
||||
}
|
||||
defer func() { _ = tx.Rollback(ctx) }()
|
||||
q := s.q.WithTx(tx)
|
||||
n, e := q.CompleteAttachment(ctx, queries.CompleteAttachmentParams{Variants: raw, JobID: j.ID, LeaseID: lease})
|
||||
if e != nil {
|
||||
return false, mapErr(e)
|
||||
}
|
||||
if n != 1 {
|
||||
return false, nil
|
||||
}
|
||||
if e = q.CompleteJob(ctx, queries.CompleteJobParams{JobID: j.ID, LeaseID: lease}); e != nil {
|
||||
return false, mapErr(e)
|
||||
}
|
||||
return true, mapErr(tx.Commit(ctx))
|
||||
}
|
||||
func (s *Store) RetryJob(ctx context.Context, j model.Job, lease uuid.UUID, code string, delay time.Duration, failed bool) error {
|
||||
status := "queued"
|
||||
if failed {
|
||||
status = "failed"
|
||||
}
|
||||
tx, e := s.pool.Begin(ctx)
|
||||
if e != nil {
|
||||
return mapErr(e)
|
||||
}
|
||||
defer func() { _ = tx.Rollback(ctx) }()
|
||||
q := s.q.WithTx(tx)
|
||||
n, e := q.RetryAttachment(ctx, queries.RetryAttachmentParams{NextStatus: status, ErrorCode: code, JobID: j.ID, LeaseID: lease})
|
||||
if e != nil {
|
||||
return mapErr(e)
|
||||
}
|
||||
if n == 0 {
|
||||
return nil
|
||||
}
|
||||
if e = q.RetryJob(ctx, queries.RetryJobParams{DelayMs: int32(delay / time.Millisecond), Completed: failed, JobID: j.ID, LeaseID: lease}); e != nil {
|
||||
return mapErr(e)
|
||||
}
|
||||
return mapErr(tx.Commit(ctx))
|
||||
}
|
||||
func (s *Store) ReplayJob(ctx context.Context, id uuid.UUID) (bool, error) {
|
||||
tx, e := s.pool.Begin(ctx)
|
||||
if e != nil {
|
||||
return false, mapErr(e)
|
||||
}
|
||||
defer func() { _ = tx.Rollback(ctx) }()
|
||||
q := s.q.WithTx(tx)
|
||||
a, e := q.ReplayAttachment(ctx, id)
|
||||
if errors.Is(e, pgx.ErrNoRows) {
|
||||
return false, nil
|
||||
}
|
||||
if e != nil {
|
||||
return false, mapErr(e)
|
||||
}
|
||||
if e = q.ReplayJobs(ctx, queries.ReplayJobsParams{AttachmentID: id, PipelineVersion: a.PipelineVersion}); e != nil {
|
||||
return false, mapErr(e)
|
||||
}
|
||||
return true, mapErr(tx.Commit(ctx))
|
||||
}
|
||||
func (s *Store) AdvancePipeline(ctx context.Context, id uuid.UUID) (bool, error) {
|
||||
tx, e := s.pool.Begin(ctx)
|
||||
if e != nil {
|
||||
return false, mapErr(e)
|
||||
}
|
||||
defer func() { _ = tx.Rollback(ctx) }()
|
||||
q := s.q.WithTx(tx)
|
||||
a, e := q.AdvancePipeline(ctx, id)
|
||||
if errors.Is(e, pgx.ErrNoRows) {
|
||||
return false, nil
|
||||
}
|
||||
if e != nil {
|
||||
return false, mapErr(e)
|
||||
}
|
||||
if e = q.InsertJob(ctx, queries.InsertJobParams{JobID: uuid.New(), AttachmentID: id, PipelineVersion: a.PipelineVersion}); e != nil {
|
||||
return false, mapErr(e)
|
||||
}
|
||||
return true, mapErr(tx.Commit(ctx))
|
||||
}
|
||||
|
||||
func (s *Store) StagingCleanup(ctx context.Context) ([]model.Attachment, error) {
|
||||
rows, e := s.q.StagingCleanup(ctx)
|
||||
if e != nil {
|
||||
return nil, mapErr(e)
|
||||
}
|
||||
out := make([]model.Attachment, len(rows))
|
||||
for i, r := range rows {
|
||||
out[i] = attachment(r)
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
func (s *Store) StagingCleaned(ctx context.Context, id uuid.UUID) error {
|
||||
return mapErr(s.q.StagingCleaned(ctx, id))
|
||||
}
|
||||
@@ -0,0 +1,331 @@
|
||||
package postgres
|
||||
|
||||
import (
|
||||
"backend/internal/adapter/storage"
|
||||
"backend/internal/application/usecase"
|
||||
"backend/internal/config"
|
||||
"backend/internal/domain/model"
|
||||
"backend/internal/domain/port"
|
||||
"bytes"
|
||||
"context"
|
||||
"crypto/sha256"
|
||||
"encoding/hex"
|
||||
"errors"
|
||||
"github.com/google/uuid"
|
||||
"github.com/jackc/pgx/v5/pgxpool"
|
||||
"io"
|
||||
"os"
|
||||
"reflect"
|
||||
"sync"
|
||||
"syscall"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestReplayAfterCompletedPreviousVersionCleanup(t *testing.T) {
|
||||
if os.Getenv("RUN_PIPELINE_DB_TESTS") != "1" {
|
||||
t.Skip("explicit isolated database required")
|
||||
}
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 20*time.Second)
|
||||
defer cancel()
|
||||
raw, e := config.ReadSecret("/run/secrets/database_url")
|
||||
if e != nil {
|
||||
t.Fatal("database file unavailable")
|
||||
}
|
||||
pool, e := pgxpool.New(ctx, raw)
|
||||
if e != nil {
|
||||
t.Fatal("database connection unavailable")
|
||||
}
|
||||
defer pool.Close()
|
||||
s := New(pool, nil)
|
||||
user, e := s.CreateUser(ctx, model.UserDraft{Username: "v2_" + uuid.NewString()[:8], DisplayName: "Synthetic version test", PasswordHash: "disabled-synthetic"})
|
||||
if e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
var chatID, attachmentID uuid.UUID
|
||||
defer func() {
|
||||
cleanup, c := context.WithTimeout(context.Background(), 5*time.Second)
|
||||
defer c()
|
||||
for _, q := range []struct {
|
||||
sql string
|
||||
id uuid.UUID
|
||||
}{{"DELETE FROM attachment_jobs WHERE attachment_id=$1", attachmentID}, {"DELETE FROM attachments WHERE id=$1", attachmentID}, {"DELETE FROM chat_members WHERE chat_id=$1", chatID}, {"DELETE FROM chats WHERE id=$1", chatID}, {"DELETE FROM users WHERE id=$1", user.ID}} {
|
||||
if _, e := pool.Exec(cleanup, q.sql, q.id); e != nil {
|
||||
t.Error("version fixture cleanup failed")
|
||||
}
|
||||
}
|
||||
}()
|
||||
chat, e := s.CreateChat(ctx, model.ChatDraft{Title: "Owned version fixture", Creator: user.ID, MemberIDs: []uuid.UUID{user.ID}})
|
||||
if e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
chatID = chat.ID
|
||||
attachmentID = uuid.New()
|
||||
a, e := s.ReserveAttachment(ctx, model.Attachment{ID: attachmentID, ChatID: chatID, OwnerID: user.ID, Filename: "test.png", ContentType: "image/png", SizeBytes: 3, SHA256: "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"})
|
||||
if e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
if _, e = s.QueueAttachment(ctx, a, "", ""); e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
jobs, e := s.PendingJobs(ctx)
|
||||
if e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
var j model.Job
|
||||
for _, candidate := range jobs {
|
||||
if candidate.AttachmentID == attachmentID {
|
||||
j = candidate
|
||||
}
|
||||
}
|
||||
lease := uuid.New()
|
||||
j, _, ok, e := s.AcquireJob(ctx, j, lease, 30*time.Second)
|
||||
if e != nil || !ok {
|
||||
t.Fatal("version1 acquisition failed")
|
||||
}
|
||||
if ok, e = s.CompleteJob(ctx, j, lease, []model.Variant{}); e != nil || !ok {
|
||||
t.Fatal("version1 completion failed")
|
||||
}
|
||||
if _, e = s.StagingCleanup(ctx); e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
if e = s.StagingCleaned(ctx, attachmentID); e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
if ok, e = s.AdvancePipeline(ctx, attachmentID); e != nil || !ok {
|
||||
t.Fatal("version2 advance failed")
|
||||
}
|
||||
jobs, e = s.PendingJobs(ctx)
|
||||
if e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
for _, candidate := range jobs {
|
||||
if candidate.AttachmentID == attachmentID && candidate.PipelineVersion == 2 {
|
||||
j = candidate
|
||||
}
|
||||
}
|
||||
lease = uuid.New()
|
||||
j, _, ok, e = s.AcquireJob(ctx, j, lease, 30*time.Second)
|
||||
if e != nil || !ok {
|
||||
t.Fatal("version2 acquisition failed")
|
||||
}
|
||||
if e = s.RetryJob(ctx, j, lease, "retry_exhausted", 0, true); e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
ok, e = s.ReplayJob(ctx, attachmentID)
|
||||
if e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
if !ok {
|
||||
t.Fatal("ready version1 staging cleanup permanently blocked replay of failed version2 despite retained original")
|
||||
}
|
||||
var replays int
|
||||
var replayed time.Time
|
||||
if e = pool.QueryRow(ctx, "SELECT replay_count,replayed_at FROM attachment_jobs WHERE attachment_id=$1 AND pipeline_version=2", attachmentID).Scan(&replays, &replayed); e != nil || replays != 1 || replayed.IsZero() {
|
||||
t.Fatal("explicit replay has no durable audit count/timestamp")
|
||||
}
|
||||
}
|
||||
|
||||
// This deterministic transformer makes v1/v2 effects distinguishable; the Store,
|
||||
// pipeline ownership/leases, transactions and S3 operations remain real.
|
||||
type versionTransformer struct {
|
||||
body string
|
||||
err error
|
||||
}
|
||||
|
||||
func (v versionTransformer) Transform(context.Context, io.Reader) ([]port.ProcessedVariant, error) {
|
||||
if v.err != nil {
|
||||
return nil, v.err
|
||||
}
|
||||
out := []port.ProcessedVariant{}
|
||||
for _, name := range []string{"thumbnail", "crop", "optimized"} {
|
||||
body := []byte(v.body + name)
|
||||
sum := sha256.Sum256(body)
|
||||
out = append(out, port.ProcessedVariant{Metadata: model.Variant{Name: name, ContentType: "image/jpeg", SHA256: hex.EncodeToString(sum[:]), SizeBytes: int64(len(body)), Width: 1, Height: 1}, Bytes: body})
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
func TestVersionedPipelineDuplicateReorderRetryAndCleanup(t *testing.T) {
|
||||
if os.Getenv("RUN_PIPELINE_DB_TESTS") != "1" {
|
||||
t.Skip("explicit isolated database and S3 required")
|
||||
}
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 40*time.Second)
|
||||
defer cancel()
|
||||
raw, e := config.ReadSecret("/run/secrets/database_url")
|
||||
if e != nil {
|
||||
t.Fatal("database file unavailable")
|
||||
}
|
||||
pool, e := pgxpool.New(ctx, raw)
|
||||
if e != nil {
|
||||
t.Fatal("database unavailable")
|
||||
}
|
||||
defer pool.Close()
|
||||
s := New(pool, nil)
|
||||
cfg, e := storage.ReadConfig("/run/secrets/s3_credentials")
|
||||
if e != nil {
|
||||
t.Fatal("S3 config unavailable")
|
||||
}
|
||||
objects, e := storage.FromConfig(cfg)
|
||||
if e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
user, e := s.CreateUser(ctx, model.UserDraft{Username: "matrix_" + uuid.NewString()[:8], DisplayName: "Synthetic fault matrix", PasswordHash: "disabled"})
|
||||
if e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
chat, e := s.CreateChat(ctx, model.ChatDraft{Title: "Owned pipeline matrix", Creator: user.ID, MemberIDs: []uuid.UUID{user.ID}})
|
||||
if e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
id := uuid.New()
|
||||
body := []byte("immutable-original")
|
||||
sum := sha256.Sum256(body)
|
||||
defer func() {
|
||||
c, stop := context.WithTimeout(context.Background(), 5*time.Second)
|
||||
defer stop()
|
||||
for _, key := range []string{"staging/" + id.String(), usecase.ObjectKey(id)} {
|
||||
if e := objects.Remove(c, key); e != nil {
|
||||
t.Error("object fixture cleanup failed")
|
||||
}
|
||||
}
|
||||
for version := int32(1); version <= 3; version++ {
|
||||
for _, name := range []string{"thumbnail", "crop", "optimized"} {
|
||||
if e := objects.Remove(c, usecase.VariantKey(id, version, name)); e != nil {
|
||||
t.Error("variant fixture cleanup failed")
|
||||
}
|
||||
}
|
||||
}
|
||||
for _, q := range []struct {
|
||||
sql string
|
||||
id uuid.UUID
|
||||
}{{"DELETE FROM attachment_jobs WHERE attachment_id=$1", id}, {"DELETE FROM attachments WHERE id=$1", id}, {"DELETE FROM chat_members WHERE chat_id=$1", chat.ID}, {"DELETE FROM chats WHERE id=$1", chat.ID}, {"DELETE FROM users WHERE id=$1", user.ID}} {
|
||||
if _, e := pool.Exec(c, q.sql, q.id); e != nil {
|
||||
t.Error("database fixture cleanup failed")
|
||||
}
|
||||
}
|
||||
}()
|
||||
a, e := s.ReserveAttachment(ctx, model.Attachment{ID: id, ChatID: chat.ID, OwnerID: user.ID, Filename: "matrix.png", ContentType: "image/png", SizeBytes: int64(len(body)), SHA256: hex.EncodeToString(sum[:])})
|
||||
if e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
if e = objects.Put(ctx, "staging/"+id.String(), bytes.NewReader(body), int64(len(body)), "image/png"); e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
if _, e = s.QueueAttachment(ctx, a, "", ""); e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
next := func(version int32) model.Job {
|
||||
t.Helper()
|
||||
jobs, e := s.PendingJobs(ctx)
|
||||
if e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
for _, j := range jobs {
|
||||
if j.AttachmentID == id && j.PipelineVersion == version {
|
||||
return j
|
||||
}
|
||||
}
|
||||
t.Fatal("owned current job not found")
|
||||
return model.Job{}
|
||||
}
|
||||
j1 := next(1)
|
||||
p1 := usecase.NewPipeline(s, objects, versionTransformer{body: "version1-"}, 5)
|
||||
p1.Fault = func(point string) error {
|
||||
if point == "after_commit" {
|
||||
return errors.New("synthetic crash after commit")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
if e = p1.Process(ctx, j1); e == nil {
|
||||
t.Fatal("fault did not interrupt after commit")
|
||||
}
|
||||
a, e = s.GetAttachment(ctx, id)
|
||||
if e != nil || a.Status != "ready" || a.StagingCleaned {
|
||||
t.Fatal("commit fault did not preserve ready/pending cleanup")
|
||||
}
|
||||
if e = p1.Process(ctx, j1); e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
if _, e = objects.Get(ctx, "staging/"+id.String()); !errors.Is(e, model.ErrNotFound) {
|
||||
t.Fatal("completed redelivery did not remove staging")
|
||||
}
|
||||
if ok, e := s.AdvancePipeline(ctx, id); e != nil || !ok {
|
||||
t.Fatal("advance v2 failed")
|
||||
}
|
||||
j2 := next(2)
|
||||
// Old delivery arriving before v2 and a fabricated future delivery are no-ops.
|
||||
if e = p1.Process(ctx, j1); e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
future := j2
|
||||
future.PipelineVersion = 3
|
||||
if e = p1.Process(ctx, future); e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
p2 := usecase.NewPipeline(s, objects, versionTransformer{body: "version2-"}, 5)
|
||||
var group sync.WaitGroup
|
||||
errs := make(chan error, 2)
|
||||
for i := 0; i < 2; i++ {
|
||||
group.Add(1)
|
||||
go func() { defer group.Done(); errs <- p2.Process(ctx, j2) }()
|
||||
}
|
||||
group.Wait()
|
||||
close(errs)
|
||||
for e := range errs {
|
||||
if e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
}
|
||||
a, e = s.GetAttachment(ctx, id)
|
||||
if e != nil || a.PipelineVersion != 2 || a.Status != "ready" || len(a.Variants) != 3 {
|
||||
t.Fatal("duplicate current job lost result")
|
||||
}
|
||||
snapshot := a.Variants
|
||||
for _, j := range []model.Job{j1, j2, j1, future, j2} {
|
||||
if e = p1.Process(ctx, j); e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
}
|
||||
a, e = s.GetAttachment(ctx, id)
|
||||
if e != nil || !reflect.DeepEqual(snapshot, a.Variants) {
|
||||
t.Fatal("stale or duplicate job overwrote current metadata")
|
||||
}
|
||||
for _, v := range a.Variants {
|
||||
r, e := objects.Get(ctx, usecase.VariantKey(id, 2, v.Name))
|
||||
if e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
got, e := io.ReadAll(r)
|
||||
r.Close()
|
||||
if e != nil || string(got) != "version2-"+v.Name {
|
||||
t.Fatal("old transformation overwrote v2 objects")
|
||||
}
|
||||
}
|
||||
if ok, e := s.AdvancePipeline(ctx, id); e != nil || !ok {
|
||||
t.Fatal("advance v3 failed")
|
||||
}
|
||||
j3 := next(3)
|
||||
broken := usecase.NewPipeline(s, objects, versionTransformer{err: syscall.ENOSPC}, 5)
|
||||
for i := 0; i < 5; i++ {
|
||||
if _, e = pool.Exec(ctx, "UPDATE attachment_jobs SET next_attempt='epoch' WHERE id=$1", j3.ID); e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
if e = broken.Process(ctx, j3); e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
}
|
||||
a, e = s.GetAttachment(ctx, id)
|
||||
if e != nil || a.Status != "failed" || a.ErrorCode != "retry_exhausted" {
|
||||
t.Fatal("transient infrastructure failure did not exhaust bounded retry")
|
||||
}
|
||||
if ok, e := s.ReplayJob(ctx, id); e != nil || !ok {
|
||||
t.Fatal("explicit replay blocked despite retained immutable source")
|
||||
}
|
||||
if e = p2.Process(ctx, j3); e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
a, e = s.GetAttachment(ctx, id)
|
||||
if e != nil || a.Status != "ready" || a.PipelineVersion != 3 {
|
||||
t.Fatal("replayed job did not recover")
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,199 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.31.1
|
||||
// source: attachments.sql
|
||||
|
||||
package queries
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
const chargeAttachment = `-- name: ChargeAttachment :one
|
||||
UPDATE users SET attachment_count=attachment_count+1 WHERE id=$1 AND attachment_count<10000 RETURNING id
|
||||
`
|
||||
|
||||
func (q *Queries) ChargeAttachment(ctx context.Context, id uuid.UUID) (uuid.UUID, error) {
|
||||
row := q.db.QueryRow(ctx, chargeAttachment, id)
|
||||
var id_2 uuid.UUID
|
||||
err := row.Scan(&id_2)
|
||||
return id_2, err
|
||||
}
|
||||
|
||||
const getAttachment = `-- name: GetAttachment :one
|
||||
SELECT id, chat_id, owner_id, filename, content_type, size_bytes, sha256, status, pipeline_version, error_code, variants, staging_expired, staging_cleaned, created_at, updated_at, accepted_at, first_ready_at FROM attachments WHERE id=$1 FOR SHARE
|
||||
`
|
||||
|
||||
func (q *Queries) GetAttachment(ctx context.Context, id uuid.UUID) (Attachment, error) {
|
||||
row := q.db.QueryRow(ctx, getAttachment, id)
|
||||
var i Attachment
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.ChatID,
|
||||
&i.OwnerID,
|
||||
&i.Filename,
|
||||
&i.ContentType,
|
||||
&i.SizeBytes,
|
||||
&i.Sha256,
|
||||
&i.Status,
|
||||
&i.PipelineVersion,
|
||||
&i.ErrorCode,
|
||||
&i.Variants,
|
||||
&i.StagingExpired,
|
||||
&i.StagingCleaned,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
&i.AcceptedAt,
|
||||
&i.FirstReadyAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const insertAttachment = `-- name: InsertAttachment :one
|
||||
INSERT INTO attachments(id,chat_id,owner_id,filename,content_type,size_bytes,sha256,status)
|
||||
VALUES($1,$2,$3,$4,$5,$6,$7,'uploading') RETURNING id, chat_id, owner_id, filename, content_type, size_bytes, sha256, status, pipeline_version, error_code, variants, staging_expired, staging_cleaned, created_at, updated_at, accepted_at, first_ready_at
|
||||
`
|
||||
|
||||
type InsertAttachmentParams struct {
|
||||
ID uuid.UUID
|
||||
ChatID uuid.UUID
|
||||
OwnerID uuid.UUID
|
||||
Filename string
|
||||
ContentType string
|
||||
SizeBytes int64
|
||||
Sha256 string
|
||||
}
|
||||
|
||||
func (q *Queries) InsertAttachment(ctx context.Context, arg InsertAttachmentParams) (Attachment, error) {
|
||||
row := q.db.QueryRow(ctx, insertAttachment,
|
||||
arg.ID,
|
||||
arg.ChatID,
|
||||
arg.OwnerID,
|
||||
arg.Filename,
|
||||
arg.ContentType,
|
||||
arg.SizeBytes,
|
||||
arg.Sha256,
|
||||
)
|
||||
var i Attachment
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.ChatID,
|
||||
&i.OwnerID,
|
||||
&i.Filename,
|
||||
&i.ContentType,
|
||||
&i.SizeBytes,
|
||||
&i.Sha256,
|
||||
&i.Status,
|
||||
&i.PipelineVersion,
|
||||
&i.ErrorCode,
|
||||
&i.Variants,
|
||||
&i.StagingExpired,
|
||||
&i.StagingCleaned,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
&i.AcceptedAt,
|
||||
&i.FirstReadyAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const insertMessageAttachment = `-- name: InsertMessageAttachment :exec
|
||||
INSERT INTO message_attachments(message_id,attachment_id,ordinal) VALUES($1,$2,$3)
|
||||
`
|
||||
|
||||
type InsertMessageAttachmentParams struct {
|
||||
MessageID uuid.UUID
|
||||
AttachmentID uuid.UUID
|
||||
Ordinal int32
|
||||
}
|
||||
|
||||
func (q *Queries) InsertMessageAttachment(ctx context.Context, arg InsertMessageAttachmentParams) error {
|
||||
_, err := q.db.Exec(ctx, insertMessageAttachment, arg.MessageID, arg.AttachmentID, arg.Ordinal)
|
||||
return err
|
||||
}
|
||||
|
||||
const messageAttachments = `-- name: MessageAttachments :many
|
||||
SELECT attachment_id FROM message_attachments WHERE message_id=$1 ORDER BY ordinal LIMIT 10
|
||||
`
|
||||
|
||||
func (q *Queries) MessageAttachments(ctx context.Context, messageID uuid.UUID) ([]uuid.UUID, error) {
|
||||
rows, err := q.db.Query(ctx, messageAttachments, messageID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
items := []uuid.UUID{}
|
||||
for rows.Next() {
|
||||
var attachment_id uuid.UUID
|
||||
if err := rows.Scan(&attachment_id); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, attachment_id)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const reconcileAttachments = `-- name: ReconcileAttachments :many
|
||||
SELECT id, chat_id, owner_id, filename, content_type, size_bytes, sha256, status, pipeline_version, error_code, variants, staging_expired, staging_cleaned, created_at, updated_at, accepted_at, first_ready_at FROM attachments WHERE id>$1 ORDER BY id LIMIT 101
|
||||
`
|
||||
|
||||
func (q *Queries) ReconcileAttachments(ctx context.Context, id uuid.UUID) ([]Attachment, error) {
|
||||
rows, err := q.db.Query(ctx, reconcileAttachments, id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
items := []Attachment{}
|
||||
for rows.Next() {
|
||||
var i Attachment
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.ChatID,
|
||||
&i.OwnerID,
|
||||
&i.Filename,
|
||||
&i.ContentType,
|
||||
&i.SizeBytes,
|
||||
&i.Sha256,
|
||||
&i.Status,
|
||||
&i.PipelineVersion,
|
||||
&i.ErrorCode,
|
||||
&i.Variants,
|
||||
&i.StagingExpired,
|
||||
&i.StagingCleaned,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
&i.AcceptedAt,
|
||||
&i.FirstReadyAt,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const setAttachmentStatus = `-- name: SetAttachmentStatus :execrows
|
||||
UPDATE attachments SET status=$2,updated_at=clock_timestamp() WHERE id=$1 AND status=$3 AND pipeline_version=0
|
||||
`
|
||||
|
||||
type SetAttachmentStatusParams struct {
|
||||
ID uuid.UUID
|
||||
Status string
|
||||
Status_2 string
|
||||
}
|
||||
|
||||
func (q *Queries) SetAttachmentStatus(ctx context.Context, arg SetAttachmentStatusParams) (int64, error) {
|
||||
result, err := q.db.Exec(ctx, setAttachmentStatus, arg.ID, arg.Status, arg.Status_2)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return result.RowsAffected(), nil
|
||||
}
|
||||
@@ -0,0 +1,358 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.31.1
|
||||
// source: core.sql
|
||||
|
||||
package queries
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
const authenticateSession = `-- name: AuthenticateSession :one
|
||||
SELECT user_id FROM sessions WHERE token_hash=$1 AND expires_at>clock_timestamp()
|
||||
`
|
||||
|
||||
func (q *Queries) AuthenticateSession(ctx context.Context, tokenHash string) (uuid.UUID, error) {
|
||||
row := q.db.QueryRow(ctx, authenticateSession, tokenHash)
|
||||
var user_id uuid.UUID
|
||||
err := row.Scan(&user_id)
|
||||
return user_id, err
|
||||
}
|
||||
|
||||
const chargeChat = `-- name: ChargeChat :one
|
||||
UPDATE users SET chat_count=chat_count+1 WHERE id=$1 AND chat_count<1000 RETURNING id
|
||||
`
|
||||
|
||||
func (q *Queries) ChargeChat(ctx context.Context, id uuid.UUID) (uuid.UUID, error) {
|
||||
row := q.db.QueryRow(ctx, chargeChat, id)
|
||||
var id_2 uuid.UUID
|
||||
err := row.Scan(&id_2)
|
||||
return id_2, err
|
||||
}
|
||||
|
||||
const chargeMessage = `-- name: ChargeMessage :one
|
||||
UPDATE users SET message_count=message_count+1 WHERE id=$1 AND message_count<1000000 RETURNING id
|
||||
`
|
||||
|
||||
func (q *Queries) ChargeMessage(ctx context.Context, id uuid.UUID) (uuid.UUID, error) {
|
||||
row := q.db.QueryRow(ctx, chargeMessage, id)
|
||||
var id_2 uuid.UUID
|
||||
err := row.Scan(&id_2)
|
||||
return id_2, err
|
||||
}
|
||||
|
||||
const createUser = `-- name: CreateUser :one
|
||||
INSERT INTO users(id,username,display_name,password_hash) VALUES($1,$2,$3,$4)
|
||||
RETURNING id,username,display_name,created_at
|
||||
`
|
||||
|
||||
type CreateUserParams struct {
|
||||
ID uuid.UUID
|
||||
Username string
|
||||
DisplayName string
|
||||
PasswordHash string
|
||||
}
|
||||
|
||||
type CreateUserRow struct {
|
||||
ID uuid.UUID
|
||||
Username string
|
||||
DisplayName string
|
||||
CreatedAt time.Time
|
||||
}
|
||||
|
||||
func (q *Queries) CreateUser(ctx context.Context, arg CreateUserParams) (CreateUserRow, error) {
|
||||
row := q.db.QueryRow(ctx, createUser,
|
||||
arg.ID,
|
||||
arg.Username,
|
||||
arg.DisplayName,
|
||||
arg.PasswordHash,
|
||||
)
|
||||
var i CreateUserRow
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.Username,
|
||||
&i.DisplayName,
|
||||
&i.CreatedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const credentials = `-- name: Credentials :one
|
||||
SELECT id,password_hash FROM users WHERE username=$1
|
||||
`
|
||||
|
||||
type CredentialsRow struct {
|
||||
ID uuid.UUID
|
||||
PasswordHash string
|
||||
}
|
||||
|
||||
func (q *Queries) Credentials(ctx context.Context, username string) (CredentialsRow, error) {
|
||||
row := q.db.QueryRow(ctx, credentials, username)
|
||||
var i CredentialsRow
|
||||
err := row.Scan(&i.ID, &i.PasswordHash)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const deleteExpiredSessions = `-- name: DeleteExpiredSessions :exec
|
||||
DELETE FROM sessions WHERE user_id=$1 AND expires_at<=clock_timestamp()
|
||||
`
|
||||
|
||||
func (q *Queries) DeleteExpiredSessions(ctx context.Context, userID uuid.UUID) error {
|
||||
_, err := q.db.Exec(ctx, deleteExpiredSessions, userID)
|
||||
return err
|
||||
}
|
||||
|
||||
const getChat = `-- name: GetChat :one
|
||||
SELECT c.id,c.title,c.created_at,ARRAY(SELECT user_id FROM chat_members WHERE chat_id=c.id ORDER BY user_id)::uuid[] AS members
|
||||
FROM chats c WHERE c.id=$1
|
||||
`
|
||||
|
||||
type GetChatRow struct {
|
||||
ID uuid.UUID
|
||||
Title string
|
||||
CreatedAt time.Time
|
||||
Members []uuid.UUID
|
||||
}
|
||||
|
||||
func (q *Queries) GetChat(ctx context.Context, id uuid.UUID) (GetChatRow, error) {
|
||||
row := q.db.QueryRow(ctx, getChat, id)
|
||||
var i GetChatRow
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.Title,
|
||||
&i.CreatedAt,
|
||||
&i.Members,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const getUser = `-- name: GetUser :one
|
||||
SELECT id,username,display_name,created_at FROM users WHERE id=$1
|
||||
`
|
||||
|
||||
type GetUserRow struct {
|
||||
ID uuid.UUID
|
||||
Username string
|
||||
DisplayName string
|
||||
CreatedAt time.Time
|
||||
}
|
||||
|
||||
func (q *Queries) GetUser(ctx context.Context, id uuid.UUID) (GetUserRow, error) {
|
||||
row := q.db.QueryRow(ctx, getUser, id)
|
||||
var i GetUserRow
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.Username,
|
||||
&i.DisplayName,
|
||||
&i.CreatedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const insertChat = `-- name: InsertChat :one
|
||||
INSERT INTO chats(id,title) VALUES($1,$2) RETURNING id,title,created_at
|
||||
`
|
||||
|
||||
type InsertChatParams struct {
|
||||
ID uuid.UUID
|
||||
Title string
|
||||
}
|
||||
|
||||
func (q *Queries) InsertChat(ctx context.Context, arg InsertChatParams) (Chat, error) {
|
||||
row := q.db.QueryRow(ctx, insertChat, arg.ID, arg.Title)
|
||||
var i Chat
|
||||
err := row.Scan(&i.ID, &i.Title, &i.CreatedAt)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const insertMembers = `-- name: InsertMembers :exec
|
||||
INSERT INTO chat_members(chat_id,user_id) SELECT $1,unnest($2::uuid[])
|
||||
`
|
||||
|
||||
type InsertMembersParams struct {
|
||||
ChatID uuid.UUID
|
||||
Column2 []uuid.UUID
|
||||
}
|
||||
|
||||
func (q *Queries) InsertMembers(ctx context.Context, arg InsertMembersParams) error {
|
||||
_, err := q.db.Exec(ctx, insertMembers, arg.ChatID, arg.Column2)
|
||||
return err
|
||||
}
|
||||
|
||||
const insertMessage = `-- name: InsertMessage :one
|
||||
INSERT INTO messages(id,chat_id,sender_id,text) VALUES($1,$2,$3,$4) RETURNING id,chat_id,sender_id,text,created_at
|
||||
`
|
||||
|
||||
type InsertMessageParams struct {
|
||||
ID uuid.UUID
|
||||
ChatID uuid.UUID
|
||||
SenderID uuid.UUID
|
||||
Text string
|
||||
}
|
||||
|
||||
func (q *Queries) InsertMessage(ctx context.Context, arg InsertMessageParams) (Message, error) {
|
||||
row := q.db.QueryRow(ctx, insertMessage,
|
||||
arg.ID,
|
||||
arg.ChatID,
|
||||
arg.SenderID,
|
||||
arg.Text,
|
||||
)
|
||||
var i Message
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.ChatID,
|
||||
&i.SenderID,
|
||||
&i.Text,
|
||||
&i.CreatedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const insertSession = `-- name: InsertSession :one
|
||||
INSERT INTO sessions(token_hash,user_id,expires_at)
|
||||
SELECT $1,$2,$3 WHERE (SELECT count(*) FROM sessions WHERE user_id=$2)<100
|
||||
RETURNING user_id
|
||||
`
|
||||
|
||||
type InsertSessionParams struct {
|
||||
TokenHash string
|
||||
UserID uuid.UUID
|
||||
ExpiresAt time.Time
|
||||
}
|
||||
|
||||
func (q *Queries) InsertSession(ctx context.Context, arg InsertSessionParams) (uuid.UUID, error) {
|
||||
row := q.db.QueryRow(ctx, insertSession, arg.TokenHash, arg.UserID, arg.ExpiresAt)
|
||||
var user_id uuid.UUID
|
||||
err := row.Scan(&user_id)
|
||||
return user_id, err
|
||||
}
|
||||
|
||||
const listChats = `-- name: ListChats :many
|
||||
SELECT c.id,c.title,c.created_at,ARRAY(SELECT user_id FROM chat_members WHERE chat_id=c.id ORDER BY user_id)::uuid[] AS members
|
||||
FROM chats c JOIN chat_members m ON m.chat_id=c.id
|
||||
WHERE m.user_id=$1 AND (c.created_at,c.id)>($2::timestamptz,$3::uuid)
|
||||
ORDER BY c.created_at,c.id LIMIT $4
|
||||
`
|
||||
|
||||
type ListChatsParams struct {
|
||||
MemberID uuid.UUID
|
||||
AfterTime time.Time
|
||||
AfterID uuid.UUID
|
||||
PageLimit int32
|
||||
}
|
||||
|
||||
type ListChatsRow struct {
|
||||
ID uuid.UUID
|
||||
Title string
|
||||
CreatedAt time.Time
|
||||
Members []uuid.UUID
|
||||
}
|
||||
|
||||
func (q *Queries) ListChats(ctx context.Context, arg ListChatsParams) ([]ListChatsRow, error) {
|
||||
rows, err := q.db.Query(ctx, listChats,
|
||||
arg.MemberID,
|
||||
arg.AfterTime,
|
||||
arg.AfterID,
|
||||
arg.PageLimit,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
items := []ListChatsRow{}
|
||||
for rows.Next() {
|
||||
var i ListChatsRow
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.Title,
|
||||
&i.CreatedAt,
|
||||
&i.Members,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const listMessages = `-- name: ListMessages :many
|
||||
SELECT m.id,m.chat_id,m.sender_id,m.text,m.created_at,
|
||||
ARRAY(SELECT attachment_id FROM message_attachments WHERE message_id=m.id ORDER BY ordinal LIMIT 10)::uuid[] AS attachment_ids
|
||||
FROM messages m WHERE m.chat_id=$1 AND (m.created_at,m.id)>($2::timestamptz,$3::uuid)
|
||||
ORDER BY m.created_at,m.id LIMIT $4
|
||||
`
|
||||
|
||||
type ListMessagesParams struct {
|
||||
ChatID uuid.UUID
|
||||
AfterTime time.Time
|
||||
AfterID uuid.UUID
|
||||
PageLimit int32
|
||||
}
|
||||
|
||||
type ListMessagesRow struct {
|
||||
ID uuid.UUID
|
||||
ChatID uuid.UUID
|
||||
SenderID uuid.UUID
|
||||
Text string
|
||||
CreatedAt time.Time
|
||||
AttachmentIds []uuid.UUID
|
||||
}
|
||||
|
||||
func (q *Queries) ListMessages(ctx context.Context, arg ListMessagesParams) ([]ListMessagesRow, error) {
|
||||
rows, err := q.db.Query(ctx, listMessages,
|
||||
arg.ChatID,
|
||||
arg.AfterTime,
|
||||
arg.AfterID,
|
||||
arg.PageLimit,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
items := []ListMessagesRow{}
|
||||
for rows.Next() {
|
||||
var i ListMessagesRow
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.ChatID,
|
||||
&i.SenderID,
|
||||
&i.Text,
|
||||
&i.CreatedAt,
|
||||
&i.AttachmentIds,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const lockSessionOwner = `-- name: LockSessionOwner :one
|
||||
SELECT id FROM users WHERE id=$1 FOR UPDATE
|
||||
`
|
||||
|
||||
func (q *Queries) LockSessionOwner(ctx context.Context, id uuid.UUID) (uuid.UUID, error) {
|
||||
row := q.db.QueryRow(ctx, lockSessionOwner, id)
|
||||
var id_2 uuid.UUID
|
||||
err := row.Scan(&id_2)
|
||||
return id_2, err
|
||||
}
|
||||
|
||||
const revokeSession = `-- name: RevokeSession :exec
|
||||
DELETE FROM sessions WHERE token_hash=$1
|
||||
`
|
||||
|
||||
func (q *Queries) RevokeSession(ctx context.Context, tokenHash string) error {
|
||||
_, err := q.db.Exec(ctx, revokeSession, tokenHash)
|
||||
return err
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.31.1
|
||||
|
||||
package queries
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/jackc/pgx/v5"
|
||||
"github.com/jackc/pgx/v5/pgconn"
|
||||
)
|
||||
|
||||
type DBTX interface {
|
||||
Exec(context.Context, string, ...interface{}) (pgconn.CommandTag, error)
|
||||
Query(context.Context, string, ...interface{}) (pgx.Rows, error)
|
||||
QueryRow(context.Context, string, ...interface{}) pgx.Row
|
||||
}
|
||||
|
||||
func New(db DBTX) *Queries {
|
||||
return &Queries{db: db}
|
||||
}
|
||||
|
||||
type Queries struct {
|
||||
db DBTX
|
||||
}
|
||||
|
||||
func (q *Queries) WithTx(tx pgx.Tx) *Queries {
|
||||
return &Queries{
|
||||
db: tx,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.31.1
|
||||
// source: idempotency.sql
|
||||
|
||||
package queries
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
const replayMessage = `-- name: ReplayMessage :one
|
||||
SELECT m.id,m.chat_id,m.sender_id,m.text,m.created_at,i.payload_hash,
|
||||
ARRAY(SELECT attachment_id FROM message_attachments WHERE message_id=m.id ORDER BY ordinal LIMIT 10)::uuid[] AS attachment_ids
|
||||
FROM idempotency i JOIN messages m ON m.id=i.message_id
|
||||
WHERE i.user_id=$1 AND i.chat_id=$2 AND i.key=$3
|
||||
`
|
||||
|
||||
type ReplayMessageParams struct {
|
||||
UserID uuid.UUID
|
||||
ChatID uuid.UUID
|
||||
Key string
|
||||
}
|
||||
|
||||
type ReplayMessageRow struct {
|
||||
ID uuid.UUID
|
||||
ChatID uuid.UUID
|
||||
SenderID uuid.UUID
|
||||
Text string
|
||||
CreatedAt time.Time
|
||||
PayloadHash string
|
||||
AttachmentIds []uuid.UUID
|
||||
}
|
||||
|
||||
func (q *Queries) ReplayMessage(ctx context.Context, arg ReplayMessageParams) (ReplayMessageRow, error) {
|
||||
row := q.db.QueryRow(ctx, replayMessage, arg.UserID, arg.ChatID, arg.Key)
|
||||
var i ReplayMessageRow
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.ChatID,
|
||||
&i.SenderID,
|
||||
&i.Text,
|
||||
&i.CreatedAt,
|
||||
&i.PayloadHash,
|
||||
&i.AttachmentIds,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const reserveKey = `-- name: ReserveKey :one
|
||||
INSERT INTO idempotency(user_id,chat_id,key,payload_hash,message_id,expires_at)
|
||||
VALUES($1,$2,$3,$4,$5,clock_timestamp()+interval '24 hours')
|
||||
ON CONFLICT(user_id,chat_id,key) DO UPDATE SET payload_hash=excluded.payload_hash,
|
||||
message_id=excluded.message_id,expires_at=excluded.expires_at
|
||||
WHERE idempotency.expires_at<=clock_timestamp()
|
||||
RETURNING message_id
|
||||
`
|
||||
|
||||
type ReserveKeyParams struct {
|
||||
UserID uuid.UUID
|
||||
ChatID uuid.UUID
|
||||
Key string
|
||||
PayloadHash string
|
||||
MessageID uuid.UUID
|
||||
}
|
||||
|
||||
func (q *Queries) ReserveKey(ctx context.Context, arg ReserveKeyParams) (uuid.UUID, error) {
|
||||
row := q.db.QueryRow(ctx, reserveKey,
|
||||
arg.UserID,
|
||||
arg.ChatID,
|
||||
arg.Key,
|
||||
arg.PayloadHash,
|
||||
arg.MessageID,
|
||||
)
|
||||
var message_id uuid.UUID
|
||||
err := row.Scan(&message_id)
|
||||
return message_id, err
|
||||
}
|
||||
@@ -0,0 +1,106 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.31.1
|
||||
|
||||
package queries
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
)
|
||||
|
||||
type Attachment struct {
|
||||
ID uuid.UUID
|
||||
ChatID uuid.UUID
|
||||
OwnerID uuid.UUID
|
||||
Filename string
|
||||
ContentType string
|
||||
SizeBytes int64
|
||||
Sha256 string
|
||||
Status string
|
||||
PipelineVersion int32
|
||||
ErrorCode string
|
||||
Variants []byte
|
||||
StagingExpired bool
|
||||
StagingCleaned bool
|
||||
CreatedAt time.Time
|
||||
UpdatedAt time.Time
|
||||
AcceptedAt pgtype.Timestamptz
|
||||
FirstReadyAt pgtype.Timestamptz
|
||||
}
|
||||
|
||||
type AttachmentJob struct {
|
||||
ID uuid.UUID
|
||||
AttachmentID uuid.UUID
|
||||
PipelineVersion int32
|
||||
Attempt int32
|
||||
Traceparent string
|
||||
Tracestate string
|
||||
LeaseID uuid.UUID
|
||||
LeaseUntil time.Time
|
||||
NextAttempt time.Time
|
||||
PublishedAt time.Time
|
||||
Completed bool
|
||||
CreatedAt time.Time
|
||||
ReplayCount int64
|
||||
ReplayedAt time.Time
|
||||
}
|
||||
|
||||
type Chat struct {
|
||||
ID uuid.UUID
|
||||
Title string
|
||||
CreatedAt time.Time
|
||||
}
|
||||
|
||||
type ChatMember struct {
|
||||
ChatID uuid.UUID
|
||||
UserID uuid.UUID
|
||||
}
|
||||
|
||||
type Idempotency struct {
|
||||
UserID uuid.UUID
|
||||
ChatID uuid.UUID
|
||||
Key string
|
||||
PayloadHash string
|
||||
MessageID uuid.UUID
|
||||
ExpiresAt time.Time
|
||||
}
|
||||
|
||||
type LoginLimit struct {
|
||||
Bucket int16
|
||||
StartedAt time.Time
|
||||
Attempts int16
|
||||
}
|
||||
|
||||
type Message struct {
|
||||
ID uuid.UUID
|
||||
ChatID uuid.UUID
|
||||
SenderID uuid.UUID
|
||||
Text string
|
||||
CreatedAt time.Time
|
||||
}
|
||||
|
||||
type MessageAttachment struct {
|
||||
MessageID uuid.UUID
|
||||
AttachmentID uuid.UUID
|
||||
Ordinal int32
|
||||
}
|
||||
|
||||
type Session struct {
|
||||
TokenHash string
|
||||
UserID uuid.UUID
|
||||
ExpiresAt time.Time
|
||||
}
|
||||
|
||||
type User struct {
|
||||
ID uuid.UUID
|
||||
Username string
|
||||
DisplayName string
|
||||
PasswordHash string
|
||||
CreatedAt time.Time
|
||||
ChatCount int32
|
||||
MessageCount int32
|
||||
AttachmentCount int32
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.31.1
|
||||
// source: observability.sql
|
||||
|
||||
package queries
|
||||
|
||||
import (
|
||||
"context"
|
||||
)
|
||||
|
||||
const pipelineMetrics = `-- name: PipelineMetrics :one
|
||||
SELECT count(*)::bigint AS depth,
|
||||
COALESCE(EXTRACT(EPOCH FROM clock_timestamp()-min(j.created_at)),0)::float8 AS oldest
|
||||
FROM attachments a JOIN attachment_jobs j ON j.attachment_id=a.id AND j.pipeline_version=a.pipeline_version
|
||||
WHERE a.status IN ('queued','processing') AND NOT j.completed
|
||||
`
|
||||
|
||||
type PipelineMetricsRow struct {
|
||||
Depth int64
|
||||
Oldest float64
|
||||
}
|
||||
|
||||
func (q *Queries) PipelineMetrics(ctx context.Context) (PipelineMetricsRow, error) {
|
||||
row := q.db.QueryRow(ctx, pipelineMetrics)
|
||||
var i PipelineMetricsRow
|
||||
err := row.Scan(&i.Depth, &i.Oldest)
|
||||
return i, err
|
||||
}
|
||||
@@ -0,0 +1,403 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.31.1
|
||||
// source: pipeline.sql
|
||||
|
||||
package queries
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
const acquireJob = `-- name: AcquireJob :one
|
||||
UPDATE attachment_jobs j SET attempt=j.attempt+1,lease_id=$1,lease_until=clock_timestamp()+$2::int*interval '1 second'
|
||||
WHERE j.id=$3 AND j.pipeline_version=$4 AND NOT j.completed
|
||||
AND j.next_attempt<=clock_timestamp() AND j.lease_until<clock_timestamp()
|
||||
AND EXISTS(SELECT 1 FROM attachments a WHERE a.id=j.attachment_id AND a.pipeline_version=j.pipeline_version AND a.status IN ('queued','processing'))
|
||||
RETURNING j.id, j.attachment_id, j.pipeline_version, j.attempt, j.traceparent, j.tracestate, j.lease_id, j.lease_until, j.next_attempt, j.published_at, j.completed, j.created_at, j.replay_count, j.replayed_at
|
||||
`
|
||||
|
||||
type AcquireJobParams struct {
|
||||
LeaseID uuid.UUID
|
||||
LeaseSeconds int32
|
||||
JobID uuid.UUID
|
||||
PipelineVersion int32
|
||||
}
|
||||
|
||||
func (q *Queries) AcquireJob(ctx context.Context, arg AcquireJobParams) (AttachmentJob, error) {
|
||||
row := q.db.QueryRow(ctx, acquireJob,
|
||||
arg.LeaseID,
|
||||
arg.LeaseSeconds,
|
||||
arg.JobID,
|
||||
arg.PipelineVersion,
|
||||
)
|
||||
var i AttachmentJob
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.AttachmentID,
|
||||
&i.PipelineVersion,
|
||||
&i.Attempt,
|
||||
&i.Traceparent,
|
||||
&i.Tracestate,
|
||||
&i.LeaseID,
|
||||
&i.LeaseUntil,
|
||||
&i.NextAttempt,
|
||||
&i.PublishedAt,
|
||||
&i.Completed,
|
||||
&i.CreatedAt,
|
||||
&i.ReplayCount,
|
||||
&i.ReplayedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const advancePipeline = `-- name: AdvancePipeline :one
|
||||
UPDATE attachments SET status='queued',error_code='',variants='[]',pipeline_version=pipeline_version+1,staging_expired=false,updated_at=clock_timestamp() WHERE id=$1 AND (status='ready' OR (status='failed' AND NOT staging_expired)) RETURNING id, chat_id, owner_id, filename, content_type, size_bytes, sha256, status, pipeline_version, error_code, variants, staging_expired, staging_cleaned, created_at, updated_at, accepted_at, first_ready_at
|
||||
`
|
||||
|
||||
func (q *Queries) AdvancePipeline(ctx context.Context, id uuid.UUID) (Attachment, error) {
|
||||
row := q.db.QueryRow(ctx, advancePipeline, id)
|
||||
var i Attachment
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.ChatID,
|
||||
&i.OwnerID,
|
||||
&i.Filename,
|
||||
&i.ContentType,
|
||||
&i.SizeBytes,
|
||||
&i.Sha256,
|
||||
&i.Status,
|
||||
&i.PipelineVersion,
|
||||
&i.ErrorCode,
|
||||
&i.Variants,
|
||||
&i.StagingExpired,
|
||||
&i.StagingCleaned,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
&i.AcceptedAt,
|
||||
&i.FirstReadyAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const completeAttachment = `-- name: CompleteAttachment :execrows
|
||||
UPDATE attachments a SET first_ready_at=COALESCE(a.first_ready_at,clock_timestamp()),status='ready',variants=$1::jsonb,error_code='',updated_at=clock_timestamp()
|
||||
FROM attachment_jobs j WHERE j.id=$2 AND j.attachment_id=a.id AND j.pipeline_version=a.pipeline_version
|
||||
AND j.lease_id=$3 AND j.lease_until>clock_timestamp() AND NOT j.completed AND a.status='processing'
|
||||
`
|
||||
|
||||
type CompleteAttachmentParams struct {
|
||||
Variants []byte
|
||||
JobID uuid.UUID
|
||||
LeaseID uuid.UUID
|
||||
}
|
||||
|
||||
func (q *Queries) CompleteAttachment(ctx context.Context, arg CompleteAttachmentParams) (int64, error) {
|
||||
result, err := q.db.Exec(ctx, completeAttachment, arg.Variants, arg.JobID, arg.LeaseID)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return result.RowsAffected(), nil
|
||||
}
|
||||
|
||||
const completeJob = `-- name: CompleteJob :exec
|
||||
UPDATE attachment_jobs SET completed=true,lease_until='epoch' WHERE id=$1 AND lease_id=$2
|
||||
`
|
||||
|
||||
type CompleteJobParams struct {
|
||||
JobID uuid.UUID
|
||||
LeaseID uuid.UUID
|
||||
}
|
||||
|
||||
func (q *Queries) CompleteJob(ctx context.Context, arg CompleteJobParams) error {
|
||||
_, err := q.db.Exec(ctx, completeJob, arg.JobID, arg.LeaseID)
|
||||
return err
|
||||
}
|
||||
|
||||
const insertJob = `-- name: InsertJob :exec
|
||||
INSERT INTO attachment_jobs(id,attachment_id,pipeline_version,traceparent,tracestate)
|
||||
VALUES($1,$2,$3,$4,$5)
|
||||
`
|
||||
|
||||
type InsertJobParams struct {
|
||||
JobID uuid.UUID
|
||||
AttachmentID uuid.UUID
|
||||
PipelineVersion int32
|
||||
Traceparent string
|
||||
Tracestate string
|
||||
}
|
||||
|
||||
func (q *Queries) InsertJob(ctx context.Context, arg InsertJobParams) error {
|
||||
_, err := q.db.Exec(ctx, insertJob,
|
||||
arg.JobID,
|
||||
arg.AttachmentID,
|
||||
arg.PipelineVersion,
|
||||
arg.Traceparent,
|
||||
arg.Tracestate,
|
||||
)
|
||||
return err
|
||||
}
|
||||
|
||||
const pendingJobs = `-- name: PendingJobs :many
|
||||
SELECT j.id, j.attachment_id, j.pipeline_version, j.attempt, j.traceparent, j.tracestate, j.lease_id, j.lease_until, j.next_attempt, j.published_at, j.completed, j.created_at, j.replay_count, j.replayed_at FROM attachment_jobs j JOIN attachments a ON a.id=j.attachment_id AND a.pipeline_version=j.pipeline_version
|
||||
WHERE NOT j.completed AND a.status IN ('queued','processing') AND j.next_attempt<=clock_timestamp()
|
||||
AND j.lease_until<clock_timestamp() AND j.published_at<clock_timestamp()-interval '2 seconds'
|
||||
ORDER BY j.created_at,j.id LIMIT 100
|
||||
`
|
||||
|
||||
func (q *Queries) PendingJobs(ctx context.Context) ([]AttachmentJob, error) {
|
||||
rows, err := q.db.Query(ctx, pendingJobs)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
items := []AttachmentJob{}
|
||||
for rows.Next() {
|
||||
var i AttachmentJob
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.AttachmentID,
|
||||
&i.PipelineVersion,
|
||||
&i.Attempt,
|
||||
&i.Traceparent,
|
||||
&i.Tracestate,
|
||||
&i.LeaseID,
|
||||
&i.LeaseUntil,
|
||||
&i.NextAttempt,
|
||||
&i.PublishedAt,
|
||||
&i.Completed,
|
||||
&i.CreatedAt,
|
||||
&i.ReplayCount,
|
||||
&i.ReplayedAt,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const processingAttachment = `-- name: ProcessingAttachment :one
|
||||
UPDATE attachments SET status='processing',updated_at=clock_timestamp()
|
||||
WHERE id=$1 AND pipeline_version=$2 AND status IN ('queued','processing') RETURNING id, chat_id, owner_id, filename, content_type, size_bytes, sha256, status, pipeline_version, error_code, variants, staging_expired, staging_cleaned, created_at, updated_at, accepted_at, first_ready_at
|
||||
`
|
||||
|
||||
type ProcessingAttachmentParams struct {
|
||||
AttachmentID uuid.UUID
|
||||
PipelineVersion int32
|
||||
}
|
||||
|
||||
func (q *Queries) ProcessingAttachment(ctx context.Context, arg ProcessingAttachmentParams) (Attachment, error) {
|
||||
row := q.db.QueryRow(ctx, processingAttachment, arg.AttachmentID, arg.PipelineVersion)
|
||||
var i Attachment
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.ChatID,
|
||||
&i.OwnerID,
|
||||
&i.Filename,
|
||||
&i.ContentType,
|
||||
&i.SizeBytes,
|
||||
&i.Sha256,
|
||||
&i.Status,
|
||||
&i.PipelineVersion,
|
||||
&i.ErrorCode,
|
||||
&i.Variants,
|
||||
&i.StagingExpired,
|
||||
&i.StagingCleaned,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
&i.AcceptedAt,
|
||||
&i.FirstReadyAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const published = `-- name: Published :exec
|
||||
UPDATE attachment_jobs SET published_at=clock_timestamp() WHERE id=$1
|
||||
`
|
||||
|
||||
func (q *Queries) Published(ctx context.Context, id uuid.UUID) error {
|
||||
_, err := q.db.Exec(ctx, published, id)
|
||||
return err
|
||||
}
|
||||
|
||||
const queueAttachment = `-- name: QueueAttachment :one
|
||||
UPDATE attachments SET accepted_at=COALESCE(accepted_at,clock_timestamp()),status='queued',updated_at=clock_timestamp() WHERE id=$1 AND status='uploading' AND NOT staging_expired RETURNING id, chat_id, owner_id, filename, content_type, size_bytes, sha256, status, pipeline_version, error_code, variants, staging_expired, staging_cleaned, created_at, updated_at, accepted_at, first_ready_at
|
||||
`
|
||||
|
||||
func (q *Queries) QueueAttachment(ctx context.Context, id uuid.UUID) (Attachment, error) {
|
||||
row := q.db.QueryRow(ctx, queueAttachment, id)
|
||||
var i Attachment
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.ChatID,
|
||||
&i.OwnerID,
|
||||
&i.Filename,
|
||||
&i.ContentType,
|
||||
&i.SizeBytes,
|
||||
&i.Sha256,
|
||||
&i.Status,
|
||||
&i.PipelineVersion,
|
||||
&i.ErrorCode,
|
||||
&i.Variants,
|
||||
&i.StagingExpired,
|
||||
&i.StagingCleaned,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
&i.AcceptedAt,
|
||||
&i.FirstReadyAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const replayAttachment = `-- name: ReplayAttachment :one
|
||||
UPDATE attachments SET status='queued',error_code='',updated_at=clock_timestamp() WHERE id=$1 AND status='failed' AND NOT staging_expired RETURNING id, chat_id, owner_id, filename, content_type, size_bytes, sha256, status, pipeline_version, error_code, variants, staging_expired, staging_cleaned, created_at, updated_at, accepted_at, first_ready_at
|
||||
`
|
||||
|
||||
func (q *Queries) ReplayAttachment(ctx context.Context, id uuid.UUID) (Attachment, error) {
|
||||
row := q.db.QueryRow(ctx, replayAttachment, id)
|
||||
var i Attachment
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.ChatID,
|
||||
&i.OwnerID,
|
||||
&i.Filename,
|
||||
&i.ContentType,
|
||||
&i.SizeBytes,
|
||||
&i.Sha256,
|
||||
&i.Status,
|
||||
&i.PipelineVersion,
|
||||
&i.ErrorCode,
|
||||
&i.Variants,
|
||||
&i.StagingExpired,
|
||||
&i.StagingCleaned,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
&i.AcceptedAt,
|
||||
&i.FirstReadyAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const replayJobs = `-- name: ReplayJobs :exec
|
||||
UPDATE attachment_jobs SET replay_count=replay_count+1,replayed_at=clock_timestamp(),completed=false,attempt=0,lease_until='epoch',next_attempt='epoch',published_at='epoch' WHERE attachment_id=$1 AND pipeline_version=$2
|
||||
`
|
||||
|
||||
type ReplayJobsParams struct {
|
||||
AttachmentID uuid.UUID
|
||||
PipelineVersion int32
|
||||
}
|
||||
|
||||
func (q *Queries) ReplayJobs(ctx context.Context, arg ReplayJobsParams) error {
|
||||
_, err := q.db.Exec(ctx, replayJobs, arg.AttachmentID, arg.PipelineVersion)
|
||||
return err
|
||||
}
|
||||
|
||||
const retryAttachment = `-- name: RetryAttachment :execrows
|
||||
UPDATE attachments a SET status=$1,error_code=$2,updated_at=clock_timestamp()
|
||||
FROM attachment_jobs j WHERE j.id=$3 AND j.attachment_id=a.id AND j.pipeline_version=a.pipeline_version
|
||||
AND j.lease_id=$4 AND j.lease_until>clock_timestamp() AND NOT j.completed AND a.status='processing'
|
||||
`
|
||||
|
||||
type RetryAttachmentParams struct {
|
||||
NextStatus string
|
||||
ErrorCode string
|
||||
JobID uuid.UUID
|
||||
LeaseID uuid.UUID
|
||||
}
|
||||
|
||||
func (q *Queries) RetryAttachment(ctx context.Context, arg RetryAttachmentParams) (int64, error) {
|
||||
result, err := q.db.Exec(ctx, retryAttachment,
|
||||
arg.NextStatus,
|
||||
arg.ErrorCode,
|
||||
arg.JobID,
|
||||
arg.LeaseID,
|
||||
)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return result.RowsAffected(), nil
|
||||
}
|
||||
|
||||
const retryJob = `-- name: RetryJob :exec
|
||||
UPDATE attachment_jobs SET lease_until='epoch',next_attempt=clock_timestamp()+$1::int*interval '1 millisecond',completed=$2
|
||||
WHERE id=$3 AND lease_id=$4
|
||||
`
|
||||
|
||||
type RetryJobParams struct {
|
||||
DelayMs int32
|
||||
Completed bool
|
||||
JobID uuid.UUID
|
||||
LeaseID uuid.UUID
|
||||
}
|
||||
|
||||
func (q *Queries) RetryJob(ctx context.Context, arg RetryJobParams) error {
|
||||
_, err := q.db.Exec(ctx, retryJob,
|
||||
arg.DelayMs,
|
||||
arg.Completed,
|
||||
arg.JobID,
|
||||
arg.LeaseID,
|
||||
)
|
||||
return err
|
||||
}
|
||||
|
||||
const stagingCleaned = `-- name: StagingCleaned :exec
|
||||
UPDATE attachments SET staging_cleaned=true WHERE id=$1 AND (staging_expired OR status='ready')
|
||||
`
|
||||
|
||||
func (q *Queries) StagingCleaned(ctx context.Context, id uuid.UUID) error {
|
||||
_, err := q.db.Exec(ctx, stagingCleaned, id)
|
||||
return err
|
||||
}
|
||||
|
||||
const stagingCleanup = `-- name: StagingCleanup :many
|
||||
WITH candidates AS (
|
||||
SELECT id FROM attachments WHERE NOT staging_cleaned AND (status='ready' OR (status IN ('failed','uploading') AND updated_at<clock_timestamp()-interval '24 hours'))
|
||||
ORDER BY updated_at,id LIMIT 20
|
||||
)
|
||||
UPDATE attachments a SET staging_expired=(a.status<>'ready') FROM candidates c WHERE a.id=c.id AND NOT a.staging_cleaned
|
||||
AND (a.status='ready' OR (a.status IN ('failed','uploading') AND a.updated_at<clock_timestamp()-interval '24 hours')) RETURNING a.id, a.chat_id, a.owner_id, a.filename, a.content_type, a.size_bytes, a.sha256, a.status, a.pipeline_version, a.error_code, a.variants, a.staging_expired, a.staging_cleaned, a.created_at, a.updated_at, a.accepted_at, a.first_ready_at
|
||||
`
|
||||
|
||||
func (q *Queries) StagingCleanup(ctx context.Context) ([]Attachment, error) {
|
||||
rows, err := q.db.Query(ctx, stagingCleanup)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
items := []Attachment{}
|
||||
for rows.Next() {
|
||||
var i Attachment
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.ChatID,
|
||||
&i.OwnerID,
|
||||
&i.Filename,
|
||||
&i.ContentType,
|
||||
&i.SizeBytes,
|
||||
&i.Sha256,
|
||||
&i.Status,
|
||||
&i.PipelineVersion,
|
||||
&i.ErrorCode,
|
||||
&i.Variants,
|
||||
&i.StagingExpired,
|
||||
&i.StagingCleaned,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
&i.AcceptedAt,
|
||||
&i.FirstReadyAt,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.31.1
|
||||
// source: security.sql
|
||||
|
||||
package queries
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
const allowLogin = `-- name: AllowLogin :one
|
||||
UPDATE login_limits SET attempts=CASE WHEN started_at<=clock_timestamp()-interval '60 seconds' THEN 1 ELSE attempts+1 END,
|
||||
started_at=CASE WHEN started_at<=clock_timestamp()-interval '60 seconds' THEN clock_timestamp() ELSE started_at END
|
||||
WHERE bucket=$1 AND (started_at<=clock_timestamp()-interval '60 seconds' OR attempts<10) RETURNING bucket
|
||||
`
|
||||
|
||||
func (q *Queries) AllowLogin(ctx context.Context, bucket int16) (int16, error) {
|
||||
row := q.db.QueryRow(ctx, allowLogin, bucket)
|
||||
var bucket_2 int16
|
||||
err := row.Scan(&bucket_2)
|
||||
return bucket_2, err
|
||||
}
|
||||
|
||||
const rehashPassword = `-- name: RehashPassword :one
|
||||
UPDATE users SET password_hash=$1 WHERE id=$2 AND password_hash=$3 RETURNING id
|
||||
`
|
||||
|
||||
type RehashPasswordParams struct {
|
||||
Replacement string
|
||||
UserID uuid.UUID
|
||||
Previous string
|
||||
}
|
||||
|
||||
func (q *Queries) RehashPassword(ctx context.Context, arg RehashPasswordParams) (uuid.UUID, error) {
|
||||
row := q.db.QueryRow(ctx, rehashPassword, arg.Replacement, arg.UserID, arg.Previous)
|
||||
var id uuid.UUID
|
||||
err := row.Scan(&id)
|
||||
return id, err
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.31.1
|
||||
// source: slo.sql
|
||||
|
||||
package queries
|
||||
|
||||
import (
|
||||
"context"
|
||||
)
|
||||
|
||||
const readySLI = `-- name: ReadySLI :one
|
||||
WITH clock AS (SELECT clock_timestamp() AS now), cohort AS (
|
||||
SELECT a.accepted_at,a.first_ready_at,c.now FROM attachments a CROSS JOIN clock c
|
||||
WHERE a.accepted_at>c.now-interval '310 seconds' AND a.accepted_at<=c.now-interval '10 seconds'
|
||||
)
|
||||
SELECT count(*) FILTER(WHERE accepted_at>now-interval '20 seconds')::bigint AS matured10,
|
||||
count(*) FILTER(WHERE accepted_at>now-interval '20 seconds' AND first_ready_at>=accepted_at AND first_ready_at<=accepted_at+interval '10 seconds')::bigint AS timely10,
|
||||
count(*) FILTER(WHERE accepted_at>now-interval '40 seconds')::bigint AS matured30,
|
||||
count(*) FILTER(WHERE accepted_at>now-interval '40 seconds' AND first_ready_at>=accepted_at AND first_ready_at<=accepted_at+interval '10 seconds')::bigint AS timely30,
|
||||
count(*)::bigint AS matured300,
|
||||
count(*) FILTER(WHERE first_ready_at>=accepted_at AND first_ready_at<=accepted_at+interval '10 seconds')::bigint AS timely300 FROM cohort
|
||||
`
|
||||
|
||||
type ReadySLIRow struct {
|
||||
Matured10 int64
|
||||
Timely10 int64
|
||||
Matured30 int64
|
||||
Timely30 int64
|
||||
Matured300 int64
|
||||
Timely300 int64
|
||||
}
|
||||
|
||||
func (q *Queries) ReadySLI(ctx context.Context) (ReadySLIRow, error) {
|
||||
row := q.db.QueryRow(ctx, readySLI)
|
||||
var i ReadySLIRow
|
||||
err := row.Scan(
|
||||
&i.Matured10,
|
||||
&i.Timely10,
|
||||
&i.Matured30,
|
||||
&i.Timely30,
|
||||
&i.Matured300,
|
||||
&i.Timely300,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
@@ -0,0 +1,243 @@
|
||||
package postgres
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"time"
|
||||
|
||||
"backend/internal/adapter/repository/postgres/queries"
|
||||
"backend/internal/domain/model"
|
||||
"backend/internal/domain/repository"
|
||||
"github.com/google/uuid"
|
||||
"github.com/jackc/pgx/v5"
|
||||
"github.com/jackc/pgx/v5/pgconn"
|
||||
"github.com/jackc/pgx/v5/pgxpool"
|
||||
"github.com/redis/go-redis/v9"
|
||||
)
|
||||
|
||||
//go:generate go tool sqlc generate -f ../../../../db/sqlc/sqlc.yaml
|
||||
type Store struct {
|
||||
pool *pgxpool.Pool
|
||||
q *queries.Queries
|
||||
cache *redis.Client
|
||||
}
|
||||
|
||||
func New(pool *pgxpool.Pool, cache *redis.Client) repository.Persistent {
|
||||
return &Store{pool, queries.New(pool), cache}
|
||||
}
|
||||
func mapErr(err error) error {
|
||||
if err == nil {
|
||||
return nil
|
||||
}
|
||||
if errors.Is(err, pgx.ErrNoRows) {
|
||||
return model.ErrNotFound
|
||||
}
|
||||
var pg *pgconn.PgError
|
||||
if errors.As(err, &pg) {
|
||||
switch pg.Code {
|
||||
case "23505":
|
||||
return model.ErrUsernameTaken
|
||||
case "23503":
|
||||
return model.ErrUnknownMember
|
||||
case "23514":
|
||||
return &model.ValidationError{Message: "constraint violation"}
|
||||
}
|
||||
}
|
||||
return model.ErrUnavailable
|
||||
}
|
||||
func (s *Store) CreateUser(ctx context.Context, d model.UserDraft) (model.User, error) {
|
||||
row, err := s.q.CreateUser(ctx, queries.CreateUserParams{ID: uuid.New(), Username: d.Username, DisplayName: d.DisplayName, PasswordHash: d.PasswordHash})
|
||||
return model.User{ID: row.ID, Username: row.Username, DisplayName: row.DisplayName, CreatedAt: row.CreatedAt}, mapErr(err)
|
||||
}
|
||||
func (s *Store) GetUser(ctx context.Context, id uuid.UUID) (model.User, error) {
|
||||
key := "profile:" + id.String()
|
||||
if s.cache != nil {
|
||||
c, cancel := context.WithTimeout(ctx, 80*time.Millisecond)
|
||||
raw, err := s.cache.Get(c, key).Bytes()
|
||||
cancel()
|
||||
if err == nil {
|
||||
var u model.User
|
||||
if json.Unmarshal(raw, &u) == nil && u.ID == id {
|
||||
return u, nil
|
||||
}
|
||||
}
|
||||
}
|
||||
row, err := s.q.GetUser(ctx, id)
|
||||
if err != nil {
|
||||
return model.User{}, mapErr(err)
|
||||
}
|
||||
user := model.User{ID: row.ID, Username: row.Username, DisplayName: row.DisplayName, CreatedAt: row.CreatedAt}
|
||||
if s.cache != nil {
|
||||
raw, e := json.Marshal(user)
|
||||
if e == nil {
|
||||
c, cancel := context.WithTimeout(ctx, 80*time.Millisecond)
|
||||
_ = s.cache.Set(c, key, raw, time.Minute).Err()
|
||||
cancel()
|
||||
}
|
||||
}
|
||||
return user, nil
|
||||
}
|
||||
func (s *Store) CreateChat(ctx context.Context, d model.ChatDraft) (model.Chat, error) {
|
||||
tx, err := s.pool.Begin(ctx)
|
||||
if err != nil {
|
||||
return model.Chat{}, mapErr(err)
|
||||
}
|
||||
defer func() { _ = tx.Rollback(ctx) }()
|
||||
q := s.q.WithTx(tx)
|
||||
if _, err = q.ChargeChat(ctx, d.Creator); err != nil {
|
||||
if errors.Is(err, pgx.ErrNoRows) {
|
||||
return model.Chat{}, model.ErrStorageFull
|
||||
}
|
||||
return model.Chat{}, mapErr(err)
|
||||
}
|
||||
row, err := q.InsertChat(ctx, queries.InsertChatParams{ID: uuid.New(), Title: d.Title})
|
||||
if err != nil {
|
||||
return model.Chat{}, mapErr(err)
|
||||
}
|
||||
if err = q.InsertMembers(ctx, queries.InsertMembersParams{ChatID: row.ID, Column2: d.MemberIDs}); err != nil {
|
||||
return model.Chat{}, mapErr(err)
|
||||
}
|
||||
if err = tx.Commit(ctx); err != nil {
|
||||
return model.Chat{}, mapErr(err)
|
||||
}
|
||||
return model.Chat{ID: row.ID, Title: row.Title, CreatedAt: row.CreatedAt, MemberIDs: d.MemberIDs}, nil
|
||||
}
|
||||
func (s *Store) GetChat(ctx context.Context, id uuid.UUID) (model.Chat, error) {
|
||||
r, e := s.q.GetChat(ctx, id)
|
||||
return model.Chat{ID: r.ID, Title: r.Title, CreatedAt: r.CreatedAt, MemberIDs: r.Members}, mapErr(e)
|
||||
}
|
||||
func position(q model.PageQuery) (time.Time, uuid.UUID) {
|
||||
if q.After == nil {
|
||||
return time.Unix(0, 0).UTC(), uuid.Nil
|
||||
}
|
||||
return q.After.CreatedAt, q.After.ID
|
||||
}
|
||||
func (s *Store) ListChats(ctx context.Context, id uuid.UUID, p model.PageQuery) ([]model.Chat, bool, error) {
|
||||
at, aid := position(p)
|
||||
rows, err := s.q.ListChats(ctx, queries.ListChatsParams{MemberID: id, AfterTime: at, AfterID: aid, PageLimit: int32(p.Limit + 1)})
|
||||
if err != nil {
|
||||
return nil, false, mapErr(err)
|
||||
}
|
||||
more := len(rows) > p.Limit
|
||||
if more {
|
||||
rows = rows[:p.Limit]
|
||||
}
|
||||
out := make([]model.Chat, len(rows))
|
||||
for i, r := range rows {
|
||||
out[i] = model.Chat{ID: r.ID, Title: r.Title, CreatedAt: r.CreatedAt, MemberIDs: r.Members}
|
||||
}
|
||||
return out, more, nil
|
||||
}
|
||||
func (s *Store) CreateMessage(ctx context.Context, d model.MessageDraft) (model.Message, error) {
|
||||
tx, err := s.pool.Begin(ctx)
|
||||
if err != nil {
|
||||
return model.Message{}, mapErr(err)
|
||||
}
|
||||
defer func() { _ = tx.Rollback(ctx) }()
|
||||
q := s.q.WithTx(tx)
|
||||
messageID := uuid.New()
|
||||
reserved, e := q.ReserveKey(ctx, queries.ReserveKeyParams{UserID: d.SenderID, ChatID: d.ChatID, Key: d.Key, PayloadHash: d.PayloadHash, MessageID: messageID})
|
||||
if errors.Is(e, pgx.ErrNoRows) {
|
||||
r, e := q.ReplayMessage(ctx, queries.ReplayMessageParams{UserID: d.SenderID, ChatID: d.ChatID, Key: d.Key})
|
||||
if e != nil {
|
||||
return model.Message{}, mapErr(e)
|
||||
}
|
||||
if r.PayloadHash != d.PayloadHash {
|
||||
return model.Message{}, model.ErrConflict
|
||||
}
|
||||
return model.Message{ID: r.ID, ChatID: r.ChatID, SenderID: r.SenderID, Text: r.Text, CreatedAt: r.CreatedAt, AttachmentIDs: r.AttachmentIds}, nil
|
||||
}
|
||||
if e != nil {
|
||||
return model.Message{}, mapErr(e)
|
||||
}
|
||||
messageID = reserved
|
||||
for _, id := range d.AttachmentIDs {
|
||||
a, e := q.GetAttachment(ctx, id)
|
||||
if errors.Is(e, pgx.ErrNoRows) {
|
||||
return model.Message{}, model.ErrNotFound
|
||||
}
|
||||
if e != nil {
|
||||
return model.Message{}, mapErr(e)
|
||||
}
|
||||
if a.ChatID != d.ChatID {
|
||||
return model.Message{}, model.ErrNotFound
|
||||
}
|
||||
if a.Status != "ready" && a.Status != "queued" && a.Status != "processing" {
|
||||
return model.Message{}, model.ErrConflict
|
||||
}
|
||||
}
|
||||
if _, err = q.ChargeMessage(ctx, d.SenderID); err != nil {
|
||||
if errors.Is(err, pgx.ErrNoRows) {
|
||||
return model.Message{}, model.ErrStorageFull
|
||||
}
|
||||
return model.Message{}, mapErr(err)
|
||||
}
|
||||
r, err := q.InsertMessage(ctx, queries.InsertMessageParams{ID: messageID, ChatID: d.ChatID, SenderID: d.SenderID, Text: d.Text})
|
||||
if err != nil {
|
||||
return model.Message{}, mapErr(err)
|
||||
}
|
||||
for i, id := range d.AttachmentIDs {
|
||||
if e := q.InsertMessageAttachment(ctx, queries.InsertMessageAttachmentParams{MessageID: messageID, AttachmentID: id, Ordinal: int32(i)}); e != nil {
|
||||
return model.Message{}, mapErr(e)
|
||||
}
|
||||
}
|
||||
if err = tx.Commit(ctx); err != nil {
|
||||
return model.Message{}, mapErr(err)
|
||||
}
|
||||
return model.Message{ID: r.ID, ChatID: r.ChatID, SenderID: r.SenderID, Text: r.Text, CreatedAt: r.CreatedAt, AttachmentIDs: d.AttachmentIDs}, nil
|
||||
}
|
||||
func (s *Store) ListMessages(ctx context.Context, id uuid.UUID, p model.PageQuery) ([]model.Message, bool, error) {
|
||||
at, aid := position(p)
|
||||
rows, err := s.q.ListMessages(ctx, queries.ListMessagesParams{ChatID: id, AfterTime: at, AfterID: aid, PageLimit: int32(p.Limit + 1)})
|
||||
if err != nil {
|
||||
return nil, false, mapErr(err)
|
||||
}
|
||||
more := len(rows) > p.Limit
|
||||
if more {
|
||||
rows = rows[:p.Limit]
|
||||
}
|
||||
out := make([]model.Message, len(rows))
|
||||
for i, r := range rows {
|
||||
out[i] = model.Message{ID: r.ID, ChatID: r.ChatID, SenderID: r.SenderID, Text: r.Text, CreatedAt: r.CreatedAt, AttachmentIDs: r.AttachmentIds}
|
||||
}
|
||||
return out, more, nil
|
||||
}
|
||||
func (s *Store) Credentials(ctx context.Context, name string) (uuid.UUID, string, error) {
|
||||
r, e := s.q.Credentials(ctx, name)
|
||||
if errors.Is(e, pgx.ErrNoRows) {
|
||||
return uuid.Nil, "", model.ErrUnauthorized
|
||||
}
|
||||
return r.ID, r.PasswordHash, mapErr(e)
|
||||
}
|
||||
func (s *Store) CreateSession(ctx context.Context, hash string, id uuid.UUID, expiry time.Time) error {
|
||||
tx, e := s.pool.Begin(ctx)
|
||||
if e != nil {
|
||||
return mapErr(e)
|
||||
}
|
||||
defer func() { _ = tx.Rollback(ctx) }()
|
||||
q := s.q.WithTx(tx)
|
||||
if _, e = q.LockSessionOwner(ctx, id); e != nil {
|
||||
return mapErr(e)
|
||||
}
|
||||
if e = q.DeleteExpiredSessions(ctx, id); e != nil {
|
||||
return mapErr(e)
|
||||
}
|
||||
if _, e = q.InsertSession(ctx, queries.InsertSessionParams{TokenHash: hash, UserID: id, ExpiresAt: expiry}); e != nil {
|
||||
if errors.Is(e, pgx.ErrNoRows) {
|
||||
return model.ErrStorageFull
|
||||
}
|
||||
return mapErr(e)
|
||||
}
|
||||
return mapErr(tx.Commit(ctx))
|
||||
}
|
||||
func (s *Store) AuthenticateSession(ctx context.Context, hash string) (uuid.UUID, error) {
|
||||
r, e := s.q.AuthenticateSession(ctx, hash)
|
||||
if errors.Is(e, pgx.ErrNoRows) {
|
||||
return uuid.Nil, model.ErrUnauthorized
|
||||
}
|
||||
return r, mapErr(e)
|
||||
}
|
||||
func (s *Store) RevokeSession(ctx context.Context, hash string) error {
|
||||
return mapErr(s.q.RevokeSession(ctx, hash))
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package postgres
|
||||
|
||||
import (
|
||||
"backend/internal/adapter/repository/postgres/queries"
|
||||
"context"
|
||||
"crypto/sha256"
|
||||
"encoding/binary"
|
||||
"errors"
|
||||
"github.com/google/uuid"
|
||||
"github.com/jackc/pgx/v5"
|
||||
)
|
||||
|
||||
func (s *Store) AllowLogin(ctx context.Context, name string) (bool, error) {
|
||||
hash := sha256.Sum256([]byte(name))
|
||||
bucket := int16(binary.BigEndian.Uint16(hash[:2]) % 4096)
|
||||
_, e := s.q.AllowLogin(ctx, bucket)
|
||||
if errors.Is(e, pgx.ErrNoRows) {
|
||||
return false, nil
|
||||
}
|
||||
return e == nil, mapErr(e)
|
||||
}
|
||||
func (s *Store) RehashPassword(ctx context.Context, id uuid.UUID, previous, replacement string) (bool, error) {
|
||||
_, e := s.q.RehashPassword(ctx, queries.RehashPasswordParams{UserID: id, Previous: previous, Replacement: replacement})
|
||||
if errors.Is(e, pgx.ErrNoRows) {
|
||||
return false, nil
|
||||
}
|
||||
return e == nil, mapErr(e)
|
||||
}
|
||||
@@ -0,0 +1,113 @@
|
||||
package postgres
|
||||
|
||||
import (
|
||||
"backend/internal/config"
|
||||
"context"
|
||||
"github.com/google/uuid"
|
||||
"github.com/jackc/pgx/v5/pgxpool"
|
||||
"os"
|
||||
"strings"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestSharedLoginLimitAndRehashCASInRealPostgres(t *testing.T) {
|
||||
if os.Getenv("RUN_SECURITY_DB_TESTS") != "1" {
|
||||
t.Skip("explicit isolated PostgreSQL required")
|
||||
}
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 20*time.Second)
|
||||
defer cancel()
|
||||
dsn, e := config.ReadSecret("/run/secrets/database_url")
|
||||
if e != nil {
|
||||
t.Fatal("database file unavailable")
|
||||
}
|
||||
operator, e := pgxpool.New(ctx, dsn)
|
||||
if e != nil {
|
||||
t.Fatal("operator database unavailable")
|
||||
}
|
||||
defer operator.Close()
|
||||
schema := "security_" + strings.ReplaceAll(uuid.NewString(), "-", "")
|
||||
if _, e = operator.Exec(ctx, "CREATE SCHEMA "+schema); e != nil {
|
||||
t.Fatal("isolated schema creation failed")
|
||||
}
|
||||
defer func() {
|
||||
c, stop := context.WithTimeout(context.Background(), 5*time.Second)
|
||||
defer stop()
|
||||
if _, e := operator.Exec(c, "DROP SCHEMA "+schema+" CASCADE"); e != nil {
|
||||
t.Error("isolated schema cleanup failed")
|
||||
}
|
||||
}()
|
||||
pc, e := pgxpool.ParseConfig(dsn)
|
||||
if e != nil {
|
||||
t.Fatal("database config unavailable")
|
||||
}
|
||||
pc.MaxConns = 8
|
||||
pc.ConnConfig.RuntimeParams["search_path"] = schema
|
||||
pool, e := pgxpool.NewWithConfig(ctx, pc)
|
||||
if e != nil {
|
||||
t.Fatal("isolated pool unavailable")
|
||||
}
|
||||
defer pool.Close()
|
||||
for _, q := range []string{"CREATE TABLE users(id uuid PRIMARY KEY,username text UNIQUE,password_hash text)", "CREATE TABLE login_limits(bucket smallint PRIMARY KEY,started_at timestamptz NOT NULL DEFAULT 'epoch',attempts smallint NOT NULL DEFAULT 0)", "INSERT INTO login_limits(bucket) SELECT generate_series(0,4095)::smallint"} {
|
||||
if _, e = pool.Exec(ctx, q); e != nil {
|
||||
t.Fatal("isolated fixture creation failed")
|
||||
}
|
||||
}
|
||||
a, b := New(pool, nil), New(pool, nil)
|
||||
var accepted atomic.Int32
|
||||
var failures atomic.Int32
|
||||
var group sync.WaitGroup
|
||||
for i := 0; i < 20; i++ {
|
||||
group.Add(1)
|
||||
s := a
|
||||
if i%2 == 1 {
|
||||
s = b
|
||||
}
|
||||
go func() {
|
||||
defer group.Done()
|
||||
ok, e := s.AllowLogin(ctx, "synthetic_shared")
|
||||
if e != nil {
|
||||
failures.Add(1)
|
||||
}
|
||||
if ok {
|
||||
accepted.Add(1)
|
||||
}
|
||||
}()
|
||||
}
|
||||
group.Wait()
|
||||
if failures.Load() != 0 || accepted.Load() != 10 {
|
||||
t.Fatal("concurrent replicas bypassed atomic ten-attempt limit")
|
||||
}
|
||||
var total, rows int
|
||||
if e = pool.QueryRow(ctx, "SELECT sum(attempts),count(*) FROM login_limits").Scan(&total, &rows); e != nil || total != 10 || rows != 4096 {
|
||||
t.Fatal("shared limiter persistence/cardinality incorrect")
|
||||
}
|
||||
id := uuid.New()
|
||||
if _, e = pool.Exec(ctx, "INSERT INTO users VALUES($1,'legacy','old')", id); e != nil {
|
||||
t.Fatal("user fixture creation failed")
|
||||
}
|
||||
accepted.Store(0)
|
||||
for i := 0; i < 2; i++ {
|
||||
group.Add(1)
|
||||
go func() {
|
||||
defer group.Done()
|
||||
ok, e := a.RehashPassword(ctx, id, "old", "new")
|
||||
if e != nil {
|
||||
failures.Add(1)
|
||||
}
|
||||
if ok {
|
||||
accepted.Add(1)
|
||||
}
|
||||
}()
|
||||
}
|
||||
group.Wait()
|
||||
if failures.Load() != 0 || accepted.Load() != 1 {
|
||||
t.Fatal("rehash CAS allowed duplicate overwrite")
|
||||
}
|
||||
got, hash, e := b.Credentials(ctx, "legacy")
|
||||
if e != nil || got != id || hash != "new" {
|
||||
t.Fatal("CAS replacement was not persisted/read by second replica")
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,145 @@
|
||||
package postgres
|
||||
|
||||
import (
|
||||
"backend/db"
|
||||
"backend/internal/config"
|
||||
"backend/internal/domain/model"
|
||||
"context"
|
||||
"github.com/google/uuid"
|
||||
"github.com/jackc/pgx/v5/pgxpool"
|
||||
"net/url"
|
||||
"os"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestReadySLIIncludesFailedStuckReplayAndReprocessedAcceptances(t *testing.T) {
|
||||
if os.Getenv("RUN_SLO_DB_TESTS") != "1" {
|
||||
t.Skip("isolated real PostgreSQL required")
|
||||
}
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 20*time.Second)
|
||||
defer cancel()
|
||||
dsn, e := config.ReadSecret("/run/secrets/database_url")
|
||||
if e != nil {
|
||||
t.Fatal("database file unavailable")
|
||||
}
|
||||
operator, e := pgxpool.New(ctx, dsn)
|
||||
if e != nil {
|
||||
t.Fatal("operator unavailable")
|
||||
}
|
||||
defer operator.Close()
|
||||
schema := "slo_" + strings.ReplaceAll(uuid.NewString(), "-", "")
|
||||
if _, e = operator.Exec(ctx, "CREATE SCHEMA "+schema); e != nil {
|
||||
t.Fatal("isolated schema failed")
|
||||
}
|
||||
defer func() {
|
||||
c, stop := context.WithTimeout(context.Background(), 5*time.Second)
|
||||
defer stop()
|
||||
if _, e := operator.Exec(c, "DROP SCHEMA "+schema+" CASCADE"); e != nil {
|
||||
t.Error("isolated schema cleanup failed")
|
||||
}
|
||||
}()
|
||||
u, e := url.Parse(dsn)
|
||||
if e != nil {
|
||||
t.Fatal("DSN unavailable")
|
||||
}
|
||||
query := u.Query()
|
||||
query.Set("search_path", schema)
|
||||
u.RawQuery = query.Encode()
|
||||
if e = db.Migrate(ctx, u.String()); e != nil {
|
||||
t.Fatal("isolated real migrations failed")
|
||||
}
|
||||
pool, e := pgxpool.New(ctx, u.String())
|
||||
if e != nil {
|
||||
t.Fatal("isolated pool unavailable")
|
||||
}
|
||||
defer pool.Close()
|
||||
s := New(pool, nil)
|
||||
user, e := s.CreateUser(ctx, model.UserDraft{Username: "slo_" + uuid.NewString()[:8], DisplayName: "Synthetic SLO", PasswordHash: "disabled"})
|
||||
if e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
chat, e := s.CreateChat(ctx, model.ChatDraft{Title: "Owned cohort fixture", Creator: user.ID, MemberIDs: []uuid.UUID{user.ID}})
|
||||
if e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
reserve := func() model.Attachment {
|
||||
t.Helper()
|
||||
a, e := s.ReserveAttachment(ctx, model.Attachment{ID: uuid.New(), ChatID: chat.ID, OwnerID: user.ID, Filename: "cohort.png", ContentType: "image/png", SHA256: "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", SizeBytes: 1})
|
||||
if e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
return a
|
||||
}
|
||||
var replayID uuid.UUID
|
||||
for _, f := range []struct {
|
||||
age, latency int
|
||||
status string
|
||||
advance bool
|
||||
}{{15, 5, "ready", false}, {16, 11, "ready", false}, {17, -1, "failed", false}, {18, -1, "processing", false}, {35, 6, "ready", false}, {100, 6, "ready", false}, {5, 1, "ready", false}, {500, 2, "ready", false}, {15, 2, "ready", true}} {
|
||||
a := reserve()
|
||||
if _, e = s.QueueAttachment(ctx, a, "", ""); e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
if _, e = pool.Exec(ctx, "UPDATE attachments SET accepted_at=clock_timestamp()-$2*interval '1 second',first_ready_at=CASE WHEN $3::int>=0 THEN clock_timestamp()-($2-$3)*interval '1 second' ELSE NULL END,status=$4 WHERE id=$1", a.ID, f.age, f.latency, f.status); e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
if f.advance {
|
||||
if ok, e := s.AdvancePipeline(ctx, a.ID); e != nil || !ok {
|
||||
t.Fatal("actual version advance failed")
|
||||
}
|
||||
}
|
||||
if f.status == "failed" {
|
||||
replayID = a.ID
|
||||
}
|
||||
}
|
||||
// A late explicit replay may become ready, but cannot erase the missed original deadline.
|
||||
if ok, e := s.ReplayJob(ctx, replayID); e != nil || !ok {
|
||||
t.Fatal("actual replay failed")
|
||||
}
|
||||
jobs, e := s.PendingJobs(ctx)
|
||||
if e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
for _, j := range jobs {
|
||||
if j.AttachmentID == replayID {
|
||||
lease := uuid.New()
|
||||
owned, _, ok, e := s.AcquireJob(ctx, j, lease, 30*time.Second)
|
||||
if e != nil || !ok {
|
||||
t.Fatal("replay acquisition failed")
|
||||
}
|
||||
if ok, e = s.CompleteJob(ctx, owned, lease, []model.Variant{}); e != nil || !ok {
|
||||
t.Fatal("replayed late completion failed")
|
||||
}
|
||||
}
|
||||
}
|
||||
// Upload can start long before durable acceptance. QueueAttachment must establish
|
||||
// its own timestamp, while legacy rows with unknown acceptance remain unmeasured.
|
||||
oldUpload := reserve()
|
||||
if _, e = pool.Exec(ctx, "UPDATE attachments SET created_at=clock_timestamp()-interval '1 hour' WHERE id=$1", oldUpload.ID); e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
if _, e = s.QueueAttachment(ctx, oldUpload, "", ""); e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
var age float64
|
||||
if e = pool.QueryRow(ctx, "SELECT EXTRACT(EPOCH FROM clock_timestamp()-accepted_at)::float8 FROM attachments WHERE id=$1", oldUpload.ID).Scan(&age); e != nil || age < 0 || age > 2 {
|
||||
t.Fatal("acceptance clock incorrectly reused upload start")
|
||||
}
|
||||
legacy := reserve()
|
||||
if _, e = pool.Exec(ctx, "UPDATE attachments SET created_at=clock_timestamp()-interval '15 seconds',status='ready' WHERE id=$1", legacy.ID); e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
r, e := s.(*Store).q.ReadySLI(ctx)
|
||||
if e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
if r.Matured10 != 5 || r.Timely10 != 2 || r.Matured30 != 6 || r.Timely30 != 3 || r.Matured300 != 7 || r.Timely300 != 4 {
|
||||
t.Fatal("SLO denominator or immutable first-ready outcome changed after replay/advance or counted immature/unknown upload")
|
||||
}
|
||||
metrics, e := s.PipelineMetrics(ctx)
|
||||
if e != nil || metrics.Oldest < 0 || metrics.Oldest > 5 {
|
||||
t.Fatal("queue age included pre-accept upload time instead of durable logical job")
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
package storage
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"crypto/sha256"
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/minio/minio-go/v7"
|
||||
"github.com/minio/minio-go/v7/pkg/signer"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Config struct{ Endpoint, Access, Secret, Bucket string }
|
||||
|
||||
func ReadConfig(path string) (Config, error) {
|
||||
var c Config
|
||||
b, e := os.ReadFile(path)
|
||||
if e != nil {
|
||||
return c, fmt.Errorf("S3 credentials unavailable")
|
||||
}
|
||||
if e = json.Unmarshal(b, &c); e != nil {
|
||||
return c, fmt.Errorf("invalid S3 credentials format")
|
||||
}
|
||||
if c.Endpoint == "" || c.Access == "" || c.Secret == "" || c.Bucket == "" {
|
||||
return c, fmt.Errorf("incomplete S3 configuration")
|
||||
}
|
||||
return c, nil
|
||||
}
|
||||
func FromConfig(c Config) (*S3, error) { return New(c.Endpoint, c.Access, c.Secret, c.Bucket) }
|
||||
|
||||
// RustFS provides S3 SDKs, but its documented administrative API is separate.
|
||||
// Use the SDK's SigV4 signer; do not implement signing or persist credentials in command arguments.
|
||||
func admin(ctx context.Context, c Config, path string, body []byte) error {
|
||||
r, e := http.NewRequestWithContext(ctx, http.MethodPut, "http://"+c.Endpoint+"/rustfs/admin/v3/"+path, bytes.NewReader(body))
|
||||
if e != nil {
|
||||
return e
|
||||
}
|
||||
sum := sha256.Sum256(body)
|
||||
r.Header.Set("X-Amz-Content-Sha256", hex.EncodeToString(sum[:]))
|
||||
r.Header.Set("Content-Type", "application/json")
|
||||
signed := signer.SignV4(*r, c.Access, c.Secret, "", "us-east-1")
|
||||
response, e := (&http.Client{Timeout: 5 * time.Second}).Do(signed)
|
||||
if e != nil {
|
||||
return fmt.Errorf("S3 admin transport failed")
|
||||
}
|
||||
defer response.Body.Close()
|
||||
_, _ = io.Copy(io.Discard, io.LimitReader(response.Body, 64*1024))
|
||||
if response.StatusCode != 200 && response.StatusCode != 204 {
|
||||
return fmt.Errorf("S3 admin operation rejected: HTTP %d", response.StatusCode)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
func Bootstrap(ctx context.Context, root, app Config) error {
|
||||
s, e := FromConfig(root)
|
||||
if e != nil {
|
||||
return e
|
||||
}
|
||||
exists, e := s.Client.BucketExists(ctx, root.Bucket)
|
||||
if e != nil {
|
||||
return fmt.Errorf("bucket availability check failed")
|
||||
}
|
||||
if !exists {
|
||||
if e = s.Client.MakeBucket(ctx, root.Bucket, minio.MakeBucketOptions{Region: "us-east-1"}); e != nil {
|
||||
return fmt.Errorf("bucket creation failed")
|
||||
}
|
||||
}
|
||||
policy := map[string]any{"Version": "2012-10-17", "Statement": []any{
|
||||
map[string]any{"Effect": "Allow", "Action": []string{"s3:GetBucketLocation", "s3:ListBucket"}, "Resource": []string{"arn:aws:s3:::" + app.Bucket}},
|
||||
map[string]any{"Effect": "Allow", "Action": []string{"s3:PutObject", "s3:GetObject", "s3:DeleteObject"}, "Resource": []string{"arn:aws:s3:::" + app.Bucket + "/originals/*", "arn:aws:s3:::" + app.Bucket + "/staging/*", "arn:aws:s3:::" + app.Bucket + "/variants/*"}},
|
||||
}}
|
||||
raw, _ := json.Marshal(policy)
|
||||
if e = admin(ctx, root, "add-canned-policy?name=messenger", raw); e != nil {
|
||||
return e
|
||||
}
|
||||
raw, _ = json.Marshal(map[string]string{"secretKey": app.Secret, "status": "enabled"})
|
||||
if e = admin(ctx, root, "add-user?accessKey="+url.QueryEscape(app.Access), raw); e != nil {
|
||||
return e
|
||||
}
|
||||
return admin(ctx, root, "set-user-or-group-policy?policyName=messenger&userOrGroup="+url.QueryEscape(app.Access)+"&isGroup=false", nil)
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package storage
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestMissingBucketFailsReadiness(t *testing.T) {
|
||||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { w.WriteHeader(404) }))
|
||||
defer server.Close()
|
||||
store, err := New(strings.TrimPrefix(server.URL, "http://"), "synthetic-access", "synthetic-secret", "missing")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err = store.Ready(context.Background()); err == nil {
|
||||
t.Fatal("missing bucket reported ready")
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
package storage
|
||||
|
||||
import (
|
||||
"backend/internal/domain/model"
|
||||
"backend/internal/domain/port"
|
||||
"context"
|
||||
"github.com/minio/minio-go/v7"
|
||||
"github.com/minio/minio-go/v7/pkg/credentials"
|
||||
"io"
|
||||
"net"
|
||||
"net/http"
|
||||
"time"
|
||||
)
|
||||
|
||||
type S3 struct {
|
||||
Client *minio.Client
|
||||
Bucket string
|
||||
}
|
||||
|
||||
func New(endpoint, access, secret, bucket string) (*S3, error) {
|
||||
client, err := minio.New(endpoint, &minio.Options{Creds: credentials.NewStaticV4(access, secret, ""), Secure: false, Region: "us-east-1", Transport: &http.Transport{DialContext: (&net.Dialer{Timeout: time.Second}).DialContext, ResponseHeaderTimeout: 3 * time.Second, MaxIdleConnsPerHost: 8}})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &S3{client, bucket}, nil
|
||||
}
|
||||
func mapError(err error) error {
|
||||
if err == nil {
|
||||
return nil
|
||||
}
|
||||
r := minio.ToErrorResponse(err)
|
||||
if r.Code == "NoSuchKey" || r.Code == "NoSuchObject" || r.Code == "NotFound" {
|
||||
return model.ErrNotFound
|
||||
}
|
||||
return model.ErrUnavailable
|
||||
}
|
||||
func (s *S3) Put(ctx context.Context, key string, r io.Reader, size int64, mime string) error {
|
||||
_, err := s.Client.PutObject(ctx, s.Bucket, key, r, size, minio.PutObjectOptions{ContentType: mime, DisableMultipart: true})
|
||||
return mapError(err)
|
||||
}
|
||||
func (s *S3) Get(ctx context.Context, key string) (io.ReadCloser, error) {
|
||||
obj, err := s.Client.GetObject(ctx, s.Bucket, key, minio.GetObjectOptions{})
|
||||
if err != nil {
|
||||
return nil, mapError(err)
|
||||
}
|
||||
if _, err = obj.Stat(); err != nil {
|
||||
_ = obj.Close()
|
||||
return nil, mapError(err)
|
||||
}
|
||||
return obj, nil
|
||||
}
|
||||
func (s *S3) Stat(ctx context.Context, key string) (port.Object, error) {
|
||||
r, e := s.Client.StatObject(ctx, s.Bucket, key, minio.StatObjectOptions{})
|
||||
return port.Object{Key: key, ETag: r.ETag, Size: r.Size, Modified: r.LastModified.UTC().Truncate(time.Second)}, mapError(e)
|
||||
}
|
||||
func (s *S3) Remove(ctx context.Context, key string) error {
|
||||
return mapError(s.Client.RemoveObject(ctx, s.Bucket, key, minio.RemoveObjectOptions{}))
|
||||
}
|
||||
func (s *S3) List(ctx context.Context, after string) ([]port.Object, bool, error) {
|
||||
ctx, cancel := context.WithCancel(ctx)
|
||||
defer cancel()
|
||||
out := []port.Object{}
|
||||
for r := range s.Client.ListObjects(ctx, s.Bucket, minio.ListObjectsOptions{Prefix: "originals/", StartAfter: after, Recursive: true, MaxKeys: 100}) {
|
||||
if r.Err != nil {
|
||||
return nil, false, mapError(r.Err)
|
||||
}
|
||||
// HTTP Last-Modified has second precision; RustFS inventory also carries milliseconds.
|
||||
out = append(out, port.Object{Key: r.Key, ETag: r.ETag, Size: r.Size, Modified: r.LastModified.UTC().Truncate(time.Second)})
|
||||
if len(out) > 100 {
|
||||
return out[:100], true, nil
|
||||
}
|
||||
}
|
||||
return out, false, nil
|
||||
}
|
||||
func (s *S3) Ready(ctx context.Context) error {
|
||||
exists, err := s.Client.BucketExists(ctx, s.Bucket)
|
||||
if err != nil || !exists {
|
||||
return model.ErrUnavailable
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,126 @@
|
||||
package telemetry
|
||||
|
||||
import (
|
||||
"backend/internal/domain/port"
|
||||
"context"
|
||||
"errors"
|
||||
"github.com/jackc/pgx/v5"
|
||||
"github.com/jackc/pgx/v5/pgxpool"
|
||||
"go.opentelemetry.io/otel"
|
||||
"go.opentelemetry.io/otel/attribute"
|
||||
"go.opentelemetry.io/otel/codes"
|
||||
"go.opentelemetry.io/otel/metric"
|
||||
"go.opentelemetry.io/otel/trace"
|
||||
"io"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
)
|
||||
|
||||
type DBTracer struct{}
|
||||
|
||||
func (DBTracer) TraceQueryStart(ctx context.Context, _ *pgx.Conn, _ pgx.TraceQueryStartData) context.Context {
|
||||
ctx, _ = otel.Tracer("messenger").Start(ctx, "postgres.query", trace.WithSpanKind(trace.SpanKindClient))
|
||||
return ctx
|
||||
}
|
||||
func (DBTracer) TraceQueryEnd(ctx context.Context, _ *pgx.Conn, d pgx.TraceQueryEndData) {
|
||||
s := trace.SpanFromContext(ctx)
|
||||
if d.Err != nil {
|
||||
s.SetStatus(codes.Error, "database_error")
|
||||
}
|
||||
s.End()
|
||||
}
|
||||
|
||||
type Objects struct{ port.Objects }
|
||||
|
||||
func (s Objects) Put(ctx context.Context, k string, r io.Reader, n int64, m string) error {
|
||||
ctx, span := otel.Tracer("messenger").Start(ctx, "s3.put", trace.WithSpanKind(trace.SpanKindClient))
|
||||
defer span.End()
|
||||
e := s.Objects.Put(ctx, k, r, n, m)
|
||||
if e != nil {
|
||||
span.SetStatus(codes.Error, "storage_error")
|
||||
}
|
||||
return e
|
||||
}
|
||||
func (s Objects) Get(ctx context.Context, k string) (io.ReadCloser, error) {
|
||||
ctx, span := otel.Tracer("messenger").Start(ctx, "s3.get", trace.WithSpanKind(trace.SpanKindClient))
|
||||
r, e := s.Objects.Get(ctx, k)
|
||||
if e != nil {
|
||||
span.SetStatus(codes.Error, "storage_error")
|
||||
span.End()
|
||||
return nil, e
|
||||
}
|
||||
return &tracedReader{reader: r, span: span}, nil
|
||||
}
|
||||
|
||||
// The caller owns Close, as for every io.ReadCloser. Keeping the span open until
|
||||
// Close includes streaming body reads and late Close errors in the same boundary.
|
||||
type tracedReader struct {
|
||||
reader io.ReadCloser
|
||||
span trace.Span
|
||||
once sync.Once
|
||||
closed atomic.Bool
|
||||
closeError error
|
||||
}
|
||||
|
||||
func (r *tracedReader) Read(p []byte) (int, error) {
|
||||
if r.closed.Load() {
|
||||
return 0, io.ErrClosedPipe
|
||||
}
|
||||
n, e := r.reader.Read(p)
|
||||
if e != nil && !errors.Is(e, io.EOF) {
|
||||
r.span.SetStatus(codes.Error, "storage_error")
|
||||
}
|
||||
return n, e
|
||||
}
|
||||
func (r *tracedReader) Close() error {
|
||||
r.once.Do(func() {
|
||||
r.closed.Store(true)
|
||||
r.closeError = r.reader.Close()
|
||||
if r.closeError != nil {
|
||||
r.span.SetStatus(codes.Error, "storage_error")
|
||||
}
|
||||
r.span.End()
|
||||
})
|
||||
return r.closeError
|
||||
}
|
||||
func (s Objects) Stat(ctx context.Context, k string) (port.Object, error) {
|
||||
ctx, span := otel.Tracer("messenger").Start(ctx, "s3.stat", trace.WithSpanKind(trace.SpanKindClient))
|
||||
defer span.End()
|
||||
r, e := s.Objects.Stat(ctx, k)
|
||||
if e != nil {
|
||||
span.SetStatus(codes.Error, "storage_error")
|
||||
}
|
||||
return r, e
|
||||
}
|
||||
|
||||
type acquireKey struct{}
|
||||
type acquireState struct {
|
||||
telemetry *Telemetry
|
||||
started time.Time
|
||||
span trace.Span
|
||||
}
|
||||
|
||||
func (DBTracer) TraceAcquireStart(ctx context.Context, _ *pgxpool.Pool, _ pgxpool.TraceAcquireStartData) context.Context {
|
||||
t := current.Load()
|
||||
if t == nil {
|
||||
return ctx
|
||||
}
|
||||
t.poolPending.Add(1)
|
||||
ctx, span := otel.Tracer("messenger").Start(ctx, "postgres.acquire", trace.WithSpanKind(trace.SpanKindClient))
|
||||
return context.WithValue(ctx, acquireKey{}, acquireState{t, time.Now(), span})
|
||||
}
|
||||
func (DBTracer) TraceAcquireEnd(ctx context.Context, _ *pgxpool.Pool, data pgxpool.TraceAcquireEndData) {
|
||||
s, ok := ctx.Value(acquireKey{}).(acquireState)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
s.telemetry.poolPending.Add(-1)
|
||||
outcome := "success"
|
||||
if data.Err != nil {
|
||||
outcome = "error"
|
||||
s.span.SetStatus(codes.Error, "database_acquire_error")
|
||||
}
|
||||
s.telemetry.dbAcquire.Record(ctx, time.Since(s.started).Seconds(), metric.WithAttributes(attribute.String("outcome", outcome)))
|
||||
s.span.End()
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
package telemetry
|
||||
|
||||
import (
|
||||
"backend/internal/domain/port"
|
||||
"context"
|
||||
"errors"
|
||||
"go.opentelemetry.io/otel"
|
||||
"go.opentelemetry.io/otel/codes"
|
||||
sdktrace "go.opentelemetry.io/otel/sdk/trace"
|
||||
"go.opentelemetry.io/otel/sdk/trace/tracetest"
|
||||
"io"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
type readerObjects struct {
|
||||
port.Objects
|
||||
r io.ReadCloser
|
||||
}
|
||||
|
||||
func (o readerObjects) Get(context.Context, string) (io.ReadCloser, error) { return o.r, nil }
|
||||
|
||||
type controlledReadCloser struct {
|
||||
io.Reader
|
||||
readError, closeError error
|
||||
closes int
|
||||
}
|
||||
|
||||
func (r *controlledReadCloser) Read(p []byte) (int, error) {
|
||||
if r.readError != nil {
|
||||
return 0, r.readError
|
||||
}
|
||||
return r.Reader.Read(p)
|
||||
}
|
||||
func (r *controlledReadCloser) Close() error { r.closes++; return r.closeError }
|
||||
func TestS3SpanCoversBodyReadAndClosesExactlyOnce(t *testing.T) {
|
||||
for _, failure := range []string{"none", "read", "close"} {
|
||||
t.Run(failure, func(t *testing.T) {
|
||||
recorder := tracetest.NewSpanRecorder()
|
||||
provider := sdktrace.NewTracerProvider(sdktrace.WithSpanProcessor(recorder))
|
||||
previous := otel.GetTracerProvider()
|
||||
otel.SetTracerProvider(provider)
|
||||
defer otel.SetTracerProvider(previous)
|
||||
defer func() {
|
||||
if e := provider.Shutdown(context.Background()); e != nil {
|
||||
t.Error("provider cleanup failed")
|
||||
}
|
||||
}()
|
||||
reader := &controlledReadCloser{Reader: strings.NewReader("synthetic body")}
|
||||
if failure == "read" {
|
||||
reader.readError = io.ErrUnexpectedEOF
|
||||
}
|
||||
if failure == "close" {
|
||||
reader.closeError = io.ErrClosedPipe
|
||||
}
|
||||
objects := Objects{Objects: readerObjects{r: reader}}
|
||||
r, e := objects.Get(context.Background(), "synthetic-key")
|
||||
if e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
if len(recorder.Ended()) != 0 {
|
||||
t.Error("S3 span ended before body transfer")
|
||||
}
|
||||
_, readErr := io.ReadAll(r)
|
||||
closeErr := r.Close()
|
||||
_ = r.Close()
|
||||
spans := recorder.Ended()
|
||||
if len(spans) != 1 {
|
||||
t.Fatal("stream span not ended exactly once")
|
||||
}
|
||||
if reader.closes != 1 {
|
||||
t.Error("underlying reader closed repeatedly")
|
||||
}
|
||||
if failure != "none" && spans[0].Status().Code != codes.Error {
|
||||
t.Error("body/close error missing from S3 span")
|
||||
}
|
||||
if failure == "read" && !errors.Is(readErr, io.ErrUnexpectedEOF) {
|
||||
t.Error("read error lost")
|
||||
}
|
||||
if failure == "close" && !errors.Is(closeErr, io.ErrClosedPipe) {
|
||||
t.Error("close error lost")
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
package telemetry
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
metricpb "go.opentelemetry.io/proto/otlp/collector/metrics/v1"
|
||||
"google.golang.org/protobuf/proto"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"sync/atomic"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestReviewFailedDBGaugeDoesNotSuppressUnrelatedHTTPMetrics(t *testing.T) {
|
||||
var metricExports atomic.Int64
|
||||
var invalidDB, observerDown, independentHTTP atomic.Bool
|
||||
sink := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
if r.URL.Path == "/v1/metrics" {
|
||||
metricExports.Add(1)
|
||||
raw, _ := io.ReadAll(r.Body)
|
||||
data := &metricpb.ExportMetricsServiceRequest{}
|
||||
if proto.Unmarshal(raw, data) == nil {
|
||||
for _, rm := range data.ResourceMetrics {
|
||||
for _, sm := range rm.ScopeMetrics {
|
||||
for _, m := range sm.Metrics {
|
||||
switch m.Name {
|
||||
case "queue_depth", "ready_slo_matured_10s":
|
||||
invalidDB.Store(true)
|
||||
case "http_requests":
|
||||
independentHTTP.Store(true)
|
||||
case "database_observer_up":
|
||||
for _, p := range m.GetGauge().GetDataPoints() {
|
||||
if p.GetAsDouble() == 0 {
|
||||
observerDown.Store(true)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
w.Header().Set("Content-Type", "application/x-protobuf")
|
||||
w.WriteHeader(200)
|
||||
}))
|
||||
defer sink.Close()
|
||||
t.Setenv("OTEL_EXPORTER_OTLP_ENDPOINT", sink.URL)
|
||||
t.Setenv("OTEL_SDK_DISABLED", "false")
|
||||
t.Setenv("OTEL_TRACES_SAMPLER_ARG", "1")
|
||||
sdk, err := Setup(context.Background(), "messenger-api")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer func() {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
|
||||
defer cancel()
|
||||
sdk.Shutdown(ctx)
|
||||
current.Store(nil)
|
||||
}()
|
||||
if err = sdk.Gauges(func(context.Context) (map[string]float64, error) {
|
||||
return map[string]float64{"queue_depth": 0, "ready_slo_matured_10s": 0}, errors.New("synthetic database unavailable")
|
||||
}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
sdk.requests.Add(context.Background(), 1)
|
||||
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
|
||||
defer cancel()
|
||||
flushErr := sdk.meters.ForceFlush(ctx)
|
||||
if invalidDB.Load() || !observerDown.Load() || !independentHTTP.Load() {
|
||||
t.Error("failed gauge leaked healthy zeros or omitted independent metrics/observer-down signal")
|
||||
}
|
||||
if metricExports.Load() == 0 {
|
||||
t.Fatalf("independent HTTP metrics suppressed by failed DB gauge; flush error present=%t", flushErr != nil)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
package telemetry
|
||||
|
||||
import (
|
||||
"backend/internal/domain/model"
|
||||
"context"
|
||||
"go.opentelemetry.io/otel/attribute"
|
||||
"go.opentelemetry.io/otel/metric"
|
||||
"os"
|
||||
"runtime"
|
||||
"strconv"
|
||||
"strings"
|
||||
"syscall"
|
||||
"time"
|
||||
)
|
||||
|
||||
func (t *Telemetry) Gauges(source func(context.Context) (map[string]float64, error)) error {
|
||||
if t == nil {
|
||||
return nil
|
||||
}
|
||||
meter := t.meters.Meter("messenger")
|
||||
names := []string{"queue_depth", "queue_oldest_age_seconds", "db_pool_used", "db_pool_capacity", "database_observer_up", "db_pool_pending_acquires", "worker_busy", "worker_capacity", "process_resident_memory_bytes", "go_heap_bytes", "ready_slo_matured_10s", "ready_slo_timely_10s", "ready_slo_matured_30s", "ready_slo_timely_30s", "ready_slo_matured_300s", "ready_slo_timely_300s"}
|
||||
gauges := make([]metric.Float64ObservableGauge, len(names))
|
||||
obs := make([]metric.Observable, len(names))
|
||||
for i, name := range names {
|
||||
g, e := meter.Float64ObservableGauge(name)
|
||||
if e != nil {
|
||||
return e
|
||||
}
|
||||
gauges[i] = g
|
||||
obs[i] = g
|
||||
}
|
||||
cpu, e := meter.Float64ObservableCounter("process_cpu", metric.WithUnit("s"))
|
||||
if e != nil {
|
||||
return e
|
||||
}
|
||||
failures, e := meter.Float64ObservableCounter("database_observer_failures")
|
||||
if e != nil {
|
||||
return e
|
||||
}
|
||||
obs = append(obs, cpu, failures)
|
||||
_, e = meter.RegisterCallback(func(ctx context.Context, o metric.Observer) error {
|
||||
ctx, cancel := context.WithTimeout(ctx, 500*time.Millisecond)
|
||||
defer cancel()
|
||||
values, err := source(ctx)
|
||||
if err != nil {
|
||||
values = nil
|
||||
t.observationFailures.Add(1)
|
||||
t.Event(ctx, "telemetry.database_observer", "unavailable")
|
||||
}
|
||||
if values == nil {
|
||||
values = map[string]float64{}
|
||||
}
|
||||
o.ObserveFloat64(failures, float64(t.observationFailures.Load()))
|
||||
values["database_observer_up"] = 1
|
||||
if err != nil {
|
||||
values["database_observer_up"] = 0
|
||||
}
|
||||
values["db_pool_pending_acquires"] = float64(t.poolPending.Load())
|
||||
if t.worker {
|
||||
values["worker_capacity"] = 1
|
||||
values["worker_busy"] = float64(t.busy.Load())
|
||||
}
|
||||
var self, children syscall.Rusage
|
||||
if syscall.Getrusage(syscall.RUSAGE_SELF, &self) == nil && syscall.Getrusage(syscall.RUSAGE_CHILDREN, &children) == nil {
|
||||
o.ObserveFloat64(cpu, float64(self.Utime.Sec+self.Stime.Sec+children.Utime.Sec+children.Stime.Sec)+float64(self.Utime.Usec+self.Stime.Usec+children.Utime.Usec+children.Stime.Usec)/1e6)
|
||||
}
|
||||
var mem runtime.MemStats
|
||||
runtime.ReadMemStats(&mem)
|
||||
values["go_heap_bytes"] = float64(mem.HeapAlloc)
|
||||
if raw, e := os.ReadFile("/proc/self/statm"); e == nil {
|
||||
parts := strings.Fields(string(raw))
|
||||
if len(parts) > 1 {
|
||||
n, e := strconv.ParseUint(parts[1], 10, 64)
|
||||
if e == nil {
|
||||
values["process_resident_memory_bytes"] = float64(n * uint64(os.Getpagesize()))
|
||||
}
|
||||
}
|
||||
}
|
||||
for i, name := range names {
|
||||
if v, ok := values[name]; ok {
|
||||
if name == "queue_depth" || name == "queue_oldest_age_seconds" {
|
||||
o.ObserveFloat64(gauges[i], v, metric.WithAttributes(attribute.String("queue", "attachment-jobs")))
|
||||
} else {
|
||||
o.ObserveFloat64(gauges[i], v)
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}, obs...)
|
||||
return e
|
||||
}
|
||||
|
||||
func PipelineValues(m model.PipelineMetrics) map[string]float64 {
|
||||
return map[string]float64{"queue_depth": float64(m.Depth), "queue_oldest_age_seconds": m.Oldest, "ready_slo_matured_10s": float64(m.ReadyMatured[0]), "ready_slo_timely_10s": float64(m.ReadyTimely[0]), "ready_slo_matured_30s": float64(m.ReadyMatured[1]), "ready_slo_timely_30s": float64(m.ReadyTimely[1]), "ready_slo_matured_300s": float64(m.ReadyMatured[2]), "ready_slo_timely_300s": float64(m.ReadyTimely[2])}
|
||||
}
|
||||
@@ -0,0 +1,112 @@
|
||||
package telemetry
|
||||
|
||||
import (
|
||||
"backend/internal/config"
|
||||
"context"
|
||||
"github.com/jackc/pgx/v5/pgxpool"
|
||||
metricpb "go.opentelemetry.io/proto/otlp/collector/metrics/v1"
|
||||
"google.golang.org/protobuf/proto"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"os"
|
||||
"sync/atomic"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestNativePoolWaitExportsPendingAcquire(t *testing.T) {
|
||||
if os.Getenv("RUN_TELEMETRY_DB_TESTS") != "1" {
|
||||
t.Skip("isolated real PostgreSQL required")
|
||||
}
|
||||
var observed atomic.Int64
|
||||
observed.Store(-1)
|
||||
sink := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
if r.URL.Path == "/v1/metrics" {
|
||||
raw, _ := io.ReadAll(r.Body)
|
||||
data := &metricpb.ExportMetricsServiceRequest{}
|
||||
if proto.Unmarshal(raw, data) == nil {
|
||||
for _, rm := range data.ResourceMetrics {
|
||||
for _, sm := range rm.ScopeMetrics {
|
||||
for _, m := range sm.Metrics {
|
||||
if m.Name == "db_pool_pending_acquires" {
|
||||
for _, p := range m.GetGauge().GetDataPoints() {
|
||||
observed.Store(int64(p.GetAsDouble()))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
w.Header().Set("Content-Type", "application/x-protobuf")
|
||||
w.WriteHeader(200)
|
||||
}))
|
||||
defer sink.Close()
|
||||
t.Setenv("OTEL_EXPORTER_OTLP_ENDPOINT", sink.URL)
|
||||
t.Setenv("OTEL_SDK_DISABLED", "false")
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
||||
defer cancel()
|
||||
sdk, e := Setup(ctx, "messenger-api")
|
||||
if e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
defer func() { sdk.Shutdown(context.Background()); current.Store(nil) }()
|
||||
dsn, e := config.ReadSecret("/run/secrets/database_url")
|
||||
if e != nil {
|
||||
t.Fatal("database file unavailable")
|
||||
}
|
||||
pc, e := pgxpool.ParseConfig(dsn)
|
||||
if e != nil {
|
||||
t.Fatal("database config unavailable")
|
||||
}
|
||||
pc.MaxConns = 1
|
||||
pc.ConnConfig.Tracer = DBTracer{}
|
||||
pool, e := pgxpool.NewWithConfig(ctx, pc)
|
||||
if e != nil {
|
||||
t.Fatal("pool unavailable")
|
||||
}
|
||||
defer pool.Close()
|
||||
held, e := pool.Acquire(ctx)
|
||||
if e != nil {
|
||||
t.Fatal("first acquisition failed")
|
||||
}
|
||||
defer held.Release()
|
||||
done := make(chan error, 1)
|
||||
go func() {
|
||||
c, e := pool.Acquire(ctx)
|
||||
if e == nil {
|
||||
c.Release()
|
||||
}
|
||||
done <- e
|
||||
}()
|
||||
waiting := false
|
||||
for i := 0; i < 1000; i++ {
|
||||
if sdk.poolPending.Load() == 1 {
|
||||
waiting = true
|
||||
break
|
||||
}
|
||||
time.Sleep(time.Millisecond)
|
||||
}
|
||||
if !waiting {
|
||||
t.Fatal("native blocked acquisition not tracked")
|
||||
}
|
||||
if e = sdk.Gauges(func(context.Context) (map[string]float64, error) {
|
||||
return map[string]float64{"db_pool_used": float64(pool.Stat().AcquiredConns()), "db_pool_capacity": 1}, nil
|
||||
}); e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
if e = sdk.meters.ForceFlush(ctx); e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
if observed.Load() != 1 {
|
||||
t.Fatal("actual OTLP pending-acquires gauge did not show native pool wait")
|
||||
}
|
||||
held.Release()
|
||||
if e = <-done; e != nil {
|
||||
t.Fatal("queued acquisition failed after release")
|
||||
}
|
||||
if sdk.poolPending.Load() != 0 {
|
||||
t.Fatal("completed native acquisition still pending")
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,216 @@
|
||||
package telemetry
|
||||
|
||||
import (
|
||||
"backend/internal/domain/model"
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/go-chi/chi/v5"
|
||||
chimiddleware "github.com/go-chi/chi/v5/middleware"
|
||||
"github.com/google/uuid"
|
||||
"go.opentelemetry.io/otel"
|
||||
"go.opentelemetry.io/otel/attribute"
|
||||
"go.opentelemetry.io/otel/codes"
|
||||
"go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploghttp"
|
||||
"go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp"
|
||||
"go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp"
|
||||
logapi "go.opentelemetry.io/otel/log"
|
||||
"go.opentelemetry.io/otel/metric"
|
||||
"go.opentelemetry.io/otel/propagation"
|
||||
sdklog "go.opentelemetry.io/otel/sdk/log"
|
||||
sdkmetric "go.opentelemetry.io/otel/sdk/metric"
|
||||
"go.opentelemetry.io/otel/sdk/resource"
|
||||
sdktrace "go.opentelemetry.io/otel/sdk/trace"
|
||||
"go.opentelemetry.io/otel/trace"
|
||||
"math"
|
||||
"net/http"
|
||||
"os"
|
||||
"strconv"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Telemetry struct {
|
||||
traces *sdktrace.TracerProvider
|
||||
meters *sdkmetric.MeterProvider
|
||||
logs *sdklog.LoggerProvider
|
||||
logger logapi.Logger
|
||||
requests metric.Int64Counter
|
||||
durations metric.Float64Histogram
|
||||
jobs metric.Int64Counter
|
||||
jobDuration metric.Float64Histogram
|
||||
readyDuration metric.Float64Histogram
|
||||
busy atomic.Int64
|
||||
poolPending atomic.Int64
|
||||
observationFailures atomic.Int64
|
||||
dbAcquire metric.Float64Histogram
|
||||
worker bool
|
||||
}
|
||||
|
||||
var current atomic.Pointer[Telemetry]
|
||||
|
||||
func Setup(ctx context.Context, service string) (*Telemetry, error) {
|
||||
endpoint := os.Getenv("OTEL_EXPORTER_OTLP_ENDPOINT")
|
||||
if endpoint == "" || os.Getenv("OTEL_SDK_DISABLED") == "true" {
|
||||
return nil, nil
|
||||
}
|
||||
ratio := 1.0
|
||||
if s := os.Getenv("OTEL_TRACES_SAMPLER_ARG"); s != "" {
|
||||
parsed, err := strconv.ParseFloat(s, 64)
|
||||
ratio = parsed
|
||||
if err != nil || math.IsNaN(ratio) || math.IsInf(ratio, 0) || ratio < 0 || ratio > 1 {
|
||||
return nil, fmt.Errorf("invalid sampling ratio")
|
||||
}
|
||||
}
|
||||
resource := resource.NewWithAttributes("", attribute.String("service.name", service), attribute.String("service.version", "lab6-v1"), attribute.String("service.instance.id", uuid.NewString()), attribute.String("deployment.environment.name", "lab"))
|
||||
tx, e := otlptracehttp.New(ctx, otlptracehttp.WithTimeout(time.Second), otlptracehttp.WithRetry(otlptracehttp.RetryConfig{Enabled: false}))
|
||||
if e != nil {
|
||||
return nil, e
|
||||
}
|
||||
mx, e := otlpmetrichttp.New(ctx, otlpmetrichttp.WithTimeout(time.Second), otlpmetrichttp.WithRetry(otlpmetrichttp.RetryConfig{Enabled: false}))
|
||||
if e != nil {
|
||||
return nil, e
|
||||
}
|
||||
lx, e := otlploghttp.New(ctx, otlploghttp.WithTimeout(time.Second), otlploghttp.WithRetry(otlploghttp.RetryConfig{Enabled: false}))
|
||||
if e != nil {
|
||||
return nil, e
|
||||
}
|
||||
t := &Telemetry{
|
||||
worker: service == "messenger-worker",
|
||||
traces: sdktrace.NewTracerProvider(sdktrace.WithResource(resource), sdktrace.WithSampler(sdktrace.ParentBased(sdktrace.TraceIDRatioBased(ratio))), sdktrace.WithBatcher(tx, sdktrace.WithMaxQueueSize(128), sdktrace.WithMaxExportBatchSize(32), sdktrace.WithBatchTimeout(time.Second), sdktrace.WithExportTimeout(time.Second))),
|
||||
meters: sdkmetric.NewMeterProvider(sdkmetric.WithResource(resource), sdkmetric.WithReader(sdkmetric.NewPeriodicReader(mx, sdkmetric.WithInterval(2*time.Second), sdkmetric.WithTimeout(time.Second)))),
|
||||
logs: sdklog.NewLoggerProvider(sdklog.WithResource(resource), sdklog.WithProcessor(sdklog.NewBatchProcessor(lx, sdklog.WithMaxQueueSize(128), sdklog.WithExportMaxBatchSize(32), sdklog.WithExportInterval(time.Second), sdklog.WithExportTimeout(time.Second)))),
|
||||
}
|
||||
otel.SetTracerProvider(t.traces)
|
||||
otel.SetMeterProvider(t.meters)
|
||||
otel.SetTextMapPropagator(propagation.TraceContext{})
|
||||
t.logger = t.logs.Logger("messenger")
|
||||
meter := t.meters.Meter("messenger")
|
||||
t.requests, e = meter.Int64Counter("http_requests", metric.WithDescription("Business HTTP requests"))
|
||||
if e != nil {
|
||||
return nil, e
|
||||
}
|
||||
t.durations, e = meter.Float64Histogram("http_duration", metric.WithUnit("s"), metric.WithExplicitBucketBoundaries(.005, .01, .025, .05, .1, .25, .5, 1, 2, 5))
|
||||
if e != nil {
|
||||
return nil, e
|
||||
}
|
||||
t.jobs, e = meter.Int64Counter("jobs_processed", metric.WithDescription("Owned processing attempts by result"))
|
||||
if e != nil {
|
||||
return nil, e
|
||||
}
|
||||
t.jobDuration, e = meter.Float64Histogram("job_duration", metric.WithUnit("s"), metric.WithExplicitBucketBoundaries(.01, .05, .1, .25, .5, 1, 2, 5, 10, 20))
|
||||
if e != nil {
|
||||
return nil, e
|
||||
}
|
||||
t.dbAcquire, e = meter.Float64Histogram("db_pool_acquire_duration", metric.WithUnit("s"), metric.WithExplicitBucketBoundaries(.001, .005, .01, .025, .05, .1, .25, .5, 1, 2))
|
||||
if e != nil {
|
||||
return nil, e
|
||||
}
|
||||
t.readyDuration, e = meter.Float64Histogram("time_to_ready", metric.WithUnit("s"), metric.WithExplicitBucketBoundaries(.1, .5, 1, 2, 5, 10, 30, 60, 120))
|
||||
if e != nil {
|
||||
return nil, e
|
||||
}
|
||||
current.Store(t)
|
||||
return t, nil
|
||||
}
|
||||
func (t *Telemetry) Shutdown(ctx context.Context) {
|
||||
if t == nil {
|
||||
return
|
||||
}
|
||||
_ = t.traces.Shutdown(ctx)
|
||||
_ = t.meters.Shutdown(ctx)
|
||||
_ = t.logs.Shutdown(ctx)
|
||||
}
|
||||
func (t *Telemetry) Event(ctx context.Context, event, outcome string, extra ...attribute.KeyValue) {
|
||||
if t == nil {
|
||||
return
|
||||
}
|
||||
var record logapi.Record
|
||||
record.SetTimestamp(time.Now())
|
||||
record.SetSeverity(logapi.SeverityInfo)
|
||||
record.SetSeverityText("INFO")
|
||||
record.SetBody(attribute.StringValue(event))
|
||||
record.SetEventName(event)
|
||||
record.AddAttributes(attribute.String("event", event), attribute.String("outcome", outcome))
|
||||
record.AddAttributes(extra...)
|
||||
t.logger.Emit(ctx, record)
|
||||
}
|
||||
func HTTP(next http.Handler) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
t := current.Load()
|
||||
if t == nil {
|
||||
next.ServeHTTP(w, r)
|
||||
return
|
||||
}
|
||||
ctx := otel.GetTextMapPropagator().Extract(r.Context(), propagation.HeaderCarrier(r.Header))
|
||||
ctx, span := otel.Tracer("messenger").Start(ctx, "HTTP", trace.WithSpanKind(trace.SpanKindServer))
|
||||
defer span.End()
|
||||
carrier := propagation.MapCarrier{}
|
||||
otel.GetTextMapPropagator().Inject(ctx, carrier)
|
||||
ctx = model.WithTrace(ctx, carrier.Get("traceparent"), carrier.Get("tracestate"))
|
||||
ww := chimiddleware.NewWrapResponseWriter(w, r.ProtoMajor)
|
||||
start := time.Now()
|
||||
next.ServeHTTP(ww, r.WithContext(ctx))
|
||||
route := chi.RouteContext(r.Context()).RoutePattern()
|
||||
if route == "" {
|
||||
route = "unmatched"
|
||||
}
|
||||
code := ww.Status()
|
||||
if code == 0 {
|
||||
code = 200
|
||||
}
|
||||
outcome := fmt.Sprintf("%dxx", code/100)
|
||||
method := r.Method
|
||||
switch method {
|
||||
case "GET", "POST", "DELETE", "PUT", "PATCH", "OPTIONS", "HEAD":
|
||||
default:
|
||||
method = "OTHER"
|
||||
}
|
||||
attrs := []attribute.KeyValue{attribute.String("method", method), attribute.String("route", route), attribute.String("status_class", outcome)}
|
||||
span.SetName(r.Method + " " + route)
|
||||
span.SetAttributes(attrs...)
|
||||
if code >= 500 {
|
||||
span.SetStatus(codes.Error, "server_error")
|
||||
}
|
||||
if route != "/health/ready" && route != "/health/live" {
|
||||
t.requests.Add(ctx, 1, metric.WithAttributes(attrs...))
|
||||
t.durations.Record(ctx, time.Since(start).Seconds(), metric.WithAttributes(attrs...))
|
||||
}
|
||||
if id := ww.Header().Get("X-Request-Id"); id != "" {
|
||||
t.Event(ctx, "http.request", outcome, attribute.String("request_id", id))
|
||||
} else {
|
||||
t.Event(ctx, "http.request", outcome)
|
||||
}
|
||||
})
|
||||
}
|
||||
func (t *Telemetry) Worker(next func(context.Context, model.Job) error) func(context.Context, model.Job) error {
|
||||
return func(ctx context.Context, j model.Job) error {
|
||||
if t == nil {
|
||||
return next(ctx, j)
|
||||
}
|
||||
t.busy.Add(1)
|
||||
defer t.busy.Add(-1)
|
||||
ctx = otel.GetTextMapPropagator().Extract(ctx, propagation.MapCarrier{"traceparent": j.Traceparent, "tracestate": j.Tracestate})
|
||||
ctx, span := otel.Tracer("messenger").Start(ctx, "attachment.process", trace.WithSpanKind(trace.SpanKindConsumer))
|
||||
defer span.End()
|
||||
e := next(ctx, j)
|
||||
outcome := "processed"
|
||||
if e != nil {
|
||||
outcome = "dependency_error"
|
||||
span.SetStatus(codes.Error, outcome)
|
||||
}
|
||||
t.Event(ctx, "worker.delivery", outcome)
|
||||
return e
|
||||
}
|
||||
}
|
||||
func (t *Telemetry) JobResult(ctx context.Context, j model.Job, outcome string, d time.Duration) {
|
||||
if t == nil {
|
||||
return
|
||||
}
|
||||
attrs := metric.WithAttributes(attribute.String("job_type", "attachment.process.v1"), attribute.String("outcome", outcome))
|
||||
t.jobs.Add(ctx, 1, attrs)
|
||||
t.jobDuration.Record(ctx, d.Seconds(), attrs)
|
||||
if outcome == "ready" {
|
||||
t.readyDuration.Record(ctx, time.Since(j.CreatedAt).Seconds(), metric.WithAttributes(attribute.String("job_type", "attachment.process.v1")))
|
||||
}
|
||||
t.Event(ctx, "worker.job", outcome)
|
||||
}
|
||||
@@ -0,0 +1,220 @@
|
||||
package telemetry
|
||||
|
||||
import (
|
||||
"backend/internal/domain/model"
|
||||
"bytes"
|
||||
"context"
|
||||
"github.com/go-chi/chi/v5"
|
||||
"github.com/jackc/pgx/v5/pgxpool"
|
||||
"go.opentelemetry.io/otel/trace"
|
||||
logpb "go.opentelemetry.io/proto/otlp/collector/logs/v1"
|
||||
metricpb "go.opentelemetry.io/proto/otlp/collector/metrics/v1"
|
||||
tracepb "go.opentelemetry.io/proto/otlp/collector/trace/v1"
|
||||
"google.golang.org/protobuf/proto"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"sync"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestRealOTLPExportsCorrelatedSignalsWithoutRequestSecrets(t *testing.T) {
|
||||
var mu sync.Mutex
|
||||
traces := &tracepb.ExportTraceServiceRequest{}
|
||||
logs := &logpb.ExportLogsServiceRequest{}
|
||||
metrics := &metricpb.ExportMetricsServiceRequest{}
|
||||
var exportErr error
|
||||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
raw, e := io.ReadAll(io.LimitReader(r.Body, 2<<20))
|
||||
mu.Lock()
|
||||
defer mu.Unlock()
|
||||
if e != nil {
|
||||
exportErr = e
|
||||
}
|
||||
if bytes.Contains(raw, []byte("synthetic-password-secret")) || bytes.Contains(raw, []byte("synthetic-token-secret")) {
|
||||
exportErr = io.ErrUnexpectedEOF
|
||||
}
|
||||
switch r.URL.Path {
|
||||
case "/v1/traces":
|
||||
v := &tracepb.ExportTraceServiceRequest{}
|
||||
if e := proto.Unmarshal(raw, v); e != nil {
|
||||
exportErr = e
|
||||
}
|
||||
traces.ResourceSpans = append(traces.ResourceSpans, v.ResourceSpans...)
|
||||
case "/v1/logs":
|
||||
v := &logpb.ExportLogsServiceRequest{}
|
||||
if e := proto.Unmarshal(raw, v); e != nil {
|
||||
exportErr = e
|
||||
}
|
||||
logs.ResourceLogs = append(logs.ResourceLogs, v.ResourceLogs...)
|
||||
case "/v1/metrics":
|
||||
v := &metricpb.ExportMetricsServiceRequest{}
|
||||
if e := proto.Unmarshal(raw, v); e != nil {
|
||||
exportErr = e
|
||||
}
|
||||
metrics.ResourceMetrics = append(metrics.ResourceMetrics, v.ResourceMetrics...)
|
||||
default:
|
||||
exportErr = io.ErrUnexpectedEOF
|
||||
}
|
||||
w.Header().Set("Content-Type", "application/x-protobuf")
|
||||
w.WriteHeader(200)
|
||||
}))
|
||||
defer server.Close()
|
||||
t.Setenv("OTEL_EXPORTER_OTLP_ENDPOINT", server.URL)
|
||||
t.Setenv("OTEL_SDK_DISABLED", "false")
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
||||
defer cancel()
|
||||
sdk, e := Setup(ctx, "messenger-api")
|
||||
if e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
defer sdk.Shutdown(context.Background())
|
||||
defer current.Store(nil)
|
||||
var accepted model.Job
|
||||
router := chi.NewRouter()
|
||||
router.Use(HTTP)
|
||||
router.Post("/api/v1/work", func(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("X-Request-Id", "synthetic-request-id")
|
||||
carrier := model.TraceFrom(r.Context())
|
||||
accepted = model.Job{Traceparent: carrier.Traceparent, Tracestate: carrier.Tracestate, CreatedAt: time.Now()}
|
||||
w.WriteHeader(202)
|
||||
})
|
||||
request := httptest.NewRequest("POST", "/api/v1/work", bytes.NewBufferString(`{"password":"synthetic-password-secret"}`))
|
||||
request.Header.Set("Authorization", "Bearer synthetic-token-secret")
|
||||
router.ServeHTTP(httptest.NewRecorder(), request)
|
||||
var workerTrace trace.TraceID
|
||||
if e = sdk.Worker(func(c context.Context, j model.Job) error {
|
||||
workerTrace = trace.SpanContextFromContext(c).TraceID()
|
||||
acquired := DBTracer{}.TraceAcquireStart(c, nil, pgxpool.TraceAcquireStartData{})
|
||||
if sdk.poolPending.Load() != 1 {
|
||||
t.Error("pending acquire not tracked")
|
||||
}
|
||||
DBTracer{}.TraceAcquireEnd(acquired, nil, pgxpool.TraceAcquireEndData{})
|
||||
if sdk.poolPending.Load() != 0 {
|
||||
t.Error("completed acquire still pending")
|
||||
}
|
||||
sdk.JobResult(c, j, "ready", time.Millisecond)
|
||||
return nil
|
||||
})(ctx, accepted); e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
if e = sdk.Gauges(func(context.Context) (map[string]float64, error) {
|
||||
return map[string]float64{"queue_depth": 2, "db_pool_capacity": 8}, nil
|
||||
}); e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
if e = sdk.traces.ForceFlush(ctx); e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
if e = sdk.logs.ForceFlush(ctx); e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
if e = sdk.meters.ForceFlush(ctx); e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
mu.Lock()
|
||||
defer mu.Unlock()
|
||||
if exportErr != nil {
|
||||
t.Fatal("OTLP decoding or secret exclusion failed")
|
||||
}
|
||||
spanCount, correlatedLogs := 0, 0
|
||||
requestCorrelated, queueNamed := false, false
|
||||
for _, rs := range traces.ResourceSpans {
|
||||
for _, ss := range rs.ScopeSpans {
|
||||
for _, s := range ss.Spans {
|
||||
if bytes.Equal(s.TraceId, workerTrace[:]) {
|
||||
spanCount++
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if spanCount != 3 {
|
||||
t.Fatal("API and worker spans lost common trace")
|
||||
}
|
||||
for _, rl := range logs.ResourceLogs {
|
||||
for _, sl := range rl.ScopeLogs {
|
||||
for _, l := range sl.LogRecords {
|
||||
for _, a := range l.Attributes {
|
||||
if a.Key == "request_id" && a.Value.GetStringValue() == "synthetic-request-id" {
|
||||
requestCorrelated = true
|
||||
}
|
||||
}
|
||||
if bytes.Equal(l.TraceId, workerTrace[:]) && len(l.SpanId) == 8 {
|
||||
correlatedLogs++
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if correlatedLogs < 3 {
|
||||
t.Fatal("structured logs lost trace/span correlation")
|
||||
}
|
||||
seen := map[string]bool{}
|
||||
for _, rm := range metrics.ResourceMetrics {
|
||||
for _, sm := range rm.ScopeMetrics {
|
||||
for _, m := range sm.Metrics {
|
||||
seen[m.Name] = true
|
||||
for _, p := range m.GetSum().GetDataPoints() {
|
||||
for _, a := range p.Attributes {
|
||||
if a.Key == "request_id" {
|
||||
t.Error("request id leaked into counter labels")
|
||||
}
|
||||
}
|
||||
}
|
||||
for _, p := range m.GetHistogram().GetDataPoints() {
|
||||
for _, a := range p.Attributes {
|
||||
if a.Key == "request_id" {
|
||||
t.Error("request id leaked into histogram labels")
|
||||
}
|
||||
}
|
||||
}
|
||||
if m.Name == "queue_depth" {
|
||||
for _, p := range m.GetGauge().GetDataPoints() {
|
||||
for _, a := range p.Attributes {
|
||||
if a.Key == "queue" && a.Value.GetStringValue() == "attachment-jobs" {
|
||||
queueNamed = true
|
||||
}
|
||||
if a.Key == "request_id" {
|
||||
t.Error("request identifier leaked into metric labels")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if !requestCorrelated || !queueNamed {
|
||||
t.Error("OTLP logs lost request-id correlation or queue metric omitted queue name")
|
||||
}
|
||||
for _, name := range []string{"http_requests", "http_duration", "jobs_processed", "job_duration", "time_to_ready", "queue_depth", "db_pool_capacity", "process_resident_memory_bytes", "db_pool_pending_acquires", "db_pool_acquire_duration"} {
|
||||
if !seen[name] {
|
||||
t.Fatal("actual metric was not exported: " + name)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestInvalidSamplingRatioFailsBeforeProviderSetup(t *testing.T) {
|
||||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "application/x-protobuf")
|
||||
w.WriteHeader(200)
|
||||
}))
|
||||
defer server.Close()
|
||||
t.Setenv("OTEL_EXPORTER_OTLP_ENDPOINT", server.URL)
|
||||
t.Setenv("OTEL_SDK_DISABLED", "false")
|
||||
defer current.Store(nil)
|
||||
for _, ratio := range []string{"NaN", "+Inf", "-Inf", "1.1", "-0.1", "not-a-number"} {
|
||||
t.Run(ratio, func(t *testing.T) {
|
||||
t.Setenv("OTEL_TRACES_SAMPLER_ARG", ratio)
|
||||
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
|
||||
defer cancel()
|
||||
sdk, e := Setup(ctx, "messenger-api")
|
||||
if e == nil {
|
||||
sdk.Shutdown(ctx)
|
||||
t.Fatal("invalid/nonfinite sampling ratio accepted")
|
||||
}
|
||||
if sdk != nil {
|
||||
t.Fatal("failed configuration published a provider")
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
package usecase
|
||||
|
||||
import (
|
||||
"backend/internal/domain/model"
|
||||
"backend/internal/domain/port"
|
||||
"backend/internal/domain/repository"
|
||||
"context"
|
||||
"github.com/google/uuid"
|
||||
"io"
|
||||
)
|
||||
|
||||
type Attachments struct {
|
||||
repo repository.AsyncAttachments
|
||||
messenger *Messenger
|
||||
objects port.Objects
|
||||
}
|
||||
|
||||
func NewAttachments(r repository.AsyncAttachments, m *Messenger, o port.Objects) *Attachments {
|
||||
return &Attachments{r, m, o}
|
||||
}
|
||||
func ObjectKey(id uuid.UUID) string { return "originals/" + id.String() }
|
||||
func (a *Attachments) Upload(ctx context.Context, caller, chat uuid.UUID, name, mime, sha string, size int64, body io.Reader) (model.Attachment, error) {
|
||||
if _, e := a.messenger.GetChat(ctx, caller, chat); e != nil {
|
||||
return model.Attachment{}, e
|
||||
}
|
||||
row, e := a.repo.ReserveAttachment(ctx, model.Attachment{ID: uuid.New(), ChatID: chat, OwnerID: caller, Filename: name, ContentType: mime, SHA256: sha, SizeBytes: size})
|
||||
if e != nil {
|
||||
return model.Attachment{}, e
|
||||
}
|
||||
if e = a.objects.Put(ctx, "staging/"+row.ID.String(), body, size, mime); e != nil {
|
||||
return model.Attachment{}, model.ErrUnavailable
|
||||
}
|
||||
carrier := model.TraceFrom(ctx)
|
||||
return a.repo.QueueAttachment(ctx, row, carrier.Traceparent, carrier.Tracestate)
|
||||
}
|
||||
func (a *Attachments) Get(ctx context.Context, caller, id uuid.UUID) (model.Attachment, error) {
|
||||
row, e := a.repo.GetAttachment(ctx, id)
|
||||
if e != nil {
|
||||
return model.Attachment{}, e
|
||||
}
|
||||
if _, e = a.messenger.GetChat(ctx, caller, row.ChatID); e != nil {
|
||||
return model.Attachment{}, e
|
||||
}
|
||||
return row, nil
|
||||
}
|
||||
func (a *Attachments) Content(ctx context.Context, caller, id uuid.UUID, variant string) (model.Attachment, io.ReadCloser, error) {
|
||||
row, e := a.Get(ctx, caller, id)
|
||||
if e != nil {
|
||||
return row, nil, e
|
||||
}
|
||||
if row.Status != "ready" {
|
||||
return row, nil, model.ErrConflict
|
||||
}
|
||||
key := ObjectKey(id)
|
||||
if variant != "original" {
|
||||
found := false
|
||||
for _, v := range row.Variants {
|
||||
if v.Name == variant {
|
||||
found = true
|
||||
key = VariantKey(id, row.PipelineVersion, variant)
|
||||
row.SizeBytes = v.SizeBytes
|
||||
row.ContentType = v.ContentType
|
||||
row.SHA256 = v.SHA256
|
||||
break
|
||||
}
|
||||
}
|
||||
if !found {
|
||||
return row, nil, model.ErrNotFound
|
||||
}
|
||||
}
|
||||
info, e := a.objects.Stat(ctx, key)
|
||||
if e != nil || info.Size != row.SizeBytes {
|
||||
return row, nil, model.ErrUnavailable
|
||||
}
|
||||
r, e := a.objects.Get(ctx, key)
|
||||
if e != nil {
|
||||
return row, nil, model.ErrUnavailable
|
||||
}
|
||||
return row, r, nil
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user