From 5fda36b723769274d89178b592d98d0617676d69 Mon Sep 17 00:00:00 2001 From: Vladislav Kunetskiy Date: Thu, 5 Nov 2026 21:14:34 +0300 Subject: [PATCH] lab6 --- .dockerignore | 7 + .env.example | 193 +- .github/workflows/app.yml | 125 + .gitignore | 8 + .golangci.yml | 139 + .mockery.yml | 38 + .ogen.yml | 10 + Dockerfile | 77 + Makefile | 177 +- REPORT.md | 212 +- cmd/jobctl/main.go | 215 + cmd/messenger/main.go | 269 + cmd/migrate/main.go | 89 + cmd/relay/main.go | 294 + cmd/s3init/main.go | 223 + cmd/worker/main.go | 263 + compose.yaml | 631 + config/dev/config.yaml | 54 + docker-compose.local.yaml | 283 + evidence/arch.txt | 7 + evidence/body-limit.txt | 3 + evidence/db-outage.txt | 7 + evidence/failover/run1.txt | 5 + evidence/failover/run2.txt | 5 + evidence/failover/sequential.txt | 54 + evidence/idempotency.txt | 4 + evidence/lab1-2/README.md | 17 + evidence/lab1-2/cache/api-performance.txt | 11 + evidence/lab1-2/cache/consistency.txt | 36 + evidence/lab1-2/cache/latency.txt | 22 + evidence/lab1-2/cache/performance.txt | 26 + evidence/lab1-2/cache/redis-outage.txt | 8 + evidence/lab1-2/check.txt | 3 + evidence/lab1-2/concurrency.txt | 2 + evidence/lab1-2/docker.txt | 11 + evidence/lab1-2/health.txt | 1 + evidence/lab1-2/memory-experiment.json | 17279 ++++++++++++++++ evidence/lab1-2/memory-experiment.png | Bin 0 -> 104191 bytes evidence/lab1-2/memory-experiment.txt | 8 + evidence/lab1-2/postgres/explain-analyze.txt | 64 + evidence/lab1-2/quality.txt | 43 + evidence/lab1-2/restart.txt | 10 + evidence/lab1-2/sigterm.txt | 7 + .../baseline-storage-benchmark.txt | 21 + .../lab1-2/track1-benchmark/baseline.json | 128 + .../lab1-2/track1-benchmark/comparison.json | 110 + .../track1-benchmark/go-baseline/results.json | 211 + .../track1-benchmark/go-comparison.json | 266 + .../go-optimized/results.json | 209 + .../optimized-storage-benchmark.txt | 21 + .../lab1-2/track1-benchmark/optimized.json | 128 + evidence/lab4/README.md | 30 + evidence/lab4/expiry.txt | 3 + evidence/lab4/failover.txt | 1 + evidence/lab4/memory/samples.csv | 7 + evidence/lab4/memory/summary.txt | 11 + evidence/lab4/negative.txt | 14 + evidence/lab4/persistence.txt | 3 + evidence/lab4/presign.txt | 10 + evidence/lab4/private-bucket.txt | 10 + evidence/lab4/s3-init.txt | 14 + evidence/lab4/s3-outage.txt | 8 + evidence/lab4/smoke.txt | 2 + evidence/lab4/sweep.txt | 4 + evidence/lab4/track1/results.csv | 21 + evidence/lab4/track1/summary.txt | 12 + evidence/lab5/README.md | 20 + evidence/lab5/async.txt | 12 + evidence/lab5/attachments-negative.txt | 25 + evidence/lab5/db-state.txt | 29 + evidence/lab5/failover.txt | 5 + evidence/lab5/faults.txt | 15 + evidence/lab5/idempotency.txt | 4 + evidence/lab5/integration-test.txt | 2 + evidence/lab5/lb-readiness-detail.txt | 31 + evidence/lab5/lb-readiness.txt | 34 + evidence/lab5/lint.txt | 20 + evidence/lab5/persistence.txt | 4 + evidence/lab5/presign.txt | 11 + evidence/lab5/smoke.txt | 3 + evidence/lab5/stand.txt | 20 + evidence/lab5/track2/run.txt | 7 + evidence/lab5/track2/runs.csv | 7 + evidence/lab5/track2/summary.md | 21 + evidence/lab5/unit-test.txt | 41 + evidence/lab5/validate.txt | 3 + evidence/lab5/variants.txt | 3 + evidence/lab6/README.md | 30 + evidence/lab6/checks/alert-audit.json | 77 + evidence/lab6/checks/alert-audit.md | 11 + evidence/lab6/checks/alert-audit.txt | 12 + evidence/lab6/checks/clean.txt | 57 + evidence/lab6/checks/collector-down-load.json | 27 + evidence/lab6/checks/collector-metrics.txt | 29 + evidence/lab6/checks/integration.txt | 6 + evidence/lab6/checks/static.txt | 84 + evidence/lab6/checks/storage-down-load.json | 27 + evidence/lab6/checks/storage-down-series.txt | 1265 ++ evidence/lab6/checks/trace-retry-run.txt | 16 + evidence/lab6/checks/ttr-selector.txt | 6 + evidence/lab6/checks/ttr-worker-15m.txt | 47 + evidence/lab6/checks/ttr-worker-down.txt | 28 + evidence/lab6/collector-down.txt | 78 + evidence/lab6/db-down.txt | 55 + evidence/lab6/db-pause.txt | 13 + evidence/lab6/load-smoke.json | 25 + evidence/lab6/metrics.txt | 15 + evidence/lab6/queries/promql.txt | 48 + evidence/lab6/regression/attachments.txt | 24 + evidence/lab6/regression/failover.txt | 4 + evidence/lab6/regression/faults.txt | 14 + evidence/lab6/regression/idempotency.txt | 3 + evidence/lab6/regression/integration.txt | 3 + evidence/lab6/regression/lint.txt | 20 + evidence/lab6/regression/load.txt | 15 + evidence/lab6/regression/persistence.txt | 3 + evidence/lab6/regression/presign.txt | 10 + evidence/lab6/regression/queue.txt | 11 + evidence/lab6/regression/track2-lab5.txt | 8 + evidence/lab6/smoke.txt | 2 + evidence/lab6/stand.txt | 15 + evidence/lab6/storage-down-series.json | 866 + evidence/lab6/storage-down.txt | 870 + evidence/lab6/telemetry.txt | 5 + evidence/lab6/tempo-search.json | 148 + evidence/lab6/trace-pipeline.json | 1776 ++ evidence/lab6/trace-retry.json | 1 + evidence/lab6/trace-retry.txt | 10 + evidence/lab6/track2/full-run.txt | 11 + evidence/lab6/track2/full/alert-audit.json | 83 + evidence/lab6/track2/full/alert-audit.md | 11 + evidence/lab6/track2/full/alerts.csv | 20 + evidence/lab6/track2/full/alerts.json | 154 + evidence/lab6/track2/full/baseline-load.json | 27 + evidence/lab6/track2/full/baseline.json | 12 + evidence/lab6/track2/full/burst-load.json | 40 + evidence/lab6/track2/full/burst.json | 26 + .../lab6/track2/full/false-positive-load.json | 27 + evidence/lab6/track2/full/final.json | 12 + evidence/lab6/track2/full/phases.json | 58 + evidence/lab6/track2/full/preflight-load.json | 27 + .../lab6/track2/full/resolution-load.json | 27 + .../baseline-2026-11-06T02-57-50Z.json | 12 + .../baseline-2026-11-06T10-02-51Z.json | 12 + .../burst-active-2026-11-06T02-58-30Z.json | 12 + .../burst-active-2026-11-06T10-03-31Z.json | 12 + .../burst-after-2026-11-06T04-26-41Z.json | 12 + .../burst-after-2026-11-06T11-29-41Z.json | 12 + .../snapshots/final-2026-11-06T06-22-18Z.json | 12 + .../snapshots/final-2026-11-06T13-30-24Z.json | 12 + .../final-summary-2026-11-06T06-22-19Z.json | 12 + .../final-summary-2026-11-06T13-30-25Z.json | 12 + .../resolution-2026-11-06T05-46-42Z.json | 12 + .../resolution-2026-11-06T12-52-06Z.json | 12 + ...sustained-active-2026-11-06T04-27-21Z.json | 12 + ...sustained-active-2026-11-06T11-30-21Z.json | 12 + .../sustained-after-2026-11-06T04-46-46Z.json | 12 + .../sustained-after-2026-11-06T11-49-53Z.json | 12 + .../ttr-after-2026-11-06T06-02-23Z.json | 12 + .../ttr-after-2026-11-06T13-07-47Z.json | 12 + .../warmup-2026-11-06T02-37-54Z.json | 12 + .../warmup-2026-11-06T09-42-56Z.json | 12 + evidence/lab6/track2/full/summary.md | 82 + evidence/lab6/track2/full/sustained-load.json | 40 + evidence/lab6/track2/full/sustained.json | 27 + evidence/lab6/track2/full/ttr-load.json | 41 + evidence/lab6/track2/full/warmup-load.json | 27 + evidence/lab6/track2/ttd-ttr.md | 63 + evidence/lab6/unit-test.txt | 43 + evidence/lab6/worker-stop.txt | 18 + evidence/lab6/worker-stopped-load.json | 30 + evidence/lb-readiness.txt | 31 + evidence/load-32clients.json | 17 + evidence/load-32clients.txt | 18 + evidence/native-load.json | 22 + evidence/native-load.txt | 23 + evidence/path-overhead/README.md | 40 + evidence/path-overhead/inside.txt | 17 + evidence/path-overhead/load-inside.json | 17 + evidence/path-overhead/load-outside.json | 17 + evidence/path-overhead/outside.txt | 17 + evidence/path-overhead/summary.txt | 9 + evidence/persistence.txt | 4 + evidence/quality.txt | 35 + evidence/quota-semantics.txt | 33 + evidence/rolling-update/after/load.json | 26 + evidence/rolling-update/after/load.txt | 26 + .../rolling-update/after/rolling-update.txt | 136 + evidence/rolling-update/emulated/load.json | 23 + evidence/rolling-update/emulated/load.txt | 23 + .../emulated/rolling-update.txt | 134 + evidence/smoke.txt | 3 + evidence/stand.txt | 34 + evidence/track1/load-ctl1base.json | 17 + evidence/track1/load-ctl2pg.json | 17 + evidence/track1/load-ctl3base.json | 17 + evidence/track1/load-ctl4lb.json | 17 + evidence/track1/load-d2.json | 17 + evidence/track1/load-db1cpu.json | 17 + evidence/track1/load-g05.json | 17 + evidence/track1/load-g10.json | 17 + evidence/track1/load-g15.json | 17 + evidence/track1/load-lb1cpu.json | 17 + evidence/track1/load-pool10.json | 17 + evidence/track1/load-pool5.json | 17 + evidence/track1/load-r1.json | 17 + evidence/track1/load-r2.json | 17 + evidence/track1/load-r4.json | 17 + evidence/track1/profile-ctl1base.json | 1 + evidence/track1/profile-ctl2pg.json | 1 + evidence/track1/profile-ctl3base.json | 1 + evidence/track1/profile-ctl4lb.json | 1 + evidence/track1/profile-d2.json | 1 + evidence/track1/profile-db1cpu.json | 1 + evidence/track1/profile-g05.json | 1 + evidence/track1/profile-g10.json | 1 + evidence/track1/profile-g15.json | 1 + evidence/track1/profile-lb1cpu.json | 1 + evidence/track1/profile-pool10.json | 1 + evidence/track1/profile-pool5.json | 1 + evidence/track1/profile-r1.json | 1 + evidence/track1/profile-r2.json | 1 + evidence/track1/profile-r4.json | 1 + evidence/track1/scaling-fixed-budget.png | Bin 0 -> 55891 bytes evidence/track1/scaling-growth.png | Bin 0 -> 63171 bytes evidence/track1/stats-ctl1base.csv | 160 + evidence/track1/stats-ctl2pg.csv | 160 + evidence/track1/stats-ctl3base.csv | 161 + evidence/track1/stats-ctl4lb.csv | 160 + evidence/track1/stats-d2.csv | 160 + evidence/track1/stats-db1cpu.csv | 160 + evidence/track1/stats-g05.csv | 160 + evidence/track1/stats-g10.csv | 160 + evidence/track1/stats-g15.csv | 160 + evidence/track1/stats-lb1cpu.csv | 160 + evidence/track1/stats-pool10.csv | 200 + evidence/track1/stats-pool5.csv | 200 + evidence/track1/stats-r1.csv | 141 + evidence/track1/stats-r2.csv | 160 + evidence/track1/stats-r4.csv | 200 + evidence/track1/summary.md | 19 + evidence/track1/summary.txt | 411 + go.mod | 155 + go.sum | 381 + infra/README.md | 23 +- infra/grafana/dashboards/api-overview.json | 612 + .../grafana/dashboards/infra-saturation.json | 452 + infra/grafana/dashboards/jobs-pipeline.json | 430 + .../provisioning/dashboards/dashboards.yaml | 10 + .../provisioning/datasources/datasources.yaml | 36 + infra/lb/haproxy.cfg | 92 + infra/loki/loki.yaml | 65 + infra/otel/README.md | 16 +- infra/otel/collector.yaml | 86 + infra/prometheus/prometheus.yml | 28 + infra/prometheus/rules/alerts.yml | 160 + infra/prometheus/rules/slo.yml | 95 + infra/prometheus/tests/ttr_test.yml | 65 + infra/rabbitmq/rabbitmq.conf | 3 + infra/runbooks/api-errors.md | 8 + infra/runbooks/db-availability.md | 8 + infra/runbooks/queue-lag.md | 8 + infra/runbooks/slo-burn.md | 15 + infra/runbooks/telemetry-backend-down.md | 8 + infra/s3/README.md | 27 + infra/s3/s3.json | 24 + infra/tempo/tempo.yaml | 27 + internal/broker/rabbit.go | 320 + internal/config/config.go | 425 + internal/config/config_test.go | 343 + internal/domain/attachment.go | 171 + internal/domain/chat.go | 51 + internal/domain/cursor.go | 17 + internal/domain/errors.go | 19 + internal/domain/job.go | 192 + internal/domain/keys.go | 31 + internal/domain/message.go | 70 + internal/domain/page.go | 8 + internal/domain/session.go | 19 + internal/domain/text.go | 14 + internal/domain/user.go | 44 + internal/domain/validation_test.go | 121 + internal/failpoint/failpoint.go | 107 + internal/health/checker.go | 28 + internal/health/checker_test.go | 33 + internal/imagecheck/imagecheck.go | 668 + internal/imagecheck/imagecheck_test.go | 483 + internal/imageproc/exif.go | 118 + internal/imageproc/imageproc.go | 259 + internal/imageproc/imageproc_test.go | 222 + internal/logger/errors.go | 8 + internal/logger/logger.go | 138 + internal/logger/logger_test.go | 193 + internal/outbox/relay.go | 199 + internal/platform/cache/cache.go | 31 + internal/platform/cache/cache_test.go | 31 + internal/platform/cache/distributed.go | 307 + .../cache/distributed_internal_test.go | 43 + internal/platform/cache/distributed_test.go | 374 + internal/platform/cache/mocks/Cache.go | 346 + internal/platform/cache/mocks/LockStore.go | 562 + internal/platform/cache/redis.go | 139 + internal/platform/cache/redis_client_test.go | 32 + internal/platform/instanceid/instanceid.go | 18 + internal/platform/objectstore/objectstore.go | 34 + internal/platform/objectstore/s3.go | 305 + internal/platform/objectstore/s3_test.go | 26 + internal/platform/password/password.go | 52 + internal/platform/password/password_test.go | 33 + internal/platform/token/token.go | 40 + internal/platform/token/token_test.go | 44 + .../service/attachment/mocks/LockStore.go | 115 + .../service/attachment/mocks/Repository.go | 804 + .../attachment/mocks/SweepRepository.go | 398 + internal/service/attachment/service.go | 712 + internal/service/attachment/service_test.go | 509 + internal/service/attachment/sweeper.go | 236 + internal/service/attachment/sweeper_test.go | 113 + internal/service/chat/mocks/Repository.go | 265 + internal/service/chat/service.go | 69 + internal/service/chat/service_test.go | 140 + .../message/mocks/AttachmentChecker.go | 123 + internal/service/message/mocks/Repository.go | 343 + internal/service/message/service.go | 118 + internal/service/message/service_test.go | 261 + internal/service/session/mocks/Repository.go | 310 + internal/service/session/mocks/Tokens.go | 168 + internal/service/session/service.go | 95 + internal/service/session/service_test.go | 146 + internal/service/user/mocks/Repository.go | 181 + internal/service/user/service.go | 55 + internal/service/user/service_test.go | 104 + .../postgres/cache_latency_experiment_test.go | 159 + .../cache_performance_experiment_test.go | 192 + internal/storage/postgres/chat_repository.go | 162 + .../storage/postgres/chat_repository_test.go | 239 + internal/storage/postgres/config.go | 74 + internal/storage/postgres/config_test.go | 49 + internal/storage/postgres/errors.go | 96 + internal/storage/postgres/errors_test.go | 32 + internal/storage/postgres/idempotency_test.go | 183 + .../internal/sqlcgen/attachments.sql.go | 60 + .../postgres/internal/sqlcgen/chats.sql.go | 251 + .../storage/postgres/internal/sqlcgen/db.go | 32 + .../internal/sqlcgen/idempotency.sql.go | 157 + .../postgres/internal/sqlcgen/messages.sql.go | 160 + .../postgres/internal/sqlcgen/models.go | 143 + .../postgres/internal/sqlcgen/sessions.sql.go | 83 + .../postgres/internal/sqlcgen/users.sql.go | 100 + internal/storage/postgres/main_test.go | 291 + internal/storage/postgres/mapping.go | 21 + .../storage/postgres/message_repository.go | 361 + .../postgres/message_repository_test.go | 161 + .../postgres/migrations/00001_init.sql | 71 + .../migrations/00003_message_idempotency.sql | 25 + .../postgres/migrations/00004_attachments.sql | 55 + .../migrations/00005_async_pipeline.sql | 150 + .../migrations/00006_job_trace_context.sql | 12 + .../postgres/migrations/00007_ttr_missed.sql | 14 + .../migrations/00008_ttr_missed_indexes.sql | 12 + .../storage/postgres/migrations/migrations.go | 6 + internal/storage/postgres/pagination.go | 25 + .../storage/postgres/pipeline_repository.go | 2156 ++ .../postgres/pipeline_repository_test.go | 586 + .../storage/postgres/queries/attachments.sql | 9 + internal/storage/postgres/queries/chats.sql | 75 + .../storage/postgres/queries/idempotency.sql | 50 + .../storage/postgres/queries/messages.sql | 39 + .../storage/postgres/queries/sessions.sql | 16 + internal/storage/postgres/queries/users.sql | 14 + .../storage/postgres/session_repository.go | 94 + .../postgres/session_repository_test.go | 81 + internal/storage/postgres/store.go | 165 + internal/storage/postgres/transaction.go | 32 + internal/storage/postgres/user_repository.go | 63 + .../storage/postgres/user_repository_test.go | 114 + internal/storage/redis/chat_repository.go | 183 + .../storage/redis/chat_repository_test.go | 428 + internal/storage/redis/main_test.go | 66 + internal/storage/redis/mocks/ChatSource.go | 331 + internal/telemetry/db.go | 40 + internal/telemetry/job.go | 100 + internal/telemetry/log.go | 220 + internal/telemetry/log_test.go | 129 + internal/telemetry/metrics.go | 184 + internal/telemetry/objectstore.go | 107 + internal/telemetry/process.go | 124 + internal/telemetry/setup.go | 185 + internal/transport/rest/attachments.go | 183 + internal/transport/rest/bodylimit.go | 57 + internal/transport/rest/bodylimit_test.go | 65 + internal/transport/rest/errors.go | 158 + internal/transport/rest/errors_test.go | 42 + internal/transport/rest/extensions.go | 251 + internal/transport/rest/extensions_test.go | 64 + internal/transport/rest/handler.go | 435 + internal/transport/rest/handler_test.go | 39 + internal/transport/rest/instance.go | 67 + internal/transport/rest/instance_test.go | 77 + .../rest/internal/oas/oas_cfg_gen.go | 175 + .../rest/internal/oas/oas_defaults_gen.go | 15 + .../rest/internal/oas/oas_handlers_gen.go | 1660 ++ .../rest/internal/oas/oas_interfaces_gen.go | 62 + .../rest/internal/oas/oas_json_gen.go | 2369 +++ .../rest/internal/oas/oas_middleware_gen.go | 10 + .../rest/internal/oas/oas_operations_gen.go | 23 + .../rest/internal/oas/oas_parameters_gen.go | 942 + .../internal/oas/oas_request_decoders_gen.go | 291 + .../internal/oas/oas_response_encoders_gen.go | 5014 +++++ .../rest/internal/oas/oas_router_gen.go | 996 + .../rest/internal/oas/oas_schemas_gen.go | 2176 ++ .../rest/internal/oas/oas_security_gen.go | 134 + .../rest/internal/oas/oas_server_gen.go | 116 + .../internal/oas/oas_unimplemented_gen.go | 140 + .../rest/internal/oas/oas_validators_gen.go | 2653 +++ internal/transport/rest/logging.go | 145 + internal/transport/rest/logging_test.go | 228 + .../transport/rest/mocks/AttachmentService.go | 425 + internal/transport/rest/mocks/ChatService.go | 265 + .../transport/rest/mocks/HealthChecker.go | 98 + .../transport/rest/mocks/MessageService.go | 199 + .../transport/rest/mocks/SecSessionService.go | 186 + .../transport/rest/mocks/SessionActions.go | 316 + .../transport/rest/mocks/SessionResolver.go | 114 + .../transport/rest/mocks/SessionService.go | 178 + internal/transport/rest/mocks/UserLookup.go | 115 + internal/transport/rest/mocks/UserService.go | 181 + internal/transport/rest/requestid.go | 38 + internal/transport/rest/router.go | 45 + internal/transport/rest/router_test.go | 483 + internal/transport/rest/security.go | 60 + internal/transport/rest/telemetry.go | 90 + internal/worker/worker.go | 614 + internal/worker/worker_test.go | 34 + scripts/api_cache_performance.sh | 16 + scripts/cache_evidence.sh | 21 + scripts/cache_latency_experiment.sh | 17 + scripts/cache_performance_experiment.sh | 17 + scripts/check_evidence.py | 46 + scripts/check_s3_creds.py | 74 + scripts/init-secrets.sh | 8 + scripts/lab4_memory_experiment.py | 147 + scripts/lab4_track1.py | 179 + scripts/lab5_track2.py | 165 + scripts/lab6_alert_audit.py | 81 + scripts/lab6_alerts.py | 72 + scripts/lab6_collector_down.py | 96 + scripts/lab6_load.py | 184 + scripts/lab6_storage_down_series.py | 123 + scripts/lab6_track2.py | 91 + scripts/lab6_track2_full.py | 395 + scripts/lab6_ttr_worker_down.py | 110 + scripts/lab6_verify.py | 314 + scripts/lb_readiness_check.sh | 200 + scripts/memory_experiment.py | 271 + scripts/path_overhead_check.sh | 68 + scripts/redis_outage_check.py | 132 + scripts/restart.sh | 58 + scripts/rolling_update.sh | 231 + scripts/start-broker.sh | 6 + scripts/start-worker.sh | 6 + scripts/stop-broker.sh | 6 + scripts/stop-one.sh | 72 + scripts/stop-worker.sh | 7 + scripts/track1_controls.sh | 48 + scripts/track1_report.py | 209 + scripts/track1_scaling.sh | 319 + scripts/track1_series.sh | 69 + sqlc.yaml | 19 + student-tests/attachment_failover.py | 81 + student-tests/attachments_negative.py | 229 + student-tests/cache_api_performance.py | 156 + student-tests/idempotency_parallel.py | 144 + student-tests/lab5_async.py | 153 + student-tests/lab5_faults.py | 325 + student-tests/lab5_variants.py | 89 + student-tests/presign_flow.py | 150 + student-tests/replica_failover.py | 197 + student-tests/rolling_update_load.py | 157 + student-tests/tests_helpers.py | 65 + tools/specgen/main.go | 177 + 481 files changed, 84873 insertions(+), 57 deletions(-) create mode 100644 .github/workflows/app.yml create mode 100644 .golangci.yml create mode 100644 .mockery.yml create mode 100644 .ogen.yml create mode 100644 Dockerfile create mode 100644 cmd/jobctl/main.go create mode 100644 cmd/messenger/main.go create mode 100644 cmd/migrate/main.go create mode 100644 cmd/relay/main.go create mode 100644 cmd/s3init/main.go create mode 100644 cmd/worker/main.go create mode 100644 compose.yaml create mode 100644 config/dev/config.yaml create mode 100644 docker-compose.local.yaml create mode 100644 evidence/arch.txt create mode 100644 evidence/body-limit.txt create mode 100644 evidence/db-outage.txt create mode 100644 evidence/failover/run1.txt create mode 100644 evidence/failover/run2.txt create mode 100644 evidence/failover/sequential.txt create mode 100644 evidence/idempotency.txt create mode 100644 evidence/lab1-2/README.md create mode 100644 evidence/lab1-2/cache/api-performance.txt create mode 100644 evidence/lab1-2/cache/consistency.txt create mode 100644 evidence/lab1-2/cache/latency.txt create mode 100644 evidence/lab1-2/cache/performance.txt create mode 100644 evidence/lab1-2/cache/redis-outage.txt create mode 100644 evidence/lab1-2/check.txt create mode 100644 evidence/lab1-2/concurrency.txt create mode 100644 evidence/lab1-2/docker.txt create mode 100644 evidence/lab1-2/health.txt create mode 100644 evidence/lab1-2/memory-experiment.json create mode 100644 evidence/lab1-2/memory-experiment.png create mode 100644 evidence/lab1-2/memory-experiment.txt create mode 100644 evidence/lab1-2/postgres/explain-analyze.txt create mode 100644 evidence/lab1-2/quality.txt create mode 100644 evidence/lab1-2/restart.txt create mode 100644 evidence/lab1-2/sigterm.txt create mode 100644 evidence/lab1-2/track1-benchmark/baseline-storage-benchmark.txt create mode 100644 evidence/lab1-2/track1-benchmark/baseline.json create mode 100644 evidence/lab1-2/track1-benchmark/comparison.json create mode 100644 evidence/lab1-2/track1-benchmark/go-baseline/results.json create mode 100644 evidence/lab1-2/track1-benchmark/go-comparison.json create mode 100644 evidence/lab1-2/track1-benchmark/go-optimized/results.json create mode 100644 evidence/lab1-2/track1-benchmark/optimized-storage-benchmark.txt create mode 100644 evidence/lab1-2/track1-benchmark/optimized.json create mode 100644 evidence/lab4/README.md create mode 100644 evidence/lab4/expiry.txt create mode 100644 evidence/lab4/failover.txt create mode 100644 evidence/lab4/memory/samples.csv create mode 100644 evidence/lab4/memory/summary.txt create mode 100644 evidence/lab4/negative.txt create mode 100644 evidence/lab4/persistence.txt create mode 100644 evidence/lab4/presign.txt create mode 100644 evidence/lab4/private-bucket.txt create mode 100644 evidence/lab4/s3-init.txt create mode 100644 evidence/lab4/s3-outage.txt create mode 100644 evidence/lab4/smoke.txt create mode 100644 evidence/lab4/sweep.txt create mode 100644 evidence/lab4/track1/results.csv create mode 100644 evidence/lab4/track1/summary.txt create mode 100644 evidence/lab5/README.md create mode 100644 evidence/lab5/async.txt create mode 100644 evidence/lab5/attachments-negative.txt create mode 100644 evidence/lab5/db-state.txt create mode 100644 evidence/lab5/failover.txt create mode 100644 evidence/lab5/faults.txt create mode 100644 evidence/lab5/idempotency.txt create mode 100644 evidence/lab5/integration-test.txt create mode 100644 evidence/lab5/lb-readiness-detail.txt create mode 100644 evidence/lab5/lb-readiness.txt create mode 100644 evidence/lab5/lint.txt create mode 100644 evidence/lab5/persistence.txt create mode 100644 evidence/lab5/presign.txt create mode 100644 evidence/lab5/smoke.txt create mode 100644 evidence/lab5/stand.txt create mode 100644 evidence/lab5/track2/run.txt create mode 100644 evidence/lab5/track2/runs.csv create mode 100644 evidence/lab5/track2/summary.md create mode 100644 evidence/lab5/unit-test.txt create mode 100644 evidence/lab5/validate.txt create mode 100644 evidence/lab5/variants.txt create mode 100644 evidence/lab6/README.md create mode 100644 evidence/lab6/checks/alert-audit.json create mode 100644 evidence/lab6/checks/alert-audit.md create mode 100644 evidence/lab6/checks/alert-audit.txt create mode 100644 evidence/lab6/checks/clean.txt create mode 100644 evidence/lab6/checks/collector-down-load.json create mode 100644 evidence/lab6/checks/collector-metrics.txt create mode 100644 evidence/lab6/checks/integration.txt create mode 100644 evidence/lab6/checks/static.txt create mode 100644 evidence/lab6/checks/storage-down-load.json create mode 100644 evidence/lab6/checks/storage-down-series.txt create mode 100644 evidence/lab6/checks/trace-retry-run.txt create mode 100644 evidence/lab6/checks/ttr-selector.txt create mode 100644 evidence/lab6/checks/ttr-worker-15m.txt create mode 100644 evidence/lab6/checks/ttr-worker-down.txt create mode 100644 evidence/lab6/collector-down.txt create mode 100644 evidence/lab6/db-down.txt create mode 100644 evidence/lab6/db-pause.txt create mode 100644 evidence/lab6/load-smoke.json create mode 100644 evidence/lab6/metrics.txt create mode 100644 evidence/lab6/queries/promql.txt create mode 100644 evidence/lab6/regression/attachments.txt create mode 100644 evidence/lab6/regression/failover.txt create mode 100644 evidence/lab6/regression/faults.txt create mode 100644 evidence/lab6/regression/idempotency.txt create mode 100644 evidence/lab6/regression/integration.txt create mode 100644 evidence/lab6/regression/lint.txt create mode 100644 evidence/lab6/regression/load.txt create mode 100644 evidence/lab6/regression/persistence.txt create mode 100644 evidence/lab6/regression/presign.txt create mode 100644 evidence/lab6/regression/queue.txt create mode 100644 evidence/lab6/regression/track2-lab5.txt create mode 100644 evidence/lab6/smoke.txt create mode 100644 evidence/lab6/stand.txt create mode 100644 evidence/lab6/storage-down-series.json create mode 100644 evidence/lab6/storage-down.txt create mode 100644 evidence/lab6/telemetry.txt create mode 100644 evidence/lab6/tempo-search.json create mode 100644 evidence/lab6/trace-pipeline.json create mode 100644 evidence/lab6/trace-retry.json create mode 100644 evidence/lab6/trace-retry.txt create mode 100644 evidence/lab6/track2/full-run.txt create mode 100644 evidence/lab6/track2/full/alert-audit.json create mode 100644 evidence/lab6/track2/full/alert-audit.md create mode 100644 evidence/lab6/track2/full/alerts.csv create mode 100644 evidence/lab6/track2/full/alerts.json create mode 100644 evidence/lab6/track2/full/baseline-load.json create mode 100644 evidence/lab6/track2/full/baseline.json create mode 100644 evidence/lab6/track2/full/burst-load.json create mode 100644 evidence/lab6/track2/full/burst.json create mode 100644 evidence/lab6/track2/full/false-positive-load.json create mode 100644 evidence/lab6/track2/full/final.json create mode 100644 evidence/lab6/track2/full/phases.json create mode 100644 evidence/lab6/track2/full/preflight-load.json create mode 100644 evidence/lab6/track2/full/resolution-load.json create mode 100644 evidence/lab6/track2/full/snapshots/baseline-2026-11-06T02-57-50Z.json create mode 100644 evidence/lab6/track2/full/snapshots/baseline-2026-11-06T10-02-51Z.json create mode 100644 evidence/lab6/track2/full/snapshots/burst-active-2026-11-06T02-58-30Z.json create mode 100644 evidence/lab6/track2/full/snapshots/burst-active-2026-11-06T10-03-31Z.json create mode 100644 evidence/lab6/track2/full/snapshots/burst-after-2026-11-06T04-26-41Z.json create mode 100644 evidence/lab6/track2/full/snapshots/burst-after-2026-11-06T11-29-41Z.json create mode 100644 evidence/lab6/track2/full/snapshots/final-2026-11-06T06-22-18Z.json create mode 100644 evidence/lab6/track2/full/snapshots/final-2026-11-06T13-30-24Z.json create mode 100644 evidence/lab6/track2/full/snapshots/final-summary-2026-11-06T06-22-19Z.json create mode 100644 evidence/lab6/track2/full/snapshots/final-summary-2026-11-06T13-30-25Z.json create mode 100644 evidence/lab6/track2/full/snapshots/resolution-2026-11-06T05-46-42Z.json create mode 100644 evidence/lab6/track2/full/snapshots/resolution-2026-11-06T12-52-06Z.json create mode 100644 evidence/lab6/track2/full/snapshots/sustained-active-2026-11-06T04-27-21Z.json create mode 100644 evidence/lab6/track2/full/snapshots/sustained-active-2026-11-06T11-30-21Z.json create mode 100644 evidence/lab6/track2/full/snapshots/sustained-after-2026-11-06T04-46-46Z.json create mode 100644 evidence/lab6/track2/full/snapshots/sustained-after-2026-11-06T11-49-53Z.json create mode 100644 evidence/lab6/track2/full/snapshots/ttr-after-2026-11-06T06-02-23Z.json create mode 100644 evidence/lab6/track2/full/snapshots/ttr-after-2026-11-06T13-07-47Z.json create mode 100644 evidence/lab6/track2/full/snapshots/warmup-2026-11-06T02-37-54Z.json create mode 100644 evidence/lab6/track2/full/snapshots/warmup-2026-11-06T09-42-56Z.json create mode 100644 evidence/lab6/track2/full/summary.md create mode 100644 evidence/lab6/track2/full/sustained-load.json create mode 100644 evidence/lab6/track2/full/sustained.json create mode 100644 evidence/lab6/track2/full/ttr-load.json create mode 100644 evidence/lab6/track2/full/warmup-load.json create mode 100644 evidence/lab6/track2/ttd-ttr.md create mode 100644 evidence/lab6/unit-test.txt create mode 100644 evidence/lab6/worker-stop.txt create mode 100644 evidence/lab6/worker-stopped-load.json create mode 100644 evidence/lb-readiness.txt create mode 100644 evidence/load-32clients.json create mode 100644 evidence/load-32clients.txt create mode 100644 evidence/native-load.json create mode 100644 evidence/native-load.txt create mode 100644 evidence/path-overhead/README.md create mode 100644 evidence/path-overhead/inside.txt create mode 100644 evidence/path-overhead/load-inside.json create mode 100644 evidence/path-overhead/load-outside.json create mode 100644 evidence/path-overhead/outside.txt create mode 100644 evidence/path-overhead/summary.txt create mode 100644 evidence/persistence.txt create mode 100644 evidence/quality.txt create mode 100644 evidence/quota-semantics.txt create mode 100644 evidence/rolling-update/after/load.json create mode 100644 evidence/rolling-update/after/load.txt create mode 100644 evidence/rolling-update/after/rolling-update.txt create mode 100644 evidence/rolling-update/emulated/load.json create mode 100644 evidence/rolling-update/emulated/load.txt create mode 100644 evidence/rolling-update/emulated/rolling-update.txt create mode 100644 evidence/smoke.txt create mode 100644 evidence/stand.txt create mode 100644 evidence/track1/load-ctl1base.json create mode 100644 evidence/track1/load-ctl2pg.json create mode 100644 evidence/track1/load-ctl3base.json create mode 100644 evidence/track1/load-ctl4lb.json create mode 100644 evidence/track1/load-d2.json create mode 100644 evidence/track1/load-db1cpu.json create mode 100644 evidence/track1/load-g05.json create mode 100644 evidence/track1/load-g10.json create mode 100644 evidence/track1/load-g15.json create mode 100644 evidence/track1/load-lb1cpu.json create mode 100644 evidence/track1/load-pool10.json create mode 100644 evidence/track1/load-pool5.json create mode 100644 evidence/track1/load-r1.json create mode 100644 evidence/track1/load-r2.json create mode 100644 evidence/track1/load-r4.json create mode 100644 evidence/track1/profile-ctl1base.json create mode 100644 evidence/track1/profile-ctl2pg.json create mode 100644 evidence/track1/profile-ctl3base.json create mode 100644 evidence/track1/profile-ctl4lb.json create mode 100644 evidence/track1/profile-d2.json create mode 100644 evidence/track1/profile-db1cpu.json create mode 100644 evidence/track1/profile-g05.json create mode 100644 evidence/track1/profile-g10.json create mode 100644 evidence/track1/profile-g15.json create mode 100644 evidence/track1/profile-lb1cpu.json create mode 100644 evidence/track1/profile-pool10.json create mode 100644 evidence/track1/profile-pool5.json create mode 100644 evidence/track1/profile-r1.json create mode 100644 evidence/track1/profile-r2.json create mode 100644 evidence/track1/profile-r4.json create mode 100644 evidence/track1/scaling-fixed-budget.png create mode 100644 evidence/track1/scaling-growth.png create mode 100644 evidence/track1/stats-ctl1base.csv create mode 100644 evidence/track1/stats-ctl2pg.csv create mode 100644 evidence/track1/stats-ctl3base.csv create mode 100644 evidence/track1/stats-ctl4lb.csv create mode 100644 evidence/track1/stats-d2.csv create mode 100644 evidence/track1/stats-db1cpu.csv create mode 100644 evidence/track1/stats-g05.csv create mode 100644 evidence/track1/stats-g10.csv create mode 100644 evidence/track1/stats-g15.csv create mode 100644 evidence/track1/stats-lb1cpu.csv create mode 100644 evidence/track1/stats-pool10.csv create mode 100644 evidence/track1/stats-pool5.csv create mode 100644 evidence/track1/stats-r1.csv create mode 100644 evidence/track1/stats-r2.csv create mode 100644 evidence/track1/stats-r4.csv create mode 100644 evidence/track1/summary.md create mode 100644 evidence/track1/summary.txt create mode 100644 go.mod create mode 100644 go.sum create mode 100644 infra/grafana/dashboards/api-overview.json create mode 100644 infra/grafana/dashboards/infra-saturation.json create mode 100644 infra/grafana/dashboards/jobs-pipeline.json create mode 100644 infra/grafana/provisioning/dashboards/dashboards.yaml create mode 100644 infra/grafana/provisioning/datasources/datasources.yaml create mode 100644 infra/lb/haproxy.cfg create mode 100644 infra/loki/loki.yaml create mode 100644 infra/otel/collector.yaml create mode 100644 infra/prometheus/prometheus.yml create mode 100644 infra/prometheus/rules/alerts.yml create mode 100644 infra/prometheus/rules/slo.yml create mode 100644 infra/prometheus/tests/ttr_test.yml create mode 100644 infra/rabbitmq/rabbitmq.conf create mode 100644 infra/runbooks/api-errors.md create mode 100644 infra/runbooks/db-availability.md create mode 100644 infra/runbooks/queue-lag.md create mode 100644 infra/runbooks/slo-burn.md create mode 100644 infra/runbooks/telemetry-backend-down.md create mode 100644 infra/s3/README.md create mode 100644 infra/s3/s3.json create mode 100644 infra/tempo/tempo.yaml create mode 100644 internal/broker/rabbit.go create mode 100644 internal/config/config.go create mode 100644 internal/config/config_test.go create mode 100644 internal/domain/attachment.go create mode 100644 internal/domain/chat.go create mode 100644 internal/domain/cursor.go create mode 100644 internal/domain/errors.go create mode 100644 internal/domain/job.go create mode 100644 internal/domain/keys.go create mode 100644 internal/domain/message.go create mode 100644 internal/domain/page.go create mode 100644 internal/domain/session.go create mode 100644 internal/domain/text.go create mode 100644 internal/domain/user.go create mode 100644 internal/domain/validation_test.go create mode 100644 internal/failpoint/failpoint.go create mode 100644 internal/health/checker.go create mode 100644 internal/health/checker_test.go create mode 100644 internal/imagecheck/imagecheck.go create mode 100644 internal/imagecheck/imagecheck_test.go create mode 100644 internal/imageproc/exif.go create mode 100644 internal/imageproc/imageproc.go create mode 100644 internal/imageproc/imageproc_test.go create mode 100644 internal/logger/errors.go create mode 100644 internal/logger/logger.go create mode 100644 internal/logger/logger_test.go create mode 100644 internal/outbox/relay.go create mode 100644 internal/platform/cache/cache.go create mode 100644 internal/platform/cache/cache_test.go create mode 100644 internal/platform/cache/distributed.go create mode 100644 internal/platform/cache/distributed_internal_test.go create mode 100644 internal/platform/cache/distributed_test.go create mode 100644 internal/platform/cache/mocks/Cache.go create mode 100644 internal/platform/cache/mocks/LockStore.go create mode 100644 internal/platform/cache/redis.go create mode 100644 internal/platform/cache/redis_client_test.go create mode 100644 internal/platform/instanceid/instanceid.go create mode 100644 internal/platform/objectstore/objectstore.go create mode 100644 internal/platform/objectstore/s3.go create mode 100644 internal/platform/objectstore/s3_test.go create mode 100644 internal/platform/password/password.go create mode 100644 internal/platform/password/password_test.go create mode 100644 internal/platform/token/token.go create mode 100644 internal/platform/token/token_test.go create mode 100644 internal/service/attachment/mocks/LockStore.go create mode 100644 internal/service/attachment/mocks/Repository.go create mode 100644 internal/service/attachment/mocks/SweepRepository.go create mode 100644 internal/service/attachment/service.go create mode 100644 internal/service/attachment/service_test.go create mode 100644 internal/service/attachment/sweeper.go create mode 100644 internal/service/attachment/sweeper_test.go create mode 100644 internal/service/chat/mocks/Repository.go create mode 100644 internal/service/chat/service.go create mode 100644 internal/service/chat/service_test.go create mode 100644 internal/service/message/mocks/AttachmentChecker.go create mode 100644 internal/service/message/mocks/Repository.go create mode 100644 internal/service/message/service.go create mode 100644 internal/service/message/service_test.go create mode 100644 internal/service/session/mocks/Repository.go create mode 100644 internal/service/session/mocks/Tokens.go create mode 100644 internal/service/session/service.go create mode 100644 internal/service/session/service_test.go create mode 100644 internal/service/user/mocks/Repository.go create mode 100644 internal/service/user/service.go create mode 100644 internal/service/user/service_test.go create mode 100644 internal/storage/postgres/cache_latency_experiment_test.go create mode 100644 internal/storage/postgres/cache_performance_experiment_test.go create mode 100644 internal/storage/postgres/chat_repository.go create mode 100644 internal/storage/postgres/chat_repository_test.go create mode 100644 internal/storage/postgres/config.go create mode 100644 internal/storage/postgres/config_test.go create mode 100644 internal/storage/postgres/errors.go create mode 100644 internal/storage/postgres/errors_test.go create mode 100644 internal/storage/postgres/idempotency_test.go create mode 100644 internal/storage/postgres/internal/sqlcgen/attachments.sql.go create mode 100644 internal/storage/postgres/internal/sqlcgen/chats.sql.go create mode 100644 internal/storage/postgres/internal/sqlcgen/db.go create mode 100644 internal/storage/postgres/internal/sqlcgen/idempotency.sql.go create mode 100644 internal/storage/postgres/internal/sqlcgen/messages.sql.go create mode 100644 internal/storage/postgres/internal/sqlcgen/models.go create mode 100644 internal/storage/postgres/internal/sqlcgen/sessions.sql.go create mode 100644 internal/storage/postgres/internal/sqlcgen/users.sql.go create mode 100644 internal/storage/postgres/main_test.go create mode 100644 internal/storage/postgres/mapping.go create mode 100644 internal/storage/postgres/message_repository.go create mode 100644 internal/storage/postgres/message_repository_test.go create mode 100644 internal/storage/postgres/migrations/00001_init.sql create mode 100644 internal/storage/postgres/migrations/00003_message_idempotency.sql create mode 100644 internal/storage/postgres/migrations/00004_attachments.sql create mode 100644 internal/storage/postgres/migrations/00005_async_pipeline.sql create mode 100644 internal/storage/postgres/migrations/00006_job_trace_context.sql create mode 100644 internal/storage/postgres/migrations/00007_ttr_missed.sql create mode 100644 internal/storage/postgres/migrations/00008_ttr_missed_indexes.sql create mode 100644 internal/storage/postgres/migrations/migrations.go create mode 100644 internal/storage/postgres/pagination.go create mode 100644 internal/storage/postgres/pipeline_repository.go create mode 100644 internal/storage/postgres/pipeline_repository_test.go create mode 100644 internal/storage/postgres/queries/attachments.sql create mode 100644 internal/storage/postgres/queries/chats.sql create mode 100644 internal/storage/postgres/queries/idempotency.sql create mode 100644 internal/storage/postgres/queries/messages.sql create mode 100644 internal/storage/postgres/queries/sessions.sql create mode 100644 internal/storage/postgres/queries/users.sql create mode 100644 internal/storage/postgres/session_repository.go create mode 100644 internal/storage/postgres/session_repository_test.go create mode 100644 internal/storage/postgres/store.go create mode 100644 internal/storage/postgres/transaction.go create mode 100644 internal/storage/postgres/user_repository.go create mode 100644 internal/storage/postgres/user_repository_test.go create mode 100644 internal/storage/redis/chat_repository.go create mode 100644 internal/storage/redis/chat_repository_test.go create mode 100644 internal/storage/redis/main_test.go create mode 100644 internal/storage/redis/mocks/ChatSource.go create mode 100644 internal/telemetry/db.go create mode 100644 internal/telemetry/job.go create mode 100644 internal/telemetry/log.go create mode 100644 internal/telemetry/log_test.go create mode 100644 internal/telemetry/metrics.go create mode 100644 internal/telemetry/objectstore.go create mode 100644 internal/telemetry/process.go create mode 100644 internal/telemetry/setup.go create mode 100644 internal/transport/rest/attachments.go create mode 100644 internal/transport/rest/bodylimit.go create mode 100644 internal/transport/rest/bodylimit_test.go create mode 100644 internal/transport/rest/errors.go create mode 100644 internal/transport/rest/errors_test.go create mode 100644 internal/transport/rest/extensions.go create mode 100644 internal/transport/rest/extensions_test.go create mode 100644 internal/transport/rest/handler.go create mode 100644 internal/transport/rest/handler_test.go create mode 100644 internal/transport/rest/instance.go create mode 100644 internal/transport/rest/instance_test.go create mode 100644 internal/transport/rest/internal/oas/oas_cfg_gen.go create mode 100644 internal/transport/rest/internal/oas/oas_defaults_gen.go create mode 100644 internal/transport/rest/internal/oas/oas_handlers_gen.go create mode 100644 internal/transport/rest/internal/oas/oas_interfaces_gen.go create mode 100644 internal/transport/rest/internal/oas/oas_json_gen.go create mode 100644 internal/transport/rest/internal/oas/oas_middleware_gen.go create mode 100644 internal/transport/rest/internal/oas/oas_operations_gen.go create mode 100644 internal/transport/rest/internal/oas/oas_parameters_gen.go create mode 100644 internal/transport/rest/internal/oas/oas_request_decoders_gen.go create mode 100644 internal/transport/rest/internal/oas/oas_response_encoders_gen.go create mode 100644 internal/transport/rest/internal/oas/oas_router_gen.go create mode 100644 internal/transport/rest/internal/oas/oas_schemas_gen.go create mode 100644 internal/transport/rest/internal/oas/oas_security_gen.go create mode 100644 internal/transport/rest/internal/oas/oas_server_gen.go create mode 100644 internal/transport/rest/internal/oas/oas_unimplemented_gen.go create mode 100644 internal/transport/rest/internal/oas/oas_validators_gen.go create mode 100644 internal/transport/rest/logging.go create mode 100644 internal/transport/rest/logging_test.go create mode 100644 internal/transport/rest/mocks/AttachmentService.go create mode 100644 internal/transport/rest/mocks/ChatService.go create mode 100644 internal/transport/rest/mocks/HealthChecker.go create mode 100644 internal/transport/rest/mocks/MessageService.go create mode 100644 internal/transport/rest/mocks/SecSessionService.go create mode 100644 internal/transport/rest/mocks/SessionActions.go create mode 100644 internal/transport/rest/mocks/SessionResolver.go create mode 100644 internal/transport/rest/mocks/SessionService.go create mode 100644 internal/transport/rest/mocks/UserLookup.go create mode 100644 internal/transport/rest/mocks/UserService.go create mode 100644 internal/transport/rest/requestid.go create mode 100644 internal/transport/rest/router.go create mode 100644 internal/transport/rest/router_test.go create mode 100644 internal/transport/rest/security.go create mode 100644 internal/transport/rest/telemetry.go create mode 100644 internal/worker/worker.go create mode 100644 internal/worker/worker_test.go create mode 100644 scripts/api_cache_performance.sh create mode 100644 scripts/cache_evidence.sh create mode 100644 scripts/cache_latency_experiment.sh create mode 100644 scripts/cache_performance_experiment.sh create mode 100755 scripts/check_evidence.py create mode 100755 scripts/check_s3_creds.py create mode 100755 scripts/init-secrets.sh create mode 100755 scripts/lab4_memory_experiment.py create mode 100755 scripts/lab4_track1.py create mode 100755 scripts/lab5_track2.py create mode 100644 scripts/lab6_alert_audit.py create mode 100755 scripts/lab6_alerts.py create mode 100644 scripts/lab6_collector_down.py create mode 100755 scripts/lab6_load.py create mode 100644 scripts/lab6_storage_down_series.py create mode 100755 scripts/lab6_track2.py create mode 100755 scripts/lab6_track2_full.py create mode 100644 scripts/lab6_ttr_worker_down.py create mode 100755 scripts/lab6_verify.py create mode 100755 scripts/lb_readiness_check.sh create mode 100644 scripts/memory_experiment.py create mode 100755 scripts/path_overhead_check.sh create mode 100644 scripts/redis_outage_check.py create mode 100755 scripts/restart.sh create mode 100755 scripts/rolling_update.sh create mode 100755 scripts/start-broker.sh create mode 100755 scripts/start-worker.sh create mode 100755 scripts/stop-broker.sh create mode 100755 scripts/stop-one.sh create mode 100755 scripts/stop-worker.sh create mode 100755 scripts/track1_controls.sh create mode 100755 scripts/track1_report.py create mode 100755 scripts/track1_scaling.sh create mode 100755 scripts/track1_series.sh create mode 100644 sqlc.yaml create mode 100755 student-tests/attachment_failover.py create mode 100755 student-tests/attachments_negative.py create mode 100644 student-tests/cache_api_performance.py create mode 100755 student-tests/idempotency_parallel.py create mode 100755 student-tests/lab5_async.py create mode 100755 student-tests/lab5_faults.py create mode 100755 student-tests/lab5_variants.py create mode 100755 student-tests/presign_flow.py create mode 100755 student-tests/replica_failover.py create mode 100755 student-tests/rolling_update_load.py create mode 100644 student-tests/tests_helpers.py create mode 100644 tools/specgen/main.go diff --git a/.dockerignore b/.dockerignore index bc16e55..a247294 100644 --- a/.dockerignore +++ b/.dockerignore @@ -18,3 +18,10 @@ __pycache__ node_modules evidence .DS_Store +messenger +s3init +bin +coverage.out +.cache +coverage.out.tmp +*.log diff --git a/.env.example b/.env.example index 2b32655..8dd166d 100644 --- a/.env.example +++ b/.env.example @@ -1,30 +1,183 @@ # Copy to .env for your LOCAL synthetic test environment; never commit .env. -# These are logical interface suggestions; map actual framework names in REPORT.md. -APP_HOST=0.0.0.0 -APP_PORT=8080 -APP_ENV=lab +# Values below are the variables this implementation actually reads +# (viper: section.name -> SECTION_NAME, see internal/config/config.go). +# +# Mapping to the logical names suggested by the skeleton: +# APP_HOST / APP_PORT -> SERVER_HOST / SERVER_PORT +# SESSION_STORE=postgres -> server-side sessions live in PostgreSQL (SESSION_TTL_SECONDS) +# DATABASE_URL_FILE -> unused: POSTGRES_* below pass no secret files +# CACHE_URL_FILE -> unused: REDIS_* below pass no secret files +# API_REPLICAS -> number of API replicas of the stand (compose.yaml) +# +# APP_ENV selects config//config.yaml; the implementation supports only `dev`. +APP_ENV=dev + +SERVER_HOST=0.0.0.0 +SERVER_PORT=8080 +SERVER_READ_HEADER_TIMEOUT=10s +SERVER_READ_TIMEOUT=60s +SERVER_SHUTDOWN_TIMEOUT=10s +# Предел размера тела запроса (байт): защищает реплику от чтения огромного тела +# до валидации. Для вложений LAB4 (до 10 MiB) значение нужно поднять. +SERVER_MAX_BODY_BYTES=262144 + +LOG_LEVEL=info +LOG_FORMAT=json + +# Synthetic credentials for the local stand only; override in .env for anything else. +POSTGRES_HOST=localhost +POSTGRES_PORT=5432 +POSTGRES_DATABASE=messenger +POSTGRES_USER=messenger +POSTGRES_PASSWORD=messenger +POSTGRES_SSL_MODE=disable +POSTGRES_MAX_CONNS=10 +POSTGRES_MIN_CONNS=1 +POSTGRES_MAX_CONN_LIFETIME=1h +POSTGRES_MAX_CONN_IDLE_TIME=30m +POSTGRES_CONNECT_TIMEOUT=5s +POSTGRES_QUERY_TIMEOUT=5s + +REDIS_ENABLED=true +REDIS_HOST=localhost +REDIS_PORT=6379 +REDIS_PASSWORD= +REDIS_DB=0 +# -1 disables go-redis retries; 0 keeps the library default (3 retries). +REDIS_MAX_RETRIES=-1 +REDIS_DIAL_TIMEOUT=300ms +REDIS_READ_TIMEOUT=200ms +REDIS_WRITE_TIMEOUT=200ms +REDIS_POOL_SIZE=10 + +CACHE_ENABLED=true +CACHE_CHAT_LIST_TTL=5m +CACHE_LOCK_TTL=10s +CACHE_LOCK_WAIT_TIMEOUT=2s + SESSION_TTL_SECONDS=3600 -# Choose credentials locally. File paths contain no secret values. -DATABASE_URL_FILE=/run/secrets/database_url -# Optional on 3, required use on 4 in lab2; Redis OR Valkey: -SESSION_STORE=postgres -CACHE_URL_FILE=/run/secrets/cache_url -API_REPLICAS=2 + +# Retention of a message Idempotency-Key in the shared store; contract 1.3.0 +# requires at least 24 h. IDEMPOTENCY_TTL_SECONDS=86400 -S3_ENDPOINT=http://s3:9000 + +# Lab3 stand (compose.yaml): number of API replicas behind the LB and per-replica +# CPU/RAM limits. Track 1 varies them to compare 1/2/4 replicas at a fixed total +# budget, e.g. API_REPLICAS=4 API_CPU_LIMIT=0.25 API_MEM_LIMIT=192M. +API_REPLICAS=2 +API_CPU_LIMIT=0.50 +API_MEM_LIMIT=256M + +# Connections of ONE API replica to PostgreSQL; the total is replicas × value. +# Track 1 checks whether the shared connection budget becomes the saturation +# point: at 4 replicas the default 10 means 40 connections against one database. +POSTGRES_MAX_CONNS=10 + +# CPU quota of the shared database. Track 1 shows it is the stand's saturation +# point: the API uses a fraction of its budget while PostgreSQL sits at its own. +POSTGRES_CPU_LIMIT=0.50 + +# Memory quota of the shared database. The track 1 series r/g/pool were measured +# with 512M, the db1cpu control — with 384M (see evidence/track1/profile-*.json). +POSTGRES_MEM_LIMIT=192M + +# Loopback port of the HAProxy operator page (UP/DOWN of every replica). +LB_STATS_PORT=8404 + +# --- Lab4: private S3 object store (SeaweedFS) ------------------------------- +# Synthetic local application credentials. infra/s3/s3.json must contain the +# same app values; scripts/check_s3_creds.py enforces that before the stand starts. +# Admin credentials live only in infra/s3/s3.json and s3-init defaults; never put +# them in .env, because the API service loads this file. +S3_ENDPOINT=http://localhost:8333 +S3_PUBLIC_ENDPOINT=http://127.0.0.1:8333 +S3_PORT=8333 S3_REGION=us-east-1 S3_BUCKET=messenger-attachments -S3_ACCESS_KEY_ID_FILE=/run/secrets/s3_access_key_id -S3_SECRET_ACCESS_KEY_FILE=/run/secrets/s3_secret_access_key +S3_ACCESS_KEY_ID=lab4app +S3_SECRET_ACCESS_KEY=lab4app-secret + +# Attachment limits from contract 1.5.0. MAX_UPLOAD_BYTES=10485760 MAX_IMAGE_PIXELS=40000000 -BROKER_URL_FILE=/run/secrets/broker_url -WORKER_CONCURRENCY=2 -JOB_MAX_ATTEMPTS=5 -JOB_TIMEOUT_SECONDS=60 -STAGING_RETENTION_SECONDS=86400 -OTEL_SERVICE_NAME=messenger-api -# Worker must set a distinct service.name. +# Presigned upload lifetime and the sweeper's safety window. +S3_PRESIGN_TTL=5m +S3_SWEEP_INTERVAL=1m +S3_SWEEP_GRACE=10m + +# --- Lab5: durable queues and async image processing ------------------------- +# Synthetic broker credentials for the local Compose stand. The relay/worker +# connect inside the compose network; the management UI is published only on +# loopback by compose.yaml. +BROKER_USER=messenger +BROKER_PASSWORD=messenger +BROKER_VHOST=messenger +BROKER_URL=amqp://messenger:messenger@broker:5672/messenger +BROKER_EXCHANGE=attachments.jobs +BROKER_QUEUE=attachment.process.v1 +BROKER_DLX=attachments.dlx +BROKER_DLQ=attachment.process.dead +BROKER_MANAGEMENT_PORT=15672 +BROKER_CPU_LIMIT=0.50 +BROKER_MEM_LIMIT=384M + +# Worker process bounds. Concurrency=1 is the safe default for a 40 MP image on +# the course VM; raise it together with WORKER_MEM_LIMIT. +WORKER_CONCURRENCY=1 +WORKER_PREFETCH=1 +WORKER_CPU_LIMIT=1.00 +WORKER_MEM_LIMIT=1G +WORKER_SHUTDOWN_TIMEOUT=30s +WORKER_HEALTH_PORT=8081 + +# Shared job contract. The API chooses the pipeline version for new uploads. +PROCESSING_PIPELINE_VERSION=1 +PROCESSING_MAX_ATTEMPTS=5 +PROCESSING_JOB_TIMEOUT=120s +PROCESSING_LEASE_TTL=180s +PROCESSING_HEARTBEAT=30s +PROCESSING_RETRY_BASE=2s +PROCESSING_RETRY_CAP=60s + +# Outbox relay and lease reaper. +OUTBOX_POLL_INTERVAL=1s +OUTBOX_CLAIM_TTL=30s +OUTBOX_BATCH=20 +OUTBOX_REAPER_INTERVAL=15s +OUTBOX_RECONCILE_AFTER=5m +OUTBOX_RETENTION=168h +RELAY_CPU_LIMIT=0.25 +RELAY_MEM_LIMIT=128M +RELAY_HEALTH_PORT=8082 + +# Staging cleanup and admission control. +STAGING_ORPHAN_GRACE=1h +STAGING_FAILED_RETENTION=168h +ADMISSION_MAX_PENDING_PER_USER=20 +ADMISSION_MAX_PENDING=200 +ADMISSION_MAX_STAGED_BYTES=2147483648 +ADMISSION_MAX_CONCURRENT_UPLOADS=8 + +# --- Lab6: observability ----------------------------------------------------- +# SDK/Collector settings; OTLP traffic must never carry message bodies, +# attachment bytes, credentials or user/chat/message ids as metric labels. +# Service names are set per service in compose.yaml (API/worker/relay must differ). OTEL_EXPORTER_OTLP_ENDPOINT=http://otel-collector:4318 OTEL_EXPORTER_OTLP_PROTOCOL=http/protobuf OTEL_RESOURCE_ATTRIBUTES=deployment.environment.name=lab +OTEL_METRIC_EXPORT_INTERVAL=15000 +TELEMETRY_ENABLED=1 +PROMETHEUS_PORT=9090 +LOKI_PORT=3100 +TEMPO_PORT=3200 +GRAFANA_PORT=3000 +OTEL_COLLECTOR_CPU_LIMIT=0.25 +OTEL_COLLECTOR_MEM_LIMIT=192M +PROMETHEUS_CPU_LIMIT=0.50 +PROMETHEUS_MEM_LIMIT=320M +LOKI_CPU_LIMIT=0.50 +LOKI_MEM_LIMIT=320M +TEMPO_CPU_LIMIT=0.25 +TEMPO_MEM_LIMIT=768M +GRAFANA_CPU_LIMIT=0.25 +GRAFANA_MEM_LIMIT=512M diff --git a/.github/workflows/app.yml b/.github/workflows/app.yml new file mode 100644 index 0000000..67a411d --- /dev/null +++ b/.github/workflows/app.yml @@ -0,0 +1,125 @@ +name: Application + +on: [push, pull_request] + +permissions: + contents: read + +env: + GO_VERSION: "1.27.0" + GOLANGCI_LINT_VERSION: v2.13.2 + +jobs: + lint: + name: Lint + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-go@v5 + with: + go-version: ${{ env.GO_VERSION }} + cache: true + - run: make lint + + unit-test: + name: Unit tests + needs: lint + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-go@v5 + with: + go-version: ${{ env.GO_VERSION }} + cache: true + - run: make unit-test + + build: + name: Docker build + needs: unit-test + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: docker/setup-buildx-action@v3 + - uses: docker/build-push-action@v6 + with: + context: . + push: false + tags: mtusi-messenger:ci + + stand: + name: Lab6 stand scenario (lab5 base) + needs: build + runs-on: ubuntu-latest + timeout-minutes: 20 + steps: + - uses: actions/checkout@v4 + - run: cp .env.example .env && sed -i 's/^TELEMETRY_ENABLED=.*/TELEMETRY_ENABLED=0/' .env + - run: ./scripts/init-secrets.sh + - run: docker compose --env-file .env config --quiet + - run: docker compose --env-file .env up -d --build + - name: Wait for readiness through the load balancer + run: | + for attempt in $(seq 1 60); do + if curl -fsS -o /dev/null http://localhost:8080/health/ready; then exit 0; fi + sleep 2 + done + docker compose --env-file .env ps + exit 1 + - name: Public smoke through the LB + run: make test + - name: Attachment negative scenarios + run: make test-attachments + - name: Presigned direct upload (async complete) + run: make test-presign + - name: Worker process is separate and healthy + run: docker compose --env-file .env ps worker relay broker + - name: Async worker and broker durability + run: make test-queue + - name: Track 2 duplicate and stale-version harness + run: python3 scripts/lab5_track2.py --reps 1 + - name: Parallel idempotency through the LB + run: python3 student-tests/idempotency_parallel.py --base-url http://localhost:8080 + - name: LB removes a not-ready replica + run: make test-lb-readiness + - name: Upload, stop the serving replica, download through another + run: python3 student-tests/attachment_failover.py --base-url http://localhost:8080 + - name: Stop one API replica and keep writing + run: make test-failover ACTION_SCRIPT=scripts/stop-one.sh + - name: Logs on failure + if: failure() + run: docker compose --env-file .env logs --tail 100 api worker relay + - if: always() + run: docker compose --env-file .env down -v + + observability: + name: Lab6 observability stand + needs: build + runs-on: ubuntu-latest + timeout-minutes: 25 + steps: + - uses: actions/checkout@v4 + - run: cp .env.example .env + - run: ./scripts/init-secrets.sh + - run: docker compose --env-file .env --profile telemetry config --quiet + - run: docker compose --env-file .env --profile telemetry up -d --build + - name: Validate Prometheus configuration and rules + run: | + docker compose --env-file .env --profile telemetry exec -T prometheus promtool check config /etc/prometheus/prometheus.yml + docker compose --env-file .env --profile telemetry exec -T prometheus sh -c 'promtool check rules /etc/prometheus/rules/*.yml' + - name: Wait for readiness through the LB + run: | + for attempt in $(seq 1 60); do + if curl -fsS -o /dev/null http://localhost:8080/health/ready; then exit 0; fi + sleep 2 + done + docker compose --env-file .env ps + exit 1 + - name: Public smoke with telemetry enabled + run: make test + - name: Observability and privacy checks + run: make test-observability + - name: Logs on failure + if: failure() + run: docker compose --env-file .env --profile telemetry logs --tail 120 api worker relay otel-collector prometheus loki tempo grafana + - if: always() + run: docker compose --env-file .env --profile telemetry down -v diff --git a/.gitignore b/.gitignore index b5a7189..2c1bc70 100644 --- a/.gitignore +++ b/.gitignore @@ -22,8 +22,16 @@ dist/ build/ target/ bin/ +/messenger +/s3init +/worker +/relay +/jobctl obj/ coverage/ +coverage.out +coverage.out.tmp +.cache/ *.log .DS_Store .idea/ diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 0000000..a2014d8 --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,139 @@ +# yaml-language-server: $schema=https://golangci-lint.run/jsonschema/golangci.v2.13.jsonschema.json + +version: "2" + +run: + timeout: 5m + tests: true + build-tags: + - integration + +linters: + default: standard + enable: + - bodyclose + - contextcheck + - containedctx + - noctx + - rowserrcheck + - sqlclosecheck + - fatcontext + - errorlint + - errname + - nilerr + - nilnil + - asasalint + - durationcheck + - exhaustive + - forcetypeassert + - gocheckcompilerdirectives + - gocritic + - makezero + - musttag + - reassign + - recvcheck + - unparam + - wastedassign + - gosec + - canonicalheader + - copyloopvar + - exptostd + - intrange + - perfsprint + - unconvert + - usestdlibvars + - usetesting + - prealloc + - revive + - misspell + - nolintlint + - gomoddirectives + - sloglint + - depguard + - forbidigo + - testifylint + - thelper + - tparallel + + settings: + govet: + enable-all: true + disable: + - fieldalignment + - shadow + + gosec: + excludes: + - G404 + + exhaustive: + default-signifies-exhaustive: true + + nolintlint: + require-explanation: true + require-specific: true + + sloglint: + attr-only: true + no-global: default + context: scope + + testifylint: + enable-all: true + + depguard: + rules: + main: + deny: + - pkg: math/rand$ + desc: use math/rand/v2 + - pkg: github.com/pkg/errors + desc: use stdlib errors and fmt.Errorf with %w + - pkg: io/ioutil + desc: deprecated + domain: + files: + - "**/internal/domain/**" + deny: + - pkg: database/sql + desc: domain must not depend on infrastructure + - pkg: net/http + desc: domain must not depend on transport + + forbidigo: + forbid: + - pattern: ^fmt\.Print(f|ln)?$ + msg: use slog + - pattern: ^log\.(Print|Fatal|Panic).*$ + msg: use slog + + exclusions: + generated: lax + presets: + - comments + - std-error-handling + - common-false-positives + rules: + - path: _test\.go + linters: + - gosec + - prealloc + - forcetypeassert + - unparam + +formatters: + enable: + - gofumpt + - goimports + settings: + gofumpt: + module-path: mtusi-messenger + goimports: + local-prefixes: + - mtusi-messenger + exclusions: + generated: lax + +issues: + max-issues-per-linter: 0 + max-same-issues: 0 \ No newline at end of file diff --git a/.mockery.yml b/.mockery.yml new file mode 100644 index 0000000..629f91e --- /dev/null +++ b/.mockery.yml @@ -0,0 +1,38 @@ +#https://vektra.github.io/mockery/latest/configuration/ + +all: false +dir: "{{.InterfaceDir}}/mocks" +pkgname: mocks +filename: "{{.InterfaceName}}.go" +structname: "Mock{{.InterfaceName}}" +template: testify +formatter: goimports +force-file-write: true +include-auto-generated: false +log-level: info + +packages: + mtusi-messenger/internal/platform/cache: + config: + all: true + mtusi-messenger/internal/storage/redis: + config: + all: true + mtusi-messenger/internal/service/user: + config: + all: true + mtusi-messenger/internal/service/chat: + config: + all: true + mtusi-messenger/internal/service/message: + config: + all: true + mtusi-messenger/internal/service/attachment: + config: + all: true + mtusi-messenger/internal/service/session: + config: + all: true + mtusi-messenger/internal/transport/rest: + config: + all: true diff --git a/.ogen.yml b/.ogen.yml new file mode 100644 index 0000000..8995023 --- /dev/null +++ b/.ogen.yml @@ -0,0 +1,10 @@ +# yaml-language-server: $schema=https://raw.githubusercontent.com/ogen-go/ogen/v1.24.0/schemas/ogen.jsonschema.json + +# https://ogen.dev/docs/config/ +generator: + features: + disable: + - paths/client + - webhooks/client + - webhooks/server + - ogen/otel diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..e1f5ae4 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,77 @@ +# syntax=docker/dockerfile:1.7 + +ARG GO_VERSION=1.27.1 +ARG ALPINE_VERSION=3.22 + +FROM golang:${GO_VERSION}-alpine AS build +# Platform of the produced binaries. Left empty on purpose: the classic builder +# does not supply these args, and the previous hardcoded `amd64` default silently +# produced x86-64 binaries inside an arm64 image. Those ran under emulation and +# the Go runtime crashed under load (fatals like "found pointer to free object"). +# Empty means "build for the builder's own platform"; cross-compile explicitly: +# docker build --build-arg TARGETARCH=amd64 ... +ARG TARGETOS +ARG TARGETARCH +ARG VERSION=dev +ENV GOTOOLCHAIN=local +WORKDIR /opt + +COPY go.mod go.sum ./ +RUN go mod download + +# The Go compiler spikes well above 1 GiB per package on large dependencies +# (AWS SDK + pgx + Redis), so an unbounded or even -p=2 build OOMs Docker +# Desktop's default VM. Build one package at a time; override with +# --build-arg GOFLAGS=-p=$(nproc) on a bigger host. +ARG GOFLAGS="-p=1" +ENV GOFLAGS=$GOFLAGS +# Keep the compiler well below Docker Desktop's default VM limit. +ENV GOGC=50 +ENV GOMEMLIMIT=1GiB + +COPY . . +RUN CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} \ + go build -trimpath -buildvcs=false -tags timetzdata,nodynamic \ + -ldflags="-s -w -X main.version=${VERSION}" \ + -o /out/messenger ./cmd/messenger \ + && CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} \ + go build -trimpath -buildvcs=false -tags timetzdata,nodynamic \ + -ldflags="-s -w -X main.version=${VERSION}" \ + -o /out/migrate ./cmd/migrate \ + && CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} \ + go build -trimpath -buildvcs=false -tags timetzdata,nodynamic \ + -ldflags="-s -w -X main.version=${VERSION}" \ + -o /out/s3init ./cmd/s3init \ + && CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} \ + go build -trimpath -buildvcs=false -tags timetzdata,nodynamic \ + -ldflags="-s -w -X main.version=${VERSION}" \ + -o /out/worker ./cmd/worker \ + && CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} \ + go build -trimpath -buildvcs=false -tags timetzdata,nodynamic \ + -ldflags="-s -w -X main.version=${VERSION}" \ + -o /out/relay ./cmd/relay \ + && CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} \ + go build -trimpath -buildvcs=false -tags timetzdata,nodynamic \ + -ldflags="-s -w -X main.version=${VERSION}" \ + -o /out/jobctl ./cmd/jobctl + +FROM alpine:${ALPINE_VERSION} AS runtime +RUN apk add --no-cache ca-certificates wget \ + && addgroup -S -g 10001 app \ + && adduser -S -D -H -u 10001 -G app app + +COPY --from=build --chown=10001:10001 /out/messenger /usr/local/bin/messenger +COPY --from=build --chown=10001:10001 /out/migrate /usr/local/bin/migrate +COPY --from=build --chown=10001:10001 /out/s3init /usr/local/bin/s3init +COPY --from=build --chown=10001:10001 /out/worker /usr/local/bin/worker +COPY --from=build --chown=10001:10001 /out/relay /usr/local/bin/relay +COPY --from=build --chown=10001:10001 /out/jobctl /usr/local/bin/jobctl +COPY --chown=10001:10001 config/dev/config.yaml /etc/messenger/dev/config.yaml + +USER 10001:10001 +EXPOSE 8080 +STOPSIGNAL SIGTERM +HEALTHCHECK --interval=10s --timeout=3s --start-period=5s --retries=3 \ + CMD wget -q -O /dev/null "http://127.0.0.1:${SERVER_PORT:-8080}/health/live" || exit 1 + +ENTRYPOINT ["/usr/local/bin/messenger"] diff --git a/Makefile b/Makefile index 5d86d17..beb71d9 100644 --- a/Makefile +++ b/Makefile @@ -1,30 +1,197 @@ PYTHON ?= python3 +VERSION ?= $(shell git describe --always --dirty 2>/dev/null || echo dev) +export VERSION BASE_URL ?= http://localhost:8080 CA_FILE ?= ACTION_SCRIPT ?= +PIPELINE ?= 2 TLS_ARGS = $(if $(CA_FILE),--ca-file "$(CA_FILE)",) +PYTHON_LOCAL = env -u HTTP_PROXY -u HTTPS_PROXY -u ALL_PROXY -u http_proxy -u https_proxy -u all_proxy NO_PROXY=localhost,127.0.0.1,::1 no_proxy=localhost,127.0.0.1,::1 $(PYTHON) -.PHONY: help check validate test load test-persistence test-failover +.PHONY: help check validate test test-attachments test-presign load test-persistence test-failover smoke-local load-local test-idempotency test-lb-readiness test-observability test-slo up up-base init-secrets down ps logs help: @echo "check: offline structure; validate: full OpenAPI (requirements-dev.txt); test: running API; load: synthetic writes" + @echo "up: lab6 stand with telemetry profile; up-base: lab5 regression without telemetry" + @echo "down/ps/logs: same profile; test-observability/test-slo: lab6 checks" check: $(PYTHON) scripts/check_contract.py + $(PYTHON) scripts/check_s3_creds.py validate: $(PYTHON) scripts/validate_openapi.py test: - $(PYTHON) tests/smoke.py --base-url "$(BASE_URL)" $(TLS_ARGS) + $(PYTHON_LOCAL) tests/smoke.py --base-url "$(BASE_URL)" $(TLS_ARGS) + +test-attachments: + $(PYTHON_LOCAL) student-tests/attachments_negative.py --base-url "$(BASE_URL)" $(TLS_ARGS) + +test-presign: + $(PYTHON_LOCAL) student-tests/presign_flow.py --base-url "$(BASE_URL)" $(TLS_ARGS) + +test-queue: + $(PYTHON_LOCAL) student-tests/lab5_async.py --base-url "$(BASE_URL)" $(TLS_ARGS) + +test-faults: + $(PYTHON_LOCAL) student-tests/lab5_faults.py --base-url "$(BASE_URL)" $(TLS_ARGS) + +test-track2: + $(PYTHON_LOCAL) scripts/lab5_track2.py --base-url "$(BASE_URL)" $(TLS_ARGS) + +# Lab6 observability and SLO checks (stand must be running with the telemetry profile). +test-observability: + $(PYTHON_LOCAL) scripts/check_evidence.py + $(PYTHON_LOCAL) scripts/lab6_verify.py --base-url "$(BASE_URL)" $(TLS_ARGS) + +test-slo: + $(PYTHON_LOCAL) scripts/lab6_track2.py --base-url "$(BASE_URL)" $(TLS_ARGS) load: - $(PYTHON) tests/load.py --base-url "$(BASE_URL)" $(TLS_ARGS) + $(PYTHON_LOCAL) tests/load.py --base-url "$(BASE_URL)" $(TLS_ARGS) test-persistence: @test -n "$(ACTION_SCRIPT)" || (echo "Set ACTION_SCRIPT to your implemented executable restart hook"; exit 2) - $(PYTHON) tests/resilience.py --mode persistence --action-script "$(ACTION_SCRIPT)" --base-url "$(BASE_URL)" $(TLS_ARGS) + $(PYTHON_LOCAL) tests/resilience.py --mode persistence --action-script "$(ACTION_SCRIPT)" --base-url "$(BASE_URL)" $(TLS_ARGS) test-failover: @test -n "$(ACTION_SCRIPT)" || (echo "Set ACTION_SCRIPT to your implemented executable stop-one hook"; exit 2) - $(PYTHON) tests/resilience.py --mode failover --action-script "$(ACTION_SCRIPT)" --base-url "$(BASE_URL)" $(TLS_ARGS) + $(PYTHON_LOCAL) tests/resilience.py --mode failover --action-script "$(ACTION_SCRIPT)" --base-url "$(BASE_URL)" $(TLS_ARGS) + +# Локальный запуск без прокси: в окружении автора HTTP(S)_PROXY ломает localhost. +smoke-local: + $(PYTHON_LOCAL) tests/smoke.py --base-url "$(BASE_URL)" $(TLS_ARGS) + +load-local: + $(PYTHON_LOCAL) tests/load.py --base-url "$(BASE_URL)" $(TLS_ARGS) + +# Собственная проверка уровня 4: параллельные повторы одного Idempotency-Key +# через LB обязаны создать ровно одно сообщение. +test-idempotency: + $(PYTHON_LOCAL) student-tests/idempotency_parallel.py --base-url "$(BASE_URL)" $(TLS_ARGS) + +# Собственная проверка уровня 4: LB обязан убрать из ротации реплику, которая +# осталась доступной, но потеряла БД (readiness 503). +test-lb-readiness: + scripts/lb_readiness_check.sh + +COMPOSE_BIN ?= docker compose +COMPOSE_FILE ?= compose.yaml +ENV_FILE ?= .env + +TELEMETRY_PROFILE ?= telemetry + +up: init-secrets + $(COMPOSE_BIN) --env-file $(ENV_FILE) -f $(COMPOSE_FILE) --profile $(TELEMETRY_PROFILE) up -d --build + +# Lab5 regression without the telemetry profile. +up-base: init-secrets + TELEMETRY_ENABLED=0 $(COMPOSE_BIN) --env-file $(ENV_FILE) -f $(COMPOSE_FILE) up -d --build + +init-secrets: + ./scripts/init-secrets.sh + +down: + $(COMPOSE_BIN) --env-file $(ENV_FILE) -f $(COMPOSE_FILE) --profile $(TELEMETRY_PROFILE) down + +ps: + $(COMPOSE_BIN) --env-file $(ENV_FILE) -f $(COMPOSE_FILE) --profile $(TELEMETRY_PROFILE) ps + +logs: + $(COMPOSE_BIN) --env-file $(ENV_FILE) -f $(COMPOSE_FILE) --profile $(TELEMETRY_PROFILE) logs -f --tail 100 + +# Operator views: the failed registry is PostgreSQL, the DLQ is a backstop. +jobs-failed: + $(COMPOSE_BIN) --env-file $(ENV_FILE) -f $(COMPOSE_FILE) run --rm --entrypoint /usr/local/bin/jobctl worker failed + +replay: + @test -n "$(JOB)" || (echo "Set JOB="; exit 2) + $(COMPOSE_BIN) --env-file $(ENV_FILE) -f $(COMPOSE_FILE) run --rm --entrypoint /usr/local/bin/jobctl worker replay -job "$(JOB)" + +reprocess: + @test -n "$(ATTACHMENT)" || (echo "Set ATTACHMENT="; exit 2) + $(COMPOSE_BIN) --env-file $(ENV_FILE) -f $(COMPOSE_FILE) run --rm --entrypoint /usr/local/bin/jobctl worker reprocess -attachment "$(ATTACHMENT)" -pipeline "$(PIPELINE)" + +.DEFAULT_GOAL := help +GO ?= go +APP_NAME ?= messenger +CMD_PKG := ./cmd/$(APP_NAME) +LOCAL_BIN := $(CURDIR)/bin +GOLANGCI_LINT_VERSION ?= v2.13.2 +GOLANGCI_LINT := $(LOCAL_BIN)/golangci-lint +OPENAPI_SPEC := contracts/openapi.json +OGEN_CONFIG := .ogen.yml +OAS_DIR := internal/transport/rest/internal/oas + +-include .env +export + +# .env feeds local tooling, but its application variables must not leak into the +# Go test process: the config tests assert defaults and the dev YAML, so an +# ambient REDIS_ENABLED/CACHE_ENABLED would fail them. +ENV_KEYS := $(shell sed -n 's/^\([A-Za-z_][A-Za-z0-9_]*\)=.*/\1/p' .env 2>/dev/null) +CLEAN_ENV = env $(addprefix -u ,$(ENV_KEYS)) + +.PHONY: unit-test +unit-test: + $(CLEAN_ENV) $(GO) test -race -shuffle=on -count=1 -timeout=5m ./... + +.PHONY: integration-test +integration-test: + $(GO) test -tags=integration -p 1 -count=1 -timeout=15m ./internal/storage/postgres ./internal/storage/redis + +.PHONY: test-db-up test-db-down +test-db-up: + @docker-compose -f docker-compose.local.yaml up -d --wait postgres redis + +test-db-down: + @docker-compose -f docker-compose.local.yaml down + +# не учитываем генеренные файлы, также cmd в подсчете покрытия +COVER_EXCLUDE ?= /(mocks|oas)/|/cmd/ + +.PHONY: cover +cover: + $(CLEAN_ENV) $(GO) test -race -shuffle=on -count=1 -timeout=5m \ + -covermode=atomic -coverprofile=coverage.out.tmp ./... + @grep -Ev '$(COVER_EXCLUDE)' coverage.out.tmp > coverage.out + @rm coverage.out.tmp + $(GO) tool cover -func=coverage.out | tail -n 1 + $(GO) tool cover -html=coverage.out + +.PHONY: generate +generate: generate-api generate-mocks sqlc + +.PHONY: generate-api +generate-api: + $(GO) run ./tools/specgen + $(GO) tool ogen --config $(OGEN_CONFIG) --target $(OAS_DIR) --package oas --clean .cache/openapi.codegen.json + +.PHONY: generate-mocks +generate-mocks: + $(GO) tool mockery + +.PHONY: sqlc +sqlc: + $(GO) tool sqlc generate + +.PHONY: dev-up dev-down dev-reload +dev-up: + @docker-compose -f docker-compose.local.yaml up -d --build + +dev-down: + @docker-compose -f docker-compose.local.yaml down + +dev-reload: + @docker-compose -f docker-compose.local.yaml up -d --build --force-recreate + +.PHONY: migrate +migrate: + $(GO) run ./cmd/migrate up + +$(GOLANGCI_LINT): + GOBIN=$(LOCAL_BIN) $(GO) install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@$(GOLANGCI_LINT_VERSION) + +lint: $(GOLANGCI_LINT) + $(GOLANGCI_LINT) run -v diff --git a/REPORT.md b/REPORT.md index b97ae42..9d0568c 100644 --- a/REPORT.md +++ b/REPORT.md @@ -1,37 +1,207 @@ # Отчёт — лабораторная 6 -- Автор, группа: TODO -- Целевая оценка; выбранный трек 5, если нужен: TODO -- Commit/PR: TODO после публикации -- Использованные источники, библиотеки и помощь ИИ: TODO +- Автор, группа: Кунецкий Владислав, БВТ2303 +- Целевая оценка; выбранный трек 5: **5, трек 2 (SLO и обнаружение инцидентов); полный live-прогон выполнен, есть ограничения** +- Commit/PR: один коммит `lab6` в `main`, запушен в origin +- Использованные источники, библиотеки и помощь ИИ: Go 1.27, OTel Go SDK v1.47.0 / + otelslog v0.21.0 / otelpgx v0.13.0, OTel Collector contrib 0.164.0, + Prometheus 3.15.1, Loki 3.6.4, Tempo 2.9.0, Grafana 13.2.5. ИИ-ассистент + использовался для реализации и текста; ниже перечислены реально выполненные + команды и артефакты, включая полный live-прогон трека 2. ## Запуск из чистого clone -TODO: версии runtime/образов, prerequisites, команды создания локальных secrets/.env, build, миграций, запуска, ожидания готовности, тестов и остановки. Указать необходимые действия оператора. Не вставлять секреты. Отдельно указать безопасную остановку и команду намеренного удаления учебных данных. +```sh +cp .env.example .env +./scripts/init-secrets.sh # secrets/grafana.env, gitignored +make up # docker compose --profile telemetry up -d --build +# дождаться http://localhost:8080/health/ready +make test # публичный smoke +make test-observability # сигналы, route labels, Grafana, sentinels +make test-slo # короткий alert smoke; promtool rules — CI job +python3 scripts/lab6_track2_full.py --warmup 3600 --baseline 1200 --burst 120 \ + --settle 3600 --sustained 900 --resolution 3600 --ttr 900 --false-positive 1200 \ + --out evidence/lab6/track2/full +``` + +Остановка без потери данных: `docker compose --env-file .env down`. +Намеренный сброс учебных данных: `docker compose --env-file .env --profile telemetry down -v`. +`make up-base` поднимает только lab5-профиль без telemetry; `make unit-test` — Go-тесты. +Grafana: `http://127.0.0.1:3000` (admin-пароль в `secrets/grafana.env`). +Prometheus/Loki/Tempo опубликованы только на loopback для evidence-запросов; +OTLP 4317/4318, RabbitMQ 15692 и self-metrics Collector 8888 — без host-портов. + +Версии закреплены manifest-list digest’ами Collector/Loki/Tempo/Grafana/Prometheus: +Docker выбирает arm64 на этой машине и amd64 на CI. Переопределения +`*_IMAGE/PLATFORM` остаются опциональными для нестандартного registry mirror. ## Архитектура и решения -TODO: схема процессов/хранилищ, источник истины, транзакционные границы, ограничения. Что перенесено из lab5, что изменено в этой работе. Соответствие переменных из .env.example реальной конфигурации. +```mermaid +flowchart LR + C[client] --> LB[HAProxy] + LB --> API[API x2] + API --> PG[(PostgreSQL)] + API --> S3[(SeaweedFS)] + API -->|OTLP| COL[Collector] + RELAY[relay] --> PG + RELAY --> MQ[(RabbitMQ)] + MQ --> W[worker] + W --> PG + W --> S3 + W -->|OTLP| COL + RELAY -->|OTLP| COL + COL -->|:8889| PROM[Prometheus] + COL -->|OTLP /otlp| LOKI[Loki] + COL -->|OTLP gRPC| TEMPO[Tempo] + PROM -->|scrape| MQ + PROM -->|scrape| LB + GRAF[Grafana] --> PROM + GRAF --> LOKI + GRAF --> TEMPO +``` -## Доказательства критериев +- API/worker/relay — OTel SDK; Collector — единственный OTLP-приёмник; + Prometheus/Loki/Tempo — хранилища; Grafana — UI и provisioning. +- Queue depth — `rabbitmq_prometheus`; oldest job age — SQL в relay; + CPU/RAM приложения — cgroup v2 (`messenger_process_*`), без cAdvisor и + Docker socket. Broker process metrics — RabbitMQ plugin. +- `service.name` задаётся кодом (`messenger-api`, `messenger-worker`, + `messenger-relay`) и явно в compose; `service.instance.id` — `INSTANCE_ID`/ + hostname; `deployment.environment.name=lab`. +- Логи проходят allowlist/redactor: `user_id`, `chat_id`, `message_id`, + filename, raw `path`, `query`, `object_key`, bodies, tokens и signed URL не + экспортируются. `X-Request-Id` нормализуется. +- HTTP route — OpenAPI-шаблон через `server.FindPath`; `r.Pattern` не + используется, потому что ogen регистрирует `/` на внешнем mux. +- W3C context переносится в payload outbox (`traceparent`/`tracestate`, + разрешены `contracts/jobs.schema.json`), relay создаёт `job.publish`, + worker — `job.process`; retry получает новый attempt-span. -| Критерий README | Команда/сценарий | Наблюдаемый результат | Файл доказательства | -| --- | --- | --- | --- | -| Публичный smoke | make test | TODO | TODO | -| Остальные пункты уровня 3 | TODO | TODO | TODO | -| Все пункты уровня 4, если заявлен | TODO | TODO | TODO | -| Выбранный трек 5, если заявлен | TODO | TODO | TODO | +## Сигналы и единицы -TODO: добавить отдельную строку для каждого заявленного критерия. PASS без команды и наблюдения не является доказательством. Проверка инфраструктурного hook требует подтверждения, какие реальные процессы/хранилища перезапущены. +| Сигнал | Имя | Единица/лейблы | +|---|---|---| +| HTTP requests | `http_server_request_duration_seconds_count` | histogram count; method, route, status_code/status_class | +| HTTP duration | `http_server_request_duration_seconds` | histogram, seconds, method/route/status | +| Jobs attempts | `messenger_jobs_processed_total` | job.type, outcome | +| Job duration | `messenger_job_duration_seconds` | histogram, seconds | +| Accepted/ready | `messenger_jobs_accepted_total`, `messenger_jobs_ready_within_budget_total` | pipeline.version | +| Time to ready | `messenger_job_time_to_ready_seconds` | histogram, seconds | +| Overdue jobs | `messenger_jobs_overdue` | gauge, count >30s | +| Queue depth | `rabbitmq_queue_messages_ready` | queue | +| Oldest job age | `messenger_queue_oldest_job_age_seconds` | seconds | +| Outbox age | `messenger_outbox_oldest_unpublished_age_seconds` | seconds | +| Worker saturation | `messenger_worker_busy`, `messenger_worker_capacity` | service.name | +| DB pool | `messenger_db_pool_used/idle/max`, empty-acquire counters | service.name | +| App CPU/RAM | `messenger_process_cpu_seconds_total`, `memory_usage/limit_bytes` | service.name | +| Collector | `otelcol_*` | pipeline/exporter | +| Edge SLI | `haproxy_backend_http_responses_total{proxy="api_backend"}` | code; `/health/*` — отдельный `api_health` | -## Эксперименты и отказы +SLO-окно — 7 дней; Prometheus retention 10d с лимитом 2GB: API availability 99.5% +(при request-based SLI бюджет 50.4 мин корректен только при постоянном трафике; +это не измеренный минутный бюджет). TTR SLO — **доля заданий**, ready ≤30 с +в 99% случаев; это не бюджет времени, и 100.8 мин не является измеренным +бюджетом TTR. +Burn-rate: fast 14.4× на 1h+5m, slow 6× на 6h+30m. Для 7-дневного +бюджета (168 ч) это 8.6% бюджета за час и 21.4% за 6 ч; при непрерывном +горении бюджет исчерпывается за 11.7 ч / 28 ч соответственно. +Prometheus retention настроен на 10d, но с `--storage.tsdb.retention.size=2GB`; +7d-окно не гарантировано, если объём данных достигает лимита. -TODO: гипотеза, hardware/лимиты, версии, объём данных, профиль нагрузки, concurrency/arrival rate, длительность/прогрев, повторы, успешные RPS, ошибки, p50/p95/p99, CPU/RAM. Сохранить raw summary без tokens и объяснить ограничения измерения. +| Множитель | Окна | Бюджет 7d, который сжигает | Время до исчерпания | +|---:|---|---:|---:| +| fast 14.4× | 1h + 5m | 8.6% за час | 11.7 ч | +| slow 6× | 6h + 30m | 21.4% за 6 ч | 28 ч | -| Воздействие | Что ожидаем | Что наблюдали | Время восстановления / потеря данных | -| --- | --- | --- | --- | -| TODO | TODO | TODO | TODO | +Теоретический TTD при 100% ошибок: fast ≈ 4.3 мин (`0.072 × 60`), +slow ≈ 10.8 мин (`0.03 × 360`). Если 6h-окно содержит только ~1ч45м +истории, slow выглядит как ~3.2 мин — такой TTD нерепрезентативен и не +сравнивается с fast. В отчёте это помечается явно. -## Ограничения и следующие шаги +Полный live-прогон выполнен 2026-11-06: warmup 60m, baseline 20m, burst 2m, +пауза 60m, sustained PostgreSQL 15m, resolution 60m, TTR 15m, false-positive +20m. `Aborted=False`; фактический timeline и числа — в `track2/full/` и +`track2/ttd-ttr.md`. Slow-burn 6h warmup не выполнялся, поэтому slow-TTD +считается ограниченным наблюдением, а не 6h-экспериментом. -TODO: какие отказы выдерживаются и какие нет; что не реализовано; где учебное упрощение; какое улучшение подтверждено, а какое пока гипотеза. +## Доказательства + +| Критерий | Команда/сценарий | Наблюдаемый результат | Файл | +|---|---|---|---| +| Публичный smoke | `make test` | PASS lab6 | `evidence/lab6/smoke.txt` | +| Три сигнала, Grafana provisioning | `make test-observability` | PASS, datasources/dashboard, route labels без UUID | `evidence/lab6/telemetry.txt` | +| Метрики всех уровней | PromQL из `queries/promql.txt` | непустые серии | `evidence/lab6/metrics.txt` | +| Trace upload → publish → worker, retry | Tempo trace | API span → `job.publish` → `job.process` → S3/DB; attempt 1/2 | `trace-pipeline.json`, `trace-retry.txt` | +| Лог и trace связаны | Loki query по `trace_id` | worker-запись найдена | `telemetry.txt` | +| Нет тел/токенов/filename | sentinel-запрос | 0 совпадений | `telemetry.txt` | +| Worker stop → backlog → drain | `stop-worker.sh`, controlled load, `start-worker.sh` | queue 3→0, oldest 15s→0; `JobsOverdue` fired/resolved | `worker-stop.txt`, `worker-stopped-load.json` | +| Collector down | stop collector, load + probes | API продолжает работать; TelemetryCollectorDown pending→firing→resolved | `collector-down.txt` | +| Telemetry storage down | stop Loki+Tempo, load, RSS | API работает; collector queues bounded, затем 0 | `storage-down.txt` | +| DB unavailable | stop PostgreSQL | readiness 503, edge 5xx, recovery smoke PASS | `db-down.txt` | +| P0 worker-down 15m | `scripts/lab6_ttr_worker_down.py` | ratio5 MISSING первые 90s, затем растёт до 1 с 330s; FastBurn firing, JobsOverdue/QueueOldest firing, recovery | `checks/ttr-worker-15m.txt` | +| Регрессия lab5 | `make test-attachments`, `test-presign`, `test-idempotency`, `test-queue`, `test-faults`, `test-persistence`, `test-failover`, `test-lb-readiness`, `make integration-test`, `make lint`, `make load`, `make test-track2` | PASS | `evidence/lab6/regression/` | +| Track 2: правила/исправления | `promtool check rules`, `make test-observability` | PASS | `checks/static.txt`, `infra/prometheus/rules/` | +| Track 2: full run | `scripts/lab6_track2_full.py --warmup 3600 --settle 3600` | burst 0 page; API TTD 5:00/5:20; TTR JobsOverdue 2:46, QueueHigh 12:17; FP 0 | `checks/alert-audit.txt`, `track2/full/` | + +## Track 2: гипотеза, методика, результаты + +**Гипотеза.** При 0.2 req/s и 20% uploads 2-минутная пауза PostgreSQL не +должна вызывать page; 15-минутная остановка должна дать FastBurn/SlowBurn; +остановка worker должна дать JobsOverdue/queue-age раньше, чем TTR burn. + +**Методика.** `scripts/lab6_track2_full.py`: warmup 60m, baseline 20m, burst +2m PG pause, пауза 60m, sustained 15m PG stop, resolution 60m, TTR worker +15m, false-positive 20m. Инъекции и restore записываются в `phases.json`; +алерты — `alerts.csv`; снимки — `snapshots/`. + +**Результаты.** Burst: 0 page. Sustained (injection 11:29:51Z): FastBurn firing +11:34:51Z — TTD **5:00**; SlowBurn 11:35:11Z — **5:20**. После restore +11:44:55Z FastBurn resolved 11:49:30Z (**4:35**), SlowBurn resolved 12:13:32Z +(**28:37**). TTR: JobsOverdue firing 12:55:03Z (+**2:46**), QueueHigh +13:04:34Z (+**12:17**). Critical fired 13:07:29Z, через **12 s после +записанного restore** 13:07:17Z, поэтому это не доказательство обнаружения +до восстановления; injection записан после остановки worker. В полном TTR +сценарии принято 20 задач, 160 получили 429; FastBurn не сработал, отдельный +15m worker-down его подтверждает. False-positive: 20m без новых firing. + +**Ограничения.** 6h warmup не выполнялся; slow TTD и реальный 7-дневный +бюджет не измерены. API SLO request-based; перевод бюджета в минуты зависит +от трафика. Два разобранных отказа: PostgreSQL (`db-availability.md`) и +worker/queue (`queue-lag.md`), evidence — `db-down.txt`, +`checks/ttr-worker-15m.txt`, `track2/full/`. + +## Ограничения + +- Текущая Colima VM: **4 CPU / 8 ГиБ** (диск 100 ГиБ). Часть evidence M3/M4 + снята до увеличения ресурсов (было 2 CPU / 2 ГиБ); после увеличения сборка + и strict-проверка проходят без остановки telemetry. Полный track 2 выполнен + на этой конфигурации; 70-минутный warmup прошёл без ошибок. +- Collector/Loki/Tempo/Grafana/Prometheus — single-node, без TLS/auth + (lab7); Grafana admin — локальный secret, остальные интерфейсы только loopback. +- SDK queue drops не имеют полного публичного счётчика в Go SDK; наблюдаются + Collector `otelcol_*` и app export failures, граница описана в runbook. +- Полный 6h slow-burn live-прогон не заявляется. Множители 14.4×/6× для 7d + **менее чувствительны**, чем рекомендации SRE для 30d: за 1h/6h они расходуют + 8.6%/21.4% семидневного бюджета. Выбор обоснован малым трафиком и шумом, + а не «консервативностью». +- False-positive: в завершающей 20-минутной фазе **не было новых firing** + после восстановления. Это ограниченное наблюдение, а не универсальная + оценка FP. +- Сессия загрузчика живёт 3600 s; harness обновляет её за 10 минут до TTL. +- TTR-фаза намеренно перегружает admission: 20 uploads accepted, остальные + 160 получили 429; 429 не входят в API/TTR SLI, `failures_by_reason` + сохраняет причины. +- SLI API использует backend `api_backend`; `/health/*` вынесен в + `api_health` и не входит ни в numerator, ни в denominator. +- TTR SLI event-based: если новые задания перестали поступать, burn-rate + может погаснуть, хотя backlog остаётся; для этого служат `JobsOverdue` + и queue-age alerts. Это наблюдалось отдельно. +- В `MarkTTRMissed` отметка в БД и экспорт счётчика не транзакционны: + падение relay между ними может потерять один инкремент; в текущем стенде + это не проявлялось. +- `alerts.csv` ключует алерт по `alertname + labels` и пишет pending→firing + и resolved только при исчезновении; polling 5 s. В текущем full CSV колонки + labels ещё нет (формат снят до её добавления), поэтому `checks/alert-audit.txt` + для этого файла группирует по имени; это явное ограничение, labels не + восстанавливаются догадками. diff --git a/cmd/jobctl/main.go b/cmd/jobctl/main.go new file mode 100644 index 0000000..248b8b3 --- /dev/null +++ b/cmd/jobctl/main.go @@ -0,0 +1,215 @@ +package main + +import ( + "context" + "encoding/json" + "flag" + "fmt" + "log/slog" + "os" + "time" + + "github.com/google/uuid" + + "mtusi-messenger/internal/config" + "mtusi-messenger/internal/imageproc" + "mtusi-messenger/internal/logger" + "mtusi-messenger/internal/storage/postgres" +) + +func main() { + if len(os.Args) < 2 { + usage() + os.Exit(2) + } + + cfg, err := config.Load() + if err != nil { + fmt.Fprintln(os.Stderr, "load config:", err) + os.Exit(1) + } + + log := logger.New(logger.WithLevel(cfg.SlogLevel()), logger.WithFormat(logger.FormatConsole)) + slog.SetDefault(log) + + ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second) + defer cancel() + + store, err := postgres.New(ctx, cfg.Postgres, time.Duration(cfg.Idempotency.TTLSeconds)*time.Second) + if err != nil { + fmt.Fprintln(os.Stderr, "connect database:", err) + cancel() + os.Exit(1) //nolint:gocritic // main exits after DB setup failure + } + defer store.Close() + + repo := store.Pipeline() + + switch os.Args[1] { + case "failed": + runFailed(ctx, repo) + case "replay": + runReplay(ctx, repo, cfg) + case "reprocess": + runReprocess(ctx, repo, cfg) + case "duplicate": + runDuplicate(ctx, repo) + case "inspect": + runInspect(ctx, repo) + default: + usage() + os.Exit(2) + } +} + +func usage() { + fmt.Fprintln(os.Stderr, `usage: jobctl [flags] + + failed -limit N + replay -job JOB_ID [-attempts N] + reprocess -attachment ATTACHMENT_ID -pipeline N + duplicate -attachment ATTACHMENT_ID | -job JOB_ID + inspect -attachment ATTACHMENT_ID`) +} + +func runFailed(ctx context.Context, repo *postgres.PipelineRepository) { + flags := flag.NewFlagSet("failed", flag.ExitOnError) + limit := flags.Int("limit", 50, "maximum jobs") + _ = flags.Parse(os.Args[2:]) + + jobs, err := repo.ListFailedJobs(ctx, *limit) + if err != nil { + fail(err) + } + + printJSON(jobs) +} + +func runReplay(ctx context.Context, repo *postgres.PipelineRepository, cfg config.Config) { + flags := flag.NewFlagSet("replay", flag.ExitOnError) + jobID := flags.String("job", "", "job id") + attempts := flags.Int("attempts", cfg.Processing.MaxAttempts, "additional attempts") + _ = flags.Parse(os.Args[2:]) + + id, err := uuid.Parse(*jobID) + if err != nil { + fail(fmt.Errorf("invalid job id: %w", err)) + } + + job, err := repo.ReplayJob(ctx, id, *attempts) + if err != nil { + fail(err) + } + + printJSON(job) +} + +func runReprocess(ctx context.Context, repo *postgres.PipelineRepository, cfg config.Config) { + flags := flag.NewFlagSet("reprocess", flag.ExitOnError) + attachmentID := flags.String("attachment", "", "attachment id") + version := flags.Int("pipeline", 2, "target pipeline version") + _ = flags.Parse(os.Args[2:]) + + if _, ok := imageproc.Pipeline(*version); !ok { + fail(fmt.Errorf("unsupported pipeline version %d", *version)) + } + + id, err := uuid.Parse(*attachmentID) + if err != nil { + fail(fmt.Errorf("invalid attachment id: %w", err)) + } + + jobID, err := uuid.NewV7() + if err != nil { + fail(err) + } + + job, err := repo.Reprocess(ctx, id, *version, cfg.Processing.MaxAttempts, jobID) + if err != nil { + fail(err) + } + + printJSON(job) +} + +func runDuplicate(ctx context.Context, repo *postgres.PipelineRepository) { + flags := flag.NewFlagSet("duplicate", flag.ExitOnError) + attachmentID := flags.String("attachment", "", "attachment id") + jobID := flags.String("job", "", "specific job id (old pipeline version)") + _ = flags.Parse(os.Args[2:]) + + if *jobID != "" { + id, err := uuid.Parse(*jobID) + if err != nil { + fail(fmt.Errorf("invalid job id: %w", err)) + } + + message, err := repo.DuplicateJob(ctx, id) + if err != nil { + fail(err) + } + + printJSON(message) + + return + } + + id, err := uuid.Parse(*attachmentID) + if err != nil { + fail(fmt.Errorf("attachment or job id is required: %w", err)) + } + + message, err := repo.Duplicate(ctx, id) + if err != nil { + fail(err) + } + + printJSON(message) +} + +func runInspect(ctx context.Context, repo *postgres.PipelineRepository) { + flags := flag.NewFlagSet("inspect", flag.ExitOnError) + attachmentID := flags.String("attachment", "", "attachment id") + _ = flags.Parse(os.Args[2:]) + + id, err := uuid.Parse(*attachmentID) + if err != nil { + fail(fmt.Errorf("invalid attachment id: %w", err)) + } + + attachment, err := repo.GetForID(ctx, id) + if err != nil { + fail(err) + } + + variants, err := repo.ListVariants(ctx, id, attachment.PipelineVersion) + if err != nil { + fail(err) + } + + var jobOutput any + + job, jobErr := repo.GetJobByAttachment(ctx, id, attachment.PipelineVersion) + if jobErr == nil { + jobOutput = job + } + + printJSON(map[string]any{ + "attachment": attachment, + "variants": variants, + "job": jobOutput, + }) +} + +func printJSON(value any) { + encoder := json.NewEncoder(os.Stdout) + encoder.SetIndent("", " ") + if err := encoder.Encode(value); err != nil { + fail(err) + } +} + +func fail(err error) { + fmt.Fprintln(os.Stderr, "error:", err) + os.Exit(1) +} diff --git a/cmd/messenger/main.go b/cmd/messenger/main.go new file mode 100644 index 0000000..c6a1099 --- /dev/null +++ b/cmd/messenger/main.go @@ -0,0 +1,269 @@ +package main + +import ( + "context" + "errors" + "fmt" + "log/slog" + "net/http" + "os" + "os/signal" + "sync" + "syscall" + "time" + + "mtusi-messenger/internal/config" + "mtusi-messenger/internal/health" + "mtusi-messenger/internal/logger" + "mtusi-messenger/internal/platform/cache" + "mtusi-messenger/internal/platform/objectstore" + "mtusi-messenger/internal/platform/token" + "mtusi-messenger/internal/service/attachment" + "mtusi-messenger/internal/service/chat" + "mtusi-messenger/internal/service/message" + "mtusi-messenger/internal/service/session" + "mtusi-messenger/internal/service/user" + "mtusi-messenger/internal/storage/postgres" + storageredis "mtusi-messenger/internal/storage/redis" + "mtusi-messenger/internal/telemetry" + "mtusi-messenger/internal/transport/rest" +) + +var version = "dev" + +func main() { + log := logger.New() + + cfg, err := config.Load() + if err != nil { + log.Error("load config", slog.Any("error", err)) + os.Exit(1) + } + + log = logger.New( + logger.WithLevel(cfg.SlogLevel()), + logger.WithFormat(cfg.LoggerFormat()), + ) + + shutdown, telemetryErr := telemetry.Setup(context.Background(), "messenger-api", version) + if telemetryErr != nil { + log.Warn("telemetry setup failed; continuing without OTLP", slog.Any("error", telemetryErr)) + shutdown = func(context.Context) error { return nil } + } + log = telemetry.WrapLogger(log, "messenger-api", cfg.SlogLevel()) + slog.SetDefault(log) + + if err := run(cfg, log); err != nil { + log.Error("shutdown with error", slog.Any("error", err)) + shutdownCtx, cancel := context.WithTimeout(context.Background(), 3*time.Second) + _ = shutdown(shutdownCtx) + cancel() + os.Exit(1) + } + + shutdownCtx, cancel := context.WithTimeout(context.Background(), 3*time.Second) + defer cancel() + if err := shutdown(shutdownCtx); err != nil { + log.Warn("telemetry shutdown failed", slog.Any("error", err)) + } +} + +func run(cfg config.Config, log *slog.Logger) error { + ctx, stop := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM) + defer stop() + + store, err := postgres.New(ctx, cfg.Postgres, time.Duration(cfg.Idempotency.TTLSeconds)*time.Second, postgres.WithQueryTracer(telemetry.NewPGXTracer())) + if err != nil { + return fmt.Errorf("connect database: %w", err) + } + + defer store.Close() + + if err := telemetry.RegisterDBPool(store.PoolStats); err != nil { + log.Warn("register db pool metrics", slog.Any("error", err)) + } + if err := telemetry.RegisterProcessMetrics(); err != nil { + log.Warn("register process metrics", slog.Any("error", err)) + } + + objectStoreConcrete, err := objectstore.New(objectstore.Config{ + Endpoint: cfg.S3.Endpoint, + PublicEndpoint: cfg.S3.PublicEndpoint, + Region: cfg.S3.Region, + Bucket: cfg.S3.Bucket, + AccessKeyID: cfg.S3.AccessKeyID, + SecretAccessKey: cfg.S3.SecretAccessKey, + UsePathStyle: cfg.S3.UsePathStyle, + Timeout: cfg.S3.Timeout, + }) + if err != nil { + return fmt.Errorf("connect object store: %w", err) + } + + objectStore := telemetry.WrapStore(objectStoreConcrete) + + pipelineRepository := store.Pipeline() + attachmentService := attachment.NewService( + pipelineRepository, + objectStore, + attachment.Config{ + MaxUploadBytes: cfg.S3.MaxUploadBytes, + MaxImagePixels: cfg.S3.MaxImagePixels, + PresignTTL: cfg.S3.PresignTTL, + PipelineVersion: cfg.Processing.PipelineVersion, + MaxAttempts: cfg.Processing.MaxAttempts, + MaxPendingPerUser: cfg.Admission.MaxPendingPerUser, + MaxPending: cfg.Admission.MaxPending, + MaxStagedBytes: cfg.Admission.MaxStagedBytes, + MaxConcurrent: cfg.Admission.MaxConcurrent, + }, + log, + ) + + sweeper := attachment.NewSweeper( + pipelineRepository, + objectStore, + store, + cfg.S3.SweepGrace, + cfg.Staging.OrphanGrace, + cfg.Staging.FailedRetention, + cfg.S3.SweepInterval, + log, + ) + + sweepCtx, stopSweeper := context.WithCancel(context.Background()) + var sweepWait sync.WaitGroup + + sweepWait.Add(1) + + go func() { + defer sweepWait.Done() + + sweeper.Run(sweepCtx) + }() + + defer func() { + stopSweeper() + sweepWait.Wait() + }() + + redisCache, err := connectRedis(cfg.Redis) + if err != nil { + return err + } + + defer func() { _ = redisCache.Close() }() + + sessionRepo := session.Repository(store.Sessions()) + chatRepo := chat.Repository(store.Chats()) + + pingers := []health.Pinger{store} + + if cfg.Redis.Enabled { + if cfg.Cache.Enabled { + distributed, err := cache.NewDistributed(redisCache, cache.DistributedConfig{ + LockTTL: cfg.Cache.LockTTL, + WaitTimeout: cfg.Cache.LockWaitTimeout, + }, log) + if err != nil { + return fmt.Errorf("build distributed cache: %w", err) + } + + chatRepo = storageredis.NewChatRepository( + store.Chats(), + distributed, + cfg.Cache.ChatListTTL, + log, + ) + } + + log.Info("redis cache enabled", slog.String("host", cfg.Redis.Host), slog.Int("port", cfg.Redis.Port)) + } + + ttl := time.Duration(cfg.Session.TTLSeconds) * time.Second + sessionService := session.NewService(sessionRepo, token.New(), ttl) + + router, err := rest.NewRouter( + rest.NewHandler( + user.NewService(store.Users()), + chat.NewService(chatRepo), + message.NewService(store.Messages(), pipelineRepository), + attachmentService, + health.New(pingers...), + sessionService, + ), + rest.NewSecurityHandler(sessionService), + rest.NewExtensions(attachmentService, sessionService, log), + log, + cfg.Server.MaxBodyBytes, + cfg.S3.MaxUploadBytes, + ) + if err != nil { + return fmt.Errorf("build router: %w", err) + } + + server := &http.Server{ + Addr: cfg.Addr(), + Handler: router, + ReadHeaderTimeout: cfg.Server.ReadHeaderTimeout, + ReadTimeout: cfg.Server.ReadTimeout, + } + + errc := make(chan error, 1) + + go func() { + log.Info("server started", slog.String("addr", cfg.Addr())) + + if err := server.ListenAndServe(); err != nil && !errors.Is(err, http.ErrServerClosed) { + errc <- err + } + + close(errc) + }() + + select { + case err, ok := <-errc: + if ok && err != nil { + return fmt.Errorf("listen: %w", err) + } + + return nil + case <-ctx.Done(): + } + + log.Info("shutdown signal received", slog.Duration("timeout", cfg.Server.ShutdownTimeout)) + + shutdownCtx, cancel := context.WithTimeout(context.Background(), cfg.Server.ShutdownTimeout) + defer cancel() + + if err := server.Shutdown(shutdownCtx); err != nil { + return fmt.Errorf("shutdown: %w", err) + } + + log.Info("server stopped") + + return nil +} + +func connectRedis(cfg config.Redis) (cache.LockStore, error) { + if !cfg.Enabled { + return cache.NoOpCache{}, nil + } + + client, err := cache.NewRedis(cache.RedisConfig{ + Host: cfg.Host, + Port: cfg.Port, + Password: cfg.Password, + DB: cfg.DB, + MaxRetries: cfg.MaxRetries, + DialTimeout: cfg.DialTimeout, + ReadTimeout: cfg.ReadTimeout, + WriteTimeout: cfg.WriteTimeout, + PoolSize: cfg.PoolSize, + }) + if err != nil { + return nil, fmt.Errorf("connect redis: %w", err) + } + + return client, nil +} diff --git a/cmd/migrate/main.go b/cmd/migrate/main.go new file mode 100644 index 0000000..d980b52 --- /dev/null +++ b/cmd/migrate/main.go @@ -0,0 +1,89 @@ +package main + +import ( + "context" + "database/sql" + "errors" + "fmt" + "log/slog" + "os" + + "github.com/pressly/goose/v3" + + "mtusi-messenger/internal/config" + "mtusi-messenger/internal/logger" + "mtusi-messenger/internal/storage/postgres/migrations" + + _ "github.com/jackc/pgx/v5/stdlib" +) + +func main() { + log := logger.New() + + if err := run(os.Args[1:]); err != nil { + log.Error("migrate failed", slog.Any("error", err)) + os.Exit(1) + } +} + +func run(args []string) error { + cfg, err := config.Load() + if err != nil { + return fmt.Errorf("load config: %w", err) + } + + slog.SetDefault(logger.New( + logger.WithLevel(cfg.SlogLevel()), + logger.WithFormat(cfg.LoggerFormat()), + )) + + command := "up" + if len(args) > 0 { + command = args[0] + } + + db, err := sql.Open("pgx", cfg.Postgres.DSN()) + if err != nil { + return fmt.Errorf("open database: %w", err) + } + + defer func() { _ = db.Close() }() + + pingCtx, cancel := context.WithTimeout(context.Background(), cfg.Postgres.ConnectTimeout) + defer cancel() + + if err := db.PingContext(pingCtx); err != nil { + return fmt.Errorf("ping database: %w", err) + } + + goose.SetBaseFS(migrations.FS) + + if err := goose.SetDialect("postgres"); err != nil { + return fmt.Errorf("set dialect: %w", err) + } + + if err := goCommand(db, command); err != nil { + return err + } + + return nil +} + +func goCommand(db *sql.DB, command string) error { + switch command { + case "up": + return goose.Up(db, ".") + case "up-by-one": + return goose.UpByOne(db, ".") + case "down": + return goose.Down(db, ".") + case "status": + return goose.Status(db, ".") + case "version": + return goose.Version(db, ".") + case "redo": + return goose.Redo(db, ".") + default: + return errors.New("unknown command: " + command + " (up, up-by-one, down, status, version, redo)") + } +} diff --git a/cmd/relay/main.go b/cmd/relay/main.go new file mode 100644 index 0000000..f349775 --- /dev/null +++ b/cmd/relay/main.go @@ -0,0 +1,294 @@ +package main + +import ( + "context" + "encoding/json" + "errors" + "fmt" + "log/slog" + "net/http" + "os" + "os/signal" + "sync" + "syscall" + "time" + + "mtusi-messenger/internal/broker" + "mtusi-messenger/internal/config" + "mtusi-messenger/internal/domain" + "mtusi-messenger/internal/logger" + "mtusi-messenger/internal/outbox" + "mtusi-messenger/internal/storage/postgres" + "mtusi-messenger/internal/telemetry" +) + +const maxUnpublishedAge = 10 * time.Minute + +var version = "dev" + +func main() { + log := logger.New() + + cfg, err := config.Load() + if err != nil { + log.Error("load config", slog.Any("error", err)) + os.Exit(1) + } + + log = logger.New( + logger.WithLevel(cfg.SlogLevel()), + logger.WithFormat(cfg.LoggerFormat()), + ) + + shutdown, telemetryErr := telemetry.Setup(context.Background(), "messenger-relay", version) + if telemetryErr != nil { + log.Warn("telemetry setup failed; continuing without OTLP", slog.Any("error", telemetryErr)) + shutdown = func(context.Context) error { return nil } + } + log = telemetry.WrapLogger(log, "messenger-relay", cfg.SlogLevel()) + slog.SetDefault(log) + + if err := run(cfg, log); err != nil { + log.Error("shutdown with error", slog.Any("error", err)) + shutdownCtx, cancel := context.WithTimeout(context.Background(), 3*time.Second) + _ = shutdown(shutdownCtx) + cancel() + os.Exit(1) + } + + shutdownCtx, cancel := context.WithTimeout(context.Background(), 3*time.Second) + defer cancel() + if err := shutdown(shutdownCtx); err != nil { + log.Warn("telemetry shutdown failed", slog.Any("error", err)) + } +} + +type publisher struct { + cfg broker.Config + log *slog.Logger + mu sync.Mutex + conn *broker.Client +} + +func (p *publisher) client() (*broker.Client, error) { + p.mu.Lock() + defer p.mu.Unlock() + + if p.conn != nil && p.conn.Connected() { + return p.conn, nil + } + + if p.conn != nil { + _ = p.conn.Close() + p.conn = nil + } + + conn, err := broker.Dial(p.cfg) + if err != nil { + return nil, err + } + + p.conn = conn + + return conn, nil +} + +func (p *publisher) PublishConfirmed( + ctx context.Context, + routingKey string, + message domain.JobMessage, +) error { + conn, err := p.client() + if err != nil { + return err + } + + if err := conn.PublishConfirmed(ctx, routingKey, message); err != nil { + p.mu.Lock() + if p.conn == conn { + _ = p.conn.Close() + p.conn = nil + } + p.mu.Unlock() + + return err + } + + return nil +} + +func (p *publisher) Connect() error { + _, err := p.client() + + return err +} + +func (p *publisher) Connected() bool { + p.mu.Lock() + defer p.mu.Unlock() + + return p.conn != nil && p.conn.Connected() +} + +func (p *publisher) Close() { + p.mu.Lock() + defer p.mu.Unlock() + + if p.conn != nil { + _ = p.conn.Close() + p.conn = nil + } +} + +func brokerConfig(cfg config.Config) broker.Config { + return broker.Config{ + URL: cfg.Broker.URL, + Exchange: cfg.Broker.Exchange, + DLX: cfg.Broker.DLX, + Queue: cfg.Broker.Queue, + DLQ: cfg.Broker.DLQ, + ConnectTimeout: cfg.Broker.ConnectTimeout, + ConfirmTimeout: cfg.Broker.ConfirmTimeout, + Heartbeat: cfg.Broker.Heartbeat, + Prefetch: cfg.Broker.Prefetch, + } +} + +func run(cfg config.Config, log *slog.Logger) error { + if cfg.Broker.URL == "" { + return errors.New("BROKER_URL is required for relay") + } + + ctx, stop := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM) + defer stop() + + store, err := postgres.New(ctx, cfg.Postgres, time.Duration(cfg.Idempotency.TTLSeconds)*time.Second, postgres.WithQueryTracer(telemetry.NewPGXTracer())) + if err != nil { + return fmt.Errorf("connect database: %w", err) + } + defer store.Close() + + if err := telemetry.RegisterDBPool(store.PoolStats); err != nil { + log.Warn("register db pool metrics", slog.Any("error", err)) + } + if err := telemetry.RegisterProcessMetrics(); err != nil { + log.Warn("register process metrics", slog.Any("error", err)) + } + + pub := &publisher{cfg: brokerConfig(cfg), log: log} + defer pub.Close() + + if err := pub.Connect(); err != nil { + log.Warn("broker is not reachable yet; relay will retry", slog.Any("error", err)) + } + + relay := outbox.New(store.Pipeline(), pub, outbox.Config{ + Owner: "relay-" + cfg.Broker.Queue, + PollInterval: cfg.Outbox.PollInterval, + ClaimTTL: cfg.Outbox.ClaimTTL, + Batch: cfg.Outbox.Batch, + ReaperInterval: cfg.Outbox.ReaperInterval, + ReconcileAfter: cfg.Outbox.ReconcileAfter, + Retention: cfg.Outbox.Retention, + }, log) + + if err := telemetry.RegisterRelayMetrics(store.Pipeline().OldestActiveJobAge, relay.Health, func(ctx context.Context) (int64, error) { + return store.Pipeline().CountOverdueJobs(ctx, 30*time.Second) + }); err != nil { + log.Warn("register relay metrics", slog.Any("error", err)) + } + + relayCtx, cancelRelay := context.WithCancel(ctx) + defer cancelRelay() + + relayDone := make(chan struct{}) + + go func() { + defer close(relayDone) + + relay.Run(relayCtx) + }() + + server := healthServer(cfg.Relay.HealthAddr, store, pub, relay, log) + + go func() { + if err := server.ListenAndServe(); err != nil && err != http.ErrServerClosed { + log.Error("health server failed", slog.Any("error", err)) + } + }() + + <-ctx.Done() + cancelRelay() + <-relayDone + + shutdownCtx, cancel := context.WithTimeout(context.Background(), 10*time.Second) + defer cancel() + + return server.Shutdown(shutdownCtx) +} + +func healthServer( + addr string, + store *postgres.Store, + pub *publisher, + relay *outbox.Relay, + _ *slog.Logger, +) *http.Server { + mux := http.NewServeMux() + + mux.HandleFunc("/health/live", func(w http.ResponseWriter, _ *http.Request) { + writeHealth(w, http.StatusOK, map[string]any{"status": "ok"}) + }) + + mux.HandleFunc("/health/ready", func(w http.ResponseWriter, r *http.Request) { + ctx, cancel := context.WithTimeout(r.Context(), 3*time.Second) + defer cancel() + + if err := store.Ping(ctx); err != nil { + writeHealth(w, http.StatusServiceUnavailable, map[string]any{"status": "unavailable"}) + + return + } + + if !pub.Connected() { + if err := pub.Connect(); err != nil { + writeHealth(w, http.StatusServiceUnavailable, map[string]any{"status": "unavailable"}) + + return + } + } + + oldest, err := relay.Health(ctx) + if err != nil { + writeHealth(w, http.StatusServiceUnavailable, map[string]any{"status": "unavailable"}) + + return + } + + if oldest > maxUnpublishedAge { + writeHealth(w, http.StatusServiceUnavailable, map[string]any{ + "status": "unavailable", + "outbox_oldest_seconds": int(oldest.Seconds()), + }) + + return + } + + writeHealth(w, http.StatusOK, map[string]any{ + "status": "ok", + "outbox_oldest_seconds": int(oldest.Seconds()), + }) + }) + + return &http.Server{ + Addr: addr, + Handler: mux, + ReadHeaderTimeout: 5 * time.Second, + } +} + +func writeHealth(w http.ResponseWriter, status int, body map[string]any) { + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(status) + _ = json.NewEncoder(w).Encode(body) +} diff --git a/cmd/s3init/main.go b/cmd/s3init/main.go new file mode 100644 index 0000000..fa4e947 --- /dev/null +++ b/cmd/s3init/main.go @@ -0,0 +1,223 @@ +// Command s3init bootstraps the private attachment bucket. It is idempotent: +// it runs before the API on every compose up, verifies the bucket and the +// application identity, and exits successfully when everything is in place. +package main + +import ( + "bytes" + "context" + "errors" + "fmt" + "log/slog" + "os" + "strings" + "time" + + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/credentials" + "github.com/aws/aws-sdk-go-v2/service/s3" + "github.com/aws/smithy-go" + "github.com/google/uuid" +) + +const bootstrapTimeout = 120 * time.Second + +type settings struct { + Endpoint string + Region string + Bucket string + AdminAccessKey string + AdminSecretKey string + AppAccessKey string + AppSecretKey string +} + +func main() { + log := slog.New(slog.NewJSONHandler(os.Stdout, nil)) + + if err := run(log); err != nil { + log.Error("s3 bootstrap failed", slog.Any("error", err)) + os.Exit(1) + } +} + +func run(log *slog.Logger) error { + cfg, err := loadSettings() + if err != nil { + return err + } + + ctx, cancel := context.WithTimeout(context.Background(), bootstrapTimeout) + defer cancel() + + admin := newClient(cfg, cfg.AdminAccessKey, cfg.AdminSecretKey) + app := newClient(cfg, cfg.AppAccessKey, cfg.AppSecretKey) + + if err := waitForBucket(ctx, admin, cfg.Bucket); err != nil { + return err + } + + if err := probeAppIdentity(ctx, app, cfg.Bucket); err != nil { + return err + } + + if err := probeForbiddenPrefix(ctx, app, cfg.Bucket); err != nil { + return err + } + + log.Info("s3 bucket ready", + slog.String("endpoint", cfg.Endpoint), + slog.String("bucket", cfg.Bucket), + ) + + return nil +} + +func loadSettings() (settings, error) { + cfg := settings{ + Endpoint: strings.TrimSpace(os.Getenv("S3_ENDPOINT")), + Region: strings.TrimSpace(os.Getenv("S3_REGION")), + Bucket: strings.TrimSpace(os.Getenv("S3_BUCKET")), + AdminAccessKey: strings.TrimSpace(os.Getenv("S3_ADMIN_ACCESS_KEY")), + AdminSecretKey: strings.TrimSpace(os.Getenv("S3_ADMIN_SECRET_ACCESS_KEY")), + AppAccessKey: strings.TrimSpace(os.Getenv("S3_ACCESS_KEY_ID")), + AppSecretKey: strings.TrimSpace(os.Getenv("S3_SECRET_ACCESS_KEY")), + } + + switch { + case cfg.Endpoint == "": + return settings{}, errors.New("S3_ENDPOINT is required") + case cfg.Region == "": + return settings{}, errors.New("S3_REGION is required") + case cfg.Bucket == "": + return settings{}, errors.New("S3_BUCKET is required") + case cfg.AdminAccessKey == "" || cfg.AdminSecretKey == "": + return settings{}, errors.New("S3_ADMIN_ACCESS_KEY and S3_ADMIN_SECRET_ACCESS_KEY are required") + case cfg.AppAccessKey == "" || cfg.AppSecretKey == "": + return settings{}, errors.New("S3_ACCESS_KEY_ID and S3_SECRET_ACCESS_KEY are required") + } + + return cfg, nil +} + +func newClient(cfg settings, accessKey, secretKey string) *s3.Client { + return s3.New(s3.Options{ + Region: cfg.Region, + BaseEndpoint: aws.String(cfg.Endpoint), + UsePathStyle: true, + Credentials: credentials.NewStaticCredentialsProvider(accessKey, secretKey, ""), + }) +} + +func waitForBucket(ctx context.Context, client *s3.Client, bucket string) error { + for { + _, err := client.HeadBucket(ctx, &s3.HeadBucketInput{Bucket: aws.String(bucket)}) + if err == nil { + return nil + } + + if !isNotFound(err) { + return fmt.Errorf("head bucket: %w", err) + } + + if _, err := client.CreateBucket(ctx, &s3.CreateBucketInput{Bucket: aws.String(bucket)}); err == nil { + return nil + } else if isBucketExists(err) { + return nil + } else if !isNotFound(err) { + return fmt.Errorf("create bucket: %w", err) + } + + select { + case <-ctx.Done(): + return fmt.Errorf("wait for object store: %w", ctx.Err()) + case <-time.After(time.Second): + } + } +} + +func probeAppIdentity(ctx context.Context, client *s3.Client, bucket string) error { + key := "staging/.bootstrap/" + uuid.NewString() + + if _, err := client.PutObject(ctx, &s3.PutObjectInput{ + Bucket: aws.String(bucket), + Key: aws.String(key), + Body: bytes.NewReader([]byte("ok")), + ContentLength: aws.Int64(2), + ContentType: aws.String("text/plain"), + }); err != nil { + return fmt.Errorf("application identity cannot write: %w", err) + } + + defer func() { + _, _ = client.DeleteObject(ctx, &s3.DeleteObjectInput{ + Bucket: aws.String(bucket), + Key: aws.String(key), + }) + }() + + if _, err := client.HeadObject(ctx, &s3.HeadObjectInput{ + Bucket: aws.String(bucket), + Key: aws.String(key), + }); err != nil { + return fmt.Errorf("application identity cannot read: %w", err) + } + + if _, err := client.ListObjectsV2(ctx, &s3.ListObjectsV2Input{ + Bucket: aws.String(bucket), + Prefix: aws.String("staging/"), + }); err != nil { + return fmt.Errorf("application identity cannot list: %w", err) + } + + return nil +} + +func probeForbiddenPrefix(ctx context.Context, client *s3.Client, bucket string) error { + key := "forbidden/" + uuid.NewString() + + _, err := client.PutObject(ctx, &s3.PutObjectInput{ + Bucket: aws.String(bucket), + Key: aws.String(key), + Body: bytes.NewReader([]byte("must not be stored")), + }) + if err == nil { + _, _ = client.DeleteObject(ctx, &s3.DeleteObjectInput{ + Bucket: aws.String(bucket), + Key: aws.String(key), + }) + + return errors.New("application identity can write outside the allowed prefixes; check infra/s3/s3.json") + } + + var apiErr smithy.APIError + if !errors.As(err, &apiErr) || apiErr.ErrorCode() != "AccessDenied" { + return fmt.Errorf("forbidden-prefix probe returned an unexpected error: %w", err) + } + + return nil +} + +func isNotFound(err error) bool { + var apiErr smithy.APIError + if errors.As(err, &apiErr) { + switch apiErr.ErrorCode() { + case "NotFound", "NoSuchBucket", "NoSuchKey": + return true + } + } + + return false +} + +func isBucketExists(err error) bool { + var apiErr smithy.APIError + if errors.As(err, &apiErr) { + switch apiErr.ErrorCode() { + case "BucketAlreadyExists", "BucketAlreadyOwnedByYou": + return true + } + } + + return false +} diff --git a/cmd/worker/main.go b/cmd/worker/main.go new file mode 100644 index 0000000..7d91c90 --- /dev/null +++ b/cmd/worker/main.go @@ -0,0 +1,263 @@ +package main + +import ( + "context" + "encoding/json" + "errors" + "fmt" + "log/slog" + "net/http" + "os" + "os/signal" + "sync" + "syscall" + "time" + + "mtusi-messenger/internal/broker" + "mtusi-messenger/internal/config" + "mtusi-messenger/internal/logger" + "mtusi-messenger/internal/platform/objectstore" + "mtusi-messenger/internal/storage/postgres" + "mtusi-messenger/internal/telemetry" + "mtusi-messenger/internal/worker" +) + +var version = "dev" + +func main() { + log := logger.New() + + cfg, err := config.Load() + if err != nil { + log.Error("load config", slog.Any("error", err)) + os.Exit(1) + } + + log = logger.New( + logger.WithLevel(cfg.SlogLevel()), + logger.WithFormat(cfg.LoggerFormat()), + ) + + shutdown, telemetryErr := telemetry.Setup(context.Background(), "messenger-worker", version) + if telemetryErr != nil { + log.Warn("telemetry setup failed; continuing without OTLP", slog.Any("error", telemetryErr)) + shutdown = func(context.Context) error { return nil } + } + log = telemetry.WrapLogger(log, "messenger-worker", cfg.SlogLevel()) + slog.SetDefault(log) + + if err := run(cfg, log); err != nil { + log.Error("shutdown with error", slog.Any("error", err)) + shutdownCtx, cancel := context.WithTimeout(context.Background(), 3*time.Second) + _ = shutdown(shutdownCtx) + cancel() + os.Exit(1) + } + + shutdownCtx, cancel := context.WithTimeout(context.Background(), 3*time.Second) + defer cancel() + if err := shutdown(shutdownCtx); err != nil { + log.Warn("telemetry shutdown failed", slog.Any("error", err)) + } +} + +func run(cfg config.Config, log *slog.Logger) error { + if cfg.Broker.URL == "" { + return errors.New("BROKER_URL is required for worker") + } + + ctx, stop := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM) + defer stop() + + store, err := postgres.New(ctx, cfg.Postgres, time.Duration(cfg.Idempotency.TTLSeconds)*time.Second, postgres.WithQueryTracer(telemetry.NewPGXTracer())) + if err != nil { + return fmt.Errorf("connect database: %w", err) + } + defer store.Close() + + if err := telemetry.RegisterDBPool(store.PoolStats); err != nil { + log.Warn("register db pool metrics", slog.Any("error", err)) + } + if err := telemetry.RegisterProcessMetrics(); err != nil { + log.Warn("register process metrics", slog.Any("error", err)) + } + + objectStoreConcrete, err := objectstore.New(objectstore.Config{ + Endpoint: cfg.S3.Endpoint, + PublicEndpoint: cfg.S3.PublicEndpoint, + Region: cfg.S3.Region, + Bucket: cfg.S3.Bucket, + AccessKeyID: cfg.S3.AccessKeyID, + SecretAccessKey: cfg.S3.SecretAccessKey, + UsePathStyle: cfg.S3.UsePathStyle, + Timeout: cfg.S3.Timeout, + }) + if err != nil { + return fmt.Errorf("connect object store: %w", err) + } + + objectStore := telemetry.WrapStore(objectStoreConcrete) + + workerInstance := worker.New(store.Pipeline(), objectStore, worker.Config{ + Concurrency: cfg.Worker.Concurrency, + LeaseTTL: cfg.Processing.LeaseTTL, + Heartbeat: cfg.Processing.Heartbeat, + JobTimeout: cfg.Processing.JobTimeout, + RetryBase: cfg.Processing.RetryBase, + RetryCap: cfg.Processing.RetryCap, + MaxUploadBytes: cfg.S3.MaxUploadBytes, + MaxImagePixels: cfg.S3.MaxImagePixels, + }, log) + + if err := telemetry.RegisterWorkerMetrics(workerInstance.Busy, int64(cfg.Worker.Concurrency)); err != nil { + log.Warn("register worker metrics", slog.Any("error", err)) + } + + server := healthServer(cfg.Worker.HealthAddr, store, objectStore, workerInstance) + + var serverWait sync.WaitGroup + serverWait.Add(1) + + go func() { + defer serverWait.Done() + + if err := server.ListenAndServe(); err != nil && err != http.ErrServerClosed { + log.Error("health server failed", slog.Any("error", err)) + } + }() + + runCtx, cancelRun := context.WithCancel(ctx) + defer cancelRun() + + consumerDone := make(chan struct{}) + + go func() { + defer close(consumerDone) + + consumeWithReconnect(runCtx, cfg, workerInstance, log) + }() + + <-ctx.Done() + cancelRun() + <-consumerDone + + shutdownCtx, cancel := context.WithTimeout(context.Background(), cfg.Worker.ShutdownTimeout) + defer cancel() + + _ = server.Shutdown(shutdownCtx) + serverWait.Wait() + + return nil +} + +func consumeWithReconnect( + ctx context.Context, + cfg config.Config, + workerInstance *worker.Worker, + log *slog.Logger, +) { + for ctx.Err() == nil { + client, err := broker.Dial(brokerConfig(cfg)) + if err != nil { + log.WarnContext(ctx, "broker dial failed, retrying", slog.Any("error", err)) + + if !sleepCtx(ctx, 2*time.Second) { + return + } + + continue + } + + err = workerInstance.Run(ctx, client) + _ = client.Close() + + if ctx.Err() != nil { + return + } + + if err != nil { + log.WarnContext(ctx, "consumer stopped, reconnecting", slog.Any("error", err)) + } + + if !sleepCtx(ctx, 2*time.Second) { + return + } + } +} + +func sleepCtx(ctx context.Context, d time.Duration) bool { + timer := time.NewTimer(d) + defer timer.Stop() + + select { + case <-ctx.Done(): + return false + case <-timer.C: + return true + } +} + +func brokerConfig(cfg config.Config) broker.Config { + return broker.Config{ + URL: cfg.Broker.URL, + Exchange: cfg.Broker.Exchange, + DLX: cfg.Broker.DLX, + Queue: cfg.Broker.Queue, + DLQ: cfg.Broker.DLQ, + ConnectTimeout: cfg.Broker.ConnectTimeout, + ConfirmTimeout: cfg.Broker.ConfirmTimeout, + Heartbeat: cfg.Broker.Heartbeat, + Prefetch: cfg.Worker.Prefetch, + } +} + +func healthServer( + addr string, + store *postgres.Store, + objectStore objectstore.Store, + workerInstance *worker.Worker, +) *http.Server { + mux := http.NewServeMux() + + mux.HandleFunc("/health/live", func(w http.ResponseWriter, _ *http.Request) { + writeHealth(w, http.StatusOK, map[string]any{"status": "ok"}) + }) + + mux.HandleFunc("/health/ready", func(w http.ResponseWriter, r *http.Request) { + ctx, cancel := context.WithTimeout(r.Context(), 5*time.Second) + defer cancel() + + if err := store.Ping(ctx); err != nil { + writeHealth(w, http.StatusServiceUnavailable, map[string]any{"status": "unavailable"}) + + return + } + + if err := objectStore.Ping(ctx); err != nil { + writeHealth(w, http.StatusServiceUnavailable, map[string]any{"status": "unavailable"}) + + return + } + + running, connected := workerInstance.Ready() + if !running || !connected { + writeHealth(w, http.StatusServiceUnavailable, map[string]any{"status": "unavailable"}) + + return + } + + writeHealth(w, http.StatusOK, map[string]any{"status": "ok"}) + }) + + return &http.Server{ + Addr: addr, + Handler: mux, + ReadHeaderTimeout: 5 * time.Second, + } +} + +func writeHealth(w http.ResponseWriter, status int, body map[string]any) { + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(status) + _ = json.NewEncoder(w).Encode(body) +} diff --git a/compose.yaml b/compose.yaml new file mode 100644 index 0000000..391ecf6 --- /dev/null +++ b/compose.yaml @@ -0,0 +1,631 @@ +# Lab6 stand (lab5 base + OTel profile): API replicas behind HAProxy, PostgreSQL, Redis, SeaweedFS S3, +# a durable RabbitMQ broker, one outbox relay and a separate image worker. +# +# cp -n .env.example .env +# docker compose --env-file .env up -d --build +# curl http://localhost:8080/health/ready +# +# Only the load balancer is published (127.0.0.1). Stores and API replicas are +# reachable from the host via `docker compose exec` / `docker compose logs`. +# No container_name anywhere: replica hostnames stay the short container IDs, +# which the application reports back as X-Instance-Id. +name: mtusi-messenger-lab6 + +# The image is built once by the api service. migrate and s3-init only consume +# it; duplicating `build` here makes Compose compile the same Go tree in parallel +# and OOMs Docker Desktop's default VM. +x-app: &app + image: mtusi-messenger:lab6 + logging: + driver: json-file + options: + max-size: "10m" + max-file: "3" + +services: + postgres: + image: postgres:18-alpine@sha256:77f585114c32fbca283dc835b0596f4e52b51b4c6662d7810b2f4084f60a1873 + + logging: + driver: json-file + options: + max-size: "10m" + max-file: "3" + environment: + POSTGRES_USER: ${POSTGRES_USER:-messenger} + POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-messenger} + POSTGRES_DB: ${POSTGRES_DB:-messenger} + volumes: + - postgres18-data:/var/lib/postgresql + healthcheck: + test: ["CMD-SHELL", "pg_isready -U $${POSTGRES_USER} -d $${POSTGRES_DB}"] + interval: 5s + timeout: 5s + retries: 10 + start_period: 5s + deploy: + resources: + limits: + # Saturation point of the stand (see REPORT.md, track 1): the database + # runs at its quota while API replicas idle. Raise this knob to give the + # shared dependency more of the host CPU. + cpus: "${POSTGRES_CPU_LIMIT:-0.50}" + memory: ${POSTGRES_MEM_LIMIT:-192M} + restart: unless-stopped + + redis: + image: redis:7.4-alpine@sha256:858f009f9709ce576febc734aa78b8f6d624b82571f9ddb6bda4377c833b3499 + + logging: + driver: json-file + options: + max-size: "10m" + max-file: "3" + command: + - redis-server + - --appendonly + - "yes" + - --appendfsync + - everysec + - --save + - "60" + - "1" + volumes: + - redis7-data:/data + healthcheck: + test: ["CMD", "redis-cli", "ping"] + interval: 5s + timeout: 3s + retries: 10 + start_period: 3s + deploy: + resources: + limits: + cpus: "0.25" + memory: 96M + restart: unless-stopped + + # Private S3-compatible object store. Only the S3 API is published, on + # loopback, so the presigned-upload track and evidence can reach it from the + # host. master/volume/filer ports stay inside the compose network. + seaweedfs: + image: chrislusf/seaweedfs:3.80@sha256:1055999e08eed1789b0ae45d235126e4495e23d3fb9d6396293fd42539b1ae6a + + logging: + driver: json-file + options: + max-size: "10m" + max-file: "3" + command: + - server + - -s3 + - -s3.config=/etc/seaweedfs/s3.json + - -dir=/data + - -master.volumeSizeLimitMB=64 + volumes: + - ./infra/s3/s3.json:/etc/seaweedfs/s3.json:ro + - seaweedfs-data:/data + environment: + # Keep the Go runtime below the container limit under concurrent PUTs. + GOGC: "50" + GOMEMLIMIT: "512MiB" + ports: + - "127.0.0.1:${S3_PORT:-8333}:8333" + healthcheck: + test: ["CMD-SHELL", "wget -q -O /dev/null http://127.0.0.1:8333/healthz || exit 1"] + interval: 5s + timeout: 3s + retries: 20 + start_period: 60s + deploy: + resources: + limits: + cpus: "1.00" + memory: 640M + restart: unless-stopped + + + # Durable job transport. Quorum queues, publisher confirms and a DLQ live in + # the broker; PostgreSQL's outbox remains the source of truth for intent. + broker: + image: rabbitmq:4.3.7-management-alpine@sha256:1528a88eebf2bc4d0ab7e9d5d9bc542e9bdf5e1b105e65848fcf8de5c2186528 + + logging: + driver: json-file + options: + max-size: "10m" + max-file: "3" + hostname: broker + networks: [default, observability] + environment: + RABBITMQ_DEFAULT_USER: ${BROKER_USER:-messenger} + RABBITMQ_DEFAULT_PASS: ${BROKER_PASSWORD:-messenger} + RABBITMQ_DEFAULT_VHOST: ${BROKER_VHOST:-messenger} + volumes: + - rabbitmq-data:/var/lib/rabbitmq + - ./infra/rabbitmq/rabbitmq.conf:/etc/rabbitmq/rabbitmq.conf:ro + ports: + # Management UI only on loopback, for operator evidence. AMQP stays internal. + - "127.0.0.1:${BROKER_MANAGEMENT_PORT:-15672}:15672" + healthcheck: + test: ["CMD", "rabbitmq-diagnostics", "-q", "ping"] + interval: 10s + timeout: 5s + retries: 12 + start_period: 30s + deploy: + resources: + limits: + cpus: "${BROKER_CPU_LIMIT:-0.50}" + memory: ${BROKER_MEM_LIMIT:-384M} + stop_grace_period: 30s + restart: unless-stopped + + # One-shot, idempotent bucket bootstrap and identity probe. + s3-init: + <<: *app + entrypoint: ["/usr/local/bin/s3init"] + environment: + S3_ENDPOINT: http://seaweedfs:8333 + S3_REGION: ${S3_REGION:-us-east-1} + S3_BUCKET: ${S3_BUCKET:-messenger-attachments} + S3_ADMIN_ACCESS_KEY: ${S3_ADMIN_ACCESS_KEY:-lab4admin} + S3_ADMIN_SECRET_ACCESS_KEY: ${S3_ADMIN_SECRET_ACCESS_KEY:-lab4admin-secret} + S3_ACCESS_KEY_ID: ${S3_ACCESS_KEY_ID:-lab4app} + S3_SECRET_ACCESS_KEY: ${S3_SECRET_ACCESS_KEY:-lab4app-secret} + depends_on: + seaweedfs: + condition: service_healthy + healthcheck: + disable: true + restart: "no" + + # One-shot schema bootstrap; runs once to completion before any API replica. + migrate: + <<: *app + entrypoint: ["/usr/local/bin/migrate"] + command: ["up"] + environment: + APP_CONFIG: /etc/messenger/dev/config.yaml + POSTGRES_HOST: postgres + POSTGRES_PORT: "5432" + POSTGRES_DATABASE: ${POSTGRES_DB:-messenger} + POSTGRES_USER: ${POSTGRES_USER:-messenger} + POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-messenger} + POSTGRES_SSL_MODE: disable + depends_on: + postgres: + condition: service_healthy + deploy: + resources: + limits: + cpus: "0.50" + memory: 256M + # One-shot: healthcheck из образа (проверка /health/live) для него бессмыслен. + healthcheck: + disable: true + restart: "no" + + api: + <<: *app + build: + context: . + dockerfile: Dockerfile + args: + VERSION: ${VERSION:-dev} + # Общий сетевой alias: LB резолвит одно имя в адреса всех реплик, поэтому + # масштабирование и замена контейнеров не зависят от их номеров/ID. + networks: + default: + aliases: + - api-replica + env_file: + - path: .env + required: false + # Explicit values win over localhost defaults coming from .env (see .env.example). + environment: + APP_CONFIG: /etc/messenger/dev/config.yaml + OTEL_SERVICE_NAME: messenger-api + OTEL_EXPORTER_OTLP_ENDPOINT: ${OTEL_EXPORTER_OTLP_ENDPOINT:-http://otel-collector:4318} + OTEL_EXPORTER_OTLP_PROTOCOL: http/protobuf + OTEL_RESOURCE_ATTRIBUTES: deployment.environment.name=lab + OTEL_METRIC_EXPORT_INTERVAL: ${OTEL_METRIC_EXPORT_INTERVAL:-15000} + TELEMETRY_ENABLED: ${TELEMETRY_ENABLED:-1} + GOMEMLIMIT: ${API_GOMEMLIMIT:-192MiB} + POSTGRES_HOST: postgres + POSTGRES_PORT: "5432" + POSTGRES_DATABASE: ${POSTGRES_DB:-messenger} + POSTGRES_USER: ${POSTGRES_USER:-messenger} + POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-messenger} + POSTGRES_SSL_MODE: disable + REDIS_ENABLED: "true" + REDIS_HOST: redis + REDIS_PORT: "6379" + CACHE_ENABLED: "true" + S3_ENDPOINT: http://seaweedfs:8333 + S3_PUBLIC_ENDPOINT: ${S3_PUBLIC_ENDPOINT:-http://127.0.0.1:8333} + S3_REGION: ${S3_REGION:-us-east-1} + S3_BUCKET: ${S3_BUCKET:-messenger-attachments} + S3_ACCESS_KEY_ID: ${S3_ACCESS_KEY_ID:-lab4app} + S3_SECRET_ACCESS_KEY: ${S3_SECRET_ACCESS_KEY:-lab4app-secret} + S3_USE_PATH_STYLE: "true" + S3_PRESIGN_TTL: ${S3_PRESIGN_TTL:-5m} + S3_SWEEP_INTERVAL: ${S3_SWEEP_INTERVAL:-1m} + S3_SWEEP_GRACE: ${S3_SWEEP_GRACE:-10m} + MAX_UPLOAD_BYTES: ${MAX_UPLOAD_BYTES:-10485760} + MAX_IMAGE_PIXELS: ${MAX_IMAGE_PIXELS:-40000000} + PROCESSING_PIPELINE_VERSION: ${PROCESSING_PIPELINE_VERSION:-1} + PROCESSING_MAX_ATTEMPTS: ${PROCESSING_MAX_ATTEMPTS:-5} + PROCESSING_JOB_TIMEOUT: ${PROCESSING_JOB_TIMEOUT:-120s} + PROCESSING_LEASE_TTL: ${PROCESSING_LEASE_TTL:-180s} + PROCESSING_HEARTBEAT: ${PROCESSING_HEARTBEAT:-30s} + PROCESSING_RETRY_BASE: ${PROCESSING_RETRY_BASE:-2s} + PROCESSING_RETRY_CAP: ${PROCESSING_RETRY_CAP:-60s} + STAGING_ORPHAN_GRACE: ${STAGING_ORPHAN_GRACE:-1h} + STAGING_FAILED_RETENTION: ${STAGING_FAILED_RETENTION:-168h} + ADMISSION_MAX_PENDING_PER_USER: ${ADMISSION_MAX_PENDING_PER_USER:-20} + ADMISSION_MAX_PENDING: ${ADMISSION_MAX_PENDING:-200} + ADMISSION_MAX_STAGED_BYTES: ${ADMISSION_MAX_STAGED_BYTES:-2147483648} + ADMISSION_MAX_CONCURRENT_UPLOADS: ${ADMISSION_MAX_CONCURRENT_UPLOADS:-8} + # Размер пула соединений ОДНОЙ реплики; общий расход = реплики × значение. + # Это один из общих ресурсов, который масштабирование расходует первым. + POSTGRES_MAX_CONNS: "${POSTGRES_MAX_CONNS:-10}" + deploy: + replicas: ${API_REPLICAS:-2} + resources: + limits: + cpus: "${API_CPU_LIMIT:-0.50}" + memory: ${API_MEM_LIMIT:-256M} + # The app drains on SIGTERM within SERVER_SHUTDOWN_TIMEOUT; keep the grace + # period above it so Docker does not SIGKILL an in-flight request. + stop_grace_period: 15s + depends_on: + postgres: + condition: service_healthy + redis: + condition: service_healthy + migrate: + condition: service_completed_successfully + s3-init: + condition: service_completed_successfully + healthcheck: + test: ["CMD", "wget", "-q", "-O", "/dev/null", "http://127.0.0.1:8080/health/ready"] + interval: 10s + # Готовность проверяет PostgreSQL (критичную зависимость; кэш деградирует + # безопасно): под насыщающей нагрузкой ответ может подойти к секундам, и + # слишком строгий таймаут помечает занятую, но работающую реплику как + # unhealthy. + timeout: 5s + retries: 6 + start_period: 5s + restart: unless-stopped + + + # Separate worker process. It is intentionally not published and can be + # stopped/scaled independently from the API; stopping it must not stop 202. + worker: + <<: *app + entrypoint: ["/usr/local/bin/worker"] + env_file: + - path: .env + required: false + environment: + APP_CONFIG: /etc/messenger/dev/config.yaml + OTEL_SERVICE_NAME: messenger-worker + OTEL_EXPORTER_OTLP_ENDPOINT: ${OTEL_EXPORTER_OTLP_ENDPOINT:-http://otel-collector:4318} + OTEL_EXPORTER_OTLP_PROTOCOL: http/protobuf + OTEL_RESOURCE_ATTRIBUTES: deployment.environment.name=lab + OTEL_METRIC_EXPORT_INTERVAL: ${OTEL_METRIC_EXPORT_INTERVAL:-15000} + TELEMETRY_ENABLED: ${TELEMETRY_ENABLED:-1} + GOMEMLIMIT: ${WORKER_GOMEMLIMIT:-768MiB} + POSTGRES_HOST: postgres + POSTGRES_PORT: "5432" + POSTGRES_DATABASE: ${POSTGRES_DB:-messenger} + POSTGRES_USER: ${POSTGRES_USER:-messenger} + POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-messenger} + POSTGRES_SSL_MODE: disable + S3_ENDPOINT: http://seaweedfs:8333 + S3_PUBLIC_ENDPOINT: ${S3_PUBLIC_ENDPOINT:-http://127.0.0.1:8333} + S3_REGION: ${S3_REGION:-us-east-1} + S3_BUCKET: ${S3_BUCKET:-messenger-attachments} + S3_ACCESS_KEY_ID: ${S3_ACCESS_KEY_ID:-lab4app} + S3_SECRET_ACCESS_KEY: ${S3_SECRET_ACCESS_KEY:-lab4app-secret} + S3_USE_PATH_STYLE: "true" + MAX_UPLOAD_BYTES: ${MAX_UPLOAD_BYTES:-10485760} + MAX_IMAGE_PIXELS: ${MAX_IMAGE_PIXELS:-40000000} + BROKER_URL: ${BROKER_URL:-amqp://messenger:messenger@broker:5672/messenger} + WORKER_CONCURRENCY: ${WORKER_CONCURRENCY:-1} + WORKER_PREFETCH: ${WORKER_PREFETCH:-1} + WORKER_SHUTDOWN_TIMEOUT: ${WORKER_SHUTDOWN_TIMEOUT:-30s} + WORKER_HEALTH_ADDR: ":8081" + FAULTS_ENABLED: ${FAULTS_ENABLED:-0} + FAULT_TARGET_JOB: ${FAULT_TARGET_JOB:-} + FAULT_WORKER_AFTER_CLAIM: ${FAULT_WORKER_AFTER_CLAIM:-} + FAULT_WORKER_AFTER_FIRST_VARIANT: ${FAULT_WORKER_AFTER_FIRST_VARIANT:-} + FAULT_WORKER_AFTER_PUT: ${FAULT_WORKER_AFTER_PUT:-} + FAULT_WORKER_AFTER_COMMIT: ${FAULT_WORKER_AFTER_COMMIT:-} + FAULT_WORKER_FAIL: ${FAULT_WORKER_FAIL:-} + FAULT_WORKER_SLEEP_AFTER_CLAIM: ${FAULT_WORKER_SLEEP_AFTER_CLAIM:-} + PROCESSING_PIPELINE_VERSION: ${PROCESSING_PIPELINE_VERSION:-1} + PROCESSING_MAX_ATTEMPTS: ${PROCESSING_MAX_ATTEMPTS:-5} + PROCESSING_JOB_TIMEOUT: ${PROCESSING_JOB_TIMEOUT:-120s} + PROCESSING_LEASE_TTL: ${PROCESSING_LEASE_TTL:-180s} + PROCESSING_HEARTBEAT: ${PROCESSING_HEARTBEAT:-30s} + PROCESSING_RETRY_BASE: ${PROCESSING_RETRY_BASE:-2s} + PROCESSING_RETRY_CAP: ${PROCESSING_RETRY_CAP:-60s} + ports: + - "127.0.0.1:${WORKER_HEALTH_PORT:-8081}:8081" + depends_on: + postgres: + condition: service_healthy + migrate: + condition: service_completed_successfully + s3-init: + condition: service_completed_successfully + broker: + condition: service_healthy + deploy: + resources: + limits: + cpus: "${WORKER_CPU_LIMIT:-1.00}" + memory: ${WORKER_MEM_LIMIT:-1G} + stop_grace_period: 40s + healthcheck: + test: ["CMD", "wget", "-q", "-O", "/dev/null", "http://127.0.0.1:8081/health/ready"] + interval: 10s + timeout: 5s + retries: 12 + start_period: 10s + restart: unless-stopped + + # Outbox publisher + lease reaper. One replica: duplicate relays are safe but + # a single owner keeps the evidence and the claim reaper simple. + relay: + <<: *app + entrypoint: ["/usr/local/bin/relay"] + env_file: + - path: .env + required: false + environment: + APP_CONFIG: /etc/messenger/dev/config.yaml + OTEL_SERVICE_NAME: messenger-relay + OTEL_EXPORTER_OTLP_ENDPOINT: ${OTEL_EXPORTER_OTLP_ENDPOINT:-http://otel-collector:4318} + OTEL_EXPORTER_OTLP_PROTOCOL: http/protobuf + OTEL_RESOURCE_ATTRIBUTES: deployment.environment.name=lab + OTEL_METRIC_EXPORT_INTERVAL: ${OTEL_METRIC_EXPORT_INTERVAL:-15000} + TELEMETRY_ENABLED: ${TELEMETRY_ENABLED:-1} + GOMEMLIMIT: ${RELAY_GOMEMLIMIT:-96MiB} + POSTGRES_HOST: postgres + POSTGRES_PORT: "5432" + POSTGRES_DATABASE: ${POSTGRES_DB:-messenger} + POSTGRES_USER: ${POSTGRES_USER:-messenger} + POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-messenger} + POSTGRES_SSL_MODE: disable + BROKER_URL: ${BROKER_URL:-amqp://messenger:messenger@broker:5672/messenger} + BROKER_QUEUE: ${BROKER_QUEUE:-attachment.process.v1} + BROKER_DLQ: ${BROKER_DLQ:-attachment.process.dead} + OUTBOX_POLL_INTERVAL: ${OUTBOX_POLL_INTERVAL:-1s} + OUTBOX_CLAIM_TTL: ${OUTBOX_CLAIM_TTL:-30s} + OUTBOX_BATCH: ${OUTBOX_BATCH:-20} + OUTBOX_REAPER_INTERVAL: ${OUTBOX_REAPER_INTERVAL:-15s} + OUTBOX_RECONCILE_AFTER: ${OUTBOX_RECONCILE_AFTER:-5m} + OUTBOX_RETENTION: ${OUTBOX_RETENTION:-168h} + RELAY_HEALTH_ADDR: ":8082" + FAULTS_ENABLED: ${FAULTS_ENABLED:-0} + FAULT_TARGET_JOB: ${FAULT_TARGET_JOB:-} + FAULT_OUTBOX_AFTER_COMMIT: ${FAULT_OUTBOX_AFTER_COMMIT:-} + ports: + - "127.0.0.1:${RELAY_HEALTH_PORT:-8082}:8082" + depends_on: + postgres: + condition: service_healthy + migrate: + condition: service_completed_successfully + broker: + condition: service_healthy + deploy: + replicas: 1 + resources: + limits: + cpus: "${RELAY_CPU_LIMIT:-0.25}" + memory: ${RELAY_MEM_LIMIT:-128M} + healthcheck: + test: ["CMD", "wget", "-q", "-O", "/dev/null", "http://127.0.0.1:8082/health/ready"] + interval: 10s + timeout: 5s + retries: 12 + start_period: 10s + restart: unless-stopped + + # Public entry point. Active /health/ready probes remove a not-ready replica from + # rotation entirely; infra/lb/haproxy.cfg holds the upstream, checks and retries. + lb: + image: haproxy:3.2-alpine@sha256:254e6370f01cd654e0744edf607c67f33777c1b6a9dc0d4b28bcba7171460122 + + logging: + driver: json-file + options: + max-size: "10m" + max-file: "3" + networks: [default, observability] + volumes: + - ./infra/lb/haproxy.cfg:/usr/local/etc/haproxy/haproxy.cfg:ro + ports: + - "127.0.0.1:${SERVER_PORT:-8080}:80" + # Operator-only stats page on loopback: shows which replica is UP/DOWN and why. + - "127.0.0.1:${LB_STATS_PORT:-8404}:8404" + depends_on: + api: + condition: service_healthy + deploy: + resources: + limits: + cpus: "${LB_CPU_LIMIT:-0.25}" + memory: 48M + restart: unless-stopped + + # --- Lab6 telemetry profile ------------------------------------------------ + # Start with: docker compose --profile telemetry up -d --build + otel-collector: + # Manifest-list digest: Docker selects the architecture automatically. + # Override OTEL_COLLECTOR_IMAGE only for a registry mirror. + image: ${OTEL_COLLECTOR_IMAGE:-otel/opentelemetry-collector-contrib:0.164.0@sha256:340c9ca6a36617084c6661bdc4f0fe92b7cda5a805d61673ec8db375fddc522b} + logging: + driver: json-file + options: + max-size: "10m" + max-file: "3" + environment: + GOMEMLIMIT: 140MiB + profiles: [telemetry] + command: ["--config=/etc/otel/collector.yaml"] + volumes: + - ./infra/otel/collector.yaml:/etc/otel/collector.yaml:ro + networks: [default, observability] + deploy: + resources: + limits: + cpus: "${OTEL_COLLECTOR_CPU_LIMIT:-0.25}" + memory: ${OTEL_COLLECTOR_MEM_LIMIT:-192M} + restart: unless-stopped + + prometheus: + image: ${PROMETHEUS_IMAGE:-prom/prometheus:v3.15.1@sha256:fa3302279710be2f21a8301ec17a8b4f2301fd829bd113839b3b6b02b6f191a2} + logging: + driver: json-file + options: + max-size: "10m" + max-file: "3" + environment: + GOMEMLIMIT: 256MiB + profiles: [telemetry] + command: + - --config.file=/etc/prometheus/prometheus.yml + - --storage.tsdb.path=/prometheus + - --storage.tsdb.retention.time=10d + - --storage.tsdb.retention.size=2GB + - --web.enable-lifecycle + volumes: + - ./infra/prometheus:/etc/prometheus:ro + - prometheus-data:/prometheus + ports: + - "127.0.0.1:${PROMETHEUS_PORT:-9090}:9090" + networks: [observability] + deploy: + resources: + limits: + cpus: "${PROMETHEUS_CPU_LIMIT:-0.50}" + memory: ${PROMETHEUS_MEM_LIMIT:-320M} + healthcheck: + test: ["CMD-SHELL", "wget -qO- http://127.0.0.1:9090/-/healthy >/dev/null || exit 1"] + interval: 10s + timeout: 5s + retries: 12 + start_period: 10s + restart: unless-stopped + + loki: + image: ${LOKI_IMAGE:-grafana/loki:3.6.4@sha256:be31579ac047e9f78b81e48f3b69d3af709e7299b431d5aa78bcda43382f9511} + logging: + driver: json-file + options: + max-size: "10m" + max-file: "3" + environment: + GOMEMLIMIT: 256MiB + profiles: [telemetry] + command: ["-config.file=/etc/loki/loki.yaml"] + volumes: + - ./infra/loki/loki.yaml:/etc/loki/loki.yaml:ro + - loki-data:/loki + ports: + - "127.0.0.1:${LOKI_PORT:-3100}:3100" + networks: [observability] + deploy: + resources: + limits: + cpus: "${LOKI_CPU_LIMIT:-0.50}" + memory: ${LOKI_MEM_LIMIT:-320M} + # Distroless image: no /bin/sh or wget. Readiness is checked through + # Prometheus `up` and the /ready endpoint from the host. + healthcheck: + disable: true + restart: unless-stopped + + tempo: + image: ${TEMPO_IMAGE:-grafana/tempo:2.9.0@sha256:65a5789759435f1ef696f1953258b9bbdb18eb571d5ce711ff812d2e128288a4} + logging: + driver: json-file + options: + max-size: "10m" + max-file: "3" + environment: + GOMEMLIMIT: 640MiB + profiles: [telemetry] + command: ["-config.file=/etc/tempo/tempo.yaml"] + volumes: + - ./infra/tempo/tempo.yaml:/etc/tempo/tempo.yaml:ro + - tempo-data:/var/tempo + ports: + - "127.0.0.1:${TEMPO_PORT:-3200}:3200" + networks: [observability] + deploy: + resources: + limits: + cpus: "${TEMPO_CPU_LIMIT:-0.25}" + memory: ${TEMPO_MEM_LIMIT:-768M} + # Distroless image: no /bin/sh or wget. Readiness is checked through + # Prometheus `up` and the /ready endpoint from the host. + healthcheck: + disable: true + restart: unless-stopped + + grafana: + image: ${GRAFANA_IMAGE:-grafana/grafana:13.2.5@sha256:9f7aa1e1e3246aade5792d35a738049f7f32f89cd51d1956cf426a4e86268a84} + logging: + driver: json-file + options: + max-size: "10m" + max-file: "3" + profiles: [telemetry] + env_file: + - path: ./secrets/grafana.env + required: true + environment: + GOMEMLIMIT: 256MiB + GF_AUTH_ANONYMOUS_ENABLED: "false" + GF_USERS_ALLOW_SIGN_UP: "false" + volumes: + - ./infra/grafana/provisioning:/etc/grafana/provisioning:ro + - ./infra/grafana/dashboards:/var/lib/grafana/dashboards:ro + - grafana-data:/var/lib/grafana + ports: + - "127.0.0.1:${GRAFANA_PORT:-3000}:3000" + networks: [observability] + deploy: + resources: + limits: + cpus: "${GRAFANA_CPU_LIMIT:-0.25}" + memory: ${GRAFANA_MEM_LIMIT:-512M} + healthcheck: + test: ["CMD-SHELL", "wget -qO- http://127.0.0.1:3000/api/health >/dev/null || exit 1"] + interval: 10s + timeout: 5s + retries: 12 + start_period: 10s + restart: unless-stopped + +networks: + default: + observability: + + +volumes: + postgres18-data: + redis7-data: + seaweedfs-data: + rabbitmq-data: + prometheus-data: + loki-data: + tempo-data: + grafana-data: diff --git a/config/dev/config.yaml b/config/dev/config.yaml new file mode 100644 index 0000000..5e6cd56 --- /dev/null +++ b/config/dev/config.yaml @@ -0,0 +1,54 @@ +env: dev + +server: + host: 0.0.0.0 + port: 8080 + read_header_timeout: 10s + shutdown_timeout: 10s + # Предел размера тела запроса; JSON API ЛР3 укладывается в сотни килобайт, + # а загрузка вложений ЛР4 (до 10 MiB) поднимает это значение явно. + max_body_bytes: 262144 + +log: + level: info + format: json + +postgres: + host: localhost + port: 5432 + database: messenger + user: messenger + # Dev default for a local run without environment overrides; POSTGRES_PASSWORD wins. + password: messenger + ssl_mode: disable + max_conns: 10 + min_conns: 1 + max_conn_lifetime: 1h + max_conn_idle_time: 30m + connect_timeout: 5s + query_timeout: 5s + +redis: + enabled: true + host: localhost + port: 6379 + db: 0 + # -1 disables go-redis retries; 0 keeps the library default (3 retries). + max_retries: -1 + dial_timeout: 300ms + read_timeout: 200ms + write_timeout: 200ms + pool_size: 10 + +cache: + enabled: true + chat_list_ttl: 5m + lock_ttl: 10s + lock_wait_timeout: 2s + +session: + ttl_seconds: 3600 + +# Retention of a message Idempotency-Key; contract 1.3.0 requires ≥ 24 h. +idempotency: + ttl_seconds: 86400 diff --git a/docker-compose.local.yaml b/docker-compose.local.yaml new file mode 100644 index 0000000..06f5c55 --- /dev/null +++ b/docker-compose.local.yaml @@ -0,0 +1,283 @@ +name: mtusi-messenger-lab6 + +# Built once by the api service; migrate and s3-init consume the same image. +x-app: &app + image: mtusi-messenger:lab6 + +services: + postgres: + image: postgres:18-alpine@sha256:77f585114c32fbca283dc835b0596f4e52b51b4c6662d7810b2f4084f60a1873 + environment: + POSTGRES_USER: ${POSTGRES_USER:-messenger} + POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-messenger} + POSTGRES_DB: ${POSTGRES_DB:-messenger} + ports: + - "127.0.0.1:${POSTGRES_PORT:-5432}:5432" + volumes: + - postgres18-data:/var/lib/postgresql + healthcheck: + test: ["CMD-SHELL", "pg_isready -U $${POSTGRES_USER} -d $${POSTGRES_DB}"] + interval: 5s + timeout: 5s + retries: 10 + start_period: 5s + restart: unless-stopped + redis: + image: redis:7.4-alpine@sha256:858f009f9709ce576febc734aa78b8f6d624b82571f9ddb6bda4377c833b3499 + command: + - redis-server + - --appendonly + - "yes" + - --appendfsync + - everysec + - --save + - "60" + - "1" + ports: + - "127.0.0.1:${REDIS_PORT:-6379}:6379" + volumes: + - redis7-data:/data + healthcheck: + test: ["CMD", "redis-cli", "ping"] + interval: 5s + timeout: 3s + retries: 10 + start_period: 3s + restart: unless-stopped + seaweedfs: + image: chrislusf/seaweedfs:3.80@sha256:1055999e08eed1789b0ae45d235126e4495e23d3fb9d6396293fd42539b1ae6a + command: + - server + - -s3 + - -s3.config=/etc/seaweedfs/s3.json + - -dir=/data + - -master.volumeSizeLimitMB=64 + volumes: + - ./infra/s3/s3.json:/etc/seaweedfs/s3.json:ro + - seaweedfs-data:/data + ports: + - "127.0.0.1:${S3_PORT:-8333}:8333" + healthcheck: + test: ["CMD-SHELL", "wget -q -O /dev/null http://127.0.0.1:8333/healthz || exit 1"] + interval: 5s + timeout: 3s + retries: 20 + start_period: 60s + restart: unless-stopped + + + broker: + image: rabbitmq:4.3.7-management-alpine@sha256:1528a88eebf2bc4d0ab7e9d5d9bc542e9bdf5e1b105e65848fcf8de5c2186528 + hostname: broker + environment: + RABBITMQ_DEFAULT_USER: ${BROKER_USER:-messenger} + RABBITMQ_DEFAULT_PASS: ${BROKER_PASSWORD:-messenger} + RABBITMQ_DEFAULT_VHOST: ${BROKER_VHOST:-messenger} + volumes: + - rabbitmq-data:/var/lib/rabbitmq + ports: + - "127.0.0.1:${BROKER_MANAGEMENT_PORT:-15672}:15672" + healthcheck: + test: ["CMD", "rabbitmq-diagnostics", "-q", "ping"] + interval: 10s + timeout: 5s + retries: 12 + start_period: 30s + restart: unless-stopped + + s3-init: + <<: *app + entrypoint: ["/usr/local/bin/s3init"] + environment: + S3_ENDPOINT: http://seaweedfs:8333 + S3_REGION: ${S3_REGION:-us-east-1} + S3_BUCKET: ${S3_BUCKET:-messenger-attachments} + S3_ADMIN_ACCESS_KEY: ${S3_ADMIN_ACCESS_KEY:-lab4admin} + S3_ADMIN_SECRET_ACCESS_KEY: ${S3_ADMIN_SECRET_ACCESS_KEY:-lab4admin-secret} + S3_ACCESS_KEY_ID: ${S3_ACCESS_KEY_ID:-lab4app} + S3_SECRET_ACCESS_KEY: ${S3_SECRET_ACCESS_KEY:-lab4app-secret} + depends_on: + seaweedfs: + condition: service_healthy + healthcheck: + disable: true + restart: "no" + + migrate: + <<: *app + entrypoint: ["/usr/local/bin/migrate"] + command: ["up"] + environment: + APP_CONFIG: /etc/messenger/dev/config.yaml + POSTGRES_HOST: postgres + POSTGRES_PORT: "5432" + POSTGRES_DATABASE: ${POSTGRES_DB:-messenger} + POSTGRES_USER: ${POSTGRES_USER:-messenger} + POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-messenger} + POSTGRES_SSL_MODE: disable + depends_on: + postgres: + condition: service_healthy + restart: "no" + + api: + <<: *app + build: + context: . + dockerfile: Dockerfile + env_file: + - path: .env + required: false + environment: + APP_CONFIG: /etc/messenger/dev/config.yaml + POSTGRES_HOST: postgres + POSTGRES_PORT: "5432" + POSTGRES_DATABASE: ${POSTGRES_DB:-messenger} + POSTGRES_USER: ${POSTGRES_USER:-messenger} + POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-messenger} + POSTGRES_SSL_MODE: disable + REDIS_ENABLED: "${REDIS_ENABLED:-true}" + REDIS_HOST: redis + REDIS_PORT: "6379" + CACHE_ENABLED: "${CACHE_ENABLED:-true}" + S3_ENDPOINT: http://seaweedfs:8333 + S3_PUBLIC_ENDPOINT: ${S3_PUBLIC_ENDPOINT:-http://127.0.0.1:8333} + S3_REGION: ${S3_REGION:-us-east-1} + S3_BUCKET: ${S3_BUCKET:-messenger-attachments} + S3_ACCESS_KEY_ID: ${S3_ACCESS_KEY_ID:-lab4app} + S3_SECRET_ACCESS_KEY: ${S3_SECRET_ACCESS_KEY:-lab4app-secret} + S3_USE_PATH_STYLE: "true" + MAX_UPLOAD_BYTES: ${MAX_UPLOAD_BYTES:-10485760} + MAX_IMAGE_PIXELS: ${MAX_IMAGE_PIXELS:-40000000} + PROCESSING_PIPELINE_VERSION: ${PROCESSING_PIPELINE_VERSION:-1} + PROCESSING_MAX_ATTEMPTS: ${PROCESSING_MAX_ATTEMPTS:-5} + PROCESSING_JOB_TIMEOUT: ${PROCESSING_JOB_TIMEOUT:-120s} + PROCESSING_LEASE_TTL: ${PROCESSING_LEASE_TTL:-180s} + PROCESSING_HEARTBEAT: ${PROCESSING_HEARTBEAT:-30s} + PROCESSING_RETRY_BASE: ${PROCESSING_RETRY_BASE:-2s} + PROCESSING_RETRY_CAP: ${PROCESSING_RETRY_CAP:-60s} + STAGING_ORPHAN_GRACE: ${STAGING_ORPHAN_GRACE:-1h} + STAGING_FAILED_RETENTION: ${STAGING_FAILED_RETENTION:-168h} + ADMISSION_MAX_PENDING_PER_USER: ${ADMISSION_MAX_PENDING_PER_USER:-20} + ADMISSION_MAX_PENDING: ${ADMISSION_MAX_PENDING:-200} + ADMISSION_MAX_STAGED_BYTES: ${ADMISSION_MAX_STAGED_BYTES:-2147483648} + ADMISSION_MAX_CONCURRENT_UPLOADS: ${ADMISSION_MAX_CONCURRENT_UPLOADS:-8} + ports: + - "127.0.0.1:${SERVER_PORT:-8080}:8080" + depends_on: + postgres: + condition: service_healthy + redis: + condition: service_healthy + migrate: + condition: service_completed_successfully + s3-init: + condition: service_completed_successfully + healthcheck: + test: ["CMD", "wget", "-q", "-O", "/dev/null", "http://127.0.0.1:8080/health/ready"] + interval: 10s + timeout: 3s + retries: 5 + start_period: 5s + restart: unless-stopped + + + worker: + <<: *app + entrypoint: ["/usr/local/bin/worker"] + env_file: + - path: .env + required: false + environment: + APP_CONFIG: /etc/messenger/dev/config.yaml + POSTGRES_HOST: postgres + POSTGRES_PORT: "5432" + POSTGRES_DATABASE: ${POSTGRES_DB:-messenger} + POSTGRES_USER: ${POSTGRES_USER:-messenger} + POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-messenger} + POSTGRES_SSL_MODE: disable + S3_ENDPOINT: http://seaweedfs:8333 + S3_PUBLIC_ENDPOINT: ${S3_PUBLIC_ENDPOINT:-http://127.0.0.1:8333} + S3_REGION: ${S3_REGION:-us-east-1} + S3_BUCKET: ${S3_BUCKET:-messenger-attachments} + S3_ACCESS_KEY_ID: ${S3_ACCESS_KEY_ID:-lab4app} + S3_SECRET_ACCESS_KEY: ${S3_SECRET_ACCESS_KEY:-lab4app-secret} + S3_USE_PATH_STYLE: "true" + MAX_UPLOAD_BYTES: ${MAX_UPLOAD_BYTES:-10485760} + MAX_IMAGE_PIXELS: ${MAX_IMAGE_PIXELS:-40000000} + BROKER_URL: ${BROKER_URL:-amqp://messenger:messenger@broker:5672/messenger} + WORKER_CONCURRENCY: ${WORKER_CONCURRENCY:-1} + WORKER_PREFETCH: ${WORKER_PREFETCH:-1} + WORKER_HEALTH_ADDR: ":8081" + FAULTS_ENABLED: ${FAULTS_ENABLED:-0} + FAULT_TARGET_JOB: ${FAULT_TARGET_JOB:-} + PROCESSING_PIPELINE_VERSION: ${PROCESSING_PIPELINE_VERSION:-1} + PROCESSING_MAX_ATTEMPTS: ${PROCESSING_MAX_ATTEMPTS:-5} + PROCESSING_JOB_TIMEOUT: ${PROCESSING_JOB_TIMEOUT:-120s} + PROCESSING_LEASE_TTL: ${PROCESSING_LEASE_TTL:-180s} + PROCESSING_HEARTBEAT: ${PROCESSING_HEARTBEAT:-30s} + PROCESSING_RETRY_BASE: ${PROCESSING_RETRY_BASE:-2s} + PROCESSING_RETRY_CAP: ${PROCESSING_RETRY_CAP:-60s} + ports: + - "127.0.0.1:${WORKER_HEALTH_PORT:-8081}:8081" + depends_on: + postgres: + condition: service_healthy + migrate: + condition: service_completed_successfully + s3-init: + condition: service_completed_successfully + broker: + condition: service_healthy + healthcheck: + test: ["CMD", "wget", "-q", "-O", "/dev/null", "http://127.0.0.1:8081/health/ready"] + interval: 10s + timeout: 5s + retries: 12 + start_period: 10s + restart: unless-stopped + + relay: + <<: *app + entrypoint: ["/usr/local/bin/relay"] + env_file: + - path: .env + required: false + environment: + APP_CONFIG: /etc/messenger/dev/config.yaml + POSTGRES_HOST: postgres + POSTGRES_PORT: "5432" + POSTGRES_DATABASE: ${POSTGRES_DB:-messenger} + POSTGRES_USER: ${POSTGRES_USER:-messenger} + POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-messenger} + POSTGRES_SSL_MODE: disable + BROKER_URL: ${BROKER_URL:-amqp://messenger:messenger@broker:5672/messenger} + RELAY_HEALTH_ADDR: ":8082" + FAULTS_ENABLED: ${FAULTS_ENABLED:-0} + FAULT_TARGET_JOB: ${FAULT_TARGET_JOB:-} + ports: + - "127.0.0.1:${RELAY_HEALTH_PORT:-8082}:8082" + depends_on: + postgres: + condition: service_healthy + migrate: + condition: service_completed_successfully + broker: + condition: service_healthy + healthcheck: + test: ["CMD", "wget", "-q", "-O", "/dev/null", "http://127.0.0.1:8082/health/ready"] + interval: 10s + timeout: 5s + retries: 12 + start_period: 10s + restart: unless-stopped + +volumes: + postgres18-data: + name: mtusi-messenger-lab6-postgres18-data + redis7-data: + name: mtusi-messenger-lab6-redis7-data + seaweedfs-data: + name: mtusi-messenger-lab6-seaweedfs-data + rabbitmq-data: + name: mtusi-messenger-lab6-rabbitmq-data diff --git a/evidence/arch.txt b/evidence/arch.txt new file mode 100644 index 0000000..9965033 --- /dev/null +++ b/evidence/arch.txt @@ -0,0 +1,7 @@ +# Architecture of the app binary inside the image +# generated: 2026-10-15T19:03:01Z + +## emulated build (--build-arg TARGETARCH=amd64): e_machine 3e = x86-64 + 02 00 3e 00 +## fixed build (no TARGETARCH default): e_machine b7 = aarch64 + 02 00 b7 00 diff --git a/evidence/body-limit.txt b/evidence/body-limit.txt new file mode 100644 index 0000000..b5f56f9 --- /dev/null +++ b/evidence/body-limit.txt @@ -0,0 +1,3 @@ +# body limit check — 2026-10-16T14:02:25Z (limit 256 KiB from SERVER_MAX_BODY_BYTES) +тело 400 КиБ (сверх лимита): 413 +тело 100 КиБ (в пределах): в„– 400 diff --git a/evidence/db-outage.txt b/evidence/db-outage.txt new file mode 100644 index 0000000..7018ae6 --- /dev/null +++ b/evidence/db-outage.txt @@ -0,0 +1,7 @@ +# Отказ PostgreSQL на пути отправки сообщения — 2026-10-16T14:10:06Z +до остановки БД, через LB : 201 (instance=828f6451261b) +до остановки БД, напрямую : 201 +при остановленной БД, напрямую (ожидается 503): 503 +при остановленной БД, через LB : 503 (instance=828f6451261b) +готовность после возврата БД: True +после возврата БД, через LB : 201 (instance=828f6451261b) diff --git a/evidence/failover/run1.txt b/evidence/failover/run1.txt new file mode 100644 index 0000000..57cc4cf --- /dev/null +++ b/evidence/failover/run1.txt @@ -0,0 +1,5 @@ +# make test-failover (прогон 1) — 2026-10-16T13:59:43Z +env -u HTTP_PROXY -u HTTPS_PROXY -u ALL_PROXY -u http_proxy -u https_proxy -u all_proxy NO_PROXY=localhost,127.0.0.1,::1 no_proxy=localhost,127.0.0.1,::1 python3 tests/resilience.py --mode failover --action-script "scripts/stop-one.sh" --base-url "http://localhost:8080" +Executing explicit failover hook; hook output suppressed to avoid leaking secrets. +{"observed_instances_before": 2, "successful_writes": 127, "failed_attempts": 0, "first_recovery_seconds": 0.214} +PASS: failover preserved confirmed data and existing session. Hook scope needs operator evidence. diff --git a/evidence/failover/run2.txt b/evidence/failover/run2.txt new file mode 100644 index 0000000..641f781 --- /dev/null +++ b/evidence/failover/run2.txt @@ -0,0 +1,5 @@ +# make test-failover (прогон 2) — 2026-10-16T13:59:43Z +env -u HTTP_PROXY -u HTTPS_PROXY -u ALL_PROXY -u http_proxy -u https_proxy -u all_proxy NO_PROXY=localhost,127.0.0.1,::1 no_proxy=localhost,127.0.0.1,::1 python3 tests/resilience.py --mode failover --action-script "scripts/stop-one.sh" --base-url "http://localhost:8080" +Executing explicit failover hook; hook output suppressed to avoid leaking secrets. +{"observed_instances_before": 2, "successful_writes": 100, "failed_attempts": 0, "first_recovery_seconds": 2.237} +PASS: failover preserved confirmed data and existing session. Hook scope needs operator evidence. diff --git a/evidence/failover/sequential.txt b/evidence/failover/sequential.txt new file mode 100644 index 0000000..96e5f49 --- /dev/null +++ b/evidence/failover/sequential.txt @@ -0,0 +1,54 @@ +# student-tests/replica_failover.py — 2026-10-16T13:59:43Z +{ + "before": { + "instances": [ + "52861386fddb", + "8587b4251b72" + ] + }, + "replicas": [ + { + "stopped": "52861386fddb", + "stopped_container": "stop-one.sh: stopped api replica(s): mtusi-messenger-lab3-api-5", + "hook_returncode": 0, + "hook_seconds": 0.151, + "hook_error": "", + "successful_writes": 91, + "successful_rps": 6.06, + "failed_attempts": 0, + "uncertain_retries": 0, + "first_recovery_seconds": 1.659, + "instances_after_recovery": [ + "8587b4251b72" + ], + "messages_in_history": 91, + "restored_seconds": 0.201, + "instances_restored": [ + "52861386fddb", + "8587b4251b72" + ] + }, + { + "stopped": "8587b4251b72", + "stopped_container": "stop-one.sh: stopped api replica(s): mtusi-messenger-lab3-api-6", + "hook_returncode": 0, + "hook_seconds": 0.154, + "hook_error": "", + "successful_writes": 100, + "successful_rps": 6.66, + "failed_attempts": 0, + "uncertain_retries": 0, + "first_recovery_seconds": 1.656, + "instances_after_recovery": [ + "52861386fddb" + ], + "messages_in_history": 191, + "restored_seconds": 0.182, + "instances_restored": [ + "52861386fddb", + "8587b4251b72" + ] + } + ] +} +PASS: каждая реплика остановлена по очереди; записи продолжились, дублей и потерь нет diff --git a/evidence/idempotency.txt b/evidence/idempotency.txt new file mode 100644 index 0000000..d1287d3 --- /dev/null +++ b/evidence/idempotency.txt @@ -0,0 +1,4 @@ +# make test-idempotency — 2026-10-16T13:59:43Z +env -u HTTP_PROXY -u HTTPS_PROXY -u ALL_PROXY -u http_proxy -u https_proxy -u all_proxy NO_PROXY=localhost,127.0.0.1,::1 no_proxy=localhost,127.0.0.1,::1 python3 student-tests/idempotency_parallel.py --base-url "http://localhost:8080" +{"replay": {"workers": 12, "instances": ["52861386fddb", "8587b4251b72"], "message_id": "01a14502-f747-7fa8-bbad-84fa27f0ce80"}, "conflict": {"workers": 12, "accepted": 1, "conflicts": 11}, "stable_body": {"message_id": "01a14502-f771-7ea3-a03a-4d559e466ac8"}, "key_required": {"status": 400}} +PASS: параллельный повтор с одним Idempotency-Key создаёт ровно одно сообщение diff --git a/evidence/lab1-2/README.md b/evidence/lab1-2/README.md new file mode 100644 index 0000000..052da1e --- /dev/null +++ b/evidence/lab1-2/README.md @@ -0,0 +1,17 @@ +# Артефакты предыдущих лабораторных (ЛР1 и ЛР2) + +Файлы перенесены сюда из `evidence/`, потому что относятся к **прежним** конфигурациям +стенда и не являются доказательствами ЛР3: они сняты в ЛР1/ЛР2 в репозитории +`mtusi-messenger` и попали сюда вместе с переносом кода. Часть из них ссылается на +образ `mtusi2026lab1-messenger` и на in-memory хранилище, которое удалено ещё в ЛР2, +поэтому их нельзя читать как проверки текущего решения. + +- `check.txt`, `quality.txt`, `concurrency.txt`, `docker.txt`, `health.txt`, `restart.txt`, `sigterm.txt` — ЛР1: офлайн-проверка структуры, линт и тесты, конкурентные чтения, запуск контейнера и обработка SIGTERM. +- `memory-experiment.*` — ЛР1: сравнение in-memory хранилища и PostgreSQL. +- `track1-benchmark/` — ЛР1, трек 1: бенчмарк append-оптимизации in-memory хранилища (скрипт `scripts/track1_benchmark.py` удалён в ЛР3 как осиротевший: он ссылался на удалённый файл хранилища). +- `cache/` — ЛР2: эксперименты с кэшем списка чатов, согласованность и поведение при отказе Redis. +- `postgres/explain-analyze.txt` — ЛР2: план запроса истории сообщений. + +Доказательства ЛР3 лежат рядом, в `evidence/` (`smoke.txt`, `idempotency.txt`, +`persistence.txt`, `failover/`, `lb-readiness.txt`, `rolling-update/`, +`stand.txt`, `arch.txt`, `track1/`), и собраны в `REPORT.md`. diff --git a/evidence/lab1-2/cache/api-performance.txt b/evidence/lab1-2/cache/api-performance.txt new file mode 100644 index 0000000..eee86cc --- /dev/null +++ b/evidence/lab1-2/cache/api-performance.txt @@ -0,0 +1,11 @@ +# API cache performance experiment +# generated: 2026-10-09T21:41:31Z +running trial 1, cache=False, requests=1000 +{"requests": 1000, "workers": 8, "duration_seconds": 0.455918375053443, "rps": 2193.375074831716, "p50_ms": 3.3378750667907298, "p95_ms": 5.237665958702564, "p99_ms": 7.377958972938359, "trial": 1, "cache_enabled": false} +running trial 1, cache=True, requests=1000 +{"requests": 1000, "workers": 8, "duration_seconds": 0.424924207967706, "rps": 2353.360861182094, "p50_ms": 3.075250016991049, "p95_ms": 5.355541012249887, "p99_ms": 6.619499996304512, "trial": 1, "cache_enabled": true} +running trial 2, cache=False, requests=1000 +{"requests": 1000, "workers": 8, "duration_seconds": 0.5072490000165999, "rps": 1971.4183763147382, "p50_ms": 3.680104040540755, "p95_ms": 6.2174160266295075, "p99_ms": 8.554207975976169, "trial": 2, "cache_enabled": false} +running trial 2, cache=True, requests=1000 +{"requests": 1000, "workers": 8, "duration_seconds": 0.4116047500865534, "rps": 2429.51520795063, "p50_ms": 2.9188335174694657, "p95_ms": 5.480541964061558, "p99_ms": 7.245125016197562, "trial": 2, "cache_enabled": true} +{"results": [{"requests": 1000, "workers": 8, "duration_seconds": 0.455918375053443, "rps": 2193.375074831716, "p50_ms": 3.3378750667907298, "p95_ms": 5.237665958702564, "p99_ms": 7.377958972938359, "trial": 1, "cache_enabled": false}, {"requests": 1000, "workers": 8, "duration_seconds": 0.424924207967706, "rps": 2353.360861182094, "p50_ms": 3.075250016991049, "p95_ms": 5.355541012249887, "p99_ms": 6.619499996304512, "trial": 1, "cache_enabled": true}, {"requests": 1000, "workers": 8, "duration_seconds": 0.5072490000165999, "rps": 1971.4183763147382, "p50_ms": 3.680104040540755, "p95_ms": 6.2174160266295075, "p99_ms": 8.554207975976169, "trial": 2, "cache_enabled": false}, {"requests": 1000, "workers": 8, "duration_seconds": 0.4116047500865534, "rps": 2429.51520795063, "p50_ms": 2.9188335174694657, "p95_ms": 5.480541964061558, "p99_ms": 7.245125016197562, "trial": 2, "cache_enabled": true}], "users": 4, "chats": 60, "sessions_cached_in_both_modes": true} diff --git a/evidence/lab1-2/cache/consistency.txt b/evidence/lab1-2/cache/consistency.txt new file mode 100644 index 0000000..7c1c7f6 --- /dev/null +++ b/evidence/lab1-2/cache/consistency.txt @@ -0,0 +1,36 @@ +# Cache consistency evidence (track 1) +# generated: 2026-10-09T21:38:43Z +# redis: localhost:6379 db=1 + +=== RUN TestChatRepositorySuite +=== RUN TestChatRepositorySuite/TestBrokenCacheEntryIsDroppedAndRepopulated +=== RUN TestChatRepositorySuite/TestCacheUnavailableFallsBackToSource +=== RUN TestChatRepositorySuite/TestConcurrentColdReadsAreDeduplicated + chat_repository_test.go:226: distributed lock: 100 concurrent cold reads -> 1 source load +=== RUN TestChatRepositorySuite/TestConcurrentColdReadsWithoutProtectionStampede + chat_repository_test.go:427: stampede demonstration: 100 concurrent reads -> 100 source loads +=== RUN TestChatRepositorySuite/TestCreateInvalidatesMemberCaches +=== RUN TestChatRepositorySuite/TestDeeperPagesBypassCache +=== RUN TestChatRepositorySuite/TestEvictedCacheEntryReloadsFromSource +=== RUN TestChatRepositorySuite/TestFirstPageIsCached +=== RUN TestChatRepositorySuite/TestLimitIsPartOfCacheKey +=== RUN TestChatRepositorySuite/TestMultipleInstancesShareDistributedLock + chat_repository_test.go:276: multi-instance distributed lock: 3 instances x 30 reads -> 1 source load +=== RUN TestChatRepositorySuite/TestSlowLoaderBeyondCacheBudgetReturnsData +=== RUN TestChatRepositorySuite/TestSourceErrorIsNotRetried +--- PASS: TestChatRepositorySuite (0.83s) + --- PASS: TestChatRepositorySuite/TestBrokenCacheEntryIsDroppedAndRepopulated (0.00s) + --- PASS: TestChatRepositorySuite/TestCacheUnavailableFallsBackToSource (0.00s) + --- PASS: TestChatRepositorySuite/TestConcurrentColdReadsAreDeduplicated (0.03s) + --- PASS: TestChatRepositorySuite/TestConcurrentColdReadsWithoutProtectionStampede (0.02s) + --- PASS: TestChatRepositorySuite/TestCreateInvalidatesMemberCaches (0.01s) + --- PASS: TestChatRepositorySuite/TestDeeperPagesBypassCache (0.00s) + --- PASS: TestChatRepositorySuite/TestEvictedCacheEntryReloadsFromSource (0.00s) + --- PASS: TestChatRepositorySuite/TestFirstPageIsCached (0.00s) + --- PASS: TestChatRepositorySuite/TestLimitIsPartOfCacheKey (0.00s) + --- PASS: TestChatRepositorySuite/TestMultipleInstancesShareDistributedLock (0.05s) + --- PASS: TestChatRepositorySuite/TestSlowLoaderBeyondCacheBudgetReturnsData (0.70s) + --- PASS: TestChatRepositorySuite/TestSourceErrorIsNotRetried (0.00s) +PASS +ok mtusi-messenger/internal/storage/redis 1.338s +? mtusi-messenger/internal/storage/redis/mocks [no test files] diff --git a/evidence/lab1-2/cache/latency.txt b/evidence/lab1-2/cache/latency.txt new file mode 100644 index 0000000..f84b1ec --- /dev/null +++ b/evidence/lab1-2/cache/latency.txt @@ -0,0 +1,22 @@ +# Cache latency experiment +# generated: 2026-10-06T15:53:09Z +go version go1.27.1 darwin/arm64 +Darwin arm64 +2026/10/06 18:53:10 OK 00001_init.sql (10.27ms) +2026/10/06 18:53:10 goose: successfully migrated database to version: 1 +=== RUN TestCacheLatencyExperiment + cache_latency_experiment_test.go:83: baseline: requests=1000 source_loads=1000 p50=317.209µs p95=343.542µs p99=377.625µs + cache_latency_experiment_test.go:84: redis cache: requests=1000 source_loads=1 p50=411.791µs p95=527.709µs p99=565.625µs +--- PASS: TestCacheLatencyExperiment (0.97s) +=== RUN TestCacheLatencyExperiment + cache_latency_experiment_test.go:83: baseline: requests=1000 source_loads=1000 p50=271.125µs p95=330.584µs p99=389.209µs + cache_latency_experiment_test.go:84: redis cache: requests=1000 source_loads=1 p50=388µs p95=453.959µs p99=512.625µs +--- PASS: TestCacheLatencyExperiment (0.86s) +=== RUN TestCacheLatencyExperiment + cache_latency_experiment_test.go:83: baseline: requests=1000 source_loads=1000 p50=268.541µs p95=318.417µs p99=367.083µs + cache_latency_experiment_test.go:84: redis cache: requests=1000 source_loads=1 p50=408.833µs p95=473.125µs p99=541.042µs +--- PASS: TestCacheLatencyExperiment (0.88s) +PASS +ok mtusi-messenger/internal/storage/postgres 3.097s +? mtusi-messenger/internal/storage/postgres/internal/sqlcgen [no test files] +? mtusi-messenger/internal/storage/postgres/migrations [no test files] diff --git a/evidence/lab1-2/cache/performance.txt b/evidence/lab1-2/cache/performance.txt new file mode 100644 index 0000000..54412f9 --- /dev/null +++ b/evidence/lab1-2/cache/performance.txt @@ -0,0 +1,26 @@ +# Cache performance experiment +# generated: 2026-10-09T21:41:14Z +go version go1.27.1 darwin/arm64 +Darwin arm64 +2026/10/10 00:41:15 OK 00001_init.sql (10.03ms) +2026/10/10 00:41:15 OK 00002_user_chat_versions.sql (2.17ms) +2026/10/10 00:41:15 goose: successfully migrated database to version: 2 +=== RUN TestCachePerformanceExperiment + cache_performance_experiment_test.go:115: baseline (no cache): requests=10000 concurrency=50 sql=10000 duration=1.528s rps=6542 p50=7.490875ms p95=9.302792ms p99=10.779ms + cache_performance_experiment_test.go:116: redis cache (cold): requests=10000 concurrency=50 sql=1 duration=851ms rps=11749 p50=4.192709ms p95=5.318916ms p99=5.905625ms + cache_performance_experiment_test.go:117: redis cache (hot): requests=10000 concurrency=50 sql=0 duration=751ms rps=13320 p50=3.670958ms p95=4.644958ms p99=5.21475ms +--- PASS: TestCachePerformanceExperiment (3.50s) +=== RUN TestCachePerformanceExperiment + cache_performance_experiment_test.go:115: baseline (no cache): requests=10000 concurrency=50 sql=10000 duration=1.415s rps=7066 p50=6.901958ms p95=8.697666ms p99=10.560416ms + cache_performance_experiment_test.go:116: redis cache (cold): requests=10000 concurrency=50 sql=1 duration=846ms rps=11815 p50=4.033083ms p95=6.0305ms p99=6.963417ms + cache_performance_experiment_test.go:117: redis cache (hot): requests=10000 concurrency=50 sql=0 duration=817ms rps=12234 p50=3.999959ms p95=5.060959ms p99=5.802042ms +--- PASS: TestCachePerformanceExperiment (3.39s) +=== RUN TestCachePerformanceExperiment + cache_performance_experiment_test.go:115: baseline (no cache): requests=10000 concurrency=50 sql=10000 duration=1.511s rps=6618 p50=7.302667ms p95=9.420708ms p99=12.437917ms + cache_performance_experiment_test.go:116: redis cache (cold): requests=10000 concurrency=50 sql=1 duration=827ms rps=12093 p50=3.984125ms p95=5.655167ms p99=6.8085ms + cache_performance_experiment_test.go:117: redis cache (hot): requests=10000 concurrency=50 sql=0 duration=817ms rps=12247 p50=3.946959ms p95=5.363208ms p99=6.508458ms +--- PASS: TestCachePerformanceExperiment (3.55s) +PASS +ok mtusi-messenger/internal/storage/postgres 10.978s +? mtusi-messenger/internal/storage/postgres/internal/sqlcgen [no test files] +? mtusi-messenger/internal/storage/postgres/migrations [no test files] diff --git a/evidence/lab1-2/cache/redis-outage.txt b/evidence/lab1-2/cache/redis-outage.txt new file mode 100644 index 0000000..38ea2c4 --- /dev/null +++ b/evidence/lab1-2/cache/redis-outage.txt @@ -0,0 +1,8 @@ +baseline: 6ms +after stop: 476ms + stop: n=1 max=476ms p95=476ms budget=2000ms + pause parallel: n=30 max=215ms p95=214ms budget=2000ms +create during pause: 201 +after recovery: new chat visible, 5ms +lock keys without TTL: 0 +PASS: redis outage handled within budget diff --git a/evidence/lab1-2/check.txt b/evidence/lab1-2/check.txt new file mode 100644 index 0000000..1678252 --- /dev/null +++ b/evidence/lab1-2/check.txt @@ -0,0 +1,3 @@ +$ make check +env -u HTTP_PROXY -u HTTPS_PROXY -u ALL_PROXY -u http_proxy -u https_proxy -u all_proxy NO_PROXY=localhost,127.0.0.1,::1 no_proxy=localhost,127.0.0.1,::1 python3 scripts/check_contract.py +PASS: offline skeleton structure, local refs and Python syntax; application NOT tested. diff --git a/evidence/lab1-2/concurrency.txt b/evidence/lab1-2/concurrency.txt new file mode 100644 index 0000000..58dbcb6 --- /dev/null +++ b/evidence/lab1-2/concurrency.txt @@ -0,0 +1,2 @@ +command: docker run + Python ThreadPoolExecutor(10), 100 POST messages +{"sent": 100, "read": 100, "unique": 100} diff --git a/evidence/lab1-2/docker.txt b/evidence/lab1-2/docker.txt new file mode 100644 index 0000000..22b3529 --- /dev/null +++ b/evidence/lab1-2/docker.txt @@ -0,0 +1,11 @@ +$ docker inspect --format ... +status=running health=healthy user=10001:10001 +$ curl -i http://127.0.0.1:8080/health/live +HTTP/1.1 200 OK +Access-Control-Expose-Headers: X-Request-Id +Content-Type: application/json; charset=utf-8 +X-Request-Id: 3d145e7d-423a-4510-9d6b-6f45b7cf552d +Date: Thu, 24 Sep 2026 20:13:14 GMT +Content-Length: 15 + +{"status":"ok"} \ No newline at end of file diff --git a/evidence/lab1-2/health.txt b/evidence/lab1-2/health.txt new file mode 100644 index 0000000..1a36cf5 --- /dev/null +++ b/evidence/lab1-2/health.txt @@ -0,0 +1 @@ +{"status":"ok"} \ No newline at end of file diff --git a/evidence/lab1-2/memory-experiment.json b/evidence/lab1-2/memory-experiment.json new file mode 100644 index 0000000..1068e42 --- /dev/null +++ b/evidence/lab1-2/memory-experiment.json @@ -0,0 +1,17279 @@ +{ + "image": "mtusi2026lab1-messenger:arm64", + "memory_limit": "64m", + "memory_limit_mib": 64.0, + "successful_messages": 8610, + "failed_requests": 0, + "oom_killed": true, + "last_error": null, + "fatal_error": "IncompleteRead: IncompleteRead(0 bytes read)", + "container_state": { + "Status": "exited", + "Running": false, + "Paused": false, + "Restarting": false, + "OOMKilled": true, + "Dead": false, + "Pid": 0, + "ExitCode": 137, + "Error": "", + "StartedAt": "2026-09-24T20:55:58.307994245Z", + "FinishedAt": "2026-09-24T20:56:04.29060562Z", + "Health": { + "Status": "unhealthy", + "FailingStreak": 0, + "Log": [ + { + "Start": "2026-09-24T23:56:03.357136035+03:00", + "End": "2026-09-24T23:56:03.371812177+03:00", + "ExitCode": 0, + "Output": "" + } + ] + } + }, + "container_logs_tail": "", + "failure_time_seconds": 5.931530750000093, + "memory_samples": [ + { + "time_seconds": 41378.968726375, + "memory": "10.11MiB", + "memory_mib": 10.11 + }, + { + "time_seconds": 41380.971784666, + "memory": "33.5MiB", + "memory_mib": 33.5 + }, + { + "time_seconds": 41382.973903625, + "memory": "52.24MiB", + "memory_mib": 52.24 + } + ], + "message_points_x": [ + 0.5184139170014532, + 0.5204068339953665, + 0.5219206670008134, + 0.5230430000010529, + 0.5242924999984098, + 0.5255186249996768, + 0.526668749997043, + 0.5277829589977046, + 0.5289297089984757, + 0.5299583749947487, + 0.5310334589958075, + 0.5322612499949173, + 0.5332877499968163, + 0.5342921249975916, + 0.535259500000393, + 0.5361602499979199, + 0.5370337089989334, + 0.5380593750014668, + 0.5389899169967975, + 0.5398404169973219, + 0.540663041996595, + 0.5415193750013714, + 0.5423362090004957, + 0.5431351250008447, + 0.5439704999953392, + 0.544804249999288, + 0.5456645419981214, + 0.5464134590001777, + 0.54733141700126, + 0.548126499998034, + 0.5489054999998189, + 0.549695541994879, + 0.5504482920005103, + 0.5512134589953348, + 0.5520517920012935, + 0.5529058749962132, + 0.553739625000162, + 0.5545109169979696, + 0.5552669589960715, + 0.5560028749969206, + 0.5567628339995281, + 0.5575472089985851, + 0.5583592920011142, + 0.5591555840001092, + 0.5599456669951905, + 0.5607333750012913, + 0.5614233749947743, + 0.562186124996515, + 0.5629096670018043, + 0.5636121669958811, + 0.5643381249974482, + 0.5650693749994389, + 0.5657560839972575, + 0.5664414999992005, + 0.5671678340004291, + 0.5678588340015267, + 0.5690906249947147, + 0.5698721669978113, + 0.5706161669950234, + 0.5713675000006333, + 0.5721129169978667, + 0.5728685419962858, + 0.5735694169998169, + 0.5742667090016766, + 0.5749773749994347, + 0.5756967919951421, + 0.5764001669958816, + 0.5770828339955187, + 0.5777844589974848, + 0.5785861249969457, + 0.5792511670006206, + 0.5799325839980156, + 0.5806418749998556, + 0.5813412919960683, + 0.581995583997923, + 0.5827191669959575, + 0.5834124589964631, + 0.5841665839980124, + 0.5849062089982908, + 0.5856551670003682, + 0.5863690839978517, + 0.5871183339986601, + 0.5877875840014894, + 0.5884722089977004, + 0.5892090419947635, + 0.5899365419973037, + 0.5906328339988249, + 0.5912689589968068, + 0.5920083339951816, + 0.592761125000834, + 0.593522249997477, + 0.5942453339957865, + 0.5949209169993992, + 0.5955799169969396, + 0.5963211669950397, + 0.5970629590010503, + 0.5978052499995101, + 0.5984491249982966, + 0.5991153340000892, + 0.5997544999991078, + 0.600359459000174, + 0.6009986669960199, + 0.6016269169995212, + 0.6022871249952004, + 0.6029002919967752, + 0.6035444590015686, + 0.6043039169962867, + 0.6048937919986201, + 0.6055339589947835, + 0.6061541669987491, + 0.6067552499953308, + 0.6073647919984069, + 0.6079727089963853, + 0.6085505839946563, + 0.6092511249953532, + 0.6099042089990689, + 0.6104623339997488, + 0.6110740840013023, + 0.6117397919952055, + 0.6124364999996033, + 0.6132009169959929, + 0.6139017499954207, + 0.6145433339988813, + 0.6151680420007324, + 0.615861499994935, + 0.6164850419954746, + 0.6171578339999542, + 0.6178212919985526, + 0.618482749996474, + 0.6191684169971268, + 0.6197867500013672, + 0.620482667000033, + 0.6211232919959002, + 0.6217566669947701, + 0.6223663749988191, + 0.6230042499955744, + 0.6236522499966668, + 0.6243039589971886, + 0.6249877500013099, + 0.6257640839976375, + 0.6264105000009295, + 0.6270391250000102, + 0.6277013340004487, + 0.6283780419980758, + 0.6290188749990193, + 0.62966216699715, + 0.6303317919955589, + 0.6310257919976721, + 0.6317227499966975, + 0.6324197089998052, + 0.6330538339971099, + 0.6336742919957032, + 0.6343468339982792, + 0.6350101669959258, + 0.6356489999961923, + 0.6363151670011575, + 0.6369789589953143, + 0.6376079589972505, + 0.6382454999984475, + 0.6388775000013993, + 0.639548166996974, + 0.6401784999980009, + 0.6408622499948251, + 0.6414877919960418, + 0.6421079589999863, + 0.6427445000008447, + 0.6433672089988249, + 0.643976624996867, + 0.6446119999964139, + 0.6452468749994296, + 0.6458980419993168, + 0.6465418340012548, + 0.6471705000003567, + 0.6478516249990207, + 0.648482459000661, + 0.6492391249994398, + 0.6498975840004277, + 0.6505527499975869, + 0.6512256669957424, + 0.6519522499947925, + 0.6526021249956102, + 0.6532350839988794, + 0.6538310420000926, + 0.6544814169974416, + 0.6551320840007975, + 0.655773209000472, + 0.6564397089969134, + 0.6570341249971534, + 0.6576618339968263, + 0.6582876249958645, + 0.6589354999960051, + 0.6596007499974803, + 0.6602243339948473, + 0.6608792499973788, + 0.6615296249947278, + 0.6621900419995654, + 0.6628199999977369, + 0.6634553339972626, + 0.6641407499992056, + 0.6647986249954556, + 0.6654613339997013, + 0.6661163339958875, + 0.6667379589998745, + 0.667355208999652, + 0.6679822500009323, + 0.6686080419967766, + 0.6692318339992198, + 0.6699011669988977, + 0.6705691249953816, + 0.6712787090000347, + 0.6720528750010999, + 0.6726831249980023, + 0.673339417000534, + 0.6739381669976865, + 0.6747349590004887, + 0.6753525839958456, + 0.6761363749974407, + 0.6768189590002294, + 0.6775881249996019, + 0.6782003749976866, + 0.6788513749997946, + 0.6794713339986629, + 0.6801543339970522, + 0.6807948339992436, + 0.6814544169974397, + 0.6821445419991505, + 0.6827979590016184, + 0.6834393339959206, + 0.6841052919990034, + 0.6847229170016362, + 0.6853701250001905, + 0.6859554589973413, + 0.6865738749984303, + 0.6871685000005527, + 0.6878155000013066, + 0.6885477499963599, + 0.6892197089982801, + 0.6899046670005191, + 0.6905384999990929, + 0.6912058339948999, + 0.6918827920017065, + 0.6925021249990095, + 0.6931414169957861, + 0.6938070420001168, + 0.6944683339970652, + 0.6950644589960575, + 0.6958125839955756, + 0.696425417001592, + 0.6970299589956994, + 0.6977391670006909, + 0.6984105839947006, + 0.6990365419987938, + 0.6996563339998829, + 0.7003364999982296, + 0.7009742919981363, + 0.7016083339985926, + 0.7022284589984338, + 0.7028550839968375, + 0.7035207919980166, + 0.704159583998262, + 0.7047847919966443, + 0.7054155840014573, + 0.7060796669975389, + 0.7066871249990072, + 0.7073193339965655, + 0.7080209170017042, + 0.7086323749972507, + 0.7092991249955958, + 0.7100246670015622, + 0.7107215419964632, + 0.7113945839955704, + 0.7120392500000889, + 0.7127007499948377, + 0.7133515419991454, + 0.714004624998779, + 0.7146291669996572, + 0.7152715420015738, + 0.7159206669966807, + 0.7165268339958857, + 0.7172255420009606, + 0.7179105839968543, + 0.718550833997142, + 0.7191538339975523, + 0.7197732089989586, + 0.7204269169960753, + 0.7210396250011399, + 0.7216524169998593, + 0.7222911669960013, + 0.7229739999966114, + 0.7236452090000967, + 0.7243870839956799, + 0.7250047499983339, + 0.7256294999970123, + 0.7262228749968926, + 0.7268766249981127, + 0.7275339170009829, + 0.7281923749978887, + 0.7288876669990714, + 0.7295797920014593, + 0.7302502089951304, + 0.7309008750016801, + 0.7315497499948833, + 0.7322054169999319, + 0.732817708994844, + 0.7334464589948766, + 0.7340894590015523, + 0.734732917000656, + 0.7353822500008391, + 0.7360126669955207, + 0.736632959000417, + 0.737248624995118, + 0.7378862089972245, + 0.7385313339982531, + 0.7391983339985018, + 0.7398598750005476, + 0.7405030839945539, + 0.7411182089999784, + 0.7417897089981125, + 0.7425152919968241, + 0.7431825419989764, + 0.7438407090012333, + 0.7444735839962959, + 0.7452394169959007, + 0.7459312499995576, + 0.7466316249992815, + 0.7473506669994094, + 0.7480540420001489, + 0.7487243340001442, + 0.7494109999970533, + 0.750112417001219, + 0.7508354999954463, + 0.7514743339997949, + 0.7521295839978848, + 0.752903291999246, + 0.7535692919991561, + 0.7542105839966098, + 0.7549755000000005, + 0.7556059589987854, + 0.7562496669997927, + 0.7569001250012661, + 0.7575037089991383, + 0.7581601249985397, + 0.75880687499739, + 0.7595177089970093, + 0.7601517090006382, + 0.7608166669961065, + 0.7614688339963323, + 0.7621040000012727, + 0.7627385000014328, + 0.7633910840013414, + 0.7640176669956418, + 0.7646791250008391, + 0.765362958998594, + 0.7659789999961504, + 0.7666380839946214, + 0.7673123749991646, + 0.7679994169957354, + 0.7687116669985699, + 0.7694159589955234, + 0.7700839169992832, + 0.7707527499951539, + 0.7714205000011134, + 0.7721213339973474, + 0.7727749589976156, + 0.7734382089984138, + 0.7740348750012345, + 0.7747124999950756, + 0.7753627089987276, + 0.7759780839987798, + 0.7766068749988335, + 0.7772285419996479, + 0.7778938339979504, + 0.7785501249964, + 0.7792036669998197, + 0.7798726670007454, + 0.780483374997857, + 0.7812164589995518, + 0.7818722919982974, + 0.7825164999958361, + 0.7831692499967176, + 0.7837751670012949, + 0.784428624996508, + 0.7851038340013474, + 0.7857498340017628, + 0.7864819589958643, + 0.7871889589951024, + 0.7879917919999571, + 0.7886484589980682, + 0.789309667001362, + 0.7899667089950526, + 0.7906144169974141, + 0.7912849999993341, + 0.7919452499991166, + 0.7925789169967175, + 0.7932271669997135, + 0.7938613750011427, + 0.7945078749980894, + 0.795150541998737, + 0.7957939999978407, + 0.7964372499991441, + 0.7970954170014011, + 0.7978748749956139, + 0.798495584000193, + 0.7991426669977955, + 0.799797416999354, + 0.8004426670013345, + 0.8010637499974109, + 0.8017242919959244, + 0.802363583999977, + 0.8030040839948924, + 0.8036244169998099, + 0.8042551249964163, + 0.8048780419994728, + 0.8055318749975413, + 0.806319874995097, + 0.807023458997719, + 0.8076849999997648, + 0.8083500419961638, + 0.8090357499968377, + 0.809666291999747, + 0.8102953339985106, + 0.8109624999997322, + 0.8116052920013317, + 0.812248834001366, + 0.8129138340009376, + 0.813640583997767, + 0.8142274169949815, + 0.8148451250017388, + 0.8154416249963106, + 0.8160943749971921, + 0.8167397090001032, + 0.81733545899624, + 0.8179709169999114, + 0.8186304999981076, + 0.8192848749968107, + 0.8199278749962104, + 0.8206395839952165, + 0.8213106249968405, + 0.8219412499965983, + 0.82259662499564, + 0.8232428339979379, + 0.8239938339975197, + 0.8246624999956111, + 0.8254516669985605, + 0.8261809589967015, + 0.8269463749966235, + 0.8276099590002559, + 0.8282552499949816, + 0.8288460839976324, + 0.8294932919961866, + 0.830184708996967, + 0.8308255839947378, + 0.8314710420017946, + 0.8321482499959529, + 0.832775999995647, + 0.8333912089947262, + 0.8340397089996259, + 0.8347864169991226, + 0.8354329590001726, + 0.8360665000000154, + 0.8367241669984651, + 0.8373906249980791, + 0.8380332919987268, + 0.8386750419958844, + 0.8393355000007432, + 0.8399785840010736, + 0.8405962499964517, + 0.841255250001268, + 0.8418895419963519, + 0.8425385419977829, + 0.843199791997904, + 0.8438477499948931, + 0.8445081669997307, + 0.8453110839982401, + 0.8461466250009835, + 0.8469648339960258, + 0.8476910839963239, + 0.8483675839961506, + 0.849066374998074, + 0.8497066669951892, + 0.8503576669972972, + 0.851029749996087, + 0.8516163749955012, + 0.8522922499978449, + 0.8529543339973316, + 0.8536197089997586, + 0.8543839170015417, + 0.855086042000039, + 0.8557201250005164, + 0.8563566250013537, + 0.8569952499965439, + 0.857611542000086, + 0.8582464169958257, + 0.8589438749986584, + 0.8595557500011637, + 0.8601860419948935, + 0.8608362500017392, + 0.8614728339962312, + 0.8621068749998813, + 0.8627197919995524, + 0.8633281669972348, + 0.8639666249946458, + 0.8647587919986108, + 0.8655055419949349, + 0.8662219589969027, + 0.8670333749978454, + 0.8677367089985637, + 0.8684091249961057, + 0.8690514170011738, + 0.869709458995203, + 0.8703985839965753, + 0.8710700839947094, + 0.8717131250014063, + 0.8723584589970415, + 0.8729618340003071, + 0.8735761669959174, + 0.8742086669954006, + 0.8749006250000093, + 0.8755362919982872, + 0.8761877500000992, + 0.8768401669949526, + 0.8775060839980142, + 0.878146041999571, + 0.878774249998969, + 0.8794192919958732, + 0.8800274589957553, + 0.8806592089968035, + 0.8813103339998634, + 0.881968166999286, + 0.882607374995132, + 0.8832825419958681, + 0.8839514589999453, + 0.8846694169988041, + 0.8853855419947649, + 0.8860094999981811, + 0.8866541669995058, + 0.8872888339974452, + 0.8879539999979897, + 0.8885634999969625, + 0.8891755840013502, + 0.8899544999949285, + 0.8905842089952785, + 0.891262666998955, + 0.891945791998296, + 0.8926495839987183, + 0.8934294169957866, + 0.8941153749983641, + 0.8947504589959863, + 0.8953652089985553, + 0.8960499169988907, + 0.8967349999948055, + 0.8973554170006537, + 0.8979747089979355, + 0.8986264999984996, + 0.8994230419993983, + 0.9001743339977111, + 0.9008518749978975, + 0.9014402920001885, + 0.9020516669988865, + 0.9026657499998691, + 0.9035271669999929, + 0.9041936669964343, + 0.9048791249952046, + 0.9055280839966144, + 0.90635308399942, + 0.9069974169979105, + 0.9076066249981523, + 0.9082304589974228, + 0.9088969590011402, + 0.9096225839966792, + 0.9103182499966351, + 0.9110378749974188, + 0.9117287920016679, + 0.9124074999999721, + 0.913077749995864, + 0.9137640420012758, + 0.9144117089963402, + 0.9150587920012185, + 0.9156509999957052, + 0.9162714999984019, + 0.9169459999975516, + 0.9175595839988091, + 0.9181948339974042, + 0.9188264170006732, + 0.9194585419973009, + 0.920213083998533, + 0.9208639589996892, + 0.9215036669993424, + 0.9221212499978719, + 0.9227599169971654, + 0.9234288340012426, + 0.924195374995179, + 0.9248040419988683, + 0.9255241669961833, + 0.9262475840005209, + 0.9269639589983854, + 0.9276114999956917, + 0.9282501669949852, + 0.9288867499999469, + 0.9295096669957275, + 0.9301811670011375, + 0.9308597499984899, + 0.9315007499972126, + 0.9321670419958537, + 0.9328095839955495, + 0.9335401669959538, + 0.9341952920003678, + 0.9348547499976121, + 0.9354881249964819, + 0.936140041994804, + 0.9367534999983036, + 0.9373239999986254, + 0.9379705419996753, + 0.9387245420002728, + 0.9393779169986374, + 0.9400345839967486, + 0.9406466250002268, + 0.941258792001463, + 0.9419276670014369, + 0.9425713749951683, + 0.9432124999948428, + 0.9439115839995793, + 0.9445392499983427, + 0.9452093750005588, + 0.945886541994696, + 0.9466038339960505, + 0.9472448749947944, + 0.947914167001727, + 0.9485807919991203, + 0.9492278339967015, + 0.9498565419999068, + 0.9504921670013573, + 0.9511350839966326, + 0.9517600839972147, + 0.9523709999994026, + 0.95301516699692, + 0.9536602090011002, + 0.9544291669953964, + 0.9550380000000587, + 0.9557272089950857, + 0.9563425839951378, + 0.9570088339969516, + 0.9576826249976875, + 0.9583507499992265, + 0.959175874995708, + 0.9598374589986634, + 0.960445416996663, + 0.9610509589983849, + 0.9616812089952873, + 0.9623031669980264, + 0.9629518340007053, + 0.9635810839972692, + 0.9642740419949405, + 0.9649308750013006, + 0.96557779199793, + 0.9662873339984799, + 0.966925959000946, + 0.9676125420010067, + 0.9682907089954824, + 0.9689473749967874, + 0.9695922499959124, + 0.9702262499995413, + 0.9708932919966173, + 0.9715289169980679, + 0.9721750839962624, + 0.9727999169990653, + 0.9733816250009113, + 0.9739998750010272, + 0.9746099999974831, + 0.9752227499993751, + 0.9758687499997905, + 0.976501459001156, + 0.9771456669986947, + 0.9777957499973127, + 0.978430874994956, + 0.9790849999990314, + 0.9796767500010901, + 0.9803068749970407, + 0.9809831669990672, + 0.9816053339964128, + 0.9822397499956423, + 0.9829100839997409, + 0.9836085839997395, + 0.9842744169945945, + 0.9849862919945735, + 0.9857524170001852, + 0.9864109999980428, + 0.9870339589979267, + 0.9876529589964775, + 0.9883029170014197, + 0.988948291997076, + 0.9895976249972591, + 0.9902442499951576, + 0.9909775419946527, + 0.9916536249947967, + 0.9923237499970128, + 0.9931110420002369, + 0.9937628339976072, + 0.994470833997184, + 0.9952084589967853, + 0.9959592090017395, + 0.9966284999973141, + 0.9972522089956328, + 0.9979131669970229, + 0.9985563340014778, + 0.9992098750008154, + 0.9998549589945469, + 1.0005754999947385, + 1.00126787499903, + 1.001965958996152, + 1.0026574169969535, + 1.003385124997294, + 1.0041443750014878, + 1.0048771250003483, + 1.0055522499969811, + 1.0061402919964166, + 1.0067452090006554, + 1.0073526669948478, + 1.0079100419970928, + 1.0084815839945804, + 1.0090810420006164, + 1.0097314169979654, + 1.0104347499946016, + 1.01099479199911, + 1.0120392499957234, + 1.0125666249950882, + 1.0131089169954066, + 1.013674916997843, + 1.0142782920011086, + 1.0147718340012943, + 1.015302416999475, + 1.015901999999187, + 1.0163944169980823, + 1.016919458998018, + 1.0174603749983362, + 1.0181480839964934, + 1.0186908749965369, + 1.0193297090008855, + 1.0199160420015687, + 1.0204759999978705, + 1.021009708994825, + 1.021566333998635, + 1.0220730000000913, + 1.0226067089970456, + 1.0232385839990457, + 1.023805374999938, + 1.024681791997864, + 1.0254696249976405, + 1.0264432089970796, + 1.027052042001742, + 1.0292267089971574, + 1.0301007919988479, + 1.030809459000011, + 1.0314735419960925, + 1.0321328339996398, + 1.0327611669999897, + 1.0333527920010965, + 1.034026333996735, + 1.0346310839959187, + 1.0351884999981849, + 1.0357489589951, + 1.0365015839997795, + 1.0371517919993494, + 1.037764791995869, + 1.0384526249981718, + 1.039085749995138, + 1.0397126669995487, + 1.0403384999954142, + 1.0410054169988143, + 1.0417437919968506, + 1.042436625000846, + 1.0430662090002443, + 1.0437082499993267, + 1.0443229169977712, + 1.0449623339954996, + 1.045554333999462, + 1.046089999996184, + 1.046664959001646, + 1.0471924589946866, + 1.0477484169969102, + 1.0483179590009968, + 1.048864374999539, + 1.0494218749954598, + 1.0500030839975807, + 1.0505608749954263, + 1.0512694169956376, + 1.0518768339970848, + 1.0524612919980427, + 1.052992249999079, + 1.0535431669995887, + 1.0540903750006692, + 1.0546270420018118, + 1.0551473749947036, + 1.055688624997856, + 1.0562536669967812, + 1.0567766669992125, + 1.0573037089998252, + 1.0578541669965489, + 1.0583732500017504, + 1.0588856249960372, + 1.0593769589977455, + 1.0599361669956124, + 1.0605024589967798, + 1.061050541997247, + 1.061669416994846, + 1.0622421669977484, + 1.062860958998499, + 1.0634130420003203, + 1.0639289589962573, + 1.0645133340003667, + 1.0650230839964934, + 1.0655662919962197, + 1.066138083995611, + 1.0666802919949987, + 1.0675097089988412, + 1.0682048339949688, + 1.0687223749991972, + 1.0692450419956003, + 1.0697723749981378, + 1.0703094999989844, + 1.0708216249986435, + 1.0713662499983911, + 1.071929874997295, + 1.072510375001002, + 1.0730040419948637, + 1.073525250001694, + 1.0740366669997456, + 1.0745768749984563, + 1.0751352090010187, + 1.0757110420017852, + 1.0762119589999202, + 1.0767149589955807, + 1.077301459001319, + 1.077868499996839, + 1.0784016249963315, + 1.0789064169948688, + 1.0794087499962188, + 1.0799710840001353, + 1.0805361249949783, + 1.081285708998621, + 1.08191179199639, + 1.0825124999973923, + 1.0831066669998108, + 1.083684083998378, + 1.0842169999959879, + 1.0847625419992255, + 1.0852947919993312, + 1.0858834169994225, + 1.086421749998408, + 1.0869749589983257, + 1.0875259169988567, + 1.0881064169952879, + 1.0887584589945618, + 1.0892919589969097, + 1.0898059999963152, + 1.0903907920001075, + 1.0909389590015053, + 1.0914699589993688, + 1.0920477920008125, + 1.0926581249950686, + 1.0931880839998485, + 1.0937153339982615, + 1.094273874994542, + 1.0949134999973467, + 1.0955134169998928, + 1.0960293339958298, + 1.096698124994873, + 1.09730383400165, + 1.097892124998907, + 1.0984669999961625, + 1.0989948749993346, + 1.09951970900147, + 1.1001259589975234, + 1.100764666996838, + 1.101309666999441, + 1.1019402089950745, + 1.1025378749982337, + 1.1030917089956347, + 1.1036804589966778, + 1.1041996249987278, + 1.1047873749994324, + 1.1053276249949704, + 1.1058982089962228, + 1.1064176669970038, + 1.106990959000541, + 1.1075256670010276, + 1.1080436670017662, + 1.1085778339984245, + 1.1091003339970484, + 1.1096655419969466, + 1.1102050420013256, + 1.1107321669987869, + 1.111317416995007, + 1.111890874999517, + 1.1124504170002183, + 1.113070458995935, + 1.1136314589966787, + 1.114196249996894, + 1.11480729199684, + 1.1153992089966778, + 1.1159892499999842, + 1.11656524999853, + 1.1171345420007128, + 1.117655999994895, + 1.1182114999974146, + 1.1187260000006063, + 1.1192700419996982, + 1.1199199589973432, + 1.1205497089977143, + 1.1211885000011534, + 1.1217852089976077, + 1.1223544589956873, + 1.1228776669959188, + 1.1233915839984547, + 1.12395375000051, + 1.1245373749989085, + 1.1250873749959283, + 1.1256345000001602, + 1.126189875001728, + 1.1268126249997295, + 1.1273469169973396, + 1.127911874995334, + 1.1284755419983412, + 1.1291950839950005, + 1.1297516249978798, + 1.130276916999719, + 1.1308600839984138, + 1.131461083998147, + 1.1320317499994417, + 1.132629874999111, + 1.1332253750006203, + 1.1337393750000047, + 1.1343286670016823, + 1.1348775419974118, + 1.1354403340010322, + 1.1360011249998934, + 1.1365471669996623, + 1.1371186249962193, + 1.1377009999996517, + 1.138224916998297, + 1.1387960419961018, + 1.13933937499678, + 1.1399445419956464, + 1.140536708997388, + 1.1411257500003558, + 1.1417397089971928, + 1.1439872499977355, + 1.1446458749996964, + 1.1453561249945778, + 1.1459464590006974, + 1.1465122919980786, + 1.1470558340006392, + 1.1476045419985894, + 1.148188458995719, + 1.1487490419967799, + 1.14936258400121, + 1.1499830419998034, + 1.1507948750004289, + 1.1514159590005875, + 1.1520009999949252, + 1.1526694589992985, + 1.1533417089958675, + 1.1539486670008046, + 1.1545580419988255, + 1.1551428339953418, + 1.1557589590011048, + 1.1562982089963043, + 1.1568622089980636, + 1.1573674169994774, + 1.157925791994785, + 1.1585051669972017, + 1.15911262499867, + 1.159770166996168, + 1.1603392920005717, + 1.1609600839947234, + 1.1615598749995115, + 1.1621290420007426, + 1.1626607500002137, + 1.1632087920006597, + 1.1638326249958482, + 1.1643509169953177, + 1.1648976249998668, + 1.1654338750013267, + 1.1659819999986212, + 1.1665207920013927, + 1.1670617089985171, + 1.1676194169995142, + 1.1681647090008482, + 1.1687184170004912, + 1.169463916994573, + 1.1700420419947477, + 1.1706013750008424, + 1.171165125000698, + 1.171705959000974, + 1.1722813749947818, + 1.1728908340010094, + 1.1734494170013932, + 1.1739917500017327, + 1.1745444999978645, + 1.1751195839970023, + 1.1757114169959095, + 1.1762874170017312, + 1.1768331249986659, + 1.1773625419955351, + 1.1778906670006108, + 1.1784412089982652, + 1.1789981670008274, + 1.1795850419948692, + 1.1802739999984624, + 1.180961499994737, + 1.1815203340011067, + 1.182097500000964, + 1.1826672089955537, + 1.183229834001395, + 1.1837891249961103, + 1.184359916995163, + 1.1849379999985103, + 1.1855029169964837, + 1.1860879999949248, + 1.1866134589945432, + 1.1871429169987096, + 1.1876381670008413, + 1.1881753339985153, + 1.1886626669947873, + 1.1892299169994658, + 1.1897754589954275, + 1.1903368339990266, + 1.1909092499990948, + 1.1914107919947128, + 1.1919586669973796, + 1.1924948749947362, + 1.1930197089968715, + 1.1935656249988824, + 1.1942643750007846, + 1.1948198749960284, + 1.1953805839948473, + 1.1959066249983152, + 1.1964327089954168, + 1.1970223339958466, + 1.1977087919949554, + 1.1983517089975066, + 1.199038083999767, + 1.1996357499956503, + 1.2001783749947208, + 1.2007560839992948, + 1.2013118339964421, + 1.2018805839979905, + 1.2024307499959832, + 1.2030039589953958, + 1.2035433749988442, + 1.2042269589946955, + 1.2047806670016143, + 1.2053085840016138, + 1.205881624999165, + 1.2064111250001588, + 1.2069525839979178, + 1.2074880840009428, + 1.2080535419954685, + 1.2086104999980307, + 1.2091438339994056, + 1.209690416995727, + 1.210262791995774, + 1.2107685000009951, + 1.2112948750000214, + 1.2118502090015681, + 1.2123852919976343, + 1.2129334589990322, + 1.2134774590012967, + 1.214062708997517, + 1.2146135000002687, + 1.2151681249961257, + 1.2156863749987679, + 1.2162019589959527, + 1.216731833999802, + 1.2173628749951604, + 1.21797770899866, + 1.218726749997586, + 1.2192582919960842, + 1.2197892089970992, + 1.2203325419977773, + 1.2208810419979272, + 1.2214017090009293, + 1.2219607090009958, + 1.2225066669998341, + 1.223014916999091, + 1.223530541996297, + 1.2240562500010128, + 1.224571416998515, + 1.2251042499992764, + 1.2257145839976147, + 1.2262891249993118, + 1.2268263750011101, + 1.2273387919995002, + 1.2278850419970695, + 1.2284440840012394, + 1.2289902089978568, + 1.2295190000004368, + 1.2300813339970773, + 1.230660875000467, + 1.2312042089979514, + 1.2317340840018005, + 1.2322549589953269, + 1.232788374996744, + 1.2333582499995828, + 1.2338847089995397, + 1.234444749999966, + 1.2349394999982906, + 1.2354755839987774, + 1.2361722089990508, + 1.236838249998982, + 1.237512166997476, + 1.238084999997227, + 1.2386970840016147, + 1.2392868749957415, + 1.239853041995957, + 1.2403489999996964, + 1.2408968749950873, + 1.2413957499957178, + 1.2419174169990583, + 1.2424838340011775, + 1.2430452089975006, + 1.2435925839963602, + 1.244196291998378, + 1.2447140000003856, + 1.2452579999953741, + 1.2458249170013005, + 1.2463522089965409, + 1.2469877499970607, + 1.2475545419947593, + 1.2480898750000051, + 1.2486241669976152, + 1.249147541995626, + 1.2497158749974915, + 1.250263083995378, + 1.2509375000008731, + 1.2517601250001462, + 1.2522921249983483, + 1.2528333340014797, + 1.2533933339946088, + 1.253952583996579, + 1.254462999997486, + 1.255041042000812, + 1.2555824169976404, + 1.2562071249994915, + 1.2567601249975269, + 1.2574656249998952, + 1.258211708998715, + 1.2588265419981326, + 1.2593897499973536, + 1.2599688339978456, + 1.2605404169953545, + 1.2611021249977057, + 1.261623916994722, + 1.262161250000645, + 1.2627002090011956, + 1.2632633749963134, + 1.2638412499945844, + 1.2644394589951844, + 1.2649982500006445, + 1.2655590840004152, + 1.2660696249949979, + 1.2666381249946426, + 1.2672137499976088, + 1.2677488339977572, + 1.2682942920000642, + 1.2688080840016482, + 1.2693546250011423, + 1.269945583997469, + 1.2705009589990368, + 1.271045666995633, + 1.2715517920005368, + 1.2720452499997918, + 1.2725888339991798, + 1.2731730839950615, + 1.273701666999841, + 1.2742105840006843, + 1.2748616249955376, + 1.275460208998993, + 1.2760816250010976, + 1.2766827500017826, + 1.2772770839947043, + 1.2778212919947691, + 1.2783620420013904, + 1.27890437500173, + 1.2794675839977572, + 1.2799927499945625, + 1.2805184169992572, + 1.281110042000364, + 1.2816771249999874, + 1.282263791996229, + 1.2828171250002924, + 1.283364041999448, + 1.283922458998859, + 1.2844860420009354, + 1.2850113339954987, + 1.2855362920017797, + 1.2860728749947157, + 1.28661424999882, + 1.2871689999956288, + 1.2877010839947616, + 1.2882391669991193, + 1.288868999996339, + 1.2895046669946169, + 1.2901279590005288, + 1.2907888339977944, + 1.2914427089999663, + 1.292051917000208, + 1.292658541999117, + 1.293282624996209, + 1.2939027499960503, + 1.2945543749956414, + 1.295273208997969, + 1.2959952919991338, + 1.2966428340005223, + 1.2972460419987328, + 1.2978759999969043, + 1.2984653339954093, + 1.2990772499979357, + 1.2996862500003772, + 1.3003092919971095, + 1.30096920899814, + 1.3015712089982117, + 1.3022590839973418, + 1.3029081669956213, + 1.3035324589945958, + 1.3042123339982936, + 1.3048429589980515, + 1.3054583339981036, + 1.3061065419969964, + 1.3066964999961783, + 1.3073108339958708, + 1.3079190839998773, + 1.3085466670017922, + 1.3091453339948202, + 1.3097836669985554, + 1.31041974999971, + 1.3111912089952966, + 1.3118039999972098, + 1.3124182920000749, + 1.312981374998344, + 1.3136109999977634, + 1.3142689169981168, + 1.3148822919974918, + 1.3155675000016345, + 1.316334333998384, + 1.316997124995396, + 1.3177425419999054, + 1.3184458339965204, + 1.319090334000066, + 1.3197287090006284, + 1.3204170419994625, + 1.3210571249946952, + 1.3216874589998042, + 1.3223166669995408, + 1.3229537919978611, + 1.3235865839960752, + 1.3242300839992822, + 1.3248337920013, + 1.3254365419998066, + 1.326085583998065, + 1.3268137919949368, + 1.3273964589971001, + 1.328028791998804, + 1.3286529589968268, + 1.329278583994892, + 1.3299015419979696, + 1.330610708995664, + 1.331286499997077, + 1.3320259169995552, + 1.3326614589968813, + 1.3333040419965982, + 1.3340343339950778, + 1.3347014999962994, + 1.3353991670010146, + 1.3361687090000487, + 1.3368448749970412, + 1.3374528749991441, + 1.3381050839961972, + 1.3387304589996347, + 1.3393878339993535, + 1.3400031669953023, + 1.3406193749979138, + 1.3412325419994886, + 1.341954083996825, + 1.3425796250012354, + 1.3431827919994248, + 1.343796333996579, + 1.3444541669960017, + 1.3450788339978317, + 1.3456730420002714, + 1.3462752919949708, + 1.3469537499986473, + 1.3476839590002783, + 1.3483969169974444, + 1.3490780419961084, + 1.3498173339976347, + 1.3505214999968302, + 1.3511727090008208, + 1.352095083995664, + 1.3527846669967403, + 1.3534679590011365, + 1.3541255839954829, + 1.3548870000013267, + 1.3554712920013117, + 1.3561424169965903, + 1.3567780419980409, + 1.3574068339949008, + 1.3580665420013247, + 1.358687749998353, + 1.3593352919997415, + 1.3599750840003253, + 1.3606123749996186, + 1.361250249996374, + 1.3618863340016105, + 1.3624794999996084, + 1.3631446250001318, + 1.363798874997883, + 1.3644549169985112, + 1.365073916997062, + 1.3657244169953628, + 1.3663469169987366, + 1.3669885419949424, + 1.3676328340006876, + 1.3682174589994247, + 1.3688217499948223, + 1.369476333995408, + 1.3700511249990086, + 1.3706658750015777, + 1.3712894169948413, + 1.3719071250015986, + 1.372679916996276, + 1.3733152499989956, + 1.373964624996006, + 1.3746581669984153, + 1.3754292500016163, + 1.3760935839964077, + 1.3767667499996605, + 1.3774053339948296, + 1.378130124998279, + 1.3788422500001616, + 1.3794454999951995, + 1.3800793749978766, + 1.3807607499984442, + 1.381429583998397, + 1.38207170899841, + 1.3826693750015693, + 1.3832749590001185, + 1.3838771669979906, + 1.384402042000147, + 1.3849677089965553, + 1.3855049589983537, + 1.38616304199968, + 1.386702374999004, + 1.3872478749981383, + 1.387820666997868, + 1.388354458998947, + 1.3889157919984427, + 1.3894269169977633, + 1.3899692089980817, + 1.3904647499948624, + 1.3909984589990927, + 1.3915656669996679, + 1.3922748749973834, + 1.392858333994809, + 1.3934668340007192, + 1.3940584169977228, + 1.3946189999987837, + 1.3951474589994177, + 1.3957025419949787, + 1.3961985419955454, + 1.3967372499973862, + 1.3972735839997767, + 1.397849208995467, + 1.398436416995537, + 1.3990186250011902, + 1.3995663339956081, + 1.4000689999957103, + 1.4005768339993665, + 1.4011260839979514, + 1.4017101249992265, + 1.4022688339973683, + 1.4028213749988936, + 1.40335999999661, + 1.4038968339955318, + 1.4044361669948557, + 1.4049958339965087, + 1.405526791997545, + 1.406044709001435, + 1.406573959000525, + 1.407132416999957, + 1.407591750001302, + 1.4081838749989402, + 1.4088826669976697, + 1.4094666249948204, + 1.4099940419982886, + 1.410538167001505, + 1.4110924589986098, + 1.4116490000014892, + 1.4123321250008303, + 1.4136496249993797, + 1.4144407919957303, + 1.4150045839996892, + 1.415583041998616, + 1.4161643339975853, + 1.4167001669993624, + 1.4172748749988386, + 1.417976999997336, + 1.4185413339946535, + 1.4191200839995872, + 1.4196129170013592, + 1.4201409589950345, + 1.420702709001489, + 1.4212284169989289, + 1.4217647499972372, + 1.422286916997109, + 1.4229365419960232, + 1.4235004169968306, + 1.424080500000855, + 1.4247054169973126, + 1.4252419589975034, + 1.4257924999983516, + 1.4263814169971738, + 1.4269428339976002, + 1.427514874994813, + 1.42807133399765, + 1.4286194169981172, + 1.4291549589979695, + 1.4296813339969958, + 1.4302062499991735, + 1.4309234169995761, + 1.4315840839990415, + 1.432223083997087, + 1.4329272089962615, + 1.433550916997774, + 1.4341135840004426, + 1.4347067919952678, + 1.4352171669961535, + 1.4357566670005326, + 1.4363316669987398, + 1.4369185420000576, + 1.437523084001441, + 1.4380882499972358, + 1.4386299170000711, + 1.4391875419969438, + 1.4398365419983747, + 1.4403710839978885, + 1.4409528339965618, + 1.4415049589952105, + 1.441968209001061, + 1.4424924999984796, + 1.44306904199766, + 1.4436022919981042, + 1.4441512919947854, + 1.4446509589979541, + 1.445224083996436, + 1.44573649999802, + 1.4462700840012985, + 1.4468518339999719, + 1.4474241249990882, + 1.4479812089994084, + 1.4485511669990956, + 1.4491365419962676, + 1.4496899169971584, + 1.4503064589953283, + 1.450908624996373, + 1.4515173339968896, + 1.4521191669991822, + 1.452692708997347, + 1.453289874996699, + 1.4538309589988785, + 1.4544241670009797, + 1.4550381669978378, + 1.455581958995026, + 1.4561701249986072, + 1.4567216249997728, + 1.4572209589969134, + 1.4580174169968814, + 1.4586678339983337, + 1.4592330000014044, + 1.4597894170001382, + 1.460292458999902, + 1.4608042920008302, + 1.4613101249997271, + 1.4618813339984627, + 1.4623908749999828, + 1.4629336250000051, + 1.4634487090006587, + 1.463983791996725, + 1.4645037919981405, + 1.4650150000015856, + 1.4655564589993446, + 1.4661307919959654, + 1.4666817499964964, + 1.4672365419974085, + 1.4677664999981062, + 1.468296792001638, + 1.4688962919972255, + 1.4694374169994262, + 1.4700377920016763, + 1.4706266669963952, + 1.4712653339956887, + 1.4718628749978961, + 1.47245433399803, + 1.4729963749996386, + 1.4735315840007388, + 1.4740762090004864, + 1.4746179590001702, + 1.475139374997525, + 1.4756670419956208, + 1.4762113339966163, + 1.4767735419954988, + 1.4773392499992042, + 1.4778850000002421, + 1.478550166997593, + 1.4792337920007412, + 1.4798789999986184, + 1.4804977089952445, + 1.4811552920000395, + 1.4818036669967114, + 1.48243562499556, + 1.4830682920000982, + 1.4836341670015827, + 1.4842722920002416, + 1.4849206669969135, + 1.485530124999059, + 1.486187249996874, + 1.4868179999975837, + 1.4874400839980808, + 1.4880873750007595, + 1.4886964170000283, + 1.489344624998921, + 1.490006583997456, + 1.4907569999995758, + 1.491376041994954, + 1.491992625000421, + 1.4926253340017865, + 1.4932702090009116, + 1.4939670419989852, + 1.4946176669982378, + 1.4952702500013402, + 1.4958862919957028, + 1.4965148749979562, + 1.4971455839986447, + 1.497758833997068, + 1.4984235419979086, + 1.4990987919954932, + 1.4997608749981737, + 1.5003867089981213, + 1.5010199999960605, + 1.5017268340016017, + 1.5023719589953544, + 1.5029653749952558, + 1.5036237919994164, + 1.5042584589973558, + 1.5049054999981308, + 1.5055233749953914, + 1.5061589589968207, + 1.5069078339947737, + 1.5075689169971156, + 1.508227458994952, + 1.508996833996207, + 1.5096572920010658, + 1.5103570419960306, + 1.5110185839948826, + 1.5116251669969643, + 1.5122630839978228, + 1.5129090420014109, + 1.513551791998907, + 1.514241459000914, + 1.5148874590013293, + 1.515533375000814, + 1.5161280839965912, + 1.5167648749993532, + 1.517357833996357, + 1.5179984999995213, + 1.518634749998455, + 1.519407333995332, + 1.520032499996887, + 1.5206613749978715, + 1.5212584589971812, + 1.5218913339995197, + 1.5225181249988964, + 1.5231273749959655, + 1.5237440839991905, + 1.5243762499958393, + 1.5249969590004184, + 1.5256462920006015, + 1.526277917000698, + 1.5269249589982792, + 1.5275383339976543, + 1.5281886250013486, + 1.5289419170003384, + 1.5296259999959148, + 1.5303376669980935, + 1.5309977919969242, + 1.5316295839947998, + 1.5322360840000329, + 1.5328986249951413, + 1.5335609999965527, + 1.534160333998443, + 1.534772792001604, + 1.5354358749973471, + 1.5360400839999784, + 1.5366694999975152, + 1.5373150000013993, + 1.5379704590013716, + 1.5385813339962624, + 1.5392007499976899, + 1.5399261249986012, + 1.5405664589998196, + 1.5412045420016511, + 1.5418714589977753, + 1.5425397919971147, + 1.5431624999982887, + 1.5437725000010687, + 1.5444048749996, + 1.5450314999980037, + 1.5456554999982473, + 1.5462667920000968, + 1.5469007919964497, + 1.5476044169990928, + 1.5482715420002933, + 1.5489810419967398, + 1.5497316249966389, + 1.5503614170011133, + 1.550990042000194, + 1.5516207089967793, + 1.552245958999265, + 1.5529106670001056, + 1.5535424999980023, + 1.5541901249962393, + 1.5548218749972875, + 1.555560125001648, + 1.5562088340011542, + 1.5568271669981186, + 1.557510792001267, + 1.5581467500014696, + 1.5587555839956622, + 1.5593844999966677, + 1.5600651669956278, + 1.5606865000008838, + 1.5612854589999188, + 1.5619313749994035, + 1.562565000000177, + 1.5631894170001033, + 1.5638282500003697, + 1.5644296249956824, + 1.5650728339969646, + 1.565700333994755, + 1.5663188749967958, + 1.5670308339977055, + 1.5677264999976614, + 1.5683723339971039, + 1.5690344999966328, + 1.569673291996878, + 1.5702907500017318, + 1.5709480840014294, + 1.5716179169976385, + 1.5722472089983057, + 1.5729307090005022, + 1.5735405419982271, + 1.5742111250001471, + 1.5751691249970463, + 1.5758283749964903, + 1.57651249999617, + 1.5771892499979003, + 1.5778638339979807, + 1.578496208996512, + 1.5791265840016422, + 1.5797319170014816, + 1.5803650839952752, + 1.581007041997509, + 1.5816650839988142, + 1.582286374999967, + 1.5829112499995972, + 1.5835321249978733, + 1.5841806669996004, + 1.5849832089952542, + 1.5856165000004694, + 1.5863114999956451, + 1.5869520419946639, + 1.5875692920017173, + 1.588313084001129, + 1.5890724999990198, + 1.5897353749969625, + 1.5904859169968404, + 1.5912000419994001, + 1.5918447090007248, + 1.592480125000293, + 1.593090124995797, + 1.593729333995725, + 1.5943348340006196, + 1.5950199169965344, + 1.5956645839978592, + 1.596281583995733, + 1.5969766669950332, + 1.5976107919996139, + 1.5982325000004494, + 1.598857749995659, + 1.5995154170013848, + 1.600152667000657, + 1.600785916998575, + 1.6014334999999846, + 1.60206725000171, + 1.6027029589968151, + 1.6034129170002416, + 1.6040367919995333, + 1.604654083996138, + 1.6052982499968493, + 1.605910458994913, + 1.6065525000012713, + 1.6071908340018126, + 1.6078023340014624, + 1.6084409589966526, + 1.6090889170009177, + 1.6097667499998352, + 1.6104555839992827, + 1.6111679999958142, + 1.6118268339996575, + 1.6124749590017018, + 1.6131329589989036, + 1.613785875000758, + 1.614454416994704, + 1.6152504999990924, + 1.6159151249958086, + 1.6165919999984908, + 1.6172299169993494, + 1.6179111669989652, + 1.6185699589987053, + 1.6191961669974262, + 1.6198548749962356, + 1.6205087089983863, + 1.621192083999631, + 1.621801624998625, + 1.6224010000005364, + 1.6230613750012708, + 1.6236969589954242, + 1.6243226669976139, + 1.624979499996698, + 1.62563691700052, + 1.6263237089951872, + 1.6269888749957317, + 1.6276494170015212, + 1.6283483750012238, + 1.6289936249959283, + 1.6296795000016573, + 1.6303297089980333, + 1.6309868749958696, + 1.6316130839986727, + 1.6322312919946853, + 1.632926583995868, + 1.633619333995739, + 1.6342510419999599, + 1.634894541995891, + 1.63553208400117, + 1.636174209001183, + 1.6368004999967525, + 1.637413500000548, + 1.6380069169972558, + 1.638679208997928, + 1.6392991249958868, + 1.6399425839990727, + 1.640580458995828, + 1.6412566250000964, + 1.6418880839992198, + 1.6425312089995714, + 1.6432087919965852, + 1.643834958995285, + 1.6444832919951295, + 1.6452472919991123, + 1.6458418339971104, + 1.646473374996276, + 1.6471246669971151, + 1.6478015839966247, + 1.6484606669982895, + 1.64925137499813, + 1.6499578750008368, + 1.6505722500005504, + 1.6511867090011947, + 1.6518306669968297, + 1.65247833399917, + 1.6530996250003227, + 1.65372433399898, + 1.6543572500013397, + 1.6549952089990256, + 1.6556665419993806, + 1.6563658749946626, + 1.6570087500003865, + 1.6576704170001904, + 1.6582964999979595, + 1.6589588339993497, + 1.6596261669983505, + 1.6602825419977307, + 1.660918417001085, + 1.661540666995279, + 1.6621902089973446, + 1.6629301669963752, + 1.6636615419993177, + 1.6643233340000734, + 1.664957916997082, + 1.6655765839968808, + 1.6661944590014173, + 1.6668715839987271, + 1.6675576669949805, + 1.6682629999995697, + 1.6689447919998202, + 1.6696356249958626, + 1.6702604999954929, + 1.6709267499973066, + 1.6715401249966817, + 1.672224499998265, + 1.6729037089971825, + 1.6735405840008752, + 1.6742134169981, + 1.6748559589977958, + 1.675454958996852, + 1.67608316699625, + 1.6767048339970643, + 1.6773298339976463, + 1.6779608340002596, + 1.6785796670010313, + 1.6791727499949047, + 1.6798542499964242, + 1.680560417000379, + 1.6811930420008139, + 1.6818483749957522, + 1.682451583998045, + 1.6830419589969097, + 1.6835939999946277, + 1.6842428749951068, + 1.684873250000237, + 1.685515042001498, + 1.6861189589981223, + 1.6868562499948894, + 1.6875933749979595, + 1.6883165839972207, + 1.6889672499964945, + 1.6896122089965502, + 1.6902113749965793, + 1.6908601249961066, + 1.6915023339970503, + 1.692137999998522, + 1.6928047920009703, + 1.6934226669982309, + 1.694010667000839, + 1.6946137089980766, + 1.6952499589970103, + 1.6958955419977428, + 1.6965394169965293, + 1.6972162919992115, + 1.6978512499990757, + 1.6985184590012068, + 1.6991562499970314, + 1.6997785839994322, + 1.7003837500014924, + 1.7010051249962999, + 1.7016757499950472, + 1.7022978749955655, + 1.7029546669946285, + 1.7036315419973107, + 1.704288084001746, + 1.7049497089974466, + 1.705566208998789, + 1.706216583996138, + 1.7068482089962345, + 1.7075399169989396, + 1.7082680839957902, + 1.7089494589963579, + 1.7096124589952524, + 1.7102394999965327, + 1.7110218749949127, + 1.7116449589957483, + 1.7122797499978333, + 1.7129070419978234, + 1.713622208997549, + 1.7142510839985334, + 1.7149217089972808, + 1.7155402089993004, + 1.716168041995843, + 1.7168052499982878, + 1.7174305000007735, + 1.7180724169957102, + 1.7188415839991649, + 1.7195056669952464, + 1.720166999999492, + 1.720821041999443, + 1.7214531669960706, + 1.722070416995848, + 1.7226659169973573, + 1.7233117499999935, + 1.723937709000893, + 1.72459162499581, + 1.7253572920017177, + 1.7261682089956594, + 1.7268398749947664, + 1.7275527089950629, + 1.7282505839975784, + 1.72891558399715, + 1.7295460419991286, + 1.7301421250012936, + 1.7307670839945786, + 1.7314268339978298, + 1.732052916995599, + 1.7326703340004315, + 1.733309791998181, + 1.7339829999982612, + 1.7345662500010803, + 1.735192084001028, + 1.7358399590011686, + 1.7364688749948982, + 1.7371367500018096, + 1.7377769589948002, + 1.7384155839972664, + 1.7390496250009164, + 1.7397578339950996, + 1.7404340419961954, + 1.7410581250005635, + 1.7417002090005553, + 1.7422979999973904, + 1.7429970000011963, + 1.7436507919992437, + 1.7442617089982377, + 1.7450012499975855, + 1.7456698749956558, + 1.7462487500015413, + 1.746932083995489, + 1.7475612919952255, + 1.748214499995811, + 1.748924084000464, + 1.7495565419958439, + 1.7501748750000843, + 1.7507732919984846, + 1.7513673749999725, + 1.7520100839974475, + 1.7527947089984082, + 1.7534503339993535, + 1.7540851669982658, + 1.7547313749964815, + 1.755334417000995, + 1.7559890839984291, + 1.7567474999959813, + 1.757394583997666, + 1.758008124998014, + 1.7586565419987892, + 1.759316541996668, + 1.7600302919963724, + 1.7606821669978672, + 1.761327791995427, + 1.7619243750013993, + 1.7625729999999749, + 1.7632357089969446, + 1.763817166996887, + 1.764621124995756, + 1.7653024999963236, + 1.7660375839986955, + 1.7667097919984371, + 1.767314874996373, + 1.767958999997063, + 1.7685916670016013, + 1.7693399999989197, + 1.769950958994741, + 1.7705614590013283, + 1.7711794999995618, + 1.7718285839946475, + 1.7724723339997581, + 1.77314808400115, + 1.773834416999307, + 1.7745019590001903, + 1.7751577919989359, + 1.7757846669992432, + 1.776398292000522, + 1.777001416994608, + 1.777619833999779, + 1.778229958996235, + 1.7788464999975986, + 1.7795333749963902, + 1.7801951669971459, + 1.7808357089961646, + 1.7814741670008516, + 1.782084833997942, + 1.7826824169969768, + 1.7832797090013628, + 1.7839740419949521, + 1.7846388749967446, + 1.7853442919949885, + 1.7860407089974615, + 1.7866710419984884, + 1.7872852919972502, + 1.7879169590014499, + 1.7885577919951174, + 1.7891942089991062, + 1.7897803339947131, + 1.7903538339960505, + 1.791020374999789, + 1.7916487920010695, + 1.792317291998188, + 1.7929872919994523, + 1.7936172499976237, + 1.794249916994886, + 1.7948514169984264, + 1.7954929170009564, + 1.7961029169964604, + 1.796714833995793, + 1.7973910840009921, + 1.7979805840004701, + 1.7985746249978547, + 1.79917379199469, + 1.7997988339993753, + 1.8004158339972491, + 1.8010309999954188, + 1.8016410419950262, + 1.8022555419956916, + 1.80286150000029, + 1.803517959000601, + 1.8041715419967659, + 1.8049115839967271, + 1.805572334000317, + 1.806217208999442, + 1.8068080000011832, + 1.8074158339950372, + 1.8080439589975867, + 1.8086898339970503, + 1.8093114590010373, + 1.8099464589977288, + 1.8105217089978396, + 1.811170791996119, + 1.8117486249975627, + 1.812382999996771, + 1.813003833995026, + 1.8136042499972973, + 1.8142093749993364, + 1.814818541999557, + 1.815405583998654, + 1.8160379999972065, + 1.8166410839985474, + 1.8172732499951962, + 1.8178796669963049, + 1.8185024999984307, + 1.8190970419964287, + 1.8197242919995915, + 1.8203339999963646, + 1.82099316699896, + 1.8215848749969155, + 1.82235049999872, + 1.8230836250004359, + 1.8237330420015496, + 1.8244178339955397, + 1.8250224590010475, + 1.825705499999458, + 1.8263762919959845, + 1.8270402919952176, + 1.8276505839967285, + 1.8282931249996182, + 1.8289365419987007, + 1.8295690419981838, + 1.830227541999193, + 1.8308611669999664, + 1.831544833999942, + 1.832175333998748, + 1.8327829589979956, + 1.8333796250008163, + 1.8340094169980148, + 1.8346163339956547, + 1.835294459000579, + 1.8359068749996368, + 1.8365175840008305, + 1.8371220839981106, + 1.8377323339955183, + 1.8383314589955262, + 1.8389366670016898, + 1.8395683749986347, + 1.8401958749964251, + 1.840871166998113, + 1.8414869170010206, + 1.8420716249966063, + 1.8428492499951972, + 1.843561541994859, + 1.8442801669953042, + 1.84493233399553, + 1.8455616669962183, + 1.846171459001198, + 1.8468012500015902, + 1.8474052919991664, + 1.848150291996717, + 1.8487552919978043, + 1.849433458999556, + 1.8500257499981672, + 1.8506568750017323, + 1.85124937499495, + 1.8518174169948907, + 1.8524277499964228, + 1.8530664999998407, + 1.8536962500002119, + 1.8543125840005814, + 1.854988916995353, + 1.8556246669977554, + 1.8562284169966006, + 1.856850874995871, + 1.857476791999943, + 1.858112458998221, + 1.8587266249960521, + 1.8593478749971837, + 1.8600172919977922, + 1.8605852499968023, + 1.8611777089972747, + 1.8618673749951995, + 1.8625584589972277, + 1.8632084589989972, + 1.863905166996119, + 1.8645202499974403, + 1.8651836249991902, + 1.8658127089947811, + 1.8664314589987043, + 1.8671035840015975, + 1.8677640839960077, + 1.868420166996657, + 1.8690359589963919, + 1.8696510000008857, + 1.8703827089993865, + 1.871035167001537, + 1.8716392499991343, + 1.8722252500010654, + 1.8728453750009066, + 1.873440124996705, + 1.8740464590009651, + 1.874698499996157, + 1.875336791999871, + 1.8760366249989602, + 1.8766574589972151, + 1.8772564589962712, + 1.8779169589979574, + 1.878550458997779, + 1.879191374995571, + 1.8798369590003858, + 1.8804563749945373, + 1.8812369590013986, + 1.8819140839987085, + 1.8825759999963338, + 1.8831919169970206, + 1.883840666996548, + 1.8844881249970058, + 1.8851414589953492, + 1.8858052499999758, + 1.8864776670016, + 1.8870725839951774, + 1.8876717919993098, + 1.8883539169983123, + 1.8889737089994014, + 1.8895941250011674, + 1.8902161250007339, + 1.890851208998356, + 1.8914716669969494, + 1.8920582919963636, + 1.8926806249946821, + 1.893313249995117, + 1.8939072919965838, + 1.894505083997501, + 1.8951264589995844, + 1.89574724999693, + 1.8964810839970596, + 1.8970944589964347, + 1.8977076250012033, + 1.8982501669961493, + 1.8989468750005472, + 1.8995346250012517, + 1.9002181249961723, + 1.900826541997958, + 1.9015068340013386, + 1.9023311249984545, + 1.9031094589954591, + 1.903777416999219, + 1.9044828339974629, + 1.905194416998711, + 1.9058069169986993, + 1.9064652499946533, + 1.9070947500003967, + 1.9076864999951795, + 1.9082953749966691, + 1.9089764169984846, + 1.909610041999258, + 1.910260083997855, + 1.910933416998887, + 1.9116074589983327, + 1.9122369589968002, + 1.9129247499949997, + 1.913721833996533, + 1.9144234170016716, + 1.915077833997202, + 1.915669166999578, + 1.9162553339992883, + 1.9168577089949395, + 1.9173674999983632, + 1.9179421669978183, + 1.918551666996791, + 1.919086541995057, + 1.919605874994886, + 1.9202367089965264, + 1.9209106669950415, + 1.921459249999316, + 1.9220155000002705, + 1.9225694999986445, + 1.9232027089965413, + 1.923776874995383, + 1.9243974999990314, + 1.9249607919991831, + 1.9255580839962931, + 1.9261448339966591, + 1.926708166996832, + 1.9272678749985062, + 1.9278271669973037, + 1.9283839169947896, + 1.9289506249988335, + 1.929482667001139, + 1.9300097500017728, + 1.9305909589966177, + 1.9311452920010197, + 1.9317005839984631, + 1.9322635839998838, + 1.932813791994704, + 1.9334004999982426, + 1.9339611249961308, + 1.934489624996786, + 1.9350347090003197, + 1.9356454590015346, + 1.936203666999063, + 1.93686904200149, + 1.9374227919979603, + 1.9379681669961428, + 1.938504792000458, + 1.939044874998217, + 1.9395697500003735, + 1.9400838340006885, + 1.940613624996331, + 1.9411819589950028, + 1.9417456250012037, + 1.9423319999987143, + 1.9429950420017121, + 1.9436475839975174, + 1.9442004169977736, + 1.944765208994795, + 1.945326875000319, + 1.9459266669946373, + 1.9464639169964357, + 1.9470173340014298, + 1.9475764999951934, + 1.94813137500023, + 1.9487183749952237, + 1.9492961669966462, + 1.9498457919980865, + 1.950407541997265, + 1.950998708998668, + 1.9516152500000317, + 1.952281416997721, + 1.95295674999943, + 1.9536393339949427, + 1.9542450000008103, + 1.9548603340008412, + 1.955497958995693, + 1.9561323339949013, + 1.956741249996412, + 1.9574487089994363, + 1.9581409169986728, + 1.958747124997899, + 1.9593903749992023, + 1.9600151249978808, + 1.960636167001212, + 1.9613014169954113, + 1.9620383750007022, + 1.9627291249998962, + 1.9634468750009546, + 1.9640757919987664, + 1.9647646250014077, + 1.965372375001607, + 1.9660365839954466, + 1.9666655839973828, + 1.967315834001056, + 1.9679787499990198, + 1.9686404999956721, + 1.9692725839995546, + 1.9699262919966714, + 1.9705489170009969, + 1.9712230840013945, + 1.971842333994573, + 1.9724850419952418, + 1.973160875000758, + 1.9737916250014678, + 1.9744091669999762, + 1.9750515839987202, + 1.9756633340002736, + 1.976278292000643, + 1.976925625000149, + 1.977575999997498, + 1.9781925419956679, + 1.978781291996711, + 1.9793703749965061, + 1.9800065839954186, + 1.9806049170001643, + 1.9813431669972488, + 1.9820435000001453, + 1.982761125000252, + 1.9835258339953725, + 1.984196500001417, + 1.984819500001322, + 1.985501833994931, + 1.9861968339973828, + 1.9868640419954318, + 1.9876318339956924, + 1.9883305420007673, + 1.9890279169994756, + 1.9897307919964078, + 1.9903988750011194, + 1.9910915840009693, + 1.9918024169965065, + 1.9924927089959965, + 1.9931942089970107, + 1.9938921249995474, + 1.994519959000172, + 1.9950598340001306, + 1.9956069999971078, + 1.9963096669962397, + 1.9968762499993318, + 1.9974873749961262, + 1.9980406670001685, + 1.9986212919975515, + 1.9991899999949965, + 1.999735666999186, + 2.0003397920008865, + 2.0009733339975355, + 2.0015636249954696, + 2.0021650419948855, + 2.0028221249958733, + 2.003454541998508, + 2.00410383399867, + 2.0046651250013383, + 2.005193208999117, + 2.0058184169974993, + 2.006396416996722, + 2.0069337919994723, + 2.007513584001572, + 2.008081542000582, + 2.0085585419947165, + 2.0090853750007227, + 2.0096080000002985, + 2.01014129199757, + 2.0106543340007192, + 2.0112516669978504, + 2.01179904199671, + 2.013785541996185, + 2.0143562500015832, + 2.0148572089965455, + 2.0153884169994853, + 2.015895124997769, + 2.0163846249997732, + 2.016907999997784, + 2.0174160839960678, + 2.0179705420014216, + 2.018484374995751, + 2.0191675839960226, + 2.0200431249977555, + 2.0207736250013113, + 2.021395374998974, + 2.022030000000086, + 2.022591291999561, + 2.0231362499980605, + 2.0236199169958127, + 2.024146916999598, + 2.024816583994834, + 2.025440459001402, + 2.0260013340011938, + 2.0265279589948477, + 2.0272515839969856, + 2.0278208749950863, + 2.0283937499989406, + 2.028926083999977, + 2.0295043750011246, + 2.030135708999296, + 2.030729624995729, + 2.0313045000002603, + 2.0318943339952966, + 2.032488042001205, + 2.033016041998053, + 2.033555875001184, + 2.0341558340005577, + 2.03469524999673, + 2.0352377089948277, + 2.0358087919958052, + 2.0363926669961074, + 2.0370092500015744, + 2.037530292000156, + 2.0380306669976562, + 2.0385915000006207, + 2.039142458997958, + 2.039778458994988, + 2.040440500000841, + 2.0410783749975963, + 2.04178470899933, + 2.042392709001433, + 2.0429833339949255, + 2.0435610419954173, + 2.0441462919989135, + 2.044698999998218, + 2.045296791999135, + 2.0458168749973993, + 2.0463481249971665, + 2.0468557919957675, + 2.04737870900135, + 2.0479297089987085, + 2.048506916995393, + 2.0490304170016316, + 2.0495709169990732, + 2.0500880839972524, + 2.050686875001702, + 2.0512426249988494, + 2.051769166995655, + 2.052300292001746, + 2.052869084000122, + 2.0534252500001458, + 2.0540105420004693, + 2.0545604169965372, + 2.0551122920005582, + 2.055687333995593, + 2.056235124997329, + 2.0567707090012846, + 2.057311208998726, + 2.0578221670002677, + 2.0583356249990175, + 2.0588818339965655, + 2.059503666998353, + 2.060066708996601, + 2.0606757499990636, + 2.0612223749994882, + 2.0617930840016925, + 2.0623267919945647, + 2.0629228339967085, + 2.0635012919956353, + 2.064029749999463, + 2.0645887089995085, + 2.065159792000486, + 2.065732916998968, + 2.0662699169988628, + 2.0668197919949307, + 2.067357041996729, + 2.0679012089967728, + 2.0684259589979774, + 2.0689786250004545, + 2.0695248339980026, + 2.070103250000102, + 2.0706971249965136, + 2.0712577090016566, + 2.07180245899508, + 2.0723764169961214, + 2.0729004589957185, + 2.073450708994642, + 2.073990541997773, + 2.0745090839991462, + 2.0750440420015366, + 2.075668334000511, + 2.0762243749995832, + 2.0767777919973014, + 2.077343042001303, + 2.0779707089968724, + 2.0788299170017126, + 2.0795127499950468, + 2.0801436249967082, + 2.080700667000201, + 2.0812552499992307, + 2.0818168339974363, + 2.082369625000865, + 2.0829255419957917, + 2.08343587499985, + 2.0839829169999575, + 2.0845240419948823, + 2.0850624589947984, + 2.0856222919974243, + 2.0861580839991802, + 2.086720791994594, + 2.0872295840017614, + 2.087732583997422, + 2.088305291996221, + 2.088864375000412, + 2.0894325420013047, + 2.089996834001795, + 2.0905434169981163, + 2.0910797089964035, + 2.091618541999196, + 2.0922435839966056, + 2.0928162089985562, + 2.0933883339966997, + 2.0939302089973353, + 2.094468416995369, + 2.094985874995473, + 2.0955185419952613, + 2.0960540839951136, + 2.0966631249975762, + 2.097327541996492, + 2.098019334000128, + 2.098652000000584, + 2.099254666994966, + 2.099795374997484, + 2.100343749996682, + 2.1009138750014245, + 2.1014847499973257, + 2.102051208996272, + 2.1025475839996943, + 2.1031256249989383, + 2.1036252499980037, + 2.1041888749969075, + 2.104755208994902, + 2.1053065000014612, + 2.1058275420000427, + 2.1063417089972063, + 2.106925667001633, + 2.107522209000308, + 2.1080692499963334, + 2.108613416996377, + 2.1091971249989, + 2.1096967499979655, + 2.1102189169978374, + 2.11079933399742, + 2.111370958999032, + 2.1119528339986573, + 2.112504791999527, + 2.1130284999962896, + 2.1135916669954895, + 2.1141692089950084, + 2.114904124995519, + 2.115570417001436, + 2.1163805420001154, + 2.1170147090015234, + 2.1176259589992696, + 2.118269999999029, + 2.118896959000267, + 2.119473749997269, + 2.1200656250002794, + 2.120613166996918, + 2.121160083996074, + 2.121679749994655, + 2.1222287919954397, + 2.1228419999970356, + 2.123413499997696, + 2.123943499995221, + 2.124538833995757, + 2.1251274589958484, + 2.1256642090011155, + 2.126185749999422, + 2.126775833996362, + 2.127285167000082, + 2.1278729589976138, + 2.1284264589994564, + 2.128961624999647, + 2.1295041249977658, + 2.1300441669955035, + 2.1305696249983157, + 2.1310804589957115, + 2.1316156670000055, + 2.132160417000705, + 2.1327406669952325, + 2.1332661249980447, + 2.1338462499988964, + 2.134384749995661, + 2.134917167000822, + 2.1354838749975897, + 2.136075416994572, + 2.136727791999874, + 2.1373045000000275, + 2.137902666996524, + 2.13846754199767, + 2.1390515839957516, + 2.139585958997486, + 2.1401186250004685, + 2.1406444999956875, + 2.1411576669997885, + 2.14171387499664, + 2.1422618750002584, + 2.1427791669993894, + 2.143286583996087, + 2.1438738750002813, + 2.1444231669956935, + 2.1449629589988035, + 2.14565058399603, + 2.1461864999946556, + 2.1467602089978755, + 2.147301500001049, + 2.1478489590008394, + 2.148394999996526, + 2.148950666996825, + 2.149498999999196, + 2.1500735000008717, + 2.150623417001043, + 2.1511589590008953, + 2.1517082919963286, + 2.1522522090017446, + 2.152767125000537, + 2.153303209001024, + 2.1538535419967957, + 2.1543809169961605, + 2.1549869590016897, + 2.155509833995893, + 2.156156249999185, + 2.1566959589981707, + 2.157300833998306, + 2.15792504199635, + 2.1584777919997578, + 2.15901483399648, + 2.1595390840011532, + 2.1600332089947187, + 2.1605763749976177, + 2.161125416998402, + 2.161632124996686, + 2.1622039590001805, + 2.162753791999421, + 2.1632942919968627, + 2.1639452089948463, + 2.1645498750003753, + 2.1650852089951513, + 2.165628791997733, + 2.166124374998617, + 2.166680208996695, + 2.1671900000001187, + 2.16775216699898, + 2.168267166998703, + 2.1688145000007353, + 2.169365124995238, + 2.169888042000821, + 2.1704295839954284, + 2.1710026250002556, + 2.1715622919946327, + 2.1721548339992296, + 2.172687166996184, + 2.17323370899976, + 2.1738084999960847, + 2.174341291996825, + 2.1748992499997257, + 2.1754740420001326, + 2.1761724589960068, + 2.1767455419976613, + 2.177329666999867, + 2.1778832919953857, + 2.1784556669954327, + 2.1790007499948842, + 2.179603999997198, + 2.180159666997497, + 2.180715083995892, + 2.1812428339981125, + 2.181759916995361, + 2.18228408399591, + 2.1828164589969674, + 2.183351916995889, + 2.183914041997923, + 2.1844627919999766, + 2.1851557920017513, + 2.1856772499959334, + 2.1862225840013707, + 2.186849166995671, + 2.1873873340009595, + 2.187944666999101, + 2.1884844589949353, + 2.189072542001668, + 2.1896113749971846, + 2.190190333996725, + 2.1907068750006147, + 2.1912388339987956, + 2.191799041997001, + 2.192352749996644, + 2.192913499995484, + 2.1935030839958927, + 2.194046584001626, + 2.194632708997233, + 2.1953052499957266, + 2.195978291994834, + 2.196548416999576, + 2.1971489589996054, + 2.197699083997577, + 2.1982855839960393, + 2.1988362499978393, + 2.199393292001332, + 2.1999551249973592, + 2.2005108340017614, + 2.2010833749955054, + 2.2016535000002477, + 2.202203084001667, + 2.2027412919997005, + 2.2033583750016987, + 2.2038874169957126, + 2.204479624997475, + 2.2050480420002714, + 2.2056007089995546, + 2.2061594999977387, + 2.206694874999812, + 2.207273084000917, + 2.2078849999961676, + 2.2084855840003, + 2.2090112500009127, + 2.209573125001043, + 2.2101485839957604, + 2.2107009589963127, + 2.2113095419990714, + 2.2118559169975924, + 2.2123549999960233, + 2.2129881669970928, + 2.2135478339987458, + 2.2141490419962793, + 2.21473483400041, + 2.2153330000001006, + 2.2159547089977423, + 2.216502541996306, + 2.2170642919954844, + 2.2175962920009624, + 2.2181299590010894, + 2.2186991249982384, + 2.2192204169987235, + 2.2197253749982337, + 2.220266584001365, + 2.2207714169999235, + 2.221292458998505, + 2.2218184169978485, + 2.222378624996054, + 2.222935416997643, + 2.2234654999992927, + 2.223997083994618, + 2.2245136669953354, + 2.2250406249950174, + 2.2255992499995045, + 2.2261095419962658, + 2.226637874999142, + 2.2272121669957414, + 2.2277424589992734, + 2.2282322499959264, + 2.2287573749999865, + 2.229267541995796, + 2.2298601669972413, + 2.230400499996904, + 2.2309483339995495, + 2.2314622919948306, + 2.2320317499979865, + 2.232533208996756, + 2.233121459001268, + 2.2337394999995013, + 2.234358791996783, + 2.2349688749964116, + 2.235527374999947, + 2.236169042000256, + 2.236745541995333, + 2.237385208994965, + 2.237953916999686, + 2.238490499999898, + 2.2390749999976833, + 2.239620125001238, + 2.2401967920013703, + 2.240738041997247, + 2.241302624999662, + 2.2418203339984757, + 2.2423612919956213, + 2.2429147090006154, + 2.2435152499965625, + 2.244083874997159, + 2.244629624998197, + 2.2451549589968636, + 2.245686083995679, + 2.246214749997307, + 2.2468056669968064, + 2.247490124995238, + 2.2480822919969796, + 2.248598624995793, + 2.2491341669956455, + 2.2496855839999625, + 2.250203541996598, + 2.2507321250013774, + 2.251295999994909, + 2.251880291994894, + 2.252444083998853, + 2.253012041997863, + 2.2536065419990337, + 2.254171583997959, + 2.2547087499988265, + 2.255368499994802, + 2.2563105419976637, + 2.2569960839973646, + 2.2576301250010147, + 2.2582147089997306, + 2.2587887920017238, + 2.2593742919998476, + 2.259942124997906, + 2.2604784590002964, + 2.2610272919991985, + 2.2615783750006813, + 2.2621215420003864, + 2.2627009169955272, + 2.263247750001028, + 2.2638230839947937, + 2.2643844170015655, + 2.264929166994989, + 2.2654315839972696, + 2.2659967090003192, + 2.2665576250001322, + 2.2671329169970704, + 2.267643125000177, + 2.268178291997174, + 2.268722208995314, + 2.269255624996731, + 2.2697970419976627, + 2.2704369999992196, + 2.2710783750007977, + 2.27171562500007, + 2.2723620839969954, + 2.272991334000835, + 2.273604541995155, + 2.275007459000335, + 2.2759231669988367, + 2.276816208999662, + 2.277512624998053, + 2.278118041998823, + 2.278742541995598, + 2.27944520899473, + 2.280026041997189, + 2.2806763339976897, + 2.2813496669987217, + 2.28199870899698, + 2.282658708994859, + 2.283334499996272, + 2.2839502089991583, + 2.284560291998787, + 2.285183916996175, + 2.285836167000525, + 2.286490041995421, + 2.287108917000296, + 2.287698084001022, + 2.2882970419959747, + 2.288950541995291, + 2.2895512499962933, + 2.2901517919963226, + 2.2907975419948343, + 2.291439291999268, + 2.2920773750010994, + 2.2928276249949704, + 2.293504249995749, + 2.2941461250011344, + 2.2948257089956314, + 2.295536166995589, + 2.2962075839968747, + 2.296895333995053, + 2.297557499994582, + 2.298212749999948, + 2.298850125000172, + 2.299468833996798, + 2.3001324590004515, + 2.300792249996448, + 2.301402874996711, + 2.302040834001673, + 2.3027884170005564, + 2.3033840839998447, + 2.304005416997825, + 2.304605500001344, + 2.3052455419965554, + 2.305825041999924, + 2.3064555839955574, + 2.307082958999672, + 2.307708291999006, + 2.308309249994636, + 2.3089742090014624, + 2.3095808340003714, + 2.310191833996214, + 2.3109454169971286, + 2.3115646250007558, + 2.3122022919997107, + 2.3128033749962924, + 2.3134297500000685, + 2.3141116249971674, + 2.314762541995151, + 2.3154201669967733, + 2.3161042499996256, + 2.3167560840010992, + 2.3173852920008358, + 2.318018874997506, + 2.3186081249950803, + 2.3192406249945634, + 2.319869541999651, + 2.320491624996066, + 2.321151500000269, + 2.3217623339951388, + 2.322373124996375, + 2.3230312500018044, + 2.3236744589958107, + 2.3242977499976405, + 2.324967166998249, + 2.325654583997675, + 2.326315334001265, + 2.3269324590000906, + 2.3275627920011175, + 2.328169333995902, + 2.328772166998533, + 2.3293788340015453, + 2.3300173339957837, + 2.3306733339995844, + 2.3313650419950136, + 2.332003249997797, + 2.3326414589973865, + 2.333283208994544, + 2.333954083995195, + 2.3346550419955747, + 2.335370791995956, + 2.3360312090007938, + 2.336689625000872, + 2.337325000000419, + 2.3379465420002816, + 2.338627874996746, + 2.339265416994749, + 2.3399172499994165, + 2.3405301249949844, + 2.341161291995377, + 2.3418024169950513, + 2.3424460839960375, + 2.34305295899685, + 2.3436950420000358, + 2.3443299999999, + 2.3449547919954057, + 2.3455812920001335, + 2.3462704999983544, + 2.346986124997784, + 2.347641708998708, + 2.3482946250005625, + 2.3489638339960948, + 2.3496068339954945, + 2.3502087089946144, + 2.350903124999604, + 2.3515414590001456, + 2.3521550000004936, + 2.3528001250015222, + 2.353552916996705, + 2.354292459000135, + 2.3550279999981285, + 2.355662709000171, + 2.356274375000794, + 2.356911709000997, + 2.357511208996584, + 2.3581639589974657, + 2.358732417000283, + 2.359381834001397, + 2.3599793749963283, + 2.3606147919999785, + 2.3612382919964148, + 2.3619556249977904, + 2.362623374996474, + 2.3633353339973837, + 2.3639929999990272, + 2.3646381669968832, + 2.3652634999962174, + 2.3658801249985117, + 2.3665230839978904, + 2.3671552919986425, + 2.3678353750001406, + 2.3684912499957136, + 2.3691087499973946, + 2.369757458996901, + 2.3703632920005475, + 2.3709705419969396, + 2.3715985839953646, + 2.3722009170014644, + 2.373023291998834, + 2.3736687089985935, + 2.3743789169966476, + 2.3750944169951254, + 2.375710916996468, + 2.3763337499985937, + 2.3769752090011025, + 2.3775894589998643, + 2.378202791995136, + 2.378843209000479, + 2.379480625000724, + 2.3801003339976887, + 2.380747833994974, + 2.381388750000042, + 2.3821119169952, + 2.382765958995151, + 2.38340829200024, + 2.384032624999236, + 2.3846648749968153, + 2.3853002920004656, + 2.3859347499965224, + 2.3865745840012096, + 2.3871902089958894, + 2.387839333998272, + 2.388433833999443, + 2.3890254169964464, + 2.389632708996942, + 2.3902560839997022, + 2.390852459000598, + 2.3914942089977558, + 2.3921593749983003, + 2.392794125000364, + 2.3934772499997052, + 2.3941268749986193, + 2.3947607500012964, + 2.395383041999594, + 2.3960327089953353, + 2.3966759169998113, + 2.3973279999991064, + 2.3979393749978044, + 2.398582499998156, + 2.3992000419966644, + 2.3997974999947473, + 2.400376833997143, + 2.4009626249971916, + 2.401593499998853, + 2.402223500001128, + 2.4030231249998906, + 2.4036493339954177, + 2.4043249589958577, + 2.404948791998322, + 2.405566292000003, + 2.4061674589975155, + 2.4067536250004196, + 2.4073709169970243, + 2.4080161249949015, + 2.4086261249976815, + 2.409265417001734, + 2.4099132499977713, + 2.4105148749949876, + 2.411132000001089, + 2.4117602499973145, + 2.412432749995787, + 2.41306962499948, + 2.413782083996921, + 2.4144929999965825, + 2.415140375000192, + 2.415812499995809, + 2.4164445839996915, + 2.4170940420008264, + 2.4177181249979185, + 2.4183689169949503, + 2.4189970000006724, + 2.4196397499981686, + 2.4202817089972086, + 2.420899249998911, + 2.4215241669953684, + 2.4221398750014487, + 2.4227750840000226, + 2.4235378750017844, + 2.424186374999408, + 2.4248008750000736, + 2.4254247919961927, + 2.426090333996399, + 2.4267099169956055, + 2.427339000001666, + 2.427932916994905, + 2.4285662089969264, + 2.4291728339958354, + 2.4298475420000614, + 2.430473874999734, + 2.4312317090007127, + 2.4319414169949596, + 2.4326600419954048, + 2.4332854999956908, + 2.433894292000332, + 2.434501249997993, + 2.435114291998616, + 2.4357708749957965, + 2.436391374998493, + 2.437043583995546, + 2.4378533749986673, + 2.4385098749989993, + 2.439221666994854, + 2.439836083998671, + 2.4404682499953196, + 2.441089499996451, + 2.441719666996505, + 2.442303791998711, + 2.4429279589967337, + 2.4435801669969806, + 2.4441913339978782, + 2.4448393339989707, + 2.445446041994728, + 2.44613450000179, + 2.4468230419952306, + 2.447479166999983, + 2.448133334000886, + 2.4488086249984917, + 2.4494495839971933, + 2.4500902500003576, + 2.450857874995563, + 2.451526416996785, + 2.4522557919990504, + 2.4529161669997848, + 2.4535542500016163, + 2.4542113339994103, + 2.4548691249947296, + 2.455515249996097, + 2.456125749995408, + 2.4567880839967984, + 2.4574664999963716, + 2.458096709000529, + 2.458733250001387, + 2.459286749995954, + 2.4599201249948237, + 2.460597291996237, + 2.4611728749951, + 2.4617262499959907, + 2.462214708997635, + 2.4627311669974006, + 2.463250333996257, + 2.4637630419965717, + 2.464255458995467, + 2.4647647089950624, + 2.4652830839986564, + 2.465850833999866, + 2.4663793340005213, + 2.466923499996483, + 2.4674645839986624, + 2.4680025839988957, + 2.468543208997289, + 2.469067999998515, + 2.469687459000852, + 2.4703353340009926, + 2.4709404169989284, + 2.4715115840008366, + 2.4720495419969666, + 2.4726039589950233, + 2.473123541996756, + 2.4736510000002454, + 2.4741789999970933, + 2.4747617920002085, + 2.4754288339972845, + 2.4760055000006105, + 2.476625041999796, + 2.477213458994811, + 2.4778691669998807, + 2.4785144999987097, + 2.479144291995908, + 2.47978395899554, + 2.480517833995691, + 2.4811294589962927, + 2.4817606669967063, + 2.482363584000268, + 2.483006583999668, + 2.4836208749984507, + 2.484222792001674, + 2.4848062089949963, + 2.485451791995729, + 2.486066124998615, + 2.486687874996278, + 2.4872855840003467, + 2.487948834001145, + 2.488565125000605, + 2.489239666996582, + 2.489923834000365, + 2.4909611670009326, + 2.491624124995724, + 2.4922632919988246, + 2.4928825839961064, + 2.493532125001366, + 2.4941503340014606, + 2.4947832920006476, + 2.4954010840010596, + 2.4960190419951687, + 2.496783875001711, + 2.4974042089961586, + 2.49808079200011, + 2.498698041999887, + 2.499331708997488, + 2.4999615419947077, + 2.5005719589971704, + 2.5011755419982364, + 2.501915458997246, + 2.502542166999774, + 2.503173291996063, + 2.5037984590017004, + 2.5044154999995953, + 2.5050215419978485, + 2.505668459001754, + 2.5062910419947, + 2.5069062920010765, + 2.5075363750001998, + 2.508181874996808, + 2.5088490419948357, + 2.5095423749953625, + 2.5102150839957176, + 2.5110275839979295, + 2.511689250000927, + 2.5123150419967715, + 2.512903999995615, + 2.51357737500075, + 2.5142128340012277, + 2.514850833998935, + 2.515464541997062, + 2.516139250001288, + 2.5167925839996315, + 2.5175234169946634, + 2.518174166994868, + 2.5187919169984525, + 2.5194104589972994, + 2.5200582920006127, + 2.52065366700117, + 2.521291334000125, + 2.5219309169988264, + 2.5225511669996195, + 2.523180666998087, + 2.5237635000012233, + 2.524371166997298, + 2.524976249995234, + 2.525593874997867, + 2.526348166997195, + 2.5269681249992573, + 2.527626124996459, + 2.5282031669994467, + 2.5290113750015735, + 2.5297168339966447, + 2.53040966700064, + 2.53114279199508, + 2.5317842090007616, + 2.532414166998933, + 2.5330269999976736, + 2.53364899999724, + 2.5342717499952414, + 2.5348555839955225, + 2.535486624998157, + 2.5360778749964084, + 2.5366949169983855, + 2.5372943339971243, + 2.537867125000048, + 2.538519916997757, + 2.539082083996618, + 2.5395934589978424, + 2.5401649170016753, + 2.540724083999521, + 2.5412702499961597, + 2.541877083996951, + 2.542381958999613, + 2.542944084001647, + 2.5435177499966812, + 2.544031666999217, + 2.544632334000198, + 2.5452077919981093, + 2.545800791995134, + 2.5464305839996086, + 2.5469451249955455, + 2.5475433339961455, + 2.548149458998523, + 2.548752083996078, + 2.549347583997587, + 2.549932916997932, + 2.550452541996492, + 2.5509809590002988, + 2.551494624996849, + 2.5520060839990037, + 2.5525310000011814, + 2.5530547089947504, + 2.5535908749952796, + 2.554105958995933, + 2.554642374998366, + 2.555231874997844, + 2.555770708997443, + 2.556283291996806, + 2.556823209000868, + 2.5573472499963827, + 2.5579204999958165, + 2.5584484589999192, + 2.55896483399556, + 2.5595438749951427, + 2.560086166995461, + 2.560633458997472, + 2.561195249996672, + 2.5617137500012177, + 2.5622280839961604, + 2.5627764589953586, + 2.5633111669958453, + 2.5638741250004387, + 2.5643858749972424, + 2.5649534999975003, + 2.5655022919963812, + 2.5659650419984246, + 2.5664707499963697, + 2.567066416995658, + 2.5676743750009337, + 2.5682501249975758, + 2.5688122089995886, + 2.56941458399524, + 2.570113374997163, + 2.570705708996684, + 2.5712630839989288, + 2.571840833996248, + 2.572401917001116, + 2.5729707089994918, + 2.573576583999966, + 2.5741290419973666, + 2.574633833995904, + 2.5752175839952542, + 2.5758320419990923, + 2.576407583997934, + 2.5769870840013027, + 2.577573750000738, + 2.5782483750008396, + 2.578823416995874, + 2.5793542499959585, + 2.5798897499989835, + 2.5804220419959165, + 2.5809537089953665, + 2.581481791996339, + 2.5820412920002127, + 2.5826068749956903, + 2.5831281669961754, + 2.5836730419978267, + 2.5841702920006355, + 2.5846793339951546, + 2.5852059999961057, + 2.5857541669975035, + 2.5862607499948354, + 2.5868277920017135, + 2.587389208994864, + 2.587952875001065, + 2.588471709001169, + 2.5890287500005797, + 2.5895640839953558, + 2.590119833999779, + 2.590775999997277, + 2.5913775000008172, + 2.591988374995708, + 2.592556584000704, + 2.593115666997619, + 2.593628958995396, + 2.594289791995834, + 2.594873333997384, + 2.59537362500123, + 2.5959168749977835, + 2.5964316249956028, + 2.5969904999947175, + 2.5975847500012605, + 2.5981087499967543, + 2.5987002499969094, + 2.5992744999966817, + 2.599814499997592, + 2.6003283749960246, + 2.6009251669966034, + 2.601444708998315, + 2.601957083999878, + 2.6024794170007226, + 2.6030255000005127, + 2.603610291997029, + 2.604173916995933, + 2.604682833996776, + 2.6054798339973786, + 2.606011416995898, + 2.60656987499533, + 2.6070912089999183, + 2.607661541995185, + 2.608230999998341, + 2.6088709169998765, + 2.6095149999964633, + 2.6101254589957534, + 2.6106977089948487, + 2.611264792001748, + 2.6118332089972682, + 2.6123939999961294, + 2.612925583998731, + 2.613519708997046, + 2.6140789999990375, + 2.6146882089960855, + 2.6152376249956433, + 2.615799209001125, + 2.6163218750007218, + 2.616889083998103, + 2.617402999996557, + 2.6179228339969995, + 2.618461458994716, + 2.6191021669947077, + 2.6196344169948134, + 2.6201797089961474, + 2.6207178749973536, + 2.6212316669989377, + 2.621765249998134, + 2.6222662090003723, + 2.6228074169994215, + 2.623358459000883, + 2.623898041994835, + 2.6244353750007576, + 2.625023417000193, + 2.6255470420001075, + 2.6260829589955392, + 2.626602083997568, + 2.6274367090009036, + 2.6282505419949302, + 2.6288870419957675, + 2.6295105419994798, + 2.630135583996889, + 2.630685124997399, + 2.6312329590000445, + 2.631757541996194, + 2.632359083996562, + 2.632934208995721, + 2.6334918339998694, + 2.634047166997334, + 2.6345965000000433, + 2.635139624995645, + 2.6357117090010433, + 2.6362582500005374, + 2.636788625000918, + 2.6374843750018044, + 2.6380238339988864, + 2.6385725419968367, + 2.6391337499953806, + 2.6396950839989586, + 2.6401805839996086, + 2.640686792001361, + 2.6412402919959277, + 2.641769249996287, + 2.6423077919971547, + 2.6428920420003124, + 2.6434112499991897, + 2.6439655419962946, + 2.6444824999998673, + 2.645016541995574, + 2.6455754169946886, + 2.6461343339979067, + 2.646670374997484, + 2.647227916997508, + 2.6478026249969844, + 2.6484332499967422, + 2.6490499999999884, + 2.6496318749996135, + 2.650211667001713, + 2.650760333999642, + 2.651289083994925, + 2.6518448749993695, + 2.6524145000003045, + 2.6530166669981554, + 2.65358254199964, + 2.6541529589958373, + 2.6546774589951383, + 2.655239209001593, + 2.6558023339966894, + 2.6563614170008805, + 2.6568964589969255, + 2.657437083995319, + 2.657965583995974, + 2.6584781669953372, + 2.659046834000037, + 2.6597202499979176, + 2.660337624998647, + 2.660915666994697, + 2.661510666999675, + 2.662080624999362, + 2.6625949169974774, + 2.6631225839955732, + 2.663660792000883, + 2.6642138339957455, + 2.664776958998118, + 2.665360166996834, + 2.6659044999978505, + 2.6664508339963504, + 2.6670646669954294, + 2.6676619589998154, + 2.668414916995971, + 2.6690489999964484, + 2.669620374996157, + 2.670176874999015, + 2.67072874999576, + 2.6712659999975585, + 2.671836749999784, + 2.672410374994797, + 2.672977333997551, + 2.673520249998546, + 2.674068416999944, + 2.67463329200109, + 2.6751851250010077, + 2.675712708994979, + 2.676260458996694, + 2.6768108749965904, + 2.677392666999367, + 2.677967791998526, + 2.6785457090009004, + 2.679087749995233, + 2.6796473340000375, + 2.6801926249972894, + 2.6807827090015053, + 2.68134570899565, + 2.681897583999671, + 2.6825013749985374, + 2.683058875001734, + 2.6836296249966836, + 2.6841594169964083, + 2.684700124998926, + 2.685325083999487, + 2.685897416995431, + 2.6865326249971986, + 2.687147708995326, + 2.687731874997553, + 2.6883483339988743, + 2.6889623749957536, + 2.689560624996375, + 2.69014995899488, + 2.6907299169979524, + 2.6913656670003547, + 2.692028792000201, + 2.692660959000932, + 2.6932820419970085, + 2.6939314589981223, + 2.6945952089954517, + 2.695223499998974, + 2.696027541998774, + 2.696721208994859, + 2.6973914170011994, + 2.698048749996815, + 2.698713958998269, + 2.699389166999026, + 2.700058791997435, + 2.700714999999036, + 2.7013759999972535, + 2.7020301669981563, + 2.702677291999862, + 2.7032968749990687, + 2.7039629999999306, + 2.7046105839981465, + 2.705397958998219, + 2.7061224589997437, + 2.7067410419986118, + 2.707340208995447, + 2.7080830419945414, + 2.708750375000818, + 2.7094110420002835, + 2.710063667000213, + 2.7106901250008377, + 2.711303500000213, + 2.712076124997111, + 2.712700666997989, + 2.7133564169998863, + 2.7140092499976163, + 2.7146400839992566, + 2.715263583995693, + 2.7159076669995557, + 2.716544499999145, + 2.7172281249950174, + 2.7178667089974624, + 2.7185684590003802, + 2.719185458998254, + 2.7198137500017765, + 2.720451791996311, + 2.721078041999135, + 2.721705416995974, + 2.72233087499626, + 2.722979917001794, + 2.7235994169968762, + 2.7242585839994717, + 2.7248976249975385, + 2.7255404999959865, + 2.7261585839951294, + 2.7268077920016367, + 2.7275549999976647, + 2.728229708998697, + 2.728912209000555, + 2.729526958995848, + 2.730256709000969, + 2.730912499995611, + 2.731531375000486, + 2.7321828749991255, + 2.7328370839968557, + 2.7335487499949522, + 2.7341889169983915, + 2.7347926250004093, + 2.7355040420006844, + 2.7361323750010342, + 2.736761916996329, + 2.737532667000778, + 2.7382585419982206, + 2.738877791998675, + 2.7394956249991083, + 2.7400977090001106, + 2.7407370840010117, + 2.74146354199911, + 2.742081042000791, + 2.742737542001123, + 2.7433564589955495, + 2.7439624999969965, + 2.744643375001033, + 2.7453183339966927, + 2.7460272499956773, + 2.7467483750006068, + 2.74737629199808, + 2.747999166997033, + 2.748622749997594, + 2.7492510000010952, + 2.7499115419996087, + 2.750549124997633, + 2.751236999996763, + 2.751877999995486, + 2.7524911250002333, + 2.753105167001195, + 2.7537167920017964, + 2.754382250001072, + 2.755039833995397, + 2.7557511669947417, + 2.756380958999216, + 2.7570083339960547, + 2.757622208999237, + 2.758357667000382, + 2.759004374995129, + 2.7596234589946107, + 2.7602570000017295, + 2.760878208995564, + 2.761485499999253, + 2.762126374997024, + 2.762721833998512, + 2.7633430419955403, + 2.76403266700072, + 2.7648445419981726, + 2.7655062089979765, + 2.7661822919981205, + 2.7668574589988566, + 2.7675050839970936, + 2.768142208995414, + 2.768787249995512, + 2.7694020419949084, + 2.770240833997377, + 2.7709665000002133, + 2.7716262089961674, + 2.7722752499976195, + 2.7728809999971418, + 2.7734782920015277, + 2.77409366700158, + 2.7747485840009176, + 2.7754027919945656, + 2.776006291998783, + 2.776607374995365, + 2.777215541995247, + 2.7778528339986224, + 2.778513874996861, + 2.779145000000426, + 2.7797939169977326, + 2.7804123339956277, + 2.781021458999021, + 2.7816546249960084, + 2.782277541999065, + 2.7830292500002543, + 2.783707083995978, + 2.7843421249999665, + 2.7851402499945834, + 2.785840541997459, + 2.786534999999276, + 2.7871720420007478, + 2.787836083996808, + 2.788491333994898, + 2.7891204170009587, + 2.7897479589955765, + 2.7904856669993023, + 2.7911843749971013, + 2.791811292001512, + 2.792426667001564, + 2.793028416999732, + 2.7937089999977616, + 2.7943228340009227, + 2.794956624995393, + 2.795611249996, + 2.796222459001001, + 2.796872209000867, + 2.797512833996734, + 2.798122542000783, + 2.798746708998806, + 2.799484167000628, + 2.800091708995751, + 2.800732124997012, + 2.8013729999947827, + 2.8020167499998934, + 2.8026392920000944, + 2.803273999998055, + 2.803895291996014, + 2.804660541994963, + 2.8053429999999935, + 2.8059666249973816, + 2.8066084169986425, + 2.807222791998356, + 2.8078625419948366, + 2.808498916994722, + 2.8091162919954513, + 2.8096946669975296, + 2.8103505420003785, + 2.8109941669972613, + 2.811626458998944, + 2.812251083996671, + 2.812848292000126, + 2.8134821249987, + 2.814081416996487, + 2.8146884169982513, + 2.815322834001563, + 2.8159251249962836, + 2.816558874998009, + 2.817203583996161, + 2.8178260839995346, + 2.818538041996362, + 2.8191440839946154, + 2.819761667000421, + 2.820455834000313, + 2.8210657089948654, + 2.821661000001768, + 2.8222465840008226, + 2.8229625419990043, + 2.823651083999721, + 2.824464708995947, + 2.8251145419999375, + 2.8257947089950903, + 2.8264263339951867, + 2.8270641669951146, + 2.8276979590009432, + 2.8283558339971933, + 2.82899075000023, + 2.8297647919971496, + 2.8304897919952055, + 2.8311400419988786, + 2.8318097919982392, + 2.832458166994911, + 2.8330989999958547, + 2.8337586669949815, + 2.8343954589945497, + 2.8350064999976894, + 2.8356802919952315, + 2.836275041998306, + 2.836923458999081, + 2.8375572500008275, + 2.838193333998788, + 2.8388584169952082, + 2.8395233339979313, + 2.840143417000945, + 2.840757209000003, + 2.8414162499975646, + 2.8420652499989956, + 2.8429011670014006, + 2.8436191250002594, + 2.84448049999628, + 2.8451175000009243, + 2.8457280000002356, + 2.846349209001346, + 2.8470276669977466, + 2.8476477090007393, + 2.8482594589950168, + 2.8489074999961304, + 2.8495863749994896, + 2.85019795900007, + 2.8508283339979243, + 2.851489542001218, + 2.852156749999267, + 2.8527992089948384, + 2.853437624995422, + 2.854044833999069, + 2.85466383399762, + 2.855322208997677, + 2.8559530839993386, + 2.8565857499997946, + 2.857222749997163, + 2.857864249999693, + 2.85850008399575, + 2.859120916997199, + 2.8597493749985006, + 2.8603399169951444, + 2.8609570839980734, + 2.861618750001071, + 2.8624445839959662, + 2.863130124998861, + 2.8638047499989625, + 2.864484416997584, + 2.865108917001635, + 2.865744624999934, + 2.8663867919967743, + 2.8670177919993876, + 2.8676861669955542, + 2.8683105839954806, + 2.8689663339973777, + 2.8696378339955118, + 2.8702634169967496, + 2.8709007919969736, + 2.8715133340010652, + 2.8721388749981998, + 2.8727607089967933, + 2.8733722920005675, + 2.8740559590005432, + 2.8747206249972805, + 2.8753496249992168, + 2.8759670840008766, + 2.8766169590016943, + 2.877257374995679, + 2.8779414589953376, + 2.87857570900087, + 2.879323834000388, + 2.87993108399678, + 2.880640958996082, + 2.8814119169983314, + 2.882117166998796, + 2.8828277089996845, + 2.883451374997094, + 2.8841122500016354, + 2.884733958999277, + 2.8853700420004316, + 2.8860461250005756, + 2.886715833999915, + 2.887330124998698, + 2.887983374996111, + 2.8886559999955352, + 2.8893184999978985, + 2.8899782500011497, + 2.890600999999151, + 2.8913000419997843, + 2.8919388340000296, + 2.8925529589978396, + 2.893203833998996, + 2.8938471669971477, + 2.8944595840002876, + 2.895107917000132, + 2.8957366670001647, + 2.8963530420005554, + 2.8969853339949623, + 2.8976481669960776, + 2.898270459001651, + 2.898936124998727, + 2.8995615419989917, + 2.900222999996913, + 2.900883624999551, + 2.90156137500162, + 2.902232208994974, + 2.902864249997947, + 2.9034969999993336, + 2.9042176669972832, + 2.9048688339971704, + 2.9055144589947304, + 2.9061782919961843, + 2.906821708995267, + 2.9074381249956787, + 2.9081673749969923, + 2.9088244999948074, + 2.909487375000026, + 2.9101260419993196, + 2.9107510419999016, + 2.911411708999367, + 2.9120524169993587, + 2.912692583995522, + 2.913326791996951, + 2.9139787089952733, + 2.914607166996575, + 2.9152287499964586, + 2.9158394589976524, + 2.9164404170005582, + 2.917074999997567, + 2.9177020419956534, + 2.918357709000702, + 2.9190239169984125, + 2.9196473749980214, + 2.920276583994564, + 2.9209192089983844, + 2.9215667089956696, + 2.9222005839983467, + 2.922890624999127, + 2.923592416998872, + 2.9243477919953875, + 2.925035084001138, + 2.9256609169970034, + 2.9263513749974663, + 2.926986874997965, + 2.92763679199561, + 2.9282819169966388, + 2.928848499999731, + 2.9294722089980496, + 2.93027162499493, + 2.930967125001189, + 2.931638041998667, + 2.9323023749966524, + 2.9329495839992887, + 2.9335846670001047, + 2.9342178750011954, + 2.9348436669970397, + 2.9354765839962056, + 2.9360948339963215, + 2.936715791998722, + 2.937292916998558, + 2.937925250000262, + 2.938534125001752, + 2.939170459001616, + 2.9398143340004026, + 2.9404322920017876, + 2.9410748340014834, + 2.9417412920010975, + 2.9425112919998355, + 2.9432269999961136, + 2.943928333996155, + 2.944566499994835, + 2.9452204999979585, + 2.9459222500008764, + 2.9465817919990513, + 2.947232874998008, + 2.9478623339964543, + 2.9485035839970806, + 2.9491398749960354, + 2.949772916996153, + 2.950421624998853, + 2.951058250000642, + 2.9518526249958086, + 2.9525179999982356, + 2.953130333997251, + 2.953738833995885, + 2.9544557920016814, + 2.9550826249978854, + 2.955705833999673, + 2.9563371670010383, + 2.956999916998029, + 2.9576537089960766, + 2.958357709001575, + 2.9589954589973786, + 2.959627708994958, + 2.9602764590017614, + 2.960865749999357, + 2.9615081250012736, + 2.9621480839996366, + 2.9628731249977136, + 2.9635291669983417, + 2.964215208994574, + 2.9648604999965755, + 2.9654573340012575, + 2.9660787920001894, + 2.9667255419990397, + 2.9673999169972376, + 2.968028499999491, + 2.9686271249956917, + 2.9692742089973763, + 2.9698868749983376, + 2.970506749996275, + 2.971163834001345, + 2.971802249994653, + 2.972478333998879, + 2.9730706670015934, + 2.9737096249955357, + 2.974330833996646, + 2.9750397499956307, + 2.9756639589977567, + 2.9763395839981968, + 2.976981749998231, + 2.977780041997903, + 2.9784445839977707, + 2.979071750000003, + 2.9796745419953368, + 2.980307334000827, + 2.980967374998727, + 2.9816799589971197, + 2.9823916669993196, + 2.983073584000522, + 2.983697874995414, + 2.984349416998157, + 2.9850150419952115, + 2.985646542001632, + 2.9862564169961843, + 2.986853333997715, + 2.9876137920000474, + 2.9882745419963612, + 2.988925334000669, + 2.989576166997722, + 2.990248292000615, + 2.99086774999887, + 2.991503166995244, + 2.9921492919966113, + 2.992809584000497, + 2.9935522919986397, + 2.9942622919988935, + 2.9949156250004307, + 2.9955497499977355, + 2.9962109589978354, + 2.9968579999986105, + 2.9974886249983683, + 2.9981694589951076, + 2.998747083998751, + 2.9993179999946733, + 2.9998669999986305, + 3.0007026249950286, + 3.0013829999952577, + 3.0020688340009656, + 3.002752959000645, + 3.0033182089973707, + 3.00391829200089, + 3.004559834000247, + 3.005155583996384, + 3.005756250000559, + 3.00642608400085, + 3.0069830419961363, + 3.007524333996116, + 3.008087999995041, + 3.008642583998153, + 3.009197333994962, + 3.009755084000062, + 3.0103012089966796, + 3.0108299999992596, + 3.0113304999977117, + 3.011834999997518, + 3.012349666998489, + 3.012879083995358, + 3.0134201670007315, + 3.0139564589990187, + 3.016509875000338, + 3.0170960839968757, + 3.017672499998298, + 3.018217042001197, + 3.018770541995764, + 3.019340499995451, + 3.0200519999998505, + 3.0206707499964978, + 3.0212478339963127, + 3.0218328749979264, + 3.0224268339952687, + 3.0229643339989707, + 3.0234959590015933, + 3.0240657499962253, + 3.0248271669988753, + 3.025426833999518, + 3.0259908750012983, + 3.0265586669993354, + 3.027113666998048, + 3.027676917001372, + 3.0283099169973866, + 3.028878334000183, + 3.0296154169991496, + 3.0322401669982355, + 3.033234791997529, + 3.0338321249946603, + 3.034469792000891, + 3.0350795420017675, + 3.035782749997452, + 3.0364859999972396, + 3.037096667001606, + 3.03767608400085, + 3.0382912089989986, + 3.0389313749983557, + 3.0395792499984964, + 3.0404022919974523, + 3.0411411249951925, + 3.042086041998118, + 3.0429220000005444, + 3.0435335419970215, + 3.044169166998472, + 3.0448133339959895, + 3.0453909169955296, + 3.0460097499963013, + 3.046565124997869, + 3.0471899589974782, + 3.0477493340004003, + 3.048453958996106, + 3.049035208998248, + 3.04956674999994, + 3.050134375000198, + 3.050697083999694, + 3.0513012500014156, + 3.051906874999986, + 3.0524182919980376, + 3.0529653749981662, + 3.053559416999633, + 3.0541087919991696, + 3.0547274999989895, + 3.0554101250017993, + 3.0559714589981013, + 3.056514291994972, + 3.057060667000769, + 3.0575879589960095, + 3.0581105839955853, + 3.0586442919957335, + 3.059204334000242, + 3.059767250000732, + 3.060379333997844, + 3.06102208399534, + 3.0616251669998746, + 3.062183541995182, + 3.062706042001082, + 3.063289249999798, + 3.0638750419966527, + 3.0644485000011628, + 3.0650262919953093, + 3.065610833997198, + 3.0661679589975392, + 3.0667107089975616, + 3.067255292000482, + 3.067807166997227, + 3.0683461669977987, + 3.0688866669952404, + 3.069441374995222, + 3.0700277500000084, + 3.0705889589953586, + 3.0711965000009513, + 3.0717569170010393, + 3.072281208995264, + 3.0728234999987762, + 3.0734051249964978, + 3.073904083998059, + 3.0744404590004706, + 3.0749837920011487, + 3.0755754169949796, + 3.0761367919985787, + 3.076687624998158, + 3.077243166997505, + 3.0778144169962616, + 3.0783878750007716, + 3.079038916999707, + 3.0796561669994844, + 3.080303249997087, + 3.0809318339961465, + 3.081475833998411, + 3.082029708995833, + 3.082566124998266, + 3.0831275839955197, + 3.083691291998548, + 3.0842585419959505, + 3.084849041995767, + 3.085435916997085, + 3.0859508749999804, + 3.0865125419950346, + 3.0872028749945457, + 3.087796374995378, + 3.088351458995021, + 3.088954916995135, + 3.089492084000085, + 3.090050083999813, + 3.090599958995881, + 3.091138666997722, + 3.0917002499991213, + 3.092337709000276, + 3.0929552919988055, + 3.0934915420002653, + 3.0940639589971397, + 3.0946584999983315, + 3.0952451249977457, + 3.0957486249972135, + 3.096325209000497, + 3.096871875000943, + 3.0975045419982052, + 3.098093666994828, + 3.0986794999989797, + 3.09926304200053, + 3.099854249994678, + 3.100372959001106, + 3.1009541249950416, + 3.1014635839965194, + 3.1020035420006025, + 3.1025599589993362, + 3.103144417000294, + 3.1037408339980175, + 3.1043034589965828, + 3.1048826670012204, + 3.105439083999954, + 3.1061505839970778, + 3.1066896249976708, + 3.107256791998225, + 3.10778679199575, + 3.1083500839959015, + 3.108890416995564, + 3.109436166996602, + 3.109952083999815, + 3.110508874997322, + 3.111023541998293, + 3.1115658749986324, + 3.1121401249984046, + 3.1127055839970126, + 3.1132710839956417, + 3.113814917000127, + 3.114511959000083, + 3.1151069999978063, + 3.1156681249995017, + 3.1161715839989483, + 3.1167404590014485, + 3.117376541995327, + 3.117975959001342, + 3.1186025839997455, + 3.1191934589951416, + 3.119722333998652, + 3.1202927499980433, + 3.120842708995042, + 3.121383708996291, + 3.1219075839981087, + 3.1224395419994835, + 3.122979874999146, + 3.1235466250000172, + 3.1240594999981113, + 3.124641583999619, + 3.125237374995777, + 3.1257757089988445, + 3.126343416995951, + 3.1269067089961027, + 3.127446708997013, + 3.128023958997801, + 3.128618833994551, + 3.129139042001043, + 3.129827166994801, + 3.1303840420005145, + 3.1309493750013644, + 3.1314870419955696, + 3.1320130419990164, + 3.1325933749976684, + 3.13316537499486, + 3.133702416998858, + 3.134216041995387, + 3.1347677919984562, + 3.135299000001396, + 3.135861083996133, + 3.136510749995068, + 3.137201500001538, + 3.137939208994794, + 3.138591750001069, + 3.1392303749962593, + 3.1398940419967403, + 3.140543791996606, + 3.141198708995944, + 3.1417794590015546, + 3.1423686669950257, + 3.1429897919952055, + 3.143634166997799, + 3.1442914590006694, + 3.1461784999992233, + 3.1473142089962494, + 3.147958292000112, + 3.1487090839946177, + 3.1493323339964263, + 3.1500156670008437, + 3.1506879169974127, + 3.151364334000391, + 3.152015209001547, + 3.152615416998742, + 3.1533846669990453, + 3.1541455420010607, + 3.1549099999974715, + 3.1556391669946606, + 3.1563449169989326, + 3.1571032919964637, + 3.1578229590013507, + 3.158508249995066, + 3.159188459001598, + 3.1598425839983975, + 3.1604769170007785, + 3.161112374997174, + 3.1617534589968272, + 3.1627594999954454, + 3.163469166996947, + 3.164185583998915, + 3.1648425419989508, + 3.165494791996025, + 3.166167791998305, + 3.1668260840015137, + 3.1674744999982067, + 3.168104083997605, + 3.1687218750012107, + 3.169341417000396, + 3.169958708997001, + 3.1705888340002275, + 3.1713534590016934, + 3.172032666996529, + 3.1726693339951453, + 3.173315208994609, + 3.173945416994684, + 3.1745927090014447, + 3.1754319999963627, + 3.1761416669978644, + 3.1768406670016702, + 3.177503541999613, + 3.1782113750014105, + 3.178868541996053, + 3.179519958997844, + 3.180217458997504, + 3.1808722089990624, + 3.181494416996429, + 3.1821434589946875, + 3.1827980839952943, + 3.183432375000848, + 3.1840762499996345, + 3.184718917000282, + 3.1853459589983686, + 3.185983999996097, + 3.186659166996833, + 3.1873002919965074, + 3.1879494589957176, + 3.1886094590008724, + 3.189256416997523, + 3.1898834589956095, + 3.190503958998306, + 3.1911713750014314, + 3.1917877919986495, + 3.1924303749983665, + 3.1930466249978053, + 3.193655958995805, + 3.1943129999999655, + 3.194957166997483, + 3.195776084001409, + 3.1964153750013793, + 3.197071999995387, + 3.1978018340014387, + 3.1985352499978035, + 3.199189083999954, + 3.19981099999859, + 3.2004404999970575, + 3.2010604169990984, + 3.2016877499991097, + 3.2023164999991423, + 3.2029784170008497, + 3.2035937089967774, + 3.204208249997464, + 3.2049166669967235, + 3.2055959999997867, + 3.206206458999077, + 3.206884250001167, + 3.2075040839990834, + 3.2082028750010068, + 3.2088552089990117, + 3.209512041998096, + 3.2101410839968594, + 3.210813708996284, + 3.2114552919956623, + 3.2120555419969605, + 3.2126490000009653, + 3.213272834000236, + 3.2138927089981735, + 3.2145259589960915, + 3.215168624999933, + 3.215873291999742, + 3.2165598339997814, + 3.2172377499955473, + 3.21792845899472, + 3.218534791994898, + 3.2191385420010192, + 3.219730459000857, + 3.220347167, + 3.2210782499969355, + 3.2217356249966542, + 3.222391499999503, + 3.222987208995619, + 3.223619708995102, + 3.2242617919982877, + 3.224871667000116, + 3.225563833999331, + 3.2261963749988354, + 3.2268307089980226, + 3.2275000419977005, + 3.228118708997499, + 3.2287273339970852, + 3.229374458998791, + 3.2299828749964945, + 3.2307580419947044, + 3.2313649589996203, + 3.2319976250000764, + 3.2326227919984376, + 3.233271249999234, + 3.2339404999947874, + 3.2346051249987795, + 3.2353435839977465, + 3.2360122919999412, + 3.2366865419971873, + 3.2373247089999495, + 3.2380058749986347, + 3.2386619999961113, + 3.239310500001011, + 3.239958291997027, + 3.240552958995977, + 3.241162541999074, + 3.24176545899536, + 3.242396708999877, + 3.2430446250000386, + 3.2437056669950834, + 3.2443222500005504, + 3.244964917001198, + 3.245588083998882, + 3.246175542000856, + 3.246838333994674, + 3.247599166999862, + 3.248220916997525, + 3.248890292001306, + 3.249540791999607, + 3.2502012499971897, + 3.2508552090002922, + 3.2514735419972567, + 3.2521323339969967, + 3.2527599169989116, + 3.2534228340009577, + 3.2541183339999407, + 3.254775333996804, + 3.255412416998297, + 3.256062333995942, + 3.256756583999959, + 3.257538083998952, + 3.2582414169955882, + 3.2589417499984847, + 3.2596367090009153, + 3.2602917089971015, + 3.260974708995491, + 3.261614249997365, + 3.2622512499947334, + 3.2628969590005, + 3.263619416997244, + 3.264262291995692, + 3.2649291249981616, + 3.2655919169992558, + 3.2662851249988307, + 3.266913374995056, + 3.2675420839950675, + 3.268174958997406, + 3.2688517499991576, + 3.2694997919970774, + 3.270145083995885, + 3.2707757919997675, + 3.27137912499893, + 3.272003209000104, + 3.2726302919982118, + 3.2732778339996003, + 3.273941958999785, + 3.2745652090015938, + 3.2752917499965406, + 3.2759909169981256, + 3.2767066250016796, + 3.2773775839959853, + 3.2781149169968558, + 3.278763333997631, + 3.279424416999973, + 3.280059541997616, + 3.280644083999505, + 3.2812757919964497, + 3.2819489169996814, + 3.282596958997601, + 3.2832426249951823, + 3.283902584000316, + 3.2845695419964613, + 3.285198917001253, + 3.2858230419951724, + 3.2864636250014883, + 3.287090708996402, + 3.287763749998703, + 3.288390834000893, + 3.2890507919946685, + 3.2896669170004316, + 3.2902744169987272, + 3.2909160839990363, + 3.2916325839978526, + 3.2922719169946504, + 3.2929236669951933, + 3.293542958999751, + 3.2942230420012493, + 3.294907791998412, + 3.295593999995617, + 3.2962675000017043, + 3.296959583996795, + 3.297624041995732, + 3.298241999997117, + 3.2989020419990993, + 3.299605000000156, + 3.3002712089946726, + 3.3009477500017965, + 3.3016184169973712, + 3.3022860839992063, + 3.302934416999051, + 3.303578374994686, + 3.304193708994717, + 3.3048376250008005, + 3.305430874999729, + 3.3061100419945433, + 3.306737708997389, + 3.3073635420005303, + 3.3080019999979413, + 3.3086177919976762, + 3.309279166998749, + 3.3099199589996715, + 3.310700750000251, + 3.311351083997579, + 3.3119937919982476, + 3.3126898749978864, + 3.31334433399752, + 3.3139993750010035, + 3.3146590420001303, + 3.3153308339969954, + 3.3160411669960013, + 3.3167107499975828, + 3.317365292001341, + 3.3180281249951804, + 3.318766083997616, + 3.319411833996128, + 3.320068499997433, + 3.3208208340001875, + 3.3214944589999504, + 3.3221349169980385, + 3.322788249999576, + 3.323464834000333, + 3.3241142089973437, + 3.3247379589956836, + 3.3253545420011505, + 3.326063084001362, + 3.326701250000042, + 3.3273434169968823, + 3.3280101669952273, + 3.3286192500017933, + 3.3292625839967513, + 3.329871458998241, + 3.330524583994702, + 3.331263084000966, + 3.331901874997129, + 3.332546249999723, + 3.3331979590002447, + 3.333888499997556, + 3.3345742089950363, + 3.335289541995735, + 3.3360761250005453, + 3.3367260839950177, + 3.33739070899901, + 3.3380390839956817, + 3.3386600839949097, + 3.3393160839987104, + 3.33996366700012, + 3.3405950000014855, + 3.3412170419978793, + 3.341856833998463, + 3.3424987499965937, + 3.3431088750003255, + 3.34373054200114, + 3.3443724169992493, + 3.345017542000278, + 3.345648666996567, + 3.3462386669998523, + 3.3469436669984134, + 3.3476524590005283, + 3.3483074589967146, + 3.3490077499955078, + 3.3497561249969294, + 3.350413583997579, + 3.3510585839976557, + 3.3517078750010114, + 3.352380374999484, + 3.353049708995968, + 3.353686791997461, + 3.35450279199722, + 3.3551896669960115, + 3.3558499589998974, + 3.356484541996906, + 3.35707358399668, + 3.3576872919948073, + 3.3583485839990317, + 3.359012333996361, + 3.3596360000010463, + 3.3602938749972964, + 3.360932124996907, + 3.3615910000007716, + 3.362252124999941, + 3.362869791999401, + 3.3635061669992865, + 3.3643061249968014, + 3.3652555840017158, + 3.3658603750009206, + 3.366502958997444, + 3.3671693750002305, + 3.36786462499731, + 3.3684834169980604, + 3.3691267920003156, + 3.3697196249995613, + 3.370327584001643, + 3.3709754169976804, + 3.37161820899928, + 3.3722664169981726, + 3.3729079170007026, + 3.3736322920012753, + 3.3743342089946964, + 3.37519975000032, + 3.375896334000572, + 3.3765396249946207, + 3.3771783339980175, + 3.377830375000485, + 3.3784997089969693, + 3.3791303749967483, + 3.3797821670013946, + 3.380444249996799, + 3.3810913749985048, + 3.3817543749973993, + 3.3823724999965634, + 3.382995084000868, + 3.383608916999947, + 3.384238541999366, + 3.384987874997023, + 3.3855795839990606, + 3.386210291995667, + 3.386847875000967, + 3.3874817920004716, + 3.388099042000249, + 3.3887057089959853, + 3.3893366670017713, + 3.389943750000384, + 3.3905692089974764, + 3.391206249994866, + 3.391845458994794, + 3.392499666995718, + 3.3931780839993735, + 3.3938234169982024, + 3.3944976669954485, + 3.3952364169963403, + 3.3958626669991645, + 3.396502999996301, + 3.3971652089967392, + 3.397787875001086, + 3.3984167919988977, + 3.399052084001596, + 3.399683374998858, + 3.4003630000006524, + 3.4009723749986733, + 3.4016021249990445, + 3.402213708999625, + 3.40284037499805, + 3.40349412499927, + 3.4041620419957326, + 3.404766624997137, + 3.4054207090011914, + 3.406050666999363, + 3.4066757089967723, + 3.407317166995199, + 3.4079725420015166, + 3.408576958994672, + 3.409270500000275, + 3.4099206249957206, + 3.41054395899846, + 3.4112137089978205, + 3.411928749999788, + 3.4126195419958094, + 3.4134592920017894, + 3.414146458999312, + 3.4148024169990094, + 3.415473333996488, + 3.416105708995019, + 3.416734541999176, + 3.417412874994625, + 3.418056958995294, + 3.418679666996468, + 3.4193407089987886, + 3.4200043339951662, + 3.4206351670000004, + 3.4212619999962044, + 3.4219241669998155, + 3.4225857499986887, + 3.4232239589982782, + 3.4238701249996666, + 3.424489791999804, + 3.4251300420000916, + 3.4257457919957233, + 3.4264114589968813, + 3.4270170839954517, + 3.427683083995362, + 3.4282834170007845, + 3.4288880839958438, + 3.4295159589964896, + 3.4301805419963785, + 3.4309999589968356, + 3.4316750840007444, + 3.4323575000016717, + 3.4330132089962717, + 3.4336978339997586, + 3.4343175839967444, + 3.434924166998826, + 3.4355808749969583, + 3.436199874995509, + 3.436837959001423, + 3.43745316699642, + 3.438069291994907, + 3.4386738339962903, + 3.439273708994733, + 3.439879249999649, + 3.44048233400099, + 3.4410764169952017, + 3.4416935839981306, + 3.442326708995097, + 3.442971166994539, + 3.44361362500058, + 3.444210124995152, + 3.4448706670009415, + 3.445488124998519, + 3.4460844169952907, + 3.446721125001204, + 3.4473894170005224, + 3.448063124997134, + 3.448707999996259, + 3.449337874997582, + 3.449958583994885, + 3.4506303339949227, + 3.451299749998725, + 3.452016958995955, + 3.452711708996503, + 3.4534405000013066, + 3.4541183339970303, + 3.4547372089946293, + 3.4553353340015747, + 3.4559217919959337, + 3.4565253749969997, + 3.457180334000441, + 3.457806124999479, + 3.458487833995605, + 3.4591041669991682, + 3.4597715419949964, + 3.460478000000876, + 3.461153167001612, + 3.4617918340009055, + 3.4624021669951617, + 3.4631165839964524, + 3.4637339170003543, + 3.4643543749989476, + 3.4650108749992796, + 3.46566266699665, + 3.4663013749959646, + 3.466940041995258, + 3.4676045839951257, + 3.468227334000403, + 3.4688772090012208, + 3.4695341249971534, + 3.470236916997237, + 3.4708920839984785, + 3.47163599999476, + 3.4723017500000424, + 3.4729155419991002, + 3.473530416995345, + 3.474177749994851, + 3.474828209000407, + 3.475463791997754, + 3.476055916995392, + 3.476818541996181, + 3.477461583999684, + 3.4781332919956185, + 3.478756249998696, + 3.479351041998598, + 3.479977124996367, + 3.480630541998835, + 3.4812851669994416, + 3.481976416995167, + 3.4826257089953288, + 3.4832756249961676, + 3.4839362089987844, + 3.484688999997161, + 3.4853234170004725, + 3.4860551249948912, + 3.486718791995372, + 3.4873681249955553, + 3.4880050419960753, + 3.4886401670009946, + 3.489279000001261, + 3.4901076249952894, + 3.490818375001254, + 3.4914757500009728, + 3.492121124996629, + 3.4927845839993097, + 3.4934117090015206, + 3.494044541999756, + 3.4946675839964882, + 3.4952719590000925, + 3.4958867499954067, + 3.4965122919966234, + 3.4971759589971043, + 3.497805209000944, + 3.4984264169979724, + 3.499114334001206, + 3.499759999998787, + 3.500374750001356, + 3.5010088749986608, + 3.5016061249989434, + 3.502222499999334, + 3.502855291997548, + 3.503582749995985, + 3.504217374997097, + 3.504875999999058, + 3.505487499998708, + 3.506228291997104, + 3.5068723750009667, + 3.5075207089976175, + 3.5081792089986266, + 3.5088741250001476, + 3.509629667001718, + 3.5103787499974715, + 3.511021416998119, + 3.511659083997074, + 3.5122948749994976, + 3.512920249995659, + 3.5135892089965637, + 3.5142232500002137, + 3.514834374997008, + 3.5155035839998163, + 3.5161559589978424, + 3.516809959000966, + 3.5174497089974466, + 3.5181024170015007, + 3.518726834001427, + 3.519344624997757, + 3.520002999997814, + 3.52066087500134, + 3.521281417000864, + 3.5219090839964338, + 3.522540666999703, + 3.5231666670006234, + 3.5237950000009732, + 3.5244231249962468, + 3.5250925419968553, + 3.5258293340011733, + 3.526504124994972, + 3.5271437089977553, + 3.5277922919995035, + 3.5284862920016167, + 3.5292219999973895, + 3.529953958997794, + 3.530712166997546, + 3.531400667001435, + 3.5320532089972403, + 3.5327256249947823, + 3.5333757089974824, + 3.5339961669960758, + 3.5346477499988396, + 3.535320666996995, + 3.5359379169967724, + 3.5365502089989604, + 3.537176999998337, + 3.5378104170013103, + 3.5384308339998825, + 3.539070916995115, + 3.539687917000265, + 3.5403492089972133, + 3.5411611249946873, + 3.541832292001345, + 3.5424574999997276, + 3.543096583998704, + 3.5437209169976995, + 3.5443177089982782, + 3.5449250419987948, + 3.5455860840011155, + 3.5461448339992785, + 3.5467733339974075, + 3.5474626249997527, + 3.5481374169976334, + 3.5488220839979476, + 3.549560333995032, + 3.550244541998836, + 3.550873499996669, + 3.5514630839970778, + 3.5521528749959543, + 3.5528410420010914, + 3.553455124994798, + 3.554087459000584, + 3.554759958999057, + 3.5553819589986233, + 3.555996666997089, + 3.5566191670004628, + 3.557271249999758, + 3.557880208994902, + 3.558517291996395, + 3.5592073750012787, + 3.5598481249980978, + 3.5604525839953567, + 3.5610919589962577, + 3.5617336249997607, + 3.5623607089946745, + 3.562998624998727, + 3.5636486669973237, + 3.5644134169997415, + 3.5650327920011478, + 3.56572341699939, + 3.566324583996902, + 3.5670259170001373, + 3.5677232919988455, + 3.568391916996916, + 3.569053166997037, + 3.5697057919969666, + 3.5703446670013363, + 3.5710591669994756, + 3.5717240839949227, + 3.57235404200037, + 3.5729930000015884, + 3.573597124996013, + 3.5741951249947306, + 3.5748190000012983, + 3.575457374994585, + 3.5761510000011185, + 3.5768859589952626, + 3.577525833999971, + 3.5781873339947197, + 3.5787964170012856, + 3.5793987500001094, + 3.5799790839955676, + 3.580663666994951, + 3.581327291998605, + 3.5819649170007324, + 3.58260208399588, + 3.5832276250002906, + 3.5838596670000697, + 3.5844815419986844, + 3.585118249997322, + 3.585748708996107, + 3.5864266249991488, + 3.587070749999839, + 3.5877054999946267, + 3.588360499998089, + 3.5890516669969657, + 3.589760874994681, + 3.5904516669979785, + 3.591192209001747, + 3.5918755419988884, + 3.592506708999281, + 3.59312625000166, + 3.5937599589960882, + 3.5943669170010253, + 3.5950203749962384, + 3.595619125000667, + 3.5962496669963, + 3.5969199999963166, + 3.5975484590017004, + 3.5981711669955985, + 3.598779291998653, + 3.599395375000313, + 3.600010875001317, + 3.6006698749988573, + 3.6012967499991646, + 3.6019535000014002, + 3.6025621250009863, + 3.603216124996834, + 3.603826416998345, + 3.6044695419986965, + 3.605097667001246, + 3.6057295840000734, + 3.606383583995921, + 3.607026334000693, + 3.6077824999956647, + 3.608474499997101, + 3.6091415420014528, + 3.609756166995794, + 3.610389124994981, + 3.6110920419960166, + 3.61176025000168, + 3.6124319169975934, + 3.613093249994563, + 3.6137369589996524, + 3.6143877919967053, + 3.615010916997562, + 3.615667874997598, + 3.6163025839996408, + 3.616925041998911, + 3.617577874996641, + 3.6182120419980492, + 3.618814041998121, + 3.6193892090013833, + 3.6199967499997, + 3.6206199590014876, + 3.6212712089982233, + 3.6219373749991064, + 3.622546541999327, + 3.623172583997075, + 3.623769459001778, + 3.6244097919989144, + 3.6250638749988866, + 3.625722999997379, + 3.626330250001047, + 3.6269446250007604, + 3.62753816699842, + 3.628251083995565, + 3.628929792001145, + 3.629745083999296, + 3.630404916999396, + 3.631051333999494, + 3.6316563750006026, + 3.632321375000174, + 3.6329532919990015, + 3.6336053339982755, + 3.634247709000192, + 3.634914124995703, + 3.6355353749968344, + 3.636179542001628, + 3.6368073749981704, + 3.637442874998669, + 3.638095958995109, + 3.6387164170009783, + 3.6393337920017075, + 3.6399934590008343, + 3.6406080839951755, + 3.641362208996725, + 3.641978250001557, + 3.642591291994904, + 3.643223125000077, + 3.6438324999980978, + 3.6444754999974975, + 3.645103458999074, + 3.645702292000351, + 3.646313042001566, + 3.646957500001008, + 3.647881042001245, + 3.648591999997734, + 3.649245708998933, + 3.6498996669979533, + 3.650578000000678, + 3.6512574590014992, + 3.651923583995085, + 3.6525472089997493, + 3.653169124998385, + 3.653807374997996, + 3.654444624997268, + 3.6550774999996065, + 3.6556923749958514, + 3.656321083995863, + 3.656954833997588, + 3.657573541997408, + 3.658164583997859, + 3.6587854999961564, + 3.6594184169953223, + 3.6600916249954025, + 3.660726458998397, + 3.661337958998047, + 3.661952875001589, + 3.6625959999946645, + 3.663248416996794, + 3.6640092089946847, + 3.6646822499969858, + 3.665304333997483, + 3.665968333996716, + 3.6666019999975106, + 3.667264958996384, + 3.667972833995009, + 3.668610249995254, + 3.669297624997853, + 3.669996666998486, + 3.670667250000406, + 3.671296959000756, + 3.6719734169964795, + 3.6725837499980116, + 3.6732067089978955, + 3.673850749997655, + 3.6745059169988963, + 3.675165874999948, + 3.6757988749959623, + 3.6765534590012976, + 3.6772080839946284, + 3.677858541996102, + 3.6785195420015953, + 3.6791424170005484, + 3.679784749998362, + 3.680519249995996, + 3.6811253749983734, + 3.6817948339958093, + 3.6824470840001595, + 3.683184875000734, + 3.683804666994547, + 3.6844979589950526, + 3.685122833994683, + 3.685754583995731, + 3.6864134999996168, + 3.6871154170003138, + 3.687785875001282, + 3.688431834001676, + 3.6890852919968893, + 3.6897372089952114, + 3.690381583997805, + 3.6910284999976284, + 3.6916653340013, + 3.6923001670002122, + 3.692987999995239, + 3.693615083997429, + 3.694283666998672, + 3.694920624999213, + 3.69555233400024, + 3.696184666994668, + 3.696811458998127, + 3.6974987919966225, + 3.698148167000909, + 3.698806208994938, + 3.6994543749970035, + 3.7001544999948237, + 3.7007682920011575, + 3.7013845420005964, + 3.7020582089971867, + 3.702770291994966, + 3.703414833995339, + 3.70407104199694, + 3.704669541999465, + 3.7053329999980633, + 3.7059487090009497, + 3.706738166998548, + 3.7074075839991565, + 3.70819237500109, + 3.7088691249955446, + 3.709527084000001, + 3.7101568750003935, + 3.7107735839963425, + 3.7114759999967646, + 3.7121389169988106, + 3.7127570419979747, + 3.713376749998133, + 3.7140029590009362, + 3.714640792000864, + 3.7152825419980218, + 3.7159317920013564, + 3.7165744169979007, + 3.717225624997809, + 3.717865749997145, + 3.7185056669986807, + 3.7191217919971677, + 3.7197601669977303, + 3.7203932919946965, + 3.721022958998219, + 3.7216671249989304, + 3.722409541995148, + 3.723052124994865, + 3.723901042001671, + 3.72466274999897, + 3.725324416998774, + 3.7260731249989476, + 3.7267879999999423, + 3.727483416994801, + 3.7281553339998936, + 3.7288213339998038, + 3.729440541996155, + 3.7300954169986653, + 3.7307652089948533, + 3.7313979169994127, + 3.732048208999913, + 3.732652250000683, + 3.733329834001779, + 3.7339773339990643, + 3.7345956249992014, + 3.735410374996718, + 3.736237416997028, + 3.7368754589988384, + 3.737529749996611, + 3.7381740839991835, + 3.7387930839977344, + 3.7394254589962657, + 3.740099458998884, + 3.7407336670003133, + 3.741336749997572, + 3.74199737500021, + 3.742670374995214, + 3.7432936249970226, + 3.7439646249986254, + 3.744607166998321, + 3.7452958750000107, + 3.745957291997911, + 3.746651708999707, + 3.747348624994629, + 3.747996833997604, + 3.7486100419992, + 3.749285958998371, + 3.7499231249967124, + 3.750573124998482, + 3.7512224999954924, + 3.7518560419994174, + 3.7525152919988614, + 3.753145249997033, + 3.7537862089957343, + 3.754441583994776, + 3.755081584000436, + 3.7558432090008864, + 3.7565281669958495, + 3.7572106669977074, + 3.757860666999477, + 3.758514083994669, + 3.759166458999971, + 3.759799708997889, + 3.7604105419959524, + 3.7610135419963626, + 3.761642999998003, + 3.762288375000935, + 3.7629271670011804, + 3.7635706669971114, + 3.7642421669952455, + 3.7649441249959636, + 3.765664749997086, + 3.7663847919975524, + 3.7670827499969164, + 3.767756166998879, + 3.7684154999951716, + 3.769086291998974, + 3.7697337089994107, + 3.7703692089999095, + 3.7710039999947185, + 3.7716777499954333, + 3.772329499995976, + 3.772945584001718, + 3.7735845419956604, + 3.7742618749980466, + 3.7749142089960515, + 3.7755902919961954, + 3.7762575000015204, + 3.776904458994977, + 3.777524874996743, + 3.7782166249962756, + 3.77887962499517, + 3.7795290840003872, + 3.780328291999467, + 3.7810148339995067, + 3.781696334001026, + 3.782347749998735, + 3.7830066249953234, + 3.7836824170008185, + 3.7844082500014338, + 3.7851716250006575, + 3.785865208999894, + 3.7865040420001606, + 3.787130291995709, + 3.787763000000268, + 3.788420208999014, + 3.7890486249962123, + 3.789677417000348, + 3.790279708999151, + 3.7909158339971327, + 3.7915695420015254, + 3.7922157919965684, + 3.7928644999992684, + 3.7934914590005064, + 3.7941219999993336, + 3.794753750000382, + 3.7953707089982345, + 3.7959894169980544, + 3.796635291997518, + 3.7972609999997076, + 3.7979101669989177, + 3.798604958996293, + 3.7992517499951646, + 3.799944999998843, + 3.8005994589984766, + 3.8012155839969637, + 3.8017998750001425, + 3.8024262089966214, + 3.8031238339972333, + 3.803785791998962, + 3.804516666998097, + 3.8051926249972894, + 3.8058411669990164, + 3.806485499997507, + 3.807160541997291, + 3.807856333995005, + 3.8085329169989564, + 3.8091888749986538, + 3.809813916996063, + 3.8104331669965177, + 3.8110345839959336, + 3.8117751669997233, + 3.8124450420000358, + 3.8131102089973865, + 3.8137124169952585, + 3.8143583339988254, + 3.8150013749982463, + 3.8155915419993107, + 3.8162156249964028, + 3.816867583998828, + 3.8174995000008494, + 3.8181168750015786, + 3.8187612920009997, + 3.8194007919955766, + 3.8200615839959937, + 3.8207010420010192, + 3.821344958996633, + 3.8219869999957155, + 3.822664541999984, + 3.8233079169949633, + 3.82399712500046, + 3.8246281249957974, + 3.82525058399915, + 3.8259094589957385, + 3.826561124995351, + 3.8271675419964595, + 3.827820166996389, + 3.82847879199835, + 3.829075292000198, + 3.829659041999548, + 3.8303353340015747, + 3.831011750000471, + 3.8316369589956594, + 3.832276916997216, + 3.8329051670007175, + 3.8335778339969693, + 3.834230916996603, + 3.834826250000333, + 3.83543758399901, + 3.8360730839995085, + 3.8366933340003015, + 3.8373464589967625, + 3.837985166996077, + 3.838608624995686, + 3.8392472919949796, + 3.839872958997148, + 3.840524084000208, + 3.841155791997153, + 3.841803167000762, + 3.8425068340002326, + 3.84324524999829, + 3.8439837920013815, + 3.844635583998752, + 3.845266708995041, + 3.8459124169967254, + 3.846573416994943, + 3.847240791998047, + 3.847868083998037, + 3.848533791999216, + 3.8491899169966928, + 3.8497979169987957, + 3.850415000000794, + 3.8510596249980154, + 3.8516746669993154, + 3.8524171249955543, + 3.853050459001679, + 3.8536918749960023, + 3.8543173750003916, + 3.854947791995073, + 3.8555946669948753, + 3.8562244589993497, + 3.8568677919975016, + 3.857530916997348, + 3.8581661249991157, + 3.8588126670001657, + 3.85942987499584, + 3.8602174170009675, + 3.86085487499804, + 3.861496249999618, + 3.8622915000014473, + 3.8629612090007868, + 3.8636635840011877, + 3.864442499994766, + 3.865167083997221, + 3.865780291998817, + 3.866436584001349, + 3.8670751669997117, + 3.8677435839999816, + 3.868382249995193, + 3.8690363749992684, + 3.8696471669973107, + 3.8702564999985043, + 3.870873916996061, + 3.8714887089954573, + 3.8721114590007346, + 3.8727232499950333, + 3.8733520839959965, + 3.8740243749998626, + 3.874700208994909, + 3.875363084000128, + 3.876031125000736, + 3.876685916999122, + 3.877305041998625, + 3.8779622919973917, + 3.8785808339962387, + 3.87921058399661, + 3.87985229199694, + 3.880482959000801, + 3.881266083997616, + 3.8819435839977814, + 3.8826037920007366, + 3.8832252499996684, + 3.883886999996321, + 3.8845102089981083, + 3.8851774590002606, + 3.885858374997042, + 3.8864778749994002, + 3.8871651250010473, + 3.8877929169975687, + 3.888439666996419, + 3.8890797499989276, + 3.8897066669960623, + 3.8903165419978905, + 3.8909776250002324, + 3.8916199169980246, + 3.8923525419959333, + 3.893030084000202, + 3.893674374994589, + 3.894353791998583, + 3.89499487500143, + 3.8956393749976996, + 3.896238417000859, + 3.896875291997276, + 3.897507666995807, + 3.898184041994682, + 3.898844499999541, + 3.8994981669966364, + 3.900116541997704, + 3.900773624998692, + 3.901455541999894, + 3.902206416998524, + 3.902865042000485, + 3.9035272920009447, + 3.904169916997489, + 3.904900749999797, + 3.905507999996189, + 3.9061276669963263, + 3.906818833995203, + 3.9074368750007125, + 3.9080695000011474, + 3.9086974169986206, + 3.9093516249995446, + 3.9100087499973597, + 3.9106417919974774, + 3.9112647919973824, + 3.911916500001098, + 3.912536584000918, + 3.913218166999286, + 3.9138976670001284, + 3.9145209999987856, + 3.9151402919960674, + 3.915755417001492, + 3.916382541996427, + 3.917024208996736, + 3.917641749998438, + 3.9182903749970137, + 3.918905583996093, + 3.9195236250016023, + 3.920247834001202, + 3.920897584001068, + 3.9215485419990728, + 3.922188124997774, + 3.922819499995967, + 3.923455374999321, + 3.924095666996436, + 3.924844499997562, + 3.9255317089991877, + 3.9261936670009163, + 3.9268341249990044, + 3.9274277919976157, + 3.9280782919959165, + 3.9286936249991413, + 3.9293898749965592, + 3.930083791994548, + 3.9307497499976307, + 3.931390999998257, + 3.9320294999997714, + 3.9326890839947737, + 3.9333189589960966, + 3.9339402920013526, + 3.9345816249988275, + 3.9352222089946736, + 3.935844499996165, + 3.936461124998459, + 3.9370783749982365, + 3.9376957499989658, + 3.9383345839960384, + 3.9389585419994546, + 3.939581458995235, + 3.9401915419948637, + 3.940802958997665, + 3.941449041994929, + 3.9420662919947063, + 3.9429114169979584, + 3.943579583996325, + 3.944301584000641, + 3.9449430419990676, + 3.945560291998845, + 3.946213709001313, + 3.946822624995548, + 3.9474801249962184, + 3.9481160419964, + 3.948752333999437, + 3.9494106249985634, + 3.9500549169970327, + 3.950716499995906, + 3.9513415420005913, + 3.9519881250016624, + 3.9526290419962606, + 3.953249375001178, + 3.9539246249987627, + 3.954578541997762, + 3.9551933339971583, + 3.955838458998187, + 3.956478291998792, + 3.9572271249999176, + 3.95784512499813, + 3.9585110420011915, + 3.9591762089985423, + 3.9598588750013732, + 3.9605102499990608, + 3.9611440419976134, + 3.961801833997015, + 3.962439208997239, + 3.963151874995674, + 3.9638298339996254, + 3.9644886669993866, + 3.9651307499952964, + 3.965754917000595, + 3.966404999999213, + 3.9670438339962857, + 3.9676724589953665, + 3.9682764589961153, + 3.968914083998243, + 3.9696107499985374, + 3.970248666999396, + 3.9708552500014775, + 3.9714945839950815, + 3.9721456249972107, + 3.9727821669948753, + 3.9734388340002624, + 3.974084292000043, + 3.9747310419988935, + 3.9753484169996227, + 3.976014166997629, + 3.976636084000347, + 3.977288709000277, + 3.977930875000311, + 3.9785322499956237, + 3.9791647089950857, + 3.979795084000216, + 3.980439541999658, + 3.9811451669957023, + 3.981815999999526, + 3.982478624995565, + 3.9831466249961522, + 3.983781666996947, + 3.9844073339991155, + 3.9850541669948143, + 3.9856489169978886, + 3.9862735419956152, + 3.9868973749980796, + 3.9876799170015147, + 3.9883542919997126, + 3.9889875419976306, + 3.98968520899507, + 3.9904248339953483, + 3.9911050419977983, + 3.9917882090012426, + 3.992465249997622, + 3.993155874995864, + 3.9938484169979347, + 3.994559291997575, + 3.9952280840007006, + 3.9959077919993433, + 3.996563041997433, + 3.9972369169990998, + 3.998005541994644, + 3.9986704170005396, + 3.999284459001501, + 3.9999777089979034, + 4.000729958999727, + 4.001464666995162, + 4.002223584000603, + 4.002867249997507, + 4.003481667001324, + 4.004126041996642, + 4.0047309169967775, + 4.005364416996599, + 4.0060546249951585, + 4.006642458996794, + 4.007208124996396, + 4.007808666996425, + 4.00840108400007, + 4.008994499999972, + 4.009617833995435, + 4.010145583997655, + 4.010652375000063, + 4.011290292000922, + 4.011856958997669, + 4.012382666995109, + 4.012892334001663, + 4.0134201670007315, + 4.01395395900181, + 4.014472709000984, + 4.015009666996775, + 4.015528584001004, + 4.0160102919981, + 4.016578208997089, + 4.019120666998788, + 4.0200388340017525, + 4.0207057500010706, + 4.02139399999578, + 4.0221842089958955, + 4.0227269169990905, + 4.0232345839976915, + 4.023731666995445, + 4.02430212499894, + 4.024976208995213, + 4.025498333998257, + 4.026076417001605, + 4.026654333996703, + 4.027223541997955, + 4.027803166995, + 4.02831979199982, + 4.028872083996248, + 4.029430499998853, + 4.0300764169951435, + 4.030913124996005, + 4.031531791995803, + 4.03216304200032, + 4.032696249996661, + 4.03323987499607, + 4.0337731249965145, + 4.034496208994824, + 4.0350403749980615, + 4.035586124999099, + 4.036127916995611, + 4.036729209001351, + 4.0373154589979094, + 4.037868333994993, + 4.038415167000494, + 4.0389571669948054, + 4.039680124995357, + 4.04032775000087, + 4.0409565000009025, + 4.041588084000978, + 4.0421920840017265, + 4.042766749997099, + 4.043325499995262, + 4.04389179199643, + 4.04441954199865, + 4.0449181250005495, + 4.0454750419958145, + 4.046030666999286, + 4.046589666999353, + 4.047269208997022, + 4.0478416249970905, + 4.048405166999146, + 4.048941083994578, + 4.049468749995867, + 4.0500022919950425, + 4.050517042000138, + 4.051036083998042, + 4.051567416994658, + 4.0520972090016585, + 4.052639541994722, + 4.053169334001723, + 4.053737374997581, + 4.0542628339972, + 4.054904249998799, + 4.055471708998084, + 4.056035959001747, + 4.05652425000153, + 4.057073833995673, + 4.057614666999143, + 4.058136374995229, + 4.058675708998635, + 4.059352541997214, + 4.059901874999923, + 4.060540291997313, + 4.0610986669998965, + 4.061652500000491, + 4.062223333996371, + 4.0627662089973455, + 4.063313416998426, + 4.063851166996756, + 4.064403124997625, + 4.064946209000482, + 4.06552170899522, + 4.066011333998176, + 4.066564374996233, + 4.067080959001032, + 4.067627416996402, + 4.068149250000715, + 4.06870354199782, + 4.069234499998856, + 4.06982679200155, + 4.070519875000173, + 4.071080208996136, + 4.071563291996426, + 4.072132875000534, + 4.072680249999394, + 4.073195416996896, + 4.07370070899924, + 4.074244584000553, + 4.0747824589998345, + 4.0753409169992665, + 4.075849458997254, + 4.076418708995334, + 4.076992624999548, + 4.077537708995806, + 4.078161583995097, + 4.078837333996489, + 4.079464958995231, + 4.080107041998417, + 4.08073429200158, + 4.081314750001184, + 4.081842833998962, + 4.082391333999112, + 4.082979999999225, + 4.083546458998171, + 4.084110124997096, + 4.084716874996957, + 4.085307499997725, + 4.085852917000011, + 4.086445125001774, + 4.0870387089962605, + 4.087589083996136, + 4.088104333997762, + 4.0886778339991, + 4.089262000001327, + 4.089829708995239, + 4.090387791999092, + 4.09092654199776, + 4.091481416995521, + 4.092024375000619, + 4.092593000001216, + 4.0931888749983045, + 4.093781833995308, + 4.094346083998971, + 4.094922208998469, + 4.095490542000334, + 4.096047792001627, + 4.09660804199666, + 4.0971676249973825, + 4.0979109999971115, + 4.09850537499733, + 4.099172499998531, + 4.099769374995958, + 4.100322334001248, + 4.100943583995104, + 4.101468666995061, + 4.102033292001579, + 4.1026754999984405, + 4.10323733399855, + 4.103776374999143, + 4.1043184169975575, + 4.104906499997014, + 4.105492583999876, + 4.1060312499976135, + 4.106611208997492, + 4.10717641699739, + 4.107748999995238, + 4.108291083997756, + 4.108868999996048, + 4.109427958996093, + 4.109974209000939, + 4.110527666998678, + 4.111071166997135, + 4.111606749997009, + 4.11218929199822, + 4.112814208994678, + 4.113450958997419, + 4.114077583995822, + 4.1146758339964435, + 4.115202000000863, + 4.115747124997142, + 4.116257041998324, + 4.116885584000556, + 4.117530083996826, + 4.1181120420005755, + 4.118731791997561, + 4.119275791999826, + 4.119887959001062, + 4.12044616699859, + 4.121040666999761, + 4.121570625000459, + 4.122147124995536, + 4.12264783399587, + 4.123205416995916, + 4.123748041994986, + 4.124322374998883, + 4.124925584001176, + 4.125637459001155, + 4.126252916998055, + 4.126819583994802, + 4.12740012499853, + 4.127978666998388, + 4.128522749997501, + 4.129094083997188, + 4.129638083999453, + 4.130193791999773, + 4.1307742499993765, + 4.131321542001388, + 4.1318253749996074, + 4.132344459001615, + 4.1329255839955295, + 4.133452709000267, + 4.133999291996588, + 4.134546583998599, + 4.135064666996186, + 4.135616667001159, + 4.136210666998522, + 4.136786709001171, + 4.137382166998577, + 4.138031709000643, + 4.138596791999589, + 4.139190249996318, + 4.139730791997863, + 4.140263291999872, + 4.140865000001213, + 4.14142183399963, + 4.141986124996038, + 4.1425278339957, + 4.143081083995639, + 4.143655749998288, + 4.144202499999665, + 4.1447641249978915, + 4.145332333995611, + 4.1458961669995915, + 4.146465792000527, + 4.146993750000547, + 4.147549583998625, + 4.148562958995171, + 4.149109499994665, + 4.149767791997874, + 4.150346166999952, + 4.1509058750016266, + 4.151429541998368, + 4.151983958996425, + 4.152535333996639, + 4.153125833996455, + 4.153703083997243, + 4.154238041999633, + 4.154772709000099, + 4.155348708998645, + 4.155978750000941, + 4.156624249997549, + 4.157220542001596, + 4.157794833998196, + 4.158369833996403, + 4.158914458996151, + 4.159530208999058, + 4.16009016699536, + 4.160675833998539, + 4.1612192089960445, + 4.161759416994755, + 4.162344459000451, + 4.16287949999969, + 4.163432333996752, + 4.164070541999536, + 4.164643874995818, + 4.165147667001293, + 4.165688208995562, + 4.166237124998588, + 4.166820124999504, + 4.167345834001026, + 4.167921667001792, + 4.168476749997353, + 4.169011166995915, + 4.169562750001205, + 4.170144458999857, + 4.17067537499679, + 4.1712145839992445, + 4.171765958999458, + 4.172311333997641, + 4.172916541996528, + 4.1734737919978215, + 4.174055666997447, + 4.174616124997556, + 4.175325958996837, + 4.176058749995718, + 4.17674195899599, + 4.177386249997653, + 4.177974291997089, + 4.1785625420016, + 4.179077583998151, + 4.179619875001663, + 4.180152749999252, + 4.180765375000192, + 4.1813515839967295, + 4.181914458997198, + 4.1824486249970505, + 4.182993458998681, + 4.183570374996634, + 4.18408429199917, + 4.184625834001054, + 4.185196334001375, + 4.185699916997692, + 4.186270416998013, + 4.186814249995223, + 4.187325999999302, + 4.18788024999958, + 4.188409834001504, + 4.188999083999079, + 4.189529333998507, + 4.190047958996729, + 4.190579709000303, + 4.191146708995802, + 4.191738458997861, + 4.19229779199668, + 4.192806416998792, + 4.1934742500016, + 4.194037583998579, + 4.194585541998094, + 4.195250917000521, + 4.195931166999799, + 4.196525499995914, + 4.197139167001296, + 4.197712708999461, + 4.198276374998386, + 4.198831666995829, + 4.199365166998177, + 4.199903084001562, + 4.2004742919962155, + 4.201028291994589, + 4.201531583996257, + 4.202050374995451, + 4.2025744169950485, + 4.203133916998922, + 4.20369208399643, + 4.204257208999479, + 4.204815042001428, + 4.205371291995107, + 4.205926208996971, + 4.206466333998833, + 4.2070103750011185, + 4.207547166995937, + 4.208105666999472, + 4.208767374999297, + 4.209339083994564, + 4.209973291995993, + 4.210521249995509, + 4.2110694169969065, + 4.211635583997122, + 4.212188583995157, + 4.21275041699846, + 4.213267624996661, + 4.213829833999625, + 4.214413666995824, + 4.214989374995639, + 4.2156529589992715, + 4.216308416995162, + 4.216832624995732, + 4.217364208998333, + 4.217917000001762, + 4.218458666997321, + 4.219015458998911, + 4.219551333997515, + 4.220094541997241, + 4.2206686249992345, + 4.22121683399746, + 4.221763791996636, + 4.222369124996476, + 4.222887459000049, + 4.223432209000748, + 4.223947250000492, + 4.224531250001746, + 4.225100916999509, + 4.225697124995349, + 4.2262701250001555, + 4.226813291999861, + 4.227316416996473, + 4.227869624999585, + 4.228390749995015, + 4.22891820899531, + 4.229435499997635, + 4.230030209000688, + 4.230538999996497, + 4.23110016699502, + 4.231655124996905, + 4.232199458994728, + 4.232775500000571, + 4.23332941699482, + 4.233981999997923, + 4.2345194590016035, + 4.235093625000445, + 4.235702874997514, + 4.236245041996881, + 4.236833499999193, + 4.237431333996938, + 4.237943916996301, + 4.238517291996686, + 4.239087541995104, + 4.239669624999806, + 4.240222166998137, + 4.240766958995664, + 4.2413028750015656, + 4.241861958995287, + 4.242417959001614, + 4.242996542001492, + 4.243562042000121, + 4.24411304199748, + 4.2446783339983085, + 4.245200291996298, + 4.245750458998373, + 4.246654124995985, + 4.247392208999372, + 4.247918959001254, + 4.248476417000347, + 4.249023999997007, + 4.249561416996585, + 4.250146416998177, + 4.250733499997295, + 4.251258584001334, + 4.251745292000123, + 4.2522734999947716, + 4.252814125000441, + 4.253367124998476, + 4.253921499999706, + 4.254464583995286, + 4.255078834001324, + 4.25560429199686, + 4.256284083996434, + 4.256854209001176, + 4.257439249995514, + 4.258048083996982, + 4.2586114590012585, + 4.259254874996259, + 4.259837459001574, + 4.260440291996929, + 4.261057833995437, + 4.261625166996964, + 4.262212208996061, + 4.26279079199594, + 4.26340537500073, + 4.263957292001578, + 4.264516999995976, + 4.265016042001662, + 4.265562333996058, + 4.266115458995046, + 4.2666436250001425, + 4.267163541997434, + 4.26768841699959, + 4.268198041994765, + 4.2686952500007465, + 4.269242791997385, + 4.269776542001637, + 4.270308583996666, + 4.270839917000558, + 4.2714117919967975, + 4.272108999997727, + 4.272664500000246, + 4.273227749996295, + 4.273779416995239, + 4.274280749996251, + 4.274836459000653, + 4.275330459000543, + 4.27601416700054, + 4.276559124999039, + 4.277139500001795, + 4.277723084000172, + 4.278298708995862, + 4.278901375000714, + 4.279467041997123, + 4.280038291995879, + 4.280575625001802, + 4.2811411669972586, + 4.281754916999489, + 4.282342541999242, + 4.282893584000703, + 4.283431458999985, + 4.283983624998655, + 4.284534916994744, + 4.285117166997225, + 4.285677749998285, + 4.286213833998772, + 4.286741666997841, + 4.287240874997224, + 4.287802833998285, + 4.288363333995221, + 4.288931958995818, + 4.289485959001468, + 4.290027916998952, + 4.2905757920016185, + 4.291108042001724, + 4.291683499999635, + 4.292291083998862, + 4.292900791995635, + 4.293433792001451, + 4.293989083998895, + 4.294583167000383, + 4.295225000001665, + 4.295767791998514, + 4.296335125000041, + 4.296879166999133, + 4.297449166995648, + 4.297963416996936, + 4.29854041699582, + 4.299082792000263, + 4.299658083997201, + 4.3001924169948325, + 4.300757375000103, + 4.301307000001543, + 4.301881583996874, + 4.302410249998502, + 4.302971416997025, + 4.303576708996843, + 4.304105374998471, + 4.304639000001771, + 4.305154791996756, + 4.305719167001371, + 4.3062705420015845, + 4.306847166997613, + 4.307383999999729, + 4.307906083995476, + 4.308442959001695, + 4.309012541998527, + 4.309551541999099, + 4.310089958999015, + 4.310598916999879, + 4.311133625000366, + 4.311702041995886, + 4.312235792000138, + 4.312785249996523, + 4.3133298749962705, + 4.3138610839960165, + 4.314478666994546, + 4.315057209001679, + 4.315665499998431, + 4.316227041999809, + 4.31675191699469, + 4.317280666997249, + 4.3178015839948785, + 4.31836441699852, + 4.31889974999649, + 4.31957433399657, + 4.320135166999535, + 4.32067983399611, + 4.321269624997512, + 4.321835709000879, + 4.322402291996696, + 4.3229469590005465, + 4.323482374995365, + 4.324021374995937, + 4.324570249998942, + 4.325146999995923, + 4.325673916995584, + 4.3262196669966215, + 4.32679541700054, + 4.327333624998573, + 4.3278752920014085, + 4.328438874996209, + 4.3289794999946025, + 4.32949708399974, + 4.330022292000649, + 4.330611541998223, + 4.331133916995896, + 4.331618749994959, + 4.332169916997373, + 4.332736666998244, + 4.333296208998945, + 4.334002750001673, + 4.334644333997858, + 4.335273500000767, + 4.335867041998426, + 4.336462541999936, + 4.337023084000975, + 4.337573083997995, + 4.338083666996681, + 4.338616417000594, + 4.339187999998103, + 4.3397882919962285, + 4.340335624998261, + 4.340904249998857, + 4.3415061669948045, + 4.342047583995736, + 4.342624541997793, + 4.343207958998391, + 4.343755499998224, + 4.344341291995079, + 4.34489841699542, + 4.345456833994831, + 4.345992916998512, + 4.346520499995677, + 4.347089458999108, + 4.347749874999863, + 4.348336833994836, + 4.34894487499696, + 4.34963741699903, + 4.35029349999968, + 4.3510027500014985, + 4.351640749999206, + 4.3522924999997485, + 4.352992458996596, + 4.353641958994558, + 4.354347291999147, + 4.354999625000346, + 4.355698916995607, + 4.3563022919988725, + 4.356937917000323, + 4.357592041997123, + 4.358208833997196, + 4.358806749994983, + 4.359437084000092, + 4.36004604199843, + 4.3606862089945935, + 4.361300333999679, + 4.361993958998937, + 4.362716416995681, + 4.363348334001785, + 4.363990124998963, + 4.364690124995832, + 4.365380625000398, + 4.366060624997772, + 4.366694374999497, + 4.367419709000387, + 4.368065167000168, + 4.368736500000523, + 4.369375666996348, + 4.370035749998351, + 4.37064366699633, + 4.371284499997273, + 4.371918208998977, + 4.372719416998734, + 4.373366791995068, + 4.374076708998473, + 4.374802792000992, + 4.375500333997479, + 4.3761327089960105, + 4.376772124996933, + 4.377389458997641, + 4.378010458996869, + 4.378640124996309, + 4.379266625001037, + 4.379965125001036, + 4.38057362499967, + 4.381218624999747, + 4.381879708998895, + 4.382515833996877, + 4.383175625000149, + 4.3838159590013674, + 4.384445167001104, + 4.38507920900156, + 4.385722333994636, + 4.386375624999346, + 4.3870048339958885, + 4.387625541996385, + 4.388286875000631, + 4.388909959001467, + 4.389555999994627, + 4.3901646669983165, + 4.39082166699518, + 4.391470916998514, + 4.392144749996078, + 4.392842749999545, + 4.393526041996665, + 4.394343416999618, + 4.394982208999863, + 4.395618583999749, + 4.3962709170009475, + 4.396868833995541, + 4.397512584000651, + 4.398169000000053, + 4.398761459000525, + 4.399351874999411, + 4.400021708999702, + 4.400682499996037, + 4.401343334000558, + 4.401994791995094, + 4.402636083999823, + 4.403232291995664, + 4.404046666997601, + 4.404714042000705, + 4.405378374998691, + 4.4060403749972465, + 4.406686583999544, + 4.407321291997505, + 4.407965458995022, + 4.408594833999814, + 4.409254833997693, + 4.409916708995297, + 4.410564999998314, + 4.411227958997188, + 4.411932249997335, + 4.4126047089957865, + 4.413299125000776, + 4.414696833999187, + 4.4153460419984185, + 4.415961708997202, + 4.41654158399615, + 4.417240499999025, + 4.417890625001746, + 4.418537874997128, + 4.4191941669996595, + 4.419836208995548, + 4.420507874994655, + 4.4211521670004, + 4.421828375001496, + 4.422496333994786, + 4.423167041997658, + 4.423785792001581, + 4.42447008399904, + 4.425140749997809, + 4.4257842090009945, + 4.426403124998615, + 4.427071583995712, + 4.427705624999362, + 4.428341667000495, + 4.429015666995838, + 4.429625416996714, + 4.430325166998955, + 4.431023459001153, + 4.431683916998736, + 4.432487083999149, + 4.433146791998297, + 4.433773625001777, + 4.434411333997559, + 4.435058416995162, + 4.435696499996993, + 4.436357334001514, + 4.436977249999472, + 4.437655958994583, + 4.43828124999709, + 4.438934833997337, + 4.439573208997899, + 4.440206374994887, + 4.440850416998728, + 4.441445042000851, + 4.44207029199606, + 4.44269645899476, + 4.443349458997545, + 4.44397683400166, + 4.444606708995707, + 4.445211708996794, + 4.445863249995455, + 4.446535666997079, + 4.447197749999759, + 4.44789049999963, + 4.448526583997591, + 4.449169791994791, + 4.449797374996706, + 4.450481667001441, + 4.451146749997861, + 4.4518100839995896, + 4.452586250001332, + 4.453250624996144, + 4.453944041997602, + 4.4545945419959025, + 4.455231833999278, + 4.455865416995948, + 4.456506541995623, + 4.457082583998272, + 4.457769374996133, + 4.4584412920012255, + 4.459093459001451, + 4.459719041995413, + 4.460370125001646, + 4.461023374999058, + 4.461635708998074, + 4.462261874999967, + 4.462900041995454, + 4.463524124999822, + 4.46419858399895, + 4.4648597089981195, + 4.465496416996757, + 4.466173458997218, + 4.466785541997524, + 4.467393333994551, + 4.468023166999046, + 4.468623249995289, + 4.469241124999826, + 4.469884458994784, + 4.470504791999701, + 4.471200499996485, + 4.471854584000539, + 4.472504958997888, + 4.473212666998734, + 4.473843250001664, + 4.474480208999012, + 4.475093291999656, + 4.475708250000025, + 4.476351375000377, + 4.476981583997258, + 4.4776395419976325, + 4.478291291998175, + 4.47891924999567, + 4.47956841699488, + 4.480220792000182, + 4.480892084000516, + 4.481527666997863, + 4.482251749999705, + 4.482918083995173, + 4.4835440419992665, + 4.484160374995554, + 4.484785791995819, + 4.48544291700091, + 4.486058292000962, + 4.486697499996808, + 4.48735733400099, + 4.48801258399908, + 4.48869345899584, + 4.489351208998414, + 4.4899849590001395, + 4.49070324999775, + 4.491409124995698, + 4.492077333998168, + 4.492741541995201, + 4.493400084000314, + 4.494070708999061, + 4.494730792001064, + 4.495364458998665, + 4.496064416998706, + 4.496731250001176, + 4.497331166996446, + 4.497964292000688, + 4.498591416995623, + 4.499253124995448, + 4.499897541994869, + 4.500542709000001, + 4.5011645420017885, + 4.501793541996449, + 4.502432041997963, + 4.503076959001191, + 4.503737125000043, + 4.5043367499965825, + 4.504967624998244, + 4.505710833997, + 4.506333958997857, + 4.50696291699569, + 4.507613666995894, + 4.508267708995845, + 4.509031083995069, + 4.50974420899729, + 4.510477333999006, + 4.511148917001265, + 4.5117526249960065, + 4.512390833995596, + 4.513052999995125, + 4.513762999995379, + 4.514436624995142, + 4.515065624997078, + 4.515707833998022, + 4.516425124995294, + 4.517053291994671, + 4.517706083999656, + 4.518359999994573, + 4.51901320899924, + 4.519650709000416, + 4.520284916994569, + 4.5209265839948785, + 4.521591749995423, + 4.522213958996872, + 4.522869874999742, + 4.523596708997502, + 4.52421966700058, + 4.524845916996128, + 4.525562208997144, + 4.526209291994746, + 4.526815541998076, + 4.527467749998323, + 4.5281139590006205, + 4.528922708996106, + 4.529612250000355, + 4.530347542000527, + 4.531010250000691, + 4.53161583399924, + 4.532287499998347, + 4.5329677920017275, + 4.5336489170003915, + 4.534306708999793, + 4.53492854200158, + 4.535543749996577, + 4.536200416994689, + 4.536830083998211, + 4.5375815840016, + 4.538213416999497, + 4.538859416999912, + 4.53945720900083, + 4.540074042000924, + 4.540718874995946, + 4.541369833998033, + 4.541999875000329, + 4.542660209001042, + 4.543304749997333, + 4.543958292000752, + 4.54459433399461, + 4.545253291995323, + 4.545872666996729, + 4.546477666997816, + 4.547099584000534, + 4.547872750001261, + 4.548585666998406, + 4.549292374998913, + 4.549931041998207, + 4.550584584001626, + 4.551232917001471, + 4.551884666994738, + 4.552489417001198, + 4.553127458995732, + 4.55381716699776, + 4.554497208999237, + 4.555122874997323, + 4.555754124994564, + 4.556381958995189, + 4.557047124995734, + 4.55769433399837, + 4.5583542919994215, + 4.558982834001654, + 4.559598084000754, + 4.560240792001423, + 4.560904209, + 4.561514834000263, + 4.562144999996235, + 4.562771833996521, + 4.563441541999055, + 4.5640454999957, + 4.564669999999751, + 4.565287291996356, + 4.565942708999501, + 4.5665953749994515, + 4.567416249999951, + 4.5680949589950615, + 4.568772667000303, + 4.569465125001443, + 4.570137916998647, + 4.5707925419992534, + 4.571430625001085, + 4.572033083997667, + 4.572621999999683, + 4.573267749998195, + 4.57391637499677, + 4.5746689590014284, + 4.575304250000045, + 4.575993209000444, + 4.57661558399559, + 4.577232124996954, + 4.5778650419961195, + 4.578481833996193, + 4.579111166996881, + 4.579718499997398, + 4.58040304199676, + 4.581039083997894, + 4.581659541996487, + 4.582294833999185, + 4.583023250001133, + 4.583657625000342, + 4.584502208999766, + 4.585121541997069, + 4.585911916998157, + 4.586543416997301, + 4.587151209001604, + 4.587764916999731, + 4.58837762499752, + 4.589045249995252, + 4.589760709000984, + 4.590437041995756, + 4.591151749998971, + 4.59181266700034, + 4.592481374995259, + 4.593117958997027, + 4.593777624999348, + 4.594444958995155, + 4.595078458994976, + 4.595709791996342, + 4.596325708997028, + 4.597025833994849, + 4.597652541997377, + 4.598284916995908, + 4.5989544589974685, + 4.599609666998731, + 4.600238041995908, + 4.600911333996919, + 4.601527874998283, + 4.602161958995566, + 4.602806999995664, + 4.603443084000901, + 4.604087333995267, + 4.604708458995447, + 4.605334333995415, + 4.605977708997671, + 4.6066262499953154, + 4.607247624997399, + 4.607849708998401, + 4.608462625001266, + 4.609125916998892, + 4.60974804199941, + 4.61043479199725, + 4.611101499998767, + 4.61174470900005, + 4.612367875000928, + 4.613121292000869, + 4.613826834000065, + 4.614487874998304, + 4.615127541997936, + 4.615782374996343, + 4.616415874996164, + 4.617043250000279, + 4.617688416998135, + 4.61832104199857, + 4.618941166998411, + 4.6195891669995035, + 4.620230499996978, + 4.620864459000586, + 4.621602792001795, + 4.622265708996565, + 4.622875791996194, + 4.623498749999271, + 4.624152249998588, + 4.624812249996467, + 4.6254670419948525, + 4.626104833994759, + 4.62671262499498, + 4.627274416998262, + 4.627960999998322, + 4.628620041999966, + 4.629343374996097, + 4.630039958996349, + 4.630689334000635, + 4.631313917001535, + 4.631946708999749, + 4.632582334001199, + 4.633211624997784, + 4.633861292000802, + 4.634466750001593, + 4.635118334001163, + 4.635708499998145, + 4.636367250001058, + 4.637003416995867, + 4.637607416996616, + 4.6382064999997965, + 4.638835583995387, + 4.6394590839991, + 4.640045084001031, + 4.640679124997405, + 4.64136408399645, + 4.642024458997184, + 4.642631874994549, + 4.643234791998111, + 4.643837249997887, + 4.644460750001599, + 4.64508020899666, + 4.645763666994753, + 4.646400666999398, + 4.64702108399797, + 4.647713209000358, + 4.64833579200058, + 4.649029583997617, + 4.649645042001794, + 4.650303875001555, + 4.650921874999767, + 4.651515874997131, + 4.652137624994793, + 4.652916084000026, + 4.65350179199595, + 4.654127249996236, + 4.654765458995826, + 4.655428708996624, + 4.656064624999999, + 4.656711083996925, + 4.657326249995094, + 4.657955666996713, + 4.658592250001675, + 4.6592151669974555, + 4.659846333997848, + 4.660517666998203, + 4.661129333995632, + 4.661778083995159, + 4.662391208999907, + 4.663027666996641, + 4.6637358340012725, + 4.664359583999612, + 4.665039209001407, + 4.665705416999117, + 4.666303666999738, + 4.667019542001071, + 4.6676702499971725, + 4.668357834001654, + 4.669042083995009, + 4.669755249997252, + 4.670382291995338, + 4.67102916699514, + 4.671679499995662, + 4.6723119169982965, + 4.672992874999181, + 4.673637166997651, + 4.674273249998805, + 4.674924999999348, + 4.675572959000419, + 4.676227208998171, + 4.676977541996166, + 4.677585583995096, + 4.6782344589955756, + 4.678838959000132, + 4.67943324999942, + 4.6800701249958365, + 4.680673874994682, + 4.681316458998481, + 4.681938166999316, + 4.6825607499995385, + 4.6832430840004236, + 4.684017250001489, + 4.68465595899761, + 4.685303541999019, + 4.685960458999034, + 4.686685542001214, + 4.687304499995662, + 4.688036958999874, + 4.688742958998773, + 4.689385416997538, + 4.6900312090001535, + 4.690677874998073, + 4.6913162089986145, + 4.691993458996876, + 4.692599499998323, + 4.6932081669947365, + 4.6938533339998685, + 4.6945249999989755, + 4.695196916996792, + 4.695819333996042, + 4.696462250001787, + 4.697112999994715, + 4.697804374998668, + 4.698487541994837, + 4.699101458994846, + 4.699768624996068, + 4.700443583999004, + 4.701059749997512, + 4.701723250000214, + 4.702392624996719, + 4.703069958995911, + 4.703674416996364, + 4.704311834000691, + 4.7049463340008515, + 4.705579041998135, + 4.7062324169964995, + 4.706903541999054, + 4.707558666996192, + 4.708302041995921, + 4.708964624995133, + 4.70960183400166, + 4.710310916998424, + 4.710958999996365, + 4.711624499999743, + 4.712261249995208, + 4.712916291995498, + 4.713606749995961, + 4.714242374997411, + 4.714883208995161, + 4.715515208998113, + 4.716191374995105, + 4.716855541999394, + 4.717507834000571, + 4.718168833998789, + 4.718777916998079, + 4.719422124995617, + 4.720042041997658, + 4.720660792001581, + 4.721414916995855, + 4.722039833999588, + 4.722682833998988, + 4.723301458994683, + 4.7239325839982484, + 4.724558541995066, + 4.7252518749955925, + 4.725926458995673, + 4.726612458995078, + 4.727307791996282, + 4.727999458998966, + 4.728627749995212, + 4.729275124998821, + 4.72990949999803, + 4.730546334001701, + 4.731298083999718, + 4.7319421249994775, + 4.732610209000995, + 4.733231792000879, + 4.733876291997149, + 4.734479958999145, + 4.735064542001055, + 4.735682166996412, + 4.73633316699852, + 4.7369665000005625, + 4.7376708750016405, + 4.738320749995182, + 4.738981791997503, + 4.739680583996233, + 4.740319416996499, + 4.740958416994545, + 4.741600749999634, + 4.742390374995011, + 4.743039834000228, + 4.743735666997964, + 4.74438158400153, + 4.7450339589995565, + 4.7456929170002695, + 4.746341416997893, + 4.7470643339984235, + 4.7477408749982715, + 4.748399708994839, + 4.7491095419973135, + 4.749749458998849, + 4.750382041995181, + 4.751037208996422, + 4.751670583995292, + 4.752321041996765, + 4.7529850419959985, + 4.7536066669999855, + 4.754218583999318, + 4.754881666995061, + 4.755479667001055, + 4.756136374999187, + 4.756754374997399, + 4.757351708998613, + 4.75799954199465, + 4.758699209000042, + 4.759360584001115, + 4.760006833996158, + 4.760610583995003, + 4.761231999997108, + 4.761825916997623, + 4.762429416994564, + 4.763059208999039, + 4.7637867500016, + 4.764436958997976, + 4.765142083997489, + 4.7658099999971455, + 4.766470709000714, + 4.767104958998971, + 4.767725459001667, + 4.768312916996365, + 4.768937417000416, + 4.769584666995797, + 4.770389166995301, + 4.771020791995397, + 4.771705708997615, + 4.772369166996214, + 4.773016874998575, + 4.773673458999838, + 4.774294458999066, + 4.774940625000454, + 4.775560709000274, + 4.776221499996609, + 4.776852083996346, + 4.777482958998007, + 4.778107375001127, + 4.778752166996128, + 4.779358667001361, + 4.779998999998497, + 4.780723208998097, + 4.7813603339964175, + 4.781988499998988, + 4.782629875000566, + 4.783255249996728, + 4.7842190000010305, + 4.784997999995539, + 4.785697416999028, + 4.786279291998653, + 4.786951417001546, + 4.787629749996995, + 4.7883124590007355, + 4.788928499998292, + 4.789549834000354, + 4.790185541998653, + 4.7907984999983455, + 4.791459791995294, + 4.792070208997757, + 4.792675500000769, + 4.793296249998093, + 4.793974708998576, + 4.794569124998816, + 4.7952272499969695, + 4.795882166996307, + 4.796522459000698, + 4.797151874998235, + 4.79775691699615, + 4.798455916999956, + 4.799140541996167, + 4.7997584999975516, + 4.800348541997664, + 4.800936833999003, + 4.801568833994679, + 4.802208749999409, + 4.802895333996275, + 4.803571791999275, + 4.804232791997492, + 4.805090499998187, + 4.805670333997114, + 4.806410416997096, + 4.807055833996856, + 4.807640624996566, + 4.808276916999603, + 4.8089349169968045, + 4.809541124996031, + 4.81014258399955, + 4.8107327920006355, + 4.811353583994787, + 4.811974374999409, + 4.812619333999464, + 4.813234624998586, + 4.8138532919983845, + 4.814514416997554, + 4.815172624999832, + 4.815809542000352, + 4.816451250000682, + 4.817082749999827, + 4.817672749995836, + 4.818290541996248, + 4.818913333998353, + 4.819566499994835, + 4.820163666998269, + 4.820807874995808, + 4.821453333999671, + 4.822051916999044, + 4.822846208997362, + 4.823545166997064, + 4.8242717499961145, + 4.824876041995594, + 4.825559166994935, + 4.826245333999395, + 4.826879916996404, + 4.827534541997011, + 4.828146542000468, + 4.82875358399906, + 4.829460000000836, + 4.830099624996365, + 4.830748416999995, + 4.831393499996921, + 4.832042834001186, + 4.832676083999104, + 4.833305959000427, + 4.833975041998201, + 4.834648374999233, + 4.835262749998947, + 4.835888583998894, + 4.836495833995286, + 4.837122708995594, + 4.83776133399806, + 4.8384219169965945, + 4.839024791996053, + 4.839676958996279, + 4.840307792001113, + 4.840966458999901, + 4.841587041999446, + 4.84236987499753, + 4.843135874994914, + 4.843857499996375, + 4.844488709000871, + 4.845095042001049, + 4.845760999996855, + 4.846376916997542, + 4.847003292001318, + 4.847638958999596, + 4.848288834000414, + 4.848949458995776, + 4.849578624998685, + 4.850212459001341, + 4.850812249998853, + 4.851431499999308, + 4.852082291996339, + 4.85271987500164, + 4.853351208999811, + 4.854001667001285, + 4.854660334000073, + 4.8552990419993876, + 4.85589629199967, + 4.8565200839948375, + 4.8571076250009355, + 4.857713208999485, + 4.8583591249989695, + 4.859001583994541, + 4.859623042000749, + 4.860232958999404, + 4.860850459001085, + 4.861492666997947, + 4.862201874995662, + 4.862800750001043, + 4.863606541999616, + 4.86428045899811, + 4.864955833996646, + 4.8656341249952675, + 4.866273667001224, + 4.8669480419994215, + 4.86761541699525, + 4.868274000000383, + 4.868896374995529, + 4.869561791994784, + 4.8702002499994705, + 4.870836166999652, + 4.871494958999392, + 4.8721215420009685, + 4.87275262500043, + 4.873367708998558, + 4.87397495899495, + 4.874624708994816, + 4.875261249995674, + 4.875886000001628, + 4.876534625000204, + 4.877180374998716, + 4.877814416999172, + 4.878559291995771, + 4.879199709001114, + 4.879860708999331, + 4.880495999997947, + 4.881218834001629, + 4.881884041999001, + 4.882567791995825, + 4.88321987499512, + 4.883838791996823, + 4.884468124997511, + 4.885150666996196, + 4.885782334000396, + 4.88641179199476, + 4.887031792000926, + 4.887658874999033, + 4.888333750001038, + 4.888966334001452, + 4.889601292001316, + 4.890214499995636, + 4.890830874996027, + 4.89145204200031, + 4.892079624994949, + 4.8927268749976065, + 4.89332704199478, + 4.893948375000036, + 4.89456537499791, + 4.895207166999171, + 4.895873541994661, + 4.89651241699903, + 4.897126958996523, + 4.897772666998208, + 4.898421583995514, + 4.899076041998342, + 4.899733166996157, + 4.900535000000673, + 4.901235541998176, + 4.90201079200051, + 4.902690167000401, + 4.903363459001412, + 4.904030749996309, + 4.90466795899556, + 4.9052922499977285, + 4.905959833995439, + 4.906584666998242, + 4.907237833998806, + 4.9080031249977765, + 4.908622374998231, + 4.909295083998586, + 4.909956709001563, + 4.910582208998676, + 4.911208291996445, + 4.911807584001508, + 4.912430500000482, + 4.913046083995141, + 4.913657541997964, + 4.914307084000029, + 4.914953999999852, + 4.915595916994789, + 4.916211333998945, + 4.916837584001769, + 4.917504999997618, + 4.918103833995701, + 4.918716708998545, + 4.919316416999209, + 4.919978583995544, + 4.920671416999539, + 4.921343666996108, + 4.922014333998959, + 4.922676333997515, + 4.923351541998272, + 4.924029666995921, + 4.924694791996444, + 4.925351833997411, + 4.926004208995437, + 4.9266565419966355, + 4.927315333996376, + 4.9279761249999865, + 4.92859533400042, + 4.929227125001489, + 4.929874834000657, + 4.9305302089996985, + 4.931143083995266, + 4.931798792000336, + 4.932444917001703, + 4.933072959000128, + 4.9337281249972875, + 4.934401458995126, + 4.935020999997505, + 4.935651624997263, + 4.936317125000642, + 4.9369757089953055, + 4.93761066699517, + 4.938209125000867, + 4.938880875000905, + 4.939619333999872, + 4.940288708996377, + 4.940964083994913, + 4.9415887919967645, + 4.942277166999702, + 4.942931041994598, + 4.943614958996477, + 4.944350334000774, + 4.945017792000726, + 4.945657208998455, + 4.946327334000671, + 4.94699454199872, + 4.947607417001564, + 4.9482380420013214, + 4.948914583997976, + 4.949562333997164, + 4.950189541996224, + 4.950816584001586, + 4.9514847499958705, + 4.952235291995748, + 4.952922416996444, + 4.95361704199604, + 4.9542427499982296, + 4.954926749996957, + 4.955560916998365, + 4.956178291999095, + 4.9568456249980954, + 4.957519791998493, + 4.95815975000005, + 4.958808208997652, + 4.9594630419960595, + 4.960057042000699, + 4.960687749997305, + 4.961347917000239, + 4.96205637499952, + 4.962779417001002, + 4.963487624998379, + 4.96416745899478, + 4.964800749999995, + 4.965472874995612, + 4.966101375001017, + 4.966715124995972, + 4.967405541996413, + 4.96809362500062, + 4.968746792001184, + 4.969411999998556, + 4.970068124996033, + 4.970706458996574, + 4.971342708995508, + 4.971979374997318, + 4.972575250001682, + 4.97324520899565, + 4.973883916994964, + 4.974543749995064, + 4.975148041994544, + 4.97579041699646, + 4.976447208995523, + 4.977200499997707, + 4.977822291999473, + 4.978469541994855, + 4.979135000001406, + 4.979841416999989, + 4.980504624996684, + 4.981143541997881, + 4.981795333995251, + 4.9825011669963715, + 4.983134624999366, + 4.983754291999503, + 4.984402208996471, + 4.985050958995998, + 4.985720124997897, + 4.986394624997047, + 4.987048874994798, + 4.987711666995892, + 4.988371084000391, + 4.98901987499994, + 4.989701916994818, + 4.990340500000457, + 4.991071416996419, + 4.991678041995328, + 4.992406334000407, + 4.9930990419961745, + 4.9937838339974405, + 4.9945313339994755, + 4.995196791998751, + 4.995890874997713, + 4.996575833996758, + 4.99724766700092, + 4.997917708999012, + 4.998646624997491, + 4.9997589170016, + 5.00054541699501, + 5.001234999996086, + 5.002005666996411, + 5.002753583998128, + 5.00341616699734, + 5.004545458999928, + 5.005258208999294, + 5.006082667001465, + 5.007007499996689, + 5.00767966699641, + 5.008330083997862, + 5.008952291995229, + 5.009657416994742, + 5.010393208998721, + 5.011480583998491, + 5.012551624997286, + 5.013234583995654, + 5.013975624999148, + 5.014606625001761, + 5.015184124997177, + 5.015760458998557, + 5.016331541999534, + 5.0169799590003095, + 5.017505042000266, + 5.018059374997392, + 5.018552083995019, + 5.019080334001046, + 5.019870208998327, + 5.023319250001805, + 5.023944916996697, + 5.024686500000826, + 5.025402374994883, + 5.02603866699792, + 5.0265863749955315, + 5.027174167000339, + 5.0277263749958365, + 5.028289834001043, + 5.028825583998696, + 5.029369833995588, + 5.030127291996905, + 5.030742791997909, + 5.031504541999311, + 5.032155875000171, + 5.032802124995214, + 5.035026375000598, + 5.035886124998797, + 5.036503541996353, + 5.037145124995732, + 5.037741333995655, + 5.038370875001419, + 5.039005124999676, + 5.039750249998178, + 5.040424083999824, + 5.041114667001239, + 5.041888583997206, + 5.042599041997164, + 5.043205083995417, + 5.043963833995804, + 5.044586541996978, + 5.045345999998972, + 5.04605783399893, + 5.046694625001692, + 5.0473515420017065, + 5.047905667001032, + 5.048501999997825, + 5.049089749998529, + 5.049668333995214, + 5.050240833996213, + 5.050795333998394, + 5.051339083998755, + 5.05189441699622, + 5.0524343340002815, + 5.053004666995548, + 5.053548958996544, + 5.05409787499957, + 5.054669083998306, + 5.05522991700127, + 5.055838166998001, + 5.0563959589999286, + 5.056946749995404, + 5.0575206669964246, + 5.058065583994903, + 5.058605458994862, + 5.059229291997326, + 5.059852166996279, + 5.060573958995519, + 5.0612550000005285, + 5.061972625000635, + 5.062634249996336, + 5.06327387499914, + 5.063922666995495, + 5.06455529199593, + 5.065198500000406, + 5.0658301250005024, + 5.066488124997704, + 5.067164333995606, + 5.067828791994543, + 5.068489708995912, + 5.069180749997031, + 5.069814124995901, + 5.070487958997546, + 5.071149874995172, + 5.071925708994968, + 5.072581666994665, + 5.073257042000478, + 5.073933583997132, + 5.07453383399843, + 5.075144333997741, + 5.0757993340012035, + 5.076523416995769, + 5.077237666999281, + 5.077892749999592, + 5.078536583998357, + 5.079190291995474, + 5.079878584001563, + 5.080590874997142, + 5.081265542001347, + 5.081871709000552, + 5.08251216699864, + 5.08313087499846, + 5.083794917001796, + 5.084546917001717, + 5.0852278339953045, + 5.085909624998749, + 5.0866287919998285, + 5.087302084000839, + 5.087968833999184, + 5.088600999995833, + 5.089233166996564, + 5.089885000001232, + 5.090496999997413, + 5.091139167001529, + 5.091806917000213, + 5.092489666996698, + 5.093138042000646, + 5.093802625000535, + 5.094424333998177, + 5.095094541997241, + 5.095737874995393, + 5.096422374997928, + 5.097141499994905, + 5.097871874997509, + 5.0985434589965735, + 5.099205958998937, + 5.099920499997097, + 5.10056766699563, + 5.101276499997766, + 5.102021916995, + 5.102639749995433, + 5.103300999995554, + 5.1039591250009835, + 5.104617042001337, + 5.1052906670011, + 5.105966458999319, + 5.10662679199595, + 5.107270749998861, + 5.1079346670012455, + 5.108566083996266, + 5.109228666995477, + 5.1098334999987856, + 5.110461416996259, + 5.111114499995892, + 5.111749874995439, + 5.11244091700064, + 5.113096708999365, + 5.1137430839953595, + 5.114368709000701, + 5.115063249999366, + 5.115713833998598, + 5.11631808400125, + 5.117020459001651, + 5.1176415000009, + 5.118343541995273, + 5.119002999999793, + 5.119671417000063, + 5.1203010419994825, + 5.120923499998753, + 5.121567333997518, + 5.12219691700011, + 5.12283749999915, + 5.123437333997572, + 5.124103292000655, + 5.124761958999443, + 5.125457458998426, + 5.126118959000451, + 5.126789624999219, + 5.127397042000666, + 5.12801795899577, + 5.12864350000018, + 5.12930575000064, + 5.130074249995232, + 5.13067074999708, + 5.1313599169952795, + 5.132091458996001, + 5.13276658399991, + 5.133341374996235, + 5.133975917000498, + 5.134593541995855, + 5.135234083994874, + 5.1358321250008885, + 5.13649599999917, + 5.137169208996056, + 5.137902541995572, + 5.138586916997156, + 5.139222500001779, + 5.139875916996971, + 5.140480624999327, + 5.141048042001785, + 5.1416627500002505, + 5.142376333998982, + 5.142985749997024, + 5.143539124997915, + 5.1440880419977475, + 5.144616083998699, + 5.145206959001371, + 5.145727958995849, + 5.1462449169994215, + 5.148241833994689, + 5.149255500000436, + 5.149849417000951, + 5.150470000000496, + 5.15105354199477, + 5.151713499995822, + 5.152370042000257, + 5.153083999997762, + 5.1537233339986415, + 5.154354792000959, + 5.15530966699589, + 5.156100416999834, + 5.156995541998185, + 5.1577779590006685, + 5.158518958996865, + 5.159215291998407, + 5.159879999999248, + 5.160532374997274, + 5.1612178340001265, + 5.161899041995639, + 5.162501541999518, + 5.163111624999146, + 5.163768792001065, + 5.164421374996891, + 5.165119583994965, + 5.165750749998551, + 5.166375791995961, + 5.1670010419984465, + 5.167610249998688, + 5.168192833996727, + 5.168861749996722, + 5.169538083995576, + 5.1702101249975385, + 5.170830750001187, + 5.171480166995025, + 5.172122208998189, + 5.172733333994984, + 5.173348749995057, + 5.174023041996406, + 5.174668041996483, + 5.175431124996976, + 5.176224916998763, + 5.176957541996671, + 5.177610458995332, + 5.17824483399454, + 5.178886541994871, + 5.179490583999723, + 5.180138666997664, + 5.180757999994967, + 5.181384083996818, + 5.182025624999369, + 5.1826324590001605, + 5.183271958994737, + 5.183908458995575, + 5.184541999995417, + 5.185299958997348, + 5.185971749997407, + 5.186585458999616, + 5.187212333999923, + 5.1878881250013364, + 5.188510416999634, + 5.189144249998208, + 5.189813500001037, + 5.190483499995025, + 5.191088958999899, + 5.191694124994683, + 5.192468374996679, + 5.1930561249973834, + 5.193676416995004, + 5.194324791998952, + 5.195008666996728, + 5.195639083998685, + 5.196334959000524, + 5.197044791995722, + 5.197720333999314, + 5.198362416995224, + 5.198994624995976, + 5.1996307500012335, + 5.200240209000185, + 5.200913666994893, + 5.201518083995325, + 5.20214529200166, + 5.20275699999911, + 5.203390958995442, + 5.204030959001102, + 5.204699041998538, + 5.20531724999455, + 5.20593462499528, + 5.206564125001023, + 5.207191875000717, + 5.207868334000523, + 5.208666499995161, + 5.209359417000087, + 5.21001770899602, + 5.210565541994583, + 5.211134874996787, + 5.2116787499981, + 5.212254708996625, + 5.212844749999931, + 5.213403124995239, + 5.213984000001801, + 5.214586083995528, + 5.2152003750015865, + 5.2158671249999315, + 5.216427708997799, + 5.217023083998356, + 5.217581166994933, + 5.2181244589955895, + 5.21863754199876, + 5.219167124996602, + 5.219653624997591, + 5.220226749996073, + 5.220717917000002, + 5.221265583997592, + 5.221804875000089, + 5.222331874996598, + 5.222893624995777, + 5.223475041995698, + 5.224012624996249, + 5.224519625000539, + 5.225043291997281, + 5.2256009170014295, + 5.226171541995427, + 5.22668962500029, + 5.22721054199792, + 5.227717000001576, + 5.228286917001242, + 5.228858541995578, + 5.229393124995113, + 5.229967874998692, + 5.230508125001506, + 5.231059459001699, + 5.231647624998004, + 5.232191833994875, + 5.232697958999779, + 5.233242292000796, + 5.233840499997314, + 5.234428541996749, + 5.235025333997328, + 5.235613833996467, + 5.236187333997805, + 5.236705916999199, + 5.237258708999434, + 5.2378161669985275, + 5.238323459001549, + 5.238877791998675, + 5.239471959001094, + 5.240005499996187, + 5.240559499994561, + 5.24110274999839, + 5.241659708997759, + 5.242223499997635, + 5.242821041996649, + 5.243381125001179, + 5.243937749997713, + 5.244497209001565, + 5.245051499994588, + 5.2456227090006, + 5.246199542001705, + 5.246818958999938, + 5.247474249998049, + 5.248035749995324, + 5.24858620899613, + 5.249177874997258, + 5.249720291998528, + 5.250265499998932, + 5.250827374999062, + 5.251384874994983, + 5.2519239589964855, + 5.252434624999296, + 5.253076208995481, + 5.253673749997688, + 5.254433083995536, + 5.25505775000056, + 5.255594791997282, + 5.256180625001434, + 5.256693499999528, + 5.257261792001373, + 5.257825666994904, + 5.25837304200104, + 5.258970041999419, + 5.259524041997793, + 5.260045791997982, + 5.260592416998406, + 5.26112958399608, + 5.2617019999961485, + 5.262337125001068, + 5.262884416995803, + 5.263433208994684, + 5.264035833999515, + 5.264637291998952, + 5.265182541996182, + 5.2657803339971, + 5.266323042000295, + 5.266864208999323, + 5.267428958999517, + 5.267962874997465, + 5.268516291995184, + 5.269047124995268, + 5.2695807089985465, + 5.27011020899954, + 5.270682458998635, + 5.271229749996564, + 5.271769499995571, + 5.272349749997375, + 5.272974209001404, + 5.273550166995847, + 5.274154041995644, + 5.274732166995818, + 5.275323709000077, + 5.275899833999574, + 5.276461333996849, + 5.277061834000051, + 5.277588708995609, + 5.278156959000626, + 5.278715666994685, + 5.279378374994849, + 5.279957958999148, + 5.28053920900129, + 5.281081417000678, + 5.281642374997318, + 5.282218125001236, + 5.282756417000201, + 5.283303167001577, + 5.283827291998023, + 5.284360208999715, + 5.284948959000758, + 5.285496749995218, + 5.286049333997653, + 5.286601749998226, + 5.287184333996265, + 5.287735083998996, + 5.2882714590014075, + 5.288810958998511, + 5.289350125000055, + 5.28990899999917, + 5.290457458999299, + 5.290992999995069, + 5.291575999995985, + 5.292308374999266, + 5.2930397919990355, + 5.293832208997628, + 5.294437042000936, + 5.294995167001616, + 5.295560166996438, + 5.296115958997689, + 5.29666599999473, + 5.297197749998304, + 5.29775195899856, + 5.298312458995497, + 5.298910583995166, + 5.299442709001596, + 5.299979916999291, + 5.300461749997339, + 5.301005333996727, + 5.301563041997724, + 5.302104999995208, + 5.302684166999825, + 5.3032385839978815, + 5.303779791996931, + 5.3043370000013965, + 5.304877916998521, + 5.305450041996664, + 5.305998833995545, + 5.306579333999252, + 5.307101958998828, + 5.307636416997411, + 5.308174459001748, + 5.3087259589956375, + 5.309246999997413, + 5.309892459001276, + 5.3104291669951635, + 5.31099712500145, + 5.311608958996658, + 5.312168999997084, + 5.312926583996159, + 5.313580834001186, + 5.314298208999389, + 5.314941459000693, + 5.315582208997512, + 5.316253249999136, + 5.3168688750010915, + 5.3175001249983325, + 5.31815391699638, + 5.31877858399821, + 5.319405541995366, + 5.320023749998654, + 5.320654416995239, + 5.321307041995169, + 5.321952916994633, + 5.32259183399583, + 5.323224791995017, + 5.323833416994603, + 5.324479874994722, + 5.325107124997885, + 5.325738833998912, + 5.326426874999015, + 5.327041500000632, + 5.327669291997154, + 5.328320916996745, + 5.329013458998816, + 5.32961449999857, + 5.330300791996706, + 5.331016833995818, + 5.331711041995732, + 5.332747874999768, + 5.33352054200077, + 5.3341744169956655, + 5.334788667001703, + 5.335459499998251, + 5.336118125000212, + 5.336761209000542, + 5.337396750001062, + 5.338007499995001, + 5.33863541699975, + 5.339212833998317, + 5.339859374995285, + 5.340508249995764, + 5.341161459000432, + 5.341816959000425, + 5.3425686249975115, + 5.343205208999279, + 5.343846416995802, + 5.3444775419993675, + 5.345086166998954, + 5.345746833998419, + 5.346323249999841, + 5.347014999999374, + 5.347701250000682, + 5.34842158399988, + 5.349088958995708, + 5.3497474169998895, + 5.350358374998905, + 5.350990250000905, + 5.3516359999994165, + 5.352217374995234, + 5.352808999996341, + 5.353382374996727, + 5.353948500000115, + 5.354458041998441, + 5.355002374999458, + 5.355571874999441, + 5.356099291995633, + 5.356601791994763, + 5.357166999994661, + 5.357714917001431, + 5.358288666997396, + 5.358808500001032, + 5.3593394169947715, + 5.359863749996293, + 5.360446291997505, + 5.360977584001375, + 5.36150666699541, + 5.362037833998329, + 5.3626157089966, + 5.363103042000148, + 5.363627958999132, + 5.364151208996191, + 5.364789250001195, + 5.365388749996782, + 5.365955417000805, + 5.366553250001743, + 5.367102833995887, + 5.367632041998149, + 5.3681677089989535, + 5.368703416999779, + 5.369238708997727, + 5.369894999996177, + 5.370542791999469, + 5.371179666995886, + 5.371777333995851, + 5.37247433399898, + 5.373037749996001, + 5.37358245899668, + 5.374180334001721, + 5.374702166998759, + 5.375292459000775, + 5.375874624995049, + 5.376418041996658, + 5.3769154170004185, + 5.3774792089971015, + 5.378001583994774, + 5.3785909169964725, + 5.3791377499946975, + 5.3797247920010705, + 5.3802722499967786, + 5.380965791999188, + 5.381528041994898, + 5.382069583996781, + 5.382619459000125, + 5.38318816699757, + 5.383746749997954, + 5.384316124996985, + 5.384888208995108, + 5.3854377919997205, + 5.385973958997056, + 5.3865384589953464, + 5.3871171249993495, + 5.387699874998361, + 5.388239874999272, + 5.388791624995065, + 5.389476791999186, + 5.390087583997229, + 5.390670583998144, + 5.39126079199923, + 5.3918179999964195, + 5.392364209001244, + 5.392943166996702, + 5.39348433399573, + 5.394012917000509, + 5.39454833399941, + 5.39508499999647, + 5.395630209000956, + 5.396205833996646, + 5.396768124999653, + 5.397336333997373, + 5.397900249998202, + 5.398406749998685, + 5.398924417000671, + 5.399481458996888, + 5.400041000000783, + 5.4005898339964915, + 5.401090708997799, + 5.401643999997759, + 5.402157999997144, + 5.402711458998965, + 5.403248916998564, + 5.403871583999717, + 5.404451041998982, + 5.405030541995075, + 5.405580999999074, + 5.40614362499764, + 5.4067129169998225, + 5.4072620419974555, + 5.407778333996248, + 5.408307291996607, + 5.408874000000651, + 5.409522499998275, + 5.41010812499735, + 5.4107422919987584, + 5.411302458996943, + 5.41186474999995, + 5.4123630419999245, + 5.412919499998679, + 5.413453458997537, + 5.414028209001117, + 5.414560958997754, + 5.415126416999556, + 5.415632042000652, + 5.416196375001164, + 5.416762041997572, + 5.41730424999696, + 5.41784312499658, + 5.4184150000000955, + 5.418972416999168, + 5.419540709001012, + 5.420122124996851, + 5.420693708998442, + 5.421235166999395, + 5.421748749999097, + 5.42234974999883, + 5.42292629199801, + 5.423485250001249, + 5.424036584001442, + 5.42464291700162, + 5.425203792001412, + 5.425796999996237, + 5.426354666997213, + 5.426932166999904, + 5.427602124997065, + 5.42812733399478, + 5.428732249994937, + 5.429302833996189, + 5.429851875000168, + 5.430440749994887, + 5.431020167001407, + 5.431593083994812, + 5.432127749998472, + 5.4326632090014755, + 5.43317720900086, + 5.433722499998112, + 5.434284541996021, + 5.434787375001179, + 5.435343917000864, + 5.435897416995431, + 5.43642225000076, + 5.436924208996061, + 5.4374370000005, + 5.437942374999693, + 5.4384641669967095, + 5.438991208997322, + 5.439527875001659, + 5.440098166996904, + 5.440635416998703, + 5.441151416998764, + 5.441678874994977, + 5.44223479199718, + 5.442768291999528, + 5.443312874995172, + 5.44383329199627, + 5.444341374997748, + 5.444899666996207, + 5.445439709001221, + 5.445986541999446, + 5.446549916996446, + 5.447024374996545, + 5.44757474999642, + 5.4483073340015835, + 5.448977959000331, + 5.449557041996741, + 5.450143624999328, + 5.4507197919956525, + 5.451276542000414, + 5.4518108339980245, + 5.452338584000245, + 5.453032416997303, + 5.453619833999255, + 5.454182333996869, + 5.454758874999243, + 5.455302583999583, + 5.455877208994934, + 5.456434499996249, + 5.456995249995089, + 5.457521666998218, + 5.458063833997585, + 5.45864570899721, + 5.459214750000683, + 5.45982974999788, + 5.460356083996885, + 5.46091216700006, + 5.461436917001265, + 5.461983959001373, + 5.462540333996003, + 5.463044124997396, + 5.463612833998923, + 5.464163083997846, + 5.464706583996303, + 5.465270249995228, + 5.465793874995143, + 5.466342209001596, + 5.466914999997243, + 5.467548041997361, + 5.468117042000813, + 5.468685084000754, + 5.469254584000737, + 5.46980520899524, + 5.47042112499912, + 5.47094924999692, + 5.471500833999016, + 5.472046292001323, + 5.472548291996645, + 5.473111667000921, + 5.473692958999891, + 5.474221874996147, + 5.4747836669994285, + 5.475343541998882, + 5.475906458996178, + 5.476422374995309, + 5.476945999995223, + 5.477560583996819, + 5.478288583995891, + 5.478966041999229, + 5.479597500001546, + 5.480212750000646, + 5.480854208995879, + 5.481520291999914, + 5.482205249994877, + 5.4828225419987575, + 5.483410499997262, + 5.4840463750006165, + 5.4846785420013475, + 5.485307541996008, + 5.4858937919998425, + 5.48659087499982, + 5.487196875001246, + 5.4879102499980945, + 5.488560833997326, + 5.48923233399546, + 5.489870708996023, + 5.490515459001472, + 5.491143333994842, + 5.491805500001647, + 5.492544834, + 5.493212666995532, + 5.493867083998339, + 5.494559667000431, + 5.495172374998219, + 5.4957914170008735, + 5.49648295899533, + 5.497134708995873, + 5.497760958998697, + 5.498394374997588, + 5.499031166997156, + 5.499657000000298, + 5.50024741699599, + 5.500883166998392, + 5.501542792000691, + 5.502215417000116, + 5.502852874997188, + 5.503466374997515, + 5.504078749996552, + 5.504681166996306, + 5.505307958999765, + 5.505974125000648, + 5.50661024999863, + 5.507258624995302, + 5.507875791998231, + 5.508568749995902, + 5.509270374997868, + 5.510062541994557, + 5.510785667000164, + 5.5113812089985, + 5.5120421669998905, + 5.512684208995779, + 5.513374458998442, + 5.514016666995303, + 5.514622834001784, + 5.515239833999658, + 5.515849208997679, + 5.516440708997834, + 5.5170815419987775, + 5.517726999998558, + 5.518377458996838, + 5.5190219590003835, + 5.519690666995302, + 5.52034054199612, + 5.521001542001613, + 5.5216217919951305, + 5.522217334000743, + 5.522819249999884, + 5.523432292000507, + 5.52403124999546, + 5.524654458997247, + 5.525336708997202, + 5.525971916998969, + 5.526566458996967, + 5.527201833996514, + 5.527998334000586, + 5.528734542000166, + 5.529425458997139, + 5.530073709000135, + 5.530729499994777, + 5.531380374995933, + 5.532040416997916, + 5.532661666999047, + 5.53331079200143, + 5.5339505419979105, + 5.534558916995593, + 5.535170666997146, + 5.535761041996011, + 5.5363652919986635, + 5.537022124997748, + 5.537666708994948, + 5.538301916996716, + 5.538938166995649, + 5.539585708997038, + 5.54020070900151, + 5.540875375001633, + 5.54151075000118, + 5.542149791996053, + 5.542770041996846, + 5.543506999994861, + 5.544143916995381, + 5.544765291997464, + 5.545386749996396, + 5.546017041997402, + 5.546641166998597, + 5.5472850000005565, + 5.548089333999087, + 5.548778374999529, + 5.549475125000754, + 5.550136124998971, + 5.550737375000608, + 5.551372292000451, + 5.552002124997671, + 5.55260529199586, + 5.553217666994897, + 5.553875999998127, + 5.554521541998838, + 5.555144666999695, + 5.555805291995057, + 5.55643124999915, + 5.5570737089947215, + 5.5576991669950075, + 5.55832883399853, + 5.559031500000856, + 5.559679124999093, + 5.56032525000046, + 5.560985416996118, + 5.561774292000337, + 5.562395624998317, + 5.563028083997779, + 5.5636567499968805, + 5.564307666994864, + 5.564939374999085, + 5.565600624999206, + 5.566219374995853, + 5.566899375000503, + 5.567575583998405, + 5.5682604589965194, + 5.568949166998209, + 5.569615583997802, + 5.570242791996861, + 5.570934874995146, + 5.571573499997612, + 5.572146583996073, + 5.57280804200127, + 5.573451374999422, + 5.57408349999605, + 5.574718625000969, + 5.575389249999716, + 5.576020791995688, + 5.576654625001538, + 5.57727916699514, + 5.577889333995699, + 5.578555208994658, + 5.579272541996033, + 5.5799352920003, + 5.580604874994606, + 5.581209874995693, + 5.581841166997037, + 5.582476249997853, + 5.583133458996599, + 5.5838112919955165, + 5.5844794169970555, + 5.585241959000996, + 5.585892416995193, + 5.5865683750016615, + 5.587254958998528, + 5.587955374998273, + 5.588621416995011, + 5.58926524999697, + 5.589899916994909, + 5.590507916997012, + 5.591199916998448, + 5.5919052499957616, + 5.592624459000945, + 5.593267917000048, + 5.593933416996151, + 5.594609874999151, + 5.595258374996774, + 5.595882875000825, + 5.596509916998912, + 5.597148458997253, + 5.59781291699619, + 5.598460666995379, + 5.599093917000573, + 5.599734958996123, + 5.6003601670017815, + 5.600956292000774, + 5.601596458996937, + 5.602213041995128, + 5.602882374994806, + 5.603546416998142, + 5.604150792001747, + 5.60487433399976, + 5.605473249997885, + 5.606129667001369, + 5.6068131669962895, + 5.607478624995565, + 5.608230249999906, + 5.608911416995397, + 5.60956074999558, + 5.610194333996333, + 5.610877458995674, + 5.611517042001651, + 5.612153292000585, + 5.612810749997152, + 5.6135102920015925, + 5.614123708997795, + 5.6147648749974906, + 5.6154103340013535, + 5.616016708998359, + 5.616632999997819, + 5.617233166994993, + 5.617916083996533, + 5.618601791997207, + 5.619253374999971, + 5.619907749998674, + 5.620563291995495, + 5.621219499997096, + 5.62184508399514, + 5.622484333995089, + 5.6231578340011765, + 5.623789917000977, + 5.6244108749961015, + 5.625085583997134, + 5.6258670419992995, + 5.626545833998534, + 5.627259499997308, + 5.627845458999218, + 5.628434792000917, + 5.629017624996777, + 5.62959045900061, + 5.6301526249953895, + 5.63078216699796, + 5.631319333995634, + 5.631881333996716, + 5.632595541996125, + 5.633143084000039, + 5.633705333995749, + 5.63427312499698, + 5.634815459001402, + 5.635335667000618, + 5.635849166996195, + 5.636392166998121, + 5.6369422919960925, + 5.637501917000918, + 5.638043499995547, + 5.638589374997537, + 5.639146083995001, + 5.639677667000797, + 5.6402351669967175, + 5.640788584001712, + 5.64131287499913, + 5.641822500001581, + 5.64238695899985, + 5.642923499995959, + 5.643470208997314, + 5.644048249996558, + 5.644632208997791, + 5.645254625000234, + 5.64581770899531, + 5.6464214169973275, + 5.646964291998302, + 5.647532791997946, + 5.648057083999447, + 5.648592624995217, + 5.649147124997398, + 5.649681625000085, + 5.650220874995284, + 5.650767708997591, + 5.651329583997722, + 5.651859208999667, + 5.652442291997431, + 5.652958541999396, + 5.653505124995718, + 5.654059624997899, + 5.654649416996108, + 5.65528424999502, + 5.655945958998927, + 5.656600834001438, + 5.657221124994976, + 5.6579495839978335, + 5.658584291995794, + 5.659227833995828, + 5.659871749994636, + 5.6605179170001065, + 5.661189166996337, + 5.661820124994847, + 5.66242791699915, + 5.663062542000262, + 5.663699416996678, + 5.664400166999258, + 5.665070292001474, + 5.66589445900172, + 5.666545084000973, + 5.667190667001705, + 5.667846208998526, + 5.668446249997942, + 5.669078041995817, + 5.669733874994563, + 5.670390958999633, + 5.67100595899683, + 5.671605333998741, + 5.672226666996721, + 5.672865249995084, + 5.673478958997293, + 5.6740992499981076, + 5.674725416996807, + 5.675379542000883, + 5.6760369170006015, + 5.676815041995724, + 5.677413749996049, + 5.678024208995339, + 5.678711666994786, + 5.679367999997339, + 5.679975999999442, + 5.681135209000786, + 5.68199787499907, + 5.682667083994602, + 5.68343145900144, + 5.68408449999697, + 5.684704084000259, + 5.685376959001587, + 5.686047916999087, + 5.686680041995714, + 5.687349374995392, + 5.688012667000294, + 5.688712124996528, + 5.6893162919950555, + 5.689949499996146, + 5.690587708995736, + 5.691232124998351, + 5.691879833997518, + 5.692511166998884, + 5.693148209000356, + 5.6937707499964745, + 5.694421542000782, + 5.695064749997982, + 5.695710542000597, + 5.696317834001093, + 5.6969345420002355, + 5.697589499999594, + 5.69826858399756, + 5.698985958995763, + 5.699623874999816, + 5.700358249996498, + 5.700969917001203, + 5.701590874996327, + 5.702229624999745, + 5.702836042000854, + 5.703502833996026, + 5.704210749994672, + 5.704927541999496, + 5.705567334000079, + 5.706194083999435, + 5.706807750000735, + 5.707445041996834, + 5.708135834000132, + 5.708773708996887, + 5.709540916999686, + 5.710260291998566, + 5.710932041998603, + 5.711553333996562, + 5.712227374999202, + 5.712879458995303, + 5.713502334001532, + 5.714126624996425, + 5.714777249995677, + 5.715387291995285, + 5.715998542000307, + 5.71659345900116, + 5.717220916994847, + 5.717857916999492, + 5.718515542001114, + 5.719165834001615, + 5.719824125000741, + 5.72048562499549, + 5.721140916997683, + 5.721768416995474, + 5.722449959001096, + 5.723129833997518, + 5.72379333400022, + 5.724459375000151, + 5.72513666699524, + 5.725798624996969, + 5.726457917000516, + 5.727085749997059, + 5.727685459001805, + 5.72829708399513, + 5.728945666996879, + 5.72958262499742, + 5.730187417000707, + 5.730821583994839, + 5.7314692919972, + 5.732081958994968, + 5.732677667001553, + 5.733282708999468, + 5.733919667000009, + 5.734525041996676, + 5.735111249996407, + 5.735751791995426, + 5.736398666995228, + 5.737018959000125, + 5.737671916998806, + 5.738282708996849, + 5.73891929200181, + 5.739553874998819, + 5.740354249996017, + 5.741034624996246, + 5.741675958997803, + 5.742361833996256, + 5.743075958998816, + 5.743775833994732, + 5.744453166997118, + 5.7451297090010485, + 5.745759958997951, + 5.74651866700151, + 5.747228000000177, + 5.747889708996809, + 5.748520458997518, + 5.749161125000683, + 5.749802166996233, + 5.750450166997325, + 5.751055458997143, + 5.751661166999838, + 5.752264999995532, + 5.75288449999789, + 5.753477792000922, + 5.754084000000148, + 5.754745166996145, + 5.755528208996111, + 5.756199249997735, + 5.756810667000536, + 5.757437041997036, + 5.758042875000683, + 5.758703166997293, + 5.759369958999741, + 5.760017291999247, + 5.760602791997371, + 5.761271167000814, + 5.761909791996004, + 5.762562291994982, + 5.763274500000989, + 5.763996166999277, + 5.7646624999979394, + 5.765350249996118, + 5.76600420899922, + 5.766648416996759, + 5.767273208999541, + 5.7679325839999365, + 5.768582584001706, + 5.769268124997325, + 5.769886249996489, + 5.770510499998636, + 5.7711389169999165, + 5.77182612499746, + 5.772480542000267, + 5.773147250001784, + 5.773771708998538, + 5.77446954199695, + 5.775163209000311, + 5.775796000001719, + 5.776444666997122, + 5.777064791996963, + 5.777706708999176, + 5.778307458997006, + 5.7789347500001895, + 5.779534749999584, + 5.780171250000421, + 5.780840958999761, + 5.781557541995426, + 5.7822583749948535, + 5.782946833998722, + 5.783616749999055, + 5.784262499997567, + 5.7849170839981525, + 5.7855541669996455, + 5.786245167000743, + 5.786897666999721, + 5.787543624996033, + 5.788159458999871, + 5.7888028339948505, + 5.789445624999644, + 5.790102541999659, + 5.790772416999971, + 5.791471291995549, + 5.792145667001023, + 5.792776750000485, + 5.793433624996396, + 5.794100291997893, + 5.794753249996575, + 5.7954331669971, + 5.796110208997561, + 5.796743749997404, + 5.79736899999989, + 5.79801462499745, + 5.79866620899702, + 5.799324791994877, + 5.799966124999628, + 5.800571708998177, + 5.801186584001698, + 5.801829208998242, + 5.802446333997068, + 5.803074041999935, + 5.803632249997463, + 5.804205458996876, + 5.804764749998867, + 5.8053289169984055, + 5.805874334000691, + 5.806443249995937, + 5.8070036669960245, + 5.80753833399649, + 5.808079041999008, + 5.808671041995694, + 5.80918337500043, + 5.809736958995927, + 5.810259917001531, + 5.810807541995018, + 5.8113250419992255, + 5.811907791998237, + 5.812512666998373, + 5.813131374998193, + 5.813784708996536, + 5.814452708997123, + 5.8150558339984855, + 5.8156614170002285, + 5.81633512499684, + 5.816975292000279, + 5.817596208995383, + 5.8182072499985225, + 5.818818959000055, + 5.819426750000275, + 5.8202002920006635, + 5.820871874995646, + 5.82159262499772, + 5.822269042000698, + 5.822879041996202, + 5.823495999997249, + 5.824127833999228, + 5.824803750001593, + 5.825430749995576, + 5.826101916994958, + 5.826727209001547, + 5.82736758399551, + 5.828043916997558, + 5.828684374995646, + 5.829374666995136, + 5.830058166997333, + 5.830646374997741, + 5.831297917000484, + 5.831969083999866, + 5.832578583998838, + 5.8332104590008385, + 5.833894458999566, + 5.834508791995177, + 5.8351109169962, + 5.835681249998743, + 5.836314499996661, + 5.83692579199851, + 5.837544791997061, + 5.838138084000093, + 5.838796249998268, + 5.839446792000672, + 5.840086249998421, + 5.840719749998243, + 5.841371791997517, + 5.842061541996372, + 5.842785624998214, + 5.843465124999057, + 5.844131792000553, + 5.844794917000399, + 5.845459124997433, + 5.846133166996879, + 5.846826959001191, + 5.847433333998197, + 5.84805116699863, + 5.84859508399677, + 5.84909854199941, + 5.849649708994548, + 5.8502101249978296, + 5.850697417001356, + 5.851228542000172, + 5.8517655420000665, + 5.852259624996805, + 5.852776458996232, + 5.853341541995178, + 5.8539288749962, + 5.854481666996435, + 5.854976916998567, + 5.855550959000539, + 5.856100666998827, + 5.856666374995257, + 5.857228333996318, + 5.85780016699573, + 5.858351999995648, + 5.8589033339958405, + 5.859472083997389, + 5.860015124999336, + 5.860551583995402, + 5.861087874996883, + 5.861797874997137, + 5.862770084000658, + 5.863493833996472, + 5.864086249996035, + 5.864665041997796, + 5.865207333998114, + 5.865760874999978, + 5.866301583999302, + 5.8668279589983285, + 5.867317958996864, + 5.867874458999722, + 5.86843283399503, + 5.868994208998629, + 5.869499916996574, + 5.870066958996176, + 5.870627374999458, + 5.8711791669993545, + 5.871702208998613, + 5.87233645899687, + 5.872922666996601, + 5.873443666998355, + 5.873970499997085, + 5.874500541998714, + 5.8750488750010845, + 5.875599416998739, + 5.876184041997476, + 5.876708042000246, + 5.877219709000201, + 5.877727041995968, + 5.87827108399506, + 5.878861541998049, + 5.8794156669973745, + 5.879999874996429, + 5.880557708995184, + 5.881202124997799, + 5.881823291994806, + 5.882459874999768, + 5.883052917000896, + 5.883593209000537, + 5.884099541995965, + 5.884629624997615, + 5.885154750001675, + 5.885732583999925, + 5.886266583998804, + 5.886817916994914, + 5.887373249999655, + 5.8880449589996715, + 5.888585000000603, + 5.88911625000037, + 5.8896314589947, + 5.890155542001594, + 5.89074033399811, + 5.891297292000672, + 5.891834624999319, + 5.892307583999354, + 5.8928201669987175, + 5.893349209000007, + 5.893919916998129, + 5.894483958996716, + 5.895033583998156, + 5.895561708995956, + 5.896085041997139, + 5.896646791996318, + 5.897222416999284, + 5.897817833996669, + 5.898381209000945, + 5.8989145000014105, + 5.89942579199851, + 5.899928667000495, + 5.900526166995405, + 5.901100083996425, + 5.901707583994721, + 5.902288459001284, + 5.902945916997851, + 5.9036173339991365, + 5.904197083997133, + 5.904731292001088, + 5.905232833996706, + 5.905854333999741, + 5.906449249996513, + 5.906962208995537, + 5.907496624997293, + 5.908064709001337, + 5.9086199999946984, + 5.909188708996226, + 5.909762833995046, + 5.91034029200091, + 5.910880167000869, + 5.911416041999473, + 5.911990791995777, + 5.912543291997281, + 5.913059041995439, + 5.913623708998784, + 5.914161708999018, + 5.914721583998471, + 5.91527241699805, + 5.915828416997101, + 5.9163517499982845, + 5.916918208997231, + 5.917458042000362, + 5.918012624999392, + 5.918606624996755, + 5.919254166998144, + 5.920039500000712, + 5.920612791996973, + 5.921219124997151, + 5.921826792000502, + 5.922383917000843, + 5.9229531249948195, + 5.923495625000214, + 5.924122958997032, + 5.924694291999913, + 5.925315542001044, + 5.92586612499872, + 5.926426083999104, + 5.927026666999154, + 5.927581584001018, + 5.92814266699861 + ], + "message_points_y": [ + 1, + 2, + 3, + 4, + 5, + 6, + 7, + 8, + 9, + 10, + 11, + 12, + 13, + 14, + 15, + 16, + 17, + 18, + 19, + 20, + 21, + 22, + 23, + 24, + 25, + 26, + 27, + 28, + 29, + 30, + 31, + 32, + 33, + 34, + 35, + 36, + 37, + 38, + 39, + 40, + 41, + 42, + 43, + 44, + 45, + 46, + 47, + 48, + 49, + 50, + 51, + 52, + 53, + 54, + 55, + 56, + 57, + 58, + 59, + 60, + 61, + 62, + 63, + 64, + 65, + 66, + 67, + 68, + 69, + 70, + 71, + 72, + 73, + 74, + 75, + 76, + 77, + 78, + 79, + 80, + 81, + 82, + 83, + 84, + 85, + 86, + 87, + 88, + 89, + 90, + 91, + 92, + 93, + 94, + 95, + 96, + 97, + 98, + 99, + 100, + 101, + 102, + 103, + 104, + 105, + 106, + 107, + 108, + 109, + 110, + 111, + 112, + 113, + 114, + 115, + 116, + 117, + 118, + 119, + 120, + 121, + 122, + 123, + 124, + 125, + 126, + 127, + 128, + 129, + 130, + 131, + 132, + 133, + 134, + 135, + 136, + 137, + 138, + 139, + 140, + 141, + 142, + 143, + 144, + 145, + 146, + 147, + 148, + 149, + 150, + 151, + 152, + 153, + 154, + 155, + 156, + 157, + 158, + 159, + 160, + 161, + 162, + 163, + 164, + 165, + 166, + 167, + 168, + 169, + 170, + 171, + 172, + 173, + 174, + 175, + 176, + 177, + 178, + 179, + 180, + 181, + 182, + 183, + 184, + 185, + 186, + 187, + 188, + 189, + 190, + 191, + 192, + 193, + 194, + 195, + 196, + 197, + 198, + 199, + 200, + 201, + 202, + 203, + 204, + 205, + 206, + 207, + 208, + 209, + 210, + 211, + 212, + 213, + 214, + 215, + 216, + 217, + 218, + 219, + 220, + 221, + 222, + 223, + 224, + 225, + 226, + 227, + 228, + 229, + 230, + 231, + 232, + 233, + 234, + 235, + 236, + 237, + 238, + 239, + 240, + 241, + 242, + 243, + 244, + 245, + 246, + 247, + 248, + 249, + 250, + 251, + 252, + 253, + 254, + 255, + 256, + 257, + 258, + 259, + 260, + 261, + 262, + 263, + 264, + 265, + 266, + 267, + 268, + 269, + 270, + 271, + 272, + 273, + 274, + 275, + 276, + 277, + 278, + 279, + 280, + 281, + 282, + 283, + 284, + 285, + 286, + 287, + 288, + 289, + 290, + 291, + 292, + 293, + 294, + 295, + 296, + 297, + 298, + 299, + 300, + 301, + 302, + 303, + 304, + 305, + 306, + 307, + 308, + 309, + 310, + 311, + 312, + 313, + 314, + 315, + 316, + 317, + 318, + 319, + 320, + 321, + 322, + 323, + 324, + 325, + 326, + 327, + 328, + 329, + 330, + 331, + 332, + 333, + 334, + 335, + 336, + 337, + 338, + 339, + 340, + 341, + 342, + 343, + 344, + 345, + 346, + 347, + 348, + 349, + 350, + 351, + 352, + 353, + 354, + 355, + 356, + 357, + 358, + 359, + 360, + 361, + 362, + 363, + 364, + 365, + 366, + 367, + 368, + 369, + 370, + 371, + 372, + 373, + 374, + 375, + 376, + 377, + 378, + 379, + 380, + 381, + 382, + 383, + 384, + 385, + 386, + 387, + 388, + 389, + 390, + 391, + 392, + 393, + 394, + 395, + 396, + 397, + 398, + 399, + 400, + 401, + 402, + 403, + 404, + 405, + 406, + 407, + 408, + 409, + 410, + 411, + 412, + 413, + 414, + 415, + 416, + 417, + 418, + 419, + 420, + 421, + 422, + 423, + 424, + 425, + 426, + 427, + 428, + 429, + 430, + 431, + 432, + 433, + 434, + 435, + 436, + 437, + 438, + 439, + 440, + 441, + 442, + 443, + 444, + 445, + 446, + 447, + 448, + 449, + 450, + 451, + 452, + 453, + 454, + 455, + 456, + 457, + 458, + 459, + 460, + 461, + 462, + 463, + 464, + 465, + 466, + 467, + 468, + 469, + 470, + 471, + 472, + 473, + 474, + 475, + 476, + 477, + 478, + 479, + 480, + 481, + 482, + 483, + 484, + 485, + 486, + 487, + 488, + 489, + 490, + 491, + 492, + 493, + 494, + 495, + 496, + 497, + 498, + 499, + 500, + 501, + 502, + 503, + 504, + 505, + 506, + 507, + 508, + 509, + 510, + 511, + 512, + 513, + 514, + 515, + 516, + 517, + 518, + 519, + 520, + 521, + 522, + 523, + 524, + 525, + 526, + 527, + 528, + 529, + 530, + 531, + 532, + 533, + 534, + 535, + 536, + 537, + 538, + 539, + 540, + 541, + 542, + 543, + 544, + 545, + 546, + 547, + 548, + 549, + 550, + 551, + 552, + 553, + 554, + 555, + 556, + 557, + 558, + 559, + 560, + 561, + 562, + 563, + 564, + 565, + 566, + 567, + 568, + 569, + 570, + 571, + 572, + 573, + 574, + 575, + 576, + 577, + 578, + 579, + 580, + 581, + 582, + 583, + 584, + 585, + 586, + 587, + 588, + 589, + 590, + 591, + 592, + 593, + 594, + 595, + 596, + 597, + 598, + 599, + 600, + 601, + 602, + 603, + 604, + 605, + 606, + 607, + 608, + 609, + 610, + 611, + 612, + 613, + 614, + 615, + 616, + 617, + 618, + 619, + 620, + 621, + 622, + 623, + 624, + 625, + 626, + 627, + 628, + 629, + 630, + 631, + 632, + 633, + 634, + 635, + 636, + 637, + 638, + 639, + 640, + 641, + 642, + 643, + 644, + 645, + 646, + 647, + 648, + 649, + 650, + 651, + 652, + 653, + 654, + 655, + 656, + 657, + 658, + 659, + 660, + 661, + 662, + 663, + 664, + 665, + 666, + 667, + 668, + 669, + 670, + 671, + 672, + 673, + 674, + 675, + 676, + 677, + 678, + 679, + 680, + 681, + 682, + 683, + 684, + 685, + 686, + 687, + 688, + 689, + 690, + 691, + 692, + 693, + 694, + 695, + 696, + 697, + 698, + 699, + 700, + 701, + 702, + 703, + 704, + 705, + 706, + 707, + 708, + 709, + 710, + 711, + 712, + 713, + 714, + 715, + 716, + 717, + 718, + 719, + 720, + 721, + 722, + 723, + 724, + 725, + 726, + 727, + 728, + 729, + 730, + 731, + 732, + 733, + 734, + 735, + 736, + 737, + 738, + 739, + 740, + 741, + 742, + 743, + 744, + 745, + 746, + 747, + 748, + 749, + 750, + 751, + 752, + 753, + 754, + 755, + 756, + 757, + 758, + 759, + 760, + 761, + 762, + 763, + 764, + 765, + 766, + 767, + 768, + 769, + 770, + 771, + 772, + 773, + 774, + 775, + 776, + 777, + 778, + 779, + 780, + 781, + 782, + 783, + 784, + 785, + 786, + 787, + 788, + 789, + 790, + 791, + 792, + 793, + 794, + 795, + 796, + 797, + 798, + 799, + 800, + 801, + 802, + 803, + 804, + 805, + 806, + 807, + 808, + 809, + 810, + 811, + 812, + 813, + 814, + 815, + 816, + 817, + 818, + 819, + 820, + 821, + 822, + 823, + 824, + 825, + 826, + 827, + 828, + 829, + 830, + 831, + 832, + 833, + 834, + 835, + 836, + 837, + 838, + 839, + 840, + 841, + 842, + 843, + 844, + 845, + 846, + 847, + 848, + 849, + 850, + 851, + 852, + 853, + 854, + 855, + 856, + 857, + 858, + 859, + 860, + 861, + 862, + 863, + 864, + 865, + 866, + 867, + 868, + 869, + 870, + 871, + 872, + 873, + 874, + 875, + 876, + 877, + 878, + 879, + 880, + 881, + 882, + 883, + 884, + 885, + 886, + 887, + 888, + 889, + 890, + 891, + 892, + 893, + 894, + 895, + 896, + 897, + 898, + 899, + 900, + 901, + 902, + 903, + 904, + 905, + 906, + 907, + 908, + 909, + 910, + 911, + 912, + 913, + 914, + 915, + 916, + 917, + 918, + 919, + 920, + 921, + 922, + 923, + 924, + 925, + 926, + 927, + 928, + 929, + 930, + 931, + 932, + 933, + 934, + 935, + 936, + 937, + 938, + 939, + 940, + 941, + 942, + 943, + 944, + 945, + 946, + 947, + 948, + 949, + 950, + 951, + 952, + 953, + 954, + 955, + 956, + 957, + 958, + 959, + 960, + 961, + 962, + 963, + 964, + 965, + 966, + 967, + 968, + 969, + 970, + 971, + 972, + 973, + 974, + 975, + 976, + 977, + 978, + 979, + 980, + 981, + 982, + 983, + 984, + 985, + 986, + 987, + 988, + 989, + 990, + 991, + 992, + 993, + 994, + 995, + 996, + 997, + 998, + 999, + 1000, + 1001, + 1002, + 1003, + 1004, + 1005, + 1006, + 1007, + 1008, + 1009, + 1010, + 1011, + 1012, + 1013, + 1014, + 1015, + 1016, + 1017, + 1018, + 1019, + 1020, + 1021, + 1022, + 1023, + 1024, + 1025, + 1026, + 1027, + 1028, + 1029, + 1030, + 1031, + 1032, + 1033, + 1034, + 1035, + 1036, + 1037, + 1038, + 1039, + 1040, + 1041, + 1042, + 1043, + 1044, + 1045, + 1046, + 1047, + 1048, + 1049, + 1050, + 1051, + 1052, + 1053, + 1054, + 1055, + 1056, + 1057, + 1058, + 1059, + 1060, + 1061, + 1062, + 1063, + 1064, + 1065, + 1066, + 1067, + 1068, + 1069, + 1070, + 1071, + 1072, + 1073, + 1074, + 1075, + 1076, + 1077, + 1078, + 1079, + 1080, + 1081, + 1082, + 1083, + 1084, + 1085, + 1086, + 1087, + 1088, + 1089, + 1090, + 1091, + 1092, + 1093, + 1094, + 1095, + 1096, + 1097, + 1098, + 1099, + 1100, + 1101, + 1102, + 1103, + 1104, + 1105, + 1106, + 1107, + 1108, + 1109, + 1110, + 1111, + 1112, + 1113, + 1114, + 1115, + 1116, + 1117, + 1118, + 1119, + 1120, + 1121, + 1122, + 1123, + 1124, + 1125, + 1126, + 1127, + 1128, + 1129, + 1130, + 1131, + 1132, + 1133, + 1134, + 1135, + 1136, + 1137, + 1138, + 1139, + 1140, + 1141, + 1142, + 1143, + 1144, + 1145, + 1146, + 1147, + 1148, + 1149, + 1150, + 1151, + 1152, + 1153, + 1154, + 1155, + 1156, + 1157, + 1158, + 1159, + 1160, + 1161, + 1162, + 1163, + 1164, + 1165, + 1166, + 1167, + 1168, + 1169, + 1170, + 1171, + 1172, + 1173, + 1174, + 1175, + 1176, + 1177, + 1178, + 1179, + 1180, + 1181, + 1182, + 1183, + 1184, + 1185, + 1186, + 1187, + 1188, + 1189, + 1190, + 1191, + 1192, + 1193, + 1194, + 1195, + 1196, + 1197, + 1198, + 1199, + 1200, + 1201, + 1202, + 1203, + 1204, + 1205, + 1206, + 1207, + 1208, + 1209, + 1210, + 1211, + 1212, + 1213, + 1214, + 1215, + 1216, + 1217, + 1218, + 1219, + 1220, + 1221, + 1222, + 1223, + 1224, + 1225, + 1226, + 1227, + 1228, + 1229, + 1230, + 1231, + 1232, + 1233, + 1234, + 1235, + 1236, + 1237, + 1238, + 1239, + 1240, + 1241, + 1242, + 1243, + 1244, + 1245, + 1246, + 1247, + 1248, + 1249, + 1250, + 1251, + 1252, + 1253, + 1254, + 1255, + 1256, + 1257, + 1258, + 1259, + 1260, + 1261, + 1262, + 1263, + 1264, + 1265, + 1266, + 1267, + 1268, + 1269, + 1270, + 1271, + 1272, + 1273, + 1274, + 1275, + 1276, + 1277, + 1278, + 1279, + 1280, + 1281, + 1282, + 1283, + 1284, + 1285, + 1286, + 1287, + 1288, + 1289, + 1290, + 1291, + 1292, + 1293, + 1294, + 1295, + 1296, + 1297, + 1298, + 1299, + 1300, + 1301, + 1302, + 1303, + 1304, + 1305, + 1306, + 1307, + 1308, + 1309, + 1310, + 1311, + 1312, + 1313, + 1314, + 1315, + 1316, + 1317, + 1318, + 1319, + 1320, + 1321, + 1322, + 1323, + 1324, + 1325, + 1326, + 1327, + 1328, + 1329, + 1330, + 1331, + 1332, + 1333, + 1334, + 1335, + 1336, + 1337, + 1338, + 1339, + 1340, + 1341, + 1342, + 1343, + 1344, + 1345, + 1346, + 1347, + 1348, + 1349, + 1350, + 1351, + 1352, + 1353, + 1354, + 1355, + 1356, + 1357, + 1358, + 1359, + 1360, + 1361, + 1362, + 1363, + 1364, + 1365, + 1366, + 1367, + 1368, + 1369, + 1370, + 1371, + 1372, + 1373, + 1374, + 1375, + 1376, + 1377, + 1378, + 1379, + 1380, + 1381, + 1382, + 1383, + 1384, + 1385, + 1386, + 1387, + 1388, + 1389, + 1390, + 1391, + 1392, + 1393, + 1394, + 1395, + 1396, + 1397, + 1398, + 1399, + 1400, + 1401, + 1402, + 1403, + 1404, + 1405, + 1406, + 1407, + 1408, + 1409, + 1410, + 1411, + 1412, + 1413, + 1414, + 1415, + 1416, + 1417, + 1418, + 1419, + 1420, + 1421, + 1422, + 1423, + 1424, + 1425, + 1426, + 1427, + 1428, + 1429, + 1430, + 1431, + 1432, + 1433, + 1434, + 1435, + 1436, + 1437, + 1438, + 1439, + 1440, + 1441, + 1442, + 1443, + 1444, + 1445, + 1446, + 1447, + 1448, + 1449, + 1450, + 1451, + 1452, + 1453, + 1454, + 1455, + 1456, + 1457, + 1458, + 1459, + 1460, + 1461, + 1462, + 1463, + 1464, + 1465, + 1466, + 1467, + 1468, + 1469, + 1470, + 1471, + 1472, + 1473, + 1474, + 1475, + 1476, + 1477, + 1478, + 1479, + 1480, + 1481, + 1482, + 1483, + 1484, + 1485, + 1486, + 1487, + 1488, + 1489, + 1490, + 1491, + 1492, + 1493, + 1494, + 1495, + 1496, + 1497, + 1498, + 1499, + 1500, + 1501, + 1502, + 1503, + 1504, + 1505, + 1506, + 1507, + 1508, + 1509, + 1510, + 1511, + 1512, + 1513, + 1514, + 1515, + 1516, + 1517, + 1518, + 1519, + 1520, + 1521, + 1522, + 1523, + 1524, + 1525, + 1526, + 1527, + 1528, + 1529, + 1530, + 1531, + 1532, + 1533, + 1534, + 1535, + 1536, + 1537, + 1538, + 1539, + 1540, + 1541, + 1542, + 1543, + 1544, + 1545, + 1546, + 1547, + 1548, + 1549, + 1550, + 1551, + 1552, + 1553, + 1554, + 1555, + 1556, + 1557, + 1558, + 1559, + 1560, + 1561, + 1562, + 1563, + 1564, + 1565, + 1566, + 1567, + 1568, + 1569, + 1570, + 1571, + 1572, + 1573, + 1574, + 1575, + 1576, + 1577, + 1578, + 1579, + 1580, + 1581, + 1582, + 1583, + 1584, + 1585, + 1586, + 1587, + 1588, + 1589, + 1590, + 1591, + 1592, + 1593, + 1594, + 1595, + 1596, + 1597, + 1598, + 1599, + 1600, + 1601, + 1602, + 1603, + 1604, + 1605, + 1606, + 1607, + 1608, + 1609, + 1610, + 1611, + 1612, + 1613, + 1614, + 1615, + 1616, + 1617, + 1618, + 1619, + 1620, + 1621, + 1622, + 1623, + 1624, + 1625, + 1626, + 1627, + 1628, + 1629, + 1630, + 1631, + 1632, + 1633, + 1634, + 1635, + 1636, + 1637, + 1638, + 1639, + 1640, + 1641, + 1642, + 1643, + 1644, + 1645, + 1646, + 1647, + 1648, + 1649, + 1650, + 1651, + 1652, + 1653, + 1654, + 1655, + 1656, + 1657, + 1658, + 1659, + 1660, + 1661, + 1662, + 1663, + 1664, + 1665, + 1666, + 1667, + 1668, + 1669, + 1670, + 1671, + 1672, + 1673, + 1674, + 1675, + 1676, + 1677, + 1678, + 1679, + 1680, + 1681, + 1682, + 1683, + 1684, + 1685, + 1686, + 1687, + 1688, + 1689, + 1690, + 1691, + 1692, + 1693, + 1694, + 1695, + 1696, + 1697, + 1698, + 1699, + 1700, + 1701, + 1702, + 1703, + 1704, + 1705, + 1706, + 1707, + 1708, + 1709, + 1710, + 1711, + 1712, + 1713, + 1714, + 1715, + 1716, + 1717, + 1718, + 1719, + 1720, + 1721, + 1722, + 1723, + 1724, + 1725, + 1726, + 1727, + 1728, + 1729, + 1730, + 1731, + 1732, + 1733, + 1734, + 1735, + 1736, + 1737, + 1738, + 1739, + 1740, + 1741, + 1742, + 1743, + 1744, + 1745, + 1746, + 1747, + 1748, + 1749, + 1750, + 1751, + 1752, + 1753, + 1754, + 1755, + 1756, + 1757, + 1758, + 1759, + 1760, + 1761, + 1762, + 1763, + 1764, + 1765, + 1766, + 1767, + 1768, + 1769, + 1770, + 1771, + 1772, + 1773, + 1774, + 1775, + 1776, + 1777, + 1778, + 1779, + 1780, + 1781, + 1782, + 1783, + 1784, + 1785, + 1786, + 1787, + 1788, + 1789, + 1790, + 1791, + 1792, + 1793, + 1794, + 1795, + 1796, + 1797, + 1798, + 1799, + 1800, + 1801, + 1802, + 1803, + 1804, + 1805, + 1806, + 1807, + 1808, + 1809, + 1810, + 1811, + 1812, + 1813, + 1814, + 1815, + 1816, + 1817, + 1818, + 1819, + 1820, + 1821, + 1822, + 1823, + 1824, + 1825, + 1826, + 1827, + 1828, + 1829, + 1830, + 1831, + 1832, + 1833, + 1834, + 1835, + 1836, + 1837, + 1838, + 1839, + 1840, + 1841, + 1842, + 1843, + 1844, + 1845, + 1846, + 1847, + 1848, + 1849, + 1850, + 1851, + 1852, + 1853, + 1854, + 1855, + 1856, + 1857, + 1858, + 1859, + 1860, + 1861, + 1862, + 1863, + 1864, + 1865, + 1866, + 1867, + 1868, + 1869, + 1870, + 1871, + 1872, + 1873, + 1874, + 1875, + 1876, + 1877, + 1878, + 1879, + 1880, + 1881, + 1882, + 1883, + 1884, + 1885, + 1886, + 1887, + 1888, + 1889, + 1890, + 1891, + 1892, + 1893, + 1894, + 1895, + 1896, + 1897, + 1898, + 1899, + 1900, + 1901, + 1902, + 1903, + 1904, + 1905, + 1906, + 1907, + 1908, + 1909, + 1910, + 1911, + 1912, + 1913, + 1914, + 1915, + 1916, + 1917, + 1918, + 1919, + 1920, + 1921, + 1922, + 1923, + 1924, + 1925, + 1926, + 1927, + 1928, + 1929, + 1930, + 1931, + 1932, + 1933, + 1934, + 1935, + 1936, + 1937, + 1938, + 1939, + 1940, + 1941, + 1942, + 1943, + 1944, + 1945, + 1946, + 1947, + 1948, + 1949, + 1950, + 1951, + 1952, + 1953, + 1954, + 1955, + 1956, + 1957, + 1958, + 1959, + 1960, + 1961, + 1962, + 1963, + 1964, + 1965, + 1966, + 1967, + 1968, + 1969, + 1970, + 1971, + 1972, + 1973, + 1974, + 1975, + 1976, + 1977, + 1978, + 1979, + 1980, + 1981, + 1982, + 1983, + 1984, + 1985, + 1986, + 1987, + 1988, + 1989, + 1990, + 1991, + 1992, + 1993, + 1994, + 1995, + 1996, + 1997, + 1998, + 1999, + 2000, + 2001, + 2002, + 2003, + 2004, + 2005, + 2006, + 2007, + 2008, + 2009, + 2010, + 2011, + 2012, + 2013, + 2014, + 2015, + 2016, + 2017, + 2018, + 2019, + 2020, + 2021, + 2022, + 2023, + 2024, + 2025, + 2026, + 2027, + 2028, + 2029, + 2030, + 2031, + 2032, + 2033, + 2034, + 2035, + 2036, + 2037, + 2038, + 2039, + 2040, + 2041, + 2042, + 2043, + 2044, + 2045, + 2046, + 2047, + 2048, + 2049, + 2050, + 2051, + 2052, + 2053, + 2054, + 2055, + 2056, + 2057, + 2058, + 2059, + 2060, + 2061, + 2062, + 2063, + 2064, + 2065, + 2066, + 2067, + 2068, + 2069, + 2070, + 2071, + 2072, + 2073, + 2074, + 2075, + 2076, + 2077, + 2078, + 2079, + 2080, + 2081, + 2082, + 2083, + 2084, + 2085, + 2086, + 2087, + 2088, + 2089, + 2090, + 2091, + 2092, + 2093, + 2094, + 2095, + 2096, + 2097, + 2098, + 2099, + 2100, + 2101, + 2102, + 2103, + 2104, + 2105, + 2106, + 2107, + 2108, + 2109, + 2110, + 2111, + 2112, + 2113, + 2114, + 2115, + 2116, + 2117, + 2118, + 2119, + 2120, + 2121, + 2122, + 2123, + 2124, + 2125, + 2126, + 2127, + 2128, + 2129, + 2130, + 2131, + 2132, + 2133, + 2134, + 2135, + 2136, + 2137, + 2138, + 2139, + 2140, + 2141, + 2142, + 2143, + 2144, + 2145, + 2146, + 2147, + 2148, + 2149, + 2150, + 2151, + 2152, + 2153, + 2154, + 2155, + 2156, + 2157, + 2158, + 2159, + 2160, + 2161, + 2162, + 2163, + 2164, + 2165, + 2166, + 2167, + 2168, + 2169, + 2170, + 2171, + 2172, + 2173, + 2174, + 2175, + 2176, + 2177, + 2178, + 2179, + 2180, + 2181, + 2182, + 2183, + 2184, + 2185, + 2186, + 2187, + 2188, + 2189, + 2190, + 2191, + 2192, + 2193, + 2194, + 2195, + 2196, + 2197, + 2198, + 2199, + 2200, + 2201, + 2202, + 2203, + 2204, + 2205, + 2206, + 2207, + 2208, + 2209, + 2210, + 2211, + 2212, + 2213, + 2214, + 2215, + 2216, + 2217, + 2218, + 2219, + 2220, + 2221, + 2222, + 2223, + 2224, + 2225, + 2226, + 2227, + 2228, + 2229, + 2230, + 2231, + 2232, + 2233, + 2234, + 2235, + 2236, + 2237, + 2238, + 2239, + 2240, + 2241, + 2242, + 2243, + 2244, + 2245, + 2246, + 2247, + 2248, + 2249, + 2250, + 2251, + 2252, + 2253, + 2254, + 2255, + 2256, + 2257, + 2258, + 2259, + 2260, + 2261, + 2262, + 2263, + 2264, + 2265, + 2266, + 2267, + 2268, + 2269, + 2270, + 2271, + 2272, + 2273, + 2274, + 2275, + 2276, + 2277, + 2278, + 2279, + 2280, + 2281, + 2282, + 2283, + 2284, + 2285, + 2286, + 2287, + 2288, + 2289, + 2290, + 2291, + 2292, + 2293, + 2294, + 2295, + 2296, + 2297, + 2298, + 2299, + 2300, + 2301, + 2302, + 2303, + 2304, + 2305, + 2306, + 2307, + 2308, + 2309, + 2310, + 2311, + 2312, + 2313, + 2314, + 2315, + 2316, + 2317, + 2318, + 2319, + 2320, + 2321, + 2322, + 2323, + 2324, + 2325, + 2326, + 2327, + 2328, + 2329, + 2330, + 2331, + 2332, + 2333, + 2334, + 2335, + 2336, + 2337, + 2338, + 2339, + 2340, + 2341, + 2342, + 2343, + 2344, + 2345, + 2346, + 2347, + 2348, + 2349, + 2350, + 2351, + 2352, + 2353, + 2354, + 2355, + 2356, + 2357, + 2358, + 2359, + 2360, + 2361, + 2362, + 2363, + 2364, + 2365, + 2366, + 2367, + 2368, + 2369, + 2370, + 2371, + 2372, + 2373, + 2374, + 2375, + 2376, + 2377, + 2378, + 2379, + 2380, + 2381, + 2382, + 2383, + 2384, + 2385, + 2386, + 2387, + 2388, + 2389, + 2390, + 2391, + 2392, + 2393, + 2394, + 2395, + 2396, + 2397, + 2398, + 2399, + 2400, + 2401, + 2402, + 2403, + 2404, + 2405, + 2406, + 2407, + 2408, + 2409, + 2410, + 2411, + 2412, + 2413, + 2414, + 2415, + 2416, + 2417, + 2418, + 2419, + 2420, + 2421, + 2422, + 2423, + 2424, + 2425, + 2426, + 2427, + 2428, + 2429, + 2430, + 2431, + 2432, + 2433, + 2434, + 2435, + 2436, + 2437, + 2438, + 2439, + 2440, + 2441, + 2442, + 2443, + 2444, + 2445, + 2446, + 2447, + 2448, + 2449, + 2450, + 2451, + 2452, + 2453, + 2454, + 2455, + 2456, + 2457, + 2458, + 2459, + 2460, + 2461, + 2462, + 2463, + 2464, + 2465, + 2466, + 2467, + 2468, + 2469, + 2470, + 2471, + 2472, + 2473, + 2474, + 2475, + 2476, + 2477, + 2478, + 2479, + 2480, + 2481, + 2482, + 2483, + 2484, + 2485, + 2486, + 2487, + 2488, + 2489, + 2490, + 2491, + 2492, + 2493, + 2494, + 2495, + 2496, + 2497, + 2498, + 2499, + 2500, + 2501, + 2502, + 2503, + 2504, + 2505, + 2506, + 2507, + 2508, + 2509, + 2510, + 2511, + 2512, + 2513, + 2514, + 2515, + 2516, + 2517, + 2518, + 2519, + 2520, + 2521, + 2522, + 2523, + 2524, + 2525, + 2526, + 2527, + 2528, + 2529, + 2530, + 2531, + 2532, + 2533, + 2534, + 2535, + 2536, + 2537, + 2538, + 2539, + 2540, + 2541, + 2542, + 2543, + 2544, + 2545, + 2546, + 2547, + 2548, + 2549, + 2550, + 2551, + 2552, + 2553, + 2554, + 2555, + 2556, + 2557, + 2558, + 2559, + 2560, + 2561, + 2562, + 2563, + 2564, + 2565, + 2566, + 2567, + 2568, + 2569, + 2570, + 2571, + 2572, + 2573, + 2574, + 2575, + 2576, + 2577, + 2578, + 2579, + 2580, + 2581, + 2582, + 2583, + 2584, + 2585, + 2586, + 2587, + 2588, + 2589, + 2590, + 2591, + 2592, + 2593, + 2594, + 2595, + 2596, + 2597, + 2598, + 2599, + 2600, + 2601, + 2602, + 2603, + 2604, + 2605, + 2606, + 2607, + 2608, + 2609, + 2610, + 2611, + 2612, + 2613, + 2614, + 2615, + 2616, + 2617, + 2618, + 2619, + 2620, + 2621, + 2622, + 2623, + 2624, + 2625, + 2626, + 2627, + 2628, + 2629, + 2630, + 2631, + 2632, + 2633, + 2634, + 2635, + 2636, + 2637, + 2638, + 2639, + 2640, + 2641, + 2642, + 2643, + 2644, + 2645, + 2646, + 2647, + 2648, + 2649, + 2650, + 2651, + 2652, + 2653, + 2654, + 2655, + 2656, + 2657, + 2658, + 2659, + 2660, + 2661, + 2662, + 2663, + 2664, + 2665, + 2666, + 2667, + 2668, + 2669, + 2670, + 2671, + 2672, + 2673, + 2674, + 2675, + 2676, + 2677, + 2678, + 2679, + 2680, + 2681, + 2682, + 2683, + 2684, + 2685, + 2686, + 2687, + 2688, + 2689, + 2690, + 2691, + 2692, + 2693, + 2694, + 2695, + 2696, + 2697, + 2698, + 2699, + 2700, + 2701, + 2702, + 2703, + 2704, + 2705, + 2706, + 2707, + 2708, + 2709, + 2710, + 2711, + 2712, + 2713, + 2714, + 2715, + 2716, + 2717, + 2718, + 2719, + 2720, + 2721, + 2722, + 2723, + 2724, + 2725, + 2726, + 2727, + 2728, + 2729, + 2730, + 2731, + 2732, + 2733, + 2734, + 2735, + 2736, + 2737, + 2738, + 2739, + 2740, + 2741, + 2742, + 2743, + 2744, + 2745, + 2746, + 2747, + 2748, + 2749, + 2750, + 2751, + 2752, + 2753, + 2754, + 2755, + 2756, + 2757, + 2758, + 2759, + 2760, + 2761, + 2762, + 2763, + 2764, + 2765, + 2766, + 2767, + 2768, + 2769, + 2770, + 2771, + 2772, + 2773, + 2774, + 2775, + 2776, + 2777, + 2778, + 2779, + 2780, + 2781, + 2782, + 2783, + 2784, + 2785, + 2786, + 2787, + 2788, + 2789, + 2790, + 2791, + 2792, + 2793, + 2794, + 2795, + 2796, + 2797, + 2798, + 2799, + 2800, + 2801, + 2802, + 2803, + 2804, + 2805, + 2806, + 2807, + 2808, + 2809, + 2810, + 2811, + 2812, + 2813, + 2814, + 2815, + 2816, + 2817, + 2818, + 2819, + 2820, + 2821, + 2822, + 2823, + 2824, + 2825, + 2826, + 2827, + 2828, + 2829, + 2830, + 2831, + 2832, + 2833, + 2834, + 2835, + 2836, + 2837, + 2838, + 2839, + 2840, + 2841, + 2842, + 2843, + 2844, + 2845, + 2846, + 2847, + 2848, + 2849, + 2850, + 2851, + 2852, + 2853, + 2854, + 2855, + 2856, + 2857, + 2858, + 2859, + 2860, + 2861, + 2862, + 2863, + 2864, + 2865, + 2866, + 2867, + 2868, + 2869, + 2870, + 2871, + 2872, + 2873, + 2874, + 2875, + 2876, + 2877, + 2878, + 2879, + 2880, + 2881, + 2882, + 2883, + 2884, + 2885, + 2886, + 2887, + 2888, + 2889, + 2890, + 2891, + 2892, + 2893, + 2894, + 2895, + 2896, + 2897, + 2898, + 2899, + 2900, + 2901, + 2902, + 2903, + 2904, + 2905, + 2906, + 2907, + 2908, + 2909, + 2910, + 2911, + 2912, + 2913, + 2914, + 2915, + 2916, + 2917, + 2918, + 2919, + 2920, + 2921, + 2922, + 2923, + 2924, + 2925, + 2926, + 2927, + 2928, + 2929, + 2930, + 2931, + 2932, + 2933, + 2934, + 2935, + 2936, + 2937, + 2938, + 2939, + 2940, + 2941, + 2942, + 2943, + 2944, + 2945, + 2946, + 2947, + 2948, + 2949, + 2950, + 2951, + 2952, + 2953, + 2954, + 2955, + 2956, + 2957, + 2958, + 2959, + 2960, + 2961, + 2962, + 2963, + 2964, + 2965, + 2966, + 2967, + 2968, + 2969, + 2970, + 2971, + 2972, + 2973, + 2974, + 2975, + 2976, + 2977, + 2978, + 2979, + 2980, + 2981, + 2982, + 2983, + 2984, + 2985, + 2986, + 2987, + 2988, + 2989, + 2990, + 2991, + 2992, + 2993, + 2994, + 2995, + 2996, + 2997, + 2998, + 2999, + 3000, + 3001, + 3002, + 3003, + 3004, + 3005, + 3006, + 3007, + 3008, + 3009, + 3010, + 3011, + 3012, + 3013, + 3014, + 3015, + 3016, + 3017, + 3018, + 3019, + 3020, + 3021, + 3022, + 3023, + 3024, + 3025, + 3026, + 3027, + 3028, + 3029, + 3030, + 3031, + 3032, + 3033, + 3034, + 3035, + 3036, + 3037, + 3038, + 3039, + 3040, + 3041, + 3042, + 3043, + 3044, + 3045, + 3046, + 3047, + 3048, + 3049, + 3050, + 3051, + 3052, + 3053, + 3054, + 3055, + 3056, + 3057, + 3058, + 3059, + 3060, + 3061, + 3062, + 3063, + 3064, + 3065, + 3066, + 3067, + 3068, + 3069, + 3070, + 3071, + 3072, + 3073, + 3074, + 3075, + 3076, + 3077, + 3078, + 3079, + 3080, + 3081, + 3082, + 3083, + 3084, + 3085, + 3086, + 3087, + 3088, + 3089, + 3090, + 3091, + 3092, + 3093, + 3094, + 3095, + 3096, + 3097, + 3098, + 3099, + 3100, + 3101, + 3102, + 3103, + 3104, + 3105, + 3106, + 3107, + 3108, + 3109, + 3110, + 3111, + 3112, + 3113, + 3114, + 3115, + 3116, + 3117, + 3118, + 3119, + 3120, + 3121, + 3122, + 3123, + 3124, + 3125, + 3126, + 3127, + 3128, + 3129, + 3130, + 3131, + 3132, + 3133, + 3134, + 3135, + 3136, + 3137, + 3138, + 3139, + 3140, + 3141, + 3142, + 3143, + 3144, + 3145, + 3146, + 3147, + 3148, + 3149, + 3150, + 3151, + 3152, + 3153, + 3154, + 3155, + 3156, + 3157, + 3158, + 3159, + 3160, + 3161, + 3162, + 3163, + 3164, + 3165, + 3166, + 3167, + 3168, + 3169, + 3170, + 3171, + 3172, + 3173, + 3174, + 3175, + 3176, + 3177, + 3178, + 3179, + 3180, + 3181, + 3182, + 3183, + 3184, + 3185, + 3186, + 3187, + 3188, + 3189, + 3190, + 3191, + 3192, + 3193, + 3194, + 3195, + 3196, + 3197, + 3198, + 3199, + 3200, + 3201, + 3202, + 3203, + 3204, + 3205, + 3206, + 3207, + 3208, + 3209, + 3210, + 3211, + 3212, + 3213, + 3214, + 3215, + 3216, + 3217, + 3218, + 3219, + 3220, + 3221, + 3222, + 3223, + 3224, + 3225, + 3226, + 3227, + 3228, + 3229, + 3230, + 3231, + 3232, + 3233, + 3234, + 3235, + 3236, + 3237, + 3238, + 3239, + 3240, + 3241, + 3242, + 3243, + 3244, + 3245, + 3246, + 3247, + 3248, + 3249, + 3250, + 3251, + 3252, + 3253, + 3254, + 3255, + 3256, + 3257, + 3258, + 3259, + 3260, + 3261, + 3262, + 3263, + 3264, + 3265, + 3266, + 3267, + 3268, + 3269, + 3270, + 3271, + 3272, + 3273, + 3274, + 3275, + 3276, + 3277, + 3278, + 3279, + 3280, + 3281, + 3282, + 3283, + 3284, + 3285, + 3286, + 3287, + 3288, + 3289, + 3290, + 3291, + 3292, + 3293, + 3294, + 3295, + 3296, + 3297, + 3298, + 3299, + 3300, + 3301, + 3302, + 3303, + 3304, + 3305, + 3306, + 3307, + 3308, + 3309, + 3310, + 3311, + 3312, + 3313, + 3314, + 3315, + 3316, + 3317, + 3318, + 3319, + 3320, + 3321, + 3322, + 3323, + 3324, + 3325, + 3326, + 3327, + 3328, + 3329, + 3330, + 3331, + 3332, + 3333, + 3334, + 3335, + 3336, + 3337, + 3338, + 3339, + 3340, + 3341, + 3342, + 3343, + 3344, + 3345, + 3346, + 3347, + 3348, + 3349, + 3350, + 3351, + 3352, + 3353, + 3354, + 3355, + 3356, + 3357, + 3358, + 3359, + 3360, + 3361, + 3362, + 3363, + 3364, + 3365, + 3366, + 3367, + 3368, + 3369, + 3370, + 3371, + 3372, + 3373, + 3374, + 3375, + 3376, + 3377, + 3378, + 3379, + 3380, + 3381, + 3382, + 3383, + 3384, + 3385, + 3386, + 3387, + 3388, + 3389, + 3390, + 3391, + 3392, + 3393, + 3394, + 3395, + 3396, + 3397, + 3398, + 3399, + 3400, + 3401, + 3402, + 3403, + 3404, + 3405, + 3406, + 3407, + 3408, + 3409, + 3410, + 3411, + 3412, + 3413, + 3414, + 3415, + 3416, + 3417, + 3418, + 3419, + 3420, + 3421, + 3422, + 3423, + 3424, + 3425, + 3426, + 3427, + 3428, + 3429, + 3430, + 3431, + 3432, + 3433, + 3434, + 3435, + 3436, + 3437, + 3438, + 3439, + 3440, + 3441, + 3442, + 3443, + 3444, + 3445, + 3446, + 3447, + 3448, + 3449, + 3450, + 3451, + 3452, + 3453, + 3454, + 3455, + 3456, + 3457, + 3458, + 3459, + 3460, + 3461, + 3462, + 3463, + 3464, + 3465, + 3466, + 3467, + 3468, + 3469, + 3470, + 3471, + 3472, + 3473, + 3474, + 3475, + 3476, + 3477, + 3478, + 3479, + 3480, + 3481, + 3482, + 3483, + 3484, + 3485, + 3486, + 3487, + 3488, + 3489, + 3490, + 3491, + 3492, + 3493, + 3494, + 3495, + 3496, + 3497, + 3498, + 3499, + 3500, + 3501, + 3502, + 3503, + 3504, + 3505, + 3506, + 3507, + 3508, + 3509, + 3510, + 3511, + 3512, + 3513, + 3514, + 3515, + 3516, + 3517, + 3518, + 3519, + 3520, + 3521, + 3522, + 3523, + 3524, + 3525, + 3526, + 3527, + 3528, + 3529, + 3530, + 3531, + 3532, + 3533, + 3534, + 3535, + 3536, + 3537, + 3538, + 3539, + 3540, + 3541, + 3542, + 3543, + 3544, + 3545, + 3546, + 3547, + 3548, + 3549, + 3550, + 3551, + 3552, + 3553, + 3554, + 3555, + 3556, + 3557, + 3558, + 3559, + 3560, + 3561, + 3562, + 3563, + 3564, + 3565, + 3566, + 3567, + 3568, + 3569, + 3570, + 3571, + 3572, + 3573, + 3574, + 3575, + 3576, + 3577, + 3578, + 3579, + 3580, + 3581, + 3582, + 3583, + 3584, + 3585, + 3586, + 3587, + 3588, + 3589, + 3590, + 3591, + 3592, + 3593, + 3594, + 3595, + 3596, + 3597, + 3598, + 3599, + 3600, + 3601, + 3602, + 3603, + 3604, + 3605, + 3606, + 3607, + 3608, + 3609, + 3610, + 3611, + 3612, + 3613, + 3614, + 3615, + 3616, + 3617, + 3618, + 3619, + 3620, + 3621, + 3622, + 3623, + 3624, + 3625, + 3626, + 3627, + 3628, + 3629, + 3630, + 3631, + 3632, + 3633, + 3634, + 3635, + 3636, + 3637, + 3638, + 3639, + 3640, + 3641, + 3642, + 3643, + 3644, + 3645, + 3646, + 3647, + 3648, + 3649, + 3650, + 3651, + 3652, + 3653, + 3654, + 3655, + 3656, + 3657, + 3658, + 3659, + 3660, + 3661, + 3662, + 3663, + 3664, + 3665, + 3666, + 3667, + 3668, + 3669, + 3670, + 3671, + 3672, + 3673, + 3674, + 3675, + 3676, + 3677, + 3678, + 3679, + 3680, + 3681, + 3682, + 3683, + 3684, + 3685, + 3686, + 3687, + 3688, + 3689, + 3690, + 3691, + 3692, + 3693, + 3694, + 3695, + 3696, + 3697, + 3698, + 3699, + 3700, + 3701, + 3702, + 3703, + 3704, + 3705, + 3706, + 3707, + 3708, + 3709, + 3710, + 3711, + 3712, + 3713, + 3714, + 3715, + 3716, + 3717, + 3718, + 3719, + 3720, + 3721, + 3722, + 3723, + 3724, + 3725, + 3726, + 3727, + 3728, + 3729, + 3730, + 3731, + 3732, + 3733, + 3734, + 3735, + 3736, + 3737, + 3738, + 3739, + 3740, + 3741, + 3742, + 3743, + 3744, + 3745, + 3746, + 3747, + 3748, + 3749, + 3750, + 3751, + 3752, + 3753, + 3754, + 3755, + 3756, + 3757, + 3758, + 3759, + 3760, + 3761, + 3762, + 3763, + 3764, + 3765, + 3766, + 3767, + 3768, + 3769, + 3770, + 3771, + 3772, + 3773, + 3774, + 3775, + 3776, + 3777, + 3778, + 3779, + 3780, + 3781, + 3782, + 3783, + 3784, + 3785, + 3786, + 3787, + 3788, + 3789, + 3790, + 3791, + 3792, + 3793, + 3794, + 3795, + 3796, + 3797, + 3798, + 3799, + 3800, + 3801, + 3802, + 3803, + 3804, + 3805, + 3806, + 3807, + 3808, + 3809, + 3810, + 3811, + 3812, + 3813, + 3814, + 3815, + 3816, + 3817, + 3818, + 3819, + 3820, + 3821, + 3822, + 3823, + 3824, + 3825, + 3826, + 3827, + 3828, + 3829, + 3830, + 3831, + 3832, + 3833, + 3834, + 3835, + 3836, + 3837, + 3838, + 3839, + 3840, + 3841, + 3842, + 3843, + 3844, + 3845, + 3846, + 3847, + 3848, + 3849, + 3850, + 3851, + 3852, + 3853, + 3854, + 3855, + 3856, + 3857, + 3858, + 3859, + 3860, + 3861, + 3862, + 3863, + 3864, + 3865, + 3866, + 3867, + 3868, + 3869, + 3870, + 3871, + 3872, + 3873, + 3874, + 3875, + 3876, + 3877, + 3878, + 3879, + 3880, + 3881, + 3882, + 3883, + 3884, + 3885, + 3886, + 3887, + 3888, + 3889, + 3890, + 3891, + 3892, + 3893, + 3894, + 3895, + 3896, + 3897, + 3898, + 3899, + 3900, + 3901, + 3902, + 3903, + 3904, + 3905, + 3906, + 3907, + 3908, + 3909, + 3910, + 3911, + 3912, + 3913, + 3914, + 3915, + 3916, + 3917, + 3918, + 3919, + 3920, + 3921, + 3922, + 3923, + 3924, + 3925, + 3926, + 3927, + 3928, + 3929, + 3930, + 3931, + 3932, + 3933, + 3934, + 3935, + 3936, + 3937, + 3938, + 3939, + 3940, + 3941, + 3942, + 3943, + 3944, + 3945, + 3946, + 3947, + 3948, + 3949, + 3950, + 3951, + 3952, + 3953, + 3954, + 3955, + 3956, + 3957, + 3958, + 3959, + 3960, + 3961, + 3962, + 3963, + 3964, + 3965, + 3966, + 3967, + 3968, + 3969, + 3970, + 3971, + 3972, + 3973, + 3974, + 3975, + 3976, + 3977, + 3978, + 3979, + 3980, + 3981, + 3982, + 3983, + 3984, + 3985, + 3986, + 3987, + 3988, + 3989, + 3990, + 3991, + 3992, + 3993, + 3994, + 3995, + 3996, + 3997, + 3998, + 3999, + 4000, + 4001, + 4002, + 4003, + 4004, + 4005, + 4006, + 4007, + 4008, + 4009, + 4010, + 4011, + 4012, + 4013, + 4014, + 4015, + 4016, + 4017, + 4018, + 4019, + 4020, + 4021, + 4022, + 4023, + 4024, + 4025, + 4026, + 4027, + 4028, + 4029, + 4030, + 4031, + 4032, + 4033, + 4034, + 4035, + 4036, + 4037, + 4038, + 4039, + 4040, + 4041, + 4042, + 4043, + 4044, + 4045, + 4046, + 4047, + 4048, + 4049, + 4050, + 4051, + 4052, + 4053, + 4054, + 4055, + 4056, + 4057, + 4058, + 4059, + 4060, + 4061, + 4062, + 4063, + 4064, + 4065, + 4066, + 4067, + 4068, + 4069, + 4070, + 4071, + 4072, + 4073, + 4074, + 4075, + 4076, + 4077, + 4078, + 4079, + 4080, + 4081, + 4082, + 4083, + 4084, + 4085, + 4086, + 4087, + 4088, + 4089, + 4090, + 4091, + 4092, + 4093, + 4094, + 4095, + 4096, + 4097, + 4098, + 4099, + 4100, + 4101, + 4102, + 4103, + 4104, + 4105, + 4106, + 4107, + 4108, + 4109, + 4110, + 4111, + 4112, + 4113, + 4114, + 4115, + 4116, + 4117, + 4118, + 4119, + 4120, + 4121, + 4122, + 4123, + 4124, + 4125, + 4126, + 4127, + 4128, + 4129, + 4130, + 4131, + 4132, + 4133, + 4134, + 4135, + 4136, + 4137, + 4138, + 4139, + 4140, + 4141, + 4142, + 4143, + 4144, + 4145, + 4146, + 4147, + 4148, + 4149, + 4150, + 4151, + 4152, + 4153, + 4154, + 4155, + 4156, + 4157, + 4158, + 4159, + 4160, + 4161, + 4162, + 4163, + 4164, + 4165, + 4166, + 4167, + 4168, + 4169, + 4170, + 4171, + 4172, + 4173, + 4174, + 4175, + 4176, + 4177, + 4178, + 4179, + 4180, + 4181, + 4182, + 4183, + 4184, + 4185, + 4186, + 4187, + 4188, + 4189, + 4190, + 4191, + 4192, + 4193, + 4194, + 4195, + 4196, + 4197, + 4198, + 4199, + 4200, + 4201, + 4202, + 4203, + 4204, + 4205, + 4206, + 4207, + 4208, + 4209, + 4210, + 4211, + 4212, + 4213, + 4214, + 4215, + 4216, + 4217, + 4218, + 4219, + 4220, + 4221, + 4222, + 4223, + 4224, + 4225, + 4226, + 4227, + 4228, + 4229, + 4230, + 4231, + 4232, + 4233, + 4234, + 4235, + 4236, + 4237, + 4238, + 4239, + 4240, + 4241, + 4242, + 4243, + 4244, + 4245, + 4246, + 4247, + 4248, + 4249, + 4250, + 4251, + 4252, + 4253, + 4254, + 4255, + 4256, + 4257, + 4258, + 4259, + 4260, + 4261, + 4262, + 4263, + 4264, + 4265, + 4266, + 4267, + 4268, + 4269, + 4270, + 4271, + 4272, + 4273, + 4274, + 4275, + 4276, + 4277, + 4278, + 4279, + 4280, + 4281, + 4282, + 4283, + 4284, + 4285, + 4286, + 4287, + 4288, + 4289, + 4290, + 4291, + 4292, + 4293, + 4294, + 4295, + 4296, + 4297, + 4298, + 4299, + 4300, + 4301, + 4302, + 4303, + 4304, + 4305, + 4306, + 4307, + 4308, + 4309, + 4310, + 4311, + 4312, + 4313, + 4314, + 4315, + 4316, + 4317, + 4318, + 4319, + 4320, + 4321, + 4322, + 4323, + 4324, + 4325, + 4326, + 4327, + 4328, + 4329, + 4330, + 4331, + 4332, + 4333, + 4334, + 4335, + 4336, + 4337, + 4338, + 4339, + 4340, + 4341, + 4342, + 4343, + 4344, + 4345, + 4346, + 4347, + 4348, + 4349, + 4350, + 4351, + 4352, + 4353, + 4354, + 4355, + 4356, + 4357, + 4358, + 4359, + 4360, + 4361, + 4362, + 4363, + 4364, + 4365, + 4366, + 4367, + 4368, + 4369, + 4370, + 4371, + 4372, + 4373, + 4374, + 4375, + 4376, + 4377, + 4378, + 4379, + 4380, + 4381, + 4382, + 4383, + 4384, + 4385, + 4386, + 4387, + 4388, + 4389, + 4390, + 4391, + 4392, + 4393, + 4394, + 4395, + 4396, + 4397, + 4398, + 4399, + 4400, + 4401, + 4402, + 4403, + 4404, + 4405, + 4406, + 4407, + 4408, + 4409, + 4410, + 4411, + 4412, + 4413, + 4414, + 4415, + 4416, + 4417, + 4418, + 4419, + 4420, + 4421, + 4422, + 4423, + 4424, + 4425, + 4426, + 4427, + 4428, + 4429, + 4430, + 4431, + 4432, + 4433, + 4434, + 4435, + 4436, + 4437, + 4438, + 4439, + 4440, + 4441, + 4442, + 4443, + 4444, + 4445, + 4446, + 4447, + 4448, + 4449, + 4450, + 4451, + 4452, + 4453, + 4454, + 4455, + 4456, + 4457, + 4458, + 4459, + 4460, + 4461, + 4462, + 4463, + 4464, + 4465, + 4466, + 4467, + 4468, + 4469, + 4470, + 4471, + 4472, + 4473, + 4474, + 4475, + 4476, + 4477, + 4478, + 4479, + 4480, + 4481, + 4482, + 4483, + 4484, + 4485, + 4486, + 4487, + 4488, + 4489, + 4490, + 4491, + 4492, + 4493, + 4494, + 4495, + 4496, + 4497, + 4498, + 4499, + 4500, + 4501, + 4502, + 4503, + 4504, + 4505, + 4506, + 4507, + 4508, + 4509, + 4510, + 4511, + 4512, + 4513, + 4514, + 4515, + 4516, + 4517, + 4518, + 4519, + 4520, + 4521, + 4522, + 4523, + 4524, + 4525, + 4526, + 4527, + 4528, + 4529, + 4530, + 4531, + 4532, + 4533, + 4534, + 4535, + 4536, + 4537, + 4538, + 4539, + 4540, + 4541, + 4542, + 4543, + 4544, + 4545, + 4546, + 4547, + 4548, + 4549, + 4550, + 4551, + 4552, + 4553, + 4554, + 4555, + 4556, + 4557, + 4558, + 4559, + 4560, + 4561, + 4562, + 4563, + 4564, + 4565, + 4566, + 4567, + 4568, + 4569, + 4570, + 4571, + 4572, + 4573, + 4574, + 4575, + 4576, + 4577, + 4578, + 4579, + 4580, + 4581, + 4582, + 4583, + 4584, + 4585, + 4586, + 4587, + 4588, + 4589, + 4590, + 4591, + 4592, + 4593, + 4594, + 4595, + 4596, + 4597, + 4598, + 4599, + 4600, + 4601, + 4602, + 4603, + 4604, + 4605, + 4606, + 4607, + 4608, + 4609, + 4610, + 4611, + 4612, + 4613, + 4614, + 4615, + 4616, + 4617, + 4618, + 4619, + 4620, + 4621, + 4622, + 4623, + 4624, + 4625, + 4626, + 4627, + 4628, + 4629, + 4630, + 4631, + 4632, + 4633, + 4634, + 4635, + 4636, + 4637, + 4638, + 4639, + 4640, + 4641, + 4642, + 4643, + 4644, + 4645, + 4646, + 4647, + 4648, + 4649, + 4650, + 4651, + 4652, + 4653, + 4654, + 4655, + 4656, + 4657, + 4658, + 4659, + 4660, + 4661, + 4662, + 4663, + 4664, + 4665, + 4666, + 4667, + 4668, + 4669, + 4670, + 4671, + 4672, + 4673, + 4674, + 4675, + 4676, + 4677, + 4678, + 4679, + 4680, + 4681, + 4682, + 4683, + 4684, + 4685, + 4686, + 4687, + 4688, + 4689, + 4690, + 4691, + 4692, + 4693, + 4694, + 4695, + 4696, + 4697, + 4698, + 4699, + 4700, + 4701, + 4702, + 4703, + 4704, + 4705, + 4706, + 4707, + 4708, + 4709, + 4710, + 4711, + 4712, + 4713, + 4714, + 4715, + 4716, + 4717, + 4718, + 4719, + 4720, + 4721, + 4722, + 4723, + 4724, + 4725, + 4726, + 4727, + 4728, + 4729, + 4730, + 4731, + 4732, + 4733, + 4734, + 4735, + 4736, + 4737, + 4738, + 4739, + 4740, + 4741, + 4742, + 4743, + 4744, + 4745, + 4746, + 4747, + 4748, + 4749, + 4750, + 4751, + 4752, + 4753, + 4754, + 4755, + 4756, + 4757, + 4758, + 4759, + 4760, + 4761, + 4762, + 4763, + 4764, + 4765, + 4766, + 4767, + 4768, + 4769, + 4770, + 4771, + 4772, + 4773, + 4774, + 4775, + 4776, + 4777, + 4778, + 4779, + 4780, + 4781, + 4782, + 4783, + 4784, + 4785, + 4786, + 4787, + 4788, + 4789, + 4790, + 4791, + 4792, + 4793, + 4794, + 4795, + 4796, + 4797, + 4798, + 4799, + 4800, + 4801, + 4802, + 4803, + 4804, + 4805, + 4806, + 4807, + 4808, + 4809, + 4810, + 4811, + 4812, + 4813, + 4814, + 4815, + 4816, + 4817, + 4818, + 4819, + 4820, + 4821, + 4822, + 4823, + 4824, + 4825, + 4826, + 4827, + 4828, + 4829, + 4830, + 4831, + 4832, + 4833, + 4834, + 4835, + 4836, + 4837, + 4838, + 4839, + 4840, + 4841, + 4842, + 4843, + 4844, + 4845, + 4846, + 4847, + 4848, + 4849, + 4850, + 4851, + 4852, + 4853, + 4854, + 4855, + 4856, + 4857, + 4858, + 4859, + 4860, + 4861, + 4862, + 4863, + 4864, + 4865, + 4866, + 4867, + 4868, + 4869, + 4870, + 4871, + 4872, + 4873, + 4874, + 4875, + 4876, + 4877, + 4878, + 4879, + 4880, + 4881, + 4882, + 4883, + 4884, + 4885, + 4886, + 4887, + 4888, + 4889, + 4890, + 4891, + 4892, + 4893, + 4894, + 4895, + 4896, + 4897, + 4898, + 4899, + 4900, + 4901, + 4902, + 4903, + 4904, + 4905, + 4906, + 4907, + 4908, + 4909, + 4910, + 4911, + 4912, + 4913, + 4914, + 4915, + 4916, + 4917, + 4918, + 4919, + 4920, + 4921, + 4922, + 4923, + 4924, + 4925, + 4926, + 4927, + 4928, + 4929, + 4930, + 4931, + 4932, + 4933, + 4934, + 4935, + 4936, + 4937, + 4938, + 4939, + 4940, + 4941, + 4942, + 4943, + 4944, + 4945, + 4946, + 4947, + 4948, + 4949, + 4950, + 4951, + 4952, + 4953, + 4954, + 4955, + 4956, + 4957, + 4958, + 4959, + 4960, + 4961, + 4962, + 4963, + 4964, + 4965, + 4966, + 4967, + 4968, + 4969, + 4970, + 4971, + 4972, + 4973, + 4974, + 4975, + 4976, + 4977, + 4978, + 4979, + 4980, + 4981, + 4982, + 4983, + 4984, + 4985, + 4986, + 4987, + 4988, + 4989, + 4990, + 4991, + 4992, + 4993, + 4994, + 4995, + 4996, + 4997, + 4998, + 4999, + 5000, + 5001, + 5002, + 5003, + 5004, + 5005, + 5006, + 5007, + 5008, + 5009, + 5010, + 5011, + 5012, + 5013, + 5014, + 5015, + 5016, + 5017, + 5018, + 5019, + 5020, + 5021, + 5022, + 5023, + 5024, + 5025, + 5026, + 5027, + 5028, + 5029, + 5030, + 5031, + 5032, + 5033, + 5034, + 5035, + 5036, + 5037, + 5038, + 5039, + 5040, + 5041, + 5042, + 5043, + 5044, + 5045, + 5046, + 5047, + 5048, + 5049, + 5050, + 5051, + 5052, + 5053, + 5054, + 5055, + 5056, + 5057, + 5058, + 5059, + 5060, + 5061, + 5062, + 5063, + 5064, + 5065, + 5066, + 5067, + 5068, + 5069, + 5070, + 5071, + 5072, + 5073, + 5074, + 5075, + 5076, + 5077, + 5078, + 5079, + 5080, + 5081, + 5082, + 5083, + 5084, + 5085, + 5086, + 5087, + 5088, + 5089, + 5090, + 5091, + 5092, + 5093, + 5094, + 5095, + 5096, + 5097, + 5098, + 5099, + 5100, + 5101, + 5102, + 5103, + 5104, + 5105, + 5106, + 5107, + 5108, + 5109, + 5110, + 5111, + 5112, + 5113, + 5114, + 5115, + 5116, + 5117, + 5118, + 5119, + 5120, + 5121, + 5122, + 5123, + 5124, + 5125, + 5126, + 5127, + 5128, + 5129, + 5130, + 5131, + 5132, + 5133, + 5134, + 5135, + 5136, + 5137, + 5138, + 5139, + 5140, + 5141, + 5142, + 5143, + 5144, + 5145, + 5146, + 5147, + 5148, + 5149, + 5150, + 5151, + 5152, + 5153, + 5154, + 5155, + 5156, + 5157, + 5158, + 5159, + 5160, + 5161, + 5162, + 5163, + 5164, + 5165, + 5166, + 5167, + 5168, + 5169, + 5170, + 5171, + 5172, + 5173, + 5174, + 5175, + 5176, + 5177, + 5178, + 5179, + 5180, + 5181, + 5182, + 5183, + 5184, + 5185, + 5186, + 5187, + 5188, + 5189, + 5190, + 5191, + 5192, + 5193, + 5194, + 5195, + 5196, + 5197, + 5198, + 5199, + 5200, + 5201, + 5202, + 5203, + 5204, + 5205, + 5206, + 5207, + 5208, + 5209, + 5210, + 5211, + 5212, + 5213, + 5214, + 5215, + 5216, + 5217, + 5218, + 5219, + 5220, + 5221, + 5222, + 5223, + 5224, + 5225, + 5226, + 5227, + 5228, + 5229, + 5230, + 5231, + 5232, + 5233, + 5234, + 5235, + 5236, + 5237, + 5238, + 5239, + 5240, + 5241, + 5242, + 5243, + 5244, + 5245, + 5246, + 5247, + 5248, + 5249, + 5250, + 5251, + 5252, + 5253, + 5254, + 5255, + 5256, + 5257, + 5258, + 5259, + 5260, + 5261, + 5262, + 5263, + 5264, + 5265, + 5266, + 5267, + 5268, + 5269, + 5270, + 5271, + 5272, + 5273, + 5274, + 5275, + 5276, + 5277, + 5278, + 5279, + 5280, + 5281, + 5282, + 5283, + 5284, + 5285, + 5286, + 5287, + 5288, + 5289, + 5290, + 5291, + 5292, + 5293, + 5294, + 5295, + 5296, + 5297, + 5298, + 5299, + 5300, + 5301, + 5302, + 5303, + 5304, + 5305, + 5306, + 5307, + 5308, + 5309, + 5310, + 5311, + 5312, + 5313, + 5314, + 5315, + 5316, + 5317, + 5318, + 5319, + 5320, + 5321, + 5322, + 5323, + 5324, + 5325, + 5326, + 5327, + 5328, + 5329, + 5330, + 5331, + 5332, + 5333, + 5334, + 5335, + 5336, + 5337, + 5338, + 5339, + 5340, + 5341, + 5342, + 5343, + 5344, + 5345, + 5346, + 5347, + 5348, + 5349, + 5350, + 5351, + 5352, + 5353, + 5354, + 5355, + 5356, + 5357, + 5358, + 5359, + 5360, + 5361, + 5362, + 5363, + 5364, + 5365, + 5366, + 5367, + 5368, + 5369, + 5370, + 5371, + 5372, + 5373, + 5374, + 5375, + 5376, + 5377, + 5378, + 5379, + 5380, + 5381, + 5382, + 5383, + 5384, + 5385, + 5386, + 5387, + 5388, + 5389, + 5390, + 5391, + 5392, + 5393, + 5394, + 5395, + 5396, + 5397, + 5398, + 5399, + 5400, + 5401, + 5402, + 5403, + 5404, + 5405, + 5406, + 5407, + 5408, + 5409, + 5410, + 5411, + 5412, + 5413, + 5414, + 5415, + 5416, + 5417, + 5418, + 5419, + 5420, + 5421, + 5422, + 5423, + 5424, + 5425, + 5426, + 5427, + 5428, + 5429, + 5430, + 5431, + 5432, + 5433, + 5434, + 5435, + 5436, + 5437, + 5438, + 5439, + 5440, + 5441, + 5442, + 5443, + 5444, + 5445, + 5446, + 5447, + 5448, + 5449, + 5450, + 5451, + 5452, + 5453, + 5454, + 5455, + 5456, + 5457, + 5458, + 5459, + 5460, + 5461, + 5462, + 5463, + 5464, + 5465, + 5466, + 5467, + 5468, + 5469, + 5470, + 5471, + 5472, + 5473, + 5474, + 5475, + 5476, + 5477, + 5478, + 5479, + 5480, + 5481, + 5482, + 5483, + 5484, + 5485, + 5486, + 5487, + 5488, + 5489, + 5490, + 5491, + 5492, + 5493, + 5494, + 5495, + 5496, + 5497, + 5498, + 5499, + 5500, + 5501, + 5502, + 5503, + 5504, + 5505, + 5506, + 5507, + 5508, + 5509, + 5510, + 5511, + 5512, + 5513, + 5514, + 5515, + 5516, + 5517, + 5518, + 5519, + 5520, + 5521, + 5522, + 5523, + 5524, + 5525, + 5526, + 5527, + 5528, + 5529, + 5530, + 5531, + 5532, + 5533, + 5534, + 5535, + 5536, + 5537, + 5538, + 5539, + 5540, + 5541, + 5542, + 5543, + 5544, + 5545, + 5546, + 5547, + 5548, + 5549, + 5550, + 5551, + 5552, + 5553, + 5554, + 5555, + 5556, + 5557, + 5558, + 5559, + 5560, + 5561, + 5562, + 5563, + 5564, + 5565, + 5566, + 5567, + 5568, + 5569, + 5570, + 5571, + 5572, + 5573, + 5574, + 5575, + 5576, + 5577, + 5578, + 5579, + 5580, + 5581, + 5582, + 5583, + 5584, + 5585, + 5586, + 5587, + 5588, + 5589, + 5590, + 5591, + 5592, + 5593, + 5594, + 5595, + 5596, + 5597, + 5598, + 5599, + 5600, + 5601, + 5602, + 5603, + 5604, + 5605, + 5606, + 5607, + 5608, + 5609, + 5610, + 5611, + 5612, + 5613, + 5614, + 5615, + 5616, + 5617, + 5618, + 5619, + 5620, + 5621, + 5622, + 5623, + 5624, + 5625, + 5626, + 5627, + 5628, + 5629, + 5630, + 5631, + 5632, + 5633, + 5634, + 5635, + 5636, + 5637, + 5638, + 5639, + 5640, + 5641, + 5642, + 5643, + 5644, + 5645, + 5646, + 5647, + 5648, + 5649, + 5650, + 5651, + 5652, + 5653, + 5654, + 5655, + 5656, + 5657, + 5658, + 5659, + 5660, + 5661, + 5662, + 5663, + 5664, + 5665, + 5666, + 5667, + 5668, + 5669, + 5670, + 5671, + 5672, + 5673, + 5674, + 5675, + 5676, + 5677, + 5678, + 5679, + 5680, + 5681, + 5682, + 5683, + 5684, + 5685, + 5686, + 5687, + 5688, + 5689, + 5690, + 5691, + 5692, + 5693, + 5694, + 5695, + 5696, + 5697, + 5698, + 5699, + 5700, + 5701, + 5702, + 5703, + 5704, + 5705, + 5706, + 5707, + 5708, + 5709, + 5710, + 5711, + 5712, + 5713, + 5714, + 5715, + 5716, + 5717, + 5718, + 5719, + 5720, + 5721, + 5722, + 5723, + 5724, + 5725, + 5726, + 5727, + 5728, + 5729, + 5730, + 5731, + 5732, + 5733, + 5734, + 5735, + 5736, + 5737, + 5738, + 5739, + 5740, + 5741, + 5742, + 5743, + 5744, + 5745, + 5746, + 5747, + 5748, + 5749, + 5750, + 5751, + 5752, + 5753, + 5754, + 5755, + 5756, + 5757, + 5758, + 5759, + 5760, + 5761, + 5762, + 5763, + 5764, + 5765, + 5766, + 5767, + 5768, + 5769, + 5770, + 5771, + 5772, + 5773, + 5774, + 5775, + 5776, + 5777, + 5778, + 5779, + 5780, + 5781, + 5782, + 5783, + 5784, + 5785, + 5786, + 5787, + 5788, + 5789, + 5790, + 5791, + 5792, + 5793, + 5794, + 5795, + 5796, + 5797, + 5798, + 5799, + 5800, + 5801, + 5802, + 5803, + 5804, + 5805, + 5806, + 5807, + 5808, + 5809, + 5810, + 5811, + 5812, + 5813, + 5814, + 5815, + 5816, + 5817, + 5818, + 5819, + 5820, + 5821, + 5822, + 5823, + 5824, + 5825, + 5826, + 5827, + 5828, + 5829, + 5830, + 5831, + 5832, + 5833, + 5834, + 5835, + 5836, + 5837, + 5838, + 5839, + 5840, + 5841, + 5842, + 5843, + 5844, + 5845, + 5846, + 5847, + 5848, + 5849, + 5850, + 5851, + 5852, + 5853, + 5854, + 5855, + 5856, + 5857, + 5858, + 5859, + 5860, + 5861, + 5862, + 5863, + 5864, + 5865, + 5866, + 5867, + 5868, + 5869, + 5870, + 5871, + 5872, + 5873, + 5874, + 5875, + 5876, + 5877, + 5878, + 5879, + 5880, + 5881, + 5882, + 5883, + 5884, + 5885, + 5886, + 5887, + 5888, + 5889, + 5890, + 5891, + 5892, + 5893, + 5894, + 5895, + 5896, + 5897, + 5898, + 5899, + 5900, + 5901, + 5902, + 5903, + 5904, + 5905, + 5906, + 5907, + 5908, + 5909, + 5910, + 5911, + 5912, + 5913, + 5914, + 5915, + 5916, + 5917, + 5918, + 5919, + 5920, + 5921, + 5922, + 5923, + 5924, + 5925, + 5926, + 5927, + 5928, + 5929, + 5930, + 5931, + 5932, + 5933, + 5934, + 5935, + 5936, + 5937, + 5938, + 5939, + 5940, + 5941, + 5942, + 5943, + 5944, + 5945, + 5946, + 5947, + 5948, + 5949, + 5950, + 5951, + 5952, + 5953, + 5954, + 5955, + 5956, + 5957, + 5958, + 5959, + 5960, + 5961, + 5962, + 5963, + 5964, + 5965, + 5966, + 5967, + 5968, + 5969, + 5970, + 5971, + 5972, + 5973, + 5974, + 5975, + 5976, + 5977, + 5978, + 5979, + 5980, + 5981, + 5982, + 5983, + 5984, + 5985, + 5986, + 5987, + 5988, + 5989, + 5990, + 5991, + 5992, + 5993, + 5994, + 5995, + 5996, + 5997, + 5998, + 5999, + 6000, + 6001, + 6002, + 6003, + 6004, + 6005, + 6006, + 6007, + 6008, + 6009, + 6010, + 6011, + 6012, + 6013, + 6014, + 6015, + 6016, + 6017, + 6018, + 6019, + 6020, + 6021, + 6022, + 6023, + 6024, + 6025, + 6026, + 6027, + 6028, + 6029, + 6030, + 6031, + 6032, + 6033, + 6034, + 6035, + 6036, + 6037, + 6038, + 6039, + 6040, + 6041, + 6042, + 6043, + 6044, + 6045, + 6046, + 6047, + 6048, + 6049, + 6050, + 6051, + 6052, + 6053, + 6054, + 6055, + 6056, + 6057, + 6058, + 6059, + 6060, + 6061, + 6062, + 6063, + 6064, + 6065, + 6066, + 6067, + 6068, + 6069, + 6070, + 6071, + 6072, + 6073, + 6074, + 6075, + 6076, + 6077, + 6078, + 6079, + 6080, + 6081, + 6082, + 6083, + 6084, + 6085, + 6086, + 6087, + 6088, + 6089, + 6090, + 6091, + 6092, + 6093, + 6094, + 6095, + 6096, + 6097, + 6098, + 6099, + 6100, + 6101, + 6102, + 6103, + 6104, + 6105, + 6106, + 6107, + 6108, + 6109, + 6110, + 6111, + 6112, + 6113, + 6114, + 6115, + 6116, + 6117, + 6118, + 6119, + 6120, + 6121, + 6122, + 6123, + 6124, + 6125, + 6126, + 6127, + 6128, + 6129, + 6130, + 6131, + 6132, + 6133, + 6134, + 6135, + 6136, + 6137, + 6138, + 6139, + 6140, + 6141, + 6142, + 6143, + 6144, + 6145, + 6146, + 6147, + 6148, + 6149, + 6150, + 6151, + 6152, + 6153, + 6154, + 6155, + 6156, + 6157, + 6158, + 6159, + 6160, + 6161, + 6162, + 6163, + 6164, + 6165, + 6166, + 6167, + 6168, + 6169, + 6170, + 6171, + 6172, + 6173, + 6174, + 6175, + 6176, + 6177, + 6178, + 6179, + 6180, + 6181, + 6182, + 6183, + 6184, + 6185, + 6186, + 6187, + 6188, + 6189, + 6190, + 6191, + 6192, + 6193, + 6194, + 6195, + 6196, + 6197, + 6198, + 6199, + 6200, + 6201, + 6202, + 6203, + 6204, + 6205, + 6206, + 6207, + 6208, + 6209, + 6210, + 6211, + 6212, + 6213, + 6214, + 6215, + 6216, + 6217, + 6218, + 6219, + 6220, + 6221, + 6222, + 6223, + 6224, + 6225, + 6226, + 6227, + 6228, + 6229, + 6230, + 6231, + 6232, + 6233, + 6234, + 6235, + 6236, + 6237, + 6238, + 6239, + 6240, + 6241, + 6242, + 6243, + 6244, + 6245, + 6246, + 6247, + 6248, + 6249, + 6250, + 6251, + 6252, + 6253, + 6254, + 6255, + 6256, + 6257, + 6258, + 6259, + 6260, + 6261, + 6262, + 6263, + 6264, + 6265, + 6266, + 6267, + 6268, + 6269, + 6270, + 6271, + 6272, + 6273, + 6274, + 6275, + 6276, + 6277, + 6278, + 6279, + 6280, + 6281, + 6282, + 6283, + 6284, + 6285, + 6286, + 6287, + 6288, + 6289, + 6290, + 6291, + 6292, + 6293, + 6294, + 6295, + 6296, + 6297, + 6298, + 6299, + 6300, + 6301, + 6302, + 6303, + 6304, + 6305, + 6306, + 6307, + 6308, + 6309, + 6310, + 6311, + 6312, + 6313, + 6314, + 6315, + 6316, + 6317, + 6318, + 6319, + 6320, + 6321, + 6322, + 6323, + 6324, + 6325, + 6326, + 6327, + 6328, + 6329, + 6330, + 6331, + 6332, + 6333, + 6334, + 6335, + 6336, + 6337, + 6338, + 6339, + 6340, + 6341, + 6342, + 6343, + 6344, + 6345, + 6346, + 6347, + 6348, + 6349, + 6350, + 6351, + 6352, + 6353, + 6354, + 6355, + 6356, + 6357, + 6358, + 6359, + 6360, + 6361, + 6362, + 6363, + 6364, + 6365, + 6366, + 6367, + 6368, + 6369, + 6370, + 6371, + 6372, + 6373, + 6374, + 6375, + 6376, + 6377, + 6378, + 6379, + 6380, + 6381, + 6382, + 6383, + 6384, + 6385, + 6386, + 6387, + 6388, + 6389, + 6390, + 6391, + 6392, + 6393, + 6394, + 6395, + 6396, + 6397, + 6398, + 6399, + 6400, + 6401, + 6402, + 6403, + 6404, + 6405, + 6406, + 6407, + 6408, + 6409, + 6410, + 6411, + 6412, + 6413, + 6414, + 6415, + 6416, + 6417, + 6418, + 6419, + 6420, + 6421, + 6422, + 6423, + 6424, + 6425, + 6426, + 6427, + 6428, + 6429, + 6430, + 6431, + 6432, + 6433, + 6434, + 6435, + 6436, + 6437, + 6438, + 6439, + 6440, + 6441, + 6442, + 6443, + 6444, + 6445, + 6446, + 6447, + 6448, + 6449, + 6450, + 6451, + 6452, + 6453, + 6454, + 6455, + 6456, + 6457, + 6458, + 6459, + 6460, + 6461, + 6462, + 6463, + 6464, + 6465, + 6466, + 6467, + 6468, + 6469, + 6470, + 6471, + 6472, + 6473, + 6474, + 6475, + 6476, + 6477, + 6478, + 6479, + 6480, + 6481, + 6482, + 6483, + 6484, + 6485, + 6486, + 6487, + 6488, + 6489, + 6490, + 6491, + 6492, + 6493, + 6494, + 6495, + 6496, + 6497, + 6498, + 6499, + 6500, + 6501, + 6502, + 6503, + 6504, + 6505, + 6506, + 6507, + 6508, + 6509, + 6510, + 6511, + 6512, + 6513, + 6514, + 6515, + 6516, + 6517, + 6518, + 6519, + 6520, + 6521, + 6522, + 6523, + 6524, + 6525, + 6526, + 6527, + 6528, + 6529, + 6530, + 6531, + 6532, + 6533, + 6534, + 6535, + 6536, + 6537, + 6538, + 6539, + 6540, + 6541, + 6542, + 6543, + 6544, + 6545, + 6546, + 6547, + 6548, + 6549, + 6550, + 6551, + 6552, + 6553, + 6554, + 6555, + 6556, + 6557, + 6558, + 6559, + 6560, + 6561, + 6562, + 6563, + 6564, + 6565, + 6566, + 6567, + 6568, + 6569, + 6570, + 6571, + 6572, + 6573, + 6574, + 6575, + 6576, + 6577, + 6578, + 6579, + 6580, + 6581, + 6582, + 6583, + 6584, + 6585, + 6586, + 6587, + 6588, + 6589, + 6590, + 6591, + 6592, + 6593, + 6594, + 6595, + 6596, + 6597, + 6598, + 6599, + 6600, + 6601, + 6602, + 6603, + 6604, + 6605, + 6606, + 6607, + 6608, + 6609, + 6610, + 6611, + 6612, + 6613, + 6614, + 6615, + 6616, + 6617, + 6618, + 6619, + 6620, + 6621, + 6622, + 6623, + 6624, + 6625, + 6626, + 6627, + 6628, + 6629, + 6630, + 6631, + 6632, + 6633, + 6634, + 6635, + 6636, + 6637, + 6638, + 6639, + 6640, + 6641, + 6642, + 6643, + 6644, + 6645, + 6646, + 6647, + 6648, + 6649, + 6650, + 6651, + 6652, + 6653, + 6654, + 6655, + 6656, + 6657, + 6658, + 6659, + 6660, + 6661, + 6662, + 6663, + 6664, + 6665, + 6666, + 6667, + 6668, + 6669, + 6670, + 6671, + 6672, + 6673, + 6674, + 6675, + 6676, + 6677, + 6678, + 6679, + 6680, + 6681, + 6682, + 6683, + 6684, + 6685, + 6686, + 6687, + 6688, + 6689, + 6690, + 6691, + 6692, + 6693, + 6694, + 6695, + 6696, + 6697, + 6698, + 6699, + 6700, + 6701, + 6702, + 6703, + 6704, + 6705, + 6706, + 6707, + 6708, + 6709, + 6710, + 6711, + 6712, + 6713, + 6714, + 6715, + 6716, + 6717, + 6718, + 6719, + 6720, + 6721, + 6722, + 6723, + 6724, + 6725, + 6726, + 6727, + 6728, + 6729, + 6730, + 6731, + 6732, + 6733, + 6734, + 6735, + 6736, + 6737, + 6738, + 6739, + 6740, + 6741, + 6742, + 6743, + 6744, + 6745, + 6746, + 6747, + 6748, + 6749, + 6750, + 6751, + 6752, + 6753, + 6754, + 6755, + 6756, + 6757, + 6758, + 6759, + 6760, + 6761, + 6762, + 6763, + 6764, + 6765, + 6766, + 6767, + 6768, + 6769, + 6770, + 6771, + 6772, + 6773, + 6774, + 6775, + 6776, + 6777, + 6778, + 6779, + 6780, + 6781, + 6782, + 6783, + 6784, + 6785, + 6786, + 6787, + 6788, + 6789, + 6790, + 6791, + 6792, + 6793, + 6794, + 6795, + 6796, + 6797, + 6798, + 6799, + 6800, + 6801, + 6802, + 6803, + 6804, + 6805, + 6806, + 6807, + 6808, + 6809, + 6810, + 6811, + 6812, + 6813, + 6814, + 6815, + 6816, + 6817, + 6818, + 6819, + 6820, + 6821, + 6822, + 6823, + 6824, + 6825, + 6826, + 6827, + 6828, + 6829, + 6830, + 6831, + 6832, + 6833, + 6834, + 6835, + 6836, + 6837, + 6838, + 6839, + 6840, + 6841, + 6842, + 6843, + 6844, + 6845, + 6846, + 6847, + 6848, + 6849, + 6850, + 6851, + 6852, + 6853, + 6854, + 6855, + 6856, + 6857, + 6858, + 6859, + 6860, + 6861, + 6862, + 6863, + 6864, + 6865, + 6866, + 6867, + 6868, + 6869, + 6870, + 6871, + 6872, + 6873, + 6874, + 6875, + 6876, + 6877, + 6878, + 6879, + 6880, + 6881, + 6882, + 6883, + 6884, + 6885, + 6886, + 6887, + 6888, + 6889, + 6890, + 6891, + 6892, + 6893, + 6894, + 6895, + 6896, + 6897, + 6898, + 6899, + 6900, + 6901, + 6902, + 6903, + 6904, + 6905, + 6906, + 6907, + 6908, + 6909, + 6910, + 6911, + 6912, + 6913, + 6914, + 6915, + 6916, + 6917, + 6918, + 6919, + 6920, + 6921, + 6922, + 6923, + 6924, + 6925, + 6926, + 6927, + 6928, + 6929, + 6930, + 6931, + 6932, + 6933, + 6934, + 6935, + 6936, + 6937, + 6938, + 6939, + 6940, + 6941, + 6942, + 6943, + 6944, + 6945, + 6946, + 6947, + 6948, + 6949, + 6950, + 6951, + 6952, + 6953, + 6954, + 6955, + 6956, + 6957, + 6958, + 6959, + 6960, + 6961, + 6962, + 6963, + 6964, + 6965, + 6966, + 6967, + 6968, + 6969, + 6970, + 6971, + 6972, + 6973, + 6974, + 6975, + 6976, + 6977, + 6978, + 6979, + 6980, + 6981, + 6982, + 6983, + 6984, + 6985, + 6986, + 6987, + 6988, + 6989, + 6990, + 6991, + 6992, + 6993, + 6994, + 6995, + 6996, + 6997, + 6998, + 6999, + 7000, + 7001, + 7002, + 7003, + 7004, + 7005, + 7006, + 7007, + 7008, + 7009, + 7010, + 7011, + 7012, + 7013, + 7014, + 7015, + 7016, + 7017, + 7018, + 7019, + 7020, + 7021, + 7022, + 7023, + 7024, + 7025, + 7026, + 7027, + 7028, + 7029, + 7030, + 7031, + 7032, + 7033, + 7034, + 7035, + 7036, + 7037, + 7038, + 7039, + 7040, + 7041, + 7042, + 7043, + 7044, + 7045, + 7046, + 7047, + 7048, + 7049, + 7050, + 7051, + 7052, + 7053, + 7054, + 7055, + 7056, + 7057, + 7058, + 7059, + 7060, + 7061, + 7062, + 7063, + 7064, + 7065, + 7066, + 7067, + 7068, + 7069, + 7070, + 7071, + 7072, + 7073, + 7074, + 7075, + 7076, + 7077, + 7078, + 7079, + 7080, + 7081, + 7082, + 7083, + 7084, + 7085, + 7086, + 7087, + 7088, + 7089, + 7090, + 7091, + 7092, + 7093, + 7094, + 7095, + 7096, + 7097, + 7098, + 7099, + 7100, + 7101, + 7102, + 7103, + 7104, + 7105, + 7106, + 7107, + 7108, + 7109, + 7110, + 7111, + 7112, + 7113, + 7114, + 7115, + 7116, + 7117, + 7118, + 7119, + 7120, + 7121, + 7122, + 7123, + 7124, + 7125, + 7126, + 7127, + 7128, + 7129, + 7130, + 7131, + 7132, + 7133, + 7134, + 7135, + 7136, + 7137, + 7138, + 7139, + 7140, + 7141, + 7142, + 7143, + 7144, + 7145, + 7146, + 7147, + 7148, + 7149, + 7150, + 7151, + 7152, + 7153, + 7154, + 7155, + 7156, + 7157, + 7158, + 7159, + 7160, + 7161, + 7162, + 7163, + 7164, + 7165, + 7166, + 7167, + 7168, + 7169, + 7170, + 7171, + 7172, + 7173, + 7174, + 7175, + 7176, + 7177, + 7178, + 7179, + 7180, + 7181, + 7182, + 7183, + 7184, + 7185, + 7186, + 7187, + 7188, + 7189, + 7190, + 7191, + 7192, + 7193, + 7194, + 7195, + 7196, + 7197, + 7198, + 7199, + 7200, + 7201, + 7202, + 7203, + 7204, + 7205, + 7206, + 7207, + 7208, + 7209, + 7210, + 7211, + 7212, + 7213, + 7214, + 7215, + 7216, + 7217, + 7218, + 7219, + 7220, + 7221, + 7222, + 7223, + 7224, + 7225, + 7226, + 7227, + 7228, + 7229, + 7230, + 7231, + 7232, + 7233, + 7234, + 7235, + 7236, + 7237, + 7238, + 7239, + 7240, + 7241, + 7242, + 7243, + 7244, + 7245, + 7246, + 7247, + 7248, + 7249, + 7250, + 7251, + 7252, + 7253, + 7254, + 7255, + 7256, + 7257, + 7258, + 7259, + 7260, + 7261, + 7262, + 7263, + 7264, + 7265, + 7266, + 7267, + 7268, + 7269, + 7270, + 7271, + 7272, + 7273, + 7274, + 7275, + 7276, + 7277, + 7278, + 7279, + 7280, + 7281, + 7282, + 7283, + 7284, + 7285, + 7286, + 7287, + 7288, + 7289, + 7290, + 7291, + 7292, + 7293, + 7294, + 7295, + 7296, + 7297, + 7298, + 7299, + 7300, + 7301, + 7302, + 7303, + 7304, + 7305, + 7306, + 7307, + 7308, + 7309, + 7310, + 7311, + 7312, + 7313, + 7314, + 7315, + 7316, + 7317, + 7318, + 7319, + 7320, + 7321, + 7322, + 7323, + 7324, + 7325, + 7326, + 7327, + 7328, + 7329, + 7330, + 7331, + 7332, + 7333, + 7334, + 7335, + 7336, + 7337, + 7338, + 7339, + 7340, + 7341, + 7342, + 7343, + 7344, + 7345, + 7346, + 7347, + 7348, + 7349, + 7350, + 7351, + 7352, + 7353, + 7354, + 7355, + 7356, + 7357, + 7358, + 7359, + 7360, + 7361, + 7362, + 7363, + 7364, + 7365, + 7366, + 7367, + 7368, + 7369, + 7370, + 7371, + 7372, + 7373, + 7374, + 7375, + 7376, + 7377, + 7378, + 7379, + 7380, + 7381, + 7382, + 7383, + 7384, + 7385, + 7386, + 7387, + 7388, + 7389, + 7390, + 7391, + 7392, + 7393, + 7394, + 7395, + 7396, + 7397, + 7398, + 7399, + 7400, + 7401, + 7402, + 7403, + 7404, + 7405, + 7406, + 7407, + 7408, + 7409, + 7410, + 7411, + 7412, + 7413, + 7414, + 7415, + 7416, + 7417, + 7418, + 7419, + 7420, + 7421, + 7422, + 7423, + 7424, + 7425, + 7426, + 7427, + 7428, + 7429, + 7430, + 7431, + 7432, + 7433, + 7434, + 7435, + 7436, + 7437, + 7438, + 7439, + 7440, + 7441, + 7442, + 7443, + 7444, + 7445, + 7446, + 7447, + 7448, + 7449, + 7450, + 7451, + 7452, + 7453, + 7454, + 7455, + 7456, + 7457, + 7458, + 7459, + 7460, + 7461, + 7462, + 7463, + 7464, + 7465, + 7466, + 7467, + 7468, + 7469, + 7470, + 7471, + 7472, + 7473, + 7474, + 7475, + 7476, + 7477, + 7478, + 7479, + 7480, + 7481, + 7482, + 7483, + 7484, + 7485, + 7486, + 7487, + 7488, + 7489, + 7490, + 7491, + 7492, + 7493, + 7494, + 7495, + 7496, + 7497, + 7498, + 7499, + 7500, + 7501, + 7502, + 7503, + 7504, + 7505, + 7506, + 7507, + 7508, + 7509, + 7510, + 7511, + 7512, + 7513, + 7514, + 7515, + 7516, + 7517, + 7518, + 7519, + 7520, + 7521, + 7522, + 7523, + 7524, + 7525, + 7526, + 7527, + 7528, + 7529, + 7530, + 7531, + 7532, + 7533, + 7534, + 7535, + 7536, + 7537, + 7538, + 7539, + 7540, + 7541, + 7542, + 7543, + 7544, + 7545, + 7546, + 7547, + 7548, + 7549, + 7550, + 7551, + 7552, + 7553, + 7554, + 7555, + 7556, + 7557, + 7558, + 7559, + 7560, + 7561, + 7562, + 7563, + 7564, + 7565, + 7566, + 7567, + 7568, + 7569, + 7570, + 7571, + 7572, + 7573, + 7574, + 7575, + 7576, + 7577, + 7578, + 7579, + 7580, + 7581, + 7582, + 7583, + 7584, + 7585, + 7586, + 7587, + 7588, + 7589, + 7590, + 7591, + 7592, + 7593, + 7594, + 7595, + 7596, + 7597, + 7598, + 7599, + 7600, + 7601, + 7602, + 7603, + 7604, + 7605, + 7606, + 7607, + 7608, + 7609, + 7610, + 7611, + 7612, + 7613, + 7614, + 7615, + 7616, + 7617, + 7618, + 7619, + 7620, + 7621, + 7622, + 7623, + 7624, + 7625, + 7626, + 7627, + 7628, + 7629, + 7630, + 7631, + 7632, + 7633, + 7634, + 7635, + 7636, + 7637, + 7638, + 7639, + 7640, + 7641, + 7642, + 7643, + 7644, + 7645, + 7646, + 7647, + 7648, + 7649, + 7650, + 7651, + 7652, + 7653, + 7654, + 7655, + 7656, + 7657, + 7658, + 7659, + 7660, + 7661, + 7662, + 7663, + 7664, + 7665, + 7666, + 7667, + 7668, + 7669, + 7670, + 7671, + 7672, + 7673, + 7674, + 7675, + 7676, + 7677, + 7678, + 7679, + 7680, + 7681, + 7682, + 7683, + 7684, + 7685, + 7686, + 7687, + 7688, + 7689, + 7690, + 7691, + 7692, + 7693, + 7694, + 7695, + 7696, + 7697, + 7698, + 7699, + 7700, + 7701, + 7702, + 7703, + 7704, + 7705, + 7706, + 7707, + 7708, + 7709, + 7710, + 7711, + 7712, + 7713, + 7714, + 7715, + 7716, + 7717, + 7718, + 7719, + 7720, + 7721, + 7722, + 7723, + 7724, + 7725, + 7726, + 7727, + 7728, + 7729, + 7730, + 7731, + 7732, + 7733, + 7734, + 7735, + 7736, + 7737, + 7738, + 7739, + 7740, + 7741, + 7742, + 7743, + 7744, + 7745, + 7746, + 7747, + 7748, + 7749, + 7750, + 7751, + 7752, + 7753, + 7754, + 7755, + 7756, + 7757, + 7758, + 7759, + 7760, + 7761, + 7762, + 7763, + 7764, + 7765, + 7766, + 7767, + 7768, + 7769, + 7770, + 7771, + 7772, + 7773, + 7774, + 7775, + 7776, + 7777, + 7778, + 7779, + 7780, + 7781, + 7782, + 7783, + 7784, + 7785, + 7786, + 7787, + 7788, + 7789, + 7790, + 7791, + 7792, + 7793, + 7794, + 7795, + 7796, + 7797, + 7798, + 7799, + 7800, + 7801, + 7802, + 7803, + 7804, + 7805, + 7806, + 7807, + 7808, + 7809, + 7810, + 7811, + 7812, + 7813, + 7814, + 7815, + 7816, + 7817, + 7818, + 7819, + 7820, + 7821, + 7822, + 7823, + 7824, + 7825, + 7826, + 7827, + 7828, + 7829, + 7830, + 7831, + 7832, + 7833, + 7834, + 7835, + 7836, + 7837, + 7838, + 7839, + 7840, + 7841, + 7842, + 7843, + 7844, + 7845, + 7846, + 7847, + 7848, + 7849, + 7850, + 7851, + 7852, + 7853, + 7854, + 7855, + 7856, + 7857, + 7858, + 7859, + 7860, + 7861, + 7862, + 7863, + 7864, + 7865, + 7866, + 7867, + 7868, + 7869, + 7870, + 7871, + 7872, + 7873, + 7874, + 7875, + 7876, + 7877, + 7878, + 7879, + 7880, + 7881, + 7882, + 7883, + 7884, + 7885, + 7886, + 7887, + 7888, + 7889, + 7890, + 7891, + 7892, + 7893, + 7894, + 7895, + 7896, + 7897, + 7898, + 7899, + 7900, + 7901, + 7902, + 7903, + 7904, + 7905, + 7906, + 7907, + 7908, + 7909, + 7910, + 7911, + 7912, + 7913, + 7914, + 7915, + 7916, + 7917, + 7918, + 7919, + 7920, + 7921, + 7922, + 7923, + 7924, + 7925, + 7926, + 7927, + 7928, + 7929, + 7930, + 7931, + 7932, + 7933, + 7934, + 7935, + 7936, + 7937, + 7938, + 7939, + 7940, + 7941, + 7942, + 7943, + 7944, + 7945, + 7946, + 7947, + 7948, + 7949, + 7950, + 7951, + 7952, + 7953, + 7954, + 7955, + 7956, + 7957, + 7958, + 7959, + 7960, + 7961, + 7962, + 7963, + 7964, + 7965, + 7966, + 7967, + 7968, + 7969, + 7970, + 7971, + 7972, + 7973, + 7974, + 7975, + 7976, + 7977, + 7978, + 7979, + 7980, + 7981, + 7982, + 7983, + 7984, + 7985, + 7986, + 7987, + 7988, + 7989, + 7990, + 7991, + 7992, + 7993, + 7994, + 7995, + 7996, + 7997, + 7998, + 7999, + 8000, + 8001, + 8002, + 8003, + 8004, + 8005, + 8006, + 8007, + 8008, + 8009, + 8010, + 8011, + 8012, + 8013, + 8014, + 8015, + 8016, + 8017, + 8018, + 8019, + 8020, + 8021, + 8022, + 8023, + 8024, + 8025, + 8026, + 8027, + 8028, + 8029, + 8030, + 8031, + 8032, + 8033, + 8034, + 8035, + 8036, + 8037, + 8038, + 8039, + 8040, + 8041, + 8042, + 8043, + 8044, + 8045, + 8046, + 8047, + 8048, + 8049, + 8050, + 8051, + 8052, + 8053, + 8054, + 8055, + 8056, + 8057, + 8058, + 8059, + 8060, + 8061, + 8062, + 8063, + 8064, + 8065, + 8066, + 8067, + 8068, + 8069, + 8070, + 8071, + 8072, + 8073, + 8074, + 8075, + 8076, + 8077, + 8078, + 8079, + 8080, + 8081, + 8082, + 8083, + 8084, + 8085, + 8086, + 8087, + 8088, + 8089, + 8090, + 8091, + 8092, + 8093, + 8094, + 8095, + 8096, + 8097, + 8098, + 8099, + 8100, + 8101, + 8102, + 8103, + 8104, + 8105, + 8106, + 8107, + 8108, + 8109, + 8110, + 8111, + 8112, + 8113, + 8114, + 8115, + 8116, + 8117, + 8118, + 8119, + 8120, + 8121, + 8122, + 8123, + 8124, + 8125, + 8126, + 8127, + 8128, + 8129, + 8130, + 8131, + 8132, + 8133, + 8134, + 8135, + 8136, + 8137, + 8138, + 8139, + 8140, + 8141, + 8142, + 8143, + 8144, + 8145, + 8146, + 8147, + 8148, + 8149, + 8150, + 8151, + 8152, + 8153, + 8154, + 8155, + 8156, + 8157, + 8158, + 8159, + 8160, + 8161, + 8162, + 8163, + 8164, + 8165, + 8166, + 8167, + 8168, + 8169, + 8170, + 8171, + 8172, + 8173, + 8174, + 8175, + 8176, + 8177, + 8178, + 8179, + 8180, + 8181, + 8182, + 8183, + 8184, + 8185, + 8186, + 8187, + 8188, + 8189, + 8190, + 8191, + 8192, + 8193, + 8194, + 8195, + 8196, + 8197, + 8198, + 8199, + 8200, + 8201, + 8202, + 8203, + 8204, + 8205, + 8206, + 8207, + 8208, + 8209, + 8210, + 8211, + 8212, + 8213, + 8214, + 8215, + 8216, + 8217, + 8218, + 8219, + 8220, + 8221, + 8222, + 8223, + 8224, + 8225, + 8226, + 8227, + 8228, + 8229, + 8230, + 8231, + 8232, + 8233, + 8234, + 8235, + 8236, + 8237, + 8238, + 8239, + 8240, + 8241, + 8242, + 8243, + 8244, + 8245, + 8246, + 8247, + 8248, + 8249, + 8250, + 8251, + 8252, + 8253, + 8254, + 8255, + 8256, + 8257, + 8258, + 8259, + 8260, + 8261, + 8262, + 8263, + 8264, + 8265, + 8266, + 8267, + 8268, + 8269, + 8270, + 8271, + 8272, + 8273, + 8274, + 8275, + 8276, + 8277, + 8278, + 8279, + 8280, + 8281, + 8282, + 8283, + 8284, + 8285, + 8286, + 8287, + 8288, + 8289, + 8290, + 8291, + 8292, + 8293, + 8294, + 8295, + 8296, + 8297, + 8298, + 8299, + 8300, + 8301, + 8302, + 8303, + 8304, + 8305, + 8306, + 8307, + 8308, + 8309, + 8310, + 8311, + 8312, + 8313, + 8314, + 8315, + 8316, + 8317, + 8318, + 8319, + 8320, + 8321, + 8322, + 8323, + 8324, + 8325, + 8326, + 8327, + 8328, + 8329, + 8330, + 8331, + 8332, + 8333, + 8334, + 8335, + 8336, + 8337, + 8338, + 8339, + 8340, + 8341, + 8342, + 8343, + 8344, + 8345, + 8346, + 8347, + 8348, + 8349, + 8350, + 8351, + 8352, + 8353, + 8354, + 8355, + 8356, + 8357, + 8358, + 8359, + 8360, + 8361, + 8362, + 8363, + 8364, + 8365, + 8366, + 8367, + 8368, + 8369, + 8370, + 8371, + 8372, + 8373, + 8374, + 8375, + 8376, + 8377, + 8378, + 8379, + 8380, + 8381, + 8382, + 8383, + 8384, + 8385, + 8386, + 8387, + 8388, + 8389, + 8390, + 8391, + 8392, + 8393, + 8394, + 8395, + 8396, + 8397, + 8398, + 8399, + 8400, + 8401, + 8402, + 8403, + 8404, + 8405, + 8406, + 8407, + 8408, + 8409, + 8410, + 8411, + 8412, + 8413, + 8414, + 8415, + 8416, + 8417, + 8418, + 8419, + 8420, + 8421, + 8422, + 8423, + 8424, + 8425, + 8426, + 8427, + 8428, + 8429, + 8430, + 8431, + 8432, + 8433, + 8434, + 8435, + 8436, + 8437, + 8438, + 8439, + 8440, + 8441, + 8442, + 8443, + 8444, + 8445, + 8446, + 8447, + 8448, + 8449, + 8450, + 8451, + 8452, + 8453, + 8454, + 8455, + 8456, + 8457, + 8458, + 8459, + 8460, + 8461, + 8462, + 8463, + 8464, + 8465, + 8466, + 8467, + 8468, + 8469, + 8470, + 8471, + 8472, + 8473, + 8474, + 8475, + 8476, + 8477, + 8478, + 8479, + 8480, + 8481, + 8482, + 8483, + 8484, + 8485, + 8486, + 8487, + 8488, + 8489, + 8490, + 8491, + 8492, + 8493, + 8494, + 8495, + 8496, + 8497, + 8498, + 8499, + 8500, + 8501, + 8502, + 8503, + 8504, + 8505, + 8506, + 8507, + 8508, + 8509, + 8510, + 8511, + 8512, + 8513, + 8514, + 8515, + 8516, + 8517, + 8518, + 8519, + 8520, + 8521, + 8522, + 8523, + 8524, + 8525, + 8526, + 8527, + 8528, + 8529, + 8530, + 8531, + 8532, + 8533, + 8534, + 8535, + 8536, + 8537, + 8538, + 8539, + 8540, + 8541, + 8542, + 8543, + 8544, + 8545, + 8546, + 8547, + 8548, + 8549, + 8550, + 8551, + 8552, + 8553, + 8554, + 8555, + 8556, + 8557, + 8558, + 8559, + 8560, + 8561, + 8562, + 8563, + 8564, + 8565, + 8566, + 8567, + 8568, + 8569, + 8570, + 8571, + 8572, + 8573, + 8574, + 8575, + 8576, + 8577, + 8578, + 8579, + 8580, + 8581, + 8582, + 8583, + 8584, + 8585, + 8586, + 8587, + 8588, + 8589, + 8590, + 8591, + 8592, + 8593, + 8594, + 8595, + 8596, + 8597, + 8598, + 8599, + 8600, + 8601, + 8602, + 8603, + 8604, + 8605, + 8606, + 8607, + 8608, + 8609, + 8610 + ], + "reason": "process stopped after the container memory limit was reached" +} \ No newline at end of file diff --git a/evidence/lab1-2/memory-experiment.png b/evidence/lab1-2/memory-experiment.png new file mode 100644 index 0000000000000000000000000000000000000000..84ac64d3ec49903adce18f757612b9dc0a192802 GIT binary patch literal 104191 zcmeFZcUO~X+c%1!IHHJM0l_xXi}Vhng3@~@pi)EVozO+GAfWW#As`T>C3H|nLklgC z00DwhLudk_m-o!f-1qam`;Wc$2iVtIvxG@VuAJpKe(lU#UG2xrOl(Yabac#WPaf&h z(J@Za(J{3B!3h4(Ut_JOz(2CyDyH5BZuZ`O&phquw4QmpJG*&1L!aODwe$3Xy19x8 ziQE&C7P#r??d|R*D=h5t-)9K9c{&JxvGC~uuX4)$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ev/null +++ b/evidence/lab1-2/memory-experiment.txt @@ -0,0 +1,8 @@ +$ python3 scripts/memory_experiment.py --image mtusi2026lab1-messenger:arm64 --memory 64m --max-messages 20000 --output evidence/memory-experiment.json --plot evidence/memory-experiment.png +memory_limit=64m +successful_messages=8610 +failed_requests=0 +OOMKilled=true +exit_code=137 +failure_time_seconds=5.9315 +plot=evidence/memory-experiment.png diff --git a/evidence/lab1-2/postgres/explain-analyze.txt b/evidence/lab1-2/postgres/explain-analyze.txt new file mode 100644 index 0000000..fbcb216 --- /dev/null +++ b/evidence/lab1-2/postgres/explain-analyze.txt @@ -0,0 +1,64 @@ +# EXPLAIN (ANALYZE, BUFFERS) + +## history_first_page + +Limit (cost=0.29..5.40 rows=51 width=73) (actual time=0.007..0.012 rows=51.00 loops=1) + Buffers: shared hit=4 + -> Index Scan using messages_chat_id_created_at_id_idx on messages (cost=0.29..1002.85 rows=10000 width=73) (actual time=0.006..0.009 rows=51.00 loops=1) + Index Cond: (chat_id = '01a0f77e-9381-736f-9a2b-af3b1e1e87fd'::uuid) + Index Searches: 1 + Buffers: shared hit=4 +Planning: + Buffers: shared hit=44 +Planning Time: 0.147 ms +Execution Time: 0.019 ms + +## history_next_page + +Limit (cost=0.29..7.71 rows=51 width=73) (actual time=0.004..0.010 rows=51.00 loops=1) + Buffers: shared hit=4 + -> Index Scan using messages_chat_id_created_at_id_idx on messages (cost=0.29..524.01 rows=3599 width=73) (actual time=0.004..0.008 rows=51.00 loops=1) + Index Cond: ((chat_id = '01a0f77e-9381-736f-9a2b-af3b1e1e87fd'::uuid) AND (ROW(created_at, id) > ROW('2026-10-01 11:44:23.146682+00'::timestamp with time zone, '00000000-0000-0000-0000-000000000000'::uuid))) + Index Searches: 1 + Buffers: shared hit=4 +Planning Time: 0.021 ms +Execution Time: 0.027 ms + +## chats_list_for_member + +Limit (cost=0.57..446.14 rows=51 width=70) (actual time=0.018..0.081 rows=51.00 loops=1) + Buffers: shared hit=309 + -> Nested Loop (cost=0.57..87375.78 rows=10001 width=70) (actual time=0.018..0.079 rows=51.00 loops=1) + Buffers: shared hit=309 + -> Index Scan using chats_created_at_id_idx on chats c (cost=0.29..554.24 rows=10001 width=38) (actual time=0.004..0.007 rows=51.00 loops=1) + Index Searches: 1 + Buffers: shared hit=3 + -> Index Only Scan using chat_members_user_id_chat_id_idx on chat_members visible (cost=0.29..0.36 rows=1 width=16) (actual time=0.001..0.001 rows=1.00 loops=51) + Index Cond: ((user_id = '01a0f77e-937a-7d1e-aacb-8909b9a65779'::uuid) AND (chat_id = c.id)) + Heap Fetches: 51 + Index Searches: 51 + Buffers: shared hit=153 + SubPlan 1 + -> Aggregate (cost=8.31..8.32 rows=1 width=32) (actual time=0.001..0.001 rows=1.00 loops=51) + Buffers: shared hit=153 + -> Index Only Scan using chat_members_pkey on chat_members m (cost=0.29..8.30 rows=1 width=16) (actual time=0.000..0.000 rows=1.00 loops=51) + Index Cond: (chat_id = c.id) + Heap Fetches: 51 + Index Searches: 51 + Buffers: shared hit=153 +Planning: + Buffers: shared hit=95 +Planning Time: 0.250 ms +Execution Time: 0.098 ms + +## user_by_username + +Index Scan using users_username_key on users (cost=0.29..8.30 rows=1 width=42) (actual time=0.005..0.005 rows=1.00 loops=1) + Index Cond: (username = 'bulk_5000'::text) + Index Searches: 1 + Buffers: shared hit=3 +Planning: + Buffers: shared hit=43 +Planning Time: 0.085 ms +Execution Time: 0.008 ms + diff --git a/evidence/lab1-2/quality.txt b/evidence/lab1-2/quality.txt new file mode 100644 index 0000000..300529d --- /dev/null +++ b/evidence/lab1-2/quality.txt @@ -0,0 +1,43 @@ +$ make check +env -u HTTP_PROXY -u HTTPS_PROXY -u ALL_PROXY -u http_proxy -u https_proxy -u all_proxy NO_PROXY=localhost,127.0.0.1,::1 no_proxy=localhost,127.0.0.1,::1 python3 scripts/check_contract.py +PASS: offline skeleton structure, local refs and Python syntax; application NOT tested. + +$ go vet ./... + +$ make lint +/Users/vladislav/Projects/mtusi2026lab1-fork/bin/golangci-lint run -v +level=info msg="golangci-lint has version 2.13.2 built with go1.27.0 from (unknown, modified: ?, mod sum: \"h1:bCyq3E4vo9qwzifjpzJqYndEt7Ncva80qkk8G2B4TXU=\") on (unknown)" +level=info msg="[config_reader] Config search paths: [./ /Users/vladislav/Projects/mtusi2026lab1-fork /Users/vladislav/Projects /Users/vladislav /Users /]" +level=info msg="[config_reader] Used config file .golangci.yml" +level=info msg="[config_reader] Module name \"mtusi-messenger\"" +level=info msg="[goenv] Read go env for 5.97475ms: map[string]string{\"GOCACHE\":\"/Users/vladislav/Library/Caches/go-build\", \"GOROOT\":\"/opt/homebrew/Cellar/go/1.27.1/libexec\"}" +level=info msg="[lintersdb] Active 50 linters: [asasalint bodyclose canonicalheader containedctx contextcheck copyloopvar depguard durationcheck errcheck errname errorlint exhaustive exptostd fatcontext forbidigo forcetypeassert gocheckcompilerdirectives gocritic gofumpt goimports gomoddirectives gosec govet ineffassign intrange makezero misspell musttag nilerr nilnil noctx nolintlint perfsprint prealloc reassign recvcheck revive rowserrcheck sloglint sqlclosecheck staticcheck testifylint thelper tparallel unconvert unparam unused usestdlibvars usetesting wastedassign]" +level=info msg="[loader] Using build tags: [integration]" +level=info msg="[loader] Go packages loading at mode 8767 (compiled_files|files|name|types_sizes|deps|exports_file|imports) took 122.006042ms" +level=info msg="[runner/filename_unadjuster] Pre-built 0 adjustments in 4.792166ms" +level=info msg="[linters_context/goanalysis] analyzers took 0s with no stages" +level=info msg="[runner/exclusion_rules] Skipped 2 issues by rules: [Path: \"_test\\\\.go\", Linters: \"gosec, prealloc, forcetypeassert, unparam\"]" +level=info msg="[runner] Issues before processing: 280, after processing: 0" +level=info msg="[runner] Processors filtering stat (in/out): exclusion_paths: 280/280, invalid_issue: 280/280, path_absoluter: 280/280, filename_unadjuster: 280/280, generated_file_filter: 280/100, exclusion_rules: 100/0, cgo: 280/280, path_relativity: 280/280" +level=info msg="[runner] processing took 607.916µs with stages: generated_file_filter: 420.959µs, exclusion_rules: 86.124µs, path_relativity: 83.917µs, sort_results: 4.458µs, invalid_issue: 4.292µs, cgo: 3.959µs, path_absoluter: 1.417µs, filename_unadjuster: 792ns, max_same_issues: 582ns, nolint_filter: 457ns, fixer: 292ns, exclusion_paths: 167ns, path_prettifier: 125ns, source_code: 125ns, path_shortener: 124ns, uniq_by_line: 42ns, severity-rules: 42ns, max_per_file_from_linter: 42ns, max_from_linter: 0s, diff: 0s" +level=info msg="[runner] linters took 422.737625ms with stages: goanalysis_metalinter: 422.101875ms" +0 issues. +level=info msg="File cache stats: 0 entries of total size 0B" +level=info msg="Memory: 7 samples, avg is 87.0MB, max is 111.2MB" +level=info msg="Execution took 555.972916ms" + +$ make unit-test +go test -race -shuffle=on -count=1 -timeout=5m ./... +? mtusi-messenger/cmd/messenger [no test files] +ok mtusi-messenger/internal/config 1.838s +ok mtusi-messenger/internal/domain 1.498s +ok mtusi-messenger/internal/logger 2.150s +ok mtusi-messenger/internal/service/chat 2.470s +? mtusi-messenger/internal/service/chat/mocks [no test files] +ok mtusi-messenger/internal/service/message 2.797s +? mtusi-messenger/internal/service/message/mocks [no test files] +ok mtusi-messenger/internal/service/user 3.474s +? mtusi-messenger/internal/service/user/mocks [no test files] +ok mtusi-messenger/internal/storage/memory 3.159s +ok mtusi-messenger/internal/transport/rest 3.863s +? mtusi-messenger/internal/transport/rest/oas [no test files] diff --git a/evidence/lab1-2/restart.txt b/evidence/lab1-2/restart.txt new file mode 100644 index 0000000..f695225 --- /dev/null +++ b/evidence/lab1-2/restart.txt @@ -0,0 +1,10 @@ +$ docker stop mtusi2026lab1-messenger-lab1 +$ docker run -d --name mtusi2026lab1-messenger-lab1 -p 127.0.0.1:8080:8080 mtusi2026lab1-messenger:verify +$ curl -i -H "X-User-Id: " http://127.0.0.1:8080/api/v1/users/me +HTTP/1.1 401 Unauthorized +Content-Type: application/json; charset=utf-8 +X-Request-Id: eadf9c21-d861-4c2c-8e76-46f086d27a11 +Date: Thu, 24 Sep 2026 20:13:02 GMT +Content-Length: 110 + +{"error":{"code":"unauthorized","message":"Unauthorized","request_id":"eadf9c21-d861-4c2c-8e76-46f086d27a11"}} \ No newline at end of file diff --git a/evidence/lab1-2/sigterm.txt b/evidence/lab1-2/sigterm.txt new file mode 100644 index 0000000..65cf8c6 --- /dev/null +++ b/evidence/lab1-2/sigterm.txt @@ -0,0 +1,7 @@ +$ docker kill --signal=TERM mtusi2026lab1-messenger-lab1 +$ docker wait mtusi2026lab1-messenger-lab1 +0 +elapsed_ms=114 +{"level":"info","time":"2026-09-24T20:14:19.192628563Z","msg":"server started","addr":"0.0.0.0:8080"} +{"level":"info","time":"2026-09-24T20:14:20.186231067Z","msg":"shutdown signal received","timeout":"10s"} +{"level":"info","time":"2026-09-24T20:14:20.188996621Z","msg":"server stopped"} diff --git a/evidence/lab1-2/track1-benchmark/baseline-storage-benchmark.txt b/evidence/lab1-2/track1-benchmark/baseline-storage-benchmark.txt new file mode 100644 index 0000000..2565d06 --- /dev/null +++ b/evidence/lab1-2/track1-benchmark/baseline-storage-benchmark.txt @@ -0,0 +1,21 @@ +goos: darwin +goarch: arm64 +pkg: mtusi-messenger/internal/storage/memory +cpu: Apple M5 Pro +BenchmarkMessageCreate/history=1000-18 3822346 309.5 ns/op 16 B/op 1 allocs/op +BenchmarkMessageCreate/history=1000-18 3904586 307.6 ns/op 16 B/op 1 allocs/op +BenchmarkMessageCreate/history=1000-18 3889698 308.1 ns/op 16 B/op 1 allocs/op +BenchmarkMessageCreate/history=1000-18 3892981 308.2 ns/op 16 B/op 1 allocs/op +BenchmarkMessageCreate/history=1000-18 3888345 308.3 ns/op 16 B/op 1 allocs/op +BenchmarkMessageCreate/history=10000-18 3578911 335.4 ns/op 16 B/op 1 allocs/op +BenchmarkMessageCreate/history=10000-18 3570348 335.9 ns/op 16 B/op 1 allocs/op +BenchmarkMessageCreate/history=10000-18 3581305 335.0 ns/op 16 B/op 1 allocs/op +BenchmarkMessageCreate/history=10000-18 3573933 336.0 ns/op 16 B/op 1 allocs/op +BenchmarkMessageCreate/history=10000-18 3563053 336.4 ns/op 16 B/op 1 allocs/op +BenchmarkMessageCreate/history=50000-18 3425475 349.8 ns/op 16 B/op 1 allocs/op +BenchmarkMessageCreate/history=50000-18 3435330 349.1 ns/op 16 B/op 1 allocs/op +BenchmarkMessageCreate/history=50000-18 3438290 349.3 ns/op 16 B/op 1 allocs/op +BenchmarkMessageCreate/history=50000-18 3420394 349.8 ns/op 16 B/op 1 allocs/op +BenchmarkMessageCreate/history=50000-18 3420736 350.1 ns/op 16 B/op 1 allocs/op +PASS +ok mtusi-messenger/internal/storage/memory 18.237s diff --git a/evidence/lab1-2/track1-benchmark/baseline.json b/evidence/lab1-2/track1-benchmark/baseline.json new file mode 100644 index 0000000..32d17da --- /dev/null +++ b/evidence/lab1-2/track1-benchmark/baseline.json @@ -0,0 +1,128 @@ +[ + { + "history": 100, + "concurrency": 1, + "duration_seconds": 2.002, + "successful_requests": 526, + "failed_requests": 0, + "rps": 262.791, + "p50_ms": 3.378, + "p95_ms": 4.12, + "p99_ms": 16.979, + "rss_min_kib": 18880, + "rss_max_kib": 22816, + "rss_delta_kib": 3936 + }, + { + "history": 100, + "concurrency": 4, + "duration_seconds": 2.002, + "successful_requests": 1450, + "failed_requests": 0, + "rps": 724.134, + "p50_ms": 4.18, + "p95_ms": 16.695, + "p99_ms": 21.604, + "rss_min_kib": 20512, + "rss_max_kib": 24208, + "rss_delta_kib": 3696 + }, + { + "history": 100, + "concurrency": 16, + "duration_seconds": 2.079, + "successful_requests": 2315, + "failed_requests": 0, + "rps": 1113.309, + "p50_ms": 8.563, + "p95_ms": 29.584, + "p99_ms": 93.023, + "rss_min_kib": 18880, + "rss_max_kib": 25296, + "rss_delta_kib": 6416 + }, + { + "history": 1000, + "concurrency": 1, + "duration_seconds": 2.007, + "successful_requests": 478, + "failed_requests": 0, + "rps": 238.14, + "p50_ms": 3.477, + "p95_ms": 10.892, + "p99_ms": 20.404, + "rss_min_kib": 23120, + "rss_max_kib": 23584, + "rss_delta_kib": 464 + }, + { + "history": 1000, + "concurrency": 4, + "duration_seconds": 2.003, + "successful_requests": 1380, + "failed_requests": 0, + "rps": 688.971, + "p50_ms": 4.197, + "p95_ms": 17.189, + "p99_ms": 28.458, + "rss_min_kib": 23344, + "rss_max_kib": 24592, + "rss_delta_kib": 1248 + }, + { + "history": 1000, + "concurrency": 16, + "duration_seconds": 2.005, + "successful_requests": 2298, + "failed_requests": 0, + "rps": 1146.063, + "p50_ms": 8.474, + "p95_ms": 29.384, + "p99_ms": 92.528, + "rss_min_kib": 23232, + "rss_max_kib": 26272, + "rss_delta_kib": 3040 + }, + { + "history": 5000, + "concurrency": 1, + "duration_seconds": 2.001, + "successful_requests": 494, + "failed_requests": 0, + "rps": 246.902, + "p50_ms": 3.414, + "p95_ms": 10.767, + "p99_ms": 18.996, + "rss_min_kib": 25248, + "rss_max_kib": 25296, + "rss_delta_kib": 48 + }, + { + "history": 5000, + "concurrency": 4, + "duration_seconds": 2.004, + "successful_requests": 1398, + "failed_requests": 0, + "rps": 697.712, + "p50_ms": 4.147, + "p95_ms": 17.142, + "p99_ms": 26.446, + "rss_min_kib": 24816, + "rss_max_kib": 25104, + "rss_delta_kib": 288 + }, + { + "history": 5000, + "concurrency": 16, + "duration_seconds": 2.006, + "successful_requests": 2261, + "failed_requests": 0, + "rps": 1126.862, + "p50_ms": 8.635, + "p95_ms": 24.133, + "p99_ms": 93.225, + "rss_min_kib": 25200, + "rss_max_kib": 26752, + "rss_delta_kib": 1552 + } +] diff --git a/evidence/lab1-2/track1-benchmark/comparison.json b/evidence/lab1-2/track1-benchmark/comparison.json new file mode 100644 index 0000000..2718ba4 --- /dev/null +++ b/evidence/lab1-2/track1-benchmark/comparison.json @@ -0,0 +1,110 @@ +[ + { + "history": 100, + "concurrency": 1, + "rps_before": 262.791, + "p95_ms_before": 4.12, + "p99_ms_before": 16.979, + "rss_max_kib_before": 22816, + "rps_after": 265.189, + "p95_ms_after": 4.276, + "p99_ms_after": 17.123, + "rss_max_kib_after": 22736 + }, + { + "history": 100, + "concurrency": 4, + "rps_before": 724.134, + "p95_ms_before": 16.695, + "p99_ms_before": 21.604, + "rss_max_kib_before": 24208, + "rps_after": 720.55, + "p95_ms_after": 16.868, + "p99_ms_after": 21.043, + "rss_max_kib_after": 24128 + }, + { + "history": 100, + "concurrency": 16, + "rps_before": 1113.309, + "p95_ms_before": 29.584, + "p99_ms_before": 93.023, + "rss_max_kib_before": 25296, + "rps_after": 1125.923, + "p95_ms_after": 29.142, + "p99_ms_after": 91.221, + "rss_max_kib_after": 25216 + }, + { + "history": 1000, + "concurrency": 1, + "rps_before": 238.14, + "p95_ms_before": 10.892, + "p99_ms_before": 20.404, + "rss_max_kib_before": 23584, + "rps_after": 237.68, + "p95_ms_after": 11.279, + "p99_ms_after": 19.675, + "rss_max_kib_after": 23504 + }, + { + "history": 1000, + "concurrency": 4, + "rps_before": 688.971, + "p95_ms_before": 17.189, + "p99_ms_before": 28.458, + "rss_max_kib_before": 24592, + "rps_after": 667.05, + "p95_ms_after": 17.243, + "p99_ms_after": 29.938, + "rss_max_kib_after": 25280 + }, + { + "history": 1000, + "concurrency": 16, + "rps_before": 1146.063, + "p95_ms_before": 29.384, + "p99_ms_before": 92.528, + "rss_max_kib_before": 26272, + "rps_after": 1102.581, + "p95_ms_after": 30.252, + "p99_ms_after": 93.912, + "rss_max_kib_after": 25200 + }, + { + "history": 5000, + "concurrency": 1, + "rps_before": 246.902, + "p95_ms_before": 10.767, + "p99_ms_before": 18.996, + "rss_max_kib_before": 25296, + "rps_after": 241.241, + "p95_ms_after": 10.897, + "p99_ms_after": 18.681, + "rss_max_kib_after": 25456 + }, + { + "history": 5000, + "concurrency": 4, + "rps_before": 697.712, + "p95_ms_before": 17.142, + "p99_ms_before": 26.446, + "rss_max_kib_before": 25104, + "rps_after": 685.839, + "p95_ms_after": 17.418, + "p99_ms_after": 26.618, + "rss_max_kib_after": 25376 + }, + { + "history": 5000, + "concurrency": 16, + "rps_before": 1126.862, + "p95_ms_before": 24.133, + "p99_ms_before": 93.225, + "rss_max_kib_before": 26752, + "rps_after": 1079.866, + "p95_ms_after": 31.525, + "p99_ms_after": 94.709, + "rss_max_kib_after": 26640 + } +] diff --git a/evidence/lab1-2/track1-benchmark/go-baseline/results.json b/evidence/lab1-2/track1-benchmark/go-baseline/results.json new file mode 100644 index 0000000..322933b --- /dev/null +++ b/evidence/lab1-2/track1-benchmark/go-baseline/results.json @@ -0,0 +1,211 @@ +{ + "mode": "baseline", + "command": [ + "go", + "run", + "-overlay", + "/var/folders/jd/nsgkfx9s75xb84909646j0zm0000gn/T/messenger-track1-58qai1az/overlay.json", + "./cmd/messenger" + ], + "go_version": "go version go1.27.1 darwin/arm64", + "os_arch": [ + "darwin", + "arm64" + ], + "requests_per_case": 100000, + "rss_source": "ps RSS of go run child executable, KiB; sampled every 100 ms", + "rows": [ + { + "history": 1000, + "concurrency": 1, + "duration_seconds": 13.634, + "requested_requests": 100000, + "warmup_requests": 100, + "successful_requests": 100000, + "failed_requests": 0, + "rps": 7334.409, + "p50_ms": 0.13, + "p95_ms": 0.146, + "p99_ms": 0.186, + "rss_min_kib": 23616, + "rss_max_kib": 59968, + "rss_delta_kib": 36352 + }, + { + "history": 1000, + "concurrency": 4, + "duration_seconds": 11.333, + "requested_requests": 100000, + "warmup_requests": 100, + "successful_requests": 100000, + "failed_requests": 0, + "rps": 8823.924, + "p50_ms": 0.42, + "p95_ms": 0.654, + "p99_ms": 0.869, + "rss_min_kib": 23424, + "rss_max_kib": 58464, + "rss_delta_kib": 35040 + }, + { + "history": 1000, + "concurrency": 16, + "duration_seconds": 13.63, + "requested_requests": 100000, + "warmup_requests": 100, + "successful_requests": 100000, + "failed_requests": 0, + "rps": 7336.995, + "p50_ms": 2.021, + "p95_ms": 3.514, + "p99_ms": 4.631, + "rss_min_kib": 23520, + "rss_max_kib": 66544, + "rss_delta_kib": 43024 + }, + { + "history": 1000, + "concurrency": 32, + "duration_seconds": 13.538, + "requested_requests": 100000, + "warmup_requests": 100, + "successful_requests": 100000, + "failed_requests": 0, + "rps": 7386.656, + "p50_ms": 4.022, + "p95_ms": 7.026, + "p99_ms": 8.953, + "rss_min_kib": 23856, + "rss_max_kib": 65616, + "rss_delta_kib": 41760 + }, + { + "history": 10000, + "concurrency": 1, + "duration_seconds": 14.008, + "requested_requests": 100000, + "warmup_requests": 100, + "successful_requests": 100000, + "failed_requests": 0, + "rps": 7138.887, + "p50_ms": 0.13, + "p95_ms": 0.149, + "p99_ms": 0.21, + "rss_min_kib": 25984, + "rss_max_kib": 70416, + "rss_delta_kib": 44432 + }, + { + "history": 10000, + "concurrency": 4, + "duration_seconds": 11.057, + "requested_requests": 100000, + "warmup_requests": 100, + "successful_requests": 100000, + "failed_requests": 0, + "rps": 9043.732, + "p50_ms": 0.406, + "p95_ms": 0.626, + "p99_ms": 0.841, + "rss_min_kib": 26272, + "rss_max_kib": 67376, + "rss_delta_kib": 41104 + }, + { + "history": 10000, + "concurrency": 16, + "duration_seconds": 13.436, + "requested_requests": 100000, + "warmup_requests": 100, + "successful_requests": 100000, + "failed_requests": 0, + "rps": 7442.895, + "p50_ms": 1.977, + "p95_ms": 3.485, + "p99_ms": 4.703, + "rss_min_kib": 26576, + "rss_max_kib": 75616, + "rss_delta_kib": 49040 + }, + { + "history": 10000, + "concurrency": 32, + "duration_seconds": 13.546, + "requested_requests": 100000, + "warmup_requests": 100, + "successful_requests": 100000, + "failed_requests": 0, + "rps": 7382.485, + "p50_ms": 4.01, + "p95_ms": 7.051, + "p99_ms": 9.096, + "rss_min_kib": 25456, + "rss_max_kib": 77792, + "rss_delta_kib": 52336 + }, + { + "history": 50000, + "concurrency": 1, + "duration_seconds": 13.969, + "requested_requests": 100000, + "warmup_requests": 100, + "successful_requests": 100000, + "failed_requests": 0, + "rps": 7158.653, + "p50_ms": 0.13, + "p95_ms": 0.149, + "p99_ms": 0.211, + "rss_min_kib": 40080, + "rss_max_kib": 81072, + "rss_delta_kib": 40992 + }, + { + "history": 50000, + "concurrency": 4, + "duration_seconds": 11.014, + "requested_requests": 100000, + "warmup_requests": 100, + "successful_requests": 100000, + "failed_requests": 0, + "rps": 9079.212, + "p50_ms": 0.404, + "p95_ms": 0.623, + "p99_ms": 0.823, + "rss_min_kib": 40448, + "rss_max_kib": 77088, + "rss_delta_kib": 36640 + }, + { + "history": 50000, + "concurrency": 16, + "duration_seconds": 13.479, + "requested_requests": 100000, + "warmup_requests": 100, + "successful_requests": 100000, + "failed_requests": 0, + "rps": 7419.068, + "p50_ms": 1.99, + "p95_ms": 3.471, + "p99_ms": 4.694, + "rss_min_kib": 42336, + "rss_max_kib": 79552, + "rss_delta_kib": 37216 + }, + { + "history": 50000, + "concurrency": 32, + "duration_seconds": 13.464, + "requested_requests": 100000, + "warmup_requests": 100, + "successful_requests": 100000, + "failed_requests": 0, + "rps": 7427.333, + "p50_ms": 3.99, + "p95_ms": 7.049, + "p99_ms": 9.007, + "rss_min_kib": 40336, + "rss_max_kib": 89552, + "rss_delta_kib": 49216 + } + ] +} diff --git a/evidence/lab1-2/track1-benchmark/go-comparison.json b/evidence/lab1-2/track1-benchmark/go-comparison.json new file mode 100644 index 0000000..de948fc --- /dev/null +++ b/evidence/lab1-2/track1-benchmark/go-comparison.json @@ -0,0 +1,266 @@ +[ + { + "history": 1000, + "concurrency": 1, + "requested_requests": 100000, + "warmup_requests": 100, + "duration_seconds_before": 13.634, + "duration_seconds_after": 13.919, + "successful_requests_before": 100000, + "successful_requests_after": 100000, + "failed_requests_before": 0, + "failed_requests_after": 0, + "rps_before": 7334.409, + "rps_after": 7184.594, + "p50_ms_before": 0.13, + "p50_ms_after": 0.129, + "p95_ms_before": 0.146, + "p95_ms_after": 0.15, + "p99_ms_before": 0.186, + "p99_ms_after": 0.231, + "rss_max_kib_before": 59968, + "rss_max_kib_after": 62048 + }, + { + "history": 1000, + "concurrency": 4, + "requested_requests": 100000, + "warmup_requests": 100, + "duration_seconds_before": 11.333, + "duration_seconds_after": 11.115, + "successful_requests_before": 100000, + "successful_requests_after": 100000, + "failed_requests_before": 0, + "failed_requests_after": 0, + "rps_before": 8823.924, + "rps_after": 8996.523, + "p50_ms_before": 0.42, + "p50_ms_after": 0.407, + "p95_ms_before": 0.654, + "p95_ms_after": 0.632, + "p99_ms_before": 0.869, + "p99_ms_after": 0.867, + "rss_max_kib_before": 58464, + "rss_max_kib_after": 61040 + }, + { + "history": 1000, + "concurrency": 16, + "requested_requests": 100000, + "warmup_requests": 100, + "duration_seconds_before": 13.63, + "duration_seconds_after": 13.364, + "successful_requests_before": 100000, + "successful_requests_after": 100000, + "failed_requests_before": 0, + "failed_requests_after": 0, + "rps_before": 7336.995, + "rps_after": 7482.719, + "p50_ms_before": 2.021, + "p50_ms_after": 1.977, + "p95_ms_before": 3.514, + "p95_ms_after": 3.445, + "p99_ms_before": 4.631, + "p99_ms_after": 4.577, + "rss_max_kib_before": 66544, + "rss_max_kib_after": 61328 + }, + { + "history": 1000, + "concurrency": 32, + "requested_requests": 100000, + "warmup_requests": 100, + "duration_seconds_before": 13.538, + "duration_seconds_after": 13.547, + "successful_requests_before": 100000, + "successful_requests_after": 100000, + "failed_requests_before": 0, + "failed_requests_after": 0, + "rps_before": 7386.656, + "rps_after": 7381.5, + "p50_ms_before": 4.022, + "p50_ms_after": 4.016, + "p95_ms_before": 7.026, + "p95_ms_after": 7.058, + "p99_ms_before": 8.953, + "p99_ms_after": 9.054, + "rss_max_kib_before": 65616, + "rss_max_kib_after": 68768 + }, + { + "history": 10000, + "concurrency": 1, + "requested_requests": 100000, + "warmup_requests": 100, + "duration_seconds_before": 14.008, + "duration_seconds_after": 13.984, + "successful_requests_before": 100000, + "successful_requests_after": 100000, + "failed_requests_before": 0, + "failed_requests_after": 0, + "rps_before": 7138.887, + "rps_after": 7150.931, + "p50_ms_before": 0.13, + "p50_ms_after": 0.131, + "p95_ms_before": 0.149, + "p95_ms_after": 0.146, + "p99_ms_before": 0.21, + "p99_ms_after": 0.187, + "rss_max_kib_before": 70416, + "rss_max_kib_after": 68128 + }, + { + "history": 10000, + "concurrency": 4, + "requested_requests": 100000, + "warmup_requests": 100, + "duration_seconds_before": 11.057, + "duration_seconds_after": 11.046, + "successful_requests_before": 100000, + "successful_requests_after": 100000, + "failed_requests_before": 0, + "failed_requests_after": 0, + "rps_before": 9043.732, + "rps_after": 9052.965, + "p50_ms_before": 0.406, + "p50_ms_after": 0.404, + "p95_ms_before": 0.626, + "p95_ms_after": 0.628, + "p99_ms_before": 0.841, + "p99_ms_after": 0.859, + "rss_max_kib_before": 67376, + "rss_max_kib_after": 71632 + }, + { + "history": 10000, + "concurrency": 16, + "requested_requests": 100000, + "warmup_requests": 100, + "duration_seconds_before": 13.436, + "duration_seconds_after": 13.439, + "successful_requests_before": 100000, + "successful_requests_after": 100000, + "failed_requests_before": 0, + "failed_requests_after": 0, + "rps_before": 7442.895, + "rps_after": 7440.817, + "p50_ms_before": 1.977, + "p50_ms_after": 1.989, + "p95_ms_before": 3.485, + "p95_ms_after": 3.468, + "p99_ms_before": 4.703, + "p99_ms_after": 4.701, + "rss_max_kib_before": 75616, + "rss_max_kib_after": 73712 + }, + { + "history": 10000, + "concurrency": 32, + "requested_requests": 100000, + "warmup_requests": 100, + "duration_seconds_before": 13.546, + "duration_seconds_after": 13.478, + "successful_requests_before": 100000, + "successful_requests_after": 100000, + "failed_requests_before": 0, + "failed_requests_after": 0, + "rps_before": 7382.485, + "rps_after": 7419.326, + "p50_ms_before": 4.01, + "p50_ms_after": 3.984, + "p95_ms_before": 7.051, + "p95_ms_after": 7.049, + "p99_ms_before": 9.096, + "p99_ms_after": 9.096, + "rss_max_kib_before": 77792, + "rss_max_kib_after": 70976 + }, + { + "history": 50000, + "concurrency": 1, + "requested_requests": 100000, + "warmup_requests": 100, + "duration_seconds_before": 13.969, + "duration_seconds_after": 13.863, + "successful_requests_before": 100000, + "successful_requests_after": 100000, + "failed_requests_before": 0, + "failed_requests_after": 0, + "rps_before": 7158.653, + "rps_after": 7213.61, + "p50_ms_before": 0.13, + "p50_ms_after": 0.129, + "p95_ms_before": 0.149, + "p95_ms_after": 0.145, + "p99_ms_before": 0.211, + "p99_ms_after": 0.191, + "rss_max_kib_before": 81072, + "rss_max_kib_after": 81824 + }, + { + "history": 50000, + "concurrency": 4, + "requested_requests": 100000, + "warmup_requests": 100, + "duration_seconds_before": 11.014, + "duration_seconds_after": 11.066, + "successful_requests_before": 100000, + "successful_requests_after": 100000, + "failed_requests_before": 0, + "failed_requests_after": 0, + "rps_before": 9079.212, + "rps_after": 9036.335, + "p50_ms_before": 0.404, + "p50_ms_after": 0.405, + "p95_ms_before": 0.623, + "p95_ms_after": 0.63, + "p99_ms_before": 0.823, + "p99_ms_after": 0.842, + "rss_max_kib_before": 77088, + "rss_max_kib_after": 86832 + }, + { + "history": 50000, + "concurrency": 16, + "requested_requests": 100000, + "warmup_requests": 100, + "duration_seconds_before": 13.479, + "duration_seconds_after": 13.416, + "successful_requests_before": 100000, + "successful_requests_after": 100000, + "failed_requests_before": 0, + "failed_requests_after": 0, + "rps_before": 7419.068, + "rps_after": 7453.53, + "p50_ms_before": 1.99, + "p50_ms_after": 1.978, + "p95_ms_before": 3.471, + "p95_ms_after": 3.455, + "p99_ms_before": 4.694, + "p99_ms_after": 4.688, + "rss_max_kib_before": 79552, + "rss_max_kib_after": 89824 + }, + { + "history": 50000, + "concurrency": 32, + "requested_requests": 100000, + "warmup_requests": 100, + "duration_seconds_before": 13.464, + "duration_seconds_after": 13.542, + "successful_requests_before": 100000, + "successful_requests_after": 100000, + "failed_requests_before": 0, + "failed_requests_after": 0, + "rps_before": 7427.333, + "rps_after": 7384.536, + "p50_ms_before": 3.99, + "p50_ms_after": 4.005, + "p95_ms_before": 7.049, + "p95_ms_after": 7.084, + "p99_ms_before": 9.007, + "p99_ms_after": 9.203, + "rss_max_kib_before": 89552, + "rss_max_kib_after": 80128 + } +] diff --git a/evidence/lab1-2/track1-benchmark/go-optimized/results.json b/evidence/lab1-2/track1-benchmark/go-optimized/results.json new file mode 100644 index 0000000..abd5f1c --- /dev/null +++ b/evidence/lab1-2/track1-benchmark/go-optimized/results.json @@ -0,0 +1,209 @@ +{ + "mode": "optimized", + "command": [ + "go", + "run", + "./cmd/messenger" + ], + "go_version": "go version go1.27.1 darwin/arm64", + "os_arch": [ + "darwin", + "arm64" + ], + "requests_per_case": 100000, + "rss_source": "ps RSS of go run child executable, KiB; sampled every 100 ms", + "rows": [ + { + "history": 1000, + "concurrency": 1, + "duration_seconds": 13.919, + "requested_requests": 100000, + "warmup_requests": 100, + "successful_requests": 100000, + "failed_requests": 0, + "rps": 7184.594, + "p50_ms": 0.129, + "p95_ms": 0.15, + "p99_ms": 0.231, + "rss_min_kib": 23504, + "rss_max_kib": 62048, + "rss_delta_kib": 38544 + }, + { + "history": 1000, + "concurrency": 4, + "duration_seconds": 11.115, + "requested_requests": 100000, + "warmup_requests": 100, + "successful_requests": 100000, + "failed_requests": 0, + "rps": 8996.523, + "p50_ms": 0.407, + "p95_ms": 0.632, + "p99_ms": 0.867, + "rss_min_kib": 23744, + "rss_max_kib": 61040, + "rss_delta_kib": 37296 + }, + { + "history": 1000, + "concurrency": 16, + "duration_seconds": 13.364, + "requested_requests": 100000, + "warmup_requests": 100, + "successful_requests": 100000, + "failed_requests": 0, + "rps": 7482.719, + "p50_ms": 1.977, + "p95_ms": 3.445, + "p99_ms": 4.577, + "rss_min_kib": 22480, + "rss_max_kib": 61328, + "rss_delta_kib": 38848 + }, + { + "history": 1000, + "concurrency": 32, + "duration_seconds": 13.547, + "requested_requests": 100000, + "warmup_requests": 100, + "successful_requests": 100000, + "failed_requests": 0, + "rps": 7381.5, + "p50_ms": 4.016, + "p95_ms": 7.058, + "p99_ms": 9.054, + "rss_min_kib": 23152, + "rss_max_kib": 68768, + "rss_delta_kib": 45616 + }, + { + "history": 10000, + "concurrency": 1, + "duration_seconds": 13.984, + "requested_requests": 100000, + "warmup_requests": 100, + "successful_requests": 100000, + "failed_requests": 0, + "rps": 7150.931, + "p50_ms": 0.131, + "p95_ms": 0.146, + "p99_ms": 0.187, + "rss_min_kib": 25936, + "rss_max_kib": 68128, + "rss_delta_kib": 42192 + }, + { + "history": 10000, + "concurrency": 4, + "duration_seconds": 11.046, + "requested_requests": 100000, + "warmup_requests": 100, + "successful_requests": 100000, + "failed_requests": 0, + "rps": 9052.965, + "p50_ms": 0.404, + "p95_ms": 0.628, + "p99_ms": 0.859, + "rss_min_kib": 26448, + "rss_max_kib": 71632, + "rss_delta_kib": 45184 + }, + { + "history": 10000, + "concurrency": 16, + "duration_seconds": 13.439, + "requested_requests": 100000, + "warmup_requests": 100, + "successful_requests": 100000, + "failed_requests": 0, + "rps": 7440.817, + "p50_ms": 1.989, + "p95_ms": 3.468, + "p99_ms": 4.701, + "rss_min_kib": 26480, + "rss_max_kib": 73712, + "rss_delta_kib": 47232 + }, + { + "history": 10000, + "concurrency": 32, + "duration_seconds": 13.478, + "requested_requests": 100000, + "warmup_requests": 100, + "successful_requests": 100000, + "failed_requests": 0, + "rps": 7419.326, + "p50_ms": 3.984, + "p95_ms": 7.049, + "p99_ms": 9.096, + "rss_min_kib": 26176, + "rss_max_kib": 70976, + "rss_delta_kib": 44800 + }, + { + "history": 50000, + "concurrency": 1, + "duration_seconds": 13.863, + "requested_requests": 100000, + "warmup_requests": 100, + "successful_requests": 100000, + "failed_requests": 0, + "rps": 7213.61, + "p50_ms": 0.129, + "p95_ms": 0.145, + "p99_ms": 0.191, + "rss_min_kib": 40592, + "rss_max_kib": 81824, + "rss_delta_kib": 41232 + }, + { + "history": 50000, + "concurrency": 4, + "duration_seconds": 11.066, + "requested_requests": 100000, + "warmup_requests": 100, + "successful_requests": 100000, + "failed_requests": 0, + "rps": 9036.335, + "p50_ms": 0.405, + "p95_ms": 0.63, + "p99_ms": 0.842, + "rss_min_kib": 42944, + "rss_max_kib": 86832, + "rss_delta_kib": 43888 + }, + { + "history": 50000, + "concurrency": 16, + "duration_seconds": 13.416, + "requested_requests": 100000, + "warmup_requests": 100, + "successful_requests": 100000, + "failed_requests": 0, + "rps": 7453.53, + "p50_ms": 1.978, + "p95_ms": 3.455, + "p99_ms": 4.688, + "rss_min_kib": 40768, + "rss_max_kib": 89824, + "rss_delta_kib": 49056 + }, + { + "history": 50000, + "concurrency": 32, + "duration_seconds": 13.542, + "requested_requests": 100000, + "warmup_requests": 100, + "successful_requests": 100000, + "failed_requests": 0, + "rps": 7384.536, + "p50_ms": 4.005, + "p95_ms": 7.084, + "p99_ms": 9.203, + "rss_min_kib": 42848, + "rss_max_kib": 80128, + "rss_delta_kib": 37280 + } + ] +} diff --git a/evidence/lab1-2/track1-benchmark/optimized-storage-benchmark.txt b/evidence/lab1-2/track1-benchmark/optimized-storage-benchmark.txt new file mode 100644 index 0000000..0122d9d --- /dev/null +++ b/evidence/lab1-2/track1-benchmark/optimized-storage-benchmark.txt @@ -0,0 +1,21 @@ +goos: darwin +goarch: arm64 +pkg: mtusi-messenger/internal/storage/memory +cpu: Apple M5 Pro +BenchmarkMessageCreate/history=1000-18 4830075 243.3 ns/op 16 B/op 1 allocs/op +BenchmarkMessageCreate/history=1000-18 4958697 241.4 ns/op 16 B/op 1 allocs/op +BenchmarkMessageCreate/history=1000-18 4984602 241.8 ns/op 16 B/op 1 allocs/op +BenchmarkMessageCreate/history=1000-18 4976372 241.8 ns/op 16 B/op 1 allocs/op +BenchmarkMessageCreate/history=1000-18 4962843 241.7 ns/op 16 B/op 1 allocs/op +BenchmarkMessageCreate/history=10000-18 4967149 241.8 ns/op 16 B/op 1 allocs/op +BenchmarkMessageCreate/history=10000-18 4946976 242.1 ns/op 16 B/op 1 allocs/op +BenchmarkMessageCreate/history=10000-18 4950400 242.3 ns/op 16 B/op 1 allocs/op +BenchmarkMessageCreate/history=10000-18 4938321 242.4 ns/op 16 B/op 1 allocs/op +BenchmarkMessageCreate/history=10000-18 4955269 242.2 ns/op 16 B/op 1 allocs/op +BenchmarkMessageCreate/history=50000-18 4943572 242.0 ns/op 16 B/op 1 allocs/op +BenchmarkMessageCreate/history=50000-18 4969927 242.4 ns/op 16 B/op 1 allocs/op +BenchmarkMessageCreate/history=50000-18 4931466 242.5 ns/op 16 B/op 1 allocs/op +BenchmarkMessageCreate/history=50000-18 4948990 242.8 ns/op 16 B/op 1 allocs/op +BenchmarkMessageCreate/history=50000-18 4953249 242.6 ns/op 16 B/op 1 allocs/op +PASS +ok mtusi-messenger/internal/storage/memory 18.240s diff --git a/evidence/lab1-2/track1-benchmark/optimized.json b/evidence/lab1-2/track1-benchmark/optimized.json new file mode 100644 index 0000000..973b960 --- /dev/null +++ b/evidence/lab1-2/track1-benchmark/optimized.json @@ -0,0 +1,128 @@ +[ + { + "history": 100, + "concurrency": 1, + "duration_seconds": 2.002, + "successful_requests": 531, + "failed_requests": 0, + "rps": 265.189, + "p50_ms": 3.355, + "p95_ms": 4.276, + "p99_ms": 17.123, + "rss_min_kib": 18800, + "rss_max_kib": 22736, + "rss_delta_kib": 3936 + }, + { + "history": 100, + "concurrency": 4, + "duration_seconds": 2.005, + "successful_requests": 1445, + "failed_requests": 0, + "rps": 720.55, + "p50_ms": 4.197, + "p95_ms": 16.868, + "p99_ms": 21.043, + "rss_min_kib": 20768, + "rss_max_kib": 24128, + "rss_delta_kib": 3360 + }, + { + "history": 100, + "concurrency": 16, + "duration_seconds": 2.012, + "successful_requests": 2265, + "failed_requests": 0, + "rps": 1125.923, + "p50_ms": 8.851, + "p95_ms": 29.142, + "p99_ms": 91.221, + "rss_min_kib": 20672, + "rss_max_kib": 25216, + "rss_delta_kib": 4544 + }, + { + "history": 1000, + "concurrency": 1, + "duration_seconds": 2.011, + "successful_requests": 478, + "failed_requests": 0, + "rps": 237.68, + "p50_ms": 3.467, + "p95_ms": 11.279, + "p99_ms": 19.675, + "rss_min_kib": 23264, + "rss_max_kib": 23504, + "rss_delta_kib": 240 + }, + { + "history": 1000, + "concurrency": 4, + "duration_seconds": 2.004, + "successful_requests": 1337, + "failed_requests": 0, + "rps": 667.05, + "p50_ms": 4.249, + "p95_ms": 17.243, + "p99_ms": 29.938, + "rss_min_kib": 23264, + "rss_max_kib": 25280, + "rss_delta_kib": 2016 + }, + { + "history": 1000, + "concurrency": 16, + "duration_seconds": 2.005, + "successful_requests": 2211, + "failed_requests": 0, + "rps": 1102.581, + "p50_ms": 8.818, + "p95_ms": 30.252, + "p99_ms": 93.912, + "rss_min_kib": 23424, + "rss_max_kib": 25200, + "rss_delta_kib": 1776 + }, + { + "history": 5000, + "concurrency": 1, + "duration_seconds": 2.002, + "successful_requests": 483, + "failed_requests": 0, + "rps": 241.241, + "p50_ms": 3.466, + "p95_ms": 10.897, + "p99_ms": 18.681, + "rss_min_kib": 25456, + "rss_max_kib": 25456, + "rss_delta_kib": 0 + }, + { + "history": 5000, + "concurrency": 4, + "duration_seconds": 2.003, + "successful_requests": 1374, + "failed_requests": 0, + "rps": 685.839, + "p50_ms": 4.207, + "p95_ms": 17.418, + "p99_ms": 26.618, + "rss_min_kib": 24304, + "rss_max_kib": 25376, + "rss_delta_kib": 1072 + }, + { + "history": 5000, + "concurrency": 16, + "duration_seconds": 2.002, + "successful_requests": 2162, + "failed_requests": 0, + "rps": 1079.866, + "p50_ms": 8.939, + "p95_ms": 31.525, + "p99_ms": 94.709, + "rss_min_kib": 24848, + "rss_max_kib": 26640, + "rss_delta_kib": 1792 + } +] diff --git a/evidence/lab4/README.md b/evidence/lab4/README.md new file mode 100644 index 0000000..d83321e --- /dev/null +++ b/evidence/lab4/README.md @@ -0,0 +1,30 @@ +# Lab4 evidence + +All files were produced on the local Compose stand (`docker compose up -d --build`) +with SeaweedFS 3.80, two API replicas and HAProxy. + +| File | Scenario | Command | +|---|---|---| +| `smoke.txt` | Public cumulative smoke (LAB=4) | `make test` | +| `negative.txt` | Size/format/filename/authz/limits | `make test-attachments` | +| `presign.txt` | Presigned upload happy path and negatives | `make test-presign` | +| `expiry.txt` | Expired presigned URL (TTL=3s) | `PRESIGN_EXPIRY_WAIT=4 make test-presign` | +| `failover.txt` | Upload, stop the serving replica, download via another | `python3 student-tests/attachment_failover.py` | +| `persistence.txt` | Restart the stand with volumes | `make test-persistence ACTION_SCRIPT=scripts/restart.sh` | +| `s3-init.txt` | Idempotent bucket bootstrap, app/forbidden prefix probes | `docker compose run --rm s3-init` (twice) | +| `private-bucket.txt` | Anonymous S3 GET and published ports | `docker compose exec seaweedfs wget ...` | +| `s3-outage.txt` | S3 down: attachments 503, other endpoints 200 | `docker compose stop seaweedfs` | +| `sweep.txt` | Abandoned presign cleanup after grace; ready survives | `S3_SWEEP_GRACE=2s S3_SWEEP_INTERVAL=1s S3_PRESIGN_TTL=1s` | +| `memory/` | 10 concurrent 9.4 MiB uploads, cgroup memory samples | `python3 scripts/lab4_memory_experiment.py` | +| `track1/` | Proxy vs presigned upload: traffic, latency, memory | `python3 scripts/lab4_track1.py` | + +Notes: + +- Credentials are synthetic local values from `infra/s3/s3.json`; `.env` is + ignored by git. +- `memory.current` includes page cache from temporary spool files; `anon` is + the primary RAM metric. +- Presigned completion re-reads the object once to verify SHA-256, so API RX + stays close to the file size. The client-facing LB leg is the actual saving. +- Presigned URLs sign `Content-Length`: an oversized PUT is rejected by S3 with 403 + before anything is stored. diff --git a/evidence/lab4/expiry.txt b/evidence/lab4/expiry.txt new file mode 100644 index 0000000..8c59364 --- /dev/null +++ b/evidence/lab4/expiry.txt @@ -0,0 +1,3 @@ +env -u HTTP_PROXY -u HTTPS_PROXY -u ALL_PROXY -u http_proxy -u https_proxy -u all_proxy NO_PROXY=localhost,127.0.0.1,::1 no_proxy=localhost,127.0.0.1,::1 python3 student-tests/presign_flow.py --base-url "http://localhost:8080" +EXPIRED: presigned URL rejected after 4.0 seconds +PASS: lab4 presigned upload flow diff --git a/evidence/lab4/failover.txt b/evidence/lab4/failover.txt new file mode 100644 index 0000000..0ff58fe --- /dev/null +++ b/evidence/lab4/failover.txt @@ -0,0 +1 @@ +PASS: lab4 attachment failover; served by 7fd3e5df907d diff --git a/evidence/lab4/memory/samples.csv b/evidence/lab4/memory/samples.csv new file mode 100644 index 0000000..ed28341 --- /dev/null +++ b/evidence/lab4/memory/samples.csv @@ -0,0 +1,7 @@ +elapsed,phase,anon,current +0.378,during,281362432,400949248 +0.804,during,281423872,381423616 +1.395,during,281542656,403361792 +1.827,during,281542656,371871744 +2.376,during,281632768,411824128 +2.81,during,281653248,381726720 diff --git a/evidence/lab4/memory/summary.txt b/evidence/lab4/memory/summary.txt new file mode 100644 index 0000000..5a33dda --- /dev/null +++ b/evidence/lab4/memory/summary.txt @@ -0,0 +1,11 @@ +Lab4 memory experiment +concurrency: 10 +file_size_bytes: 9454448 +uploads: 30 +rounds: 3 +elapsed_seconds: 2.980 +baseline_anon_bytes: 280317952 +peak_anon_bytes: 281653248 +anon_delta_bytes: 1335296 +peak_memory_current_bytes: 411824128 +note: memory.current includes page cache from temporary spool files; anon is the primary metric diff --git a/evidence/lab4/negative.txt b/evidence/lab4/negative.txt new file mode 100644 index 0000000..6f60999 --- /dev/null +++ b/evidence/lab4/negative.txt @@ -0,0 +1,14 @@ +env -u HTTP_PROXY -u HTTPS_PROXY -u ALL_PROXY -u http_proxy -u https_proxy -u all_proxy NO_PROXY=localhost,127.0.0.1,::1 no_proxy=localhost,127.0.0.1,::1 python3 student-tests/attachments_negative.py --base-url "http://localhost:8080" +10 MiB + 1 body: 413 +empty body: 415 +corrupt PNG (IDAT CRC): 415 +MIME spoof (PNG declared as JPEG): 415 +dangerous filenames: 400 +foreign attachment metadata/content: 404 +empty text without attachments: 400 +attachment from another chat: 404 +11 attachment ids: 400 +duplicate attachment ids: 400 +attachment-only message: 201 +anonymous direct S3 GET: 403 +PASS: lab4 attachment negative scenarios diff --git a/evidence/lab4/persistence.txt b/evidence/lab4/persistence.txt new file mode 100644 index 0000000..b15fbf1 --- /dev/null +++ b/evidence/lab4/persistence.txt @@ -0,0 +1,3 @@ +env -u HTTP_PROXY -u HTTPS_PROXY -u ALL_PROXY -u http_proxy -u https_proxy -u all_proxy NO_PROXY=localhost,127.0.0.1,::1 no_proxy=localhost,127.0.0.1,::1 python3 tests/resilience.py --mode persistence --action-script "scripts/restart.sh" --base-url "http://localhost:8080" +Executing explicit persistence hook; hook output suppressed to avoid leaking secrets. +PASS: persistence preserved confirmed data and existing session. Hook scope needs operator evidence. diff --git a/evidence/lab4/presign.txt b/evidence/lab4/presign.txt new file mode 100644 index 0000000..348242c --- /dev/null +++ b/evidence/lab4/presign.txt @@ -0,0 +1,10 @@ +env -u HTTP_PROXY -u HTTPS_PROXY -u ALL_PROXY -u http_proxy -u https_proxy -u all_proxy NO_PROXY=localhost,127.0.0.1,::1 no_proxy=localhost,127.0.0.1,::1 python3 student-tests/presign_flow.py --base-url "http://localhost:8080" +happy path: direct PUT 200, complete ready, checksum/size match +message with attachment downloaded as the second chat member +repeated complete is idempotent +foreign complete: 404 +complete before PUT: 409 +wrong completion checksum: 409 +oversized direct PUT: 403 from S3; complete: 409 (nothing stored) +same-size overwrite: last PUT wins, checksum verified +PASS: lab4 presigned upload flow diff --git a/evidence/lab4/private-bucket.txt b/evidence/lab4/private-bucket.txt new file mode 100644 index 0000000..af229e7 --- /dev/null +++ b/evidence/lab4/private-bucket.txt @@ -0,0 +1,10 @@ +=== anonymous GET === +wget: server returned error: HTTP/1.1 403 Forbidden +exit=1 +=== published ports === +api 8080/tcp +api 8080/tcp +lb 127.0.0.1:8404->8404/tcp, 127.0.0.1:8080->80/tcp +postgres 5432/tcp +redis 6379/tcp +seaweedfs 7333/tcp, 8080/tcp, 8888/tcp, 9333/tcp, 18080/tcp, 18888/tcp, 19333/tcp, 127.0.0.1:8333->8333/tcp diff --git a/evidence/lab4/s3-init.txt b/evidence/lab4/s3-init.txt new file mode 100644 index 0000000..f5d16ef --- /dev/null +++ b/evidence/lab4/s3-init.txt @@ -0,0 +1,14 @@ +=== run 1 === + Container mtusi-messenger-lab4-seaweedfs-1 Running + Container mtusi-messenger-lab4-seaweedfs-1 Waiting + Container mtusi-messenger-lab4-seaweedfs-1 Healthy + Container mtusi-messenger-lab4-s3-init-run-77217672cba1 Creating + Container mtusi-messenger-lab4-s3-init-run-77217672cba1 Created +{"time":"2026-10-21T20:24:44.714991263Z","level":"INFO","msg":"s3 bucket ready","endpoint":"http://seaweedfs:8333","bucket":"messenger-attachments"} +=== run 2 (idempotent) === + Container mtusi-messenger-lab4-seaweedfs-1 Running + Container mtusi-messenger-lab4-seaweedfs-1 Waiting + Container mtusi-messenger-lab4-seaweedfs-1 Healthy + Container mtusi-messenger-lab4-s3-init-run-33ccde88f9aa Creating + Container mtusi-messenger-lab4-s3-init-run-33ccde88f9aa Created +{"time":"2026-10-21T20:24:45.578062247Z","level":"INFO","msg":"s3 bucket ready","endpoint":"http://seaweedfs:8333","bucket":"messenger-attachments"} diff --git a/evidence/lab4/s3-outage.txt b/evidence/lab4/s3-outage.txt new file mode 100644 index 0000000..6526821 --- /dev/null +++ b/evidence/lab4/s3-outage.txt @@ -0,0 +1,8 @@ +created attachment before outage: 01a1601e-9947-753c-8085-65db29e8a909 +seaweedfs stopped +health/ready during outage: {'status': 'ok'} +chat list during outage: 200 +download during outage: 503 +upload during outage: 503 +seaweedfs restarted +upload after recovery: ready 01a1601f-1c45-793b-bb59-281781ea8482 diff --git a/evidence/lab4/smoke.txt b/evidence/lab4/smoke.txt new file mode 100644 index 0000000..1180c0c --- /dev/null +++ b/evidence/lab4/smoke.txt @@ -0,0 +1,2 @@ +env -u HTTP_PROXY -u HTTPS_PROXY -u ALL_PROXY -u http_proxy -u https_proxy -u all_proxy NO_PROXY=localhost,127.0.0.1,::1 no_proxy=localhost,127.0.0.1,::1 python3 tests/smoke.py --base-url "http://localhost:8080" +PASS: lab4 public API scenario; infrastructure and grading evidence remain separate. diff --git a/evidence/lab4/sweep.txt b/evidence/lab4/sweep.txt new file mode 100644 index 0000000..a5f8fe3 --- /dev/null +++ b/evidence/lab4/sweep.txt @@ -0,0 +1,4 @@ +ready attachment created: 01a16022-78dc-7349-b3da-2937b2faf1f0 +abandoned presign attachment: 01a16022-78e3-733f-861b-0443011dcfc8 (no PUT) +abandoned pending row removed after grace +ready attachment survived sweep: ready 99ea7533c441f79cd630d15ce4d58d1ec4e06f6f0efb3b77a5c088305cd1bd75 diff --git a/evidence/lab4/track1/results.csv b/evidence/lab4/track1/results.csv new file mode 100644 index 0000000..850470a --- /dev/null +++ b/evidence/lab4/track1/results.csv @@ -0,0 +1,21 @@ +size,bytes,flow,iteration,latency_s,lb_rx_bytes,lb_tx_bytes,api_rx_bytes,api_tx_bytes,api_anon_peak +~1MiB,1050888,proxy,0,0.2291,1058727,1075375,1074306,1059556,284934144 +~1MiB,1050888,proxy,1,0.2253,1058659,1058991,1060120,1061998,285270016 +~1MiB,1050888,proxy,2,0.2328,1058925,1059123,1058798,1059912,285433856 +~1MiB,1050888,proxy,3,0.227,1058485,1058633,1058297,1059591,285433856 +~1MiB,1050888,proxy,4,0.2284,1057165,1057115,1057126,1058104,285638656 +~1MiB,1050888,presign,0,0.2249,4098,3850,1058691,10486,285917184 +~1MiB,1050888,presign,1,0.2262,4163,3981,1058060,9274,286142464 +~1MiB,1050888,presign,2,0.2356,3548,3680,1057677,9240,286138368 +~1MiB,1050888,presign,3,0.2297,3482,3614,1058397,10146,286183424 +~1MiB,1050888,presign,4,0.2388,3482,3680,1057479,8382,286216192 +~9MiB,9454448,proxy,0,0.2374,9491811,9511561,9503858,9488878,286212096 +~9MiB,9454448,proxy,1,0.2397,9498015,9511259,9498331,9490528,286228480 +~9MiB,9454448,proxy,2,0.2247,9492207,9511759,9493573,9486286,286261248 +~9MiB,9454448,proxy,3,0.2273,9486399,9496645,9483662,9481323,286285824 +~9MiB,9454448,proxy,4,0.237,9483275,9494891,9493892,9482709,286285824 +~9MiB,9454448,presign,0,0.2431,4098,3916,9473045,12060,286306304 +~9MiB,9454448,presign,1,0.246,3552,3680,9472208,9451,286318592 +~9MiB,9454448,presign,2,0.2347,4164,3982,9473447,11088,286326784 +~9MiB,9454448,presign,3,0.2346,3482,3614,9471731,9174,286343168 +~9MiB,9454448,presign,4,0.2389,4098,3916,9473771,14040,286367744 diff --git a/evidence/lab4/track1/summary.txt b/evidence/lab4/track1/summary.txt new file mode 100644 index 0000000..0ee049d --- /dev/null +++ b/evidence/lab4/track1/summary.txt @@ -0,0 +1,12 @@ +Lab4 track 1: proxy vs presigned upload + +| size | flow | median latency, s | p95 latency, s | LB rx, bytes | API rx, bytes | API anon peak, bytes | +|---|---|---:|---:|---:|---:|---:| +| ~1MiB | proxy | 0.228 | 0.233 | 1058392 | 1061729 | 285638656 | +| ~1MiB | presign | 0.230 | 0.239 | 3755 | 1058061 | 286216192 | +| ~9MiB | proxy | 0.237 | 0.240 | 9490341 | 9494663 | 286285824 | +| ~9MiB | presign | 0.239 | 0.246 | 3879 | 9472840 | 286367744 | + +Note: presigned upload keeps the file body off the API request path and off the load balancer. +Completion still streams the object from S3 once to verify its SHA-256, so api_rx stays close to +the file size; the saving is in the client-facing LB leg and in not accepting/buffering the body. diff --git a/evidence/lab5/README.md b/evidence/lab5/README.md new file mode 100644 index 0000000..3411cae --- /dev/null +++ b/evidence/lab5/README.md @@ -0,0 +1,20 @@ +# Lab5 evidence + +All artifacts were produced against the local Compose stand on 2026-10-30 +(2 vCPU, 2 GiB Docker VM, RabbitMQ 4.3.7, PostgreSQL 18, SeaweedFS 3.80). + +- `stand.txt` — containers, image versions, VM limits. +- `smoke.txt` — public `make test`. +- `async.txt` — worker down/restart, broker restart with volume, stack restart. +- `variants.txt` — thumbnail/crop/optimized metadata, bytes, dimensions. +- `faults.txt` — permanent/transient retry, DLQ/replay, crash before/after + side effect, crash before/after ack, outbox gap, lease takeover. +- `persistence.txt`, `failover.txt`, `idempotency.txt`, `lb-readiness.txt` — + cumulative lab2–lab4 regressions. +- `track2/run.txt`, `track2/runs.csv`, `track2/summary.md` — track 2 + duplicate/stale/version harness (3 repetitions). +- `unit-test.txt`, `integration-test.txt`, `vet.txt`, `lint.txt`, + `validate.txt` — build/quality gates. + +No `.env`, tokens, credentials or presigned URLs are stored here. Raw SQL rows +contain only synthetic IDs and metadata. diff --git a/evidence/lab5/async.txt b/evidence/lab5/async.txt new file mode 100644 index 0000000..7e1a791 --- /dev/null +++ b/evidence/lab5/async.txt @@ -0,0 +1,12 @@ +# make test-queue 2026-10-31T11:26:40Z +env -u HTTP_PROXY -u HTTPS_PROXY -u ALL_PROXY -u http_proxy -u https_proxy -u all_proxy NO_PROXY=localhost,127.0.0.1,::1 no_proxy=localhost,127.0.0.1,::1 python3 student-tests/lab5_async.py --base-url "http://localhost:8080" +worker down: 202 queued, content 409, queued attachment linked, API restarted +worker restarted: ready, thumbnail and original downloadable, staging cleared +broker down: upload accepted into outbox +broker + relay recovered: queued job reached ready +stack restart: ready attachment and original preserved +worker down: reprocess pipeline 2 accepted, v1 audit event recorded, upload still queued +worker up: reprocessed upload reached ready at pipeline 2, v1 superseded +worker down: reprocess pipeline 3 refused, v1 job untouched +worker up: preserved upload reached ready at pipeline 1 +PASS: lab5 async worker/broker durability diff --git a/evidence/lab5/attachments-negative.txt b/evidence/lab5/attachments-negative.txt new file mode 100644 index 0000000..a2a255d --- /dev/null +++ b/evidence/lab5/attachments-negative.txt @@ -0,0 +1,25 @@ +# make test-attachments 2026-10-31T11:26:14Z +env -u HTTP_PROXY -u HTTPS_PROXY -u ALL_PROXY -u http_proxy -u https_proxy -u all_proxy NO_PROXY=localhost,127.0.0.1,::1 no_proxy=localhost,127.0.0.1,::1 python3 student-tests/attachments_negative.py --base-url "http://localhost:8080" +10 MiB + 1 body: 413 +empty body: 415 +corrupt PNG (IDAT CRC): 415 +MIME spoof (PNG declared as JPEG): 415 +structurally valid PNG with non-zlib IDAT: 415 +valid zlib, empty PNG raster: 415 +valid zlib, invalid PNG scanline filter: 415 +invalid PNG color type/bit depth pair: 415 +duplicate PNG IHDR: 415 +trailing bytes after PNG zlib stream: 415 +tRNS on RGBA PNG: 415 +short tRNS on RGB PNG: 415 +PLTE entries exceed palette bit depth: 415 +palette tRNS exceeds PLTE entries: 415 +dangerous filenames: 400 +foreign attachment metadata/content: 404 +empty text without attachments: 400 +attachment from another chat: 404 +11 attachment ids: 400 +duplicate attachment ids: 400 +attachment-only message: 201 +anonymous direct S3 GET: 403 +PASS: lab4 attachment negative scenarios diff --git a/evidence/lab5/db-state.txt b/evidence/lab5/db-state.txt new file mode 100644 index 0000000..c1126aa --- /dev/null +++ b/evidence/lab5/db-state.txt @@ -0,0 +1,29 @@ +# db state 2026-10-30T20:16:08Z + status | count +---------+------- + failed | 2 + pending | 4 + ready | 31 +(3 rows) + + status | count +--------+------- + failed | 2 + ready | 34 +(2 rows) + + variants +---------- + 102 +(1 row) + + unpublished | outbox +-------------+-------- + 0 | 58 +(1 row) + +Timeout: 60.0 seconds ... +Listing queues for vhost messenger ... +name messages messages_ready messages_unacknowledged consumers +attachment.process.dead 4 4 0 0 +attachment.process.v1 0 0 0 0 diff --git a/evidence/lab5/failover.txt b/evidence/lab5/failover.txt new file mode 100644 index 0000000..2ec4623 --- /dev/null +++ b/evidence/lab5/failover.txt @@ -0,0 +1,5 @@ +# failover 2026-10-30T20:11:43Z +env -u HTTP_PROXY -u HTTPS_PROXY -u ALL_PROXY -u http_proxy -u https_proxy -u all_proxy NO_PROXY=localhost,127.0.0.1,::1 no_proxy=localhost,127.0.0.1,::1 python3 tests/resilience.py --mode failover --action-script "scripts/stop-one.sh" --base-url "http://localhost:8080" +Executing explicit failover hook; hook output suppressed to avoid leaking secrets. +{"observed_instances_before": 2, "successful_writes": 99, "failed_attempts": 0, "first_recovery_seconds": 0.221} +PASS: failover preserved confirmed data and existing session. Hook scope needs operator evidence. diff --git a/evidence/lab5/faults.txt b/evidence/lab5/faults.txt new file mode 100644 index 0000000..4be57ec --- /dev/null +++ b/evidence/lab5/faults.txt @@ -0,0 +1,15 @@ +# make test-faults 2026-10-31T11:27:03Z +env -u HTTP_PROXY -u HTTPS_PROXY -u ALL_PROXY -u http_proxy -u https_proxy -u all_proxy NO_PROXY=localhost,127.0.0.1,::1 no_proxy=localhost,127.0.0.1,::1 python3 student-tests/lab5_faults.py --base-url "http://localhost:8080" +permanent failure: failed/injected_failure, content 409, failed attachment not linkable, registry visible +replay: failed -> queued -> ready, one thumbnail +replay ready job: refused +replay older failed version while v2 queued: refused, state intact +v2 published after older replay refusal +replay of failed reprocess: queued projection restored, then ready at pipeline 2 +transient exhaustion: attempts=5, retry_exhausted, four retries, DLQ message present +crash after first variant: redelivered, same three variants, attempts=2 +crash after commit before ack: ready remains, redelivery is a no-op +crash after claim before side effect: requeued, attempts=2, ready +outbox gap: crash before publish recovered through the relay, outbox published, ready +lease expiry: paused worker, reaper requeued, stale attempt fenced, ready +PASS: lab5 level 4 fault injection diff --git a/evidence/lab5/idempotency.txt b/evidence/lab5/idempotency.txt new file mode 100644 index 0000000..03f99f4 --- /dev/null +++ b/evidence/lab5/idempotency.txt @@ -0,0 +1,4 @@ +# idempotency 2026-10-30T20:11:43Z +env -u HTTP_PROXY -u HTTPS_PROXY -u ALL_PROXY -u http_proxy -u https_proxy -u all_proxy NO_PROXY=localhost,127.0.0.1,::1 no_proxy=localhost,127.0.0.1,::1 python3 student-tests/idempotency_parallel.py --base-url "http://localhost:8080" +{"replay": {"workers": 12, "instances": ["1c67613c89f2", "ee96975adb44"], "message_id": "01a18e70-8fcd-7519-91ab-d9c43b6a5f37"}, "conflict": {"workers": 12, "accepted": 1, "conflicts": 11}, "stable_body": {"message_id": "01a18e70-8ff9-759f-ab87-abd58f58c59d"}, "key_required": {"status": 400}} +PASS: параллельный повтор с одним Idempotency-Key создаёт ровно одно сообщение diff --git a/evidence/lab5/integration-test.txt b/evidence/lab5/integration-test.txt new file mode 100644 index 0000000..08905b2 --- /dev/null +++ b/evidence/lab5/integration-test.txt @@ -0,0 +1,2 @@ +ok mtusi-messenger/internal/storage/postgres 9.448s +ok mtusi-messenger/internal/storage/redis 1.238s diff --git a/evidence/lab5/lb-readiness-detail.txt b/evidence/lab5/lb-readiness-detail.txt new file mode 100644 index 0000000..eeb57ae --- /dev/null +++ b/evidence/lab5/lb-readiness-detail.txt @@ -0,0 +1,31 @@ +# LB excludes a not-ready but reachable replica (lab5) +# generated: 2026-10-30T20:18:32Z +# lb: haproxy:3.2-alpine@sha256:254e6370f01cd654e0744edf607c67f33777c1b6a9dc0d4b28bcba7171460122 + +## 1. baseline: requests through LB by replica + 22 23d07355bd77 + 18 56bd7451c245 + stats: api1=UP api2=MAINT (resolution) api3=UP api4=MAINT (resolution) api5=MAINT (resolution) api6=MAINT (resolution) api7=MAINT (resolution) api8=MAINT (resolution) BACKEND=UP + +## 2. start a temporary TCP proxy to postgres and a candidate replica behind the same network alias + instance-id: 42c73eb4c0a5, readiness while its database is reachable: 200 + load balancer slot for the candidate: api2, stats: api1=UP api2=UP 1/2 api3=UP api4=MAINT (resolution) api5=MAINT (resolution) api6=MAINT (resolution) api7=MAINT (resolution) api8=MAINT (resolution) BACKEND=UP + +## 3. cut the candidate's database access (stop only the TCP proxy) + candidate is still running: running, readiness: 503 + waiting for the load balancer to mark api2 DOWN + api2 went DOWN 1s after its database was cut (check: inter 2s fall 2) + stats after failure: api1=UP api2=DOWN api3=UP api4=MAINT (resolution) api5=MAINT (resolution) api6=MAINT (resolution) api7=MAINT (resolution) api8=MAINT (resolution) BACKEND=UP + +## 4. 40 requests through LB while the candidate is not ready + 22 23d07355bd77 + 18 56bd7451c245 + (the candidate must not appear above) + +## 5. business writes through LB during the exclusion + "failed_requests": 0, + "error_ratio": 0.0, + "successful_rps": 816.58, + +## 6. cleanup + stats after cleanup: api1=UP api2=MAINT (resolution) api3=UP api4=MAINT (resolution) api5=MAINT (resolution) api6=MAINT (resolution) api7=MAINT (resolution) api8=MAINT (resolution) BACKEND=UP diff --git a/evidence/lab5/lb-readiness.txt b/evidence/lab5/lb-readiness.txt new file mode 100644 index 0000000..1ec9538 --- /dev/null +++ b/evidence/lab5/lb-readiness.txt @@ -0,0 +1,34 @@ +# lb readiness 2026-10-30T20:18:31Z +scripts/lb_readiness_check.sh +# LB excludes a not-ready but reachable replica (lab5) +# generated: 2026-10-30T20:18:32Z +# lb: haproxy:3.2-alpine@sha256:254e6370f01cd654e0744edf607c67f33777c1b6a9dc0d4b28bcba7171460122 + +## 1. baseline: requests through LB by replica + 22 23d07355bd77 + 18 56bd7451c245 + stats: api1=UP api2=MAINT (resolution) api3=UP api4=MAINT (resolution) api5=MAINT (resolution) api6=MAINT (resolution) api7=MAINT (resolution) api8=MAINT (resolution) BACKEND=UP + +## 2. start a temporary TCP proxy to postgres and a candidate replica behind the same network alias + instance-id: 42c73eb4c0a5, readiness while its database is reachable: 200 + load balancer slot for the candidate: api2, stats: api1=UP api2=UP 1/2 api3=UP api4=MAINT (resolution) api5=MAINT (resolution) api6=MAINT (resolution) api7=MAINT (resolution) api8=MAINT (resolution) BACKEND=UP + +## 3. cut the candidate's database access (stop only the TCP proxy) + candidate is still running: running, readiness: 503 + waiting for the load balancer to mark api2 DOWN + api2 went DOWN 1s after its database was cut (check: inter 2s fall 2) + stats after failure: api1=UP api2=DOWN api3=UP api4=MAINT (resolution) api5=MAINT (resolution) api6=MAINT (resolution) api7=MAINT (resolution) api8=MAINT (resolution) BACKEND=UP + +## 4. 40 requests through LB while the candidate is not ready + 22 23d07355bd77 + 18 56bd7451c245 + (the candidate must not appear above) + +## 5. business writes through LB during the exclusion + "failed_requests": 0, + "error_ratio": 0.0, + "successful_rps": 816.58, + +## 6. cleanup + stats after cleanup: api1=UP api2=MAINT (resolution) api3=UP api4=MAINT (resolution) api5=MAINT (resolution) api6=MAINT (resolution) api7=MAINT (resolution) api8=MAINT (resolution) BACKEND=UP +lb_readiness_check.sh: evidence in evidence/lab5/lb-readiness-detail.txt diff --git a/evidence/lab5/lint.txt b/evidence/lab5/lint.txt new file mode 100644 index 0000000..8197453 --- /dev/null +++ b/evidence/lab5/lint.txt @@ -0,0 +1,20 @@ +/Users/vladislav/Projects/mtusi2026lab5/bin/golangci-lint run -v +level=info msg="golangci-lint has version 2.13.2 built with go1.27.1 from (unknown, modified: ?, mod sum: \"h1:bCyq3E4vo9qwzifjpzJqYndEt7Ncva80qkk8G2B4TXU=\") on (unknown)" +level=info msg="[config_reader] Config search paths: [./ /Users/vladislav/Projects/mtusi2026lab5 /Users/vladislav/Projects /Users/vladislav /Users /]" +level=info msg="[config_reader] Used config file .golangci.yml" +level=info msg="[config_reader] Module name \"mtusi-messenger\"" +level=info msg="[goenv] Read go env for 6.264542ms: map[string]string{\"GOCACHE\":\"/Users/vladislav/Library/Caches/go-build\", \"GOROOT\":\"/opt/homebrew/Cellar/go/1.27.1/libexec\"}" +level=info msg="[lintersdb] Active 50 linters: [asasalint bodyclose canonicalheader containedctx contextcheck copyloopvar depguard durationcheck errcheck errname errorlint exhaustive exptostd fatcontext forbidigo forcetypeassert gocheckcompilerdirectives gocritic gofumpt goimports gomoddirectives gosec govet ineffassign intrange makezero misspell musttag nilerr nilnil noctx nolintlint perfsprint prealloc reassign recvcheck revive rowserrcheck sloglint sqlclosecheck staticcheck testifylint thelper tparallel unconvert unparam unused usestdlibvars usetesting wastedassign]" +level=info msg="[loader] Using build tags: [integration]" +level=info msg="[loader] Go packages loading at mode 8767 (compiled_files|deps|exports_file|files|types_sizes|imports|name) took 193.808375ms" +level=info msg="[runner/filename_unadjuster] Pre-built 0 adjustments in 11.667ms" +level=info msg="[linters_context/goanalysis] analyzers took 0s with no stages" +level=info msg="[runner/exclusion_rules] Skipped 14 issues by rules: [Path: \"_test\\\\.go\", Linters: \"gosec, prealloc, forcetypeassert, unparam\"]" +level=info msg="[runner] Issues before processing: 887, after processing: 0" +level=info msg="[runner] Processors filtering stat (in/out): path_absoluter: 887/887, cgo: 887/887, filename_unadjuster: 887/887, nolint_filter: 6/0, invalid_issue: 887/887, exclusion_paths: 887/887, path_relativity: 887/887, generated_file_filter: 887/298, exclusion_rules: 298/6" +level=info msg="[runner] processing took 2.828168ms with stages: generated_file_filter: 1.490334ms, nolint_filter: 764.209µs, path_relativity: 284.917µs, exclusion_rules: 251.001µs, invalid_issue: 13.417µs, cgo: 12.25µs, path_absoluter: 4.666µs, sort_results: 2.916µs, filename_unadjuster: 2.542µs, max_same_issues: 874ns, diff: 167ns, fixer: 166ns, path_prettifier: 125ns, max_per_file_from_linter: 125ns, exclusion_paths: 125ns, path_shortener: 124ns, uniq_by_line: 84ns, severity-rules: 42ns, max_from_linter: 42ns, source_code: 42ns" +level=info msg="[runner] linters took 629.148708ms with stages: goanalysis_metalinter: 626.277292ms" +0 issues. +level=info msg="File cache stats: 0 entries of total size 0B" +level=info msg="Memory: 10 samples, avg is 87.2MB, max is 111.5MB" +level=info msg="Execution took 841.622625ms" diff --git a/evidence/lab5/persistence.txt b/evidence/lab5/persistence.txt new file mode 100644 index 0000000..933a884 --- /dev/null +++ b/evidence/lab5/persistence.txt @@ -0,0 +1,4 @@ +# persistence 2026-10-30T20:12:05Z +env -u HTTP_PROXY -u HTTPS_PROXY -u ALL_PROXY -u http_proxy -u https_proxy -u all_proxy NO_PROXY=localhost,127.0.0.1,::1 no_proxy=localhost,127.0.0.1,::1 python3 tests/resilience.py --mode persistence --action-script "scripts/restart.sh" --base-url "http://localhost:8080" +Executing explicit persistence hook; hook output suppressed to avoid leaking secrets. +PASS: persistence preserved confirmed data and existing session. Hook scope needs operator evidence. diff --git a/evidence/lab5/presign.txt b/evidence/lab5/presign.txt new file mode 100644 index 0000000..740e9d5 --- /dev/null +++ b/evidence/lab5/presign.txt @@ -0,0 +1,11 @@ +# presign 2026-10-30T20:11:41Z +env -u HTTP_PROXY -u HTTPS_PROXY -u ALL_PROXY -u http_proxy -u https_proxy -u all_proxy NO_PROXY=localhost,127.0.0.1,::1 no_proxy=localhost,127.0.0.1,::1 python3 student-tests/presign_flow.py --base-url "http://localhost:8080" +happy path: direct PUT 200, complete queued, ready after worker +message with attachment downloaded as the second chat member +repeated complete is idempotent +foreign complete: 404 +complete before PUT: 409 +wrong completion checksum: 409 +oversized direct PUT: 403 from S3; complete: 409 (nothing stored) +same-size overwrite: last PUT wins, checksum verified +PASS: lab4 presigned upload flow diff --git a/evidence/lab5/smoke.txt b/evidence/lab5/smoke.txt new file mode 100644 index 0000000..218f8d0 --- /dev/null +++ b/evidence/lab5/smoke.txt @@ -0,0 +1,3 @@ +# make test 2026-10-31T11:26:59Z +env -u HTTP_PROXY -u HTTPS_PROXY -u ALL_PROXY -u http_proxy -u https_proxy -u all_proxy NO_PROXY=localhost,127.0.0.1,::1 no_proxy=localhost,127.0.0.1,::1 python3 tests/smoke.py --base-url "http://localhost:8080" +PASS: lab5 public API scenario; infrastructure and grading evidence remain separate. diff --git a/evidence/lab5/stand.txt b/evidence/lab5/stand.txt new file mode 100644 index 0000000..f6eb749 --- /dev/null +++ b/evidence/lab5/stand.txt @@ -0,0 +1,20 @@ +# stand 2026-10-30T20:16:07Z +NAME IMAGE COMMAND SERVICE CREATED STATUS PORTS +mtusi-messenger-lab5-api-1 mtusi-messenger:lab5 "/usr/local/bin/mess…" api 42 seconds ago Up Less than a second (health: starting) 8080/tcp +mtusi-messenger-lab5-api-2 mtusi-messenger:lab5 "/usr/local/bin/mess…" api 42 seconds ago Up Less than a second (health: starting) 8080/tcp +mtusi-messenger-lab5-broker-1 rabbitmq:4.3.7-management-alpine@sha256:1528a88eebf2bc4d0ab7e9d5d9bc542e9bdf5e1b105e65848fcf8de5c2186528 "docker-entrypoint.s…" broker 8 minutes ago Up 8 seconds (healthy) 4369/tcp, 5671-5672/tcp, 15671/tcp, 15691-15692/tcp, 25672/tcp, 127.0.0.1:15672->15672/tcp +mtusi-messenger-lab5-lb-1 haproxy:3.2-alpine@sha256:254e6370f01cd654e0744edf607c67f33777c1b6a9dc0d4b28bcba7171460122 "docker-entrypoint.s…" lb 8 minutes ago Up 3 minutes 127.0.0.1:8404->8404/tcp, 127.0.0.1:8080->80/tcp +mtusi-messenger-lab5-postgres-1 postgres:18-alpine@sha256:77f585114c32fbca283dc835b0596f4e52b51b4c6662d7810b2f4084f60a1873 "docker-entrypoint.s…" postgres 8 minutes ago Up 3 minutes (healthy) 5432/tcp +mtusi-messenger-lab5-redis-1 redis:7.4-alpine@sha256:858f009f9709ce576febc734aa78b8f6d624b82571f9ddb6bda4377c833b3499 "docker-entrypoint.s…" redis 8 minutes ago Up 4 minutes (healthy) 6379/tcp +mtusi-messenger-lab5-relay-1 mtusi-messenger:lab5 "/usr/local/bin/relay" relay 42 seconds ago Up Less than a second (health: starting) 8080/tcp, 127.0.0.1:8082->8082/tcp +mtusi-messenger-lab5-seaweedfs-1 chrislusf/seaweedfs:3.80@sha256:1055999e08eed1789b0ae45d235126e4495e23d3fb9d6396293fd42539b1ae6a "/entrypoint.sh serv…" seaweedfs 8 minutes ago Up 3 minutes (healthy) 7333/tcp, 8080/tcp, 8888/tcp, 9333/tcp, 18080/tcp, 18888/tcp, 19333/tcp, 127.0.0.1:8333->8333/tcp +mtusi-messenger-lab5-worker-1 mtusi-messenger:lab5 "/usr/local/bin/work…" worker 42 seconds ago Up Less than a second (health: starting) 8080/tcp, 127.0.0.1:8081->8081/tcp + +mtusi-messenger:lab5 10b83ff52c7d +rabbitmq:4.3.7-management-alpine 1528a88eebf2 +haproxy:3.2-alpine 254e6370f01c +redis:7.4-alpine 858f009f9709 +postgres:18-alpine 77f585114c32 +chrislusf/seaweedfs:3.80 1055999e08ee + +CPUs=2 MemTotal=2053644288 diff --git a/evidence/lab5/track2/run.txt b/evidence/lab5/track2/run.txt new file mode 100644 index 0000000..714163c --- /dev/null +++ b/evidence/lab5/track2/run.txt @@ -0,0 +1,7 @@ +Dduplicate_before_effect rep=1: PASS +Dstale_version_after_v2 rep=1: PASS +Dduplicate_before_effect rep=2: PASS +Dstale_version_after_v2 rep=2: PASS +Dduplicate_before_effect rep=3: PASS +Dstale_version_after_v2 rep=3: PASS +PASS: track2 6/6 scenarios diff --git a/evidence/lab5/track2/runs.csv b/evidence/lab5/track2/runs.csv new file mode 100644 index 0000000..64ae4b2 --- /dev/null +++ b/evidence/lab5/track2/runs.csv @@ -0,0 +1,7 @@ +scenario,rep,pass,detail +duplicate_before_effect,1,1,attempts=1 +stale_version_after_v2,1,1,v1_job=01a18e6e-17b0-763b-b330-7adbcb43a700 +duplicate_before_effect,2,1,attempts=1 +stale_version_after_v2,2,1,v1_job=01a18e6e-455e-75f3-857a-750ed660378b +duplicate_before_effect,3,1,attempts=1 +stale_version_after_v2,3,1,v1_job=01a18e6e-74f2-7b4a-842b-c014c626413c diff --git a/evidence/lab5/track2/summary.md b/evidence/lab5/track2/summary.md new file mode 100644 index 0000000..f1e50c9 --- /dev/null +++ b/evidence/lab5/track2/summary.md @@ -0,0 +1,21 @@ +# Track 2 — versioned pipeline and duplicate/stale delivery + +Hypothesis: with the effect key `(attachment_id, pipeline_version, variant)`, +deterministic object keys, a serving version that changes only when all v2 +variants are committed, and stale-version acknowledgements, an at-least-once +pipeline loses no accepted work and never overwrites a newer result with an +older duplicate. + +Method: N=3 repetitions. Each repetition creates fresh users/chat and runs: +- duplicate pipeline publication while the worker is stopped, followed by recovery; +- v1 ready -> explicit reprocess to v2 -> old v1 message delivered after v2 ready. + +Invariants checked: unique variant rows per effect key; ready remains ready; +serving pipeline version never regresses; original bytes/checksum unchanged; +stale job state is not rewritten. + +Limitations: this harness covers duplicate and stale/reorder delivery. Crash +windows (before/after side effect, before/after ack, outbox gap) and lease +takeover are covered by student-tests/lab5_faults.py; both are single-node +Compose evidence, not a production availability claim. Delivery is +at-least-once; exactly-once is not claimed. diff --git a/evidence/lab5/unit-test.txt b/evidence/lab5/unit-test.txt new file mode 100644 index 0000000..1441fa4 --- /dev/null +++ b/evidence/lab5/unit-test.txt @@ -0,0 +1,41 @@ +env -u APP_ENV -u SERVER_HOST -u SERVER_PORT -u SERVER_READ_HEADER_TIMEOUT -u SERVER_READ_TIMEOUT -u SERVER_SHUTDOWN_TIMEOUT -u SERVER_MAX_BODY_BYTES -u LOG_LEVEL -u LOG_FORMAT -u POSTGRES_HOST -u POSTGRES_PORT -u POSTGRES_DATABASE -u POSTGRES_USER -u POSTGRES_PASSWORD -u POSTGRES_SSL_MODE -u POSTGRES_MAX_CONNS -u POSTGRES_MIN_CONNS -u POSTGRES_MAX_CONN_LIFETIME -u POSTGRES_MAX_CONN_IDLE_TIME -u POSTGRES_CONNECT_TIMEOUT -u POSTGRES_QUERY_TIMEOUT -u REDIS_ENABLED -u REDIS_HOST -u REDIS_PORT -u REDIS_PASSWORD -u REDIS_DB -u REDIS_MAX_RETRIES -u REDIS_DIAL_TIMEOUT -u REDIS_READ_TIMEOUT -u REDIS_WRITE_TIMEOUT -u REDIS_POOL_SIZE -u CACHE_ENABLED -u CACHE_CHAT_LIST_TTL -u CACHE_LOCK_TTL -u CACHE_LOCK_WAIT_TIMEOUT -u SESSION_TTL_SECONDS -u IDEMPOTENCY_TTL_SECONDS -u API_REPLICAS -u API_CPU_LIMIT -u API_MEM_LIMIT -u POSTGRES_MAX_CONNS -u POSTGRES_CPU_LIMIT -u POSTGRES_MEM_LIMIT -u LB_STATS_PORT -u S3_ENDPOINT -u S3_PUBLIC_ENDPOINT -u S3_PORT -u S3_REGION -u S3_BUCKET -u S3_ACCESS_KEY_ID -u S3_SECRET_ACCESS_KEY -u MAX_UPLOAD_BYTES -u MAX_IMAGE_PIXELS -u S3_PRESIGN_TTL -u S3_SWEEP_INTERVAL -u S3_SWEEP_GRACE -u BROKER_USER -u BROKER_PASSWORD -u BROKER_VHOST -u BROKER_URL -u BROKER_EXCHANGE -u BROKER_QUEUE -u BROKER_DLX -u BROKER_DLQ -u BROKER_MANAGEMENT_PORT -u BROKER_CPU_LIMIT -u BROKER_MEM_LIMIT -u WORKER_CONCURRENCY -u WORKER_PREFETCH -u WORKER_CPU_LIMIT -u WORKER_MEM_LIMIT -u WORKER_SHUTDOWN_TIMEOUT -u PROCESSING_PIPELINE_VERSION -u PROCESSING_MAX_ATTEMPTS -u PROCESSING_JOB_TIMEOUT -u PROCESSING_LEASE_TTL -u PROCESSING_HEARTBEAT -u PROCESSING_RETRY_BASE -u PROCESSING_RETRY_CAP -u OUTBOX_POLL_INTERVAL -u OUTBOX_CLAIM_TTL -u OUTBOX_BATCH -u OUTBOX_REAPER_INTERVAL -u OUTBOX_RETENTION -u RELAY_CPU_LIMIT -u RELAY_MEM_LIMIT -u STAGING_ORPHAN_GRACE -u STAGING_FAILED_RETENTION -u ADMISSION_MAX_PENDING_PER_USER -u ADMISSION_MAX_PENDING -u ADMISSION_MAX_STAGED_BYTES go test -race -shuffle=on -count=1 -timeout=5m ./... +? mtusi-messenger/cmd/jobctl [no test files] +? mtusi-messenger/cmd/messenger [no test files] +? mtusi-messenger/cmd/migrate [no test files] +? mtusi-messenger/cmd/relay [no test files] +? mtusi-messenger/cmd/s3init [no test files] +? mtusi-messenger/cmd/worker [no test files] +? mtusi-messenger/internal/broker [no test files] +ok mtusi-messenger/internal/config 1.717s +ok mtusi-messenger/internal/domain 2.647s +? mtusi-messenger/internal/failpoint [no test files] +ok mtusi-messenger/internal/health 1.315s +ok mtusi-messenger/internal/imagecheck 3.766s +ok mtusi-messenger/internal/imageproc 2.400s +ok mtusi-messenger/internal/logger 2.338s +? mtusi-messenger/internal/outbox [no test files] +ok mtusi-messenger/internal/platform/cache 4.909s +? mtusi-messenger/internal/platform/cache/mocks [no test files] +ok mtusi-messenger/internal/platform/objectstore 6.507s +ok mtusi-messenger/internal/platform/password 3.349s +ok mtusi-messenger/internal/platform/token 3.304s +ok mtusi-messenger/internal/service/attachment 5.105s +? mtusi-messenger/internal/service/attachment/mocks [no test files] +ok mtusi-messenger/internal/service/chat 4.460s +? mtusi-messenger/internal/service/chat/mocks [no test files] +ok mtusi-messenger/internal/service/message 4.119s +? mtusi-messenger/internal/service/message/mocks [no test files] +ok mtusi-messenger/internal/service/session 5.771s +? mtusi-messenger/internal/service/session/mocks [no test files] +ok mtusi-messenger/internal/service/user 6.251s +? mtusi-messenger/internal/service/user/mocks [no test files] +ok mtusi-messenger/internal/storage/postgres 6.484s +? mtusi-messenger/internal/storage/postgres/internal/sqlcgen [no test files] +? mtusi-messenger/internal/storage/postgres/migrations [no test files] +? mtusi-messenger/internal/storage/redis [no test files] +? mtusi-messenger/internal/storage/redis/mocks [no test files] +ok mtusi-messenger/internal/transport/rest 6.893s +? mtusi-messenger/internal/transport/rest/internal/oas [no test files] +? mtusi-messenger/internal/transport/rest/mocks [no test files] +? mtusi-messenger/internal/worker [no test files] +? mtusi-messenger/tools/specgen [no test files] diff --git a/evidence/lab5/validate.txt b/evidence/lab5/validate.txt new file mode 100644 index 0000000..5eafe4a --- /dev/null +++ b/evidence/lab5/validate.txt @@ -0,0 +1,3 @@ +# make validate PYTHON=.venv/bin/python 2026-10-30T22:22:13Z +.venv/bin/python scripts/validate_openapi.py +PASS: full OpenAPI 3.1 and JSON Schema validation; application NOT tested. diff --git a/evidence/lab5/variants.txt b/evidence/lab5/variants.txt new file mode 100644 index 0000000..224631c --- /dev/null +++ b/evidence/lab5/variants.txt @@ -0,0 +1,3 @@ +# lab5_variants 2026-10-30T20:08:36Z +variants: thumbnail 256x160, crop 128x128, optimized WebP 320x200; metadata == bytes +PASS: lab5 variant contract diff --git a/evidence/lab6/README.md b/evidence/lab6/README.md new file mode 100644 index 0000000..d2f015d --- /dev/null +++ b/evidence/lab6/README.md @@ -0,0 +1,30 @@ +# Lab6 evidence + +- `smoke.txt` — `make test` with the telemetry profile running. +- `telemetry.txt` — `make test-observability`: Prometheus/Loki/Tempo/Grafana + queries, route-label validation, forbidden-sentinel search. +- `unit-test.txt` — `make unit-test` (`go test -race -shuffle=on`). +- `stand.txt` — `docker compose --profile telemetry ps`. +- `metrics.txt` — actual sample counts from Prometheus for the required signal set. +- `queries/promql.txt` — PromQL used by dashboards and alerts. +- `tempo-search.json`, `trace-pipeline.json` — raw Tempo responses for an + upload trace; `trace-retry.txt` — attempt=2 trace after a transient fault; + traces include API, relay `job.publish`, worker `job.process`, S3 and DB + child spans. +- Track 2 evidence is generated by `scripts/lab6_track2_full.py`; raw CSV/JSON + belong in `track2/`. `/health/*` is routed to a separate HAProxy backend and + is excluded from `api_backend` SLI. TTR SLI uses two sources: good events + from the time-to-ready histogram bucket `le="30.0"` and bad events from the + separate `messenger_jobs_ttr_missed_total` counter. +- Полный live-прогон Track 2 выполнен 2026-11-06; результаты — в + `track2/full/` и `track2/ttd-ttr.md`. Старые короткие прогоны не + используются как доказательства текущего результата. +- `storage-down.txt` / `storage-down-series.json` — telemetry-storage outage + observations over time (API continues; bounded Collector queues). +- `db-down.txt` — PostgreSQL outage: API/LB responds 5xx, never 401. +- `regression/` is for the lab5 regression commands (`test-queue`, + `test-faults`, `test-attachments`, `test-presign`, `test-idempotency`, + `test-lb-readiness`, persistence/failover). + +No tokens, signed URLs, message bodies or images are stored here. The +`scripts/check_evidence.py` scanner is part of `make test-observability`. diff --git a/evidence/lab6/checks/alert-audit.json b/evidence/lab6/checks/alert-audit.json new file mode 100644 index 0000000..06e626d --- /dev/null +++ b/evidence/lab6/checks/alert-audit.json @@ -0,0 +1,77 @@ +[ + { + "phase": "warmup", + "started_utc": "2026-11-06T08:37:06Z", + "finished_utc": "2026-11-06T09:42:56Z", + "firing": {}, + "pending_not_fired": { + "APISLIMissing": 1 + }, + "page": 0, + "ticket": 0 + }, + { + "phase": "baseline", + "started_utc": "2026-11-06T09:42:56Z", + "finished_utc": "2026-11-06T10:02:51Z", + "firing": {}, + "pending_not_fired": {}, + "page": 0, + "ticket": 0 + }, + { + "phase": "burst", + "started_utc": "2026-11-06T10:02:51Z", + "finished_utc": "2026-11-06T11:29:41Z", + "firing": {}, + "pending_not_fired": { + "APISLIMissing": 2 + }, + "page": 0, + "ticket": 0 + }, + { + "phase": "sustained", + "started_utc": "2026-11-06T11:29:41Z", + "finished_utc": "2026-11-06T11:49:53Z", + "firing": { + "APIErrorBudgetFastBurn": 1, + "APIErrorBudgetSlowBurn": 1, + "QueueMetricsStale": 1 + }, + "pending_not_fired": {}, + "page": 1, + "ticket": 1 + }, + { + "phase": "resolution_wait", + "started_utc": "2026-11-06T11:49:53Z", + "finished_utc": "2026-11-06T12:52:06Z", + "firing": {}, + "pending_not_fired": {}, + "page": 0, + "ticket": 0 + }, + { + "phase": "ttr", + "started_utc": "2026-11-06T12:52:06Z", + "finished_utc": "2026-11-06T13:07:47Z", + "firing": { + "JobsOverdue": 1, + "QueueOldestJobAgeCritical": 1, + "QueueOldestJobAgeHigh": 1 + }, + "pending_not_fired": {}, + "page": 1, + "ticket": 0 + }, + { + "phase": "false-positive", + "started_utc": "2026-11-06T13:07:47Z", + "finished_utc": "2026-11-06T13:30:24Z", + "firing": {}, + "pending_not_fired": {}, + "page": 0, + "ticket": 0 + } +] diff --git a/evidence/lab6/checks/alert-audit.md b/evidence/lab6/checks/alert-audit.md new file mode 100644 index 0000000..ea46985 --- /dev/null +++ b/evidence/lab6/checks/alert-audit.md @@ -0,0 +1,11 @@ +# Alert episodes by phase + +| phase | page | ticket | firing | pending-not-fired | +|---|---:|---:|---|---| +| warmup | 0 | 0 | {} | {'APISLIMissing': 1} | +| baseline | 0 | 0 | {} | {} | +| burst | 0 | 0 | {} | {'APISLIMissing': 2} | +| sustained | 1 | 1 | {'APIErrorBudgetFastBurn': 1, 'APIErrorBudgetSlowBurn': 1, 'QueueMetricsStale': 1} | {} | +| resolution_wait | 0 | 0 | {} | {} | +| ttr | 1 | 0 | {'JobsOverdue': 1, 'QueueOldestJobAgeCritical': 1, 'QueueOldestJobAgeHigh': 1} | {} | +| false-positive | 0 | 0 | {} | {} | diff --git a/evidence/lab6/checks/alert-audit.txt b/evidence/lab6/checks/alert-audit.txt new file mode 100644 index 0000000..bcbadc1 --- /dev/null +++ b/evidence/lab6/checks/alert-audit.txt @@ -0,0 +1,12 @@ +# Alert episodes by phase + +| phase | page | ticket | firing | pending-not-fired | +|---|---:|---:|---|---| +| warmup | 0 | 0 | {} | {'APISLIMissing': 1} | +| baseline | 0 | 0 | {} | {} | +| burst | 0 | 0 | {} | {'APISLIMissing': 2} | +| sustained | 1 | 1 | {'APIErrorBudgetFastBurn': 1, 'APIErrorBudgetSlowBurn': 1, 'QueueMetricsStale': 1} | {} | +| resolution_wait | 0 | 0 | {} | {} | +| ttr | 1 | 0 | {'JobsOverdue': 1, 'QueueOldestJobAgeCritical': 1, 'QueueOldestJobAgeHigh': 1} | {} | +| false-positive | 0 | 0 | {} | {} | + diff --git a/evidence/lab6/checks/clean.txt b/evidence/lab6/checks/clean.txt new file mode 100644 index 0000000..d1a0386 --- /dev/null +++ b/evidence/lab6/checks/clean.txt @@ -0,0 +1,57 @@ +UTC 2026-11-06T13:34:14Z +HEAD 77fe98d775fdc07d5f9bfe04f7b4133c96c0849c +$ make test +env -u HTTP_PROXY -u HTTPS_PROXY -u ALL_PROXY -u http_proxy -u https_proxy -u all_proxy NO_PROXY=localhost,127.0.0.1,::1 no_proxy=localhost,127.0.0.1,::1 python3 tests/smoke.py --base-url "http://localhost:8080" +PASS: lab6 public API scenario; infrastructure and grading evidence remain separate. +$ make test-observability +env -u HTTP_PROXY -u HTTPS_PROXY -u ALL_PROXY -u http_proxy -u https_proxy -u all_proxy NO_PROXY=localhost,127.0.0.1,::1 no_proxy=localhost,127.0.0.1,::1 python3 scripts/check_evidence.py +PASS: evidence has no obvious secrets, signed URLs or bearer tokens +env -u HTTP_PROXY -u HTTPS_PROXY -u ALL_PROXY -u http_proxy -u https_proxy -u all_proxy NO_PROXY=localhost,127.0.0.1,::1 no_proxy=localhost,127.0.0.1,::1 python3 scripts/lab6_verify.py --base-url "http://localhost:8080" +NOTE: created request_id=lab6-verify-015163e6e039495c91258218e57f1a94 +PASS: lab6 strict telemetry gate (signals, trace/log correlation, labels, Grafana, rules, privacy sentinels) +$ make test-slo +env -u HTTP_PROXY -u HTTPS_PROXY -u ALL_PROXY -u http_proxy -u https_proxy -u all_proxy NO_PROXY=localhost,127.0.0.1,::1 no_proxy=localhost,127.0.0.1,::1 python3 scripts/lab6_track2.py --base-url "http://localhost:8080" + Container mtusi-messenger-lab6-postgres-1 Paused + Container mtusi-messenger-lab6-postgres-1 Unpaused +{ + "base_url": "http://localhost:8080", + "rate": 0.5, + "duration_s": 138.01, + "scheduled": 70, + "counters": { + "accepted": 3, + "ready": 3, + "failed": 61, + "messages": 56, + "uploads": 3, + "dropped": 0 + }, + "failures": 61, + "failures_by_reason": { + "http_503": 61 + }, + "failure_samples": [ + "Failure: POST /api/v1/chats/01a1b111-5050-7eb1-b4d5-4a156e2010f4/messages: expected [201], received 503", + "Failure: POST /api/v1/chats/01a1b111-5050-7eb1-b4d5-4a156e2010f4/attachments: expected [202], received 503", + "Failure: POST /api/v1/chats/01a1b111-5050-7eb1-b4d5-4a156e2010f4/messages: expected [201], received 503", + "Failure: POST /api/v1/chats/01a1b111-5050-7eb1-b4d5-4a156e2010f4/messages: expected [201], received 503", + "Failure: POST /api/v1/chats/01a1b111-5050-7eb1-b4d5-4a156e2010f4/messages: expected [201], received 503", + "Failure: POST /api/v1/chats/01a1b111-5050-7eb1-b4d5-4a156e2010f4/messages: expected [201], received 503", + "Failure: POST /api/v1/chats/01a1b111-5050-7eb1-b4d5-4a156e2010f4/messages: expected [201], received 503", + "Failure: POST /api/v1/chats/01a1b111-5050-7eb1-b4d5-4a156e2010f4/messages: expected [201], received 503", + "Failure: POST /api/v1/chats/01a1b111-5050-7eb1-b4d5-4a156e2010f4/attachments: expected [202], received 503", + "Failure: POST /api/v1/chats/01a1b111-5050-7eb1-b4d5-4a156e2010f4/messages: expected [201], received 503" + ], + "latency_ms": { + "p50": 6.7, + "p95": 10.8, + "p99": 10.8 + }, + "ttr_ms": { + "p50": 633.4, + "p95": 635.1, + "p99": 635.1 + } +} +alert timeline: /Users/vladislav/Projects/mtusi2026lab6/evidence/lab6/track2/burst-alerts.csv +track2 evidence: /Users/vladislav/Projects/mtusi2026lab6/evidence/lab6/track2 load_rc= 1 alerts_rc= 0 diff --git a/evidence/lab6/checks/collector-down-load.json b/evidence/lab6/checks/collector-down-load.json new file mode 100644 index 0000000..c32f9e6 --- /dev/null +++ b/evidence/lab6/checks/collector-down-load.json @@ -0,0 +1,27 @@ +{ + "base_url": "http://localhost:8080", + "rate": 0.2, + "duration_s": 655.01, + "scheduled": 132, + "counters": { + "accepted": 27, + "ready": 27, + "failed": 0, + "messages": 105, + "uploads": 27, + "dropped": 0 + }, + "failures": 0, + "failures_by_reason": {}, + "failure_samples": [], + "latency_ms": { + "p50": 6.2, + "p95": 9.2, + "p99": 11.9 + }, + "ttr_ms": { + "p50": 646.2, + "p95": 1265.8, + "p99": 1268.0 + } +} diff --git a/evidence/lab6/checks/collector-metrics.txt b/evidence/lab6/checks/collector-metrics.txt new file mode 100644 index 0000000..2ed95e3 --- /dev/null +++ b/evidence/lab6/checks/collector-metrics.txt @@ -0,0 +1,29 @@ +UTC 2026-11-05T22:39:30Z +HEAD 639582280f0cc2236dee3140207168df23cc8bf1 +$ docker compose exec prometheus wget -qO- http://otel-collector:8888/metrics +# HELP otelcol_exporter_queue_capacity Fixed capacity of the retry queue (in batches). [Alpha] +# TYPE otelcol_exporter_queue_capacity gauge +otelcol_exporter_queue_capacity{data_type="logs",exporter="otlp_http/loki"} 1.048576e+07 +otelcol_exporter_queue_capacity{data_type="traces",exporter="otlp_grpc/tempo"} 1.048576e+07 +# HELP otelcol_exporter_queue_size Current size of the retry queue (in batches). [Alpha] +# TYPE otelcol_exporter_queue_size gauge +otelcol_exporter_queue_size{data_type="logs",exporter="otlp_http/loki"} 0 +otelcol_exporter_queue_size{data_type="traces",exporter="otlp_grpc/tempo"} 0 +# HELP otelcol_receiver_failed_log_records The number of log records that failed to be processed by the receiver due to internal errors. [Alpha] +# TYPE otelcol_receiver_failed_log_records counter +otelcol_receiver_failed_log_records{receiver="otlp",transport="http"} 0 +# HELP otelcol_receiver_failed_metric_points The number of metric points that failed to be processed by the receiver due to internal errors. [Alpha] +# TYPE otelcol_receiver_failed_metric_points counter +otelcol_receiver_failed_metric_points{receiver="otlp",transport="http"} 0 +# HELP otelcol_receiver_failed_spans The number of spans that failed to be processed by the receiver due to internal errors. [Alpha] +# TYPE otelcol_receiver_failed_spans counter +otelcol_receiver_failed_spans{receiver="otlp",transport="http"} 0 +# HELP otelcol_receiver_refused_log_records Number of log records that could not be pushed into the pipeline. [Alpha] +# TYPE otelcol_receiver_refused_log_records counter +otelcol_receiver_refused_log_records{receiver="otlp",transport="http"} 0 +# HELP otelcol_receiver_refused_metric_points Number of metric points that could not be pushed into the pipeline. [Alpha] +# TYPE otelcol_receiver_refused_metric_points counter +otelcol_receiver_refused_metric_points{receiver="otlp",transport="http"} 0 +# HELP otelcol_receiver_refused_spans Number of spans that could not be pushed into the pipeline. [Alpha] +# TYPE otelcol_receiver_refused_spans counter +otelcol_receiver_refused_spans{receiver="otlp",transport="http"} 0 diff --git a/evidence/lab6/checks/integration.txt b/evidence/lab6/checks/integration.txt new file mode 100644 index 0000000..9e1c021 --- /dev/null +++ b/evidence/lab6/checks/integration.txt @@ -0,0 +1,6 @@ +UTC 2026-11-06T13:33:57Z +HEAD 77fe98d775fdc07d5f9bfe04f7b4133c96c0849c +$ make integration-test +go test -tags=integration -p 1 -count=1 -timeout=15m ./internal/storage/postgres ./internal/storage/redis +ok mtusi-messenger/internal/storage/postgres 8.234s +ok mtusi-messenger/internal/storage/redis 1.292s diff --git a/evidence/lab6/checks/static.txt b/evidence/lab6/checks/static.txt new file mode 100644 index 0000000..975dc08 --- /dev/null +++ b/evidence/lab6/checks/static.txt @@ -0,0 +1,84 @@ +UTC 2026-11-06T13:33:34Z +HEAD 77fe98d775fdc07d5f9bfe04f7b4133c96c0849c +$ make check +python3 scripts/check_contract.py +PASS: offline skeleton structure, local refs and Python syntax; application NOT tested. +python3 scripts/check_s3_creds.py +PASS: S3 app identity matches .env; admin stays in s3.json/s3-init +$ make unit-test +env -u APP_ENV -u SERVER_HOST -u SERVER_PORT -u SERVER_READ_HEADER_TIMEOUT -u SERVER_READ_TIMEOUT -u SERVER_SHUTDOWN_TIMEOUT -u SERVER_MAX_BODY_BYTES -u LOG_LEVEL -u LOG_FORMAT -u POSTGRES_HOST -u POSTGRES_PORT -u POSTGRES_DATABASE -u POSTGRES_USER -u POSTGRES_PASSWORD -u POSTGRES_SSL_MODE -u POSTGRES_MAX_CONNS -u POSTGRES_MIN_CONNS -u POSTGRES_MAX_CONN_LIFETIME -u POSTGRES_MAX_CONN_IDLE_TIME -u POSTGRES_CONNECT_TIMEOUT -u POSTGRES_QUERY_TIMEOUT -u REDIS_ENABLED -u REDIS_HOST -u REDIS_PORT -u REDIS_PASSWORD -u REDIS_DB -u REDIS_MAX_RETRIES -u REDIS_DIAL_TIMEOUT -u REDIS_READ_TIMEOUT -u REDIS_WRITE_TIMEOUT -u REDIS_POOL_SIZE -u CACHE_ENABLED -u CACHE_CHAT_LIST_TTL -u CACHE_LOCK_TTL -u CACHE_LOCK_WAIT_TIMEOUT -u SESSION_TTL_SECONDS -u IDEMPOTENCY_TTL_SECONDS -u API_REPLICAS -u API_CPU_LIMIT -u API_MEM_LIMIT -u POSTGRES_MAX_CONNS -u POSTGRES_CPU_LIMIT -u POSTGRES_MEM_LIMIT -u LB_STATS_PORT -u S3_ENDPOINT -u S3_PUBLIC_ENDPOINT -u S3_PORT -u S3_REGION -u S3_BUCKET -u S3_ACCESS_KEY_ID -u S3_SECRET_ACCESS_KEY -u MAX_UPLOAD_BYTES -u MAX_IMAGE_PIXELS -u S3_PRESIGN_TTL -u S3_SWEEP_INTERVAL -u S3_SWEEP_GRACE -u BROKER_USER -u BROKER_PASSWORD -u BROKER_VHOST -u BROKER_URL -u BROKER_EXCHANGE -u BROKER_QUEUE -u BROKER_DLX -u BROKER_DLQ -u BROKER_MANAGEMENT_PORT -u BROKER_CPU_LIMIT -u BROKER_MEM_LIMIT -u WORKER_CONCURRENCY -u WORKER_PREFETCH -u WORKER_CPU_LIMIT -u WORKER_MEM_LIMIT -u WORKER_SHUTDOWN_TIMEOUT -u WORKER_HEALTH_PORT -u PROCESSING_PIPELINE_VERSION -u PROCESSING_MAX_ATTEMPTS -u PROCESSING_JOB_TIMEOUT -u PROCESSING_LEASE_TTL -u PROCESSING_HEARTBEAT -u PROCESSING_RETRY_BASE -u PROCESSING_RETRY_CAP -u OUTBOX_POLL_INTERVAL -u OUTBOX_CLAIM_TTL -u OUTBOX_BATCH -u OUTBOX_REAPER_INTERVAL -u OUTBOX_RECONCILE_AFTER -u OUTBOX_RETENTION -u RELAY_CPU_LIMIT -u RELAY_MEM_LIMIT -u RELAY_HEALTH_PORT -u STAGING_ORPHAN_GRACE -u STAGING_FAILED_RETENTION -u ADMISSION_MAX_PENDING_PER_USER -u ADMISSION_MAX_PENDING -u ADMISSION_MAX_STAGED_BYTES -u ADMISSION_MAX_CONCURRENT_UPLOADS -u OTEL_EXPORTER_OTLP_ENDPOINT -u OTEL_EXPORTER_OTLP_PROTOCOL -u OTEL_RESOURCE_ATTRIBUTES -u OTEL_METRIC_EXPORT_INTERVAL -u TELEMETRY_ENABLED -u PROMETHEUS_PORT -u LOKI_PORT -u TEMPO_PORT -u GRAFANA_PORT -u OTEL_COLLECTOR_CPU_LIMIT -u OTEL_COLLECTOR_MEM_LIMIT -u PROMETHEUS_CPU_LIMIT -u PROMETHEUS_MEM_LIMIT -u LOKI_CPU_LIMIT -u LOKI_MEM_LIMIT -u TEMPO_CPU_LIMIT -u TEMPO_MEM_LIMIT -u GRAFANA_CPU_LIMIT -u GRAFANA_MEM_LIMIT go test -race -shuffle=on -count=1 -timeout=5m ./... +? mtusi-messenger/cmd/jobctl [no test files] +? mtusi-messenger/cmd/messenger [no test files] +? mtusi-messenger/cmd/migrate [no test files] +? mtusi-messenger/cmd/relay [no test files] +? mtusi-messenger/cmd/s3init [no test files] +? mtusi-messenger/cmd/worker [no test files] +? mtusi-messenger/internal/broker [no test files] +ok mtusi-messenger/internal/config 1.747s +ok mtusi-messenger/internal/domain 2.759s +? mtusi-messenger/internal/failpoint [no test files] +ok mtusi-messenger/internal/health 2.400s +ok mtusi-messenger/internal/imagecheck 2.085s +ok mtusi-messenger/internal/imageproc 3.626s +ok mtusi-messenger/internal/logger 3.554s +? mtusi-messenger/internal/outbox [no test files] +ok mtusi-messenger/internal/platform/cache 4.833s +? mtusi-messenger/internal/platform/cache/mocks [no test files] +? mtusi-messenger/internal/platform/instanceid [no test files] +ok mtusi-messenger/internal/platform/objectstore 3.918s +ok mtusi-messenger/internal/platform/password 5.632s +ok mtusi-messenger/internal/platform/token 4.941s +ok mtusi-messenger/internal/service/attachment 5.544s +? mtusi-messenger/internal/service/attachment/mocks [no test files] +ok mtusi-messenger/internal/service/chat 5.919s +? mtusi-messenger/internal/service/chat/mocks [no test files] +ok mtusi-messenger/internal/service/message 6.281s +? mtusi-messenger/internal/service/message/mocks [no test files] +ok mtusi-messenger/internal/service/session 6.928s +? mtusi-messenger/internal/service/session/mocks [no test files] +ok mtusi-messenger/internal/service/user 7.266s +? mtusi-messenger/internal/service/user/mocks [no test files] +ok mtusi-messenger/internal/storage/postgres 7.689s +? mtusi-messenger/internal/storage/postgres/internal/sqlcgen [no test files] +? mtusi-messenger/internal/storage/postgres/migrations [no test files] +? mtusi-messenger/internal/storage/redis [no test files] +? mtusi-messenger/internal/storage/redis/mocks [no test files] +ok mtusi-messenger/internal/telemetry 8.058s +ok mtusi-messenger/internal/transport/rest 8.529s +? mtusi-messenger/internal/transport/rest/internal/oas [no test files] +? mtusi-messenger/internal/transport/rest/mocks [no test files] +ok mtusi-messenger/internal/worker 7.565s +? mtusi-messenger/tools/specgen [no test files] +$ make lint +/Users/vladislav/Projects/mtusi2026lab6/bin/golangci-lint run -v +level=info msg="golangci-lint has version 2.13.2 built with go1.27.1 from (unknown, modified: ?, mod sum: \"h1:bCyq3E4vo9qwzifjpzJqYndEt7Ncva80qkk8G2B4TXU=\") on (unknown)" +level=info msg="[config_reader] Config search paths: [./ /Users/vladislav/Projects/mtusi2026lab6 /Users/vladislav/Projects /Users/vladislav /Users /]" +level=info msg="[config_reader] Used config file .golangci.yml" +level=info msg="[config_reader] Module name \"mtusi-messenger\"" +level=info msg="[goenv] Read go env for 5.452167ms: map[string]string{\"GOCACHE\":\"/Users/vladislav/Library/Caches/go-build\", \"GOROOT\":\"/opt/homebrew/Cellar/go/1.27.1/libexec\"}" +level=info msg="[lintersdb] Active 50 linters: [asasalint bodyclose canonicalheader containedctx contextcheck copyloopvar depguard durationcheck errcheck errname errorlint exhaustive exptostd fatcontext forbidigo forcetypeassert gocheckcompilerdirectives gocritic gofumpt goimports gomoddirectives gosec govet ineffassign intrange makezero misspell musttag nilerr nilnil noctx nolintlint perfsprint prealloc reassign recvcheck revive rowserrcheck sloglint sqlclosecheck staticcheck testifylint thelper tparallel unconvert unparam unused usestdlibvars usetesting wastedassign]" +level=info msg="[loader] Using build tags: [integration]" +level=info msg="[loader] Go packages loading at mode 8767 (exports_file|types_sizes|compiled_files|deps|files|imports|name) took 328.172459ms" +level=info msg="[runner/filename_unadjuster] Pre-built 0 adjustments in 8.257709ms" +level=info msg="[linters_context/goanalysis] analyzers took 0s with no stages" +level=info msg="[runner/exclusion_rules] Skipped 15 issues by rules: [Path: \"_test\\\\.go\", Linters: \"gosec, prealloc, forcetypeassert, unparam\"]" +level=info msg="[runner] Issues before processing: 894, after processing: 0" +level=info msg="[runner] Processors filtering stat (in/out): path_absoluter: 894/894, cgo: 894/894, exclusion_paths: 894/894, exclusion_rules: 305/6, filename_unadjuster: 894/894, invalid_issue: 894/894, nolint_filter: 6/0, path_relativity: 894/894, generated_file_filter: 894/305" +level=info msg="[runner] processing took 3.308334ms with stages: generated_file_filter: 1.592083ms, nolint_filter: 799.625µs, path_relativity: 567.333µs, exclusion_rules: 281.584µs, cgo: 27.917µs, invalid_issue: 16.916µs, path_absoluter: 10.542µs, filename_unadjuster: 6.208µs, sort_results: 3.876µs, max_same_issues: 625ns, exclusion_paths: 417ns, fixer: 292ns, max_from_linter: 208ns, source_code: 125ns, path_prettifier: 125ns, path_shortener: 124ns, max_per_file_from_linter: 84ns, severity-rules: 84ns, uniq_by_line: 83ns, diff: 83ns" +level=info msg="[runner] linters took 715.361458ms with stages: goanalysis_metalinter: 712.008375ms" +0 issues. +level=info msg="File cache stats: 0 entries of total size 0B" +level=info msg="Memory: 12 samples, avg is 83.2MB, max is 111.1MB" +level=info msg="Execution took 1.057716875s" +$ go vet ./... +$ promtool check rules +Checking /etc/prometheus/rules/alerts.yml + SUCCESS: 15 rules found + +Checking /etc/prometheus/rules/slo.yml + SUCCESS: 10 rules found + +$ promtool test rules + SUCCESS + +$ docker compose config -q diff --git a/evidence/lab6/checks/storage-down-load.json b/evidence/lab6/checks/storage-down-load.json new file mode 100644 index 0000000..5b85cd6 --- /dev/null +++ b/evidence/lab6/checks/storage-down-load.json @@ -0,0 +1,27 @@ +{ + "base_url": "http://localhost:8080", + "rate": 0.2, + "duration_s": 775.03, + "scheduled": 156, + "counters": { + "accepted": 31, + "ready": 31, + "failed": 0, + "messages": 125, + "uploads": 31, + "dropped": 0 + }, + "failures": 0, + "failures_by_reason": {}, + "failure_samples": [], + "latency_ms": { + "p50": 7.7, + "p95": 10.5, + "p99": 12.4 + }, + "ttr_ms": { + "p50": 955.9, + "p95": 1265.6, + "p99": 1266.7 + } +} diff --git a/evidence/lab6/checks/storage-down-series.txt b/evidence/lab6/checks/storage-down-series.txt new file mode 100644 index 0000000..95e108a --- /dev/null +++ b/evidence/lab6/checks/storage-down-series.txt @@ -0,0 +1,1265 @@ +UTC 2026-11-05T22:52:05Z +HEAD 639582280f0cc2236dee3140207168df23cc8bf1 +$ python3 scripts/lab6_storage_down_series.py --duration 300 +[ + { + "phase": "baseline", + "utc": "2026-11-05T22:52:05Z", + "api_memory": null, + "worker_memory": null, + "collector_memory": null, + "queue_logs": null, + "queue_traces": null, + "accepted_logs": "0", + "receiver_failed": "0", + "api_error_5m": "0", + "api_p99": "NaN", + "api": [ + { + "name": "mtusi-messenger-lab6-api-1", + "status": "running", + "restarts": 0, + "oom": false, + "limit_bytes": 268435456 + }, + { + "name": "mtusi-messenger-lab6-api-2", + "status": "running", + "restarts": 0, + "oom": false, + "limit_bytes": 268435456 + } + ], + "collector": [] + }, + { + "phase": "down-start", + "utc": "2026-11-05T22:52:06Z", + "api_memory": null, + "worker_memory": null, + "collector_memory": null, + "queue_logs": null, + "queue_traces": null, + "accepted_logs": "0", + "receiver_failed": "0", + "api_error_5m": "0", + "api_p99": "NaN", + "api": [ + { + "name": "mtusi-messenger-lab6-api-1", + "status": "running", + "restarts": 0, + "oom": false, + "limit_bytes": 268435456 + }, + { + "name": "mtusi-messenger-lab6-api-2", + "status": "running", + "restarts": 0, + "oom": false, + "limit_bytes": 268435456 + } + ], + "collector": [] + }, + { + "phase": "down", + "utc": "2026-11-05T22:52:16Z", + "api_memory": null, + "worker_memory": null, + "collector_memory": null, + "queue_logs": null, + "queue_traces": null, + "accepted_logs": "0", + "receiver_failed": "0", + "api_error_5m": "0", + "api_p99": "NaN", + "api": [ + { + "name": "mtusi-messenger-lab6-api-1", + "status": "running", + "restarts": 0, + "oom": false, + "limit_bytes": 268435456 + }, + { + "name": "mtusi-messenger-lab6-api-2", + "status": "running", + "restarts": 0, + "oom": false, + "limit_bytes": 268435456 + } + ], + "collector": [] + }, + { + "phase": "down", + "utc": "2026-11-05T22:52:26Z", + "api_memory": null, + "worker_memory": null, + "collector_memory": null, + "queue_logs": null, + "queue_traces": null, + "accepted_logs": null, + "receiver_failed": null, + "api_error_5m": "0", + "api_p99": null, + "api": [ + { + "name": "mtusi-messenger-lab6-api-1", + "status": "running", + "restarts": 0, + "oom": false, + "limit_bytes": 268435456 + }, + { + "name": "mtusi-messenger-lab6-api-2", + "status": "running", + "restarts": 0, + "oom": false, + "limit_bytes": 268435456 + } + ], + "collector": [] + }, + { + "phase": "down", + "utc": "2026-11-05T22:52:36Z", + "api_memory": null, + "worker_memory": null, + "collector_memory": "203190272", + "queue_logs": "23194", + "queue_traces": "48906", + "accepted_logs": null, + "receiver_failed": null, + "api_error_5m": "0", + "api_p99": null, + "api": [ + { + "name": "mtusi-messenger-lab6-api-1", + "status": "running", + "restarts": 0, + "oom": false, + "limit_bytes": 268435456 + }, + { + "name": "mtusi-messenger-lab6-api-2", + "status": "running", + "restarts": 0, + "oom": false, + "limit_bytes": 268435456 + } + ], + "collector": [ + { + "name": "mtusi-messenger-lab6-otel-collector-1", + "status": "running", + "restarts": 0, + "oom": false, + "limit_bytes": 201326592 + } + ] + }, + { + "phase": "down", + "utc": "2026-11-05T22:52:46Z", + "api_memory": null, + "worker_memory": "17195008", + "collector_memory": "205754368", + "queue_logs": "23194", + "queue_traces": "51096", + "accepted_logs": "0", + "receiver_failed": "0", + "api_error_5m": "0", + "api_p99": null, + "api": [ + { + "name": "mtusi-messenger-lab6-api-1", + "status": "running", + "restarts": 0, + "oom": false, + "limit_bytes": 268435456 + }, + { + "name": "mtusi-messenger-lab6-api-2", + "status": "running", + "restarts": 0, + "oom": false, + "limit_bytes": 268435456 + } + ], + "collector": [ + { + "name": "mtusi-messenger-lab6-otel-collector-1", + "status": "running", + "restarts": 0, + "oom": false, + "limit_bytes": 201326592 + } + ] + }, + { + "phase": "down", + "utc": "2026-11-05T22:52:56Z", + "api_memory": "147922944", + "worker_memory": "17195008", + "collector_memory": "208908288", + "queue_logs": "23194", + "queue_traces": "53286", + "accepted_logs": "0", + "receiver_failed": "0", + "api_error_5m": "0", + "api_p99": "NaN", + "api": [ + { + "name": "mtusi-messenger-lab6-api-1", + "status": "running", + "restarts": 0, + "oom": false, + "limit_bytes": 268435456 + }, + { + "name": "mtusi-messenger-lab6-api-2", + "status": "running", + "restarts": 0, + "oom": false, + "limit_bytes": 268435456 + } + ], + "collector": [ + { + "name": "mtusi-messenger-lab6-otel-collector-1", + "status": "running", + "restarts": 0, + "oom": false, + "limit_bytes": 201326592 + } + ] + }, + { + "phase": "down", + "utc": "2026-11-05T22:53:07Z", + "api_memory": "148213760", + "worker_memory": "17203200", + "collector_memory": "210948096", + "queue_logs": "0", + "queue_traces": "6216", + "accepted_logs": "0", + "receiver_failed": "0", + "api_error_5m": "0", + "api_p99": "NaN", + "api": [ + { + "name": "mtusi-messenger-lab6-api-1", + "status": "running", + "restarts": 0, + "oom": false, + "limit_bytes": 268435456 + }, + { + "name": "mtusi-messenger-lab6-api-2", + "status": "running", + "restarts": 0, + "oom": false, + "limit_bytes": 268435456 + } + ], + "collector": [ + { + "name": "mtusi-messenger-lab6-otel-collector-1", + "status": "running", + "restarts": 0, + "oom": false, + "limit_bytes": 201326592 + } + ] + }, + { + "phase": "down", + "utc": "2026-11-05T22:53:17Z", + "api_memory": "148213760", + "worker_memory": "17199104", + "collector_memory": "211140608", + "queue_logs": "0", + "queue_traces": "6692", + "accepted_logs": "0", + "receiver_failed": "0", + "api_error_5m": "0", + "api_p99": "NaN", + "api": [ + { + "name": "mtusi-messenger-lab6-api-1", + "status": "running", + "restarts": 0, + "oom": false, + "limit_bytes": 268435456 + }, + { + "name": "mtusi-messenger-lab6-api-2", + "status": "running", + "restarts": 0, + "oom": false, + "limit_bytes": 268435456 + } + ], + "collector": [ + { + "name": "mtusi-messenger-lab6-otel-collector-1", + "status": "running", + "restarts": 0, + "oom": false, + "limit_bytes": 201326592 + } + ] + }, + { + "phase": "down", + "utc": "2026-11-05T22:53:27Z", + "api_memory": "148627456", + "worker_memory": "17199104", + "collector_memory": "211447808", + "queue_logs": "0", + "queue_traces": "8882", + "accepted_logs": "0", + "receiver_failed": "0", + "api_error_5m": "0", + "api_p99": "NaN", + "api": [ + { + "name": "mtusi-messenger-lab6-api-1", + "status": "running", + "restarts": 0, + "oom": false, + "limit_bytes": 268435456 + }, + { + "name": "mtusi-messenger-lab6-api-2", + "status": "running", + "restarts": 0, + "oom": false, + "limit_bytes": 268435456 + } + ], + "collector": [ + { + "name": "mtusi-messenger-lab6-otel-collector-1", + "status": "running", + "restarts": 0, + "oom": false, + "limit_bytes": 201326592 + } + ] + }, + { + "phase": "down", + "utc": "2026-11-05T22:53:37Z", + "api_memory": "148787200", + "worker_memory": "17461248", + "collector_memory": "211992576", + "queue_logs": "0", + "queue_traces": "6692", + "accepted_logs": "0", + "receiver_failed": "0", + "api_error_5m": "0", + "api_p99": "NaN", + "api": [ + { + "name": "mtusi-messenger-lab6-api-1", + "status": "running", + "restarts": 0, + "oom": false, + "limit_bytes": 268435456 + }, + { + "name": "mtusi-messenger-lab6-api-2", + "status": "running", + "restarts": 0, + "oom": false, + "limit_bytes": 268435456 + } + ], + "collector": [ + { + "name": "mtusi-messenger-lab6-otel-collector-1", + "status": "running", + "restarts": 0, + "oom": false, + "limit_bytes": 201326592 + } + ] + }, + { + "phase": "down", + "utc": "2026-11-05T22:53:47Z", + "api_memory": "148787200", + "worker_memory": "17199104", + "collector_memory": "212234240", + "queue_logs": "0", + "queue_traces": "8882", + "accepted_logs": "0", + "receiver_failed": "0", + "api_error_5m": "0", + "api_p99": "NaN", + "api": [ + { + "name": "mtusi-messenger-lab6-api-1", + "status": "running", + "restarts": 0, + "oom": false, + "limit_bytes": 268435456 + }, + { + "name": "mtusi-messenger-lab6-api-2", + "status": "running", + "restarts": 0, + "oom": false, + "limit_bytes": 268435456 + } + ], + "collector": [ + { + "name": "mtusi-messenger-lab6-otel-collector-1", + "status": "running", + "restarts": 0, + "oom": false, + "limit_bytes": 201326592 + } + ] + }, + { + "phase": "down", + "utc": "2026-11-05T22:53:57Z", + "api_memory": "148967424", + "worker_memory": "17199104", + "collector_memory": "213938176", + "queue_logs": "0", + "queue_traces": "10392", + "accepted_logs": "0", + "receiver_failed": "0", + "api_error_5m": "0", + "api_p99": "NaN", + "api": [ + { + "name": "mtusi-messenger-lab6-api-1", + "status": "running", + "restarts": 0, + "oom": false, + "limit_bytes": 268435456 + }, + { + "name": "mtusi-messenger-lab6-api-2", + "status": "running", + "restarts": 0, + "oom": false, + "limit_bytes": 268435456 + } + ], + "collector": [ + { + "name": "mtusi-messenger-lab6-otel-collector-1", + "status": "running", + "restarts": 0, + "oom": false, + "limit_bytes": 201326592 + } + ] + }, + { + "phase": "down", + "utc": "2026-11-05T22:54:08Z", + "api_memory": "149463040", + "worker_memory": "17457152", + "collector_memory": "216592384", + "queue_logs": "0", + "queue_traces": "10392", + "accepted_logs": "0", + "receiver_failed": "0", + "api_error_5m": "0", + "api_p99": "NaN", + "api": [ + { + "name": "mtusi-messenger-lab6-api-1", + "status": "running", + "restarts": 0, + "oom": false, + "limit_bytes": 268435456 + }, + { + "name": "mtusi-messenger-lab6-api-2", + "status": "running", + "restarts": 0, + "oom": false, + "limit_bytes": 268435456 + } + ], + "collector": [ + { + "name": "mtusi-messenger-lab6-otel-collector-1", + "status": "running", + "restarts": 0, + "oom": false, + "limit_bytes": 201326592 + } + ] + }, + { + "phase": "down", + "utc": "2026-11-05T22:54:18Z", + "api_memory": "149463040", + "worker_memory": "17199104", + "collector_memory": "219217920", + "queue_logs": "0", + "queue_traces": "12582", + "accepted_logs": "0", + "receiver_failed": "0", + "api_error_5m": "0", + "api_p99": "NaN", + "api": [ + { + "name": "mtusi-messenger-lab6-api-1", + "status": "running", + "restarts": 0, + "oom": false, + "limit_bytes": 268435456 + }, + { + "name": "mtusi-messenger-lab6-api-2", + "status": "running", + "restarts": 0, + "oom": false, + "limit_bytes": 268435456 + } + ], + "collector": [ + { + "name": "mtusi-messenger-lab6-otel-collector-1", + "status": "running", + "restarts": 0, + "oom": false, + "limit_bytes": 201326592 + } + ] + }, + { + "phase": "down", + "utc": "2026-11-05T22:54:28Z", + "api_memory": "146219008", + "worker_memory": "17199104", + "collector_memory": "219590656", + "queue_logs": "0", + "queue_traces": "13058", + "accepted_logs": "0", + "receiver_failed": "0", + "api_error_5m": "0", + "api_p99": "NaN", + "api": [ + { + "name": "mtusi-messenger-lab6-api-1", + "status": "running", + "restarts": 0, + "oom": false, + "limit_bytes": 268435456 + }, + { + "name": "mtusi-messenger-lab6-api-2", + "status": "running", + "restarts": 0, + "oom": false, + "limit_bytes": 268435456 + } + ], + "collector": [ + { + "name": "mtusi-messenger-lab6-otel-collector-1", + "status": "running", + "restarts": 0, + "oom": false, + "limit_bytes": 201326592 + } + ] + }, + { + "phase": "down", + "utc": "2026-11-05T22:54:38Z", + "api_memory": "146415616", + "worker_memory": "17461248", + "collector_memory": "219697152", + "queue_logs": "0", + "queue_traces": "13058", + "accepted_logs": "0", + "receiver_failed": "0", + "api_error_5m": "0", + "api_p99": "NaN", + "api": [ + { + "name": "mtusi-messenger-lab6-api-1", + "status": "running", + "restarts": 0, + "oom": false, + "limit_bytes": 268435456 + }, + { + "name": "mtusi-messenger-lab6-api-2", + "status": "running", + "restarts": 0, + "oom": false, + "limit_bytes": 268435456 + } + ], + "collector": [ + { + "name": "mtusi-messenger-lab6-otel-collector-1", + "status": "running", + "restarts": 0, + "oom": false, + "limit_bytes": 201326592 + } + ] + }, + { + "phase": "down", + "utc": "2026-11-05T22:54:48Z", + "api_memory": "146415616", + "worker_memory": "10653696", + "collector_memory": "219734016", + "queue_logs": "0", + "queue_traces": "15248", + "accepted_logs": "0", + "receiver_failed": "0", + "api_error_5m": "0", + "api_p99": "NaN", + "api": [ + { + "name": "mtusi-messenger-lab6-api-1", + "status": "running", + "restarts": 0, + "oom": false, + "limit_bytes": 268435456 + }, + { + "name": "mtusi-messenger-lab6-api-2", + "status": "running", + "restarts": 0, + "oom": false, + "limit_bytes": 268435456 + } + ], + "collector": [ + { + "name": "mtusi-messenger-lab6-otel-collector-1", + "status": "running", + "restarts": 0, + "oom": false, + "limit_bytes": 201326592 + } + ] + }, + { + "phase": "down", + "utc": "2026-11-05T22:54:59Z", + "api_memory": "17170432", + "worker_memory": "10653696", + "collector_memory": "219754496", + "queue_logs": "0", + "queue_traces": "14772", + "accepted_logs": "0", + "receiver_failed": "0", + "api_error_5m": "0", + "api_p99": "NaN", + "api": [ + { + "name": "mtusi-messenger-lab6-api-1", + "status": "running", + "restarts": 0, + "oom": false, + "limit_bytes": 268435456 + }, + { + "name": "mtusi-messenger-lab6-api-2", + "status": "running", + "restarts": 0, + "oom": false, + "limit_bytes": 268435456 + } + ], + "collector": [ + { + "name": "mtusi-messenger-lab6-otel-collector-1", + "status": "running", + "restarts": 0, + "oom": false, + "limit_bytes": 201326592 + } + ] + }, + { + "phase": "down", + "utc": "2026-11-05T22:55:09Z", + "api_memory": "17481728", + "worker_memory": "10391552", + "collector_memory": "219779072", + "queue_logs": "0", + "queue_traces": "16608", + "accepted_logs": "0", + "receiver_failed": "0", + "api_error_5m": "0", + "api_p99": "NaN", + "api": [ + { + "name": "mtusi-messenger-lab6-api-1", + "status": "running", + "restarts": 0, + "oom": false, + "limit_bytes": 268435456 + }, + { + "name": "mtusi-messenger-lab6-api-2", + "status": "running", + "restarts": 0, + "oom": false, + "limit_bytes": 268435456 + } + ], + "collector": [ + { + "name": "mtusi-messenger-lab6-otel-collector-1", + "status": "running", + "restarts": 0, + "oom": false, + "limit_bytes": 201326592 + } + ] + }, + { + "phase": "down", + "utc": "2026-11-05T22:55:19Z", + "api_memory": "17481728", + "worker_memory": "10653696", + "collector_memory": "220012544", + "queue_logs": "0", + "queue_traces": "18798", + "accepted_logs": "0", + "receiver_failed": "0", + "api_error_5m": "0", + "api_p99": "NaN", + "api": [ + { + "name": "mtusi-messenger-lab6-api-1", + "status": "running", + "restarts": 0, + "oom": false, + "limit_bytes": 268435456 + }, + { + "name": "mtusi-messenger-lab6-api-2", + "status": "running", + "restarts": 0, + "oom": false, + "limit_bytes": 268435456 + } + ], + "collector": [ + { + "name": "mtusi-messenger-lab6-otel-collector-1", + "status": "running", + "restarts": 0, + "oom": false, + "limit_bytes": 201326592 + } + ] + }, + { + "phase": "down", + "utc": "2026-11-05T22:55:29Z", + "api_memory": "17731584", + "worker_memory": "10653696", + "collector_memory": "220229632", + "queue_logs": "0", + "queue_traces": "18798", + "accepted_logs": "0", + "receiver_failed": "0", + "api_error_5m": "0", + "api_p99": "NaN", + "api": [ + { + "name": "mtusi-messenger-lab6-api-1", + "status": "running", + "restarts": 0, + "oom": false, + "limit_bytes": 268435456 + }, + { + "name": "mtusi-messenger-lab6-api-2", + "status": "running", + "restarts": 0, + "oom": false, + "limit_bytes": 268435456 + } + ], + "collector": [ + { + "name": "mtusi-messenger-lab6-otel-collector-1", + "status": "running", + "restarts": 0, + "oom": false, + "limit_bytes": 201326592 + } + ] + }, + { + "phase": "down", + "utc": "2026-11-05T22:55:40Z", + "api_memory": "17502208", + "worker_memory": "10391552", + "collector_memory": "221249536", + "queue_logs": "0", + "queue_traces": "19274", + "accepted_logs": "0", + "receiver_failed": "0", + "api_error_5m": "0", + "api_p99": "NaN", + "api": [ + { + "name": "mtusi-messenger-lab6-api-1", + "status": "running", + "restarts": 0, + "oom": false, + "limit_bytes": 268435456 + }, + { + "name": "mtusi-messenger-lab6-api-2", + "status": "running", + "restarts": 0, + "oom": false, + "limit_bytes": 268435456 + } + ], + "collector": [ + { + "name": "mtusi-messenger-lab6-otel-collector-1", + "status": "running", + "restarts": 0, + "oom": false, + "limit_bytes": 201326592 + } + ] + }, + { + "phase": "down", + "utc": "2026-11-05T22:55:50Z", + "api_memory": "17502208", + "worker_memory": "10395648", + "collector_memory": "222822400", + "queue_logs": "0", + "queue_traces": "21464", + "accepted_logs": "0", + "receiver_failed": "0", + "api_error_5m": "0", + "api_p99": "NaN", + "api": [ + { + "name": "mtusi-messenger-lab6-api-1", + "status": "running", + "restarts": 0, + "oom": false, + "limit_bytes": 268435456 + }, + { + "name": "mtusi-messenger-lab6-api-2", + "status": "running", + "restarts": 0, + "oom": false, + "limit_bytes": 268435456 + } + ], + "collector": [ + { + "name": "mtusi-messenger-lab6-otel-collector-1", + "status": "running", + "restarts": 0, + "oom": false, + "limit_bytes": 201326592 + } + ] + }, + { + "phase": "down", + "utc": "2026-11-05T22:56:00Z", + "api_memory": "17547264", + "worker_memory": "10428416", + "collector_memory": "222900224", + "queue_logs": "0", + "queue_traces": "20784", + "accepted_logs": "0", + "receiver_failed": "0", + "api_error_5m": "0", + "api_p99": "NaN", + "api": [ + { + "name": "mtusi-messenger-lab6-api-1", + "status": "running", + "restarts": 0, + "oom": false, + "limit_bytes": 268435456 + }, + { + "name": "mtusi-messenger-lab6-api-2", + "status": "running", + "restarts": 0, + "oom": false, + "limit_bytes": 268435456 + } + ], + "collector": [ + { + "name": "mtusi-messenger-lab6-otel-collector-1", + "status": "running", + "restarts": 0, + "oom": false, + "limit_bytes": 201326592 + } + ] + }, + { + "phase": "down", + "utc": "2026-11-05T22:56:10Z", + "api_memory": "17551360", + "worker_memory": "10428416", + "collector_memory": "222924800", + "queue_logs": "0", + "queue_traces": "22620", + "accepted_logs": "0", + "receiver_failed": "0", + "api_error_5m": "0", + "api_p99": "NaN", + "api": [ + { + "name": "mtusi-messenger-lab6-api-1", + "status": "running", + "restarts": 0, + "oom": false, + "limit_bytes": 268435456 + }, + { + "name": "mtusi-messenger-lab6-api-2", + "status": "running", + "restarts": 0, + "oom": false, + "limit_bytes": 268435456 + } + ], + "collector": [ + { + "name": "mtusi-messenger-lab6-otel-collector-1", + "status": "running", + "restarts": 0, + "oom": false, + "limit_bytes": 201326592 + } + ] + }, + { + "phase": "down", + "utc": "2026-11-05T22:56:21Z", + "api_memory": "17371136", + "worker_memory": "10477568", + "collector_memory": "223027200", + "queue_logs": "0", + "queue_traces": "24334", + "accepted_logs": "0", + "receiver_failed": "0", + "api_error_5m": "0", + "api_p99": "NaN", + "api": [ + { + "name": "mtusi-messenger-lab6-api-1", + "status": "running", + "restarts": 0, + "oom": false, + "limit_bytes": 268435456 + }, + { + "name": "mtusi-messenger-lab6-api-2", + "status": "running", + "restarts": 0, + "oom": false, + "limit_bytes": 268435456 + } + ], + "collector": [ + { + "name": "mtusi-messenger-lab6-otel-collector-1", + "status": "running", + "restarts": 0, + "oom": false, + "limit_bytes": 201326592 + } + ] + }, + { + "phase": "down", + "utc": "2026-11-05T22:56:31Z", + "api_memory": "17371136", + "worker_memory": "10592256", + "collector_memory": "223248384", + "queue_logs": "0", + "queue_traces": "24810", + "accepted_logs": "0", + "receiver_failed": "0", + "api_error_5m": "0", + "api_p99": "NaN", + "api": [ + { + "name": "mtusi-messenger-lab6-api-1", + "status": "running", + "restarts": 0, + "oom": false, + "limit_bytes": 268435456 + }, + { + "name": "mtusi-messenger-lab6-api-2", + "status": "running", + "restarts": 0, + "oom": false, + "limit_bytes": 268435456 + } + ], + "collector": [ + { + "name": "mtusi-messenger-lab6-otel-collector-1", + "status": "running", + "restarts": 0, + "oom": false, + "limit_bytes": 201326592 + } + ] + }, + { + "phase": "down", + "utc": "2026-11-05T22:56:41Z", + "api_memory": "17129472", + "worker_memory": "10592256", + "collector_memory": "223277056", + "queue_logs": "0", + "queue_traces": "27000", + "accepted_logs": "0", + "receiver_failed": "0", + "api_error_5m": "0", + "api_p99": "NaN", + "api": [ + { + "name": "mtusi-messenger-lab6-api-1", + "status": "running", + "restarts": 0, + "oom": false, + "limit_bytes": 268435456 + }, + { + "name": "mtusi-messenger-lab6-api-2", + "status": "running", + "restarts": 0, + "oom": false, + "limit_bytes": 268435456 + } + ], + "collector": [ + { + "name": "mtusi-messenger-lab6-otel-collector-1", + "status": "running", + "restarts": 0, + "oom": false, + "limit_bytes": 201326592 + } + ] + }, + { + "phase": "down", + "utc": "2026-11-05T22:56:51Z", + "api_memory": "17141760", + "worker_memory": "10645504", + "collector_memory": "223289344", + "queue_logs": "0", + "queue_traces": "24810", + "accepted_logs": "0", + "receiver_failed": "0", + "api_error_5m": "0", + "api_p99": "NaN", + "api": [ + { + "name": "mtusi-messenger-lab6-api-1", + "status": "running", + "restarts": 0, + "oom": false, + "limit_bytes": 268435456 + }, + { + "name": "mtusi-messenger-lab6-api-2", + "status": "running", + "restarts": 0, + "oom": false, + "limit_bytes": 268435456 + } + ], + "collector": [ + { + "name": "mtusi-messenger-lab6-otel-collector-1", + "status": "running", + "restarts": 0, + "oom": false, + "limit_bytes": 201326592 + } + ] + }, + { + "phase": "down", + "utc": "2026-11-05T22:57:01Z", + "api_memory": "17141760", + "worker_memory": "10678272", + "collector_memory": "222760960", + "queue_logs": "0", + "queue_traces": "27680", + "accepted_logs": "0", + "receiver_failed": "0", + "api_error_5m": "0", + "api_p99": "NaN", + "api": [ + { + "name": "mtusi-messenger-lab6-api-1", + "status": "running", + "restarts": 0, + "oom": false, + "limit_bytes": 268435456 + }, + { + "name": "mtusi-messenger-lab6-api-2", + "status": "running", + "restarts": 0, + "oom": false, + "limit_bytes": 268435456 + } + ], + "collector": [ + { + "name": "mtusi-messenger-lab6-otel-collector-1", + "status": "running", + "restarts": 0, + "oom": false, + "limit_bytes": 201326592 + } + ] + }, + { + "phase": "down", + "utc": "2026-11-05T22:57:12Z", + "api_memory": "17432576", + "worker_memory": "10678272", + "collector_memory": "222760960", + "queue_logs": "0", + "queue_traces": "30074", + "accepted_logs": "0", + "receiver_failed": "0", + "api_error_5m": "0", + "api_p99": "NaN", + "api": [ + { + "name": "mtusi-messenger-lab6-api-1", + "status": "running", + "restarts": 0, + "oom": false, + "limit_bytes": 268435456 + }, + { + "name": "mtusi-messenger-lab6-api-2", + "status": "running", + "restarts": 0, + "oom": false, + "limit_bytes": 268435456 + } + ], + "collector": [ + { + "name": "mtusi-messenger-lab6-otel-collector-1", + "status": "running", + "restarts": 0, + "oom": false, + "limit_bytes": 201326592 + } + ] + }, + { + "phase": "recovery-start", + "utc": "2026-11-05T22:57:12Z", + "api_memory": "17432576", + "worker_memory": "10678272", + "collector_memory": "222760960", + "queue_logs": "0", + "queue_traces": "30074", + "accepted_logs": "0", + "receiver_failed": "0", + "api_error_5m": "0", + "api_p99": "NaN", + "api": [ + { + "name": "mtusi-messenger-lab6-api-1", + "status": "running", + "restarts": 0, + "oom": false, + "limit_bytes": 268435456 + }, + { + "name": "mtusi-messenger-lab6-api-2", + "status": "running", + "restarts": 0, + "oom": false, + "limit_bytes": 268435456 + } + ], + "collector": [ + { + "name": "mtusi-messenger-lab6-otel-collector-1", + "status": "running", + "restarts": 0, + "oom": false, + "limit_bytes": 201326592 + } + ] + }, + { + "phase": "recovery", + "utc": "2026-11-05T22:57:42Z", + "api_memory": "17522688", + "worker_memory": "10457088", + "collector_memory": "222773248", + "queue_logs": "0", + "queue_traces": "32740", + "accepted_logs": "0", + "receiver_failed": "0", + "api_error_5m": "0", + "api_p99": "NaN", + "api": [ + { + "name": "mtusi-messenger-lab6-api-1", + "status": "running", + "restarts": 0, + "oom": false, + "limit_bytes": 268435456 + }, + { + "name": "mtusi-messenger-lab6-api-2", + "status": "running", + "restarts": 0, + "oom": false, + "limit_bytes": 268435456 + } + ], + "collector": [ + { + "name": "mtusi-messenger-lab6-otel-collector-1", + "status": "running", + "restarts": 0, + "oom": false, + "limit_bytes": 201326592 + } + ] + } +] diff --git a/evidence/lab6/checks/trace-retry-run.txt b/evidence/lab6/checks/trace-retry-run.txt new file mode 100644 index 0000000..20e0d7b --- /dev/null +++ b/evidence/lab6/checks/trace-retry-run.txt @@ -0,0 +1,16 @@ +UTC 2026-11-05T22:44:18Z +HEAD 639582280f0cc2236dee3140207168df23cc8bf1 +$ student-tests/lab5_faults.py +permanent failure: failed/injected_failure, content 409, failed attachment not linkable, registry visible +replay: failed -> queued -> ready, one thumbnail +replay ready job: refused +replay older failed version while v2 queued: refused, state intact +v2 published after older replay refusal +replay of failed reprocess: queued projection restored, then ready at pipeline 2 +transient exhaustion: attempts=5, retry_exhausted, four retries, DLQ message present +crash after first variant: redelivered, same three variants, attempts=2 +crash after commit before ack: ready remains, redelivery is a no-op +crash after claim before side effect: requeued, attempts=2, ready +outbox gap: crash before publish recovered through the relay, outbox published, ready +lease expiry: paused worker, reaper requeued, stale attempt fenced, ready +PASS: lab5 level 4 fault injection diff --git a/evidence/lab6/checks/ttr-selector.txt b/evidence/lab6/checks/ttr-selector.txt new file mode 100644 index 0000000..9fb4423 --- /dev/null +++ b/evidence/lab6/checks/ttr-selector.txt @@ -0,0 +1,6 @@ +UTC 2026-11-05T22:40:10Z +HEAD 639582280f0cc2236dee3140207168df23cc8bf1 +$ le values +{"status":"success","data":["+Inf","1.0","10.0","120.0","2.5","20.0","30.0","300.0","5.0","60.0"]} +$ rule groups +{"status":"success","data":{"groups":[{"name":"lab6-alerts","file":"/etc/prometheus/rules/alerts.yml","rules":[{"state":"firing","name":"APIErrorBudgetFastBurn","query":"slo:api_error_ratio:1h \u003e 0.072 and slo:api_error_ratio:5m \u003e 0.072 and on () sum(increase(haproxy_backend_http_responses_total{proxy=\"api_backend\"}[5m])) \u003e= 20","duration":0,"keepFiringFor":0,"labels":{"severity":"page","slo":"api-availability"},"annotations":{"runbook":"infra/runbooks/slo-burn.md","summary":"API 5xx burn rate is above 14.4x"},"alerts":[{"labels":{"alertname":"APIErrorBudgetFastBurn","severity":"page","slo":"api-availability"},"annotations":{"runbook":"infra/runbooks/slo-burn.md","summary":"API 5xx burn rate is above 14.4x"},"state":"firing","activeAt":"2026-11-05T22:37:18.187213033Z","value":"4.236111111111111e-01"}],"health":"ok","evaluationTime":0.000478281,"lastEvaluation":"2026-11-05T22:40:06.465725113Z","type":"alerting"},{"state":"firing","name":"APIErrorBudgetSlowBurn","query":"slo:api_error_ratio:6h \u003e 0.03 and slo:api_error_ratio:30m \u003e 0.03 and on () sum(increase(haproxy_backend_http_responses_total{proxy=\"api_backend\"}[30m])) \u003e= 100","duration":0,"keepFiringFor":0,"labels":{"severity":"ticket","slo":"api-availability"},"annotations":{"runbook":"infra/runbooks/slo-burn.md","summary":"API 5xx burn rate is above 6x"},"alerts":[{"labels":{"alertname":"APIErrorBudgetSlowBurn","severity":"ticket","slo":"api-availability"},"annotations":{"runbook":"infra/runbooks/slo-burn.md","summary":"API 5xx burn rate is above 6x"},"state":"firing","activeAt":"2026-11-05T22:38:08.187213033Z","value":"4.236111111111111e-01"}],"health":"ok","evaluationTime":0.000176797,"lastEvaluation":"2026-11-05T22:40:06.466208397Z","type":"alerting"},{"state":"inactive","name":"TTRErrorBudgetFastBurn","query":"slo:job_ttr_bad_ratio:1h \u003e 0.144 and slo:job_ttr_bad_ratio:5m \u003e 0.144 and on () sum(increase(messenger_job_time_to_ready_seconds_count[5m])) + sum(increase(messenger_jobs_ttr_missed_total[5m])) \u003e= 10","duration":0,"keepFiringFor":0,"labels":{"severity":"page","slo":"time-to-ready"},"annotations":{"runbook":"infra/runbooks/queue-lag.md","summary":"Jobs are missing the 30s time-to-ready objective"},"alerts":[],"health":"ok","evaluationTime":0.00011289,"lastEvaluation":"2026-11-05T22:40:06.466387903Z","type":"alerting"},{"state":"inactive","name":"TTRErrorBudgetSlowBurn","query":"slo:job_ttr_bad_ratio:6h \u003e 0.06 and slo:job_ttr_bad_ratio:30m \u003e 0.06 and on () sum(increase(messenger_job_time_to_ready_seconds_count[30m])) + sum(increase(messenger_jobs_ttr_missed_total[30m])) \u003e= 30","duration":0,"keepFiringFor":0,"labels":{"severity":"ticket","slo":"time-to-ready"},"annotations":{"runbook":"infra/runbooks/queue-lag.md","summary":"Time-to-ready budget is burning slowly"},"alerts":[],"health":"ok","evaluationTime":0.000066325,"lastEvaluation":"2026-11-05T22:40:06.466503127Z","type":"alerting"},{"state":"inactive","name":"QueueOldestJobAgeHigh","query":"max(messenger_queue_oldest_job_age_seconds) \u003e 120","duration":600,"keepFiringFor":0,"labels":{"severity":"warning"},"annotations":{"runbook":"infra/runbooks/queue-lag.md","summary":"The oldest queued/processing job is older than 2 minutes"},"alerts":[],"health":"ok","evaluationTime":0.000030557,"lastEvaluation":"2026-11-05T22:40:06.466571245Z","type":"alerting"},{"state":"inactive","name":"QueueOldestJobAgeCritical","query":"max(messenger_queue_oldest_job_age_seconds) \u003e 600","duration":300,"keepFiringFor":0,"labels":{"severity":"page"},"annotations":{"runbook":"infra/runbooks/queue-lag.md","summary":"The oldest queued/processing job is older than 10 minutes"},"alerts":[],"health":"ok","evaluationTime":0.000023971,"lastEvaluation":"2026-11-05T22:40:06.466603552Z","type":"alerting"},{"state":"inactive","name":"QueueDepthGrowing","query":"max(rabbitmq_queue_messages_ready{queue=\"attachment.process.v1\"}) \u003e 20 and on () max(deriv(rabbitmq_queue_messages_ready{queue=\"attachment.process.v1\"}[10m])) \u003e 0","duration":600,"keepFiringFor":0,"labels":{"severity":"warning"},"annotations":{"runbook":"infra/runbooks/queue-lag.md","summary":"RabbitMQ ready depth is growing"},"alerts":[],"health":"ok","evaluationTime":0.000058112,"lastEvaluation":"2026-11-05T22:40:06.466629232Z","type":"alerting"},{"state":"inactive","name":"JobsOverdue","query":"max(messenger_jobs_overdue) \u003e 0","duration":120,"keepFiringFor":0,"labels":{"severity":"warning","slo":"time-to-ready"},"annotations":{"runbook":"infra/runbooks/queue-lag.md","summary":"Jobs have been queued/processing for more than 30 seconds"},"alerts":[],"health":"ok","evaluationTime":0.000025346,"lastEvaluation":"2026-11-05T22:40:06.46668922Z","type":"alerting"},{"state":"inactive","name":"WorkerSaturated","query":"(sum(messenger_worker_busy) / clamp_min(sum(messenger_worker_capacity), 1) \u003e 0.8) and (max(messenger_queue_oldest_job_age_seconds) \u003e 120)","duration":600,"keepFiringFor":0,"labels":{"severity":"warning"},"annotations":{"runbook":"infra/runbooks/queue-lag.md","summary":"Worker slots are saturated while the queue is aging"},"alerts":[],"health":"ok","evaluationTime":0.000075204,"lastEvaluation":"2026-11-05T22:40:06.466716067Z","type":"alerting"},{"state":"inactive","name":"DBPoolSaturated","query":"((sum(rate(messenger_db_pool_empty_acquire_wait_seconds_total[5m])) / clamp_min(sum(rate(messenger_db_pool_empty_acquire_total[5m])), 0.000000001) \u003e 0.05) and (sum(rate(messenger_db_pool_empty_acquire_total[5m])) \u003e 0.1)) or (sum(messenger_db_pool_used) / clamp_min(sum(messenger_db_pool_max), 1) \u003e 0.8)","duration":300,"keepFiringFor":0,"labels":{"severity":"warning"},"annotations":{"runbook":"infra/runbooks/db-availability.md","summary":"PostgreSQL pool is waiting or nearly exhausted"},"alerts":[],"health":"ok","evaluationTime":0.000168042,"lastEvaluation":"2026-11-05T22:40:06.466793439Z","type":"alerting"},{"state":"inactive","name":"CollectorDroppedTelemetry","query":"sum(rate(otelcol_receiver_failed_spans[5m])) \u003e 0 or sum(rate(otelcol_receiver_failed_metric_points[5m])) \u003e 0 or sum(rate(otelcol_receiver_failed_log_records[5m])) \u003e 0 or sum(rate(otelcol_receiver_refused_spans[5m])) \u003e 0 or sum(rate(otelcol_receiver_refused_metric_points[5m])) \u003e 0 or sum(rate(otelcol_receiver_refused_log_records[5m])) \u003e 0 or sum(otelcol_exporter_queue_size) \u003e= sum(otelcol_exporter_queue_capacity) * 0.9","duration":300,"keepFiringFor":0,"labels":{"severity":"warning"},"annotations":{"runbook":"infra/runbooks/telemetry-backend-down.md","summary":"Collector is dropping or refusing telemetry"},"alerts":[],"health":"ok","evaluationTime":0.000185801,"lastEvaluation":"2026-11-05T22:40:06.466963691Z","type":"alerting"},{"state":"inactive","name":"TelemetryStorageDown","query":"up{job=~\"loki|tempo\"} == 0","duration":120,"keepFiringFor":0,"labels":{"component":"telemetry","severity":"warning"},"annotations":{"runbook":"infra/runbooks/telemetry-backend-down.md","summary":"Loki or Tempo is unavailable; Collector queues are bounded"},"alerts":[],"health":"ok","evaluationTime":0.000044439,"lastEvaluation":"2026-11-05T22:40:06.467151493Z","type":"alerting"},{"state":"inactive","name":"TelemetryCollectorDown","query":"up{job=\"otel-collector\"} == 0","duration":120,"keepFiringFor":0,"labels":{"component":"telemetry","severity":"warning"},"annotations":{"runbook":"infra/runbooks/telemetry-backend-down.md","summary":"OTel Collector is unavailable; application keeps running"},"alerts":[],"health":"ok","evaluationTime":0.00002989,"lastEvaluation":"2026-11-05T22:40:06.467197724Z","type":"alerting"},{"state":"inactive","name":"APISLIMissing","query":"absent(slo:api_error_ratio:5m) or up{job=\"haproxy\"} == 0","duration":120,"keepFiringFor":0,"labels":{"severity":"page"},"annotations":{"runbook":"infra/runbooks/api-errors.md","summary":"Edge availability data is missing"},"alerts":[],"health":"ok","evaluationTime":0.000041354,"lastEvaluation":"2026-11-05T22:40:06.46722974Z","type":"alerting"},{"state":"inactive","name":"QueueMetricsStale","query":"(absent(messenger_queue_oldest_job_age_seconds) or absent(messenger_jobs_accepted_total)) and on () (up{job=\"otel-collector\"} == 1)","duration":120,"keepFiringFor":0,"labels":{"severity":"warning"},"annotations":{"runbook":"infra/runbooks/queue-lag.md","summary":"Queue/backlog metrics are missing"},"alerts":[],"health":"ok","evaluationTime":0.000058112,"lastEvaluation":"2026-11-05T22:40:06.467273762Z","type":"alerting"}],"interval":5,"limit":0,"evaluationTime":0.001646906,"lastEvaluation":"2026-11-05T22:40:06.46568747Z"},{"name":"slo","file":"/etc/prometheus/rules/slo.yml","rules":[{"name":"slo:api_error_ratio:5m","query":"sum(rate(haproxy_backend_http_responses_total{code=~\"5..\",proxy=\"api_backend\"}[5m])) / clamp_min(sum(rate(haproxy_backend_http_responses_total{proxy=\"api_backend\"}[5m])), 0.001)","labels":{},"health":"ok","evaluationTime":0.000303693,"lastEvaluation":"2026-11-05T22:40:06.173494571Z","type":"recording"},{"name":"slo:api_error_ratio:1h","query":"sum(rate(haproxy_backend_http_responses_total{code=~\"5..\",proxy=\"api_backend\"}[1h])) / clamp_min(sum(rate(haproxy_backend_http_responses_total{proxy=\"api_backend\"}[1h])), 0.001)","labels":{},"health":"ok","evaluationTime":0.000135568,"lastEvaluation":"2026-11-05T22:40:06.1738031Z","type":"recording"},{"name":"slo:api_error_ratio:6h","query":"sum(rate(haproxy_backend_http_responses_total{code=~\"5..\",proxy=\"api_backend\"}[6h])) / clamp_min(sum(rate(haproxy_backend_http_responses_total{proxy=\"api_backend\"}[6h])), 0.001)","labels":{},"health":"ok","evaluationTime":0.000105427,"lastEvaluation":"2026-11-05T22:40:06.17394267Z","type":"recording"},{"name":"slo:api_error_ratio:30m","query":"sum(rate(haproxy_backend_http_responses_total{code=~\"5..\",proxy=\"api_backend\"}[30m])) / clamp_min(sum(rate(haproxy_backend_http_responses_total{proxy=\"api_backend\"}[30m])), 0.001)","labels":{},"health":"ok","evaluationTime":0.000143071,"lastEvaluation":"2026-11-05T22:40:06.174051808Z","type":"recording"},{"name":"slo:job_ttr_bad_ratio:5m","query":"sum(rate(messenger_jobs_ttr_missed_total[5m])) / clamp_min(sum(rate(messenger_job_time_to_ready_seconds_bucket{le=\"30.0\"}[5m])) + sum(rate(messenger_jobs_ttr_missed_total[5m])), 0.001) and (sum(increase(messenger_job_time_to_ready_seconds_count[5m])) + sum(increase(messenger_jobs_ttr_missed_total[5m]))) \u003e= 10","labels":{},"health":"ok","evaluationTime":0.000131982,"lastEvaluation":"2026-11-05T22:40:06.174197464Z","type":"recording"},{"name":"slo:job_ttr_bad_ratio:1h","query":"sum(rate(messenger_jobs_ttr_missed_total[1h])) / clamp_min(sum(rate(messenger_job_time_to_ready_seconds_bucket{le=\"30.0\"}[1h])) + sum(rate(messenger_jobs_ttr_missed_total[1h])), 0.001) and (sum(increase(messenger_job_time_to_ready_seconds_count[1h])) + sum(increase(messenger_jobs_ttr_missed_total[1h]))) \u003e= 10","labels":{},"health":"ok","evaluationTime":0.000168335,"lastEvaluation":"2026-11-05T22:40:06.174332365Z","type":"recording"},{"name":"slo:job_ttr_bad_ratio:6h","query":"sum(rate(messenger_jobs_ttr_missed_total[6h])) / clamp_min(sum(rate(messenger_job_time_to_ready_seconds_bucket{le=\"30.0\"}[6h])) + sum(rate(messenger_jobs_ttr_missed_total[6h])), 0.001) and (sum(increase(messenger_job_time_to_ready_seconds_count[6h])) + sum(increase(messenger_jobs_ttr_missed_total[6h]))) \u003e= 30","labels":{},"health":"ok","evaluationTime":0.000134526,"lastEvaluation":"2026-11-05T22:40:06.174503825Z","type":"recording"},{"name":"slo:job_ttr_bad_ratio:30m","query":"sum(rate(messenger_jobs_ttr_missed_total[30m])) / clamp_min(sum(rate(messenger_job_time_to_ready_seconds_bucket{le=\"30.0\"}[30m])) + sum(rate(messenger_jobs_ttr_missed_total[30m])), 0.001) and (sum(increase(messenger_job_time_to_ready_seconds_count[30m])) + sum(increase(messenger_jobs_ttr_missed_total[30m]))) \u003e= 30","labels":{},"health":"ok","evaluationTime":0.000105302,"lastEvaluation":"2026-11-05T22:40:06.174640602Z","type":"recording"}],"interval":5,"limit":0,"evaluationTime":0.001286977,"lastEvaluation":"2026-11-05T22:40:06.173461971Z"},{"name":"slo-long","file":"/etc/prometheus/rules/slo.yml","rules":[{"name":"slo:api_error_ratio:7d","query":"sum(rate(haproxy_backend_http_responses_total{code=~\"5..\",proxy=\"api_backend\"}[1w])) / clamp_min(sum(rate(haproxy_backend_http_responses_total{proxy=\"api_backend\"}[1w])), 0.001)","labels":{},"health":"ok","evaluationTime":0.000370647,"lastEvaluation":"2026-11-05T22:39:50.739434913Z","type":"recording"},{"name":"slo:api_budget_remaining:7d","query":"clamp(1 - (slo:api_error_ratio:7d / 0.005), 0, 1)","labels":{},"health":"ok","evaluationTime":0.000064142,"lastEvaluation":"2026-11-05T22:39:50.739811034Z","type":"recording"}],"interval":60,"limit":0,"evaluationTime":0.000491703,"lastEvaluation":"2026-11-05T22:39:50.739385396Z"}]}} \ No newline at end of file diff --git a/evidence/lab6/checks/ttr-worker-15m.txt b/evidence/lab6/checks/ttr-worker-15m.txt new file mode 100644 index 0000000..5f06047 --- /dev/null +++ b/evidence/lab6/checks/ttr-worker-15m.txt @@ -0,0 +1,47 @@ +UTC 2026-11-06T00:30:14Z +HEAD 935b228d0b55ac60d00cdc855218ec45e20f2530 +$ /api/v1/rules (contains or vector(0)) +or_vector_0= True +json_len= 12780 +$ pre ALERTS [] +$ stop worker + +t=30s ratio5=MISSING ratio1h=MISSING missed_total=100 missed_inc5=0 bucket_count=10 overdue=0 oldest=12.610594 alerts=[] +t=60s ratio5=MISSING ratio1h=MISSING missed_total=100 missed_inc5=0 bucket_count=10 overdue=3 oldest=42.61288 alerts=[["JobsOverdue", "pending"]] +t=90s ratio5=MISSING ratio1h=MISSING missed_total=106 missed_inc5=6.2756181818181815 bucket_count=10 overdue=9 oldest=72.614253 alerts=[["JobsOverdue", "pending"]] +t=120s ratio5=0.923076923076923 ratio1h=0.9230769230769231 missed_total=112 missed_inc5=12.435503224838758 bucket_count=10 overdue=15 oldest=102.611122 alerts=[["TTRErrorBudgetFastBurn", "firing"], ["QueueDepthGrowing", "pending"], ["JobsOverdue", "pending"]] +t=150s ratio5=0.9473684210526316 ratio1h=0.9473684210526315 missed_total=118 missed_inc5=18.549592785748487 bucket_count=10 overdue=23 oldest=132.508928 alerts=[["TTRErrorBudgetFastBurn", "firing"], ["QueueOldestJobAgeHigh", "pending"], ["QueueDepthGrowing", "pending"], ["JobsOverdue", "pending"]] +t=180s ratio5=0.962962962962963 ratio1h=0.962962962962963 missed_total=126 missed_inc5=26.679560826021273 bucket_count=10 overdue=29 oldest=162.508223 alerts=[["TTRErrorBudgetFastBurn", "firing"], ["QueueOldestJobAgeHigh", "pending"], ["QueueDepthGrowing", "pending"], ["JobsOverdue", "firing"]] +t=210s ratio5=0.9696969696969697 ratio1h=0.9696969696969698 missed_total=132 missed_inc5=32.73157721245076 bucket_count=10 overdue=35 oldest=192.509517 alerts=[["TTRErrorBudgetFastBurn", "firing"], ["TTRErrorBudgetSlowBurn", "firing"], ["QueueOldestJobAgeHigh", "pending"], ["QueueDepthGrowing", "pending"], ["JobsOverdue", "firing"]] +t=240s ratio5=0.9743589743589745 ratio1h=0.9743589743589743 missed_total=138 missed_inc5=38.77170399329681 bucket_count=10 overdue=43 oldest=222.509683 alerts=[["TTRErrorBudgetFastBurn", "firing"], ["TTRErrorBudgetSlowBurn", "firing"], ["QueueOldestJobAgeHigh", "pending"], ["QueueDepthGrowing", "pending"], ["JobsOverdue", "firing"]] +t=270s ratio5=0.9787234042553192 ratio1h=0.9787234042553192 missed_total=146 missed_inc5=46.84163777134747 bucket_count=10 overdue=49 oldest=252.509732 alerts=[["TTRErrorBudgetFastBurn", "firing"], ["TTRErrorBudgetSlowBurn", "firing"], ["QueueOldestJobAgeHigh", "pending"], ["QueueDepthGrowing", "pending"], ["JobsOverdue", "firing"]] +t=300s ratio5=0.9811320754716981 ratio1h=0.9811320754716981 missed_total=152 missed_inc5=52.8994672752366 bucket_count=10 overdue=55 oldest=282.510069 alerts=[["TTRErrorBudgetFastBurn", "firing"], ["TTRErrorBudgetSlowBurn", "firing"], ["QueueOldestJobAgeHigh", "pending"], ["QueueDepthGrowing", "pending"], ["JobsOverdue", "firing"]] +t=330s ratio5=1 ratio1h=0.9829645869209094 missed_total=158 missed_inc5=59.00325196084083 bucket_count=MISSING overdue=63 oldest=312.51145 alerts=[["TTRErrorBudgetFastBurn", "firing"], ["TTRErrorBudgetSlowBurn", "firing"], ["QueueOldestJobAgeHigh", "pending"], ["QueueDepthGrowing", "pending"], ["JobsOverdue", "firing"]] +t=360s ratio5=1 ratio1h=0.9849866155016431 missed_total=166 missed_inc5=67.14185921911984 bucket_count=MISSING overdue=69 oldest=342.509047 alerts=[["TTRErrorBudgetFastBurn", "firing"], ["TTRErrorBudgetSlowBurn", "firing"], ["QueueOldestJobAgeHigh", "pending"], ["QueueDepthGrowing", "pending"], ["JobsOverdue", "firing"]] +t=390s ratio5=1 ratio1h=0.9862112005033712 missed_total=172 missed_inc5=67.14163154164646 bucket_count=MISSING overdue=75 oldest=372.509037 alerts=[["TTRErrorBudgetFastBurn", "firing"], ["TTRErrorBudgetSlowBurn", "firing"], ["QueueOldestJobAgeHigh", "pending"], ["QueueDepthGrowing", "pending"], ["JobsOverdue", "firing"]] +t=420s ratio5=1 ratio1h=0.9872508295058324 missed_total=178 missed_inc5=67.14185921911984 bucket_count=MISSING overdue=83 oldest=402.510244 alerts=[["TTRErrorBudgetFastBurn", "firing"], ["TTRErrorBudgetSlowBurn", "firing"], ["QueueOldestJobAgeHigh", "pending"], ["QueueDepthGrowing", "pending"], ["JobsOverdue", "firing"]] +t=450s ratio5=1 ratio1h=0.9884172689944903 missed_total=186 missed_inc5=69.15254237288136 bucket_count=MISSING overdue=89 oldest=432.509801 alerts=[["TTRErrorBudgetFastBurn", "firing"], ["TTRErrorBudgetSlowBurn", "firing"], ["QueueOldestJobAgeHigh", "pending"], ["QueueDepthGrowing", "pending"], ["JobsOverdue", "firing"]] +t=480s ratio5=1 ratio1h=0.9891595307016704 missed_total=192 missed_inc5=67.11750648294097 bucket_count=MISSING overdue=95 oldest=462.508192 alerts=[["TTRErrorBudgetFastBurn", "firing"], ["TTRErrorBudgetSlowBurn", "firing"], ["QueueOldestJobAgeHigh", "pending"], ["QueueDepthGrowing", "pending"], ["JobsOverdue", "firing"]] +t=510s ratio5=1 ratio1h=0.9898124841753306 missed_total=198 missed_inc5=67.11864406779661 bucket_count=MISSING overdue=103 oldest=492.508813 alerts=[["TTRErrorBudgetFastBurn", "firing"], ["TTRErrorBudgetSlowBurn", "firing"], ["QueueOldestJobAgeHigh", "pending"], ["QueueDepthGrowing", "pending"], ["JobsOverdue", "firing"]] +t=540s ratio5=1 ratio1h=0.9905707750128784 missed_total=206 missed_inc5=69.15207354526409 bucket_count=MISSING overdue=109 oldest=522.508408 alerts=[["TTRErrorBudgetFastBurn", "firing"], ["TTRErrorBudgetSlowBurn", "firing"], ["QueueOldestJobAgeHigh", "pending"], ["QueueDepthGrowing", "pending"], ["JobsOverdue", "firing"]] +t=570s ratio5=1 ratio1h=0.9910685528663303 missed_total=212 missed_inc5=67.14185921911982 bucket_count=MISSING overdue=115 oldest=552.510401 alerts=[["TTRErrorBudgetFastBurn", "firing"], ["TTRErrorBudgetSlowBurn", "firing"], ["QueueOldestJobAgeHigh", "pending"], ["QueueDepthGrowing", "pending"], ["JobsOverdue", "firing"]] +t=600s ratio5=1 ratio1h=0.9915177473866992 missed_total=218 missed_inc5=67.14254226080469 bucket_count=MISSING overdue=123 oldest=582.406662 alerts=[["TTRErrorBudgetFastBurn", "firing"], ["TTRErrorBudgetSlowBurn", "firing"], ["QueueOldestJobAgeHigh", "pending"], ["QueueDepthGrowing", "pending"], ["JobsOverdue", "firing"]] +t=630s ratio5=1 ratio1h=0.9920498972652931 missed_total=226 missed_inc5=69.17622643684787 bucket_count=MISSING overdue=129 oldest=612.40958 alerts=[["TTRErrorBudgetFastBurn", "firing"], ["TTRErrorBudgetSlowBurn", "firing"], ["QueueOldestJobAgeHigh", "pending"], ["QueueOldestJobAgeCritical", "pending"], ["QueueDepthGrowing", "pending"], ["JobsOverdue", "firing"]] +t=660s ratio5=1 ratio1h=0.9924066715178286 missed_total=232 missed_inc5=67.14163154164646 bucket_count=MISSING overdue=135 oldest=642.40658 alerts=[["TTRErrorBudgetFastBurn", "firing"], ["TTRErrorBudgetSlowBurn", "firing"], ["QueueOldestJobAgeHigh", "pending"], ["QueueOldestJobAgeCritical", "pending"], ["QueueDepthGrowing", "pending"], ["JobsOverdue", "firing"]] +t=690s ratio5=1 ratio1h=0.9927327859192547 missed_total=238 missed_inc5=67.14276994445463 bucket_count=MISSING overdue=143 oldest=672.408057 alerts=[["TTRErrorBudgetFastBurn", "firing"], ["TTRErrorBudgetSlowBurn", "firing"], ["QueueOldestJobAgeHigh", "pending"], ["QueueOldestJobAgeCritical", "pending"], ["QueueDepthGrowing", "pending"], ["JobsOverdue", "firing"]] +t=720s ratio5=1 ratio1h=0.9931268165094485 missed_total=246 missed_inc5=69.17528814559364 bucket_count=MISSING overdue=149 oldest=702.408433 alerts=[["TTRErrorBudgetFastBurn", "firing"], ["TTRErrorBudgetSlowBurn", "firing"], ["QueueOldestJobAgeHigh", "pending"], ["QueueOldestJobAgeCritical", "pending"], ["QueueDepthGrowing", "firing"], ["JobsOverdue", "firing"]] +t=750s ratio5=1 ratio1h=0.9933950961225724 missed_total=252 missed_inc5=67.14163154164646 bucket_count=MISSING overdue=155 oldest=732.408746 alerts=[["TTRErrorBudgetFastBurn", "firing"], ["TTRErrorBudgetSlowBurn", "firing"], ["QueueOldestJobAgeHigh", "firing"], ["QueueOldestJobAgeCritical", "pending"], ["QueueDepthGrowing", "firing"], ["JobsOverdue", "firing"]] +t=780s ratio5=1 ratio1h=0.993643194764043 missed_total=258 missed_inc5=67.14185921911982 bucket_count=MISSING overdue=163 oldest=762.409049 alerts=[["TTRErrorBudgetFastBurn", "firing"], ["TTRErrorBudgetSlowBurn", "firing"], ["QueueOldestJobAgeHigh", "firing"], ["QueueOldestJobAgeCritical", "pending"], ["QueueDepthGrowing", "firing"], ["JobsOverdue", "firing"]] +t=810s ratio5=1 ratio1h=0.9939467049022863 missed_total=266 missed_inc5=69.17622643684787 bucket_count=MISSING overdue=169 oldest=792.41206 alerts=[["TTRErrorBudgetFastBurn", "firing"], ["TTRErrorBudgetSlowBurn", "firing"], ["QueueOldestJobAgeHigh", "firing"], ["QueueOldestJobAgeCritical", "pending"], ["QueueDepthGrowing", "firing"], ["JobsOverdue", "firing"]] +t=840s ratio5=1 ratio1h=0.9941557453893992 missed_total=272 missed_inc5=67.14163154164646 bucket_count=MISSING overdue=175 oldest=822.407542 alerts=[["TTRErrorBudgetFastBurn", "firing"], ["TTRErrorBudgetSlowBurn", "firing"], ["QueueOldestJobAgeHigh", "firing"], ["QueueOldestJobAgeCritical", "pending"], ["QueueDepthGrowing", "firing"], ["JobsOverdue", "firing"]] +t=870s ratio5=1 ratio1h=0.9943508304157103 missed_total=278 missed_inc5=67.11932663722003 bucket_count=MISSING overdue=183 oldest=852.407439 alerts=[["TTRErrorBudgetFastBurn", "firing"], ["TTRErrorBudgetSlowBurn", "firing"], ["QueueOldestJobAgeHigh", "firing"], ["QueueOldestJobAgeCritical", "pending"], ["QueueDepthGrowing", "firing"], ["JobsOverdue", "firing"]] +t=900s ratio5=1 ratio1h=0.9945917759853372 missed_total=286 missed_inc5=69.15230795827812 bucket_count=MISSING overdue=189 oldest=882.407004 alerts=[["TTRErrorBudgetFastBurn", "firing"], ["TTRErrorBudgetSlowBurn", "firing"], ["QueueOldestJobAgeHigh", "firing"], ["QueueOldestJobAgeCritical", "pending"], ["QueueDepthGrowing", "firing"], ["JobsOverdue", "firing"]] +t=930s ratio5=1 ratio1h=0.9947592532907682 missed_total=292 missed_inc5=67.11841654774052 bucket_count=MISSING overdue=195 oldest=912.40742 alerts=[["TTRErrorBudgetFastBurn", "firing"], ["TTRErrorBudgetSlowBurn", "firing"], ["QueueOldestJobAgeHigh", "firing"], ["QueueOldestJobAgeCritical", "firing"], ["QueueDepthGrowing", "firing"], ["JobsOverdue", "firing"]] +$ start worker + +recovery t=30s ratio5=1 ratio1h=0.8602719300487442 missed_total=300 overdue=0 oldest=0 alerts=[["TTRErrorBudgetFastBurn", "firing"], ["TTRErrorBudgetSlowBurn", "firing"]] +recovery t=60s ratio5=0.46027848712991326 ratio1h=0.6701622041415539 missed_total=300 overdue=0 oldest=0 alerts=[["TTRErrorBudgetFastBurn", "firing"], ["TTRErrorBudgetSlowBurn", "firing"]] +recovery t=120s ratio5=0.28651555183796223 ratio1h=0.5530347475575486 missed_total=300 overdue=0 oldest=0 alerts=[["TTRErrorBudgetFastBurn", "firing"], ["TTRErrorBudgetSlowBurn", "firing"]] +recovery t=180s ratio5=0.19892599842282524 ratio1h=0.4741651045063767 missed_total=300 overdue=0 oldest=0 alerts=[["TTRErrorBudgetFastBurn", "firing"], ["TTRErrorBudgetSlowBurn", "firing"]] +recovery t=240s ratio5=0.14269663063401883 ratio1h=0.4150096929787228 missed_total=300 overdue=0 oldest=0 alerts=[["TTRErrorBudgetSlowBurn", "firing"]] +recovery t=300s ratio5=0.09905644731015488 ratio1h=0.3703642198471703 missed_total=300 overdue=0 oldest=0 alerts=[["TTRErrorBudgetSlowBurn", "firing"]] diff --git a/evidence/lab6/checks/ttr-worker-down.txt b/evidence/lab6/checks/ttr-worker-down.txt new file mode 100644 index 0000000..1317516 --- /dev/null +++ b/evidence/lab6/checks/ttr-worker-down.txt @@ -0,0 +1,28 @@ +UTC 2026-11-05T22:40:16Z +HEAD 639582280f0cc2236dee3140207168df23cc8bf1 +$ load + stop worker + Container mtusi-messenger-lab6-worker-1 Stopping + Container mtusi-messenger-lab6-worker-1 Stopped +$ ttr ratio during outage +{"status":"success","data":{"resultType":"vector","result":[{"metric":{"__name__":"slo:job_ttr_bad_ratio:5m"},"value":[1793918511.951,"0.6265581574633149"]}]}} +$ alerts during outage +[('TTRErrorBudgetFastBurn', 'firing')] +$ start worker + Container mtusi-messenger-lab6-seaweedfs-1 Waiting + Container mtusi-messenger-lab6-postgres-1 Waiting + Container mtusi-messenger-lab6-postgres-1 Healthy + Container mtusi-messenger-lab6-seaweedfs-1 Healthy + Container mtusi-messenger-lab6-migrate-1 Starting + Container mtusi-messenger-lab6-s3-init-1 Starting + Container mtusi-messenger-lab6-migrate-1 Started + Container mtusi-messenger-lab6-s3-init-1 Started + Container mtusi-messenger-lab6-broker-1 Waiting + Container mtusi-messenger-lab6-postgres-1 Waiting + Container mtusi-messenger-lab6-migrate-1 Waiting + Container mtusi-messenger-lab6-s3-init-1 Waiting + Container mtusi-messenger-lab6-migrate-1 Exited + Container mtusi-messenger-lab6-postgres-1 Healthy + Container mtusi-messenger-lab6-s3-init-1 Exited + Container mtusi-messenger-lab6-broker-1 Healthy + Container mtusi-messenger-lab6-worker-1 Starting + Container mtusi-messenger-lab6-worker-1 Started diff --git a/evidence/lab6/collector-down.txt b/evidence/lab6/collector-down.txt new file mode 100644 index 0000000..c716df0 --- /dev/null +++ b/evidence/lab6/collector-down.txt @@ -0,0 +1,78 @@ +UTC 2026-11-06T13:51:07Z +HEAD 255f601a9946187c4c330828426c6458a89aad2b +pre_alerts= [] +$ docker compose ps -a +NAME IMAGE COMMAND SERVICE CREATED STATUS PORTS +mtusi-messenger-lab6-api-1 mtusi-messenger:lab6 "/usr/local/bin/mess…" api 5 hours ago Up 5 hours (healthy) 8080/tcp +mtusi-messenger-lab6-api-2 mtusi-messenger:lab6 "/usr/local/bin/mess…" api 5 hours ago Up 5 hours (healthy) 8080/tcp +mtusi-messenger-lab6-broker-1 rabbitmq:4.3.7-management-alpine@sha256:1528a88eebf2bc4d0ab7e9d5d9bc542e9bdf5e1b105e65848fcf8de5c2186528 "docker-entrypoint.s…" broker 5 hours ago Up 25 minutes (healthy) 4369/tcp, 5671-5672/tcp, 15671/tcp, 15691-15692/tcp, 25672/tcp, 127.0.0.1:15672->15672/tcp +mtusi-messenger-lab6-grafana-1 grafana/grafana:13.2.5@sha256:9f7aa1e1e3246aade5792d35a738049f7f32f89cd51d1956cf426a4e86268a84 "/run.sh" grafana 5 hours ago Up 5 hours (healthy) 127.0.0.1:3000->3000/tcp +mtusi-messenger-lab6-lb-1 haproxy:3.2-alpine@sha256:254e6370f01cd654e0744edf607c67f33777c1b6a9dc0d4b28bcba7171460122 "docker-entrypoint.s…" lb 5 hours ago Up 5 hours 127.0.0.1:8404->8404/tcp, 127.0.0.1:8080->80/tcp +mtusi-messenger-lab6-loki-1 grafana/loki:3.6.4@sha256:be31579ac047e9f78b81e48f3b69d3af709e7299b431d5aa78bcda43382f9511 "/usr/bin/loki -conf…" loki 5 hours ago Up 5 hours 127.0.0.1:3100->3100/tcp +mtusi-messenger-lab6-migrate-1 mtusi-messenger:lab6 "/usr/local/bin/migr…" migrate 5 hours ago Exited (0) 19 minutes ago +mtusi-messenger-lab6-otel-collector-1 otel/opentelemetry-collector-contrib:0.164.0@sha256:340c9ca6a36617084c6661bdc4f0fe92b7cda5a805d61673ec8db375fddc522b "/otelcol-contrib --…" otel-collector 5 hours ago Up 5 hours 4317-4318/tcp, 55679/tcp +mtusi-messenger-lab6-postgres-1 postgres:18-alpine@sha256:77f585114c32fbca283dc835b0596f4e52b51b4c6662d7810b2f4084f60a1873 "docker-entrypoint.s…" postgres 5 hours ago Up 2 hours (healthy) 5432/tcp +mtusi-messenger-lab6-prometheus-1 prom/prometheus:v3.15.1@sha256:fa3302279710be2f21a8301ec17a8b4f2301fd829bd113839b3b6b02b6f191a2 "/bin/prometheus --c…" prometheus 46 seconds ago Up 45 seconds (healthy) 127.0.0.1:9090->9090/tcp +mtusi-messenger-lab6-redis-1 redis:7.4-alpine@sha256:858f009f9709ce576febc734aa78b8f6d624b82571f9ddb6bda4377c833b3499 "docker-entrypoint.s…" redis 5 hours ago Up 5 hours (healthy) 6379/tcp +mtusi-messenger-lab6-relay-1 mtusi-messenger:lab6 "/usr/local/bin/relay" relay 17 minutes ago Up 17 minutes (healthy) 8080/tcp, 127.0.0.1:8082->8082/tcp +mtusi-messenger-lab6-s3-init-1 mtusi-messenger:lab6 "/usr/local/bin/s3in…" s3-init 5 hours ago Exited (0) 19 minutes ago +mtusi-messenger-lab6-seaweedfs-1 chrislusf/seaweedfs:3.80@sha256:1055999e08eed1789b0ae45d235126e4495e23d3fb9d6396293fd42539b1ae6a "/entrypoint.sh serv…" seaweedfs 5 hours ago Up 5 hours (healthy) 7333/tcp, 8080/tcp, 8888/tcp, 9333/tcp, 18080/tcp, 18888/tcp, 19333/tcp, 127.0.0.1:8333->8333/tcp +mtusi-messenger-lab6-tempo-1 grafana/tempo:2.9.0@sha256:65a5789759435f1ef696f1953258b9bbdb18eb571d5ce711ff812d2e128288a4 "/tempo -config.file…" tempo 5 hours ago Up 5 hours 127.0.0.1:3200->3200/tcp +mtusi-messenger-lab6-worker-1 mtusi-messenger:lab6 "/usr/local/bin/work…" worker 17 minutes ago Up 17 minutes (healthy) 8080/tcp, 127.0.0.1:8081->8081/tcp + +$ docker compose stop otel-collector + +down t=30s up=0 api_p99=NaN api_error_5m=0 queue_logs=MISSING queue_traces=MISSING alerts=[["TelemetryCollectorDown", "pending"]] +down t=60s up=0 api_p99=NaN api_error_5m=0 queue_logs=MISSING queue_traces=MISSING alerts=[["TelemetryCollectorDown", "pending"]] +down t=90s up=0 api_p99=NaN api_error_5m=0 queue_logs=MISSING queue_traces=MISSING alerts=[["TelemetryCollectorDown", "pending"]] +down t=120s up=0 api_p99=NaN api_error_5m=0 queue_logs=MISSING queue_traces=MISSING alerts=[["TelemetryCollectorDown", "pending"]] +down t=150s up=0 api_p99=NaN api_error_5m=0 queue_logs=MISSING queue_traces=MISSING alerts=[["TelemetryCollectorDown", "firing"]] +down t=180s up=0 api_p99=NaN api_error_5m=0 queue_logs=MISSING queue_traces=MISSING alerts=[["TelemetryCollectorDown", "firing"]] +down t=210s up=0 api_p99=NaN api_error_5m=0 queue_logs=MISSING queue_traces=MISSING alerts=[["TelemetryCollectorDown", "firing"]] +down t=240s up=0 api_p99=NaN api_error_5m=0 queue_logs=MISSING queue_traces=MISSING alerts=[["TelemetryCollectorDown", "firing"]] +down t=270s up=0 api_p99=NaN api_error_5m=0 queue_logs=MISSING queue_traces=MISSING alerts=[["TelemetryCollectorDown", "firing"]] +down t=300s up=0 api_p99=MISSING api_error_5m=0 queue_logs=MISSING queue_traces=MISSING alerts=[["TelemetryCollectorDown", "firing"]] +$ docker compose ps -a (down) +NAME IMAGE COMMAND SERVICE CREATED STATUS PORTS +mtusi-messenger-lab6-api-1 mtusi-messenger:lab6 "/usr/local/bin/mess…" api 5 hours ago Up 5 hours (healthy) 8080/tcp +mtusi-messenger-lab6-api-2 mtusi-messenger:lab6 "/usr/local/bin/mess…" api 5 hours ago Up 5 hours (healthy) 8080/tcp +mtusi-messenger-lab6-broker-1 rabbitmq:4.3.7-management-alpine@sha256:1528a88eebf2bc4d0ab7e9d5d9bc542e9bdf5e1b105e65848fcf8de5c2186528 "docker-entrypoint.s…" broker 5 hours ago Up 30 minutes (healthy) 4369/tcp, 5671-5672/tcp, 15671/tcp, 15691-15692/tcp, 25672/tcp, 127.0.0.1:15672->15672/tcp +mtusi-messenger-lab6-grafana-1 grafana/grafana:13.2.5@sha256:9f7aa1e1e3246aade5792d35a738049f7f32f89cd51d1956cf426a4e86268a84 "/run.sh" grafana 5 hours ago Up 5 hours (healthy) 127.0.0.1:3000->3000/tcp +mtusi-messenger-lab6-lb-1 haproxy:3.2-alpine@sha256:254e6370f01cd654e0744edf607c67f33777c1b6a9dc0d4b28bcba7171460122 "docker-entrypoint.s…" lb 5 hours ago Up 5 hours 127.0.0.1:8404->8404/tcp, 127.0.0.1:8080->80/tcp +mtusi-messenger-lab6-loki-1 grafana/loki:3.6.4@sha256:be31579ac047e9f78b81e48f3b69d3af709e7299b431d5aa78bcda43382f9511 "/usr/bin/loki -conf…" loki 5 hours ago Up 5 hours 127.0.0.1:3100->3100/tcp +mtusi-messenger-lab6-migrate-1 mtusi-messenger:lab6 "/usr/local/bin/migr…" migrate 5 hours ago Exited (0) 24 minutes ago +mtusi-messenger-lab6-otel-collector-1 otel/opentelemetry-collector-contrib:0.164.0@sha256:340c9ca6a36617084c6661bdc4f0fe92b7cda5a805d61673ec8db375fddc522b "/otelcol-contrib --…" otel-collector 5 hours ago Exited (0) 5 minutes ago +mtusi-messenger-lab6-postgres-1 postgres:18-alpine@sha256:77f585114c32fbca283dc835b0596f4e52b51b4c6662d7810b2f4084f60a1873 "docker-entrypoint.s…" postgres 5 hours ago Up 2 hours (healthy) 5432/tcp +mtusi-messenger-lab6-prometheus-1 prom/prometheus:v3.15.1@sha256:fa3302279710be2f21a8301ec17a8b4f2301fd829bd113839b3b6b02b6f191a2 "/bin/prometheus --c…" prometheus 5 minutes ago Up 5 minutes (healthy) 127.0.0.1:9090->9090/tcp +mtusi-messenger-lab6-redis-1 redis:7.4-alpine@sha256:858f009f9709ce576febc734aa78b8f6d624b82571f9ddb6bda4377c833b3499 "docker-entrypoint.s…" redis 5 hours ago Up 5 hours (healthy) 6379/tcp +mtusi-messenger-lab6-relay-1 mtusi-messenger:lab6 "/usr/local/bin/relay" relay 22 minutes ago Up 22 minutes (healthy) 8080/tcp, 127.0.0.1:8082->8082/tcp +mtusi-messenger-lab6-s3-init-1 mtusi-messenger:lab6 "/usr/local/bin/s3in…" s3-init 5 hours ago Exited (0) 24 minutes ago +mtusi-messenger-lab6-seaweedfs-1 chrislusf/seaweedfs:3.80@sha256:1055999e08eed1789b0ae45d235126e4495e23d3fb9d6396293fd42539b1ae6a "/entrypoint.sh serv…" seaweedfs 5 hours ago Up 5 hours (healthy) 7333/tcp, 8080/tcp, 8888/tcp, 9333/tcp, 18080/tcp, 18888/tcp, 19333/tcp, 127.0.0.1:8333->8333/tcp +mtusi-messenger-lab6-tempo-1 grafana/tempo:2.9.0@sha256:65a5789759435f1ef696f1953258b9bbdb18eb571d5ce711ff812d2e128288a4 "/tempo -config.file…" tempo 5 hours ago Up 5 hours 127.0.0.1:3200->3200/tcp +mtusi-messenger-lab6-worker-1 mtusi-messenger:lab6 "/usr/local/bin/work…" worker 22 minutes ago Up 22 minutes (healthy) 8080/tcp, 127.0.0.1:8081->8081/tcp + +$ docker compose start otel-collector + +recovery t=30s up=1 api_p99=0.02425 api_error_5m=0 queue_logs=0 queue_traces=0 alerts=[] +telemetry alerts inactive +load_exit= 0 +load_summary= {"counters": {"accepted": 27, "ready": 27, "failed": 0, "messages": 105, "uploads": 27, "dropped": 0}, "failures": 0, "failures_by_reason": {}, "duration_s": 655.01} +$ docker compose ps -a (final) +NAME IMAGE COMMAND SERVICE CREATED STATUS PORTS +mtusi-messenger-lab6-api-1 mtusi-messenger:lab6 "/usr/local/bin/mess…" api 5 hours ago Up 5 hours (healthy) 8080/tcp +mtusi-messenger-lab6-api-2 mtusi-messenger:lab6 "/usr/local/bin/mess…" api 5 hours ago Up 5 hours (healthy) 8080/tcp +mtusi-messenger-lab6-broker-1 rabbitmq:4.3.7-management-alpine@sha256:1528a88eebf2bc4d0ab7e9d5d9bc542e9bdf5e1b105e65848fcf8de5c2186528 "docker-entrypoint.s…" broker 5 hours ago Up 35 minutes (healthy) 4369/tcp, 5671-5672/tcp, 15671/tcp, 15691-15692/tcp, 25672/tcp, 127.0.0.1:15672->15672/tcp +mtusi-messenger-lab6-grafana-1 grafana/grafana:13.2.5@sha256:9f7aa1e1e3246aade5792d35a738049f7f32f89cd51d1956cf426a4e86268a84 "/run.sh" grafana 5 hours ago Up 5 hours (healthy) 127.0.0.1:3000->3000/tcp +mtusi-messenger-lab6-lb-1 haproxy:3.2-alpine@sha256:254e6370f01cd654e0744edf607c67f33777c1b6a9dc0d4b28bcba7171460122 "docker-entrypoint.s…" lb 5 hours ago Up 5 hours 127.0.0.1:8404->8404/tcp, 127.0.0.1:8080->80/tcp +mtusi-messenger-lab6-loki-1 grafana/loki:3.6.4@sha256:be31579ac047e9f78b81e48f3b69d3af709e7299b431d5aa78bcda43382f9511 "/usr/bin/loki -conf…" loki 5 hours ago Up 5 hours 127.0.0.1:3100->3100/tcp +mtusi-messenger-lab6-migrate-1 mtusi-messenger:lab6 "/usr/local/bin/migr…" migrate 5 hours ago Exited (0) 30 minutes ago +mtusi-messenger-lab6-otel-collector-1 otel/opentelemetry-collector-contrib:0.164.0@sha256:340c9ca6a36617084c6661bdc4f0fe92b7cda5a805d61673ec8db375fddc522b "/otelcol-contrib --…" otel-collector 5 hours ago Up 5 minutes 4317-4318/tcp, 55679/tcp +mtusi-messenger-lab6-postgres-1 postgres:18-alpine@sha256:77f585114c32fbca283dc835b0596f4e52b51b4c6662d7810b2f4084f60a1873 "docker-entrypoint.s…" postgres 5 hours ago Up 2 hours (healthy) 5432/tcp +mtusi-messenger-lab6-prometheus-1 prom/prometheus:v3.15.1@sha256:fa3302279710be2f21a8301ec17a8b4f2301fd829bd113839b3b6b02b6f191a2 "/bin/prometheus --c…" prometheus 11 minutes ago Up 11 minutes (healthy) 127.0.0.1:9090->9090/tcp +mtusi-messenger-lab6-redis-1 redis:7.4-alpine@sha256:858f009f9709ce576febc734aa78b8f6d624b82571f9ddb6bda4377c833b3499 "docker-entrypoint.s…" redis 5 hours ago Up 5 hours (healthy) 6379/tcp +mtusi-messenger-lab6-relay-1 mtusi-messenger:lab6 "/usr/local/bin/relay" relay 28 minutes ago Up 28 minutes (healthy) 8080/tcp, 127.0.0.1:8082->8082/tcp +mtusi-messenger-lab6-s3-init-1 mtusi-messenger:lab6 "/usr/local/bin/s3in…" s3-init 5 hours ago Exited (0) 30 minutes ago +mtusi-messenger-lab6-seaweedfs-1 chrislusf/seaweedfs:3.80@sha256:1055999e08eed1789b0ae45d235126e4495e23d3fb9d6396293fd42539b1ae6a "/entrypoint.sh serv…" seaweedfs 5 hours ago Up 5 hours (healthy) 7333/tcp, 8080/tcp, 8888/tcp, 9333/tcp, 18080/tcp, 18888/tcp, 19333/tcp, 127.0.0.1:8333->8333/tcp +mtusi-messenger-lab6-tempo-1 grafana/tempo:2.9.0@sha256:65a5789759435f1ef696f1953258b9bbdb18eb571d5ce711ff812d2e128288a4 "/tempo -config.file…" tempo 5 hours ago Up 5 hours 127.0.0.1:3200->3200/tcp +mtusi-messenger-lab6-worker-1 mtusi-messenger:lab6 "/usr/local/bin/work…" worker 28 minutes ago Up 28 minutes (healthy) 8080/tcp, 127.0.0.1:8081->8081/tcp + diff --git a/evidence/lab6/db-down.txt b/evidence/lab6/db-down.txt new file mode 100644 index 0000000..2587f72 --- /dev/null +++ b/evidence/lab6/db-down.txt @@ -0,0 +1,55 @@ +UTC 2026-11-05T22:39:36Z +HEAD 639582280f0cc2236dee3140207168df23cc8bf1 +$ docker compose stop postgres + Container mtusi-messenger-lab6-postgres-1 Stopping + Container mtusi-messenger-lab6-postgres-1 Stopped +$ direct api request (stopped DB) +--2026-11-05 22:39:39-- http://127.0.0.1:8080/api/v1/users/me +Connecting to 127.0.0.1:8080... connected. +HTTP request sent, awaiting response... + HTTP/1.1 503 Service Unavailable + Content-Type: application/json; charset=utf-8 + X-Instance-Id: 32a0ab2f10f0 + X-Request-Id: 68f42379-8fe8-4655-a99e-bd3a65975cc7 + Date: Thu, 05 Nov 2026 22:39:39 GMT + Content-Length: 116 +2026-11-05 22:39:39 ERROR 503: Service Unavailable. + + +$ start postgres and immediate direct request +--2026-11-05 22:39:39-- http://127.0.0.1:8080/api/v1/users/me +Connecting to 127.0.0.1:8080... connected. +HTTP request sent, awaiting response... + HTTP/1.1 200 OK + Access-Control-Expose-Headers: X-Instance-Id,X-Request-Id + Content-Type: application/json; charset=utf-8 + X-Instance-Id: 32a0ab2f10f0 + X-Request-Id: 5be628de-cfd2-4aeb-aa3f-4ca045a8d50a + Date: Thu, 05 Nov 2026 22:39:39 GMT + Content-Length: 153 +Length: 153 [application/json] +Saving to: 'STDOUT' + + 0K {"created_at":"2026-11-05T22:39:36Z","display_name":"Студент alice","id":"01a1adde-1a14-7f20-bdfa-448058e1d060","username":"u_alice_7eeac91c971f"} 100% 61.9M=0s + +2026-11-05 22:39:39 (61.9 MB/s) - written to stdout [153/153] + + +$ wait recovery +--2026-11-05 22:39:51-- http://127.0.0.1:8080/api/v1/users/me +Connecting to 127.0.0.1:8080... connected. +HTTP request sent, awaiting response... + HTTP/1.1 200 OK + Access-Control-Expose-Headers: X-Instance-Id,X-Request-Id + Content-Type: application/json; charset=utf-8 + X-Instance-Id: 32a0ab2f10f0 + X-Request-Id: f8053440-cb37-49ff-ba79-eb8c4ceff53b + Date: Thu, 05 Nov 2026 22:39:51 GMT + Content-Length: 153 +Length: 153 [application/json] +Saving to: 'STDOUT' +{"created_at":"2026-11-05T22:39:36Z","display_name":"Студент alice","id":"01a1adde-1a14-7f20-bdfa-448058e1d060","username":"u_alice_7eeac91c971f"} + 0K 100% 72.8M=0s + +2026-11-05 22:39:51 (72.8 MB/s) - written to stdout [153/153] + diff --git a/evidence/lab6/db-pause.txt b/evidence/lab6/db-pause.txt new file mode 100644 index 0000000..3cc2cc3 --- /dev/null +++ b/evidence/lab6/db-pause.txt @@ -0,0 +1,13 @@ +PostgreSQL pause (short burst) — local check +============================================= +$ docker compose --env-file .env pause postgres +$ python3 scripts/lab6_load.py --rate 1 --duration 8 --upload-ratio 0 --deadline 5 + messages were attempted during a frozen DB; client deadline errors are bad. +$ sum(rate(haproxy_frontend_http_responses_total{proxy="http_front",code=~"5.."}[1m])) + -> 0.017002102915598543 +$ slo:api_error_ratio:5m -> 0 +$ docker compose --env-file .env unpause postgres +$ make test -> PASS lab6 public API scenario +$ Prometheus alerts -> [] +Interpretation: a short sub-5m burst is below the multi-window page threshold; +this is the expected no-page control, not evidence of a sustained incident. diff --git a/evidence/lab6/load-smoke.json b/evidence/lab6/load-smoke.json new file mode 100644 index 0000000..16a9cca --- /dev/null +++ b/evidence/lab6/load-smoke.json @@ -0,0 +1,25 @@ +{ + "base_url": "http://localhost:8080", + "rate": 0.5, + "duration_s": 8.36, + "scheduled": 5, + "counters": { + "accepted": 5, + "ready": 5, + "failed": 0, + "messages": 0, + "uploads": 5 + }, + "failures": 0, + "failure_samples": [], + "latency_ms": { + "p50": null, + "p95": null, + "p99": null + }, + "ttr_ms": { + "p50": 349.0, + "p95": 359.9, + "p99": 359.9 + } +} diff --git a/evidence/lab6/metrics.txt b/evidence/lab6/metrics.txt new file mode 100644 index 0000000..a7b4941 --- /dev/null +++ b/evidence/lab6/metrics.txt @@ -0,0 +1,15 @@ +http_server_request_duration_seconds_count: 40 +http_server_request_duration_seconds_bucket: 480 +messenger_jobs_processed_total: 1 +messenger_jobs_accepted_total: 2 +messenger_job_duration_seconds_bucket: 11 +messenger_job_time_to_ready_seconds_bucket: 10 +messenger_jobs_overdue: 1 +messenger_worker_busy: 1 +messenger_db_pool_used: 4 +messenger_queue_oldest_job_age_seconds: 1 +messenger_outbox_oldest_unpublished_age_seconds: 1 +messenger_process_cpu_seconds_total: 4 +rabbitmq_queue_messages_ready: 2 +otelcol_exporter_queue_size: 2 +haproxy_backend_http_responses_total: 12 diff --git a/evidence/lab6/queries/promql.txt b/evidence/lab6/queries/promql.txt new file mode 100644 index 0000000..f1888b4 --- /dev/null +++ b/evidence/lab6/queries/promql.txt @@ -0,0 +1,48 @@ +# Actual PromQL used by the provisioned dashboards and alert rules. +sum(rate(http_server_request_duration_seconds_count[5m])) +slo:api_error_ratio:5m +histogram_quantile(0.50, sum by (le) (rate(http_server_request_duration_seconds_bucket[5m]))) +histogram_quantile(0.95, sum by (le) (rate(http_server_request_duration_seconds_bucket[5m]))) +histogram_quantile(0.99, sum by (le) (rate(http_server_request_duration_seconds_bucket[5m]))) +sum(rate(messenger_jobs_processed_total{outcome="succeeded"}[5m])) +sum(rate(messenger_jobs_processed_total{outcome="failed"}[5m])) +sum(rate(messenger_jobs_processed_total{outcome="retried"}[5m])) +histogram_quantile(0.50, sum by (le) (rate(messenger_job_duration_seconds_bucket[5m]))) +histogram_quantile(0.95, sum by (le) (rate(messenger_job_duration_seconds_bucket[5m]))) +histogram_quantile(0.99, sum by (le) (rate(messenger_job_duration_seconds_bucket[5m]))) +histogram_quantile(0.95, sum by (le) (rate(messenger_job_time_to_ready_seconds_bucket[5m]))) +slo:job_ttr_bad_ratio:5m +max(rabbitmq_queue_messages_ready{queue="attachment.process.v1"}) +max(messenger_queue_oldest_job_age_seconds) +max(messenger_jobs_overdue) +max(messenger_outbox_oldest_unpublished_age_seconds) +sum(messenger_worker_busy) +sum(messenger_worker_capacity) +sum(messenger_db_pool_used) +sum(messenger_db_pool_idle) +sum(messenger_db_pool_max) +sum(rate(messenger_db_pool_empty_acquire_total[5m])) +max(messenger_process_cpu_seconds_total) +max(messenger_process_memory_usage_bytes) +otelcol_exporter_queue_size +sum(rate(otelcol_receiver_failed_spans[5m])) +sum(rate(otelcol_receiver_failed_metric_points[5m])) +sum(rate(otelcol_receiver_failed_log_records[5m])) +sum(rate(otelcol_receiver_refused_spans[5m])) +sum(rate(otelcol_receiver_refused_metric_points[5m])) +sum(rate(otelcol_receiver_refused_log_records[5m])) +otelcol_exporter_queue_capacity +sum(rate(haproxy_backend_http_responses_total{proxy="api_backend",code=~"5.."}[5m])) +slo:job_ttr_bad_ratio:1h +slo:job_ttr_bad_ratio:30m +slo:api_error_ratio:1h +slo:api_error_ratio:6h +slo:api_error_ratio:30m +slo:api_error_ratio:7d +slo:api_budget_remaining:7d +(sum(rate(messenger_jobs_ttr_missed_total[5m])) or vector(0)) / clamp_min((sum(rate(messenger_job_time_to_ready_seconds_bucket{le="30.0"}[5m])) or vector(0)) + (sum(rate(messenger_jobs_ttr_missed_total[5m])) or vector(0)), 0.001) +sum(rate(messenger_db_pool_empty_acquire_wait_seconds_total[5m])) / clamp_min(sum(rate(messenger_db_pool_empty_acquire_total[5m])), 1e-9) +sum by (service_name) (rate(messenger_process_cpu_seconds_total[5m])) +sum by (service_name) (messenger_process_memory_usage_bytes) / clamp_min(sum by (service_name) (messenger_process_memory_limit_bytes), 1) +sum by (http_route,http_response_status_code) (rate(http_server_request_duration_seconds_count[5m])) +sum(rate(haproxy_backend_http_responses_total{proxy="api_backend"}[5m])) diff --git a/evidence/lab6/regression/attachments.txt b/evidence/lab6/regression/attachments.txt new file mode 100644 index 0000000..3a29966 --- /dev/null +++ b/evidence/lab6/regression/attachments.txt @@ -0,0 +1,24 @@ +env -u HTTP_PROXY -u HTTPS_PROXY -u ALL_PROXY -u http_proxy -u https_proxy -u all_proxy NO_PROXY=localhost,127.0.0.1,::1 no_proxy=localhost,127.0.0.1,::1 python3 student-tests/attachments_negative.py --base-url "http://localhost:8080" +10 MiB + 1 body: 413 +empty body: 415 +corrupt PNG (IDAT CRC): 415 +MIME spoof (PNG declared as JPEG): 415 +structurally valid PNG with non-zlib IDAT: 415 +valid zlib, empty PNG raster: 415 +valid zlib, invalid PNG scanline filter: 415 +invalid PNG color type/bit depth pair: 415 +duplicate PNG IHDR: 415 +trailing bytes after PNG zlib stream: 415 +tRNS on RGBA PNG: 415 +short tRNS on RGB PNG: 415 +PLTE entries exceed palette bit depth: 415 +palette tRNS exceeds PLTE entries: 415 +dangerous filenames: 400 +foreign attachment metadata/content: 404 +empty text without attachments: 400 +attachment from another chat: 404 +11 attachment ids: 400 +duplicate attachment ids: 400 +attachment-only message: 201 +anonymous direct S3 GET: 403 +PASS: lab4 attachment negative scenarios diff --git a/evidence/lab6/regression/failover.txt b/evidence/lab6/regression/failover.txt new file mode 100644 index 0000000..c95c535 --- /dev/null +++ b/evidence/lab6/regression/failover.txt @@ -0,0 +1,4 @@ +env -u HTTP_PROXY -u HTTPS_PROXY -u ALL_PROXY -u http_proxy -u https_proxy -u all_proxy NO_PROXY=localhost,127.0.0.1,::1 no_proxy=localhost,127.0.0.1,::1 python3 tests/resilience.py --mode failover --action-script "scripts/stop-one.sh" --base-url "http://localhost:8080" +Executing explicit failover hook; hook output suppressed to avoid leaking secrets. +{"observed_instances_before": 2, "successful_writes": 97, "failed_attempts": 0, "first_recovery_seconds": 3.068} +PASS: failover preserved confirmed data and existing session. Hook scope needs operator evidence. diff --git a/evidence/lab6/regression/faults.txt b/evidence/lab6/regression/faults.txt new file mode 100644 index 0000000..66e355d --- /dev/null +++ b/evidence/lab6/regression/faults.txt @@ -0,0 +1,14 @@ +env -u HTTP_PROXY -u HTTPS_PROXY -u ALL_PROXY -u http_proxy -u https_proxy -u all_proxy NO_PROXY=localhost,127.0.0.1,::1 no_proxy=localhost,127.0.0.1,::1 python3 student-tests/lab5_faults.py --base-url "http://localhost:8080" +permanent failure: failed/injected_failure, content 409, failed attachment not linkable, registry visible +replay: failed -> queued -> ready, one thumbnail +replay ready job: refused +replay older failed version while v2 queued: refused, state intact +v2 published after older replay refusal +replay of failed reprocess: queued projection restored, then ready at pipeline 2 +transient exhaustion: attempts=5, retry_exhausted, four retries, DLQ message present +crash after first variant: redelivered, same three variants, attempts=2 +crash after commit before ack: ready remains, redelivery is a no-op +crash after claim before side effect: requeued, attempts=2, ready +outbox gap: crash before publish recovered through the relay, outbox published, ready +lease expiry: paused worker, reaper requeued, stale attempt fenced, ready +PASS: lab5 level 4 fault injection diff --git a/evidence/lab6/regression/idempotency.txt b/evidence/lab6/regression/idempotency.txt new file mode 100644 index 0000000..5e864ba --- /dev/null +++ b/evidence/lab6/regression/idempotency.txt @@ -0,0 +1,3 @@ +env -u HTTP_PROXY -u HTTPS_PROXY -u ALL_PROXY -u http_proxy -u https_proxy -u all_proxy NO_PROXY=localhost,127.0.0.1,::1 no_proxy=localhost,127.0.0.1,::1 python3 student-tests/idempotency_parallel.py --base-url "http://localhost:8080" +{"replay": {"workers": 12, "instances": ["8f0e5bdd7998", "e8d2415b9c96"], "message_id": "01a1a763-5b9b-7a27-994f-78248c9271aa"}, "conflict": {"workers": 12, "accepted": 1, "conflicts": 11}, "stable_body": {"message_id": "01a1a763-5bd8-778e-ba62-16240fa3ec36"}, "key_required": {"status": 400}} +PASS: параллельный повтор с одним Idempotency-Key создаёт ровно одно сообщение diff --git a/evidence/lab6/regression/integration.txt b/evidence/lab6/regression/integration.txt new file mode 100644 index 0000000..d57ecda --- /dev/null +++ b/evidence/lab6/regression/integration.txt @@ -0,0 +1,3 @@ +go test -tags=integration -p 1 -count=1 -timeout=15m ./internal/storage/postgres ./internal/storage/redis +ok mtusi-messenger/internal/storage/postgres 8.003s +ok mtusi-messenger/internal/storage/redis 1.133s diff --git a/evidence/lab6/regression/lint.txt b/evidence/lab6/regression/lint.txt new file mode 100644 index 0000000..caabb14 --- /dev/null +++ b/evidence/lab6/regression/lint.txt @@ -0,0 +1,20 @@ +/Users/vladislav/Projects/mtusi2026lab6/bin/golangci-lint run -v +level=info msg="golangci-lint has version 2.13.2 built with go1.27.1 from (unknown, modified: ?, mod sum: \"h1:bCyq3E4vo9qwzifjpzJqYndEt7Ncva80qkk8G2B4TXU=\") on (unknown)" +level=info msg="[config_reader] Config search paths: [./ /Users/vladislav/Projects/mtusi2026lab6 /Users/vladislav/Projects /Users/vladislav /Users /]" +level=info msg="[config_reader] Used config file .golangci.yml" +level=info msg="[config_reader] Module name \"mtusi-messenger\"" +level=info msg="[goenv] Read go env for 5.163584ms: map[string]string{\"GOCACHE\":\"/Users/vladislav/Library/Caches/go-build\", \"GOROOT\":\"/opt/homebrew/Cellar/go/1.27.1/libexec\"}" +level=info msg="[lintersdb] Active 50 linters: [asasalint bodyclose canonicalheader containedctx contextcheck copyloopvar depguard durationcheck errcheck errname errorlint exhaustive exptostd fatcontext forbidigo forcetypeassert gocheckcompilerdirectives gocritic gofumpt goimports gomoddirectives gosec govet ineffassign intrange makezero misspell musttag nilerr nilnil noctx nolintlint perfsprint prealloc reassign recvcheck revive rowserrcheck sloglint sqlclosecheck staticcheck testifylint thelper tparallel unconvert unparam unused usestdlibvars usetesting wastedassign]" +level=info msg="[loader] Using build tags: [integration]" +level=info msg="[loader] Go packages loading at mode 8767 (compiled_files|deps|files|imports|types_sizes|exports_file|name) took 363.317916ms" +level=info msg="[runner/filename_unadjuster] Pre-built 0 adjustments in 9.772458ms" +level=info msg="[linters_context/goanalysis] analyzers took 10.930463359s with top 10 stages: revive: 2.628586625s, goimports: 1.744804s, gosec: 899.898833ms, unparam: 692.242917ms, wastedassign: 325.500166ms, gocritic: 151.973916ms, buildir: 143.08475ms, gofumpt: 134.217041ms, forbidigo: 133.863209ms, buildssa: 114.559414ms" +level=info msg="[runner/exclusion_rules] Skipped 14 issues by rules: [Path: \"_test\\\\.go\", Linters: \"gosec, prealloc, forcetypeassert, unparam\"]" +level=info msg="[runner] Issues before processing: 893, after processing: 0" +level=info msg="[runner] Processors filtering stat (in/out): path_absoluter: 893/893, cgo: 893/893, exclusion_paths: 893/893, generated_file_filter: 893/304, filename_unadjuster: 893/893, invalid_issue: 893/893, path_relativity: 893/893, nolint_filter: 6/0, exclusion_rules: 304/6" +level=info msg="[runner] processing took 3.351875ms with stages: generated_file_filter: 2.096458ms, nolint_filter: 636.084µs, path_relativity: 291.167µs, exclusion_rules: 290.125µs, invalid_issue: 13.834µs, cgo: 11.916µs, path_absoluter: 6.458µs, filename_unadjuster: 2.75µs, sort_results: 791ns, max_same_issues: 584ns, fixer: 334ns, exclusion_paths: 292ns, max_from_linter: 167ns, diff: 166ns, uniq_by_line: 166ns, path_prettifier: 166ns, max_per_file_from_linter: 125ns, source_code: 125ns, path_shortener: 84ns, severity-rules: 83ns" +level=info msg="[runner] linters took 1.75139825s with stages: goanalysis_metalinter: 1.74801175s" +0 issues. +level=info msg="File cache stats: 0 entries of total size 0B" +level=info msg="Memory: 23 samples, avg is 358.6MB, max is 642.8MB" +level=info msg="Execution took 2.130137542s" diff --git a/evidence/lab6/regression/load.txt b/evidence/lab6/regression/load.txt new file mode 100644 index 0000000..c1aaa7a --- /dev/null +++ b/evidence/lab6/regression/load.txt @@ -0,0 +1,15 @@ + "workload": "closed-loop POST messages; no automatic retries", + "requested_duration_seconds": 30, + "elapsed_seconds": 30.009, + "concurrency": 4, + "successful_requests": 30857, + "failed_requests": 0, + "error_ratio": 0.0, + "successful_rps": 1028.26, + "successful_latency_ms": { + "p50": 2.846, + "p95": 9.485, + "p99": 17.614 + }, + "note": "Latency percentiles cover successes only. Timeouts/errors are counted separately; closed-loop has coordinated omission and client overhead." +} diff --git a/evidence/lab6/regression/persistence.txt b/evidence/lab6/regression/persistence.txt new file mode 100644 index 0000000..1d3d684 --- /dev/null +++ b/evidence/lab6/regression/persistence.txt @@ -0,0 +1,3 @@ +env -u HTTP_PROXY -u HTTPS_PROXY -u ALL_PROXY -u http_proxy -u https_proxy -u all_proxy NO_PROXY=localhost,127.0.0.1,::1 no_proxy=localhost,127.0.0.1,::1 python3 tests/resilience.py --mode persistence --action-script "scripts/restart.sh" --base-url "http://localhost:8080" +Executing explicit persistence hook; hook output suppressed to avoid leaking secrets. +PASS: persistence preserved confirmed data and existing session. Hook scope needs operator evidence. diff --git a/evidence/lab6/regression/presign.txt b/evidence/lab6/regression/presign.txt new file mode 100644 index 0000000..6db70db --- /dev/null +++ b/evidence/lab6/regression/presign.txt @@ -0,0 +1,10 @@ +env -u HTTP_PROXY -u HTTPS_PROXY -u ALL_PROXY -u http_proxy -u https_proxy -u all_proxy NO_PROXY=localhost,127.0.0.1,::1 no_proxy=localhost,127.0.0.1,::1 python3 student-tests/presign_flow.py --base-url "http://localhost:8080" +happy path: direct PUT 200, complete queued, ready after worker +message with attachment downloaded as the second chat member +repeated complete is idempotent +foreign complete: 404 +complete before PUT: 409 +wrong completion checksum: 409 +oversized direct PUT: 403 from S3; complete: 409 (nothing stored) +same-size overwrite: last PUT wins, checksum verified +PASS: lab4 presigned upload flow diff --git a/evidence/lab6/regression/queue.txt b/evidence/lab6/regression/queue.txt new file mode 100644 index 0000000..1ff1015 --- /dev/null +++ b/evidence/lab6/regression/queue.txt @@ -0,0 +1,11 @@ +$ make test-queue +worker down: 202 queued, content 409, queued attachment linked, API restarted +worker restarted: ready, thumbnail and original downloadable, staging cleared +broker down: upload accepted into outbox +broker + relay recovered: queued job reached ready +stack restart: ready attachment and original preserved +worker down: reprocess pipeline 2 accepted, v1 audit event recorded, upload still queued +worker up: reprocessed upload reached ready at pipeline 2, v1 superseded +worker down: reprocess pipeline 3 refused, v1 job untouched +worker up: preserved upload reached ready at pipeline 1 +PASS: lab5 async worker/broker durability diff --git a/evidence/lab6/regression/track2-lab5.txt b/evidence/lab6/regression/track2-lab5.txt new file mode 100644 index 0000000..3650872 --- /dev/null +++ b/evidence/lab6/regression/track2-lab5.txt @@ -0,0 +1,8 @@ +env -u HTTP_PROXY -u HTTPS_PROXY -u ALL_PROXY -u http_proxy -u https_proxy -u all_proxy NO_PROXY=localhost,127.0.0.1,::1 no_proxy=localhost,127.0.0.1,::1 python3 scripts/lab5_track2.py --base-url "http://localhost:8080" +Dduplicate_before_effect rep=1: PASS +Dstale_version_after_v2 rep=1: PASS +Dduplicate_before_effect rep=2: PASS +Dstale_version_after_v2 rep=2: PASS +Dduplicate_before_effect rep=3: PASS +Dstale_version_after_v2 rep=3: PASS +PASS: track2 6/6 scenarios diff --git a/evidence/lab6/smoke.txt b/evidence/lab6/smoke.txt new file mode 100644 index 0000000..414c497 --- /dev/null +++ b/evidence/lab6/smoke.txt @@ -0,0 +1,2 @@ +env -u HTTP_PROXY -u HTTPS_PROXY -u ALL_PROXY -u http_proxy -u https_proxy -u all_proxy NO_PROXY=localhost,127.0.0.1,::1 no_proxy=localhost,127.0.0.1,::1 python3 tests/smoke.py --base-url "http://localhost:8080" +PASS: lab6 public API scenario; infrastructure and grading evidence remain separate. diff --git a/evidence/lab6/stand.txt b/evidence/lab6/stand.txt new file mode 100644 index 0000000..ab4ca3b --- /dev/null +++ b/evidence/lab6/stand.txt @@ -0,0 +1,15 @@ +NAME IMAGE COMMAND SERVICE CREATED STATUS PORTS +mtusi-messenger-lab6-api-1 mtusi-messenger:lab6 "/usr/local/bin/mess…" api 59 seconds ago Up 57 seconds (healthy) 8080/tcp +mtusi-messenger-lab6-api-2 mtusi-messenger:lab6 "/usr/local/bin/mess…" api 59 seconds ago Up 57 seconds (healthy) 8080/tcp +mtusi-messenger-lab6-broker-1 rabbitmq:4.3.7-management-alpine@sha256:1528a88eebf2bc4d0ab7e9d5d9bc542e9bdf5e1b105e65848fcf8de5c2186528 "docker-entrypoint.s…" broker 3 hours ago Up 26 minutes (healthy) 4369/tcp, 5671-5672/tcp, 15671/tcp, 15691-15692/tcp, 25672/tcp, 127.0.0.1:15672->15672/tcp +mtusi-messenger-lab6-grafana-1 grafana/grafana:13.2.5@sha256:9f7aa1e1e3246aade5792d35a738049f7f32f89cd51d1956cf426a4e86268a84 "/run.sh" grafana 3 hours ago Up 31 minutes (healthy) 127.0.0.1:3000->3000/tcp +mtusi-messenger-lab6-lb-1 haproxy:3.2-alpine@sha256:254e6370f01cd654e0744edf607c67f33777c1b6a9dc0d4b28bcba7171460122 "docker-entrypoint.s…" lb 3 hours ago Up 26 minutes 127.0.0.1:8404->8404/tcp, 127.0.0.1:8080->80/tcp +mtusi-messenger-lab6-loki-1 grafana/loki:3.6.4@sha256:be31579ac047e9f78b81e48f3b69d3af709e7299b431d5aa78bcda43382f9511 "/usr/bin/loki -conf…" loki 3 hours ago Up 7 minutes 127.0.0.1:3100->3100/tcp +mtusi-messenger-lab6-otel-collector-1 otel/opentelemetry-collector-contrib:0.164.0@sha256:340c9ca6a36617084c6661bdc4f0fe92b7cda5a805d61673ec8db375fddc522b "/otelcol-contrib --…" otel-collector 31 minutes ago Up 56 seconds 4317-4318/tcp, 55679/tcp +mtusi-messenger-lab6-postgres-1 postgres:18-alpine@sha256:77f585114c32fbca283dc835b0596f4e52b51b4c6662d7810b2f4084f60a1873 "docker-entrypoint.s…" postgres 3 hours ago Up 5 minutes (healthy) 5432/tcp +mtusi-messenger-lab6-prometheus-1 prom/prometheus:v3.15.1@sha256:fa3302279710be2f21a8301ec17a8b4f2301fd829bd113839b3b6b02b6f191a2 "/bin/prometheus --c…" prometheus 59 seconds ago Up 59 seconds (healthy) 127.0.0.1:9090->9090/tcp +mtusi-messenger-lab6-redis-1 redis:7.4-alpine@sha256:858f009f9709ce576febc734aa78b8f6d624b82571f9ddb6bda4377c833b3499 "docker-entrypoint.s…" redis 3 hours ago Up 26 minutes (healthy) 6379/tcp +mtusi-messenger-lab6-relay-1 mtusi-messenger:lab6 "/usr/local/bin/relay" relay 59 seconds ago Up 57 seconds (healthy) 8080/tcp, 127.0.0.1:8082->8082/tcp +mtusi-messenger-lab6-seaweedfs-1 chrislusf/seaweedfs:3.80@sha256:1055999e08eed1789b0ae45d235126e4495e23d3fb9d6396293fd42539b1ae6a "/entrypoint.sh serv…" seaweedfs 3 hours ago Up 26 minutes (healthy) 7333/tcp, 8080/tcp, 8888/tcp, 9333/tcp, 18080/tcp, 18888/tcp, 19333/tcp, 127.0.0.1:8333->8333/tcp +mtusi-messenger-lab6-tempo-1 grafana/tempo:2.9.0@sha256:65a5789759435f1ef696f1953258b9bbdb18eb571d5ce711ff812d2e128288a4 "/tempo -config.file…" tempo 28 minutes ago Up 7 minutes 127.0.0.1:3200->3200/tcp +mtusi-messenger-lab6-worker-1 mtusi-messenger:lab6 "/usr/local/bin/work…" worker 59 seconds ago Up 57 seconds (healthy) 8080/tcp, 127.0.0.1:8081->8081/tcp diff --git a/evidence/lab6/storage-down-series.json b/evidence/lab6/storage-down-series.json new file mode 100644 index 0000000..205cd41 --- /dev/null +++ b/evidence/lab6/storage-down-series.json @@ -0,0 +1,866 @@ +[ + { + "phase": "baseline", + "utc": "2026-11-06T14:16:36Z", + "api_memory": "19447808", + "collector_rss": "235225088", + "collector_heap": "49942672", + "queue_logs": "0", + "queue_traces": "0", + "sent_spans": "4.860972126582021", + "send_failed_spans": "0", + "enqueue_failed_spans": "MISSING", + "accepted_logs": "0.3324321482240321", + "api_error_5m": "0", + "api_p99": "0.02352142857142857", + "api_instances": [ + "2f5a79e18ab9", + "709c0280d839" + ], + "cgroup": [ + "mtusi-messenger-lab6-api-1 189.2MiB / 256MiB 73.92%", + "mtusi-messenger-lab6-api-2 187.9MiB / 256MiB 73.40%", + "mtusi-messenger-lab6-otel-collector-1 72.32MiB / 192MiB 37.67%" + ] + }, + { + "phase": "baseline", + "utc": "2026-11-06T14:16:48Z", + "api_memory": "198602752", + "collector_rss": "235229184", + "collector_heap": "52750392", + "queue_logs": "0", + "queue_traces": "0", + "sent_spans": "4.8270668530102165", + "send_failed_spans": "0", + "enqueue_failed_spans": "MISSING", + "accepted_logs": "0.342609804746333", + "api_error_5m": "0", + "api_p99": "0.07924999999999999", + "api_instances": [ + "2f5a79e18ab9", + "709c0280d839" + ], + "cgroup": [ + "mtusi-messenger-lab6-api-1 188.9MiB / 256MiB 73.78%", + "mtusi-messenger-lab6-api-2 188.1MiB / 256MiB 73.46%", + "mtusi-messenger-lab6-otel-collector-1 72.33MiB / 192MiB 37.67%" + ] + }, + { + "phase": "baseline", + "utc": "2026-11-06T14:17:00Z", + "api_memory": "197406720", + "collector_rss": "235229184", + "collector_heap": "55751416", + "queue_logs": "0", + "queue_traces": "0", + "sent_spans": "4.906714773043249", + "send_failed_spans": "0", + "enqueue_failed_spans": "MISSING", + "accepted_logs": "0.3424866565842212", + "api_error_5m": "0", + "api_p99": "0.07849999999999993", + "api_instances": [ + "2f5a79e18ab9", + "709c0280d839" + ], + "cgroup": [ + "mtusi-messenger-lab6-api-1 189MiB / 256MiB 73.84%", + "mtusi-messenger-lab6-api-2 188.1MiB / 256MiB 73.50%", + "mtusi-messenger-lab6-otel-collector-1 72.33MiB / 192MiB 37.67%" + ] + }, + { + "phase": "baseline", + "utc": "2026-11-06T14:17:12Z", + "api_memory": "198733824", + "collector_rss": "235233280", + "collector_heap": "32717896", + "queue_logs": "0", + "queue_traces": "0", + "sent_spans": "4.910172330771997", + "send_failed_spans": "0", + "enqueue_failed_spans": "MISSING", + "accepted_logs": "0.3424913020773284", + "api_error_5m": "0", + "api_p99": "0.07900000000000006", + "api_instances": [ + "2f5a79e18ab9", + "709c0280d839" + ], + "cgroup": [ + "mtusi-messenger-lab6-api-1 189.2MiB / 256MiB 73.91%", + "mtusi-messenger-lab6-api-2 188.3MiB / 256MiB 73.56%", + "mtusi-messenger-lab6-otel-collector-1 72.33MiB / 192MiB 37.67%" + ] + }, + { + "phase": "baseline", + "utc": "2026-11-06T14:17:25Z", + "api_memory": "198746112", + "collector_rss": "235233280", + "collector_heap": "35503232", + "queue_logs": "0", + "queue_traces": "0", + "sent_spans": "4.7575287977999405", + "send_failed_spans": "0", + "enqueue_failed_spans": "MISSING", + "accepted_logs": "0.3289239439676366", + "api_error_5m": "0", + "api_p99": "0.0795000000000001", + "api_instances": [ + "2f5a79e18ab9", + "709c0280d839" + ], + "cgroup": [ + "mtusi-messenger-lab6-api-1 187.5MiB / 256MiB 73.26%", + "mtusi-messenger-lab6-api-2 189.1MiB / 256MiB 73.88%", + "mtusi-messenger-lab6-otel-collector-1 72.34MiB / 192MiB 37.68%" + ] + }, + { + "phase": "baseline", + "utc": "2026-11-06T14:17:37Z", + "api_memory": "198746112", + "collector_rss": "235245568", + "collector_heap": "39833144", + "queue_logs": "0", + "queue_traces": "0", + "sent_spans": "4.811751660715557", + "send_failed_spans": "0", + "enqueue_failed_spans": "MISSING", + "accepted_logs": "0.3390945497333021", + "api_error_5m": "0", + "api_p99": "0.08075000000000006", + "api_instances": [ + "2f5a79e18ab9", + "709c0280d839" + ], + "cgroup": [ + "mtusi-messenger-lab6-api-1 188.4MiB / 256MiB 73.61%", + "mtusi-messenger-lab6-api-2 189.5MiB / 256MiB 74.01%", + "mtusi-messenger-lab6-otel-collector-1 72.34MiB / 192MiB 37.68%" + ] + }, + { + "phase": "down-start", + "utc": "2026-11-06T14:17:39Z", + "api_memory": "196960256", + "collector_rss": "235245568", + "collector_heap": "39833144", + "queue_logs": "0", + "queue_traces": "0", + "sent_spans": "4.811751660715557", + "send_failed_spans": "0", + "enqueue_failed_spans": "MISSING", + "accepted_logs": "0.3390945497333021", + "api_error_5m": "0", + "api_p99": "0.07874999999999993", + "api_instances": [ + "2f5a79e18ab9", + "709c0280d839" + ], + "cgroup": [ + "mtusi-messenger-lab6-api-1 188.4MiB / 256MiB 73.61%", + "mtusi-messenger-lab6-api-2 189.5MiB / 256MiB 74.02%", + "mtusi-messenger-lab6-otel-collector-1 72.35MiB / 192MiB 37.68%" + ] + }, + { + "phase": "down", + "utc": "2026-11-06T14:17:51Z", + "api_memory": "196960256", + "collector_rss": "235249664", + "collector_heap": "44557832", + "queue_logs": "5287", + "queue_traces": "17234", + "sent_spans": "4.665988470668022", + "send_failed_spans": "0", + "enqueue_failed_spans": "MISSING", + "accepted_logs": "0.36283485927433035", + "api_error_5m": "0", + "api_p99": "0.07950000000000007", + "api_instances": [ + "2f5a79e18ab9", + "709c0280d839" + ], + "cgroup": [ + "mtusi-messenger-lab6-api-1 189MiB / 256MiB 73.82%", + "mtusi-messenger-lab6-api-2 187.7MiB / 256MiB 73.33%", + "mtusi-messenger-lab6-otel-collector-1 72.35MiB / 192MiB 37.68%" + ] + }, + { + "phase": "down", + "utc": "2026-11-06T14:18:03Z", + "api_memory": "197980160", + "collector_rss": "235249664", + "collector_heap": "47533792", + "queue_logs": "6807", + "queue_traces": "22823", + "sent_spans": "4.516770034689609", + "send_failed_spans": "0", + "enqueue_failed_spans": "MISSING", + "accepted_logs": "0.3628336289127538", + "api_error_5m": "0", + "api_p99": "0.0774999999999999", + "api_instances": [ + "2f5a79e18ab9", + "709c0280d839" + ], + "cgroup": [ + "mtusi-messenger-lab6-api-1 188.1MiB / 256MiB 73.48%", + "mtusi-messenger-lab6-api-2 188MiB / 256MiB 73.43%", + "mtusi-messenger-lab6-otel-collector-1 72.35MiB / 192MiB 37.68%" + ] + }, + { + "phase": "down", + "utc": "2026-11-06T14:18:15Z", + "api_memory": "197365760", + "collector_rss": "235253760", + "collector_heap": "50792392", + "queue_logs": "7567", + "queue_traces": "26898", + "sent_spans": "4.411679931095053", + "send_failed_spans": "0.11868470222008212", + "enqueue_failed_spans": "MISSING", + "accepted_logs": "0.3730090641202581", + "api_error_5m": "0", + "api_p99": "0.07625000000000012", + "api_instances": [ + "2f5a79e18ab9", + "709c0280d839" + ], + "cgroup": [ + "mtusi-messenger-lab6-api-1 188.4MiB / 256MiB 73.58%", + "mtusi-messenger-lab6-api-2 188.7MiB / 256MiB 73.71%", + "mtusi-messenger-lab6-otel-collector-1 72.35MiB / 192MiB 37.68%" + ] + }, + { + "phase": "down", + "utc": "2026-11-06T14:18:27Z", + "api_memory": "197820416", + "collector_rss": "235257856", + "collector_heap": "55635944", + "queue_logs": "10262", + "queue_traces": "35035", + "sent_spans": "4.065812586046701", + "send_failed_spans": "0.34588230506819306", + "enqueue_failed_spans": "MISSING", + "accepted_logs": "0.3967473499311627", + "api_error_5m": "0", + "api_p99": "0.07549999999999997", + "api_instances": [ + "2f5a79e18ab9", + "709c0280d839" + ], + "cgroup": [ + "mtusi-messenger-lab6-api-1 95.14MiB / 256MiB 37.16%", + "mtusi-messenger-lab6-api-2 78.77MiB / 256MiB 30.77%", + "mtusi-messenger-lab6-otel-collector-1 72.35MiB / 192MiB 37.68%" + ] + }, + { + "phase": "down", + "utc": "2026-11-06T14:18:39Z", + "api_memory": "100081664", + "collector_rss": "235257856", + "collector_heap": "58521320", + "queue_logs": "14374", + "queue_traces": "47240", + "sent_spans": "3.9247080213976298", + "send_failed_spans": "0.4002727281978568", + "enqueue_failed_spans": "MISSING", + "accepted_logs": "0.3968805864334682", + "api_error_5m": "0", + "api_p99": "0.07549999999999987", + "api_instances": [ + "2f5a79e18ab9", + "709c0280d839" + ], + "cgroup": [ + "mtusi-messenger-lab6-api-1 95.32MiB / 256MiB 37.23%", + "mtusi-messenger-lab6-api-2 78.8MiB / 256MiB 30.78%", + "mtusi-messenger-lab6-otel-collector-1 72.8MiB / 192MiB 37.92%" + ] + }, + { + "phase": "down", + "utc": "2026-11-06T14:18:51Z", + "api_memory": "100081664", + "collector_rss": "235732992", + "collector_heap": "33370496", + "queue_logs": "15134", + "queue_traces": "53761", + "sent_spans": "3.727989090798075", + "send_failed_spans": "0.45794224500249325", + "enqueue_failed_spans": "MISSING", + "accepted_logs": "0.373138125557587", + "api_error_5m": "0", + "api_p99": "0.07624999999999998", + "api_instances": [ + "2f5a79e18ab9", + "709c0280d839" + ], + "cgroup": [ + "mtusi-messenger-lab6-api-1 19.49MiB / 256MiB 7.61%", + "mtusi-messenger-lab6-api-2 78.82MiB / 256MiB 30.79%", + "mtusi-messenger-lab6-otel-collector-1 72.81MiB / 192MiB 37.92%" + ] + }, + { + "phase": "down", + "utc": "2026-11-06T14:19:03Z", + "api_memory": "100519936", + "collector_rss": "235806720", + "collector_heap": "36385224", + "queue_logs": "16654", + "queue_traces": "54799", + "sent_spans": "3.3752039539072647", + "send_failed_spans": "0.5495306940029918", + "enqueue_failed_spans": "MISSING", + "accepted_logs": "0.3799224551131795", + "api_error_5m": "0", + "api_p99": "0.07549999999999987", + "api_instances": [ + "2f5a79e18ab9", + "709c0280d839" + ], + "cgroup": [ + "mtusi-messenger-lab6-api-1 19.49MiB / 256MiB 7.61%", + "mtusi-messenger-lab6-api-2 78.88MiB / 256MiB 30.81%", + "mtusi-messenger-lab6-otel-collector-1 72.81MiB / 192MiB 37.92%" + ] + }, + { + "phase": "down", + "utc": "2026-11-06T14:19:16Z", + "api_memory": "20692992", + "collector_rss": "235880448", + "collector_heap": "41257584", + "queue_logs": "19142", + "queue_traces": "68887", + "sent_spans": "3.065376917945297", + "send_failed_spans": "0.6537691794529688", + "enqueue_failed_spans": "MISSING", + "accepted_logs": "0.3769179452968646", + "api_error_5m": "0", + "api_p99": "0.07575000000000007", + "api_instances": [ + "2f5a79e18ab9", + "709c0280d839" + ], + "cgroup": [ + "mtusi-messenger-lab6-api-1 19.49MiB / 256MiB 7.61%", + "mtusi-messenger-lab6-api-2 78.9MiB / 256MiB 30.82%", + "mtusi-messenger-lab6-otel-collector-1 72.82MiB / 192MiB 37.93%" + ] + }, + { + "phase": "down", + "utc": "2026-11-06T14:19:28Z", + "api_memory": "20959232", + "collector_rss": "235880448", + "collector_heap": "44260552", + "queue_logs": "20661", + "queue_traces": "65858", + "sent_spans": "2.924016282225238", + "send_failed_spans": "0.8582089552238806", + "enqueue_failed_spans": "MISSING", + "accepted_logs": "0.3799185888738128", + "api_error_5m": "0", + "api_p99": "0.07624999999999983", + "api_instances": [ + "2f5a79e18ab9", + "709c0280d839" + ], + "cgroup": [ + "mtusi-messenger-lab6-api-1 19.5MiB / 256MiB 7.62%", + "mtusi-messenger-lab6-api-2 78.91MiB / 256MiB 30.83%", + "mtusi-messenger-lab6-otel-collector-1 72.82MiB / 192MiB 37.93%" + ] + }, + { + "phase": "down", + "utc": "2026-11-06T14:19:40Z", + "api_memory": "20717568", + "collector_rss": "235888640", + "collector_heap": "47361016", + "queue_logs": "19261", + "queue_traces": "72770", + "sent_spans": "2.6289277027920908", + "send_failed_spans": "0.8582176887824503", + "enqueue_failed_spans": "MISSING", + "accepted_logs": "0.3663537960019945", + "api_error_5m": "0", + "api_p99": "0.07674999999999987", + "api_instances": [ + "2f5a79e18ab9", + "709c0280d839" + ], + "cgroup": [ + "mtusi-messenger-lab6-api-1 19.52MiB / 256MiB 7.62%", + "mtusi-messenger-lab6-api-2 78.95MiB / 256MiB 30.84%", + "mtusi-messenger-lab6-otel-collector-1 72.83MiB / 192MiB 37.93%" + ] + }, + { + "phase": "down", + "utc": "2026-11-06T14:19:52Z", + "api_memory": "20717568", + "collector_rss": "235954176", + "collector_heap": "52161840", + "queue_logs": "23811", + "queue_traces": "87554", + "sent_spans": "2.2278663008941986", + "send_failed_spans": "0.9460802099687694", + "enqueue_failed_spans": "MISSING", + "accepted_logs": "0.3628336289127538", + "api_error_5m": "0", + "api_p99": "0.07875", + "api_instances": [ + "2f5a79e18ab9", + "709c0280d839" + ], + "cgroup": [ + "mtusi-messenger-lab6-api-1 18.1MiB / 256MiB 7.07%", + "mtusi-messenger-lab6-api-2 79.09MiB / 256MiB 30.89%", + "mtusi-messenger-lab6-otel-collector-1 72.83MiB / 192MiB 37.93%" + ] + }, + { + "phase": "down", + "utc": "2026-11-06T14:20:04Z", + "api_memory": "20987904", + "collector_rss": "235962368", + "collector_heap": "55371152", + "queue_logs": "24571", + "queue_traces": "90306", + "sent_spans": "2.078684833400023", + "send_failed_spans": "1.047819924177173", + "enqueue_failed_spans": "MISSING", + "accepted_logs": "0.38318333796770415", + "api_error_5m": "0", + "api_p99": "0.07774999999999985", + "api_instances": [ + "2f5a79e18ab9", + "709c0280d839" + ], + "cgroup": [ + "mtusi-messenger-lab6-api-1 18.1MiB / 256MiB 7.07%", + "mtusi-messenger-lab6-api-2 15.01MiB / 256MiB 5.86%", + "mtusi-messenger-lab6-otel-collector-1 68.88MiB / 192MiB 35.87%" + ] + }, + { + "phase": "down", + "utc": "2026-11-06T14:20:16Z", + "api_memory": "19234816", + "collector_rss": "231804928", + "collector_heap": "30398280", + "queue_logs": "25659", + "queue_traces": "96377", + "sent_spans": "1.8854040563315326", + "send_failed_spans": "1.2546753612278185", + "enqueue_failed_spans": "MISSING", + "accepted_logs": "0.3831846373479554", + "api_error_5m": "0", + "api_p99": "0.07599999999999993", + "api_instances": [ + "2f5a79e18ab9", + "709c0280d839" + ], + "cgroup": [ + "mtusi-messenger-lab6-api-1 18.09MiB / 256MiB 7.07%", + "mtusi-messenger-lab6-api-2 15.02MiB / 256MiB 5.87%", + "mtusi-messenger-lab6-otel-collector-1 68.87MiB / 192MiB 35.87%" + ] + }, + { + "phase": "down", + "utc": "2026-11-06T14:20:28Z", + "api_memory": "19234816", + "collector_rss": "231813120", + "collector_heap": "33688048", + "queue_logs": "27594", + "queue_traces": "101221", + "sent_spans": "1.831147824494654", + "send_failed_spans": "1.3462327524525513", + "enqueue_failed_spans": "MISSING", + "accepted_logs": "0.4103127532663947", + "api_error_5m": "0", + "api_p99": "0.07500000000000002", + "api_instances": [ + "2f5a79e18ab9", + "709c0280d839" + ], + "cgroup": [ + "mtusi-messenger-lab6-api-1 18.09MiB / 256MiB 7.07%", + "mtusi-messenger-lab6-api-2 15.02MiB / 256MiB 5.87%", + "mtusi-messenger-lab6-otel-collector-1 68.89MiB / 192MiB 35.88%" + ] + }, + { + "phase": "down", + "utc": "2026-11-06T14:20:40Z", + "api_memory": "19496960", + "collector_rss": "231817216", + "collector_heap": "36910680", + "queue_logs": "30512", + "queue_traces": "113187", + "sent_spans": "1.7910630026764178", + "send_failed_spans": "1.3975718884520534", + "enqueue_failed_spans": "MISSING", + "accepted_logs": "0.4240205972245308", + "api_error_5m": "0", + "api_p99": "0.07324999999999986", + "api_instances": [ + "2f5a79e18ab9", + "709c0280d839" + ], + "cgroup": [ + "mtusi-messenger-lab6-api-1 18.09MiB / 256MiB 7.07%", + "mtusi-messenger-lab6-api-2 15.05MiB / 256MiB 5.88%", + "mtusi-messenger-lab6-otel-collector-1 68.89MiB / 192MiB 35.88%" + ] + }, + { + "phase": "down", + "utc": "2026-11-06T14:20:52Z", + "api_memory": "19496960", + "collector_rss": "231821312", + "collector_heap": "41366880", + "queue_logs": "35822", + "queue_traces": "128858", + "sent_spans": "1.7469589345925005", + "send_failed_spans": "1.4518416000108547", + "enqueue_failed_spans": "MISSING", + "accepted_logs": "0.44776423177904867", + "api_error_5m": "0", + "api_p99": "0.07325", + "api_instances": [ + "2f5a79e18ab9", + "709c0280d839" + ], + "cgroup": [ + "mtusi-messenger-lab6-api-1 17.49MiB / 256MiB 6.83%", + "mtusi-messenger-lab6-api-2 15.05MiB / 256MiB 5.88%", + "mtusi-messenger-lab6-otel-collector-1 68.89MiB / 192MiB 35.88%" + ] + }, + { + "phase": "down", + "utc": "2026-11-06T14:21:04Z", + "api_memory": "19496960", + "collector_rss": "231821312", + "collector_heap": "44702392", + "queue_logs": "35822", + "queue_traces": "130372", + "sent_spans": "1.6994745536759195", + "send_failed_spans": "1.5400428091194958", + "enqueue_failed_spans": "MISSING", + "accepted_logs": "0.454550080224697", + "api_error_5m": "0", + "api_p99": "0.07250000000000008", + "api_instances": [ + "2f5a79e18ab9", + "709c0280d839" + ], + "cgroup": [ + "mtusi-messenger-lab6-api-1 17.48MiB / 256MiB 6.83%", + "mtusi-messenger-lab6-api-2 15.05MiB / 256MiB 5.88%", + "mtusi-messenger-lab6-otel-collector-1 68.89MiB / 192MiB 35.88%" + ] + }, + { + "phase": "down", + "utc": "2026-11-06T14:21:17Z", + "api_memory": "18595840", + "collector_rss": "231829504", + "collector_heap": "49175936", + "queue_logs": "38101", + "queue_traces": "137284", + "sent_spans": "1.6587404427378376", + "send_failed_spans": "1.5942904050854472", + "enqueue_failed_spans": "MISSING", + "accepted_logs": "0.47150290703590886", + "api_error_5m": "0", + "api_p99": "0.07174999999999984", + "api_instances": [ + "2f5a79e18ab9", + "709c0280d839" + ], + "cgroup": [ + "mtusi-messenger-lab6-api-1 17.48MiB / 256MiB 6.83%", + "mtusi-messenger-lab6-api-2 14.72MiB / 256MiB 5.75%", + "mtusi-messenger-lab6-otel-collector-1 68.89MiB / 192MiB 35.88%" + ] + }, + { + "phase": "down", + "utc": "2026-11-06T14:21:29Z", + "api_memory": "18595840", + "collector_rss": "231845888", + "collector_heap": "28314784", + "queue_logs": "41436", + "queue_traces": "151031", + "sent_spans": "1.6553651810216452", + "send_failed_spans": "1.6519730392572565", + "enqueue_failed_spans": "MISSING", + "accepted_logs": "0.4579391381924633", + "api_error_5m": "0", + "api_p99": "0.07000000000000008", + "api_instances": [ + "2f5a79e18ab9", + "709c0280d839" + ], + "cgroup": [ + "mtusi-messenger-lab6-api-1 17.48MiB / 256MiB 6.83%", + "mtusi-messenger-lab6-api-2 14.72MiB / 256MiB 5.75%", + "mtusi-messenger-lab6-otel-collector-1 68.91MiB / 192MiB 35.89%" + ] + }, + { + "phase": "down", + "utc": "2026-11-06T14:21:41Z", + "api_memory": "18595840", + "collector_rss": "231845888", + "collector_heap": "32877592", + "queue_logs": "43716", + "queue_traces": "160304", + "sent_spans": "1.139763499073942", + "send_failed_spans": "1.6519786430030055", + "enqueue_failed_spans": "MISSING", + "accepted_logs": "0.4308034654237817", + "api_error_5m": "0", + "api_p99": "0.02295625", + "api_instances": [ + "2f5a79e18ab9", + "709c0280d839" + ], + "cgroup": [ + "mtusi-messenger-lab6-api-1 17.48MiB / 256MiB 6.83%", + "mtusi-messenger-lab6-api-2 14.72MiB / 256MiB 5.75%", + "mtusi-messenger-lab6-otel-collector-1 68.91MiB / 192MiB 35.89%" + ] + }, + { + "phase": "down", + "utc": "2026-11-06T14:21:53Z", + "api_memory": "18595840", + "collector_rss": "231845888", + "collector_heap": "36050000", + "queue_logs": "40381", + "queue_traces": "150406", + "sent_spans": "0.7940305192755999", + "send_failed_spans": "1.9816830053715822", + "enqueue_failed_spans": "MISSING", + "accepted_logs": "0.4173750165423025", + "api_error_5m": "0", + "api_p99": "0.022835714285714282", + "api_instances": [ + "2f5a79e18ab9", + "709c0280d839" + ], + "cgroup": [ + "mtusi-messenger-lab6-api-1 18.2MiB / 256MiB 7.11%", + "mtusi-messenger-lab6-api-2 14.73MiB / 256MiB 5.75%", + "mtusi-messenger-lab6-otel-collector-1 68.91MiB / 192MiB 35.89%" + ] + }, + { + "phase": "down", + "utc": "2026-11-06T14:22:05Z", + "api_memory": "18595840", + "collector_rss": "231845888", + "collector_heap": "39159560", + "queue_logs": "43076", + "queue_traces": "158459", + "sent_spans": "0.6447300108246775", + "send_failed_spans": "1.9816964543242719", + "enqueue_failed_spans": "MISSING", + "accepted_logs": "0.43773774419149153", + "api_error_5m": "0", + "api_p99": "0.022835714285714286", + "api_instances": [ + "2f5a79e18ab9", + "709c0280d839" + ], + "cgroup": [ + "mtusi-messenger-lab6-api-1 18.36MiB / 256MiB 7.17%", + "mtusi-messenger-lab6-api-2 14.73MiB / 256MiB 5.75%", + "mtusi-messenger-lab6-otel-collector-1 68.91MiB / 192MiB 35.89%" + ] + }, + { + "phase": "down", + "utc": "2026-11-06T14:22:17Z", + "api_memory": "19341312", + "collector_rss": "231845888", + "collector_heap": "43874408", + "queue_logs": "47931", + "queue_traces": "174667", + "sent_spans": "0.4513125390232647", + "send_failed_spans": "2.0359964166463067", + "enqueue_failed_spans": "MISSING", + "accepted_logs": "0.458099193745419", + "api_error_5m": "0", + "api_p99": "0.022975", + "api_instances": [ + "2f5a79e18ab9", + "709c0280d839" + ], + "cgroup": [ + "mtusi-messenger-lab6-api-1 18.37MiB / 256MiB 7.17%", + "mtusi-messenger-lab6-api-2 14.73MiB / 256MiB 5.75%", + "mtusi-messenger-lab6-otel-collector-1 68.91MiB / 192MiB 35.89%" + ] + }, + { + "phase": "down", + "utc": "2026-11-06T14:22:29Z", + "api_memory": "19775488", + "collector_rss": "231845888", + "collector_heap": "47045432", + "queue_logs": "50851", + "queue_traces": "184628", + "sent_spans": "0.2816433038456187", + "send_failed_spans": "2.1242013037031002", + "enqueue_failed_spans": "MISSING", + "accepted_logs": "0.4343414806293879", + "api_error_5m": "0", + "api_p99": "0.023133333333333336", + "api_instances": [ + "2f5a79e18ab9", + "709c0280d839" + ], + "cgroup": [ + "mtusi-messenger-lab6-api-1 18.37MiB / 256MiB 7.17%", + "mtusi-messenger-lab6-api-2 14.73MiB / 256MiB 5.75%", + "mtusi-messenger-lab6-otel-collector-1 68.91MiB / 192MiB 35.89%" + ] + }, + { + "phase": "down", + "utc": "2026-11-06T14:22:41Z", + "api_memory": "19701760", + "collector_rss": "231858176", + "collector_heap": "51689352", + "queue_logs": "53241", + "queue_traces": "192480", + "sent_spans": "0", + "send_failed_spans": "2.178501381074863", + "enqueue_failed_spans": "MISSING", + "accepted_logs": "0.43094965015032344", + "api_error_5m": "0", + "api_p99": "0.023149999999999997", + "api_instances": [ + "2f5a79e18ab9", + "709c0280d839" + ], + "cgroup": [ + "mtusi-messenger-lab6-api-1 18.54MiB / 256MiB 7.24%", + "mtusi-messenger-lab6-api-2 14.73MiB / 256MiB 5.75%", + "mtusi-messenger-lab6-otel-collector-1 68.93MiB / 192MiB 35.90%" + ] + }, + { + "phase": "recovery-start", + "utc": "2026-11-06T14:22:44Z", + "api_memory": "19701760", + "collector_rss": "231858176", + "collector_heap": "51689352", + "queue_logs": "53241", + "queue_traces": "192480", + "sent_spans": "0", + "send_failed_spans": "2.178501381074863", + "enqueue_failed_spans": "MISSING", + "accepted_logs": "0.4309496501503233", + "api_error_5m": "0", + "api_p99": "0.023149999999999997", + "api_instances": [ + "2f5a79e18ab9", + "709c0280d839" + ], + "cgroup": [ + "mtusi-messenger-lab6-api-1 18.54MiB / 256MiB 7.24%", + "mtusi-messenger-lab6-api-2 14.73MiB / 256MiB 5.75%", + "mtusi-messenger-lab6-otel-collector-1 68.93MiB / 192MiB 35.90%" + ] + }, + { + "phase": "recovery", + "utc": "2026-11-06T14:22:55Z", + "api_memory": "17846272", + "collector_rss": "231858176", + "collector_heap": "33163992", + "queue_logs": "0", + "queue_traces": "209455", + "sent_spans": "0", + "send_failed_spans": "2.19221413627764", + "enqueue_failed_spans": "MISSING", + "accepted_logs": "0.4471182561053331", + "api_error_5m": "0", + "api_p99": "0.02316666666666667", + "api_instances": [ + "2f5a79e18ab9", + "709c0280d839" + ], + "cgroup": [ + "mtusi-messenger-lab6-api-1 18.53MiB / 256MiB 7.24%", + "mtusi-messenger-lab6-api-2 14.72MiB / 256MiB 5.75%", + "mtusi-messenger-lab6-otel-collector-1 68.93MiB / 192MiB 35.90%" + ] + }, + { + "phase": "recovery", + "utc": "2026-11-06T14:23:07Z", + "api_memory": "17846272", + "collector_rss": "233185280", + "collector_heap": "39395888", + "queue_logs": "0", + "queue_traces": "0", + "sent_spans": "4.5300766550049705", + "send_failed_spans": "2.1106424564892077", + "enqueue_failed_spans": "MISSING", + "accepted_logs": "0.42755779665215454", + "api_error_5m": "0", + "api_p99": "0.0233", + "api_instances": [ + "2f5a79e18ab9", + "709c0280d839" + ], + "cgroup": [ + "mtusi-messenger-lab6-api-1 18.54MiB / 256MiB 7.24%", + "mtusi-messenger-lab6-api-2 14.73MiB / 256MiB 5.75%", + "mtusi-messenger-lab6-otel-collector-1 70.2MiB / 192MiB 36.56%" + ] + }, + { + "phase": "recovery", + "utc": "2026-11-06T14:23:20Z", + "api_memory": "19693568", + "collector_rss": "233189376", + "collector_heap": "42195304", + "queue_logs": "0", + "queue_traces": "0", + "sent_spans": "4.635190802912773", + "send_failed_spans": "1.8832583423254678", + "enqueue_failed_spans": "MISSING", + "accepted_logs": "0.4207640260330775", + "api_error_5m": "0", + "api_p99": "0.023181249999999997", + "api_instances": [ + "2f5a79e18ab9", + "709c0280d839" + ], + "cgroup": [ + "mtusi-messenger-lab6-api-1 18.54MiB / 256MiB 7.24%", + "mtusi-messenger-lab6-api-2 14.05MiB / 256MiB 5.49%", + "mtusi-messenger-lab6-otel-collector-1 70.2MiB / 192MiB 36.56%" + ] + } +] diff --git a/evidence/lab6/storage-down.txt b/evidence/lab6/storage-down.txt new file mode 100644 index 0000000..dfc70bd --- /dev/null +++ b/evidence/lab6/storage-down.txt @@ -0,0 +1,870 @@ +UTC 2026-11-06T14:30:14Z +HEAD 255f601a9946187c4c330828426c6458a89aad2b +load_exit= 0 +load_summary= {"counters": {"accepted": 31, "ready": 31, "failed": 0, "messages": 125, "uploads": 31, "dropped": 0}, "failures": 0, "failures_by_reason": {}, "duration_s": 775.03} +[ + { + "phase": "baseline", + "utc": "2026-11-06T14:16:36Z", + "api_memory": "19447808", + "collector_rss": "235225088", + "collector_heap": "49942672", + "queue_logs": "0", + "queue_traces": "0", + "sent_spans": "4.860972126582021", + "send_failed_spans": "0", + "enqueue_failed_spans": "MISSING", + "accepted_logs": "0.3324321482240321", + "api_error_5m": "0", + "api_p99": "0.02352142857142857", + "api_instances": [ + "2f5a79e18ab9", + "709c0280d839" + ], + "cgroup": [ + "mtusi-messenger-lab6-api-1 189.2MiB / 256MiB 73.92%", + "mtusi-messenger-lab6-api-2 187.9MiB / 256MiB 73.40%", + "mtusi-messenger-lab6-otel-collector-1 72.32MiB / 192MiB 37.67%" + ] + }, + { + "phase": "baseline", + "utc": "2026-11-06T14:16:48Z", + "api_memory": "198602752", + "collector_rss": "235229184", + "collector_heap": "52750392", + "queue_logs": "0", + "queue_traces": "0", + "sent_spans": "4.8270668530102165", + "send_failed_spans": "0", + "enqueue_failed_spans": "MISSING", + "accepted_logs": "0.342609804746333", + "api_error_5m": "0", + "api_p99": "0.07924999999999999", + "api_instances": [ + "2f5a79e18ab9", + "709c0280d839" + ], + "cgroup": [ + "mtusi-messenger-lab6-api-1 188.9MiB / 256MiB 73.78%", + "mtusi-messenger-lab6-api-2 188.1MiB / 256MiB 73.46%", + "mtusi-messenger-lab6-otel-collector-1 72.33MiB / 192MiB 37.67%" + ] + }, + { + "phase": "baseline", + "utc": "2026-11-06T14:17:00Z", + "api_memory": "197406720", + "collector_rss": "235229184", + "collector_heap": "55751416", + "queue_logs": "0", + "queue_traces": "0", + "sent_spans": "4.906714773043249", + "send_failed_spans": "0", + "enqueue_failed_spans": "MISSING", + "accepted_logs": "0.3424866565842212", + "api_error_5m": "0", + "api_p99": "0.07849999999999993", + "api_instances": [ + "2f5a79e18ab9", + "709c0280d839" + ], + "cgroup": [ + "mtusi-messenger-lab6-api-1 189MiB / 256MiB 73.84%", + "mtusi-messenger-lab6-api-2 188.1MiB / 256MiB 73.50%", + "mtusi-messenger-lab6-otel-collector-1 72.33MiB / 192MiB 37.67%" + ] + }, + { + "phase": "baseline", + "utc": "2026-11-06T14:17:12Z", + "api_memory": "198733824", + "collector_rss": "235233280", + "collector_heap": "32717896", + "queue_logs": "0", + "queue_traces": "0", + "sent_spans": "4.910172330771997", + "send_failed_spans": "0", + "enqueue_failed_spans": "MISSING", + "accepted_logs": "0.3424913020773284", + "api_error_5m": "0", + "api_p99": "0.07900000000000006", + "api_instances": [ + "2f5a79e18ab9", + "709c0280d839" + ], + "cgroup": [ + "mtusi-messenger-lab6-api-1 189.2MiB / 256MiB 73.91%", + "mtusi-messenger-lab6-api-2 188.3MiB / 256MiB 73.56%", + "mtusi-messenger-lab6-otel-collector-1 72.33MiB / 192MiB 37.67%" + ] + }, + { + "phase": "baseline", + "utc": "2026-11-06T14:17:25Z", + "api_memory": "198746112", + "collector_rss": "235233280", + "collector_heap": "35503232", + "queue_logs": "0", + "queue_traces": "0", + "sent_spans": "4.7575287977999405", + "send_failed_spans": "0", + "enqueue_failed_spans": "MISSING", + "accepted_logs": "0.3289239439676366", + "api_error_5m": "0", + "api_p99": "0.0795000000000001", + "api_instances": [ + "2f5a79e18ab9", + "709c0280d839" + ], + "cgroup": [ + "mtusi-messenger-lab6-api-1 187.5MiB / 256MiB 73.26%", + "mtusi-messenger-lab6-api-2 189.1MiB / 256MiB 73.88%", + "mtusi-messenger-lab6-otel-collector-1 72.34MiB / 192MiB 37.68%" + ] + }, + { + "phase": "baseline", + "utc": "2026-11-06T14:17:37Z", + "api_memory": "198746112", + "collector_rss": "235245568", + "collector_heap": "39833144", + "queue_logs": "0", + "queue_traces": "0", + "sent_spans": "4.811751660715557", + "send_failed_spans": "0", + "enqueue_failed_spans": "MISSING", + "accepted_logs": "0.3390945497333021", + "api_error_5m": "0", + "api_p99": "0.08075000000000006", + "api_instances": [ + "2f5a79e18ab9", + "709c0280d839" + ], + "cgroup": [ + "mtusi-messenger-lab6-api-1 188.4MiB / 256MiB 73.61%", + "mtusi-messenger-lab6-api-2 189.5MiB / 256MiB 74.01%", + "mtusi-messenger-lab6-otel-collector-1 72.34MiB / 192MiB 37.68%" + ] + }, + { + "phase": "down-start", + "utc": "2026-11-06T14:17:39Z", + "api_memory": "196960256", + "collector_rss": "235245568", + "collector_heap": "39833144", + "queue_logs": "0", + "queue_traces": "0", + "sent_spans": "4.811751660715557", + "send_failed_spans": "0", + "enqueue_failed_spans": "MISSING", + "accepted_logs": "0.3390945497333021", + "api_error_5m": "0", + "api_p99": "0.07874999999999993", + "api_instances": [ + "2f5a79e18ab9", + "709c0280d839" + ], + "cgroup": [ + "mtusi-messenger-lab6-api-1 188.4MiB / 256MiB 73.61%", + "mtusi-messenger-lab6-api-2 189.5MiB / 256MiB 74.02%", + "mtusi-messenger-lab6-otel-collector-1 72.35MiB / 192MiB 37.68%" + ] + }, + { + "phase": "down", + "utc": "2026-11-06T14:17:51Z", + "api_memory": "196960256", + "collector_rss": "235249664", + "collector_heap": "44557832", + "queue_logs": "5287", + "queue_traces": "17234", + "sent_spans": "4.665988470668022", + "send_failed_spans": "0", + "enqueue_failed_spans": "MISSING", + "accepted_logs": "0.36283485927433035", + "api_error_5m": "0", + "api_p99": "0.07950000000000007", + "api_instances": [ + "2f5a79e18ab9", + "709c0280d839" + ], + "cgroup": [ + "mtusi-messenger-lab6-api-1 189MiB / 256MiB 73.82%", + "mtusi-messenger-lab6-api-2 187.7MiB / 256MiB 73.33%", + "mtusi-messenger-lab6-otel-collector-1 72.35MiB / 192MiB 37.68%" + ] + }, + { + "phase": "down", + "utc": "2026-11-06T14:18:03Z", + "api_memory": "197980160", + "collector_rss": "235249664", + "collector_heap": "47533792", + "queue_logs": "6807", + "queue_traces": "22823", + "sent_spans": "4.516770034689609", + "send_failed_spans": "0", + "enqueue_failed_spans": "MISSING", + "accepted_logs": "0.3628336289127538", + "api_error_5m": "0", + "api_p99": "0.0774999999999999", + "api_instances": [ + "2f5a79e18ab9", + "709c0280d839" + ], + "cgroup": [ + "mtusi-messenger-lab6-api-1 188.1MiB / 256MiB 73.48%", + "mtusi-messenger-lab6-api-2 188MiB / 256MiB 73.43%", + "mtusi-messenger-lab6-otel-collector-1 72.35MiB / 192MiB 37.68%" + ] + }, + { + "phase": "down", + "utc": "2026-11-06T14:18:15Z", + "api_memory": "197365760", + "collector_rss": "235253760", + "collector_heap": "50792392", + "queue_logs": "7567", + "queue_traces": "26898", + "sent_spans": "4.411679931095053", + "send_failed_spans": "0.11868470222008212", + "enqueue_failed_spans": "MISSING", + "accepted_logs": "0.3730090641202581", + "api_error_5m": "0", + "api_p99": "0.07625000000000012", + "api_instances": [ + "2f5a79e18ab9", + "709c0280d839" + ], + "cgroup": [ + "mtusi-messenger-lab6-api-1 188.4MiB / 256MiB 73.58%", + "mtusi-messenger-lab6-api-2 188.7MiB / 256MiB 73.71%", + "mtusi-messenger-lab6-otel-collector-1 72.35MiB / 192MiB 37.68%" + ] + }, + { + "phase": "down", + "utc": "2026-11-06T14:18:27Z", + "api_memory": "197820416", + "collector_rss": "235257856", + "collector_heap": "55635944", + "queue_logs": "10262", + "queue_traces": "35035", + "sent_spans": "4.065812586046701", + "send_failed_spans": "0.34588230506819306", + "enqueue_failed_spans": "MISSING", + "accepted_logs": "0.3967473499311627", + "api_error_5m": "0", + "api_p99": "0.07549999999999997", + "api_instances": [ + "2f5a79e18ab9", + "709c0280d839" + ], + "cgroup": [ + "mtusi-messenger-lab6-api-1 95.14MiB / 256MiB 37.16%", + "mtusi-messenger-lab6-api-2 78.77MiB / 256MiB 30.77%", + "mtusi-messenger-lab6-otel-collector-1 72.35MiB / 192MiB 37.68%" + ] + }, + { + "phase": "down", + "utc": "2026-11-06T14:18:39Z", + "api_memory": "100081664", + "collector_rss": "235257856", + "collector_heap": "58521320", + "queue_logs": "14374", + "queue_traces": "47240", + "sent_spans": "3.9247080213976298", + "send_failed_spans": "0.4002727281978568", + "enqueue_failed_spans": "MISSING", + "accepted_logs": "0.3968805864334682", + "api_error_5m": "0", + "api_p99": "0.07549999999999987", + "api_instances": [ + "2f5a79e18ab9", + "709c0280d839" + ], + "cgroup": [ + "mtusi-messenger-lab6-api-1 95.32MiB / 256MiB 37.23%", + "mtusi-messenger-lab6-api-2 78.8MiB / 256MiB 30.78%", + "mtusi-messenger-lab6-otel-collector-1 72.8MiB / 192MiB 37.92%" + ] + }, + { + "phase": "down", + "utc": "2026-11-06T14:18:51Z", + "api_memory": "100081664", + "collector_rss": "235732992", + "collector_heap": "33370496", + "queue_logs": "15134", + "queue_traces": "53761", + "sent_spans": "3.727989090798075", + "send_failed_spans": "0.45794224500249325", + "enqueue_failed_spans": "MISSING", + "accepted_logs": "0.373138125557587", + "api_error_5m": "0", + "api_p99": "0.07624999999999998", + "api_instances": [ + "2f5a79e18ab9", + "709c0280d839" + ], + "cgroup": [ + "mtusi-messenger-lab6-api-1 19.49MiB / 256MiB 7.61%", + "mtusi-messenger-lab6-api-2 78.82MiB / 256MiB 30.79%", + "mtusi-messenger-lab6-otel-collector-1 72.81MiB / 192MiB 37.92%" + ] + }, + { + "phase": "down", + "utc": "2026-11-06T14:19:03Z", + "api_memory": "100519936", + "collector_rss": "235806720", + "collector_heap": "36385224", + "queue_logs": "16654", + "queue_traces": "54799", + "sent_spans": "3.3752039539072647", + "send_failed_spans": "0.5495306940029918", + "enqueue_failed_spans": "MISSING", + "accepted_logs": "0.3799224551131795", + "api_error_5m": "0", + "api_p99": "0.07549999999999987", + "api_instances": [ + "2f5a79e18ab9", + "709c0280d839" + ], + "cgroup": [ + "mtusi-messenger-lab6-api-1 19.49MiB / 256MiB 7.61%", + "mtusi-messenger-lab6-api-2 78.88MiB / 256MiB 30.81%", + "mtusi-messenger-lab6-otel-collector-1 72.81MiB / 192MiB 37.92%" + ] + }, + { + "phase": "down", + "utc": "2026-11-06T14:19:16Z", + "api_memory": "20692992", + "collector_rss": "235880448", + "collector_heap": "41257584", + "queue_logs": "19142", + "queue_traces": "68887", + "sent_spans": "3.065376917945297", + "send_failed_spans": "0.6537691794529688", + "enqueue_failed_spans": "MISSING", + "accepted_logs": "0.3769179452968646", + "api_error_5m": "0", + "api_p99": "0.07575000000000007", + "api_instances": [ + "2f5a79e18ab9", + "709c0280d839" + ], + "cgroup": [ + "mtusi-messenger-lab6-api-1 19.49MiB / 256MiB 7.61%", + "mtusi-messenger-lab6-api-2 78.9MiB / 256MiB 30.82%", + "mtusi-messenger-lab6-otel-collector-1 72.82MiB / 192MiB 37.93%" + ] + }, + { + "phase": "down", + "utc": "2026-11-06T14:19:28Z", + "api_memory": "20959232", + "collector_rss": "235880448", + "collector_heap": "44260552", + "queue_logs": "20661", + "queue_traces": "65858", + "sent_spans": "2.924016282225238", + "send_failed_spans": "0.8582089552238806", + "enqueue_failed_spans": "MISSING", + "accepted_logs": "0.3799185888738128", + "api_error_5m": "0", + "api_p99": "0.07624999999999983", + "api_instances": [ + "2f5a79e18ab9", + "709c0280d839" + ], + "cgroup": [ + "mtusi-messenger-lab6-api-1 19.5MiB / 256MiB 7.62%", + "mtusi-messenger-lab6-api-2 78.91MiB / 256MiB 30.83%", + "mtusi-messenger-lab6-otel-collector-1 72.82MiB / 192MiB 37.93%" + ] + }, + { + "phase": "down", + "utc": "2026-11-06T14:19:40Z", + "api_memory": "20717568", + "collector_rss": "235888640", + "collector_heap": "47361016", + "queue_logs": "19261", + "queue_traces": "72770", + "sent_spans": "2.6289277027920908", + "send_failed_spans": "0.8582176887824503", + "enqueue_failed_spans": "MISSING", + "accepted_logs": "0.3663537960019945", + "api_error_5m": "0", + "api_p99": "0.07674999999999987", + "api_instances": [ + "2f5a79e18ab9", + "709c0280d839" + ], + "cgroup": [ + "mtusi-messenger-lab6-api-1 19.52MiB / 256MiB 7.62%", + "mtusi-messenger-lab6-api-2 78.95MiB / 256MiB 30.84%", + "mtusi-messenger-lab6-otel-collector-1 72.83MiB / 192MiB 37.93%" + ] + }, + { + "phase": "down", + "utc": "2026-11-06T14:19:52Z", + "api_memory": "20717568", + "collector_rss": "235954176", + "collector_heap": "52161840", + "queue_logs": "23811", + "queue_traces": "87554", + "sent_spans": "2.2278663008941986", + "send_failed_spans": "0.9460802099687694", + "enqueue_failed_spans": "MISSING", + "accepted_logs": "0.3628336289127538", + "api_error_5m": "0", + "api_p99": "0.07875", + "api_instances": [ + "2f5a79e18ab9", + "709c0280d839" + ], + "cgroup": [ + "mtusi-messenger-lab6-api-1 18.1MiB / 256MiB 7.07%", + "mtusi-messenger-lab6-api-2 79.09MiB / 256MiB 30.89%", + "mtusi-messenger-lab6-otel-collector-1 72.83MiB / 192MiB 37.93%" + ] + }, + { + "phase": "down", + "utc": "2026-11-06T14:20:04Z", + "api_memory": "20987904", + "collector_rss": "235962368", + "collector_heap": "55371152", + "queue_logs": "24571", + "queue_traces": "90306", + "sent_spans": "2.078684833400023", + "send_failed_spans": "1.047819924177173", + "enqueue_failed_spans": "MISSING", + "accepted_logs": "0.38318333796770415", + "api_error_5m": "0", + "api_p99": "0.07774999999999985", + "api_instances": [ + "2f5a79e18ab9", + "709c0280d839" + ], + "cgroup": [ + "mtusi-messenger-lab6-api-1 18.1MiB / 256MiB 7.07%", + "mtusi-messenger-lab6-api-2 15.01MiB / 256MiB 5.86%", + "mtusi-messenger-lab6-otel-collector-1 68.88MiB / 192MiB 35.87%" + ] + }, + { + "phase": "down", + "utc": "2026-11-06T14:20:16Z", + "api_memory": "19234816", + "collector_rss": "231804928", + "collector_heap": "30398280", + "queue_logs": "25659", + "queue_traces": "96377", + "sent_spans": "1.8854040563315326", + "send_failed_spans": "1.2546753612278185", + "enqueue_failed_spans": "MISSING", + "accepted_logs": "0.3831846373479554", + "api_error_5m": "0", + "api_p99": "0.07599999999999993", + "api_instances": [ + "2f5a79e18ab9", + "709c0280d839" + ], + "cgroup": [ + "mtusi-messenger-lab6-api-1 18.09MiB / 256MiB 7.07%", + "mtusi-messenger-lab6-api-2 15.02MiB / 256MiB 5.87%", + "mtusi-messenger-lab6-otel-collector-1 68.87MiB / 192MiB 35.87%" + ] + }, + { + "phase": "down", + "utc": "2026-11-06T14:20:28Z", + "api_memory": "19234816", + "collector_rss": "231813120", + "collector_heap": "33688048", + "queue_logs": "27594", + "queue_traces": "101221", + "sent_spans": "1.831147824494654", + "send_failed_spans": "1.3462327524525513", + "enqueue_failed_spans": "MISSING", + "accepted_logs": "0.4103127532663947", + "api_error_5m": "0", + "api_p99": "0.07500000000000002", + "api_instances": [ + "2f5a79e18ab9", + "709c0280d839" + ], + "cgroup": [ + "mtusi-messenger-lab6-api-1 18.09MiB / 256MiB 7.07%", + "mtusi-messenger-lab6-api-2 15.02MiB / 256MiB 5.87%", + "mtusi-messenger-lab6-otel-collector-1 68.89MiB / 192MiB 35.88%" + ] + }, + { + "phase": "down", + "utc": "2026-11-06T14:20:40Z", + "api_memory": "19496960", + "collector_rss": "231817216", + "collector_heap": "36910680", + "queue_logs": "30512", + "queue_traces": "113187", + "sent_spans": "1.7910630026764178", + "send_failed_spans": "1.3975718884520534", + "enqueue_failed_spans": "MISSING", + "accepted_logs": "0.4240205972245308", + "api_error_5m": "0", + "api_p99": "0.07324999999999986", + "api_instances": [ + "2f5a79e18ab9", + "709c0280d839" + ], + "cgroup": [ + "mtusi-messenger-lab6-api-1 18.09MiB / 256MiB 7.07%", + "mtusi-messenger-lab6-api-2 15.05MiB / 256MiB 5.88%", + "mtusi-messenger-lab6-otel-collector-1 68.89MiB / 192MiB 35.88%" + ] + }, + { + "phase": "down", + "utc": "2026-11-06T14:20:52Z", + "api_memory": "19496960", + "collector_rss": "231821312", + "collector_heap": "41366880", + "queue_logs": "35822", + "queue_traces": "128858", + "sent_spans": "1.7469589345925005", + "send_failed_spans": "1.4518416000108547", + "enqueue_failed_spans": "MISSING", + "accepted_logs": "0.44776423177904867", + "api_error_5m": "0", + "api_p99": "0.07325", + "api_instances": [ + "2f5a79e18ab9", + "709c0280d839" + ], + "cgroup": [ + "mtusi-messenger-lab6-api-1 17.49MiB / 256MiB 6.83%", + "mtusi-messenger-lab6-api-2 15.05MiB / 256MiB 5.88%", + "mtusi-messenger-lab6-otel-collector-1 68.89MiB / 192MiB 35.88%" + ] + }, + { + "phase": "down", + "utc": "2026-11-06T14:21:04Z", + "api_memory": "19496960", + "collector_rss": "231821312", + "collector_heap": "44702392", + "queue_logs": "35822", + "queue_traces": "130372", + "sent_spans": "1.6994745536759195", + "send_failed_spans": "1.5400428091194958", + "enqueue_failed_spans": "MISSING", + "accepted_logs": "0.454550080224697", + "api_error_5m": "0", + "api_p99": "0.07250000000000008", + "api_instances": [ + "2f5a79e18ab9", + "709c0280d839" + ], + "cgroup": [ + "mtusi-messenger-lab6-api-1 17.48MiB / 256MiB 6.83%", + "mtusi-messenger-lab6-api-2 15.05MiB / 256MiB 5.88%", + "mtusi-messenger-lab6-otel-collector-1 68.89MiB / 192MiB 35.88%" + ] + }, + { + "phase": "down", + "utc": "2026-11-06T14:21:17Z", + "api_memory": "18595840", + "collector_rss": "231829504", + "collector_heap": "49175936", + "queue_logs": "38101", + "queue_traces": "137284", + "sent_spans": "1.6587404427378376", + "send_failed_spans": "1.5942904050854472", + "enqueue_failed_spans": "MISSING", + "accepted_logs": "0.47150290703590886", + "api_error_5m": "0", + "api_p99": "0.07174999999999984", + "api_instances": [ + "2f5a79e18ab9", + "709c0280d839" + ], + "cgroup": [ + "mtusi-messenger-lab6-api-1 17.48MiB / 256MiB 6.83%", + "mtusi-messenger-lab6-api-2 14.72MiB / 256MiB 5.75%", + "mtusi-messenger-lab6-otel-collector-1 68.89MiB / 192MiB 35.88%" + ] + }, + { + "phase": "down", + "utc": "2026-11-06T14:21:29Z", + "api_memory": "18595840", + "collector_rss": "231845888", + "collector_heap": "28314784", + "queue_logs": "41436", + "queue_traces": "151031", + "sent_spans": "1.6553651810216452", + "send_failed_spans": "1.6519730392572565", + "enqueue_failed_spans": "MISSING", + "accepted_logs": "0.4579391381924633", + "api_error_5m": "0", + "api_p99": "0.07000000000000008", + "api_instances": [ + "2f5a79e18ab9", + "709c0280d839" + ], + "cgroup": [ + "mtusi-messenger-lab6-api-1 17.48MiB / 256MiB 6.83%", + "mtusi-messenger-lab6-api-2 14.72MiB / 256MiB 5.75%", + "mtusi-messenger-lab6-otel-collector-1 68.91MiB / 192MiB 35.89%" + ] + }, + { + "phase": "down", + "utc": "2026-11-06T14:21:41Z", + "api_memory": "18595840", + "collector_rss": "231845888", + "collector_heap": "32877592", + "queue_logs": "43716", + "queue_traces": "160304", + "sent_spans": "1.139763499073942", + "send_failed_spans": "1.6519786430030055", + "enqueue_failed_spans": "MISSING", + "accepted_logs": "0.4308034654237817", + "api_error_5m": "0", + "api_p99": "0.02295625", + "api_instances": [ + "2f5a79e18ab9", + "709c0280d839" + ], + "cgroup": [ + "mtusi-messenger-lab6-api-1 17.48MiB / 256MiB 6.83%", + "mtusi-messenger-lab6-api-2 14.72MiB / 256MiB 5.75%", + "mtusi-messenger-lab6-otel-collector-1 68.91MiB / 192MiB 35.89%" + ] + }, + { + "phase": "down", + "utc": "2026-11-06T14:21:53Z", + "api_memory": "18595840", + "collector_rss": "231845888", + "collector_heap": "36050000", + "queue_logs": "40381", + "queue_traces": "150406", + "sent_spans": "0.7940305192755999", + "send_failed_spans": "1.9816830053715822", + "enqueue_failed_spans": "MISSING", + "accepted_logs": "0.4173750165423025", + "api_error_5m": "0", + "api_p99": "0.022835714285714282", + "api_instances": [ + "2f5a79e18ab9", + "709c0280d839" + ], + "cgroup": [ + "mtusi-messenger-lab6-api-1 18.2MiB / 256MiB 7.11%", + "mtusi-messenger-lab6-api-2 14.73MiB / 256MiB 5.75%", + "mtusi-messenger-lab6-otel-collector-1 68.91MiB / 192MiB 35.89%" + ] + }, + { + "phase": "down", + "utc": "2026-11-06T14:22:05Z", + "api_memory": "18595840", + "collector_rss": "231845888", + "collector_heap": "39159560", + "queue_logs": "43076", + "queue_traces": "158459", + "sent_spans": "0.6447300108246775", + "send_failed_spans": "1.9816964543242719", + "enqueue_failed_spans": "MISSING", + "accepted_logs": "0.43773774419149153", + "api_error_5m": "0", + "api_p99": "0.022835714285714286", + "api_instances": [ + "2f5a79e18ab9", + "709c0280d839" + ], + "cgroup": [ + "mtusi-messenger-lab6-api-1 18.36MiB / 256MiB 7.17%", + "mtusi-messenger-lab6-api-2 14.73MiB / 256MiB 5.75%", + "mtusi-messenger-lab6-otel-collector-1 68.91MiB / 192MiB 35.89%" + ] + }, + { + "phase": "down", + "utc": "2026-11-06T14:22:17Z", + "api_memory": "19341312", + "collector_rss": "231845888", + "collector_heap": "43874408", + "queue_logs": "47931", + "queue_traces": "174667", + "sent_spans": "0.4513125390232647", + "send_failed_spans": "2.0359964166463067", + "enqueue_failed_spans": "MISSING", + "accepted_logs": "0.458099193745419", + "api_error_5m": "0", + "api_p99": "0.022975", + "api_instances": [ + "2f5a79e18ab9", + "709c0280d839" + ], + "cgroup": [ + "mtusi-messenger-lab6-api-1 18.37MiB / 256MiB 7.17%", + "mtusi-messenger-lab6-api-2 14.73MiB / 256MiB 5.75%", + "mtusi-messenger-lab6-otel-collector-1 68.91MiB / 192MiB 35.89%" + ] + }, + { + "phase": "down", + "utc": "2026-11-06T14:22:29Z", + "api_memory": "19775488", + "collector_rss": "231845888", + "collector_heap": "47045432", + "queue_logs": "50851", + "queue_traces": "184628", + "sent_spans": "0.2816433038456187", + "send_failed_spans": "2.1242013037031002", + "enqueue_failed_spans": "MISSING", + "accepted_logs": "0.4343414806293879", + "api_error_5m": "0", + "api_p99": "0.023133333333333336", + "api_instances": [ + "2f5a79e18ab9", + "709c0280d839" + ], + "cgroup": [ + "mtusi-messenger-lab6-api-1 18.37MiB / 256MiB 7.17%", + "mtusi-messenger-lab6-api-2 14.73MiB / 256MiB 5.75%", + "mtusi-messenger-lab6-otel-collector-1 68.91MiB / 192MiB 35.89%" + ] + }, + { + "phase": "down", + "utc": "2026-11-06T14:22:41Z", + "api_memory": "19701760", + "collector_rss": "231858176", + "collector_heap": "51689352", + "queue_logs": "53241", + "queue_traces": "192480", + "sent_spans": "0", + "send_failed_spans": "2.178501381074863", + "enqueue_failed_spans": "MISSING", + "accepted_logs": "0.43094965015032344", + "api_error_5m": "0", + "api_p99": "0.023149999999999997", + "api_instances": [ + "2f5a79e18ab9", + "709c0280d839" + ], + "cgroup": [ + "mtusi-messenger-lab6-api-1 18.54MiB / 256MiB 7.24%", + "mtusi-messenger-lab6-api-2 14.73MiB / 256MiB 5.75%", + "mtusi-messenger-lab6-otel-collector-1 68.93MiB / 192MiB 35.90%" + ] + }, + { + "phase": "recovery-start", + "utc": "2026-11-06T14:22:44Z", + "api_memory": "19701760", + "collector_rss": "231858176", + "collector_heap": "51689352", + "queue_logs": "53241", + "queue_traces": "192480", + "sent_spans": "0", + "send_failed_spans": "2.178501381074863", + "enqueue_failed_spans": "MISSING", + "accepted_logs": "0.4309496501503233", + "api_error_5m": "0", + "api_p99": "0.023149999999999997", + "api_instances": [ + "2f5a79e18ab9", + "709c0280d839" + ], + "cgroup": [ + "mtusi-messenger-lab6-api-1 18.54MiB / 256MiB 7.24%", + "mtusi-messenger-lab6-api-2 14.73MiB / 256MiB 5.75%", + "mtusi-messenger-lab6-otel-collector-1 68.93MiB / 192MiB 35.90%" + ] + }, + { + "phase": "recovery", + "utc": "2026-11-06T14:22:55Z", + "api_memory": "17846272", + "collector_rss": "231858176", + "collector_heap": "33163992", + "queue_logs": "0", + "queue_traces": "209455", + "sent_spans": "0", + "send_failed_spans": "2.19221413627764", + "enqueue_failed_spans": "MISSING", + "accepted_logs": "0.4471182561053331", + "api_error_5m": "0", + "api_p99": "0.02316666666666667", + "api_instances": [ + "2f5a79e18ab9", + "709c0280d839" + ], + "cgroup": [ + "mtusi-messenger-lab6-api-1 18.53MiB / 256MiB 7.24%", + "mtusi-messenger-lab6-api-2 14.72MiB / 256MiB 5.75%", + "mtusi-messenger-lab6-otel-collector-1 68.93MiB / 192MiB 35.90%" + ] + }, + { + "phase": "recovery", + "utc": "2026-11-06T14:23:07Z", + "api_memory": "17846272", + "collector_rss": "233185280", + "collector_heap": "39395888", + "queue_logs": "0", + "queue_traces": "0", + "sent_spans": "4.5300766550049705", + "send_failed_spans": "2.1106424564892077", + "enqueue_failed_spans": "MISSING", + "accepted_logs": "0.42755779665215454", + "api_error_5m": "0", + "api_p99": "0.0233", + "api_instances": [ + "2f5a79e18ab9", + "709c0280d839" + ], + "cgroup": [ + "mtusi-messenger-lab6-api-1 18.54MiB / 256MiB 7.24%", + "mtusi-messenger-lab6-api-2 14.73MiB / 256MiB 5.75%", + "mtusi-messenger-lab6-otel-collector-1 70.2MiB / 192MiB 36.56%" + ] + }, + { + "phase": "recovery", + "utc": "2026-11-06T14:23:20Z", + "api_memory": "19693568", + "collector_rss": "233189376", + "collector_heap": "42195304", + "queue_logs": "0", + "queue_traces": "0", + "sent_spans": "4.635190802912773", + "send_failed_spans": "1.8832583423254678", + "enqueue_failed_spans": "MISSING", + "accepted_logs": "0.4207640260330775", + "api_error_5m": "0", + "api_p99": "0.023181249999999997", + "api_instances": [ + "2f5a79e18ab9", + "709c0280d839" + ], + "cgroup": [ + "mtusi-messenger-lab6-api-1 18.54MiB / 256MiB 7.24%", + "mtusi-messenger-lab6-api-2 14.05MiB / 256MiB 5.49%", + "mtusi-messenger-lab6-otel-collector-1 70.2MiB / 192MiB 36.56%" + ] + } +] diff --git a/evidence/lab6/telemetry.txt b/evidence/lab6/telemetry.txt new file mode 100644 index 0000000..a1f22c3 --- /dev/null +++ b/evidence/lab6/telemetry.txt @@ -0,0 +1,5 @@ +env -u HTTP_PROXY -u HTTPS_PROXY -u ALL_PROXY -u http_proxy -u https_proxy -u all_proxy NO_PROXY=localhost,127.0.0.1,::1 no_proxy=localhost,127.0.0.1,::1 python3 scripts/check_evidence.py +PASS: evidence has no obvious secrets, signed URLs or bearer tokens +env -u HTTP_PROXY -u HTTPS_PROXY -u ALL_PROXY -u http_proxy -u https_proxy -u all_proxy NO_PROXY=localhost,127.0.0.1,::1 no_proxy=localhost,127.0.0.1,::1 python3 scripts/lab6_verify.py --base-url "http://localhost:8080" +NOTE: created request_id=lab6-verify-4bb0892c6612450eaaa6eef0fc44e854 +PASS: lab6 strict telemetry gate (signals, trace/log correlation, labels, Grafana, rules, privacy sentinels) diff --git a/evidence/lab6/tempo-search.json b/evidence/lab6/tempo-search.json new file mode 100644 index 0000000..0353eae --- /dev/null +++ b/evidence/lab6/tempo-search.json @@ -0,0 +1,148 @@ +{ + "traces": [ + { + "traceID": "ab5d63adca313645838a34fc3ad7f8ca", + "rootServiceName": "messenger-api", + "rootTraceName": "POST /api/v1/chats/{chat_id}/attachments", + "startTimeUnixNano": "1793802395453580634", + "durationMs": 331 + }, + { + "traceID": "5cf3ce94777116f51994548bcf747052", + "rootServiceName": "messenger-api", + "rootTraceName": "POST /api/v1/chats/{chat_id}/attachments", + "startTimeUnixNano": "1793802394113546330", + "durationMs": 684 + }, + { + "traceID": "280c2940aca363c6df3cdb2f96d49986", + "rootServiceName": "messenger-relay", + "rootTraceName": "job.requeue", + "startTimeUnixNano": "1793802302815608431", + "durationMs": 10295 + }, + { + "traceID": "2baabe5633a1fdffc903471dbf0ad125", + "rootServiceName": "", + "startTimeUnixNano": "1793802286828434101", + "durationMs": 26284 + }, + { + "traceID": "82ccdbe9637df43f06ffe9395c93b2c0", + "rootServiceName": "", + "startTimeUnixNano": "1793802283997651340", + "durationMs": 66 + }, + { + "traceID": "8f101cc3cd1062641cd9eaa83c59c643", + "rootServiceName": "messenger-relay", + "rootTraceName": "job.requeue", + "startTimeUnixNano": "1793802249508919589", + "durationMs": 1057 + }, + { + "traceID": "61b680a368c7eec86c2102ea3615e732", + "rootServiceName": "messenger-api", + "rootTraceName": "POST /api/v1/chats/{chat_id}/attachments", + "startTimeUnixNano": "1793802231049714535", + "durationMs": 6522 + }, + { + "traceID": "1767197f0752b7ebbfff4207d9ce968", + "rootServiceName": "messenger-api", + "rootTraceName": "POST /api/v1/chats/{chat_id}/attachments", + "startTimeUnixNano": "1793802229382459658", + "durationMs": 5632 + }, + { + "traceID": "3a1357d5589a82f6a6c0c39e705f3ecb", + "rootServiceName": "messenger-relay", + "rootTraceName": "job.requeue", + "startTimeUnixNano": "1793802226689471392", + "durationMs": 1053 + }, + { + "traceID": "74f025e1b6e88b5d9cfdc4f99069efdf", + "rootServiceName": "messenger-api", + "rootTraceName": "POST /api/v1/chats/{chat_id}/attachments", + "startTimeUnixNano": "1793802208176199125", + "durationMs": 6582 + }, + { + "traceID": "b9167e578de7e82af6e6105d5ec0a2e9", + "rootServiceName": "messenger-api", + "rootTraceName": "POST /api/v1/chats/{chat_id}/attachments", + "startTimeUnixNano": "1793802200775289740", + "durationMs": 4342 + }, + { + "traceID": "14e39e95e83064c0adfcba0877b44c49", + "rootServiceName": "messenger-relay", + "rootTraceName": "job.publish", + "startTimeUnixNano": "1793802200114468641", + "durationMs": 36 + }, + { + "traceID": "887eb29fbf7ad92e0c27c32e027f32b0", + "rootServiceName": "messenger-relay", + "rootTraceName": "job.publish", + "startTimeUnixNano": "1793802197116311702", + "durationMs": 9 + }, + { + "traceID": "5672c6454888c536c5f006c8266522a4", + "rootServiceName": "messenger-api", + "rootTraceName": "POST /api/v1/chats/{chat_id}/attachments", + "startTimeUnixNano": "1793802194349063459", + "durationMs": 2399 + }, + { + "traceID": "40ef0be37efbba23776a3dc2b83bd7f5", + "rootServiceName": "messenger-relay", + "rootTraceName": "job.publish", + "startTimeUnixNano": "1793802192116769803", + "durationMs": 1754 + }, + { + "traceID": "c16f04beae65b3b9f62855e8a7ea984e", + "rootServiceName": "messenger-api", + "rootTraceName": "POST /api/v1/chats/{chat_id}/attachments", + "startTimeUnixNano": "1793802188641651123", + "durationMs": 481 + }, + { + "traceID": "c7c01244d150f988c198e5b23767d8c2", + "rootServiceName": "messenger-relay", + "rootTraceName": "job.publish", + "startTimeUnixNano": "1793802186116479256", + "durationMs": 46 + }, + { + "traceID": "2abac52091c4e48c83f257b01c8b9afb", + "rootServiceName": "messenger-api", + "rootTraceName": "POST /api/v1/chats/{chat_id}/attachments", + "startTimeUnixNano": "1793802180136938542", + "durationMs": 987 + }, + { + "traceID": "c21959639cf799d78b3dd30fa8fb14cc", + "rootServiceName": "messenger-api", + "rootTraceName": "POST /api/v1/chats/{chat_id}/attachments", + "startTimeUnixNano": "1793802140038435535", + "durationMs": 108 + }, + { + "traceID": "b9e0d22c746e6dedefd32b6ea29682e0", + "rootServiceName": "messenger-api", + "rootTraceName": "POST /api/v1/chats/{chat_id}/attachments", + "startTimeUnixNano": "1793802138735163857", + "durationMs": 427 + } + ], + "metrics": { + "inspectedTraces": 3709, + "inspectedBytes": "595516", + "completedJobs": 1, + "totalJobs": 1 + } +} diff --git a/evidence/lab6/trace-pipeline.json b/evidence/lab6/trace-pipeline.json new file mode 100644 index 0000000..40f4237 --- /dev/null +++ b/evidence/lab6/trace-pipeline.json @@ -0,0 +1,1776 @@ +{ + "batches": [ + { + "resource": { + "attributes": [ + { + "key": "deployment.environment.name", + "value": { + "stringValue": "lab" + } + }, + { + "key": "service.instance.id", + "value": { + "stringValue": "e8a057b9355c" + } + }, + { + "key": "service.version", + "value": { + "stringValue": "dev" + } + }, + { + "key": "telemetry.sdk.language", + "value": { + "stringValue": "go" + } + }, + { + "key": "telemetry.sdk.name", + "value": { + "stringValue": "opentelemetry" + } + }, + { + "key": "telemetry.sdk.version", + "value": { + "stringValue": "1.47.0" + } + }, + { + "key": "service.name", + "value": { + "stringValue": "messenger-relay" + } + } + ] + }, + "scopeSpans": [ + { + "scope": { + "name": "messenger/queue" + }, + "spans": [ + { + "traceId": "q11jrcoxNkWDijT8Otf4yg==", + "spanId": "oN85QJB5xaA=", + "parentSpanId": "PYX0hZrvFv4=", + "name": "job.publish", + "kind": "SPAN_KIND_PRODUCER", + "startTimeUnixNano": "1793802395736654878", + "endTimeUnixNano": "1793802395739327243", + "attributes": [ + { + "key": "messaging.system", + "value": { + "stringValue": "rabbitmq" + } + }, + { + "key": "messaging.operation", + "value": { + "stringValue": "publish" + } + }, + { + "key": "messaging.destination.name", + "value": { + "stringValue": "attachment.process.v1" + } + }, + { + "key": "job.id", + "value": { + "stringValue": "01a1a6f4-5f40-77db-9331-2261a2c747b0" + } + }, + { + "key": "job.type", + "value": { + "stringValue": "attachment.process.v1" + } + }, + { + "key": "job.attempt", + "value": { + "intValue": "1" + } + } + ], + "status": {} + } + ] + } + ] + }, + { + "resource": { + "attributes": [ + { + "key": "deployment.environment.name", + "value": { + "stringValue": "lab" + } + }, + { + "key": "service.instance.id", + "value": { + "stringValue": "d97e22fe420e" + } + }, + { + "key": "service.version", + "value": { + "stringValue": "dev" + } + }, + { + "key": "telemetry.sdk.language", + "value": { + "stringValue": "go" + } + }, + { + "key": "telemetry.sdk.name", + "value": { + "stringValue": "opentelemetry" + } + }, + { + "key": "telemetry.sdk.version", + "value": { + "stringValue": "1.47.0" + } + }, + { + "key": "service.name", + "value": { + "stringValue": "messenger-worker" + } + } + ] + }, + "scopeSpans": [ + { + "scope": { + "name": "messenger/s3" + }, + "spans": [ + { + "traceId": "q11jrcoxNkWDijT8Otf4yg==", + "spanId": "sPjksIkMlbU=", + "parentSpanId": "0o4HJmhKdUc=", + "name": "S3.GetObject", + "kind": "SPAN_KIND_CLIENT", + "startTimeUnixNano": "1793802395743690577", + "endTimeUnixNano": "1793802395748370487", + "attributes": [ + { + "key": "rpc.system", + "value": { + "stringValue": "aws.s3" + } + }, + { + "key": "rpc.service", + "value": { + "stringValue": "S3" + } + }, + { + "key": "rpc.method", + "value": { + "stringValue": "GetObject" + } + }, + { + "key": "aws.s3.operation", + "value": { + "stringValue": "GetObject" + } + }, + { + "key": "aws.s3.object.size", + "value": { + "intValue": "111817" + } + } + ], + "status": {} + }, + { + "traceId": "q11jrcoxNkWDijT8Otf4yg==", + "spanId": "KOGfMHgDV68=", + "parentSpanId": "0o4HJmhKdUc=", + "name": "S3.PutObject", + "kind": "SPAN_KIND_CLIENT", + "startTimeUnixNano": "1793802395754326456", + "endTimeUnixNano": "1793802395758256714", + "attributes": [ + { + "key": "rpc.system", + "value": { + "stringValue": "aws.s3" + } + }, + { + "key": "rpc.service", + "value": { + "stringValue": "S3" + } + }, + { + "key": "rpc.method", + "value": { + "stringValue": "PutObject" + } + }, + { + "key": "aws.s3.operation", + "value": { + "stringValue": "PutObject" + } + }, + { + "key": "aws.s3.object.size", + "value": { + "intValue": "111817" + } + } + ], + "status": {} + }, + { + "traceId": "q11jrcoxNkWDijT8Otf4yg==", + "spanId": "DjUiBygbyvo=", + "parentSpanId": "0o4HJmhKdUc=", + "name": "S3.PutObject", + "kind": "SPAN_KIND_CLIENT", + "startTimeUnixNano": "1793802395760192469", + "endTimeUnixNano": "1793802395766000982", + "attributes": [ + { + "key": "rpc.system", + "value": { + "stringValue": "aws.s3" + } + }, + { + "key": "rpc.service", + "value": { + "stringValue": "S3" + } + }, + { + "key": "rpc.method", + "value": { + "stringValue": "PutObject" + } + }, + { + "key": "aws.s3.operation", + "value": { + "stringValue": "PutObject" + } + }, + { + "key": "aws.s3.object.size", + "value": { + "intValue": "5653" + } + } + ], + "status": {} + }, + { + "traceId": "q11jrcoxNkWDijT8Otf4yg==", + "spanId": "rO05iZLOiZI=", + "parentSpanId": "0o4HJmhKdUc=", + "name": "S3.PutObject", + "kind": "SPAN_KIND_CLIENT", + "startTimeUnixNano": "1793802395767125545", + "endTimeUnixNano": "1793802395771114302", + "attributes": [ + { + "key": "rpc.system", + "value": { + "stringValue": "aws.s3" + } + }, + { + "key": "rpc.service", + "value": { + "stringValue": "S3" + } + }, + { + "key": "rpc.method", + "value": { + "stringValue": "PutObject" + } + }, + { + "key": "aws.s3.operation", + "value": { + "stringValue": "PutObject" + } + }, + { + "key": "aws.s3.object.size", + "value": { + "intValue": "2441" + } + } + ], + "status": {} + }, + { + "traceId": "q11jrcoxNkWDijT8Otf4yg==", + "spanId": "Xd0hQfAjGZA=", + "parentSpanId": "0o4HJmhKdUc=", + "name": "S3.PutObject", + "kind": "SPAN_KIND_CLIENT", + "startTimeUnixNano": "1793802395779580848", + "endTimeUnixNano": "1793802395781121610", + "attributes": [ + { + "key": "rpc.system", + "value": { + "stringValue": "aws.s3" + } + }, + { + "key": "rpc.service", + "value": { + "stringValue": "S3" + } + }, + { + "key": "rpc.method", + "value": { + "stringValue": "PutObject" + } + }, + { + "key": "aws.s3.operation", + "value": { + "stringValue": "PutObject" + } + }, + { + "key": "aws.s3.object.size", + "value": { + "intValue": "2588" + } + } + ], + "status": {} + }, + { + "traceId": "q11jrcoxNkWDijT8Otf4yg==", + "spanId": "p4zv1IBZl0U=", + "parentSpanId": "0o4HJmhKdUc=", + "name": "S3.DeleteObject", + "kind": "SPAN_KIND_CLIENT", + "startTimeUnixNano": "1793802395783437774", + "endTimeUnixNano": "1793802395784156218", + "attributes": [ + { + "key": "rpc.system", + "value": { + "stringValue": "aws.s3" + } + }, + { + "key": "rpc.service", + "value": { + "stringValue": "S3" + } + }, + { + "key": "rpc.method", + "value": { + "stringValue": "DeleteObject" + } + }, + { + "key": "aws.s3.operation", + "value": { + "stringValue": "DeleteObject" + } + } + ], + "status": {} + } + ] + }, + { + "scope": { + "name": "github.com/exaring/otelpgx", + "version": "v0.13.0" + }, + "spans": [ + { + "traceId": "q11jrcoxNkWDijT8Otf4yg==", + "spanId": "cPpoLv8+Hw0=", + "parentSpanId": "0o4HJmhKdUc=", + "name": "pool.acquire", + "kind": "SPAN_KIND_CLIENT", + "startTimeUnixNano": "1793802395740442681", + "endTimeUnixNano": "1793802395740481722", + "attributes": [ + { + "key": "db.system.name", + "value": { + "stringValue": "postgresql" + } + } + ], + "status": {} + }, + { + "traceId": "q11jrcoxNkWDijT8Otf4yg==", + "spanId": "7QHwOwW9lRw=", + "parentSpanId": "0o4HJmhKdUc=", + "name": "BEGIN", + "kind": "SPAN_KIND_CLIENT", + "startTimeUnixNano": "1793802395740522096", + "endTimeUnixNano": "1793802395740688676", + "attributes": [ + { + "key": "db.system.name", + "value": { + "stringValue": "postgresql" + } + }, + { + "key": "pgx.rows_affected", + "value": { + "intValue": "0" + } + } + ], + "status": {} + }, + { + "traceId": "q11jrcoxNkWDijT8Otf4yg==", + "spanId": "K7AJi/h9yfM=", + "parentSpanId": "0o4HJmhKdUc=", + "name": "SELECT", + "kind": "SPAN_KIND_CLIENT", + "startTimeUnixNano": "1793802395740710426", + "endTimeUnixNano": "1793802395741213167", + "attributes": [ + { + "key": "db.system.name", + "value": { + "stringValue": "postgresql" + } + }, + { + "key": "pgx.rows_affected", + "value": { + "intValue": "1" + } + } + ], + "status": {} + }, + { + "traceId": "q11jrcoxNkWDijT8Otf4yg==", + "spanId": "1G/J5zes0OM=", + "parentSpanId": "0o4HJmhKdUc=", + "name": "SELECT", + "kind": "SPAN_KIND_CLIENT", + "startTimeUnixNano": "1793802395741234457", + "endTimeUnixNano": "1793802395741553617", + "attributes": [ + { + "key": "db.system.name", + "value": { + "stringValue": "postgresql" + } + }, + { + "key": "pgx.rows_affected", + "value": { + "intValue": "1" + } + } + ], + "status": {} + }, + { + "traceId": "q11jrcoxNkWDijT8Otf4yg==", + "spanId": "TmKUClTHGFc=", + "parentSpanId": "0o4HJmhKdUc=", + "name": "UPDATE", + "kind": "SPAN_KIND_CLIENT", + "startTimeUnixNano": "1793802395741571492", + "endTimeUnixNano": "1793802395742012692", + "attributes": [ + { + "key": "db.system.name", + "value": { + "stringValue": "postgresql" + } + }, + { + "key": "pgx.rows_affected", + "value": { + "intValue": "1" + } + } + ], + "status": {} + }, + { + "traceId": "q11jrcoxNkWDijT8Otf4yg==", + "spanId": "zPZSfI4gCDE=", + "parentSpanId": "0o4HJmhKdUc=", + "name": "UPDATE", + "kind": "SPAN_KIND_CLIENT", + "startTimeUnixNano": "1793802395742029692", + "endTimeUnixNano": "1793802395742564056", + "attributes": [ + { + "key": "db.system.name", + "value": { + "stringValue": "postgresql" + } + }, + { + "key": "pgx.rows_affected", + "value": { + "intValue": "1" + } + } + ], + "status": {} + }, + { + "traceId": "q11jrcoxNkWDijT8Otf4yg==", + "spanId": "SV1e22mLLcY=", + "parentSpanId": "0o4HJmhKdUc=", + "name": "INSERT", + "kind": "SPAN_KIND_CLIENT", + "startTimeUnixNano": "1793802395742573682", + "endTimeUnixNano": "1793802395742858468", + "attributes": [ + { + "key": "db.system.name", + "value": { + "stringValue": "postgresql" + } + }, + { + "key": "pgx.rows_affected", + "value": { + "intValue": "1" + } + } + ], + "status": {} + }, + { + "traceId": "q11jrcoxNkWDijT8Otf4yg==", + "spanId": "OE6OO5Dijz0=", + "parentSpanId": "0o4HJmhKdUc=", + "name": "COMMIT", + "kind": "SPAN_KIND_CLIENT", + "startTimeUnixNano": "1793802395742867676", + "endTimeUnixNano": "1793802395743466206", + "attributes": [ + { + "key": "db.system.name", + "value": { + "stringValue": "postgresql" + } + }, + { + "key": "pgx.rows_affected", + "value": { + "intValue": "0" + } + } + ], + "status": {} + }, + { + "traceId": "q11jrcoxNkWDijT8Otf4yg==", + "spanId": "RNy722+Sshs=", + "parentSpanId": "0o4HJmhKdUc=", + "name": "pool.acquire", + "kind": "SPAN_KIND_CLIENT", + "startTimeUnixNano": "1793802395781135234", + "endTimeUnixNano": "1793802395781147693", + "attributes": [ + { + "key": "db.system.name", + "value": { + "stringValue": "postgresql" + } + } + ], + "status": {} + }, + { + "traceId": "q11jrcoxNkWDijT8Otf4yg==", + "spanId": "dsDrBFLuC54=", + "parentSpanId": "0o4HJmhKdUc=", + "name": "BEGIN", + "kind": "SPAN_KIND_CLIENT", + "startTimeUnixNano": "1793802395781150484", + "endTimeUnixNano": "1793802395781209899", + "attributes": [ + { + "key": "db.system.name", + "value": { + "stringValue": "postgresql" + } + }, + { + "key": "pgx.rows_affected", + "value": { + "intValue": "0" + } + } + ], + "status": {} + }, + { + "traceId": "q11jrcoxNkWDijT8Otf4yg==", + "spanId": "729wTBL1Hlc=", + "parentSpanId": "0o4HJmhKdUc=", + "name": "SELECT", + "kind": "SPAN_KIND_CLIENT", + "startTimeUnixNano": "1793802395781216900", + "endTimeUnixNano": "1793802395781404313", + "attributes": [ + { + "key": "db.system.name", + "value": { + "stringValue": "postgresql" + } + }, + { + "key": "pgx.rows_affected", + "value": { + "intValue": "1" + } + } + ], + "status": {} + }, + { + "traceId": "q11jrcoxNkWDijT8Otf4yg==", + "spanId": "Xx1FREDbGyY=", + "parentSpanId": "0o4HJmhKdUc=", + "name": "SELECT", + "kind": "SPAN_KIND_CLIENT", + "startTimeUnixNano": "1793802395781408229", + "endTimeUnixNano": "1793802395782070758", + "attributes": [ + { + "key": "db.system.name", + "value": { + "stringValue": "postgresql" + } + }, + { + "key": "pgx.rows_affected", + "value": { + "intValue": "1" + } + } + ], + "status": {} + }, + { + "traceId": "q11jrcoxNkWDijT8Otf4yg==", + "spanId": "Nb2AV4LFXJ4=", + "parentSpanId": "0o4HJmhKdUc=", + "name": "INSERT", + "kind": "SPAN_KIND_CLIENT", + "startTimeUnixNano": "1793802395782078508", + "endTimeUnixNano": "1793802395782260463", + "attributes": [ + { + "key": "db.system.name", + "value": { + "stringValue": "postgresql" + } + }, + { + "key": "pgx.rows_affected", + "value": { + "intValue": "1" + } + } + ], + "status": {} + }, + { + "traceId": "q11jrcoxNkWDijT8Otf4yg==", + "spanId": "1sQr4MKHMuM=", + "parentSpanId": "0o4HJmhKdUc=", + "name": "INSERT", + "kind": "SPAN_KIND_CLIENT", + "startTimeUnixNano": "1793802395782263046", + "endTimeUnixNano": "1793802395782398627", + "attributes": [ + { + "key": "db.system.name", + "value": { + "stringValue": "postgresql" + } + }, + { + "key": "pgx.rows_affected", + "value": { + "intValue": "1" + } + } + ], + "status": {} + }, + { + "traceId": "q11jrcoxNkWDijT8Otf4yg==", + "spanId": "HJ33M4VLlY4=", + "parentSpanId": "0o4HJmhKdUc=", + "name": "INSERT", + "kind": "SPAN_KIND_CLIENT", + "startTimeUnixNano": "1793802395782408460", + "endTimeUnixNano": "1793802395782594790", + "attributes": [ + { + "key": "db.system.name", + "value": { + "stringValue": "postgresql" + } + }, + { + "key": "pgx.rows_affected", + "value": { + "intValue": "1" + } + } + ], + "status": {} + }, + { + "traceId": "q11jrcoxNkWDijT8Otf4yg==", + "spanId": "6YX3a2r14Ro=", + "parentSpanId": "0o4HJmhKdUc=", + "name": "UPDATE", + "kind": "SPAN_KIND_CLIENT", + "startTimeUnixNano": "1793802395782598248", + "endTimeUnixNano": "1793802395782788953", + "attributes": [ + { + "key": "db.system.name", + "value": { + "stringValue": "postgresql" + } + }, + { + "key": "pgx.rows_affected", + "value": { + "intValue": "1" + } + } + ], + "status": {} + }, + { + "traceId": "q11jrcoxNkWDijT8Otf4yg==", + "spanId": "AcwmdvpVhxY=", + "parentSpanId": "0o4HJmhKdUc=", + "name": "UPDATE", + "kind": "SPAN_KIND_CLIENT", + "startTimeUnixNano": "1793802395782795078", + "endTimeUnixNano": "1793802395782927992", + "attributes": [ + { + "key": "db.system.name", + "value": { + "stringValue": "postgresql" + } + }, + { + "key": "pgx.rows_affected", + "value": { + "intValue": "1" + } + } + ], + "status": {} + }, + { + "traceId": "q11jrcoxNkWDijT8Otf4yg==", + "spanId": "vqusgHDzIk8=", + "parentSpanId": "0o4HJmhKdUc=", + "name": "INSERT", + "kind": "SPAN_KIND_CLIENT", + "startTimeUnixNano": "1793802395782930950", + "endTimeUnixNano": "1793802395783029490", + "attributes": [ + { + "key": "db.system.name", + "value": { + "stringValue": "postgresql" + } + }, + { + "key": "pgx.rows_affected", + "value": { + "intValue": "1" + } + } + ], + "status": {} + }, + { + "traceId": "q11jrcoxNkWDijT8Otf4yg==", + "spanId": "7fQbGRyppzI=", + "parentSpanId": "0o4HJmhKdUc=", + "name": "COMMIT", + "kind": "SPAN_KIND_CLIENT", + "startTimeUnixNano": "1793802395783036573", + "endTimeUnixNano": "1793802395783365400", + "attributes": [ + { + "key": "db.system.name", + "value": { + "stringValue": "postgresql" + } + }, + { + "key": "pgx.rows_affected", + "value": { + "intValue": "0" + } + } + ], + "status": {} + }, + { + "traceId": "q11jrcoxNkWDijT8Otf4yg==", + "spanId": "6GainDTI+UU=", + "parentSpanId": "0o4HJmhKdUc=", + "name": "pool.acquire", + "kind": "SPAN_KIND_CLIENT", + "startTimeUnixNano": "1793802395784160843", + "endTimeUnixNano": "1793802395784165509", + "attributes": [ + { + "key": "db.system.name", + "value": { + "stringValue": "postgresql" + } + } + ], + "status": {} + }, + { + "traceId": "q11jrcoxNkWDijT8Otf4yg==", + "spanId": "+lk0shUxPWw=", + "parentSpanId": "0o4HJmhKdUc=", + "name": "UPDATE", + "kind": "SPAN_KIND_CLIENT", + "startTimeUnixNano": "1793802395784166885", + "endTimeUnixNano": "1793802395784543795", + "attributes": [ + { + "key": "db.system.name", + "value": { + "stringValue": "postgresql" + } + }, + { + "key": "pgx.rows_affected", + "value": { + "intValue": "1" + } + } + ], + "status": {} + } + ] + }, + { + "scope": { + "name": "messenger/worker" + }, + "spans": [ + { + "traceId": "q11jrcoxNkWDijT8Otf4yg==", + "spanId": "0o4HJmhKdUc=", + "parentSpanId": "oN85QJB5xaA=", + "name": "job.process", + "kind": "SPAN_KIND_CONSUMER", + "startTimeUnixNano": "1793802395740407265", + "endTimeUnixNano": "1793802395784624751", + "attributes": [ + { + "key": "messaging.system", + "value": { + "stringValue": "rabbitmq" + } + }, + { + "key": "messaging.operation", + "value": { + "stringValue": "process" + } + }, + { + "key": "messaging.destination.name", + "value": { + "stringValue": "attachment.process.v1" + } + }, + { + "key": "job.id", + "value": { + "stringValue": "01a1a6f4-5f40-77db-9331-2261a2c747b0" + } + }, + { + "key": "job.type", + "value": { + "stringValue": "attachment.process.v1" + } + }, + { + "key": "job.attempt", + "value": { + "intValue": "1" + } + }, + { + "key": "pipeline.version", + "value": { + "intValue": "1" + } + } + ], + "status": {} + } + ] + } + ] + }, + { + "resource": { + "attributes": [ + { + "key": "deployment.environment.name", + "value": { + "stringValue": "lab" + } + }, + { + "key": "service.instance.id", + "value": { + "stringValue": "05930701c929" + } + }, + { + "key": "service.version", + "value": { + "stringValue": "dev" + } + }, + { + "key": "telemetry.sdk.language", + "value": { + "stringValue": "go" + } + }, + { + "key": "telemetry.sdk.name", + "value": { + "stringValue": "opentelemetry" + } + }, + { + "key": "telemetry.sdk.version", + "value": { + "stringValue": "1.47.0" + } + }, + { + "key": "service.name", + "value": { + "stringValue": "messenger-api" + } + } + ] + }, + "scopeSpans": [ + { + "scope": { + "name": "github.com/exaring/otelpgx", + "version": "v0.13.0" + }, + "spans": [ + { + "traceId": "q11jrcoxNkWDijT8Otf4yg==", + "spanId": "kZ57mfnH2bU=", + "parentSpanId": "PYX0hZrvFv4=", + "name": "pool.acquire", + "kind": "SPAN_KIND_CLIENT", + "startTimeUnixNano": "1793802395453611509", + "endTimeUnixNano": "1793802395453615925", + "attributes": [ + { + "key": "db.system.name", + "value": { + "stringValue": "postgresql" + } + } + ], + "status": {} + }, + { + "traceId": "q11jrcoxNkWDijT8Otf4yg==", + "spanId": "cgWz+XzfPmg=", + "parentSpanId": "PYX0hZrvFv4=", + "name": "SELECT", + "kind": "SPAN_KIND_CLIENT", + "startTimeUnixNano": "1793802395453618717", + "endTimeUnixNano": "1793802395453794922", + "attributes": [ + { + "key": "db.system.name", + "value": { + "stringValue": "postgresql" + } + }, + { + "key": "pgx.rows_affected", + "value": { + "intValue": "1" + } + } + ], + "status": {} + }, + { + "traceId": "q11jrcoxNkWDijT8Otf4yg==", + "spanId": "8bVgqLP/0uU=", + "parentSpanId": "PYX0hZrvFv4=", + "name": "pool.acquire", + "kind": "SPAN_KIND_CLIENT", + "startTimeUnixNano": "1793802395453808505", + "endTimeUnixNano": "1793802395453809963", + "attributes": [ + { + "key": "db.system.name", + "value": { + "stringValue": "postgresql" + } + } + ], + "status": {} + }, + { + "traceId": "q11jrcoxNkWDijT8Otf4yg==", + "spanId": "wPWtPUlEDio=", + "parentSpanId": "WnsLZopRomY=", + "name": "SELECT", + "kind": "SPAN_KIND_CLIENT", + "startTimeUnixNano": "1793802395453814797", + "endTimeUnixNano": "1793802395453896254", + "attributes": [ + { + "key": "db.system.name", + "value": { + "stringValue": "postgresql" + } + }, + { + "key": "pgx.prepare_stmt.name", + "value": { + "stringValue": "stmtcache_de0ea135810354b7f61683adb3b09404ce39ab5d034c1a14" + } + }, + { + "key": "db.operation.name", + "value": { + "stringValue": "SELECT" + } + } + ], + "status": {} + }, + { + "traceId": "q11jrcoxNkWDijT8Otf4yg==", + "spanId": "WnsLZopRomY=", + "parentSpanId": "PYX0hZrvFv4=", + "name": "SELECT", + "kind": "SPAN_KIND_CLIENT", + "startTimeUnixNano": "1793802395453810880", + "endTimeUnixNano": "1793802395454017084", + "attributes": [ + { + "key": "db.system.name", + "value": { + "stringValue": "postgresql" + } + }, + { + "key": "pgx.rows_affected", + "value": { + "intValue": "1" + } + } + ], + "status": {} + }, + { + "traceId": "q11jrcoxNkWDijT8Otf4yg==", + "spanId": "jEq4yF6bJ4c=", + "parentSpanId": "PYX0hZrvFv4=", + "name": "pool.acquire", + "kind": "SPAN_KIND_CLIENT", + "startTimeUnixNano": "1793802395454022876", + "endTimeUnixNano": "1793802395454024667", + "attributes": [ + { + "key": "db.system.name", + "value": { + "stringValue": "postgresql" + } + } + ], + "status": {} + }, + { + "traceId": "q11jrcoxNkWDijT8Otf4yg==", + "spanId": "7c+kU2FHIwg=", + "parentSpanId": "bYfKpK2Qry4=", + "name": "SELECT", + "kind": "SPAN_KIND_CLIENT", + "startTimeUnixNano": "1793802395454029459", + "endTimeUnixNano": "1793802395454250372", + "attributes": [ + { + "key": "db.system.name", + "value": { + "stringValue": "postgresql" + } + }, + { + "key": "pgx.prepare_stmt.name", + "value": { + "stringValue": "stmtcache_0653adaeb90b9d056b56a00b5e9a7ff06c410e757f5f0f33" + } + }, + { + "key": "db.operation.name", + "value": { + "stringValue": "SELECT" + } + } + ], + "status": {} + }, + { + "traceId": "q11jrcoxNkWDijT8Otf4yg==", + "spanId": "bYfKpK2Qry4=", + "parentSpanId": "PYX0hZrvFv4=", + "name": "SELECT", + "kind": "SPAN_KIND_CLIENT", + "startTimeUnixNano": "1793802395454025918", + "endTimeUnixNano": "1793802395454578866", + "attributes": [ + { + "key": "db.system.name", + "value": { + "stringValue": "postgresql" + } + }, + { + "key": "pgx.rows_affected", + "value": { + "intValue": "1" + } + } + ], + "status": {} + }, + { + "traceId": "q11jrcoxNkWDijT8Otf4yg==", + "spanId": "DVd4mZMF4aQ=", + "parentSpanId": "PYX0hZrvFv4=", + "name": "pool.acquire", + "kind": "SPAN_KIND_CLIENT", + "startTimeUnixNano": "1793802395464015101", + "endTimeUnixNano": "1793802395464024101", + "attributes": [ + { + "key": "db.system.name", + "value": { + "stringValue": "postgresql" + } + } + ], + "status": {} + }, + { + "traceId": "q11jrcoxNkWDijT8Otf4yg==", + "spanId": "m8uA0khNg/w=", + "parentSpanId": "PYX0hZrvFv4=", + "name": "BEGIN", + "kind": "SPAN_KIND_CLIENT", + "startTimeUnixNano": "1793802395464026309", + "endTimeUnixNano": "1793802395464095100", + "attributes": [ + { + "key": "db.system.name", + "value": { + "stringValue": "postgresql" + } + }, + { + "key": "pgx.rows_affected", + "value": { + "intValue": "0" + } + } + ], + "status": {} + }, + { + "traceId": "q11jrcoxNkWDijT8Otf4yg==", + "spanId": "a+MOeYooA2k=", + "parentSpanId": "toZ0hvmTDcQ=", + "name": "SELECT", + "kind": "SPAN_KIND_CLIENT", + "startTimeUnixNano": "1793802395464102600", + "endTimeUnixNano": "1793802395464211889", + "attributes": [ + { + "key": "db.system.name", + "value": { + "stringValue": "postgresql" + } + }, + { + "key": "pgx.prepare_stmt.name", + "value": { + "stringValue": "stmtcache_a06e1d9f6f95e4c4c2b98310ebddcc9d963cc033582bf2e9" + } + }, + { + "key": "db.operation.name", + "value": { + "stringValue": "SELECT" + } + } + ], + "status": {} + }, + { + "traceId": "q11jrcoxNkWDijT8Otf4yg==", + "spanId": "toZ0hvmTDcQ=", + "parentSpanId": "PYX0hZrvFv4=", + "name": "SELECT", + "kind": "SPAN_KIND_CLIENT", + "startTimeUnixNano": "1793802395464100391", + "endTimeUnixNano": "1793802395464260180", + "attributes": [ + { + "key": "db.system.name", + "value": { + "stringValue": "postgresql" + } + }, + { + "key": "pgx.rows_affected", + "value": { + "intValue": "1" + } + } + ], + "status": {} + }, + { + "traceId": "q11jrcoxNkWDijT8Otf4yg==", + "spanId": "MK2GBK8eLTs=", + "parentSpanId": "G4RGzrsTobY=", + "name": "SELECT", + "kind": "SPAN_KIND_CLIENT", + "startTimeUnixNano": "1793802395464267596", + "endTimeUnixNano": "1793802395464325179", + "attributes": [ + { + "key": "db.system.name", + "value": { + "stringValue": "postgresql" + } + }, + { + "key": "pgx.prepare_stmt.name", + "value": { + "stringValue": "stmtcache_07c46797cbfa81d213deef56f51735a4f36385c48ba06154" + } + }, + { + "key": "db.operation.name", + "value": { + "stringValue": "SELECT" + } + } + ], + "status": {} + }, + { + "traceId": "q11jrcoxNkWDijT8Otf4yg==", + "spanId": "G4RGzrsTobY=", + "parentSpanId": "PYX0hZrvFv4=", + "name": "SELECT", + "kind": "SPAN_KIND_CLIENT", + "startTimeUnixNano": "1793802395464264055", + "endTimeUnixNano": "1793802395464551716", + "attributes": [ + { + "key": "db.system.name", + "value": { + "stringValue": "postgresql" + } + }, + { + "key": "pgx.rows_affected", + "value": { + "intValue": "1" + } + } + ], + "status": {} + }, + { + "traceId": "q11jrcoxNkWDijT8Otf4yg==", + "spanId": "BME8KY6w41g=", + "parentSpanId": "UH0CMrr/hzE=", + "name": "SELECT", + "kind": "SPAN_KIND_CLIENT", + "startTimeUnixNano": "1793802395464557091", + "endTimeUnixNano": "1793802395464589132", + "attributes": [ + { + "key": "db.system.name", + "value": { + "stringValue": "postgresql" + } + }, + { + "key": "pgx.prepare_stmt.name", + "value": { + "stringValue": "stmtcache_f76724b3c1e99473765b9b6667245a4f70550ddcfaeb487c" + } + }, + { + "key": "db.operation.name", + "value": { + "stringValue": "SELECT" + } + } + ], + "status": {} + }, + { + "traceId": "q11jrcoxNkWDijT8Otf4yg==", + "spanId": "UH0CMrr/hzE=", + "parentSpanId": "PYX0hZrvFv4=", + "name": "SELECT", + "kind": "SPAN_KIND_CLIENT", + "startTimeUnixNano": "1793802395464554674", + "endTimeUnixNano": "1793802395464727254", + "attributes": [ + { + "key": "db.system.name", + "value": { + "stringValue": "postgresql" + } + }, + { + "key": "pgx.rows_affected", + "value": { + "intValue": "1" + } + } + ], + "status": {} + }, + { + "traceId": "q11jrcoxNkWDijT8Otf4yg==", + "spanId": "M+md+NdJlOc=", + "parentSpanId": "RHlHifPxVT0=", + "name": "INSERT", + "kind": "SPAN_KIND_CLIENT", + "startTimeUnixNano": "1793802395464734004", + "endTimeUnixNano": "1793802395464778378", + "attributes": [ + { + "key": "db.system.name", + "value": { + "stringValue": "postgresql" + } + }, + { + "key": "pgx.prepare_stmt.name", + "value": { + "stringValue": "stmtcache_bb4955d9edbde9fe5507f79b4fea34d6fc34fcc6d640e8f2" + } + }, + { + "key": "db.operation.name", + "value": { + "stringValue": "INSERT" + } + } + ], + "status": {} + }, + { + "traceId": "q11jrcoxNkWDijT8Otf4yg==", + "spanId": "RHlHifPxVT0=", + "parentSpanId": "PYX0hZrvFv4=", + "name": "INSERT", + "kind": "SPAN_KIND_CLIENT", + "startTimeUnixNano": "1793802395464732129", + "endTimeUnixNano": "1793802395465256494", + "attributes": [ + { + "key": "db.system.name", + "value": { + "stringValue": "postgresql" + } + }, + { + "key": "pgx.rows_affected", + "value": { + "intValue": "1" + } + } + ], + "status": {} + }, + { + "traceId": "q11jrcoxNkWDijT8Otf4yg==", + "spanId": "cT0rT57CMTg=", + "parentSpanId": "rBDxadkKFsU=", + "name": "INSERT", + "kind": "SPAN_KIND_CLIENT", + "startTimeUnixNano": "1793802395465261827", + "endTimeUnixNano": "1793802395465496073", + "attributes": [ + { + "key": "db.system.name", + "value": { + "stringValue": "postgresql" + } + }, + { + "key": "pgx.prepare_stmt.name", + "value": { + "stringValue": "stmtcache_189223a1e419a869bef6ea254806c23811f32e5dab57507e" + } + }, + { + "key": "db.operation.name", + "value": { + "stringValue": "INSERT" + } + } + ], + "status": {} + }, + { + "traceId": "q11jrcoxNkWDijT8Otf4yg==", + "spanId": "rBDxadkKFsU=", + "parentSpanId": "PYX0hZrvFv4=", + "name": "INSERT", + "kind": "SPAN_KIND_CLIENT", + "startTimeUnixNano": "1793802395465258994", + "endTimeUnixNano": "1793802395465758317", + "attributes": [ + { + "key": "db.system.name", + "value": { + "stringValue": "postgresql" + } + }, + { + "key": "pgx.rows_affected", + "value": { + "intValue": "1" + } + } + ], + "status": {} + }, + { + "traceId": "q11jrcoxNkWDijT8Otf4yg==", + "spanId": "fDXELczToRA=", + "parentSpanId": "P3r2SrzfxZw=", + "name": "INSERT", + "kind": "SPAN_KIND_CLIENT", + "startTimeUnixNano": "1793802395465764901", + "endTimeUnixNano": "1793802395465997897", + "attributes": [ + { + "key": "db.system.name", + "value": { + "stringValue": "postgresql" + } + }, + { + "key": "pgx.prepare_stmt.name", + "value": { + "stringValue": "stmtcache_4ebc8e8cf059e889f4e7768a351363c78a335ebd72ea57c1" + } + }, + { + "key": "db.operation.name", + "value": { + "stringValue": "INSERT" + } + } + ], + "status": {} + }, + { + "traceId": "q11jrcoxNkWDijT8Otf4yg==", + "spanId": "P3r2SrzfxZw=", + "parentSpanId": "PYX0hZrvFv4=", + "name": "INSERT", + "kind": "SPAN_KIND_CLIENT", + "startTimeUnixNano": "1793802395465763401", + "endTimeUnixNano": "1793802395466209267", + "attributes": [ + { + "key": "db.system.name", + "value": { + "stringValue": "postgresql" + } + }, + { + "key": "pgx.rows_affected", + "value": { + "intValue": "1" + } + } + ], + "status": {} + }, + { + "traceId": "q11jrcoxNkWDijT8Otf4yg==", + "spanId": "zggpkziN/gw=", + "parentSpanId": "eUOyyqgJu2Q=", + "name": "INSERT", + "kind": "SPAN_KIND_CLIENT", + "startTimeUnixNano": "1793802395466273391", + "endTimeUnixNano": "1793802395466351348", + "attributes": [ + { + "key": "db.system.name", + "value": { + "stringValue": "postgresql" + } + }, + { + "key": "pgx.prepare_stmt.name", + "value": { + "stringValue": "stmtcache_1a9e31070dddea814c8e3bfa6542b1b34c1c471eb96b3a74" + } + }, + { + "key": "db.operation.name", + "value": { + "stringValue": "INSERT" + } + } + ], + "status": {} + }, + { + "traceId": "q11jrcoxNkWDijT8Otf4yg==", + "spanId": "eUOyyqgJu2Q=", + "parentSpanId": "PYX0hZrvFv4=", + "name": "INSERT", + "kind": "SPAN_KIND_CLIENT", + "startTimeUnixNano": "1793802395466261517", + "endTimeUnixNano": "1793802395466522512", + "attributes": [ + { + "key": "db.system.name", + "value": { + "stringValue": "postgresql" + } + }, + { + "key": "pgx.rows_affected", + "value": { + "intValue": "1" + } + } + ], + "status": {} + }, + { + "traceId": "q11jrcoxNkWDijT8Otf4yg==", + "spanId": "BHGeHoh+ON0=", + "parentSpanId": "PYX0hZrvFv4=", + "name": "COMMIT", + "kind": "SPAN_KIND_CLIENT", + "startTimeUnixNano": "1793802395466525136", + "endTimeUnixNano": "1793802395466967586", + "attributes": [ + { + "key": "db.system.name", + "value": { + "stringValue": "postgresql" + } + }, + { + "key": "pgx.rows_affected", + "value": { + "intValue": "0" + } + } + ], + "status": {} + } + ] + }, + { + "scope": { + "name": "messenger/http" + }, + "spans": [ + { + "traceId": "q11jrcoxNkWDijT8Otf4yg==", + "spanId": "PYX0hZrvFv4=", + "name": "POST /api/v1/chats/{chat_id}/attachments", + "kind": "SPAN_KIND_SERVER", + "startTimeUnixNano": "1793802395453580634", + "endTimeUnixNano": "1793802395467131875", + "attributes": [ + { + "key": "http.request.method", + "value": { + "stringValue": "POST" + } + }, + { + "key": "http.route", + "value": { + "stringValue": "/api/v1/chats/{chat_id}/attachments" + } + }, + { + "key": "http.response.status_code", + "value": { + "intValue": "202" + } + } + ], + "status": {} + } + ] + }, + { + "scope": { + "name": "messenger/s3" + }, + "spans": [ + { + "traceId": "q11jrcoxNkWDijT8Otf4yg==", + "spanId": "twJRBVyTXgc=", + "parentSpanId": "PYX0hZrvFv4=", + "name": "S3.PutObject", + "kind": "SPAN_KIND_CLIENT", + "startTimeUnixNano": "1793802395456519745", + "endTimeUnixNano": "1793802395463618984", + "attributes": [ + { + "key": "rpc.system", + "value": { + "stringValue": "aws.s3" + } + }, + { + "key": "rpc.service", + "value": { + "stringValue": "S3" + } + }, + { + "key": "rpc.method", + "value": { + "stringValue": "PutObject" + } + }, + { + "key": "aws.s3.operation", + "value": { + "stringValue": "PutObject" + } + }, + { + "key": "aws.s3.object.size", + "value": { + "intValue": "111817" + } + } + ], + "status": {} + }, + { + "traceId": "q11jrcoxNkWDijT8Otf4yg==", + "spanId": "n5w2CUNMyIE=", + "parentSpanId": "PYX0hZrvFv4=", + "name": "S3.HeadObject", + "kind": "SPAN_KIND_CLIENT", + "startTimeUnixNano": "1793802395463629817", + "endTimeUnixNano": "1793802395464004351", + "attributes": [ + { + "key": "rpc.system", + "value": { + "stringValue": "aws.s3" + } + }, + { + "key": "rpc.service", + "value": { + "stringValue": "S3" + } + }, + { + "key": "rpc.method", + "value": { + "stringValue": "HeadObject" + } + }, + { + "key": "aws.s3.operation", + "value": { + "stringValue": "HeadObject" + } + } + ], + "status": {} + } + ] + } + ] + } + ] +} diff --git a/evidence/lab6/trace-retry.json b/evidence/lab6/trace-retry.json new file mode 100644 index 0000000..31a63e5 --- /dev/null +++ b/evidence/lab6/trace-retry.json @@ -0,0 +1 @@ +{"batches":[{"resource":{"attributes":[{"key":"deployment.environment.name","value":{"stringValue":"lab"}},{"key":"service.instance.id","value":{"stringValue":"709c0280d839"}},{"key":"service.version","value":{"stringValue":"dev"}},{"key":"telemetry.sdk.language","value":{"stringValue":"go"}},{"key":"telemetry.sdk.name","value":{"stringValue":"opentelemetry"}},{"key":"telemetry.sdk.version","value":{"stringValue":"1.47.0"}},{"key":"service.name","value":{"stringValue":"messenger-api"}}]},"scopeSpans":[{"scope":{"name":"messenger/http"},"spans":[{"traceId":"j95dugCfEdBY9YgXsJxuMw==","spanId":"PG9WhmyuKyQ=","name":"POST /api/v1/chats/{chat_id}/attachments","kind":"SPAN_KIND_SERVER","startTimeUnixNano":"1793971970859077352","endTimeUnixNano":"1793971970868753448","attributes":[{"key":"http.request.method","value":{"stringValue":"POST"}},{"key":"http.route","value":{"stringValue":"/api/v1/chats/{chat_id}/attachments"}},{"key":"http.response.status_code","value":{"intValue":"202"}}],"status":{}}]},{"scope":{"name":"github.com/exaring/otelpgx","version":"v0.13.0"},"spans":[{"traceId":"j95dugCfEdBY9YgXsJxuMw==","spanId":"BV3ycOeBQlg=","parentSpanId":"PG9WhmyuKyQ=","name":"pool.acquire","kind":"SPAN_KIND_CLIENT","startTimeUnixNano":"1793971970859118422","endTimeUnixNano":"1793971970859130910","attributes":[{"key":"db.system.name","value":{"stringValue":"postgresql"}}],"status":{}},{"traceId":"j95dugCfEdBY9YgXsJxuMw==","spanId":"xinRAREceGg=","parentSpanId":"PG9WhmyuKyQ=","name":"SELECT","kind":"SPAN_KIND_CLIENT","startTimeUnixNano":"1793971970859140633","endTimeUnixNano":"1793971970859340200","attributes":[{"key":"db.system.name","value":{"stringValue":"postgresql"}},{"key":"pgx.rows_affected","value":{"intValue":"1"}}],"status":{}},{"traceId":"j95dugCfEdBY9YgXsJxuMw==","spanId":"VCuORXOM/ew=","parentSpanId":"PG9WhmyuKyQ=","name":"pool.acquire","kind":"SPAN_KIND_CLIENT","startTimeUnixNano":"1793971970859356753","endTimeUnixNano":"1793971970859359687","attributes":[{"key":"db.system.name","value":{"stringValue":"postgresql"}}],"status":{}},{"traceId":"j95dugCfEdBY9YgXsJxuMw==","spanId":"4Cu93CiTDbY=","parentSpanId":"PG9WhmyuKyQ=","name":"SELECT","kind":"SPAN_KIND_CLIENT","startTimeUnixNano":"1793971970859360902","endTimeUnixNano":"1793971970859466972","attributes":[{"key":"db.system.name","value":{"stringValue":"postgresql"}},{"key":"pgx.rows_affected","value":{"intValue":"1"}}],"status":{}},{"traceId":"j95dugCfEdBY9YgXsJxuMw==","spanId":"Dcvq7vWNpf0=","parentSpanId":"PG9WhmyuKyQ=","name":"pool.acquire","kind":"SPAN_KIND_CLIENT","startTimeUnixNano":"1793971970859476653","endTimeUnixNano":"1793971970859478245","attributes":[{"key":"db.system.name","value":{"stringValue":"postgresql"}}],"status":{}},{"traceId":"j95dugCfEdBY9YgXsJxuMw==","spanId":"lwp84skA1/M=","parentSpanId":"PG9WhmyuKyQ=","name":"SELECT","kind":"SPAN_KIND_CLIENT","startTimeUnixNano":"1793971970859479419","endTimeUnixNano":"1793971970859704843","attributes":[{"key":"db.system.name","value":{"stringValue":"postgresql"}},{"key":"pgx.rows_affected","value":{"intValue":"1"}}],"status":{}},{"traceId":"j95dugCfEdBY9YgXsJxuMw==","spanId":"JAe8u0q70s8=","parentSpanId":"PG9WhmyuKyQ=","name":"pool.acquire","kind":"SPAN_KIND_CLIENT","startTimeUnixNano":"1793971970866105438","endTimeUnixNano":"1793971970866112478","attributes":[{"key":"db.system.name","value":{"stringValue":"postgresql"}}],"status":{}},{"traceId":"j95dugCfEdBY9YgXsJxuMw==","spanId":"0740MNeSDSQ=","parentSpanId":"PG9WhmyuKyQ=","name":"BEGIN","kind":"SPAN_KIND_CLIENT","startTimeUnixNano":"1793971970866114741","endTimeUnixNano":"1793971970866201701","attributes":[{"key":"db.system.name","value":{"stringValue":"postgresql"}},{"key":"pgx.rows_affected","value":{"intValue":"0"}}],"status":{}},{"traceId":"j95dugCfEdBY9YgXsJxuMw==","spanId":"efVPQ1FuZCg=","parentSpanId":"PG9WhmyuKyQ=","name":"SELECT","kind":"SPAN_KIND_CLIENT","startTimeUnixNano":"1793971970866208658","endTimeUnixNano":"1793971970866869298","attributes":[{"key":"db.system.name","value":{"stringValue":"postgresql"}},{"key":"pgx.rows_affected","value":{"intValue":"1"}}],"status":{}},{"traceId":"j95dugCfEdBY9YgXsJxuMw==","spanId":"8iKmQ7wJmEk=","parentSpanId":"PG9WhmyuKyQ=","name":"SELECT","kind":"SPAN_KIND_CLIENT","startTimeUnixNano":"1793971970866876758","endTimeUnixNano":"1793971970867060064","attributes":[{"key":"db.system.name","value":{"stringValue":"postgresql"}},{"key":"pgx.rows_affected","value":{"intValue":"1"}}],"status":{}},{"traceId":"j95dugCfEdBY9YgXsJxuMw==","spanId":"yfyL8Y4MGHc=","parentSpanId":"PG9WhmyuKyQ=","name":"SELECT","kind":"SPAN_KIND_CLIENT","startTimeUnixNano":"1793971970867065345","endTimeUnixNano":"1793971970867183819","attributes":[{"key":"db.system.name","value":{"stringValue":"postgresql"}},{"key":"pgx.rows_affected","value":{"intValue":"1"}}],"status":{}},{"traceId":"j95dugCfEdBY9YgXsJxuMw==","spanId":"x2zWwRiohPk=","parentSpanId":"PG9WhmyuKyQ=","name":"INSERT","kind":"SPAN_KIND_CLIENT","startTimeUnixNano":"1793971970867189770","endTimeUnixNano":"1793971970867487025","attributes":[{"key":"db.system.name","value":{"stringValue":"postgresql"}},{"key":"pgx.rows_affected","value":{"intValue":"1"}}],"status":{}},{"traceId":"j95dugCfEdBY9YgXsJxuMw==","spanId":"XsSJg5UlkXc=","parentSpanId":"PG9WhmyuKyQ=","name":"INSERT","kind":"SPAN_KIND_CLIENT","startTimeUnixNano":"1793971970867496203","endTimeUnixNano":"1793971970867824386","attributes":[{"key":"db.system.name","value":{"stringValue":"postgresql"}},{"key":"pgx.rows_affected","value":{"intValue":"1"}}],"status":{}},{"traceId":"j95dugCfEdBY9YgXsJxuMw==","spanId":"XPaNkEh4fV8=","parentSpanId":"PG9WhmyuKyQ=","name":"INSERT","kind":"SPAN_KIND_CLIENT","startTimeUnixNano":"1793971970867829834","endTimeUnixNano":"1793971970868070177","attributes":[{"key":"db.system.name","value":{"stringValue":"postgresql"}},{"key":"pgx.rows_affected","value":{"intValue":"1"}}],"status":{}},{"traceId":"j95dugCfEdBY9YgXsJxuMw==","spanId":"FTCBVlLfncY=","parentSpanId":"PG9WhmyuKyQ=","name":"INSERT","kind":"SPAN_KIND_CLIENT","startTimeUnixNano":"1793971970868087234","endTimeUnixNano":"1793971970868292751","attributes":[{"key":"db.system.name","value":{"stringValue":"postgresql"}},{"key":"pgx.rows_affected","value":{"intValue":"1"}}],"status":{}},{"traceId":"j95dugCfEdBY9YgXsJxuMw==","spanId":"KqXIjUTTEMA=","parentSpanId":"PG9WhmyuKyQ=","name":"COMMIT","kind":"SPAN_KIND_CLIENT","startTimeUnixNano":"1793971970868297864","endTimeUnixNano":"1793971970868629065","attributes":[{"key":"db.system.name","value":{"stringValue":"postgresql"}},{"key":"pgx.rows_affected","value":{"intValue":"0"}}],"status":{}}]},{"scope":{"name":"messenger/s3"},"spans":[{"traceId":"j95dugCfEdBY9YgXsJxuMw==","spanId":"GTWHR7AfzVw=","parentSpanId":"PG9WhmyuKyQ=","name":"S3.PutObject","kind":"SPAN_KIND_CLIENT","startTimeUnixNano":"1793971970860911631","endTimeUnixNano":"1793971970865689834","attributes":[{"key":"rpc.system","value":{"stringValue":"aws.s3"}},{"key":"rpc.service","value":{"stringValue":"S3"}},{"key":"rpc.method","value":{"stringValue":"PutObject"}},{"key":"aws.s3.operation","value":{"stringValue":"PutObject"}},{"key":"aws.s3.object.size","value":{"intValue":"111817"}}],"status":{}},{"traceId":"j95dugCfEdBY9YgXsJxuMw==","spanId":"FHV3Jbsuk/I=","parentSpanId":"PG9WhmyuKyQ=","name":"S3.HeadObject","kind":"SPAN_KIND_CLIENT","startTimeUnixNano":"1793971970865700311","endTimeUnixNano":"1793971970866099990","attributes":[{"key":"rpc.system","value":{"stringValue":"aws.s3"}},{"key":"rpc.service","value":{"stringValue":"S3"}},{"key":"rpc.method","value":{"stringValue":"HeadObject"}},{"key":"aws.s3.operation","value":{"stringValue":"HeadObject"}}],"status":{}}]}]},{"resource":{"attributes":[{"key":"deployment.environment.name","value":{"stringValue":"lab"}},{"key":"service.instance.id","value":{"stringValue":"a5b2b9b851e8"}},{"key":"service.version","value":{"stringValue":"dev"}},{"key":"telemetry.sdk.language","value":{"stringValue":"go"}},{"key":"telemetry.sdk.name","value":{"stringValue":"opentelemetry"}},{"key":"telemetry.sdk.version","value":{"stringValue":"1.47.0"}},{"key":"service.name","value":{"stringValue":"messenger-relay"}}]},"scopeSpans":[{"scope":{"name":"messenger/queue"},"spans":[{"traceId":"j95dugCfEdBY9YgXsJxuMw==","spanId":"UcMZs5m1AA8=","parentSpanId":"PG9WhmyuKyQ=","name":"job.publish","kind":"SPAN_KIND_PRODUCER","startTimeUnixNano":"1793971972196159085","endTimeUnixNano":"1793971972197810281","attributes":[{"key":"messaging.system","value":{"stringValue":"rabbitmq"}},{"key":"messaging.operation","value":{"stringValue":"publish"}},{"key":"messaging.destination.name","value":{"stringValue":"attachment.process.v1"}},{"key":"job.id","value":{"stringValue":"01a1b10f-e32c-7dd8-ac25-ee5af8abcdda"}},{"key":"job.type","value":{"stringValue":"attachment.process.v1"}},{"key":"job.attempt","value":{"intValue":"1"}}],"status":{}}]}]},{"resource":{"attributes":[{"key":"deployment.environment.name","value":{"stringValue":"lab"}},{"key":"service.instance.id","value":{"stringValue":"7fd7662bf332"}},{"key":"service.name","value":{"stringValue":"messenger-worker"}},{"key":"service.version","value":{"stringValue":"dev"}},{"key":"telemetry.sdk.language","value":{"stringValue":"go"}},{"key":"telemetry.sdk.name","value":{"stringValue":"opentelemetry"}},{"key":"telemetry.sdk.version","value":{"stringValue":"1.47.0"}}]},"scopeSpans":[{"scope":{"name":"messenger/worker"},"spans":[{"traceId":"j95dugCfEdBY9YgXsJxuMw==","spanId":"DvAzatGdTe8=","parentSpanId":"UcMZs5m1AA8=","flags":769,"name":"job.process","kind":"SPAN_KIND_CONSUMER","startTimeUnixNano":"1793971972197980846","endTimeUnixNano":"1793971988387328208","attributes":[{"key":"messaging.system","value":{"stringValue":"rabbitmq"}},{"key":"messaging.operation","value":{"stringValue":"process"}},{"key":"messaging.destination.name","value":{"stringValue":"attachment.process.v1"}},{"key":"job.id","value":{"stringValue":"01a1b10f-e32c-7dd8-ac25-ee5af8abcdda"}},{"key":"job.type","value":{"stringValue":"attachment.process.v1"}},{"key":"job.attempt","value":{"intValue":"1"}},{"key":"pipeline.version","value":{"intValue":"1"}},{"key":"job.outcome","value":{"stringValue":"retried"}}],"events":[{"timeUnixNano":"1793971988261016757","name":"exception","attributes":[{"key":"exception.type","value":{"stringValue":"*errors.errorString"}},{"key":"exception.message","value":{"stringValue":"open source: temporarily unavailable: open object \"***\": operation error S3: GetObject, https response error StatusCode: 0, RequestID: , HostID: , canceled, context deadline exceeded"}}]}],"status":{"message":"retried","code":"STATUS_CODE_ERROR"}}]}]},{"resource":{"attributes":[{"key":"deployment.environment.name","value":{"stringValue":"lab"}},{"key":"service.instance.id","value":{"stringValue":"7fd7662bf332"}},{"key":"service.name","value":{"stringValue":"messenger-worker"}},{"key":"service.version","value":{"stringValue":"dev"}},{"key":"telemetry.sdk.language","value":{"stringValue":"go"}},{"key":"telemetry.sdk.name","value":{"stringValue":"opentelemetry"}},{"key":"telemetry.sdk.version","value":{"stringValue":"1.47.0"}}]},"scopeSpans":[{"scope":{"name":"github.com/exaring/otelpgx","version":"v0.13.0"},"spans":[{"traceId":"j95dugCfEdBY9YgXsJxuMw==","spanId":"0McYdimyeI8=","parentSpanId":"DvAzatGdTe8=","flags":257,"name":"pool.acquire","kind":"SPAN_KIND_CLIENT","startTimeUnixNano":"1793971972197993780","endTimeUnixNano":"1793971972198004245","attributes":[{"key":"db.system.name","value":{"stringValue":"postgresql"}}],"status":{}},{"traceId":"j95dugCfEdBY9YgXsJxuMw==","spanId":"SA1AHsi7dUM=","parentSpanId":"DvAzatGdTe8=","flags":257,"name":"BEGIN","kind":"SPAN_KIND_CLIENT","startTimeUnixNano":"1793971972198012657","endTimeUnixNano":"1793971972198099300","attributes":[{"key":"db.system.name","value":{"stringValue":"postgresql"}},{"key":"pgx.rows_affected","value":{"intValue":"0"}}],"status":{}},{"traceId":"j95dugCfEdBY9YgXsJxuMw==","spanId":"lOwfu/7m3FE=","parentSpanId":"DvAzatGdTe8=","flags":257,"name":"SELECT","kind":"SPAN_KIND_CLIENT","startTimeUnixNano":"1793971972198106332","endTimeUnixNano":"1793971972199161659","attributes":[{"key":"db.system.name","value":{"stringValue":"postgresql"}},{"key":"pgx.rows_affected","value":{"intValue":"1"}}],"status":{}},{"traceId":"j95dugCfEdBY9YgXsJxuMw==","spanId":"W6T/o4LzPe4=","parentSpanId":"lOwfu/7m3FE=","flags":257,"name":"SELECT","kind":"SPAN_KIND_CLIENT","startTimeUnixNano":"1793971972198111480","endTimeUnixNano":"1793971972198505893","attributes":[{"key":"db.system.name","value":{"stringValue":"postgresql"}},{"key":"pgx.prepare_stmt.name","value":{"stringValue":"stmtcache_fc12cd3e4a20e54eb57837883d796b16cec717d466a7da66"}},{"key":"db.operation.name","value":{"stringValue":"SELECT"}}],"status":{}},{"traceId":"j95dugCfEdBY9YgXsJxuMw==","spanId":"DuOREnJxq/M=","parentSpanId":"DvAzatGdTe8=","flags":257,"name":"SELECT","kind":"SPAN_KIND_CLIENT","startTimeUnixNano":"1793971972199166891","endTimeUnixNano":"1793971972199695370","attributes":[{"key":"db.system.name","value":{"stringValue":"postgresql"}},{"key":"pgx.rows_affected","value":{"intValue":"1"}}],"status":{}},{"traceId":"j95dugCfEdBY9YgXsJxuMw==","spanId":"EqWp5op7nII=","parentSpanId":"DuOREnJxq/M=","flags":257,"name":"SELECT","kind":"SPAN_KIND_CLIENT","startTimeUnixNano":"1793971972199169109","endTimeUnixNano":"1793971972199305561","attributes":[{"key":"db.system.name","value":{"stringValue":"postgresql"}},{"key":"pgx.prepare_stmt.name","value":{"stringValue":"stmtcache_e9f82c41b029d022feebf718883ce3c9c89a787ade4a6c6f"}},{"key":"db.operation.name","value":{"stringValue":"SELECT"}}],"status":{}},{"traceId":"j95dugCfEdBY9YgXsJxuMw==","spanId":"GeDcgymuT/0=","parentSpanId":"DvAzatGdTe8=","flags":257,"name":"UPDATE","kind":"SPAN_KIND_CLIENT","startTimeUnixNano":"1793971972199703030","endTimeUnixNano":"1793971972200152527","attributes":[{"key":"db.system.name","value":{"stringValue":"postgresql"}},{"key":"pgx.rows_affected","value":{"intValue":"1"}}],"status":{}},{"traceId":"j95dugCfEdBY9YgXsJxuMw==","spanId":"pq+XFK5QvM4=","parentSpanId":"GeDcgymuT/0=","flags":257,"name":"UPDATE","kind":"SPAN_KIND_CLIENT","startTimeUnixNano":"1793971972199705248","endTimeUnixNano":"1793971972199878450","attributes":[{"key":"db.system.name","value":{"stringValue":"postgresql"}},{"key":"pgx.prepare_stmt.name","value":{"stringValue":"stmtcache_356de9f00db89330cb70bd29cadea5c865813e56511a9a1f"}},{"key":"db.operation.name","value":{"stringValue":"UPDATE"}}],"status":{}},{"traceId":"j95dugCfEdBY9YgXsJxuMw==","spanId":"ibW2ak11sI0=","parentSpanId":"DvAzatGdTe8=","flags":257,"name":"UPDATE","kind":"SPAN_KIND_CLIENT","startTimeUnixNano":"1793971972200157424","endTimeUnixNano":"1793971972200523877","attributes":[{"key":"db.system.name","value":{"stringValue":"postgresql"}},{"key":"pgx.rows_affected","value":{"intValue":"1"}}],"status":{}},{"traceId":"j95dugCfEdBY9YgXsJxuMw==","spanId":"cSTSh6BgChg=","parentSpanId":"ibW2ak11sI0=","flags":257,"name":"UPDATE","kind":"SPAN_KIND_CLIENT","startTimeUnixNano":"1793971972200159307","endTimeUnixNano":"1793971972200224813","attributes":[{"key":"db.system.name","value":{"stringValue":"postgresql"}},{"key":"pgx.prepare_stmt.name","value":{"stringValue":"stmtcache_a5da8f4131ad6b9f3e9d3e41a259def2fe967e39e909a2b4"}},{"key":"db.operation.name","value":{"stringValue":"UPDATE"}}],"status":{}},{"traceId":"j95dugCfEdBY9YgXsJxuMw==","spanId":"6BGlHoxWZP0=","parentSpanId":"DvAzatGdTe8=","flags":257,"name":"INSERT","kind":"SPAN_KIND_CLIENT","startTimeUnixNano":"1793971972200529653","endTimeUnixNano":"1793971972201113634","attributes":[{"key":"db.system.name","value":{"stringValue":"postgresql"}},{"key":"pgx.rows_affected","value":{"intValue":"1"}}],"status":{}},{"traceId":"j95dugCfEdBY9YgXsJxuMw==","spanId":"8sPcTFdzLJU=","parentSpanId":"6BGlHoxWZP0=","flags":257,"name":"INSERT","kind":"SPAN_KIND_CLIENT","startTimeUnixNano":"1793971972200531872","endTimeUnixNano":"1793971972200826333","attributes":[{"key":"db.system.name","value":{"stringValue":"postgresql"}},{"key":"pgx.prepare_stmt.name","value":{"stringValue":"stmtcache_4ebc8e8cf059e889f4e7768a351363c78a335ebd72ea57c1"}},{"key":"db.operation.name","value":{"stringValue":"INSERT"}}],"status":{}},{"traceId":"j95dugCfEdBY9YgXsJxuMw==","spanId":"bas2xGpoNMw=","parentSpanId":"DvAzatGdTe8=","flags":257,"name":"COMMIT","kind":"SPAN_KIND_CLIENT","startTimeUnixNano":"1793971972201122759","endTimeUnixNano":"1793971972201390515","attributes":[{"key":"db.system.name","value":{"stringValue":"postgresql"}},{"key":"pgx.rows_affected","value":{"intValue":"0"}}],"status":{}}]}]},{"resource":{"attributes":[{"key":"deployment.environment.name","value":{"stringValue":"lab"}},{"key":"service.instance.id","value":{"stringValue":"a5b2b9b851e8"}},{"key":"service.name","value":{"stringValue":"messenger-relay"}},{"key":"service.version","value":{"stringValue":"dev"}},{"key":"telemetry.sdk.language","value":{"stringValue":"go"}},{"key":"telemetry.sdk.name","value":{"stringValue":"opentelemetry"}},{"key":"telemetry.sdk.version","value":{"stringValue":"1.47.0"}}]},"scopeSpans":[{"scope":{"name":"messenger/relay"},"spans":[{"traceId":"j95dugCfEdBY9YgXsJxuMw==","spanId":"x4G/QURH+70=","parentSpanId":"PG9WhmyuKyQ=","flags":769,"name":"job.requeue","kind":"SPAN_KIND_INTERNAL","startTimeUnixNano":"1793971988075180121","endTimeUnixNano":"1793971988075584934","attributes":[{"key":"job.id","value":{"stringValue":"01a1b10f-e32c-7dd8-ac25-ee5af8abcdda"}},{"key":"job.type","value":{"stringValue":"attachment.process.v1"}},{"key":"job.attempt","value":{"intValue":"2"}}],"status":{}}]}]},{"resource":{"attributes":[{"key":"deployment.environment.name","value":{"stringValue":"lab"}},{"key":"service.instance.id","value":{"stringValue":"a5b2b9b851e8"}},{"key":"service.name","value":{"stringValue":"messenger-relay"}},{"key":"service.version","value":{"stringValue":"dev"}},{"key":"telemetry.sdk.language","value":{"stringValue":"go"}},{"key":"telemetry.sdk.name","value":{"stringValue":"opentelemetry"}},{"key":"telemetry.sdk.version","value":{"stringValue":"1.47.0"}}]},"scopeSpans":[{"scope":{"name":"github.com/exaring/otelpgx","version":"v0.13.0"},"spans":[{"traceId":"j95dugCfEdBY9YgXsJxuMw==","spanId":"RwRmyIPg7dM=","parentSpanId":"x4G/QURH+70=","flags":257,"name":"INSERT","kind":"SPAN_KIND_CLIENT","startTimeUnixNano":"1793971988075206188","endTimeUnixNano":"1793971988075577546","attributes":[{"key":"db.system.name","value":{"stringValue":"postgresql"}},{"key":"pgx.rows_affected","value":{"intValue":"1"}}],"status":{}},{"traceId":"j95dugCfEdBY9YgXsJxuMw==","spanId":"S1LmUt5NPj8=","parentSpanId":"RwRmyIPg7dM=","flags":257,"name":"INSERT","kind":"SPAN_KIND_CLIENT","startTimeUnixNano":"1793971988075209001","endTimeUnixNano":"1793971988075299416","attributes":[{"key":"db.system.name","value":{"stringValue":"postgresql"}},{"key":"pgx.prepare_stmt.name","value":{"stringValue":"stmtcache_1a9e31070dddea814c8e3bfa6542b1b34c1c471eb96b3a74"}},{"key":"db.operation.name","value":{"stringValue":"INSERT"}}],"status":{}}]}]},{"resource":{"attributes":[{"key":"deployment.environment.name","value":{"stringValue":"lab"}},{"key":"service.instance.id","value":{"stringValue":"7fd7662bf332"}},{"key":"service.name","value":{"stringValue":"messenger-worker"}},{"key":"service.version","value":{"stringValue":"dev"}},{"key":"telemetry.sdk.language","value":{"stringValue":"go"}},{"key":"telemetry.sdk.name","value":{"stringValue":"opentelemetry"}},{"key":"telemetry.sdk.version","value":{"stringValue":"1.47.0"}}]},"scopeSpans":[{"scope":{"name":"github.com/exaring/otelpgx","version":"v0.13.0"},"spans":[{"traceId":"j95dugCfEdBY9YgXsJxuMw==","spanId":"NmZZsUmhm10=","parentSpanId":"DvAzatGdTe8=","flags":257,"name":"pool.acquire","kind":"SPAN_KIND_CLIENT","startTimeUnixNano":"1793971988259540307","endTimeUnixNano":"1793971988260368192","attributes":[{"key":"db.system.name","value":{"stringValue":"postgresql"}}],"events":[{"timeUnixNano":"1793971988260367394","name":"exception","attributes":[{"key":"exception.type","value":{"stringValue":"context.deadlineExceededError"}},{"key":"exception.message","value":{"stringValue":"context deadline exceeded"}}]}],"status":{"message":"context deadline exceeded","code":"STATUS_CODE_ERROR"}},{"traceId":"j95dugCfEdBY9YgXsJxuMw==","spanId":"vfC58u7PcwY=","parentSpanId":"DvAzatGdTe8=","flags":257,"name":"pool.acquire","kind":"SPAN_KIND_CLIENT","startTimeUnixNano":"1793971988261076279","endTimeUnixNano":"1793971988261902400","attributes":[{"key":"db.system.name","value":{"stringValue":"postgresql"}}],"status":{}},{"traceId":"j95dugCfEdBY9YgXsJxuMw==","spanId":"INVfiUvXFmk=","parentSpanId":"DvAzatGdTe8=","flags":257,"name":"BEGIN","kind":"SPAN_KIND_CLIENT","startTimeUnixNano":"1793971988261930524","endTimeUnixNano":"1793971988261997139","attributes":[{"key":"db.system.name","value":{"stringValue":"postgresql"}},{"key":"pgx.rows_affected","value":{"intValue":"0"}}],"status":{}},{"traceId":"j95dugCfEdBY9YgXsJxuMw==","spanId":"dO8V2iHnRf4=","parentSpanId":"DvAzatGdTe8=","flags":257,"name":"SELECT","kind":"SPAN_KIND_CLIENT","startTimeUnixNano":"1793971988262001673","endTimeUnixNano":"1793971988263811955","attributes":[{"key":"db.system.name","value":{"stringValue":"postgresql"}},{"key":"pgx.rows_affected","value":{"intValue":"1"}}],"status":{}},{"traceId":"j95dugCfEdBY9YgXsJxuMw==","spanId":"guKJamGE8/U=","parentSpanId":"dO8V2iHnRf4=","flags":257,"name":"SELECT","kind":"SPAN_KIND_CLIENT","startTimeUnixNano":"1793971988262007088","endTimeUnixNano":"1793971988262600917","attributes":[{"key":"db.system.name","value":{"stringValue":"postgresql"}},{"key":"pgx.prepare_stmt.name","value":{"stringValue":"stmtcache_c19e02bfbf807e5896b637057fb543d1b26401af7c443ffd"}},{"key":"db.operation.name","value":{"stringValue":"SELECT"}}],"status":{}},{"traceId":"j95dugCfEdBY9YgXsJxuMw==","spanId":"eXPfhqTCpKQ=","parentSpanId":"DvAzatGdTe8=","flags":257,"name":"SELECT","kind":"SPAN_KIND_CLIENT","startTimeUnixNano":"1793971988263823708","endTimeUnixNano":"1793971988264459093","attributes":[{"key":"db.system.name","value":{"stringValue":"postgresql"}},{"key":"pgx.rows_affected","value":{"intValue":"1"}}],"status":{}},{"traceId":"j95dugCfEdBY9YgXsJxuMw==","spanId":"GmXWkURcB2Y=","parentSpanId":"eXPfhqTCpKQ=","flags":257,"name":"SELECT","kind":"SPAN_KIND_CLIENT","startTimeUnixNano":"1793971988263830424","endTimeUnixNano":"1793971988264036818","attributes":[{"key":"db.system.name","value":{"stringValue":"postgresql"}},{"key":"pgx.prepare_stmt.name","value":{"stringValue":"stmtcache_f84d5e7b870c3c7e00c3b8adbd40b43d9eddd5b9c36e751e"}},{"key":"db.operation.name","value":{"stringValue":"SELECT"}}],"status":{}},{"traceId":"j95dugCfEdBY9YgXsJxuMw==","spanId":"nmf8owdKFs8=","parentSpanId":"DvAzatGdTe8=","flags":257,"name":"COMMIT","kind":"SPAN_KIND_CLIENT","startTimeUnixNano":"1793971988264467656","endTimeUnixNano":"1793971988264717411","attributes":[{"key":"db.system.name","value":{"stringValue":"postgresql"}},{"key":"pgx.rows_affected","value":{"intValue":"0"}}],"status":{}},{"traceId":"j95dugCfEdBY9YgXsJxuMw==","spanId":"4fNcB/+I6Iw=","parentSpanId":"5/rdEDez4/0=","flags":257,"name":"pool.acquire","kind":"SPAN_KIND_CLIENT","startTimeUnixNano":"1793971990280220987","endTimeUnixNano":"1793971990280334600","attributes":[{"key":"db.system.name","value":{"stringValue":"postgresql"}}],"status":{}},{"traceId":"j95dugCfEdBY9YgXsJxuMw==","spanId":"bvSENCwDevE=","parentSpanId":"5/rdEDez4/0=","flags":257,"name":"BEGIN","kind":"SPAN_KIND_CLIENT","startTimeUnixNano":"1793971990280347508","endTimeUnixNano":"1793971990280410118","attributes":[{"key":"db.system.name","value":{"stringValue":"postgresql"}},{"key":"pgx.rows_affected","value":{"intValue":"0"}}],"status":{}},{"traceId":"j95dugCfEdBY9YgXsJxuMw==","spanId":"/rnHb9clDTM=","parentSpanId":"5/rdEDez4/0=","flags":257,"name":"SELECT","kind":"SPAN_KIND_CLIENT","startTimeUnixNano":"1793971990280417117","endTimeUnixNano":"1793971990280833474","attributes":[{"key":"db.system.name","value":{"stringValue":"postgresql"}},{"key":"pgx.rows_affected","value":{"intValue":"1"}}],"status":{}},{"traceId":"j95dugCfEdBY9YgXsJxuMw==","spanId":"qtUZuS3Z+3A=","parentSpanId":"/rnHb9clDTM=","flags":257,"name":"SELECT","kind":"SPAN_KIND_CLIENT","startTimeUnixNano":"1793971990280423068","endTimeUnixNano":"1793971990280561784","attributes":[{"key":"db.system.name","value":{"stringValue":"postgresql"}},{"key":"pgx.prepare_stmt.name","value":{"stringValue":"stmtcache_fc12cd3e4a20e54eb57837883d796b16cec717d466a7da66"}},{"key":"db.operation.name","value":{"stringValue":"SELECT"}}],"status":{}},{"traceId":"j95dugCfEdBY9YgXsJxuMw==","spanId":"nJvrXoZtQBo=","parentSpanId":"5/rdEDez4/0=","flags":257,"name":"SELECT","kind":"SPAN_KIND_CLIENT","startTimeUnixNano":"1793971990280849692","endTimeUnixNano":"1793971990281155873","attributes":[{"key":"db.system.name","value":{"stringValue":"postgresql"}},{"key":"pgx.rows_affected","value":{"intValue":"1"}}],"status":{}},{"traceId":"j95dugCfEdBY9YgXsJxuMw==","spanId":"YPVVboU+Ui4=","parentSpanId":"nJvrXoZtQBo=","flags":257,"name":"SELECT","kind":"SPAN_KIND_CLIENT","startTimeUnixNano":"1793971990280861720","endTimeUnixNano":"1793971990281001567","attributes":[{"key":"db.system.name","value":{"stringValue":"postgresql"}},{"key":"pgx.prepare_stmt.name","value":{"stringValue":"stmtcache_e9f82c41b029d022feebf718883ce3c9c89a787ade4a6c6f"}},{"key":"db.operation.name","value":{"stringValue":"SELECT"}}],"status":{}},{"traceId":"j95dugCfEdBY9YgXsJxuMw==","spanId":"1ud7nP0mF20=","parentSpanId":"5/rdEDez4/0=","flags":257,"name":"UPDATE","kind":"SPAN_KIND_CLIENT","startTimeUnixNano":"1793971990281162955","endTimeUnixNano":"1793971990281735797","attributes":[{"key":"db.system.name","value":{"stringValue":"postgresql"}},{"key":"pgx.rows_affected","value":{"intValue":"1"}}],"status":{}},{"traceId":"j95dugCfEdBY9YgXsJxuMw==","spanId":"rNT/KY4iDTc=","parentSpanId":"1ud7nP0mF20=","flags":257,"name":"UPDATE","kind":"SPAN_KIND_CLIENT","startTimeUnixNano":"1793971990281165470","endTimeUnixNano":"1793971990281382218","attributes":[{"key":"db.system.name","value":{"stringValue":"postgresql"}},{"key":"pgx.prepare_stmt.name","value":{"stringValue":"stmtcache_356de9f00db89330cb70bd29cadea5c865813e56511a9a1f"}},{"key":"db.operation.name","value":{"stringValue":"UPDATE"}}],"status":{}},{"traceId":"j95dugCfEdBY9YgXsJxuMw==","spanId":"EyIBO/+dT0Q=","parentSpanId":"5/rdEDez4/0=","flags":257,"name":"UPDATE","kind":"SPAN_KIND_CLIENT","startTimeUnixNano":"1793971990281742460","endTimeUnixNano":"1793971990282135893","attributes":[{"key":"db.system.name","value":{"stringValue":"postgresql"}},{"key":"pgx.rows_affected","value":{"intValue":"1"}}],"status":{}},{"traceId":"j95dugCfEdBY9YgXsJxuMw==","spanId":"7XrQAmJdu8Q=","parentSpanId":"EyIBO/+dT0Q=","flags":257,"name":"UPDATE","kind":"SPAN_KIND_CLIENT","startTimeUnixNano":"1793971990281745310","endTimeUnixNano":"1793971990281819948","attributes":[{"key":"db.system.name","value":{"stringValue":"postgresql"}},{"key":"pgx.prepare_stmt.name","value":{"stringValue":"stmtcache_a5da8f4131ad6b9f3e9d3e41a259def2fe967e39e909a2b4"}},{"key":"db.operation.name","value":{"stringValue":"UPDATE"}}],"status":{}},{"traceId":"j95dugCfEdBY9YgXsJxuMw==","spanId":"tcWEi2Hh1W0=","parentSpanId":"5/rdEDez4/0=","flags":257,"name":"INSERT","kind":"SPAN_KIND_CLIENT","startTimeUnixNano":"1793971990282141551","endTimeUnixNano":"1793971990283009509","attributes":[{"key":"db.system.name","value":{"stringValue":"postgresql"}},{"key":"pgx.rows_affected","value":{"intValue":"1"}}],"status":{}},{"traceId":"j95dugCfEdBY9YgXsJxuMw==","spanId":"wkgFVApYOtc=","parentSpanId":"tcWEi2Hh1W0=","flags":257,"name":"INSERT","kind":"SPAN_KIND_CLIENT","startTimeUnixNano":"1793971990282143185","endTimeUnixNano":"1793971990282489304","attributes":[{"key":"db.system.name","value":{"stringValue":"postgresql"}},{"key":"pgx.prepare_stmt.name","value":{"stringValue":"stmtcache_4ebc8e8cf059e889f4e7768a351363c78a335ebd72ea57c1"}},{"key":"db.operation.name","value":{"stringValue":"INSERT"}}],"status":{}},{"traceId":"j95dugCfEdBY9YgXsJxuMw==","spanId":"KgYo9aLN1Cg=","parentSpanId":"5/rdEDez4/0=","flags":257,"name":"COMMIT","kind":"SPAN_KIND_CLIENT","startTimeUnixNano":"1793971990283020238","endTimeUnixNano":"1793971990283416857","attributes":[{"key":"db.system.name","value":{"stringValue":"postgresql"}},{"key":"pgx.rows_affected","value":{"intValue":"0"}}],"status":{}}]}]},{"resource":{"attributes":[{"key":"deployment.environment.name","value":{"stringValue":"lab"}},{"key":"service.instance.id","value":{"stringValue":"7fd7662bf332"}},{"key":"service.name","value":{"stringValue":"messenger-worker"}},{"key":"service.version","value":{"stringValue":"dev"}},{"key":"telemetry.sdk.language","value":{"stringValue":"go"}},{"key":"telemetry.sdk.name","value":{"stringValue":"opentelemetry"}},{"key":"telemetry.sdk.version","value":{"stringValue":"1.47.0"}}]},"scopeSpans":[{"scope":{"name":"messenger/s3"},"spans":[{"traceId":"j95dugCfEdBY9YgXsJxuMw==","spanId":"mSn6Mk/9ao8=","parentSpanId":"DvAzatGdTe8=","flags":257,"name":"S3.GetObject","kind":"SPAN_KIND_CLIENT","startTimeUnixNano":"1793971988259980715","endTimeUnixNano":"1793971988260301367","attributes":[{"key":"rpc.system","value":{"stringValue":"aws.s3"}},{"key":"rpc.service","value":{"stringValue":"S3"}},{"key":"rpc.method","value":{"stringValue":"GetObject"}},{"key":"aws.s3.operation","value":{"stringValue":"GetObject"}}],"events":[{"timeUnixNano":"1793971988260300569","name":"exception","attributes":[{"key":"exception.type","value":{"stringValue":"*errors.errorString"}},{"key":"exception.message","value":{"stringValue":"temporarily unavailable: open object \"***\": operation error S3: GetObject, https response error StatusCode: 0, RequestID: , HostID: , canceled, context deadline exceeded"}}]}],"status":{}}]}]},{"resource":{"attributes":[{"key":"deployment.environment.name","value":{"stringValue":"lab"}},{"key":"service.instance.id","value":{"stringValue":"a5b2b9b851e8"}},{"key":"service.name","value":{"stringValue":"messenger-relay"}},{"key":"service.version","value":{"stringValue":"dev"}},{"key":"telemetry.sdk.language","value":{"stringValue":"go"}},{"key":"telemetry.sdk.name","value":{"stringValue":"opentelemetry"}},{"key":"telemetry.sdk.version","value":{"stringValue":"1.47.0"}}]},"scopeSpans":[{"scope":{"name":"messenger/queue"},"spans":[{"traceId":"j95dugCfEdBY9YgXsJxuMw==","spanId":"+VRIOo1OxO4=","parentSpanId":"x4G/QURH+70=","flags":769,"name":"job.publish","kind":"SPAN_KIND_PRODUCER","startTimeUnixNano":"1793971989072875566","endTimeUnixNano":"1793971989075002910","attributes":[{"key":"messaging.system","value":{"stringValue":"rabbitmq"}},{"key":"messaging.operation","value":{"stringValue":"publish"}},{"key":"messaging.destination.name","value":{"stringValue":"attachment.process.v1"}},{"key":"job.id","value":{"stringValue":"01a1b10f-e32c-7dd8-ac25-ee5af8abcdda"}},{"key":"job.type","value":{"stringValue":"attachment.process.v1"}},{"key":"job.attempt","value":{"intValue":"2"}}],"status":{}}]}]},{"resource":{"attributes":[{"key":"deployment.environment.name","value":{"stringValue":"lab"}},{"key":"service.instance.id","value":{"stringValue":"7fd7662bf332"}},{"key":"service.name","value":{"stringValue":"messenger-worker"}},{"key":"service.version","value":{"stringValue":"dev"}},{"key":"telemetry.sdk.language","value":{"stringValue":"go"}},{"key":"telemetry.sdk.name","value":{"stringValue":"opentelemetry"}},{"key":"telemetry.sdk.version","value":{"stringValue":"1.47.0"}}]},"scopeSpans":[{"scope":{"name":"messenger/worker"},"spans":[{"traceId":"j95dugCfEdBY9YgXsJxuMw==","spanId":"5/rdEDez4/0=","parentSpanId":"+VRIOo1OxO4=","flags":769,"name":"job.process","kind":"SPAN_KIND_CONSUMER","startTimeUnixNano":"1793971990280209211","endTimeUnixNano":"1793971998313649281","attributes":[{"key":"messaging.system","value":{"stringValue":"rabbitmq"}},{"key":"messaging.operation","value":{"stringValue":"process"}},{"key":"messaging.destination.name","value":{"stringValue":"attachment.process.v1"}},{"key":"job.id","value":{"stringValue":"01a1b10f-e32c-7dd8-ac25-ee5af8abcdda"}},{"key":"job.type","value":{"stringValue":"attachment.process.v1"}},{"key":"job.attempt","value":{"intValue":"2"}},{"key":"pipeline.version","value":{"intValue":"1"}},{"key":"job.outcome","value":{"stringValue":"succeeded"}}],"status":{}},{"traceId":"j95dugCfEdBY9YgXsJxuMw==","spanId":"dCX4isahjAw=","parentSpanId":"UcMZs5m1AA8=","flags":769,"name":"job.process","kind":"SPAN_KIND_CONSUMER","startTimeUnixNano":"1793971998314964324","endTimeUnixNano":"1793971998315567929","attributes":[{"key":"messaging.system","value":{"stringValue":"rabbitmq"}},{"key":"messaging.operation","value":{"stringValue":"process"}},{"key":"messaging.destination.name","value":{"stringValue":"attachment.process.v1"}},{"key":"job.id","value":{"stringValue":"01a1b10f-e32c-7dd8-ac25-ee5af8abcdda"}},{"key":"job.type","value":{"stringValue":"attachment.process.v1"}},{"key":"job.attempt","value":{"intValue":"1"}},{"key":"pipeline.version","value":{"intValue":"1"}},{"key":"job.outcome","value":{"stringValue":"already_ready"}}],"status":{}}]}]},{"resource":{"attributes":[{"key":"deployment.environment.name","value":{"stringValue":"lab"}},{"key":"service.instance.id","value":{"stringValue":"7fd7662bf332"}},{"key":"service.name","value":{"stringValue":"messenger-worker"}},{"key":"service.version","value":{"stringValue":"dev"}},{"key":"telemetry.sdk.language","value":{"stringValue":"go"}},{"key":"telemetry.sdk.name","value":{"stringValue":"opentelemetry"}},{"key":"telemetry.sdk.version","value":{"stringValue":"1.47.0"}}]},"scopeSpans":[{"scope":{"name":"github.com/exaring/otelpgx","version":"v0.13.0"},"spans":[{"traceId":"j95dugCfEdBY9YgXsJxuMw==","spanId":"qh/t7wN0unA=","parentSpanId":"5/rdEDez4/0=","flags":257,"name":"pool.acquire","kind":"SPAN_KIND_CLIENT","startTimeUnixNano":"1793971993284465187","endTimeUnixNano":"1793971993284716324","attributes":[{"key":"db.system.name","value":{"stringValue":"postgresql"}}],"status":{}},{"traceId":"j95dugCfEdBY9YgXsJxuMw==","spanId":"H4XUjNenQkk=","parentSpanId":"5/rdEDez4/0=","flags":257,"name":"UPDATE","kind":"SPAN_KIND_CLIENT","startTimeUnixNano":"1793971993284800329","endTimeUnixNano":"1793971993286081743","attributes":[{"key":"db.system.name","value":{"stringValue":"postgresql"}},{"key":"pgx.rows_affected","value":{"intValue":"1"}}],"status":{}},{"traceId":"j95dugCfEdBY9YgXsJxuMw==","spanId":"hD0aVS6jP0g=","parentSpanId":"H4XUjNenQkk=","flags":257,"name":"UPDATE","kind":"SPAN_KIND_CLIENT","startTimeUnixNano":"1793971993284809449","endTimeUnixNano":"1793971993285164630","attributes":[{"key":"db.system.name","value":{"stringValue":"postgresql"}},{"key":"pgx.prepare_stmt.name","value":{"stringValue":"stmtcache_dd0ca3739b55a7632fe7326a344ad1133f72a0e3d2e8959d"}},{"key":"db.operation.name","value":{"stringValue":"UPDATE"}}],"status":{}},{"traceId":"j95dugCfEdBY9YgXsJxuMw==","spanId":"QhkqinPFXvY=","parentSpanId":"5/rdEDez4/0=","flags":257,"name":"pool.acquire","kind":"SPAN_KIND_CLIENT","startTimeUnixNano":"1793971996286861325","endTimeUnixNano":"1793971996287169626","attributes":[{"key":"db.system.name","value":{"stringValue":"postgresql"}}],"status":{}},{"traceId":"j95dugCfEdBY9YgXsJxuMw==","spanId":"S+Ms5rEakh8=","parentSpanId":"5/rdEDez4/0=","flags":257,"name":"UPDATE","kind":"SPAN_KIND_CLIENT","startTimeUnixNano":"1793971996287197163","endTimeUnixNano":"1793971996288473030","attributes":[{"key":"db.system.name","value":{"stringValue":"postgresql"}},{"key":"pgx.rows_affected","value":{"intValue":"1"}}],"status":{}}]}]},{"resource":{"attributes":[{"key":"deployment.environment.name","value":{"stringValue":"lab"}},{"key":"service.instance.id","value":{"stringValue":"7fd7662bf332"}},{"key":"service.name","value":{"stringValue":"messenger-worker"}},{"key":"service.version","value":{"stringValue":"dev"}},{"key":"telemetry.sdk.language","value":{"stringValue":"go"}},{"key":"telemetry.sdk.name","value":{"stringValue":"opentelemetry"}},{"key":"telemetry.sdk.version","value":{"stringValue":"1.47.0"}}]},"scopeSpans":[{"scope":{"name":"messenger/s3"},"spans":[{"traceId":"j95dugCfEdBY9YgXsJxuMw==","spanId":"mdeEmqUi6Yo=","parentSpanId":"5/rdEDez4/0=","flags":257,"name":"S3.GetObject","kind":"SPAN_KIND_CLIENT","startTimeUnixNano":"1793971998284683137","endTimeUnixNano":"1793971998290048008","attributes":[{"key":"rpc.system","value":{"stringValue":"aws.s3"}},{"key":"rpc.service","value":{"stringValue":"S3"}},{"key":"rpc.method","value":{"stringValue":"GetObject"}},{"key":"aws.s3.operation","value":{"stringValue":"GetObject"}},{"key":"aws.s3.object.size","value":{"intValue":"111817"}}],"status":{}},{"traceId":"j95dugCfEdBY9YgXsJxuMw==","spanId":"TzgExCZJvtg=","parentSpanId":"5/rdEDez4/0=","flags":257,"name":"S3.PutObject","kind":"SPAN_KIND_CLIENT","startTimeUnixNano":"1793971998293181842","endTimeUnixNano":"1793971998296055491","attributes":[{"key":"rpc.system","value":{"stringValue":"aws.s3"}},{"key":"rpc.service","value":{"stringValue":"S3"}},{"key":"rpc.method","value":{"stringValue":"PutObject"}},{"key":"aws.s3.operation","value":{"stringValue":"PutObject"}},{"key":"aws.s3.object.size","value":{"intValue":"111817"}}],"status":{}},{"traceId":"j95dugCfEdBY9YgXsJxuMw==","spanId":"TyGjqZrevMs=","parentSpanId":"5/rdEDez4/0=","flags":257,"name":"S3.PutObject","kind":"SPAN_KIND_CLIENT","startTimeUnixNano":"1793971998297976227","endTimeUnixNano":"1793971998299161219","attributes":[{"key":"rpc.system","value":{"stringValue":"aws.s3"}},{"key":"rpc.service","value":{"stringValue":"S3"}},{"key":"rpc.method","value":{"stringValue":"PutObject"}},{"key":"aws.s3.operation","value":{"stringValue":"PutObject"}},{"key":"aws.s3.object.size","value":{"intValue":"5653"}}],"status":{}},{"traceId":"j95dugCfEdBY9YgXsJxuMw==","spanId":"+nBPTAnarJI=","parentSpanId":"5/rdEDez4/0=","flags":257,"name":"S3.PutObject","kind":"SPAN_KIND_CLIENT","startTimeUnixNano":"1793971998300119101","endTimeUnixNano":"1793971998301189662","attributes":[{"key":"rpc.system","value":{"stringValue":"aws.s3"}},{"key":"rpc.service","value":{"stringValue":"S3"}},{"key":"rpc.method","value":{"stringValue":"PutObject"}},{"key":"aws.s3.operation","value":{"stringValue":"PutObject"}},{"key":"aws.s3.object.size","value":{"intValue":"2441"}}],"status":{}},{"traceId":"j95dugCfEdBY9YgXsJxuMw==","spanId":"N4QuwUoY9Lo=","parentSpanId":"5/rdEDez4/0=","flags":257,"name":"S3.PutObject","kind":"SPAN_KIND_CLIENT","startTimeUnixNano":"1793971998307725450","endTimeUnixNano":"1793971998309040117","attributes":[{"key":"rpc.system","value":{"stringValue":"aws.s3"}},{"key":"rpc.service","value":{"stringValue":"S3"}},{"key":"rpc.method","value":{"stringValue":"PutObject"}},{"key":"aws.s3.operation","value":{"stringValue":"PutObject"}},{"key":"aws.s3.object.size","value":{"intValue":"2588"}}],"status":{}},{"traceId":"j95dugCfEdBY9YgXsJxuMw==","spanId":"7hf7PS1JCZc=","parentSpanId":"5/rdEDez4/0=","flags":257,"name":"S3.DeleteObject","kind":"SPAN_KIND_CLIENT","startTimeUnixNano":"1793971998311880731","endTimeUnixNano":"1793971998312991592","attributes":[{"key":"rpc.system","value":{"stringValue":"aws.s3"}},{"key":"rpc.service","value":{"stringValue":"S3"}},{"key":"rpc.method","value":{"stringValue":"DeleteObject"}},{"key":"aws.s3.operation","value":{"stringValue":"DeleteObject"}}],"status":{}}]}]},{"resource":{"attributes":[{"key":"deployment.environment.name","value":{"stringValue":"lab"}},{"key":"service.instance.id","value":{"stringValue":"7fd7662bf332"}},{"key":"service.name","value":{"stringValue":"messenger-worker"}},{"key":"service.version","value":{"stringValue":"dev"}},{"key":"telemetry.sdk.language","value":{"stringValue":"go"}},{"key":"telemetry.sdk.name","value":{"stringValue":"opentelemetry"}},{"key":"telemetry.sdk.version","value":{"stringValue":"1.47.0"}}]},"scopeSpans":[{"scope":{"name":"github.com/exaring/otelpgx","version":"v0.13.0"},"spans":[{"traceId":"j95dugCfEdBY9YgXsJxuMw==","spanId":"4Eg8NE5FUg4=","parentSpanId":"5/rdEDez4/0=","flags":257,"name":"pool.acquire","kind":"SPAN_KIND_CLIENT","startTimeUnixNano":"1793971998309054525","endTimeUnixNano":"1793971998309065759","attributes":[{"key":"db.system.name","value":{"stringValue":"postgresql"}}],"status":{}},{"traceId":"j95dugCfEdBY9YgXsJxuMw==","spanId":"S6dwuhDehLc=","parentSpanId":"5/rdEDez4/0=","flags":257,"name":"BEGIN","kind":"SPAN_KIND_CLIENT","startTimeUnixNano":"1793971998309068182","endTimeUnixNano":"1793971998309170794","attributes":[{"key":"db.system.name","value":{"stringValue":"postgresql"}},{"key":"pgx.rows_affected","value":{"intValue":"0"}}],"status":{}},{"traceId":"j95dugCfEdBY9YgXsJxuMw==","spanId":"3c66DG+vMzY=","parentSpanId":"5/rdEDez4/0=","flags":257,"name":"SELECT","kind":"SPAN_KIND_CLIENT","startTimeUnixNano":"1793971998309180107","endTimeUnixNano":"1793971998309438539","attributes":[{"key":"db.system.name","value":{"stringValue":"postgresql"}},{"key":"pgx.rows_affected","value":{"intValue":"1"}}],"status":{}},{"traceId":"j95dugCfEdBY9YgXsJxuMw==","spanId":"kgrXGIoCakE=","parentSpanId":"5/rdEDez4/0=","flags":257,"name":"SELECT","kind":"SPAN_KIND_CLIENT","startTimeUnixNano":"1793971998309448102","endTimeUnixNano":"1793971998309597490","attributes":[{"key":"db.system.name","value":{"stringValue":"postgresql"}},{"key":"pgx.rows_affected","value":{"intValue":"1"}}],"status":{}},{"traceId":"j95dugCfEdBY9YgXsJxuMw==","spanId":"cHcdzaBx/j0=","parentSpanId":"5/rdEDez4/0=","flags":257,"name":"INSERT","kind":"SPAN_KIND_CLIENT","startTimeUnixNano":"1793971998309605592","endTimeUnixNano":"1793971998310270589","attributes":[{"key":"db.system.name","value":{"stringValue":"postgresql"}},{"key":"pgx.rows_affected","value":{"intValue":"1"}}],"status":{}},{"traceId":"j95dugCfEdBY9YgXsJxuMw==","spanId":"UX8iFSxgZdU=","parentSpanId":"cHcdzaBx/j0=","flags":257,"name":"INSERT","kind":"SPAN_KIND_CLIENT","startTimeUnixNano":"1793971998309610478","endTimeUnixNano":"1793971998309831072","attributes":[{"key":"db.system.name","value":{"stringValue":"postgresql"}},{"key":"pgx.prepare_stmt.name","value":{"stringValue":"stmtcache_14dc60f644da6f8a7202f0c5d5df0eb1141c844b78b82019"}},{"key":"db.operation.name","value":{"stringValue":"INSERT"}}],"status":{}},{"traceId":"j95dugCfEdBY9YgXsJxuMw==","spanId":"dWIZiuFAUAo=","parentSpanId":"5/rdEDez4/0=","flags":257,"name":"INSERT","kind":"SPAN_KIND_CLIENT","startTimeUnixNano":"1793971998310283494","endTimeUnixNano":"1793971998310439104","attributes":[{"key":"db.system.name","value":{"stringValue":"postgresql"}},{"key":"pgx.rows_affected","value":{"intValue":"1"}}],"status":{}},{"traceId":"j95dugCfEdBY9YgXsJxuMw==","spanId":"loEfwQHLybA=","parentSpanId":"5/rdEDez4/0=","flags":257,"name":"INSERT","kind":"SPAN_KIND_CLIENT","startTimeUnixNano":"1793971998310446329","endTimeUnixNano":"1793971998310592793","attributes":[{"key":"db.system.name","value":{"stringValue":"postgresql"}},{"key":"pgx.rows_affected","value":{"intValue":"1"}}],"status":{}},{"traceId":"j95dugCfEdBY9YgXsJxuMw==","spanId":"b2suTVl6yEo=","parentSpanId":"5/rdEDez4/0=","flags":257,"name":"UPDATE","kind":"SPAN_KIND_CLIENT","startTimeUnixNano":"1793971998310599182","endTimeUnixNano":"1793971998310892402","attributes":[{"key":"db.system.name","value":{"stringValue":"postgresql"}},{"key":"pgx.rows_affected","value":{"intValue":"1"}}],"status":{}},{"traceId":"j95dugCfEdBY9YgXsJxuMw==","spanId":"lwKX/y+9N6A=","parentSpanId":"b2suTVl6yEo=","flags":257,"name":"UPDATE","kind":"SPAN_KIND_CLIENT","startTimeUnixNano":"1793971998310602273","endTimeUnixNano":"1793971998310684755","attributes":[{"key":"db.system.name","value":{"stringValue":"postgresql"}},{"key":"pgx.prepare_stmt.name","value":{"stringValue":"stmtcache_bfb6a7dc0f53dfcd38aefaf13c90ae7ea9b8ec25681d6ac2"}},{"key":"db.operation.name","value":{"stringValue":"UPDATE"}}],"status":{}},{"traceId":"j95dugCfEdBY9YgXsJxuMw==","spanId":"pwL045wqPpw=","parentSpanId":"5/rdEDez4/0=","flags":257,"name":"UPDATE","kind":"SPAN_KIND_CLIENT","startTimeUnixNano":"1793971998310900337","endTimeUnixNano":"1793971998311112453","attributes":[{"key":"db.system.name","value":{"stringValue":"postgresql"}},{"key":"pgx.rows_affected","value":{"intValue":"1"}}],"status":{}},{"traceId":"j95dugCfEdBY9YgXsJxuMw==","spanId":"pdgTttBLKXg=","parentSpanId":"pwL045wqPpw=","flags":257,"name":"UPDATE","kind":"SPAN_KIND_CLIENT","startTimeUnixNano":"1793971998310904096","endTimeUnixNano":"1793971998310975804","attributes":[{"key":"db.system.name","value":{"stringValue":"postgresql"}},{"key":"pgx.prepare_stmt.name","value":{"stringValue":"stmtcache_f56957570da2038c8d89e8156bef39fa49e55ec384c81945"}},{"key":"db.operation.name","value":{"stringValue":"UPDATE"}}],"status":{}},{"traceId":"j95dugCfEdBY9YgXsJxuMw==","spanId":"Mry+kXJPa9Y=","parentSpanId":"5/rdEDez4/0=","flags":257,"name":"INSERT","kind":"SPAN_KIND_CLIENT","startTimeUnixNano":"1793971998311118968","endTimeUnixNano":"1793971998311234861","attributes":[{"key":"db.system.name","value":{"stringValue":"postgresql"}},{"key":"pgx.rows_affected","value":{"intValue":"1"}}],"status":{}},{"traceId":"j95dugCfEdBY9YgXsJxuMw==","spanId":"yQy0ksPFGBQ=","parentSpanId":"5/rdEDez4/0=","flags":257,"name":"COMMIT","kind":"SPAN_KIND_CLIENT","startTimeUnixNano":"1793971998311241293","endTimeUnixNano":"1793971998311818420","attributes":[{"key":"db.system.name","value":{"stringValue":"postgresql"}},{"key":"pgx.rows_affected","value":{"intValue":"0"}}],"status":{}},{"traceId":"j95dugCfEdBY9YgXsJxuMw==","spanId":"cBRjATDcT2U=","parentSpanId":"5/rdEDez4/0=","flags":257,"name":"pool.acquire","kind":"SPAN_KIND_CLIENT","startTimeUnixNano":"1793971998312998860","endTimeUnixNano":"1793971998313001658","attributes":[{"key":"db.system.name","value":{"stringValue":"postgresql"}}],"status":{}},{"traceId":"j95dugCfEdBY9YgXsJxuMw==","spanId":"l344mSK54RA=","parentSpanId":"5/rdEDez4/0=","flags":257,"name":"UPDATE","kind":"SPAN_KIND_CLIENT","startTimeUnixNano":"1793971998313002827","endTimeUnixNano":"1793971998313552473","attributes":[{"key":"db.system.name","value":{"stringValue":"postgresql"}},{"key":"pgx.rows_affected","value":{"intValue":"1"}}],"status":{}},{"traceId":"j95dugCfEdBY9YgXsJxuMw==","spanId":"40zi2PZgW8A=","parentSpanId":"l344mSK54RA=","flags":257,"name":"UPDATE","kind":"SPAN_KIND_CLIENT","startTimeUnixNano":"1793971998313005208","endTimeUnixNano":"1793971998313102182","attributes":[{"key":"db.system.name","value":{"stringValue":"postgresql"}},{"key":"pgx.prepare_stmt.name","value":{"stringValue":"stmtcache_6c84955ce8a23b4b2d881a1f3183345b48410266e3eb12ad"}},{"key":"db.operation.name","value":{"stringValue":"UPDATE"}}],"status":{}},{"traceId":"j95dugCfEdBY9YgXsJxuMw==","spanId":"n16+BZ2yeAE=","parentSpanId":"dCX4isahjAw=","flags":257,"name":"pool.acquire","kind":"SPAN_KIND_CLIENT","startTimeUnixNano":"1793971998314968500","endTimeUnixNano":"1793971998314970713","attributes":[{"key":"db.system.name","value":{"stringValue":"postgresql"}}],"status":{}},{"traceId":"j95dugCfEdBY9YgXsJxuMw==","spanId":"mpP4WSygFmI=","parentSpanId":"dCX4isahjAw=","flags":257,"name":"BEGIN","kind":"SPAN_KIND_CLIENT","startTimeUnixNano":"1793971998314972217","endTimeUnixNano":"1793971998315041920","attributes":[{"key":"db.system.name","value":{"stringValue":"postgresql"}},{"key":"pgx.rows_affected","value":{"intValue":"0"}}],"status":{}},{"traceId":"j95dugCfEdBY9YgXsJxuMw==","spanId":"EP7CkH3cf9g=","parentSpanId":"dCX4isahjAw=","flags":257,"name":"SELECT","kind":"SPAN_KIND_CLIENT","startTimeUnixNano":"1793971998315049395","endTimeUnixNano":"1793971998315184708","attributes":[{"key":"db.system.name","value":{"stringValue":"postgresql"}},{"key":"pgx.rows_affected","value":{"intValue":"1"}}],"status":{}},{"traceId":"j95dugCfEdBY9YgXsJxuMw==","spanId":"+sk/ER1hEZI=","parentSpanId":"dCX4isahjAw=","flags":257,"name":"SELECT","kind":"SPAN_KIND_CLIENT","startTimeUnixNano":"1793971998315191767","endTimeUnixNano":"1793971998315322528","attributes":[{"key":"db.system.name","value":{"stringValue":"postgresql"}},{"key":"pgx.rows_affected","value":{"intValue":"1"}}],"status":{}},{"traceId":"j95dugCfEdBY9YgXsJxuMw==","spanId":"Wbh7wue2nhI=","parentSpanId":"dCX4isahjAw=","flags":257,"name":"COMMIT","kind":"SPAN_KIND_CLIENT","startTimeUnixNano":"1793971998315329168","endTimeUnixNano":"1793971998315559492","attributes":[{"key":"db.system.name","value":{"stringValue":"postgresql"}},{"key":"pgx.rows_affected","value":{"intValue":"0"}}],"status":{}}]}]}]} \ No newline at end of file diff --git a/evidence/lab6/trace-retry.txt b/evidence/lab6/trace-retry.txt new file mode 100644 index 0000000..604687f --- /dev/null +++ b/evidence/lab6/trace-retry.txt @@ -0,0 +1,10 @@ +UTC 2026-11-06T13:33:27Z +HEAD 77fe98d775fdc07d5f9bfe04f7b4133c96c0849c +trace_id 8fde5dba009f11d058f58817b09c6e33 +messenger-api POST /api/v1/chats/{chat_id}/attachments kind SPAN_KIND_SERVER attempt None outcome None parent None +messenger-relay job.publish kind SPAN_KIND_PRODUCER attempt 1 outcome None parent PG9WhmyuKyQ= +messenger-worker job.process kind SPAN_KIND_CONSUMER attempt 1 outcome retried parent UcMZs5m1AA8= +messenger-relay job.requeue kind SPAN_KIND_INTERNAL attempt 2 outcome None parent PG9WhmyuKyQ= +messenger-relay job.publish kind SPAN_KIND_PRODUCER attempt 2 outcome None parent x4G/QURH+70= +messenger-worker job.process kind SPAN_KIND_CONSUMER attempt 2 outcome succeeded parent +VRIOo1OxO4= +messenger-worker job.process kind SPAN_KIND_CONSUMER attempt 1 outcome already_ready parent UcMZs5m1AA8= diff --git a/evidence/lab6/track2/full-run.txt b/evidence/lab6/track2/full-run.txt new file mode 100644 index 0000000..cfd9b63 --- /dev/null +++ b/evidence/lab6/track2/full-run.txt @@ -0,0 +1,11 @@ +2026-11-06T08:37:06Z preflight OK; start full track +2026-11-06T08:37:06Z warmup started +2026-11-06T09:42:56Z baseline started +2026-11-06T10:03:01Z burst: pause postgres +2026-11-06T10:05:01Z burst: unpause postgres +2026-11-06T11:29:51Z sustained: stop postgres +2026-11-06T11:44:55Z sustained: postgres restored +2026-11-06T11:49:53Z resolution under normal load +2026-11-06T12:52:17Z ttr: worker stopped and uploads started +2026-11-06T13:07:47Z false-positive phase started +2026-11-06T13:30:25Z done; evidence /Users/vladislav/Projects/mtusi2026lab6/evidence/lab6/track2/full diff --git a/evidence/lab6/track2/full/alert-audit.json b/evidence/lab6/track2/full/alert-audit.json new file mode 100644 index 0000000..56c2be4 --- /dev/null +++ b/evidence/lab6/track2/full/alert-audit.json @@ -0,0 +1,83 @@ +[ + { + "phase": "warmup", + "started_utc": "2026-11-06T08:37:06Z", + "finished_utc": "2026-11-06T09:42:56Z", + "firing": {}, + "pending": { + "APISLIMissing": 1 + }, + "page": 0, + "ticket": 0 + }, + { + "phase": "baseline", + "started_utc": "2026-11-06T09:42:56Z", + "finished_utc": "2026-11-06T10:02:51Z", + "firing": {}, + "pending": {}, + "page": 0, + "ticket": 0 + }, + { + "phase": "burst", + "started_utc": "2026-11-06T10:02:51Z", + "finished_utc": "2026-11-06T11:29:41Z", + "firing": {}, + "pending": { + "APISLIMissing": 2 + }, + "page": 0, + "ticket": 0 + }, + { + "phase": "sustained", + "started_utc": "2026-11-06T11:29:41Z", + "finished_utc": "2026-11-06T11:49:53Z", + "firing": { + "APIErrorBudgetFastBurn": 1, + "APIErrorBudgetSlowBurn": 1, + "QueueMetricsStale": 1 + }, + "pending": { + "QueueMetricsStale": 1 + }, + "page": 1, + "ticket": 1 + }, + { + "phase": "resolution_wait", + "started_utc": "2026-11-06T11:49:53Z", + "finished_utc": "2026-11-06T12:52:06Z", + "firing": {}, + "pending": {}, + "page": 0, + "ticket": 0 + }, + { + "phase": "ttr", + "started_utc": "2026-11-06T12:52:06Z", + "finished_utc": "2026-11-06T13:07:47Z", + "firing": { + "JobsOverdue": 1, + "QueueOldestJobAgeHigh": 1, + "QueueOldestJobAgeCritical": 1 + }, + "pending": { + "JobsOverdue": 1, + "QueueOldestJobAgeHigh": 1, + "QueueOldestJobAgeCritical": 1 + }, + "page": 1, + "ticket": 0 + }, + { + "phase": "false-positive", + "started_utc": "2026-11-06T13:07:47Z", + "finished_utc": "2026-11-06T13:30:24Z", + "firing": {}, + "pending": {}, + "page": 0, + "ticket": 0 + } +] diff --git a/evidence/lab6/track2/full/alert-audit.md b/evidence/lab6/track2/full/alert-audit.md new file mode 100644 index 0000000..9898143 --- /dev/null +++ b/evidence/lab6/track2/full/alert-audit.md @@ -0,0 +1,11 @@ +# Alert firing by phase + +| phase | page | ticket | firing | pending-not-fired | +|---|---:|---:|---|---| +| warmup | 0 | 0 | {} | {'APISLIMissing': 1} | +| baseline | 0 | 0 | {} | {} | +| burst | 0 | 0 | {} | {'APISLIMissing': 2} | +| sustained | 1 | 1 | {'APIErrorBudgetFastBurn': 1, 'APIErrorBudgetSlowBurn': 1, 'QueueMetricsStale': 1} | {'QueueMetricsStale': 1} | +| resolution_wait | 0 | 0 | {} | {} | +| ttr | 1 | 0 | {'JobsOverdue': 1, 'QueueOldestJobAgeHigh': 1, 'QueueOldestJobAgeCritical': 1} | {'JobsOverdue': 1, 'QueueOldestJobAgeHigh': 1, 'QueueOldestJobAgeCritical': 1} | +| false-positive | 0 | 0 | {} | {} | diff --git a/evidence/lab6/track2/full/alerts.csv b/evidence/lab6/track2/full/alerts.csv new file mode 100644 index 0000000..f51f16c --- /dev/null +++ b/evidence/lab6/track2/full/alerts.csv @@ -0,0 +1,20 @@ +observed_utc,alert,state,active_at,value,injection_utc +2026-11-06T09:25:32Z,APISLIMissing,pending,2026-11-06T09:25:28.187213033Z,1e+00, +2026-11-06T10:31:47Z,APISLIMissing,pending,2026-11-06T10:31:43.187213033Z,1e+00,2026-11-06T10:03:01Z +2026-11-06T11:08:09Z,APISLIMissing,pending,2026-11-06T11:08:08.187213033Z,1e+00,2026-11-06T10:03:01Z +2026-11-06T11:34:51Z,APIErrorBudgetFastBurn,firing,2026-11-06T11:34:48.187213033Z,7.220216606498195e-02,2026-11-06T11:29:51Z +2026-11-06T11:34:56Z,QueueMetricsStale,pending,2026-11-06T11:34:53.187213033Z,1e+00,2026-11-06T11:29:51Z +2026-11-06T11:35:11Z,APIErrorBudgetSlowBurn,firing,2026-11-06T11:35:08.187213033Z,3.0189959294436908e-02,2026-11-06T11:29:51Z +2026-11-06T11:36:56Z,QueueMetricsStale,firing,2026-11-06T11:34:53.187213033Z,1e+00,2026-11-06T11:29:51Z +2026-11-06T11:45:12Z,QueueMetricsStale,resolved,,,2026-11-06T11:29:51Z +2026-11-06T11:49:30Z,APIErrorBudgetFastBurn,resolved,,,2026-11-06T11:29:51Z +2026-11-06T12:13:32Z,APIErrorBudgetSlowBurn,resolved,,,2026-11-06T11:29:51Z +2026-11-06T12:53:03Z,JobsOverdue,pending,2026-11-06T12:52:58.187213033Z,3e+00,2026-11-06T12:52:17Z +2026-11-06T12:54:33Z,QueueOldestJobAgeHigh,pending,2026-11-06T12:54:28.187213033Z,1.32353293e+02,2026-11-06T12:52:17Z +2026-11-06T12:55:03Z,JobsOverdue,firing,2026-11-06T12:52:58.187213033Z,2e+01,2026-11-06T12:52:17Z +2026-11-06T13:02:24Z,QueueOldestJobAgeCritical,pending,2026-11-06T13:02:23.187213033Z,6.09947642e+02,2026-11-06T12:52:17Z +2026-11-06T13:04:34Z,QueueOldestJobAgeHigh,firing,2026-11-06T12:54:28.187213033Z,7.29503946e+02,2026-11-06T12:52:17Z +2026-11-06T13:07:29Z,QueueOldestJobAgeCritical,firing,2026-11-06T13:02:23.187213033Z,9.08863892e+02,2026-11-06T12:52:17Z +2026-11-06T13:07:44Z,JobsOverdue,resolved,,,2026-11-06T12:52:17Z +2026-11-06T13:07:44Z,QueueOldestJobAgeCritical,resolved,,,2026-11-06T12:52:17Z +2026-11-06T13:07:44Z,QueueOldestJobAgeHigh,resolved,,,2026-11-06T12:52:17Z diff --git a/evidence/lab6/track2/full/alerts.json b/evidence/lab6/track2/full/alerts.json new file mode 100644 index 0000000..8571269 --- /dev/null +++ b/evidence/lab6/track2/full/alerts.json @@ -0,0 +1,154 @@ +[ + [ + "2026-11-06T09:25:32Z", + "APISLIMissing", + "pending", + "2026-11-06T09:25:28.187213033Z", + "1e+00", + "" + ], + [ + "2026-11-06T10:31:47Z", + "APISLIMissing", + "pending", + "2026-11-06T10:31:43.187213033Z", + "1e+00", + "2026-11-06T10:03:01Z" + ], + [ + "2026-11-06T11:08:09Z", + "APISLIMissing", + "pending", + "2026-11-06T11:08:08.187213033Z", + "1e+00", + "2026-11-06T10:03:01Z" + ], + [ + "2026-11-06T11:34:51Z", + "APIErrorBudgetFastBurn", + "firing", + "2026-11-06T11:34:48.187213033Z", + "7.220216606498195e-02", + "2026-11-06T11:29:51Z" + ], + [ + "2026-11-06T11:34:56Z", + "QueueMetricsStale", + "pending", + "2026-11-06T11:34:53.187213033Z", + "1e+00", + "2026-11-06T11:29:51Z" + ], + [ + "2026-11-06T11:35:11Z", + "APIErrorBudgetSlowBurn", + "firing", + "2026-11-06T11:35:08.187213033Z", + "3.0189959294436908e-02", + "2026-11-06T11:29:51Z" + ], + [ + "2026-11-06T11:36:56Z", + "QueueMetricsStale", + "firing", + "2026-11-06T11:34:53.187213033Z", + "1e+00", + "2026-11-06T11:29:51Z" + ], + [ + "2026-11-06T11:45:12Z", + "QueueMetricsStale", + "resolved", + "", + "", + "2026-11-06T11:29:51Z" + ], + [ + "2026-11-06T11:49:30Z", + "APIErrorBudgetFastBurn", + "resolved", + "", + "", + "2026-11-06T11:29:51Z" + ], + [ + "2026-11-06T12:13:32Z", + "APIErrorBudgetSlowBurn", + "resolved", + "", + "", + "2026-11-06T11:29:51Z" + ], + [ + "2026-11-06T12:53:03Z", + "JobsOverdue", + "pending", + "2026-11-06T12:52:58.187213033Z", + "3e+00", + "2026-11-06T12:52:17Z" + ], + [ + "2026-11-06T12:54:33Z", + "QueueOldestJobAgeHigh", + "pending", + "2026-11-06T12:54:28.187213033Z", + "1.32353293e+02", + "2026-11-06T12:52:17Z" + ], + [ + "2026-11-06T12:55:03Z", + "JobsOverdue", + "firing", + "2026-11-06T12:52:58.187213033Z", + "2e+01", + "2026-11-06T12:52:17Z" + ], + [ + "2026-11-06T13:02:24Z", + "QueueOldestJobAgeCritical", + "pending", + "2026-11-06T13:02:23.187213033Z", + "6.09947642e+02", + "2026-11-06T12:52:17Z" + ], + [ + "2026-11-06T13:04:34Z", + "QueueOldestJobAgeHigh", + "firing", + "2026-11-06T12:54:28.187213033Z", + "7.29503946e+02", + "2026-11-06T12:52:17Z" + ], + [ + "2026-11-06T13:07:29Z", + "QueueOldestJobAgeCritical", + "firing", + "2026-11-06T13:02:23.187213033Z", + "9.08863892e+02", + "2026-11-06T12:52:17Z" + ], + [ + "2026-11-06T13:07:44Z", + "JobsOverdue", + "resolved", + "", + "", + "2026-11-06T12:52:17Z" + ], + [ + "2026-11-06T13:07:44Z", + "QueueOldestJobAgeCritical", + "resolved", + "", + "", + "2026-11-06T12:52:17Z" + ], + [ + "2026-11-06T13:07:44Z", + "QueueOldestJobAgeHigh", + "resolved", + "", + "", + "2026-11-06T12:52:17Z" + ] +] diff --git a/evidence/lab6/track2/full/baseline-load.json b/evidence/lab6/track2/full/baseline-load.json new file mode 100644 index 0000000..401e95c --- /dev/null +++ b/evidence/lab6/track2/full/baseline-load.json @@ -0,0 +1,27 @@ +{ + "base_url": "http://localhost:8080", + "rate": 0.2, + "duration_s": 1195.02, + "scheduled": 240, + "counters": { + "accepted": 48, + "ready": 48, + "failed": 0, + "messages": 192, + "uploads": 48, + "dropped": 0 + }, + "failures": 0, + "failures_by_reason": {}, + "failure_samples": [], + "latency_ms": { + "p50": 9.0, + "p95": 11.9, + "p99": 14.3 + }, + "ttr_ms": { + "p50": 645.7, + "p95": 1260.5, + "p99": 1276.0 + } +} diff --git a/evidence/lab6/track2/full/baseline.json b/evidence/lab6/track2/full/baseline.json new file mode 100644 index 0000000..e363299 --- /dev/null +++ b/evidence/lab6/track2/full/baseline.json @@ -0,0 +1,12 @@ +{ + "api_error_5m": "0", + "api_error_1h": "0", + "api_error_30m": "0", + "api_error_6h": "0", + "ttr_bad_5m": "0", + "ttr_bad_1h": "0", + "queue_oldest": "0", + "queue_depth": "0", + "jobs_overdue": "0", + "worker_busy": "0" +} diff --git a/evidence/lab6/track2/full/burst-load.json b/evidence/lab6/track2/full/burst-load.json new file mode 100644 index 0000000..ac95645 --- /dev/null +++ b/evidence/lab6/track2/full/burst-load.json @@ -0,0 +1,40 @@ +{ + "base_url": "http://localhost:8080", + "rate": 0.2, + "duration_s": 3715.02, + "scheduled": 744, + "counters": { + "accepted": 144, + "ready": 144, + "failed": 25, + "messages": 595, + "uploads": 144, + "dropped": 0 + }, + "failures": 25, + "failures_by_reason": { + "http_503": 25 + }, + "failure_samples": [ + "Failure: POST /api/v1/chats/01a1b04f-a4f6-7d42-ab24-09cf408df4d9/messages: expected [201], received 503", + "Failure: POST /api/v1/chats/01a1b04f-a4f6-7d42-ab24-09cf408df4d9/attachments: expected [202], received 503", + "Failure: POST /api/v1/chats/01a1b04f-a4f6-7d42-ab24-09cf408df4d9/messages: expected [201], received 503", + "Failure: POST /api/v1/chats/01a1b04f-a4f6-7d42-ab24-09cf408df4d9/messages: expected [201], received 503", + "Failure: POST /api/v1/chats/01a1b04f-a4f6-7d42-ab24-09cf408df4d9/messages: expected [201], received 503", + "Failure: POST /api/v1/chats/01a1b04f-a4f6-7d42-ab24-09cf408df4d9/messages: expected [201], received 503", + "Failure: POST /api/v1/chats/01a1b04f-a4f6-7d42-ab24-09cf408df4d9/messages: expected [201], received 503", + "Failure: POST /api/v1/chats/01a1b04f-a4f6-7d42-ab24-09cf408df4d9/messages: expected [201], received 503", + "Failure: POST /api/v1/chats/01a1b04f-a4f6-7d42-ab24-09cf408df4d9/messages: expected [201], received 503", + "Failure: POST /api/v1/chats/01a1b04f-a4f6-7d42-ab24-09cf408df4d9/attachments: expected [202], received 503" + ], + "latency_ms": { + "p50": 6.8, + "p95": 9.7, + "p99": 18.9 + }, + "ttr_ms": { + "p50": 644.0, + "p95": 1254.8, + "p99": 1283.6 + } +} diff --git a/evidence/lab6/track2/full/burst.json b/evidence/lab6/track2/full/burst.json new file mode 100644 index 0000000..c582e43 --- /dev/null +++ b/evidence/lab6/track2/full/burst.json @@ -0,0 +1,26 @@ +{ + "active": { + "api_error_5m": "0.049019607843137254", + "api_error_1h": "0.004570383912248629", + "api_error_30m": "0.008223684210526315", + "api_error_6h": "0.00297441998810232", + "ttr_bad_5m": "0", + "ttr_bad_1h": "0", + "queue_oldest": "0", + "queue_depth": "0", + "jobs_overdue": "0", + "worker_busy": "0" + }, + "after": { + "api_error_5m": "0", + "api_error_1h": "0", + "api_error_30m": "0", + "api_error_6h": "0.00871383757406762", + "ttr_bad_5m": "0", + "ttr_bad_1h": "0", + "queue_oldest": "0", + "queue_depth": "0", + "jobs_overdue": "0", + "worker_busy": "0" + } +} diff --git a/evidence/lab6/track2/full/false-positive-load.json b/evidence/lab6/track2/full/false-positive-load.json new file mode 100644 index 0000000..ba17ca1 --- /dev/null +++ b/evidence/lab6/track2/full/false-positive-load.json @@ -0,0 +1,27 @@ +{ + "base_url": "http://localhost:8080", + "rate": 0.2, + "duration_s": 1195.01, + "scheduled": 240, + "counters": { + "accepted": 48, + "ready": 48, + "failed": 0, + "messages": 192, + "uploads": 48, + "dropped": 0 + }, + "failures": 0, + "failures_by_reason": {}, + "failure_samples": [], + "latency_ms": { + "p50": 7.1, + "p95": 9.8, + "p99": 11.4 + }, + "ttr_ms": { + "p50": 643.0, + "p95": 963.5, + "p99": 1275.4 + } +} diff --git a/evidence/lab6/track2/full/final.json b/evidence/lab6/track2/full/final.json new file mode 100644 index 0000000..2269663 --- /dev/null +++ b/evidence/lab6/track2/full/final.json @@ -0,0 +1,12 @@ +{ + "api_error_5m": "0", + "api_error_1h": "0", + "api_error_30m": "0", + "api_error_6h": "0.02338251986379115", + "ttr_bad_5m": "0", + "ttr_bad_1h": "0.1665980653407489", + "queue_oldest": "0", + "queue_depth": "0", + "jobs_overdue": "0", + "worker_busy": "0" +} diff --git a/evidence/lab6/track2/full/phases.json b/evidence/lab6/track2/full/phases.json new file mode 100644 index 0000000..d47a135 --- /dev/null +++ b/evidence/lab6/track2/full/phases.json @@ -0,0 +1,58 @@ +[ + { + "phase": "warmup", + "started_utc": "2026-11-06T08:37:06Z", + "finished_utc": "2026-11-06T09:42:56Z", + "duration_s": 3950.1, + "injection_utc": "", + "restore_utc": "" + }, + { + "phase": "baseline", + "started_utc": "2026-11-06T09:42:56Z", + "finished_utc": "2026-11-06T10:02:51Z", + "duration_s": 1195.4, + "injection_utc": "", + "restore_utc": "" + }, + { + "phase": "burst", + "started_utc": "2026-11-06T10:02:51Z", + "finished_utc": "2026-11-06T11:29:41Z", + "duration_s": 5209.5, + "injection_utc": "2026-11-06T10:03:01Z", + "restore_utc": "2026-11-06T10:05:01Z" + }, + { + "phase": "sustained", + "started_utc": "2026-11-06T11:29:41Z", + "finished_utc": "2026-11-06T11:49:53Z", + "duration_s": 1212.7, + "injection_utc": "2026-11-06T11:29:51Z", + "restore_utc": "2026-11-06T11:44:55Z" + }, + { + "phase": "resolution_wait", + "started_utc": "2026-11-06T11:49:53Z", + "finished_utc": "2026-11-06T12:52:06Z", + "duration_s": 3733.0, + "injection_utc": "", + "restore_utc": "" + }, + { + "phase": "ttr", + "started_utc": "2026-11-06T12:52:06Z", + "finished_utc": "2026-11-06T13:07:47Z", + "duration_s": 940.4, + "injection_utc": "2026-11-06T12:52:17Z", + "restore_utc": "2026-11-06T13:07:17Z" + }, + { + "phase": "false-positive", + "started_utc": "2026-11-06T13:07:47Z", + "finished_utc": "2026-11-06T13:30:24Z", + "duration_s": 1357.4, + "injection_utc": "", + "restore_utc": "" + } +] diff --git a/evidence/lab6/track2/full/preflight-load.json b/evidence/lab6/track2/full/preflight-load.json new file mode 100644 index 0000000..e3856d8 --- /dev/null +++ b/evidence/lab6/track2/full/preflight-load.json @@ -0,0 +1,27 @@ +{ + "base_url": "http://localhost:8080", + "rate": 1.0, + "duration_s": 2.02, + "scheduled": 3, + "counters": { + "accepted": 2, + "ready": 2, + "failed": 0, + "messages": 1, + "uploads": 2, + "dropped": 0 + }, + "failures": 0, + "failures_by_reason": {}, + "failure_samples": [], + "latency_ms": { + "p50": 5.6, + "p95": 5.6, + "p99": 5.6 + }, + "ttr_ms": { + "p50": 646.0, + "p95": 649.3, + "p99": 649.3 + } +} diff --git a/evidence/lab6/track2/full/resolution-load.json b/evidence/lab6/track2/full/resolution-load.json new file mode 100644 index 0000000..effb86e --- /dev/null +++ b/evidence/lab6/track2/full/resolution-load.json @@ -0,0 +1,27 @@ +{ + "base_url": "http://localhost:8080", + "rate": 0.2, + "duration_s": 3595.65, + "scheduled": 720, + "counters": { + "accepted": 145, + "ready": 145, + "failed": 0, + "messages": 575, + "uploads": 145, + "dropped": 0 + }, + "failures": 0, + "failures_by_reason": {}, + "failure_samples": [], + "latency_ms": { + "p50": 5.9, + "p95": 8.3, + "p99": 17.7 + }, + "ttr_ms": { + "p50": 638.6, + "p95": 962.5, + "p99": 1259.8 + } +} diff --git a/evidence/lab6/track2/full/snapshots/baseline-2026-11-06T02-57-50Z.json b/evidence/lab6/track2/full/snapshots/baseline-2026-11-06T02-57-50Z.json new file mode 100644 index 0000000..e363299 --- /dev/null +++ b/evidence/lab6/track2/full/snapshots/baseline-2026-11-06T02-57-50Z.json @@ -0,0 +1,12 @@ +{ + "api_error_5m": "0", + "api_error_1h": "0", + "api_error_30m": "0", + "api_error_6h": "0", + "ttr_bad_5m": "0", + "ttr_bad_1h": "0", + "queue_oldest": "0", + "queue_depth": "0", + "jobs_overdue": "0", + "worker_busy": "0" +} diff --git a/evidence/lab6/track2/full/snapshots/baseline-2026-11-06T10-02-51Z.json b/evidence/lab6/track2/full/snapshots/baseline-2026-11-06T10-02-51Z.json new file mode 100644 index 0000000..e363299 --- /dev/null +++ b/evidence/lab6/track2/full/snapshots/baseline-2026-11-06T10-02-51Z.json @@ -0,0 +1,12 @@ +{ + "api_error_5m": "0", + "api_error_1h": "0", + "api_error_30m": "0", + "api_error_6h": "0", + "ttr_bad_5m": "0", + "ttr_bad_1h": "0", + "queue_oldest": "0", + "queue_depth": "0", + "jobs_overdue": "0", + "worker_busy": "0" +} diff --git a/evidence/lab6/track2/full/snapshots/burst-active-2026-11-06T02-58-30Z.json b/evidence/lab6/track2/full/snapshots/burst-active-2026-11-06T02-58-30Z.json new file mode 100644 index 0000000..4dc37d5 --- /dev/null +++ b/evidence/lab6/track2/full/snapshots/burst-active-2026-11-06T02-58-30Z.json @@ -0,0 +1,12 @@ +{ + "api_error_5m": "0.04901960784313726", + "api_error_1h": "0.004177109440267336", + "api_error_30m": "0.008237232289950576", + "api_error_6h": "0.0029708853238265003", + "ttr_bad_5m": "0", + "ttr_bad_1h": "0", + "queue_oldest": "0", + "queue_depth": "0", + "jobs_overdue": "0", + "worker_busy": "0" +} diff --git a/evidence/lab6/track2/full/snapshots/burst-active-2026-11-06T10-03-31Z.json b/evidence/lab6/track2/full/snapshots/burst-active-2026-11-06T10-03-31Z.json new file mode 100644 index 0000000..bcbed61 --- /dev/null +++ b/evidence/lab6/track2/full/snapshots/burst-active-2026-11-06T10-03-31Z.json @@ -0,0 +1,12 @@ +{ + "api_error_5m": "0.049019607843137254", + "api_error_1h": "0.004570383912248629", + "api_error_30m": "0.008223684210526315", + "api_error_6h": "0.00297441998810232", + "ttr_bad_5m": "0", + "ttr_bad_1h": "0", + "queue_oldest": "0", + "queue_depth": "0", + "jobs_overdue": "0", + "worker_busy": "0" +} diff --git a/evidence/lab6/track2/full/snapshots/burst-after-2026-11-06T04-26-41Z.json b/evidence/lab6/track2/full/snapshots/burst-after-2026-11-06T04-26-41Z.json new file mode 100644 index 0000000..2e010fc --- /dev/null +++ b/evidence/lab6/track2/full/snapshots/burst-after-2026-11-06T04-26-41Z.json @@ -0,0 +1,12 @@ +{ + "api_error_5m": "0", + "api_error_1h": "0", + "api_error_30m": "0", + "api_error_6h": "0.008868393047179852", + "ttr_bad_5m": "0", + "ttr_bad_1h": "0", + "queue_oldest": "0", + "queue_depth": "0", + "jobs_overdue": "0", + "worker_busy": "0" +} diff --git a/evidence/lab6/track2/full/snapshots/burst-after-2026-11-06T11-29-41Z.json b/evidence/lab6/track2/full/snapshots/burst-after-2026-11-06T11-29-41Z.json new file mode 100644 index 0000000..cf34ec5 --- /dev/null +++ b/evidence/lab6/track2/full/snapshots/burst-after-2026-11-06T11-29-41Z.json @@ -0,0 +1,12 @@ +{ + "api_error_5m": "0", + "api_error_1h": "0", + "api_error_30m": "0", + "api_error_6h": "0.00871383757406762", + "ttr_bad_5m": "0", + "ttr_bad_1h": "0", + "queue_oldest": "0", + "queue_depth": "0", + "jobs_overdue": "0", + "worker_busy": "0" +} diff --git a/evidence/lab6/track2/full/snapshots/final-2026-11-06T06-22-18Z.json b/evidence/lab6/track2/full/snapshots/final-2026-11-06T06-22-18Z.json new file mode 100644 index 0000000..f431fd7 --- /dev/null +++ b/evidence/lab6/track2/full/snapshots/final-2026-11-06T06-22-18Z.json @@ -0,0 +1,12 @@ +{ + "api_error_5m": "0", + "api_error_1h": "0", + "api_error_30m": "0", + "api_error_6h": "0.023575188830395975", + "ttr_bad_5m": "0", + "ttr_bad_1h": "0.1586439457023727", + "queue_oldest": "0", + "queue_depth": "0", + "jobs_overdue": "0", + "worker_busy": "0" +} diff --git a/evidence/lab6/track2/full/snapshots/final-2026-11-06T13-30-24Z.json b/evidence/lab6/track2/full/snapshots/final-2026-11-06T13-30-24Z.json new file mode 100644 index 0000000..2269663 --- /dev/null +++ b/evidence/lab6/track2/full/snapshots/final-2026-11-06T13-30-24Z.json @@ -0,0 +1,12 @@ +{ + "api_error_5m": "0", + "api_error_1h": "0", + "api_error_30m": "0", + "api_error_6h": "0.02338251986379115", + "ttr_bad_5m": "0", + "ttr_bad_1h": "0.1665980653407489", + "queue_oldest": "0", + "queue_depth": "0", + "jobs_overdue": "0", + "worker_busy": "0" +} diff --git a/evidence/lab6/track2/full/snapshots/final-summary-2026-11-06T06-22-19Z.json b/evidence/lab6/track2/full/snapshots/final-summary-2026-11-06T06-22-19Z.json new file mode 100644 index 0000000..f431fd7 --- /dev/null +++ b/evidence/lab6/track2/full/snapshots/final-summary-2026-11-06T06-22-19Z.json @@ -0,0 +1,12 @@ +{ + "api_error_5m": "0", + "api_error_1h": "0", + "api_error_30m": "0", + "api_error_6h": "0.023575188830395975", + "ttr_bad_5m": "0", + "ttr_bad_1h": "0.1586439457023727", + "queue_oldest": "0", + "queue_depth": "0", + "jobs_overdue": "0", + "worker_busy": "0" +} diff --git a/evidence/lab6/track2/full/snapshots/final-summary-2026-11-06T13-30-25Z.json b/evidence/lab6/track2/full/snapshots/final-summary-2026-11-06T13-30-25Z.json new file mode 100644 index 0000000..2269663 --- /dev/null +++ b/evidence/lab6/track2/full/snapshots/final-summary-2026-11-06T13-30-25Z.json @@ -0,0 +1,12 @@ +{ + "api_error_5m": "0", + "api_error_1h": "0", + "api_error_30m": "0", + "api_error_6h": "0.02338251986379115", + "ttr_bad_5m": "0", + "ttr_bad_1h": "0.1665980653407489", + "queue_oldest": "0", + "queue_depth": "0", + "jobs_overdue": "0", + "worker_busy": "0" +} diff --git a/evidence/lab6/track2/full/snapshots/resolution-2026-11-06T05-46-42Z.json b/evidence/lab6/track2/full/snapshots/resolution-2026-11-06T05-46-42Z.json new file mode 100644 index 0000000..83a59a4 --- /dev/null +++ b/evidence/lab6/track2/full/snapshots/resolution-2026-11-06T05-46-42Z.json @@ -0,0 +1,12 @@ +{ + "api_error_5m": "0", + "api_error_1h": "0", + "api_error_30m": "0", + "api_error_6h": "0.04805225099136926", + "ttr_bad_5m": "0", + "ttr_bad_1h": "0", + "queue_oldest": "0", + "queue_depth": "0", + "jobs_overdue": "0", + "worker_busy": "0" +} diff --git a/evidence/lab6/track2/full/snapshots/resolution-2026-11-06T12-52-06Z.json b/evidence/lab6/track2/full/snapshots/resolution-2026-11-06T12-52-06Z.json new file mode 100644 index 0000000..d9d77eb --- /dev/null +++ b/evidence/lab6/track2/full/snapshots/resolution-2026-11-06T12-52-06Z.json @@ -0,0 +1,12 @@ +{ + "api_error_5m": "0", + "api_error_1h": "0", + "api_error_30m": "0", + "api_error_6h": "0.04763005780346821", + "ttr_bad_5m": "0", + "ttr_bad_1h": "0", + "queue_oldest": "0", + "queue_depth": "0", + "jobs_overdue": "0", + "worker_busy": "0" +} diff --git a/evidence/lab6/track2/full/snapshots/sustained-active-2026-11-06T04-27-21Z.json b/evidence/lab6/track2/full/snapshots/sustained-active-2026-11-06T04-27-21Z.json new file mode 100644 index 0000000..852e187 --- /dev/null +++ b/evidence/lab6/track2/full/snapshots/sustained-active-2026-11-06T04-27-21Z.json @@ -0,0 +1,12 @@ +{ + "api_error_5m": "0.050505050505050504", + "api_error_1h": "0.008333333333333333", + "api_error_30m": "0.015060240963855422", + "api_error_6h": "0.010567101091933777", + "ttr_bad_5m": "0", + "ttr_bad_1h": "0", + "queue_oldest": "0.648426", + "queue_depth": "0", + "jobs_overdue": "0", + "worker_busy": "0" +} diff --git a/evidence/lab6/track2/full/snapshots/sustained-active-2026-11-06T11-30-21Z.json b/evidence/lab6/track2/full/snapshots/sustained-active-2026-11-06T11-30-21Z.json new file mode 100644 index 0000000..350ec5b --- /dev/null +++ b/evidence/lab6/track2/full/snapshots/sustained-active-2026-11-06T11-30-21Z.json @@ -0,0 +1,12 @@ +{ + "api_error_5m": "0.046296296296296294", + "api_error_1h": "0.005973715651135006", + "api_error_30m": "0.011547344110854504", + "api_error_6h": "0.010384215991692628", + "ttr_bad_5m": "0", + "ttr_bad_1h": "0", + "queue_oldest": "0", + "queue_depth": "0", + "jobs_overdue": "0", + "worker_busy": "0" +} diff --git a/evidence/lab6/track2/full/snapshots/sustained-after-2026-11-06T04-46-46Z.json b/evidence/lab6/track2/full/snapshots/sustained-after-2026-11-06T04-46-46Z.json new file mode 100644 index 0000000..4097e0f --- /dev/null +++ b/evidence/lab6/track2/full/snapshots/sustained-after-2026-11-06T04-46-46Z.json @@ -0,0 +1,12 @@ +{ + "api_error_5m": "0.024096385542168676", + "api_error_1h": "0.2981878088962109", + "api_error_30m": "0.3943355119825709", + "api_error_6h": "0.0665374677002584", + "ttr_bad_5m": "0", + "ttr_bad_1h": "0", + "queue_oldest": "0", + "queue_depth": "0", + "jobs_overdue": "0", + "worker_busy": "0" +} diff --git a/evidence/lab6/track2/full/snapshots/sustained-after-2026-11-06T11-49-53Z.json b/evidence/lab6/track2/full/snapshots/sustained-after-2026-11-06T11-49-53Z.json new file mode 100644 index 0000000..8d4f25e --- /dev/null +++ b/evidence/lab6/track2/full/snapshots/sustained-after-2026-11-06T11-49-53Z.json @@ -0,0 +1,12 @@ +{ + "api_error_5m": "0.010869565217391304", + "api_error_1h": "0.2394179894179894", + "api_error_30m": "0.37319587628865974", + "api_error_6h": "0.06527249683143219", + "ttr_bad_5m": "0", + "ttr_bad_1h": "0", + "queue_oldest": "0", + "queue_depth": "0", + "jobs_overdue": "0", + "worker_busy": "0" +} diff --git a/evidence/lab6/track2/full/snapshots/ttr-after-2026-11-06T06-02-23Z.json b/evidence/lab6/track2/full/snapshots/ttr-after-2026-11-06T06-02-23Z.json new file mode 100644 index 0000000..3dba373 --- /dev/null +++ b/evidence/lab6/track2/full/snapshots/ttr-after-2026-11-06T06-02-23Z.json @@ -0,0 +1,12 @@ +{ + "api_error_5m": "0", + "api_error_1h": "0", + "api_error_30m": "0", + "api_error_6h": "0.024685440383463146", + "ttr_bad_5m": null, + "ttr_bad_1h": "0.15612704507336422", + "queue_oldest": "0", + "queue_depth": "0", + "jobs_overdue": "0", + "worker_busy": "0" +} diff --git a/evidence/lab6/track2/full/snapshots/ttr-after-2026-11-06T13-07-47Z.json b/evidence/lab6/track2/full/snapshots/ttr-after-2026-11-06T13-07-47Z.json new file mode 100644 index 0000000..ecf322c --- /dev/null +++ b/evidence/lab6/track2/full/snapshots/ttr-after-2026-11-06T13-07-47Z.json @@ -0,0 +1,12 @@ +{ + "api_error_5m": "0", + "api_error_1h": "0", + "api_error_30m": "0", + "api_error_6h": "0.02447427824640608", + "ttr_bad_5m": null, + "ttr_bad_1h": "0.16383131398899278", + "queue_oldest": "0", + "queue_depth": "0", + "jobs_overdue": "0", + "worker_busy": "0" +} diff --git a/evidence/lab6/track2/full/snapshots/warmup-2026-11-06T02-37-54Z.json b/evidence/lab6/track2/full/snapshots/warmup-2026-11-06T02-37-54Z.json new file mode 100644 index 0000000..e363299 --- /dev/null +++ b/evidence/lab6/track2/full/snapshots/warmup-2026-11-06T02-37-54Z.json @@ -0,0 +1,12 @@ +{ + "api_error_5m": "0", + "api_error_1h": "0", + "api_error_30m": "0", + "api_error_6h": "0", + "ttr_bad_5m": "0", + "ttr_bad_1h": "0", + "queue_oldest": "0", + "queue_depth": "0", + "jobs_overdue": "0", + "worker_busy": "0" +} diff --git a/evidence/lab6/track2/full/snapshots/warmup-2026-11-06T09-42-56Z.json b/evidence/lab6/track2/full/snapshots/warmup-2026-11-06T09-42-56Z.json new file mode 100644 index 0000000..e363299 --- /dev/null +++ b/evidence/lab6/track2/full/snapshots/warmup-2026-11-06T09-42-56Z.json @@ -0,0 +1,12 @@ +{ + "api_error_5m": "0", + "api_error_1h": "0", + "api_error_30m": "0", + "api_error_6h": "0", + "ttr_bad_5m": "0", + "ttr_bad_1h": "0", + "queue_oldest": "0", + "queue_depth": "0", + "jobs_overdue": "0", + "worker_busy": "0" +} diff --git a/evidence/lab6/track2/full/summary.md b/evidence/lab6/track2/full/summary.md new file mode 100644 index 0000000..56d009c --- /dev/null +++ b/evidence/lab6/track2/full/summary.md @@ -0,0 +1,82 @@ +# Full Track 2 run + +Phases: +```json +[ + { + "phase": "warmup", + "started_utc": "2026-11-06T08:37:06Z", + "finished_utc": "2026-11-06T09:42:56Z", + "duration_s": 3950.1, + "injection_utc": "", + "restore_utc": "" + }, + { + "phase": "baseline", + "started_utc": "2026-11-06T09:42:56Z", + "finished_utc": "2026-11-06T10:02:51Z", + "duration_s": 1195.4, + "injection_utc": "", + "restore_utc": "" + }, + { + "phase": "burst", + "started_utc": "2026-11-06T10:02:51Z", + "finished_utc": "2026-11-06T11:29:41Z", + "duration_s": 5209.5, + "injection_utc": "2026-11-06T10:03:01Z", + "restore_utc": "2026-11-06T10:05:01Z" + }, + { + "phase": "sustained", + "started_utc": "2026-11-06T11:29:41Z", + "finished_utc": "2026-11-06T11:49:53Z", + "duration_s": 1212.7, + "injection_utc": "2026-11-06T11:29:51Z", + "restore_utc": "2026-11-06T11:44:55Z" + }, + { + "phase": "resolution_wait", + "started_utc": "2026-11-06T11:49:53Z", + "finished_utc": "2026-11-06T12:52:06Z", + "duration_s": 3733.0, + "injection_utc": "", + "restore_utc": "" + }, + { + "phase": "ttr", + "started_utc": "2026-11-06T12:52:06Z", + "finished_utc": "2026-11-06T13:07:47Z", + "duration_s": 940.4, + "injection_utc": "2026-11-06T12:52:17Z", + "restore_utc": "2026-11-06T13:07:17Z" + }, + { + "phase": "false-positive", + "started_utc": "2026-11-06T13:07:47Z", + "finished_utc": "2026-11-06T13:30:24Z", + "duration_s": 1357.4, + "injection_utc": "", + "restore_utc": "" + } +] +``` + +Final snapshot: +```json +{ + "api_error_5m": "0", + "api_error_1h": "0", + "api_error_30m": "0", + "api_error_6h": "0.02338251986379115", + "ttr_bad_5m": "0", + "ttr_bad_1h": "0.1665980653407489", + "queue_oldest": "0", + "queue_depth": "0", + "jobs_overdue": "0", + "worker_busy": "0" +} +``` + +Aborted: False +Restored: True diff --git a/evidence/lab6/track2/full/sustained-load.json b/evidence/lab6/track2/full/sustained-load.json new file mode 100644 index 0000000..debfa2b --- /dev/null +++ b/evidence/lab6/track2/full/sustained-load.json @@ -0,0 +1,40 @@ +{ + "base_url": "http://localhost:8080", + "rate": 0.2, + "duration_s": 1195.02, + "scheduled": 240, + "counters": { + "accepted": 13, + "ready": 13, + "failed": 181, + "messages": 192, + "uploads": 13, + "dropped": 0 + }, + "failures": 181, + "failures_by_reason": { + "http_503": 181 + }, + "failure_samples": [ + "Failure: POST /api/v1/chats/01a1b09f-2302-7b49-9a83-f634b41bf55d/messages: expected [201], received 503", + "Failure: POST /api/v1/chats/01a1b09f-2302-7b49-9a83-f634b41bf55d/attachments: expected [202], received 503", + "Failure: POST /api/v1/chats/01a1b09f-2302-7b49-9a83-f634b41bf55d/messages: expected [201], received 503", + "Failure: POST /api/v1/chats/01a1b09f-2302-7b49-9a83-f634b41bf55d/messages: expected [201], received 503", + "Failure: POST /api/v1/chats/01a1b09f-2302-7b49-9a83-f634b41bf55d/messages: expected [201], received 503", + "Failure: POST /api/v1/chats/01a1b09f-2302-7b49-9a83-f634b41bf55d/messages: expected [201], received 503", + "Failure: POST /api/v1/chats/01a1b09f-2302-7b49-9a83-f634b41bf55d/messages: expected [201], received 503", + "Failure: POST /api/v1/chats/01a1b09f-2302-7b49-9a83-f634b41bf55d/messages: expected [201], received 503", + "Failure: POST /api/v1/chats/01a1b09f-2302-7b49-9a83-f634b41bf55d/messages: expected [201], received 503", + "Failure: POST /api/v1/chats/01a1b09f-2302-7b49-9a83-f634b41bf55d/attachments: expected [202], received 503" + ], + "latency_ms": { + "p50": 6.9, + "p95": 9.8, + "p99": 16.3 + }, + "ttr_ms": { + "p50": 644.7, + "p95": 1255.0, + "p99": 1255.0 + } +} diff --git a/evidence/lab6/track2/full/sustained.json b/evidence/lab6/track2/full/sustained.json new file mode 100644 index 0000000..fa36b0b --- /dev/null +++ b/evidence/lab6/track2/full/sustained.json @@ -0,0 +1,27 @@ +{ + "active": { + "api_error_5m": "0.046296296296296294", + "api_error_1h": "0.005973715651135006", + "api_error_30m": "0.011547344110854504", + "api_error_6h": "0.010384215991692628", + "ttr_bad_5m": "0", + "ttr_bad_1h": "0", + "queue_oldest": "0", + "queue_depth": "0", + "jobs_overdue": "0", + "worker_busy": "0" + }, + "after": { + "api_error_5m": "0.010869565217391304", + "api_error_1h": "0.2394179894179894", + "api_error_30m": "0.37319587628865974", + "api_error_6h": "0.06527249683143219", + "ttr_bad_5m": "0", + "ttr_bad_1h": "0", + "queue_oldest": "0", + "queue_depth": "0", + "jobs_overdue": "0", + "worker_busy": "0" + }, + "queue_drained": true +} diff --git a/evidence/lab6/track2/full/ttr-load.json b/evidence/lab6/track2/full/ttr-load.json new file mode 100644 index 0000000..36c6609 --- /dev/null +++ b/evidence/lab6/track2/full/ttr-load.json @@ -0,0 +1,41 @@ +{ + "base_url": "http://localhost:8080", + "rate": 0.2, + "duration_s": 895.02, + "scheduled": 180, + "counters": { + "accepted": 20, + "ready": 0, + "failed": 180, + "messages": 0, + "uploads": 20, + "dropped": 0 + }, + "failures": 180, + "failures_by_reason": { + "attachment did not become ready within test deadline": 20, + "http_429": 160 + }, + "failure_samples": [ + "ready: Failure: attachment did not become ready within test deadline", + "ready: Failure: attachment did not become ready within test deadline", + "ready: Failure: attachment did not become ready within test deadline", + "ready: Failure: attachment did not become ready within test deadline", + "ready: Failure: attachment did not become ready within test deadline", + "ready: Failure: attachment did not become ready within test deadline", + "ready: Failure: attachment did not become ready within test deadline", + "ready: Failure: attachment did not become ready within test deadline", + "Failure: POST /api/v1/chats/01a1b0ea-9b18-78c7-b24f-cecf5fa0fefa/attachments: expected [202], received 429", + "ready: Failure: attachment did not become ready within test deadline" + ], + "latency_ms": { + "p50": null, + "p95": null, + "p99": null + }, + "ttr_ms": { + "p50": null, + "p95": null, + "p99": null + } +} diff --git a/evidence/lab6/track2/full/warmup-load.json b/evidence/lab6/track2/full/warmup-load.json new file mode 100644 index 0000000..edfdec7 --- /dev/null +++ b/evidence/lab6/track2/full/warmup-load.json @@ -0,0 +1,27 @@ +{ + "base_url": "http://localhost:8080", + "rate": 0.2, + "duration_s": 3596.27, + "scheduled": 720, + "counters": { + "accepted": 145, + "ready": 145, + "failed": 0, + "messages": 575, + "uploads": 145, + "dropped": 0 + }, + "failures": 0, + "failures_by_reason": {}, + "failure_samples": [], + "latency_ms": { + "p50": 7.9, + "p95": 10.6, + "p99": 18.7 + }, + "ttr_ms": { + "p50": 646.9, + "p95": 1269.3, + "p99": 1279.5 + } +} diff --git a/evidence/lab6/track2/ttd-ttr.md b/evidence/lab6/track2/ttd-ttr.md new file mode 100644 index 0000000..14e0283 --- /dev/null +++ b/evidence/lab6/track2/ttd-ttr.md @@ -0,0 +1,63 @@ +# Track 2: TTD/TTR + +Полный live-прогон выполнен 2026-11-06 (warmup 60m). Наблюдаемые TTD/TTR +приведены ниже; 6h warmup и реальный 7-дневный бюджет не измерялись. + +## Теоретические TTD при 100% ошибок + +| Alert | Окна | Порог | Теоретический TTD | +|---|---|---:|---:| +| APIErrorBudgetFastBurn | 1h + 5m | 7.2% | ≈4.3 мин | +| APIErrorBudgetSlowBurn | 6h + 30m | 3% | ≈10.8 мин | + +Если 6h-окно содержит только ~1ч45м истории, slow-алерт выглядит как ≈3.2 мин; +это неполное окно, а не доказательство более быстрого обнаружения. + +## TTR + +TTR SLI теперь использует good = `bucket{le="30.0"}` и bad = +`messenger_jobs_ttr_missed_total`; bad_ratio = bad/(good+bad). Guard: +≥10 событий good+bad за 5m для fast, ≥30 за 30m для slow. Sweeper в relay +помечает задачу как missed через 30s, поэтому алерт может сработать во время +простоя worker, а не только после восстановления. + +## False-positive + +`checks/alert-audit.txt` считает firing по фазам из `alerts.csv`. В +завершающей 20-минутной фазе новых firing не было; это ограниченное +наблюдение, не универсальная оценка FP. + +## Ограничения + +- Полный 6h slow-burn и 7d-бюджет не измерялись. +- Старые TTD/TTR числа из прогонов до изменения SLI не используются. + + +## P0 isolated worker outage (15 min) + +`checks/ttr-worker-15m.txt` (HEAD `935b228`): непрерывная нагрузка новых +пользователей каждые 90 с. `ratio5` первые ~90 с отсутствовал, затем был <1 +и стал 1 примерно с 330-й секунды; `TTRErrorBudgetFastBurn` firing с ~2 мин, +`JobsOverdue` firing, `QueueOldestJobAgeHigh` firing к ~12 мин. +После старта worker `overdue=0`, `ratio5` снижается; FastBurn resolved примерно +через 4 минуты. `TTRErrorBudgetSlowBurn` остаётся firing из-за 1h/6h окна — +это ожидаемое медленное окно, не ошибка. + + +## Полный прогон (2026-11-06) + +- Warmup 60m, baseline 20m, burst 2m, пауза 60m, sustained 15m, + resolution 60m, TTR 15m, false-positive 20m; `Aborted=False`. +- API: FastBurn firing 11:34:51Z (инъекция 11:29:51Z) → TTD 5m00s; + SlowBurn firing 11:35:11Z → 5m20s (на 60m warmup, не 6h theory). + От restore 11:44:55Z до resolved: FastBurn 4m35s, SlowBurn 28m37s. +- Burst: page/ticket 0; 144 ready, 0 401, 25 клиентских 503 во время pause. +- TTR: JobsOverdue firing 12:55:03Z (+2m46s), QueueOldestJobAgeHigh + firing 13:04:34Z (+12m17s); restore 13:07:17Z; Critical fired + 13:07:29Z — через 12s **после restore**, поэтому это не обнаружение до + восстановления; все resolved 13:07:44Z (~27s после restore). Injection + 12:52:17Z записан после остановки worker. +- False-positive: 13:07:47–13:30:24Z, firing 0. +- Ограничение: `TTRErrorBudgetFastBurn` в полном TTR-фазе не попал в + `alerts.csv`: 20 missed jobs теряются на фоне большого 1h good-окна; + изолированный 15m worker-down с непрерывной нагрузкой его показывает. diff --git a/evidence/lab6/unit-test.txt b/evidence/lab6/unit-test.txt new file mode 100644 index 0000000..422d73b --- /dev/null +++ b/evidence/lab6/unit-test.txt @@ -0,0 +1,43 @@ +env -u APP_ENV -u SERVER_HOST -u SERVER_PORT -u SERVER_READ_HEADER_TIMEOUT -u SERVER_READ_TIMEOUT -u SERVER_SHUTDOWN_TIMEOUT -u SERVER_MAX_BODY_BYTES -u LOG_LEVEL -u LOG_FORMAT -u POSTGRES_HOST -u POSTGRES_PORT -u POSTGRES_DATABASE -u POSTGRES_USER -u POSTGRES_PASSWORD -u POSTGRES_SSL_MODE -u POSTGRES_MAX_CONNS -u POSTGRES_MIN_CONNS -u POSTGRES_MAX_CONN_LIFETIME -u POSTGRES_MAX_CONN_IDLE_TIME -u POSTGRES_CONNECT_TIMEOUT -u POSTGRES_QUERY_TIMEOUT -u REDIS_ENABLED -u REDIS_HOST -u REDIS_PORT -u REDIS_PASSWORD -u REDIS_DB -u REDIS_MAX_RETRIES -u REDIS_DIAL_TIMEOUT -u REDIS_READ_TIMEOUT -u REDIS_WRITE_TIMEOUT -u REDIS_POOL_SIZE -u CACHE_ENABLED -u CACHE_CHAT_LIST_TTL -u CACHE_LOCK_TTL -u CACHE_LOCK_WAIT_TIMEOUT -u SESSION_TTL_SECONDS -u IDEMPOTENCY_TTL_SECONDS -u API_REPLICAS -u API_CPU_LIMIT -u API_MEM_LIMIT -u POSTGRES_MAX_CONNS -u POSTGRES_CPU_LIMIT -u POSTGRES_MEM_LIMIT -u LB_STATS_PORT -u S3_ENDPOINT -u S3_PUBLIC_ENDPOINT -u S3_PORT -u S3_REGION -u S3_BUCKET -u S3_ACCESS_KEY_ID -u S3_SECRET_ACCESS_KEY -u MAX_UPLOAD_BYTES -u MAX_IMAGE_PIXELS -u S3_PRESIGN_TTL -u S3_SWEEP_INTERVAL -u S3_SWEEP_GRACE -u BROKER_USER -u BROKER_PASSWORD -u BROKER_VHOST -u BROKER_URL -u BROKER_EXCHANGE -u BROKER_QUEUE -u BROKER_DLX -u BROKER_DLQ -u BROKER_MANAGEMENT_PORT -u BROKER_CPU_LIMIT -u BROKER_MEM_LIMIT -u WORKER_CONCURRENCY -u WORKER_PREFETCH -u WORKER_CPU_LIMIT -u WORKER_MEM_LIMIT -u WORKER_SHUTDOWN_TIMEOUT -u WORKER_HEALTH_PORT -u PROCESSING_PIPELINE_VERSION -u PROCESSING_MAX_ATTEMPTS -u PROCESSING_JOB_TIMEOUT -u PROCESSING_LEASE_TTL -u PROCESSING_HEARTBEAT -u PROCESSING_RETRY_BASE -u PROCESSING_RETRY_CAP -u OUTBOX_POLL_INTERVAL -u OUTBOX_CLAIM_TTL -u OUTBOX_BATCH -u OUTBOX_REAPER_INTERVAL -u OUTBOX_RECONCILE_AFTER -u OUTBOX_RETENTION -u RELAY_CPU_LIMIT -u RELAY_MEM_LIMIT -u RELAY_HEALTH_PORT -u STAGING_ORPHAN_GRACE -u STAGING_FAILED_RETENTION -u ADMISSION_MAX_PENDING_PER_USER -u ADMISSION_MAX_PENDING -u ADMISSION_MAX_STAGED_BYTES -u ADMISSION_MAX_CONCURRENT_UPLOADS -u OTEL_EXPORTER_OTLP_ENDPOINT -u OTEL_EXPORTER_OTLP_PROTOCOL -u OTEL_RESOURCE_ATTRIBUTES -u OTEL_METRIC_EXPORT_INTERVAL -u TELEMETRY_ENABLED -u PROMETHEUS_PORT -u LOKI_PORT -u TEMPO_PORT -u GRAFANA_PORT -u OTEL_COLLECTOR_CPU_LIMIT -u OTEL_COLLECTOR_MEM_LIMIT -u PROMETHEUS_CPU_LIMIT -u PROMETHEUS_MEM_LIMIT -u LOKI_CPU_LIMIT -u LOKI_MEM_LIMIT -u TEMPO_CPU_LIMIT -u TEMPO_MEM_LIMIT -u GRAFANA_CPU_LIMIT -u GRAFANA_MEM_LIMIT go test -race -shuffle=on -count=1 -timeout=5m ./... +? mtusi-messenger/cmd/jobctl [no test files] +? mtusi-messenger/cmd/messenger [no test files] +? mtusi-messenger/cmd/migrate [no test files] +? mtusi-messenger/cmd/relay [no test files] +? mtusi-messenger/cmd/s3init [no test files] +? mtusi-messenger/cmd/worker [no test files] +? mtusi-messenger/internal/broker [no test files] +ok mtusi-messenger/internal/config 3.198s +ok mtusi-messenger/internal/domain 5.063s +? mtusi-messenger/internal/failpoint [no test files] +ok mtusi-messenger/internal/health 9.434s +ok mtusi-messenger/internal/imagecheck 2.795s +ok mtusi-messenger/internal/imageproc 8.860s +ok mtusi-messenger/internal/logger 5.419s +? mtusi-messenger/internal/outbox [no test files] +ok mtusi-messenger/internal/platform/cache 7.191s +? mtusi-messenger/internal/platform/cache/mocks [no test files] +? mtusi-messenger/internal/platform/instanceid [no test files] +ok mtusi-messenger/internal/platform/objectstore 7.683s +ok mtusi-messenger/internal/platform/password 2.131s +ok mtusi-messenger/internal/platform/token 2.099s +ok mtusi-messenger/internal/service/attachment 9.423s +? mtusi-messenger/internal/service/attachment/mocks [no test files] +ok mtusi-messenger/internal/service/chat 9.939s +? mtusi-messenger/internal/service/chat/mocks [no test files] +ok mtusi-messenger/internal/service/message 10.300s +? mtusi-messenger/internal/service/message/mocks [no test files] +ok mtusi-messenger/internal/service/session 11.441s +? mtusi-messenger/internal/service/session/mocks [no test files] +ok mtusi-messenger/internal/service/user 10.787s +? mtusi-messenger/internal/service/user/mocks [no test files] +ok mtusi-messenger/internal/storage/postgres 11.786s +? mtusi-messenger/internal/storage/postgres/internal/sqlcgen [no test files] +? mtusi-messenger/internal/storage/postgres/migrations [no test files] +? mtusi-messenger/internal/storage/redis [no test files] +? mtusi-messenger/internal/storage/redis/mocks [no test files] +ok mtusi-messenger/internal/telemetry 12.820s +ok mtusi-messenger/internal/transport/rest 14.628s +? mtusi-messenger/internal/transport/rest/internal/oas [no test files] +? mtusi-messenger/internal/transport/rest/mocks [no test files] +? mtusi-messenger/internal/worker [no test files] +? mtusi-messenger/tools/specgen [no test files] diff --git a/evidence/lab6/worker-stop.txt b/evidence/lab6/worker-stop.txt new file mode 100644 index 0000000..e781b21 --- /dev/null +++ b/evidence/lab6/worker-stop.txt @@ -0,0 +1,18 @@ +Worker stop scenario (local, 2026-11-04) +========================================== +$ ./scripts/stop-worker.sh + Container mtusi-messenger-lab6-worker-1 Stopped +$ python3 scripts/lab6_load.py --rate 1 --duration 3 --upload-ratio 1 --deadline 3 + (three upload requests were accepted as 202; wait_ready timed out because no worker) +$ max(messenger_queue_oldest_job_age_seconds) after 20s + {"value":"15.218417"} (seconds) +$ max(rabbitmq_queue_messages_ready{queue="attachment.process.v1"}) + {"value":"3"} +$ ./scripts/start-worker.sh + Container mtusi-messenger-lab6-worker-1 Healthy +$ max(messenger_queue_oldest_job_age_seconds) after drain + {"value":"0"} +$ max(rabbitmq_queue_messages_ready{queue="attachment.process.v1"}) after drain + {"value":"0"} +Business result: accepted jobs were not lost; worker drain made them ready. +Logs: `job claimed`/`attachment ready` include trace_id; job_id is redacted; bodies and filenames are absent. diff --git a/evidence/lab6/worker-stopped-load.json b/evidence/lab6/worker-stopped-load.json new file mode 100644 index 0000000..71cadc2 --- /dev/null +++ b/evidence/lab6/worker-stopped-load.json @@ -0,0 +1,30 @@ +{ + "base_url": "http://localhost:8080", + "rate": 1.0, + "duration_s": 5.12, + "scheduled": 3, + "counters": { + "accepted": 3, + "ready": 0, + "failed": 3, + "messages": 0, + "uploads": 3, + "dropped": 0 + }, + "failures": 3, + "failure_samples": [ + "ready: Failure: attachment did not become ready within test deadline", + "ready: Failure: attachment did not become ready within test deadline", + "ready: Failure: attachment did not become ready within test deadline" + ], + "latency_ms": { + "p50": null, + "p95": null, + "p99": null + }, + "ttr_ms": { + "p50": null, + "p95": null, + "p99": null + } +} diff --git a/evidence/lb-readiness.txt b/evidence/lb-readiness.txt new file mode 100644 index 0000000..8972421 --- /dev/null +++ b/evidence/lb-readiness.txt @@ -0,0 +1,31 @@ +# LB excludes a not-ready but reachable replica (lab3) +# generated: 2026-10-16T14:02:26Z +# lb: haproxy:3.2-alpine + +## 1. baseline: requests through LB by replica + 18 52861386fddb + 22 8587b4251b72 + stats: api1=UP api2=UP api3=MAINT (resolution) api4=MAINT (resolution) api5=MAINT (resolution) api6=MAINT (resolution) api7=MAINT (resolution) api8=MAINT (resolution) BACKEND=UP + +## 2. start a temporary TCP proxy to postgres and a candidate replica behind the same network alias + instance-id: 9e9e905440d3, readiness while its database is reachable: 200 + load balancer slot for the candidate: api3, stats: api1=UP api2=UP api3=UP api4=MAINT (resolution) api5=MAINT (resolution) api6=MAINT (resolution) api7=MAINT (resolution) api8=MAINT (resolution) BACKEND=UP + +## 3. cut the candidate's database access (stop only the TCP proxy) + candidate is still running: running, readiness: 503 + waiting for the load balancer to mark api3 DOWN + api3 went DOWN 2s after its database was cut (check: inter 2s fall 2) + stats after failure: api1=UP api2=UP api3=DOWN api4=MAINT (resolution) api5=MAINT (resolution) api6=MAINT (resolution) api7=MAINT (resolution) api8=MAINT (resolution) BACKEND=UP + +## 4. 40 requests through LB while the candidate is not ready + 18 52861386fddb + 22 8587b4251b72 + (the candidate must not appear above) + +## 5. business writes through LB during the exclusion + "failed_requests": 0, + "error_ratio": 0.0, + "successful_rps": 1163.529, + +## 6. cleanup + stats after cleanup: api1=UP api2=UP api3=MAINT (resolution) api4=MAINT (resolution) api5=MAINT (resolution) api6=MAINT (resolution) api7=MAINT (resolution) api8=MAINT (resolution) BACKEND=UP diff --git a/evidence/load-32clients.json b/evidence/load-32clients.json new file mode 100644 index 0000000..5f1db3f --- /dev/null +++ b/evidence/load-32clients.json @@ -0,0 +1,17 @@ +{ + "lab": 3, + "workload": "closed-loop POST messages; no automatic retries", + "requested_duration_seconds": 30.0, + "elapsed_seconds": 30.031, + "concurrency": 32, + "successful_requests": 38549, + "failed_requests": 0, + "error_ratio": 0.0, + "successful_rps": 1283.644, + "successful_latency_ms": { + "p50": 19.177, + "p95": 52.823, + "p99": 60.246 + }, + "note": "Latency percentiles cover successes only. Timeouts/errors are counted separately; closed-loop has coordinated omission and client overhead." +} diff --git a/evidence/load-32clients.txt b/evidence/load-32clients.txt new file mode 100644 index 0000000..abad426 --- /dev/null +++ b/evidence/load-32clients.txt @@ -0,0 +1,18 @@ +# контейнерный стенд через LB, 32 клиента, 30 с — 2026-10-16T14:26:39Z +{ + "lab": 3, + "workload": "closed-loop POST messages; no automatic retries", + "requested_duration_seconds": 30.0, + "elapsed_seconds": 30.031, + "concurrency": 32, + "successful_requests": 38549, + "failed_requests": 0, + "error_ratio": 0.0, + "successful_rps": 1283.644, + "successful_latency_ms": { + "p50": 19.177, + "p95": 52.823, + "p99": 60.246 + }, + "note": "Latency percentiles cover successes only. Timeouts/errors are counted separately; closed-loop has coordinated omission and client overhead." +} diff --git a/evidence/native-load.json b/evidence/native-load.json new file mode 100644 index 0000000..d7664cc --- /dev/null +++ b/evidence/native-load.json @@ -0,0 +1,22 @@ +{ + "lab": 3, + "workload": "closed-loop POST messages; failures counted, not raised", + "requested_duration_seconds": 90.0, + "elapsed_seconds": 90.033, + "concurrency": 32, + "successful_requests": 220781, + "failed_requests": 0, + "error_ratio": 0.0, + "errors_by_kind": {}, + "successful_rps": 2452.222, + "successful_latency_ms": { + "p50": 12.541, + "p95": 17.549, + "p99": 22.396 + }, + "instances": { + "Vladislavs-MacBook-Pro.local": 220781 + }, + "bootstrap_attempts": 1, + "note": "Percentiles cover successful writes only; transitional errors are expected during a rolling update." +} diff --git a/evidence/native-load.txt b/evidence/native-load.txt new file mode 100644 index 0000000..7d08d0b --- /dev/null +++ b/evidence/native-load.txt @@ -0,0 +1,23 @@ +# нативный процесс вне Docker, 32 клиента, 90 с — 2026-10-16T14:26:39Z +{ + "lab": 3, + "workload": "closed-loop POST messages; failures counted, not raised", + "requested_duration_seconds": 90.0, + "elapsed_seconds": 90.033, + "concurrency": 32, + "successful_requests": 220781, + "failed_requests": 0, + "error_ratio": 0.0, + "errors_by_kind": {}, + "successful_rps": 2452.222, + "successful_latency_ms": { + "p50": 12.541, + "p95": 17.549, + "p99": 22.396 + }, + "instances": { + "Vladislavs-MacBook-Pro.local": 220781 + }, + "bootstrap_attempts": 1, + "note": "Percentiles cover successful writes only; transitional errors are expected during a rolling update." +} diff --git a/evidence/path-overhead/README.md b/evidence/path-overhead/README.md new file mode 100644 index 0000000..b1efa16 --- /dev/null +++ b/evidence/path-overhead/README.md @@ -0,0 +1,40 @@ +# Контроль пути «хост -> Colima VM -> LB» + +Один и тот же генератор (`tests/load.py`), один и тот же профиль (закрытый цикл, +8 клиентов, 15 с прогрева, 60 с замера) и один и тот же стенд. Меняется только +место клиента: на хосте (через опубликованный порт) или в контейнере внутри VM +(напрямую в балансировщик по docker-сети). Воспроизведение: +`scripts/path_overhead_check.sh`. + +| клиент | успешных | отказов | ошибки | RPS | p50, мс | p95, мс | +| --- | --- | --- | --- | --- | --- | --- | +| на хосте, `http://127.0.0.1:8080` | 92 378 | 32 575 | 26.1 % | 1 539 | 3.79 | 7.16 | +| в VM, `http://lb` | 88 596 | **0** | 0 % | 1 475 | 5.29 | 8.42 | + +## Что это показывает + +1. **Пропускная способность одна и та же** (1 539 против 1 475, разница в пределах + разброса; клиент в VM даже немного медленнее, потому что делит с стендом те же + 2 vCPU). Значит путь «хост -> проброс порта -> VM» **не задаёт потолок**: его + исключение из маршрута ничего не прибавляет. +2. **Отказы целиком клиентские.** Тот же стенд под той же нагрузкой не отказал ни + разу для клиента внутри VM. При этом за прогон с 26 % клиентских отказов + балансировщик отдал все запросы без 5xx (`hrsp_5xx=0` в статистике HAProxy), а + в логах API нет ни одной записи уровня выше `info`. +3. Причина — сам проброс порта: генератор ходит без keep-alive (новое TCP-соединение + на запрос), и под шквалом соединений forwarder хоста начинает их отклонять. + Наблюдения: в момент замера на хосте было **19 556 сокетов в `TIME_WAIT`** при + диапазоне эфемерных портов 49 152-65 535 (16 384), а точечный пробник из 40 000 + быстрых подключений подряд получил 1 294 успеха и 38 706 `ECONNREFUSED`. +4. Предел этой хрупкости тоже измерен: прогон на ~4 500 соединений/с по тривиальному + `/health/live` дал 100 % отказов, после чего проброс порта (и доступ к Docker-эндпоинту + Colima) перестал отвечать до `colima restart`. Стенд при этом не падал — недоступным + был именно хостовый путь; серия трека 1 поэтому снимается клиентом внутри VM + (`CLIENT=vm`), где отказов нет. + +Клиент на хосте способен на большее: тот же закрытый цикл по тривиальному серверу, +поднятому на самом хосте (без Docker), дал 4 469 RPS без отказов — то есть ~1 500 RPS +не являются потолком генератора. + +Артефакты: `outside.txt`, `inside.txt`, `load-outside.json`, `load-inside.json`, +`summary.txt`. diff --git a/evidence/path-overhead/inside.txt b/evidence/path-overhead/inside.txt new file mode 100644 index 0000000..b8c7061 --- /dev/null +++ b/evidence/path-overhead/inside.txt @@ -0,0 +1,17 @@ +{ + "lab": 3, + "workload": "closed-loop POST messages; no automatic retries", + "requested_duration_seconds": 60.0, + "elapsed_seconds": 60.073, + "concurrency": 8, + "successful_requests": 88596, + "failed_requests": 0, + "error_ratio": 0.0, + "successful_rps": 1474.795, + "successful_latency_ms": { + "p50": 5.292, + "p95": 8.415, + "p99": 10.433 + }, + "note": "Latency percentiles cover successes only. Timeouts/errors are counted separately; closed-loop has coordinated omission and client overhead." +} diff --git a/evidence/path-overhead/load-inside.json b/evidence/path-overhead/load-inside.json new file mode 100644 index 0000000..b8c7061 --- /dev/null +++ b/evidence/path-overhead/load-inside.json @@ -0,0 +1,17 @@ +{ + "lab": 3, + "workload": "closed-loop POST messages; no automatic retries", + "requested_duration_seconds": 60.0, + "elapsed_seconds": 60.073, + "concurrency": 8, + "successful_requests": 88596, + "failed_requests": 0, + "error_ratio": 0.0, + "successful_rps": 1474.795, + "successful_latency_ms": { + "p50": 5.292, + "p95": 8.415, + "p99": 10.433 + }, + "note": "Latency percentiles cover successes only. Timeouts/errors are counted separately; closed-loop has coordinated omission and client overhead." +} diff --git a/evidence/path-overhead/load-outside.json b/evidence/path-overhead/load-outside.json new file mode 100644 index 0000000..20b2005 --- /dev/null +++ b/evidence/path-overhead/load-outside.json @@ -0,0 +1,17 @@ +{ + "lab": 3, + "workload": "closed-loop POST messages; no automatic retries", + "requested_duration_seconds": 60.0, + "elapsed_seconds": 60.026, + "concurrency": 8, + "successful_requests": 92378, + "failed_requests": 32575, + "error_ratio": 0.260698, + "successful_rps": 1538.959, + "successful_latency_ms": { + "p50": 3.793, + "p95": 7.159, + "p99": 21.756 + }, + "note": "Latency percentiles cover successes only. Timeouts/errors are counted separately; closed-loop has coordinated omission and client overhead." +} diff --git a/evidence/path-overhead/outside.txt b/evidence/path-overhead/outside.txt new file mode 100644 index 0000000..20b2005 --- /dev/null +++ b/evidence/path-overhead/outside.txt @@ -0,0 +1,17 @@ +{ + "lab": 3, + "workload": "closed-loop POST messages; no automatic retries", + "requested_duration_seconds": 60.0, + "elapsed_seconds": 60.026, + "concurrency": 8, + "successful_requests": 92378, + "failed_requests": 32575, + "error_ratio": 0.260698, + "successful_rps": 1538.959, + "successful_latency_ms": { + "p50": 3.793, + "p95": 7.159, + "p99": 21.756 + }, + "note": "Latency percentiles cover successes only. Timeouts/errors are counted separately; closed-loop has coordinated omission and client overhead." +} diff --git a/evidence/path-overhead/summary.txt b/evidence/path-overhead/summary.txt new file mode 100644 index 0000000..d9c322f --- /dev/null +++ b/evidence/path-overhead/summary.txt @@ -0,0 +1,9 @@ +# Контроль пути к балансировщику +# generated: 2026-10-16T18:17:21Z +# profile: tests/load.py duration=60 concurrency=8 warmup=15 +# docker network: mtusi-messenger-lab3_default +# клиент в VM: python:3.12-alpine + +=== извне: клиент на хосте, http://127.0.0.1:8080 === + +=== изнутри: клиент в VM, http://lb === diff --git a/evidence/persistence.txt b/evidence/persistence.txt new file mode 100644 index 0000000..0946dd7 --- /dev/null +++ b/evidence/persistence.txt @@ -0,0 +1,4 @@ +# make test-persistence — 2026-10-16T13:59:43Z +env -u HTTP_PROXY -u HTTPS_PROXY -u ALL_PROXY -u http_proxy -u https_proxy -u all_proxy NO_PROXY=localhost,127.0.0.1,::1 no_proxy=localhost,127.0.0.1,::1 python3 tests/resilience.py --mode persistence --action-script "scripts/restart.sh" --base-url "http://localhost:8080" +Executing explicit persistence hook; hook output suppressed to avoid leaking secrets. +PASS: persistence preserved confirmed data and existing session. Hook scope needs operator evidence. diff --git a/evidence/quality.txt b/evidence/quality.txt new file mode 100644 index 0000000..917d529 --- /dev/null +++ b/evidence/quality.txt @@ -0,0 +1,35 @@ +# quality checks — 2026-10-16T14:30:53Z +python3 scripts/check_contract.py +PASS: offline skeleton structure, local refs and Python syntax; application NOT tested. +.venv/bin/python scripts/validate_openapi.py +PASS: full OpenAPI 3.1 and JSON Schema validation; application NOT tested. +env -u APP_ENV -u SERVER_HOST -u SERVER_PORT -u SERVER_READ_HEADER_TIMEOUT -u SERVER_SHUTDOWN_TIMEOUT -u LOG_LEVEL -u LOG_FORMAT -u POSTGRES_HOST -u POSTGRES_PORT -u POSTGRES_DATABASE -u POSTGRES_USER -u POSTGRES_PASSWORD -u POSTGRES_SSL_MODE -u POSTGRES_MAX_CONNS -u POSTGRES_MIN_CONNS -u POSTGRES_MAX_CONN_LIFETIME -u POSTGRES_MAX_CONN_IDLE_TIME -u POSTGRES_CONNECT_TIMEOUT -u POSTGRES_QUERY_TIMEOUT -u REDIS_ENABLED -u REDIS_HOST -u REDIS_PORT -u REDIS_PASSWORD -u REDIS_DB -u REDIS_MAX_RETRIES -u REDIS_DIAL_TIMEOUT -u REDIS_READ_TIMEOUT -u REDIS_WRITE_TIMEOUT -u REDIS_POOL_SIZE -u CACHE_ENABLED -u CACHE_CHAT_LIST_TTL -u CACHE_LOCK_TTL -u CACHE_LOCK_WAIT_TIMEOUT -u SESSION_TTL_SECONDS -u IDEMPOTENCY_TTL_SECONDS -u API_REPLICAS -u API_CPU_LIMIT -u API_MEM_LIMIT go test -race -shuffle=on -count=1 -timeout=5m ./... +? mtusi-messenger/cmd/messenger [no test files] +? mtusi-messenger/cmd/migrate [no test files] +ok mtusi-messenger/internal/config 1.633s +ok mtusi-messenger/internal/domain 1.222s +ok mtusi-messenger/internal/health 1.397s +ok mtusi-messenger/internal/logger 1.803s +ok mtusi-messenger/internal/platform/cache 2.104s +? mtusi-messenger/internal/platform/cache/mocks [no test files] +ok mtusi-messenger/internal/platform/password 2.659s +ok mtusi-messenger/internal/platform/token 2.147s +ok mtusi-messenger/internal/service/chat 2.733s +? mtusi-messenger/internal/service/chat/mocks [no test files] +ok mtusi-messenger/internal/service/message 2.527s +? mtusi-messenger/internal/service/message/mocks [no test files] +ok mtusi-messenger/internal/service/session 3.204s +? mtusi-messenger/internal/service/session/mocks [no test files] +ok mtusi-messenger/internal/service/user 3.505s +? mtusi-messenger/internal/service/user/mocks [no test files] +ok mtusi-messenger/internal/storage/postgres 3.147s +? mtusi-messenger/internal/storage/postgres/internal/sqlcgen [no test files] +? mtusi-messenger/internal/storage/postgres/migrations [no test files] +? mtusi-messenger/internal/storage/redis [no test files] +? mtusi-messenger/internal/storage/redis/mocks [no test files] +ok mtusi-messenger/internal/transport/rest 3.609s +? mtusi-messenger/internal/transport/rest/internal/oas [no test files] +? mtusi-messenger/internal/transport/rest/mocks [no test files] +go test -tags=integration -p 1 -count=1 -timeout=15m ./internal/storage/postgres ./internal/storage/redis +ok mtusi-messenger/internal/storage/postgres 7.210s +ok mtusi-messenger/internal/storage/redis 1.192s diff --git a/evidence/quota-semantics.txt b/evidence/quota-semantics.txt new file mode 100644 index 0000000..f50c0cf --- /dev/null +++ b/evidence/quota-semantics.txt @@ -0,0 +1,33 @@ +# Что означает CPU% в `docker stats` на этом стенде + +Колонка `cpu_percent` в `stats-*.csv` снимается через `docker stats`. Чтобы не +толковать её наугад, поведение проверено прямым экспериментом на том же Docker-host +(Colima, 2 vCPU). + +```sh +docker run -d --name lab3-quota-probe --cpus 0.5 alpine:3.20 sh -c 'while :; do :; done' +sleep 12 +docker stats --no-stream --format '{{.Name}} CPU={{.CPUPerc}}' lab3-quota-probe +docker exec lab3-quota-probe cat /sys/fs/cgroup/cpu.max +``` + +``` +lab3-quota-probe CPU=49.49% MEM=344KiB / 1.913GiB +50000 100000 +``` + +Контейнер упёрт в свою квоту (`cpu.max = 50000 100000` — это 0.5 CPU) и показывает +**49.49 %**. Значит в этом окружении `docker stats` печатает процент от **одного +ядра**: 100 % = 1 ядро, квота 0.5 CPU = ~50 %, квота 0.25 = ~25 %. + +Как это читать в артефактах: + +| сервис | квота | наблюдение в профилях | вывод | +| --- | --- | --- | --- | +| `postgres` | 0.50 | 45-50.5 % | 0.45-0.5 ядра, то есть **у самой квоты** | +| `api` (2 реплики) | 0.50 каждая | ~20 % каждая | 0.2 ядра, квота не выбрана | +| `lb` | 0.25 | 11-14 % | 0.11-0.14 ядра, квота не выбрана | + +Отсюда же следует, что разница между профилем `r2` (PostgreSQL 0.50) и `db1cpu` +(PostgreSQL 1.00) читается корректно: в `db1cpu` загрузка БД падала до ~46 %, то есть +удвоенная квота не была использована — БД не была зажата квотой. diff --git a/evidence/rolling-update/after/load.json b/evidence/rolling-update/after/load.json new file mode 100644 index 0000000..d45df8a --- /dev/null +++ b/evidence/rolling-update/after/load.json @@ -0,0 +1,26 @@ +{ + "lab": 3, + "workload": "closed-loop POST messages; failures counted, not raised", + "requested_duration_seconds": 60.0, + "elapsed_seconds": 60.013, + "concurrency": 8, + "successful_requests": 97359, + "failed_requests": 3, + "error_ratio": 3.1e-05, + "errors_by_kind": { + "http_error": 3 + }, + "successful_rps": 1622.308, + "successful_latency_ms": { + "p50": 4.011, + "p95": 8.688, + "p99": 23.718 + }, + "instances": { + "f00a99f95855": 594, + "8782633d0431": 48162, + "4248067e3f04": 48603 + }, + "bootstrap_attempts": 1, + "note": "Percentiles cover successful writes only; transitional errors are expected during a rolling update." +} diff --git a/evidence/rolling-update/after/load.txt b/evidence/rolling-update/after/load.txt new file mode 100644 index 0000000..d45df8a --- /dev/null +++ b/evidence/rolling-update/after/load.txt @@ -0,0 +1,26 @@ +{ + "lab": 3, + "workload": "closed-loop POST messages; failures counted, not raised", + "requested_duration_seconds": 60.0, + "elapsed_seconds": 60.013, + "concurrency": 8, + "successful_requests": 97359, + "failed_requests": 3, + "error_ratio": 3.1e-05, + "errors_by_kind": { + "http_error": 3 + }, + "successful_rps": 1622.308, + "successful_latency_ms": { + "p50": 4.011, + "p95": 8.688, + "p99": 23.718 + }, + "instances": { + "f00a99f95855": 594, + "8782633d0431": 48162, + "4248067e3f04": 48603 + }, + "bootstrap_attempts": 1, + "note": "Percentiles cover successful writes only; transitional errors are expected during a rolling update." +} diff --git a/evidence/rolling-update/after/rolling-update.txt b/evidence/rolling-update/after/rolling-update.txt new file mode 100644 index 0000000..769e63a --- /dev/null +++ b/evidence/rolling-update/after/rolling-update.txt @@ -0,0 +1,136 @@ +# Rolling update under load (surge, one replica at a time) +# generated: 2026-10-16T14:26:39Z +# load: tolerant loader, duration=60s concurrency=8 +# проверки готовности LB: httpchk /health/ready, inter 2s fall 2 rise 2, timeout check 1s + +time="2026-10-16T17:26:40+03:00" level=warning msg="buildx Docker CLI plugin not found: falling back to the classic builder. BuildKit-only build features (multi-arch, secrets, ssh, additional contexts, ...) will not be available" + Image mtusi-messenger:lab3 Building + Image mtusi-messenger:lab3 Building +Sending build context to Docker daemon 238kB +Step 1/25 : ARG GO_VERSION=1.27.1 +Step 2/25 : ARG ALPINE_VERSION=3.22 +Step 3/25 : FROM golang:${GO_VERSION}-alpine AS build + ---> 8a5910f31396 +Step 4/25 : ARG TARGETOS + ---> Using cache + ---> d5f2c47ea7a5 +Step 5/25 : ARG TARGETARCH + ---> Using cache + ---> 047ee34b445c +Step 6/25 : ARG VERSION=dev + ---> Using cache + ---> a529d045efeb +Step 7/25 : ENV GOTOOLCHAIN=local + ---> Using cache + ---> 428f1b16b5c5 +Step 8/25 : WORKDIR /opt + ---> Using cache + ---> f37febf8b423 +Step 9/25 : COPY go.mod go.sum ./ + ---> Using cache + ---> c4015f597b99 +Step 10/25 : RUN go mod download + ---> Using cache + ---> 34ef6a6167b0 +Step 11/25 : ARG GOFLAGS="-p=2" + ---> Using cache + ---> deb54a0ce57a +Step 12/25 : ENV GOFLAGS=$GOFLAGS + ---> Using cache + ---> 3da36569422d +Step 13/25 : COPY . . + ---> 198f052f6cce +Step 14/25 : RUN CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -trimpath -buildvcs=false -tags timetzdata -ldflags="-s -w -X main.version=${VERSION}" -o /out/messenger ./cmd/messenger && CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -trimpath -buildvcs=false -tags timetzdata -ldflags="-s -w -X main.version=${VERSION}" -o /out/migrate ./cmd/migrate + ---> Running in 658437823eb9 + ---> Removed intermediate container 658437823eb9 + ---> 10a89d0bb592 +Step 15/25 : FROM alpine:${ALPINE_VERSION} AS runtime + ---> 5291449c3df7 +Step 16/25 : RUN apk add --no-cache ca-certificates wget && addgroup -S -g 10001 app && adduser -S -D -H -u 10001 -G app app + ---> Using cache + ---> f47b074d9bd5 +Step 17/25 : COPY --from=build --chown=10001:10001 /out/messenger /usr/local/bin/messenger + ---> Using cache + ---> 703f8f10d2cc +Step 18/25 : COPY --from=build --chown=10001:10001 /out/migrate /usr/local/bin/migrate + ---> Using cache + ---> c9121622dae2 +Step 19/25 : COPY --chown=10001:10001 config/dev/config.yaml /etc/messenger/dev/config.yaml + ---> Using cache + ---> 0379076307ea +Step 20/25 : USER 10001:10001 + ---> Using cache + ---> 2ff943b7d2e0 +Step 21/25 : EXPOSE 8080 + ---> Using cache + ---> 01674ab574a6 +Step 22/25 : STOPSIGNAL SIGTERM + ---> Using cache + ---> 6c30af2a102c +Step 23/25 : HEALTHCHECK --interval=10s --timeout=3s --start-period=5s --retries=3 CMD wget -q -O /dev/null "http://127.0.0.1:${SERVER_PORT:-8080}/health/live" || exit 1 + ---> Using cache + ---> 76379f8db08d +Step 24/25 : ENTRYPOINT ["/usr/local/bin/messenger"] + ---> Using cache + ---> 778babec5020 +Step 25/25 : LABEL com.docker.compose.image.builder=classic + ---> Using cache + ---> 9e7e0224c87c +Successfully built 9e7e0224c87c +Successfully tagged mtusi-messenger:lab3 + Image mtusi-messenger:lab3 Built + Image mtusi-messenger:lab3 Built +реплик до обновления: 2 +образ старых реплик: sha256:9e7e0224c87cee0ccfa05d5799ec8e2a84b836e51fbda6f1dc3d175d5c0d4640 +образ новой ревизии: sha256:9e7e0224c87cee0ccfa05d5799ec8e2a84b836e51fbda6f1dc3d175d5c0d4640 +ревизия меняется: нет (образ не изменился) +слотов UP до: 3; restarts до: mtusi-messenger-lab3-api-1=0 mtusi-messenger-lab3-api-2=0 + + step 1: lb-rollout-1 обслуживает (образ 9e7e0224c87cee0ccfa05d5799ec8e2a84b836e51fbda6f1dc3d175d5c0d4640, instance 8782633d0431), старый контейнер 2ed432da6dd1 (2ed432da6dd1) снят; UP-слотов 3; 5xx накоплено 416; старт шага 2026-10-16T14:27:22Z + step 2: lb-rollout-2 обслуживает (образ 9e7e0224c87cee0ccfa05d5799ec8e2a84b836e51fbda6f1dc3d175d5c0d4640, instance 4248067e3f04), старый контейнер f00a99f95855 (f00a99f95855) снят; UP-слотов 4; 5xx накоплено 419; старт шага 2026-10-16T14:27:22Z + +load summary (tolerant generator): +{ + "lab": 3, + "workload": "closed-loop POST messages; failures counted, not raised", + "requested_duration_seconds": 60.0, + "elapsed_seconds": 60.013, + "concurrency": 8, + "successful_requests": 97359, + "failed_requests": 3, + "error_ratio": 3.1e-05, + "errors_by_kind": { + "http_error": 3 + }, + "successful_rps": 1622.308, + "successful_latency_ms": { + "p50": 4.011, + "p95": 8.688, + "p99": 23.718 + }, + "instances": { + "f00a99f95855": 594, + "8782633d0431": 48162, + "4248067e3f04": 48603 + }, + "bootstrap_attempts": 1, + "note": "Percentiles cover successful writes only; transitional errors are expected during a rolling update." +} + +5xx от LB за время обновления (hrsp_5xx frontend): 3 +restarts после: lb-rollout-2=0 lb-rollout-1=0 + +возврат стенда под управление compose: + Container mtusi-messenger-lab3-api-2 Creating + Container mtusi-messenger-lab3-api-1 Creating + Container mtusi-messenger-lab3-api-1 Created + Container mtusi-messenger-lab3-api-2 Created + Container mtusi-messenger-lab3-api-1 Starting + Container mtusi-messenger-lab3-api-1 Started + Container mtusi-messenger-lab3-api-2 Starting + Container mtusi-messenger-lab3-api-2 Started +снято временных контейнеров наплыва: проверено +UP-слотов после: 3; restarts в конце: mtusi-messenger-lab3-api-1=0 mtusi-messenger-lab3-api-2=0 +API containers после обновления: +mtusi-messenger-lab3-api-1 Up Less than a second (health: starting) +mtusi-messenger-lab3-api-2 Up Less than a second (health: starting) diff --git a/evidence/rolling-update/emulated/load.json b/evidence/rolling-update/emulated/load.json new file mode 100644 index 0000000..e46ce7b --- /dev/null +++ b/evidence/rolling-update/emulated/load.json @@ -0,0 +1,23 @@ +{ + "lab": 3, + "workload": "closed-loop POST messages; failures counted, not raised", + "requested_duration_seconds": 45.0, + "elapsed_seconds": 45.014, + "concurrency": 8, + "successful_requests": 89560, + "failed_requests": 0, + "error_ratio": 0.0, + "errors_by_kind": {}, + "successful_rps": 1989.584, + "successful_latency_ms": { + "p50": 3.905, + "p95": 6.02, + "p99": 7.984 + }, + "instances": { + "388ebcb74200": 7524, + "73d07d7d76db": 45354, + "cc6274635bd6": 36682 + }, + "note": "Percentiles cover successful writes only; transitional errors are expected during a rolling update." +} diff --git a/evidence/rolling-update/emulated/load.txt b/evidence/rolling-update/emulated/load.txt new file mode 100644 index 0000000..e46ce7b --- /dev/null +++ b/evidence/rolling-update/emulated/load.txt @@ -0,0 +1,23 @@ +{ + "lab": 3, + "workload": "closed-loop POST messages; failures counted, not raised", + "requested_duration_seconds": 45.0, + "elapsed_seconds": 45.014, + "concurrency": 8, + "successful_requests": 89560, + "failed_requests": 0, + "error_ratio": 0.0, + "errors_by_kind": {}, + "successful_rps": 1989.584, + "successful_latency_ms": { + "p50": 3.905, + "p95": 6.02, + "p99": 7.984 + }, + "instances": { + "388ebcb74200": 7524, + "73d07d7d76db": 45354, + "cc6274635bd6": 36682 + }, + "note": "Percentiles cover successful writes only; transitional errors are expected during a rolling update." +} diff --git a/evidence/rolling-update/emulated/rolling-update.txt b/evidence/rolling-update/emulated/rolling-update.txt new file mode 100644 index 0000000..c41c89d --- /dev/null +++ b/evidence/rolling-update/emulated/rolling-update.txt @@ -0,0 +1,134 @@ +# Rolling update under load +# generated: 2026-10-15T19:03:13Z +# load: tests/load.py duration=45s concurrency=8 (closed loop) +# steps: delete one replica, recreate it from the freshly built image, wait for health + LB + +time="2026-10-15T22:03:13+03:00" level=warning msg="buildx Docker CLI plugin not found: falling back to the classic builder. BuildKit-only build features (multi-arch, secrets, ssh, additional contexts, ...) will not be available" + Image mtusi-messenger:lab3 Building + Image mtusi-messenger:lab3 Building +Sending build context to Docker daemon 213.7kB +Step 1/25 : ARG GO_VERSION=1.27.1 +Step 2/25 : ARG ALPINE_VERSION=3.22 +Step 3/25 : FROM golang:${GO_VERSION}-alpine AS build + ---> 8a5910f31396 +Step 4/25 : ARG TARGETOS + ---> Using cache + ---> d5f2c47ea7a5 +Step 5/25 : ARG TARGETARCH + ---> Using cache + ---> 047ee34b445c +Step 6/25 : ARG VERSION=dev + ---> Using cache + ---> a529d045efeb +Step 7/25 : ENV GOTOOLCHAIN=local + ---> Using cache + ---> 428f1b16b5c5 +Step 8/25 : WORKDIR /opt + ---> Using cache + ---> f37febf8b423 +Step 9/25 : COPY go.mod go.sum ./ + ---> Using cache + ---> c4015f597b99 +Step 10/25 : RUN go mod download + ---> Using cache + ---> 34ef6a6167b0 +Step 11/25 : ARG GOFLAGS="-p=2" + ---> Using cache + ---> deb54a0ce57a +Step 12/25 : ENV GOFLAGS=$GOFLAGS + ---> Using cache + ---> 3da36569422d +Step 13/25 : COPY . . + ---> Using cache + ---> 596dc1ab02d1 +Step 14/25 : RUN CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -trimpath -buildvcs=false -tags timetzdata -ldflags="-s -w -X main.version=${VERSION}" -o /out/messenger ./cmd/messenger && CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -trimpath -buildvcs=false -tags timetzdata -ldflags="-s -w -X main.version=${VERSION}" -o /out/migrate ./cmd/migrate + ---> Using cache + ---> 01aa8bc6200d +Step 15/25 : FROM alpine:${ALPINE_VERSION} AS runtime + ---> 5291449c3df7 +Step 16/25 : RUN apk add --no-cache ca-certificates wget && addgroup -S -g 10001 app && adduser -S -D -H -u 10001 -G app app + ---> Using cache + ---> f47b074d9bd5 +Step 17/25 : COPY --from=build --chown=10001:10001 /out/messenger /usr/local/bin/messenger + ---> Using cache + ---> 50fc6abe3b04 +Step 18/25 : COPY --from=build --chown=10001:10001 /out/migrate /usr/local/bin/migrate + ---> Using cache + ---> 9bf6afe0256d +Step 19/25 : COPY --chown=10001:10001 config/dev/config.yaml /etc/messenger/dev/config.yaml + ---> Using cache + ---> 0d1870a325ec +Step 20/25 : USER 10001:10001 + ---> Using cache + ---> 1991f2ae06cc +Step 21/25 : EXPOSE 8080 + ---> Using cache + ---> 762d1bfb7606 +Step 22/25 : STOPSIGNAL SIGTERM + ---> Using cache + ---> 8a9d8f4f7101 +Step 23/25 : HEALTHCHECK --interval=10s --timeout=3s --start-period=5s --retries=3 CMD wget -q -O /dev/null "http://127.0.0.1:${SERVER_PORT:-8080}/health/live" || exit 1 + ---> Using cache + ---> 65dea502a3f3 +Step 24/25 : ENTRYPOINT ["/usr/local/bin/messenger"] + ---> Using cache + ---> 83bbee72905e +Step 25/25 : LABEL com.docker.compose.image.builder=classic + ---> Using cache + ---> 037f969d5ea1 +Successfully built 037f969d5ea1 +Successfully tagged mtusi-messenger:lab3 + Image mtusi-messenger:lab3 Built + Image mtusi-messenger:lab3 Built + Container mtusi-messenger-lab3-api-13 Recreate + Container mtusi-messenger-lab3-api-14 Recreate + Container mtusi-messenger-lab3-api-13 Recreated + Container mtusi-messenger-lab3-api-14 Recreated + Container mtusi-messenger-lab3-api-14 Starting + Container mtusi-messenger-lab3-api-14 Started + Container mtusi-messenger-lab3-api-13 Starting + Container mtusi-messenger-lab3-api-13 Started +replicas before: 2; instances seen through LB: 2 + Container mtusi-messenger-lab3-api-13 Running + Container mtusi-messenger-lab3-api-14 Creating + Container mtusi-messenger-lab3-api-14 Created + Container mtusi-messenger-lab3-api-14 Starting + Container mtusi-messenger-lab3-api-14 Started + step 1: removed 54a7e7888b5f at 2026-10-15T19:03:20Z, 2 healthy replicas served again at 2026-10-15T19:03:26Z + Container mtusi-messenger-lab3-api-14 Running + Container mtusi-messenger-lab3-api-15 Creating + Container mtusi-messenger-lab3-api-15 Created + Container mtusi-messenger-lab3-api-15 Starting + Container mtusi-messenger-lab3-api-15 Started + step 2: removed 388ebcb74200 at 2026-10-15T19:03:26Z, 2 healthy replicas served again at 2026-10-15T19:03:31Z + +load summary (tolerant generator): +{ + "lab": 3, + "workload": "closed-loop POST messages; failures counted, not raised", + "requested_duration_seconds": 45.0, + "elapsed_seconds": 45.014, + "concurrency": 8, + "successful_requests": 89560, + "failed_requests": 0, + "error_ratio": 0.0, + "errors_by_kind": {}, + "successful_rps": 1989.584, + "successful_latency_ms": { + "p50": 3.905, + "p95": 6.02, + "p99": 7.984 + }, + "instances": { + "388ebcb74200": 7524, + "73d07d7d76db": 45354, + "cc6274635bd6": 36682 + }, + "note": "Percentiles cover successful writes only; transitional errors are expected during a rolling update." +} + +LB responses with 5xx during the update: 0 + +API containers after the update: +mtusi-messenger-lab3-api-15 Up 41 seconds (healthy) +mtusi-messenger-lab3-api-14 Up 46 seconds (healthy) diff --git a/evidence/smoke.txt b/evidence/smoke.txt new file mode 100644 index 0000000..9ac3434 --- /dev/null +++ b/evidence/smoke.txt @@ -0,0 +1,3 @@ +# make test — 2026-10-16T14:07:37Z (final image) +env -u HTTP_PROXY -u HTTPS_PROXY -u ALL_PROXY -u http_proxy -u https_proxy -u all_proxy NO_PROXY=localhost,127.0.0.1,::1 no_proxy=localhost,127.0.0.1,::1 python3 tests/smoke.py --base-url "http://localhost:8080" +PASS: lab3 public API scenario; infrastructure and grading evidence remain separate. diff --git a/evidence/stand.txt b/evidence/stand.txt new file mode 100644 index 0000000..bc9dd06 --- /dev/null +++ b/evidence/stand.txt @@ -0,0 +1,34 @@ +# Lab3 stand evidence +# generated: 2026-10-16T13:38:19Z + +## docker ps (ports) +mtusi-messenger-lab3-api-6 | 8080/tcp +mtusi-messenger-lab3-api-5 | 8080/tcp +mtusi-messenger-lab3-lb-1 | 127.0.0.1:8404->8404/tcp, 127.0.0.1:8080->80/tcp +mtusi-messenger-lab3-postgres-1 | 5432/tcp +mtusi-messenger-lab3-redis-1 | 6379/tcp + +## compose config: limits/replicas/published + api: + replicas: 2 + cpus: 0.5 + memory: "268435456" + lb: + cpus: 0.25 + memory: "67108864" + published: "8080" + published: "8404" + migrate: + cpus: 0.5 + memory: "268435456" + postgres: + cpus: 0.5 + memory: "402653184" + redis: + cpus: 0.25 + memory: "201326592" + default: + build: + image: mtusi-messenger:lab3 + +container_name: absent diff --git a/evidence/track1/load-ctl1base.json b/evidence/track1/load-ctl1base.json new file mode 100644 index 0000000..8e0050e --- /dev/null +++ b/evidence/track1/load-ctl1base.json @@ -0,0 +1,17 @@ +{ + "lab": 3, + "workload": "closed-loop POST messages; no automatic retries", + "requested_duration_seconds": 60.0, + "elapsed_seconds": 60.082, + "concurrency": 8, + "successful_requests": 83581, + "failed_requests": 0, + "error_ratio": 0.0, + "successful_rps": 1391.108, + "successful_latency_ms": { + "p50": 5.571, + "p95": 9.03, + "p99": 11.692 + }, + "note": "Latency percentiles cover successes only. Timeouts/errors are counted separately; closed-loop has coordinated omission and client overhead." +} diff --git a/evidence/track1/load-ctl2pg.json b/evidence/track1/load-ctl2pg.json new file mode 100644 index 0000000..0d68d98 --- /dev/null +++ b/evidence/track1/load-ctl2pg.json @@ -0,0 +1,17 @@ +{ + "lab": 3, + "workload": "closed-loop POST messages; no automatic retries", + "requested_duration_seconds": 60.0, + "elapsed_seconds": 60.072, + "concurrency": 8, + "successful_requests": 83599, + "failed_requests": 0, + "error_ratio": 0.0, + "successful_rps": 1391.647, + "successful_latency_ms": { + "p50": 5.575, + "p95": 8.994, + "p99": 11.512 + }, + "note": "Latency percentiles cover successes only. Timeouts/errors are counted separately; closed-loop has coordinated omission and client overhead." +} diff --git a/evidence/track1/load-ctl3base.json b/evidence/track1/load-ctl3base.json new file mode 100644 index 0000000..e7ad300 --- /dev/null +++ b/evidence/track1/load-ctl3base.json @@ -0,0 +1,17 @@ +{ + "lab": 3, + "workload": "closed-loop POST messages; no automatic retries", + "requested_duration_seconds": 60.0, + "elapsed_seconds": 60.078, + "concurrency": 8, + "successful_requests": 81711, + "failed_requests": 0, + "error_ratio": 0.0, + "successful_rps": 1360.087, + "successful_latency_ms": { + "p50": 5.664, + "p95": 9.482, + "p99": 12.322 + }, + "note": "Latency percentiles cover successes only. Timeouts/errors are counted separately; closed-loop has coordinated omission and client overhead." +} diff --git a/evidence/track1/load-ctl4lb.json b/evidence/track1/load-ctl4lb.json new file mode 100644 index 0000000..ed60447 --- /dev/null +++ b/evidence/track1/load-ctl4lb.json @@ -0,0 +1,17 @@ +{ + "lab": 3, + "workload": "closed-loop POST messages; no automatic retries", + "requested_duration_seconds": 60.0, + "elapsed_seconds": 60.074, + "concurrency": 8, + "successful_requests": 81688, + "failed_requests": 0, + "error_ratio": 0.0, + "successful_rps": 1359.794, + "successful_latency_ms": { + "p50": 5.688, + "p95": 9.37, + "p99": 12.032 + }, + "note": "Latency percentiles cover successes only. Timeouts/errors are counted separately; closed-loop has coordinated omission and client overhead." +} diff --git a/evidence/track1/load-d2.json b/evidence/track1/load-d2.json new file mode 100644 index 0000000..9590a53 --- /dev/null +++ b/evidence/track1/load-d2.json @@ -0,0 +1,17 @@ +{ + "lab": 3, + "workload": "closed-loop POST messages; no automatic retries", + "requested_duration_seconds": 60.0, + "elapsed_seconds": 60.068, + "concurrency": 8, + "successful_requests": 83445, + "failed_requests": 0, + "error_ratio": 0.0, + "successful_rps": 1389.179, + "successful_latency_ms": { + "p50": 5.585, + "p95": 9.054, + "p99": 11.711 + }, + "note": "Latency percentiles cover successes only. Timeouts/errors are counted separately; closed-loop has coordinated omission and client overhead." +} diff --git a/evidence/track1/load-db1cpu.json b/evidence/track1/load-db1cpu.json new file mode 100644 index 0000000..f9ae714 --- /dev/null +++ b/evidence/track1/load-db1cpu.json @@ -0,0 +1,17 @@ +{ + "lab": 3, + "workload": "closed-loop POST messages; no automatic retries", + "requested_duration_seconds": 60.0, + "elapsed_seconds": 60.077, + "concurrency": 8, + "successful_requests": 76301, + "failed_requests": 0, + "error_ratio": 0.0, + "successful_rps": 1270.045, + "successful_latency_ms": { + "p50": 6.057, + "p95": 10.141, + "p99": 13.724 + }, + "note": "Latency percentiles cover successes only. Timeouts/errors are counted separately; closed-loop has coordinated omission and client overhead." +} diff --git a/evidence/track1/load-g05.json b/evidence/track1/load-g05.json new file mode 100644 index 0000000..413da3b --- /dev/null +++ b/evidence/track1/load-g05.json @@ -0,0 +1,17 @@ +{ + "lab": 3, + "workload": "closed-loop POST messages; no automatic retries", + "requested_duration_seconds": 60.0, + "elapsed_seconds": 60.064, + "concurrency": 8, + "successful_requests": 89486, + "failed_requests": 0, + "error_ratio": 0.0, + "successful_rps": 1489.856, + "successful_latency_ms": { + "p50": 5.238, + "p95": 8.245, + "p99": 10.54 + }, + "note": "Latency percentiles cover successes only. Timeouts/errors are counted separately; closed-loop has coordinated omission and client overhead." +} diff --git a/evidence/track1/load-g10.json b/evidence/track1/load-g10.json new file mode 100644 index 0000000..69f2ef2 --- /dev/null +++ b/evidence/track1/load-g10.json @@ -0,0 +1,17 @@ +{ + "lab": 3, + "workload": "closed-loop POST messages; no automatic retries", + "requested_duration_seconds": 60.0, + "elapsed_seconds": 60.071, + "concurrency": 8, + "successful_requests": 89886, + "failed_requests": 0, + "error_ratio": 0.0, + "successful_rps": 1496.325, + "successful_latency_ms": { + "p50": 5.207, + "p95": 8.221, + "p99": 10.508 + }, + "note": "Latency percentiles cover successes only. Timeouts/errors are counted separately; closed-loop has coordinated omission and client overhead." +} diff --git a/evidence/track1/load-g15.json b/evidence/track1/load-g15.json new file mode 100644 index 0000000..d172671 --- /dev/null +++ b/evidence/track1/load-g15.json @@ -0,0 +1,17 @@ +{ + "lab": 3, + "workload": "closed-loop POST messages; no automatic retries", + "requested_duration_seconds": 60.0, + "elapsed_seconds": 60.061, + "concurrency": 8, + "successful_requests": 89566, + "failed_requests": 0, + "error_ratio": 0.0, + "successful_rps": 1491.252, + "successful_latency_ms": { + "p50": 5.251, + "p95": 8.176, + "p99": 10.209 + }, + "note": "Latency percentiles cover successes only. Timeouts/errors are counted separately; closed-loop has coordinated omission and client overhead." +} diff --git a/evidence/track1/load-lb1cpu.json b/evidence/track1/load-lb1cpu.json new file mode 100644 index 0000000..91e3616 --- /dev/null +++ b/evidence/track1/load-lb1cpu.json @@ -0,0 +1,17 @@ +{ + "lab": 3, + "workload": "closed-loop POST messages; no automatic retries", + "requested_duration_seconds": 60.0, + "elapsed_seconds": 60.071, + "concurrency": 8, + "successful_requests": 82138, + "failed_requests": 0, + "error_ratio": 0.0, + "successful_rps": 1367.357, + "successful_latency_ms": { + "p50": 5.67, + "p95": 9.26, + "p99": 12.055 + }, + "note": "Latency percentiles cover successes only. Timeouts/errors are counted separately; closed-loop has coordinated omission and client overhead." +} diff --git a/evidence/track1/load-pool10.json b/evidence/track1/load-pool10.json new file mode 100644 index 0000000..46d7de0 --- /dev/null +++ b/evidence/track1/load-pool10.json @@ -0,0 +1,17 @@ +{ + "lab": 3, + "workload": "closed-loop POST messages; no automatic retries", + "requested_duration_seconds": 60.0, + "elapsed_seconds": 60.074, + "concurrency": 8, + "successful_requests": 84040, + "failed_requests": 4, + "error_ratio": 4.8e-05, + "successful_rps": 1398.951, + "successful_latency_ms": { + "p50": 5.556, + "p95": 8.741, + "p99": 11.048 + }, + "note": "Latency percentiles cover successes only. Timeouts/errors are counted separately; closed-loop has coordinated omission and client overhead." +} diff --git a/evidence/track1/load-pool5.json b/evidence/track1/load-pool5.json new file mode 100644 index 0000000..03dfbc9 --- /dev/null +++ b/evidence/track1/load-pool5.json @@ -0,0 +1,17 @@ +{ + "lab": 3, + "workload": "closed-loop POST messages; no automatic retries", + "requested_duration_seconds": 60.0, + "elapsed_seconds": 60.078, + "concurrency": 8, + "successful_requests": 78078, + "failed_requests": 4, + "error_ratio": 5.1e-05, + "successful_rps": 1299.617, + "successful_latency_ms": { + "p50": 5.957, + "p95": 9.594, + "p99": 12.386 + }, + "note": "Latency percentiles cover successes only. Timeouts/errors are counted separately; closed-loop has coordinated omission and client overhead." +} diff --git a/evidence/track1/load-r1.json b/evidence/track1/load-r1.json new file mode 100644 index 0000000..48015e6 --- /dev/null +++ b/evidence/track1/load-r1.json @@ -0,0 +1,17 @@ +{ + "lab": 3, + "workload": "closed-loop POST messages; no automatic retries", + "requested_duration_seconds": 60.0, + "elapsed_seconds": 60.075, + "concurrency": 8, + "successful_requests": 92690, + "failed_requests": 0, + "error_ratio": 0.0, + "successful_rps": 1542.892, + "successful_latency_ms": { + "p50": 5.047, + "p95": 8.006, + "p99": 10.239 + }, + "note": "Latency percentiles cover successes only. Timeouts/errors are counted separately; closed-loop has coordinated omission and client overhead." +} diff --git a/evidence/track1/load-r2.json b/evidence/track1/load-r2.json new file mode 100644 index 0000000..ee84407 --- /dev/null +++ b/evidence/track1/load-r2.json @@ -0,0 +1,17 @@ +{ + "lab": 3, + "workload": "closed-loop POST messages; no automatic retries", + "requested_duration_seconds": 60.0, + "elapsed_seconds": 60.073, + "concurrency": 8, + "successful_requests": 89588, + "failed_requests": 0, + "error_ratio": 0.0, + "successful_rps": 1491.325, + "successful_latency_ms": { + "p50": 5.245, + "p95": 8.225, + "p99": 10.303 + }, + "note": "Latency percentiles cover successes only. Timeouts/errors are counted separately; closed-loop has coordinated omission and client overhead." +} diff --git a/evidence/track1/load-r4.json b/evidence/track1/load-r4.json new file mode 100644 index 0000000..89fd5bb --- /dev/null +++ b/evidence/track1/load-r4.json @@ -0,0 +1,17 @@ +{ + "lab": 3, + "workload": "closed-loop POST messages; no automatic retries", + "requested_duration_seconds": 60.0, + "elapsed_seconds": 60.069, + "concurrency": 8, + "successful_requests": 85041, + "failed_requests": 0, + "error_ratio": 0.0, + "successful_rps": 1415.713, + "successful_latency_ms": { + "p50": 5.538, + "p95": 8.614, + "p99": 10.749 + }, + "note": "Latency percentiles cover successes only. Timeouts/errors are counted separately; closed-loop has coordinated omission and client overhead." +} diff --git a/evidence/track1/profile-ctl1base.json b/evidence/track1/profile-ctl1base.json new file mode 100644 index 0000000..05ce1e9 --- /dev/null +++ b/evidence/track1/profile-ctl1base.json @@ -0,0 +1 @@ +{"label":"ctl1base","replicas":2,"total_cpu":1.0,"total_mem_mb":768,"duration":60,"concurrency":8,"warmup":15,"postgres_cpu_limit":"0.50","postgres_mem_limit":"384M","postgres_max_conns":10,"lb_cpu_limit":"0.25","client":"vm"} diff --git a/evidence/track1/profile-ctl2pg.json b/evidence/track1/profile-ctl2pg.json new file mode 100644 index 0000000..6a812b6 --- /dev/null +++ b/evidence/track1/profile-ctl2pg.json @@ -0,0 +1 @@ +{"label":"ctl2pg","replicas":2,"total_cpu":1.0,"total_mem_mb":768,"duration":60,"concurrency":8,"warmup":15,"postgres_cpu_limit":"1.00","postgres_mem_limit":"384M","postgres_max_conns":10,"lb_cpu_limit":"0.25","client":"vm"} diff --git a/evidence/track1/profile-ctl3base.json b/evidence/track1/profile-ctl3base.json new file mode 100644 index 0000000..4f65cdc --- /dev/null +++ b/evidence/track1/profile-ctl3base.json @@ -0,0 +1 @@ +{"label":"ctl3base","replicas":2,"total_cpu":1.0,"total_mem_mb":768,"duration":60,"concurrency":8,"warmup":15,"postgres_cpu_limit":"0.50","postgres_mem_limit":"384M","postgres_max_conns":10,"lb_cpu_limit":"0.25","client":"vm"} diff --git a/evidence/track1/profile-ctl4lb.json b/evidence/track1/profile-ctl4lb.json new file mode 100644 index 0000000..44e58b8 --- /dev/null +++ b/evidence/track1/profile-ctl4lb.json @@ -0,0 +1 @@ +{"label":"ctl4lb","replicas":2,"total_cpu":1.0,"total_mem_mb":768,"duration":60,"concurrency":8,"warmup":15,"postgres_cpu_limit":"0.50","postgres_mem_limit":"384M","postgres_max_conns":10,"lb_cpu_limit":"1.00","client":"vm"} diff --git a/evidence/track1/profile-d2.json b/evidence/track1/profile-d2.json new file mode 100644 index 0000000..03c21fd --- /dev/null +++ b/evidence/track1/profile-d2.json @@ -0,0 +1 @@ +{"label":"d2","replicas":2,"total_cpu":1.0,"total_mem_mb":768,"duration":60,"concurrency":8,"warmup":15,"postgres_cpu_limit":"0.50","postgres_mem_limit":"384M","postgres_max_conns":10,"lb_cpu_limit":"0.25","client":"vm"} diff --git a/evidence/track1/profile-db1cpu.json b/evidence/track1/profile-db1cpu.json new file mode 100644 index 0000000..e6b0cfd --- /dev/null +++ b/evidence/track1/profile-db1cpu.json @@ -0,0 +1 @@ +{"label":"db1cpu","replicas":2,"total_cpu":1.0,"total_mem_mb":768,"duration":60,"concurrency":8,"warmup":15,"postgres_cpu_limit":"1.00","postgres_mem_limit":"384M","postgres_max_conns":10,"lb_cpu_limit":"0.25","client":"vm"} diff --git a/evidence/track1/profile-g05.json b/evidence/track1/profile-g05.json new file mode 100644 index 0000000..e44efa9 --- /dev/null +++ b/evidence/track1/profile-g05.json @@ -0,0 +1 @@ +{"label":"g05","replicas":2,"total_cpu":0.5,"total_mem_mb":768,"duration":60,"concurrency":8,"warmup":15,"postgres_cpu_limit":"0.50","postgres_mem_limit":"384M","postgres_max_conns":10,"lb_cpu_limit":"0.25","client":"vm"} diff --git a/evidence/track1/profile-g10.json b/evidence/track1/profile-g10.json new file mode 100644 index 0000000..168f6b8 --- /dev/null +++ b/evidence/track1/profile-g10.json @@ -0,0 +1 @@ +{"label":"g10","replicas":2,"total_cpu":1.0,"total_mem_mb":768,"duration":60,"concurrency":8,"warmup":15,"postgres_cpu_limit":"0.50","postgres_mem_limit":"384M","postgres_max_conns":10,"lb_cpu_limit":"0.25","client":"vm"} diff --git a/evidence/track1/profile-g15.json b/evidence/track1/profile-g15.json new file mode 100644 index 0000000..886a5b3 --- /dev/null +++ b/evidence/track1/profile-g15.json @@ -0,0 +1 @@ +{"label":"g15","replicas":2,"total_cpu":1.5,"total_mem_mb":768,"duration":60,"concurrency":8,"warmup":15,"postgres_cpu_limit":"0.50","postgres_mem_limit":"384M","postgres_max_conns":10,"lb_cpu_limit":"0.25","client":"vm"} diff --git a/evidence/track1/profile-lb1cpu.json b/evidence/track1/profile-lb1cpu.json new file mode 100644 index 0000000..6ade280 --- /dev/null +++ b/evidence/track1/profile-lb1cpu.json @@ -0,0 +1 @@ +{"label":"lb1cpu","replicas":2,"total_cpu":1.0,"total_mem_mb":768,"duration":60,"concurrency":8,"warmup":15,"postgres_cpu_limit":"0.50","postgres_mem_limit":"384M","postgres_max_conns":10,"lb_cpu_limit":"1.00","client":"vm"} diff --git a/evidence/track1/profile-pool10.json b/evidence/track1/profile-pool10.json new file mode 100644 index 0000000..02414d3 --- /dev/null +++ b/evidence/track1/profile-pool10.json @@ -0,0 +1 @@ +{"label":"pool10","replicas":4,"total_cpu":1.0,"total_mem_mb":768,"duration":60,"concurrency":8,"warmup":15,"postgres_cpu_limit":"0.50","postgres_mem_limit":"384M","postgres_max_conns":10,"lb_cpu_limit":"0.25","client":"vm"} diff --git a/evidence/track1/profile-pool5.json b/evidence/track1/profile-pool5.json new file mode 100644 index 0000000..42c7878 --- /dev/null +++ b/evidence/track1/profile-pool5.json @@ -0,0 +1 @@ +{"label":"pool5","replicas":4,"total_cpu":1.0,"total_mem_mb":768,"duration":60,"concurrency":8,"warmup":15,"postgres_cpu_limit":"0.50","postgres_mem_limit":"384M","postgres_max_conns":5,"lb_cpu_limit":"0.25","client":"vm"} diff --git a/evidence/track1/profile-r1.json b/evidence/track1/profile-r1.json new file mode 100644 index 0000000..7962183 --- /dev/null +++ b/evidence/track1/profile-r1.json @@ -0,0 +1 @@ +{"label":"r1","replicas":1,"total_cpu":1.0,"total_mem_mb":768,"duration":60,"concurrency":8,"warmup":15,"postgres_cpu_limit":"0.50","postgres_mem_limit":"384M","postgres_max_conns":10,"lb_cpu_limit":"0.25","client":"vm"} diff --git a/evidence/track1/profile-r2.json b/evidence/track1/profile-r2.json new file mode 100644 index 0000000..ef37047 --- /dev/null +++ b/evidence/track1/profile-r2.json @@ -0,0 +1 @@ +{"label":"r2","replicas":2,"total_cpu":1.0,"total_mem_mb":768,"duration":60,"concurrency":8,"warmup":15,"postgres_cpu_limit":"0.50","postgres_mem_limit":"384M","postgres_max_conns":10,"lb_cpu_limit":"0.25","client":"vm"} diff --git a/evidence/track1/profile-r4.json b/evidence/track1/profile-r4.json new file mode 100644 index 0000000..e37896b --- /dev/null +++ b/evidence/track1/profile-r4.json @@ -0,0 +1 @@ +{"label":"r4","replicas":4,"total_cpu":1.0,"total_mem_mb":768,"duration":60,"concurrency":8,"warmup":15,"postgres_cpu_limit":"0.50","postgres_mem_limit":"384M","postgres_max_conns":10,"lb_cpu_limit":"0.25","client":"vm"} diff --git a/evidence/track1/scaling-fixed-budget.png b/evidence/track1/scaling-fixed-budget.png new file mode 100644 index 0000000000000000000000000000000000000000..ba60ea563f4e1db00e30282daf1f827342958396 GIT binary patch literal 55891 zcmdSBWl)t{9|uY+2q+=aNNhT!rIipi-Q8@ul#m7i1(e=&OG-B=ts=2WY1v43ch_B< z^SA9ky5W3y{L!Ggr@kBwHY=cU_)bvc>n!cy2 zp+j+RPr@f`j{5$>jL&Y%>5RV4bgq6`{agL(QmqpA3cCz*Yv+XiB+>e z3IFd8BFNEorT=rmMoGWZ{rAf4L?QX_C&>7*D*yX|?n3T&GXMR=t4LIKIyxSxPK9wt zgX`)ea&o)10#$Ni0)lM+wxHnP+;PNhukd7|CM_-Pw}4x5PUGgV_RxomEB$GRQS)K< z^8-s!-?L{%nepGhzcBpv`sH;w7A9s#!|d_q#GBKdX-!880)nAX)4S(Y{DkpPR8;hL zt*wS;xgpsXl`N}A;qZ)x2BB1b`w&!gthwLWQX4}RCK7zkGlq@|rTuAwxo@|T-7&Q2 zIFDK1gMXimTfCD+y?82&dE)G~$_<5%ou$0@FOKc|GDLK){jCsi%*Slnnz!QO-bc&> ztEKvNILp0BT{YH&>UCvc%uvgMAsarZzW@P&8mo}&3a?$w_a?HmyO*{O-{;KnnOcOs?0l% z#8<~kbh@)7BpN+-qbz$9^X+^-hK0d{{+SQ&S^vwj9?hW{S41j5+f1upNr**5L&J}e z5u*9|dAqbLg0HqCjDL_w@^53X4VY&!tZr+%NryvWe6~B5-ptZ6Va}raP&S%6(qXcC zzNDg6a-!TQme+cK*unkcWHl=w$8oBj^(pV`xfgj)m{c-5A6Q$|_{0#m8be56Y~bcmH6y_nwD` z2YPDT$@PbKD1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8m}?d@5AdB#j4bHl8}I?0blEU(P^TseO3HiPW7pdc-@bht zlZ}6PGX7K$Ue7q&xb-K`sb{9I;)O6-?H!xS^KW#0#m)nQl;wIc%XE|oWWlQRVB_uZ z_}@VsBW@)RPatieZbk6#G!?23`=n!Uw7=|7{_NSoLlUlKs18ZLTb;(;s&-*xsj`& zYi2i459Gke5lYrW_95nUwozm_8*@Qr#&cxkasO0);5=Kqh+xH4%vk$Zg?w7JD5FEV z@$u@W!8RuG^dTEif!Zhg(v&Yifx+BCne* zuv6!NwztSz^>WtWr=#mL?bTh8{A9OOj_GDkT5XTtDLiIb8llE(#-9R-x- z0+agvwBmh&G@l!R)1DJ_C73;!IY0@TEtcibK-`v%AMluQj@=Oa3B<`clwwTk6pyO_ z&a5$ZQ-DjD-Dvx^%~Vs)1O@bSrU~am_Wd-EwU{eiYv<*^DUfx&Y2xFg&c_*cA3CAB zb>D~eE^O^fC?xjqj{`zm&3Y;GDfAxilx6Ca2L&|sxMN@}@IwOAUxy1dx^wIZ()*8V zhL%(R`=<8+>Hk}7o#6ggb^SMl;s0;V_V0@Sr{?{CZM^@#i@<*utikU||2Zddwjt~a RycGzdAgg*O{nq2x{|~E9w#NVf literal 0 HcmV?d00001 diff --git a/evidence/track1/scaling-growth.png b/evidence/track1/scaling-growth.png new file mode 100644 index 0000000000000000000000000000000000000000..95891c0e4f457db93ef1f5c40786a4cc35511d97 GIT binary patch literal 63171 zcmdqJWmJ{X_ce;Bl!T;$gmiaFi_+bl5=wVBsC0LCH_{y{Ez;fH%>fQ^_wo1tz4zV^ z?-=iw`{kZ796FAi=XuWFYp*reoO2PZASaH7LVyAX2ZtspA)*8a_pAyI?#T)g0(hq` zF)kDQ#p@`l;izn5>gZx8-Pgy@Q#JH9He4D-#>T+b@oewhp|^ z%vS&FCzx#PKQsG=AAyU&A=^r5I>5nUIl}%tSu!PYg@e0dmJ|_IaZNi|M0AZ+eT8`9 z1Icn!6vH=(Z{rTKG%k9JR0GMV5qU2fo$re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JihFRABAoK?%3~WnYrGF1%sO-4=;&*Mvk^)1S6xF{my}wyTwv$Lk`!C(;Ds${A|V3j|j@Xiw=#m2pjr zM*@VI@3gH<1ps`QOo|Mn5ghFWLY6WLs|Cple 1.00/384M, пересоздаю контейнер === +=== applied label=db1cpu replicas=2 postgres=1.00/384M lb_cpu=0.25 (снято с контейнеров) +{ + "lab": 3, + "workload": "closed-loop POST messages; no automatic retries", + "requested_duration_seconds": 60.0, + "elapsed_seconds": 60.077, + "concurrency": 8, + "successful_requests": 76301, + "failed_requests": 0, + "error_ratio": 0.0, + "successful_rps": 1270.045, + "successful_latency_ms": { + "p50": 6.057, + "p95": 10.141, + "p99": 13.724 + }, + "note": "Latency percentiles cover successes only. Timeouts/errors are counted separately; closed-loop has coordinated omission and client overhead." +} +postgres_connections=19 +postgres_max_connections=100 +messages_rows=4463395 +idempotency_rows=4463395 + +=== возвращаю PostgreSQL к бюджету 0.50/384M === +=== invocation 2026-10-16T18:35:53Z: REPLICAS="2" TOTAL_CPU=1.0 TOTAL_MEM_MB=768 DURATION=60 CONCURRENCY=8 WARMUP=15 === + +=== profile label=lb1cpu replicas=2 cpu=0.50 mem=384M postgres=0.50/384M lb_cpu=1.00 max_conns=10 client=vm === +=== LB: бюджет CPU 0.25 -> 1.00, пересоздаю контейнер === +=== applied label=lb1cpu replicas=2 postgres=0.50/384M lb_cpu=1.00 (снято с контейнеров) +{ + "lab": 3, + "workload": "closed-loop POST messages; no automatic retries", + "requested_duration_seconds": 60.0, + "elapsed_seconds": 60.071, + "concurrency": 8, + "successful_requests": 82138, + "failed_requests": 0, + "error_ratio": 0.0, + "successful_rps": 1367.357, + "successful_latency_ms": { + "p50": 5.67, + "p95": 9.26, + "p99": 12.055 + }, + "note": "Latency percentiles cover successes only. Timeouts/errors are counted separately; closed-loop has coordinated omission and client overhead." +} +postgres_connections=19 +postgres_max_connections=100 +messages_rows=4566754 +idempotency_rows=4566754 + +=== возвращаю LB к бюджету CPU 0.25 === +=== invocation 2026-10-16T18:37:30Z: REPLICAS="2" TOTAL_CPU=1.0 TOTAL_MEM_MB=768 DURATION=60 CONCURRENCY=8 WARMUP=15 === + +=== profile label=d2 replicas=2 cpu=0.50 mem=384M postgres=0.50/384M lb_cpu=0.25 max_conns=10 client=vm === +=== applied label=d2 replicas=2 postgres=0.50/384M lb_cpu=0.25 (снято с контейнеров) +{ + "lab": 3, + "workload": "closed-loop POST messages; no automatic retries", + "requested_duration_seconds": 60.0, + "elapsed_seconds": 60.068, + "concurrency": 8, + "successful_requests": 83445, + "failed_requests": 0, + "error_ratio": 0.0, + "successful_rps": 1389.179, + "successful_latency_ms": { + "p50": 5.585, + "p95": 9.054, + "p99": 11.711 + }, + "note": "Latency percentiles cover successes only. Timeouts/errors are counted separately; closed-loop has coordinated omission and client overhead." +} +postgres_connections=19 +postgres_max_connections=100 +messages_rows=4671368 +idempotency_rows=4671368 + +=== invocation 2026-10-16T18:38:55Z: REPLICAS="2" TOTAL_CPU=1.0 TOTAL_MEM_MB=768 DURATION=60 CONCURRENCY=8 WARMUP=15 === + +=== profile label=ctl1base replicas=2 cpu=0.50 mem=384M postgres=0.50/384M lb_cpu=0.25 max_conns=10 client=vm === +=== applied label=ctl1base replicas=2 postgres=0.50/384M lb_cpu=0.25 (снято с контейнеров) +{ + "lab": 3, + "workload": "closed-loop POST messages; no automatic retries", + "requested_duration_seconds": 60.0, + "elapsed_seconds": 60.082, + "concurrency": 8, + "successful_requests": 83581, + "failed_requests": 0, + "error_ratio": 0.0, + "successful_rps": 1391.108, + "successful_latency_ms": { + "p50": 5.571, + "p95": 9.03, + "p99": 11.692 + }, + "note": "Latency percentiles cover successes only. Timeouts/errors are counted separately; closed-loop has coordinated omission and client overhead." +} +postgres_connections=19 +postgres_max_connections=100 +messages_rows=4776213 +idempotency_rows=4776213 + +=== invocation 2026-10-16T18:40:14Z: REPLICAS="2" TOTAL_CPU=1.0 TOTAL_MEM_MB=768 DURATION=60 CONCURRENCY=8 WARMUP=15 === + +=== profile label=ctl2pg replicas=2 cpu=0.50 mem=384M postgres=1.00/384M lb_cpu=0.25 max_conns=10 client=vm === +=== PostgreSQL: бюджет 0.50/384M -> 1.00/384M, пересоздаю контейнер === +=== applied label=ctl2pg replicas=2 postgres=1.00/384M lb_cpu=0.25 (снято с контейнеров) +{ + "lab": 3, + "workload": "closed-loop POST messages; no automatic retries", + "requested_duration_seconds": 60.0, + "elapsed_seconds": 60.072, + "concurrency": 8, + "successful_requests": 83599, + "failed_requests": 0, + "error_ratio": 0.0, + "successful_rps": 1391.647, + "successful_latency_ms": { + "p50": 5.575, + "p95": 8.994, + "p99": 11.512 + }, + "note": "Latency percentiles cover successes only. Timeouts/errors are counted separately; closed-loop has coordinated omission and client overhead." +} +postgres_connections=19 +postgres_max_connections=100 +messages_rows=4881024 +idempotency_rows=4881024 + +=== возвращаю PostgreSQL к бюджету 0.50/384M === +=== invocation 2026-10-16T18:41:33Z: REPLICAS="2" TOTAL_CPU=1.0 TOTAL_MEM_MB=768 DURATION=60 CONCURRENCY=8 WARMUP=15 === + +=== profile label=ctl3base replicas=2 cpu=0.50 mem=384M postgres=0.50/384M lb_cpu=0.25 max_conns=10 client=vm === +=== applied label=ctl3base replicas=2 postgres=0.50/384M lb_cpu=0.25 (снято с контейнеров) +{ + "lab": 3, + "workload": "closed-loop POST messages; no automatic retries", + "requested_duration_seconds": 60.0, + "elapsed_seconds": 60.078, + "concurrency": 8, + "successful_requests": 81711, + "failed_requests": 0, + "error_ratio": 0.0, + "successful_rps": 1360.087, + "successful_latency_ms": { + "p50": 5.664, + "p95": 9.482, + "p99": 12.322 + }, + "note": "Latency percentiles cover successes only. Timeouts/errors are counted separately; closed-loop has coordinated omission and client overhead." +} +postgres_connections=19 +postgres_max_connections=100 +messages_rows=4983558 +idempotency_rows=4983558 + +=== invocation 2026-10-16T18:42:51Z: REPLICAS="2" TOTAL_CPU=1.0 TOTAL_MEM_MB=768 DURATION=60 CONCURRENCY=8 WARMUP=15 === + +=== profile label=ctl4lb replicas=2 cpu=0.50 mem=384M postgres=0.50/384M lb_cpu=1.00 max_conns=10 client=vm === +=== LB: бюджет CPU 0.25 -> 1.00, пересоздаю контейнер === +=== applied label=ctl4lb replicas=2 postgres=0.50/384M lb_cpu=1.00 (снято с контейнеров) +{ + "lab": 3, + "workload": "closed-loop POST messages; no automatic retries", + "requested_duration_seconds": 60.0, + "elapsed_seconds": 60.074, + "concurrency": 8, + "successful_requests": 81688, + "failed_requests": 0, + "error_ratio": 0.0, + "successful_rps": 1359.794, + "successful_latency_ms": { + "p50": 5.688, + "p95": 9.37, + "p99": 12.032 + }, + "note": "Latency percentiles cover successes only. Timeouts/errors are counted separately; closed-loop has coordinated omission and client overhead." +} +postgres_connections=19 +postgres_max_connections=100 +messages_rows=5086444 +idempotency_rows=5086444 + +=== возвращаю LB к бюджету CPU 0.25 === diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..9bb1245 --- /dev/null +++ b/go.mod @@ -0,0 +1,155 @@ +module mtusi-messenger + +go 1.27.0 + +require ( + github.com/aws/aws-sdk-go-v2 v1.47.3 + github.com/aws/aws-sdk-go-v2/credentials v1.20.9 + github.com/aws/aws-sdk-go-v2/service/s3 v1.114.4 + github.com/aws/smithy-go v1.28.6 + github.com/exaring/otelpgx v0.13.0 + github.com/gen2brain/webp v0.6.4 + github.com/go-faster/errors v0.8.0 + github.com/go-faster/jx v1.2.0 + github.com/go-playground/validator/v10 v10.30.5 + github.com/google/uuid v1.6.0 + github.com/jackc/pgx/v5 v5.11.0 + github.com/ogen-go/ogen v1.24.0 + github.com/pressly/goose/v3 v3.28.0 + github.com/rabbitmq/amqp091-go v1.16.0 + github.com/redis/go-redis/v9 v9.22.0 + github.com/spf13/viper v1.21.0 + github.com/stretchr/testify v1.12.1 + go.opentelemetry.io/contrib/bridges/otelslog v0.21.0 + go.opentelemetry.io/otel v1.47.0 + go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploghttp v0.23.0 + go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp v1.47.0 + go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.47.0 + go.opentelemetry.io/otel/metric v1.47.0 + go.opentelemetry.io/otel/sdk v1.47.0 + go.opentelemetry.io/otel/sdk/log v1.47.0 + go.opentelemetry.io/otel/sdk/metric v1.47.0 + go.opentelemetry.io/otel/trace v1.47.0 + go.uber.org/zap v1.28.0 + go.uber.org/zap/exp v0.3.0 + golang.org/x/crypto v0.57.0 + golang.org/x/image v0.47.0 + golang.org/x/sync v0.24.0 +) + +require ( + cel.dev/expr v0.25.2 // indirect + filippo.io/edwards25519 v1.2.0 // indirect + github.com/antlr4-go/antlr/v4 v4.13.1 // indirect + github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.7.23 // indirect + github.com/aws/aws-sdk-go-v2/internal/configsources v1.5.6 // indirect + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.8.6 // indirect + github.com/aws/aws-sdk-go-v2/internal/v4a v1.5.6 // indirect + github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.13.21 // indirect + github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.11.7 // indirect + github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.14.6 // indirect + github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.20.6 // indirect + github.com/brunoga/deep v1.3.1 // indirect + github.com/cenkalti/backoff/v5 v5.0.3 // indirect + github.com/cespare/xxhash/v2 v2.3.0 // indirect + github.com/clipperhouse/uax29/v2 v2.2.0 // indirect + github.com/coreos/go-semver v0.3.1 // indirect + github.com/cubicdaiya/gonp v1.0.4 // indirect + github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect + github.com/dlclark/regexp2 v1.12.0 // indirect + github.com/ebitengine/purego v0.10.1 // indirect + github.com/fatih/color v1.19.0 // indirect + github.com/fatih/structs v1.1.0 // indirect + github.com/fatih/structtag v1.2.0 // indirect + github.com/fsnotify/fsnotify v1.9.0 // indirect + github.com/gabriel-vasile/mimetype v1.4.15 // indirect + github.com/ghodss/yaml v1.0.0 // indirect + github.com/go-faster/yaml v0.4.6 // indirect + github.com/go-logr/logr v1.4.4 // indirect + github.com/go-logr/stdr v1.2.2 // indirect + github.com/go-playground/locales v0.14.1 // indirect + github.com/go-playground/universal-translator v0.18.1 // indirect + github.com/go-sql-driver/mysql v1.10.0 // indirect + github.com/go-viper/mapstructure/v2 v2.5.0 // indirect + github.com/google/cel-go v0.28.0 // indirect + github.com/grpc-ecosystem/grpc-gateway/v2 v2.30.0 // indirect + github.com/huandu/xstrings v1.5.0 // 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/puddle/v2 v2.2.2 // indirect + github.com/jedib0t/go-pretty/v6 v6.7.8 // indirect + github.com/jinzhu/inflection v1.0.0 // indirect + github.com/knadh/koanf/maps v0.1.2 // indirect + github.com/knadh/koanf/parsers/yaml v1.1.0 // indirect + github.com/knadh/koanf/providers/env v1.1.0 // indirect + github.com/knadh/koanf/providers/file v1.2.1 // indirect + github.com/knadh/koanf/providers/posflag v1.0.1 // indirect + github.com/knadh/koanf/providers/structs v1.0.0 // indirect + github.com/knadh/koanf/v2 v2.3.2 // indirect + github.com/leodido/go-urn v1.5.0 // indirect + github.com/mattn/go-colorable v0.1.14 // indirect + github.com/mattn/go-isatty v0.0.24 // indirect + github.com/mattn/go-runewidth v0.0.19 // indirect + github.com/mfridman/interpolate v0.0.2 // indirect + github.com/mitchellh/copystructure v1.2.0 // indirect + github.com/mitchellh/reflectwalk v1.0.2 // indirect + github.com/ncruces/go-sqlite3 v0.32.0 // indirect + github.com/ncruces/julianday v1.0.0 // indirect + github.com/pelletier/go-toml/v2 v2.2.4 // indirect + github.com/pganalyze/pg_query_go/v6 v6.2.2 // 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/riza-io/grpc-go v0.2.0 // indirect + github.com/rs/zerolog v1.34.0 // indirect + github.com/sagikazarmark/locafero v0.11.0 // indirect + github.com/segmentio/asm v1.2.1 // indirect + github.com/sethvargo/go-retry v0.4.0 // indirect + github.com/shopspring/decimal v1.4.0 // indirect + github.com/sourcegraph/conc v0.3.1-0.20240121214520-5f936abd7ae8 // 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/stretchr/objx v0.5.3 // indirect + github.com/subosito/gotenv v1.6.0 // indirect + github.com/tetratelabs/wazero v1.11.0 // indirect + github.com/vektra/mockery/v3 v3.8.0 // 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/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb // indirect + github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect + github.com/xeipuuv/gojsonschema v1.2.0 // indirect + github.com/yuin/goldmark v1.8.2 // indirect + go.opentelemetry.io/auto/sdk v1.2.1 // indirect + go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.47.0 // indirect + go.opentelemetry.io/otel/log v1.47.0 // indirect + go.opentelemetry.io/proto/otlp v1.11.0 // indirect + go.uber.org/atomic v1.11.0 // indirect + go.uber.org/multierr v1.11.0 // indirect + go.yaml.in/yaml/v3 v3.0.5 // indirect + golang.org/x/exp v0.0.0-20260824195058-e88cd73687aa // indirect + golang.org/x/mod v0.41.0 // indirect + golang.org/x/net v0.59.0 // indirect + golang.org/x/sys v0.49.0 // indirect + golang.org/x/term v0.46.0 // indirect + golang.org/x/text v0.43.0 // indirect + golang.org/x/tools v0.51.0 // indirect + google.golang.org/genproto/googleapis/api v0.0.0-20260928230214-8a89bd6388cc // indirect + google.golang.org/genproto/googleapis/rpc v0.0.0-20260928230214-8a89bd6388cc // indirect + google.golang.org/grpc v1.83.2 // indirect + google.golang.org/protobuf v1.36.12 // indirect + gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect + gopkg.in/yaml.v2 v2.4.0 // indirect + gopkg.in/yaml.v3 v3.0.1 // indirect +) + +tool ( + github.com/ogen-go/ogen/cmd/ogen + github.com/sqlc-dev/sqlc/cmd/sqlc + github.com/vektra/mockery/v3 +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..03e2b21 --- /dev/null +++ b/go.sum @@ -0,0 +1,381 @@ +cel.dev/expr v0.25.2 h1:K6j46C81hXtZQfuX60cVWQFBJahKSE2gfRbNuvr5bFs= +cel.dev/expr v0.25.2/go.mod h1:hrXvqGP6G6gyx8UAHSHJ5RGk//1Oj5nXQ2NI02Nrsg4= +filippo.io/edwards25519 v1.2.0 h1:crnVqOiS4jqYleHd9vaKZ+HKtHfllngJIiOpNpoJsjo= +filippo.io/edwards25519 v1.2.0/go.mod h1:xzAOLCNug/yB62zG1bQ8uziwrIqIuxhctzJT18Q77mc= +github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= +github.com/antlr4-go/antlr/v4 v4.13.1 h1:SqQKkuVZ+zWkMMNkjy5FZe5mr5WURWnlpmOuzYWrPrQ= +github.com/antlr4-go/antlr/v4 v4.13.1/go.mod h1:GKmUxMtwp6ZgGwZSva4eWPC5mS6vUAmOABFgjdkM7Nw= +github.com/aws/aws-sdk-go-v2 v1.47.3 h1:HRoT/MkNi3bjO5xF4dCzLzvVmkvRGHj3/cLINDnJejk= +github.com/aws/aws-sdk-go-v2 v1.47.3/go.mod h1:xSl+OSI5ZUw6bSMupWc218zE5Pl+65MCCu3ySWFY99A= +github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.7.23 h1:/fGPpKrXTjzkhsDXExBgNT2cGwxiF9rLrQXh8RlXMhI= +github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.7.23/go.mod h1:QWUDuRi9PFjBHIU2iH1Pkldbe7zqLfXJC4wWLbF8nuQ= +github.com/aws/aws-sdk-go-v2/credentials v1.20.9 h1:SNO55PnWhaDafsOcv16lCA0kdoFMl/YlegWoVsU02s0= +github.com/aws/aws-sdk-go-v2/credentials v1.20.9/go.mod h1:+2reOTRtdD3VSBqpRDNwrZIYy8yMCYa7oK3WKTJ/I1I= +github.com/aws/aws-sdk-go-v2/internal/configsources v1.5.6 h1:CqL8NN3p4I0JTwwV5MEoatIl4Y2amZ2X9dRD+0hbRL0= +github.com/aws/aws-sdk-go-v2/internal/configsources v1.5.6/go.mod h1:exdJ32hMqXl0Wyo6NwqEC5yIhtua3+PDaKE8P29m4qE= +github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.8.6 h1:FpBq24TG6WVSObTNhQOv7Q0088rounUUlwn3zlNItkM= +github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.8.6/go.mod h1:ONzdPVYC95oBOu0VWNEsKEntcoemP3xVKjT+qWml1s4= +github.com/aws/aws-sdk-go-v2/internal/v4a v1.5.6 h1:Qmn60RWuk9+bd2ddvJJqwf3Cpac3VvGMOdbGemtUhX4= +github.com/aws/aws-sdk-go-v2/internal/v4a v1.5.6/go.mod h1:h/YJhe4AVyQxEUMluph10iqV7mjajH7A9L+BHF5ppis= +github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.13.21 h1:e6YW5uME30TkrElR+4/xcY7NB6CCj2dcv7vtmGXhfhQ= +github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.13.21/go.mod h1:obpHAMP693+f3/A8PkLhIqfK1C+NWWn8zXzqD3OH520= +github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.11.7 h1:CwvFlKw0uUScfgOMflXSRZa+ayXgOf6wk7lhyMemQYU= +github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.11.7/go.mod h1:4SbD8BB+p+QEnG0aX6DoWwrtk9SufyYXRsUv0nve8LE= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.14.6 h1:LHHdobjo5le1sjJdolitV7uVvYg3wkaeM1Ju2fDgeZQ= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.14.6/go.mod h1:CBGB0evAiaMD3Lk4wPO7LQCcCZLuhzL5Qf/wfEUHQ5w= +github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.20.6 h1:mYViDr2azcgxOpRrObZOl631bvavqILoE/L+Kxgbwys= +github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.20.6/go.mod h1:OXVdAo9jNhggB+hJRGOyy7WolGTKB6Rg7IIulDeSzPM= +github.com/aws/aws-sdk-go-v2/service/s3 v1.114.4 h1:MrkWRB58Qw5TEkb51QVooVLjlM3IevO2iVXEz74B8pg= +github.com/aws/aws-sdk-go-v2/service/s3 v1.114.4/go.mod h1:yfIxaKRHasvfy6tNEm3/LpqKsupMzQjMaWj9Y0jMVbo= +github.com/aws/smithy-go v1.28.6 h1:Pj+/sUviNYjow8ELRtNwKHZ9ECeF+7pATX3+shjLIrw= +github.com/aws/smithy-go v1.28.6/go.mod h1:YE2RhdIuDbA5E5bTdciG9KrW3+TiEONeUWCqxX9i1Fc= +github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA= +github.com/brunoga/deep v1.3.1 h1:bSrL6FhAZa6JlVv4vsi7Hg8SLwroDb1kgDERRVipBCo= +github.com/brunoga/deep v1.3.1/go.mod h1:GDV6dnXqn80ezsLSZ5Wlv1PdKAWAO4L5PnKYtv2dgaI= +github.com/bsm/ginkgo/v2 v2.12.0 h1:Ny8MWAHyOepLGlLKYmXG4IEkioBysk6GpaRTLC8zwWs= +github.com/bsm/ginkgo/v2 v2.12.0/go.mod h1:SwYbGRRDovPVboqFv0tPTcG1sN61LM1Z4ARdbAV9g4c= +github.com/bsm/gomega v1.27.10 h1:yeMWxP2pV2fG3FgAODIY8EiRE3dy0aeFYt4l7wh6yKA= +github.com/bsm/gomega v1.27.10/go.mod h1:JyEr/xRbxbtgWNi8tIEVPUYZ5Dzef52k01W3YH0H+O0= +github.com/cenkalti/backoff/v5 v5.0.3 h1:ZN+IMa753KfX5hd8vVaMixjnqRZ3y8CuJKRKj1xcsSM= +github.com/cenkalti/backoff/v5 v5.0.3/go.mod h1:rkhZdG3JZukswDf7f0cwqPNk4K0sa+F97BxZthm/crw= +github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs= +github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= +github.com/clipperhouse/uax29/v2 v2.2.0 h1:ChwIKnQN3kcZteTXMgb1wztSgaU+ZemkgWdohwgs8tY= +github.com/clipperhouse/uax29/v2 v2.2.0/go.mod h1:EFJ2TJMRUaplDxHKj1qAEhCtQPW2tJSwu5BF98AuoVM= +github.com/coreos/go-semver v0.3.1 h1:yi21YpKnrx1gt5R+la8n5WgS0kCrsPp33dmEyHReZr4= +github.com/coreos/go-semver v0.3.1/go.mod h1:irMmmIw/7yzSRPWryHsK7EYSg09caPQL03VsM8rvUec= +github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc= +github.com/cpuguy83/go-md2man/v2 v2.0.6/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g= +github.com/cubicdaiya/gonp v1.0.4 h1:ky2uIAJh81WiLcGKBVD5R7KsM/36W6IqqTy6Bo6rGws= +github.com/cubicdaiya/gonp v1.0.4/go.mod h1:iWGuP/7+JVTn02OWhRemVbMmG1DOUnmrGTYYACpOI0I= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM= +github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/dlclark/regexp2 v1.12.0 h1:0j4c5qQmnC6XOWNjP3PIXURXN2gWx76rd3KvgdPkCz8= +github.com/dlclark/regexp2 v1.12.0/go.mod h1:DHkYz0B9wPfa6wondMfaivmHpzrQ3v9q8cnmRbL6yW8= +github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY= +github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto= +github.com/ebitengine/purego v0.10.1 h1:dewVBCBT2GaMu1SrNTYxQhgQBethzfhiwvZiLGP/qyY= +github.com/ebitengine/purego v0.10.1/go.mod h1:iIjxzd6CiRiOG0UyXP+V1+jWqUXVjPKLAI0mRfJZTmQ= +github.com/exaring/otelpgx v0.13.0 h1:Vi0I2GWRS3nnVzgr73L/XbSLqthR0h6A1rm4Wt3W4aA= +github.com/exaring/otelpgx v0.13.0/go.mod h1:3OojrUKhhy3lTbYIMBijP3YjMey/jo14eHAW5cXcUdk= +github.com/fatih/color v1.19.0 h1:Zp3PiM21/9Ld6FzSKyL5c/BULoe/ONr9KlbYVOfG8+w= +github.com/fatih/color v1.19.0/go.mod h1:zNk67I0ZUT1bEGsSGyCZYZNrHuTkJJB+r6Q9VuMi0LE= +github.com/fatih/structs v1.1.0 h1:Q7juDM0QtcnhCpeyLGQKyg4TOIghuNXrkL32pHAUMxo= +github.com/fatih/structs v1.1.0/go.mod h1:9NiDSp5zOcgEDl+j00MP/WkGVPOlPRLejGD8Ga6PJ7M= +github.com/fatih/structtag v1.2.0 h1:/OdNE99OxoI/PqaW/SuSK9uxxT3f/tcSZgon/ssNSx4= +github.com/fatih/structtag v1.2.0/go.mod h1:mBJUNpUnHmRKrKlQQlmCrh5PuhftFbNv8Ys4/aAZl94= +github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8= +github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0= +github.com/fsnotify/fsnotify v1.9.0 h1:2Ml+OJNzbYCTzsxtv8vKSFD9PbJjmhYF14k/jKC7S9k= +github.com/fsnotify/fsnotify v1.9.0/go.mod h1:8jBTzvmWwFyi3Pb8djgCCO5IBqzKJ/Jwo8TRcHyHii0= +github.com/gabriel-vasile/mimetype v1.4.15 h1:05iP/CYtZ/w455R/KZM6rZ5ieAdh99UPtd+d3YzLmaI= +github.com/gabriel-vasile/mimetype v1.4.15/go.mod h1:azpTcoLcDZRNgFou5j+APrqQx9HqVPWa6ijYQIIVswQ= +github.com/gen2brain/webp v0.6.4 h1:SUDdmxADOAiPQ+5ylNmuHhuYf2dOi0KgKZHL5vpVCNU= +github.com/gen2brain/webp v0.6.4/go.mod h1:iGWMaCSw7t3I/Cv9llzEKmpnR36S8lS8VL/ZVjxU0JE= +github.com/ghodss/yaml v1.0.0 h1:wQHKEahhL6wmXdzwWG11gIVCkOv05bNOh+Rxn0yngAk= +github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= +github.com/go-faster/errors v0.8.0 h1:9T9eJrM+72dFk7n4DfhuaDDe6cyuFCSW2oNUkN77Yqc= +github.com/go-faster/errors v0.8.0/go.mod h1:5ySTjWFiphBs07IKuiL69nxdfd5+fzh1u7FPGZP2quo= +github.com/go-faster/jx v1.2.0 h1:T2YHJPrFaYu21fJtUxC9GzmluKu8rVIFDwwGBKTDseI= +github.com/go-faster/jx v1.2.0/go.mod h1:UWLOVDmMG597a5tBFPLIWJdUxz5/2emOpfsj9Neg0PE= +github.com/go-faster/yaml v0.4.6 h1:lOK/EhI04gCpPgPhgt0bChS6bvw7G3WwI8xxVe0sw9I= +github.com/go-faster/yaml v0.4.6/go.mod h1:390dRIvV4zbnO7qC9FGo6YYutc+wyyUSHBgbXL52eXk= +github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= +github.com/go-logr/logr v1.4.4 h1:tG4xh9yMsRCAiodLVTxyrkzSZ9+o0L1Kg/+cPVcbP/8= +github.com/go-logr/logr v1.4.4/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= +github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag= +github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE= +github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s= +github.com/go-playground/assert/v2 v2.2.0/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4= +github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA= +github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY= +github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY= +github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY= +github.com/go-playground/validator/v10 v10.30.5 h1:YyCXvVShZbs2Sm3Mb53eNOlhRXctSOzW5QJAouCTZL4= +github.com/go-playground/validator/v10 v10.30.5/go.mod h1:wEqiaov48pXX1kjhc3Da8y0M0Dtg/BK7gurFBLgwFrQ= +github.com/go-sql-driver/mysql v1.10.0 h1:Q+1LV8DkHJvSYAdR83XzuhDaTykuDx0l6fkXxoWCWfw= +github.com/go-sql-driver/mysql v1.10.0/go.mod h1:M+cqaI7+xxXGG9swrdeUIoPG3Y3KCkF0pZej+SK+nWk= +github.com/go-viper/mapstructure/v2 v2.5.0 h1:vM5IJoUAy3d7zRSVtIwQgBj7BiWtMPfmPEgAXnvj1Ro= +github.com/go-viper/mapstructure/v2 v2.5.0/go.mod h1:oJDH3BJKyqBA2TXFhDsKDGDTlndYOZ6rGS0BRZIxGhM= +github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= +github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek= +github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps= +github.com/google/cel-go v0.28.0 h1:KjSWstCpz/MN5t4a8gnGJNIYUsJRpdi/r97xWDphIQc= +github.com/google/cel-go v0.28.0/go.mod h1:X0bD6iVNR8pkROSOoHVdgTkzmRcosof7WQqCD6wcMc8= +github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8= +github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU= +github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= +github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/grpc-ecosystem/grpc-gateway/v2 v2.30.0 h1:/Tnpcb2E0Pz/tN9s3bfEY2Q8ePCEX9iuS+cneUwncnw= +github.com/grpc-ecosystem/grpc-gateway/v2 v2.30.0/go.mod h1:zOBXOsUaBSjKgmH4OGzV1esUpR3oUSCPYVd2cUBjKYY= +github.com/huandu/xstrings v1.5.0 h1:2ag3IFq9ZDANvthTwTiqSSZLjDc+BedvHPAp5tJy2TI= +github.com/huandu/xstrings v1.5.0/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE= +github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8= +github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= +github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM= +github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg= +github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 h1:iCEnooe7UlwOQYpKFhBabPMi4aNAfoODPEFNiAnClxo= +github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761/go.mod h1:5TJZWKEWniPve33vlWYSoGYefn3gLQRzjfDlhSJ9ZKM= +github.com/jackc/pgx/v5 v5.11.0 h1:IzBBtyK9AHqf98cctWFifYSci2hgQR/cd56wB4p+ogg= +github.com/jackc/pgx/v5 v5.11.0/go.mod h1:mal1tBGAFfLHvZzaYh77YS/eC6IX9OWbRV1QIIM0Jn4= +github.com/jackc/puddle/v2 v2.2.2 h1:PR8nw+E/1w0GLuRFSmiioY6UooMp6KJv0/61nB7icHo= +github.com/jackc/puddle/v2 v2.2.2/go.mod h1:vriiEXHvEE654aYKXXjOvZM39qJ0q+azkZFrfEOc3H4= +github.com/jedib0t/go-pretty/v6 v6.7.8 h1:BVYrDy5DPBA3Qn9ICT+PokP9cvCv1KaHv2i+Hc8sr5o= +github.com/jedib0t/go-pretty/v6 v6.7.8/go.mod h1:YwC5CE4fJ1HFUDeivSV1r//AmANFHyqczZk+U6BDALU= +github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E= +github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc= +github.com/klauspost/cpuid/v2 v2.2.10 h1:tBs3QSyvjDyFTq3uoc/9xFpCuOsJQFNPiAhYdw2skhE= +github.com/klauspost/cpuid/v2 v2.2.10/go.mod h1:hqwkgyIinND0mEev00jJYCxPNVRVXFQeu1XKlok6oO0= +github.com/knadh/koanf/maps v0.1.2 h1:RBfmAW5CnZT+PJ1CVc1QSJKf4Xu9kxfQgYVQSu8hpbo= +github.com/knadh/koanf/maps v0.1.2/go.mod h1:npD/QZY3V6ghQDdcQzl1W4ICNVTkohC8E73eI2xW4yI= +github.com/knadh/koanf/parsers/yaml v1.1.0 h1:3ltfm9ljprAHt4jxgeYLlFPmUaunuCgu1yILuTXRdM4= +github.com/knadh/koanf/parsers/yaml v1.1.0/go.mod h1:HHmcHXUrp9cOPcuC+2wrr44GTUB0EC+PyfN3HZD9tFg= +github.com/knadh/koanf/providers/env v1.1.0 h1:U2VXPY0f+CsNDkvdsG8GcsnK4ah85WwWyJgef9oQMSc= +github.com/knadh/koanf/providers/env v1.1.0/go.mod h1:QhHHHZ87h9JxJAn2czdEl6pdkNnDh/JS1Vtsyt65hTY= +github.com/knadh/koanf/providers/file v1.2.1 h1:bEWbtQwYrA+W2DtdBrQWyXqJaJSG3KrP3AESOJYp9wM= +github.com/knadh/koanf/providers/file v1.2.1/go.mod h1:bp1PM5f83Q+TOUu10J/0ApLBd9uIzg+n9UgthfY+nRA= +github.com/knadh/koanf/providers/posflag v1.0.1 h1:EnMxHSrPkYCFnKgBUl5KBgrjed8gVFrcXDzaW4l/C6Y= +github.com/knadh/koanf/providers/posflag v1.0.1/go.mod h1:3Wn3+YG3f4ljzRyCUgIwH7G0sZ1pMjCOsNBovrbKmAk= +github.com/knadh/koanf/providers/structs v1.0.0 h1:DznjB7NQykhqCar2LvNug3MuxEQsZ5KvfgMbio+23u4= +github.com/knadh/koanf/providers/structs v1.0.0/go.mod h1:kjo5TFtgpaZORlpoJqcbeLowM2cINodv8kX+oFAeQ1w= +github.com/knadh/koanf/v2 v2.3.2 h1:Ee6tuzQYFwcZXQpc2MiVeC6qHMandf5SMUJJNoFp/c4= +github.com/knadh/koanf/v2 v2.3.2/go.mod h1:gRb40VRAbd4iJMYYD5IxZ6hfuopFcXBpc9bbQpZwo28= +github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= +github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= +github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= +github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= +github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= +github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= +github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= +github.com/leodido/go-urn v1.5.0 h1:pLqT2kq1zpHW/1D18QMjMpdtX7cekxqtJJjg5ANyWw0= +github.com/leodido/go-urn v1.5.0/go.mod h1:9BORnCDhdPBJNDEX+w1bJisa8yOKYi116VeO96s4ifE= +github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg= +github.com/mattn/go-colorable v0.1.14 h1:9A9LHSqF/7dyVVX6g0U9cwm9pG3kP9gSzcuIPHPsaIE= +github.com/mattn/go-colorable v0.1.14/go.mod h1:6LmQG8QLFO4G5z1gPvYEzlUgJ2wF+stgPZH1UqBm1s8= +github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= +github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= +github.com/mattn/go-isatty v0.0.24 h1:tGZZoVgT/KiqK1c8ocVLeDS8BSWMRd47J3Lbz7vsReI= +github.com/mattn/go-isatty v0.0.24/go.mod h1:nMCL3Zebbrt45jsMDgnfIwz6ydEQApk5oEI3HqDio6A= +github.com/mattn/go-runewidth v0.0.19 h1:v++JhqYnZuu5jSKrk9RbgF5v4CGUjqRfBm05byFGLdw= +github.com/mattn/go-runewidth v0.0.19/go.mod h1:XBkDxAl56ILZc9knddidhrOlY5R/pDhgLpndooCuJAs= +github.com/mfridman/interpolate v0.0.2 h1:pnuTK7MQIxxFz1Gr+rjSIx9u7qVjf5VOoM/u6BbAxPY= +github.com/mfridman/interpolate v0.0.2/go.mod h1:p+7uk6oE07mpE/Ik1b8EckO0O4ZXiGAfshKBWLUM9Xg= +github.com/mitchellh/copystructure v1.2.0 h1:vpKXTN4ewci03Vljg/q9QvCGUDttBOGBIa15WveJJGw= +github.com/mitchellh/copystructure v1.2.0/go.mod h1:qLl+cE2AmVv+CoeAwDPye/v+N2HKCj9FbZEVFJRxO9s= +github.com/mitchellh/reflectwalk v1.0.2 h1:G2LzWKi524PWgd3mLHV8Y5k7s6XUvT0Gef6zxSIeXaQ= +github.com/mitchellh/reflectwalk v1.0.2/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw= +github.com/ncruces/go-sqlite3 v0.32.0 h1:hNBUXp88LrfQCsuyXLqWTbTUG35sUuktDsqhhgHvU20= +github.com/ncruces/go-sqlite3 v0.32.0/go.mod h1:MIWTK60ONDl0oVY073zYvJP21C3Dly6P9bxVpgkLwdQ= +github.com/ncruces/go-strftime v1.0.0 h1:HMFp8mLCTPp341M/ZnA4qaf7ZlsbTc+miZjCLOFAw7w= +github.com/ncruces/go-strftime v1.0.0/go.mod h1:Fwc5htZGVVkseilnfgOVb9mKy6w1naJmn9CehxcKcls= +github.com/ncruces/julianday v1.0.0 h1:fH0OKwa7NWvniGQtxdJRxAgkBMolni2BjDHaWTxqt7M= +github.com/ncruces/julianday v1.0.0/go.mod h1:Dusn2KvZrrovOMJuOt0TNXL6tB7U2E8kvza5fFc9G7g= +github.com/ogen-go/ogen v1.24.0 h1:NehBG/8s0JeM6jYHPJeFJntBG3cE/xQgZd1q8BchPNM= +github.com/ogen-go/ogen v1.24.0/go.mod h1:hcg4aTzLcu/MS1SGGahUriPBEOZB3c82RGIC6dYcdFU= +github.com/pelletier/go-toml/v2 v2.2.4 h1:mye9XuhQ6gvn5h28+VilKrrPoQVanw5PMw/TB0t5Ec4= +github.com/pelletier/go-toml/v2 v2.2.4/go.mod h1:2gIqNv+qfxSVS7cM2xJQKtLSTLUE9V8t9Stt+h56mCY= +github.com/pganalyze/pg_query_go/v6 v6.2.2 h1:O0L6zMC226R82RF3X5n0Ki6HjytDsoAzuzp4ATVAHNo= +github.com/pganalyze/pg_query_go/v6 v6.2.2/go.mod h1:Cn6+j4870kJz3iYNsb0VsNG04vpSWgEvBwc590J4qD0= +github.com/pingcap/errors v0.11.0/go.mod h1:Oi8TUi2kEtXXLMJk9l1cGmz20kV3TaQ0usTwv5KuLY8= +github.com/pingcap/errors v0.11.5-0.20250523034308-74f78ae071ee h1:/IDPbpzkzA97t1/Z1+C3KlxbevjMeaI6BQYxvivu4u8= +github.com/pingcap/errors v0.11.5-0.20250523034308-74f78ae071ee/go.mod h1:X2r9ueLEUZgtx2cIogM0v4Zj5uvvzhuuiu7Pn8HzMPg= +github.com/pingcap/failpoint v0.0.0-20240528011301-b51a646c7c86 h1:tdMsjOqUR7YXHoBitzdebTvOjs/swniBTOLy5XiMtuE= +github.com/pingcap/failpoint v0.0.0-20240528011301-b51a646c7c86/go.mod h1:exzhVYca3WRtd6gclGNErRWb1qEgff3LYta0LvRmON4= +github.com/pingcap/log v1.1.0 h1:ELiPxACz7vdo1qAvvaWJg1NrYFoY6gqAh/+Uo6aXdD8= +github.com/pingcap/log v1.1.0/go.mod h1:DWQW5jICDR7UJh4HtxXSM20Churx4CQL0fwL/SoOSA4= +github.com/pingcap/tidb/pkg/parser v0.0.0-20260418072757-ce92298d1124 h1:zYmP5fBH+i2yhhU6f5uOol6zxHtR2/sD47BsJLfy0oU= +github.com/pingcap/tidb/pkg/parser v0.0.0-20260418072757-ce92298d1124/go.mod h1:zDLDsfNBU5+L6T4J9/OgWAHc/WZvMUjbpgHqQ/t3yKo= +github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/pressly/goose/v3 v3.28.0 h1:D2M+iL31GmpZxSHOhX8mqyqAT3CXnokUmm0eKoSP+Vc= +github.com/pressly/goose/v3 v3.28.0/go.mod h1:v26MOuB8bL3kzzrt3Vqhb3R0PRVsl8hFQKdrht/L6Rk= +github.com/rabbitmq/amqp091-go v1.16.0 h1:1O8oQqnj9hLACoo6CVMgn57z2pLWXvgemhh4GsquV+Y= +github.com/rabbitmq/amqp091-go v1.16.0/go.mod h1:Hy4jKW5kQART1u+JkDTF9YYOQUHXqMuhrgxOEeS7G4o= +github.com/redis/go-redis/v9 v9.22.0 h1:laDvpYXTJtZLloinw1fA5Kqd6HAEH2XKxOkG/PDq2F0= +github.com/redis/go-redis/v9 v9.22.0/go.mod h1:y2g0Wj8rQvuK0ELM+oxSudcLtC09JScs98I/X9gRWY4= +github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec h1:W09IVJc94icq4NjY3clb7Lk8O1qJ8BdBEF8z0ibU0rE= +github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo= +github.com/riza-io/grpc-go v0.2.0 h1:2HxQKFVE7VuYstcJ8zqpN84VnAoJ4dCL6YFhJewNcHQ= +github.com/riza-io/grpc-go v0.2.0/go.mod h1:2bDvR9KkKC3KhtlSHfR3dAXjUMT86kg4UfWFyVGWqi8= +github.com/rogpeppe/go-internal v1.14.1 h1:UQB4HGPB6osV0SQTLymcB4TgvyWu6ZyliaW0tI/otEQ= +github.com/rogpeppe/go-internal v1.14.1/go.mod h1:MaRKkUm5W0goXpeCfT7UZI6fk/L7L7so1lCWt35ZSgc= +github.com/rs/xid v1.6.0/go.mod h1:7XoLgs4eV+QndskICGsho+ADou8ySMSjJKDIan90Nz0= +github.com/rs/zerolog v1.34.0 h1:k43nTLIwcTVQAncfCw4KZ2VY6ukYoZaBPNOE8txlOeY= +github.com/rs/zerolog v1.34.0/go.mod h1:bJsvje4Z08ROH4Nhs5iH600c3IkWhwp44iRc54W6wYQ= +github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= +github.com/sagikazarmark/locafero v0.11.0 h1:1iurJgmM9G3PA/I+wWYIOw/5SyBtxapeHDcg+AAIFXc= +github.com/sagikazarmark/locafero v0.11.0/go.mod h1:nVIGvgyzw595SUSUE6tvCp3YYTeHs15MvlmU87WwIik= +github.com/segmentio/asm v1.2.1 h1:DTNbBqs57ioxAD4PrArqftgypG4/qNpXoJx8TVXxPR0= +github.com/segmentio/asm v1.2.1/go.mod h1:BqMnlJP91P8d+4ibuonYZw9mfnzI9HfxselHZr5aAcs= +github.com/sethvargo/go-retry v0.4.0 h1:9qy1OoIAxBL+gBYnkTnTnWle5wlfsXQlwRzIbbpdqPw= +github.com/sethvargo/go-retry v0.4.0/go.mod h1:tvsjdKG6xfiCx4LSiUZ06kcv38xvdVQwv8R6/VnnVWg= +github.com/shopspring/decimal v1.4.0 h1:bxl37RwXBklmTi0C79JfXCEBD1cqqHt0bbgBAGFp81k= +github.com/shopspring/decimal v1.4.0/go.mod h1:gawqmDU56v4yIKSwfBSFip1HdCCXN8/+DMd9qYNcwME= +github.com/sourcegraph/conc v0.3.1-0.20240121214520-5f936abd7ae8 h1:+jumHNA0Wrelhe64i8F6HNlS8pkoyMv5sreGx2Ry5Rw= +github.com/sourcegraph/conc v0.3.1-0.20240121214520-5f936abd7ae8/go.mod h1:3n1Cwaq1E1/1lhQhtRK2ts/ZwZEhjcQeJQ1RuC6Q/8U= +github.com/spf13/afero v1.15.0 h1:b/YBCLWAJdFWJTN9cLhiXXcD7mzKn9Dm86dNnfyQw1I= +github.com/spf13/afero v1.15.0/go.mod h1:NC2ByUVxtQs4b3sIUphxK0NioZnmxgyCrfzeuq8lxMg= +github.com/spf13/cast v1.10.0 h1:h2x0u2shc1QuLHfxi+cTJvs30+ZAHOGRic8uyGTDWxY= +github.com/spf13/cast v1.10.0/go.mod h1:jNfB8QC9IA6ZuY2ZjDp0KtFO2LZZlg4S/7bzP6qqeHo= +github.com/spf13/cobra v1.10.2 h1:DMTTonx5m65Ic0GOoRY2c16WCbHxOOw6xxezuLaBpcU= +github.com/spf13/cobra v1.10.2/go.mod h1:7C1pvHqHw5A4vrJfjNwvOdzYu0Gml16OCs2GRiTUUS4= +github.com/spf13/pflag v1.0.9/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= +github.com/spf13/pflag v1.0.10 h1:4EBh2KAYBwaONj6b2Ye1GiHfwjqyROoF4RwYO+vPwFk= +github.com/spf13/pflag v1.0.10/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= +github.com/spf13/viper v1.21.0 h1:x5S+0EU27Lbphp4UKm1C+1oQO+rKx36vfCoaVebLFSU= +github.com/spf13/viper v1.21.0/go.mod h1:P0lhsswPGWD/1lZJ9ny3fYnVqxiegrlNrEmgLjbTCAY= +github.com/sqlc-dev/doubleclick v1.0.0 h1:2/OApfQ2eLgcfa/Fqs8WSMA6atH0G8j9hHbQIgMfAXI= +github.com/sqlc-dev/doubleclick v1.0.0/go.mod h1:ODHRroSrk/rr5neRHlWMSRijqOak8YmNaO3VAZCNl5Y= +github.com/sqlc-dev/sqlc v1.31.1 h1:+V+BjBJfFNPX/RFfL8eiZD9jk9lVJUEGGllWvnYNqbc= +github.com/sqlc-dev/sqlc v1.31.1/go.mod h1:6ZPww/Jd3G6MzJeW6NrqizjL+52vYNaaXP9yMeJ/Nao= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/objx v0.5.3 h1:jmXUvGomnU1o3W/V5h2VEradbpJDwGrzugQQvL0POH4= +github.com/stretchr/objx v0.5.3/go.mod h1:rDQraq+vQZU7Fde9LOZLr8Tax6zZvy4kuNKF+QYS+U0= +github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= +github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= +github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.12.1 h1:EuwCh5fleGS7H32xRwO3wRGT7DxrDhLAT6FF8MpWDWE= +github.com/stretchr/testify v1.12.1/go.mod h1:MDEgiDPPsNp5cuIrHPPCyornHKgEVbtFUmoNlxoYthg= +github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8= +github.com/subosito/gotenv v1.6.0/go.mod h1:Dk4QP5c2W3ibzajGcXpNraDfq2IrhjMIvMSWPKKo0FU= +github.com/tetratelabs/wazero v1.11.0 h1:+gKemEuKCTevU4d7ZTzlsvgd1uaToIDtlQlmNbwqYhA= +github.com/tetratelabs/wazero v1.11.0/go.mod h1:eV28rsN8Q+xwjogd7f4/Pp4xFxO7uOGbLcD/LzB1wiU= +github.com/vektra/mockery/v3 v3.8.0 h1:Tklqcx844iV8GtYziqJXam1a8RdcKip4UErMa66Nxps= +github.com/vektra/mockery/v3 v3.8.0/go.mod h1:K+L72OoFVizA9eWtO4L+kU65oylgreiJEJ57Gu8g9Ew= +github.com/wasilibs/go-pgquery v0.0.0-20250409022910-10ac41983c07 h1:mJdDDPblDfPe7z7go8Dvv1AJQDI3eQ/5xith3q2mFlo= +github.com/wasilibs/go-pgquery v0.0.0-20250409022910-10ac41983c07/go.mod h1:Ak17IJ037caFp4jpCw/iQQ7/W74Sqpb1YuKJU6HTKfM= +github.com/wasilibs/wazero-helpers v0.0.0-20240620070341-3dff1577cd52 h1:OvLBa8SqJnZ6P+mjlzc2K7PM22rRUPE1x32G9DTPrC4= +github.com/wasilibs/wazero-helpers v0.0.0-20240620070341-3dff1577cd52/go.mod h1:jMeV4Vpbi8osrE/pKUxRZkVaA0EX7NZN0A9/oRzgpgY= +github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f/go.mod h1:N2zxlSyiKSe5eX1tZViRH5QA0qijqEDrYZiPEAiq3wU= +github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb h1:zGWFAtiMcyryUHoUjUJX0/lt1H2+i2Ka2n+D3DImSNo= +github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb/go.mod h1:N2zxlSyiKSe5eX1tZViRH5QA0qijqEDrYZiPEAiq3wU= +github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 h1:EzJWgHovont7NscjpAxXsDA8S8BMYve8Y5+7cuRE7R0= +github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415/go.mod h1:GwrjFmJcFw6At/Gs6z4yjiIwzuJ1/+UwLxMQDVQXShQ= +github.com/xeipuuv/gojsonschema v1.2.0 h1:LhYJRs+L4fBtjZUfuSZIKGeVu0QRy8e5Xi7D17UxZ74= +github.com/xeipuuv/gojsonschema v1.2.0/go.mod h1:anYRn/JVcOK2ZgGU+IjEV4nwlhoK5sQluxsYJ78Id3Y= +github.com/yuin/goldmark v1.8.2 h1:kEGpgqJXdgbkhcOgBxkC0X0PmoPG1ZyoZ117rDVp4zE= +github.com/yuin/goldmark v1.8.2/go.mod h1:ip/1k0VRfGynBgxOz0yCqHrbZXhcjxyuS66Brc7iBKg= +github.com/zeebo/xxh3 v1.1.0 h1:s7DLGDK45Dyfg7++yxI0khrfwq9661w9EN78eP/UZVs= +github.com/zeebo/xxh3 v1.1.0/go.mod h1:IisAie1LELR4xhVinxWS5+zf1lA4p0MW4T+w+W07F5s= +go.opentelemetry.io/auto/sdk v1.2.1 h1:jXsnJ4Lmnqd11kwkBV2LgLoFMZKizbCi5fNZ/ipaZ64= +go.opentelemetry.io/auto/sdk v1.2.1/go.mod h1:KRTj+aOaElaLi+wW1kO/DZRXwkF4C5xPbEe3ZiIhN7Y= +go.opentelemetry.io/contrib/bridges/otelslog v0.21.0 h1:/CdgE52i1OEPHhsGUqrggYNRaZy4v4YgVenGd52dRBI= +go.opentelemetry.io/contrib/bridges/otelslog v0.21.0/go.mod h1:9pBdbVbuehIDzxN4accnzzxEUPT8Nq7grbZMo+J1VN4= +go.opentelemetry.io/otel v1.47.0 h1:j7ALJ/zgkS7Z6aeJW09p8VC9804bC+PpeTfCD4XPnOM= +go.opentelemetry.io/otel v1.47.0/go.mod h1:8wS9O2qfXrYrzp6hIF/HOYJJf/wIhFPhR2xLuP+iXQU= +go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploghttp v0.23.0 h1:5WVp40k2fJHuc5BtNTgKk+EugKFT8Eg3lywFfCPI/nE= +go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploghttp v0.23.0/go.mod h1:59nH0RYCGHRlwt15WyioeSYINBbuObeBpTowPhEKWHY= +go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp v1.47.0 h1:7kszRN4Ze5GeAkUnBjBSUIunVBMA+mZIG04auueqguM= +go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp v1.47.0/go.mod h1:CLzakYy8jOdkBfcveCWYkeKJxujcF4xPhh2Z7IfE98U= +go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.47.0 h1:julhjPeUH/q/7hinbSdDdqt5h7Zw9YWmRlWRhI0jd54= +go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.47.0/go.mod h1:Ao2mz688LH/tFf0yMAenidq6k2YNSx6SIY2q6jDACck= +go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.47.0 h1:aXZXsZ012wOgVkqaiQv+Z/d8V0xKjmg70F6m4CE94lc= +go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.47.0/go.mod h1:ziu1gUIJhAaxM3EV1e3Ralk5AAyL1UOYz3lJJ4VSI38= +go.opentelemetry.io/otel/log v1.47.0 h1:cOTS1CcLbSQeZKanGJ+0JpF/+t4PELi3O3bbl2lqCcI= +go.opentelemetry.io/otel/log v1.47.0/go.mod h1:9byitSQ5pLC6PpqwGXjqdMKya6ZTswHRZh2vvXT33nw= +go.opentelemetry.io/otel/metric v1.47.0 h1:4PptaldXx3Eat1XjMZ68pPJEs5wrhlemctZE9a3UdWY= +go.opentelemetry.io/otel/metric v1.47.0/go.mod h1:ADGSXxRrXM6bjbvLo535EstVFlPpPYZm4LBKixjDHwU= +go.opentelemetry.io/otel/metric/x v0.69.0 h1:DjRLr15H83v+hCW7JA9NoJvOkYTtmq5YoDRbe9deYpM= +go.opentelemetry.io/otel/metric/x v0.69.0/go.mod h1:uVvsMPMFFyj/HUQfrUnH3JjnOQ1dwFDorgFLRBasM0k= +go.opentelemetry.io/otel/sdk v1.47.0 h1:zWXEr4j2lFefG87TU6Yg8a7ngfohIKFZHKp0Hf5hC6I= +go.opentelemetry.io/otel/sdk v1.47.0/go.mod h1:VUc24kiOeoGsxG8G9ULx3fWKvB7jMhnGE8Oi607lgR0= +go.opentelemetry.io/otel/sdk/log v1.47.0 h1:W4N/ZfgpkRRnmARnqYoQ6BrWA0mrj8IzVDNLlpmUJZY= +go.opentelemetry.io/otel/sdk/log v1.47.0/go.mod h1:Wu74Z2EmOKXi2FleSNAb0Hyau2G+r5kubSEMJw5aAMs= +go.opentelemetry.io/otel/sdk/log/logtest v0.23.0 h1:j3pm42QCrKYYLLkI6OrV1QHFkUfDA6/4EP+Y1PzggLg= +go.opentelemetry.io/otel/sdk/log/logtest v0.23.0/go.mod h1:zt0gEnuTZgDvqvczHwYswz93eqMaIr6upTTsdV/HUlU= +go.opentelemetry.io/otel/sdk/metric v1.47.0 h1:lfISg2j93VT6yqdk9OfUaZmw/GfcZqCCV3jdXtsPnKw= +go.opentelemetry.io/otel/sdk/metric v1.47.0/go.mod h1:ypLp+mW1Nt2x+Szt3b5/i1syodyts49lMOwxpDI3VGw= +go.opentelemetry.io/otel/trace v1.47.0 h1:JOjX/Oci8K94QHddo+bbfya/Ai/nf6/dt9ZfrFNWSrM= +go.opentelemetry.io/otel/trace v1.47.0/go.mod h1:jNaSLa2PZEYFG6fRjJABAu+bw4FS08uDmPg28lTghu0= +go.opentelemetry.io/proto/otlp v1.11.0 h1:5rrYs0Ykyj50sdU/JU0x8etU+LubXWb+gED6TbEdMIk= +go.opentelemetry.io/proto/otlp v1.11.0/go.mod h1:SmVizdCOAm3XBtG1g1NnOdhW6jtddT72hLMhv8VwA8E= +go.uber.org/atomic v1.6.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ= +go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc= +go.uber.org/atomic v1.9.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc= +go.uber.org/atomic v1.11.0 h1:ZvwS0R+56ePWxUNi+Atn9dWONBPp/AUETXlHW0DxSjE= +go.uber.org/atomic v1.11.0/go.mod h1:LUxbIzbOniOlMKjJjyPfpl4v+PKK2cNJn91OQbhoJI0= +go.uber.org/goleak v1.1.10/go.mod h1:8a7PlsEVH3e/a/GLqe5IIrQx6GzcnRmZEufDUTk4A7A= +go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto= +go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE= +go.uber.org/multierr v1.6.0/go.mod h1:cdWPpRnG4AhwMwsgIHip0KRBQjJy5kYEpYjJxpXp9iU= +go.uber.org/multierr v1.7.0/go.mod h1:7EAYxJLBy9rStEaz58O2t4Uvip6FSURkq8/ppBp95ak= +go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0= +go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y= +go.uber.org/zap v1.19.0/go.mod h1:xg/QME4nWcxGxrpdeYfq7UvYrLh66cuVKdrbD1XF/NI= +go.uber.org/zap v1.28.0 h1:IZzaP1Fv73/T/pBMLk4VutPl36uNC+OSUh3JLG3FIjo= +go.uber.org/zap v1.28.0/go.mod h1:rDLpOi171uODNm/mxFcuYWxDsqWSAVkFdX4XojSKg/Q= +go.uber.org/zap/exp v0.3.0 h1:6JYzdifzYkGmTdRR59oYH+Ng7k49H9qVpWwNSsGJj3U= +go.uber.org/zap/exp v0.3.0/go.mod h1:5I384qq7XGxYyByIhHm6jg5CHkGY0nsTfbDLgDDlgJQ= +go.yaml.in/yaml/v3 v3.0.4/go.mod h1:DhzuOOF2ATzADvBadXxruRBLzYTpT36CKvDb3+aBEFg= +go.yaml.in/yaml/v3 v3.0.5 h1:N6y/pJk8buWs9NY5ERU2HSMfm+IuD/OtfdAnq6kESPw= +go.yaml.in/yaml/v3 v3.0.5/go.mod h1:HVTZu1O7/Vkt2N+BFy8Zza+lnLsABggaTM2ZpNIGuKg= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.57.0 h1:3ZVCjf8Ggz7zneR/EHRVx68Ctf+2pmIMP2UFhh9cC6M= +golang.org/x/crypto v0.57.0/go.mod h1:Fdz0i5U6CoizGwLda9DttjSk6qlZo25zYNtR+ycvuZA= +golang.org/x/exp v0.0.0-20260824195058-e88cd73687aa h1:QSyA8ishJCyT21kER9KwNt0b7BM3iRK4x9QXhjN5Fdk= +golang.org/x/exp v0.0.0-20260824195058-e88cd73687aa/go.mod h1:zeBbvyFKDaLwa7CH/zI8KXt7gTl14SF7sO08Pl5jBCM= +golang.org/x/image v0.47.0 h1:za/8gVz++PPZqmZJBNSISICN5Rrj5zixP/8K++fgmqo= +golang.org/x/image v0.47.0/go.mod h1:IkN5o4A7vq55vXN8FWjjnhg9Rs2GOtffqsSi9mWAKYE= +golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= +golang.org/x/mod v0.41.0 h1:qJmnOUb4YB+FsEuM3HcWucdZASCPGhsX6uljO6pog0c= +golang.org/x/mod v0.41.0/go.mod h1:Ek9pY8RKWXwsWvd3rQiHYtMqkjSUV+s1Rj7j4H5Ur6o= +golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.59.0 h1:5zfYln+w5XCxwrnMMJPufRgNoXEaGxl0wo5GqPXyues= +golang.org/x/net v0.59.0/go.mod h1:2DA/G1UfVbCpQPeWTmMPGY7Cs2PkBkwu743bVX5PIVg= +golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.24.0 h1:iqiDrGoDgyuvAKrhLQthUEzU/R378N78gXbBjxed7oA= +golang.org/x/sync v0.24.0/go.mod h1:sUUOizhqBxiL6pEWpqNLUiaJn1ShEbZ6BBqskPbjZm0= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.49.0 h1:XbzkgYJHdqh/8m2Uu0W/dQv8nktxx4BFHp1M0gROTXA= +golang.org/x/sys v0.49.0/go.mod h1:hNLxWAXmnKAxqDtdwIYC4bM9oQPEecfsnNMuSxOs3og= +golang.org/x/term v0.46.0 h1:3+OXuTbaKDgwk8jTi3aSLHRlmWqHEUDUtxnbFigO4YE= +golang.org/x/term v0.46.0/go.mod h1:+K02xbkittuwc0Am4abfA3Fc+XRGXkvBXNO88NCXPoc= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.43.0 h1:1QivrlhwAsnMOcqgOdl9my7s9OyZl8O5/UGUTJVXoWc= +golang.org/x/text v0.43.0/go.mod h1:hbSIYA/amXcRXTFSZqh8tWHEoqRvvbKPJ2uz/KU+a+s= +golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +golang.org/x/tools v0.0.0-20191029041327-9cc4af7d6b2c/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191108193012-7d206e10da11/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.51.0 h1:k4Xc/1Om9jwkBJBo4NVLMSARBoWtK10mx+W5BnXCeAI= +golang.org/x/tools v0.51.0/go.mod h1:9eEncMayCV6zRMGhR5eZEC2iBx98qWcF1HZ9Z7wJOoA= +golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +gonum.org/v1/gonum v0.17.0 h1:VbpOemQlsSMrYmn7T2OUvQ4dqxQXU+ouZFQsZOx50z4= +gonum.org/v1/gonum v0.17.0/go.mod h1:El3tOrEuMpv2UdMrbNlKEh9vd86bmQ6vqIcDwxEOc1E= +google.golang.org/genproto/googleapis/api v0.0.0-20260928230214-8a89bd6388cc h1:rZHRz0ogq4Pid1IKtA/ivHi8XONVF5tqUQXA2TtgpkE= +google.golang.org/genproto/googleapis/api v0.0.0-20260928230214-8a89bd6388cc/go.mod h1:K/n0XLazCJHjD73YuMyNJsN38BPPy1kfFnKxUXaThFU= +google.golang.org/genproto/googleapis/rpc v0.0.0-20260928230214-8a89bd6388cc h1:4bNTbnb44EqGVy9HaQxSY2jnafSUdgV3qHtedvNpDKg= +google.golang.org/genproto/googleapis/rpc v0.0.0-20260928230214-8a89bd6388cc/go.mod h1:OaIUM3+LpYcK2GXM4FTmhWoIq371Owdr+Cc7/BsYHHc= +google.golang.org/grpc v1.83.2 h1:EManeRomTObA0BU7I8vXgg/78uE5MJ9M8B39EX2WscU= +google.golang.org/grpc v1.83.2/go.mod h1:YPI1hK3kDked6iHvgX3tR0y+nX/qpMFKhPgFsokw1S8= +google.golang.org/protobuf v1.36.12 h1:pJOKDDOyeXErUroCihFAd5LQuwXBSpVnKGrj5o/fwxc= +google.golang.org/protobuf v1.36.12/go.mod h1:HTf+CrKn2C3g5S8VImy6tdcUvCska2kB7j23XfzDpco= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= +gopkg.in/natefinch/lumberjack.v2 v2.0.0/go.mod h1:l0ndWWf7gzL7RNwBG7wST/UCcT4T24xpD6X8LsfU/+k= +gopkg.in/natefinch/lumberjack.v2 v2.2.1 h1:bBRl1b0OH9s/DuPhuXpNl+VtCaJXFZ5/uEFST95x9zc= +gopkg.in/natefinch/lumberjack.v2 v2.2.1/go.mod h1:YD8tP3GAjkrDg1eZH7EGmyESg/lsYskCTPBJVb9jqSc= +gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= +gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +modernc.org/libc v1.75.6 h1:yKk8qo+Di4gkmvRboK8ocCqH22FiUCR6jRy2OwtCRus= +modernc.org/libc v1.75.6/go.mod h1:bO5o2ztHxBb2rjz0PgdHN0sSMw57CgxGFLZ3Qd/QpVQ= +modernc.org/mathutil v1.7.1 h1:GCZVGXdaN8gTqB1Mf/usp1Y/hSqgI2vAGGP4jZMCxOU= +modernc.org/mathutil v1.7.1/go.mod h1:4p5IwJITfppl0G4sUEDtCr4DthTaT47/N3aT6MhfgJg= +modernc.org/memory v1.12.1 h1:nFMiWrpStgZczNl6XI9GnIk/rWhYIyHGUaR04pGbp9g= +modernc.org/memory v1.12.1/go.mod h1:/JP4VbVC+K5sU2wZi9bHoq2MAkCnrt2r98UGeSK7Mjw= +modernc.org/sqlite v1.57.0 h1:qNQP6xnx5M0ISNtlnxoOX0+cD5bJ0/gr9aMmndFczzg= +modernc.org/sqlite v1.57.0/go.mod h1:yCJ2cmAaIkHQ25oXWrF8H4O1lIfPYPR26yCEDj2P3pQ= diff --git a/infra/README.md b/infra/README.md index 5a39e86..03e303c 100644 --- a/infra/README.md +++ b/infra/README.md @@ -1,7 +1,18 @@ -# Инфраструктура студента +# Инфраструктура lab6 -Здесь разместите конфигурации выбранных сервисов; основную топологию — в корневом compose.yaml/stack.yaml. `compose.example.yaml` — только worksheet ролей и намеренно не запускается. `contracts/infrastructure.json` задаёт минимальные роли, не готовые образы/пароли. - -В REPORT.md сопоставьте роль → service name → версия/digest → health/readiness → volume → сеть/порт → способ передачи credentials. Приведите bootstrap (schema, bucket, broker topology, а с lab6 provisioning) и безопасное повторение этих команд. - -Приложение строится из исходников. Не используйте заранее существующий образ преподавательского сервера вместо своей реализации. Restart hook перезапускает все соответствующие stores с volumes; failover hook останавливает только заданную API-реплику. +- `otel/collector.yaml` — OTLP receivers, memory_limiter (140 MiB), batch, + bounded Loki/Tempo exporter queues (`sizer: bytes`), Prometheus exporter + `:8889`, self-metrics `:8888`, health `:13133`. +- `prometheus/` — scrape config (collector, collector-self, HAProxy, RabbitMQ), + 7d/2GB retention, SLO recording rules and alerts. +- `loki/loki.yaml` — filesystem, schema v13, 168h retention, OTLP mapping with + only `service.name`/`deployment.environment.name` as index labels. +- `tempo/tempo.yaml` — local storage, OTLP, 72h block retention. +- `grafana/` — provisioned datasources (Prometheus/Loki/Tempo), dashboard + provider and JSON dashboards; admin password only in gitignored + `secrets/grafana.env`. +- `rabbitmq/rabbitmq.conf` — per-object Prometheus metrics so `queue` is a + real label for depth/age panels. +- `runbooks/` — DB availability, queue lag, API errors, telemetry backend down. +- cAdvisor не используется: контейнерные CPU/RAM приложения снимаются из + cgroup v2, брокер — из `rabbitmq_prometheus`; Docker socket не монтируется. diff --git a/infra/grafana/dashboards/api-overview.json b/infra/grafana/dashboards/api-overview.json new file mode 100644 index 0000000..36d5fa8 --- /dev/null +++ b/infra/grafana/dashboards/api-overview.json @@ -0,0 +1,612 @@ +{ + "annotations": { + "list": [] + }, + "editable": false, + "graphTooltip": 1, + "panels": [ + { + "id": 1, + "title": "API RPS", + "type": "timeseries", + "gridPos": { + "h": 7, + "w": 12, + "x": 0, + "y": 0 + }, + "datasource": { + "type": "prometheus", + "uid": "prometheus" + }, + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "prometheus" + }, + "expr": "sum(rate(http_server_request_duration_seconds_count[5m]))", + "legendFormat": "rps", + "refId": "A", + "range": true + } + ], + "fieldConfig": { + "defaults": { + "unit": "reqps" + }, + "overrides": [] + }, + "options": {} + }, + { + "id": 2, + "title": "API error ratio (edge SLI)", + "type": "timeseries", + "gridPos": { + "h": 7, + "w": 12, + "x": 12, + "y": 0 + }, + "datasource": { + "type": "prometheus", + "uid": "prometheus" + }, + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "prometheus" + }, + "expr": "slo:api_error_ratio:5m", + "legendFormat": "5xx ratio", + "refId": "A", + "range": true + }, + { + "datasource": { + "type": "prometheus", + "uid": "prometheus" + }, + "expr": "slo:api_error_ratio:1h", + "legendFormat": "1h", + "refId": "B", + "range": true + } + ], + "fieldConfig": { + "defaults": { + "unit": "percentunit" + }, + "overrides": [] + }, + "options": {} + }, + { + "id": 3, + "title": "API latency p50/p95/p99", + "type": "timeseries", + "gridPos": { + "h": 7, + "w": 12, + "x": 0, + "y": 7 + }, + "datasource": { + "type": "prometheus", + "uid": "prometheus" + }, + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "prometheus" + }, + "expr": "histogram_quantile(0.50, sum by (le) (rate(http_server_request_duration_seconds_bucket[5m])))", + "legendFormat": "p50", + "refId": "A", + "range": true + }, + { + "datasource": { + "type": "prometheus", + "uid": "prometheus" + }, + "expr": "histogram_quantile(0.95, sum by (le) (rate(http_server_request_duration_seconds_bucket[5m])))", + "legendFormat": "p95", + "refId": "B", + "range": true + }, + { + "datasource": { + "type": "prometheus", + "uid": "prometheus" + }, + "expr": "histogram_quantile(0.99, sum by (le) (rate(http_server_request_duration_seconds_bucket[5m])))", + "legendFormat": "p99", + "refId": "C", + "range": true + } + ], + "fieldConfig": { + "defaults": { + "unit": "s" + }, + "overrides": [] + }, + "options": {} + }, + { + "id": 4, + "title": "Jobs processed / failed / retried", + "type": "timeseries", + "gridPos": { + "h": 7, + "w": 12, + "x": 12, + "y": 7 + }, + "datasource": { + "type": "prometheus", + "uid": "prometheus" + }, + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "prometheus" + }, + "expr": "sum(rate(messenger_jobs_processed_total{outcome=\"succeeded\"}[5m]))", + "legendFormat": "succeeded", + "refId": "A", + "range": true + }, + { + "datasource": { + "type": "prometheus", + "uid": "prometheus" + }, + "expr": "sum(rate(messenger_jobs_processed_total{outcome=\"failed\"}[5m]))", + "legendFormat": "failed", + "refId": "B", + "range": true + }, + { + "datasource": { + "type": "prometheus", + "uid": "prometheus" + }, + "expr": "sum(rate(messenger_jobs_processed_total{outcome=\"retried\"}[5m]))", + "legendFormat": "retried", + "refId": "C", + "range": true + } + ], + "fieldConfig": { + "defaults": { + "unit": "ops" + }, + "overrides": [] + }, + "options": {} + }, + { + "id": 5, + "title": "Time-to-ready p50/p95/p99", + "type": "timeseries", + "gridPos": { + "h": 7, + "w": 12, + "x": 0, + "y": 14 + }, + "datasource": { + "type": "prometheus", + "uid": "prometheus" + }, + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "prometheus" + }, + "expr": "histogram_quantile(0.50, sum by (le) (rate(messenger_job_time_to_ready_seconds_bucket[5m])))", + "legendFormat": "p50", + "refId": "A", + "range": true + }, + { + "datasource": { + "type": "prometheus", + "uid": "prometheus" + }, + "expr": "histogram_quantile(0.95, sum by (le) (rate(messenger_job_time_to_ready_seconds_bucket[5m])))", + "legendFormat": "p95", + "refId": "B", + "range": true + }, + { + "datasource": { + "type": "prometheus", + "uid": "prometheus" + }, + "expr": "histogram_quantile(0.99, sum by (le) (rate(messenger_job_time_to_ready_seconds_bucket[5m])))", + "legendFormat": "p99", + "refId": "C", + "range": true + } + ], + "fieldConfig": { + "defaults": { + "unit": "s" + }, + "overrides": [] + }, + "options": {} + }, + { + "id": 6, + "title": "TTR bad ratio (missed / (within 30s + missed))", + "type": "timeseries", + "gridPos": { + "h": 7, + "w": 12, + "x": 12, + "y": 14 + }, + "datasource": { + "type": "prometheus", + "uid": "prometheus" + }, + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "prometheus" + }, + "expr": "slo:job_ttr_bad_ratio:5m", + "legendFormat": "5m", + "refId": "A", + "range": true + }, + { + "datasource": { + "type": "prometheus", + "uid": "prometheus" + }, + "expr": "slo:job_ttr_bad_ratio:1h", + "legendFormat": "1h", + "refId": "B", + "range": true + } + ], + "fieldConfig": { + "defaults": { + "unit": "percentunit" + }, + "overrides": [] + }, + "options": {} + }, + { + "id": 7, + "title": "Queue depth", + "type": "timeseries", + "gridPos": { + "h": 7, + "w": 8, + "x": 0, + "y": 21 + }, + "datasource": { + "type": "prometheus", + "uid": "prometheus" + }, + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "prometheus" + }, + "expr": "max(rabbitmq_queue_messages_ready{queue=\"attachment.process.v1\"})", + "legendFormat": "ready", + "refId": "A", + "range": true + } + ], + "fieldConfig": { + "defaults": { + "unit": "short" + }, + "overrides": [] + }, + "options": {} + }, + { + "id": 8, + "title": "Oldest job age", + "type": "timeseries", + "gridPos": { + "h": 7, + "w": 8, + "x": 8, + "y": 21 + }, + "datasource": { + "type": "prometheus", + "uid": "prometheus" + }, + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "prometheus" + }, + "expr": "max(messenger_queue_oldest_job_age_seconds)", + "legendFormat": "oldest job seconds", + "refId": "A", + "range": true + } + ], + "fieldConfig": { + "defaults": { + "unit": "s" + }, + "overrides": [] + }, + "options": {} + }, + { + "id": 9, + "title": "Worker saturation", + "type": "timeseries", + "gridPos": { + "h": 7, + "w": 8, + "x": 16, + "y": 21 + }, + "datasource": { + "type": "prometheus", + "uid": "prometheus" + }, + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "prometheus" + }, + "expr": "sum(messenger_worker_busy)", + "legendFormat": "busy", + "refId": "A", + "range": true + }, + { + "datasource": { + "type": "prometheus", + "uid": "prometheus" + }, + "expr": "sum(messenger_worker_capacity)", + "legendFormat": "capacity", + "refId": "B", + "range": true + } + ], + "fieldConfig": { + "defaults": { + "unit": "short" + }, + "overrides": [] + }, + "options": {} + }, + { + "id": 10, + "title": "DB pool used / idle / max", + "type": "timeseries", + "gridPos": { + "h": 7, + "w": 12, + "x": 0, + "y": 28 + }, + "datasource": { + "type": "prometheus", + "uid": "prometheus" + }, + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "prometheus" + }, + "expr": "sum(messenger_db_pool_used)", + "legendFormat": "used", + "refId": "A", + "range": true + }, + { + "datasource": { + "type": "prometheus", + "uid": "prometheus" + }, + "expr": "sum(messenger_db_pool_idle)", + "legendFormat": "idle", + "refId": "B", + "range": true + }, + { + "datasource": { + "type": "prometheus", + "uid": "prometheus" + }, + "expr": "sum(messenger_db_pool_max)", + "legendFormat": "max", + "refId": "C", + "range": true + } + ], + "fieldConfig": { + "defaults": { + "unit": "short" + }, + "overrides": [] + }, + "options": {} + }, + { + "id": 11, + "title": "DB empty acquire / wait", + "type": "timeseries", + "gridPos": { + "h": 7, + "w": 12, + "x": 12, + "y": 28 + }, + "datasource": { + "type": "prometheus", + "uid": "prometheus" + }, + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "prometheus" + }, + "expr": "sum(rate(messenger_db_pool_empty_acquire_total[5m]))", + "legendFormat": "empty acquire/s", + "refId": "A", + "range": true + }, + { + "datasource": { + "type": "prometheus", + "uid": "prometheus" + }, + "expr": "sum(rate(messenger_db_pool_empty_acquire_wait_seconds_total[5m]))", + "legendFormat": "wait seconds/s", + "refId": "B", + "range": true + } + ], + "fieldConfig": { + "defaults": { + "unit": "short" + }, + "overrides": [] + }, + "options": {} + }, + { + "id": 12, + "title": "API logs", + "type": "logs", + "gridPos": { + "h": 9, + "w": 12, + "x": 0, + "y": 35 + }, + "datasource": { + "type": "loki", + "uid": "loki" + }, + "targets": [ + { + "datasource": { + "type": "loki", + "uid": "loki" + }, + "expr": "{service_name=\"messenger-api\"}", + "refId": "A", + "queryType": "range" + } + ], + "fieldConfig": { + "defaults": {}, + "overrides": [] + }, + "options": {} + }, + { + "id": 13, + "title": "Traces: job.process", + "type": "traces", + "gridPos": { + "h": 9, + "w": 12, + "x": 12, + "y": 35 + }, + "datasource": { + "type": "tempo", + "uid": "tempo" + }, + "targets": [ + { + "datasource": { + "type": "tempo", + "uid": "tempo" + }, + "query": "{ name = \"job.process\" }", + "refId": "A", + "queryType": "traceql" + } + ], + "fieldConfig": { + "defaults": {}, + "overrides": [] + }, + "options": {} + }, + { + "id": 14, + "type": "stat", + "title": "API error budget remaining (7d)", + "datasource": { + "type": "prometheus", + "uid": "prometheus" + }, + "targets": [ + { + "expr": "slo:api_budget_remaining:7d", + "refId": "A", + "legendFormat": "remaining" + } + ], + "fieldConfig": { + "defaults": { + "unit": "percentunit", + "min": 0, + "max": 1 + }, + "overrides": [] + }, + "gridPos": { + "h": 6, + "w": 6, + "x": 0, + "y": 0 + } + } + ], + "refresh": "5s", + "schemaVersion": 39, + "tags": [ + "lab6", + "messenger" + ], + "templating": { + "list": [] + }, + "time": { + "from": "now-30m", + "to": "now" + }, + "timezone": "browser", + "title": "Lab6 — messenger observability", + "uid": "lab6-overview", + "version": 1 +} \ No newline at end of file diff --git a/infra/grafana/dashboards/infra-saturation.json b/infra/grafana/dashboards/infra-saturation.json new file mode 100644 index 0000000..c9c89e3 --- /dev/null +++ b/infra/grafana/dashboards/infra-saturation.json @@ -0,0 +1,452 @@ +{ + "annotations": { + "list": [] + }, + "editable": false, + "panels": [ + { + "id": 1, + "title": "API RPS", + "type": "timeseries", + "gridPos": { + "h": 7, + "w": 12, + "x": 0, + "y": 0 + }, + "datasource": { + "type": "prometheus", + "uid": "prometheus" + }, + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "prometheus" + }, + "expr": "sum(rate(http_server_request_duration_seconds_count[5m]))", + "legendFormat": "rps", + "refId": "A", + "range": true + } + ], + "fieldConfig": { + "defaults": { + "unit": "reqps" + }, + "overrides": [] + }, + "options": {} + }, + { + "id": 3, + "title": "API latency p50/p95/p99", + "type": "timeseries", + "gridPos": { + "h": 7, + "w": 12, + "x": 0, + "y": 7 + }, + "datasource": { + "type": "prometheus", + "uid": "prometheus" + }, + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "prometheus" + }, + "expr": "histogram_quantile(0.50, sum by (le) (rate(http_server_request_duration_seconds_bucket[5m])))", + "legendFormat": "p50", + "refId": "A", + "range": true + }, + { + "datasource": { + "type": "prometheus", + "uid": "prometheus" + }, + "expr": "histogram_quantile(0.95, sum by (le) (rate(http_server_request_duration_seconds_bucket[5m])))", + "legendFormat": "p95", + "refId": "B", + "range": true + }, + { + "datasource": { + "type": "prometheus", + "uid": "prometheus" + }, + "expr": "histogram_quantile(0.99, sum by (le) (rate(http_server_request_duration_seconds_bucket[5m])))", + "legendFormat": "p99", + "refId": "C", + "range": true + } + ], + "fieldConfig": { + "defaults": { + "unit": "s" + }, + "overrides": [] + }, + "options": {} + }, + { + "id": 10, + "title": "DB pool used / idle / max", + "type": "timeseries", + "gridPos": { + "h": 7, + "w": 12, + "x": 0, + "y": 28 + }, + "datasource": { + "type": "prometheus", + "uid": "prometheus" + }, + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "prometheus" + }, + "expr": "sum(messenger_db_pool_used)", + "legendFormat": "used", + "refId": "A", + "range": true + }, + { + "datasource": { + "type": "prometheus", + "uid": "prometheus" + }, + "expr": "sum(messenger_db_pool_idle)", + "legendFormat": "idle", + "refId": "B", + "range": true + }, + { + "datasource": { + "type": "prometheus", + "uid": "prometheus" + }, + "expr": "sum(messenger_db_pool_max)", + "legendFormat": "max", + "refId": "C", + "range": true + } + ], + "fieldConfig": { + "defaults": { + "unit": "none" + }, + "overrides": [] + }, + "options": {} + }, + { + "id": 11, + "title": "DB empty acquire / wait", + "type": "timeseries", + "gridPos": { + "h": 7, + "w": 12, + "x": 12, + "y": 28 + }, + "datasource": { + "type": "prometheus", + "uid": "prometheus" + }, + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "prometheus" + }, + "expr": "sum(rate(messenger_db_pool_empty_acquire_total[5m]))", + "legendFormat": "empty acquire/s", + "refId": "A", + "range": true + }, + { + "datasource": { + "type": "prometheus", + "uid": "prometheus" + }, + "expr": "sum(rate(messenger_db_pool_empty_acquire_wait_seconds_total[5m]))", + "legendFormat": "wait seconds/s", + "refId": "B", + "range": true + } + ], + "fieldConfig": { + "defaults": { + "unit": "none" + }, + "overrides": [ + { + "matcher": { + "id": "byFrameRefID", + "options": "A" + }, + "properties": [ + { + "id": "unit", + "value": "ops" + } + ] + }, + { + "matcher": { + "id": "byFrameRefID", + "options": "B" + }, + "properties": [ + { + "id": "unit", + "value": "s" + } + ] + } + ] + }, + "options": {} + }, + { + "id": 12, + "title": "API logs", + "type": "logs", + "gridPos": { + "h": 9, + "w": 12, + "x": 0, + "y": 35 + }, + "datasource": { + "type": "loki", + "uid": "loki" + }, + "targets": [ + { + "datasource": { + "type": "loki", + "uid": "loki" + }, + "expr": "{service_name=\"messenger-api\"}", + "refId": "A", + "queryType": "range" + } + ], + "fieldConfig": { + "defaults": {}, + "overrides": [] + }, + "options": {} + }, + { + "id": 30, + "title": "Process memory usage", + "type": "timeseries", + "gridPos": { + "h": 7, + "w": 12, + "x": 0, + "y": 28 + }, + "datasource": { + "type": "prometheus", + "uid": "prometheus" + }, + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "prometheus" + }, + "expr": "sum by (service_name) (messenger_process_memory_usage_bytes)", + "legendFormat": "{{service_name}}", + "refId": "A", + "range": true + } + ], + "fieldConfig": { + "defaults": { + "unit": "bytes" + }, + "overrides": [] + }, + "options": {} + }, + { + "id": 31, + "title": "Collector exporter queue", + "type": "timeseries", + "gridPos": { + "h": 7, + "w": 12, + "x": 12, + "y": 28 + }, + "datasource": { + "type": "prometheus", + "uid": "prometheus" + }, + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "prometheus" + }, + "expr": "max(otelcol_exporter_queue_size)", + "legendFormat": "queue", + "refId": "A", + "range": true + } + ], + "fieldConfig": { + "defaults": { + "unit": "bytes" + }, + "overrides": [] + }, + "options": {} + }, + { + "id": 32, + "title": "Scrape targets up", + "type": "timeseries", + "gridPos": { + "h": 7, + "w": 12, + "x": 0, + "y": 35 + }, + "datasource": { + "type": "prometheus", + "uid": "prometheus" + }, + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "prometheus" + }, + "expr": "up", + "legendFormat": "{{job}}", + "refId": "A", + "range": true + } + ], + "fieldConfig": { + "defaults": { + "unit": "none" + }, + "overrides": [] + }, + "options": {} + }, + { + "id": 33, + "type": "timeseries", + "title": "Process CPU by service", + "datasource": { + "type": "prometheus", + "uid": "prometheus" + }, + "targets": [ + { + "expr": "sum by (service_name) (rate(messenger_process_cpu_seconds_total[5m]))", + "refId": "A", + "legendFormat": "{{service_name}}" + } + ], + "fieldConfig": { + "defaults": { + "unit": "cores" + }, + "overrides": [] + }, + "gridPos": { + "h": 7, + "w": 12, + "x": 0, + "y": 0 + } + }, + { + "id": 34, + "type": "timeseries", + "title": "Process memory vs limit", + "datasource": { + "type": "prometheus", + "uid": "prometheus" + }, + "targets": [ + { + "expr": "sum by (service_name) (messenger_process_memory_usage_bytes) / clamp_min(sum by (service_name) (messenger_process_memory_limit_bytes), 1)", + "refId": "A", + "legendFormat": "{{service_name}}" + } + ], + "fieldConfig": { + "defaults": { + "unit": "percentunit" + }, + "overrides": [] + }, + "gridPos": { + "h": 7, + "w": 12, + "x": 0, + "y": 0 + } + }, + { + "id": 35, + "type": "timeseries", + "title": "RPS by route and status", + "datasource": { + "type": "prometheus", + "uid": "prometheus" + }, + "targets": [ + { + "expr": "sum by (http_route,http_response_status_class) (rate(http_server_request_duration_seconds_count[5m]))", + "refId": "A", + "legendFormat": "{{http_route}} {{http_response_status_code}}" + } + ], + "fieldConfig": { + "defaults": { + "unit": "reqps" + }, + "overrides": [] + }, + "gridPos": { + "h": 7, + "w": 12, + "x": 0, + "y": 0 + } + } + ], + "refresh": "5s", + "schemaVersion": 39, + "tags": [ + "lab6", + "infra" + ], + "templating": { + "list": [] + }, + "time": { + "from": "now-30m", + "to": "now" + }, + "title": "Lab6 — infrastructure saturation", + "uid": "lab6-infra", + "version": 1 +} \ No newline at end of file diff --git a/infra/grafana/dashboards/jobs-pipeline.json b/infra/grafana/dashboards/jobs-pipeline.json new file mode 100644 index 0000000..f9ff2a4 --- /dev/null +++ b/infra/grafana/dashboards/jobs-pipeline.json @@ -0,0 +1,430 @@ +{ + "annotations": { + "list": [] + }, + "editable": false, + "panels": [ + { + "id": 4, + "title": "Jobs processed / failed / retried", + "type": "timeseries", + "gridPos": { + "h": 7, + "w": 12, + "x": 12, + "y": 7 + }, + "datasource": { + "type": "prometheus", + "uid": "prometheus" + }, + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "prometheus" + }, + "expr": "sum(rate(messenger_jobs_processed_total{outcome=\"succeeded\"}[5m]))", + "legendFormat": "succeeded", + "refId": "A", + "range": true + }, + { + "datasource": { + "type": "prometheus", + "uid": "prometheus" + }, + "expr": "sum(rate(messenger_jobs_processed_total{outcome=\"failed\"}[5m]))", + "legendFormat": "failed", + "refId": "B", + "range": true + }, + { + "datasource": { + "type": "prometheus", + "uid": "prometheus" + }, + "expr": "sum(rate(messenger_jobs_processed_total{outcome=\"retried\"}[5m]))", + "legendFormat": "retried", + "refId": "C", + "range": true + } + ], + "fieldConfig": { + "defaults": { + "unit": "ops" + }, + "overrides": [] + }, + "options": {} + }, + { + "id": 5, + "title": "Time-to-ready p50/p95/p99", + "type": "timeseries", + "gridPos": { + "h": 7, + "w": 12, + "x": 0, + "y": 14 + }, + "datasource": { + "type": "prometheus", + "uid": "prometheus" + }, + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "prometheus" + }, + "expr": "histogram_quantile(0.50, sum by (le) (rate(messenger_job_time_to_ready_seconds_bucket[5m])))", + "legendFormat": "p50", + "refId": "A", + "range": true + }, + { + "datasource": { + "type": "prometheus", + "uid": "prometheus" + }, + "expr": "histogram_quantile(0.95, sum by (le) (rate(messenger_job_time_to_ready_seconds_bucket[5m])))", + "legendFormat": "p95", + "refId": "B", + "range": true + }, + { + "datasource": { + "type": "prometheus", + "uid": "prometheus" + }, + "expr": "histogram_quantile(0.99, sum by (le) (rate(messenger_job_time_to_ready_seconds_bucket[5m])))", + "legendFormat": "p99", + "refId": "C", + "range": true + } + ], + "fieldConfig": { + "defaults": { + "unit": "s" + }, + "overrides": [] + }, + "options": {} + }, + { + "id": 6, + "title": "TTR bad ratio (missed / (within 30s + missed))", + "type": "timeseries", + "gridPos": { + "h": 7, + "w": 12, + "x": 12, + "y": 14 + }, + "datasource": { + "type": "prometheus", + "uid": "prometheus" + }, + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "prometheus" + }, + "expr": "slo:job_ttr_bad_ratio:5m", + "legendFormat": "5m", + "refId": "A", + "range": true + }, + { + "datasource": { + "type": "prometheus", + "uid": "prometheus" + }, + "expr": "slo:job_ttr_bad_ratio:1h", + "legendFormat": "1h", + "refId": "B", + "range": true + } + ], + "fieldConfig": { + "defaults": { + "unit": "percentunit" + }, + "overrides": [] + }, + "options": {} + }, + { + "id": 7, + "title": "Queue depth", + "type": "timeseries", + "gridPos": { + "h": 7, + "w": 8, + "x": 0, + "y": 21 + }, + "datasource": { + "type": "prometheus", + "uid": "prometheus" + }, + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "prometheus" + }, + "expr": "max(rabbitmq_queue_messages_ready{queue=\"attachment.process.v1\"})", + "legendFormat": "ready", + "refId": "A", + "range": true + } + ], + "fieldConfig": { + "defaults": { + "unit": "short" + }, + "overrides": [] + }, + "options": {} + }, + { + "id": 8, + "title": "Oldest job age", + "type": "timeseries", + "gridPos": { + "h": 7, + "w": 8, + "x": 8, + "y": 21 + }, + "datasource": { + "type": "prometheus", + "uid": "prometheus" + }, + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "prometheus" + }, + "expr": "max(messenger_queue_oldest_job_age_seconds)", + "legendFormat": "oldest job seconds", + "refId": "A", + "range": true + } + ], + "fieldConfig": { + "defaults": { + "unit": "s" + }, + "overrides": [] + }, + "options": {} + }, + { + "id": 9, + "title": "Worker saturation", + "type": "timeseries", + "gridPos": { + "h": 7, + "w": 8, + "x": 16, + "y": 21 + }, + "datasource": { + "type": "prometheus", + "uid": "prometheus" + }, + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "prometheus" + }, + "expr": "sum(messenger_worker_busy)", + "legendFormat": "busy", + "refId": "A", + "range": true + }, + { + "datasource": { + "type": "prometheus", + "uid": "prometheus" + }, + "expr": "sum(messenger_worker_capacity)", + "legendFormat": "capacity", + "refId": "B", + "range": true + } + ], + "fieldConfig": { + "defaults": { + "unit": "short" + }, + "overrides": [] + }, + "options": {} + }, + { + "id": 10, + "title": "DB pool used / idle / max", + "type": "timeseries", + "gridPos": { + "h": 7, + "w": 12, + "x": 0, + "y": 28 + }, + "datasource": { + "type": "prometheus", + "uid": "prometheus" + }, + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "prometheus" + }, + "expr": "sum(messenger_db_pool_used)", + "legendFormat": "used", + "refId": "A", + "range": true + }, + { + "datasource": { + "type": "prometheus", + "uid": "prometheus" + }, + "expr": "sum(messenger_db_pool_idle)", + "legendFormat": "idle", + "refId": "B", + "range": true + }, + { + "datasource": { + "type": "prometheus", + "uid": "prometheus" + }, + "expr": "sum(messenger_db_pool_max)", + "legendFormat": "max", + "refId": "C", + "range": true + } + ], + "fieldConfig": { + "defaults": { + "unit": "short" + }, + "overrides": [] + }, + "options": {} + }, + { + "id": 20, + "title": "Job duration p50/p95/p99", + "type": "timeseries", + "gridPos": { + "h": 7, + "w": 12, + "x": 0, + "y": 42 + }, + "datasource": { + "type": "prometheus", + "uid": "prometheus" + }, + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "prometheus" + }, + "expr": "histogram_quantile(0.50, sum by (le) (rate(messenger_job_duration_seconds_bucket[5m])))", + "legendFormat": "p50", + "refId": "A", + "range": true + }, + { + "datasource": { + "type": "prometheus", + "uid": "prometheus" + }, + "expr": "histogram_quantile(0.95, sum by (le) (rate(messenger_job_duration_seconds_bucket[5m])))", + "legendFormat": "p95", + "refId": "B", + "range": true + }, + { + "datasource": { + "type": "prometheus", + "uid": "prometheus" + }, + "expr": "histogram_quantile(0.99, sum by (le) (rate(messenger_job_duration_seconds_bucket[5m])))", + "legendFormat": "p99", + "refId": "C", + "range": true + } + ], + "fieldConfig": { + "defaults": { + "unit": "s" + }, + "overrides": [] + }, + "options": {} + }, + { + "id": 21, + "title": "Overdue jobs (>30s)", + "type": "timeseries", + "gridPos": { + "h": 7, + "w": 12, + "x": 12, + "y": 42 + }, + "datasource": { + "type": "prometheus", + "uid": "prometheus" + }, + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "prometheus" + }, + "expr": "max(messenger_jobs_overdue)", + "legendFormat": "overdue", + "refId": "A", + "range": true + } + ], + "fieldConfig": { + "defaults": { + "unit": "short" + }, + "overrides": [] + }, + "options": {} + } + ], + "refresh": "5s", + "schemaVersion": 39, + "tags": [ + "lab6", + "jobs" + ], + "templating": { + "list": [] + }, + "time": { + "from": "now-30m", + "to": "now" + }, + "title": "Lab6 — jobs and queue", + "uid": "lab6-jobs", + "version": 1 +} diff --git a/infra/grafana/provisioning/dashboards/dashboards.yaml b/infra/grafana/provisioning/dashboards/dashboards.yaml new file mode 100644 index 0000000..9701b2a --- /dev/null +++ b/infra/grafana/provisioning/dashboards/dashboards.yaml @@ -0,0 +1,10 @@ +apiVersion: 1 +providers: + - name: lab6 + orgId: 1 + folder: Lab6 + type: file + disableDeletion: false + updateIntervalSeconds: 10 + options: + path: /var/lib/grafana/dashboards diff --git a/infra/grafana/provisioning/datasources/datasources.yaml b/infra/grafana/provisioning/datasources/datasources.yaml new file mode 100644 index 0000000..f2c113a --- /dev/null +++ b/infra/grafana/provisioning/datasources/datasources.yaml @@ -0,0 +1,36 @@ +apiVersion: 1 +datasources: + - name: Prometheus + uid: prometheus + type: prometheus + access: proxy + url: http://prometheus:9090 + isDefault: true + editable: false + - name: Loki + uid: loki + type: loki + access: proxy + url: http://loki:3100 + editable: false + jsonData: + derivedFields: + - datasourceUid: tempo + matcherType: label + matcherRegex: trace_id + url: "$${__value.raw}" + urlDisplayLabel: Open trace + - name: Tempo + uid: tempo + type: tempo + access: proxy + url: http://tempo:3200 + editable: false + jsonData: + tracesToLogsV2: + datasourceUid: loki + filterByTraceID: true + filterBySpanID: false + tags: + - key: service.name + value: service_name diff --git a/infra/lb/haproxy.cfg b/infra/lb/haproxy.cfg new file mode 100644 index 0000000..d0ffe14 --- /dev/null +++ b/infra/lb/haproxy.cfg @@ -0,0 +1,92 @@ +# Load balancer for the lab3 stand (HAProxy, container `lb`). +# +# Почему активные проверки, а не пассивные: nginx OSS умел только пассивные, и +# реплика, которая осталась доступной по сети, но потеряла БД, продолжала получать +# трафик и отвечала 503 (измерено: 20 из 40 запросов /health/live). HAProxy сам +# опрашивает /health/ready и полностью убирает неготовую реплику из ротации. +# +# Почему повторы безопасны: `retry-on conn-failure` — повтор только когда +# соединение не установилось и запрос НЕ ушёл. Если запрос уже передан серверу, +# повтора нет, поэтому прозрачного дублирования POST (создание чата, сообщения) +# балансировщик не делает. Неопределённый результат повторяет клиент, а сообщение +# защищено обязательным Idempotency-Key (контракт 1.3.0). + +global + log stdout format raw local0 + maxconn 2048 + +defaults + mode http + log global + log-format "%ST %Tt %b" + option dontlognull + timeout connect 1s + timeout client 70s + timeout server 45s + # Проверка готовности: одна проба не может висеть дольше 1 с, поэтому при + # inter 2s fall 2 реплика уходит из ротации максимум за ~4 с, даже если она + # держит соединение открытым и не отвечает. + # + # timeout server увеличен для 10 MiB загрузок: spool + S3 Put не всегда + # укладываются в прежние 5 с под конкурентной нагрузкой. Readiness-проба + # остаётся с timeout check 1s, поэтому обнаружение мёртвой реплики не + # замедляется. + timeout check 1s + retry-on conn-failure + retries 2 + option redispatch + +resolvers docker + nameserver dns 127.0.0.11:53 + resolve_retries 3 + timeout resolve 1s + timeout retry 1s + hold valid 5s + hold nx 2s + hold timeout 1s + hold refused 1s + hold obsolete 5s + +backend api_backend + balance leastconn + # Период проверки 2 с; реплика исключается после 2 неудач (<=4 с) и + # возвращается в ротацию после 2 успехов (<=4 с). + option httpchk + http-check send meth GET uri /health/ready + http-check expect status 200 + # Одно имя -> все адреса реплик (общий network alias в compose.yaml), + # адреса переразрешаются каждые 5 с: масштабирование и замена контейнеров + # не зависят от их номеров и IP. + default-server check inter 2s fall 2 rise 2 resolvers docker resolve-prefer ipv4 init-addr none + # Слотов больше, чем типовых реплик (1/2/4 в треке 1): свободный слот нужен + # ещё и сценарию scripts/lb_readiness_check.sh, который поднимает рядом + # «неготовую» реплику. + server-template api 8 api-replica:8080 + +backend api_health + balance leastconn + # Dedicated backend for client readiness/liveness endpoints. Keeping it + # separate keeps /health traffic out of the API availability SLI. + option httpchk + http-check send meth GET uri /health/ready + http-check expect status 200 + default-server check inter 2s fall 2 rise 2 resolvers docker resolve-prefer ipv4 init-addr none + server-template api 8 api-replica:8080 + +frontend http_front + bind *:80 + use_backend api_health if { path_beg /health/ } + default_backend api_backend + +frontend stats_front + # Только для оператора и доказательств: видно, какие реплики UP/DOWN и почему. + bind *:8404 + # Built-in Prometheus exporter (HAProxy built with USE_PROMEX). The edge + # SLI uses backend api_backend; /health/* is routed to api_health and is not + # part of the availability numerator or denominator. + http-request use-service prometheus-exporter if { path /metrics } + stats enable + stats uri /stats + stats refresh 2s + monitor-uri /healthz + no log diff --git a/infra/loki/loki.yaml b/infra/loki/loki.yaml new file mode 100644 index 0000000..bbbe9d2 --- /dev/null +++ b/infra/loki/loki.yaml @@ -0,0 +1,65 @@ +auth_enabled: false + +server: + http_listen_port: 3100 + grpc_listen_port: 9096 + +common: + path_prefix: /loki + storage: + filesystem: + chunks_directory: /loki/chunks + rules_directory: /loki/rules + replication_factor: 1 + ring: + kvstore: + store: inmemory + +schema_config: + configs: + - from: 2024-01-01 + store: tsdb + object_store: filesystem + schema: v13 + index: + prefix: index_ + period: 24h + +storage_config: + filesystem: + directory: /loki/storage + tsdb_shipper: + active_index_directory: /loki/tsdb-index + cache_location: /loki/tsdb-cache + +limits_config: + retention_period: 168h + allow_structured_metadata: true + max_line_size: 32KB + max_line_size_truncate: true + otlp_config: + resource_attributes: + ignore_defaults: true + attributes_config: + - action: index_label + attributes: + - service.name + - deployment.environment.name + - action: structured_metadata + attributes: + - service.instance.id + - service.version + log_attributes: + - action: structured_metadata + regex: .* + +compactor: + working_directory: /loki/compactor + retention_enabled: true + delete_request_store: filesystem + +ruler: + storage: + type: local + local: + directory: /loki/rules diff --git a/infra/otel/README.md b/infra/otel/README.md index c46fe89..c636429 100644 --- a/infra/otel/README.md +++ b/infra/otel/README.md @@ -1,7 +1,13 @@ -# Конфигурация наблюдаемости — реализовать +# OTel Collector -Добавьте `collector.yaml` с OTLP receivers, processors и exporters выбранной версии Collector. Укажите явные bind endpoints, внутренние сети, memory limits/batch и поведение при backpressure по уровню. Сопоставьте все три pipeline с реально развёрнутыми backend. +`collector.yaml` — единственный OTLP-приёмник стенда. API/worker/relay шлют +traces/metrics/logs по HTTP `:4318`; Collector экспортирует: +- метрики — pull-exporter Prometheus `:8889` (Prometheus scrape); +- логи — OTLP HTTP в Loki `/otlp`; +- трассы — OTLP gRPC в Tempo `:4317`. -Добавьте конфигурации storage, Grafana provisioning/datasources, provisioning/dashboards и импортируемые dashboard JSON. На 4 — alert rules и runbooks. Пустой dashboard или debug exporter, который только печатает данные в stdout, не заменяют хранилища/доказательства из `contracts/observability.md`. - -Не публикуйте OTLP/metrics/административные ports в общую сеть без необходимости. В lab7 реализуйте TLS/mTLS по trust matrix; экспорт Authorization и message bodies запрещён. +`memory_limiter` ограничивает 140 MiB, batch — 5 с/1024, очереди Loki/Tempo +ограничены 10 MiB (`sizer: bytes`) и retry не дольше 30 с. Self-metrics +Collector отдаются на `:8888` отдельным scrape-job. OTLP-порты не публикуются +на host; Collector подключён к `default` и `observability`, backend'ы — только +к `observability`. TLS/auth относятся к lab7. diff --git a/infra/otel/collector.yaml b/infra/otel/collector.yaml new file mode 100644 index 0000000..c670256 --- /dev/null +++ b/infra/otel/collector.yaml @@ -0,0 +1,86 @@ +receivers: + otlp: + protocols: + grpc: + endpoint: 0.0.0.0:4317 + http: + endpoint: 0.0.0.0:4318 + +processors: + memory_limiter: + check_interval: 1s + # limit_mib, not limit_percentage: Docker Desktop cgroup limits are easy to + # misread and a percentage would fall back to the VM total. + limit_mib: 140 + spike_limit_mib: 40 + batch: + timeout: 5s + send_batch_size: 1024 + +exporters: + # Pull-based: no sending_queue/retry for this exporter. + prometheus: + endpoint: 0.0.0.0:8889 + translation_strategy: UnderscoreEscapingWithSuffixes + resource_constant_labels: + included: + - service.name + - service.instance.id + - deployment.environment.name + - service.version + otlp_http/loki: + endpoint: http://loki:3100/otlp + sending_queue: + enabled: true + sizer: bytes + queue_size: 10485760 + num_consumers: 2 + retry_on_failure: + enabled: true + initial_interval: 1s + max_interval: 5s + max_elapsed_time: 30s + timeout: 5s + otlp_grpc/tempo: + endpoint: tempo:4317 + tls: + insecure: true + sending_queue: + enabled: true + sizer: bytes + queue_size: 10485760 + num_consumers: 2 + retry_on_failure: + enabled: true + initial_interval: 1s + max_interval: 5s + max_elapsed_time: 30s + timeout: 5s + +extensions: + health_check: + endpoint: 0.0.0.0:13133 + +service: + extensions: [health_check] + telemetry: + metrics: + readers: + - pull: + exporter: + prometheus: + host: 0.0.0.0 + port: 8888 + pipelines: + traces: + receivers: [otlp] + processors: [memory_limiter, batch] + exporters: [otlp_grpc/tempo] + metrics: + receivers: [otlp] + processors: [memory_limiter, batch] + exporters: [prometheus] + logs: + receivers: [otlp] + processors: [memory_limiter, batch] + exporters: [otlp_http/loki] diff --git a/infra/prometheus/prometheus.yml b/infra/prometheus/prometheus.yml new file mode 100644 index 0000000..693e1ab --- /dev/null +++ b/infra/prometheus/prometheus.yml @@ -0,0 +1,28 @@ +global: + scrape_interval: 5s + evaluation_interval: 5s + +rule_files: + - /etc/prometheus/rules/*.yml + +scrape_configs: + - job_name: otel-collector + static_configs: + - targets: ["otel-collector:8889"] + - job_name: otel-collector-self + static_configs: + - targets: ["otel-collector:8888"] + - job_name: haproxy + metrics_path: /metrics + static_configs: + - targets: ["lb:8404"] + - job_name: rabbitmq + static_configs: + - targets: ["broker:15692"] + - job_name: loki + static_configs: + - targets: ["loki:3100"] + - job_name: tempo + metrics_path: /metrics + static_configs: + - targets: ["tempo:3200"] diff --git a/infra/prometheus/rules/alerts.yml b/infra/prometheus/rules/alerts.yml new file mode 100644 index 0000000..c84301b --- /dev/null +++ b/infra/prometheus/rules/alerts.yml @@ -0,0 +1,160 @@ +groups: + - name: lab6-alerts + interval: 5s + rules: + - alert: APIErrorBudgetFastBurn + expr: slo:api_error_ratio:1h > 0.072 and slo:api_error_ratio:5m > 0.072 and on() sum(increase(haproxy_backend_http_responses_total{proxy="api_backend"}[5m])) >= 20 + for: 0s + labels: + severity: page + slo: api-availability + annotations: + summary: API 5xx burn rate is above 14.4x + runbook: infra/runbooks/slo-burn.md + - alert: APIErrorBudgetSlowBurn + expr: slo:api_error_ratio:6h > 0.03 and slo:api_error_ratio:30m > 0.03 and on() sum(increase(haproxy_backend_http_responses_total{proxy="api_backend"}[30m])) >= 100 + for: 0s + labels: + severity: ticket + slo: api-availability + annotations: + summary: API 5xx burn rate is above 6x + runbook: infra/runbooks/slo-burn.md + - alert: TTRErrorBudgetFastBurn + expr: slo:job_ttr_bad_ratio:1h > 0.144 and slo:job_ttr_bad_ratio:5m > 0.144 and on() (sum(increase(messenger_job_time_to_ready_seconds_bucket{le="30.0"}[5m])) or vector(0)) + (sum(increase(messenger_jobs_ttr_missed_total[5m])) or vector(0)) >= 10 + for: 0s + labels: + severity: page + slo: time-to-ready + annotations: + summary: Jobs are missing the 30s time-to-ready objective + runbook: infra/runbooks/queue-lag.md + - alert: TTRErrorBudgetSlowBurn + expr: slo:job_ttr_bad_ratio:6h > 0.06 and slo:job_ttr_bad_ratio:30m > 0.06 and on() (sum(increase(messenger_job_time_to_ready_seconds_bucket{le="30.0"}[30m])) or vector(0)) + (sum(increase(messenger_jobs_ttr_missed_total[30m])) or vector(0)) >= 30 + for: 0s + labels: + severity: ticket + slo: time-to-ready + annotations: + summary: Time-to-ready budget is burning slowly + runbook: infra/runbooks/queue-lag.md + - alert: QueueOldestJobAgeHigh + expr: max(messenger_queue_oldest_job_age_seconds) > 120 + for: 10m + labels: + severity: warning + annotations: + summary: The oldest queued/processing job is older than 2 minutes + runbook: infra/runbooks/queue-lag.md + - alert: QueueOldestJobAgeCritical + expr: max(messenger_queue_oldest_job_age_seconds) > 600 + for: 5m + labels: + severity: page + annotations: + summary: The oldest queued/processing job is older than 10 minutes + runbook: infra/runbooks/queue-lag.md + - alert: QueueDepthGrowing + expr: | + max(rabbitmq_queue_messages_ready{queue="attachment.process.v1"}) > 20 + and on() max(deriv(rabbitmq_queue_messages_ready{queue="attachment.process.v1"}[10m])) > 0 + for: 10m + labels: + severity: warning + annotations: + summary: RabbitMQ ready depth is growing + runbook: infra/runbooks/queue-lag.md + - alert: JobsOverdue + expr: max(messenger_jobs_overdue) > 0 + for: 2m + labels: + severity: warning + slo: time-to-ready + annotations: + summary: Jobs have been queued/processing for more than 30 seconds + runbook: infra/runbooks/queue-lag.md + - alert: WorkerSaturated + expr: | + (sum(messenger_worker_busy) / clamp_min(sum(messenger_worker_capacity), 1) > 0.8) + and (max(messenger_queue_oldest_job_age_seconds) > 120) + for: 10m + labels: + severity: warning + annotations: + summary: Worker slots are saturated while the queue is aging + runbook: infra/runbooks/queue-lag.md + - alert: DBPoolSaturated + expr: | + ( + ( + sum(rate(messenger_db_pool_empty_acquire_wait_seconds_total[5m])) + / + clamp_min(sum(rate(messenger_db_pool_empty_acquire_total[5m])), 1e-9) + > 0.05 + ) + and (sum(rate(messenger_db_pool_empty_acquire_total[5m])) > 0.1) + ) + or (sum(messenger_db_pool_used) / clamp_min(sum(messenger_db_pool_max), 1) > 0.8) + for: 5m + labels: + severity: warning + annotations: + summary: PostgreSQL pool is waiting or nearly exhausted + runbook: infra/runbooks/db-availability.md + - alert: CollectorDroppedTelemetry + expr: | + sum(rate(otelcol_receiver_failed_spans[5m])) > 0 + or sum(rate(otelcol_receiver_failed_metric_points[5m])) > 0 + or sum(rate(otelcol_receiver_failed_log_records[5m])) > 0 + or sum(rate(otelcol_receiver_refused_spans[5m])) > 0 + or sum(rate(otelcol_receiver_refused_metric_points[5m])) > 0 + or sum(rate(otelcol_receiver_refused_log_records[5m])) > 0 + or sum(rate(otelcol_exporter_send_failed_spans[5m])) > 0 + or sum(rate(otelcol_exporter_send_failed_log_records[5m])) > 0 + or sum(rate(otelcol_exporter_send_failed_metric_points[5m])) > 0 + or sum(rate(otelcol_exporter_enqueue_failed_spans[5m])) > 0 + or sum(rate(otelcol_exporter_enqueue_failed_log_records[5m])) > 0 + or sum(rate(otelcol_exporter_enqueue_failed_metric_points[5m])) > 0 + or sum(otelcol_exporter_queue_size) >= sum(otelcol_exporter_queue_capacity) * 0.9 + for: 5m + labels: + severity: warning + annotations: + summary: Collector is dropping or refusing telemetry + runbook: infra/runbooks/telemetry-backend-down.md + - alert: TelemetryStorageDown + expr: up{job=~"loki|tempo"} == 0 + for: 2m + labels: + severity: warning + component: telemetry + annotations: + summary: Loki or Tempo is unavailable; Collector queues are bounded + runbook: infra/runbooks/telemetry-backend-down.md + - alert: TelemetryCollectorDown + expr: up{job="otel-collector"} == 0 + for: 2m + labels: + severity: warning + component: telemetry + annotations: + summary: OTel Collector is unavailable; application keeps running + runbook: infra/runbooks/telemetry-backend-down.md + - alert: APISLIMissing + expr: absent(slo:api_error_ratio:5m) or up{job="haproxy"} == 0 + for: 2m + labels: + severity: page + annotations: + summary: Edge availability data is missing + runbook: infra/runbooks/api-errors.md + - alert: QueueMetricsStale + expr: | + (absent(messenger_queue_oldest_job_age_seconds) or absent(messenger_jobs_accepted_total)) + and on() (up{job="otel-collector"} == 1) + for: 2m + labels: + severity: warning + annotations: + summary: Queue/backlog metrics are missing + runbook: infra/runbooks/queue-lag.md diff --git a/infra/prometheus/rules/slo.yml b/infra/prometheus/rules/slo.yml new file mode 100644 index 0000000..f00d418 --- /dev/null +++ b/infra/prometheus/rules/slo.yml @@ -0,0 +1,95 @@ +groups: + - name: slo + interval: 5s + rules: + - record: slo:api_error_ratio:5m + expr: | + sum(rate(haproxy_backend_http_responses_total{proxy="api_backend",code=~"5.."}[5m])) + / + clamp_min(sum(rate(haproxy_backend_http_responses_total{proxy="api_backend"}[5m])), 0.001) + - record: slo:api_error_ratio:1h + expr: | + sum(rate(haproxy_backend_http_responses_total{proxy="api_backend",code=~"5.."}[1h])) + / + clamp_min(sum(rate(haproxy_backend_http_responses_total{proxy="api_backend"}[1h])), 0.001) + - record: slo:api_error_ratio:6h + expr: | + sum(rate(haproxy_backend_http_responses_total{proxy="api_backend",code=~"5.."}[6h])) + / + clamp_min(sum(rate(haproxy_backend_http_responses_total{proxy="api_backend"}[6h])), 0.001) + - record: slo:api_error_ratio:30m + expr: | + sum(rate(haproxy_backend_http_responses_total{proxy="api_backend",code=~"5.."}[30m])) + / + clamp_min(sum(rate(haproxy_backend_http_responses_total{proxy="api_backend"}[30m])), 0.001) + - record: slo:job_ttr_bad_ratio:5m + expr: | + ( + (sum(rate(messenger_jobs_ttr_missed_total[5m])) or vector(0)) + / + clamp_min( + (sum(rate(messenger_job_time_to_ready_seconds_bucket{le="30.0"}[5m])) or vector(0)) + + (sum(rate(messenger_jobs_ttr_missed_total[5m])) or vector(0)), + 0.001 + ) + ) + and on() ( + (sum(increase(messenger_job_time_to_ready_seconds_bucket{le="30.0"}[5m])) or vector(0)) + + (sum(increase(messenger_jobs_ttr_missed_total[5m])) or vector(0)) + ) >= 10 + - record: slo:job_ttr_bad_ratio:1h + expr: | + ( + (sum(rate(messenger_jobs_ttr_missed_total[1h])) or vector(0)) + / + clamp_min( + (sum(rate(messenger_job_time_to_ready_seconds_bucket{le="30.0"}[1h])) or vector(0)) + + (sum(rate(messenger_jobs_ttr_missed_total[1h])) or vector(0)), + 0.001 + ) + ) + and on() ( + (sum(increase(messenger_job_time_to_ready_seconds_bucket{le="30.0"}[1h])) or vector(0)) + + (sum(increase(messenger_jobs_ttr_missed_total[1h])) or vector(0)) + ) >= 10 + - record: slo:job_ttr_bad_ratio:6h + expr: | + ( + (sum(rate(messenger_jobs_ttr_missed_total[6h])) or vector(0)) + / + clamp_min( + (sum(rate(messenger_job_time_to_ready_seconds_bucket{le="30.0"}[6h])) or vector(0)) + + (sum(rate(messenger_jobs_ttr_missed_total[6h])) or vector(0)), + 0.001 + ) + ) + and on() ( + (sum(increase(messenger_job_time_to_ready_seconds_bucket{le="30.0"}[6h])) or vector(0)) + + (sum(increase(messenger_jobs_ttr_missed_total[6h])) or vector(0)) + ) >= 30 + - record: slo:job_ttr_bad_ratio:30m + expr: | + ( + (sum(rate(messenger_jobs_ttr_missed_total[30m])) or vector(0)) + / + clamp_min( + (sum(rate(messenger_job_time_to_ready_seconds_bucket{le="30.0"}[30m])) or vector(0)) + + (sum(rate(messenger_jobs_ttr_missed_total[30m])) or vector(0)), + 0.001 + ) + ) + and on() ( + (sum(increase(messenger_job_time_to_ready_seconds_bucket{le="30.0"}[30m])) or vector(0)) + + (sum(increase(messenger_jobs_ttr_missed_total[30m])) or vector(0)) + ) >= 30 + + - name: slo-long + interval: 1m + rules: + - record: slo:api_error_ratio:7d + expr: | + sum(rate(haproxy_backend_http_responses_total{proxy="api_backend",code=~"5.."}[7d])) + / + clamp_min(sum(rate(haproxy_backend_http_responses_total{proxy="api_backend"}[7d])), 0.001) + - record: slo:api_budget_remaining:7d + expr: clamp(1 - (slo:api_error_ratio:7d / 0.005), 0, 1) diff --git a/infra/prometheus/tests/ttr_test.yml b/infra/prometheus/tests/ttr_test.yml new file mode 100644 index 0000000..dc38e0f --- /dev/null +++ b/infra/prometheus/tests/ttr_test.yml @@ -0,0 +1,65 @@ +rule_files: + - ../rules/slo.yml + - ../rules/alerts.yml +evaluation_interval: 1m +tests: + - interval: 1m + input_series: + - series: 'messenger_job_time_to_ready_seconds_bucket{le="30.0"}' + values: '0+10x10' + - series: 'messenger_job_time_to_ready_seconds_count' + values: '0+10x10' + promql_expr_test: + - expr: slo:job_ttr_bad_ratio:5m + eval_time: 5m + exp_samples: + - labels: '{__name__="slo:job_ttr_bad_ratio:5m"}' + value: 0 + - interval: 1m + input_series: + - series: 'messenger_jobs_ttr_missed_total' + values: '0+10x10' + promql_expr_test: + - expr: slo:job_ttr_bad_ratio:5m + eval_time: 5m + exp_samples: + - labels: '{__name__="slo:job_ttr_bad_ratio:5m"}' + value: 1 + - interval: 1m + input_series: + - series: 'messenger_job_time_to_ready_seconds_bucket{le="30.0"}' + values: '10+0x5 stale' + - series: 'messenger_job_time_to_ready_seconds_count' + values: '10+0x5 stale' + - series: 'messenger_jobs_ttr_missed_total' + values: '0+10x20' + promql_expr_test: + - expr: slo:job_ttr_bad_ratio:5m + eval_time: 15m + exp_samples: + - labels: '{__name__="slo:job_ttr_bad_ratio:5m"}' + value: 1 + - interval: 1m + input_series: + - series: 'messenger_job_time_to_ready_seconds_bucket{le="30.0"}' + values: '0+5x10' + - series: 'messenger_job_time_to_ready_seconds_count' + values: '0+10x10' + - series: 'messenger_jobs_ttr_missed_total' + values: '0+2x10' + promql_expr_test: + - expr: slo:job_ttr_bad_ratio:5m + eval_time: 5m + exp_samples: + - labels: '{__name__="slo:job_ttr_bad_ratio:5m"}' + value: 0.2857142857142857 + - interval: 1m + input_series: + - series: 'messenger_job_time_to_ready_seconds_bucket{le="30.0"}' + values: '0x10' + - series: 'messenger_jobs_ttr_missed_total' + values: '0 6 6 6 6 6 6 6 6 6 6' + alert_rule_test: + - eval_time: 5m + alertname: TTRErrorBudgetFastBurn + exp_alerts: [] diff --git a/infra/rabbitmq/rabbitmq.conf b/infra/rabbitmq/rabbitmq.conf new file mode 100644 index 0000000..72289d0 --- /dev/null +++ b/infra/rabbitmq/rabbitmq.conf @@ -0,0 +1,3 @@ +# Per-queue Prometheus series: the default exporter aggregates queues, but the +# lab dashboard and oldest/queue-depth alert need the queue label. +prometheus.return_per_object_metrics = true diff --git a/infra/runbooks/api-errors.md b/infra/runbooks/api-errors.md new file mode 100644 index 0000000..982b7a0 --- /dev/null +++ b/infra/runbooks/api-errors.md @@ -0,0 +1,8 @@ +# API error / availability SLI + +1. Grafana → Lab6 → API overview. Check `slo:api_error_ratio:5m` and the edge panel; 5xx at HAProxy is the SLI, API-side 5xx is diagnostic. +2. Prometheus → Status → Targets: `haproxy`, `otel-collector`, `rabbitmq` must be UP. If HAProxy is DOWN, no edge SLI exists; inspect `docker compose ps lb`. +3. HAProxy stats `http://127.0.0.1:8404/stats`: look for DOWN replicas and `check` errors. A stale `X-Instance-Id` is the stopped replica. +4. If all replicas are DOWN, check `/health/ready` of one replica (5xx means DB/S3 dependency) and PostgreSQL logs. +5. For a slow handler, open a Tempo trace from the error panel; DB child span (`SELECT`/`INSERT`/`UPDATE`/`BEGIN`/`COMMIT`) duration vs HTTP span shows whether PostgreSQL or the handler is slow. Correlate `trace_id` in Loki. +6. Recover DB/S3, wait for HAProxy `rise 2`, then verify a 2xx through the LB and resolved alert. diff --git a/infra/runbooks/db-availability.md b/infra/runbooks/db-availability.md new file mode 100644 index 0000000..69f7edf --- /dev/null +++ b/infra/runbooks/db-availability.md @@ -0,0 +1,8 @@ +# PostgreSQL slow/unavailable + +1. Edge SLI first: HAProxy may return 503/504 while API replicas are removed by `/health/ready`; API-side 5xx can therefore be near zero. Use the HAProxy panel and `up{job="haproxy"}`. +2. `docker compose ps postgres`; `docker compose logs --tail=100 postgres`; `pg_isready` from a replica. +3. Prometheus: `messenger_db_pool_used/idle/max`, `messenger_db_pool_empty_acquire_total`, `rate(...wait_seconds)`; API/worker DB spans in Tempo (`SELECT`/`INSERT`/`UPDATE`/`BEGIN`/`COMMIT`, `pool.acquire`) show failures/latency. +4. Loki: `{service_name=~"messenger-api|messenger-worker"} | severity_text="error" | trace_id=""`. A handler span with a long DB child span is a DB problem; a long handler without a DB child is an application problem. +5. If PostgreSQL was stopped, start it, wait for health, then let the pool reconnect. Worker deliveries are requeued; verify no accepted job is lost (jobs accepted/ready/failed counts). +6. Confirm the alert resolved; record injection/restore and first successful request timestamps. diff --git a/infra/runbooks/queue-lag.md b/infra/runbooks/queue-lag.md new file mode 100644 index 0000000..bb08eac --- /dev/null +++ b/infra/runbooks/queue-lag.md @@ -0,0 +1,8 @@ +# Queue lag / time-to-ready + +1. Grafana → Lab6 → Jobs and queue: `messenger_queue_oldest_job_age_seconds`, `rabbitmq_queue_messages_ready`, `messenger_worker_busy/capacity`, TTR p95. +2. If oldest age grows and `worker_busy == capacity`, the worker is saturated: inspect `worker` logs (`job claimed`, `job retry scheduled`) and `WORKER_CONCURRENCY`. +3. If queue depth grows but `worker_busy == 0`, the worker is stopped or cannot connect to the broker: `docker compose ps worker`, worker `/health/ready`, broker `rabbitmqctl list_queues`. +4. If retries grow, filter Loki `{service_name="messenger-worker"} | severity_text="error"` and trace `job.process` attempts; check `error_code`. +5. For a lost delivery, relay logs `outbox publish cycle` / `lost queued jobs reconciled` and `jobctl failed`. +6. Restore worker/broker, verify queue depth < 5 and oldest age < 5s for two scrapes, then confirm the alert resolved. diff --git a/infra/runbooks/slo-burn.md b/infra/runbooks/slo-burn.md new file mode 100644 index 0000000..7af769f --- /dev/null +++ b/infra/runbooks/slo-burn.md @@ -0,0 +1,15 @@ +# SLO burn-rate + +1. Open Grafana → Lab6 → API overview and Jobs and queue. +2. Check `slo:api_error_ratio:1h` + `5m` for fast burn, `6h` + `30m` + for slow burn; TTR uses `slo:job_ttr_bad_ratio:*`. +3. Fast page means the current hour is consuming the 7-day error budget at + ≥14.4×. Confirm edge traffic in HAProxy (`proxy="api_backend"`), then inspect + API traces for 5xx and DB spans (`SELECT`/`INSERT`/`UPDATE`/`BEGIN`/`COMMIT`) + or missing worker `job.process` spans. +4. Slow ticket means a sustained 6-hour burn. It can fire with a low current + rate; do not suppress it until the 30m window is below 3% (API) or 6% (TTR). +5. Resolve only after the SLO ratio stays below the fast/slow thresholds and + the underlying dependency (worker, PostgreSQL, broker) is healthy. +6. Record injection/restore UTC and the first firing/resolved timestamps in + `evidence/lab6/track2/`. diff --git a/infra/runbooks/telemetry-backend-down.md b/infra/runbooks/telemetry-backend-down.md new file mode 100644 index 0000000..dfd2f9b --- /dev/null +++ b/infra/runbooks/telemetry-backend-down.md @@ -0,0 +1,8 @@ +# Telemetry backend down + +1. This is an observability incident, not a business outage. First verify API: `curl -fsS http://127.0.0.1:8080/health/ready` and a smoke request. +2. `docker compose ps otel-collector prometheus loki tempo grafana`. +3. If Tempo/Loki is down, Collector exporter queues fill; inspect `otelcol_exporter_queue_size`, `otelcol_exporter_send_failed_*`, `otelcol_processor_refused_*`. Queues are bounded by `sizer: bytes`; the Collector does not grow without limit. +4. If the Collector is down, Prometheus `up{job="otel-collector"}=0`; the application continues to accept work. Application OTLP export failures are best-effort and do not affect `/health/ready`. +5. Restart the failed backend/collector; confirm `up`, queue drains, and no new refused records. Lost telemetry is bounded and documented; business data in PostgreSQL/S3 is unaffected. +6. Do not stop Prometheus while diagnosing another alert: without Prometheus there is no rule evaluation. Use HAProxy stats and container logs as fallback. diff --git a/infra/s3/README.md b/infra/s3/README.md new file mode 100644 index 0000000..bf9216c --- /dev/null +++ b/infra/s3/README.md @@ -0,0 +1,27 @@ +# SeaweedFS identities + +`infra/s3/s3.json` is mounted read-only into the `seaweedfs` container and is +the single source of truth for S3 credentials and permissions. + +- `admin` is used only by the one-shot `s3-init` service (bucket creation and + probing). It is never given to the API and must not be placed in `.env`: + the API service loads `.env` as an environment file. Compose supplies the + synthetic admin values to `s3-init` directly. +- `app` is used by the API and by presigned uploads. It can read/write only + `messenger-attachments/attachments/*` and `messenger-attachments/staging/*`, + and list the bucket for the orphan sweeper. + +The credentials are synthetic values for the local stand. `.env.example` +carries the same values for the API and `scripts/check_s3_creds.py` fails the +offline check if they drift. Replace them in `.env` for any non-local run. + +Verify manually: + +```sh +# anonymous requests are denied +docker compose exec -T seaweedfs \ + wget -qO- http://127.0.0.1:8333/messenger-attachments/attachments/missing + +# the app identity cannot write outside its prefixes +docker compose run --rm s3-init # probes this and exits non-zero on violation +``` diff --git a/infra/s3/s3.json b/infra/s3/s3.json new file mode 100644 index 0000000..773f3bf --- /dev/null +++ b/infra/s3/s3.json @@ -0,0 +1,24 @@ +{ + "identities": [ + { + "name": "admin", + "credentials": [ + {"accessKey": "lab4admin", "secretKey": "lab4admin-secret"} + ], + "actions": ["Admin", "Read", "Write", "List", "Tagging"] + }, + { + "name": "app", + "credentials": [ + {"accessKey": "lab4app", "secretKey": "lab4app-secret"} + ], + "actions": [ + "Read:messenger-attachments/attachments/*", + "Write:messenger-attachments/attachments/*", + "Read:messenger-attachments/staging/*", + "Write:messenger-attachments/staging/*", + "List:messenger-attachments" + ] + } + ] +} diff --git a/infra/tempo/tempo.yaml b/infra/tempo/tempo.yaml new file mode 100644 index 0000000..71301d3 --- /dev/null +++ b/infra/tempo/tempo.yaml @@ -0,0 +1,27 @@ +server: + http_listen_port: 3200 + grpc_listen_port: 9095 + +distributor: + receivers: + otlp: + protocols: + grpc: + endpoint: 0.0.0.0:4317 + http: + endpoint: 0.0.0.0:4318 + +storage: + trace: + backend: local + local: + path: /var/tempo/traces + wal: + path: /var/tempo/wal + +compactor: + compaction: + block_retention: 72h + +usage_report: + reporting_enabled: false diff --git a/internal/broker/rabbit.go b/internal/broker/rabbit.go new file mode 100644 index 0000000..934af61 --- /dev/null +++ b/internal/broker/rabbit.go @@ -0,0 +1,320 @@ +// Package broker owns the RabbitMQ topology, confirmed publishing and the +// consumer loop. Business state never lives here: PostgreSQL is the source of +// truth for jobs and the outbox. +package broker + +import ( + "context" + "errors" + "fmt" + "sync" + "time" + + amqp "github.com/rabbitmq/amqp091-go" + + "mtusi-messenger/internal/domain" +) + +type Config struct { + URL string + Exchange string + DLX string + Queue string + DLQ string + ConnectTimeout time.Duration + ConfirmTimeout time.Duration + Heartbeat time.Duration + Prefetch int +} + +type Client struct { + cfg Config + + conn *amqp.Connection + publisher *amqp.Channel + + mu sync.Mutex + returns chan amqp.Return + closed chan *amqp.Error +} + +// Dial connects, declares the durable topology idempotently and opens a +// confirm-mode publisher channel. +func Dial(cfg Config) (*Client, error) { + if cfg.URL == "" { + return nil, errors.New("broker url is empty") + } + + conn, err := amqp.DialConfig(cfg.URL, amqp.Config{ + Heartbeat: cfg.Heartbeat, + Dial: amqp.DefaultDial(cfg.ConnectTimeout), + Properties: amqp.Table{ + "connection_name": "messenger-relay", + }, + }) + if err != nil { + return nil, fmt.Errorf("dial broker: %w", err) + } + + channel, err := conn.Channel() + if err != nil { + _ = conn.Close() + + return nil, fmt.Errorf("open topology channel: %w", err) + } + + if err := declareTopology(channel, cfg); err != nil { + _ = channel.Close() + _ = conn.Close() + + return nil, err + } + + if err := channel.Close(); err != nil { + _ = conn.Close() + + return nil, fmt.Errorf("close topology channel: %w", err) + } + + publisher, err := conn.Channel() + if err != nil { + _ = conn.Close() + + return nil, fmt.Errorf("open publisher channel: %w", err) + } + + client := &Client{ + cfg: cfg, + conn: conn, + publisher: publisher, + returns: make(chan amqp.Return, 16), + closed: conn.NotifyClose(make(chan *amqp.Error, 1)), + } + + if err := publisher.Confirm(false); err != nil { + _ = client.Close() + + return nil, fmt.Errorf("enable publisher confirms: %w", err) + } + + publisher.NotifyReturn(client.returns) + + return client, nil +} + +func declareTopology(channel *amqp.Channel, cfg Config) error { + if err := channel.ExchangeDeclare(cfg.Exchange, "direct", true, false, false, false, nil); err != nil { + return fmt.Errorf("declare exchange: %w", err) + } + + if err := channel.ExchangeDeclare(cfg.DLX, "direct", true, false, false, false, nil); err != nil { + return fmt.Errorf("declare dlx: %w", err) + } + + queue, err := channel.QueueDeclare(cfg.Queue, true, false, false, false, amqp.Table{ + "x-queue-type": "quorum", + "x-delivery-limit": int32(100), + "x-delayed-retry-type": "all", + "x-delayed-retry-min": int32(5000), + "x-delayed-retry-max": int32(60000), + "x-dead-letter-exchange": cfg.DLX, + "x-dead-letter-routing-key": cfg.DLQ, + "x-dead-letter-strategy": "at-least-once", + "x-overflow": "reject-publish", + "x-max-length": int32(100000), + "x-consumer-timeout": int32(300000), + }) + if err != nil { + return fmt.Errorf("declare job queue: %w", err) + } + + if queue.Name != cfg.Queue { + return fmt.Errorf("broker returned queue %q, want %q", queue.Name, cfg.Queue) + } + + if err := channel.QueueBind(cfg.Queue, cfg.Queue, cfg.Exchange, false, nil); err != nil { + return fmt.Errorf("bind job queue: %w", err) + } + + if _, err := channel.QueueDeclare(cfg.DLQ, true, false, false, false, amqp.Table{ + "x-queue-type": "quorum", + "x-max-length": int32(100000), + "x-overflow": "reject-publish", + "x-message-ttl": int32(7 * 24 * 60 * 60 * 1000), + }); err != nil { + return fmt.Errorf("declare dlq: %w", err) + } + + if err := channel.QueueBind(cfg.DLQ, cfg.DLQ, cfg.DLX, false, nil); err != nil { + return fmt.Errorf("bind dlq: %w", err) + } + + return nil +} + +func (c *Client) Connected() bool { + c.mu.Lock() + defer c.mu.Unlock() + + return c.conn != nil && !c.conn.IsClosed() +} + +// PublishConfirmed returns only after the broker acknowledged the persistent +// message. A duplicate publication after a crash is normal and harmless. +func (c *Client) PublishConfirmed(ctx context.Context, routingKey string, message domain.JobMessage) error { + payload, err := message.MarshalPayload() + if err != nil { + return fmt.Errorf("marshal job message: %w", err) + } + + confirmation, err := c.publisher.PublishWithDeferredConfirmWithContext( + ctx, + c.cfg.Exchange, + routingKey, + true, + false, + amqp.Publishing{ + ContentType: "application/json", + DeliveryMode: amqp.Persistent, + MessageId: message.JobID.String(), + Type: message.Type, + Timestamp: message.CreatedAt, + Body: payload, + }, + ) + if err != nil { + return fmt.Errorf("publish job: %w", err) + } + + confirmCtx := ctx + if c.cfg.ConfirmTimeout > 0 { + var cancel context.CancelFunc + confirmCtx, cancel = context.WithTimeout(ctx, c.cfg.ConfirmTimeout) + defer cancel() + } + + confirmed, err := confirmation.WaitContext(confirmCtx) + if err != nil { + return fmt.Errorf("await publisher confirm: %w", err) + } + + if !confirmed { + return errors.New("broker nacked the job message") + } + + // mandatory=true: an unroutable message is returned even though the + // confirm may still be positive. The topology is declared before publish, + // so this is a safety net rather than a normal path. + select { + case returned := <-c.returns: + if returned.MessageId == message.JobID.String() { + return fmt.Errorf("broker returned unroutable message: %s", returned.ReplyText) + } + default: + } + + return nil +} + +type Outcome int + +const ( + Ack Outcome = iota + Requeue + Drop +) + +type Handler func(ctx context.Context, delivery amqp.Delivery) Outcome + +// Consume blocks until the context is cancelled or the consumer channel fails. +// Each call uses its own channel so worker slots do not share prefetch state. +func (c *Client) Consume(ctx context.Context, handler Handler) error { + channel, err := c.conn.Channel() + if err != nil { + return fmt.Errorf("open consumer channel: %w", err) + } + defer channel.Close() + + if err := channel.Qos(c.cfg.Prefetch, 0, false); err != nil { + return fmt.Errorf("set qos: %w", err) + } + + consumerTag := fmt.Sprintf("messenger-%d", time.Now().UnixNano()) + + deliveries, err := channel.Consume( + c.cfg.Queue, + consumerTag, + false, + false, + false, + false, + nil, + ) + if err != nil { + return fmt.Errorf("consume: %w", err) + } + + done := make(chan struct{}) + defer close(done) + + go func() { + select { + case <-ctx.Done(): + _ = channel.Cancel(consumerTag, false) + case <-done: + } + }() + + for delivery := range deliveries { + outcome := safeHandle(ctx, handler, delivery) + + switch outcome { + case Ack: + _ = delivery.Ack(false) + case Requeue: + _ = delivery.Nack(false, true) + case Drop: + _ = delivery.Nack(false, false) + } + + if ctx.Err() != nil { + // Let unacked deliveries return to the broker on channel close. + return nil + } + } + + if ctx.Err() != nil { + return nil + } + + return errors.New("consumer channel closed") +} + +func safeHandle(ctx context.Context, handler Handler, delivery amqp.Delivery) (outcome Outcome) { + defer func() { + if recover() != nil { + outcome = Requeue + } + }() + + return handler(ctx, delivery) +} + +func (c *Client) Close() error { + c.mu.Lock() + defer c.mu.Unlock() + + if c.publisher != nil { + _ = c.publisher.Close() + c.publisher = nil + } + + if c.conn != nil { + err := c.conn.Close() + c.conn = nil + + return err + } + + return nil +} diff --git a/internal/config/config.go b/internal/config/config.go new file mode 100644 index 0000000..a1c7a0d --- /dev/null +++ b/internal/config/config.go @@ -0,0 +1,425 @@ +package config + +import ( + "errors" + "fmt" + "log/slog" + "net" + "net/url" + "os" + "path/filepath" + "reflect" + "strconv" + "strings" + "time" + + "github.com/go-playground/validator/v10" + "github.com/spf13/viper" + + "mtusi-messenger/internal/logger" +) + +const ( + configEnvKey = "APP_CONFIG" + envKey = "APP_ENV" + configName = "config" + defaultEnv = "dev" + configDir = "./config/" +) + +type Config struct { + Env string `mapstructure:"env" validate:"omitempty,eq=dev"` + Server Server `mapstructure:"server"` + Log Log `mapstructure:"log"` + Postgres Postgres `mapstructure:"postgres"` + Redis Redis `mapstructure:"redis"` + Cache Cache `mapstructure:"cache"` + Session Session `mapstructure:"session"` + Idempotency Idempotency `mapstructure:"idempotency"` + S3 S3 `mapstructure:"s3"` + Broker Broker `mapstructure:"broker"` + Worker Worker `mapstructure:"worker"` + Relay Relay `mapstructure:"relay"` + Outbox Outbox `mapstructure:"outbox"` + Processing Processing `mapstructure:"processing"` + Staging Staging `mapstructure:"staging"` + Admission Admission `mapstructure:"admission"` +} + +// Broker carries the AMQP transport settings. The API never publishes; relay +// and worker require a non-empty URL at startup. +type Broker struct { + URL string `mapstructure:"url"` + ConnectTimeout time.Duration `mapstructure:"connect_timeout"` + ConfirmTimeout time.Duration `mapstructure:"confirm_timeout"` + Heartbeat time.Duration `mapstructure:"heartbeat"` + Exchange string `mapstructure:"exchange" validate:"required"` + DLX string `mapstructure:"dlx" validate:"required"` + Queue string `mapstructure:"queue" validate:"required"` + DLQ string `mapstructure:"dlq" validate:"required"` + Prefetch int `mapstructure:"prefetch" validate:"required,gt=0"` +} + +// Worker bounds the process that consumes jobs. +type Worker struct { + Concurrency int `mapstructure:"concurrency" validate:"required,gt=0,lte=32"` + Prefetch int `mapstructure:"prefetch" validate:"required,gt=0,lte=100"` + ShutdownTimeout time.Duration `mapstructure:"shutdown_timeout" validate:"required,gt=0"` + HealthAddr string `mapstructure:"health_addr" validate:"required"` +} + +// Relay bounds the outbox publisher and lease reaper. +type Relay struct { + HealthAddr string `mapstructure:"health_addr" validate:"required"` +} + +// Outbox schedules publications and reclaims abandoned relay claims. +type Outbox struct { + PollInterval time.Duration `mapstructure:"poll_interval" validate:"required,gt=0"` + ClaimTTL time.Duration `mapstructure:"claim_ttl" validate:"required,gt=0"` + Batch int `mapstructure:"batch" validate:"required,gt=0,lte=1000"` + ReaperInterval time.Duration `mapstructure:"reaper_interval" validate:"required,gt=0"` + ReconcileAfter time.Duration `mapstructure:"reconcile_after" validate:"omitempty,gt=0"` + Retention time.Duration `mapstructure:"retention" validate:"required,gt=0"` +} + +// Processing holds the shared job contract knobs read by API and worker. +type Processing struct { + PipelineVersion int `mapstructure:"pipeline_version" validate:"required,gte=1,lte=2"` + MaxAttempts int `mapstructure:"max_attempts" validate:"required,gte=1,lte=100"` + JobTimeout time.Duration `mapstructure:"job_timeout" validate:"required,gt=0"` + LeaseTTL time.Duration `mapstructure:"lease_ttl" validate:"required,gt=0"` + Heartbeat time.Duration `mapstructure:"heartbeat" validate:"required,gt=0"` + RetryBase time.Duration `mapstructure:"retry_base" validate:"required,gt=0"` + RetryCap time.Duration `mapstructure:"retry_cap" validate:"required,gt=0"` +} + +// Staging controls cleanup of objects that are no longer the active source. +type Staging struct { + OrphanGrace time.Duration `mapstructure:"orphan_grace" validate:"required,gt=0"` + FailedRetention time.Duration `mapstructure:"failed_retention" validate:"required,gt=0"` +} + +// Admission bounds accepted-but-unfinished work per user and globally. +type Admission struct { + MaxPendingPerUser int `mapstructure:"max_pending_per_user" validate:"required,gte=0"` + MaxPending int `mapstructure:"max_pending" validate:"required,gte=0"` + MaxStagedBytes int64 `mapstructure:"max_staged_bytes" validate:"required,gte=0"` + MaxConcurrent int `mapstructure:"max_concurrent_uploads" validate:"omitempty,gt=0"` +} + +// S3 describes the object store and attachment limits. Access keys are checked +// by the object-store constructor rather than the global validator: cmd/migrate +// and unit tests load this config without any S3 credentials. +type S3 struct { + Endpoint string `mapstructure:"endpoint" validate:"required,url"` + PublicEndpoint string `mapstructure:"public_endpoint" validate:"omitempty,url"` + Region string `mapstructure:"region" validate:"required"` + Bucket string `mapstructure:"bucket" validate:"required"` + AccessKeyID string `mapstructure:"access_key_id"` + SecretAccessKey string `mapstructure:"secret_access_key"` + UsePathStyle bool `mapstructure:"use_path_style"` + Timeout time.Duration `mapstructure:"timeout" validate:"required,gt=0"` + + MaxUploadBytes int64 `mapstructure:"max_upload_bytes" validate:"required,gt=0,lte=10485760"` + MaxImagePixels int64 `mapstructure:"max_image_pixels" validate:"required,gt=0,lte=40000000"` + PresignTTL time.Duration `mapstructure:"presign_ttl" validate:"required,gt=0,lte=168h"` + SweepInterval time.Duration `mapstructure:"sweep_interval" validate:"required,gt=0"` + SweepGrace time.Duration `mapstructure:"sweep_grace" validate:"required,gt=0"` +} + +type Session struct { + TTLSeconds int `mapstructure:"ttl_seconds" validate:"required,gt=0"` +} + +// Idempotency holds the retention window of a message Idempotency-Key (contract +// 1.3.0 requires at least 24 hours). +type Idempotency struct { + TTLSeconds int `mapstructure:"ttl_seconds" validate:"required,gt=0"` +} + +type Redis struct { + Enabled bool `mapstructure:"enabled"` + Host string `mapstructure:"host" validate:"omitempty,hostname|ip"` + Port int `mapstructure:"port" validate:"omitempty,min=1,max=65535"` + Password string `mapstructure:"password"` + DB int `mapstructure:"db" validate:"omitempty,gte=0,lte=15"` + MaxRetries int `mapstructure:"max_retries" validate:"omitempty,gte=-1"` + DialTimeout time.Duration `mapstructure:"dial_timeout" validate:"omitempty,gt=0"` + ReadTimeout time.Duration `mapstructure:"read_timeout" validate:"omitempty,gt=0"` + WriteTimeout time.Duration `mapstructure:"write_timeout" validate:"omitempty,gt=0"` + PoolSize int `mapstructure:"pool_size" validate:"omitempty,gt=0"` +} + +type Cache struct { + Enabled bool `mapstructure:"enabled"` + ChatListTTL time.Duration `mapstructure:"chat_list_ttl" validate:"required,gt=0"` + LockTTL time.Duration `mapstructure:"lock_ttl" validate:"required,gt=1s"` + LockWaitTimeout time.Duration `mapstructure:"lock_wait_timeout" validate:"required,gt=0"` +} + +type Server struct { + Host string `mapstructure:"host" validate:"required,hostname|ip"` + Port int `mapstructure:"port" validate:"required,min=1,max=65535"` + ReadHeaderTimeout time.Duration `mapstructure:"read_header_timeout" validate:"required,gt=0"` + ReadTimeout time.Duration `mapstructure:"read_timeout" validate:"required,gt=0"` + ShutdownTimeout time.Duration `mapstructure:"shutdown_timeout" validate:"required,gt=0"` + // MaxBodyBytes bounds a request body before the transport decodes it; uploads + // of a later lab raise it explicitly (contract 4: 10 MiB attachments). + MaxBodyBytes int64 `mapstructure:"max_body_bytes" validate:"required,gt=0"` +} + +type Log struct { + Level string `mapstructure:"level" validate:"required,oneof=debug info warn error"` + Format string `mapstructure:"format" validate:"required,oneof=json console"` +} + +type Postgres struct { + Host string `mapstructure:"host" validate:"omitempty,hostname|ip"` + Port int `mapstructure:"port" validate:"omitempty,min=1,max=65535"` + Database string `mapstructure:"database" validate:"omitempty,min=1"` + User string `mapstructure:"user" validate:"omitempty,min=1"` + Password string `mapstructure:"password"` + SSLMode string `mapstructure:"ssl_mode" validate:"omitempty,oneof=disable require verify-ca verify-full"` + MaxConns int32 `mapstructure:"max_conns" validate:"omitempty,gt=0"` + MinConns int32 `mapstructure:"min_conns" validate:"omitempty,gte=0"` + MaxConnLifetime time.Duration `mapstructure:"max_conn_lifetime" validate:"omitempty,gt=0"` + MaxConnIdleTime time.Duration `mapstructure:"max_conn_idle_time" validate:"omitempty,gt=0"` + ConnectTimeout time.Duration `mapstructure:"connect_timeout" validate:"omitempty,gt=0"` + QueryTimeout time.Duration `mapstructure:"query_timeout" validate:"omitempty,gt=0"` +} + +func (p Postgres) DSN() string { + u := &url.URL{ + Scheme: "postgres", + Host: net.JoinHostPort(p.Host, strconv.Itoa(p.Port)), + Path: "/" + p.Database, + } + + if p.Password == "" { + u.User = url.User(p.User) + } else { + u.User = url.UserPassword(p.User, p.Password) + } + + query := url.Values{} + query.Set("sslmode", p.SSLMode) + u.RawQuery = query.Encode() + + return u.String() +} + +var defaults = map[string]any{ + "env": "dev", + "server.host": "0.0.0.0", + "server.port": 8080, + "server.read_header_timeout": "10s", + "server.read_timeout": "60s", + "server.shutdown_timeout": "10s", + "server.max_body_bytes": 262144, + "s3.endpoint": "http://localhost:8333", + "s3.public_endpoint": "http://localhost:8333", + "s3.region": "us-east-1", + "s3.bucket": "messenger-attachments", + "s3.access_key_id": "", + "s3.secret_access_key": "", + "s3.use_path_style": true, + "s3.timeout": "30s", + "s3.max_upload_bytes": 10485760, + "s3.max_image_pixels": 40000000, + "s3.presign_ttl": "5m", + "s3.sweep_interval": "1m", + "s3.sweep_grace": "10m", + "log.level": "info", + "log.format": "json", + "session.ttl_seconds": 3600, + "idempotency.ttl_seconds": 86400, + "redis.enabled": false, + "redis.host": "localhost", + "redis.port": 6379, + "redis.db": 0, + "redis.max_retries": -1, + "redis.dial_timeout": "300ms", + "redis.read_timeout": "200ms", + "redis.write_timeout": "200ms", + "redis.pool_size": 10, + "cache.enabled": false, + "cache.chat_list_ttl": "5m", + "cache.lock_ttl": "10s", + "cache.lock_wait_timeout": "2s", + + "broker.url": "", + "broker.connect_timeout": "5s", + "broker.confirm_timeout": "5s", + "broker.heartbeat": "10s", + "broker.exchange": "attachments.jobs", + "broker.dlx": "attachments.dlx", + "broker.queue": "attachment.process.v1", + "broker.dlq": "attachment.process.dead", + "broker.prefetch": 1, + "worker.concurrency": 1, + "worker.prefetch": 1, + "worker.shutdown_timeout": "30s", + "worker.health_addr": ":8081", + "relay.health_addr": ":8082", + "outbox.poll_interval": "1s", + "outbox.claim_ttl": "30s", + "outbox.batch": 20, + "outbox.reaper_interval": "15s", + "outbox.retention": "168h", + "processing.pipeline_version": 1, + "processing.max_attempts": 5, + "processing.job_timeout": "120s", + "processing.lease_ttl": "180s", + "processing.heartbeat": "30s", + "processing.retry_base": "2s", + "processing.retry_cap": "60s", + "staging.orphan_grace": "1h", + "staging.failed_retention": "168h", + "admission.max_pending_per_user": 20, + "admission.max_pending": 200, + "admission.max_staged_bytes": 2147483648, +} + +func Load() (Config, error) { + v := viper.New() + + if err := configureSource(v); err != nil { + return Config{}, err + } + + v.AllowEmptyEnv(true) + v.AutomaticEnv() + v.SetEnvKeyReplacer(strings.NewReplacer(".", "_")) + + for key := range defaults { + if err := v.BindEnv(key); err != nil { + return Config{}, fmt.Errorf("bind env %q: %w", key, err) + } + } + + // The skeleton suggests MAX_UPLOAD_BYTES / MAX_IMAGE_PIXELS. Keep those + // names while storing the values under the S3 section. + for key, env := range map[string]string{ + "s3.max_upload_bytes": "MAX_UPLOAD_BYTES", + "s3.max_image_pixels": "MAX_IMAGE_PIXELS", + } { + if err := v.BindEnv(key, env); err != nil { + return Config{}, fmt.Errorf("bind env %q: %w", env, err) + } + } + + var cfg Config + if err := v.Unmarshal(&cfg); err != nil { + return Config{}, fmt.Errorf("unmarshal config: %w", err) + } + + if err := validate.Struct(cfg); err != nil { + return Config{}, fmt.Errorf("validate config: %w", err) + } + + if err := cfg.validateDependencies(); err != nil { + return Config{}, err + } + + return cfg, nil +} + +func (c Config) validateDependencies() error { + if c.Cache.Enabled && !c.Redis.Enabled { + return errors.New("validate config: cache.enabled requires redis.enabled") + } + + if c.S3.SweepGrace <= c.S3.PresignTTL { + return errors.New("validate config: s3.sweep_grace must exceed s3.presign_ttl") + } + + if c.Processing.LeaseTTL < 3*c.Processing.Heartbeat { + return errors.New("validate config: processing.lease_ttl must be at least 3x processing.heartbeat") + } + + if c.Processing.JobTimeout >= c.Processing.LeaseTTL { + return errors.New("validate config: processing.job_timeout must be below processing.lease_ttl") + } + + if c.Processing.RetryCap < c.Processing.RetryBase { + return errors.New("validate config: processing.retry_cap must be >= processing.retry_base") + } + + if c.Staging.FailedRetention < c.Staging.OrphanGrace { + return errors.New("validate config: staging.failed_retention must be >= staging.orphan_grace") + } + + if c.Broker.URL != "" { + if _, err := url.Parse(c.Broker.URL); err != nil { + return fmt.Errorf("validate config: broker.url: %w", err) + } + } + + return nil +} + +func configureSource(v *viper.Viper) error { + for key, value := range defaults { + v.SetDefault(key, value) + } + + v.SetConfigType("yaml") + + if path := os.Getenv(configEnvKey); path != "" { + v.SetConfigFile(path) + } else { + env := os.Getenv(envKey) + if env == "" { + env = defaultEnv + } + + v.SetConfigName(configName) + v.AddConfigPath(filepath.Join(configDir, env)) + } + + if err := v.ReadInConfig(); err != nil { + var notFound viper.ConfigFileNotFoundError + if errors.As(err, ¬Found) { + return nil + } + + return fmt.Errorf("read config: %w", err) + } + + return nil +} + +func (c Config) Addr() string { + return net.JoinHostPort(c.Server.Host, strconv.Itoa(c.Server.Port)) +} + +func (c Config) SlogLevel() slog.Level { + level, _ := logger.ParseLevel(c.Log.Level) + + return level +} + +func (c Config) LoggerFormat() logger.Format { + format, _ := logger.ParseFormat(c.Log.Format) + + return format +} + +var validate = newValidator() + +func newValidator() *validator.Validate { + v := validator.New(validator.WithRequiredStructEnabled()) + v.RegisterTagNameFunc(envName) + + return v +} + +func envName(field reflect.StructField) string { + key := field.Tag.Get("mapstructure") + if key == "" { + return field.Name + } + + return strings.ToUpper(key) +} diff --git a/internal/config/config_test.go b/internal/config/config_test.go new file mode 100644 index 0000000..ccd3abc --- /dev/null +++ b/internal/config/config_test.go @@ -0,0 +1,343 @@ +package config_test + +import ( + "os" + "path/filepath" + "testing" + "time" + + "github.com/go-playground/validator/v10" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + + "mtusi-messenger/internal/config" + "mtusi-messenger/internal/logger" +) + +func TestDefaults(t *testing.T) { + cfg, err := config.Load() + require.NoError(t, err) + + assert.Equal(t, "0.0.0.0", cfg.Server.Host) + assert.Equal(t, 8080, cfg.Server.Port) + assert.Equal(t, 10*time.Second, cfg.Server.ReadHeaderTimeout) + assert.Equal(t, 10*time.Second, cfg.Server.ShutdownTimeout) + assert.Equal(t, "info", cfg.Log.Level) + assert.Equal(t, "json", cfg.Log.Format) + assert.Equal(t, config.Postgres{}, cfg.Postgres, "postgres defaults live in the adapter") +} + +func TestEnvOverridesDefaults(t *testing.T) { + t.Setenv("SERVER_HOST", "127.0.0.1") + t.Setenv("SERVER_PORT", "9090") + t.Setenv("SERVER_READ_HEADER_TIMEOUT", "3s") + t.Setenv("SERVER_SHUTDOWN_TIMEOUT", "30s") + t.Setenv("LOG_LEVEL", "debug") + t.Setenv("LOG_FORMAT", "console") + + cfg, err := config.Load() + require.NoError(t, err) + + assert.Equal(t, "127.0.0.1", cfg.Server.Host) + assert.Equal(t, 9090, cfg.Server.Port) + assert.Equal(t, 3*time.Second, cfg.Server.ReadHeaderTimeout) + assert.Equal(t, 30*time.Second, cfg.Server.ShutdownTimeout) + assert.Equal(t, "debug", cfg.Log.Level) + assert.Equal(t, "console", cfg.Log.Format) +} + +func TestDsnEncodesCredentials(t *testing.T) { + cfg := config.Postgres{ + Host: "db", + Port: 5432, + Database: "app", + User: "user", + Password: "p@ss:w/rd", + SSLMode: "disable", + } + + assert.Equal(t, "postgres://user:p%40ss%3Aw%2Frd@db:5432/app?sslmode=disable", cfg.DSN()) +} + +func writeConfig(t *testing.T, body string) string { + t.Helper() + + path := filepath.Join(t.TempDir(), "config.yaml") + require.NoError(t, os.WriteFile(path, []byte(body), 0o600)) + + return path +} + +func TestLoadsYAMLFile(t *testing.T) { + path := writeConfig(t, ` +env: dev +server: + host: 10.0.0.1 + port: 9999 + read_header_timeout: 3s + shutdown_timeout: 7s +log: + level: debug + format: console +postgres: + host: db + port: 5433 + database: app + user: app + password: secret + ssl_mode: disable + max_conns: 7 + min_conns: 2 + max_conn_lifetime: 2h + max_conn_idle_time: 10m + connect_timeout: 2s + query_timeout: 3s +`) + + t.Setenv("APP_CONFIG", path) + + cfg, err := config.Load() + require.NoError(t, err) + + assert.Equal(t, "10.0.0.1", cfg.Server.Host) + assert.Equal(t, 9999, cfg.Server.Port) + assert.Equal(t, 3*time.Second, cfg.Server.ReadHeaderTimeout) + assert.Equal(t, "debug", cfg.Log.Level) + assert.Equal(t, "console", cfg.Log.Format) + assert.Equal(t, "db", cfg.Postgres.Host) + assert.Equal(t, 5433, cfg.Postgres.Port) + assert.Equal(t, "app", cfg.Postgres.Database) + assert.Equal(t, int32(7), cfg.Postgres.MaxConns) + assert.Equal(t, 2*time.Second, cfg.Postgres.ConnectTimeout) +} + +func TestEnvOverridesYAML(t *testing.T) { + path := writeConfig(t, ` +env: dev +server: + host: 10.0.0.1 + port: 9999 + read_header_timeout: 3s + shutdown_timeout: 7s +log: + level: debug + format: console +postgres: + host: db + port: 5433 + database: app + user: app + password: file + ssl_mode: disable +`) + + t.Setenv("APP_CONFIG", path) + t.Setenv("SERVER_HOST", "127.0.0.1") + t.Setenv("POSTGRES_PASSWORD", "env") + + cfg, err := config.Load() + require.NoError(t, err) + + assert.Equal(t, "127.0.0.1", cfg.Server.Host, "env переопределяет YAML") + assert.Equal(t, 9999, cfg.Server.Port) + assert.Equal(t, "env", cfg.Postgres.Password) +} + +func TestSessionTTLFromContractEnv(t *testing.T) { + t.Setenv("SESSION_TTL_SECONDS", "2") + + cfg, err := config.Load() + require.NoError(t, err) + + assert.Equal(t, 2, cfg.Session.TTLSeconds) +} + +func TestInvalidValues(t *testing.T) { + tests := map[string]map[string]string{ + "пустой server.host": {"SERVER_HOST": ""}, + "host не адрес и не имя": {"SERVER_HOST": "не адрес"}, + "порт ниже диапазона": {"SERVER_PORT": "0"}, + "порт выше диапазона": {"SERVER_PORT": "65536"}, + "нулевой read header timeout": {"SERVER_READ_HEADER_TIMEOUT": "0s"}, + "отрицательный shutdown": {"SERVER_SHUTDOWN_TIMEOUT": "-1s"}, + "неизвестный log level": {"LOG_LEVEL": "trace"}, + "неизвестный log format": {"LOG_FORMAT": "xml"}, + } + + for name, env := range tests { + t.Run(name, func(t *testing.T) { + for key, value := range env { + t.Setenv(key, value) + } + + _, err := config.Load() + require.Error(t, err) + + var validationErrs validator.ValidationErrors + require.ErrorAs(t, err, &validationErrs) + require.NotEmpty(t, validationErrs) + }) + } +} + +func TestInvalidPostgresValues(t *testing.T) { + path := writeConfig(t, ` +env: dev +postgres: + host: db + port: 5432 + database: messenger + user: messenger + ssl_mode: disable + max_conns: 10 +`) + + tests := map[string]map[string]string{ + "неизвестный ssl mode": {"POSTGRES_SSL_MODE": "bogus"}, + "отрицательный max_conns": {"POSTGRES_MAX_CONNS": "-1"}, + } + + for name, env := range tests { + t.Run(name, func(t *testing.T) { + t.Setenv("APP_CONFIG", path) + for key, value := range env { + t.Setenv(key, value) + } + + _, err := config.Load() + require.Error(t, err) + + var validationErrs validator.ValidationErrors + require.ErrorAs(t, err, &validationErrs) + require.NotEmpty(t, validationErrs) + }) + } +} + +func TestUnparsableValues(t *testing.T) { + tests := map[string]map[string]string{ + "порт не число": {"SERVER_PORT": "не-число"}, + "timeout не duration": {"SERVER_READ_HEADER_TIMEOUT": "быстро"}, + } + + for name, env := range tests { + t.Run(name, func(t *testing.T) { + for key, value := range env { + t.Setenv(key, value) + } + + _, err := config.Load() + require.Error(t, err) + }) + } +} + +func TestLoggerSettings(t *testing.T) { + t.Setenv("LOG_LEVEL", "warn") + t.Setenv("LOG_FORMAT", "console") + + cfg, err := config.Load() + require.NoError(t, err) + + level, err := logger.ParseLevel(cfg.Log.Level) + require.NoError(t, err) + assert.Equal(t, level, cfg.SlogLevel()) + + format, err := logger.ParseFormat(cfg.Log.Format) + require.NoError(t, err) + assert.Equal(t, format, cfg.LoggerFormat()) +} + +func TestAddr(t *testing.T) { + t.Setenv("SERVER_HOST", "0.0.0.0") + t.Setenv("SERVER_PORT", "8080") + + cfg, err := config.Load() + require.NoError(t, err) + + assert.Equal(t, "0.0.0.0:8080", cfg.Addr()) +} + +func TestAddrWithIPv6Host(t *testing.T) { + t.Setenv("SERVER_HOST", "::1") + + cfg, err := config.Load() + require.NoError(t, err) + + assert.Equal(t, "[::1]:8080", cfg.Addr()) +} + +func TestLoadIsIndependentOfProcessState(t *testing.T) { + t.Setenv("SERVER_PORT", "7070") + + first, err := config.Load() + require.NoError(t, err) + + second, err := config.Load() + require.NoError(t, err) + + assert.Equal(t, first, second) +} + +func TestRedisDefaultsDisabled(t *testing.T) { + cfg, err := config.Load() + require.NoError(t, err) + + assert.False(t, cfg.Redis.Enabled) + assert.Equal(t, "localhost", cfg.Redis.Host) + assert.Equal(t, 6379, cfg.Redis.Port) + assert.Equal(t, -1, cfg.Redis.MaxRetries) + assert.Equal(t, 300*time.Millisecond, cfg.Redis.DialTimeout) + assert.Equal(t, 200*time.Millisecond, cfg.Redis.ReadTimeout) + assert.Equal(t, 200*time.Millisecond, cfg.Redis.WriteTimeout) + assert.False(t, cfg.Cache.Enabled) + assert.Equal(t, 5*time.Minute, cfg.Cache.ChatListTTL) + assert.Equal(t, 10*time.Second, cfg.Cache.LockTTL) + assert.Equal(t, 2*time.Second, cfg.Cache.LockWaitTimeout) +} + +func TestRedisEnvOverrides(t *testing.T) { + t.Setenv("REDIS_ENABLED", "true") + t.Setenv("REDIS_HOST", "cache") + t.Setenv("REDIS_PORT", "6380") + t.Setenv("CACHE_ENABLED", "true") + t.Setenv("CACHE_CHAT_LIST_TTL", "1m") + t.Setenv("CACHE_LOCK_TTL", "7s") + t.Setenv("CACHE_LOCK_WAIT_TIMEOUT", "1500ms") + + cfg, err := config.Load() + require.NoError(t, err) + + assert.True(t, cfg.Redis.Enabled) + assert.Equal(t, "cache", cfg.Redis.Host) + assert.Equal(t, 6380, cfg.Redis.Port) + assert.True(t, cfg.Cache.Enabled) + assert.Equal(t, time.Minute, cfg.Cache.ChatListTTL) + assert.Equal(t, 7*time.Second, cfg.Cache.LockTTL) + assert.Equal(t, 1500*time.Millisecond, cfg.Cache.LockWaitTimeout) +} + +func TestInvalidCacheTTL(t *testing.T) { + for _, key := range []string{ + "CACHE_CHAT_LIST_TTL", + "CACHE_LOCK_TTL", + "CACHE_LOCK_WAIT_TIMEOUT", + } { + for _, value := range []string{"0s", "-1s"} { + t.Run(key+"/"+value, func(t *testing.T) { + t.Setenv(key, value) + _, err := config.Load() + require.Error(t, err) + var validationErrs validator.ValidationErrors + require.ErrorAs(t, err, &validationErrs) + }) + } + } +} + +func TestCacheRequiresRedis(t *testing.T) { + t.Setenv("CACHE_ENABLED", "true") + + _, err := config.Load() + require.ErrorContains(t, err, "cache.enabled requires redis.enabled") +} diff --git a/internal/domain/attachment.go b/internal/domain/attachment.go new file mode 100644 index 0000000..fabf698 --- /dev/null +++ b/internal/domain/attachment.go @@ -0,0 +1,171 @@ +package domain + +import ( + "time" + + "github.com/google/uuid" +) + +// AttachmentStatus is the public lifecycle of an attachment. Pending is an +// internal presign state and is never exposed by the API. +type AttachmentStatus string + +const ( + AttachmentPending AttachmentStatus = "pending" + AttachmentQueued AttachmentStatus = "queued" + AttachmentProcessing AttachmentStatus = "processing" + AttachmentReady AttachmentStatus = "ready" + AttachmentFailed AttachmentStatus = "failed" +) + +func (s AttachmentStatus) Valid() bool { + switch s { + case AttachmentPending, AttachmentQueued, AttachmentProcessing, AttachmentReady, AttachmentFailed: + return true + default: + return false + } +} + +// Public reports whether the status is part of the API enum. +func (s AttachmentStatus) Public() bool { + switch s { + case AttachmentQueued, AttachmentProcessing, AttachmentReady, AttachmentFailed: + return true + default: + return false + } +} + +// VariantName is the contract variant identifier. +type VariantName string + +const ( + VariantOriginal VariantName = "original" + VariantThumbnail VariantName = "thumbnail" + VariantCrop VariantName = "crop" + VariantOptimized VariantName = "optimized" +) + +func (n VariantName) Valid() bool { + switch n { + case VariantThumbnail, VariantCrop, VariantOptimized: + return true + default: + return false + } +} + +// ContentType returns the contract media type of the variant. +func (n VariantName) ContentType() string { + if n == VariantOptimized { + return "image/webp" + } + + return "image/jpeg" +} + +// ObjectName returns the object suffix for the variant. +func (n VariantName) ObjectName() string { + if n == VariantOptimized { + return string(n) + ".webp" + } + + return string(n) + ".jpg" +} + +// Variant is one derived image. ObjectKey is internal and never leaves the +// service. +type Variant struct { + Name VariantName + ContentType string + SizeBytes int64 + Width int + Height int + SHA256 string + ObjectKey string +} + +// Attachment describes the original object and the current pipeline result. +type Attachment struct { + ID uuid.UUID + ChatID uuid.UUID + OwnerID uuid.UUID + Filename string + ContentType string + SizeBytes int64 + SHA256 string + Status AttachmentStatus + ErrorCode *string + ObjectKey string + StagingKey string + PipelineVersion int + Variants []Variant + CreatedAt time.Time + UpdatedAt time.Time + ReadyAt *time.Time + FailedAt *time.Time +} + +// AdmissionLimits bounds accepted-but-unfinished work. Zero means unlimited. +type AdmissionLimits struct { + PerUser int + Total int + Bytes int64 +} + +// AttachmentDraft is a fully validated attachment awaiting persistence. +type AttachmentDraft struct { + ID uuid.UUID + ChatID uuid.UUID + OwnerID uuid.UUID + ObjectKey string + StagingKey string + Filename string + ContentType string + SizeBytes int64 + SHA256 string + Status AttachmentStatus + PipelineVersion int +} + +// AttachmentState is the minimal projection used while validating message +// attachments in a transaction. +type AttachmentState struct { + ID uuid.UUID + Status AttachmentStatus +} + +// AttachmentKey is the minimal projection used by the orphan sweeper. +type AttachmentKey struct { + ID uuid.UUID + ObjectKey string + Status AttachmentStatus + CreatedAt time.Time +} + +// StaleStaging is one staging object whose owner row is already terminal. +type StaleStaging struct { + AttachmentID uuid.UUID + StagingKey string + Status AttachmentStatus +} + +// PresignRequest is the validated client intent for a direct upload. +type PresignRequest struct { + ChatID uuid.UUID + OwnerID uuid.UUID + Filename string + ContentType string + SizeBytes int64 + SHA256 string +} + +// PresignResult is returned by the server and never contains credentials. +type PresignResult struct { + AttachmentID uuid.UUID + UploadURL string + ExpiresAt time.Time + SizeBytes int64 + SHA256 string +} diff --git a/internal/domain/chat.go b/internal/domain/chat.go new file mode 100644 index 0000000..9438528 --- /dev/null +++ b/internal/domain/chat.go @@ -0,0 +1,51 @@ +package domain + +import ( + "fmt" + "slices" + "time" + + "github.com/google/uuid" +) + +type Chat struct { + ID uuid.UUID + Title string + MemberIDs []uuid.UUID + CreatedAt time.Time +} + +func (c Chat) HasMember(userID uuid.UUID) bool { + return slices.Contains(c.MemberIDs, userID) +} + +type ChatDraft struct { + Title string + MemberIDs []uuid.UUID + CallerID uuid.UUID +} + +func (d ChatDraft) Validate() error { + if err := validateNotBlank("title", d.Title); err != nil { + return err + } + + if len(d.MemberIDs) == 0 { + return fmt.Errorf("member_ids must not be empty: %w", ErrValidation) + } + + seen := make(map[uuid.UUID]struct{}, len(d.MemberIDs)) + for _, id := range d.MemberIDs { + if _, ok := seen[id]; ok { + return fmt.Errorf("member_ids contains duplicates: %w", ErrValidation) + } + + seen[id] = struct{}{} + } + + if _, ok := seen[d.CallerID]; !ok { + return fmt.Errorf("member_ids must contain the caller: %w", ErrValidation) + } + + return nil +} diff --git a/internal/domain/cursor.go b/internal/domain/cursor.go new file mode 100644 index 0000000..e18118c --- /dev/null +++ b/internal/domain/cursor.go @@ -0,0 +1,17 @@ +package domain + +import ( + "time" + + "github.com/google/uuid" +) + +type Cursor struct { + Scope uuid.UUID + CreatedAt time.Time + ID uuid.UUID +} + +func (c Cursor) BelongsTo(scope uuid.UUID) bool { + return c.Scope == scope +} diff --git a/internal/domain/errors.go b/internal/domain/errors.go new file mode 100644 index 0000000..c582328 --- /dev/null +++ b/internal/domain/errors.go @@ -0,0 +1,19 @@ +package domain + +import "errors" + +var ( + ErrNotFound = errors.New("not found") + ErrUsernameTaken = errors.New("username already taken") + ErrUnknownMember = errors.New("member does not exist") + ErrValidation = errors.New("validation failed") + ErrInvalidCursor = errors.New("invalid cursor") + ErrConflict = errors.New("conflict") + ErrIdempotency = errors.New("idempotency key already used with another payload") + ErrUnauthenticated = errors.New("unauthenticated") + ErrUnavailable = errors.New("temporarily unavailable") + ErrTooLarge = errors.New("payload is too large") + ErrUnsupportedMedia = errors.New("unsupported media type") + ErrIncomplete = errors.New("object is not fully uploaded") + ErrRateLimited = errors.New("too many unfinished uploads") +) diff --git a/internal/domain/job.go b/internal/domain/job.go new file mode 100644 index 0000000..481775b --- /dev/null +++ b/internal/domain/job.go @@ -0,0 +1,192 @@ +package domain + +import ( + "encoding/json" + "errors" + "fmt" + "regexp" + "time" + + "github.com/google/uuid" +) + +// JobType is the fixed contract type from contracts/jobs.schema.json. +const JobType = "attachment.process.v1" + +// JobStatus is the durable state of one logical processing job. Superseded is +// internal: a newer pipeline version replaced the job before it completed. +type JobStatus string + +const ( + JobQueued JobStatus = "queued" + JobProcessing JobStatus = "processing" + JobReady JobStatus = "ready" + JobFailed JobStatus = "failed" + JobSuperseded JobStatus = "superseded" +) + +func (s JobStatus) Valid() bool { + switch s { + case JobQueued, JobProcessing, JobReady, JobFailed, JobSuperseded: + return true + default: + return false + } +} + +// Job is the durable processing intent. SourceKey is the trusted object the +// worker reads: staging for a fresh upload, the original object for reprocess. +type Job struct { + ID uuid.UUID + AttachmentID uuid.UUID + PipelineVersion int + SourceKey string + Attempt int + MaxAttempts int + Status JobStatus + AvailableAt time.Time + LeaseOwner string + LeaseExpiresAt *time.Time + LastErrorCode *string + ReplayCount int + CreatedAt time.Time + UpdatedAt time.Time + CompletedAt *time.Time + Traceparent string + Tracestate string +} + +// OutboxMessage is one pending broker publication. Payload is the exact +// jobs.schema.json document; no binary data or credentials are stored. +type OutboxMessage struct { + ID int64 + JobID uuid.UUID + Attempt int + Kind string + RoutingKey string + Payload []byte + AvailableAt time.Time + PublishedAt *time.Time + ClaimedBy string + ClaimedUntil *time.Time + PublishAttempts int + LastError *string + CreatedAt time.Time +} + +// JobMessage is the broker carrier defined by contracts/jobs.schema.json. +type JobMessage struct { + SchemaVersion int `json:"schema_version"` + JobID uuid.UUID `json:"job_id"` + Type string `json:"type"` + AttachmentID uuid.UUID `json:"attachment_id"` + PipelineVersion int `json:"pipeline_version"` + Attempt int `json:"attempt"` + CreatedAt time.Time `json:"created_at"` + Traceparent string `json:"traceparent,omitempty"` + Tracestate string `json:"tracestate,omitempty"` +} + +// NewJobMessage builds the only message the application is allowed to publish. +func NewJobMessage(job Job) JobMessage { + return JobMessage{ + SchemaVersion: 1, + JobID: job.ID, + Type: JobType, + AttachmentID: job.AttachmentID, + PipelineVersion: job.PipelineVersion, + Attempt: job.Attempt, + CreatedAt: job.CreatedAt.UTC(), + } +} + +// Validate enforces the closed schema. The worker must never trust paths or +// storage metadata from this message. +func (m JobMessage) Validate() error { + if m.SchemaVersion != 1 { + return errors.New("unsupported schema_version") + } + + if m.Type != JobType { + return fmt.Errorf("unsupported type %q", m.Type) + } + + if m.JobID == uuid.Nil || m.AttachmentID == uuid.Nil { + return errors.New("job_id and attachment_id are required") + } + + if m.PipelineVersion < 1 || m.Attempt < 1 { + return errors.New("pipeline_version and attempt must be >= 1") + } + + if m.CreatedAt.IsZero() { + return errors.New("created_at is required") + } + + if m.Traceparent != "" && !traceparentPattern.MatchString(m.Traceparent) { + return errors.New("traceparent does not match W3C format") + } + if len(m.Tracestate) > 512 { + return errors.New("tracestate is too long") + } + + return nil +} + +var traceparentPattern = regexp.MustCompile(`^00-[0-9a-f]{32}-[0-9a-f]{16}-[0-9a-f]{2}$`) + +func (m JobMessage) MarshalPayload() ([]byte, error) { + return json.Marshal(m) +} + +func ParseJobMessage(payload []byte) (JobMessage, error) { + var message JobMessage + + if err := json.Unmarshal(payload, &message); err != nil { + return JobMessage{}, fmt.Errorf("decode job message: %w", err) + } + + if err := message.Validate(); err != nil { + return JobMessage{}, err + } + + return message, nil +} + +// ClaimOutcome explains why a delivery did or did not become the active +// processing attempt. The worker maps it to ack/nack without guessing. +type ClaimOutcome string + +const ( + ClaimAcquired ClaimOutcome = "acquired" + ClaimAlreadyReady ClaimOutcome = "already_ready" + ClaimAlreadyFailed ClaimOutcome = "already_failed" + ClaimSuperseded ClaimOutcome = "superseded" + ClaimStaleAttempt ClaimOutcome = "stale_attempt" + ClaimFutureAttempt ClaimOutcome = "future_attempt" + ClaimBusyLease ClaimOutcome = "busy_lease" + ClaimNotDue ClaimOutcome = "not_due" + ClaimVersionStale ClaimOutcome = "version_stale" + ClaimJobNotFound ClaimOutcome = "job_not_found" + ClaimSourceMissing ClaimOutcome = "source_missing" + ClaimPayloadInvalid ClaimOutcome = "payload_invalid" +) + +type ClaimResult struct { + Outcome ClaimOutcome + Job Job + Attachment Attachment +} + +// Job event names used by the operator audit trail. +const ( + EventEnqueued = "enqueued" + EventClaimed = "claimed" + EventRetried = "retried" + EventReady = "ready" + EventFailed = "failed" + EventLeaseExpired = "lease_expired" + EventReplayed = "replayed" + EventReprocessed = "reprocessed" + EventSuperseded = "superseded" +) diff --git a/internal/domain/keys.go b/internal/domain/keys.go new file mode 100644 index 0000000..d99ab7b --- /dev/null +++ b/internal/domain/keys.go @@ -0,0 +1,31 @@ +package domain + +import ( + "strconv" + + "github.com/google/uuid" +) + +const ( + StagingUploadPrefix = "staging/uploads/" + StagingVerifiedPrefix = "staging/verified/" + StagingPresignPrefix = "staging/presign/" + AttachmentsPrefix = "attachments/" +) + +func StagingUploadKey(chatID, attachmentID uuid.UUID) string { + return StagingUploadPrefix + chatID.String() + "/" + attachmentID.String() +} + +func StagingVerifiedKey(chatID, attachmentID uuid.UUID) string { + return StagingVerifiedPrefix + chatID.String() + "/" + attachmentID.String() +} + +func OriginalObjectKey(chatID, attachmentID uuid.UUID) string { + return AttachmentsPrefix + chatID.String() + "/" + attachmentID.String() + "/original" +} + +func VariantObjectKey(chatID, attachmentID uuid.UUID, pipelineVersion int, name VariantName) string { + return AttachmentsPrefix + chatID.String() + "/" + attachmentID.String() + + "/variants/v" + strconv.Itoa(pipelineVersion) + "/" + name.ObjectName() +} diff --git a/internal/domain/message.go b/internal/domain/message.go new file mode 100644 index 0000000..9820c38 --- /dev/null +++ b/internal/domain/message.go @@ -0,0 +1,70 @@ +package domain + +import ( + "crypto/sha256" + "fmt" + "strings" + "time" + + "github.com/google/uuid" +) + +// MaxMessageAttachments is the contract limit for attachment_ids on a message. +const MaxMessageAttachments = 10 + +type Message struct { + ID uuid.UUID + ChatID uuid.UUID + SenderID uuid.UUID + Text string + AttachmentIDs []uuid.UUID + CreatedAt time.Time +} + +// MessageIdempotency is the client Idempotency-Key together with the fingerprint +// of the payload it was first used with. The same key and fingerprint replay the +// stored message; the same key with another payload is a conflict. +type MessageIdempotency struct { + Key string + RequestHash [sha256.Size]byte +} + +type MessageDraft struct { + ChatID uuid.UUID + SenderID uuid.UUID + Text string + AttachmentIDs []uuid.UUID + Idempotency MessageIdempotency +} + +// Validate enforces the contract rule that a message carries either non-blank +// text or at least one attachment, never neither. +func (d MessageDraft) Validate() error { + if strings.TrimSpace(d.Text) == "" && len(d.AttachmentIDs) == 0 { + return fmt.Errorf("message has neither text nor attachments: %w", ErrValidation) + } + + if len(d.AttachmentIDs) > MaxMessageAttachments { + return fmt.Errorf("too many attachments: %w", ErrValidation) + } + + seen := make(map[uuid.UUID]struct{}, len(d.AttachmentIDs)) + + for _, id := range d.AttachmentIDs { + if id == uuid.Nil { + return fmt.Errorf("attachment id is empty: %w", ErrValidation) + } + + if _, ok := seen[id]; ok { + return fmt.Errorf("duplicate attachment id %s: %w", id, ErrValidation) + } + + seen[id] = struct{}{} + } + + if d.Idempotency.Key == "" { + return fmt.Errorf("idempotency key is missing: %w", ErrValidation) + } + + return nil +} diff --git a/internal/domain/page.go b/internal/domain/page.go new file mode 100644 index 0000000..bd0bd31 --- /dev/null +++ b/internal/domain/page.go @@ -0,0 +1,8 @@ +package domain + +const DefaultPageLimit = 50 + +type Page[T any] struct { + Items []T + Next *Cursor +} diff --git a/internal/domain/session.go b/internal/domain/session.go new file mode 100644 index 0000000..0aea153 --- /dev/null +++ b/internal/domain/session.go @@ -0,0 +1,19 @@ +package domain + +import ( + "time" + + "github.com/google/uuid" +) + +type Session struct { + Token string + ExpiresAt time.Time + User User +} + +type NewSession struct { + TokenHash []byte + UserID uuid.UUID + ExpiresAt time.Time +} diff --git a/internal/domain/text.go b/internal/domain/text.go new file mode 100644 index 0000000..e944b85 --- /dev/null +++ b/internal/domain/text.go @@ -0,0 +1,14 @@ +package domain + +import ( + "fmt" + "strings" +) + +func validateNotBlank(field, value string) error { + if strings.TrimSpace(value) == "" { + return fmt.Errorf("%s consists of whitespace only: %w", field, ErrValidation) + } + + return nil +} diff --git a/internal/domain/user.go b/internal/domain/user.go new file mode 100644 index 0000000..5bb4ffe --- /dev/null +++ b/internal/domain/user.go @@ -0,0 +1,44 @@ +package domain + +import ( + "fmt" + "time" + + "github.com/google/uuid" +) + +type User struct { + ID uuid.UUID + Username string + DisplayName string + CreatedAt time.Time +} + +type UserDraft struct { + Username string + DisplayName string + Password string +} + +func (d UserDraft) Validate() error { + if err := validateNotBlank("display_name", d.DisplayName); err != nil { + return err + } + + if length := len([]rune(d.Password)); length < 12 || length > 128 { + return fmt.Errorf("password length must be between 12 and 128 code points: %w", ErrValidation) + } + + return nil +} + +type NewUser struct { + Username string + DisplayName string + PasswordHash string +} + +type UserCredentials struct { + User User + PasswordHash string +} diff --git a/internal/domain/validation_test.go b/internal/domain/validation_test.go new file mode 100644 index 0000000..adff519 --- /dev/null +++ b/internal/domain/validation_test.go @@ -0,0 +1,121 @@ +package domain_test + +import ( + "strings" + "testing" + + "github.com/google/uuid" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + + "mtusi-messenger/internal/domain" +) + +// Длины, regex и uniqueItems проверяет сгенерированный слой по contracts/openapi.json. +// Домен закрывает только то, что схема выразить не может. + +func TestUserDraftRejectsBlankDisplayName(t *testing.T) { + t.Parallel() + + for _, blank := range []string{" ", " ", "\t", "\n", "\u00a0"} { + draft := domain.UserDraft{Username: "alice", DisplayName: blank} + require.ErrorIs(t, draft.Validate(), domain.ErrValidation) + } +} + +func TestUserDraftAcceptsVisibleName(t *testing.T) { + t.Parallel() + + draft := domain.UserDraft{Username: "alice", DisplayName: "Алиса", Password: "very-secret-password"} + assert.NoError(t, draft.Validate()) +} + +func TestUserDraftRejectsShortPassword(t *testing.T) { + t.Parallel() + + draft := domain.UserDraft{Username: "alice", DisplayName: "Алиса", Password: "too-short"} + require.ErrorIs(t, draft.Validate(), domain.ErrValidation) +} + +func TestUserDraftRejectsTooLongPassword(t *testing.T) { + t.Parallel() + + draft := domain.UserDraft{Username: "alice", DisplayName: "Алиса", Password: strings.Repeat("a", 129)} + require.ErrorIs(t, draft.Validate(), domain.ErrValidation) +} + +func TestUserDraftAcceptsMinimalPassword(t *testing.T) { + t.Parallel() + + draft := domain.UserDraft{Username: "alice", DisplayName: "Алиса", Password: strings.Repeat("a", 12)} + assert.NoError(t, draft.Validate()) +} + +func TestChatDraftRequiresCallerAmongMembers(t *testing.T) { + t.Parallel() + + caller := uuid.New() + + outside := domain.ChatDraft{ + Title: "Проект", + MemberIDs: []uuid.UUID{uuid.New(), uuid.New()}, + CallerID: caller, + } + require.ErrorIs(t, outside.Validate(), domain.ErrValidation) + + inside := domain.ChatDraft{ + Title: "Проект", + MemberIDs: []uuid.UUID{uuid.New(), caller}, + CallerID: caller, + } + assert.NoError(t, inside.Validate()) +} + +func TestChatDraftRejectsBlankTitle(t *testing.T) { + t.Parallel() + + caller := uuid.New() + + draft := domain.ChatDraft{ + Title: " ", + MemberIDs: []uuid.UUID{caller}, + CallerID: caller, + } + require.ErrorIs(t, draft.Validate(), domain.ErrValidation) +} + +func TestMessageDraftRejectsBlankText(t *testing.T) { + t.Parallel() + + draft := domain.MessageDraft{ + ChatID: uuid.New(), + SenderID: uuid.New(), + Text: strings.Repeat(" ", 10), + Idempotency: domain.MessageIdempotency{Key: "key-1"}, + } + require.ErrorIs(t, draft.Validate(), domain.ErrValidation) +} + +func TestMessageDraftRejectsMissingIdempotencyKey(t *testing.T) { + t.Parallel() + + draft := domain.MessageDraft{ + ChatID: uuid.New(), + SenderID: uuid.New(), + Text: "привет", + } + require.ErrorIs(t, draft.Validate(), domain.ErrValidation, + "с lab3 отправка сообщения невозможна без Idempotency-Key") +} + +func TestMessageDraftAcceptsTextWithSurroundingSpaces(t *testing.T) { + t.Parallel() + + draft := domain.MessageDraft{ + ChatID: uuid.New(), + SenderID: uuid.New(), + Text: " привет ", + Idempotency: domain.MessageIdempotency{Key: "key-1"}, + } + assert.NoError(t, draft.Validate(), "контракт запрещает только полностью пробельный текст") +} diff --git a/internal/failpoint/failpoint.go b/internal/failpoint/failpoint.go new file mode 100644 index 0000000..c43cf00 --- /dev/null +++ b/internal/failpoint/failpoint.go @@ -0,0 +1,107 @@ +// Package failpoint implements deterministic, environment-gated crash windows +// for the lab5 fault-injection evidence. Nothing fires unless FAULTS_ENABLED=1 +// and the action matches both FAULT_ and, for job-scoped faults, +// FAULT_TARGET_JOB. Production and CI leave the variables unset. +package failpoint + +import ( + "log/slog" + "os" + "path/filepath" + "time" + + "github.com/google/uuid" +) + +// Enabled reports whether fault injection is explicitly switched on. +func Enabled() bool { + if os.Getenv("FAULTS_ENABLED") != "1" { + return false + } + + env := os.Getenv("APP_ENV") + return env == "" || env == "dev" +} + +// Check exits the process if the action is armed for this job. It must be +// called at the exact window the evidence describes; a marker line is written +// before exit so the harness can prove the fault actually fired. +func Check(action string, jobID uuid.UUID) { + if !Enabled() { + return + } + + if os.Getenv("FAULT_"+action) != "exit" { + return + } + + target := os.Getenv("FAULT_TARGET_JOB") + if target != "" && target != jobID.String() { + return + } + + // A one-shot marker survives the container restart performed by the + // restart policy. Without it a targeted crash failpoint would loop forever. + marker := filepath.Join(os.TempDir(), "messenger-failpoint-"+action+"-"+jobID.String()) + if _, err := os.Stat(marker); err == nil { + return + } + + _ = os.WriteFile(marker, []byte("fired\n"), 0o600) + + slog.Default().Error("failpoint fired", + slog.String("action", action), + slog.String("job_id", jobID.String()), + slog.Int("exit_code", 70), + ) + _ = os.Stdout.Sync() + _ = os.Stderr.Sync() + + os.Exit(70) +} + +// Mode returns the armed value for an action/job pair. Unlike Check it does not +// exit; the worker uses it to inject a permanent or transient processing error. +func Mode(action string, jobID uuid.UUID) string { + if !Enabled() { + return "" + } + + target := os.Getenv("FAULT_TARGET_JOB") + if target != "" && target != jobID.String() { + return "" + } + + return os.Getenv("FAULT_" + action) +} + +// Sleep blocks for the configured duration when the action is armed for this +// job. It is used for hang/slow-worker scenarios where the heartbeat must keep +// running (the caller controls that separately). +func Sleep(action string, jobID uuid.UUID) { + if !Enabled() { + return + } + + raw := os.Getenv("FAULT_" + action) + if raw == "" { + return + } + + target := os.Getenv("FAULT_TARGET_JOB") + if target != "" && target != jobID.String() { + return + } + + delay, err := time.ParseDuration(raw) + if err != nil { + return + } + + slog.Default().Warn("failpoint sleeping", + slog.String("action", action), + slog.String("job_id", jobID.String()), + slog.Duration("duration", delay), + ) + time.Sleep(delay) +} diff --git a/internal/health/checker.go b/internal/health/checker.go new file mode 100644 index 0000000..86fc322 --- /dev/null +++ b/internal/health/checker.go @@ -0,0 +1,28 @@ +package health + +import ( + "context" + "fmt" +) + +type Pinger interface { + Ping(ctx context.Context) error +} + +type Checker struct { + pingers []Pinger +} + +func New(pingers ...Pinger) *Checker { + return &Checker{pingers: pingers} +} + +func (c *Checker) Ping(ctx context.Context) error { + for _, pinger := range c.pingers { + if err := pinger.Ping(ctx); err != nil { + return fmt.Errorf("ping %T: %w", pinger, err) + } + } + + return nil +} diff --git a/internal/health/checker_test.go b/internal/health/checker_test.go new file mode 100644 index 0000000..e379655 --- /dev/null +++ b/internal/health/checker_test.go @@ -0,0 +1,33 @@ +package health_test + +import ( + "context" + "errors" + "testing" + + "github.com/stretchr/testify/require" + + "mtusi-messenger/internal/health" +) + +type stubPinger struct { + err error +} + +func (s stubPinger) Ping(context.Context) error { return s.err } + +func TestCheckerPassesWhenAllHealthy(t *testing.T) { + t.Parallel() + + checker := health.New(stubPinger{}, stubPinger{}) + require.NoError(t, checker.Ping(context.Background())) +} + +func TestCheckerReturnsFirstFailure(t *testing.T) { + t.Parallel() + + sentinel := errors.New("dependency down") + checker := health.New(stubPinger{}, stubPinger{err: sentinel}, stubPinger{err: errors.New("later")}) + + require.ErrorIs(t, checker.Ping(context.Background()), sentinel) +} diff --git a/internal/imagecheck/imagecheck.go b/internal/imagecheck/imagecheck.go new file mode 100644 index 0000000..c746f88 --- /dev/null +++ b/internal/imagecheck/imagecheck.go @@ -0,0 +1,668 @@ +// Package imagecheck validates PNG and JPEG structure without decoding the +// raster into an image. A full decode of a 40-megapixel image would allocate +// hundreds of megabytes; attachment uploads must stay bounded. For PNG the +// parser verifies chunk CRCs and streams the zlib image data to check exact +// scanline sizes and filter types without keeping the raster in memory. The +// JPEG parser verifies marker/scan structure. Both catch truncation and +// corruption while using bounded memory. +package imagecheck + +import ( + "bufio" + "bytes" + "compress/zlib" + "encoding/binary" + "errors" + "fmt" + "hash/crc32" + "io" + "os" +) + +var ( + ErrUnsupported = errors.New("unsupported image format") + ErrCorrupt = errors.New("corrupt image") + ErrTooLarge = errors.New("image has too many pixels") +) + +const ( + pngSignature = "\x89PNG\r\n\x1a\n" + maxChunkSize = 1 << 30 +) + +// Info is the validated header. ContentType is one of image/png or image/jpeg. +type Info struct { + ContentType string + Width int64 + Height int64 +} + +func ValidateFile(path string, maxPixels int64) (Info, error) { + file, err := os.Open(path) + if err != nil { + return Info{}, fmt.Errorf("open upload: %w", err) + } + defer func() { _ = file.Close() }() + + return Validate(file, maxPixels) +} + +// Validate consumes the reader to EOF (so a caller hashing the stream gets all +// bytes) and returns the detected format and dimensions. +func Validate(r io.Reader, maxPixels int64) (Info, error) { + reader := bufio.NewReaderSize(r, 64<<10) + + header, err := reader.Peek(8) + if err != nil { + if errors.Is(err, io.EOF) || errors.Is(err, io.ErrUnexpectedEOF) { + return Info{}, fmt.Errorf("%w: image is empty or truncated", ErrUnsupported) + } + + return Info{}, err + } + + switch { + case string(header[:8]) == pngSignature: + return validatePNG(reader, maxPixels) + case header[0] == 0xFF && header[1] == 0xD8 && header[2] == 0xFF: + return validateJPEG(reader, maxPixels) + default: + return Info{}, fmt.Errorf("%w: unrecognised signature", ErrUnsupported) + } +} + +func validatePNG(reader *bufio.Reader, maxPixels int64) (Info, error) { + if _, err := reader.Discard(len(pngSignature)); err != nil { + return Info{}, corrupt("png signature", err) + } + + var ( + info Info + seen = make(map[string]bool, 4) + first = true + hasIDAT bool + paletteReady bool + trnsSeen bool + colorType byte + bitDepth byte + paletteEntries int + idat bytes.Buffer + raster []pngPass + rasterBytes int64 + maxIDAT int64 = -1 + lastChunk string + ) + + info.ContentType = "image/png" + + for { + var lengthBytes [4]byte + if _, err := io.ReadFull(reader, lengthBytes[:]); err != nil { + return Info{}, corrupt("png chunk length", err) + } + + length := int64(binary.BigEndian.Uint32(lengthBytes[:])) + if length < 0 || length > maxChunkSize { + return Info{}, corruptf("png chunk length %d", length) + } + + var typeBytes [4]byte + if _, err := io.ReadFull(reader, typeBytes[:]); err != nil { + return Info{}, corrupt("png chunk type", err) + } + + chunkType := string(typeBytes[:]) + checksum := crc32.NewIEEE() + _, _ = checksum.Write(typeBytes[:]) + + if first && chunkType != "IHDR" { + return Info{}, corruptf("png first chunk is %q, want IHDR", chunkType) + } + + first = false + + if seen[chunkType] && (chunkType == "IHDR" || chunkType == "PLTE" || chunkType == "IEND") { + return Info{}, corruptf("png duplicate %s chunk", chunkType) + } + + if chunkType == "PLTE" && hasIDAT { + return Info{}, corruptf("png PLTE chunk after IDAT") + } + + if chunkType == "IDAT" && seen["IDAT"] && lastChunk != "IDAT" { + return Info{}, corruptf("png IDAT chunks must be consecutive") + } + + if err := checkCriticalChunk(chunkType, seen); err != nil { + return Info{}, err + } + + var chunkSink io.Writer + if chunkType == "IDAT" { + if maxIDAT >= 0 && int64(idat.Len())+length > maxIDAT { + return Info{}, corruptf("png idat compressed data exceeds %d bytes", maxIDAT) + } + + chunkSink = &idat + } + + data, err := readChunkData(reader, checksum, length, chunkSink) + if err != nil { + return Info{}, corrupt("png chunk data", err) + } + + var crcBytes [4]byte + if _, err := io.ReadFull(reader, crcBytes[:]); err != nil { + return Info{}, corrupt("png chunk crc", err) + } + + if binary.BigEndian.Uint32(crcBytes[:]) != checksum.Sum32() { + return Info{}, corruptf("png chunk %q crc mismatch", chunkType) + } + + switch chunkType { + case "IHDR": + if length != 13 { + return Info{}, corruptf("png IHDR length %d", length) + } + + info.Width = int64(binary.BigEndian.Uint32(data[0:4])) + info.Height = int64(binary.BigEndian.Uint32(data[4:8])) + colorType = data[9] + bitDepth = data[8] + + if info.Width <= 0 || info.Height <= 0 { + return Info{}, corruptf("png dimensions %dx%d", info.Width, info.Height) + } + + // Short-circuit before multiplying: a malicious IHDR can contain + // 32-bit dimensions whose product overflows int64. + if maxPixels > 0 && (info.Width > maxPixels || info.Height > maxPixels || info.Width*info.Height > maxPixels) { + return Info{}, fmt.Errorf("%w: %dx%d", ErrTooLarge, info.Width, info.Height) + } + + bound, err := pngRasterLayout(info, data[8], data[9], data[10], data[11], data[12]) + if err != nil { + return Info{}, err + } + + raster = bound + rasterBytes = pngRasterBytes(bound) + if rasterBytes <= 1<<40 { + // zlib overhead: ~5 bytes per 16 KiB block, 2-byte header and + // a 4-byte Adler trailer. The 1 MiB constant covers tiny + // images where the relative term vanishes. + maxIDAT = rasterBytes + rasterBytes/256 + 1<<20 + } + case "IDAT": + hasIDAT = true + case "PLTE": + if colorType == 0 || colorType == 4 { + return Info{}, corruptf("png PLTE is invalid for color type %d", colorType) + } + + if length == 0 || length%3 != 0 || length > 3*256 { + return Info{}, corruptf("png PLTE length %d", length) + } + + if length/3 > 1< 256 { + return Info{}, corruptf("png tRNS length %d", length) + } + + if int(length) > paletteEntries { + return Info{}, corruptf( + "png tRNS length %d exceeds %d palette entries", + length, paletteEntries, + ) + } + default: + return Info{}, corruptf("png tRNS invalid for color type %d", colorType) + } + + trnsSeen = true + case "IEND": + if length != 0 { + return Info{}, corruptf("png IEND length %d", length) + } + + if !hasIDAT { + return Info{}, corruptf("png has no IDAT chunk") + } + + if colorType == 3 && !paletteReady { + return Info{}, corruptf("png palette image has no PLTE before IDAT") + } + + // The chunk walker proves structure, but a stream whose bytes + // merely look like a chunk layout (valid length/type/CRC) may + // still not be a PNG raster: the zlib payload must inflate to + // exactly the IHDR-declared scanlines with valid filter bytes. + if err := validateRaster(idat.Bytes(), raster); err != nil { + return Info{}, err + } + + if _, err := io.Copy(io.Discard, reader); err != nil { + return Info{}, corrupt("png trailing data", err) + } + + return info, nil + } + + lastChunk = chunkType + } +} + +// pngPass is one consecutive block of scanlines in the inflated image stream. +// Non-interlaced PNGs have a single pass; Adam7 has up to seven. +type pngPass struct { + rowBytes int64 + rows int64 +} + +type pngPassSpec struct { + x0, y0 int64 + dx, dy int64 +} + +var adam7Passes = []pngPassSpec{ + {x0: 0, y0: 0, dx: 8, dy: 8}, + {x0: 4, y0: 0, dx: 8, dy: 8}, + {x0: 0, y0: 4, dx: 4, dy: 8}, + {x0: 2, y0: 0, dx: 4, dy: 4}, + {x0: 0, y0: 2, dx: 2, dy: 4}, + {x0: 1, y0: 0, dx: 2, dy: 2}, + {x0: 0, y0: 1, dx: 1, dy: 2}, +} + +// pngRasterLayout returns the exact inflated size and row layout for the +// IHDR. The Adam7 layout matters: a single non-interlaced formula either +// rejects valid interlaced images or accepts oversized streams. +func pngRasterLayout( + info Info, + bitDepth, colorType, compression, filter, interlace byte, +) ([]pngPass, error) { + if compression != 0 || filter != 0 { + return nil, corruptf( + "png compression/filter method %d/%d", compression, filter, + ) + } + + var bitsPerPixel int64 + + switch colorType { + case 0: // grayscale + if bitDepth != 1 && bitDepth != 2 && bitDepth != 4 && bitDepth != 8 && bitDepth != 16 { + return nil, corruptf("png invalid bit depth %d for color type 0", bitDepth) + } + + bitsPerPixel = int64(bitDepth) + case 2: // truecolor + if bitDepth != 8 && bitDepth != 16 { + return nil, corruptf("png invalid bit depth %d for color type 2", bitDepth) + } + + bitsPerPixel = 3 * int64(bitDepth) + case 3: // palette + if bitDepth != 1 && bitDepth != 2 && bitDepth != 4 && bitDepth != 8 { + return nil, corruptf("png invalid bit depth %d for color type 3", bitDepth) + } + + bitsPerPixel = int64(bitDepth) + case 4: // grayscale + alpha + if bitDepth != 8 && bitDepth != 16 { + return nil, corruptf("png invalid bit depth %d for color type 4", bitDepth) + } + + bitsPerPixel = 2 * int64(bitDepth) + case 6: // RGBA + if bitDepth != 8 && bitDepth != 16 { + return nil, corruptf("png invalid bit depth %d for color type 6", bitDepth) + } + + bitsPerPixel = 4 * int64(bitDepth) + default: + return nil, corruptf("png invalid color type %d", colorType) + } + + specs := []pngPassSpec{{x0: 0, y0: 0, dx: 1, dy: 1}} + switch interlace { + case 0: + case 1: + specs = adam7Passes + default: + return nil, corruptf("png invalid interlace method %d", interlace) + } + + passes := make([]pngPass, 0, len(specs)) + + for _, spec := range specs { + if info.Width <= spec.x0 || info.Height <= spec.y0 { + continue + } + + width := (info.Width - spec.x0 + spec.dx - 1) / spec.dx + rows := (info.Height - spec.y0 + spec.dy - 1) / spec.dy + rowBytes := (width*bitsPerPixel + 7) / 8 + + // Keep the total overflow-safe. Valid PNGs are additionally bounded + // by the pixel limit checked by the caller. + if rowBytes+1 > (1<<62)/rows { + return nil, fmt.Errorf("%w: png dimensions overflow", ErrTooLarge) + } + + passes = append(passes, pngPass{rowBytes: rowBytes, rows: rows}) + } + + return passes, nil +} + +func pngRasterBytes(passes []pngPass) int64 { + var total int64 + + for _, pass := range passes { + row := (pass.rowBytes + 1) * pass.rows + if total > (1<<62)-row { + return 1<<62 - 1 + } + + total += row + } + + return total +} + +// validateRaster streams the inflated image data, checking every scanline +// filter byte and requiring exactly the IHDR-declared number of rows. It +// catches zlib streams that decompress cleanly but do not describe a valid +// raster (empty payloads, bogus filter bytes) and rejects extra data as a +// decompression bomb. +func validateRaster(compressed []byte, passes []pngPass) error { + source := bytes.NewReader(compressed) + + reader, err := zlib.NewReader(source) + if err != nil { + return corrupt("png idat zlib header", err) + } + + for _, pass := range passes { + for range pass.rows { + var filter [1]byte + if _, err := io.ReadFull(reader, filter[:]); err != nil { + return corrupt("png scanline filter", err) + } + + if filter[0] > 4 { + return corruptf("png invalid scanline filter %d", filter[0]) + } + + if _, err := io.CopyN(io.Discard, reader, pass.rowBytes); err != nil { + return corrupt("png scanline data", err) + } + } + } + + var extra [1]byte + switch _, err := io.ReadFull(reader, extra[:]); { + case errors.Is(err, io.EOF): + // A clean zlib EOF also verifies the Adler-32 trailer. bytes.Reader + // satisfies io.ByteReader, so the inflater consumes exactly the zlib + // stream; anything left is data after the stream, which PNG forbids. + if source.Len() != 0 { + return corruptf("png idat has %d trailing bytes", source.Len()) + } + + return nil + case err == nil: + return fmt.Errorf("%w: png raster exceeds declared dimensions", ErrTooLarge) + default: + return corrupt("png idat zlib trailer", err) + } +} + +func checkCriticalChunk(chunkType string, seen map[string]bool) error { + if chunkType == "IHDR" || chunkType == "PLTE" || chunkType == "IDAT" || chunkType == "IEND" { + seen[chunkType] = true + + return nil + } + + if chunkType[0] >= 'A' && chunkType[0] <= 'Z' { + return corruptf("png unknown critical chunk %q", chunkType) + } + + return nil +} + +func readChunkData(reader io.Reader, checksum io.Writer, length int64, sink io.Writer) ([]byte, error) { + if length <= 64<<10 { + data := make([]byte, length) + if _, err := io.ReadFull(reader, data); err != nil { + return nil, err + } + + _, _ = checksum.Write(data) + if sink != nil { + _, _ = sink.Write(data) + } + + return data, nil + } + + destination := checksum + if sink != nil { + destination = io.MultiWriter(checksum, sink) + } + + if _, err := io.CopyN(destination, reader, length); err != nil { + return nil, err + } + + return nil, nil +} + +func validateJPEG(reader *bufio.Reader, maxPixels int64) (Info, error) { + if _, err := reader.Discard(2); err != nil { + return Info{}, corrupt("jpeg SOI", err) + } + + var ( + info Info + hasSOF bool + hasSOS bool + pending byte + markerErr error + ) + + info.ContentType = "image/jpeg" + + for { + marker := pending + pending = 0 + + if marker == 0 { + marker, markerErr = nextMarker(reader) + if markerErr != nil { + return Info{}, corrupt("jpeg marker", markerErr) + } + } + + switch { + case marker == 0xD9: // EOI + if !hasSOF || !hasSOS { + return Info{}, corruptf("jpeg missing SOF or SOS") + } + + if _, err := io.Copy(io.Discard, reader); err != nil { + return Info{}, corrupt("jpeg trailing data", err) + } + + return info, nil + case isStandalone(marker): + continue + } + + length, err := readUint16(reader) + if err != nil { + return Info{}, corrupt("jpeg segment length", err) + } + + if length < 2 { + return Info{}, corruptf("jpeg segment %02x length %d", marker, length) + } + + data := make([]byte, int(length)-2) + if _, err := io.ReadFull(reader, data); err != nil { + return Info{}, corrupt("jpeg segment data", err) + } + + switch { + case isSOF(marker): + if len(data) < 5 { + return Info{}, corruptf("jpeg SOF %02x is too short", marker) + } + + info.Height = int64(binary.BigEndian.Uint16(data[1:3])) + info.Width = int64(binary.BigEndian.Uint16(data[3:5])) + + if info.Width <= 0 || info.Height <= 0 { + return Info{}, corruptf("jpeg dimensions %dx%d", info.Width, info.Height) + } + + hasSOF = true + + if maxPixels > 0 && info.Width*info.Height > maxPixels { + return Info{}, fmt.Errorf("%w: %dx%d", ErrTooLarge, info.Width, info.Height) + } + case marker == 0xDA: // SOS + hasSOS = true + + next, err := scanEntropy(reader) + if err != nil { + return Info{}, corrupt("jpeg scan", err) + } + + pending = next + } + } +} + +func nextMarker(reader *bufio.Reader) (byte, error) { + for { + value, err := reader.ReadByte() + if err != nil { + return 0, err + } + + if value != 0xFF { + return 0, fmt.Errorf("unexpected byte %02x before marker", value) + } + + value, err = reader.ReadByte() + if err != nil { + return 0, err + } + + if value == 0xFF { + continue + } + + return value, nil + } +} + +// scanEntropy consumes entropy-coded data after SOS and returns the next +// non-RST marker (0xFF prefix consumed). +func scanEntropy(reader *bufio.Reader) (byte, error) { + for { + value, err := reader.ReadByte() + if err != nil { + return 0, err + } + + if value != 0xFF { + continue + } + + value, err = reader.ReadByte() + if err != nil { + return 0, err + } + + switch { + case value == 0x00: + continue + case value >= 0xD0 && value <= 0xD7: + continue + default: + return value, nil + } + } +} + +func readUint16(reader io.Reader) (uint16, error) { + var raw [2]byte + if _, err := io.ReadFull(reader, raw[:]); err != nil { + return 0, err + } + + return binary.BigEndian.Uint16(raw[:]), nil +} + +func isSOF(marker byte) bool { + switch marker { + case 0xC0, 0xC1, 0xC2, 0xC3, 0xC5, 0xC6, 0xC7, 0xC9, 0xCA, 0xCB, 0xCD, 0xCE, 0xCF: + return true + default: + return false + } +} + +func isStandalone(marker byte) bool { + return marker == 0x01 || (marker >= 0xD0 && marker <= 0xD7) +} + +func corrupt(context string, err error) error { + return fmt.Errorf("%w: %s: %w", ErrCorrupt, context, err) +} + +func corruptf(format string, args ...any) error { + return fmt.Errorf("%w: %s", ErrCorrupt, fmt.Sprintf(format, args...)) +} diff --git a/internal/imagecheck/imagecheck_test.go b/internal/imagecheck/imagecheck_test.go new file mode 100644 index 0000000..7d60e04 --- /dev/null +++ b/internal/imagecheck/imagecheck_test.go @@ -0,0 +1,483 @@ +package imagecheck_test + +import ( + "bytes" + "compress/zlib" + "encoding/binary" + "hash/crc32" + "image" + "image/color" + "image/jpeg" + "image/png" + "testing" + + "github.com/stretchr/testify/require" + + "mtusi-messenger/internal/imagecheck" +) + +func encodePNG(t *testing.T, width, height int) []byte { + t.Helper() + + source := image.NewRGBA(image.Rect(0, 0, width, height)) + for x := range width { + for y := range height { + source.Set(x, y, color.RGBA{R: uint8(x), G: uint8(y), B: 128, A: 255}) + } + } + + var buffer bytes.Buffer + require.NoError(t, png.Encode(&buffer, source)) + + return buffer.Bytes() +} + +func encodeJPEG(t *testing.T, width, height int) []byte { + t.Helper() + + source := image.NewRGBA(image.Rect(0, 0, width, height)) + for x := range width { + for y := range height { + source.Set(x, y, color.RGBA{R: uint8(x), G: uint8(y), B: 64, A: 255}) + } + } + + var buffer bytes.Buffer + require.NoError(t, jpeg.Encode(&buffer, source, &jpeg.Options{Quality: 90})) + + return buffer.Bytes() +} + +func pngChunk(ctype string, payload []byte) []byte { + out := make([]byte, 12+len(payload)) + binary.BigEndian.PutUint32(out[0:4], uint32(len(payload))) + copy(out[4:8], ctype) + copy(out[8:], payload) + + checksum := crc32.NewIEEE() + _, _ = checksum.Write(out[4 : 8+len(payload)]) + binary.BigEndian.PutUint32(out[8+len(payload):], checksum.Sum32()) + + return out +} + +func pngFile(chunks ...[]byte) []byte { + data := []byte(pngSignatureForTest) + for _, chunk := range chunks { + data = append(data, chunk...) + } + + return data +} + +const pngSignatureForTest = "\x89PNG\r\n\x1a\n" + +func TestValidatePNG(t *testing.T) { + info, err := imagecheck.Validate(bytes.NewReader(encodePNG(t, 32, 20)), 40_000_000) + require.NoError(t, err) + require.Equal(t, "image/png", info.ContentType) + require.Equal(t, int64(32), info.Width) + require.Equal(t, int64(20), info.Height) +} + +func TestValidateJPEG(t *testing.T) { + info, err := imagecheck.Validate(bytes.NewReader(encodeJPEG(t, 24, 16)), 40_000_000) + require.NoError(t, err) + require.Equal(t, "image/jpeg", info.ContentType) + require.Equal(t, int64(24), info.Width) + require.Equal(t, int64(16), info.Height) +} + +func TestValidateRejectsUnsupported(t *testing.T) { + _, err := imagecheck.Validate(bytes.NewReader([]byte("not an image at all")), 40_000_000) + require.ErrorIs(t, err, imagecheck.ErrUnsupported) + + _, err = imagecheck.Validate(bytes.NewReader(nil), 40_000_000) + require.ErrorIs(t, err, imagecheck.ErrUnsupported) +} + +func TestValidateRejectsTruncatedPNG(t *testing.T) { + data := encodePNG(t, 64, 64) + _, err := imagecheck.Validate(bytes.NewReader(data[:len(data)/2]), 40_000_000) + require.ErrorIs(t, err, imagecheck.ErrCorrupt) +} + +func TestValidateRejectsPNGCRCMismatch(t *testing.T) { + data := encodePNG(t, 64, 64) + index := bytes.Index(data, []byte("IDAT")) + require.Positive(t, index) + data[index+8] ^= 0xFF // first IDAT payload byte; CRC no longer matches + + _, err := imagecheck.Validate(bytes.NewReader(data), 40_000_000) + require.ErrorIs(t, err, imagecheck.ErrCorrupt) +} + +// Builds a structurally valid PNG (signature, well-formed IHDR/IDAT/IEND, +// correct CRCs) whose IDAT payload is not a zlib stream at all. Merely a +// stream-like structure must not make the upload pass: it has to inflate. +func TestValidateRejectsPNGIDATNotAZlibStream(t *testing.T) { + ihdr := make([]byte, 13) + binary.BigEndian.PutUint32(ihdr[0:4], 64) // width + binary.BigEndian.PutUint32(ihdr[4:8], 32) // height + ihdr[8] = 8 // bit depth + ihdr[9] = 6 // color type RGBA + + data := pngFile( + pngChunk("IHDR", ihdr), + pngChunk("IDAT", []byte("this is not a zlib stream, but the CRC is right")), + pngChunk("IEND", nil), + ) + + _, err := imagecheck.Validate(bytes.NewReader(data), 40_000_000) + require.ErrorIs(t, err, imagecheck.ErrCorrupt) +} + +func craftedPNG(t *testing.T, width, height int, interlace byte, raster []byte) []byte { + t.Helper() + + return craftedPNGType(t, width, height, 6, interlace, raster) +} + +func craftedPNGType(t *testing.T, width, height int, colorType, interlace byte, raster []byte) []byte { + t.Helper() + + return craftedPNGDepth(t, width, height, 8, colorType, interlace, raster) +} + +func craftedPNGDepth(t *testing.T, width, height int, bitDepth, colorType, interlace byte, raster []byte) []byte { + t.Helper() + + return pngFile( + pngChunk("IHDR", pngIHDR(width, height, bitDepth, colorType, interlace)), + pngChunk("IDAT", zlibBytes(t, raster)), + pngChunk("IEND", nil), + ) +} + +func pngIHDR(width, height int, bitDepth, colorType, interlace byte) []byte { + ihdr := make([]byte, 13) + binary.BigEndian.PutUint32(ihdr[0:4], uint32(width)) + binary.BigEndian.PutUint32(ihdr[4:8], uint32(height)) + ihdr[8] = bitDepth + ihdr[9] = colorType + ihdr[12] = interlace + + return ihdr +} + +func zlibBytes(t *testing.T, raster []byte) []byte { + t.Helper() + + var compressed bytes.Buffer + + writer := zlib.NewWriter(&compressed) + _, err := writer.Write(raster) + require.NoError(t, err) + require.NoError(t, writer.Close()) + + return compressed.Bytes() +} + +func TestValidateRejectsPNGEmptyRaster(t *testing.T) { + data := craftedPNG(t, 2, 2, 0, nil) + + _, err := imagecheck.Validate(bytes.NewReader(data), 40_000_000) + require.ErrorIs(t, err, imagecheck.ErrCorrupt) +} + +func TestValidateRejectsPNGInvalidScanlineFilter(t *testing.T) { + raster := []byte{5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} + data := craftedPNG(t, 2, 2, 0, raster) + + _, err := imagecheck.Validate(bytes.NewReader(data), 40_000_000) + require.ErrorIs(t, err, imagecheck.ErrCorrupt) +} + +func TestValidateRejectsPNGPaletteWithoutPLTE(t *testing.T) { + raster := []byte{0, 0, 0, 0, 0, 0} // two rows of two 8-bit palette indexes + data := craftedPNGType(t, 2, 2, 3, 0, raster) + + _, err := imagecheck.Validate(bytes.NewReader(data), 40_000_000) + require.ErrorIs(t, err, imagecheck.ErrCorrupt) +} + +func TestValidateAcceptsPalettePNG(t *testing.T) { + palette := color.Palette{color.RGBA{R: 255, A: 255}, color.RGBA{G: 255, A: 255}, color.RGBA{B: 255, A: 255}} + source := image.NewPaletted(image.Rect(0, 0, 13, 5), palette) + for x := range 13 { + for y := range 5 { + source.SetColorIndex(x, y, uint8((x+y)%len(palette))) + } + } + + var buffer bytes.Buffer + require.NoError(t, png.Encode(&buffer, source)) + + info, err := imagecheck.Validate(bytes.NewReader(buffer.Bytes()), 40_000_000) + require.NoError(t, err) + require.Equal(t, int64(13), info.Width) + require.Equal(t, int64(5), info.Height) +} + +func TestValidateRejectsPNGInvalidColorDepthCombination(t *testing.T) { + data := craftedPNGDepth(t, 1, 1, 1, 6, 0, []byte{0, 0, 0}) + + _, err := imagecheck.Validate(bytes.NewReader(data), 40_000_000) + require.ErrorIs(t, err, imagecheck.ErrCorrupt) +} + +func TestValidateRejectsPNGDuplicateIHDR(t *testing.T) { + ihdr := pngChunk("IHDR", pngIHDR(1, 1, 8, 6, 0)) + data := pngFile( + ihdr, + ihdr, + pngChunk("IDAT", zlibBytes(t, []byte{0, 0, 0, 0, 0})), + pngChunk("IEND", nil), + ) + + _, err := imagecheck.Validate(bytes.NewReader(data), 40_000_000) + require.ErrorIs(t, err, imagecheck.ErrCorrupt) +} + +func TestValidateRejectsPNGDuplicatePLTE(t *testing.T) { + plte := pngChunk("PLTE", []byte{255, 0, 0}) + data := pngFile( + pngChunk("IHDR", pngIHDR(1, 1, 8, 3, 0)), + plte, + plte, + pngChunk("IDAT", zlibBytes(t, []byte{0, 0})), + pngChunk("IEND", nil), + ) + + _, err := imagecheck.Validate(bytes.NewReader(data), 40_000_000) + require.ErrorIs(t, err, imagecheck.ErrCorrupt) +} + +func TestValidateRejectsPNGNonConsecutiveIDAT(t *testing.T) { + compressed := zlibBytes(t, []byte{0, 0, 0, 0, 0}) + middle := len(compressed) / 2 + + data := pngFile( + pngChunk("IHDR", pngIHDR(1, 1, 8, 6, 0)), + pngChunk("IDAT", compressed[:middle]), + pngChunk("tEXt", []byte("k\x00v")), + pngChunk("IDAT", compressed[middle:]), + pngChunk("IEND", nil), + ) + + _, err := imagecheck.Validate(bytes.NewReader(data), 40_000_000) + require.ErrorIs(t, err, imagecheck.ErrCorrupt) +} + +func TestValidateRejectsPNGTrailingIDATData(t *testing.T) { + idat := append(zlibBytes(t, []byte{0, 0, 0, 0, 0}), []byte("junk")...) + data := pngFile( + pngChunk("IHDR", pngIHDR(1, 1, 8, 6, 0)), + pngChunk("IDAT", idat), + pngChunk("IEND", nil), + ) + + _, err := imagecheck.Validate(bytes.NewReader(data), 40_000_000) + require.ErrorIs(t, err, imagecheck.ErrCorrupt) +} + +func TestValidateAcceptsSplitIDAT(t *testing.T) { + compressed := zlibBytes(t, []byte{0, 0, 0, 0, 0}) + middle := len(compressed) / 2 + + data := pngFile( + pngChunk("IHDR", pngIHDR(1, 1, 8, 6, 0)), + pngChunk("IDAT", compressed[:middle]), + pngChunk("IDAT", compressed[middle:]), + pngChunk("IEND", nil), + ) + + info, err := imagecheck.Validate(bytes.NewReader(data), 40_000_000) + require.NoError(t, err) + require.Equal(t, int64(1), info.Width) +} + +func TestValidateAcceptsStandardEncodings(t *testing.T) { + bounds := image.Rect(0, 0, 7, 5) + images := []image.Image{ + image.NewGray(bounds), + image.NewGray16(bounds), + image.NewRGBA(bounds), + image.NewNRGBA(bounds), + image.NewNRGBA64(bounds), + } + + for _, source := range images { + var buffer bytes.Buffer + require.NoError(t, png.Encode(&buffer, source)) + + info, err := imagecheck.Validate(bytes.NewReader(buffer.Bytes()), 40_000_000) + require.NoError(t, err) + require.Equal(t, int64(7), info.Width) + require.Equal(t, int64(5), info.Height) + } +} + +func TestValidateRejectsPNGPLTEEntriesExceedBitDepth(t *testing.T) { + data := pngFile( + pngChunk("IHDR", pngIHDR(1, 1, 1, 3, 0)), + pngChunk("PLTE", []byte{255, 0, 0, 0, 255, 0, 0, 0, 255}), + pngChunk("IDAT", zlibBytes(t, []byte{0, 0})), + pngChunk("IEND", nil), + ) + + _, err := imagecheck.Validate(bytes.NewReader(data), 40_000_000) + require.ErrorIs(t, err, imagecheck.ErrCorrupt) +} + +func TestValidateRejectsInvalidTRNS(t *testing.T) { + rgb := pngChunk("IDAT", zlibBytes(t, []byte{0, 10, 20, 30})) + gray := pngChunk("IDAT", zlibBytes(t, []byte{0, 10})) + rgba := pngChunk("IDAT", zlibBytes(t, []byte{0, 10, 20, 30, 255})) + paletted := pngChunk("IDAT", zlibBytes(t, []byte{0, 0})) + + cases := map[string][]byte{ + "tRNS on RGBA": pngFile( + pngChunk("IHDR", pngIHDR(1, 1, 8, 6, 0)), + pngChunk("tRNS", []byte{0}), + rgba, + pngChunk("IEND", nil), + ), + "RGB length": pngFile( + pngChunk("IHDR", pngIHDR(1, 1, 8, 2, 0)), + pngChunk("tRNS", []byte{0}), + rgb, + pngChunk("IEND", nil), + ), + "gray length": pngFile( + pngChunk("IHDR", pngIHDR(1, 1, 8, 0, 0)), + pngChunk("tRNS", []byte{0}), + gray, + pngChunk("IEND", nil), + ), + "palette before PLTE": pngFile( + pngChunk("IHDR", pngIHDR(1, 1, 8, 3, 0)), + pngChunk("tRNS", []byte{0}), + pngChunk("PLTE", []byte{255, 0, 0, 0, 255, 0}), + paletted, + pngChunk("IEND", nil), + ), + "palette tRNS longer than PLTE": pngFile( + pngChunk("IHDR", pngIHDR(1, 1, 8, 3, 0)), + pngChunk("PLTE", []byte{255, 0, 0}), + pngChunk("tRNS", []byte{0, 0}), + paletted, + pngChunk("IEND", nil), + ), + "duplicate tRNS": pngFile( + pngChunk("IHDR", pngIHDR(1, 1, 8, 2, 0)), + pngChunk("tRNS", make([]byte, 6)), + pngChunk("tRNS", make([]byte, 6)), + rgb, + pngChunk("IEND", nil), + ), + "tRNS after IDAT": pngFile( + pngChunk("IHDR", pngIHDR(1, 1, 8, 2, 0)), + rgb, + pngChunk("tRNS", make([]byte, 6)), + pngChunk("IEND", nil), + ), + } + + for name, data := range cases { + _, err := imagecheck.Validate(bytes.NewReader(data), 40_000_000) + require.ErrorIs(t, err, imagecheck.ErrCorrupt, name) + } +} + +func TestValidateAcceptsValidTRNS(t *testing.T) { + cases := map[string][]byte{ + "RGB": pngFile( + pngChunk("IHDR", pngIHDR(1, 1, 8, 2, 0)), + pngChunk("tRNS", make([]byte, 6)), + pngChunk("IDAT", zlibBytes(t, []byte{0, 10, 20, 30})), + pngChunk("IEND", nil), + ), + "gray": pngFile( + pngChunk("IHDR", pngIHDR(1, 1, 8, 0, 0)), + pngChunk("tRNS", make([]byte, 2)), + pngChunk("IDAT", zlibBytes(t, []byte{0, 10})), + pngChunk("IEND", nil), + ), + "palette": pngFile( + pngChunk("IHDR", pngIHDR(1, 1, 1, 3, 0)), + pngChunk("PLTE", []byte{255, 0, 0, 0, 255, 0}), + pngChunk("tRNS", []byte{128}), + pngChunk("IDAT", zlibBytes(t, []byte{0, 0})), + pngChunk("IEND", nil), + ), + } + + for name, data := range cases { + _, err := imagecheck.Validate(bytes.NewReader(data), 40_000_000) + require.NoError(t, err, name) + } +} + +// A valid Adam7 stream for a tall, narrow image exceeds the old +// (rowBytes+1)*(height+8) guess; the exact pass layout must accept it. +func TestValidateAcceptsAdam7PNG(t *testing.T) { + const width, height = 2, 256 + + var raster bytes.Buffer + + 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 _, pass := range passes { + x0, y0, dx, dy := pass[0], pass[1], pass[2], pass[3] + if width <= x0 || height <= y0 { + continue + } + + for y := y0; y < height; y += dy { + raster.WriteByte(0) // filter: none + + for x := x0; x < width; x += dx { + raster.Write([]byte{byte(x), byte(y), 128, 255}) + } + } + } + + data := craftedPNG(t, width, height, 1, raster.Bytes()) + + info, err := imagecheck.Validate(bytes.NewReader(data), 40_000_000) + require.NoError(t, err) + require.Equal(t, int64(width), info.Width) + require.Equal(t, int64(height), info.Height) +} + +func TestValidateRejectsTruncatedJPEG(t *testing.T) { + data := encodeJPEG(t, 64, 64) + _, err := imagecheck.Validate(bytes.NewReader(data[:len(data)-32]), 40_000_000) + require.ErrorIs(t, err, imagecheck.ErrCorrupt) +} + +func TestValidateRejectsTooManyPixels(t *testing.T) { + _, err := imagecheck.Validate(bytes.NewReader(encodePNG(t, 100, 100)), 9_999) + require.ErrorIs(t, err, imagecheck.ErrTooLarge) + + _, err = imagecheck.Validate(bytes.NewReader(encodeJPEG(t, 100, 100)), 9_999) + require.ErrorIs(t, err, imagecheck.ErrTooLarge) +} + +func TestValidateAllowsTrailingBytes(t *testing.T) { + pngData := append(encodePNG(t, 8, 8), []byte("trailing")...) + _, err := imagecheck.Validate(bytes.NewReader(pngData), 40_000_000) + require.NoError(t, err) + + jpegData := append(encodeJPEG(t, 8, 8), []byte("trailing")...) + _, err = imagecheck.Validate(bytes.NewReader(jpegData), 40_000_000) + require.NoError(t, err) +} diff --git a/internal/imageproc/exif.go b/internal/imageproc/exif.go new file mode 100644 index 0000000..943c0ed --- /dev/null +++ b/internal/imageproc/exif.go @@ -0,0 +1,118 @@ +package imageproc + +import ( + "encoding/binary" + "io" +) + +const ( + exifMaxBytes = 64 << 10 + exifTagOrient = 0x0112 +) + +// readEXIFOrientation extracts only IFD0 Orientation from a JPEG APP1 segment. +// The parser is deliberately small and bounded: no TIFF offsets are trusted and +// the whole segment is capped at 64 KiB, so attacker-controlled EXIF cannot make +// the worker allocate unbounded memory. +func readEXIFOrientation(r io.Reader) int { + data, err := io.ReadAll(io.LimitReader(r, exifMaxBytes)) + if err != nil || len(data) < 4 || data[0] != 0xff || data[1] != 0xd8 { + return 1 + } + + pos := 2 + + for pos+4 <= len(data) { + if data[pos] != 0xff { + return 1 + } + + marker := data[pos+1] + pos += 2 + + // Standalone markers without a length field. + if marker == 0xd8 || marker == 0xd9 || marker == 0x01 || (marker >= 0xd0 && marker <= 0xd7) { + continue + } + + if pos+2 > len(data) { + return 1 + } + + length := int(binary.BigEndian.Uint16(data[pos : pos+2])) + if length < 2 || pos+length > len(data) { + return 1 + } + + segment := data[pos+2 : pos+length] + pos += length + + if marker != 0xe1 || len(segment) < 6 { + continue + } + + if string(segment[:6]) != "Exif\x00\x00" { + continue + } + + return parseTIFFOrientation(segment[6:]) + } + + return 1 +} + +func parseTIFFOrientation(tiff []byte) int { + if len(tiff) < 8 { + return 1 + } + + var order binary.ByteOrder + + switch string(tiff[:2]) { + case "II": + order = binary.LittleEndian + case "MM": + order = binary.BigEndian + default: + return 1 + } + + if order.Uint16(tiff[2:4]) != 42 { + return 1 + } + + ifdOffset := int(order.Uint32(tiff[4:8])) + if ifdOffset < 8 || ifdOffset+2 > len(tiff) { + return 1 + } + + count := int(order.Uint16(tiff[ifdOffset : ifdOffset+2])) + if count > 512 { + count = 512 + } + + entry := ifdOffset + 2 + + for range count { + if entry+12 > len(tiff) { + return 1 + } + + tag := order.Uint16(tiff[entry : entry+2]) + typ := order.Uint16(tiff[entry+2 : entry+4]) + n := order.Uint32(tiff[entry+4 : entry+8]) + + if tag == exifTagOrient && typ == 3 && n == 1 { + value := order.Uint16(tiff[entry+8 : entry+10]) + if value >= 1 && value <= 8 { + return int(value) + } + + return 1 + } + + entry += 12 + } + + return 1 +} diff --git a/internal/imageproc/imageproc.go b/internal/imageproc/imageproc.go new file mode 100644 index 0000000..545b16e --- /dev/null +++ b/internal/imageproc/imageproc.go @@ -0,0 +1,259 @@ +// Package imageproc turns one decoded original into the contract variants. +// Output bytes are deterministic for a given pipeline version, source bytes and +// encoder versions; the worker uses that property for idempotent retries. +package imageproc + +import ( + "bytes" + "crypto/sha256" + "encoding/hex" + "fmt" + "image" + "image/color" + "image/jpeg" + _ "image/png" // register the PNG decoder + "io" + "math" + "os" + + "github.com/gen2brain/webp" + xdraw "golang.org/x/image/draw" + + "mtusi-messenger/internal/domain" +) + +const ( + thumbnailMax = 256 + cropSize = 128 + optimizedMax = 1280 + defaultMethod = 2 +) + +// Params are immutable per pipeline version. They are compiled into the binary +// so a retry can never silently produce different bytes than the first attempt. +type Params struct { + JPEGQuality int + WebPQuality int + WebPMethod int +} + +// Pipeline returns the versioned encoder parameters. Only v1 and v2 are +// defined; the course baseline is v1. +func Pipeline(version int) (Params, bool) { + switch version { + case 1: + return Params{JPEGQuality: 85, WebPQuality: 80, WebPMethod: defaultMethod}, true + case 2: + return Params{JPEGQuality: 70, WebPQuality: 65, WebPMethod: 4}, true + default: + return Params{}, false + } +} + +// Image is one encoded variant. +type Image struct { + Name domain.VariantName + ContentType string + Data []byte + SizeBytes int64 + Width int + Height int + SHA256 string +} + +// Load decodes a PNG/JPEG file, applies EXIF orientation and composites alpha +// on white. The returned image is always *image.RGBA, which bounds the variant +// encoders to 8-bit output. +func Load(path string, maxPixels int64) (image.Image, string, error) { + file, err := os.Open(path) + if err != nil { + return nil, "", fmt.Errorf("open source: %w", err) + } + defer file.Close() + + cfg, format, err := image.DecodeConfig(file) + if err != nil { + return nil, "", fmt.Errorf("decode config: %w", err) + } + + if cfg.Width <= 0 || cfg.Height <= 0 { + return nil, "", fmt.Errorf("invalid dimensions %dx%d", cfg.Width, cfg.Height) + } + + if maxPixels > 0 && int64(cfg.Width)*int64(cfg.Height) > maxPixels { + return nil, "", fmt.Errorf("image has %d pixels, limit %d", int64(cfg.Width)*int64(cfg.Height), maxPixels) + } + + if _, err := file.Seek(0, io.SeekStart); err != nil { + return nil, "", fmt.Errorf("rewind source: %w", err) + } + + decoded, _, err := image.Decode(file) + if err != nil { + return nil, "", fmt.Errorf("decode image: %w", err) + } + + orientation := 1 + if format == "jpeg" { + if _, err := file.Seek(0, io.SeekStart); err == nil { + orientation = readEXIFOrientation(file) + } + } + + return toWhiteRGBA(decoded, orientation), format, nil +} + +func toWhiteRGBA(src image.Image, orientation int) image.Image { + transformed := orient(src, orientation) + bounds := transformed.Bounds() + + dst := image.NewRGBA(image.Rect(0, 0, bounds.Dx(), bounds.Dy())) + xdraw.Draw(dst, dst.Bounds(), image.NewUniform(color.White), image.Point{}, xdraw.Src) + xdraw.Draw(dst, dst.Bounds(), transformed, bounds.Min, xdraw.Over) + + return dst +} + +// orient applies the eight EXIF orientation values. The result has the same +// bounds as the source except for 90-degree rotations. +func orient(src image.Image, orientation int) image.Image { + if orientation < 2 || orientation > 8 { + return src + } + + b := src.Bounds() + w, h := b.Dx(), b.Dy() + + width, height := w, h + if orientation >= 5 { + width, height = h, w + } + + dst := image.NewRGBA(image.Rect(0, 0, width, height)) + + for y := range h { + for x := range w { + nx, ny := orientPoint(orientation, x, y, w, h) + + dst.Set(nx, ny, src.At(b.Min.X+x, b.Min.Y+y)) + } + } + + return dst +} + +func orientPoint(orientation, x, y, w, h int) (int, int) { + switch orientation { + case 2: + return w - 1 - x, y + case 3: + return w - 1 - x, h - 1 - y + case 4: + return x, h - 1 - y + case 5: + return y, x + case 6: + return h - 1 - y, x + case 7: + return h - 1 - y, w - 1 - x + case 8: + return y, w - 1 - x + default: + return x, y + } +} + +// Thumbnail fits inside 256x256 without upscaling; dimensions are floored and +// never below 1 px. +func Thumbnail(src image.Image, params Params) (Image, error) { + return encodeJPEG(fit(src, thumbnailMax, thumbnailMax, false), domain.VariantThumbnail, params) +} + +// Crop takes the centered square and scales it to 128x128. Upscaling small +// sources is allowed by the contract. +func Crop(src image.Image, params Params) (Image, error) { + b := src.Bounds() + side := b.Dx() + if b.Dy() < side { + side = b.Dy() + } + + left := b.Min.X + (b.Dx()-side)/2 + top := b.Min.Y + (b.Dy()-side)/2 + + square := image.NewRGBA(image.Rect(0, 0, side, side)) + xdraw.Draw(square, square.Bounds(), src, image.Pt(left, top), xdraw.Src) + + dst := image.NewRGBA(image.Rect(0, 0, cropSize, cropSize)) + xdraw.CatmullRom.Scale(dst, dst.Bounds(), square, square.Bounds(), xdraw.Over, nil) + + return encodeJPEG(dst, domain.VariantCrop, params) +} + +// Optimized fits inside 1280x1280 without upscaling and encodes WebP. Metadata +// is stripped because the output is a fresh re-encode. +func Optimized(src image.Image, params Params) (Image, error) { + dst := fit(src, optimizedMax, optimizedMax, false) + + var buf bytes.Buffer + + if err := webp.Encode(&buf, dst, webp.Options{ + Quality: params.WebPQuality, + Method: params.WebPMethod, + }); err != nil { + return Image{}, fmt.Errorf("encode webp: %w", err) + } + + return newImage(domain.VariantOptimized, "image/webp", buf.Bytes(), dst.Bounds().Dx(), dst.Bounds().Dy()), nil +} + +func encodeJPEG(dst image.Image, name domain.VariantName, params Params) (Image, error) { + var buf bytes.Buffer + + if err := jpeg.Encode(&buf, dst, &jpeg.Options{Quality: params.JPEGQuality}); err != nil { + return Image{}, fmt.Errorf("encode jpeg: %w", err) + } + + return newImage(name, "image/jpeg", buf.Bytes(), dst.Bounds().Dx(), dst.Bounds().Dy()), nil +} + +func newImage(name domain.VariantName, contentType string, data []byte, width, height int) Image { + sum := sha256.Sum256(data) + + return Image{ + Name: name, + ContentType: contentType, + Data: data, + SizeBytes: int64(len(data)), + Width: width, + Height: height, + SHA256: hex.EncodeToString(sum[:]), + } +} + +// fit scales src into maxWidth x maxHeight preserving aspect ratio, floors the +// dimensions, enforces at least 1 px and, unless allowUpscale is set, never +// enlarges the source. +func fit(src image.Image, maxWidth, maxHeight int, allowUpscale bool) *image.RGBA { + b := src.Bounds() + w, h := b.Dx(), b.Dy() + + scale := math.Min(float64(maxWidth)/float64(w), float64(maxHeight)/float64(h)) + if !allowUpscale && scale > 1 { + scale = 1 + } + + width := int(math.Floor(float64(w) * scale)) + height := int(math.Floor(float64(h) * scale)) + if width < 1 { + width = 1 + } + if height < 1 { + height = 1 + } + + dst := image.NewRGBA(image.Rect(0, 0, width, height)) + xdraw.CatmullRom.Scale(dst, dst.Bounds(), src, b, xdraw.Over, nil) + + return dst +} diff --git a/internal/imageproc/imageproc_test.go b/internal/imageproc/imageproc_test.go new file mode 100644 index 0000000..24b1002 --- /dev/null +++ b/internal/imageproc/imageproc_test.go @@ -0,0 +1,222 @@ +package imageproc_test + +import ( + "bytes" + "encoding/binary" + "image" + "image/color" + "image/jpeg" + "image/png" + "os" + "path/filepath" + "testing" + + "github.com/gen2brain/webp" + "github.com/stretchr/testify/require" + + "mtusi-messenger/internal/domain" + "mtusi-messenger/internal/imageproc" +) + +func writePNG(t *testing.T, width, height int, alpha bool) string { + t.Helper() + + img := image.NewNRGBA(image.Rect(0, 0, width, height)) + for x := range width { + for y := range height { + a := uint8(255) + if alpha && x < width/2 && y < height/2 { + a = 0 + } + img.Set(x, y, color.NRGBA{R: 200, G: 40, B: 20, A: a}) + } + } + + var buf bytes.Buffer + require.NoError(t, png.Encode(&buf, img)) + + path := filepath.Join(t.TempDir(), "source.png") + require.NoError(t, os.WriteFile(path, buf.Bytes(), 0o600)) + + return path +} + +func writeJPEG(t *testing.T, width, height, orientation int) string { + t.Helper() + + img := image.NewRGBA(image.Rect(0, 0, width, height)) + for x := range width { + for y := range height { + img.Set(x, y, color.RGBA{R: 200, G: 40, B: 20, A: 255}) + } + } + + var raw bytes.Buffer + require.NoError(t, jpeg.Encode(&raw, img, &jpeg.Options{Quality: 95})) + + data := append([]byte(nil), raw.Bytes()...) + if orientation > 1 { + data = insertEXIFOrientation(t, data, uint16(orientation)) + } + + path := filepath.Join(t.TempDir(), "source.jpg") + require.NoError(t, os.WriteFile(path, data, 0o600)) + + return path +} + +func insertEXIFOrientation(t *testing.T, jpegBytes []byte, orientation uint16) []byte { + t.Helper() + + // TIFF: II, 42, IFD0 at offset 8, one entry (0x0112 SHORT 1 = orientation). + tiff := make([]byte, 8+2+12+4) + binary.LittleEndian.PutUint16(tiff[0:2], 0x4949) + binary.LittleEndian.PutUint16(tiff[2:4], 42) + binary.LittleEndian.PutUint32(tiff[4:8], 8) + binary.LittleEndian.PutUint16(tiff[8:10], 1) + binary.LittleEndian.PutUint16(tiff[10:12], 0x0112) + binary.LittleEndian.PutUint16(tiff[12:14], 3) + binary.LittleEndian.PutUint32(tiff[14:18], 1) + binary.LittleEndian.PutUint16(tiff[18:20], orientation) + + payload := append([]byte("Exif\x00\x00"), tiff...) + segment := make([]byte, 4+len(payload)) + segment[0] = 0xff + segment[1] = 0xe1 + binary.BigEndian.PutUint16(segment[2:4], uint16(len(payload)+2)) + copy(segment[4:], payload) + + // Insert immediately after SOI (before the first DQT/SOF). + out := append([]byte(nil), jpegBytes[:2]...) + out = append(out, segment...) + out = append(out, jpegBytes[2:]...) + + return out +} + +func decodeConfig(t *testing.T, data []byte) image.Config { + t.Helper() + + cfg, _, err := image.DecodeConfig(bytes.NewReader(data)) + require.NoError(t, err) + + return cfg +} + +func TestThumbnailContract(t *testing.T) { + params, ok := imageproc.Pipeline(1) + require.True(t, ok) + + cases := []struct { + name string + width int + height int + expected [2]int + }{ + {"320x200", 320, 200, [2]int{256, 160}}, + {"no upscale 64x64", 64, 64, [2]int{64, 64}}, + {"no upscale 64x40", 64, 40, [2]int{64, 40}}, + {"floor 1000x10", 1000, 10, [2]int{256, 2}}, + {"height limited", 100, 320, [2]int{80, 256}}, + {"minimum 1x1", 1, 1, [2]int{1, 1}}, + } + + for _, test := range cases { + t.Run(test.name, func(t *testing.T) { + img, _, err := imageproc.Load(writePNG(t, test.width, test.height, false), 40_000_000) + require.NoError(t, err) + + thumb, err := imageproc.Thumbnail(img, params) + require.NoError(t, err) + + cfg := decodeConfig(t, thumb.Data) + require.Equal(t, test.expected[0], cfg.Width) + require.Equal(t, test.expected[1], cfg.Height) + require.Equal(t, test.expected[0], thumb.Width) + require.Equal(t, test.expected[1], thumb.Height) + require.Equal(t, "image/jpeg", thumb.ContentType) + require.NotContains(t, string(thumb.Data), "Exif") + }) + } +} + +func TestCropAndOptimized(t *testing.T) { + params, ok := imageproc.Pipeline(1) + require.True(t, ok) + + img, _, err := imageproc.Load(writePNG(t, 320, 200, false), 40_000_000) + require.NoError(t, err) + + crop, err := imageproc.Crop(img, params) + require.NoError(t, err) + cfg := decodeConfig(t, crop.Data) + require.Equal(t, 128, cfg.Width) + require.Equal(t, 128, cfg.Height) + + optimized, err := imageproc.Optimized(img, params) + require.NoError(t, err) + cfg = decodeConfig(t, optimized.Data) + require.Equal(t, 320, cfg.Width) + require.Equal(t, 200, cfg.Height) + require.Equal(t, "image/webp", optimized.ContentType) + + decoded, err := webp.Decode(bytes.NewReader(optimized.Data)) + require.NoError(t, err) + require.Equal(t, 320, decoded.Bounds().Dx()) + require.Equal(t, 200, decoded.Bounds().Dy()) +} + +func TestEXIFOrientationChangesThumbnailDimensions(t *testing.T) { + params, ok := imageproc.Pipeline(1) + require.True(t, ok) + + for _, orientation := range []int{6, 8} { + img, _, err := imageproc.Load(writeJPEG(t, 320, 200, orientation), 40_000_000) + require.NoError(t, err) + + thumb, err := imageproc.Thumbnail(img, params) + require.NoError(t, err) + + cfg := decodeConfig(t, thumb.Data) + require.Equal(t, 160, cfg.Width, "orientation %d", orientation) + require.Equal(t, 256, cfg.Height, "orientation %d", orientation) + } +} + +func TestAlphaCompositedOnWhite(t *testing.T) { + params, ok := imageproc.Pipeline(1) + require.True(t, ok) + + img, _, err := imageproc.Load(writePNG(t, 100, 100, true), 40_000_000) + require.NoError(t, err) + + thumb, err := imageproc.Thumbnail(img, params) + require.NoError(t, err) + + decoded, err := jpeg.Decode(bytes.NewReader(thumb.Data)) + require.NoError(t, err) + + r, g, b, _ := decoded.At(0, 0).RGBA() + require.Greater(t, r, uint32(0xf000), "transparent corner must be white") + require.Greater(t, g, uint32(0xf000), "transparent corner must be white") + require.Greater(t, b, uint32(0xf000), "transparent corner must be white") +} + +func TestPipelineVersionsDiffer(t *testing.T) { + v1, ok := imageproc.Pipeline(1) + require.True(t, ok) + v2, ok := imageproc.Pipeline(2) + require.True(t, ok) + require.NotEqual(t, v1, v2) + + _, ok = imageproc.Pipeline(3) + require.False(t, ok) +} + +func TestVariantNames(t *testing.T) { + require.Equal(t, "image/jpeg", domain.VariantThumbnail.ContentType()) + require.Equal(t, "image/jpeg", domain.VariantCrop.ContentType()) + require.Equal(t, "image/webp", domain.VariantOptimized.ContentType()) + require.Equal(t, "thumbnail.jpg", domain.VariantThumbnail.ObjectName()) + require.Equal(t, "optimized.webp", domain.VariantOptimized.ObjectName()) +} diff --git a/internal/logger/errors.go b/internal/logger/errors.go new file mode 100644 index 0000000..799c84d --- /dev/null +++ b/internal/logger/errors.go @@ -0,0 +1,8 @@ +package logger + +import "errors" + +var ( + ErrUnknownLevel = errors.New("unknown log level") + ErrUnknownFormat = errors.New("unknown log format") +) diff --git a/internal/logger/logger.go b/internal/logger/logger.go new file mode 100644 index 0000000..96aa8ce --- /dev/null +++ b/internal/logger/logger.go @@ -0,0 +1,138 @@ +package logger + +import ( + "fmt" + "io" + "log/slog" + "os" + "strings" + + "go.uber.org/zap/exp/zapslog" + "go.uber.org/zap/zapcore" +) + +type Format string + +const ( + FormatJSON Format = "json" + FormatConsole Format = "console" +) + +const ( + DefaultLevel = slog.LevelInfo + DefaultFormat = FormatJSON +) + +type options struct { + writer io.Writer + level slog.Level + format Format + name string +} + +type Option func(*options) + +func WithWriter(writer io.Writer) Option { + return func(opts *options) { + if writer != nil { + opts.writer = writer + } + } +} + +func WithLevel(level slog.Level) Option { + return func(opts *options) { + opts.level = level + } +} + +func WithFormat(format Format) Option { + return func(opts *options) { + if format != "" { + opts.format = format + } + } +} + +func WithName(name string) Option { + return func(opts *options) { + opts.name = name + } +} + +func New(options ...Option) *slog.Logger { + opts := optionsConfig() + for _, option := range options { + option(&opts) + } + + encoderCfg := zapcore.EncoderConfig{ + TimeKey: "time", + LevelKey: "level", + NameKey: "logger", + CallerKey: "caller", + MessageKey: "msg", + StacktraceKey: "stacktrace", + LineEnding: zapcore.DefaultLineEnding, + EncodeLevel: zapcore.LowercaseLevelEncoder, + EncodeTime: zapcore.RFC3339NanoTimeEncoder, + EncodeDuration: zapcore.StringDurationEncoder, + EncodeCaller: zapcore.ShortCallerEncoder, + } + + var encoder zapcore.Encoder + if opts.format == FormatConsole { + encoder = zapcore.NewConsoleEncoder(encoderCfg) + } else { + encoder = zapcore.NewJSONEncoder(encoderCfg) + } + + core := zapcore.NewCore(encoder, zapcore.AddSync(opts.writer), zapLevel(opts.level)) + handlerOptions := make([]zapslog.HandlerOption, 0, 1) + if opts.name != "" { + handlerOptions = append(handlerOptions, zapslog.WithName(opts.name)) + } + + return slog.New(zapslog.NewHandler(core, handlerOptions...)) +} + +func optionsConfig() options { + return options{ + writer: os.Stdout, + level: DefaultLevel, + format: DefaultFormat, + } +} + +func ParseLevel(raw string) (slog.Level, error) { + var level slog.Level + if err := level.UnmarshalText([]byte(strings.TrimSpace(raw))); err != nil { + return 0, fmt.Errorf("%q: %w", raw, ErrUnknownLevel) + } + + return level, nil +} + +func ParseFormat(raw string) (Format, error) { + switch Format(strings.ToLower(strings.TrimSpace(raw))) { + case FormatJSON: + return FormatJSON, nil + case FormatConsole: + return FormatConsole, nil + default: + return "", fmt.Errorf("%q: %w", raw, ErrUnknownFormat) + } +} + +func zapLevel(level slog.Level) zapcore.Level { + switch { + case level < slog.LevelInfo: + return zapcore.DebugLevel + case level < slog.LevelWarn: + return zapcore.InfoLevel + case level < slog.LevelError: + return zapcore.WarnLevel + default: + return zapcore.ErrorLevel + } +} diff --git a/internal/logger/logger_test.go b/internal/logger/logger_test.go new file mode 100644 index 0000000..0b30827 --- /dev/null +++ b/internal/logger/logger_test.go @@ -0,0 +1,193 @@ +package logger_test + +import ( + "bytes" + "encoding/json" + "log/slog" + "strings" + "testing" + + "github.com/stretchr/testify/require" + "github.com/stretchr/testify/suite" + + "mtusi-messenger/internal/logger" +) + +type LoggerSuite struct { + suite.Suite + + bb *bytes.Buffer +} + +func TestLoggerSuite(t *testing.T) { + t.Parallel() + suite.Run(t, new(LoggerSuite)) +} + +func (s *LoggerSuite) SetupTest() { + s.bb = &bytes.Buffer{} +} + +func (s *LoggerSuite) records() []map[string]any { + var out []map[string]any + + for line := range strings.SplitSeq(strings.TrimSpace(s.bb.String()), "\n") { + if line == "" { + continue + } + + var record map[string]any + s.Require().NoError(json.Unmarshal([]byte(line), &record)) + + out = append(out, record) + } + + return out +} + +func (s *LoggerSuite) TestJSONOutputCarriesAttributes() { + log := logger.New(logger.WithWriter(s.bb)) + + log.Info("сервер запущен", slog.String("addr", "0.0.0.0:8080")) + + records := s.records() + s.Require().Len(records, 1) + + s.Equal("info", records[0]["level"]) + s.Equal("сервер запущен", records[0]["msg"]) + s.Equal("0.0.0.0:8080", records[0]["addr"]) + s.Contains(records[0], "time") +} + +func (s *LoggerSuite) TestDefaultLevelDropsDebug() { + log := logger.New(logger.WithWriter(s.bb)) + + log.Debug("не должно попасть в вывод") + log.Info("должно попасть") + + records := s.records() + s.Require().Len(records, 1) + s.Equal("должно попасть", records[0]["msg"]) +} + +func (s *LoggerSuite) TestWithLevelEnablesDebug() { + log := logger.New(logger.WithWriter(s.bb), logger.WithLevel(slog.LevelDebug)) + + log.Debug("подробность") + + records := s.records() + s.Require().Len(records, 1) + s.Equal("debug", records[0]["level"]) +} + +func (s *LoggerSuite) TestGroupsAreNested() { + log := logger.New(logger.WithWriter(s.bb)) + + log.Info("запрос", slog.Group("payload", slog.Int("size", 12))) + + records := s.records() + s.Require().Len(records, 1) + + payload, ok := records[0]["payload"].(map[string]any) + s.Require().True(ok, "группа должна кодироваться вложенным объектом") + s.InDelta(12, payload["size"], 0) +} + +func (s *LoggerSuite) TestWithNameSetsLoggerField() { + log := logger.New(logger.WithWriter(s.bb), logger.WithName("messenger")) + + log.Info("старт") + + records := s.records() + s.Require().Len(records, 1) + s.Equal("messenger", records[0]["logger"]) +} + +func (s *LoggerSuite) TestConsoleFormatIsNotJSON() { + log := logger.New(s.consoleOptions()...) + + log.Info("человекочитаемо") + + line := strings.TrimSpace(s.bb.String()) + s.Require().NotEmpty(line) + + var record map[string]any + s.Require().Error(json.Unmarshal([]byte(line), &record), "console-формат не должен быть JSON") + s.Contains(line, "человекочитаемо") +} + +func (s *LoggerSuite) consoleOptions() []logger.Option { + return []logger.Option{ + logger.WithWriter(s.bb), + logger.WithFormat(logger.FormatConsole), + } +} + +func (s *LoggerSuite) TestNilWriterKeepsDefault() { + s.Require().NotPanics(func() { + logger.New(logger.WithWriter(nil)).Info("пишем в stdout по умолчанию") + }) +} + +func TestParseLevel(t *testing.T) { + t.Parallel() + + tests := map[string]struct { + want slog.Level + wantErr bool + }{ + "debug": {want: slog.LevelDebug}, + "info": {want: slog.LevelInfo}, + "WARN": {want: slog.LevelWarn}, + "error": {want: slog.LevelError}, + "trace": {wantErr: true}, + "": {wantErr: true}, + } + + for raw, tt := range tests { + t.Run(raw, func(t *testing.T) { + t.Parallel() + + got, err := logger.ParseLevel(raw) + if tt.wantErr { + require.ErrorIs(t, err, logger.ErrUnknownLevel) + + return + } + + require.NoError(t, err) + require.Equal(t, tt.want, got) + }) + } +} + +func TestParseFormat(t *testing.T) { + t.Parallel() + + tests := map[string]struct { + want logger.Format + wantErr bool + }{ + "json": {want: logger.FormatJSON}, + "JSON": {want: logger.FormatJSON}, + "console": {want: logger.FormatConsole}, + "xml": {wantErr: true}, + "": {wantErr: true}, + } + + for raw, tt := range tests { + t.Run(raw, func(t *testing.T) { + t.Parallel() + + got, err := logger.ParseFormat(raw) + if tt.wantErr { + require.ErrorIs(t, err, logger.ErrUnknownFormat) + + return + } + + require.NoError(t, err) + require.Equal(t, tt.want, got) + }) + } +} diff --git a/internal/outbox/relay.go b/internal/outbox/relay.go new file mode 100644 index 0000000..0cda9a9 --- /dev/null +++ b/internal/outbox/relay.go @@ -0,0 +1,199 @@ +// Package outbox publishes the durable job intents with publisher confirms and +// reclaims abandoned relay claims and expired worker leases. +package outbox + +import ( + "context" + "errors" + "log/slog" + "time" + + "go.opentelemetry.io/otel/codes" + + "mtusi-messenger/internal/domain" + "mtusi-messenger/internal/failpoint" + "mtusi-messenger/internal/telemetry" +) + +type Repository interface { + ClaimOutbox(ctx context.Context, owner string, claimTTL time.Duration, limit int) ([]domain.OutboxMessage, error) + MarkPublished(ctx context.Context, ids []int64) error + ReleaseOutbox(ctx context.Context, id int64, reason string) error + ReapOutboxClaims(ctx context.Context) error + ReapExpiredLeases(ctx context.Context, limit int) (int, error) + ReconcileQueuedJobs(ctx context.Context, olderThan time.Duration, limit int, traceparent, tracestate string) (int, error) + OldestActiveJobAge(ctx context.Context) (float64, error) + CountOverdueJobs(ctx context.Context, olderThan time.Duration) (int64, error) + MarkTTRMissed(ctx context.Context, objective time.Duration) (int64, error) + PruneOutbox(ctx context.Context, retention time.Duration) error + OldestUnpublished(ctx context.Context) (time.Time, error) +} + +type Publisher interface { + PublishConfirmed(ctx context.Context, routingKey string, message domain.JobMessage) error +} + +type Config struct { + Owner string + PollInterval time.Duration + ClaimTTL time.Duration + Batch int + ReaperInterval time.Duration + ReconcileAfter time.Duration + Retention time.Duration +} + +type Relay struct { + repo Repository + publisher Publisher + config Config + log *slog.Logger + + lastPublished time.Time + lastReap time.Time + startedAt time.Time +} + +func New(repo Repository, publisher Publisher, config Config, log *slog.Logger) *Relay { + if log == nil { + log = slog.Default() + } + + return &Relay{repo: repo, publisher: publisher, config: config, log: log, startedAt: time.Now()} +} + +func (r *Relay) Run(ctx context.Context) { + telemetry.RecordTTRMissed(ctx, 0) + poll := time.NewTicker(r.config.PollInterval) + defer poll.Stop() + + reaper := time.NewTicker(r.config.ReaperInterval) + defer reaper.Stop() + + for { + select { + case <-ctx.Done(): + return + case <-poll.C: + if _, err := r.RunOnce(ctx); err != nil { + r.log.WarnContext(ctx, "outbox publish cycle failed", slog.Any("error", err)) + } + case <-reaper.C: + r.reap(ctx) + } + } +} + +// RunOnce claims due rows, publishes each with a broker confirm and marks only +// confirmed rows. A crash between confirm and mark causes a duplicate publish, +// which the worker tolerates by CAS. +func (r *Relay) RunOnce(ctx context.Context) (int, error) { + messages, err := r.repo.ClaimOutbox(ctx, r.config.Owner, r.config.ClaimTTL, r.config.Batch) + if err != nil { + return 0, err + } + + published := make([]int64, 0, len(messages)) + + for _, message := range messages { + job, err := domain.ParseJobMessage(message.Payload) + if err != nil { + // A malformed payload is an application bug, not a transient + // failure. Keep the row claim until it expires and log loudly; the + // operator can inspect the outbox. + r.log.ErrorContext(ctx, "outbox payload is invalid", + slog.Int64("outbox_id", message.ID), + slog.Any("error", err), + ) + _ = r.repo.ReleaseOutbox(ctx, message.ID, "invalid payload") + + continue + } + + failpoint.Check("OUTBOX_AFTER_COMMIT", job.JobID) + + publishCtx, span := telemetry.StartPublishSpan(ctx, job) + job.Traceparent, job.Tracestate = telemetry.Inject(publishCtx) + err = r.publisher.PublishConfirmed(publishCtx, message.RoutingKey, job) + if err != nil { + span.RecordError(errors.New(telemetry.Redact(err.Error()))) + span.SetStatus(codes.Error, telemetry.Redact(err.Error())) + } + span.End() + if err != nil { + _ = r.repo.ReleaseOutbox(ctx, message.ID, err.Error()) + + continue + } + + published = append(published, message.ID) + r.lastPublished = time.Now() + } + + if err := r.repo.MarkPublished(ctx, published); err != nil { + return len(published), err + } + + return len(published), nil +} + +func (r *Relay) reap(ctx context.Context) { + ctx, span := telemetry.StartRequeueSpan(ctx, "requeue") + defer span.End() + + if err := r.repo.ReapOutboxClaims(ctx); err != nil { + r.log.WarnContext(ctx, "outbox claim reaper failed", slog.Any("error", err)) + } + + if time.Since(r.startedAt) >= 30*time.Second { + missed, err := r.repo.MarkTTRMissed(ctx, 30*time.Second) + if err != nil { + r.log.WarnContext(ctx, "TTR miss sweep failed", slog.Any("error", err)) + } else if missed > 0 { + telemetry.RecordTTRMissed(ctx, missed) + r.log.InfoContext(ctx, "TTR misses recorded", slog.Int64("count", missed)) + } + } + + reaped, err := r.repo.ReapExpiredLeases(ctx, 100) + if err != nil { + r.log.WarnContext(ctx, "lease reaper failed", slog.Any("error", err)) + } else if reaped > 0 { + r.log.InfoContext(ctx, "expired job leases requeued", slog.Int("count", reaped)) + } + + // The broker is not the source of truth. If a delivery was dead-lettered + // or lost, the queued job has no unpublished outbox row; republish it. + if r.config.ReconcileAfter > 0 { + traceparent, tracestate := telemetry.Inject(ctx) + reconciled, err := r.repo.ReconcileQueuedJobs(ctx, r.config.ReconcileAfter, 100, traceparent, tracestate) + if err != nil { + r.log.WarnContext(ctx, "queued-job reconciliation failed", slog.Any("error", err)) + } else if reconciled > 0 { + r.log.InfoContext(ctx, "lost queued jobs reconciled", slog.Int("count", reconciled)) + } + } + + if r.config.Retention > 0 { + if err := r.repo.PruneOutbox(ctx, r.config.Retention); err != nil { + r.log.WarnContext(ctx, "outbox retention failed", slog.Any("error", err)) + } + } + + r.lastReap = time.Now() +} + +// Health returns the age of the oldest unpublished intent. A bounded age is a +// better relay readiness signal than "connected to broker". +func (r *Relay) Health(ctx context.Context) (oldest time.Duration, err error) { + oldestAt, err := r.repo.OldestUnpublished(ctx) + if err != nil { + return 0, err + } + + if oldestAt.IsZero() { + return 0, nil + } + + return time.Since(oldestAt), nil +} diff --git a/internal/platform/cache/cache.go b/internal/platform/cache/cache.go new file mode 100644 index 0000000..57f070d --- /dev/null +++ b/internal/platform/cache/cache.go @@ -0,0 +1,31 @@ +package cache + +import ( + "context" + "errors" + "time" +) + +var ErrCacheMiss = errors.New("cache miss") + +type Cache interface { + Get(ctx context.Context, key string) ([]byte, error) + Set(ctx context.Context, key string, value []byte, ttl time.Duration) error + Delete(ctx context.Context, keys ...string) error + Ping(ctx context.Context) error + Close() error +} + +type NoOpCache struct{} + +func (NoOpCache) Get(context.Context, string) ([]byte, error) { return nil, ErrCacheMiss } +func (NoOpCache) Set(context.Context, string, []byte, time.Duration) error { return nil } +func (NoOpCache) Delete(context.Context, ...string) error { return nil } +func (NoOpCache) AcquireLock(context.Context, string, string, time.Duration) (bool, error) { + return true, nil +} + +func (NoOpCache) ReleaseLock(context.Context, string, string) (bool, error) { return true, nil } +func (NoOpCache) LockHeld(context.Context, string) (bool, error) { return false, nil } +func (NoOpCache) Ping(context.Context) error { return nil } +func (NoOpCache) Close() error { return nil } diff --git a/internal/platform/cache/cache_test.go b/internal/platform/cache/cache_test.go new file mode 100644 index 0000000..757c03d --- /dev/null +++ b/internal/platform/cache/cache_test.go @@ -0,0 +1,31 @@ +package cache_test + +import ( + "testing" + "time" + + "github.com/stretchr/testify/require" + + "mtusi-messenger/internal/platform/cache" +) + +func TestNoOpCache(t *testing.T) { + t.Parallel() + ctx := t.Context() + store := cache.NoOpCache{} + require.NoError(t, store.Set(ctx, "key", []byte("value"), time.Minute)) + _, err := store.Get(ctx, "key") + require.ErrorIs(t, err, cache.ErrCacheMiss) + require.NoError(t, store.Delete(ctx, "key")) + acquired, err := store.AcquireLock(ctx, "lock", "token", time.Second) + require.NoError(t, err) + require.True(t, acquired) + held, err := store.LockHeld(ctx, "lock") + require.NoError(t, err) + require.False(t, held) + released, err := store.ReleaseLock(ctx, "lock", "token") + require.NoError(t, err) + require.True(t, released) + require.NoError(t, store.Ping(ctx)) + require.NoError(t, store.Close()) +} diff --git a/internal/platform/cache/distributed.go b/internal/platform/cache/distributed.go new file mode 100644 index 0000000..43a5ead --- /dev/null +++ b/internal/platform/cache/distributed.go @@ -0,0 +1,307 @@ +package cache + +import ( + "bytes" + "context" + "crypto/rand" + "encoding/hex" + "errors" + "fmt" + "log/slog" + mathrand "math/rand/v2" + "strconv" + "sync/atomic" + "time" + + "golang.org/x/sync/singleflight" +) + +const ( + DefaultLockTTL = 10 * time.Second + DefaultWaitTimeout = 2 * time.Second + minLockTTL = time.Second + redisOpTimeout = 200 * time.Millisecond + releaseTimeout = 300 * time.Millisecond +) + +type DistributedConfig struct { + LockTTL time.Duration + WaitTimeout time.Duration +} + +type LockStore interface { + Cache + AcquireLock(ctx context.Context, key, token string, ttl time.Duration) (bool, error) + ReleaseLock(ctx context.Context, key, token string) (bool, error) + LockHeld(ctx context.Context, key string) (bool, error) +} + +type DistributedCache struct { + store LockStore + lockTTL time.Duration + waitTimeout time.Duration + log *slog.Logger + group singleflight.Group +} + +var fallbackTokenCounter atomic.Uint64 + +func NewDistributed(store LockStore, cfg DistributedConfig, log *slog.Logger) (*DistributedCache, error) { + if cfg.LockTTL <= 0 { + cfg.LockTTL = DefaultLockTTL + } + + if cfg.WaitTimeout <= 0 { + cfg.WaitTimeout = DefaultWaitTimeout + } + + if cfg.LockTTL <= minLockTTL { + return nil, fmt.Errorf("cache: lock ttl %s must be greater than %s", cfg.LockTTL, minLockTTL) + } + + if cfg.WaitTimeout > cfg.LockTTL { + return nil, fmt.Errorf("cache: wait timeout %s must not exceed lock ttl %s", cfg.WaitTimeout, cfg.LockTTL) + } + + return &DistributedCache{ + store: store, + lockTTL: cfg.LockTTL, + waitTimeout: cfg.WaitTimeout, + log: log, + }, nil +} + +func (d *DistributedCache) GetOrLoad( + ctx context.Context, + key string, + ttl time.Duration, + loader func(ctx context.Context) ([]byte, error), +) ([]byte, error) { + ch := d.group.DoChan(key, func() (any, error) { + lctx, cancel := context.WithTimeout(context.WithoutCancel(ctx), d.lockTTL+d.waitTimeout) + defer cancel() + + return d.getOrLoad(lctx, key, ttl, loader) + }) + + select { + case <-ctx.Done(): + return nil, ctx.Err() + case result := <-ch: + if result.Err != nil { + return nil, result.Err + } + + value, ok := result.Val.([]byte) + if !ok { + return nil, errors.New("cache: unexpected singleflight result") + } + + return bytes.Clone(value), nil + } +} + +func (d *DistributedCache) getOrLoad( + ctx context.Context, + key string, + ttl time.Duration, + loader func(ctx context.Context) ([]byte, error), +) ([]byte, error) { + lockKey := "lock:" + key + + for { + if err := ctx.Err(); err != nil { + return nil, err + } + + if value, err := d.store.Get(ctx, key); err == nil { + return value, nil + } else if !errors.Is(err, ErrCacheMiss) { + return loader(ctx) + } + + token := randomToken() + + acquired, err := d.store.AcquireLock(ctx, lockKey, token, d.lockTTL) + if err != nil { + return loader(ctx) + } + + if acquired { + return d.fill(ctx, key, lockKey, token, ttl, loader) + } + + value, outcome, err := d.await(ctx, key, lockKey) + if err != nil { + return nil, err + } + + switch outcome { + case waitHit: + return value, nil + case waitDegraded: + return loader(ctx) + case waitTimeout: + return loader(ctx) + case waitRetry: + if ctx.Err() != nil { + return nil, ctx.Err() + } + case waitNone: + return nil, errors.New("cache: unexpected wait outcome") + } + } +} + +func (d *DistributedCache) fill( + ctx context.Context, + key, lockKey, token string, + ttl time.Duration, + loader func(ctx context.Context) ([]byte, error), +) ([]byte, error) { + base := context.WithoutCancel(ctx) + + defer func() { + rctx, cancel := context.WithTimeout(base, releaseTimeout) + defer cancel() + + held, err := d.store.ReleaseLock(rctx, lockKey, token) + switch { + case err != nil: + d.warn(base, "lock release failed", key, err) + case !held: + d.warn(base, "lock expired before release: loader slower than lock ttl", key, nil) + } + }() + + getCtx, cancelGet := context.WithTimeout(base, redisOpTimeout) + value, err := d.store.Get(getCtx, key) + cancelGet() + + if err == nil { + return value, nil + } + + loadCtx, cancel := context.WithTimeout(base, d.lockTTL-minLockTTL) + defer cancel() + + value, err = loader(loadCtx) + if err != nil { + return nil, err + } + + setCtx, cancelSet := context.WithTimeout(base, redisOpTimeout) + setErr := d.store.Set(setCtx, key, value, ttl) + cancelSet() + + if setErr != nil { + d.warn(base, "distributed cache write failed", key, setErr) + } + + return value, nil +} + +type waitOutcome int + +const ( + waitNone waitOutcome = iota + waitHit + waitRetry + waitTimeout + waitDegraded +) + +func (d *DistributedCache) await(ctx context.Context, key, lockKey string) ([]byte, waitOutcome, error) { + wctx, cancel := context.WithTimeout(ctx, d.waitTimeout) + defer cancel() + + for attempt := 1; ; attempt++ { + value, err := d.store.Get(wctx, key) + switch { + case err == nil: + return value, waitHit, nil + case ctx.Err() != nil: + return nil, waitNone, ctx.Err() + case wctx.Err() != nil: + return nil, waitTimeout, nil + case !errors.Is(err, ErrCacheMiss): + return nil, waitDegraded, nil + } + + if held, err := d.store.LockHeld(wctx, lockKey); err == nil && !held { + return nil, waitRetry, nil + } + + select { + case <-wctx.Done(): + if err := ctx.Err(); err != nil { + return nil, waitNone, err + } + + return nil, waitTimeout, nil + case <-time.After(jittered(waitBackoff(attempt))): + } + } +} + +func (d *DistributedCache) Get(ctx context.Context, key string) ([]byte, error) { + return d.store.Get(ctx, key) +} + +func (d *DistributedCache) Set(ctx context.Context, key string, value []byte, ttl time.Duration) error { + return d.store.Set(ctx, key, value, ttl) +} + +func (d *DistributedCache) Delete(ctx context.Context, keys ...string) error { + return d.store.Delete(ctx, keys...) +} + +func (d *DistributedCache) Ping(ctx context.Context) error { + return d.store.Ping(ctx) +} + +func (d *DistributedCache) Close() error { + return d.store.Close() +} + +func (d *DistributedCache) warn(ctx context.Context, msg, key string, err error) { + if d.log == nil { + return + } + + attrs := []slog.Attr{slog.String("key", key)} + if err != nil { + attrs = append(attrs, slog.Any("error", err)) + } + + d.log.LogAttrs(ctx, slog.LevelWarn, msg, attrs...) +} + +func waitBackoff(attempt int) time.Duration { + const base, maxWait = 50 * time.Millisecond, 500 * time.Millisecond + if attempt > 4 { + return maxWait + } + + return base << (attempt - 1) +} + +func jittered(d time.Duration) time.Duration { + half := d / 2 + if half <= 0 { + return d + } + + return half + mathrand.N(half) +} + +func randomToken() string { + raw := make([]byte, 16) + if _, err := rand.Read(raw); err != nil { + counter := fallbackTokenCounter.Add(1) + + return strconv.FormatInt(time.Now().UnixNano(), 10) + ":" + strconv.FormatUint(counter, 10) + } + + return hex.EncodeToString(raw) +} diff --git a/internal/platform/cache/distributed_internal_test.go b/internal/platform/cache/distributed_internal_test.go new file mode 100644 index 0000000..94c369d --- /dev/null +++ b/internal/platform/cache/distributed_internal_test.go @@ -0,0 +1,43 @@ +package cache + +import ( + "testing" + "time" + + "github.com/stretchr/testify/mock" + "github.com/stretchr/testify/require" + + "mtusi-messenger/internal/platform/cache/mocks" +) + +func TestAwaitChecksCacheBeforePolling(t *testing.T) { + t.Parallel() + + store := mocks.NewMockLockStore(t) + store.EXPECT().Get(mock.Anything, "key").Return([]byte("ready"), nil).Once() + + d, err := NewDistributed(store, DistributedConfig{WaitTimeout: time.Second}, nil) + require.NoError(t, err) + + started := time.Now() + value, outcome, err := d.await(t.Context(), "key", "lock:key") + require.NoError(t, err) + require.Equal(t, waitHit, outcome) + require.Equal(t, "ready", string(value)) + require.Less(t, time.Since(started), 25*time.Millisecond, "cache must be checked before the first sleep") +} + +func TestAwaitReturnsTimeoutWhileLockHeld(t *testing.T) { + t.Parallel() + + store := mocks.NewMockLockStore(t) + store.EXPECT().Get(mock.Anything, "key").Return(nil, ErrCacheMiss).Maybe() + store.EXPECT().LockHeld(mock.Anything, "lock:key").Return(true, nil).Maybe() + + d, err := NewDistributed(store, DistributedConfig{WaitTimeout: 60 * time.Millisecond}, nil) + require.NoError(t, err) + + _, outcome, err := d.await(t.Context(), "key", "lock:key") + require.NoError(t, err) + require.Equal(t, waitTimeout, outcome) +} diff --git a/internal/platform/cache/distributed_test.go b/internal/platform/cache/distributed_test.go new file mode 100644 index 0000000..63aa245 --- /dev/null +++ b/internal/platform/cache/distributed_test.go @@ -0,0 +1,374 @@ +package cache_test + +import ( + "context" + "sync" + "sync/atomic" + "testing" + "time" + + "github.com/stretchr/testify/mock" + "github.com/stretchr/testify/require" + + "mtusi-messenger/internal/platform/cache" + "mtusi-messenger/internal/platform/cache/mocks" +) + +func newDistributed(t *testing.T, store cache.LockStore, cfg cache.DistributedConfig) *cache.DistributedCache { + t.Helper() + + dc, err := cache.NewDistributed(store, cfg, nil) + require.NoError(t, err) + + return dc +} + +func expectFill(store *mocks.MockLockStore, key string) { + store.EXPECT().Get(mock.Anything, key).Return(nil, cache.ErrCacheMiss).Once() + store.EXPECT().AcquireLock(mock.Anything, "lock:"+key, mock.AnythingOfType("string"), mock.Anything).Return(true, nil).Once() + store.EXPECT().Get(mock.Anything, key).Return(nil, cache.ErrCacheMiss).Once() + store.EXPECT().Set(mock.Anything, key, mock.Anything, mock.Anything).Return(nil).Once() + store.EXPECT().ReleaseLock(mock.Anything, "lock:"+key, mock.AnythingOfType("string")).Return(true, nil).Once() +} + +// sharedWaitTimeout bounds every wait in these tests: a stuck helper must fail +// the test instead of hanging the whole package until -timeout fires. +const sharedWaitTimeout = 5 * time.Second + +func awaitSignal(t *testing.T, ch <-chan struct{}, message string) { + t.Helper() + + select { + case <-ch: + case <-time.After(sharedWaitTimeout): + t.Fatal("timed out: " + message) + } +} + +func awaitValue[T any](t *testing.T, ch <-chan T) T { + t.Helper() + + select { + case value := <-ch: + return value + case <-time.After(sharedWaitTimeout): + var zero T + + t.Fatal("timed out waiting for the shared load to report its result") + + return zero + } +} + +func awaitWaitGroup(t *testing.T, wg *sync.WaitGroup) { + t.Helper() + + done := make(chan struct{}) + + go func() { + wg.Wait() + close(done) + }() + + awaitSignal(t, done, "goroutines did not finish") +} + +func TestDistributedCachesResult(t *testing.T) { + t.Parallel() + + store := mocks.NewMockLockStore(t) + dc := newDistributed(t, store, cache.DistributedConfig{}) + ctx := context.Background() + + var calls atomic.Int32 + + loader := func(context.Context) ([]byte, error) { + calls.Add(1) + + return []byte("payload"), nil + } + + expectFill(store, "key") + store.EXPECT().Get(mock.Anything, "key").Return([]byte("payload"), nil).Once() + + first, err := dc.GetOrLoad(ctx, "key", time.Minute, loader) + require.NoError(t, err) + require.Equal(t, []byte("payload"), first) + + second, err := dc.GetOrLoad(ctx, "key", time.Minute, loader) + require.NoError(t, err) + require.Equal(t, []byte("payload"), second) + require.Equal(t, int32(1), calls.Load()) +} + +func TestDistributedDeduplicatesConcurrentMisses(t *testing.T) { + t.Parallel() + + store := mocks.NewMockLockStore(t) + dc := newDistributed(t, store, cache.DistributedConfig{}) + ctx := context.Background() + + var calls atomic.Int32 + + loader := func(context.Context) ([]byte, error) { + calls.Add(1) + time.Sleep(30 * time.Millisecond) + + return []byte("payload"), nil + } + + store.EXPECT().Get(mock.Anything, "shared").Return(nil, cache.ErrCacheMiss).Twice() + store.EXPECT().AcquireLock(mock.Anything, "lock:shared", mock.AnythingOfType("string"), mock.Anything).Return(true, nil).Once() + store.EXPECT().Set(mock.Anything, "shared", mock.Anything, mock.Anything).Return(nil).Once() + store.EXPECT().ReleaseLock(mock.Anything, "lock:shared", mock.AnythingOfType("string")).Return(true, nil).Once() + + const workers = 50 + + var ( + wg sync.WaitGroup + failures atomic.Int32 + ) + + wg.Add(workers) + + for range workers { + go func() { + defer wg.Done() + + value, err := dc.GetOrLoad(ctx, "shared", time.Minute, loader) + if err != nil || string(value) != "payload" { + failures.Add(1) + } + }() + } + + awaitWaitGroup(t, &wg) + + require.Zero(t, failures.Load()) + require.Equal(t, int32(1), calls.Load(), "one instance must load once for concurrent misses") +} + +func TestDistributedFallsBackOnWaitTimeout(t *testing.T) { + t.Parallel() + + store := mocks.NewMockLockStore(t) + dc := newDistributed(t, store, cache.DistributedConfig{WaitTimeout: 100 * time.Millisecond}) + ctx := context.Background() + + store.EXPECT().Get(mock.Anything, "key").Return(nil, cache.ErrCacheMiss).Maybe() + store.EXPECT().AcquireLock(mock.Anything, "lock:key", mock.AnythingOfType("string"), mock.Anything).Return(false, nil).Once() + store.EXPECT().LockHeld(mock.Anything, "lock:key").Return(true, nil).Maybe() + + var calls atomic.Int32 + + value, err := dc.GetOrLoad(ctx, "key", time.Minute, func(context.Context) ([]byte, error) { + calls.Add(1) + + return []byte("fallback"), nil + }) + require.NoError(t, err) + require.Equal(t, []byte("fallback"), value) + require.Equal(t, int32(1), calls.Load(), "a wait timeout must fall back to a direct load") +} + +func TestDistributedSharedLoadSurvivesCallerCancellation(t *testing.T) { + t.Parallel() + + store := mocks.NewMockLockStore(t) + dc := newDistributed(t, store, cache.DistributedConfig{}) + leaderCtx, cancelLeader := context.WithCancel(context.Background()) + defer cancelLeader() + + var calls atomic.Int32 + + started := make(chan struct{}) + release := make(chan struct{}) + + loader := func(loadCtx context.Context) ([]byte, error) { + calls.Add(1) + close(started) + <-release + + if err := loadCtx.Err(); err != nil { + return nil, err + } + + return []byte("value"), nil + } + + store.EXPECT().Get(mock.Anything, "key").Return(nil, cache.ErrCacheMiss).Twice() + store.EXPECT().AcquireLock(mock.Anything, "lock:key", mock.AnythingOfType("string"), mock.Anything).Return(true, nil).Once() + store.EXPECT().Set(mock.Anything, "key", mock.Anything, mock.Anything).Return(nil).Once() + store.EXPECT().ReleaseLock(mock.Anything, "lock:key", mock.AnythingOfType("string")).Return(true, nil).Once() + + leaderErr := make(chan error, 1) + + go func() { + _, err := dc.GetOrLoad(leaderCtx, "key", time.Minute, loader) + leaderErr <- err + }() + + awaitSignal(t, started, "leader must reach the loader") + + // The follower starts while the leader's loader is still blocked, so the + // singleflight call cannot complete: the signal below means DoChan was + // already called, i.e. the follower joined the leader's in-flight call + // instead of starting its own load. + followerJoined := make(chan struct{}) + + var ( + wg sync.WaitGroup + followerV []byte + followerE error + ) + + wg.Add(1) + + go func() { + defer wg.Done() + + ctx := newJoiningContext(followerJoined) + followerV, followerE = dc.GetOrLoad(ctx, "key", time.Minute, loader) + }() + + awaitSignal(t, followerJoined, "follower must join the in-flight load") + + cancelLeader() + close(release) + + require.ErrorIs(t, awaitValue(t, leaderErr), context.Canceled) + awaitWaitGroup(t, &wg) + + require.NoError(t, followerE) + require.Equal(t, []byte("value"), followerV) + require.Equal(t, int32(1), calls.Load()) +} + +// joiningContext reports when GetOrLoad reaches the shared-result wait path. The +// delegate is kept as function fields so no struct holds a context.Context. +type joiningContext struct { + deadline func() (time.Time, bool) + done func() <-chan struct{} + err func() error + value func(any) any + + once *sync.Once + joined chan struct{} +} + +func newJoiningContext(joined chan struct{}) joiningContext { + base := context.Background() + + return joiningContext{ + deadline: base.Deadline, + done: base.Done, + err: base.Err, + value: base.Value, + once: new(sync.Once), + joined: joined, + } +} + +func (c joiningContext) Deadline() (time.Time, bool) { return c.deadline() } + +func (c joiningContext) Done() <-chan struct{} { + c.once.Do(func() { close(c.joined) }) + + return c.done() +} + +func (c joiningContext) Err() error { return c.err() } + +func (c joiningContext) Value(key any) any { return c.value(key) } + +func TestDistributedRetriesWhenLockVanishes(t *testing.T) { + t.Parallel() + + store := mocks.NewMockLockStore(t) + dc := newDistributed(t, store, cache.DistributedConfig{}) + ctx := context.Background() + + var released atomic.Bool + + time.AfterFunc(120*time.Millisecond, func() { released.Store(true) }) + + store.EXPECT().Get(mock.Anything, "key").Return(nil, cache.ErrCacheMiss).Maybe() + store.EXPECT().AcquireLock(mock.Anything, "lock:key", mock.AnythingOfType("string"), mock.Anything).Return(false, nil).Once() + store.EXPECT().AcquireLock(mock.Anything, "lock:key", mock.AnythingOfType("string"), mock.Anything).Return(true, nil).Once() + store.EXPECT().LockHeld(mock.Anything, "lock:key").RunAndReturn(func(context.Context, string) (bool, error) { + return !released.Load(), nil + }).Maybe() + store.EXPECT().Set(mock.Anything, "key", mock.Anything, mock.Anything).Return(nil).Once() + store.EXPECT().ReleaseLock(mock.Anything, "lock:key", mock.AnythingOfType("string")).Return(true, nil).Once() + + var calls atomic.Int32 + + value, err := dc.GetOrLoad(ctx, "key", time.Minute, func(context.Context) ([]byte, error) { + calls.Add(1) + + return []byte("recovered"), nil + }) + require.NoError(t, err) + require.Equal(t, []byte("recovered"), value) + require.Equal(t, int32(1), calls.Load()) +} + +func TestFillStoreCallsAreBoundedByDeadline(t *testing.T) { + t.Parallel() + + store := mocks.NewMockLockStore(t) + dc := newDistributed(t, store, cache.DistributedConfig{}) + + var ( + mu sync.Mutex + getBudgets []time.Duration + setBudget time.Duration + setHasDead bool + ) + + store.EXPECT().Get(mock.Anything, "key").RunAndReturn(func(ctx context.Context, _ string) ([]byte, error) { + mu.Lock() + defer mu.Unlock() + + if deadline, ok := ctx.Deadline(); ok { + getBudgets = append(getBudgets, time.Until(deadline)) + } + + return nil, cache.ErrCacheMiss + }).Twice() + store.EXPECT().AcquireLock(mock.Anything, "lock:key", mock.AnythingOfType("string"), mock.Anything).Return(true, nil).Once() + store.EXPECT().Set(mock.Anything, "key", mock.Anything, mock.Anything). + RunAndReturn(func(ctx context.Context, _ string, _ []byte, _ time.Duration) error { + mu.Lock() + defer mu.Unlock() + + deadline, ok := ctx.Deadline() + setHasDead = ok + if ok { + setBudget = time.Until(deadline) + } + + return nil + }).Once() + store.EXPECT().ReleaseLock(mock.Anything, "lock:key", mock.AnythingOfType("string")).Return(true, nil).Once() + + _, err := dc.GetOrLoad(context.Background(), "key", time.Minute, func(context.Context) ([]byte, error) { + return []byte("value"), nil + }) + require.NoError(t, err) + + mu.Lock() + defer mu.Unlock() + + require.True(t, setHasDead, "Set must receive a bounded context") + require.LessOrEqual(t, setBudget, 300*time.Millisecond) + + minGetBudget := time.Hour + for _, budget := range getBudgets { + if budget < minGetBudget { + minGetBudget = budget + } + } + + require.LessOrEqual(t, minGetBudget, 300*time.Millisecond, "fill's Get must receive a bounded context") +} diff --git a/internal/platform/cache/mocks/Cache.go b/internal/platform/cache/mocks/Cache.go new file mode 100644 index 0000000..d511bc7 --- /dev/null +++ b/internal/platform/cache/mocks/Cache.go @@ -0,0 +1,346 @@ +// Code generated by mockery; DO NOT EDIT. +// github.com/vektra/mockery +// template: testify + +package mocks + +import ( + "context" + "time" + + mock "github.com/stretchr/testify/mock" +) + +// NewMockCache creates a new instance of MockCache. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewMockCache(t interface { + mock.TestingT + Cleanup(func()) +}) *MockCache { + if helper, ok := t.(interface{ Helper() }); ok { + helper.Helper() + } + + mock := &MockCache{} + mock.Mock.Test(t) + + t.Cleanup(func() { + if helper, ok := t.(interface{ Helper() }); ok { + helper.Helper() + } + mock.AssertExpectations(t) + }) + + return mock +} + +// MockCache is an autogenerated mock type for the Cache type +type MockCache struct { + mock.Mock +} + +type MockCache_Expecter struct { + mock *mock.Mock +} + +func (_m *MockCache) EXPECT() *MockCache_Expecter { + return &MockCache_Expecter{mock: &_m.Mock} +} + +// Close provides a mock function for the type MockCache +func (_mock *MockCache) Close() error { + ret := _mock.Called() + + if len(ret) == 0 { + panic("no return value specified for Close") + } + + var r0 error + if returnFunc, ok := ret.Get(0).(func() error); ok { + r0 = returnFunc() + } else { + r0 = ret.Error(0) + } + return r0 +} + +// MockCache_Close_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Close' +type MockCache_Close_Call struct { + *mock.Call +} + +// Close is a helper method to define mock.On call +func (_e *MockCache_Expecter) Close() *MockCache_Close_Call { + return &MockCache_Close_Call{Call: _e.mock.On("Close")} +} + +func (_c *MockCache_Close_Call) Run(run func()) *MockCache_Close_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *MockCache_Close_Call) Return(err error) *MockCache_Close_Call { + _c.Call.Return(err) + return _c +} + +func (_c *MockCache_Close_Call) RunAndReturn(run func() error) *MockCache_Close_Call { + _c.Call.Return(run) + return _c +} + +// Delete provides a mock function for the type MockCache +func (_mock *MockCache) Delete(ctx context.Context, keys ...string) error { + var tmpRet mock.Arguments + if len(keys) > 0 { + tmpRet = _mock.Called(ctx, keys) + } else { + tmpRet = _mock.Called(ctx) + } + ret := tmpRet + + if len(ret) == 0 { + panic("no return value specified for Delete") + } + + var r0 error + if returnFunc, ok := ret.Get(0).(func(context.Context, ...string) error); ok { + r0 = returnFunc(ctx, keys...) + } else { + r0 = ret.Error(0) + } + return r0 +} + +// MockCache_Delete_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Delete' +type MockCache_Delete_Call struct { + *mock.Call +} + +// Delete is a helper method to define mock.On call +// - ctx context.Context +// - keys ...string +func (_e *MockCache_Expecter) Delete(ctx any, keys ...any) *MockCache_Delete_Call { + return &MockCache_Delete_Call{Call: _e.mock.On("Delete", + append([]any{ctx}, keys...)...)} +} + +func (_c *MockCache_Delete_Call) Run(run func(ctx context.Context, keys ...string)) *MockCache_Delete_Call { + _c.Call.Run(func(args mock.Arguments) { + var arg0 context.Context + if args[0] != nil { + arg0 = args[0].(context.Context) + } + var arg1 []string + var variadicArgs []string + if len(args) > 1 { + variadicArgs = args[1].([]string) + } + arg1 = variadicArgs + run( + arg0, + arg1..., + ) + }) + return _c +} + +func (_c *MockCache_Delete_Call) Return(err error) *MockCache_Delete_Call { + _c.Call.Return(err) + return _c +} + +func (_c *MockCache_Delete_Call) RunAndReturn(run func(ctx context.Context, keys ...string) error) *MockCache_Delete_Call { + _c.Call.Return(run) + return _c +} + +// Get provides a mock function for the type MockCache +func (_mock *MockCache) Get(ctx context.Context, key string) ([]byte, error) { + ret := _mock.Called(ctx, key) + + if len(ret) == 0 { + panic("no return value specified for Get") + } + + var r0 []byte + var r1 error + if returnFunc, ok := ret.Get(0).(func(context.Context, string) ([]byte, error)); ok { + return returnFunc(ctx, key) + } + if returnFunc, ok := ret.Get(0).(func(context.Context, string) []byte); ok { + r0 = returnFunc(ctx, key) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]byte) + } + } + if returnFunc, ok := ret.Get(1).(func(context.Context, string) error); ok { + r1 = returnFunc(ctx, key) + } else { + r1 = ret.Error(1) + } + return r0, r1 +} + +// MockCache_Get_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Get' +type MockCache_Get_Call struct { + *mock.Call +} + +// Get is a helper method to define mock.On call +// - ctx context.Context +// - key string +func (_e *MockCache_Expecter) Get(ctx any, key any) *MockCache_Get_Call { + return &MockCache_Get_Call{Call: _e.mock.On("Get", ctx, key)} +} + +func (_c *MockCache_Get_Call) Run(run func(ctx context.Context, key string)) *MockCache_Get_Call { + _c.Call.Run(func(args mock.Arguments) { + var arg0 context.Context + if args[0] != nil { + arg0 = args[0].(context.Context) + } + var arg1 string + if args[1] != nil { + arg1 = args[1].(string) + } + run( + arg0, + arg1, + ) + }) + return _c +} + +func (_c *MockCache_Get_Call) Return(bytes []byte, err error) *MockCache_Get_Call { + _c.Call.Return(bytes, err) + return _c +} + +func (_c *MockCache_Get_Call) RunAndReturn(run func(ctx context.Context, key string) ([]byte, error)) *MockCache_Get_Call { + _c.Call.Return(run) + return _c +} + +// Ping provides a mock function for the type MockCache +func (_mock *MockCache) Ping(ctx context.Context) error { + ret := _mock.Called(ctx) + + if len(ret) == 0 { + panic("no return value specified for Ping") + } + + var r0 error + if returnFunc, ok := ret.Get(0).(func(context.Context) error); ok { + r0 = returnFunc(ctx) + } else { + r0 = ret.Error(0) + } + return r0 +} + +// MockCache_Ping_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Ping' +type MockCache_Ping_Call struct { + *mock.Call +} + +// Ping is a helper method to define mock.On call +// - ctx context.Context +func (_e *MockCache_Expecter) Ping(ctx any) *MockCache_Ping_Call { + return &MockCache_Ping_Call{Call: _e.mock.On("Ping", ctx)} +} + +func (_c *MockCache_Ping_Call) Run(run func(ctx context.Context)) *MockCache_Ping_Call { + _c.Call.Run(func(args mock.Arguments) { + var arg0 context.Context + if args[0] != nil { + arg0 = args[0].(context.Context) + } + run( + arg0, + ) + }) + return _c +} + +func (_c *MockCache_Ping_Call) Return(err error) *MockCache_Ping_Call { + _c.Call.Return(err) + return _c +} + +func (_c *MockCache_Ping_Call) RunAndReturn(run func(ctx context.Context) error) *MockCache_Ping_Call { + _c.Call.Return(run) + return _c +} + +// Set provides a mock function for the type MockCache +func (_mock *MockCache) Set(ctx context.Context, key string, value []byte, ttl time.Duration) error { + ret := _mock.Called(ctx, key, value, ttl) + + if len(ret) == 0 { + panic("no return value specified for Set") + } + + var r0 error + if returnFunc, ok := ret.Get(0).(func(context.Context, string, []byte, time.Duration) error); ok { + r0 = returnFunc(ctx, key, value, ttl) + } else { + r0 = ret.Error(0) + } + return r0 +} + +// MockCache_Set_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Set' +type MockCache_Set_Call struct { + *mock.Call +} + +// Set is a helper method to define mock.On call +// - ctx context.Context +// - key string +// - value []byte +// - ttl time.Duration +func (_e *MockCache_Expecter) Set(ctx any, key any, value any, ttl any) *MockCache_Set_Call { + return &MockCache_Set_Call{Call: _e.mock.On("Set", ctx, key, value, ttl)} +} + +func (_c *MockCache_Set_Call) Run(run func(ctx context.Context, key string, value []byte, ttl time.Duration)) *MockCache_Set_Call { + _c.Call.Run(func(args mock.Arguments) { + var arg0 context.Context + if args[0] != nil { + arg0 = args[0].(context.Context) + } + var arg1 string + if args[1] != nil { + arg1 = args[1].(string) + } + var arg2 []byte + if args[2] != nil { + arg2 = args[2].([]byte) + } + var arg3 time.Duration + if args[3] != nil { + arg3 = args[3].(time.Duration) + } + run( + arg0, + arg1, + arg2, + arg3, + ) + }) + return _c +} + +func (_c *MockCache_Set_Call) Return(err error) *MockCache_Set_Call { + _c.Call.Return(err) + return _c +} + +func (_c *MockCache_Set_Call) RunAndReturn(run func(ctx context.Context, key string, value []byte, ttl time.Duration) error) *MockCache_Set_Call { + _c.Call.Return(run) + return _c +} diff --git a/internal/platform/cache/mocks/LockStore.go b/internal/platform/cache/mocks/LockStore.go new file mode 100644 index 0000000..bb9903f --- /dev/null +++ b/internal/platform/cache/mocks/LockStore.go @@ -0,0 +1,562 @@ +// Code generated by mockery; DO NOT EDIT. +// github.com/vektra/mockery +// template: testify + +package mocks + +import ( + "context" + "time" + + mock "github.com/stretchr/testify/mock" +) + +// NewMockLockStore creates a new instance of MockLockStore. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewMockLockStore(t interface { + mock.TestingT + Cleanup(func()) +}) *MockLockStore { + if helper, ok := t.(interface{ Helper() }); ok { + helper.Helper() + } + + mock := &MockLockStore{} + mock.Mock.Test(t) + + t.Cleanup(func() { + if helper, ok := t.(interface{ Helper() }); ok { + helper.Helper() + } + mock.AssertExpectations(t) + }) + + return mock +} + +// MockLockStore is an autogenerated mock type for the LockStore type +type MockLockStore struct { + mock.Mock +} + +type MockLockStore_Expecter struct { + mock *mock.Mock +} + +func (_m *MockLockStore) EXPECT() *MockLockStore_Expecter { + return &MockLockStore_Expecter{mock: &_m.Mock} +} + +// AcquireLock provides a mock function for the type MockLockStore +func (_mock *MockLockStore) AcquireLock(ctx context.Context, key string, token string, ttl time.Duration) (bool, error) { + ret := _mock.Called(ctx, key, token, ttl) + + if len(ret) == 0 { + panic("no return value specified for AcquireLock") + } + + var r0 bool + var r1 error + if returnFunc, ok := ret.Get(0).(func(context.Context, string, string, time.Duration) (bool, error)); ok { + return returnFunc(ctx, key, token, ttl) + } + if returnFunc, ok := ret.Get(0).(func(context.Context, string, string, time.Duration) bool); ok { + r0 = returnFunc(ctx, key, token, ttl) + } else { + r0 = ret.Get(0).(bool) + } + if returnFunc, ok := ret.Get(1).(func(context.Context, string, string, time.Duration) error); ok { + r1 = returnFunc(ctx, key, token, ttl) + } else { + r1 = ret.Error(1) + } + return r0, r1 +} + +// MockLockStore_AcquireLock_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'AcquireLock' +type MockLockStore_AcquireLock_Call struct { + *mock.Call +} + +// AcquireLock is a helper method to define mock.On call +// - ctx context.Context +// - key string +// - token string +// - ttl time.Duration +func (_e *MockLockStore_Expecter) AcquireLock(ctx any, key any, token any, ttl any) *MockLockStore_AcquireLock_Call { + return &MockLockStore_AcquireLock_Call{Call: _e.mock.On("AcquireLock", ctx, key, token, ttl)} +} + +func (_c *MockLockStore_AcquireLock_Call) Run(run func(ctx context.Context, key string, token string, ttl time.Duration)) *MockLockStore_AcquireLock_Call { + _c.Call.Run(func(args mock.Arguments) { + var arg0 context.Context + if args[0] != nil { + arg0 = args[0].(context.Context) + } + var arg1 string + if args[1] != nil { + arg1 = args[1].(string) + } + var arg2 string + if args[2] != nil { + arg2 = args[2].(string) + } + var arg3 time.Duration + if args[3] != nil { + arg3 = args[3].(time.Duration) + } + run( + arg0, + arg1, + arg2, + arg3, + ) + }) + return _c +} + +func (_c *MockLockStore_AcquireLock_Call) Return(b bool, err error) *MockLockStore_AcquireLock_Call { + _c.Call.Return(b, err) + return _c +} + +func (_c *MockLockStore_AcquireLock_Call) RunAndReturn(run func(ctx context.Context, key string, token string, ttl time.Duration) (bool, error)) *MockLockStore_AcquireLock_Call { + _c.Call.Return(run) + return _c +} + +// Close provides a mock function for the type MockLockStore +func (_mock *MockLockStore) Close() error { + ret := _mock.Called() + + if len(ret) == 0 { + panic("no return value specified for Close") + } + + var r0 error + if returnFunc, ok := ret.Get(0).(func() error); ok { + r0 = returnFunc() + } else { + r0 = ret.Error(0) + } + return r0 +} + +// MockLockStore_Close_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Close' +type MockLockStore_Close_Call struct { + *mock.Call +} + +// Close is a helper method to define mock.On call +func (_e *MockLockStore_Expecter) Close() *MockLockStore_Close_Call { + return &MockLockStore_Close_Call{Call: _e.mock.On("Close")} +} + +func (_c *MockLockStore_Close_Call) Run(run func()) *MockLockStore_Close_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *MockLockStore_Close_Call) Return(err error) *MockLockStore_Close_Call { + _c.Call.Return(err) + return _c +} + +func (_c *MockLockStore_Close_Call) RunAndReturn(run func() error) *MockLockStore_Close_Call { + _c.Call.Return(run) + return _c +} + +// Delete provides a mock function for the type MockLockStore +func (_mock *MockLockStore) Delete(ctx context.Context, keys ...string) error { + var tmpRet mock.Arguments + if len(keys) > 0 { + tmpRet = _mock.Called(ctx, keys) + } else { + tmpRet = _mock.Called(ctx) + } + ret := tmpRet + + if len(ret) == 0 { + panic("no return value specified for Delete") + } + + var r0 error + if returnFunc, ok := ret.Get(0).(func(context.Context, ...string) error); ok { + r0 = returnFunc(ctx, keys...) + } else { + r0 = ret.Error(0) + } + return r0 +} + +// MockLockStore_Delete_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Delete' +type MockLockStore_Delete_Call struct { + *mock.Call +} + +// Delete is a helper method to define mock.On call +// - ctx context.Context +// - keys ...string +func (_e *MockLockStore_Expecter) Delete(ctx any, keys ...any) *MockLockStore_Delete_Call { + return &MockLockStore_Delete_Call{Call: _e.mock.On("Delete", + append([]any{ctx}, keys...)...)} +} + +func (_c *MockLockStore_Delete_Call) Run(run func(ctx context.Context, keys ...string)) *MockLockStore_Delete_Call { + _c.Call.Run(func(args mock.Arguments) { + var arg0 context.Context + if args[0] != nil { + arg0 = args[0].(context.Context) + } + var arg1 []string + var variadicArgs []string + if len(args) > 1 { + variadicArgs = args[1].([]string) + } + arg1 = variadicArgs + run( + arg0, + arg1..., + ) + }) + return _c +} + +func (_c *MockLockStore_Delete_Call) Return(err error) *MockLockStore_Delete_Call { + _c.Call.Return(err) + return _c +} + +func (_c *MockLockStore_Delete_Call) RunAndReturn(run func(ctx context.Context, keys ...string) error) *MockLockStore_Delete_Call { + _c.Call.Return(run) + return _c +} + +// Get provides a mock function for the type MockLockStore +func (_mock *MockLockStore) Get(ctx context.Context, key string) ([]byte, error) { + ret := _mock.Called(ctx, key) + + if len(ret) == 0 { + panic("no return value specified for Get") + } + + var r0 []byte + var r1 error + if returnFunc, ok := ret.Get(0).(func(context.Context, string) ([]byte, error)); ok { + return returnFunc(ctx, key) + } + if returnFunc, ok := ret.Get(0).(func(context.Context, string) []byte); ok { + r0 = returnFunc(ctx, key) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]byte) + } + } + if returnFunc, ok := ret.Get(1).(func(context.Context, string) error); ok { + r1 = returnFunc(ctx, key) + } else { + r1 = ret.Error(1) + } + return r0, r1 +} + +// MockLockStore_Get_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Get' +type MockLockStore_Get_Call struct { + *mock.Call +} + +// Get is a helper method to define mock.On call +// - ctx context.Context +// - key string +func (_e *MockLockStore_Expecter) Get(ctx any, key any) *MockLockStore_Get_Call { + return &MockLockStore_Get_Call{Call: _e.mock.On("Get", ctx, key)} +} + +func (_c *MockLockStore_Get_Call) Run(run func(ctx context.Context, key string)) *MockLockStore_Get_Call { + _c.Call.Run(func(args mock.Arguments) { + var arg0 context.Context + if args[0] != nil { + arg0 = args[0].(context.Context) + } + var arg1 string + if args[1] != nil { + arg1 = args[1].(string) + } + run( + arg0, + arg1, + ) + }) + return _c +} + +func (_c *MockLockStore_Get_Call) Return(bytes []byte, err error) *MockLockStore_Get_Call { + _c.Call.Return(bytes, err) + return _c +} + +func (_c *MockLockStore_Get_Call) RunAndReturn(run func(ctx context.Context, key string) ([]byte, error)) *MockLockStore_Get_Call { + _c.Call.Return(run) + return _c +} + +// LockHeld provides a mock function for the type MockLockStore +func (_mock *MockLockStore) LockHeld(ctx context.Context, key string) (bool, error) { + ret := _mock.Called(ctx, key) + + if len(ret) == 0 { + panic("no return value specified for LockHeld") + } + + var r0 bool + var r1 error + if returnFunc, ok := ret.Get(0).(func(context.Context, string) (bool, error)); ok { + return returnFunc(ctx, key) + } + if returnFunc, ok := ret.Get(0).(func(context.Context, string) bool); ok { + r0 = returnFunc(ctx, key) + } else { + r0 = ret.Get(0).(bool) + } + if returnFunc, ok := ret.Get(1).(func(context.Context, string) error); ok { + r1 = returnFunc(ctx, key) + } else { + r1 = ret.Error(1) + } + return r0, r1 +} + +// MockLockStore_LockHeld_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'LockHeld' +type MockLockStore_LockHeld_Call struct { + *mock.Call +} + +// LockHeld is a helper method to define mock.On call +// - ctx context.Context +// - key string +func (_e *MockLockStore_Expecter) LockHeld(ctx any, key any) *MockLockStore_LockHeld_Call { + return &MockLockStore_LockHeld_Call{Call: _e.mock.On("LockHeld", ctx, key)} +} + +func (_c *MockLockStore_LockHeld_Call) Run(run func(ctx context.Context, key string)) *MockLockStore_LockHeld_Call { + _c.Call.Run(func(args mock.Arguments) { + var arg0 context.Context + if args[0] != nil { + arg0 = args[0].(context.Context) + } + var arg1 string + if args[1] != nil { + arg1 = args[1].(string) + } + run( + arg0, + arg1, + ) + }) + return _c +} + +func (_c *MockLockStore_LockHeld_Call) Return(b bool, err error) *MockLockStore_LockHeld_Call { + _c.Call.Return(b, err) + return _c +} + +func (_c *MockLockStore_LockHeld_Call) RunAndReturn(run func(ctx context.Context, key string) (bool, error)) *MockLockStore_LockHeld_Call { + _c.Call.Return(run) + return _c +} + +// Ping provides a mock function for the type MockLockStore +func (_mock *MockLockStore) Ping(ctx context.Context) error { + ret := _mock.Called(ctx) + + if len(ret) == 0 { + panic("no return value specified for Ping") + } + + var r0 error + if returnFunc, ok := ret.Get(0).(func(context.Context) error); ok { + r0 = returnFunc(ctx) + } else { + r0 = ret.Error(0) + } + return r0 +} + +// MockLockStore_Ping_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Ping' +type MockLockStore_Ping_Call struct { + *mock.Call +} + +// Ping is a helper method to define mock.On call +// - ctx context.Context +func (_e *MockLockStore_Expecter) Ping(ctx any) *MockLockStore_Ping_Call { + return &MockLockStore_Ping_Call{Call: _e.mock.On("Ping", ctx)} +} + +func (_c *MockLockStore_Ping_Call) Run(run func(ctx context.Context)) *MockLockStore_Ping_Call { + _c.Call.Run(func(args mock.Arguments) { + var arg0 context.Context + if args[0] != nil { + arg0 = args[0].(context.Context) + } + run( + arg0, + ) + }) + return _c +} + +func (_c *MockLockStore_Ping_Call) Return(err error) *MockLockStore_Ping_Call { + _c.Call.Return(err) + return _c +} + +func (_c *MockLockStore_Ping_Call) RunAndReturn(run func(ctx context.Context) error) *MockLockStore_Ping_Call { + _c.Call.Return(run) + return _c +} + +// ReleaseLock provides a mock function for the type MockLockStore +func (_mock *MockLockStore) ReleaseLock(ctx context.Context, key string, token string) (bool, error) { + ret := _mock.Called(ctx, key, token) + + if len(ret) == 0 { + panic("no return value specified for ReleaseLock") + } + + var r0 bool + var r1 error + if returnFunc, ok := ret.Get(0).(func(context.Context, string, string) (bool, error)); ok { + return returnFunc(ctx, key, token) + } + if returnFunc, ok := ret.Get(0).(func(context.Context, string, string) bool); ok { + r0 = returnFunc(ctx, key, token) + } else { + r0 = ret.Get(0).(bool) + } + if returnFunc, ok := ret.Get(1).(func(context.Context, string, string) error); ok { + r1 = returnFunc(ctx, key, token) + } else { + r1 = ret.Error(1) + } + return r0, r1 +} + +// MockLockStore_ReleaseLock_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ReleaseLock' +type MockLockStore_ReleaseLock_Call struct { + *mock.Call +} + +// ReleaseLock is a helper method to define mock.On call +// - ctx context.Context +// - key string +// - token string +func (_e *MockLockStore_Expecter) ReleaseLock(ctx any, key any, token any) *MockLockStore_ReleaseLock_Call { + return &MockLockStore_ReleaseLock_Call{Call: _e.mock.On("ReleaseLock", ctx, key, token)} +} + +func (_c *MockLockStore_ReleaseLock_Call) Run(run func(ctx context.Context, key string, token string)) *MockLockStore_ReleaseLock_Call { + _c.Call.Run(func(args mock.Arguments) { + var arg0 context.Context + if args[0] != nil { + arg0 = args[0].(context.Context) + } + var arg1 string + if args[1] != nil { + arg1 = args[1].(string) + } + var arg2 string + if args[2] != nil { + arg2 = args[2].(string) + } + run( + arg0, + arg1, + arg2, + ) + }) + return _c +} + +func (_c *MockLockStore_ReleaseLock_Call) Return(b bool, err error) *MockLockStore_ReleaseLock_Call { + _c.Call.Return(b, err) + return _c +} + +func (_c *MockLockStore_ReleaseLock_Call) RunAndReturn(run func(ctx context.Context, key string, token string) (bool, error)) *MockLockStore_ReleaseLock_Call { + _c.Call.Return(run) + return _c +} + +// Set provides a mock function for the type MockLockStore +func (_mock *MockLockStore) Set(ctx context.Context, key string, value []byte, ttl time.Duration) error { + ret := _mock.Called(ctx, key, value, ttl) + + if len(ret) == 0 { + panic("no return value specified for Set") + } + + var r0 error + if returnFunc, ok := ret.Get(0).(func(context.Context, string, []byte, time.Duration) error); ok { + r0 = returnFunc(ctx, key, value, ttl) + } else { + r0 = ret.Error(0) + } + return r0 +} + +// MockLockStore_Set_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Set' +type MockLockStore_Set_Call struct { + *mock.Call +} + +// Set is a helper method to define mock.On call +// - ctx context.Context +// - key string +// - value []byte +// - ttl time.Duration +func (_e *MockLockStore_Expecter) Set(ctx any, key any, value any, ttl any) *MockLockStore_Set_Call { + return &MockLockStore_Set_Call{Call: _e.mock.On("Set", ctx, key, value, ttl)} +} + +func (_c *MockLockStore_Set_Call) Run(run func(ctx context.Context, key string, value []byte, ttl time.Duration)) *MockLockStore_Set_Call { + _c.Call.Run(func(args mock.Arguments) { + var arg0 context.Context + if args[0] != nil { + arg0 = args[0].(context.Context) + } + var arg1 string + if args[1] != nil { + arg1 = args[1].(string) + } + var arg2 []byte + if args[2] != nil { + arg2 = args[2].([]byte) + } + var arg3 time.Duration + if args[3] != nil { + arg3 = args[3].(time.Duration) + } + run( + arg0, + arg1, + arg2, + arg3, + ) + }) + return _c +} + +func (_c *MockLockStore_Set_Call) Return(err error) *MockLockStore_Set_Call { + _c.Call.Return(err) + return _c +} + +func (_c *MockLockStore_Set_Call) RunAndReturn(run func(ctx context.Context, key string, value []byte, ttl time.Duration) error) *MockLockStore_Set_Call { + _c.Call.Return(run) + return _c +} diff --git a/internal/platform/cache/redis.go b/internal/platform/cache/redis.go new file mode 100644 index 0000000..5759daf --- /dev/null +++ b/internal/platform/cache/redis.go @@ -0,0 +1,139 @@ +package cache + +import ( + "context" + "errors" + "fmt" + "net" + "strconv" + "time" + + "github.com/redis/go-redis/v9" +) + +type RedisConfig struct { + Host string + Port int + Password string + DB int + MaxRetries int + DialTimeout time.Duration + ReadTimeout time.Duration + WriteTimeout time.Duration + PoolSize int +} + +type RedisCache struct { + client *redis.Client +} + +func NewRedis(cfg RedisConfig) (*RedisCache, error) { + client := redis.NewClient(newClientOptions(cfg)) + + ctx, cancel := context.WithTimeout(context.Background(), cfg.DialTimeout) + defer cancel() + + if err := client.Ping(ctx).Err(); err != nil { + _ = client.Close() + + return nil, fmt.Errorf("ping redis: %w", err) + } + + return &RedisCache{client: client}, nil +} + +func newClientOptions(cfg RedisConfig) *redis.Options { + return &redis.Options{ + Addr: net.JoinHostPort(cfg.Host, strconv.Itoa(cfg.Port)), + Password: cfg.Password, + DB: cfg.DB, + MaxRetries: cfg.MaxRetries, + DialTimeout: cfg.DialTimeout, + ReadTimeout: cfg.ReadTimeout, + WriteTimeout: cfg.WriteTimeout, + PoolSize: cfg.PoolSize, + } +} + +func (r *RedisCache) Get(ctx context.Context, key string) ([]byte, error) { + value, err := r.client.Get(ctx, key).Bytes() + if errors.Is(err, redis.Nil) { + return nil, ErrCacheMiss + } + + if err != nil { + return nil, fmt.Errorf("redis get %q: %w", key, err) + } + + return value, nil +} + +func (r *RedisCache) Set(ctx context.Context, key string, value []byte, ttl time.Duration) error { + if err := r.client.Set(ctx, key, value, ttl).Err(); err != nil { + return fmt.Errorf("redis set %q: %w", key, err) + } + + return nil +} + +func (r *RedisCache) Delete(ctx context.Context, keys ...string) error { + if len(keys) == 0 { + return nil + } + + if err := r.client.Del(ctx, keys...).Err(); err != nil { + return fmt.Errorf("redis delete: %w", err) + } + + return nil +} + +var releaseLockScript = redis.NewScript(` +if redis.call("GET", KEYS[1]) == ARGV[1] then + return redis.call("DEL", KEYS[1]) +end +return 0 +`) + +func (r *RedisCache) AcquireLock(ctx context.Context, key, token string, ttl time.Duration) (bool, error) { + acquired, err := r.client.SetNX(ctx, key, token, ttl).Result() + if err != nil { + return false, fmt.Errorf("redis acquire lock %q: %w", key, err) + } + + return acquired, nil +} + +func (r *RedisCache) ReleaseLock(ctx context.Context, key, token string) (bool, error) { + deleted, err := releaseLockScript.Run(ctx, r.client, []string{key}, token).Int64() + if err != nil { + return false, fmt.Errorf("redis release lock %q: %w", key, err) + } + + return deleted > 0, nil +} + +func (r *RedisCache) LockHeld(ctx context.Context, key string) (bool, error) { + exists, err := r.client.Exists(ctx, key).Result() + if err != nil { + return false, fmt.Errorf("redis check lock %q: %w", key, err) + } + + return exists > 0, nil +} + +func (r *RedisCache) Ping(ctx context.Context) error { + if err := r.client.Ping(ctx).Err(); err != nil { + return fmt.Errorf("redis ping: %w", err) + } + + return nil +} + +func (r *RedisCache) Close() error { + if err := r.client.Close(); err != nil { + return fmt.Errorf("redis close: %w", err) + } + + return nil +} diff --git a/internal/platform/cache/redis_client_test.go b/internal/platform/cache/redis_client_test.go new file mode 100644 index 0000000..f33d4ba --- /dev/null +++ b/internal/platform/cache/redis_client_test.go @@ -0,0 +1,32 @@ +package cache + +import ( + "testing" + "time" + + "github.com/redis/go-redis/v9" + "github.com/stretchr/testify/require" +) + +func TestNewClientOptionsAppliesTimeoutsAndRetries(t *testing.T) { + t.Parallel() + + client := redis.NewClient(newClientOptions(RedisConfig{ + Host: "localhost", + Port: 6379, + MaxRetries: -1, + DialTimeout: 300 * time.Millisecond, + ReadTimeout: 200 * time.Millisecond, + WriteTimeout: 200 * time.Millisecond, + PoolSize: 5, + })) + + defer func() { _ = client.Close() }() + + opts := client.Options() + require.Equal(t, 0, opts.MaxRetries, "go-redis: -1 disables retries, 0 would restore the default of 3") + require.Equal(t, 300*time.Millisecond, opts.DialTimeout) + require.Equal(t, 200*time.Millisecond, opts.ReadTimeout) + require.Equal(t, 200*time.Millisecond, opts.WriteTimeout) + require.Equal(t, 5, opts.PoolSize) +} diff --git a/internal/platform/instanceid/instanceid.go b/internal/platform/instanceid/instanceid.go new file mode 100644 index 0000000..679398e --- /dev/null +++ b/internal/platform/instanceid/instanceid.go @@ -0,0 +1,18 @@ +// Package instanceid returns the stable identifier this process reports in +// X-Instance-Id and in the telemetry resource. INSTANCE_ID wins; otherwise the +// container hostname (short container id) is used. +package instanceid + +import "os" + +func FromEnvOrHostname() string { + if id := os.Getenv("INSTANCE_ID"); id != "" { + return id + } + + if host, err := os.Hostname(); err == nil && host != "" { + return host + } + + return "unknown" +} diff --git a/internal/platform/objectstore/objectstore.go b/internal/platform/objectstore/objectstore.go new file mode 100644 index 0000000..7a75726 --- /dev/null +++ b/internal/platform/objectstore/objectstore.go @@ -0,0 +1,34 @@ +// Package objectstore defines the S3-compatible port used by attachments. +// Metadata never belongs here: PostgreSQL is the source of truth, this package +// only moves bytes and exposes object timestamps for the orphan sweeper. +package objectstore + +import ( + "context" + "io" + "time" +) + +// Object is the provider-neutral view of one stored object. +type Object struct { + Key string + Size int64 + ContentType string + LastModified time.Time + Metadata map[string]string +} + +// Store is implemented by S3-compatible backends. Put requires a seekable body +// because AWS SigV4 may need to rewind the payload; the proxy upload path always +// passes an *os.File. +type Store interface { + // Ping verifies that the bucket is reachable and the credentials are valid. + Ping(ctx context.Context) error + Put(ctx context.Context, key string, body io.ReadSeeker, size int64, contentType string, metadata map[string]string) error + Open(ctx context.Context, key string) (io.ReadCloser, Object, error) + Head(ctx context.Context, key string) (Object, error) + Copy(ctx context.Context, src, dst, contentType string, metadata map[string]string) error + Delete(ctx context.Context, key string) error + List(ctx context.Context, prefix string) ([]Object, error) + PresignPut(ctx context.Context, key string, size int64, ttl time.Duration) (string, time.Time, error) +} diff --git a/internal/platform/objectstore/s3.go b/internal/platform/objectstore/s3.go new file mode 100644 index 0000000..f21c31c --- /dev/null +++ b/internal/platform/objectstore/s3.go @@ -0,0 +1,305 @@ +package objectstore + +import ( + "context" + "errors" + "fmt" + "io" + "net" + "net/http" + "strings" + "time" + + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/credentials" + "github.com/aws/aws-sdk-go-v2/service/s3" + "github.com/aws/aws-sdk-go-v2/service/s3/types" + "github.com/aws/smithy-go" + + "mtusi-messenger/internal/domain" +) + +// Config is the S3 connection subset. Limits belong to the attachment service. +type Config struct { + Endpoint string + PublicEndpoint string + Region string + Bucket string + AccessKeyID string + SecretAccessKey string + UsePathStyle bool + Timeout time.Duration +} + +// S3 is an object store backed by an S3-compatible server (SeaweedFS in the +// lab stand, MinIO/AWS in other deployments). +type S3 struct { + bucket string + internal *s3.Client + public *s3.Client + timeout time.Duration +} + +var _ Store = (*S3)(nil) + +func New(cfg Config) (*S3, error) { + if cfg.Endpoint == "" || cfg.Region == "" || cfg.Bucket == "" { + return nil, errors.New("object store: endpoint, region and bucket are required") + } + + if cfg.AccessKeyID == "" || cfg.SecretAccessKey == "" { + return nil, errors.New("object store: access key id and secret access key are required") + } + + if cfg.PublicEndpoint == "" { + cfg.PublicEndpoint = cfg.Endpoint + } + + httpClient := &http.Client{ + Transport: &http.Transport{ + Proxy: http.ProxyFromEnvironment, + DialContext: (&net.Dialer{ + Timeout: 3 * time.Second, + KeepAlive: 30 * time.Second, + }).DialContext, + TLSHandshakeTimeout: 3 * time.Second, + ResponseHeaderTimeout: 15 * time.Second, + MaxIdleConnsPerHost: 16, + IdleConnTimeout: 90 * time.Second, + }, + // Downloads stream through the response body; an overall client + // timeout would abort them. + } + + newClient := func(endpoint string) *s3.Client { + return s3.New(s3.Options{ + Region: cfg.Region, + BaseEndpoint: aws.String(endpoint), + UsePathStyle: cfg.UsePathStyle, + Credentials: credentials.NewStaticCredentialsProvider(cfg.AccessKeyID, cfg.SecretAccessKey, ""), + HTTPClient: httpClient, + }) + } + + st := &S3{ + bucket: cfg.Bucket, + internal: newClient(cfg.Endpoint), + public: newClient(cfg.PublicEndpoint), + timeout: cfg.Timeout, + } + + return st, nil +} + +func (s *S3) Ping(ctx context.Context) error { + // HeadBucket needs bucket-level permissions that the application identity + // intentionally does not have. A HeadObject on a sentinel staging key is + // enough to prove connectivity and the object-level credentials; a missing + // sentinel is the expected healthy result. + _, err := s.Head(ctx, "staging/.health/ping") + if err == nil || errors.Is(err, domain.ErrNotFound) { + return nil + } + + return err +} + +func (s *S3) Put( + ctx context.Context, + key string, + body io.ReadSeeker, + size int64, + contentType string, + metadata map[string]string, +) error { + ctx, cancel := s.operationContext(ctx) + defer cancel() + + _, err := s.internal.PutObject(ctx, &s3.PutObjectInput{ + Bucket: aws.String(s.bucket), + Key: aws.String(key), + Body: body, + ContentLength: aws.Int64(size), + ContentType: aws.String(contentType), + Metadata: metadata, + }) + if err != nil { + return mapObjectError("put object", key, err) + } + + return nil +} + +func (s *S3) Open(ctx context.Context, key string) (io.ReadCloser, Object, error) { + output, err := s.internal.GetObject(ctx, &s3.GetObjectInput{ + Bucket: aws.String(s.bucket), + Key: aws.String(key), + }) + if err != nil { + return nil, Object{}, mapObjectError("open object", key, err) + } + + object := Object{ + Key: key, + Size: aws.ToInt64(output.ContentLength), + ContentType: aws.ToString(output.ContentType), + LastModified: aws.ToTime(output.LastModified), + Metadata: output.Metadata, + } + + return output.Body, object, nil +} + +func (s *S3) Head(ctx context.Context, key string) (Object, error) { + output, err := s.internal.HeadObject(ctx, &s3.HeadObjectInput{ + Bucket: aws.String(s.bucket), + Key: aws.String(key), + }) + if err != nil { + return Object{}, mapObjectError("head object", key, err) + } + + return Object{ + Key: key, + Size: aws.ToInt64(output.ContentLength), + ContentType: aws.ToString(output.ContentType), + LastModified: aws.ToTime(output.LastModified), + Metadata: output.Metadata, + }, nil +} + +func (s *S3) Copy(ctx context.Context, src, dst, contentType string, metadata map[string]string) error { + ctx, cancel := s.operationContext(ctx) + defer cancel() + + _, err := s.internal.CopyObject(ctx, &s3.CopyObjectInput{ + Bucket: aws.String(s.bucket), + Key: aws.String(dst), + CopySource: aws.String(s.bucket + "/" + src), + MetadataDirective: types.MetadataDirectiveReplace, + ContentType: aws.String(contentType), + Metadata: metadata, + }) + if err != nil { + return mapObjectError("copy object", src+" -> "+dst, err) + } + + return nil +} + +func (s *S3) Delete(ctx context.Context, key string) error { + ctx, cancel := s.operationContext(ctx) + defer cancel() + + _, err := s.internal.DeleteObject(ctx, &s3.DeleteObjectInput{ + Bucket: aws.String(s.bucket), + Key: aws.String(key), + }) + if err != nil { + return mapObjectError("delete object", key, err) + } + + return nil +} + +func (s *S3) List(ctx context.Context, prefix string) ([]Object, error) { + ctx, cancel := s.operationContext(ctx) + defer cancel() + + var ( + objects []Object + token *string + ) + + for { + output, err := s.internal.ListObjectsV2(ctx, &s3.ListObjectsV2Input{ + Bucket: aws.String(s.bucket), + Prefix: aws.String(prefix), + ContinuationToken: token, + }) + if err != nil { + return nil, mapObjectError("list objects", prefix, err) + } + + for _, item := range output.Contents { + objects = append(objects, Object{ + Key: aws.ToString(item.Key), + Size: aws.ToInt64(item.Size), + LastModified: aws.ToTime(item.LastModified), + }) + } + + if !aws.ToBool(output.IsTruncated) { + break + } + + token = output.NextContinuationToken + if token == nil || *token == "" { + break + } + } + + return objects, nil +} + +// PresignPut signs the bucket, key, host and exact Content-Length. The size is +// therefore enforced by S3 at write time: a client that uploads a different +// number of bytes gets 403 SignatureDoesNotMatch. Content-Type and checksums +// are not signed (SeaweedFS does not validate checksums); completion verifies +// the actual bytes and their structure. +func (s *S3) PresignPut( + ctx context.Context, + key string, + size int64, + ttl time.Duration, +) (string, time.Time, error) { + expiresAt := time.Now().UTC().Add(ttl) + + presigned, err := s3.NewPresignClient(s.public).PresignPutObject( + ctx, + &s3.PutObjectInput{ + Bucket: aws.String(s.bucket), + Key: aws.String(key), + ContentLength: aws.Int64(size), + }, + func(options *s3.PresignOptions) { + options.Expires = ttl + }, + ) + if err != nil { + return "", time.Time{}, mapObjectError("presign put", key, err) + } + + return presigned.URL, expiresAt, nil +} + +func (s *S3) operationContext(ctx context.Context) (context.Context, context.CancelFunc) { + if s.timeout <= 0 { + return context.WithCancel(ctx) + } + + return context.WithTimeout(ctx, s.timeout) +} + +func mapObjectError(operation, subject string, err error) error { + var apiErr smithy.APIError + + if errors.As(err, &apiErr) { + switch apiErr.ErrorCode() { + case "NoSuchBucket": + return fmt.Errorf("%w: %s %q: %w", domain.ErrUnavailable, operation, subject, err) + case "NotFound", "NoSuchKey": + return fmt.Errorf("%s %q: %w", operation, subject, domain.ErrNotFound) + } + } + + if errors.Is(err, context.Canceled) { + return fmt.Errorf("%s %q: %w", operation, subject, err) + } + + if strings.Contains(strings.ToLower(err.Error()), "no such key") { + return fmt.Errorf("%s %q: %w", operation, subject, domain.ErrNotFound) + } + + return fmt.Errorf("%w: %s %q: %w", domain.ErrUnavailable, operation, subject, err) +} diff --git a/internal/platform/objectstore/s3_test.go b/internal/platform/objectstore/s3_test.go new file mode 100644 index 0000000..3383a26 --- /dev/null +++ b/internal/platform/objectstore/s3_test.go @@ -0,0 +1,26 @@ +package objectstore + +import ( + "testing" + + "github.com/aws/smithy-go" + "github.com/stretchr/testify/require" + + "mtusi-messenger/internal/domain" +) + +func TestMapObjectErrorBucketIsUnavailable(t *testing.T) { + err := mapObjectError("put object", "key", &smithy.GenericAPIError{ + Code: "NoSuchBucket", + Message: "bucket is missing", + }) + require.ErrorIs(t, err, domain.ErrUnavailable) +} + +func TestMapObjectErrorMissingKeyIsNotFound(t *testing.T) { + err := mapObjectError("open object", "key", &smithy.GenericAPIError{ + Code: "NoSuchKey", + Message: "object is missing", + }) + require.ErrorIs(t, err, domain.ErrNotFound) +} diff --git a/internal/platform/password/password.go b/internal/platform/password/password.go new file mode 100644 index 0000000..acc6237 --- /dev/null +++ b/internal/platform/password/password.go @@ -0,0 +1,52 @@ +package password + +import ( + "crypto/rand" + "crypto/subtle" + "encoding/base64" + "strings" + + "golang.org/x/crypto/argon2" +) + +const ( + argonTime = 1 + argonMemory = 64 * 1024 + argonThreads = 4 + argonKeyLen = 32 + argonSaltLen = 16 +) + +func Hash(plain string) (string, error) { + salt := make([]byte, argonSaltLen) + if _, err := rand.Read(salt); err != nil { + return "", err + } + + hash := argon2.IDKey([]byte(plain), salt, argonTime, argonMemory, argonThreads, argonKeyLen) + + return "argon2id$" + + base64.RawStdEncoding.EncodeToString(salt) + "$" + + base64.RawStdEncoding.EncodeToString(hash), nil +} + +func Verify(plain, encoded string) bool { + parts := strings.Split(encoded, "$") + if len(parts) != 3 || parts[0] != "argon2id" { + return false + } + + salt, err := base64.RawStdEncoding.DecodeString(parts[1]) + if err != nil { + return false + } + + expected, err := base64.RawStdEncoding.DecodeString(parts[2]) + if err != nil || len(salt) != argonSaltLen || len(expected) != argonKeyLen { + return false + } + + actual := argon2.IDKey([]byte(plain), salt, argonTime, argonMemory, argonThreads, argonKeyLen) + + return subtle.ConstantTimeCompare(actual, expected) == 1 +} diff --git a/internal/platform/password/password_test.go b/internal/platform/password/password_test.go new file mode 100644 index 0000000..1fe449b --- /dev/null +++ b/internal/platform/password/password_test.go @@ -0,0 +1,33 @@ +package password_test + +import ( + "strings" + "testing" + + "github.com/stretchr/testify/require" + + "mtusi-messenger/internal/platform/password" +) + +func TestHashVerifyRoundTrip(t *testing.T) { + encoded, err := password.Hash("very-secret-password") + require.NoError(t, err) + require.True(t, password.Verify("very-secret-password", encoded)) + require.False(t, password.Verify("wrong-password-value", encoded)) +} + +func TestHashIsSalted(t *testing.T) { + first, err := password.Hash("very-secret-password") + require.NoError(t, err) + + second, err := password.Hash("very-secret-password") + require.NoError(t, err) + + require.NotEqual(t, first, second) +} + +func TestVerifyRejectsMalformedHash(t *testing.T) { + require.False(t, password.Verify("very-secret-password", "")) + require.False(t, password.Verify("very-secret-password", "plain-text")) + require.False(t, password.Verify("very-secret-password", strings.Repeat("x", 64))) +} diff --git a/internal/platform/token/token.go b/internal/platform/token/token.go new file mode 100644 index 0000000..b5d2351 --- /dev/null +++ b/internal/platform/token/token.go @@ -0,0 +1,40 @@ +package token + +import ( + "crypto/rand" + "crypto/sha256" + "encoding/base64" + "errors" +) + +const size = 32 + +var ErrInvalid = errors.New("invalid token") + +type Token struct{} + +func New() Token { + return Token{} +} + +func (Token) Generate() (string, []byte, error) { + raw := make([]byte, size) + if _, err := rand.Read(raw); err != nil { + return "", nil, err + } + + sum := sha256.Sum256(raw) + + return base64.RawURLEncoding.EncodeToString(raw), sum[:], nil +} + +func (Token) Hash(raw string) ([]byte, error) { + decoded, err := base64.RawURLEncoding.DecodeString(raw) + if err != nil || len(decoded) != size { + return nil, ErrInvalid + } + + sum := sha256.Sum256(decoded) + + return sum[:], nil +} diff --git a/internal/platform/token/token_test.go b/internal/platform/token/token_test.go new file mode 100644 index 0000000..54dfc2e --- /dev/null +++ b/internal/platform/token/token_test.go @@ -0,0 +1,44 @@ +package token_test + +import ( + "crypto/sha256" + "testing" + + "github.com/stretchr/testify/require" + + "mtusi-messenger/internal/platform/token" +) + +func TestGenerateProducesUniqueOpaqueTokens(t *testing.T) { + tokens := token.New() + + first, firstHash, err := tokens.Generate() + require.NoError(t, err) + require.NotEmpty(t, first) + require.Len(t, firstHash, sha256.Size) + + second, secondHash, err := tokens.Generate() + require.NoError(t, err) + require.NotEqual(t, first, second) + require.NotEqual(t, firstHash, secondHash) +} + +func TestHashMatchesGeneratedHash(t *testing.T) { + tokens := token.New() + + raw, hash, err := tokens.Generate() + require.NoError(t, err) + + actual, err := tokens.Hash(raw) + require.NoError(t, err) + require.Equal(t, hash, actual) +} + +func TestHashRejectsMalformed(t *testing.T) { + tokens := token.New() + + for _, raw := range []string{"", "not-base64!", "c2hvcnQ"} { + _, err := tokens.Hash(raw) + require.ErrorIs(t, err, token.ErrInvalid, raw) + } +} diff --git a/internal/service/attachment/mocks/LockStore.go b/internal/service/attachment/mocks/LockStore.go new file mode 100644 index 0000000..52155f3 --- /dev/null +++ b/internal/service/attachment/mocks/LockStore.go @@ -0,0 +1,115 @@ +// Code generated by mockery; DO NOT EDIT. +// github.com/vektra/mockery +// template: testify + +package mocks + +import ( + "context" + + mock "github.com/stretchr/testify/mock" +) + +// NewMockLockStore creates a new instance of MockLockStore. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewMockLockStore(t interface { + mock.TestingT + Cleanup(func()) +}) *MockLockStore { + if helper, ok := t.(interface{ Helper() }); ok { + helper.Helper() + } + + mock := &MockLockStore{} + mock.Mock.Test(t) + + t.Cleanup(func() { + if helper, ok := t.(interface{ Helper() }); ok { + helper.Helper() + } + mock.AssertExpectations(t) + }) + + return mock +} + +// MockLockStore is an autogenerated mock type for the LockStore type +type MockLockStore struct { + mock.Mock +} + +type MockLockStore_Expecter struct { + mock *mock.Mock +} + +func (_m *MockLockStore) EXPECT() *MockLockStore_Expecter { + return &MockLockStore_Expecter{mock: &_m.Mock} +} + +// AcquireSweepLock provides a mock function for the type MockLockStore +func (_mock *MockLockStore) AcquireSweepLock(ctx context.Context) (func(), bool, error) { + ret := _mock.Called(ctx) + + if len(ret) == 0 { + panic("no return value specified for AcquireSweepLock") + } + + var r0 func() + var r1 bool + var r2 error + if returnFunc, ok := ret.Get(0).(func(context.Context) (func(), bool, error)); ok { + return returnFunc(ctx) + } + if returnFunc, ok := ret.Get(0).(func(context.Context) func()); ok { + r0 = returnFunc(ctx) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(func()) + } + } + if returnFunc, ok := ret.Get(1).(func(context.Context) bool); ok { + r1 = returnFunc(ctx) + } else { + r1 = ret.Get(1).(bool) + } + if returnFunc, ok := ret.Get(2).(func(context.Context) error); ok { + r2 = returnFunc(ctx) + } else { + r2 = ret.Error(2) + } + return r0, r1, r2 +} + +// MockLockStore_AcquireSweepLock_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'AcquireSweepLock' +type MockLockStore_AcquireSweepLock_Call struct { + *mock.Call +} + +// AcquireSweepLock is a helper method to define mock.On call +// - ctx context.Context +func (_e *MockLockStore_Expecter) AcquireSweepLock(ctx any) *MockLockStore_AcquireSweepLock_Call { + return &MockLockStore_AcquireSweepLock_Call{Call: _e.mock.On("AcquireSweepLock", ctx)} +} + +func (_c *MockLockStore_AcquireSweepLock_Call) Run(run func(ctx context.Context)) *MockLockStore_AcquireSweepLock_Call { + _c.Call.Run(func(args mock.Arguments) { + var arg0 context.Context + if args[0] != nil { + arg0 = args[0].(context.Context) + } + run( + arg0, + ) + }) + return _c +} + +func (_c *MockLockStore_AcquireSweepLock_Call) Return(release func(), acquired bool, err error) *MockLockStore_AcquireSweepLock_Call { + _c.Call.Return(release, acquired, err) + return _c +} + +func (_c *MockLockStore_AcquireSweepLock_Call) RunAndReturn(run func(ctx context.Context) (func(), bool, error)) *MockLockStore_AcquireSweepLock_Call { + _c.Call.Return(run) + return _c +} diff --git a/internal/service/attachment/mocks/Repository.go b/internal/service/attachment/mocks/Repository.go new file mode 100644 index 0000000..f31bea6 --- /dev/null +++ b/internal/service/attachment/mocks/Repository.go @@ -0,0 +1,804 @@ +// Code generated by mockery; DO NOT EDIT. +// github.com/vektra/mockery +// template: testify + +package mocks + +import ( + "context" + "mtusi-messenger/internal/domain" + + "github.com/google/uuid" + mock "github.com/stretchr/testify/mock" +) + +// NewMockRepository creates a new instance of MockRepository. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewMockRepository(t interface { + mock.TestingT + Cleanup(func()) +}) *MockRepository { + if helper, ok := t.(interface{ Helper() }); ok { + helper.Helper() + } + + mock := &MockRepository{} + mock.Mock.Test(t) + + t.Cleanup(func() { + if helper, ok := t.(interface{ Helper() }); ok { + helper.Helper() + } + mock.AssertExpectations(t) + }) + + return mock +} + +// MockRepository is an autogenerated mock type for the Repository type +type MockRepository struct { + mock.Mock +} + +type MockRepository_Expecter struct { + mock *mock.Mock +} + +func (_m *MockRepository) EXPECT() *MockRepository_Expecter { + return &MockRepository_Expecter{mock: &_m.Mock} +} + +// Admission provides a mock function for the type MockRepository +func (_mock *MockRepository) Admission(ctx context.Context, ownerID uuid.UUID) (int, int, int64, error) { + ret := _mock.Called(ctx, ownerID) + + if len(ret) == 0 { + panic("no return value specified for Admission") + } + + var r0 int + var r1 int + var r2 int64 + var r3 error + if returnFunc, ok := ret.Get(0).(func(context.Context, uuid.UUID) (int, int, int64, error)); ok { + return returnFunc(ctx, ownerID) + } + if returnFunc, ok := ret.Get(0).(func(context.Context, uuid.UUID) int); ok { + r0 = returnFunc(ctx, ownerID) + } else { + r0 = ret.Get(0).(int) + } + if returnFunc, ok := ret.Get(1).(func(context.Context, uuid.UUID) int); ok { + r1 = returnFunc(ctx, ownerID) + } else { + r1 = ret.Get(1).(int) + } + if returnFunc, ok := ret.Get(2).(func(context.Context, uuid.UUID) int64); ok { + r2 = returnFunc(ctx, ownerID) + } else { + r2 = ret.Get(2).(int64) + } + if returnFunc, ok := ret.Get(3).(func(context.Context, uuid.UUID) error); ok { + r3 = returnFunc(ctx, ownerID) + } else { + r3 = ret.Error(3) + } + return r0, r1, r2, r3 +} + +// MockRepository_Admission_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Admission' +type MockRepository_Admission_Call struct { + *mock.Call +} + +// Admission is a helper method to define mock.On call +// - ctx context.Context +// - ownerID uuid.UUID +func (_e *MockRepository_Expecter) Admission(ctx any, ownerID any) *MockRepository_Admission_Call { + return &MockRepository_Admission_Call{Call: _e.mock.On("Admission", ctx, ownerID)} +} + +func (_c *MockRepository_Admission_Call) Run(run func(ctx context.Context, ownerID uuid.UUID)) *MockRepository_Admission_Call { + _c.Call.Run(func(args mock.Arguments) { + var arg0 context.Context + if args[0] != nil { + arg0 = args[0].(context.Context) + } + var arg1 uuid.UUID + if args[1] != nil { + arg1 = args[1].(uuid.UUID) + } + run( + arg0, + arg1, + ) + }) + return _c +} + +func (_c *MockRepository_Admission_Call) Return(userPending int, totalPending int, stagedBytes int64, err error) *MockRepository_Admission_Call { + _c.Call.Return(userPending, totalPending, stagedBytes, err) + return _c +} + +func (_c *MockRepository_Admission_Call) RunAndReturn(run func(ctx context.Context, ownerID uuid.UUID) (int, int, int64, error)) *MockRepository_Admission_Call { + _c.Call.Return(run) + return _c +} + +// CompletePresign provides a mock function for the type MockRepository +func (_mock *MockRepository) CompletePresign(ctx context.Context, ownerID uuid.UUID, attachmentID uuid.UUID, verifiedKey string, finalKey string, pipelineVersion int, maxAttempts int, jobID uuid.UUID) (domain.Attachment, error) { + ret := _mock.Called(ctx, ownerID, attachmentID, verifiedKey, finalKey, pipelineVersion, maxAttempts, jobID) + + if len(ret) == 0 { + panic("no return value specified for CompletePresign") + } + + var r0 domain.Attachment + var r1 error + if returnFunc, ok := ret.Get(0).(func(context.Context, uuid.UUID, uuid.UUID, string, string, int, int, uuid.UUID) (domain.Attachment, error)); ok { + return returnFunc(ctx, ownerID, attachmentID, verifiedKey, finalKey, pipelineVersion, maxAttempts, jobID) + } + if returnFunc, ok := ret.Get(0).(func(context.Context, uuid.UUID, uuid.UUID, string, string, int, int, uuid.UUID) domain.Attachment); ok { + r0 = returnFunc(ctx, ownerID, attachmentID, verifiedKey, finalKey, pipelineVersion, maxAttempts, jobID) + } else { + r0 = ret.Get(0).(domain.Attachment) + } + if returnFunc, ok := ret.Get(1).(func(context.Context, uuid.UUID, uuid.UUID, string, string, int, int, uuid.UUID) error); ok { + r1 = returnFunc(ctx, ownerID, attachmentID, verifiedKey, finalKey, pipelineVersion, maxAttempts, jobID) + } else { + r1 = ret.Error(1) + } + return r0, r1 +} + +// MockRepository_CompletePresign_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'CompletePresign' +type MockRepository_CompletePresign_Call struct { + *mock.Call +} + +// CompletePresign is a helper method to define mock.On call +// - ctx context.Context +// - ownerID uuid.UUID +// - attachmentID uuid.UUID +// - verifiedKey string +// - finalKey string +// - pipelineVersion int +// - maxAttempts int +// - jobID uuid.UUID +func (_e *MockRepository_Expecter) CompletePresign(ctx any, ownerID any, attachmentID any, verifiedKey any, finalKey any, pipelineVersion any, maxAttempts any, jobID any) *MockRepository_CompletePresign_Call { + return &MockRepository_CompletePresign_Call{Call: _e.mock.On("CompletePresign", ctx, ownerID, attachmentID, verifiedKey, finalKey, pipelineVersion, maxAttempts, jobID)} +} + +func (_c *MockRepository_CompletePresign_Call) Run(run func(ctx context.Context, ownerID uuid.UUID, attachmentID uuid.UUID, verifiedKey string, finalKey string, pipelineVersion int, maxAttempts int, jobID uuid.UUID)) *MockRepository_CompletePresign_Call { + _c.Call.Run(func(args mock.Arguments) { + var arg0 context.Context + if args[0] != nil { + arg0 = args[0].(context.Context) + } + var arg1 uuid.UUID + if args[1] != nil { + arg1 = args[1].(uuid.UUID) + } + var arg2 uuid.UUID + if args[2] != nil { + arg2 = args[2].(uuid.UUID) + } + var arg3 string + if args[3] != nil { + arg3 = args[3].(string) + } + var arg4 string + if args[4] != nil { + arg4 = args[4].(string) + } + var arg5 int + if args[5] != nil { + arg5 = args[5].(int) + } + var arg6 int + if args[6] != nil { + arg6 = args[6].(int) + } + var arg7 uuid.UUID + if args[7] != nil { + arg7 = args[7].(uuid.UUID) + } + run( + arg0, + arg1, + arg2, + arg3, + arg4, + arg5, + arg6, + arg7, + ) + }) + return _c +} + +func (_c *MockRepository_CompletePresign_Call) Return(attachment domain.Attachment, err error) *MockRepository_CompletePresign_Call { + _c.Call.Return(attachment, err) + return _c +} + +func (_c *MockRepository_CompletePresign_Call) RunAndReturn(run func(ctx context.Context, ownerID uuid.UUID, attachmentID uuid.UUID, verifiedKey string, finalKey string, pipelineVersion int, maxAttempts int, jobID uuid.UUID) (domain.Attachment, error)) *MockRepository_CompletePresign_Call { + _c.Call.Return(run) + return _c +} + +// CreatePresign provides a mock function for the type MockRepository +func (_mock *MockRepository) CreatePresign(ctx context.Context, draft domain.AttachmentDraft, limits domain.AdmissionLimits) (domain.Attachment, error) { + ret := _mock.Called(ctx, draft, limits) + + if len(ret) == 0 { + panic("no return value specified for CreatePresign") + } + + var r0 domain.Attachment + var r1 error + if returnFunc, ok := ret.Get(0).(func(context.Context, domain.AttachmentDraft, domain.AdmissionLimits) (domain.Attachment, error)); ok { + return returnFunc(ctx, draft, limits) + } + if returnFunc, ok := ret.Get(0).(func(context.Context, domain.AttachmentDraft, domain.AdmissionLimits) domain.Attachment); ok { + r0 = returnFunc(ctx, draft, limits) + } else { + r0 = ret.Get(0).(domain.Attachment) + } + if returnFunc, ok := ret.Get(1).(func(context.Context, domain.AttachmentDraft, domain.AdmissionLimits) error); ok { + r1 = returnFunc(ctx, draft, limits) + } else { + r1 = ret.Error(1) + } + return r0, r1 +} + +// MockRepository_CreatePresign_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'CreatePresign' +type MockRepository_CreatePresign_Call struct { + *mock.Call +} + +// CreatePresign is a helper method to define mock.On call +// - ctx context.Context +// - draft domain.AttachmentDraft +// - limits domain.AdmissionLimits +func (_e *MockRepository_Expecter) CreatePresign(ctx any, draft any, limits any) *MockRepository_CreatePresign_Call { + return &MockRepository_CreatePresign_Call{Call: _e.mock.On("CreatePresign", ctx, draft, limits)} +} + +func (_c *MockRepository_CreatePresign_Call) Run(run func(ctx context.Context, draft domain.AttachmentDraft, limits domain.AdmissionLimits)) *MockRepository_CreatePresign_Call { + _c.Call.Run(func(args mock.Arguments) { + var arg0 context.Context + if args[0] != nil { + arg0 = args[0].(context.Context) + } + var arg1 domain.AttachmentDraft + if args[1] != nil { + arg1 = args[1].(domain.AttachmentDraft) + } + var arg2 domain.AdmissionLimits + if args[2] != nil { + arg2 = args[2].(domain.AdmissionLimits) + } + run( + arg0, + arg1, + arg2, + ) + }) + return _c +} + +func (_c *MockRepository_CreatePresign_Call) Return(attachment domain.Attachment, err error) *MockRepository_CreatePresign_Call { + _c.Call.Return(attachment, err) + return _c +} + +func (_c *MockRepository_CreatePresign_Call) RunAndReturn(run func(ctx context.Context, draft domain.AttachmentDraft, limits domain.AdmissionLimits) (domain.Attachment, error)) *MockRepository_CreatePresign_Call { + _c.Call.Return(run) + return _c +} + +// CreateQueued provides a mock function for the type MockRepository +func (_mock *MockRepository) CreateQueued(ctx context.Context, draft domain.AttachmentDraft, job domain.Job, limits domain.AdmissionLimits) (domain.Attachment, error) { + ret := _mock.Called(ctx, draft, job, limits) + + if len(ret) == 0 { + panic("no return value specified for CreateQueued") + } + + var r0 domain.Attachment + var r1 error + if returnFunc, ok := ret.Get(0).(func(context.Context, domain.AttachmentDraft, domain.Job, domain.AdmissionLimits) (domain.Attachment, error)); ok { + return returnFunc(ctx, draft, job, limits) + } + if returnFunc, ok := ret.Get(0).(func(context.Context, domain.AttachmentDraft, domain.Job, domain.AdmissionLimits) domain.Attachment); ok { + r0 = returnFunc(ctx, draft, job, limits) + } else { + r0 = ret.Get(0).(domain.Attachment) + } + if returnFunc, ok := ret.Get(1).(func(context.Context, domain.AttachmentDraft, domain.Job, domain.AdmissionLimits) error); ok { + r1 = returnFunc(ctx, draft, job, limits) + } else { + r1 = ret.Error(1) + } + return r0, r1 +} + +// MockRepository_CreateQueued_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'CreateQueued' +type MockRepository_CreateQueued_Call struct { + *mock.Call +} + +// CreateQueued is a helper method to define mock.On call +// - ctx context.Context +// - draft domain.AttachmentDraft +// - job domain.Job +// - limits domain.AdmissionLimits +func (_e *MockRepository_Expecter) CreateQueued(ctx any, draft any, job any, limits any) *MockRepository_CreateQueued_Call { + return &MockRepository_CreateQueued_Call{Call: _e.mock.On("CreateQueued", ctx, draft, job, limits)} +} + +func (_c *MockRepository_CreateQueued_Call) Run(run func(ctx context.Context, draft domain.AttachmentDraft, job domain.Job, limits domain.AdmissionLimits)) *MockRepository_CreateQueued_Call { + _c.Call.Run(func(args mock.Arguments) { + var arg0 context.Context + if args[0] != nil { + arg0 = args[0].(context.Context) + } + var arg1 domain.AttachmentDraft + if args[1] != nil { + arg1 = args[1].(domain.AttachmentDraft) + } + var arg2 domain.Job + if args[2] != nil { + arg2 = args[2].(domain.Job) + } + var arg3 domain.AdmissionLimits + if args[3] != nil { + arg3 = args[3].(domain.AdmissionLimits) + } + run( + arg0, + arg1, + arg2, + arg3, + ) + }) + return _c +} + +func (_c *MockRepository_CreateQueued_Call) Return(attachment domain.Attachment, err error) *MockRepository_CreateQueued_Call { + _c.Call.Return(attachment, err) + return _c +} + +func (_c *MockRepository_CreateQueued_Call) RunAndReturn(run func(ctx context.Context, draft domain.AttachmentDraft, job domain.Job, limits domain.AdmissionLimits) (domain.Attachment, error)) *MockRepository_CreateQueued_Call { + _c.Call.Return(run) + return _c +} + +// DeletePending provides a mock function for the type MockRepository +func (_mock *MockRepository) DeletePending(ctx context.Context, id uuid.UUID) error { + ret := _mock.Called(ctx, id) + + if len(ret) == 0 { + panic("no return value specified for DeletePending") + } + + var r0 error + if returnFunc, ok := ret.Get(0).(func(context.Context, uuid.UUID) error); ok { + r0 = returnFunc(ctx, id) + } else { + r0 = ret.Error(0) + } + return r0 +} + +// MockRepository_DeletePending_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'DeletePending' +type MockRepository_DeletePending_Call struct { + *mock.Call +} + +// DeletePending is a helper method to define mock.On call +// - ctx context.Context +// - id uuid.UUID +func (_e *MockRepository_Expecter) DeletePending(ctx any, id any) *MockRepository_DeletePending_Call { + return &MockRepository_DeletePending_Call{Call: _e.mock.On("DeletePending", ctx, id)} +} + +func (_c *MockRepository_DeletePending_Call) Run(run func(ctx context.Context, id uuid.UUID)) *MockRepository_DeletePending_Call { + _c.Call.Run(func(args mock.Arguments) { + var arg0 context.Context + if args[0] != nil { + arg0 = args[0].(context.Context) + } + var arg1 uuid.UUID + if args[1] != nil { + arg1 = args[1].(uuid.UUID) + } + run( + arg0, + arg1, + ) + }) + return _c +} + +func (_c *MockRepository_DeletePending_Call) Return(err error) *MockRepository_DeletePending_Call { + _c.Call.Return(err) + return _c +} + +func (_c *MockRepository_DeletePending_Call) RunAndReturn(run func(ctx context.Context, id uuid.UUID) error) *MockRepository_DeletePending_Call { + _c.Call.Return(run) + return _c +} + +// GetForMember provides a mock function for the type MockRepository +func (_mock *MockRepository) GetForMember(ctx context.Context, userID uuid.UUID, id uuid.UUID) (domain.Attachment, error) { + ret := _mock.Called(ctx, userID, id) + + if len(ret) == 0 { + panic("no return value specified for GetForMember") + } + + var r0 domain.Attachment + var r1 error + if returnFunc, ok := ret.Get(0).(func(context.Context, uuid.UUID, uuid.UUID) (domain.Attachment, error)); ok { + return returnFunc(ctx, userID, id) + } + if returnFunc, ok := ret.Get(0).(func(context.Context, uuid.UUID, uuid.UUID) domain.Attachment); ok { + r0 = returnFunc(ctx, userID, id) + } else { + r0 = ret.Get(0).(domain.Attachment) + } + if returnFunc, ok := ret.Get(1).(func(context.Context, uuid.UUID, uuid.UUID) error); ok { + r1 = returnFunc(ctx, userID, id) + } else { + r1 = ret.Error(1) + } + return r0, r1 +} + +// MockRepository_GetForMember_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetForMember' +type MockRepository_GetForMember_Call struct { + *mock.Call +} + +// GetForMember is a helper method to define mock.On call +// - ctx context.Context +// - userID uuid.UUID +// - id uuid.UUID +func (_e *MockRepository_Expecter) GetForMember(ctx any, userID any, id any) *MockRepository_GetForMember_Call { + return &MockRepository_GetForMember_Call{Call: _e.mock.On("GetForMember", ctx, userID, id)} +} + +func (_c *MockRepository_GetForMember_Call) Run(run func(ctx context.Context, userID uuid.UUID, id uuid.UUID)) *MockRepository_GetForMember_Call { + _c.Call.Run(func(args mock.Arguments) { + var arg0 context.Context + if args[0] != nil { + arg0 = args[0].(context.Context) + } + var arg1 uuid.UUID + if args[1] != nil { + arg1 = args[1].(uuid.UUID) + } + var arg2 uuid.UUID + if args[2] != nil { + arg2 = args[2].(uuid.UUID) + } + run( + arg0, + arg1, + arg2, + ) + }) + return _c +} + +func (_c *MockRepository_GetForMember_Call) Return(attachment domain.Attachment, err error) *MockRepository_GetForMember_Call { + _c.Call.Return(attachment, err) + return _c +} + +func (_c *MockRepository_GetForMember_Call) RunAndReturn(run func(ctx context.Context, userID uuid.UUID, id uuid.UUID) (domain.Attachment, error)) *MockRepository_GetForMember_Call { + _c.Call.Return(run) + return _c +} + +// GetForOwner provides a mock function for the type MockRepository +func (_mock *MockRepository) GetForOwner(ctx context.Context, ownerID uuid.UUID, id uuid.UUID) (domain.Attachment, error) { + ret := _mock.Called(ctx, ownerID, id) + + if len(ret) == 0 { + panic("no return value specified for GetForOwner") + } + + var r0 domain.Attachment + var r1 error + if returnFunc, ok := ret.Get(0).(func(context.Context, uuid.UUID, uuid.UUID) (domain.Attachment, error)); ok { + return returnFunc(ctx, ownerID, id) + } + if returnFunc, ok := ret.Get(0).(func(context.Context, uuid.UUID, uuid.UUID) domain.Attachment); ok { + r0 = returnFunc(ctx, ownerID, id) + } else { + r0 = ret.Get(0).(domain.Attachment) + } + if returnFunc, ok := ret.Get(1).(func(context.Context, uuid.UUID, uuid.UUID) error); ok { + r1 = returnFunc(ctx, ownerID, id) + } else { + r1 = ret.Error(1) + } + return r0, r1 +} + +// MockRepository_GetForOwner_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetForOwner' +type MockRepository_GetForOwner_Call struct { + *mock.Call +} + +// GetForOwner is a helper method to define mock.On call +// - ctx context.Context +// - ownerID uuid.UUID +// - id uuid.UUID +func (_e *MockRepository_Expecter) GetForOwner(ctx any, ownerID any, id any) *MockRepository_GetForOwner_Call { + return &MockRepository_GetForOwner_Call{Call: _e.mock.On("GetForOwner", ctx, ownerID, id)} +} + +func (_c *MockRepository_GetForOwner_Call) Run(run func(ctx context.Context, ownerID uuid.UUID, id uuid.UUID)) *MockRepository_GetForOwner_Call { + _c.Call.Run(func(args mock.Arguments) { + var arg0 context.Context + if args[0] != nil { + arg0 = args[0].(context.Context) + } + var arg1 uuid.UUID + if args[1] != nil { + arg1 = args[1].(uuid.UUID) + } + var arg2 uuid.UUID + if args[2] != nil { + arg2 = args[2].(uuid.UUID) + } + run( + arg0, + arg1, + arg2, + ) + }) + return _c +} + +func (_c *MockRepository_GetForOwner_Call) Return(attachment domain.Attachment, err error) *MockRepository_GetForOwner_Call { + _c.Call.Return(attachment, err) + return _c +} + +func (_c *MockRepository_GetForOwner_Call) RunAndReturn(run func(ctx context.Context, ownerID uuid.UUID, id uuid.UUID) (domain.Attachment, error)) *MockRepository_GetForOwner_Call { + _c.Call.Return(run) + return _c +} + +// GetVariant provides a mock function for the type MockRepository +func (_mock *MockRepository) GetVariant(ctx context.Context, attachmentID uuid.UUID, pipelineVersion int, name domain.VariantName) (domain.Variant, error) { + ret := _mock.Called(ctx, attachmentID, pipelineVersion, name) + + if len(ret) == 0 { + panic("no return value specified for GetVariant") + } + + var r0 domain.Variant + var r1 error + if returnFunc, ok := ret.Get(0).(func(context.Context, uuid.UUID, int, domain.VariantName) (domain.Variant, error)); ok { + return returnFunc(ctx, attachmentID, pipelineVersion, name) + } + if returnFunc, ok := ret.Get(0).(func(context.Context, uuid.UUID, int, domain.VariantName) domain.Variant); ok { + r0 = returnFunc(ctx, attachmentID, pipelineVersion, name) + } else { + r0 = ret.Get(0).(domain.Variant) + } + if returnFunc, ok := ret.Get(1).(func(context.Context, uuid.UUID, int, domain.VariantName) error); ok { + r1 = returnFunc(ctx, attachmentID, pipelineVersion, name) + } else { + r1 = ret.Error(1) + } + return r0, r1 +} + +// MockRepository_GetVariant_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetVariant' +type MockRepository_GetVariant_Call struct { + *mock.Call +} + +// GetVariant is a helper method to define mock.On call +// - ctx context.Context +// - attachmentID uuid.UUID +// - pipelineVersion int +// - name domain.VariantName +func (_e *MockRepository_Expecter) GetVariant(ctx any, attachmentID any, pipelineVersion any, name any) *MockRepository_GetVariant_Call { + return &MockRepository_GetVariant_Call{Call: _e.mock.On("GetVariant", ctx, attachmentID, pipelineVersion, name)} +} + +func (_c *MockRepository_GetVariant_Call) Run(run func(ctx context.Context, attachmentID uuid.UUID, pipelineVersion int, name domain.VariantName)) *MockRepository_GetVariant_Call { + _c.Call.Run(func(args mock.Arguments) { + var arg0 context.Context + if args[0] != nil { + arg0 = args[0].(context.Context) + } + var arg1 uuid.UUID + if args[1] != nil { + arg1 = args[1].(uuid.UUID) + } + var arg2 int + if args[2] != nil { + arg2 = args[2].(int) + } + var arg3 domain.VariantName + if args[3] != nil { + arg3 = args[3].(domain.VariantName) + } + run( + arg0, + arg1, + arg2, + arg3, + ) + }) + return _c +} + +func (_c *MockRepository_GetVariant_Call) Return(variant domain.Variant, err error) *MockRepository_GetVariant_Call { + _c.Call.Return(variant, err) + return _c +} + +func (_c *MockRepository_GetVariant_Call) RunAndReturn(run func(ctx context.Context, attachmentID uuid.UUID, pipelineVersion int, name domain.VariantName) (domain.Variant, error)) *MockRepository_GetVariant_Call { + _c.Call.Return(run) + return _c +} + +// IsChatMember provides a mock function for the type MockRepository +func (_mock *MockRepository) IsChatMember(ctx context.Context, chatID uuid.UUID, userID uuid.UUID) (bool, error) { + ret := _mock.Called(ctx, chatID, userID) + + if len(ret) == 0 { + panic("no return value specified for IsChatMember") + } + + var r0 bool + var r1 error + if returnFunc, ok := ret.Get(0).(func(context.Context, uuid.UUID, uuid.UUID) (bool, error)); ok { + return returnFunc(ctx, chatID, userID) + } + if returnFunc, ok := ret.Get(0).(func(context.Context, uuid.UUID, uuid.UUID) bool); ok { + r0 = returnFunc(ctx, chatID, userID) + } else { + r0 = ret.Get(0).(bool) + } + if returnFunc, ok := ret.Get(1).(func(context.Context, uuid.UUID, uuid.UUID) error); ok { + r1 = returnFunc(ctx, chatID, userID) + } else { + r1 = ret.Error(1) + } + return r0, r1 +} + +// MockRepository_IsChatMember_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'IsChatMember' +type MockRepository_IsChatMember_Call struct { + *mock.Call +} + +// IsChatMember is a helper method to define mock.On call +// - ctx context.Context +// - chatID uuid.UUID +// - userID uuid.UUID +func (_e *MockRepository_Expecter) IsChatMember(ctx any, chatID any, userID any) *MockRepository_IsChatMember_Call { + return &MockRepository_IsChatMember_Call{Call: _e.mock.On("IsChatMember", ctx, chatID, userID)} +} + +func (_c *MockRepository_IsChatMember_Call) Run(run func(ctx context.Context, chatID uuid.UUID, userID uuid.UUID)) *MockRepository_IsChatMember_Call { + _c.Call.Run(func(args mock.Arguments) { + var arg0 context.Context + if args[0] != nil { + arg0 = args[0].(context.Context) + } + var arg1 uuid.UUID + if args[1] != nil { + arg1 = args[1].(uuid.UUID) + } + var arg2 uuid.UUID + if args[2] != nil { + arg2 = args[2].(uuid.UUID) + } + run( + arg0, + arg1, + arg2, + ) + }) + return _c +} + +func (_c *MockRepository_IsChatMember_Call) Return(b bool, err error) *MockRepository_IsChatMember_Call { + _c.Call.Return(b, err) + return _c +} + +func (_c *MockRepository_IsChatMember_Call) RunAndReturn(run func(ctx context.Context, chatID uuid.UUID, userID uuid.UUID) (bool, error)) *MockRepository_IsChatMember_Call { + _c.Call.Return(run) + return _c +} + +// ListVariants provides a mock function for the type MockRepository +func (_mock *MockRepository) ListVariants(ctx context.Context, attachmentID uuid.UUID, pipelineVersion int) ([]domain.Variant, error) { + ret := _mock.Called(ctx, attachmentID, pipelineVersion) + + if len(ret) == 0 { + panic("no return value specified for ListVariants") + } + + var r0 []domain.Variant + var r1 error + if returnFunc, ok := ret.Get(0).(func(context.Context, uuid.UUID, int) ([]domain.Variant, error)); ok { + return returnFunc(ctx, attachmentID, pipelineVersion) + } + if returnFunc, ok := ret.Get(0).(func(context.Context, uuid.UUID, int) []domain.Variant); ok { + r0 = returnFunc(ctx, attachmentID, pipelineVersion) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]domain.Variant) + } + } + if returnFunc, ok := ret.Get(1).(func(context.Context, uuid.UUID, int) error); ok { + r1 = returnFunc(ctx, attachmentID, pipelineVersion) + } else { + r1 = ret.Error(1) + } + return r0, r1 +} + +// MockRepository_ListVariants_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ListVariants' +type MockRepository_ListVariants_Call struct { + *mock.Call +} + +// ListVariants is a helper method to define mock.On call +// - ctx context.Context +// - attachmentID uuid.UUID +// - pipelineVersion int +func (_e *MockRepository_Expecter) ListVariants(ctx any, attachmentID any, pipelineVersion any) *MockRepository_ListVariants_Call { + return &MockRepository_ListVariants_Call{Call: _e.mock.On("ListVariants", ctx, attachmentID, pipelineVersion)} +} + +func (_c *MockRepository_ListVariants_Call) Run(run func(ctx context.Context, attachmentID uuid.UUID, pipelineVersion int)) *MockRepository_ListVariants_Call { + _c.Call.Run(func(args mock.Arguments) { + var arg0 context.Context + if args[0] != nil { + arg0 = args[0].(context.Context) + } + var arg1 uuid.UUID + if args[1] != nil { + arg1 = args[1].(uuid.UUID) + } + var arg2 int + if args[2] != nil { + arg2 = args[2].(int) + } + run( + arg0, + arg1, + arg2, + ) + }) + return _c +} + +func (_c *MockRepository_ListVariants_Call) Return(variants []domain.Variant, err error) *MockRepository_ListVariants_Call { + _c.Call.Return(variants, err) + return _c +} + +func (_c *MockRepository_ListVariants_Call) RunAndReturn(run func(ctx context.Context, attachmentID uuid.UUID, pipelineVersion int) ([]domain.Variant, error)) *MockRepository_ListVariants_Call { + _c.Call.Return(run) + return _c +} diff --git a/internal/service/attachment/mocks/SweepRepository.go b/internal/service/attachment/mocks/SweepRepository.go new file mode 100644 index 0000000..e5e5e51 --- /dev/null +++ b/internal/service/attachment/mocks/SweepRepository.go @@ -0,0 +1,398 @@ +// Code generated by mockery; DO NOT EDIT. +// github.com/vektra/mockery +// template: testify + +package mocks + +import ( + "context" + "mtusi-messenger/internal/domain" + "time" + + "github.com/google/uuid" + mock "github.com/stretchr/testify/mock" +) + +// NewMockSweepRepository creates a new instance of MockSweepRepository. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewMockSweepRepository(t interface { + mock.TestingT + Cleanup(func()) +}) *MockSweepRepository { + if helper, ok := t.(interface{ Helper() }); ok { + helper.Helper() + } + + mock := &MockSweepRepository{} + mock.Mock.Test(t) + + t.Cleanup(func() { + if helper, ok := t.(interface{ Helper() }); ok { + helper.Helper() + } + mock.AssertExpectations(t) + }) + + return mock +} + +// MockSweepRepository is an autogenerated mock type for the SweepRepository type +type MockSweepRepository struct { + mock.Mock +} + +type MockSweepRepository_Expecter struct { + mock *mock.Mock +} + +func (_m *MockSweepRepository) EXPECT() *MockSweepRepository_Expecter { + return &MockSweepRepository_Expecter{mock: &_m.Mock} +} + +// DeletePending provides a mock function for the type MockSweepRepository +func (_mock *MockSweepRepository) DeletePending(ctx context.Context, id uuid.UUID) error { + ret := _mock.Called(ctx, id) + + if len(ret) == 0 { + panic("no return value specified for DeletePending") + } + + var r0 error + if returnFunc, ok := ret.Get(0).(func(context.Context, uuid.UUID) error); ok { + r0 = returnFunc(ctx, id) + } else { + r0 = ret.Error(0) + } + return r0 +} + +// MockSweepRepository_DeletePending_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'DeletePending' +type MockSweepRepository_DeletePending_Call struct { + *mock.Call +} + +// DeletePending is a helper method to define mock.On call +// - ctx context.Context +// - id uuid.UUID +func (_e *MockSweepRepository_Expecter) DeletePending(ctx any, id any) *MockSweepRepository_DeletePending_Call { + return &MockSweepRepository_DeletePending_Call{Call: _e.mock.On("DeletePending", ctx, id)} +} + +func (_c *MockSweepRepository_DeletePending_Call) Run(run func(ctx context.Context, id uuid.UUID)) *MockSweepRepository_DeletePending_Call { + _c.Call.Run(func(args mock.Arguments) { + var arg0 context.Context + if args[0] != nil { + arg0 = args[0].(context.Context) + } + var arg1 uuid.UUID + if args[1] != nil { + arg1 = args[1].(uuid.UUID) + } + run( + arg0, + arg1, + ) + }) + return _c +} + +func (_c *MockSweepRepository_DeletePending_Call) Return(err error) *MockSweepRepository_DeletePending_Call { + _c.Call.Return(err) + return _c +} + +func (_c *MockSweepRepository_DeletePending_Call) RunAndReturn(run func(ctx context.Context, id uuid.UUID) error) *MockSweepRepository_DeletePending_Call { + _c.Call.Return(run) + return _c +} + +// ListPendingPresign provides a mock function for the type MockSweepRepository +func (_mock *MockSweepRepository) ListPendingPresign(ctx context.Context, createdBefore time.Time, limit int) ([]domain.Attachment, error) { + ret := _mock.Called(ctx, createdBefore, limit) + + if len(ret) == 0 { + panic("no return value specified for ListPendingPresign") + } + + var r0 []domain.Attachment + var r1 error + if returnFunc, ok := ret.Get(0).(func(context.Context, time.Time, int) ([]domain.Attachment, error)); ok { + return returnFunc(ctx, createdBefore, limit) + } + if returnFunc, ok := ret.Get(0).(func(context.Context, time.Time, int) []domain.Attachment); ok { + r0 = returnFunc(ctx, createdBefore, limit) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]domain.Attachment) + } + } + if returnFunc, ok := ret.Get(1).(func(context.Context, time.Time, int) error); ok { + r1 = returnFunc(ctx, createdBefore, limit) + } else { + r1 = ret.Error(1) + } + return r0, r1 +} + +// MockSweepRepository_ListPendingPresign_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ListPendingPresign' +type MockSweepRepository_ListPendingPresign_Call struct { + *mock.Call +} + +// ListPendingPresign is a helper method to define mock.On call +// - ctx context.Context +// - createdBefore time.Time +// - limit int +func (_e *MockSweepRepository_Expecter) ListPendingPresign(ctx any, createdBefore any, limit any) *MockSweepRepository_ListPendingPresign_Call { + return &MockSweepRepository_ListPendingPresign_Call{Call: _e.mock.On("ListPendingPresign", ctx, createdBefore, limit)} +} + +func (_c *MockSweepRepository_ListPendingPresign_Call) Run(run func(ctx context.Context, createdBefore time.Time, limit int)) *MockSweepRepository_ListPendingPresign_Call { + _c.Call.Run(func(args mock.Arguments) { + var arg0 context.Context + if args[0] != nil { + arg0 = args[0].(context.Context) + } + var arg1 time.Time + if args[1] != nil { + arg1 = args[1].(time.Time) + } + var arg2 int + if args[2] != nil { + arg2 = args[2].(int) + } + run( + arg0, + arg1, + arg2, + ) + }) + return _c +} + +func (_c *MockSweepRepository_ListPendingPresign_Call) Return(attachments []domain.Attachment, err error) *MockSweepRepository_ListPendingPresign_Call { + _c.Call.Return(attachments, err) + return _c +} + +func (_c *MockSweepRepository_ListPendingPresign_Call) RunAndReturn(run func(ctx context.Context, createdBefore time.Time, limit int) ([]domain.Attachment, error)) *MockSweepRepository_ListPendingPresign_Call { + _c.Call.Return(run) + return _c +} + +// ListReferencedKeys provides a mock function for the type MockSweepRepository +func (_mock *MockSweepRepository) ListReferencedKeys(ctx context.Context, afterKey string, limit int) ([]string, error) { + ret := _mock.Called(ctx, afterKey, limit) + + if len(ret) == 0 { + panic("no return value specified for ListReferencedKeys") + } + + var r0 []string + var r1 error + if returnFunc, ok := ret.Get(0).(func(context.Context, string, int) ([]string, error)); ok { + return returnFunc(ctx, afterKey, limit) + } + if returnFunc, ok := ret.Get(0).(func(context.Context, string, int) []string); ok { + r0 = returnFunc(ctx, afterKey, limit) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]string) + } + } + if returnFunc, ok := ret.Get(1).(func(context.Context, string, int) error); ok { + r1 = returnFunc(ctx, afterKey, limit) + } else { + r1 = ret.Error(1) + } + return r0, r1 +} + +// MockSweepRepository_ListReferencedKeys_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ListReferencedKeys' +type MockSweepRepository_ListReferencedKeys_Call struct { + *mock.Call +} + +// ListReferencedKeys is a helper method to define mock.On call +// - ctx context.Context +// - afterKey string +// - limit int +func (_e *MockSweepRepository_Expecter) ListReferencedKeys(ctx any, afterKey any, limit any) *MockSweepRepository_ListReferencedKeys_Call { + return &MockSweepRepository_ListReferencedKeys_Call{Call: _e.mock.On("ListReferencedKeys", ctx, afterKey, limit)} +} + +func (_c *MockSweepRepository_ListReferencedKeys_Call) Run(run func(ctx context.Context, afterKey string, limit int)) *MockSweepRepository_ListReferencedKeys_Call { + _c.Call.Run(func(args mock.Arguments) { + var arg0 context.Context + if args[0] != nil { + arg0 = args[0].(context.Context) + } + var arg1 string + if args[1] != nil { + arg1 = args[1].(string) + } + var arg2 int + if args[2] != nil { + arg2 = args[2].(int) + } + run( + arg0, + arg1, + arg2, + ) + }) + return _c +} + +func (_c *MockSweepRepository_ListReferencedKeys_Call) Return(strings []string, err error) *MockSweepRepository_ListReferencedKeys_Call { + _c.Call.Return(strings, err) + return _c +} + +func (_c *MockSweepRepository_ListReferencedKeys_Call) RunAndReturn(run func(ctx context.Context, afterKey string, limit int) ([]string, error)) *MockSweepRepository_ListReferencedKeys_Call { + _c.Call.Return(run) + return _c +} + +// ListStaleStaging provides a mock function for the type MockSweepRepository +func (_mock *MockSweepRepository) ListStaleStaging(ctx context.Context, readyBefore time.Time, failedBefore time.Time, limit int) ([]domain.StaleStaging, error) { + ret := _mock.Called(ctx, readyBefore, failedBefore, limit) + + if len(ret) == 0 { + panic("no return value specified for ListStaleStaging") + } + + var r0 []domain.StaleStaging + var r1 error + if returnFunc, ok := ret.Get(0).(func(context.Context, time.Time, time.Time, int) ([]domain.StaleStaging, error)); ok { + return returnFunc(ctx, readyBefore, failedBefore, limit) + } + if returnFunc, ok := ret.Get(0).(func(context.Context, time.Time, time.Time, int) []domain.StaleStaging); ok { + r0 = returnFunc(ctx, readyBefore, failedBefore, limit) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]domain.StaleStaging) + } + } + if returnFunc, ok := ret.Get(1).(func(context.Context, time.Time, time.Time, int) error); ok { + r1 = returnFunc(ctx, readyBefore, failedBefore, limit) + } else { + r1 = ret.Error(1) + } + return r0, r1 +} + +// MockSweepRepository_ListStaleStaging_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ListStaleStaging' +type MockSweepRepository_ListStaleStaging_Call struct { + *mock.Call +} + +// ListStaleStaging is a helper method to define mock.On call +// - ctx context.Context +// - readyBefore time.Time +// - failedBefore time.Time +// - limit int +func (_e *MockSweepRepository_Expecter) ListStaleStaging(ctx any, readyBefore any, failedBefore any, limit any) *MockSweepRepository_ListStaleStaging_Call { + return &MockSweepRepository_ListStaleStaging_Call{Call: _e.mock.On("ListStaleStaging", ctx, readyBefore, failedBefore, limit)} +} + +func (_c *MockSweepRepository_ListStaleStaging_Call) Run(run func(ctx context.Context, readyBefore time.Time, failedBefore time.Time, limit int)) *MockSweepRepository_ListStaleStaging_Call { + _c.Call.Run(func(args mock.Arguments) { + var arg0 context.Context + if args[0] != nil { + arg0 = args[0].(context.Context) + } + var arg1 time.Time + if args[1] != nil { + arg1 = args[1].(time.Time) + } + var arg2 time.Time + if args[2] != nil { + arg2 = args[2].(time.Time) + } + var arg3 int + if args[3] != nil { + arg3 = args[3].(int) + } + run( + arg0, + arg1, + arg2, + arg3, + ) + }) + return _c +} + +func (_c *MockSweepRepository_ListStaleStaging_Call) Return(staleStagings []domain.StaleStaging, err error) *MockSweepRepository_ListStaleStaging_Call { + _c.Call.Return(staleStagings, err) + return _c +} + +func (_c *MockSweepRepository_ListStaleStaging_Call) RunAndReturn(run func(ctx context.Context, readyBefore time.Time, failedBefore time.Time, limit int) ([]domain.StaleStaging, error)) *MockSweepRepository_ListStaleStaging_Call { + _c.Call.Return(run) + return _c +} + +// MarkStagingDeleted provides a mock function for the type MockSweepRepository +func (_mock *MockSweepRepository) MarkStagingDeleted(ctx context.Context, attachmentID uuid.UUID, stagingKey string) error { + ret := _mock.Called(ctx, attachmentID, stagingKey) + + if len(ret) == 0 { + panic("no return value specified for MarkStagingDeleted") + } + + var r0 error + if returnFunc, ok := ret.Get(0).(func(context.Context, uuid.UUID, string) error); ok { + r0 = returnFunc(ctx, attachmentID, stagingKey) + } else { + r0 = ret.Error(0) + } + return r0 +} + +// MockSweepRepository_MarkStagingDeleted_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'MarkStagingDeleted' +type MockSweepRepository_MarkStagingDeleted_Call struct { + *mock.Call +} + +// MarkStagingDeleted is a helper method to define mock.On call +// - ctx context.Context +// - attachmentID uuid.UUID +// - stagingKey string +func (_e *MockSweepRepository_Expecter) MarkStagingDeleted(ctx any, attachmentID any, stagingKey any) *MockSweepRepository_MarkStagingDeleted_Call { + return &MockSweepRepository_MarkStagingDeleted_Call{Call: _e.mock.On("MarkStagingDeleted", ctx, attachmentID, stagingKey)} +} + +func (_c *MockSweepRepository_MarkStagingDeleted_Call) Run(run func(ctx context.Context, attachmentID uuid.UUID, stagingKey string)) *MockSweepRepository_MarkStagingDeleted_Call { + _c.Call.Run(func(args mock.Arguments) { + var arg0 context.Context + if args[0] != nil { + arg0 = args[0].(context.Context) + } + var arg1 uuid.UUID + if args[1] != nil { + arg1 = args[1].(uuid.UUID) + } + var arg2 string + if args[2] != nil { + arg2 = args[2].(string) + } + run( + arg0, + arg1, + arg2, + ) + }) + return _c +} + +func (_c *MockSweepRepository_MarkStagingDeleted_Call) Return(err error) *MockSweepRepository_MarkStagingDeleted_Call { + _c.Call.Return(err) + return _c +} + +func (_c *MockSweepRepository_MarkStagingDeleted_Call) RunAndReturn(run func(ctx context.Context, attachmentID uuid.UUID, stagingKey string) error) *MockSweepRepository_MarkStagingDeleted_Call { + _c.Call.Return(run) + return _c +} diff --git a/internal/service/attachment/service.go b/internal/service/attachment/service.go new file mode 100644 index 0000000..50e8290 --- /dev/null +++ b/internal/service/attachment/service.go @@ -0,0 +1,712 @@ +package attachment + +import ( + "context" + "crypto/sha256" + "encoding/hex" + "errors" + "fmt" + "io" + "log/slog" + "net/http" + "os" + "regexp" + "strings" + "time" + "unicode" + "unicode/utf8" + + "github.com/google/uuid" + "golang.org/x/sync/semaphore" + + "mtusi-messenger/internal/domain" + "mtusi-messenger/internal/imagecheck" + "mtusi-messenger/internal/platform/objectstore" + "mtusi-messenger/internal/telemetry" +) + +const ( + contentTypePNG = "image/png" + contentTypeJPEG = "image/jpeg" + + objectPrefixAttachments = domain.AttachmentsPrefix + objectPrefixStaging = domain.StagingUploadPrefix + objectPrefixPresign = domain.StagingPresignPrefix +) + +var sha256Pattern = regexp.MustCompile(`^[0-9a-f]{64}$`) + +// Repository is the persistence port. It is consumer-side so the service can be +// tested without PostgreSQL. Job/outbox writes are atomic with the attachment +// row inside CreateQueued/CompletePresign. +type Repository interface { + IsChatMember(ctx context.Context, chatID, userID uuid.UUID) (bool, error) + GetForMember(ctx context.Context, userID, id uuid.UUID) (domain.Attachment, error) + GetForOwner(ctx context.Context, ownerID, id uuid.UUID) (domain.Attachment, error) + ListVariants(ctx context.Context, attachmentID uuid.UUID, pipelineVersion int) ([]domain.Variant, error) + GetVariant( + ctx context.Context, + attachmentID uuid.UUID, + pipelineVersion int, + name domain.VariantName, + ) (domain.Variant, error) + CreateQueued( + ctx context.Context, + draft domain.AttachmentDraft, + job domain.Job, + limits domain.AdmissionLimits, + ) (domain.Attachment, error) + CreatePresign( + ctx context.Context, + draft domain.AttachmentDraft, + limits domain.AdmissionLimits, + ) (domain.Attachment, error) + CompletePresign( + ctx context.Context, + ownerID, attachmentID uuid.UUID, + verifiedKey, finalKey string, + pipelineVersion, maxAttempts int, + jobID uuid.UUID, + ) (domain.Attachment, error) + Admission(ctx context.Context, ownerID uuid.UUID) (userPending, totalPending int, stagedBytes int64, err error) + DeletePending(ctx context.Context, id uuid.UUID) error +} + +// Config carries attachment limits and the shared job contract knobs. +type Config struct { + MaxUploadBytes int64 + MaxImagePixels int64 + PresignTTL time.Duration + + PipelineVersion int + MaxAttempts int + MaxPendingPerUser int + MaxPending int + MaxStagedBytes int64 + MaxConcurrent int +} + +type Service struct { + repo Repository + store objectstore.Store + config Config + log *slog.Logger + upload *semaphore.Weighted +} + +func NewService(repo Repository, store objectstore.Store, config Config, log *slog.Logger) *Service { + if log == nil { + log = slog.Default() + } + + service := &Service{repo: repo, store: store, config: config, log: log} + if config.MaxConcurrent > 0 { + service.upload = semaphore.NewWeighted(int64(config.MaxConcurrent)) + } + + return service +} + +// UploadInput is one raw-body upload. DeclaredContentType comes from the HTTP +// Content-Type header and is cross-checked against the detected format. +type UploadInput struct { + ChatID uuid.UUID + OwnerID uuid.UUID + Filename string + DeclaredContentType string + Body io.Reader +} + +// Upload durably stages the original, records the job intent and returns the +// queued snapshot. It never waits for the broker or the worker. +func (s *Service) Upload(ctx context.Context, input UploadInput) (domain.Attachment, error) { + if s.upload != nil { + if err := s.upload.Acquire(ctx, 1); err != nil { + return domain.Attachment{}, unavailable("acquire upload slot", err) + } + defer s.upload.Release(1) + } + + if err := ValidateFilename(input.Filename); err != nil { + return domain.Attachment{}, err + } + + member, err := s.repo.IsChatMember(ctx, input.ChatID, input.OwnerID) + if err != nil { + return domain.Attachment{}, err + } + + if !member { + return domain.Attachment{}, fmt.Errorf("%w: chat is not visible", domain.ErrNotFound) + } + + userPending, totalPending, stagedBytes, err := s.repo.Admission(ctx, input.OwnerID) + if err != nil { + return domain.Attachment{}, unavailable("check admission", err) + } + + if (s.config.MaxPendingPerUser > 0 && userPending >= s.config.MaxPendingPerUser) || + (s.config.MaxPending > 0 && totalPending >= s.config.MaxPending) || + (s.config.MaxStagedBytes > 0 && stagedBytes >= s.config.MaxStagedBytes) { + return domain.Attachment{}, fmt.Errorf("%w: too many unfinished uploads", domain.ErrRateLimited) + } + + file, size, sum, err := s.spool(input.Body) + if err != nil { + return domain.Attachment{}, err + } + + defer func() { _ = file.Close() }() + defer func() { _ = os.Remove(file.Name()) }() + + if _, err := file.Seek(0, io.SeekStart); err != nil { + return domain.Attachment{}, fmt.Errorf("rewind upload: %w", err) + } + + info, err := imagecheck.Validate(file, s.config.MaxImagePixels) + if err != nil { + return domain.Attachment{}, mapImageError(err) + } + + if info.ContentType != input.DeclaredContentType { + return domain.Attachment{}, fmt.Errorf( + "%w: declared %q, detected %q", + domain.ErrUnsupportedMedia, input.DeclaredContentType, info.ContentType, + ) + } + + id, err := uuid.NewV7() + if err != nil { + return domain.Attachment{}, fmt.Errorf("generate attachment id: %w", err) + } + + jobID, err := uuid.NewV7() + if err != nil { + return domain.Attachment{}, fmt.Errorf("generate job id: %w", err) + } + + stagingKey := domain.StagingUploadKey(input.ChatID, id) + finalKey := domain.OriginalObjectKey(input.ChatID, id) + + if _, err := file.Seek(0, io.SeekStart); err != nil { + return domain.Attachment{}, fmt.Errorf("rewind upload: %w", err) + } + + if err := s.store.Put(ctx, stagingKey, file, size, info.ContentType, map[string]string{"sha256": sum}); err != nil { + return domain.Attachment{}, unavailable("store staging object", err) + } + + if err := s.verifyStaging(ctx, stagingKey, size, sum); err != nil { + s.deleteObject(ctx, id, stagingKey) + + return domain.Attachment{}, unavailable("verify staging object", err) + } + + job := domain.Job{ + ID: jobID, + AttachmentID: id, + PipelineVersion: s.config.PipelineVersion, + SourceKey: stagingKey, + Attempt: 1, + MaxAttempts: s.config.MaxAttempts, + CreatedAt: time.Now().UTC(), + } + + limits := s.admissionLimits() + + created, err := s.repo.CreateQueued(ctx, domain.AttachmentDraft{ + ID: id, + ChatID: input.ChatID, + OwnerID: input.OwnerID, + ObjectKey: finalKey, + StagingKey: stagingKey, + Filename: input.Filename, + ContentType: info.ContentType, + SizeBytes: size, + SHA256: sum, + Status: domain.AttachmentQueued, + PipelineVersion: s.config.PipelineVersion, + }, job, limits) + if err != nil { + if errors.Is(err, domain.ErrRateLimited) { + s.deleteObject(ctx, id, stagingKey) + + return domain.Attachment{}, err + } + + // An ambiguous COMMIT may have persisted the intent; leave the staging + // object for the sweeper instead of destroying a queued job's source. + return domain.Attachment{}, unavailable("commit attachment intent", err) + } + + created.Variants = []domain.Variant{} + telemetry.RecordJobAccepted(ctx, created.PipelineVersion) + + return created, nil +} + +// Get returns metadata for any public status. Variants are exposed only for the +// currently published pipeline version and only when ready. +func (s *Service) Get(ctx context.Context, callerID, id uuid.UUID) (domain.Attachment, error) { + attachment, err := s.repo.GetForMember(ctx, callerID, id) + if err != nil { + return domain.Attachment{}, err + } + + if !attachment.Status.Public() { + return domain.Attachment{}, fmt.Errorf("%w: attachment is %s", domain.ErrConflict, attachment.Status) + } + + return s.withVariants(ctx, attachment) +} + +// OpenVariant returns metadata plus the selected content stream. Only a ready +// attachment has bytes. +func (s *Service) OpenVariant( + ctx context.Context, + callerID, id uuid.UUID, + name domain.VariantName, +) (domain.Attachment, domain.Variant, io.ReadCloser, error) { + attachment, err := s.repo.GetForMember(ctx, callerID, id) + if err != nil { + return domain.Attachment{}, domain.Variant{}, nil, err + } + + if !attachment.Status.Public() || attachment.Status != domain.AttachmentReady { + return domain.Attachment{}, domain.Variant{}, nil, fmt.Errorf( + "%w: attachment is %s", domain.ErrConflict, attachment.Status, + ) + } + + if name == "" || name == domain.VariantOriginal { + body, _, err := s.store.Open(ctx, attachment.ObjectKey) + if err != nil { + return domain.Attachment{}, domain.Variant{}, nil, err + } + + return attachment, domain.Variant{ + Name: domain.VariantOriginal, + ContentType: attachment.ContentType, + SizeBytes: attachment.SizeBytes, + SHA256: attachment.SHA256, + ObjectKey: attachment.ObjectKey, + }, body, nil + } + + if !name.Valid() { + return domain.Attachment{}, domain.Variant{}, nil, fmt.Errorf( + "%w: variant %q", domain.ErrValidation, name, + ) + } + + variant, err := s.repo.GetVariant(ctx, attachment.ID, attachment.PipelineVersion, name) + if err != nil { + return domain.Attachment{}, domain.Variant{}, nil, err + } + + body, _, err := s.store.Open(ctx, variant.ObjectKey) + if err != nil { + return domain.Attachment{}, domain.Variant{}, nil, err + } + + return attachment, variant, body, nil +} + +// Open is kept for the legacy service port used by tests. +func (s *Service) Open(ctx context.Context, callerID, id uuid.UUID) (domain.Attachment, io.ReadCloser, error) { + attachment, _, body, err := s.OpenVariant(ctx, callerID, id, domain.VariantOriginal) + + return attachment, body, err +} + +func (s *Service) withVariants(ctx context.Context, attachment domain.Attachment) (domain.Attachment, error) { + attachment.Variants = []domain.Variant{} + + if attachment.Status != domain.AttachmentReady { + return attachment, nil + } + + variants, err := s.repo.ListVariants(ctx, attachment.ID, attachment.PipelineVersion) + if err != nil { + return domain.Attachment{}, err + } + + if variants != nil { + attachment.Variants = variants + } + + return attachment, nil +} + +func (s *Service) Presign(ctx context.Context, request domain.PresignRequest) (domain.PresignResult, error) { + if err := ValidateFilename(request.Filename); err != nil { + return domain.PresignResult{}, err + } + + if request.ContentType != contentTypePNG && request.ContentType != contentTypeJPEG { + return domain.PresignResult{}, fmt.Errorf("%w: content type %q", domain.ErrUnsupportedMedia, request.ContentType) + } + + if request.SizeBytes < 1 { + return domain.PresignResult{}, fmt.Errorf("%w: size %d", domain.ErrValidation, request.SizeBytes) + } + + if request.SizeBytes > s.config.MaxUploadBytes { + return domain.PresignResult{}, fmt.Errorf("%w: size %d", domain.ErrTooLarge, request.SizeBytes) + } + + if !sha256Pattern.MatchString(request.SHA256) { + return domain.PresignResult{}, fmt.Errorf("%w: sha256 must be 64 lowercase hex characters", domain.ErrValidation) + } + + member, err := s.repo.IsChatMember(ctx, request.ChatID, request.OwnerID) + if err != nil { + return domain.PresignResult{}, err + } + + if !member { + return domain.PresignResult{}, fmt.Errorf("%w: chat is not visible", domain.ErrNotFound) + } + + id, err := uuid.NewV7() + if err != nil { + return domain.PresignResult{}, fmt.Errorf("generate attachment id: %w", err) + } + + stagingKey := objectPrefixPresign + request.ChatID.String() + "/" + id.String() + + if _, err := s.repo.CreatePresign(ctx, domain.AttachmentDraft{ + ID: id, + ChatID: request.ChatID, + OwnerID: request.OwnerID, + ObjectKey: stagingKey, + StagingKey: stagingKey, + Filename: request.Filename, + ContentType: request.ContentType, + SizeBytes: request.SizeBytes, + SHA256: request.SHA256, + Status: domain.AttachmentPending, + PipelineVersion: s.config.PipelineVersion, + }, s.admissionLimits()); err != nil { + return domain.PresignResult{}, err + } + + url, expiresAt, err := s.store.PresignPut(ctx, stagingKey, request.SizeBytes, s.config.PresignTTL) + if err != nil { + s.cleanupPending(ctx, id, "") + + return domain.PresignResult{}, unavailable("presign attachment", err) + } + + return domain.PresignResult{ + AttachmentID: id, + UploadURL: url, + ExpiresAt: expiresAt, + SizeBytes: request.SizeBytes, + SHA256: request.SHA256, + }, nil +} + +// Complete verifies the presigned object, copies the verified bytes to a +// server-owned staging key, and enqueues the same async pipeline as the proxy +// upload. The client's staging key remains writable until the verified copy is +// durable. +func (s *Service) Complete( + ctx context.Context, + ownerID, id uuid.UUID, + requestSHA string, +) (domain.Attachment, error) { + if !sha256Pattern.MatchString(requestSHA) { + return domain.Attachment{}, fmt.Errorf("%w: sha256 must be 64 lowercase hex characters", domain.ErrValidation) + } + + attachment, err := s.repo.GetForOwner(ctx, ownerID, id) + if err != nil { + return domain.Attachment{}, err + } + + switch attachment.Status { + case domain.AttachmentReady, domain.AttachmentQueued, domain.AttachmentProcessing: + if attachment.SHA256 != requestSHA { + return domain.Attachment{}, fmt.Errorf("%w: attachment already completed with another checksum", domain.ErrConflict) + } + + return s.withVariants(ctx, attachment) + case domain.AttachmentFailed: + return domain.Attachment{}, fmt.Errorf("%w: attachment is failed", domain.ErrConflict) + case domain.AttachmentPending: + default: + return domain.Attachment{}, fmt.Errorf("%w: unknown attachment status", domain.ErrConflict) + } + + if !strings.HasPrefix(attachment.ObjectKey, objectPrefixPresign) { + return domain.Attachment{}, fmt.Errorf("%w: attachment is not a presigned upload", domain.ErrConflict) + } + + head, err := s.store.Head(ctx, attachment.ObjectKey) + if err != nil { + if errors.Is(err, domain.ErrNotFound) { + return domain.Attachment{}, fmt.Errorf("%w: object was not uploaded", domain.ErrIncomplete) + } + + return domain.Attachment{}, err + } + + if head.Size != attachment.SizeBytes { + s.cleanupPending(ctx, id, attachment.ObjectKey) + + return domain.Attachment{}, fmt.Errorf( + "%w: uploaded %d bytes, declared %d", + domain.ErrValidation, head.Size, attachment.SizeBytes, + ) + } + + body, _, err := s.store.Open(ctx, attachment.ObjectKey) + if err != nil { + return domain.Attachment{}, err + } + + file, size, sum, err := s.spool(body) + _ = body.Close() + + if err != nil { + return domain.Attachment{}, err + } + + defer func() { _ = file.Close() }() + defer func() { _ = os.Remove(file.Name()) }() + + if size != attachment.SizeBytes { + s.cleanupPending(ctx, id, attachment.ObjectKey) + + return domain.Attachment{}, fmt.Errorf("%w: uploaded object size changed", domain.ErrValidation) + } + + if _, err := file.Seek(0, io.SeekStart); err != nil { + return domain.Attachment{}, fmt.Errorf("rewind uploaded object: %w", err) + } + + info, err := imagecheck.Validate(file, s.config.MaxImagePixels) + if err != nil { + s.cleanupPending(ctx, id, attachment.ObjectKey) + + return domain.Attachment{}, mapImageError(err) + } + + if info.ContentType != attachment.ContentType { + s.cleanupPending(ctx, id, attachment.ObjectKey) + + return domain.Attachment{}, fmt.Errorf( + "%w: declared %q, detected %q", + domain.ErrUnsupportedMedia, attachment.ContentType, info.ContentType, + ) + } + + if sum != attachment.SHA256 { + s.cleanupPending(ctx, id, attachment.ObjectKey) + + return domain.Attachment{}, fmt.Errorf("%w: uploaded object checksum mismatch", domain.ErrValidation) + } + + if requestSHA != attachment.SHA256 { + return domain.Attachment{}, fmt.Errorf("%w: completion checksum mismatch", domain.ErrConflict) + } + + verifiedKey := domain.StagingVerifiedKey(attachment.ChatID, attachment.ID) + finalKey := domain.OriginalObjectKey(attachment.ChatID, attachment.ID) + + if _, err := file.Seek(0, io.SeekStart); err != nil { + return domain.Attachment{}, fmt.Errorf("rewind verified object: %w", err) + } + + if err := s.store.Put(ctx, verifiedKey, file, size, info.ContentType, map[string]string{"sha256": sum}); err != nil { + return domain.Attachment{}, unavailable("store verified object", err) + } + + if err := s.verifyStaging(ctx, verifiedKey, size, sum); err != nil { + s.deleteObject(ctx, id, verifiedKey) + + return domain.Attachment{}, unavailable("verify staging object", err) + } + + jobID, err := uuid.NewV7() + if err != nil { + s.deleteObject(ctx, id, verifiedKey) + + return domain.Attachment{}, fmt.Errorf("generate job id: %w", err) + } + + queued, err := s.repo.CompletePresign( + ctx, ownerID, id, verifiedKey, finalKey, + s.config.PipelineVersion, s.config.MaxAttempts, jobID, + ) + if err != nil { + // The verified key is shared by concurrent completions of this + // attachment. Never delete it here: a winning request may already have + // queued a job pointing at it. The orphan sweeper owns abandoned keys. + if errors.Is(err, domain.ErrConflict) { + current, getErr := s.repo.GetForOwner(ctx, ownerID, id) + if getErr == nil && current.SHA256 == requestSHA && current.Status.Public() { + return s.withVariants(ctx, current) + } + + return domain.Attachment{}, fmt.Errorf("%w: attachment is no longer pending", domain.ErrConflict) + } + + return domain.Attachment{}, unavailable("commit presigned attachment", err) + } + + if err := s.store.Delete(ctx, attachment.ObjectKey); err != nil && !errors.Is(err, domain.ErrNotFound) { + s.log.WarnContext(ctx, "presign staging cleanup failed", + slog.String("attachment_id", id.String()), + slog.Any("error", err), + ) + } + + queued.Variants = []domain.Variant{} + telemetry.RecordJobAccepted(ctx, queued.PipelineVersion) + + return queued, nil +} + +// verifyStaging checks the freshly written object; a mismatch is a broken +// staging handoff and must never become a 202. +func (s *Service) admissionLimits() domain.AdmissionLimits { + return domain.AdmissionLimits{ + PerUser: s.config.MaxPendingPerUser, + Total: s.config.MaxPending, + Bytes: s.config.MaxStagedBytes, + } +} + +func (s *Service) verifyStaging(ctx context.Context, key string, size int64, sum string) error { + head, err := s.store.Head(ctx, key) + if err != nil { + return fmt.Errorf("head staging object: %w", err) + } + + if head.Size != size { + return fmt.Errorf("staging size %d, want %d", head.Size, size) + } + + if sha := head.Metadata["sha256"]; sha != "" && sha != sum { + return errors.New("staging checksum metadata does not match") + } + + return nil +} + +func (s *Service) spool(body io.Reader) (*os.File, int64, string, error) { + file, err := os.CreateTemp("", "lab5-upload-*") + if err != nil { + return nil, 0, "", fmt.Errorf("create upload spool: %w", err) + } + + cleanup := func() { + _ = file.Close() + _ = os.Remove(file.Name()) + } + + hasher := sha256.New() + limited := io.LimitReader(body, s.config.MaxUploadBytes+1) + buffer := make([]byte, 32<<10) + + size, err := io.CopyBuffer(io.MultiWriter(file, hasher), limited, buffer) + if err != nil { + cleanup() + + var maxBytes *http.MaxBytesError + if errors.As(err, &maxBytes) { + return nil, 0, "", fmt.Errorf("%w: request body exceeds %d bytes", domain.ErrTooLarge, s.config.MaxUploadBytes) + } + + return nil, 0, "", fmt.Errorf("%w: read upload: %w", domain.ErrValidation, err) + } + + if size > s.config.MaxUploadBytes { + cleanup() + + return nil, 0, "", fmt.Errorf("%w: upload exceeds %d bytes", domain.ErrTooLarge, s.config.MaxUploadBytes) + } + + if size == 0 { + cleanup() + + return nil, 0, "", fmt.Errorf("%w: empty image", domain.ErrUnsupportedMedia) + } + + return file, size, hex.EncodeToString(hasher.Sum(nil)), nil +} + +func (s *Service) deleteObject(ctx context.Context, id uuid.UUID, key string) { + if key == "" { + return + } + + if err := s.store.Delete(ctx, key); err != nil && !errors.Is(err, domain.ErrNotFound) { + s.log.WarnContext(ctx, "object cleanup failed", + slog.String("attachment_id", id.String()), + slog.Any("error", err), + ) + } +} + +func (s *Service) cleanupPending(ctx context.Context, id uuid.UUID, objectKey string) { + s.deleteObject(ctx, id, objectKey) + + if err := s.repo.DeletePending(ctx, id); err != nil && !errors.Is(err, domain.ErrNotFound) { + s.log.WarnContext(ctx, "pending attachment cleanup failed", + slog.String("attachment_id", id.String()), + slog.Any("error", err), + ) + } +} + +// ValidateFilename implements the contract rule: 1-255 Unicode code points, +// no path separators, NUL or control characters. The name is display-only; the +// S3 key is always generated. +func ValidateFilename(name string) error { + if !utf8.ValidString(name) { + return fmt.Errorf("%w: filename is not valid UTF-8", domain.ErrValidation) + } + + length := utf8.RuneCountInString(name) + if length < 1 || length > 255 { + return fmt.Errorf("%w: filename length is %d, want 1-255 code points", domain.ErrValidation, length) + } + + if strings.TrimSpace(name) == "" { + return fmt.Errorf("%w: filename consists of whitespace only", domain.ErrValidation) + } + + if strings.ContainsAny(name, "/\\\x00") { + return fmt.Errorf("%w: filename contains a path separator or NUL", domain.ErrValidation) + } + + for _, r := range name { + if unicode.IsControl(r) { + return fmt.Errorf("%w: filename contains a control character", domain.ErrValidation) + } + } + + return nil +} + +func mapImageError(err error) error { + switch { + case errors.Is(err, imagecheck.ErrTooLarge): + return fmt.Errorf("%w: %w", domain.ErrTooLarge, err) + case errors.Is(err, imagecheck.ErrUnsupported), errors.Is(err, imagecheck.ErrCorrupt): + return fmt.Errorf("%w: %w", domain.ErrUnsupportedMedia, err) + default: + return err + } +} + +func unavailable(operation string, err error) error { + if errors.Is(err, domain.ErrUnavailable) || errors.Is(err, domain.ErrNotFound) { + return err + } + + return fmt.Errorf("%w: %s: %w", domain.ErrUnavailable, operation, err) +} diff --git a/internal/service/attachment/service_test.go b/internal/service/attachment/service_test.go new file mode 100644 index 0000000..9c065fd --- /dev/null +++ b/internal/service/attachment/service_test.go @@ -0,0 +1,509 @@ +package attachment_test + +import ( + "bytes" + "context" + "crypto/sha256" + "encoding/hex" + "image" + "image/color" + "image/png" + "io" + "log/slog" + "strings" + "testing" + "time" + + "github.com/google/uuid" + "github.com/stretchr/testify/mock" + "github.com/stretchr/testify/require" + + "mtusi-messenger/internal/domain" + "mtusi-messenger/internal/platform/objectstore" + "mtusi-messenger/internal/service/attachment" + "mtusi-messenger/internal/service/attachment/mocks" +) + +type storedObject struct { + data []byte + contentType string + metadata map[string]string + lastModified time.Time +} + +type fakeStore struct { + objects map[string]storedObject +} + +func newFakeStore() *fakeStore { + return &fakeStore{objects: make(map[string]storedObject)} +} + +func (f *fakeStore) Put( + _ context.Context, + key string, + body io.ReadSeeker, + _ int64, + contentType string, + metadata map[string]string, +) error { + data, err := io.ReadAll(body) + if err != nil { + return err + } + + f.objects[key] = storedObject{ + data: data, + contentType: contentType, + metadata: metadata, + lastModified: time.Now().UTC(), + } + + return nil +} + +func (f *fakeStore) Open(_ context.Context, key string) (io.ReadCloser, objectstore.Object, error) { + object, ok := f.objects[key] + if !ok { + return nil, objectstore.Object{}, domain.ErrNotFound + } + + return io.NopCloser(bytes.NewReader(object.data)), f.object(key, object), nil +} + +func (f *fakeStore) Ping(context.Context) error { return nil } + +func (f *fakeStore) Head(_ context.Context, key string) (objectstore.Object, error) { + object, ok := f.objects[key] + if !ok { + return objectstore.Object{}, domain.ErrNotFound + } + + return f.object(key, object), nil +} + +func (f *fakeStore) Copy(_ context.Context, src, dst, contentType string, metadata map[string]string) error { + object, ok := f.objects[src] + if !ok { + return domain.ErrNotFound + } + + f.objects[dst] = storedObject{ + data: append([]byte(nil), object.data...), + contentType: contentType, + metadata: metadata, + lastModified: time.Now().UTC(), + } + + return nil +} + +func (f *fakeStore) Delete(_ context.Context, key string) error { + delete(f.objects, key) + return nil +} + +func (f *fakeStore) List(_ context.Context, prefix string) ([]objectstore.Object, error) { + objects := make([]objectstore.Object, 0, len(f.objects)) + for key, object := range f.objects { + if strings.HasPrefix(key, prefix) { + objects = append(objects, f.object(key, object)) + } + } + + return objects, nil +} + +func (f *fakeStore) PresignPut(_ context.Context, key string, _ int64, ttl time.Duration) (string, time.Time, error) { + return "http://s3.example/" + key, time.Now().UTC().Add(ttl), nil +} + +func (f *fakeStore) object(key string, object storedObject) objectstore.Object { + return objectstore.Object{ + Key: key, + Size: int64(len(object.data)), + ContentType: object.contentType, + LastModified: object.lastModified, + Metadata: object.metadata, + } +} + +func pngBytes(t *testing.T, width, height int) []byte { + t.Helper() + + source := image.NewRGBA(image.Rect(0, 0, width, height)) + for x := range width { + for y := range height { + source.Set(x, y, color.RGBA{R: uint8(x), G: uint8(y), B: 200, A: 255}) + } + } + + var buffer bytes.Buffer + require.NoError(t, png.Encode(&buffer, source)) + + return buffer.Bytes() +} + +func serviceConfig() attachment.Config { + return attachment.Config{ + MaxUploadBytes: 1 << 20, + MaxImagePixels: 1_000_000, + PresignTTL: 5 * time.Minute, + PipelineVersion: 1, + MaxAttempts: 5, + } +} + +func TestValidateFilename(t *testing.T) { + valid := []string{"photo.png", "фото.png", "a b.jpeg", strings.Repeat("я", 255)} + for _, name := range valid { + require.NoError(t, attachment.ValidateFilename(name), name) + } + + invalid := []string{"", " ", "\t\n", strings.Repeat("x", 256), "a/b.png", `a\b.png`, "a\x00b.png", "a\nb.png"} + for _, name := range invalid { + require.ErrorIs(t, attachment.ValidateFilename(name), domain.ErrValidation, name) + } +} + +func TestUploadStagesAndQueues(t *testing.T) { + repo := mocks.NewMockRepository(t) + store := newFakeStore() + service := attachment.NewService(repo, store, serviceConfig(), slog.Default()) + + chatID := uuid.New() + ownerID := uuid.New() + content := pngBytes(t, 16, 16) + sum := sha256.Sum256(content) + digest := hex.EncodeToString(sum[:]) + + repo.EXPECT().IsChatMember(mock.Anything, chatID, ownerID).Return(true, nil).Once() + repo.EXPECT().Admission(mock.Anything, ownerID).Return(0, 0, int64(0), nil).Once() + repo.EXPECT().CreateQueued(mock.Anything, mock.MatchedBy(func(draft domain.AttachmentDraft) bool { + return draft.ChatID == chatID && draft.OwnerID == ownerID && + draft.ContentType == "image/png" && draft.SizeBytes == int64(len(content)) && + draft.SHA256 == digest && draft.Status == domain.AttachmentQueued && + draft.PipelineVersion == 1 && + strings.HasPrefix(draft.ObjectKey, "attachments/") && + strings.HasPrefix(draft.StagingKey, "staging/uploads/") + }), mock.MatchedBy(func(job domain.Job) bool { + return job.PipelineVersion == 1 && job.Attempt == 1 && + job.MaxAttempts == 5 && job.SourceKey != "" + }), domain.AdmissionLimits{}).Return(domain.Attachment{ + ID: uuid.New(), ChatID: chatID, OwnerID: ownerID, + ContentType: "image/png", SizeBytes: int64(len(content)), SHA256: digest, + Status: domain.AttachmentQueued, PipelineVersion: 1, + }, nil).Once() + + result, err := service.Upload(t.Context(), attachment.UploadInput{ + ChatID: chatID, + OwnerID: ownerID, + Filename: "photo.png", + DeclaredContentType: "image/png", + Body: bytes.NewReader(content), + }) + require.NoError(t, err) + require.Equal(t, domain.AttachmentQueued, result.Status) + require.Len(t, store.objects, 1) + for key := range store.objects { + require.Contains(t, key, "staging/uploads/") + } +} + +func TestUploadRejectsTooLargeBody(t *testing.T) { + repo := mocks.NewMockRepository(t) + service := attachment.NewService(repo, newFakeStore(), attachment.Config{ + MaxUploadBytes: 8, MaxImagePixels: 1_000_000, PresignTTL: time.Minute, + PipelineVersion: 1, MaxAttempts: 5, + }, slog.Default()) + + repo.EXPECT().IsChatMember(mock.Anything, mock.Anything, mock.Anything).Return(true, nil).Once() + repo.EXPECT().Admission(mock.Anything, mock.Anything).Return(0, 0, int64(0), nil).Once() + + _, err := service.Upload(t.Context(), attachment.UploadInput{ + ChatID: uuid.New(), OwnerID: uuid.New(), Filename: "photo.png", + DeclaredContentType: "image/png", + Body: bytes.NewReader(bytes.Repeat([]byte("x"), 9)), + }) + require.ErrorIs(t, err, domain.ErrTooLarge) +} + +func TestUploadRejectsMIMEMismatch(t *testing.T) { + repo := mocks.NewMockRepository(t) + service := attachment.NewService(repo, newFakeStore(), serviceConfig(), slog.Default()) + + repo.EXPECT().IsChatMember(mock.Anything, mock.Anything, mock.Anything).Return(true, nil).Once() + repo.EXPECT().Admission(mock.Anything, mock.Anything).Return(0, 0, int64(0), nil).Once() + + _, err := service.Upload(t.Context(), attachment.UploadInput{ + ChatID: uuid.New(), OwnerID: uuid.New(), Filename: "photo.jpg", + DeclaredContentType: "image/jpeg", + Body: bytes.NewReader(pngBytes(t, 8, 8)), + }) + require.ErrorIs(t, err, domain.ErrUnsupportedMedia) +} + +func TestUploadAdmissionRejectsFlood(t *testing.T) { + repo := mocks.NewMockRepository(t) + service := attachment.NewService(repo, newFakeStore(), attachment.Config{ + MaxUploadBytes: 1 << 20, MaxImagePixels: 1_000_000, PresignTTL: time.Minute, + PipelineVersion: 1, MaxAttempts: 5, MaxPendingPerUser: 1, + }, slog.Default()) + + repo.EXPECT().IsChatMember(mock.Anything, mock.Anything, mock.Anything).Return(true, nil).Once() + repo.EXPECT().Admission(mock.Anything, mock.Anything).Return(1, 1, int64(0), nil).Once() + + _, err := service.Upload(t.Context(), attachment.UploadInput{ + ChatID: uuid.New(), OwnerID: uuid.New(), Filename: "photo.png", + DeclaredContentType: "image/png", Body: bytes.NewReader(pngBytes(t, 8, 8)), + }) + require.ErrorIs(t, err, domain.ErrRateLimited) +} + +func TestGetReturnsQueuedSnapshotWithoutVariants(t *testing.T) { + repo := mocks.NewMockRepository(t) + service := attachment.NewService(repo, newFakeStore(), serviceConfig(), slog.Default()) + + repo.EXPECT().GetForMember(mock.Anything, mock.Anything, mock.Anything). + Return(domain.Attachment{Status: domain.AttachmentQueued, PipelineVersion: 1}, nil).Once() + + got, err := service.Get(t.Context(), uuid.New(), uuid.New()) + require.NoError(t, err) + require.Equal(t, domain.AttachmentQueued, got.Status) + require.Empty(t, got.Variants) +} + +func TestGetReadyLoadsCurrentVariants(t *testing.T) { + repo := mocks.NewMockRepository(t) + service := attachment.NewService(repo, newFakeStore(), serviceConfig(), slog.Default()) + + attachmentID := uuid.New() + variant := domain.Variant{Name: domain.VariantThumbnail, ContentType: "image/jpeg", SizeBytes: 10, Width: 256, Height: 160, SHA256: strings.Repeat("a", 64)} + + repo.EXPECT().GetForMember(mock.Anything, mock.Anything, attachmentID). + Return(domain.Attachment{ID: attachmentID, Status: domain.AttachmentReady, PipelineVersion: 2}, nil).Once() + repo.EXPECT().ListVariants(mock.Anything, attachmentID, 2).Return([]domain.Variant{variant}, nil).Once() + + got, err := service.Get(t.Context(), uuid.New(), attachmentID) + require.NoError(t, err) + require.Equal(t, []domain.Variant{variant}, got.Variants) +} + +func TestGetRejectsInternalPending(t *testing.T) { + repo := mocks.NewMockRepository(t) + service := attachment.NewService(repo, newFakeStore(), serviceConfig(), slog.Default()) + + repo.EXPECT().GetForMember(mock.Anything, mock.Anything, mock.Anything). + Return(domain.Attachment{Status: domain.AttachmentPending}, nil).Once() + + _, err := service.Get(t.Context(), uuid.New(), uuid.New()) + require.ErrorIs(t, err, domain.ErrConflict) +} + +func TestOpenVariantRejectsQueued(t *testing.T) { + repo := mocks.NewMockRepository(t) + service := attachment.NewService(repo, newFakeStore(), serviceConfig(), slog.Default()) + + repo.EXPECT().GetForMember(mock.Anything, mock.Anything, mock.Anything). + Return(domain.Attachment{Status: domain.AttachmentQueued}, nil).Once() + + _, _, _, err := service.OpenVariant(t.Context(), uuid.New(), uuid.New(), domain.VariantOriginal) + require.ErrorIs(t, err, domain.ErrConflict) +} + +func TestCompleteQueuesPresignedObject(t *testing.T) { + repo := mocks.NewMockRepository(t) + store := newFakeStore() + service := attachment.NewService(repo, store, serviceConfig(), slog.Default()) + + id := uuid.New() + chatID := uuid.New() + ownerID := uuid.New() + content := pngBytes(t, 10, 10) + sum := sha256.Sum256(content) + digest := hex.EncodeToString(sum[:]) + stagingKey := "staging/presign/" + chatID.String() + "/" + id.String() + + store.objects[stagingKey] = storedObject{ + data: content, contentType: "image/png", + metadata: map[string]string{"sha256": digest}, lastModified: time.Now().UTC(), + } + + pending := domain.Attachment{ + ID: id, ChatID: chatID, OwnerID: ownerID, ObjectKey: stagingKey, + StagingKey: stagingKey, ContentType: "image/png", + SizeBytes: int64(len(content)), SHA256: digest, + Status: domain.AttachmentPending, PipelineVersion: 1, + } + + repo.EXPECT().GetForOwner(mock.Anything, ownerID, id).Return(pending, nil).Once() + repo.EXPECT().CompletePresign( + mock.Anything, ownerID, id, + mock.MatchedBy(func(key string) bool { return strings.HasPrefix(key, "staging/verified/") }), + mock.MatchedBy(func(key string) bool { return strings.HasPrefix(key, "attachments/") }), + 1, 5, mock.Anything, + ).Return(domain.Attachment{ + ID: id, ChatID: chatID, OwnerID: ownerID, ContentType: "image/png", + SizeBytes: int64(len(content)), SHA256: digest, + Status: domain.AttachmentQueued, PipelineVersion: 1, + }, nil).Once() + + completed, err := service.Complete(t.Context(), ownerID, id, digest) + require.NoError(t, err) + require.Equal(t, domain.AttachmentQueued, completed.Status) + require.NotContains(t, store.objects, stagingKey) + require.Len(t, store.objects, 1) +} + +func TestCompleteConcurrentConflictKeepsVerifiedSource(t *testing.T) { + repo := mocks.NewMockRepository(t) + store := newFakeStore() + service := attachment.NewService(repo, store, serviceConfig(), slog.Default()) + + id := uuid.New() + chatID := uuid.New() + ownerID := uuid.New() + content := pngBytes(t, 10, 10) + sum := sha256.Sum256(content) + digest := hex.EncodeToString(sum[:]) + stagingKey := "staging/presign/" + chatID.String() + "/" + id.String() + + store.objects[stagingKey] = storedObject{ + data: content, contentType: "image/png", + metadata: map[string]string{"sha256": digest}, + } + + pending := domain.Attachment{ + ID: id, ChatID: chatID, OwnerID: ownerID, ObjectKey: stagingKey, + StagingKey: stagingKey, ContentType: "image/png", + SizeBytes: int64(len(content)), SHA256: digest, + Status: domain.AttachmentPending, PipelineVersion: 1, + } + queued := domain.Attachment{ + ID: id, ChatID: chatID, OwnerID: ownerID, ObjectKey: "attachments/" + chatID.String() + "/" + id.String(), + ContentType: "image/png", SizeBytes: int64(len(content)), SHA256: digest, + Status: domain.AttachmentQueued, PipelineVersion: 1, + } + + repo.EXPECT().GetForOwner(mock.Anything, ownerID, id).Return(pending, nil).Once() + repo.EXPECT().CompletePresign( + mock.Anything, ownerID, id, mock.Anything, mock.Anything, + 1, 5, mock.Anything, + ).Return(domain.Attachment{}, domain.ErrConflict).Once() + repo.EXPECT().GetForOwner(mock.Anything, ownerID, id).Return(queued, nil).Once() + + got, err := service.Complete(t.Context(), ownerID, id, digest) + require.NoError(t, err) + require.Equal(t, domain.AttachmentQueued, got.Status) + + verified := 0 + for key := range store.objects { + if strings.HasPrefix(key, "staging/verified/") { + verified++ + } + } + require.Equal(t, 1, verified, "loser must not delete the winner's verified source") +} + +func TestPresignHonoursAdmissionLimit(t *testing.T) { + repo := mocks.NewMockRepository(t) + service := attachment.NewService(repo, newFakeStore(), serviceConfig(), slog.Default()) + + repo.EXPECT().IsChatMember(mock.Anything, mock.Anything, mock.Anything).Return(true, nil).Once() + repo.EXPECT().CreatePresign(mock.Anything, mock.Anything, mock.Anything). + Return(domain.Attachment{}, domain.ErrRateLimited).Once() + + _, err := service.Presign(t.Context(), domain.PresignRequest{ + ChatID: uuid.New(), OwnerID: uuid.New(), Filename: "photo.png", + ContentType: "image/png", SizeBytes: 10, SHA256: strings.Repeat("a", 64), + }) + require.ErrorIs(t, err, domain.ErrRateLimited) +} + +func TestUploadRateLimitedByAtomicAdmissionRemovesStaging(t *testing.T) { + repo := mocks.NewMockRepository(t) + store := newFakeStore() + service := attachment.NewService(repo, store, serviceConfig(), slog.Default()) + + repo.EXPECT().IsChatMember(mock.Anything, mock.Anything, mock.Anything).Return(true, nil).Once() + repo.EXPECT().Admission(mock.Anything, mock.Anything).Return(0, 0, int64(0), nil).Once() + repo.EXPECT().CreateQueued(mock.Anything, mock.Anything, mock.Anything, mock.Anything). + Return(domain.Attachment{}, domain.ErrRateLimited).Once() + + _, err := service.Upload(t.Context(), attachment.UploadInput{ + ChatID: uuid.New(), OwnerID: uuid.New(), Filename: "photo.png", + DeclaredContentType: "image/png", Body: bytes.NewReader(pngBytes(t, 8, 8)), + }) + require.ErrorIs(t, err, domain.ErrRateLimited) + require.Empty(t, store.objects, "a rejected atomic admission must not leave staging") +} + +func TestCompleteRejectsChecksumMismatch(t *testing.T) { + repo := mocks.NewMockRepository(t) + store := newFakeStore() + service := attachment.NewService(repo, store, serviceConfig(), slog.Default()) + + id := uuid.New() + chatID := uuid.New() + ownerID := uuid.New() + content := pngBytes(t, 10, 10) + sum := sha256.Sum256(content) + digest := hex.EncodeToString(sum[:]) + stagingKey := "staging/presign/" + chatID.String() + "/" + id.String() + + store.objects[stagingKey] = storedObject{data: content, contentType: "image/png", metadata: map[string]string{"sha256": digest}} + + pending := domain.Attachment{ + ID: id, ChatID: chatID, OwnerID: ownerID, ObjectKey: stagingKey, + StagingKey: stagingKey, ContentType: "image/png", + SizeBytes: int64(len(content)) + 1, SHA256: digest, + Status: domain.AttachmentPending, PipelineVersion: 1, + } + + repo.EXPECT().GetForOwner(mock.Anything, ownerID, id).Return(pending, nil).Once() + repo.EXPECT().DeletePending(mock.Anything, id).Return(nil).Once() + + _, err := service.Complete(t.Context(), ownerID, id, digest) + require.ErrorIs(t, err, domain.ErrValidation) + require.NotContains(t, store.objects, stagingKey) +} + +func TestCompleteKeepsObjectOnWrongRequestChecksum(t *testing.T) { + repo := mocks.NewMockRepository(t) + store := newFakeStore() + service := attachment.NewService(repo, store, serviceConfig(), slog.Default()) + + id := uuid.New() + chatID := uuid.New() + ownerID := uuid.New() + content := pngBytes(t, 10, 10) + sum := sha256.Sum256(content) + digest := hex.EncodeToString(sum[:]) + stagingKey := "staging/presign/" + chatID.String() + "/" + id.String() + + store.objects[stagingKey] = storedObject{data: content, contentType: "image/png", metadata: map[string]string{"sha256": digest}} + pending := domain.Attachment{ + ID: id, ChatID: chatID, OwnerID: ownerID, ObjectKey: stagingKey, + StagingKey: stagingKey, ContentType: "image/png", + SizeBytes: int64(len(content)), SHA256: digest, + Status: domain.AttachmentPending, PipelineVersion: 1, + } + + repo.EXPECT().GetForOwner(mock.Anything, ownerID, id).Return(pending, nil).Once() + + _, err := service.Complete(t.Context(), ownerID, id, strings.Repeat("0", 64)) + require.ErrorIs(t, err, domain.ErrConflict) + require.Contains(t, store.objects, stagingKey) +} + +func TestPresignRejectsNonPositiveSize(t *testing.T) { + repo := mocks.NewMockRepository(t) + service := attachment.NewService(repo, newFakeStore(), serviceConfig(), slog.Default()) + + _, err := service.Presign(t.Context(), domain.PresignRequest{ + ChatID: uuid.New(), OwnerID: uuid.New(), + Filename: "photo.png", ContentType: "image/png", + SizeBytes: 0, SHA256: strings.Repeat("a", 64), + }) + require.ErrorIs(t, err, domain.ErrValidation) +} diff --git a/internal/service/attachment/sweeper.go b/internal/service/attachment/sweeper.go new file mode 100644 index 0000000..c6bd879 --- /dev/null +++ b/internal/service/attachment/sweeper.go @@ -0,0 +1,236 @@ +package attachment + +import ( + "context" + "errors" + "log/slog" + "time" + + "github.com/google/uuid" + + "mtusi-messenger/internal/domain" + "mtusi-messenger/internal/platform/objectstore" +) + +// LockStore serialises sweepers across API replicas. +type LockStore interface { + AcquireSweepLock(ctx context.Context) (release func(), acquired bool, err error) +} + +// SweepRepository is the storage port used by cleanup. It exposes only +// read/delete projections; object bytes still live in S3. +type SweepRepository interface { + ListPendingPresign(ctx context.Context, createdBefore time.Time, limit int) ([]domain.Attachment, error) + DeletePending(ctx context.Context, id uuid.UUID) error + ListStaleStaging(ctx context.Context, readyBefore, failedBefore time.Time, limit int) ([]domain.StaleStaging, error) + MarkStagingDeleted(ctx context.Context, attachmentID uuid.UUID, stagingKey string) error + ListReferencedKeys(ctx context.Context, afterKey string, limit int) ([]string, error) +} + +type SweepStats struct { + RowsDeleted int + ObjectsDeleted int + StagingCleared int +} + +type Sweeper struct { + repo SweepRepository + store objectstore.Store + locker LockStore + grace time.Duration + orphanGrace time.Duration + failedRetain time.Duration + interval time.Duration + log *slog.Logger +} + +func NewSweeper( + repo SweepRepository, + store objectstore.Store, + locker LockStore, + grace, orphanGrace, failedRetain, interval time.Duration, + log *slog.Logger, +) *Sweeper { + if log == nil { + log = slog.Default() + } + + return &Sweeper{ + repo: repo, + store: store, + locker: locker, + grace: grace, + orphanGrace: orphanGrace, + failedRetain: failedRetain, + interval: interval, + log: log, + } +} + +// Run sweeps immediately, then on every interval until the context is done. +func (s *Sweeper) Run(ctx context.Context) { + s.sweep(ctx) + + ticker := time.NewTicker(s.interval) + defer ticker.Stop() + + for { + select { + case <-ctx.Done(): + return + case <-ticker.C: + s.sweep(ctx) + } + } +} + +func (s *Sweeper) sweep(ctx context.Context) { + stats, err := s.SweepOnce(ctx) + if err != nil { + s.log.WarnContext(ctx, "attachment sweep failed", slog.Any("error", err)) + + return + } + + if stats.RowsDeleted+stats.ObjectsDeleted+stats.StagingCleared > 0 { + s.log.InfoContext(ctx, "attachment sweep finished", + slog.Int("rows_deleted", stats.RowsDeleted), + slog.Int("objects_deleted", stats.ObjectsDeleted), + slog.Int("staging_cleared", stats.StagingCleared), + ) + } +} + +// SweepOnce applies explicit, status-aware retention rules. It never deletes +// staging of a queued/processing attachment and aborts object collection if any +// database page or S3 listing fails. +func (s *Sweeper) SweepOnce(ctx context.Context) (SweepStats, error) { + release, acquired, err := s.locker.AcquireSweepLock(ctx) + if err != nil { + return SweepStats{}, err + } + + if !acquired { + return SweepStats{}, nil + } + + defer release() + + now := time.Now().UTC() + var stats SweepStats + + // Abandoned presign rows: no completion ever arrived. + pending, err := s.repo.ListPendingPresign(ctx, now.Add(-s.grace), 100) + if err != nil { + return stats, err + } + + for _, row := range pending { + if row.StagingKey != "" { + if s.deleteObject(ctx, row.StagingKey) { + stats.ObjectsDeleted++ + } + } + + if err := s.repo.DeletePending(ctx, row.ID); err != nil && !errors.Is(err, domain.ErrNotFound) { + return stats, err + } + + stats.RowsDeleted++ + } + + // Ready/failed rows keep their staging key until the object is safely + // removed. Active queued/processing staging is never in this list. + stale, err := s.repo.ListStaleStaging( + ctx, now.Add(-s.orphanGrace), now.Add(-s.failedRetain), 100, + ) + if err != nil { + return stats, err + } + + for _, row := range stale { + if s.deleteObject(ctx, row.StagingKey) { + stats.ObjectsDeleted++ + } + + if err := s.repo.MarkStagingDeleted(ctx, row.AttachmentID, row.StagingKey); err != nil { + return stats, err + } + + stats.StagingCleared++ + } + + referenced, err := s.referencedKeys(ctx) + if err != nil { + return stats, err + } + + // Orphans: objects no row references. Final objects and variants use the + // normal grace; staging uses the longer orphan grace. + for _, prefix := range []string{domain.AttachmentsPrefix, "staging/"} { + before := now.Add(-s.grace) + if prefix == "staging/" { + before = now.Add(-s.orphanGrace) + } + + objects, err := s.store.List(ctx, prefix) + if err != nil { + return stats, err + } + + for _, object := range objects { + if object.LastModified.IsZero() || !object.LastModified.Before(before) { + continue + } + + if _, ok := referenced[object.Key]; ok { + continue + } + + if s.deleteObject(ctx, object.Key) { + stats.ObjectsDeleted++ + } + } + } + + return stats, nil +} + +func (s *Sweeper) referencedKeys(ctx context.Context) (map[string]struct{}, error) { + const pageSize = 1000 + + keys := make(map[string]struct{}) + after := "" + + for { + rows, err := s.repo.ListReferencedKeys(ctx, after, pageSize) + if err != nil { + return nil, err + } + + for _, key := range rows { + keys[key] = struct{}{} + } + + if len(rows) < pageSize { + return keys, nil + } + + after = rows[len(rows)-1] + } +} + +func (s *Sweeper) deleteObject(ctx context.Context, key string) bool { + err := s.store.Delete(ctx, key) + if err == nil { + return true + } + + if !errors.Is(err, domain.ErrNotFound) { + s.log.WarnContext(ctx, "sweep delete failed", + slog.Any("error", err), + ) + } + + return false +} diff --git a/internal/service/attachment/sweeper_test.go b/internal/service/attachment/sweeper_test.go new file mode 100644 index 0000000..51f8c89 --- /dev/null +++ b/internal/service/attachment/sweeper_test.go @@ -0,0 +1,113 @@ +package attachment_test + +import ( + "context" + "log/slog" + "testing" + "time" + + "github.com/google/uuid" + "github.com/stretchr/testify/mock" + "github.com/stretchr/testify/require" + + "mtusi-messenger/internal/domain" + "mtusi-messenger/internal/service/attachment" + "mtusi-messenger/internal/service/attachment/mocks" +) + +func TestSweepAppliesStatusAwareRetention(t *testing.T) { + repo := mocks.NewMockSweepRepository(t) + locker := mocks.NewMockLockStore(t) + store := newFakeStore() + + stale := time.Now().UTC().Add(-2 * time.Hour) + + presign := domain.Attachment{ + ID: uuid.New(), StagingKey: "staging/presign/chat/" + uuid.NewString(), + Status: domain.AttachmentPending, + } + staleStaging := domain.StaleStaging{ + AttachmentID: uuid.New(), StagingKey: "staging/uploads/chat/ready", Status: domain.AttachmentReady, + } + activeStaging := "staging/uploads/chat/active" + readyKey := "attachments/chat/ready/original" + variantKey := "attachments/chat/ready/variants/v1/thumbnail.jpg" + + for _, key := range []string{ + presign.StagingKey, staleStaging.StagingKey, activeStaging, readyKey, variantKey, + "attachments/chat/orphan", "staging/orphan", + } { + store.objects[key] = storedObject{data: []byte("x"), lastModified: stale} + } + store.objects["staging/fresh"] = storedObject{data: []byte("x"), lastModified: time.Now().UTC()} + + repo.EXPECT().ListPendingPresign(mock.Anything, mock.Anything, 100). + Return([]domain.Attachment{presign}, nil).Once() + repo.EXPECT().DeletePending(mock.Anything, presign.ID).Return(nil).Once() + repo.EXPECT().ListStaleStaging(mock.Anything, mock.Anything, mock.Anything, 100). + Return([]domain.StaleStaging{staleStaging}, nil).Once() + repo.EXPECT().MarkStagingDeleted(mock.Anything, staleStaging.AttachmentID, staleStaging.StagingKey). + Return(nil).Once() + repo.EXPECT().ListReferencedKeys(mock.Anything, "", 1000). + Return([]string{activeStaging, readyKey, variantKey}, nil).Once() + locker.EXPECT().AcquireSweepLock(mock.Anything).Return(func() {}, true, nil).Once() + + sweeper := attachment.NewSweeper( + repo, store, locker, + 10*time.Minute, time.Hour, 24*time.Hour, time.Minute, slog.Default(), + ) + + stats, err := sweeper.SweepOnce(t.Context()) + require.NoError(t, err) + require.Equal(t, 1, stats.RowsDeleted) + require.Equal(t, 1, stats.StagingCleared) + require.Equal(t, 4, stats.ObjectsDeleted) + + require.NotContains(t, store.objects, presign.StagingKey) + require.NotContains(t, store.objects, staleStaging.StagingKey) + require.NotContains(t, store.objects, "attachments/chat/orphan") + require.NotContains(t, store.objects, "staging/orphan") + require.Contains(t, store.objects, activeStaging) + require.Contains(t, store.objects, readyKey) + require.Contains(t, store.objects, variantKey) + require.Contains(t, store.objects, "staging/fresh") +} + +func TestSweepSkipsWhenAnotherReplicaHoldsTheLock(t *testing.T) { + repo := mocks.NewMockSweepRepository(t) + locker := mocks.NewMockLockStore(t) + sweeper := attachment.NewSweeper( + repo, newFakeStore(), locker, + time.Minute, time.Hour, 24*time.Hour, time.Minute, slog.Default(), + ) + + locker.EXPECT().AcquireSweepLock(mock.Anything).Return(nil, false, nil).Once() + + stats, err := sweeper.SweepOnce(t.Context()) + require.NoError(t, err) + require.Zero(t, stats) +} + +func TestSweepAbortsObjectCollectionWhenKeysCannotBeRead(t *testing.T) { + repo := mocks.NewMockSweepRepository(t) + locker := mocks.NewMockLockStore(t) + store := newFakeStore() + + orphan := "attachments/chat/orphan" + store.objects[orphan] = storedObject{data: []byte("x"), lastModified: time.Now().UTC().Add(-2 * time.Hour)} + + repo.EXPECT().ListPendingPresign(mock.Anything, mock.Anything, 100).Return(nil, nil).Once() + repo.EXPECT().ListStaleStaging(mock.Anything, mock.Anything, mock.Anything, 100).Return(nil, nil).Once() + repo.EXPECT().ListReferencedKeys(mock.Anything, "", 1000). + Return(nil, context.DeadlineExceeded).Once() + locker.EXPECT().AcquireSweepLock(mock.Anything).Return(func() {}, true, nil).Once() + + sweeper := attachment.NewSweeper( + repo, store, locker, + time.Minute, time.Hour, 24*time.Hour, time.Minute, slog.Default(), + ) + + _, err := sweeper.SweepOnce(t.Context()) + require.ErrorIs(t, err, context.DeadlineExceeded) + require.Contains(t, store.objects, orphan, "fail-closed: no deletion when the key set is unknown") +} diff --git a/internal/service/chat/mocks/Repository.go b/internal/service/chat/mocks/Repository.go new file mode 100644 index 0000000..aa6f58f --- /dev/null +++ b/internal/service/chat/mocks/Repository.go @@ -0,0 +1,265 @@ +// Code generated by mockery; DO NOT EDIT. +// github.com/vektra/mockery +// template: testify + +package mocks + +import ( + "context" + "mtusi-messenger/internal/domain" + + "github.com/google/uuid" + mock "github.com/stretchr/testify/mock" +) + +// NewMockRepository creates a new instance of MockRepository. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewMockRepository(t interface { + mock.TestingT + Cleanup(func()) +}) *MockRepository { + if helper, ok := t.(interface{ Helper() }); ok { + helper.Helper() + } + + mock := &MockRepository{} + mock.Mock.Test(t) + + t.Cleanup(func() { + if helper, ok := t.(interface{ Helper() }); ok { + helper.Helper() + } + mock.AssertExpectations(t) + }) + + return mock +} + +// MockRepository is an autogenerated mock type for the Repository type +type MockRepository struct { + mock.Mock +} + +type MockRepository_Expecter struct { + mock *mock.Mock +} + +func (_m *MockRepository) EXPECT() *MockRepository_Expecter { + return &MockRepository_Expecter{mock: &_m.Mock} +} + +// Create provides a mock function for the type MockRepository +func (_mock *MockRepository) Create(ctx context.Context, draft domain.ChatDraft) (domain.Chat, error) { + ret := _mock.Called(ctx, draft) + + if len(ret) == 0 { + panic("no return value specified for Create") + } + + var r0 domain.Chat + var r1 error + if returnFunc, ok := ret.Get(0).(func(context.Context, domain.ChatDraft) (domain.Chat, error)); ok { + return returnFunc(ctx, draft) + } + if returnFunc, ok := ret.Get(0).(func(context.Context, domain.ChatDraft) domain.Chat); ok { + r0 = returnFunc(ctx, draft) + } else { + r0 = ret.Get(0).(domain.Chat) + } + if returnFunc, ok := ret.Get(1).(func(context.Context, domain.ChatDraft) error); ok { + r1 = returnFunc(ctx, draft) + } else { + r1 = ret.Error(1) + } + return r0, r1 +} + +// MockRepository_Create_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Create' +type MockRepository_Create_Call struct { + *mock.Call +} + +// Create is a helper method to define mock.On call +// - ctx context.Context +// - draft domain.ChatDraft +func (_e *MockRepository_Expecter) Create(ctx any, draft any) *MockRepository_Create_Call { + return &MockRepository_Create_Call{Call: _e.mock.On("Create", ctx, draft)} +} + +func (_c *MockRepository_Create_Call) Run(run func(ctx context.Context, draft domain.ChatDraft)) *MockRepository_Create_Call { + _c.Call.Run(func(args mock.Arguments) { + var arg0 context.Context + if args[0] != nil { + arg0 = args[0].(context.Context) + } + var arg1 domain.ChatDraft + if args[1] != nil { + arg1 = args[1].(domain.ChatDraft) + } + run( + arg0, + arg1, + ) + }) + return _c +} + +func (_c *MockRepository_Create_Call) Return(chat domain.Chat, err error) *MockRepository_Create_Call { + _c.Call.Return(chat, err) + return _c +} + +func (_c *MockRepository_Create_Call) RunAndReturn(run func(ctx context.Context, draft domain.ChatDraft) (domain.Chat, error)) *MockRepository_Create_Call { + _c.Call.Return(run) + return _c +} + +// GetVisible provides a mock function for the type MockRepository +func (_mock *MockRepository) GetVisible(ctx context.Context, chatID uuid.UUID, callerID uuid.UUID) (domain.Chat, error) { + ret := _mock.Called(ctx, chatID, callerID) + + if len(ret) == 0 { + panic("no return value specified for GetVisible") + } + + var r0 domain.Chat + var r1 error + if returnFunc, ok := ret.Get(0).(func(context.Context, uuid.UUID, uuid.UUID) (domain.Chat, error)); ok { + return returnFunc(ctx, chatID, callerID) + } + if returnFunc, ok := ret.Get(0).(func(context.Context, uuid.UUID, uuid.UUID) domain.Chat); ok { + r0 = returnFunc(ctx, chatID, callerID) + } else { + r0 = ret.Get(0).(domain.Chat) + } + if returnFunc, ok := ret.Get(1).(func(context.Context, uuid.UUID, uuid.UUID) error); ok { + r1 = returnFunc(ctx, chatID, callerID) + } else { + r1 = ret.Error(1) + } + return r0, r1 +} + +// MockRepository_GetVisible_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetVisible' +type MockRepository_GetVisible_Call struct { + *mock.Call +} + +// GetVisible is a helper method to define mock.On call +// - ctx context.Context +// - chatID uuid.UUID +// - callerID uuid.UUID +func (_e *MockRepository_Expecter) GetVisible(ctx any, chatID any, callerID any) *MockRepository_GetVisible_Call { + return &MockRepository_GetVisible_Call{Call: _e.mock.On("GetVisible", ctx, chatID, callerID)} +} + +func (_c *MockRepository_GetVisible_Call) Run(run func(ctx context.Context, chatID uuid.UUID, callerID uuid.UUID)) *MockRepository_GetVisible_Call { + _c.Call.Run(func(args mock.Arguments) { + var arg0 context.Context + if args[0] != nil { + arg0 = args[0].(context.Context) + } + var arg1 uuid.UUID + if args[1] != nil { + arg1 = args[1].(uuid.UUID) + } + var arg2 uuid.UUID + if args[2] != nil { + arg2 = args[2].(uuid.UUID) + } + run( + arg0, + arg1, + arg2, + ) + }) + return _c +} + +func (_c *MockRepository_GetVisible_Call) Return(chat domain.Chat, err error) *MockRepository_GetVisible_Call { + _c.Call.Return(chat, err) + return _c +} + +func (_c *MockRepository_GetVisible_Call) RunAndReturn(run func(ctx context.Context, chatID uuid.UUID, callerID uuid.UUID) (domain.Chat, error)) *MockRepository_GetVisible_Call { + _c.Call.Return(run) + return _c +} + +// ListVisible provides a mock function for the type MockRepository +func (_mock *MockRepository) ListVisible(ctx context.Context, callerID uuid.UUID, after *domain.Cursor, limit int) (domain.Page[domain.Chat], error) { + ret := _mock.Called(ctx, callerID, after, limit) + + if len(ret) == 0 { + panic("no return value specified for ListVisible") + } + + var r0 domain.Page[domain.Chat] + var r1 error + if returnFunc, ok := ret.Get(0).(func(context.Context, uuid.UUID, *domain.Cursor, int) (domain.Page[domain.Chat], error)); ok { + return returnFunc(ctx, callerID, after, limit) + } + if returnFunc, ok := ret.Get(0).(func(context.Context, uuid.UUID, *domain.Cursor, int) domain.Page[domain.Chat]); ok { + r0 = returnFunc(ctx, callerID, after, limit) + } else { + r0 = ret.Get(0).(domain.Page[domain.Chat]) + } + if returnFunc, ok := ret.Get(1).(func(context.Context, uuid.UUID, *domain.Cursor, int) error); ok { + r1 = returnFunc(ctx, callerID, after, limit) + } else { + r1 = ret.Error(1) + } + return r0, r1 +} + +// MockRepository_ListVisible_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ListVisible' +type MockRepository_ListVisible_Call struct { + *mock.Call +} + +// ListVisible is a helper method to define mock.On call +// - ctx context.Context +// - callerID uuid.UUID +// - after *domain.Cursor +// - limit int +func (_e *MockRepository_Expecter) ListVisible(ctx any, callerID any, after any, limit any) *MockRepository_ListVisible_Call { + return &MockRepository_ListVisible_Call{Call: _e.mock.On("ListVisible", ctx, callerID, after, limit)} +} + +func (_c *MockRepository_ListVisible_Call) Run(run func(ctx context.Context, callerID uuid.UUID, after *domain.Cursor, limit int)) *MockRepository_ListVisible_Call { + _c.Call.Run(func(args mock.Arguments) { + var arg0 context.Context + if args[0] != nil { + arg0 = args[0].(context.Context) + } + var arg1 uuid.UUID + if args[1] != nil { + arg1 = args[1].(uuid.UUID) + } + var arg2 *domain.Cursor + if args[2] != nil { + arg2 = args[2].(*domain.Cursor) + } + var arg3 int + if args[3] != nil { + arg3 = args[3].(int) + } + run( + arg0, + arg1, + arg2, + arg3, + ) + }) + return _c +} + +func (_c *MockRepository_ListVisible_Call) Return(page domain.Page[domain.Chat], err error) *MockRepository_ListVisible_Call { + _c.Call.Return(page, err) + return _c +} + +func (_c *MockRepository_ListVisible_Call) RunAndReturn(run func(ctx context.Context, callerID uuid.UUID, after *domain.Cursor, limit int) (domain.Page[domain.Chat], error)) *MockRepository_ListVisible_Call { + _c.Call.Return(run) + return _c +} diff --git a/internal/service/chat/service.go b/internal/service/chat/service.go new file mode 100644 index 0000000..f3a0d3f --- /dev/null +++ b/internal/service/chat/service.go @@ -0,0 +1,69 @@ +package chat + +import ( + "context" + "fmt" + + "github.com/google/uuid" + + "mtusi-messenger/internal/domain" +) + +type Repository interface { + Create(ctx context.Context, draft domain.ChatDraft) (domain.Chat, error) + GetVisible(ctx context.Context, chatID, callerID uuid.UUID) (domain.Chat, error) + ListVisible( + ctx context.Context, + callerID uuid.UUID, + after *domain.Cursor, + limit int, + ) (domain.Page[domain.Chat], error) +} + +type Service struct { + chats Repository +} + +func NewService(chats Repository) *Service { + return &Service{chats: chats} +} + +func (s *Service) Create(ctx context.Context, draft domain.ChatDraft) (domain.Chat, error) { + if err := draft.Validate(); err != nil { + return domain.Chat{}, err + } + + created, err := s.chats.Create(ctx, draft) + if err != nil { + return domain.Chat{}, fmt.Errorf("create chat: %w", err) + } + + return created, nil +} + +func (s *Service) Get(ctx context.Context, callerID, chatID uuid.UUID) (domain.Chat, error) { + found, err := s.chats.GetVisible(ctx, chatID, callerID) + if err != nil { + return domain.Chat{}, fmt.Errorf("get chat: %w", err) + } + + return found, nil +} + +func (s *Service) List( + ctx context.Context, + callerID uuid.UUID, + after *domain.Cursor, + limit int, +) (domain.Page[domain.Chat], error) { + if after != nil && !after.BelongsTo(callerID) { + return domain.Page[domain.Chat]{}, fmt.Errorf("cursor is bound to another list: %w", domain.ErrInvalidCursor) + } + + page, err := s.chats.ListVisible(ctx, callerID, after, limit) + if err != nil { + return domain.Page[domain.Chat]{}, fmt.Errorf("list chats: %w", err) + } + + return page, nil +} diff --git a/internal/service/chat/service_test.go b/internal/service/chat/service_test.go new file mode 100644 index 0000000..47450f9 --- /dev/null +++ b/internal/service/chat/service_test.go @@ -0,0 +1,140 @@ +package chat_test + +import ( + "errors" + "testing" + "time" + + "github.com/google/uuid" + "github.com/stretchr/testify/suite" + + "mtusi-messenger/internal/domain" + "mtusi-messenger/internal/service/chat" + "mtusi-messenger/internal/service/chat/mocks" +) + +var errRepository = errors.New("repository is unavailable") + +type ServiceSuite struct { + suite.Suite + + chats *mocks.MockRepository + service *chat.Service + caller uuid.UUID + now time.Time +} + +func TestServiceSuite(t *testing.T) { + t.Parallel() + suite.Run(t, new(ServiceSuite)) +} + +func (s *ServiceSuite) SetupTest() { + s.chats = mocks.NewMockRepository(s.T()) + s.service = chat.NewService(s.chats) + s.caller = uuid.New() + s.now = time.Date(2026, 9, 1, 12, 0, 0, 0, time.UTC) +} + +func (s *ServiceSuite) draft() domain.ChatDraft { + return domain.ChatDraft{ + Title: "Проект по ВНП", + MemberIDs: []uuid.UUID{s.caller}, + CallerID: s.caller, + } +} + +func (s *ServiceSuite) TestCreateReturnsStoredChat() { + draft := s.draft() + stored := domain.Chat{ + ID: uuid.New(), + Title: draft.Title, + MemberIDs: draft.MemberIDs, + CreatedAt: s.now, + } + + s.chats.EXPECT().Create(s.T().Context(), draft).Return(stored, nil).Once() + + got, err := s.service.Create(s.T().Context(), draft) + s.Require().NoError(err) + s.Equal(stored, got) +} + +func (s *ServiceSuite) TestCreateRejectsDraftWithoutCallerWithoutRepositoryCall() { + draft := s.draft() + draft.MemberIDs = []uuid.UUID{uuid.New()} + + _, err := s.service.Create(s.T().Context(), draft) + s.Require().ErrorIs(err, domain.ErrValidation) +} + +func (s *ServiceSuite) TestCreateRejectsBlankTitleWithoutRepositoryCall() { + draft := s.draft() + draft.Title = " " + + _, err := s.service.Create(s.T().Context(), draft) + s.Require().ErrorIs(err, domain.ErrValidation) +} + +func (s *ServiceSuite) TestCreatePropagatesUnknownMember() { + draft := s.draft() + + s.chats.EXPECT().Create(s.T().Context(), draft).Return(domain.Chat{}, domain.ErrUnknownMember).Once() + + _, err := s.service.Create(s.T().Context(), draft) + s.Require().ErrorIs(err, domain.ErrUnknownMember, + "целостность участников проверяет хранилище, сервис только пробрасывает исход") +} + +func (s *ServiceSuite) TestGetPropagatesNotFoundForForeignChat() { + chatID := uuid.New() + + s.chats.EXPECT().GetVisible(s.T().Context(), chatID, s.caller).Return(domain.Chat{}, domain.ErrNotFound).Once() + + _, err := s.service.Get(s.T().Context(), s.caller, chatID) + s.Require().ErrorIs(err, domain.ErrNotFound) +} + +func (s *ServiceSuite) TestListPassesNilCursorOnFirstPage() { + stored := domain.Chat{ID: uuid.New(), Title: "Проект", MemberIDs: []uuid.UUID{s.caller}, CreatedAt: s.now} + + s.chats.EXPECT(). + ListVisible(s.T().Context(), s.caller, (*domain.Cursor)(nil), domain.DefaultPageLimit). + Return(domain.Page[domain.Chat]{Items: []domain.Chat{stored}}, nil). + Once() + + page, err := s.service.List(s.T().Context(), s.caller, nil, domain.DefaultPageLimit) + s.Require().NoError(err) + s.Equal([]domain.Chat{stored}, page.Items) + s.Nil(page.Next, "на последней странице курсора нет") +} + +func (s *ServiceSuite) TestListRejectsCursorFromAnotherCaller() { + foreign := &domain.Cursor{Scope: uuid.New(), CreatedAt: s.now, ID: uuid.New()} + + _, err := s.service.List(s.T().Context(), s.caller, foreign, domain.DefaultPageLimit) + s.Require().ErrorIs(err, domain.ErrInvalidCursor, + "курсор чужого списка не должен открывать чужие чаты") +} + +func (s *ServiceSuite) TestListAcceptsOwnCursor() { + own := &domain.Cursor{Scope: s.caller, CreatedAt: s.now, ID: uuid.New()} + + s.chats.EXPECT(). + ListVisible(s.T().Context(), s.caller, own, 10). + Return(domain.Page[domain.Chat]{}, nil). + Once() + + _, err := s.service.List(s.T().Context(), s.caller, own, 10) + s.Require().NoError(err) +} + +func (s *ServiceSuite) TestListWrapsRepositoryFailure() { + s.chats.EXPECT(). + ListVisible(s.T().Context(), s.caller, (*domain.Cursor)(nil), domain.DefaultPageLimit). + Return(domain.Page[domain.Chat]{}, errRepository). + Once() + + _, err := s.service.List(s.T().Context(), s.caller, nil, domain.DefaultPageLimit) + s.Require().ErrorIs(err, errRepository) +} diff --git a/internal/service/message/mocks/AttachmentChecker.go b/internal/service/message/mocks/AttachmentChecker.go new file mode 100644 index 0000000..6a21bed --- /dev/null +++ b/internal/service/message/mocks/AttachmentChecker.go @@ -0,0 +1,123 @@ +// Code generated by mockery; DO NOT EDIT. +// github.com/vektra/mockery +// template: testify + +package mocks + +import ( + "context" + "mtusi-messenger/internal/domain" + + "github.com/google/uuid" + mock "github.com/stretchr/testify/mock" +) + +// NewMockAttachmentChecker creates a new instance of MockAttachmentChecker. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewMockAttachmentChecker(t interface { + mock.TestingT + Cleanup(func()) +}) *MockAttachmentChecker { + if helper, ok := t.(interface{ Helper() }); ok { + helper.Helper() + } + + mock := &MockAttachmentChecker{} + mock.Mock.Test(t) + + t.Cleanup(func() { + if helper, ok := t.(interface{ Helper() }); ok { + helper.Helper() + } + mock.AssertExpectations(t) + }) + + return mock +} + +// MockAttachmentChecker is an autogenerated mock type for the AttachmentChecker type +type MockAttachmentChecker struct { + mock.Mock +} + +type MockAttachmentChecker_Expecter struct { + mock *mock.Mock +} + +func (_m *MockAttachmentChecker) EXPECT() *MockAttachmentChecker_Expecter { + return &MockAttachmentChecker_Expecter{mock: &_m.Mock} +} + +// ListStates provides a mock function for the type MockAttachmentChecker +func (_mock *MockAttachmentChecker) ListStates(ctx context.Context, chatID uuid.UUID, ids []uuid.UUID) ([]domain.AttachmentState, error) { + ret := _mock.Called(ctx, chatID, ids) + + if len(ret) == 0 { + panic("no return value specified for ListStates") + } + + var r0 []domain.AttachmentState + var r1 error + if returnFunc, ok := ret.Get(0).(func(context.Context, uuid.UUID, []uuid.UUID) ([]domain.AttachmentState, error)); ok { + return returnFunc(ctx, chatID, ids) + } + if returnFunc, ok := ret.Get(0).(func(context.Context, uuid.UUID, []uuid.UUID) []domain.AttachmentState); ok { + r0 = returnFunc(ctx, chatID, ids) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]domain.AttachmentState) + } + } + if returnFunc, ok := ret.Get(1).(func(context.Context, uuid.UUID, []uuid.UUID) error); ok { + r1 = returnFunc(ctx, chatID, ids) + } else { + r1 = ret.Error(1) + } + return r0, r1 +} + +// MockAttachmentChecker_ListStates_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ListStates' +type MockAttachmentChecker_ListStates_Call struct { + *mock.Call +} + +// ListStates is a helper method to define mock.On call +// - ctx context.Context +// - chatID uuid.UUID +// - ids []uuid.UUID +func (_e *MockAttachmentChecker_Expecter) ListStates(ctx any, chatID any, ids any) *MockAttachmentChecker_ListStates_Call { + return &MockAttachmentChecker_ListStates_Call{Call: _e.mock.On("ListStates", ctx, chatID, ids)} +} + +func (_c *MockAttachmentChecker_ListStates_Call) Run(run func(ctx context.Context, chatID uuid.UUID, ids []uuid.UUID)) *MockAttachmentChecker_ListStates_Call { + _c.Call.Run(func(args mock.Arguments) { + var arg0 context.Context + if args[0] != nil { + arg0 = args[0].(context.Context) + } + var arg1 uuid.UUID + if args[1] != nil { + arg1 = args[1].(uuid.UUID) + } + var arg2 []uuid.UUID + if args[2] != nil { + arg2 = args[2].([]uuid.UUID) + } + run( + arg0, + arg1, + arg2, + ) + }) + return _c +} + +func (_c *MockAttachmentChecker_ListStates_Call) Return(attachmentStates []domain.AttachmentState, err error) *MockAttachmentChecker_ListStates_Call { + _c.Call.Return(attachmentStates, err) + return _c +} + +func (_c *MockAttachmentChecker_ListStates_Call) RunAndReturn(run func(ctx context.Context, chatID uuid.UUID, ids []uuid.UUID) ([]domain.AttachmentState, error)) *MockAttachmentChecker_ListStates_Call { + _c.Call.Return(run) + return _c +} diff --git a/internal/service/message/mocks/Repository.go b/internal/service/message/mocks/Repository.go new file mode 100644 index 0000000..369d2dc --- /dev/null +++ b/internal/service/message/mocks/Repository.go @@ -0,0 +1,343 @@ +// Code generated by mockery; DO NOT EDIT. +// github.com/vektra/mockery +// template: testify + +package mocks + +import ( + "context" + "mtusi-messenger/internal/domain" + + "github.com/google/uuid" + mock "github.com/stretchr/testify/mock" +) + +// NewMockRepository creates a new instance of MockRepository. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewMockRepository(t interface { + mock.TestingT + Cleanup(func()) +}) *MockRepository { + if helper, ok := t.(interface{ Helper() }); ok { + helper.Helper() + } + + mock := &MockRepository{} + mock.Mock.Test(t) + + t.Cleanup(func() { + if helper, ok := t.(interface{ Helper() }); ok { + helper.Helper() + } + mock.AssertExpectations(t) + }) + + return mock +} + +// MockRepository is an autogenerated mock type for the Repository type +type MockRepository struct { + mock.Mock +} + +type MockRepository_Expecter struct { + mock *mock.Mock +} + +func (_m *MockRepository) EXPECT() *MockRepository_Expecter { + return &MockRepository_Expecter{mock: &_m.Mock} +} + +// Create provides a mock function for the type MockRepository +func (_mock *MockRepository) Create(ctx context.Context, draft domain.MessageDraft) (domain.Message, error) { + ret := _mock.Called(ctx, draft) + + if len(ret) == 0 { + panic("no return value specified for Create") + } + + var r0 domain.Message + var r1 error + if returnFunc, ok := ret.Get(0).(func(context.Context, domain.MessageDraft) (domain.Message, error)); ok { + return returnFunc(ctx, draft) + } + if returnFunc, ok := ret.Get(0).(func(context.Context, domain.MessageDraft) domain.Message); ok { + r0 = returnFunc(ctx, draft) + } else { + r0 = ret.Get(0).(domain.Message) + } + if returnFunc, ok := ret.Get(1).(func(context.Context, domain.MessageDraft) error); ok { + r1 = returnFunc(ctx, draft) + } else { + r1 = ret.Error(1) + } + return r0, r1 +} + +// MockRepository_Create_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Create' +type MockRepository_Create_Call struct { + *mock.Call +} + +// Create is a helper method to define mock.On call +// - ctx context.Context +// - draft domain.MessageDraft +func (_e *MockRepository_Expecter) Create(ctx any, draft any) *MockRepository_Create_Call { + return &MockRepository_Create_Call{Call: _e.mock.On("Create", ctx, draft)} +} + +func (_c *MockRepository_Create_Call) Run(run func(ctx context.Context, draft domain.MessageDraft)) *MockRepository_Create_Call { + _c.Call.Run(func(args mock.Arguments) { + var arg0 context.Context + if args[0] != nil { + arg0 = args[0].(context.Context) + } + var arg1 domain.MessageDraft + if args[1] != nil { + arg1 = args[1].(domain.MessageDraft) + } + run( + arg0, + arg1, + ) + }) + return _c +} + +func (_c *MockRepository_Create_Call) Return(message domain.Message, err error) *MockRepository_Create_Call { + _c.Call.Return(message, err) + return _c +} + +func (_c *MockRepository_Create_Call) RunAndReturn(run func(ctx context.Context, draft domain.MessageDraft) (domain.Message, error)) *MockRepository_Create_Call { + _c.Call.Return(run) + return _c +} + +// IsChatMember provides a mock function for the type MockRepository +func (_mock *MockRepository) IsChatMember(ctx context.Context, chatID uuid.UUID, userID uuid.UUID) (bool, error) { + ret := _mock.Called(ctx, chatID, userID) + + if len(ret) == 0 { + panic("no return value specified for IsChatMember") + } + + var r0 bool + var r1 error + if returnFunc, ok := ret.Get(0).(func(context.Context, uuid.UUID, uuid.UUID) (bool, error)); ok { + return returnFunc(ctx, chatID, userID) + } + if returnFunc, ok := ret.Get(0).(func(context.Context, uuid.UUID, uuid.UUID) bool); ok { + r0 = returnFunc(ctx, chatID, userID) + } else { + r0 = ret.Get(0).(bool) + } + if returnFunc, ok := ret.Get(1).(func(context.Context, uuid.UUID, uuid.UUID) error); ok { + r1 = returnFunc(ctx, chatID, userID) + } else { + r1 = ret.Error(1) + } + return r0, r1 +} + +// MockRepository_IsChatMember_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'IsChatMember' +type MockRepository_IsChatMember_Call struct { + *mock.Call +} + +// IsChatMember is a helper method to define mock.On call +// - ctx context.Context +// - chatID uuid.UUID +// - userID uuid.UUID +func (_e *MockRepository_Expecter) IsChatMember(ctx any, chatID any, userID any) *MockRepository_IsChatMember_Call { + return &MockRepository_IsChatMember_Call{Call: _e.mock.On("IsChatMember", ctx, chatID, userID)} +} + +func (_c *MockRepository_IsChatMember_Call) Run(run func(ctx context.Context, chatID uuid.UUID, userID uuid.UUID)) *MockRepository_IsChatMember_Call { + _c.Call.Run(func(args mock.Arguments) { + var arg0 context.Context + if args[0] != nil { + arg0 = args[0].(context.Context) + } + var arg1 uuid.UUID + if args[1] != nil { + arg1 = args[1].(uuid.UUID) + } + var arg2 uuid.UUID + if args[2] != nil { + arg2 = args[2].(uuid.UUID) + } + run( + arg0, + arg1, + arg2, + ) + }) + return _c +} + +func (_c *MockRepository_IsChatMember_Call) Return(b bool, err error) *MockRepository_IsChatMember_Call { + _c.Call.Return(b, err) + return _c +} + +func (_c *MockRepository_IsChatMember_Call) RunAndReturn(run func(ctx context.Context, chatID uuid.UUID, userID uuid.UUID) (bool, error)) *MockRepository_IsChatMember_Call { + _c.Call.Return(run) + return _c +} + +// ListVisible provides a mock function for the type MockRepository +func (_mock *MockRepository) ListVisible(ctx context.Context, chatID uuid.UUID, callerID uuid.UUID, after *domain.Cursor, limit int) (domain.Page[domain.Message], error) { + ret := _mock.Called(ctx, chatID, callerID, after, limit) + + if len(ret) == 0 { + panic("no return value specified for ListVisible") + } + + var r0 domain.Page[domain.Message] + var r1 error + if returnFunc, ok := ret.Get(0).(func(context.Context, uuid.UUID, uuid.UUID, *domain.Cursor, int) (domain.Page[domain.Message], error)); ok { + return returnFunc(ctx, chatID, callerID, after, limit) + } + if returnFunc, ok := ret.Get(0).(func(context.Context, uuid.UUID, uuid.UUID, *domain.Cursor, int) domain.Page[domain.Message]); ok { + r0 = returnFunc(ctx, chatID, callerID, after, limit) + } else { + r0 = ret.Get(0).(domain.Page[domain.Message]) + } + if returnFunc, ok := ret.Get(1).(func(context.Context, uuid.UUID, uuid.UUID, *domain.Cursor, int) error); ok { + r1 = returnFunc(ctx, chatID, callerID, after, limit) + } else { + r1 = ret.Error(1) + } + return r0, r1 +} + +// MockRepository_ListVisible_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ListVisible' +type MockRepository_ListVisible_Call struct { + *mock.Call +} + +// ListVisible is a helper method to define mock.On call +// - ctx context.Context +// - chatID uuid.UUID +// - callerID uuid.UUID +// - after *domain.Cursor +// - limit int +func (_e *MockRepository_Expecter) ListVisible(ctx any, chatID any, callerID any, after any, limit any) *MockRepository_ListVisible_Call { + return &MockRepository_ListVisible_Call{Call: _e.mock.On("ListVisible", ctx, chatID, callerID, after, limit)} +} + +func (_c *MockRepository_ListVisible_Call) Run(run func(ctx context.Context, chatID uuid.UUID, callerID uuid.UUID, after *domain.Cursor, limit int)) *MockRepository_ListVisible_Call { + _c.Call.Run(func(args mock.Arguments) { + var arg0 context.Context + if args[0] != nil { + arg0 = args[0].(context.Context) + } + var arg1 uuid.UUID + if args[1] != nil { + arg1 = args[1].(uuid.UUID) + } + var arg2 uuid.UUID + if args[2] != nil { + arg2 = args[2].(uuid.UUID) + } + var arg3 *domain.Cursor + if args[3] != nil { + arg3 = args[3].(*domain.Cursor) + } + var arg4 int + if args[4] != nil { + arg4 = args[4].(int) + } + run( + arg0, + arg1, + arg2, + arg3, + arg4, + ) + }) + return _c +} + +func (_c *MockRepository_ListVisible_Call) Return(page domain.Page[domain.Message], err error) *MockRepository_ListVisible_Call { + _c.Call.Return(page, err) + return _c +} + +func (_c *MockRepository_ListVisible_Call) RunAndReturn(run func(ctx context.Context, chatID uuid.UUID, callerID uuid.UUID, after *domain.Cursor, limit int) (domain.Page[domain.Message], error)) *MockRepository_ListVisible_Call { + _c.Call.Return(run) + return _c +} + +// Replay provides a mock function for the type MockRepository +func (_mock *MockRepository) Replay(ctx context.Context, draft domain.MessageDraft) (domain.Message, bool, error) { + ret := _mock.Called(ctx, draft) + + if len(ret) == 0 { + panic("no return value specified for Replay") + } + + var r0 domain.Message + var r1 bool + var r2 error + if returnFunc, ok := ret.Get(0).(func(context.Context, domain.MessageDraft) (domain.Message, bool, error)); ok { + return returnFunc(ctx, draft) + } + if returnFunc, ok := ret.Get(0).(func(context.Context, domain.MessageDraft) domain.Message); ok { + r0 = returnFunc(ctx, draft) + } else { + r0 = ret.Get(0).(domain.Message) + } + if returnFunc, ok := ret.Get(1).(func(context.Context, domain.MessageDraft) bool); ok { + r1 = returnFunc(ctx, draft) + } else { + r1 = ret.Get(1).(bool) + } + if returnFunc, ok := ret.Get(2).(func(context.Context, domain.MessageDraft) error); ok { + r2 = returnFunc(ctx, draft) + } else { + r2 = ret.Error(2) + } + return r0, r1, r2 +} + +// MockRepository_Replay_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Replay' +type MockRepository_Replay_Call struct { + *mock.Call +} + +// Replay is a helper method to define mock.On call +// - ctx context.Context +// - draft domain.MessageDraft +func (_e *MockRepository_Expecter) Replay(ctx any, draft any) *MockRepository_Replay_Call { + return &MockRepository_Replay_Call{Call: _e.mock.On("Replay", ctx, draft)} +} + +func (_c *MockRepository_Replay_Call) Run(run func(ctx context.Context, draft domain.MessageDraft)) *MockRepository_Replay_Call { + _c.Call.Run(func(args mock.Arguments) { + var arg0 context.Context + if args[0] != nil { + arg0 = args[0].(context.Context) + } + var arg1 domain.MessageDraft + if args[1] != nil { + arg1 = args[1].(domain.MessageDraft) + } + run( + arg0, + arg1, + ) + }) + return _c +} + +func (_c *MockRepository_Replay_Call) Return(message domain.Message, b bool, err error) *MockRepository_Replay_Call { + _c.Call.Return(message, b, err) + return _c +} + +func (_c *MockRepository_Replay_Call) RunAndReturn(run func(ctx context.Context, draft domain.MessageDraft) (domain.Message, bool, error)) *MockRepository_Replay_Call { + _c.Call.Return(run) + return _c +} diff --git a/internal/service/message/service.go b/internal/service/message/service.go new file mode 100644 index 0000000..45bc589 --- /dev/null +++ b/internal/service/message/service.go @@ -0,0 +1,118 @@ +package message + +import ( + "context" + "fmt" + + "github.com/google/uuid" + + "mtusi-messenger/internal/domain" +) + +type Repository interface { + IsChatMember(ctx context.Context, chatID, userID uuid.UUID) (bool, error) + // Replay returns the stored message for a live Idempotency-Key. It must be + // checked before attachment-state validation: a message that was accepted + // while the attachment was queued keeps replaying as 201 even after the + // attachment later fails. + Replay(ctx context.Context, draft domain.MessageDraft) (domain.Message, bool, error) + Create(ctx context.Context, draft domain.MessageDraft) (domain.Message, error) + ListVisible( + ctx context.Context, + chatID, callerID uuid.UUID, + after *domain.Cursor, + limit int, + ) (domain.Page[domain.Message], error) +} + +// AttachmentChecker validates that requested attachments exist in the chat and +// are ready. The contract returns 404 for unknown/foreign IDs and 409 for +// attachments that cannot be linked. +type AttachmentChecker interface { + ListStates(ctx context.Context, chatID uuid.UUID, ids []uuid.UUID) ([]domain.AttachmentState, error) +} + +type Service struct { + messages Repository + attachments AttachmentChecker +} + +func NewService(messages Repository, attachments AttachmentChecker) *Service { + return &Service{messages: messages, attachments: attachments} +} + +func (s *Service) Send(ctx context.Context, draft domain.MessageDraft) (domain.Message, error) { + if err := draft.Validate(); err != nil { + return domain.Message{}, err + } + + member, err := s.messages.IsChatMember(ctx, draft.ChatID, draft.SenderID) + if err != nil { + return domain.Message{}, fmt.Errorf("check chat membership: %w", err) + } + + if !member { + return domain.Message{}, fmt.Errorf("%w: chat is not visible", domain.ErrNotFound) + } + + replayed, found, err := s.messages.Replay(ctx, draft) + if err != nil { + return domain.Message{}, fmt.Errorf("replay message: %w", err) + } + + if found { + return replayed, nil + } + + if len(draft.AttachmentIDs) > 0 { + if s.attachments == nil { + return domain.Message{}, fmt.Errorf("attachment checker is not configured: %w", domain.ErrUnavailable) + } + + states, err := s.attachments.ListStates(ctx, draft.ChatID, draft.AttachmentIDs) + if err != nil { + return domain.Message{}, fmt.Errorf("check attachments: %w", err) + } + + if len(states) != len(draft.AttachmentIDs) { + return domain.Message{}, fmt.Errorf("%w: attachment is not visible", domain.ErrNotFound) + } + + for _, state := range states { + switch state.Status { + case domain.AttachmentQueued, domain.AttachmentProcessing, domain.AttachmentReady: + // Accepted work is linkable by contract. + default: + return domain.Message{}, fmt.Errorf( + "%w: attachment %s is %s", + domain.ErrConflict, state.ID, state.Status, + ) + } + } + } + + sent, err := s.messages.Create(ctx, draft) + if err != nil { + return domain.Message{}, fmt.Errorf("create message: %w", err) + } + + return sent, nil +} + +func (s *Service) History( + ctx context.Context, + callerID, chatID uuid.UUID, + after *domain.Cursor, + limit int, +) (domain.Page[domain.Message], error) { + if after != nil && !after.BelongsTo(chatID) { + return domain.Page[domain.Message]{}, fmt.Errorf("cursor is bound to another chat: %w", domain.ErrInvalidCursor) + } + + page, err := s.messages.ListVisible(ctx, chatID, callerID, after, limit) + if err != nil { + return domain.Page[domain.Message]{}, fmt.Errorf("list messages: %w", err) + } + + return page, nil +} diff --git a/internal/service/message/service_test.go b/internal/service/message/service_test.go new file mode 100644 index 0000000..afa9f05 --- /dev/null +++ b/internal/service/message/service_test.go @@ -0,0 +1,261 @@ +package message_test + +import ( + "errors" + "testing" + "time" + + "github.com/google/uuid" + "github.com/stretchr/testify/mock" + "github.com/stretchr/testify/suite" + + "mtusi-messenger/internal/domain" + "mtusi-messenger/internal/service/message" + "mtusi-messenger/internal/service/message/mocks" +) + +var errRepository = errors.New("repository is unavailable") + +type ServiceSuite struct { + suite.Suite + + messages *mocks.MockRepository + attachments *mocks.MockAttachmentChecker + service *message.Service + caller uuid.UUID + chatID uuid.UUID + now time.Time +} + +func TestServiceSuite(t *testing.T) { + t.Parallel() + suite.Run(t, new(ServiceSuite)) +} + +func (s *ServiceSuite) SetupTest() { + s.messages = mocks.NewMockRepository(s.T()) + s.attachments = mocks.NewMockAttachmentChecker(s.T()) + s.service = message.NewService(s.messages, s.attachments) + s.caller = uuid.New() + s.chatID = uuid.New() + s.now = time.Date(2026, 9, 1, 12, 0, 0, 0, time.UTC) + s.messages.EXPECT().Replay(mock.Anything, mock.Anything). + Return(domain.Message{}, false, nil).Maybe() +} + +func (s *ServiceSuite) draft() domain.MessageDraft { + return domain.MessageDraft{ + ChatID: s.chatID, + SenderID: s.caller, + Text: "Привет, Боб!", + Idempotency: domain.MessageIdempotency{Key: "service-suite-key"}, + } +} + +func (s *ServiceSuite) TestSendReturnsStoredMessage() { + draft := s.draft() + stored := domain.Message{ + ID: uuid.New(), + ChatID: draft.ChatID, + SenderID: draft.SenderID, + Text: draft.Text, + CreatedAt: s.now, + } + + s.messages.EXPECT().IsChatMember(s.T().Context(), draft.ChatID, draft.SenderID).Return(true, nil).Once() + s.messages.EXPECT().Create(s.T().Context(), draft).Return(stored, nil).Once() + + got, err := s.service.Send(s.T().Context(), draft) + s.Require().NoError(err) + s.Equal(stored, got) +} + +func (s *ServiceSuite) TestSendRejectsWhitespaceTextWithoutRepositoryCall() { + draft := s.draft() + draft.Text = " \t\n " + + _, err := s.service.Send(s.T().Context(), draft) + s.Require().ErrorIs(err, domain.ErrValidation, + "пробельный текст не проходит схему контракта, но проходит minLength") +} + +func (s *ServiceSuite) TestSendPropagatesNotFoundForOutsider() { + draft := s.draft() + + s.messages.EXPECT().IsChatMember(s.T().Context(), draft.ChatID, draft.SenderID).Return(false, nil).Once() + + _, err := s.service.Send(s.T().Context(), draft) + s.Require().ErrorIs(err, domain.ErrNotFound, + "посторонний не должен узнать о существовании чата") +} + +func (s *ServiceSuite) TestHistoryPassesNilCursorOnFirstPage() { + stored := domain.Message{ + ID: uuid.New(), + ChatID: s.chatID, + SenderID: s.caller, + Text: "первое", + CreatedAt: s.now, + } + + s.messages.EXPECT(). + ListVisible(s.T().Context(), s.chatID, s.caller, (*domain.Cursor)(nil), domain.DefaultPageLimit). + Return(domain.Page[domain.Message]{Items: []domain.Message{stored}}, nil). + Once() + + page, err := s.service.History(s.T().Context(), s.caller, s.chatID, nil, domain.DefaultPageLimit) + s.Require().NoError(err) + s.Equal([]domain.Message{stored}, page.Items) + s.Nil(page.Next) +} + +func (s *ServiceSuite) TestHistoryRejectsCursorFromAnotherChat() { + foreign := &domain.Cursor{Scope: uuid.New(), CreatedAt: s.now, ID: uuid.New()} + + _, err := s.service.History(s.T().Context(), s.caller, s.chatID, foreign, domain.DefaultPageLimit) + s.Require().ErrorIs(err, domain.ErrInvalidCursor, + "контракт требует 400 на курсор от другого чата") +} + +func (s *ServiceSuite) TestHistoryAcceptsCursorOfSameChat() { + own := &domain.Cursor{Scope: s.chatID, CreatedAt: s.now, ID: uuid.New()} + + s.messages.EXPECT(). + ListVisible(s.T().Context(), s.chatID, s.caller, own, 7). + Return(domain.Page[domain.Message]{}, nil). + Once() + + _, err := s.service.History(s.T().Context(), s.caller, s.chatID, own, 7) + s.Require().NoError(err) +} + +func (s *ServiceSuite) TestHistoryPropagatesNotFoundForOutsider() { + s.messages.EXPECT(). + ListVisible(s.T().Context(), s.chatID, s.caller, (*domain.Cursor)(nil), domain.DefaultPageLimit). + Return(domain.Page[domain.Message]{}, domain.ErrNotFound). + Once() + + _, err := s.service.History(s.T().Context(), s.caller, s.chatID, nil, domain.DefaultPageLimit) + s.Require().ErrorIs(err, domain.ErrNotFound) +} + +func (s *ServiceSuite) TestHistoryWrapsRepositoryFailure() { + s.messages.EXPECT(). + ListVisible(s.T().Context(), s.chatID, s.caller, (*domain.Cursor)(nil), domain.DefaultPageLimit). + Return(domain.Page[domain.Message]{}, errRepository). + Once() + + _, err := s.service.History(s.T().Context(), s.caller, s.chatID, nil, domain.DefaultPageLimit) + s.Require().ErrorIs(err, errRepository) +} + +func (s *ServiceSuite) TestSendAcceptsReadyAttachment() { + attachmentID := uuid.New() + draft := s.draft() + draft.AttachmentIDs = []uuid.UUID{attachmentID} + stored := domain.Message{ + ID: uuid.New(), ChatID: draft.ChatID, SenderID: draft.SenderID, + AttachmentIDs: []uuid.UUID{attachmentID}, CreatedAt: s.now, + } + + s.messages.EXPECT().IsChatMember(s.T().Context(), draft.ChatID, draft.SenderID).Return(true, nil).Once() + s.attachments.EXPECT(). + ListStates(s.T().Context(), draft.ChatID, []uuid.UUID{attachmentID}). + Return([]domain.AttachmentState{{ID: attachmentID, Status: domain.AttachmentReady}}, nil). + Once() + s.messages.EXPECT().Create(s.T().Context(), draft).Return(stored, nil).Once() + + got, err := s.service.Send(s.T().Context(), draft) + s.Require().NoError(err) + s.Equal([]uuid.UUID{attachmentID}, got.AttachmentIDs) +} + +func (s *ServiceSuite) TestSendReplaysBeforeAttachmentValidation() { + draft := s.draft() + draft.AttachmentIDs = []uuid.UUID{uuid.New()} + stored := domain.Message{ + ID: uuid.New(), ChatID: draft.ChatID, SenderID: draft.SenderID, + Text: draft.Text, AttachmentIDs: draft.AttachmentIDs, CreatedAt: s.now, + } + + // The stored key is authoritative even if the attachment has since failed; + // ListStates must not be consulted on a replay. + s.messages.ExpectedCalls = nil + s.messages.EXPECT().IsChatMember(s.T().Context(), draft.ChatID, draft.SenderID).Return(true, nil).Once() + s.messages.EXPECT().Replay(s.T().Context(), draft).Return(stored, true, nil).Once() + + got, err := s.service.Send(s.T().Context(), draft) + s.Require().NoError(err) + s.Equal(stored, got) +} + +func (s *ServiceSuite) TestSendRejectsFailedAttachment() { + attachmentID := uuid.New() + draft := s.draft() + draft.AttachmentIDs = []uuid.UUID{attachmentID} + + s.messages.EXPECT().IsChatMember(s.T().Context(), draft.ChatID, draft.SenderID).Return(true, nil).Once() + s.attachments.EXPECT(). + ListStates(s.T().Context(), draft.ChatID, []uuid.UUID{attachmentID}). + Return([]domain.AttachmentState{{ID: attachmentID, Status: domain.AttachmentFailed}}, nil). + Once() + + _, err := s.service.Send(s.T().Context(), draft) + s.Require().ErrorIs(err, domain.ErrConflict) +} + +func (s *ServiceSuite) TestSendAllowsAttachmentOnlyMessage() { + attachmentID := uuid.New() + draft := s.draft() + draft.Text = "" + draft.AttachmentIDs = []uuid.UUID{attachmentID} + + s.messages.EXPECT().IsChatMember(s.T().Context(), draft.ChatID, draft.SenderID).Return(true, nil).Once() + s.attachments.EXPECT(). + ListStates(s.T().Context(), draft.ChatID, []uuid.UUID{attachmentID}). + Return([]domain.AttachmentState{{ID: attachmentID, Status: domain.AttachmentReady}}, nil). + Once() + s.messages.EXPECT().Create(s.T().Context(), draft).Return(domain.Message{AttachmentIDs: draft.AttachmentIDs}, nil).Once() + + _, err := s.service.Send(s.T().Context(), draft) + s.Require().NoError(err) +} + +func (s *ServiceSuite) TestSendRejectsForeignAttachment() { + attachmentID := uuid.New() + draft := s.draft() + draft.AttachmentIDs = []uuid.UUID{attachmentID} + + s.messages.EXPECT().IsChatMember(s.T().Context(), draft.ChatID, draft.SenderID).Return(true, nil).Once() + s.attachments.EXPECT(). + ListStates(s.T().Context(), draft.ChatID, []uuid.UUID{attachmentID}). + Return([]domain.AttachmentState{}, nil). + Once() + + _, err := s.service.Send(s.T().Context(), draft) + s.Require().ErrorIs(err, domain.ErrNotFound) +} + +func (s *ServiceSuite) TestSendRejectsPendingAttachment() { + attachmentID := uuid.New() + draft := s.draft() + draft.AttachmentIDs = []uuid.UUID{attachmentID} + + s.messages.EXPECT().IsChatMember(s.T().Context(), draft.ChatID, draft.SenderID).Return(true, nil).Once() + s.attachments.EXPECT(). + ListStates(s.T().Context(), draft.ChatID, []uuid.UUID{attachmentID}). + Return([]domain.AttachmentState{{ID: attachmentID, Status: domain.AttachmentPending}}, nil). + Once() + + _, err := s.service.Send(s.T().Context(), draft) + s.Require().ErrorIs(err, domain.ErrConflict) +} + +func (s *ServiceSuite) TestSendRejectsDuplicateAttachments() { + id := uuid.New() + draft := s.draft() + draft.AttachmentIDs = []uuid.UUID{id, id} + + _, err := s.service.Send(s.T().Context(), draft) + s.Require().ErrorIs(err, domain.ErrValidation) +} diff --git a/internal/service/session/mocks/Repository.go b/internal/service/session/mocks/Repository.go new file mode 100644 index 0000000..76925a5 --- /dev/null +++ b/internal/service/session/mocks/Repository.go @@ -0,0 +1,310 @@ +// Code generated by mockery; DO NOT EDIT. +// github.com/vektra/mockery +// template: testify + +package mocks + +import ( + "context" + "mtusi-messenger/internal/domain" + + "github.com/google/uuid" + mock "github.com/stretchr/testify/mock" +) + +// NewMockRepository creates a new instance of MockRepository. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewMockRepository(t interface { + mock.TestingT + Cleanup(func()) +}) *MockRepository { + if helper, ok := t.(interface{ Helper() }); ok { + helper.Helper() + } + + mock := &MockRepository{} + mock.Mock.Test(t) + + t.Cleanup(func() { + if helper, ok := t.(interface{ Helper() }); ok { + helper.Helper() + } + mock.AssertExpectations(t) + }) + + return mock +} + +// MockRepository is an autogenerated mock type for the Repository type +type MockRepository struct { + mock.Mock +} + +type MockRepository_Expecter struct { + mock *mock.Mock +} + +func (_m *MockRepository) EXPECT() *MockRepository_Expecter { + return &MockRepository_Expecter{mock: &_m.Mock} +} + +// Create provides a mock function for the type MockRepository +func (_mock *MockRepository) Create(ctx context.Context, session domain.NewSession) (domain.Session, error) { + ret := _mock.Called(ctx, session) + + if len(ret) == 0 { + panic("no return value specified for Create") + } + + var r0 domain.Session + var r1 error + if returnFunc, ok := ret.Get(0).(func(context.Context, domain.NewSession) (domain.Session, error)); ok { + return returnFunc(ctx, session) + } + if returnFunc, ok := ret.Get(0).(func(context.Context, domain.NewSession) domain.Session); ok { + r0 = returnFunc(ctx, session) + } else { + r0 = ret.Get(0).(domain.Session) + } + if returnFunc, ok := ret.Get(1).(func(context.Context, domain.NewSession) error); ok { + r1 = returnFunc(ctx, session) + } else { + r1 = ret.Error(1) + } + return r0, r1 +} + +// MockRepository_Create_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Create' +type MockRepository_Create_Call struct { + *mock.Call +} + +// Create is a helper method to define mock.On call +// - ctx context.Context +// - session domain.NewSession +func (_e *MockRepository_Expecter) Create(ctx any, session any) *MockRepository_Create_Call { + return &MockRepository_Create_Call{Call: _e.mock.On("Create", ctx, session)} +} + +func (_c *MockRepository_Create_Call) Run(run func(ctx context.Context, session domain.NewSession)) *MockRepository_Create_Call { + _c.Call.Run(func(args mock.Arguments) { + var arg0 context.Context + if args[0] != nil { + arg0 = args[0].(context.Context) + } + var arg1 domain.NewSession + if args[1] != nil { + arg1 = args[1].(domain.NewSession) + } + run( + arg0, + arg1, + ) + }) + return _c +} + +func (_c *MockRepository_Create_Call) Return(session1 domain.Session, err error) *MockRepository_Create_Call { + _c.Call.Return(session1, err) + return _c +} + +func (_c *MockRepository_Create_Call) RunAndReturn(run func(ctx context.Context, session domain.NewSession) (domain.Session, error)) *MockRepository_Create_Call { + _c.Call.Return(run) + return _c +} + +// Credentials provides a mock function for the type MockRepository +func (_mock *MockRepository) Credentials(ctx context.Context, username string) (domain.UserCredentials, error) { + ret := _mock.Called(ctx, username) + + if len(ret) == 0 { + panic("no return value specified for Credentials") + } + + var r0 domain.UserCredentials + var r1 error + if returnFunc, ok := ret.Get(0).(func(context.Context, string) (domain.UserCredentials, error)); ok { + return returnFunc(ctx, username) + } + if returnFunc, ok := ret.Get(0).(func(context.Context, string) domain.UserCredentials); ok { + r0 = returnFunc(ctx, username) + } else { + r0 = ret.Get(0).(domain.UserCredentials) + } + if returnFunc, ok := ret.Get(1).(func(context.Context, string) error); ok { + r1 = returnFunc(ctx, username) + } else { + r1 = ret.Error(1) + } + return r0, r1 +} + +// MockRepository_Credentials_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Credentials' +type MockRepository_Credentials_Call struct { + *mock.Call +} + +// Credentials is a helper method to define mock.On call +// - ctx context.Context +// - username string +func (_e *MockRepository_Expecter) Credentials(ctx any, username any) *MockRepository_Credentials_Call { + return &MockRepository_Credentials_Call{Call: _e.mock.On("Credentials", ctx, username)} +} + +func (_c *MockRepository_Credentials_Call) Run(run func(ctx context.Context, username string)) *MockRepository_Credentials_Call { + _c.Call.Run(func(args mock.Arguments) { + var arg0 context.Context + if args[0] != nil { + arg0 = args[0].(context.Context) + } + var arg1 string + if args[1] != nil { + arg1 = args[1].(string) + } + run( + arg0, + arg1, + ) + }) + return _c +} + +func (_c *MockRepository_Credentials_Call) Return(userCredentials domain.UserCredentials, err error) *MockRepository_Credentials_Call { + _c.Call.Return(userCredentials, err) + return _c +} + +func (_c *MockRepository_Credentials_Call) RunAndReturn(run func(ctx context.Context, username string) (domain.UserCredentials, error)) *MockRepository_Credentials_Call { + _c.Call.Return(run) + return _c +} + +// Resolve provides a mock function for the type MockRepository +func (_mock *MockRepository) Resolve(ctx context.Context, tokenHash []byte) (domain.Session, error) { + ret := _mock.Called(ctx, tokenHash) + + if len(ret) == 0 { + panic("no return value specified for Resolve") + } + + var r0 domain.Session + var r1 error + if returnFunc, ok := ret.Get(0).(func(context.Context, []byte) (domain.Session, error)); ok { + return returnFunc(ctx, tokenHash) + } + if returnFunc, ok := ret.Get(0).(func(context.Context, []byte) domain.Session); ok { + r0 = returnFunc(ctx, tokenHash) + } else { + r0 = ret.Get(0).(domain.Session) + } + if returnFunc, ok := ret.Get(1).(func(context.Context, []byte) error); ok { + r1 = returnFunc(ctx, tokenHash) + } else { + r1 = ret.Error(1) + } + return r0, r1 +} + +// MockRepository_Resolve_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Resolve' +type MockRepository_Resolve_Call struct { + *mock.Call +} + +// Resolve is a helper method to define mock.On call +// - ctx context.Context +// - tokenHash []byte +func (_e *MockRepository_Expecter) Resolve(ctx any, tokenHash any) *MockRepository_Resolve_Call { + return &MockRepository_Resolve_Call{Call: _e.mock.On("Resolve", ctx, tokenHash)} +} + +func (_c *MockRepository_Resolve_Call) Run(run func(ctx context.Context, tokenHash []byte)) *MockRepository_Resolve_Call { + _c.Call.Run(func(args mock.Arguments) { + var arg0 context.Context + if args[0] != nil { + arg0 = args[0].(context.Context) + } + var arg1 []byte + if args[1] != nil { + arg1 = args[1].([]byte) + } + run( + arg0, + arg1, + ) + }) + return _c +} + +func (_c *MockRepository_Resolve_Call) Return(session domain.Session, err error) *MockRepository_Resolve_Call { + _c.Call.Return(session, err) + return _c +} + +func (_c *MockRepository_Resolve_Call) RunAndReturn(run func(ctx context.Context, tokenHash []byte) (domain.Session, error)) *MockRepository_Resolve_Call { + _c.Call.Return(run) + return _c +} + +// Revoke provides a mock function for the type MockRepository +func (_mock *MockRepository) Revoke(ctx context.Context, userID uuid.UUID, tokenHash []byte) error { + ret := _mock.Called(ctx, userID, tokenHash) + + if len(ret) == 0 { + panic("no return value specified for Revoke") + } + + var r0 error + if returnFunc, ok := ret.Get(0).(func(context.Context, uuid.UUID, []byte) error); ok { + r0 = returnFunc(ctx, userID, tokenHash) + } else { + r0 = ret.Error(0) + } + return r0 +} + +// MockRepository_Revoke_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Revoke' +type MockRepository_Revoke_Call struct { + *mock.Call +} + +// Revoke is a helper method to define mock.On call +// - ctx context.Context +// - userID uuid.UUID +// - tokenHash []byte +func (_e *MockRepository_Expecter) Revoke(ctx any, userID any, tokenHash any) *MockRepository_Revoke_Call { + return &MockRepository_Revoke_Call{Call: _e.mock.On("Revoke", ctx, userID, tokenHash)} +} + +func (_c *MockRepository_Revoke_Call) Run(run func(ctx context.Context, userID uuid.UUID, tokenHash []byte)) *MockRepository_Revoke_Call { + _c.Call.Run(func(args mock.Arguments) { + var arg0 context.Context + if args[0] != nil { + arg0 = args[0].(context.Context) + } + var arg1 uuid.UUID + if args[1] != nil { + arg1 = args[1].(uuid.UUID) + } + var arg2 []byte + if args[2] != nil { + arg2 = args[2].([]byte) + } + run( + arg0, + arg1, + arg2, + ) + }) + return _c +} + +func (_c *MockRepository_Revoke_Call) Return(err error) *MockRepository_Revoke_Call { + _c.Call.Return(err) + return _c +} + +func (_c *MockRepository_Revoke_Call) RunAndReturn(run func(ctx context.Context, userID uuid.UUID, tokenHash []byte) error) *MockRepository_Revoke_Call { + _c.Call.Return(run) + return _c +} diff --git a/internal/service/session/mocks/Tokens.go b/internal/service/session/mocks/Tokens.go new file mode 100644 index 0000000..f5724a5 --- /dev/null +++ b/internal/service/session/mocks/Tokens.go @@ -0,0 +1,168 @@ +// Code generated by mockery; DO NOT EDIT. +// github.com/vektra/mockery +// template: testify + +package mocks + +import ( + mock "github.com/stretchr/testify/mock" +) + +// NewMockTokens creates a new instance of MockTokens. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewMockTokens(t interface { + mock.TestingT + Cleanup(func()) +}) *MockTokens { + if helper, ok := t.(interface{ Helper() }); ok { + helper.Helper() + } + + mock := &MockTokens{} + mock.Mock.Test(t) + + t.Cleanup(func() { + if helper, ok := t.(interface{ Helper() }); ok { + helper.Helper() + } + mock.AssertExpectations(t) + }) + + return mock +} + +// MockTokens is an autogenerated mock type for the Tokens type +type MockTokens struct { + mock.Mock +} + +type MockTokens_Expecter struct { + mock *mock.Mock +} + +func (_m *MockTokens) EXPECT() *MockTokens_Expecter { + return &MockTokens_Expecter{mock: &_m.Mock} +} + +// Generate provides a mock function for the type MockTokens +func (_mock *MockTokens) Generate() (string, []byte, error) { + ret := _mock.Called() + + if len(ret) == 0 { + panic("no return value specified for Generate") + } + + var r0 string + var r1 []byte + var r2 error + if returnFunc, ok := ret.Get(0).(func() (string, []byte, error)); ok { + return returnFunc() + } + if returnFunc, ok := ret.Get(0).(func() string); ok { + r0 = returnFunc() + } else { + r0 = ret.Get(0).(string) + } + if returnFunc, ok := ret.Get(1).(func() []byte); ok { + r1 = returnFunc() + } else { + if ret.Get(1) != nil { + r1 = ret.Get(1).([]byte) + } + } + if returnFunc, ok := ret.Get(2).(func() error); ok { + r2 = returnFunc() + } else { + r2 = ret.Error(2) + } + return r0, r1, r2 +} + +// MockTokens_Generate_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Generate' +type MockTokens_Generate_Call struct { + *mock.Call +} + +// Generate is a helper method to define mock.On call +func (_e *MockTokens_Expecter) Generate() *MockTokens_Generate_Call { + return &MockTokens_Generate_Call{Call: _e.mock.On("Generate")} +} + +func (_c *MockTokens_Generate_Call) Run(run func()) *MockTokens_Generate_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *MockTokens_Generate_Call) Return(s string, bytes []byte, err error) *MockTokens_Generate_Call { + _c.Call.Return(s, bytes, err) + return _c +} + +func (_c *MockTokens_Generate_Call) RunAndReturn(run func() (string, []byte, error)) *MockTokens_Generate_Call { + _c.Call.Return(run) + return _c +} + +// Hash provides a mock function for the type MockTokens +func (_mock *MockTokens) Hash(raw string) ([]byte, error) { + ret := _mock.Called(raw) + + if len(ret) == 0 { + panic("no return value specified for Hash") + } + + var r0 []byte + var r1 error + if returnFunc, ok := ret.Get(0).(func(string) ([]byte, error)); ok { + return returnFunc(raw) + } + if returnFunc, ok := ret.Get(0).(func(string) []byte); ok { + r0 = returnFunc(raw) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]byte) + } + } + if returnFunc, ok := ret.Get(1).(func(string) error); ok { + r1 = returnFunc(raw) + } else { + r1 = ret.Error(1) + } + return r0, r1 +} + +// MockTokens_Hash_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Hash' +type MockTokens_Hash_Call struct { + *mock.Call +} + +// Hash is a helper method to define mock.On call +// - raw string +func (_e *MockTokens_Expecter) Hash(raw any) *MockTokens_Hash_Call { + return &MockTokens_Hash_Call{Call: _e.mock.On("Hash", raw)} +} + +func (_c *MockTokens_Hash_Call) Run(run func(raw string)) *MockTokens_Hash_Call { + _c.Call.Run(func(args mock.Arguments) { + var arg0 string + if args[0] != nil { + arg0 = args[0].(string) + } + run( + arg0, + ) + }) + return _c +} + +func (_c *MockTokens_Hash_Call) Return(bytes []byte, err error) *MockTokens_Hash_Call { + _c.Call.Return(bytes, err) + return _c +} + +func (_c *MockTokens_Hash_Call) RunAndReturn(run func(raw string) ([]byte, error)) *MockTokens_Hash_Call { + _c.Call.Return(run) + return _c +} diff --git a/internal/service/session/service.go b/internal/service/session/service.go new file mode 100644 index 0000000..6b57aba --- /dev/null +++ b/internal/service/session/service.go @@ -0,0 +1,95 @@ +package session + +import ( + "context" + "fmt" + "time" + + "github.com/google/uuid" + + "mtusi-messenger/internal/domain" + "mtusi-messenger/internal/platform/password" +) + +type Repository interface { + Credentials(ctx context.Context, username string) (domain.UserCredentials, error) + Create(ctx context.Context, session domain.NewSession) (domain.Session, error) + Resolve(ctx context.Context, tokenHash []byte) (domain.Session, error) + Revoke(ctx context.Context, userID uuid.UUID, tokenHash []byte) error +} + +type Tokens interface { + Generate() (string, []byte, error) + Hash(raw string) ([]byte, error) +} + +type Service struct { + sessions Repository + tokens Tokens + ttl time.Duration +} + +func NewService(sessions Repository, tokens Tokens, ttl time.Duration) *Service { + return &Service{sessions: sessions, tokens: tokens, ttl: ttl} +} + +func (s *Service) Authenticate(ctx context.Context, username, plain string) (domain.User, error) { + credentials, err := s.sessions.Credentials(ctx, username) + if err != nil { + return domain.User{}, fmt.Errorf("authenticate: %w", err) + } + + if !password.Verify(plain, credentials.PasswordHash) { + return domain.User{}, fmt.Errorf("authenticate: %w", domain.ErrUnauthenticated) + } + + return credentials.User, nil +} + +func (s *Service) Resolve(ctx context.Context, raw string) (domain.User, error) { + hash, err := s.tokens.Hash(raw) + if err != nil { + return domain.User{}, fmt.Errorf("resolve session: %w", domain.ErrUnauthenticated) + } + + session, err := s.sessions.Resolve(ctx, hash) + if err != nil { + return domain.User{}, fmt.Errorf("resolve session: %w", err) + } + + return session.User, nil +} + +func (s *Service) Create(ctx context.Context, user domain.User) (domain.Session, error) { + raw, hash, err := s.tokens.Generate() + if err != nil { + return domain.Session{}, fmt.Errorf("generate token: %w", err) + } + + session, err := s.sessions.Create(ctx, domain.NewSession{ + TokenHash: hash, + UserID: user.ID, + ExpiresAt: time.Now().UTC().Add(s.ttl), + }) + if err != nil { + return domain.Session{}, fmt.Errorf("create session: %w", err) + } + + session.Token = raw + session.User = user + + return session, nil +} + +func (s *Service) Revoke(ctx context.Context, userID uuid.UUID, raw string) error { + hash, err := s.tokens.Hash(raw) + if err != nil { + return fmt.Errorf("revoke session: %w", domain.ErrUnauthenticated) + } + + if err := s.sessions.Revoke(ctx, userID, hash); err != nil { + return fmt.Errorf("revoke session: %w", err) + } + + return nil +} diff --git a/internal/service/session/service_test.go b/internal/service/session/service_test.go new file mode 100644 index 0000000..8d062cc --- /dev/null +++ b/internal/service/session/service_test.go @@ -0,0 +1,146 @@ +package session_test + +import ( + "bytes" + "errors" + "testing" + "time" + + "github.com/google/uuid" + "github.com/stretchr/testify/mock" + "github.com/stretchr/testify/suite" + + "mtusi-messenger/internal/domain" + "mtusi-messenger/internal/platform/password" + "mtusi-messenger/internal/service/session" + "mtusi-messenger/internal/service/session/mocks" +) + +type ServiceSuite struct { + suite.Suite + + sessions *mocks.MockRepository + tokens *mocks.MockTokens + service *session.Service + ttl time.Duration + user domain.User +} + +func TestServiceSuite(t *testing.T) { + t.Parallel() + suite.Run(t, new(ServiceSuite)) +} + +func (s *ServiceSuite) SetupTest() { + s.sessions = mocks.NewMockRepository(s.T()) + s.tokens = mocks.NewMockTokens(s.T()) + s.ttl = time.Hour + s.service = session.NewService(s.sessions, s.tokens, s.ttl) + s.user = domain.User{ + ID: uuid.New(), + Username: "alice", + DisplayName: "Алиса", + CreatedAt: time.Now().UTC(), + } +} + +func (s *ServiceSuite) TestResolveHashesTokenBeforeStorage() { + hash := []byte("hashed-token") + stored := domain.Session{ExpiresAt: time.Now().Add(time.Hour), User: s.user} + + s.tokens.EXPECT().Hash("raw-token").Return(hash, nil).Once() + s.sessions.EXPECT().Resolve(mock.Anything, hash).Return(stored, nil).Once() + + got, err := s.service.Resolve(s.T().Context(), "raw-token") + s.Require().NoError(err) + s.Equal(s.user, got) +} + +func (s *ServiceSuite) TestResolveRejectsMalformedTokenWithoutStorage() { + s.tokens.EXPECT().Hash("garbage").Return(nil, errors.New("invalid token")).Once() + + _, err := s.service.Resolve(s.T().Context(), "garbage") + s.Require().ErrorIs(err, domain.ErrUnauthenticated) +} + +func (s *ServiceSuite) TestCreateGeneratesTokenAndReturnsIt() { + hash := []byte("hashed-token") + expiresAt := time.Now().Add(s.ttl) + + s.tokens.EXPECT().Generate().Return("raw-token", hash, nil).Once() + s.sessions.EXPECT(). + Create(mock.Anything, mock.MatchedBy(func(candidate domain.NewSession) bool { + return bytes.Equal(candidate.TokenHash, hash) && + candidate.UserID == s.user.ID && + candidate.ExpiresAt.After(time.Now()) + })). + Return(domain.Session{ExpiresAt: expiresAt}, nil). + Once() + + got, err := s.service.Create(s.T().Context(), s.user) + s.Require().NoError(err) + s.Equal("raw-token", got.Token) + s.Equal(s.user, got.User) + s.Equal(expiresAt, got.ExpiresAt) +} + +func (s *ServiceSuite) TestCreatePropagatesTokenGenerationError() { + s.tokens.EXPECT().Generate().Return("", nil, errors.New("no entropy")).Once() + + _, err := s.service.Create(s.T().Context(), s.user) + s.Require().Error(err) +} + +func (s *ServiceSuite) TestRevokeHashesTokenBeforeStorage() { + hash := []byte("hashed-token") + userID := uuid.New() + + s.tokens.EXPECT().Hash("raw-token").Return(hash, nil).Once() + s.sessions.EXPECT().Revoke(mock.Anything, userID, hash).Return(nil).Once() + + s.Require().NoError(s.service.Revoke(s.T().Context(), userID, "raw-token")) +} + +func (s *ServiceSuite) TestRevokeRejectsMalformedToken() { + s.tokens.EXPECT().Hash("garbage").Return(nil, errors.New("invalid token")).Once() + + err := s.service.Revoke(s.T().Context(), uuid.New(), "garbage") + s.Require().ErrorIs(err, domain.ErrUnauthenticated) +} + +func (s *ServiceSuite) TestAuthenticateVerifiesPassword() { + hash, err := password.Hash("secret-password-123") + s.Require().NoError(err) + + s.sessions.EXPECT(). + Credentials(mock.Anything, "alice"). + Return(domain.UserCredentials{User: s.user, PasswordHash: hash}, nil). + Once() + + got, err := s.service.Authenticate(s.T().Context(), "alice", "secret-password-123") + s.Require().NoError(err) + s.Equal(s.user, got) +} + +func (s *ServiceSuite) TestAuthenticateRejectsWrongPassword() { + hash, err := password.Hash("secret-password-123") + s.Require().NoError(err) + + s.sessions.EXPECT(). + Credentials(mock.Anything, "alice"). + Return(domain.UserCredentials{User: s.user, PasswordHash: hash}, nil). + Once() + + _, err = s.service.Authenticate(s.T().Context(), "alice", "wrong-password-value") + s.Require().ErrorIs(err, domain.ErrUnauthenticated) +} + +func (s *ServiceSuite) TestAuthenticatePropagatesUnknownUser() { + s.sessions.EXPECT(). + Credentials(mock.Anything, "nobody"). + Return(domain.UserCredentials{}, domain.ErrUnauthenticated). + Once() + + _, err := s.service.Authenticate(s.T().Context(), "nobody", "secret-password-123") + s.Require().ErrorIs(err, domain.ErrUnauthenticated) +} diff --git a/internal/service/user/mocks/Repository.go b/internal/service/user/mocks/Repository.go new file mode 100644 index 0000000..96978d3 --- /dev/null +++ b/internal/service/user/mocks/Repository.go @@ -0,0 +1,181 @@ +// Code generated by mockery; DO NOT EDIT. +// github.com/vektra/mockery +// template: testify + +package mocks + +import ( + "context" + "mtusi-messenger/internal/domain" + + "github.com/google/uuid" + mock "github.com/stretchr/testify/mock" +) + +// NewMockRepository creates a new instance of MockRepository. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewMockRepository(t interface { + mock.TestingT + Cleanup(func()) +}) *MockRepository { + if helper, ok := t.(interface{ Helper() }); ok { + helper.Helper() + } + + mock := &MockRepository{} + mock.Mock.Test(t) + + t.Cleanup(func() { + if helper, ok := t.(interface{ Helper() }); ok { + helper.Helper() + } + mock.AssertExpectations(t) + }) + + return mock +} + +// MockRepository is an autogenerated mock type for the Repository type +type MockRepository struct { + mock.Mock +} + +type MockRepository_Expecter struct { + mock *mock.Mock +} + +func (_m *MockRepository) EXPECT() *MockRepository_Expecter { + return &MockRepository_Expecter{mock: &_m.Mock} +} + +// Create provides a mock function for the type MockRepository +func (_mock *MockRepository) Create(ctx context.Context, draft domain.NewUser) (domain.User, error) { + ret := _mock.Called(ctx, draft) + + if len(ret) == 0 { + panic("no return value specified for Create") + } + + var r0 domain.User + var r1 error + if returnFunc, ok := ret.Get(0).(func(context.Context, domain.NewUser) (domain.User, error)); ok { + return returnFunc(ctx, draft) + } + if returnFunc, ok := ret.Get(0).(func(context.Context, domain.NewUser) domain.User); ok { + r0 = returnFunc(ctx, draft) + } else { + r0 = ret.Get(0).(domain.User) + } + if returnFunc, ok := ret.Get(1).(func(context.Context, domain.NewUser) error); ok { + r1 = returnFunc(ctx, draft) + } else { + r1 = ret.Error(1) + } + return r0, r1 +} + +// MockRepository_Create_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Create' +type MockRepository_Create_Call struct { + *mock.Call +} + +// Create is a helper method to define mock.On call +// - ctx context.Context +// - draft domain.NewUser +func (_e *MockRepository_Expecter) Create(ctx any, draft any) *MockRepository_Create_Call { + return &MockRepository_Create_Call{Call: _e.mock.On("Create", ctx, draft)} +} + +func (_c *MockRepository_Create_Call) Run(run func(ctx context.Context, draft domain.NewUser)) *MockRepository_Create_Call { + _c.Call.Run(func(args mock.Arguments) { + var arg0 context.Context + if args[0] != nil { + arg0 = args[0].(context.Context) + } + var arg1 domain.NewUser + if args[1] != nil { + arg1 = args[1].(domain.NewUser) + } + run( + arg0, + arg1, + ) + }) + return _c +} + +func (_c *MockRepository_Create_Call) Return(user domain.User, err error) *MockRepository_Create_Call { + _c.Call.Return(user, err) + return _c +} + +func (_c *MockRepository_Create_Call) RunAndReturn(run func(ctx context.Context, draft domain.NewUser) (domain.User, error)) *MockRepository_Create_Call { + _c.Call.Return(run) + return _c +} + +// GetByID provides a mock function for the type MockRepository +func (_mock *MockRepository) GetByID(ctx context.Context, id uuid.UUID) (domain.User, error) { + ret := _mock.Called(ctx, id) + + if len(ret) == 0 { + panic("no return value specified for GetByID") + } + + var r0 domain.User + var r1 error + if returnFunc, ok := ret.Get(0).(func(context.Context, uuid.UUID) (domain.User, error)); ok { + return returnFunc(ctx, id) + } + if returnFunc, ok := ret.Get(0).(func(context.Context, uuid.UUID) domain.User); ok { + r0 = returnFunc(ctx, id) + } else { + r0 = ret.Get(0).(domain.User) + } + if returnFunc, ok := ret.Get(1).(func(context.Context, uuid.UUID) error); ok { + r1 = returnFunc(ctx, id) + } else { + r1 = ret.Error(1) + } + return r0, r1 +} + +// MockRepository_GetByID_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetByID' +type MockRepository_GetByID_Call struct { + *mock.Call +} + +// GetByID is a helper method to define mock.On call +// - ctx context.Context +// - id uuid.UUID +func (_e *MockRepository_Expecter) GetByID(ctx any, id any) *MockRepository_GetByID_Call { + return &MockRepository_GetByID_Call{Call: _e.mock.On("GetByID", ctx, id)} +} + +func (_c *MockRepository_GetByID_Call) Run(run func(ctx context.Context, id uuid.UUID)) *MockRepository_GetByID_Call { + _c.Call.Run(func(args mock.Arguments) { + var arg0 context.Context + if args[0] != nil { + arg0 = args[0].(context.Context) + } + var arg1 uuid.UUID + if args[1] != nil { + arg1 = args[1].(uuid.UUID) + } + run( + arg0, + arg1, + ) + }) + return _c +} + +func (_c *MockRepository_GetByID_Call) Return(user domain.User, err error) *MockRepository_GetByID_Call { + _c.Call.Return(user, err) + return _c +} + +func (_c *MockRepository_GetByID_Call) RunAndReturn(run func(ctx context.Context, id uuid.UUID) (domain.User, error)) *MockRepository_GetByID_Call { + _c.Call.Return(run) + return _c +} diff --git a/internal/service/user/service.go b/internal/service/user/service.go new file mode 100644 index 0000000..57a0eb1 --- /dev/null +++ b/internal/service/user/service.go @@ -0,0 +1,55 @@ +package user + +import ( + "context" + "fmt" + + "github.com/google/uuid" + + "mtusi-messenger/internal/domain" + "mtusi-messenger/internal/platform/password" +) + +type Repository interface { + Create(ctx context.Context, draft domain.NewUser) (domain.User, error) + GetByID(ctx context.Context, id uuid.UUID) (domain.User, error) +} + +type Service struct { + users Repository +} + +func NewService(users Repository) *Service { + return &Service{users: users} +} + +func (s *Service) Register(ctx context.Context, draft domain.UserDraft) (domain.User, error) { + if err := draft.Validate(); err != nil { + return domain.User{}, err + } + + hash, err := password.Hash(draft.Password) + if err != nil { + return domain.User{}, fmt.Errorf("hash password: %w", err) + } + + user, err := s.users.Create(ctx, domain.NewUser{ + Username: draft.Username, + DisplayName: draft.DisplayName, + PasswordHash: hash, + }) + if err != nil { + return domain.User{}, fmt.Errorf("create user: %w", err) + } + + return user, nil +} + +func (s *Service) GetByID(ctx context.Context, id uuid.UUID) (domain.User, error) { + user, err := s.users.GetByID(ctx, id) + if err != nil { + return domain.User{}, fmt.Errorf("get user: %w", err) + } + + return user, nil +} diff --git a/internal/service/user/service_test.go b/internal/service/user/service_test.go new file mode 100644 index 0000000..f816e5b --- /dev/null +++ b/internal/service/user/service_test.go @@ -0,0 +1,104 @@ +package user_test + +import ( + "errors" + "testing" + "time" + + "github.com/google/uuid" + "github.com/stretchr/testify/mock" + "github.com/stretchr/testify/suite" + + "mtusi-messenger/internal/domain" + "mtusi-messenger/internal/service/user" + "mtusi-messenger/internal/service/user/mocks" +) + +var errRepository = errors.New("repository is unavailable") + +type ServiceSuite struct { + suite.Suite + + users *mocks.MockRepository + service *user.Service + now time.Time +} + +func TestServiceSuite(t *testing.T) { + t.Parallel() + suite.Run(t, new(ServiceSuite)) +} + +func (s *ServiceSuite) SetupTest() { + s.users = mocks.NewMockRepository(s.T()) + s.service = user.NewService(s.users) + s.now = time.Date(2026, 9, 1, 12, 0, 0, 0, time.UTC) +} + +func (s *ServiceSuite) TestRegisterHashesPasswordAndReturnsStoredUser() { + draft := domain.UserDraft{Username: "alice", DisplayName: "Алиса", Password: "very-secret-password"} + stored := domain.User{ + ID: uuid.New(), + Username: draft.Username, + DisplayName: draft.DisplayName, + CreatedAt: s.now, + } + + s.users.EXPECT(). + Create(s.T().Context(), mock.MatchedBy(func(candidate domain.NewUser) bool { + return candidate.Username == draft.Username && + candidate.DisplayName == draft.DisplayName && + candidate.PasswordHash != "" && + candidate.PasswordHash != draft.Password + })). + Return(stored, nil). + Once() + + got, err := s.service.Register(s.T().Context(), draft) + s.Require().NoError(err) + s.Equal(stored, got, "сервис отдаёт то, что присвоило хранилище") +} + +func (s *ServiceSuite) TestRegisterRejectsBlankDisplayNameWithoutRepositoryCall() { + draft := domain.UserDraft{Username: "alice", DisplayName: " ", Password: "very-secret-password"} + + _, err := s.service.Register(s.T().Context(), draft) + s.Require().ErrorIs(err, domain.ErrValidation) +} + +func (s *ServiceSuite) TestRegisterRejectsShortPasswordWithoutRepositoryCall() { + draft := domain.UserDraft{Username: "alice", DisplayName: "Алиса", Password: "too-short"} + + _, err := s.service.Register(s.T().Context(), draft) + s.Require().ErrorIs(err, domain.ErrValidation) +} + +func (s *ServiceSuite) TestRegisterPropagatesUsernameConflict() { + draft := domain.UserDraft{Username: "alice", DisplayName: "Алиса", Password: "very-secret-password"} + + s.users.EXPECT(). + Create(s.T().Context(), mock.Anything). + Return(domain.User{}, domain.ErrUsernameTaken). + Once() + + _, err := s.service.Register(s.T().Context(), draft) + s.Require().ErrorIs(err, domain.ErrUsernameTaken) +} + +func (s *ServiceSuite) TestGetByIDPropagatesNotFound() { + id := uuid.New() + + s.users.EXPECT().GetByID(s.T().Context(), id).Return(domain.User{}, domain.ErrNotFound).Once() + + _, err := s.service.GetByID(s.T().Context(), id) + s.Require().ErrorIs(err, domain.ErrNotFound) +} + +func (s *ServiceSuite) TestGetByIDWrapsRepositoryFailure() { + id := uuid.New() + + s.users.EXPECT().GetByID(s.T().Context(), id).Return(domain.User{}, errRepository).Once() + + _, err := s.service.GetByID(s.T().Context(), id) + s.Require().ErrorIs(err, errRepository) +} diff --git a/internal/storage/postgres/cache_latency_experiment_test.go b/internal/storage/postgres/cache_latency_experiment_test.go new file mode 100644 index 0000000..39858fd --- /dev/null +++ b/internal/storage/postgres/cache_latency_experiment_test.go @@ -0,0 +1,159 @@ +//go:build integration + +package postgres_test + +import ( + "context" + "fmt" + "sort" + "sync/atomic" + "testing" + "time" + + "github.com/google/uuid" + "github.com/stretchr/testify/mock" + "github.com/stretchr/testify/require" + + "mtusi-messenger/internal/domain" + "mtusi-messenger/internal/platform/cache" + storageredis "mtusi-messenger/internal/storage/redis" + "mtusi-messenger/internal/storage/redis/mocks" +) + +func TestCacheLatencyExperiment(t *testing.T) { + suite := new(BaseSuite) + suite.SetT(t) + suite.SetupTest() + defer suite.TearDownTest() + + ctx := context.Background() + redisConfig := cache.RedisConfig{ + Host: envOr("TEST_REDIS_HOST", "localhost"), + Port: envInt("TEST_REDIS_PORT", 6379), + Password: envOr("TEST_REDIS_PASSWORD", ""), + DB: envInt("TEST_REDIS_DB", 2), + DialTimeout: 5 * time.Second, + ReadTimeout: 3 * time.Second, + WriteTimeout: 3 * time.Second, + PoolSize: 5, + } + redisCache, err := cache.NewRedis(redisConfig) + require.NoError(t, err) + defer func() { _ = redisCache.Close() }() + + alice := suite.createUser("latency_alice") + for range 20 { + suite.createChat(alice) + } + + realChats := suite.store.Chats() + + var loads atomic.Int32 + + source := mocks.NewMockChatSource(t) + source.EXPECT().ListVersion(mock.Anything, mock.Anything).RunAndReturn( + func(ctx context.Context, userID uuid.UUID) (int64, error) { + return realChats.ListVersion(ctx, userID) + }).Maybe() + source.EXPECT().ListVisible(mock.Anything, mock.Anything, mock.Anything, mock.Anything). + RunAndReturn(func(ctx context.Context, callerID uuid.UUID, after *domain.Cursor, limit int) (domain.Page[domain.Chat], error) { + loads.Add(1) + + return realChats.ListVisible(ctx, callerID, after, limit) + }).Maybe() + + for range 50 { + _, err := source.ListVisible(ctx, alice.ID, nil, 50) + require.NoError(t, err) + } + loads.Store(0) + baseline := measureLatency(ctx, t, source.ListVisible, &loads, alice.ID, 1000) + + distributed, err := cache.NewDistributed(redisCache, cache.DistributedConfig{}, nil) + require.NoError(t, err) + + cached := storageredis.NewChatRepository( + source, + distributed, + time.Minute, + nil, + ) + loads.Store(0) + cachedStats := measureCachedLatency(ctx, t, cached, alice.ID, 1000) + cachedStats.Loads = int(loads.Load()) + require.Equal(t, 1000, baseline.Loads) + require.Equal(t, 1, cachedStats.Loads) + + t.Logf("baseline: %s", formatLatency(baseline)) + t.Logf("redis cache: %s", formatLatency(cachedStats)) +} + +func measureLatency( + ctx context.Context, + t *testing.T, + list func(context.Context, uuid.UUID, *domain.Cursor, int) (domain.Page[domain.Chat], error), + loads *atomic.Int32, + callerID uuid.UUID, + requests int, +) latencyStats { + t.Helper() + values := make([]time.Duration, 0, requests) + for range requests { + started := time.Now() + _, err := list(ctx, callerID, nil, 50) + require.NoError(t, err) + values = append(values, time.Since(started)) + } + + return makeLatencyStats(values, int(loads.Load())) +} + +func measureCachedLatency( + ctx context.Context, + t *testing.T, + repository *storageredis.ChatRepository, + callerID uuid.UUID, + requests int, +) latencyStats { + t.Helper() + values := make([]time.Duration, 0, requests) + for range requests { + started := time.Now() + _, err := repository.ListVisible(ctx, callerID, nil, 50) + require.NoError(t, err) + values = append(values, time.Since(started)) + } + + return makeLatencyStats(values, 0) +} + +type latencyStats struct { + Requests int + Loads int + P50 time.Duration + P95 time.Duration + P99 time.Duration +} + +func makeLatencyStats(values []time.Duration, loads int) latencyStats { + sort.Slice(values, func(i, j int) bool { return values[i] < values[j] }) + percentile := func(percent int) time.Duration { + index := (len(values)*percent + 99) / 100 + if index > 0 { + index-- + } + return values[index] + } + + return latencyStats{ + Requests: len(values), Loads: loads, + P50: percentile(50), P95: percentile(95), P99: percentile(99), + } +} + +func formatLatency(value latencyStats) string { + return fmt.Sprintf( + "requests=%d source_loads=%d p50=%s p95=%s p99=%s", + value.Requests, value.Loads, value.P50, value.P95, value.P99, + ) +} diff --git a/internal/storage/postgres/cache_performance_experiment_test.go b/internal/storage/postgres/cache_performance_experiment_test.go new file mode 100644 index 0000000..c803fdd --- /dev/null +++ b/internal/storage/postgres/cache_performance_experiment_test.go @@ -0,0 +1,192 @@ +//go:build integration + +package postgres_test + +import ( + "context" + "fmt" + "sort" + "sync" + "sync/atomic" + "testing" + "time" + + "github.com/google/uuid" + "github.com/stretchr/testify/mock" + "github.com/stretchr/testify/require" + + "mtusi-messenger/internal/domain" + "mtusi-messenger/internal/platform/cache" + storageredis "mtusi-messenger/internal/storage/redis" + "mtusi-messenger/internal/storage/redis/mocks" +) + +func TestCachePerformanceExperiment(t *testing.T) { + suite := new(BaseSuite) + suite.SetT(t) + suite.SetupTest() + defer suite.TearDownTest() + + ctx := context.Background() + redisConfig := cache.RedisConfig{ + Host: envOr("TEST_REDIS_HOST", "localhost"), + Port: envInt("TEST_REDIS_PORT", 6379), + Password: envOr("TEST_REDIS_PASSWORD", ""), + DB: envInt("TEST_REDIS_DB", 2), + DialTimeout: 5 * time.Second, + ReadTimeout: 3 * time.Second, + WriteTimeout: 3 * time.Second, + PoolSize: 10, + } + redisCache, err := cache.NewRedis(redisConfig) + require.NoError(t, err) + defer func() { _ = redisCache.Close() }() + + alice := suite.createUser("perf_alice") + bob := suite.createUser("perf_bob") + carol := suite.createUser("perf_carol") + + for i := range 150 { + title := fmt.Sprintf("Chat %d with Alice", i+1) + members := []uuid.UUID{alice.ID} + if i%3 == 0 { + members = append(members, bob.ID) + } + if i%5 == 0 { + members = append(members, carol.ID) + } + _, err := suite.store.Chats().Create(ctx, domain.ChatDraft{ + Title: title, + MemberIDs: members, + }) + require.NoError(t, err) + } + + realChats := suite.store.Chats() + + var loads atomic.Int32 + + source := mocks.NewMockChatSource(t) + source.EXPECT().ListVersion(mock.Anything, mock.Anything).RunAndReturn( + func(ctx context.Context, userID uuid.UUID) (int64, error) { + return realChats.ListVersion(ctx, userID) + }).Maybe() + source.EXPECT().ListVisible(mock.Anything, mock.Anything, mock.Anything, mock.Anything). + RunAndReturn(func(ctx context.Context, callerID uuid.UUID, after *domain.Cursor, limit int) (domain.Page[domain.Chat], error) { + loads.Add(1) + + return realChats.ListVisible(ctx, callerID, after, limit) + }).Maybe() + + distributed, err := cache.NewDistributed(redisCache, cache.DistributedConfig{}, nil) + require.NoError(t, err) + + cached := storageredis.NewChatRepository( + source, + distributed, + time.Minute, + nil, + ) + + baselineStats := benchmarkConcurrent(ctx, t, func(ctx context.Context) error { + _, err := source.ListVisible(ctx, alice.ID, nil, 50) + return err + }, 50, 200) + + baselineStats.SQLQueries = int(loads.Load()) + loads.Store(0) + cachedStats := benchmarkConcurrent(ctx, t, func(ctx context.Context) error { + _, err := cached.ListVisible(ctx, alice.ID, nil, 50) + return err + }, 50, 200) + + cachedStats.SQLQueries = int(loads.Load()) + loads.Store(0) + + _, err = cached.ListVisible(ctx, alice.ID, nil, 50) + require.NoError(t, err) + + cachedHotStats := benchmarkConcurrent(ctx, t, func(ctx context.Context) error { + _, err := cached.ListVisible(ctx, alice.ID, nil, 50) + return err + }, 50, 200) + cachedHotStats.SQLQueries = int(loads.Load()) + + t.Logf("baseline (no cache): %s", formatPerfStats(baselineStats)) + t.Logf("redis cache (cold): %s", formatPerfStats(cachedStats)) + t.Logf("redis cache (hot): %s", formatPerfStats(cachedHotStats)) +} + +type perfStats struct { + TotalRequests int + Concurrency int + SQLQueries int + Duration time.Duration + RPS float64 + P50 time.Duration + P95 time.Duration + P99 time.Duration +} + +func benchmarkConcurrent( + ctx context.Context, + t *testing.T, + operation func(context.Context) error, + concurrency int, + requestsPerWorker int, +) perfStats { + t.Helper() + + totalRequests := concurrency * requestsPerWorker + latencies := make([]time.Duration, totalRequests) + var wg sync.WaitGroup + var failures atomic.Int32 + started := time.Now() + + for worker := range concurrency { + wg.Add(1) + go func(workerID int) { + defer wg.Done() + offset := workerID * requestsPerWorker + for i := range requestsPerWorker { + reqStart := time.Now() + err := operation(ctx) + if err != nil { + failures.Add(1) + } + latencies[offset+i] = time.Since(reqStart) + } + }(worker) + } + + wg.Wait() + require.Zero(t, failures.Load(), "some requests failed") + duration := time.Since(started) + + sort.Slice(latencies, func(i, j int) bool { return latencies[i] < latencies[j] }) + percentile := func(p int) time.Duration { + index := (len(latencies)*p + 99) / 100 + if index > 0 { + index-- + } + return latencies[index] + } + + return perfStats{ + TotalRequests: totalRequests, + Concurrency: concurrency, + Duration: duration, + RPS: float64(totalRequests) / duration.Seconds(), + P50: percentile(50), + P95: percentile(95), + P99: percentile(99), + } +} + +func formatPerfStats(s perfStats) string { + return fmt.Sprintf( + "requests=%d concurrency=%d sql=%d duration=%s rps=%.0f p50=%s p95=%s p99=%s", + s.TotalRequests, s.Concurrency, s.SQLQueries, s.Duration.Round(time.Millisecond), + s.RPS, s.P50, s.P95, s.P99, + ) +} diff --git a/internal/storage/postgres/chat_repository.go b/internal/storage/postgres/chat_repository.go new file mode 100644 index 0000000..0cda071 --- /dev/null +++ b/internal/storage/postgres/chat_repository.go @@ -0,0 +1,162 @@ +package postgres + +import ( + "bytes" + "context" + "errors" + "fmt" + "slices" + "time" + + "github.com/google/uuid" + + "mtusi-messenger/internal/domain" + "mtusi-messenger/internal/storage/postgres/internal/sqlcgen" +) + +type ChatRepository struct { + store *Store +} + +func (r *ChatRepository) Create(ctx context.Context, draft domain.ChatDraft) (domain.Chat, error) { + ctx, cancel := r.store.timeout(ctx) + defer cancel() + + var created domain.Chat + + if err := r.store.RunInTx(ctx, func(queries *sqlcgen.Queries) error { + missing, err := queries.ListMissingUserIDs(ctx, draft.MemberIDs) + if err != nil { + return fmt.Errorf("check chat members: %w", mapError(err)) + } + + if len(missing) > 0 { + return domain.ErrUnknownMember + } + + row, err := queries.CreateChat(ctx, draft.Title) + if err != nil { + return fmt.Errorf("create chat: %w", mapError(err)) + } + + if err := queries.AddChatMembers(ctx, sqlcgen.AddChatMembersParams{ + ChatID: row.ID, + UserIds: draft.MemberIDs, + }); err != nil { + return fmt.Errorf("add chat members: %w", mapError(err)) + } + + if err := queries.BumpChatListVersions(ctx, sortedUnique(draft.MemberIDs)); err != nil { + return fmt.Errorf("bump chat list versions: %w", mapError(err)) + } + + created = mapChat(row.ID, row.Title, row.CreatedAt, draft.MemberIDs) + + return nil + }); err != nil { + return domain.Chat{}, err + } + + return created, nil +} + +func (r *ChatRepository) ListVersion(ctx context.Context, userID uuid.UUID) (int64, error) { + ctx, cancel := r.store.timeout(ctx) + defer cancel() + + version, err := r.store.queries.GetChatListVersion(ctx, userID) + if err != nil { + return 0, fmt.Errorf("get chat list version: %w", mapError(err)) + } + + return version, nil +} + +func sortedUnique(ids []uuid.UUID) []uuid.UUID { + sorted := slices.Clone(ids) + slices.SortFunc(sorted, func(a, b uuid.UUID) int { + return bytes.Compare(a[:], b[:]) + }) + + return slices.Compact(sorted) +} + +func (r *ChatRepository) GetVisible(ctx context.Context, chatID, callerID uuid.UUID) (domain.Chat, error) { + ctx, cancel := r.store.timeout(ctx) + defer cancel() + + row, err := r.store.queries.GetChatForMember(ctx, sqlcgen.GetChatForMemberParams{ + UserID: callerID, + ID: chatID, + }) + if err != nil { + mapped := mapError(err) + if errors.Is(mapped, domain.ErrNotFound) { + return domain.Chat{}, fmt.Errorf("%w: chat %s for user %s", domain.ErrNotFound, chatID, callerID) + } + + return domain.Chat{}, fmt.Errorf("get chat: %w", mapped) + } + + return mapChat(row.ID, row.Title, row.CreatedAt, row.MemberIds), nil +} + +func (r *ChatRepository) ListVisible( + ctx context.Context, + callerID uuid.UUID, + after *domain.Cursor, + limit int, +) (domain.Page[domain.Chat], error) { + ctx, cancel := r.store.timeout(ctx) + defer cancel() + + limit = clampLimit(limit) + fetch := int32(limit + 1) //nolint:gosec // limit is clamped to maxPageSize + + var rows []domain.Chat + + if after == nil { + pageRows, err := r.store.queries.ListChatsForMember(ctx, sqlcgen.ListChatsForMemberParams{ + UserID: callerID, + RowLimit: fetch, + }) + if err != nil { + return domain.Page[domain.Chat]{}, fmt.Errorf("list chats: %w", mapError(err)) + } + + rows = mapAll(pageRows, mapChatRow) + } else { + pageRows, err := r.store.queries.ListChatsForMemberAfter(ctx, sqlcgen.ListChatsForMemberAfterParams{ + UserID: callerID, + AfterCreatedAt: after.CreatedAt, + AfterID: after.ID, + RowLimit: fetch, + }) + if err != nil { + return domain.Page[domain.Chat]{}, fmt.Errorf("list chats: %w", mapError(err)) + } + + rows = mapAll(pageRows, mapChatRowAfter) + } + + return buildPage(rows, limit, func(chat domain.Chat) domain.Cursor { + return domain.Cursor{Scope: callerID, CreatedAt: chat.CreatedAt, ID: chat.ID} + }), nil +} + +func mapChatRow(row sqlcgen.ListChatsForMemberRow) domain.Chat { + return mapChat(row.ID, row.Title, row.CreatedAt, row.MemberIds) +} + +func mapChatRowAfter(row sqlcgen.ListChatsForMemberAfterRow) domain.Chat { + return mapChat(row.ID, row.Title, row.CreatedAt, row.MemberIds) +} + +func mapChat(id uuid.UUID, title string, createdAt time.Time, memberIDs []uuid.UUID) domain.Chat { + return domain.Chat{ + ID: id, + Title: title, + MemberIDs: memberIDs, + CreatedAt: toUTCTime(createdAt), + } +} diff --git a/internal/storage/postgres/chat_repository_test.go b/internal/storage/postgres/chat_repository_test.go new file mode 100644 index 0000000..3f81345 --- /dev/null +++ b/internal/storage/postgres/chat_repository_test.go @@ -0,0 +1,239 @@ +//go:build integration + +package postgres_test + +import ( + "fmt" + "slices" + "sync" + "testing" + + "github.com/google/uuid" + "github.com/stretchr/testify/suite" + + "mtusi-messenger/internal/domain" +) + +type ChatRepositorySuite struct { + BaseSuite +} + +func TestChatRepositorySuite(t *testing.T) { + suite.Run(t, new(ChatRepositorySuite)) +} + +func (s *ChatRepositorySuite) TestCreateRejectsUnknownMemberAtomically() { + alice := s.createUser("alice") + + _, err := s.store.Chats().Create(s.T().Context(), domain.ChatDraft{ + Title: "С неизвестным участником", + MemberIDs: []uuid.UUID{alice.ID, uuid.New()}, + CallerID: alice.ID, + }) + s.Require().ErrorIs(err, domain.ErrUnknownMember) + + var chats int + s.Require().NoError(s.pool.QueryRow(s.T().Context(), "SELECT count(*) FROM chats").Scan(&chats)) + s.Zero(chats, "неуспешное создание чата не оставляет строк") + + var members int + s.Require().NoError(s.pool.QueryRow(s.T().Context(), "SELECT count(*) FROM chat_members").Scan(&members)) + s.Zero(members) +} + +func (s *ChatRepositorySuite) TestCreateRejectsDuplicateMembers() { + alice := s.createUser("alice") + + _, err := s.store.Chats().Create(s.T().Context(), domain.ChatDraft{ + Title: "Дубликаты", + MemberIDs: []uuid.UUID{alice.ID, alice.ID}, + CallerID: alice.ID, + }) + s.Require().ErrorIs(err, domain.ErrConflict) +} + +func (s *ChatRepositorySuite) TestCreateBumpsMemberListVersions() { + ctx := s.T().Context() + alice := s.createUser("alice") + bob := s.createUser("bob") + carol := s.createUser("carol") + + s.createChat(alice, bob) + + aliceVersion, err := s.store.Chats().ListVersion(ctx, alice.ID) + s.Require().NoError(err) + s.Equal(int64(1), aliceVersion, "creator version must be bumped") + + bobVersion, err := s.store.Chats().ListVersion(ctx, bob.ID) + s.Require().NoError(err) + s.Equal(int64(1), bobVersion, "member version must be bumped") + + carolVersion, err := s.store.Chats().ListVersion(ctx, carol.ID) + s.Require().NoError(err) + s.Zero(carolVersion, "non-member version must stay unchanged") + + s.createChat(alice, carol) + + aliceVersion, err = s.store.Chats().ListVersion(ctx, alice.ID) + s.Require().NoError(err) + s.Equal(int64(2), aliceVersion, "version must grow monotonically") + + carolVersion, err = s.store.Chats().ListVersion(ctx, carol.ID) + s.Require().NoError(err) + s.Equal(int64(1), carolVersion) +} + +func (s *ChatRepositorySuite) TestConcurrentCreateNoDeadlock() { + ctx := s.T().Context() + + users := make([]domain.User, 0, 8) + for i := range 8 { + users = append(users, s.createUser(fmt.Sprintf("member%d", i))) + } + + const workers = 16 + + var wg sync.WaitGroup + + errs := make(chan error, workers) + + wg.Add(workers) + + for w := range workers { + go func(w int) { + defer wg.Done() + + ids := []uuid.UUID{ + users[w%len(users)].ID, + users[(w+1)%len(users)].ID, + users[(w+2)%len(users)].ID, + } + if w%2 == 1 { + slices.Reverse(ids) + } + + _, err := s.store.Chats().Create(ctx, domain.ChatDraft{ + Title: fmt.Sprintf("chat-%d", w), + MemberIDs: ids, + CallerID: ids[0], + }) + if err != nil { + errs <- err + } + }(w) + } + + wg.Wait() + close(errs) + + for err := range errs { + s.Require().NoError(err) + } +} + +func (s *ChatRepositorySuite) TestCreateStoresAllMembers() { + alice := s.createUser("alice") + bob := s.createUser("bob") + eve := s.createUser("eve") + + chat := s.createChat(alice, bob, eve) + s.Equal(uuid.Version(7), chat.ID.Version()) + s.False(chat.CreatedAt.IsZero()) + + visible, err := s.store.Chats().GetVisible(s.T().Context(), chat.ID, bob.ID) + s.Require().NoError(err) + s.ElementsMatch([]uuid.UUID{alice.ID, bob.ID, eve.ID}, visible.MemberIDs) +} + +func (s *ChatRepositorySuite) TestVisibility() { + alice := s.createUser("alice") + bob := s.createUser("bob") + eve := s.createUser("eve") + + chat := s.createChat(alice, bob) + + visible, err := s.store.Chats().GetVisible(s.T().Context(), chat.ID, bob.ID) + s.Require().NoError(err) + s.Equal(chat.ID, visible.ID) + s.ElementsMatch([]uuid.UUID{alice.ID, bob.ID}, visible.MemberIDs) + + _, err = s.store.Chats().GetVisible(s.T().Context(), chat.ID, eve.ID) + s.Require().ErrorIs(err, domain.ErrNotFound) + + page, err := s.store.Chats().ListVisible(s.T().Context(), eve.ID, nil, 50) + s.Require().NoError(err) + s.Empty(page.Items) + + page, err = s.store.Chats().ListVisible(s.T().Context(), alice.ID, nil, 50) + s.Require().NoError(err) + s.Require().Len(page.Items, 1) + s.ElementsMatch([]uuid.UUID{alice.ID, bob.ID}, page.Items[0].MemberIDs) + s.Nil(page.Next) +} + +func (s *ChatRepositorySuite) TestListPagination() { + alice := s.createUser("alice") + + const total = 5 + for range total { + s.createChat(alice) + } + + seen := make(map[uuid.UUID]struct{}, total) + + var cursor *domain.Cursor + + for { + page, err := s.store.Chats().ListVisible(s.T().Context(), alice.ID, cursor, 2) + s.Require().NoError(err) + s.Require().NotEmpty(page.Items) + + for _, chat := range page.Items { + _, duplicate := seen[chat.ID] + s.Require().False(duplicate) + seen[chat.ID] = struct{}{} + } + + if page.Next == nil { + break + } + + cursor = page.Next + } + + s.Len(seen, total) +} + +func (s *ChatRepositorySuite) TestListPaginationWithSharedTimestamp() { + alice := s.createUser("alice") + + for range 5 { + s.createChat(alice) + } + + _, err := s.pool.Exec(s.T().Context(), "UPDATE chats SET created_at = '2026-01-01 00:00:00+00'") + s.Require().NoError(err) + + seen := make(map[uuid.UUID]struct{}, 5) + + var cursor *domain.Cursor + + for { + page, err := s.store.Chats().ListVisible(s.T().Context(), alice.ID, cursor, 2) + s.Require().NoError(err) + + for _, chat := range page.Items { + _, duplicate := seen[chat.ID] + s.Require().False(duplicate) + seen[chat.ID] = struct{}{} + } + + if page.Next == nil { + break + } + + cursor = page.Next + } + + s.Len(seen, 5) +} diff --git a/internal/storage/postgres/config.go b/internal/storage/postgres/config.go new file mode 100644 index 0000000..305b212 --- /dev/null +++ b/internal/storage/postgres/config.go @@ -0,0 +1,74 @@ +package postgres + +import ( + "errors" + "time" + + "mtusi-messenger/internal/config" +) + +const ( + defaultHost = "localhost" + defaultPort = 5432 + defaultDatabase = "messenger" + defaultUser = "messenger" + defaultSSLMode = "disable" + defaultMaxConns = int32(10) + defaultMinConns = int32(1) + defaultMaxConnLifetime = time.Hour + defaultMaxConnIdleTime = 30 * time.Minute + defaultConnectTimeout = 5 * time.Second + defaultQueryTimeout = 5 * time.Second +) + +func normalize(cfg config.Postgres) (config.Postgres, error) { + if cfg.Host == "" { + cfg.Host = defaultHost + } + + if cfg.Port == 0 { + cfg.Port = defaultPort + } + + if cfg.Database == "" { + cfg.Database = defaultDatabase + } + + if cfg.User == "" { + cfg.User = defaultUser + } + + if cfg.SSLMode == "" { + cfg.SSLMode = defaultSSLMode + } + + if cfg.MaxConns == 0 { + cfg.MaxConns = defaultMaxConns + } + + if cfg.MinConns == 0 { + cfg.MinConns = defaultMinConns + } + + if cfg.MaxConnLifetime == 0 { + cfg.MaxConnLifetime = defaultMaxConnLifetime + } + + if cfg.MaxConnIdleTime == 0 { + cfg.MaxConnIdleTime = defaultMaxConnIdleTime + } + + if cfg.ConnectTimeout == 0 { + cfg.ConnectTimeout = defaultConnectTimeout + } + + if cfg.QueryTimeout == 0 { + cfg.QueryTimeout = defaultQueryTimeout + } + + if cfg.MinConns > cfg.MaxConns { + return cfg, errors.New("postgres: min_conns must not exceed max_conns") + } + + return cfg, nil +} diff --git a/internal/storage/postgres/config_test.go b/internal/storage/postgres/config_test.go new file mode 100644 index 0000000..4461dd8 --- /dev/null +++ b/internal/storage/postgres/config_test.go @@ -0,0 +1,49 @@ +package postgres + +import ( + "testing" + "time" + + "github.com/stretchr/testify/require" + + "mtusi-messenger/internal/config" +) + +func TestNormalizeAppliesDefaults(t *testing.T) { + cfg, err := normalize(config.Postgres{}) + require.NoError(t, err) + + require.Equal(t, "localhost", cfg.Host) + require.Equal(t, 5432, cfg.Port) + require.Equal(t, "messenger", cfg.Database) + require.Equal(t, "messenger", cfg.User) + require.Equal(t, "disable", cfg.SSLMode) + require.Equal(t, int32(10), cfg.MaxConns) + require.Equal(t, int32(1), cfg.MinConns) + require.Equal(t, time.Hour, cfg.MaxConnLifetime) + require.Equal(t, 5*time.Second, cfg.ConnectTimeout) +} + +func TestNormalizeKeepsProvidedValues(t *testing.T) { + cfg, err := normalize(config.Postgres{ + Host: "db", + Port: 6543, + Database: "app", + User: "app", + SSLMode: "require", + MaxConns: 7, + MinConns: 2, + }) + require.NoError(t, err) + + require.Equal(t, "db", cfg.Host) + require.Equal(t, 6543, cfg.Port) + require.Equal(t, "app", cfg.Database) + require.Equal(t, "require", cfg.SSLMode) + require.Equal(t, int32(7), cfg.MaxConns) +} + +func TestNormalizeRejectsMinGreaterThanMax(t *testing.T) { + _, err := normalize(config.Postgres{MinConns: 5, MaxConns: 2}) + require.Error(t, err) +} diff --git a/internal/storage/postgres/errors.go b/internal/storage/postgres/errors.go new file mode 100644 index 0000000..9c8d3a8 --- /dev/null +++ b/internal/storage/postgres/errors.go @@ -0,0 +1,96 @@ +package postgres + +import ( + "context" + "errors" + "fmt" + "io" + "net" + "syscall" + + "github.com/jackc/pgx/v5" + "github.com/jackc/pgx/v5/pgconn" + + "mtusi-messenger/internal/domain" +) + +const ( + pgUniqueViolation = "23505" + pgForeignKeyViolation = "23503" + pgCheckViolation = "23514" +) + +func isUniqueViolation(err error) bool { + var pgErr *pgconn.PgError + + return errors.As(err, &pgErr) && pgErr.Code == pgUniqueViolation +} + +// isUnavailable reports whether err is a transport-level failure — the server is +// down, the connection dropped, or the pool/query deadline expired — rather than +// a statement-level error. Such failures are dependency outages, not caller errors. +func isUnavailable(err error) bool { + if err == nil { + return false + } + + var pgErr *pgconn.PgError + if errors.As(err, &pgErr) { + switch pgErr.Code { + // Class 08 — connection exception. 57P01/57P02/57P03 are the + // server-side shutdown/startup states; 53300 is "too many + // connections". All are dependency outages, not caller errors. + case "57P01", "57P02", "57P03", "53300": + return true + } + if len(pgErr.Code) >= 2 && pgErr.Code[:2] == "08" { + return true + } + } + + var ( + connectErr *pgconn.ConnectError + netErr net.Error + ) + + return errors.As(err, &connectErr) || + errors.As(err, &netErr) || + errors.Is(err, context.DeadlineExceeded) || + errors.Is(err, syscall.ECONNREFUSED) || + errors.Is(err, syscall.ECONNRESET) || + errors.Is(err, syscall.EPIPE) || + errors.Is(err, io.EOF) || + errors.Is(err, io.ErrUnexpectedEOF) || + errors.Is(err, pgx.ErrTxClosed) || + errors.Is(err, pgx.ErrTxCommitRollback) +} + +func mapError(err error) error { + if err == nil { + return nil + } + + if errors.Is(err, pgx.ErrNoRows) { + return domain.ErrNotFound + } + + if pgErr, ok := errors.AsType[*pgconn.PgError](err); ok { + switch pgErr.Code { + case pgUniqueViolation: + return domain.ErrConflict + case pgForeignKeyViolation: + // Нарушение внешнего ключа означает ссылку на отсутствующую сущность: + // например, отправка сообщения в несуществующий чат или в чат, где + // отправителя нет. Для клиента это 404, а не 500. + return domain.ErrNotFound + case pgCheckViolation: + return domain.ErrValidation + } + } + + if isUnavailable(err) { + return fmt.Errorf("%w: %w", domain.ErrUnavailable, err) + } + + return err +} diff --git a/internal/storage/postgres/errors_test.go b/internal/storage/postgres/errors_test.go new file mode 100644 index 0000000..c8fcc72 --- /dev/null +++ b/internal/storage/postgres/errors_test.go @@ -0,0 +1,32 @@ +package postgres + +import ( + "errors" + "testing" + + "github.com/jackc/pgx/v5/pgconn" + + "mtusi-messenger/internal/domain" +) + +func TestIsUnavailablePostgresConnectionClasses(t *testing.T) { + t.Parallel() + + for _, code := range []string{"08000", "08006", "57P01", "57P02", "57P03", "53300"} { + if !isUnavailable(&pgconn.PgError{Code: code}) { + t.Errorf("code %s was not classified as unavailable", code) + } + } + if isUnavailable(&pgconn.PgError{Code: "23505"}) { + t.Error("unique violation was classified as unavailable") + } +} + +func TestMapErrorConnectionClassIsUnavailable(t *testing.T) { + t.Parallel() + + err := mapError(&pgconn.PgError{Code: "57P03"}) + if !errors.Is(err, domain.ErrUnavailable) { + t.Fatalf("mapError = %v, want ErrUnavailable", err) + } +} diff --git a/internal/storage/postgres/idempotency_test.go b/internal/storage/postgres/idempotency_test.go new file mode 100644 index 0000000..29ae9ad --- /dev/null +++ b/internal/storage/postgres/idempotency_test.go @@ -0,0 +1,183 @@ +//go:build integration + +package postgres_test + +import ( + "crypto/sha256" + "sync" + "testing" + "time" + + "github.com/google/uuid" + "github.com/stretchr/testify/suite" + + "mtusi-messenger/internal/domain" +) + +type IdempotencySuite struct { + BaseSuite +} + +func TestIdempotencySuite(t *testing.T) { + suite.Run(t, new(IdempotencySuite)) +} + +func messageDraft(chat domain.Chat, sender domain.User, key, text string) domain.MessageDraft { + return domain.MessageDraft{ + ChatID: chat.ID, + SenderID: sender.ID, + Text: text, + Idempotency: domain.MessageIdempotency{ + Key: key, + RequestHash: sha256.Sum256([]byte(text)), + }, + } +} + +func (s *IdempotencySuite) history(chat domain.Chat, actor domain.User) []domain.Message { + s.T().Helper() + + page, err := s.store.Messages().ListVisible(s.T().Context(), chat.ID, actor.ID, nil, 100) + s.Require().NoError(err) + + return page.Items +} + +func (s *IdempotencySuite) TestReplayReturnsStoredMessage() { + alice := s.createUser("alice") + bob := s.createUser("bob") + chat := s.createChat(alice, bob) + draft := messageDraft(chat, alice, "key-1", "привет") + + created, err := s.store.Messages().Create(s.T().Context(), draft) + s.Require().NoError(err) + + replayed, err := s.store.Messages().Create(s.T().Context(), draft) + s.Require().NoError(err) + + s.Equal(created, replayed, "повтор с тем же ключом и payload возвращает исходное сообщение") + s.Len(s.history(chat, bob), 1, "повтор не создаёт дубль") +} + +func (s *IdempotencySuite) TestSameKeyWithAnotherPayloadConflicts() { + alice := s.createUser("alice") + bob := s.createUser("bob") + chat := s.createChat(alice, bob) + + created, err := s.store.Messages().Create(s.T().Context(), messageDraft(chat, alice, "key-1", "привет")) + s.Require().NoError(err) + + _, err = s.store.Messages().Create(s.T().Context(), messageDraft(chat, alice, "key-1", "другое")) + s.Require().ErrorIs(err, domain.ErrIdempotency) + + history := s.history(chat, bob) + s.Require().Len(history, 1, "конфликт не создаёт сообщение") + s.Equal(created.ID, history[0].ID, "исходное сообщение не изменено") +} + +func (s *IdempotencySuite) TestConcurrentReplaysCreateOneMessage() { + const callers = 8 + + alice := s.createUser("alice") + bob := s.createUser("bob") + chat := s.createChat(alice, bob) + draft := messageDraft(chat, alice, "key-concurrent", "конкурентный повтор") + + ctx := s.T().Context() + results := make([]domain.Message, callers) + errs := make([]error, callers) + + start := make(chan struct{}) + + var wg sync.WaitGroup + + for i := range callers { + wg.Add(1) + + go func() { + defer wg.Done() + + <-start + + results[i], errs[i] = s.store.Messages().Create(ctx, draft) + }() + } + + close(start) + wg.Wait() + + for i := range callers { + s.Require().NoError(errs[i], "caller %d", i) + s.Equal(results[0].ID, results[i].ID, "все одновременные повторы получают одно сообщение") + } + + s.Len(s.history(chat, bob), 1, "конкурентный повтор создаёт ровно одно сообщение") +} + +func (s *IdempotencySuite) TestKeyIsScopedToActorAndChat() { + alice := s.createUser("alice") + bob := s.createUser("bob") + carol := s.createUser("carol") + + first := s.createChat(alice, bob) + second := s.createChat(alice, carol) + + mine, err := s.store.Messages().Create(s.T().Context(), messageDraft(first, alice, "shared-key", "от Алисы")) + s.Require().NoError(err) + + byBob, err := s.store.Messages().Create(s.T().Context(), messageDraft(first, bob, "shared-key", "от Боба")) + s.Require().NoError(err) + + s.NotEqual(mine.ID, byBob.ID, "одинаковый ключ разных пользователей независим") + + another, err := s.store.Messages().Create(s.T().Context(), messageDraft(second, alice, "shared-key", "в другом чате")) + s.Require().NoError(err) + + s.NotEqual(mine.ID, another.ID, "одинаковый ключ в другом чате независим") +} + +func (s *IdempotencySuite) TestExpiredKeyIsReplaced() { + alice := s.createUser("alice") + bob := s.createUser("bob") + chat := s.createChat(alice, bob) + draft := messageDraft(chat, alice, "key-expiring", "первое") + + // Отрицательный TTL: записи идемпотентности истекают сразу. + expiring := openStoreWithTTL(s.T(), s.db, -time.Second, nil) + s.T().Cleanup(expiring.Close) + + created, err := expiring.Messages().Create(s.T().Context(), draft) + s.Require().NoError(err) + + replaced, err := expiring.Messages().Create(s.T().Context(), messageDraft(chat, alice, "key-expiring", "второе")) + s.Require().NoError(err, "истёкший ключ можно использовать с другим payload") + s.NotEqual(created.ID, replaced.ID) +} + +func (s *IdempotencySuite) TestClaimForMissingChatIsNotFound() { + alice := s.createUser("alice") + + // Чат не существует: claim ключа ссылается на chats(id), поэтому наружу + // должен уйти 404, а не 500 из-за нарушения внешнего ключа. + _, err := s.store.Messages().Create( + s.T().Context(), + messageDraft(domain.Chat{ID: uuid.New()}, alice, "key-1", "привет"), + ) + s.Require().ErrorIs(err, domain.ErrNotFound) +} + +func (s *IdempotencySuite) TestFailedAttemptLeavesNoClaim() { + alice := s.createUser("alice") + outsider := s.createUser("outsider") + chat := s.createChat(alice) + + _, err := s.store.Messages().Create(s.T().Context(), messageDraft(chat, outsider, "key-1", "привет")) + s.Require().ErrorIs(err, domain.ErrNotFound) + + var claims int + + s.Require().NoError( + s.pool.QueryRow(s.T().Context(), "SELECT count(*) FROM message_idempotency").Scan(&claims), + ) + s.Zero(claims, "отклонённая попытка не оставляет claim: транзакция откатывается целиком") +} diff --git a/internal/storage/postgres/internal/sqlcgen/attachments.sql.go b/internal/storage/postgres/internal/sqlcgen/attachments.sql.go new file mode 100644 index 0000000..4fa3568 --- /dev/null +++ b/internal/storage/postgres/internal/sqlcgen/attachments.sql.go @@ -0,0 +1,60 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.31.1 +// source: attachments.sql + +package sqlcgen + +import ( + "context" + + "github.com/google/uuid" +) + +const attachToMessage = `-- name: AttachToMessage :exec +INSERT INTO message_attachments (message_id, attachment_id, position) +VALUES ($1, $2, $3) +` + +type AttachToMessageParams struct { + MessageID uuid.UUID + AttachmentID uuid.UUID + Position int16 +} + +func (q *Queries) AttachToMessage(ctx context.Context, arg AttachToMessageParams) error { + _, err := q.db.Exec(ctx, attachToMessage, arg.MessageID, arg.AttachmentID, arg.Position) + return err +} + +const listMessageAttachments = `-- name: ListMessageAttachments :many +SELECT message_id, attachment_id +FROM message_attachments +WHERE message_id = ANY($1::uuid[]) +ORDER BY message_id, position +` + +type ListMessageAttachmentsRow struct { + MessageID uuid.UUID + AttachmentID uuid.UUID +} + +func (q *Queries) ListMessageAttachments(ctx context.Context, messageIds []uuid.UUID) ([]ListMessageAttachmentsRow, error) { + rows, err := q.db.Query(ctx, listMessageAttachments, messageIds) + if err != nil { + return nil, err + } + defer rows.Close() + items := []ListMessageAttachmentsRow{} + for rows.Next() { + var i ListMessageAttachmentsRow + if err := rows.Scan(&i.MessageID, &i.AttachmentID); err != nil { + return nil, err + } + items = append(items, i) + } + if err := rows.Err(); err != nil { + return nil, err + } + return items, nil +} diff --git a/internal/storage/postgres/internal/sqlcgen/chats.sql.go b/internal/storage/postgres/internal/sqlcgen/chats.sql.go new file mode 100644 index 0000000..cd2b5d3 --- /dev/null +++ b/internal/storage/postgres/internal/sqlcgen/chats.sql.go @@ -0,0 +1,251 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.31.1 +// source: chats.sql + +package sqlcgen + +import ( + "context" + "time" + + "github.com/google/uuid" +) + +const addChatMembers = `-- name: AddChatMembers :exec +INSERT INTO chat_members (chat_id, user_id) +SELECT $1, members.member_id +FROM unnest($2::uuid[]) AS members(member_id) +` + +type AddChatMembersParams struct { + ChatID uuid.UUID + UserIds []uuid.UUID +} + +func (q *Queries) AddChatMembers(ctx context.Context, arg AddChatMembersParams) error { + _, err := q.db.Exec(ctx, addChatMembers, arg.ChatID, arg.UserIds) + return err +} + +const bumpChatListVersions = `-- name: BumpChatListVersions :exec +INSERT INTO user_chat_versions (user_id, version) +SELECT DISTINCT m, 1 +FROM unnest($1::uuid[]) AS m +ORDER BY m +ON CONFLICT (user_id) DO UPDATE SET version = user_chat_versions.version + 1 +` + +func (q *Queries) BumpChatListVersions(ctx context.Context, userIds []uuid.UUID) error { + _, err := q.db.Exec(ctx, bumpChatListVersions, userIds) + return err +} + +const createChat = `-- name: CreateChat :one +INSERT INTO chats (title) +VALUES ($1) +RETURNING id, title, created_at +` + +func (q *Queries) CreateChat(ctx context.Context, title string) (Chat, error) { + row := q.db.QueryRow(ctx, createChat, title) + var i Chat + err := row.Scan(&i.ID, &i.Title, &i.CreatedAt) + return i, err +} + +const getChatForMember = `-- name: GetChatForMember :one +SELECT + c.id, + c.title, + c.created_at, + ( + SELECT COALESCE(array_agg(m.user_id ORDER BY m.user_id), '{}') + FROM chat_members m + WHERE m.chat_id = c.id + )::uuid[] AS member_ids +FROM chats c +JOIN chat_members visible + ON visible.chat_id = c.id AND visible.user_id = $1 +WHERE c.id = $2 +` + +type GetChatForMemberParams struct { + UserID uuid.UUID + ID uuid.UUID +} + +type GetChatForMemberRow struct { + ID uuid.UUID + Title string + CreatedAt time.Time + MemberIds []uuid.UUID +} + +func (q *Queries) GetChatForMember(ctx context.Context, arg GetChatForMemberParams) (GetChatForMemberRow, error) { + row := q.db.QueryRow(ctx, getChatForMember, arg.UserID, arg.ID) + var i GetChatForMemberRow + err := row.Scan( + &i.ID, + &i.Title, + &i.CreatedAt, + &i.MemberIds, + ) + return i, err +} + +const getChatListVersion = `-- name: GetChatListVersion :one +SELECT COALESCE(MAX(version), 0)::bigint AS version +FROM user_chat_versions +WHERE user_id = $1 +` + +func (q *Queries) GetChatListVersion(ctx context.Context, userID uuid.UUID) (int64, error) { + row := q.db.QueryRow(ctx, getChatListVersion, userID) + var version int64 + err := row.Scan(&version) + return version, err +} + +const listChatsForMember = `-- name: ListChatsForMember :many +SELECT + c.id, + c.title, + c.created_at, + ( + SELECT COALESCE(array_agg(m.user_id ORDER BY m.user_id), '{}') + FROM chat_members m + WHERE m.chat_id = c.id + )::uuid[] AS member_ids +FROM chats c +JOIN chat_members visible ON visible.chat_id = c.id +WHERE visible.user_id = $1 +ORDER BY c.created_at, c.id +LIMIT $2 +` + +type ListChatsForMemberParams struct { + UserID uuid.UUID + RowLimit int32 +} + +type ListChatsForMemberRow struct { + ID uuid.UUID + Title string + CreatedAt time.Time + MemberIds []uuid.UUID +} + +func (q *Queries) ListChatsForMember(ctx context.Context, arg ListChatsForMemberParams) ([]ListChatsForMemberRow, error) { + rows, err := q.db.Query(ctx, listChatsForMember, arg.UserID, arg.RowLimit) + if err != nil { + return nil, err + } + defer rows.Close() + items := []ListChatsForMemberRow{} + for rows.Next() { + var i ListChatsForMemberRow + if err := rows.Scan( + &i.ID, + &i.Title, + &i.CreatedAt, + &i.MemberIds, + ); err != nil { + return nil, err + } + items = append(items, i) + } + if err := rows.Err(); err != nil { + return nil, err + } + return items, nil +} + +const listChatsForMemberAfter = `-- name: ListChatsForMemberAfter :many +SELECT + c.id, + c.title, + c.created_at, + ( + SELECT COALESCE(array_agg(m.user_id ORDER BY m.user_id), '{}') + FROM chat_members m + WHERE m.chat_id = c.id + )::uuid[] AS member_ids +FROM chats c +JOIN chat_members visible ON visible.chat_id = c.id +WHERE visible.user_id = $1 + AND (c.created_at, c.id) > ($2::timestamptz, $3::uuid) +ORDER BY c.created_at, c.id +LIMIT $4 +` + +type ListChatsForMemberAfterParams struct { + UserID uuid.UUID + AfterCreatedAt time.Time + AfterID uuid.UUID + RowLimit int32 +} + +type ListChatsForMemberAfterRow struct { + ID uuid.UUID + Title string + CreatedAt time.Time + MemberIds []uuid.UUID +} + +func (q *Queries) ListChatsForMemberAfter(ctx context.Context, arg ListChatsForMemberAfterParams) ([]ListChatsForMemberAfterRow, error) { + rows, err := q.db.Query(ctx, listChatsForMemberAfter, + arg.UserID, + arg.AfterCreatedAt, + arg.AfterID, + arg.RowLimit, + ) + if err != nil { + return nil, err + } + defer rows.Close() + items := []ListChatsForMemberAfterRow{} + for rows.Next() { + var i ListChatsForMemberAfterRow + if err := rows.Scan( + &i.ID, + &i.Title, + &i.CreatedAt, + &i.MemberIds, + ); err != nil { + return nil, err + } + items = append(items, i) + } + if err := rows.Err(); err != nil { + return nil, err + } + return items, nil +} + +const listMissingUserIDs = `-- name: ListMissingUserIDs :many +SELECT input.id::uuid AS missing_id +FROM unnest($1::uuid[]) AS input(id) +LEFT JOIN users u ON u.id = input.id +WHERE u.id IS NULL +` + +func (q *Queries) ListMissingUserIDs(ctx context.Context, userIds []uuid.UUID) ([]uuid.UUID, error) { + rows, err := q.db.Query(ctx, listMissingUserIDs, userIds) + if err != nil { + return nil, err + } + defer rows.Close() + items := []uuid.UUID{} + for rows.Next() { + var missing_id uuid.UUID + if err := rows.Scan(&missing_id); err != nil { + return nil, err + } + items = append(items, missing_id) + } + if err := rows.Err(); err != nil { + return nil, err + } + return items, nil +} diff --git a/internal/storage/postgres/internal/sqlcgen/db.go b/internal/storage/postgres/internal/sqlcgen/db.go new file mode 100644 index 0000000..38811fc --- /dev/null +++ b/internal/storage/postgres/internal/sqlcgen/db.go @@ -0,0 +1,32 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.31.1 + +package sqlcgen + +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, + } +} diff --git a/internal/storage/postgres/internal/sqlcgen/idempotency.sql.go b/internal/storage/postgres/internal/sqlcgen/idempotency.sql.go new file mode 100644 index 0000000..4913a7b --- /dev/null +++ b/internal/storage/postgres/internal/sqlcgen/idempotency.sql.go @@ -0,0 +1,157 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.31.1 +// source: idempotency.sql + +package sqlcgen + +import ( + "context" + "time" + + "github.com/google/uuid" + "github.com/jackc/pgx/v5/pgtype" +) + +const claimMessageIdempotency = `-- name: ClaimMessageIdempotency :one +INSERT INTO message_idempotency (actor_id, chat_id, key, request_hash, expires_at) +VALUES ( + $1, + $2, + $3, + $4, + $5 +) +ON CONFLICT (actor_id, chat_id, key) DO UPDATE + SET request_hash = EXCLUDED.request_hash, + expires_at = EXCLUDED.expires_at, + message_id = NULL + WHERE message_idempotency.expires_at <= now() +RETURNING key +` + +type ClaimMessageIdempotencyParams struct { + ActorID uuid.UUID + ChatID uuid.UUID + Key string + RequestHash []byte + ExpiresAt time.Time +} + +// Claims the key for this actor/chat and returns whether this request owns it. +// A live record wins: the statement returns nothing and the caller replays the +// stored message. An expired record is replaced in place. +func (q *Queries) ClaimMessageIdempotency(ctx context.Context, arg ClaimMessageIdempotencyParams) (string, error) { + row := q.db.QueryRow(ctx, claimMessageIdempotency, + arg.ActorID, + arg.ChatID, + arg.Key, + arg.RequestHash, + arg.ExpiresAt, + ) + var key string + err := row.Scan(&key) + return key, err +} + +const completeMessageIdempotency = `-- name: CompleteMessageIdempotency :exec +UPDATE message_idempotency +SET message_id = $1 +WHERE actor_id = $2 + AND chat_id = $3 + AND key = $4 +` + +type CompleteMessageIdempotencyParams struct { + MessageID pgtype.UUID + ActorID uuid.UUID + ChatID uuid.UUID + Key string +} + +func (q *Queries) CompleteMessageIdempotency(ctx context.Context, arg CompleteMessageIdempotencyParams) error { + _, err := q.db.Exec(ctx, completeMessageIdempotency, + arg.MessageID, + arg.ActorID, + arg.ChatID, + arg.Key, + ) + return err +} + +const getMessageByID = `-- name: GetMessageByID :one +SELECT id, chat_id, sender_id, text, created_at +FROM messages +WHERE id = $1 +` + +func (q *Queries) GetMessageByID(ctx context.Context, id uuid.UUID) (Message, error) { + row := q.db.QueryRow(ctx, getMessageByID, id) + var i Message + err := row.Scan( + &i.ID, + &i.ChatID, + &i.SenderID, + &i.Text, + &i.CreatedAt, + ) + return i, err +} + +const getMessageIdempotency = `-- name: GetMessageIdempotency :one +SELECT message_id, request_hash +FROM message_idempotency +WHERE actor_id = $1 + AND chat_id = $2 + AND key = $3 +FOR UPDATE +` + +type GetMessageIdempotencyParams struct { + ActorID uuid.UUID + ChatID uuid.UUID + Key string +} + +type GetMessageIdempotencyRow struct { + MessageID pgtype.UUID + RequestHash []byte +} + +// Concurrent duplicates block here until the owner commits, then read the +// result it stored in the same transaction. +func (q *Queries) GetMessageIdempotency(ctx context.Context, arg GetMessageIdempotencyParams) (GetMessageIdempotencyRow, error) { + row := q.db.QueryRow(ctx, getMessageIdempotency, arg.ActorID, arg.ChatID, arg.Key) + var i GetMessageIdempotencyRow + err := row.Scan(&i.MessageID, &i.RequestHash) + return i, err +} + +const lookupMessageIdempotency = `-- name: LookupMessageIdempotency :one +SELECT message_id, request_hash +FROM message_idempotency +WHERE actor_id = $1 + AND chat_id = $2 + AND key = $3 + AND expires_at > now() +` + +type LookupMessageIdempotencyParams struct { + ActorID uuid.UUID + ChatID uuid.UUID + Key string +} + +type LookupMessageIdempotencyRow struct { + MessageID pgtype.UUID + RequestHash []byte +} + +// Read-only replay lookup used before attachment-state validation. A live key +// returns the stored message; an expired key is ignored and may be claimed. +func (q *Queries) LookupMessageIdempotency(ctx context.Context, arg LookupMessageIdempotencyParams) (LookupMessageIdempotencyRow, error) { + row := q.db.QueryRow(ctx, lookupMessageIdempotency, arg.ActorID, arg.ChatID, arg.Key) + var i LookupMessageIdempotencyRow + err := row.Scan(&i.MessageID, &i.RequestHash) + return i, err +} diff --git a/internal/storage/postgres/internal/sqlcgen/messages.sql.go b/internal/storage/postgres/internal/sqlcgen/messages.sql.go new file mode 100644 index 0000000..43a2510 --- /dev/null +++ b/internal/storage/postgres/internal/sqlcgen/messages.sql.go @@ -0,0 +1,160 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.31.1 +// source: messages.sql + +package sqlcgen + +import ( + "context" + "time" + + "github.com/google/uuid" +) + +const createMessage = `-- name: CreateMessage :one +INSERT INTO messages (chat_id, sender_id, text) +SELECT $1, $2, $3 +WHERE EXISTS ( + SELECT 1 + FROM chat_members + WHERE chat_id = $1 + AND user_id = $2 +) +RETURNING id, chat_id, sender_id, text, created_at +` + +type CreateMessageParams struct { + ChatID uuid.UUID + SenderID uuid.UUID + Text string +} + +func (q *Queries) CreateMessage(ctx context.Context, arg CreateMessageParams) (Message, error) { + row := q.db.QueryRow(ctx, createMessage, 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 isChatMember = `-- name: IsChatMember :one +SELECT EXISTS ( + SELECT 1 + FROM chat_members + WHERE chat_id = $1 + AND user_id = $2 +) AS is_member +` + +type IsChatMemberParams struct { + ChatID uuid.UUID + UserID uuid.UUID +} + +func (q *Queries) IsChatMember(ctx context.Context, arg IsChatMemberParams) (bool, error) { + row := q.db.QueryRow(ctx, isChatMember, arg.ChatID, arg.UserID) + var is_member bool + err := row.Scan(&is_member) + return is_member, err +} + +const listMessagesForChat = `-- name: ListMessagesForChat :many +SELECT m.id, m.chat_id, m.sender_id, m.text, m.created_at +FROM messages m +JOIN chat_members cm + ON cm.chat_id = m.chat_id + AND cm.user_id = $1 +WHERE m.chat_id = $2 +ORDER BY m.created_at, m.id +LIMIT $3 +` + +type ListMessagesForChatParams struct { + CallerID uuid.UUID + ChatID uuid.UUID + RowLimit int32 +} + +func (q *Queries) ListMessagesForChat(ctx context.Context, arg ListMessagesForChatParams) ([]Message, error) { + rows, err := q.db.Query(ctx, listMessagesForChat, arg.CallerID, arg.ChatID, arg.RowLimit) + if err != nil { + return nil, err + } + defer rows.Close() + items := []Message{} + for rows.Next() { + var i Message + if err := rows.Scan( + &i.ID, + &i.ChatID, + &i.SenderID, + &i.Text, + &i.CreatedAt, + ); err != nil { + return nil, err + } + items = append(items, i) + } + if err := rows.Err(); err != nil { + return nil, err + } + return items, nil +} + +const listMessagesForChatAfter = `-- name: ListMessagesForChatAfter :many +SELECT m.id, m.chat_id, m.sender_id, m.text, m.created_at +FROM messages m +JOIN chat_members cm + ON cm.chat_id = m.chat_id + AND cm.user_id = $1 +WHERE m.chat_id = $2 + AND (m.created_at, m.id) > ($3::timestamptz, $4::uuid) +ORDER BY m.created_at, m.id +LIMIT $5 +` + +type ListMessagesForChatAfterParams struct { + CallerID uuid.UUID + ChatID uuid.UUID + AfterCreatedAt time.Time + AfterID uuid.UUID + RowLimit int32 +} + +func (q *Queries) ListMessagesForChatAfter(ctx context.Context, arg ListMessagesForChatAfterParams) ([]Message, error) { + rows, err := q.db.Query(ctx, listMessagesForChatAfter, + arg.CallerID, + arg.ChatID, + arg.AfterCreatedAt, + arg.AfterID, + arg.RowLimit, + ) + if err != nil { + return nil, err + } + defer rows.Close() + items := []Message{} + for rows.Next() { + var i Message + if err := rows.Scan( + &i.ID, + &i.ChatID, + &i.SenderID, + &i.Text, + &i.CreatedAt, + ); err != nil { + return nil, err + } + items = append(items, i) + } + if err := rows.Err(); err != nil { + return nil, err + } + return items, nil +} diff --git a/internal/storage/postgres/internal/sqlcgen/models.go b/internal/storage/postgres/internal/sqlcgen/models.go new file mode 100644 index 0000000..fc862a0 --- /dev/null +++ b/internal/storage/postgres/internal/sqlcgen/models.go @@ -0,0 +1,143 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.31.1 + +package sqlcgen + +import ( + "time" + + "github.com/google/uuid" + "github.com/jackc/pgx/v5/pgtype" +) + +type Attachment struct { + ID uuid.UUID + ChatID uuid.UUID + OwnerID uuid.UUID + ObjectKey string + Filename string + ContentType string + SizeBytes int64 + Sha256 string + Status string + ErrorCode pgtype.Text + CreatedAt time.Time + UpdatedAt time.Time + PipelineVersion int32 + StagingKey pgtype.Text + ReadyAt pgtype.Timestamptz + FailedAt pgtype.Timestamptz +} + +type AttachmentJob struct { + JobID uuid.UUID + AttachmentID uuid.UUID + PipelineVersion int32 + SourceKey string + Attempt int32 + MaxAttempts int32 + Status string + AvailableAt time.Time + LeaseOwner pgtype.Text + LeaseExpiresAt pgtype.Timestamptz + LastErrorCode pgtype.Text + ReplayCount int32 + CreatedAt time.Time + UpdatedAt time.Time + CompletedAt pgtype.Timestamptz +} + +type AttachmentJobEvent struct { + ID int64 + JobID uuid.UUID + Event string + Attempt pgtype.Int4 + Detail []byte + CreatedAt time.Time +} + +type AttachmentVariant struct { + AttachmentID uuid.UUID + PipelineVersion int32 + Name string + ContentType string + SizeBytes int64 + Width int32 + Height int32 + Sha256 string + ObjectKey string + CreatedAt time.Time +} + +type Chat struct { + ID uuid.UUID + Title string + CreatedAt time.Time +} + +type ChatMember struct { + ChatID uuid.UUID + UserID uuid.UUID + CreatedAt time.Time +} + +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 + Position int16 +} + +type MessageIdempotency struct { + ActorID uuid.UUID + ChatID uuid.UUID + Key string + RequestHash []byte + MessageID pgtype.UUID + CreatedAt time.Time + ExpiresAt time.Time +} + +type OutboxMessage struct { + ID int64 + JobID uuid.UUID + Attempt int32 + Kind string + RoutingKey string + Payload []byte + AvailableAt time.Time + PublishedAt pgtype.Timestamptz + ClaimedBy pgtype.Text + ClaimedUntil pgtype.Timestamptz + PublishAttempts int32 + LastError pgtype.Text + CreatedAt time.Time +} + +type Session struct { + TokenHash []byte + UserID uuid.UUID + ExpiresAt time.Time + CreatedAt time.Time +} + +type User struct { + ID uuid.UUID + Username string + PasswordHash string + DisplayName string + CreatedAt time.Time +} + +type UserChatVersion struct { + UserID uuid.UUID + Version int64 +} diff --git a/internal/storage/postgres/internal/sqlcgen/sessions.sql.go b/internal/storage/postgres/internal/sqlcgen/sessions.sql.go new file mode 100644 index 0000000..fc20b00 --- /dev/null +++ b/internal/storage/postgres/internal/sqlcgen/sessions.sql.go @@ -0,0 +1,83 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.31.1 +// source: sessions.sql + +package sqlcgen + +import ( + "context" + "time" + + "github.com/google/uuid" +) + +const createSession = `-- name: CreateSession :one +INSERT INTO sessions (token_hash, user_id, expires_at) +VALUES ($1, $2, $3) +RETURNING token_hash, user_id, expires_at +` + +type CreateSessionParams struct { + TokenHash []byte + UserID uuid.UUID + ExpiresAt time.Time +} + +type CreateSessionRow struct { + TokenHash []byte + UserID uuid.UUID + ExpiresAt time.Time +} + +func (q *Queries) CreateSession(ctx context.Context, arg CreateSessionParams) (CreateSessionRow, error) { + row := q.db.QueryRow(ctx, createSession, arg.TokenHash, arg.UserID, arg.ExpiresAt) + var i CreateSessionRow + err := row.Scan(&i.TokenHash, &i.UserID, &i.ExpiresAt) + return i, err +} + +const deleteSession = `-- name: DeleteSession :exec +DELETE FROM sessions +WHERE token_hash = $1 + AND user_id = $2 +` + +type DeleteSessionParams struct { + TokenHash []byte + UserID uuid.UUID +} + +func (q *Queries) DeleteSession(ctx context.Context, arg DeleteSessionParams) error { + _, err := q.db.Exec(ctx, deleteSession, arg.TokenHash, arg.UserID) + return err +} + +const getSessionUser = `-- name: GetSessionUser :one +SELECT u.id, u.username, u.display_name, u.created_at, s.expires_at +FROM sessions s +JOIN users u ON u.id = s.user_id +WHERE s.token_hash = $1 + AND s.expires_at > now() +` + +type GetSessionUserRow struct { + ID uuid.UUID + Username string + DisplayName string + CreatedAt time.Time + ExpiresAt time.Time +} + +func (q *Queries) GetSessionUser(ctx context.Context, tokenHash []byte) (GetSessionUserRow, error) { + row := q.db.QueryRow(ctx, getSessionUser, tokenHash) + var i GetSessionUserRow + err := row.Scan( + &i.ID, + &i.Username, + &i.DisplayName, + &i.CreatedAt, + &i.ExpiresAt, + ) + return i, err +} diff --git a/internal/storage/postgres/internal/sqlcgen/users.sql.go b/internal/storage/postgres/internal/sqlcgen/users.sql.go new file mode 100644 index 0000000..fdbc1b6 --- /dev/null +++ b/internal/storage/postgres/internal/sqlcgen/users.sql.go @@ -0,0 +1,100 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.31.1 +// source: users.sql + +package sqlcgen + +import ( + "context" + "time" + + "github.com/google/uuid" +) + +const createUser = `-- name: CreateUser :one +INSERT INTO users (username, display_name, password_hash) +VALUES ($1, $2, $3) +RETURNING id, username, display_name, created_at, password_hash +` + +type CreateUserParams struct { + Username string + DisplayName string + PasswordHash string +} + +type CreateUserRow struct { + ID uuid.UUID + Username string + DisplayName string + CreatedAt time.Time + PasswordHash string +} + +func (q *Queries) CreateUser(ctx context.Context, arg CreateUserParams) (CreateUserRow, error) { + row := q.db.QueryRow(ctx, createUser, arg.Username, arg.DisplayName, arg.PasswordHash) + var i CreateUserRow + err := row.Scan( + &i.ID, + &i.Username, + &i.DisplayName, + &i.CreatedAt, + &i.PasswordHash, + ) + return i, err +} + +const getUserByID = `-- name: GetUserByID :one +SELECT id, username, display_name, created_at, password_hash +FROM users +WHERE id = $1 +` + +type GetUserByIDRow struct { + ID uuid.UUID + Username string + DisplayName string + CreatedAt time.Time + PasswordHash string +} + +func (q *Queries) GetUserByID(ctx context.Context, id uuid.UUID) (GetUserByIDRow, error) { + row := q.db.QueryRow(ctx, getUserByID, id) + var i GetUserByIDRow + err := row.Scan( + &i.ID, + &i.Username, + &i.DisplayName, + &i.CreatedAt, + &i.PasswordHash, + ) + return i, err +} + +const getUserByUsername = `-- name: GetUserByUsername :one +SELECT id, username, display_name, created_at, password_hash +FROM users +WHERE username = $1 +` + +type GetUserByUsernameRow struct { + ID uuid.UUID + Username string + DisplayName string + CreatedAt time.Time + PasswordHash string +} + +func (q *Queries) GetUserByUsername(ctx context.Context, username string) (GetUserByUsernameRow, error) { + row := q.db.QueryRow(ctx, getUserByUsername, username) + var i GetUserByUsernameRow + err := row.Scan( + &i.ID, + &i.Username, + &i.DisplayName, + &i.CreatedAt, + &i.PasswordHash, + ) + return i, err +} diff --git a/internal/storage/postgres/main_test.go b/internal/storage/postgres/main_test.go new file mode 100644 index 0000000..324975c --- /dev/null +++ b/internal/storage/postgres/main_test.go @@ -0,0 +1,291 @@ +//go:build integration + +package postgres_test + +import ( + "context" + "database/sql" + "fmt" + "os" + "strconv" + "strings" + "testing" + "time" + + "github.com/google/uuid" + "github.com/jackc/pgx/v5/pgxpool" + "github.com/pressly/goose/v3" + "github.com/stretchr/testify/require" + "github.com/stretchr/testify/suite" + + "mtusi-messenger/internal/config" + "mtusi-messenger/internal/domain" + "mtusi-messenger/internal/platform/password" + "mtusi-messenger/internal/storage/postgres" + "mtusi-messenger/internal/storage/postgres/migrations" + + _ "github.com/jackc/pgx/v5/stdlib" +) + +const templateDB = "messenger_template" + +var adminPool *pgxpool.Pool + +func envOr(key, fallback string) string { + if value := os.Getenv(key); value != "" { + return value + } + + return fallback +} + +func envInt(key string, fallback int) int { + value := os.Getenv(key) + if value == "" { + return fallback + } + + parsed, err := strconv.Atoi(value) + if err != nil { + return fallback + } + + return parsed +} + +func testConfig() config.Postgres { + return config.Postgres{ + Host: envOr("TEST_POSTGRES_HOST", "localhost"), + Port: envInt("TEST_POSTGRES_PORT", 5432), + Database: envOr("TEST_POSTGRES_DATABASE", "messenger"), + User: envOr("TEST_POSTGRES_USER", "messenger"), + Password: envOr("TEST_POSTGRES_PASSWORD", "messenger"), + SSLMode: envOr("TEST_POSTGRES_SSL_MODE", "disable"), + MaxConns: 5, + MinConns: 1, + MaxConnLifetime: time.Hour, + MaxConnIdleTime: 30 * time.Minute, + ConnectTimeout: 5 * time.Second, + QueryTimeout: 5 * time.Second, + } +} + +func dsnFor(database string) string { + cfg := testConfig() + cfg.Database = database + + return cfg.DSN() +} + +func TestMain(m *testing.M) { + ctx := context.Background() + + var err error + + adminPool, err = pgxpool.New(ctx, dsnFor(testConfig().Database)) + if err != nil { + fmt.Fprintln(os.Stderr, "admin pool:", err) + os.Exit(1) + } + + if err := waitForDatabase(ctx, adminPool); err != nil { + fmt.Fprintln(os.Stderr, "database is not ready:", err) + os.Exit(1) + } + + if err := recreateTemplate(ctx); err != nil { + fmt.Fprintln(os.Stderr, "create template:", err) + os.Exit(1) + } + + code := m.Run() + + adminPool.Close() + os.Exit(code) +} + +func waitForDatabase(ctx context.Context, pool *pgxpool.Pool) error { + var lastErr error + + for range 60 { + err := pool.Ping(ctx) + if err == nil { + return nil + } + + lastErr = err + + time.Sleep(500 * time.Millisecond) + } + + return lastErr +} + +func adminExec(ctx context.Context, query string) error { + conn, err := adminPool.Acquire(ctx) + if err != nil { + return err + } + + defer conn.Release() + + _, err = conn.Conn().PgConn().Exec(ctx, query).ReadAll() + + return err +} + +const templateLockKey int64 = 0x6d657373656e6765 + +func withAdvisoryLock(ctx context.Context, shared bool, fn func() error) error { + conn, err := adminPool.Acquire(ctx) + if err != nil { + return err + } + + defer conn.Release() + + lock, unlock := "pg_advisory_lock", "pg_advisory_unlock" + if shared { + lock, unlock = "pg_advisory_lock_shared", "pg_advisory_unlock_shared" + } + + if _, err := conn.Exec(ctx, "SELECT "+lock+"($1)", templateLockKey); err != nil { + return err + } + + defer func() { _, _ = conn.Exec(context.WithoutCancel(ctx), "SELECT "+unlock+"($1)", templateLockKey) }() + + return fn() +} + +func recreateTemplate(ctx context.Context) error { + return withAdvisoryLock(ctx, false, func() error { + if err := adminExec(ctx, "DROP DATABASE IF EXISTS "+templateDB+" WITH (FORCE)"); err != nil { + return err + } + + if err := adminExec(ctx, "CREATE DATABASE "+templateDB); err != nil { + return err + } + + db, err := sql.Open("pgx", dsnFor(templateDB)) + if err != nil { + return err + } + + defer func() { _ = db.Close() }() + + if err := db.PingContext(ctx); err != nil { + return err + } + + goose.SetBaseFS(migrations.FS) + + if err := goose.SetDialect("postgres"); err != nil { + return err + } + + return goose.Up(db, ".") + }) +} + +type BaseSuite struct { + suite.Suite + + store *postgres.Store + pool *pgxpool.Pool + db string +} + +func (s *BaseSuite) SetupTest() { + ctx := s.T().Context() + s.db = "test_" + strings.ReplaceAll(uuid.NewString(), "-", "") + + s.Require().NoError(withAdvisoryLock(ctx, true, func() error { + return adminExec(ctx, "CREATE DATABASE "+s.db+" TEMPLATE "+templateDB) + })) + + var err error + + s.pool, err = pgxpool.New(ctx, dsnFor(s.db)) + s.Require().NoError(err) + + s.store = openStore(s.T(), s.db, nil) +} + +func (s *BaseSuite) TearDownTest() { + if s.store != nil { + s.store.Close() + } + + if s.pool != nil { + s.pool.Close() + } + + if s.db != "" { + s.Require().NoError(adminExec(s.T().Context(), "DROP DATABASE "+s.db+" WITH (FORCE)")) + } +} + +const testIdempotencyTTL = 24 * time.Hour + +func openStore(t *testing.T, database string, override func(*config.Postgres)) *postgres.Store { + t.Helper() + + return openStoreWithTTL(t, database, testIdempotencyTTL, override) +} + +func openStoreWithTTL( + t *testing.T, + database string, + idempotencyTTL time.Duration, + override func(*config.Postgres), +) *postgres.Store { + t.Helper() + + cfg := testConfig() + cfg.Database = database + + if override != nil { + override(&cfg) + } + + store, err := postgres.New(t.Context(), cfg, idempotencyTTL) + require.NoError(t, err) + + return store +} + +func (s *BaseSuite) createUser(username string) domain.User { + s.T().Helper() + + hash, err := password.Hash("strong-test-password") + s.Require().NoError(err) + + user, err := s.store.Users().Create(s.T().Context(), domain.NewUser{ + Username: username, + DisplayName: "Пользователь " + username, + PasswordHash: hash, + }) + s.Require().NoError(err) + + return user +} + +func (s *BaseSuite) createChat(owner domain.User, members ...domain.User) domain.Chat { + s.T().Helper() + + ids := []uuid.UUID{owner.ID} + for _, member := range members { + ids = append(ids, member.ID) + } + + chat, err := s.store.Chats().Create(s.T().Context(), domain.ChatDraft{ + Title: "Чат", + MemberIDs: ids, + CallerID: owner.ID, + }) + s.Require().NoError(err) + + return chat +} diff --git a/internal/storage/postgres/mapping.go b/internal/storage/postgres/mapping.go new file mode 100644 index 0000000..62bb7b3 --- /dev/null +++ b/internal/storage/postgres/mapping.go @@ -0,0 +1,21 @@ +package postgres + +import "time" + +func toUTCTime(t time.Time) time.Time { + if t.Location() == time.UTC { + return t + } + + return t.UTC() +} + +func mapAll[S, D any](rows []S, mapRow func(S) D) []D { + mapped := make([]D, 0, len(rows)) + + for _, row := range rows { + mapped = append(mapped, mapRow(row)) + } + + return mapped +} diff --git a/internal/storage/postgres/message_repository.go b/internal/storage/postgres/message_repository.go new file mode 100644 index 0000000..a80b196 --- /dev/null +++ b/internal/storage/postgres/message_repository.go @@ -0,0 +1,361 @@ +package postgres + +import ( + "bytes" + "context" + "errors" + "fmt" + "time" + + "github.com/google/uuid" + "github.com/jackc/pgx/v5" + "github.com/jackc/pgx/v5/pgtype" + + "mtusi-messenger/internal/domain" + "mtusi-messenger/internal/storage/postgres/internal/sqlcgen" +) + +type MessageRepository struct { + store *Store +} + +func (r *MessageRepository) IsChatMember(ctx context.Context, chatID, userID uuid.UUID) (bool, error) { + ctx, cancel := r.store.timeout(ctx) + defer cancel() + + member, err := r.store.queries.IsChatMember(ctx, sqlcgen.IsChatMemberParams{ + ChatID: chatID, + UserID: userID, + }) + if err != nil { + return false, fmt.Errorf("check chat membership: %w", mapError(err)) + } + + return member, nil +} + +func (r *MessageRepository) Create(ctx context.Context, draft domain.MessageDraft) (domain.Message, error) { + var created domain.Message + + err := r.store.RunInTx(ctx, func(queries *sqlcgen.Queries) error { + message, err := createIdempotent(ctx, queries, draft, r.store.idempotencyTTL) + if err != nil { + return err + } + + created = message + + return nil + }) + if err != nil { + // mapError нужен и здесь: отказ BEGIN/COMMIT (недоступная БД, исчерпанный + // пул, истёкший контекст) обязан давать 503, а не 500. + return domain.Message{}, fmt.Errorf("create message: %w", mapError(err)) + } + + return created, nil +} + +// Replay returns the stored message for a live Idempotency-Key without +// touching attachment state. The caller uses it before attachment validation so +// a replay stays 201 even if a linked attachment later failed. +func (r *MessageRepository) Replay( + ctx context.Context, + draft domain.MessageDraft, +) (domain.Message, bool, error) { + var ( + replayed domain.Message + found bool + ) + + err := r.store.RunInTx(ctx, func(queries *sqlcgen.Queries) error { + stored, err := queries.LookupMessageIdempotency(ctx, sqlcgen.LookupMessageIdempotencyParams{ + ActorID: draft.SenderID, + ChatID: draft.ChatID, + Key: draft.Idempotency.Key, + }) + if errors.Is(err, pgx.ErrNoRows) { + return nil + } + if err != nil { + return mapError(err) + } + + if !bytes.Equal(stored.RequestHash, draft.Idempotency.RequestHash[:]) { + return domain.ErrIdempotency + } + + if !stored.MessageID.Valid { + return errors.New("idempotency record without a message") + } + + row, err := queries.GetMessageByID(ctx, uuid.UUID(stored.MessageID.Bytes)) + if err != nil { + return mapError(err) + } + + replayed = mapMessage(row.ID, row.ChatID, row.SenderID, row.Text, row.CreatedAt) + replayed.AttachmentIDs, err = listAttachmentIDs(ctx, queries, row.ID) + if err != nil { + return err + } + + found = true + + return nil + }) + if err != nil { + return domain.Message{}, false, fmt.Errorf("replay idempotent message: %w", mapError(err)) + } + + return replayed, found, nil +} + +// createIdempotent stores the message and its Idempotency-Key in one +// transaction: either both are committed or neither, so a replay never observes +// a claimed key whose message is missing. Claiming is a single statement, so +// concurrent duplicates with the same key wait for the winner and then replay +// the message it stored. +func createIdempotent( + ctx context.Context, + queries *sqlcgen.Queries, + draft domain.MessageDraft, + ttl time.Duration, +) (domain.Message, error) { + _, err := queries.ClaimMessageIdempotency(ctx, sqlcgen.ClaimMessageIdempotencyParams{ + ActorID: draft.SenderID, + ChatID: draft.ChatID, + Key: draft.Idempotency.Key, + RequestHash: draft.Idempotency.RequestHash[:], + ExpiresAt: time.Now().Add(ttl), + }) + + switch { + case errors.Is(err, pgx.ErrNoRows): // the key is still live: replay it + return replayIdempotent(ctx, queries, draft) + case err != nil: + return domain.Message{}, mapError(err) + default: + return createClaimed(ctx, queries, draft) + } +} + +func createClaimed(ctx context.Context, queries *sqlcgen.Queries, draft domain.MessageDraft) (domain.Message, error) { + row, err := queries.CreateMessage(ctx, sqlcgen.CreateMessageParams{ + ChatID: draft.ChatID, + SenderID: draft.SenderID, + Text: draft.Text, + }) + if err != nil { + return domain.Message{}, mapError(err) + } + + for position, attachmentID := range draft.AttachmentIDs { + if err := queries.AttachToMessage(ctx, sqlcgen.AttachToMessageParams{ + MessageID: row.ID, + AttachmentID: attachmentID, + Position: int16(position), + }); err != nil { + return domain.Message{}, mapError(err) + } + } + + err = queries.CompleteMessageIdempotency(ctx, sqlcgen.CompleteMessageIdempotencyParams{ + MessageID: pgtype.UUID{Bytes: row.ID, Valid: true}, + ActorID: draft.SenderID, + ChatID: draft.ChatID, + Key: draft.Idempotency.Key, + }) + if err != nil { + return domain.Message{}, mapError(err) + } + + created := mapMessage(row.ID, row.ChatID, row.SenderID, row.Text, row.CreatedAt) + created.AttachmentIDs = make([]uuid.UUID, 0, len(draft.AttachmentIDs)) + created.AttachmentIDs = append(created.AttachmentIDs, draft.AttachmentIDs...) + + return created, nil +} + +func replayIdempotent(ctx context.Context, queries *sqlcgen.Queries, draft domain.MessageDraft) (domain.Message, error) { + stored, err := queries.GetMessageIdempotency(ctx, sqlcgen.GetMessageIdempotencyParams{ + ActorID: draft.SenderID, + ChatID: draft.ChatID, + Key: draft.Idempotency.Key, + }) + if err != nil { + return domain.Message{}, mapError(err) + } + + if !bytes.Equal(stored.RequestHash, draft.Idempotency.RequestHash[:]) { + return domain.Message{}, domain.ErrIdempotency + } + + if !stored.MessageID.Valid { + return domain.Message{}, errors.New("idempotency record without a message") + } + + row, err := queries.GetMessageByID(ctx, uuid.UUID(stored.MessageID.Bytes)) + if err != nil { + return domain.Message{}, mapError(err) + } + + replayed := mapMessage(row.ID, row.ChatID, row.SenderID, row.Text, row.CreatedAt) + replayed.AttachmentIDs, err = listAttachmentIDs(ctx, queries, row.ID) + if err != nil { + return domain.Message{}, err + } + + return replayed, nil +} + +// listAttachmentIDs returns attachment IDs in the order the sender supplied +// them. An empty result is normalised to an empty slice, never nil: the +// contract marks attachment_ids as required. +func listAttachmentIDs( + ctx context.Context, + queries *sqlcgen.Queries, + messageID uuid.UUID, +) ([]uuid.UUID, error) { + rows, err := queries.ListMessageAttachments(ctx, []uuid.UUID{messageID}) + if err != nil { + return nil, fmt.Errorf("list message attachments: %w", mapError(err)) + } + + ids := make([]uuid.UUID, 0, len(rows)) + for _, row := range rows { + ids = append(ids, row.AttachmentID) + } + + return ids, nil +} + +func (r *MessageRepository) ListVisible( + ctx context.Context, + chatID, callerID uuid.UUID, + after *domain.Cursor, + limit int, +) (domain.Page[domain.Message], error) { + ctx, cancel := r.store.timeout(ctx) + defer cancel() + + limit = clampLimit(limit) + fetch := int32(limit + 1) //nolint:gosec // limit is clamped to maxPageSize + + messages, err := r.fetch(ctx, chatID, callerID, after, fetch) + if err != nil { + return domain.Page[domain.Message]{}, err + } + + if len(messages) == 0 { + member, err := r.store.queries.IsChatMember(ctx, sqlcgen.IsChatMemberParams{ + ChatID: chatID, + UserID: callerID, + }) + if err != nil { + return domain.Page[domain.Message]{}, fmt.Errorf("check chat membership: %w", mapError(err)) + } + + if !member { + return domain.Page[domain.Message]{}, fmt.Errorf( + "%w: chat %s for user %s", + domain.ErrNotFound, chatID, callerID, + ) + } + } + + return buildPage(messages, limit, func(message domain.Message) domain.Cursor { + return domain.Cursor{Scope: chatID, CreatedAt: message.CreatedAt, ID: message.ID} + }), nil +} + +func (r *MessageRepository) fetch( + ctx context.Context, + chatID, callerID uuid.UUID, + after *domain.Cursor, + fetch int32, +) ([]domain.Message, error) { + var messages []domain.Message + + if after == nil { + rows, err := r.store.queries.ListMessagesForChat(ctx, sqlcgen.ListMessagesForChatParams{ + ChatID: chatID, + CallerID: callerID, + RowLimit: fetch, + }) + if err != nil { + return nil, fmt.Errorf("list messages: %w", mapError(err)) + } + + messages = mapAll(rows, mapMessageRow) + } else { + rows, err := r.store.queries.ListMessagesForChatAfter(ctx, sqlcgen.ListMessagesForChatAfterParams{ + ChatID: chatID, + CallerID: callerID, + AfterCreatedAt: after.CreatedAt, + AfterID: after.ID, + RowLimit: fetch, + }) + if err != nil { + return nil, fmt.Errorf("list messages: %w", mapError(err)) + } + + messages = mapAll(rows, mapMessageRow) + } + + if err := attachMessageLinks(ctx, r.store.queries, messages); err != nil { + return nil, err + } + + return messages, nil +} + +// attachMessageLinks fetches all links for a page in one query and normalises +// absent lists to empty slices. +func attachMessageLinks( + ctx context.Context, + queries *sqlcgen.Queries, + messages []domain.Message, +) error { + if len(messages) == 0 { + return nil + } + + ids := make([]uuid.UUID, 0, len(messages)) + for index := range messages { + ids = append(ids, messages[index].ID) + messages[index].AttachmentIDs = []uuid.UUID{} + } + + rows, err := queries.ListMessageAttachments(ctx, ids) + if err != nil { + return fmt.Errorf("list message attachments: %w", mapError(err)) + } + + byMessage := make(map[uuid.UUID][]uuid.UUID, len(messages)) + for _, row := range rows { + byMessage[row.MessageID] = append(byMessage[row.MessageID], row.AttachmentID) + } + + for index := range messages { + if linked, ok := byMessage[messages[index].ID]; ok { + messages[index].AttachmentIDs = linked + } + } + + return nil +} + +func mapMessageRow(row sqlcgen.Message) domain.Message { + return mapMessage(row.ID, row.ChatID, row.SenderID, row.Text, row.CreatedAt) +} + +func mapMessage(id, chatID, senderID uuid.UUID, text string, createdAt time.Time) domain.Message { + return domain.Message{ + ID: id, + ChatID: chatID, + SenderID: senderID, + Text: text, + CreatedAt: toUTCTime(createdAt), + } +} diff --git a/internal/storage/postgres/message_repository_test.go b/internal/storage/postgres/message_repository_test.go new file mode 100644 index 0000000..73f4c28 --- /dev/null +++ b/internal/storage/postgres/message_repository_test.go @@ -0,0 +1,161 @@ +//go:build integration + +package postgres_test + +import ( + "crypto/sha256" + "fmt" + "sync" + "testing" + + "github.com/google/uuid" + "github.com/stretchr/testify/suite" + + "mtusi-messenger/internal/domain" +) + +type MessageRepositorySuite struct { + BaseSuite +} + +func TestMessageRepositorySuite(t *testing.T) { + suite.Run(t, new(MessageRepositorySuite)) +} + +// draft builds a message draft with a fresh Idempotency-Key (lab3 contract). +func (s *MessageRepositorySuite) draft(chatID, senderID uuid.UUID, text string) domain.MessageDraft { + s.T().Helper() + + key := uuid.NewString() + + return domain.MessageDraft{ + ChatID: chatID, + SenderID: senderID, + Text: text, + Idempotency: domain.MessageIdempotency{ + Key: key, + RequestHash: sha256.Sum256([]byte(key + text)), + }, + } +} + +func (s *MessageRepositorySuite) TestCreateAndPagination() { + alice := s.createUser("alice") + bob := s.createUser("bob") + + chat := s.createChat(alice, bob) + + const total = 5 + for i := range total { + message, err := s.store.Messages().Create(s.T().Context(), s.draft(chat.ID, alice.ID, fmt.Sprintf("сообщение %d", i))) + s.Require().NoError(err) + s.Equal(uuid.Version(7), message.ID.Version()) + s.False(message.CreatedAt.IsZero()) + } + + seen := make(map[uuid.UUID]struct{}, total) + + var cursor *domain.Cursor + + for { + page, err := s.store.Messages().ListVisible(s.T().Context(), chat.ID, alice.ID, cursor, 2) + s.Require().NoError(err) + s.Require().NotEmpty(page.Items) + + for _, message := range page.Items { + _, duplicate := seen[message.ID] + s.Require().False(duplicate, "keyset-пагинация не повторяет сообщения") + seen[message.ID] = struct{}{} + } + + if page.Next == nil { + break + } + + cursor = page.Next + } + + s.Len(seen, total) +} + +func (s *MessageRepositorySuite) TestPaginationWithSharedTimestamp() { + alice := s.createUser("alice") + chat := s.createChat(alice) + + for range 5 { + _, err := s.store.Messages().Create(s.T().Context(), s.draft(chat.ID, alice.ID, "same timestamp")) + s.Require().NoError(err) + } + + _, err := s.pool.Exec(s.T().Context(), "UPDATE messages SET created_at = '2026-01-01 00:00:00+00'") + s.Require().NoError(err) + + seen := make(map[uuid.UUID]struct{}, 5) + + var cursor *domain.Cursor + + for { + page, err := s.store.Messages().ListVisible(s.T().Context(), chat.ID, alice.ID, cursor, 2) + s.Require().NoError(err) + + for _, message := range page.Items { + _, duplicate := seen[message.ID] + s.Require().False(duplicate) + seen[message.ID] = struct{}{} + } + + if page.Next == nil { + break + } + + cursor = page.Next + } + + s.Len(seen, 5) +} + +func (s *MessageRepositorySuite) TestAccessIsRestricted() { + alice := s.createUser("alice") + bob := s.createUser("bob") + + chat := s.createChat(alice) + + _, err := s.store.Messages().Create(s.T().Context(), s.draft(chat.ID, bob.ID, "чужое")) + s.Require().ErrorIs(err, domain.ErrNotFound, "не участник не может писать в чат") + + _, err = s.store.Messages().ListVisible(s.T().Context(), chat.ID, bob.ID, nil, 50) + s.Require().ErrorIs(err, domain.ErrNotFound, "не участник не может читать историю") +} + +func (s *MessageRepositorySuite) TestListingForMissingChatReturnsNotFound() { + alice := s.createUser("alice") + + _, err := s.store.Messages().ListVisible(s.T().Context(), uuid.New(), alice.ID, nil, 50) + s.Require().ErrorIs(err, domain.ErrNotFound) +} + +func (s *MessageRepositorySuite) TestFinishedMessageSurvivesConcurrentReads() { + alice := s.createUser("alice") + chat := s.createChat(alice) + + const total = 20 + + var wg sync.WaitGroup + + wg.Go(func() { + for i := range total { + _, err := s.store.Messages().Create(s.T().Context(), s.draft(chat.ID, alice.ID, fmt.Sprintf("message %d", i))) + if err != nil { + return + } + } + }) + + for range total { + page, err := s.store.Messages().ListVisible(s.T().Context(), chat.ID, alice.ID, nil, 100) + s.Require().NoError(err) + s.LessOrEqual(len(page.Items), total) + } + + wg.Wait() +} diff --git a/internal/storage/postgres/migrations/00001_init.sql b/internal/storage/postgres/migrations/00001_init.sql new file mode 100644 index 0000000..0928241 --- /dev/null +++ b/internal/storage/postgres/migrations/00001_init.sql @@ -0,0 +1,71 @@ +-- +goose Up + +CREATE TABLE users ( + id uuid PRIMARY KEY DEFAULT uuidv7(), + username text NOT NULL, + password_hash text NOT NULL, + display_name text NOT NULL, + created_at timestamptz NOT NULL DEFAULT now(), + + CONSTRAINT users_username_key UNIQUE (username), + CONSTRAINT users_username_format CHECK (username ~ '^[a-z0-9_]{3,32}$'), + CONSTRAINT users_display_name_not_blank CHECK (btrim(display_name) <> ''), + CONSTRAINT users_display_name_length CHECK (char_length(display_name) BETWEEN 1 AND 100) +); + +CREATE TABLE chats ( + id uuid PRIMARY KEY DEFAULT uuidv7(), + title text NOT NULL, + created_at timestamptz NOT NULL DEFAULT now(), + CONSTRAINT chats_title_not_blank CHECK (btrim(title) <> '') +); + +CREATE TABLE chat_members ( + chat_id uuid NOT NULL REFERENCES chats (id) ON DELETE CASCADE, + user_id uuid NOT NULL REFERENCES users (id) ON DELETE RESTRICT, + created_at timestamptz NOT NULL DEFAULT now(), + PRIMARY KEY (chat_id, user_id) +); + +CREATE TABLE messages ( + id uuid PRIMARY KEY DEFAULT uuidv7(), + chat_id uuid NOT NULL REFERENCES chats (id) ON DELETE CASCADE, + sender_id uuid NOT NULL REFERENCES users (id) ON DELETE RESTRICT, + text text NOT NULL, + created_at timestamptz NOT NULL DEFAULT now(), + CONSTRAINT messages_text_not_blank CHECK (btrim(text) <> ''), + CONSTRAINT messages_text_length CHECK (char_length(text) <= 4000) +); + +CREATE TABLE sessions ( + token_hash bytea PRIMARY KEY, + user_id uuid NOT NULL REFERENCES users (id) ON DELETE CASCADE, + expires_at timestamptz NOT NULL, + created_at timestamptz NOT NULL DEFAULT now() +); + +CREATE TABLE user_chat_versions ( + user_id uuid PRIMARY KEY REFERENCES users (id) ON DELETE CASCADE, + version bigint NOT NULL DEFAULT 0 +); + +CREATE INDEX messages_chat_id_created_at_id_idx + ON messages (chat_id, created_at, id); + +CREATE INDEX chat_members_user_id_chat_id_idx + ON chat_members (user_id, chat_id); + +CREATE INDEX chats_created_at_id_idx + ON chats (created_at, id); + +CREATE INDEX sessions_user_id_idx + ON sessions (user_id); + +-- +goose Down + +DROP TABLE sessions; +DROP TABLE messages; +DROP TABLE chat_members; +DROP TABLE chats; +DROP TABLE users; +DROP TABLE user_chat_versions; diff --git a/internal/storage/postgres/migrations/00003_message_idempotency.sql b/internal/storage/postgres/migrations/00003_message_idempotency.sql new file mode 100644 index 0000000..b1facb5 --- /dev/null +++ b/internal/storage/postgres/migrations/00003_message_idempotency.sql @@ -0,0 +1,25 @@ +-- +goose Up +-- Версия 3, а не 2: в базе, перенесённой из лабораторной 2, goose уже содержит +-- запись версии 2 (другая миграция того же репозитория), и одноимённый номер был +-- бы молча пропущен при обновлении существующего стенда до ЛР3. + +CREATE TABLE message_idempotency ( + actor_id uuid NOT NULL REFERENCES users (id) ON DELETE CASCADE, + chat_id uuid NOT NULL REFERENCES chats (id) ON DELETE CASCADE, + key text NOT NULL, + request_hash bytea NOT NULL, + message_id uuid REFERENCES messages (id) ON DELETE CASCADE, + created_at timestamptz NOT NULL DEFAULT now(), + expires_at timestamptz NOT NULL, + + PRIMARY KEY (actor_id, chat_id, key), + CONSTRAINT message_idempotency_key_length CHECK (char_length(key) BETWEEN 1 AND 128) +); + +-- Expired records are replaced lazily by a new claim, the index keeps that +-- lookup and a future sweep cheap. +CREATE INDEX message_idempotency_expires_at_idx ON message_idempotency (expires_at); + +-- +goose Down + +DROP TABLE message_idempotency; diff --git a/internal/storage/postgres/migrations/00004_attachments.sql b/internal/storage/postgres/migrations/00004_attachments.sql new file mode 100644 index 0000000..96fcbdc --- /dev/null +++ b/internal/storage/postgres/migrations/00004_attachments.sql @@ -0,0 +1,55 @@ +-- +goose Up +-- Attachment metadata lives in PostgreSQL; the original bytes live only in S3. +CREATE TABLE attachments ( + id uuid PRIMARY KEY, + chat_id uuid NOT NULL REFERENCES chats (id) ON DELETE CASCADE, + owner_id uuid NOT NULL REFERENCES users (id) ON DELETE RESTRICT, + object_key text NOT NULL, + filename text NOT NULL, + content_type text NOT NULL, + size_bytes bigint NOT NULL, + sha256 text NOT NULL, + status text NOT NULL, + error_code text, + created_at timestamptz NOT NULL DEFAULT now(), + updated_at timestamptz NOT NULL DEFAULT now(), + + CONSTRAINT attachments_object_key_key UNIQUE (object_key), + CONSTRAINT attachments_status_check CHECK (status IN ('pending', 'ready', 'failed')), + CONSTRAINT attachments_content_type_check CHECK (content_type IN ('image/png', 'image/jpeg')), + CONSTRAINT attachments_filename_length CHECK (char_length(filename) BETWEEN 1 AND 255), + CONSTRAINT attachments_size_check CHECK (size_bytes BETWEEN 1 AND 10485760), + CONSTRAINT attachments_sha256_check CHECK (sha256 ~ '^[0-9a-f]{64}$'), + CONSTRAINT attachments_error_consistency CHECK ( + (status = 'ready' AND error_code IS NULL) OR + (status = 'failed' AND error_code IS NOT NULL) OR + status = 'pending' + ) +); + +CREATE INDEX attachments_chat_id_created_at_id_idx ON attachments (chat_id, created_at, id); +CREATE INDEX attachments_status_created_at_idx ON attachments (status, created_at); + +CREATE TABLE message_attachments ( + message_id uuid NOT NULL REFERENCES messages (id) ON DELETE CASCADE, + attachment_id uuid NOT NULL REFERENCES attachments (id) ON DELETE RESTRICT, + position smallint NOT NULL, + + PRIMARY KEY (message_id, attachment_id), + CONSTRAINT message_attachments_position_check CHECK (position BETWEEN 0 AND 9), + CONSTRAINT message_attachments_position_key UNIQUE (message_id, position) +); + +CREATE INDEX message_attachments_attachment_id_idx ON message_attachments (attachment_id); + +-- Lab1-3 messages must stay valid. Attachment-only messages use text = ''; +-- the "text OR attachment" rule is enforced by the service and ogen. +ALTER TABLE messages DROP CONSTRAINT messages_text_not_blank; + +-- +goose Down +-- WARNING: fails if attachment-only messages already exist. Roll back such +-- rows or the constraint cannot be restored. +ALTER TABLE messages ADD CONSTRAINT messages_text_not_blank CHECK (btrim(text) <> ''); + +DROP TABLE message_attachments; +DROP TABLE attachments; diff --git a/internal/storage/postgres/migrations/00005_async_pipeline.sql b/internal/storage/postgres/migrations/00005_async_pipeline.sql new file mode 100644 index 0000000..0b76416 --- /dev/null +++ b/internal/storage/postgres/migrations/00005_async_pipeline.sql @@ -0,0 +1,150 @@ +-- +goose Up +-- Lab5 async attachment pipeline: durable intent (jobs + transactional outbox), +-- per-version results (variants), and operator audit (events). + +ALTER TABLE attachments DROP CONSTRAINT attachments_status_check; +ALTER TABLE attachments ADD CONSTRAINT attachments_status_check CHECK ( + status IN ('pending', 'queued', 'processing', 'ready', 'failed') +) NOT VALID; +ALTER TABLE attachments VALIDATE CONSTRAINT attachments_status_check; + +ALTER TABLE attachments DROP CONSTRAINT attachments_error_consistency; +ALTER TABLE attachments ADD CONSTRAINT attachments_error_consistency CHECK ( + (status IN ('ready', 'queued', 'processing') AND error_code IS NULL) OR + (status = 'failed' AND error_code IS NOT NULL) OR + status = 'pending' +) NOT VALID; +ALTER TABLE attachments VALIDATE CONSTRAINT attachments_error_consistency; + +ALTER TABLE attachments + ADD COLUMN pipeline_version integer NOT NULL DEFAULT 1 + CHECK (pipeline_version >= 1), + ADD COLUMN staging_key text, + ADD COLUMN ready_at timestamptz, + ADD COLUMN failed_at timestamptz; + +CREATE UNIQUE INDEX attachments_staging_key_key + ON attachments (staging_key) + WHERE staging_key IS NOT NULL; + +CREATE INDEX attachments_pipeline_status_idx + ON attachments (status, pipeline_version); + +-- One logical job per (attachment, pipeline version). job_id is stable across +-- redelivery; attempt is the managed attempt number (1-based). +CREATE TABLE attachment_jobs ( + job_id uuid PRIMARY KEY, + attachment_id uuid NOT NULL REFERENCES attachments (id) ON DELETE CASCADE, + pipeline_version integer NOT NULL CHECK (pipeline_version >= 1), + source_key text NOT NULL, + attempt integer NOT NULL DEFAULT 1 CHECK (attempt >= 1), + max_attempts integer NOT NULL CHECK (max_attempts BETWEEN 1 AND 100), + status text NOT NULL CHECK ( + status IN ('queued', 'processing', 'ready', 'failed', 'superseded') + ), + available_at timestamptz NOT NULL DEFAULT now(), + lease_owner text, + lease_expires_at timestamptz, + last_error_code text, + replay_count integer NOT NULL DEFAULT 0, + created_at timestamptz NOT NULL DEFAULT now(), + updated_at timestamptz NOT NULL DEFAULT now(), + completed_at timestamptz, + + CONSTRAINT attachment_jobs_attachment_version_key UNIQUE (attachment_id, pipeline_version), + CONSTRAINT attachment_jobs_lease_consistency CHECK ( + (status = 'processing' AND lease_owner IS NOT NULL AND lease_expires_at IS NOT NULL) OR + (status <> 'processing') + ) +); + +CREATE INDEX attachment_jobs_due_idx + ON attachment_jobs (status, available_at); + +CREATE INDEX attachment_jobs_lease_idx + ON attachment_jobs (status, lease_expires_at); + +-- Delivery ledger. available_at is the only retry scheduler; RabbitMQ is the +-- durable transport. No UNIQUE(job_id, attempt): a graceful shutdown may +-- re-publish the same attempt, and duplicates are harmless (worker CAS). +CREATE TABLE outbox_messages ( + id bigserial PRIMARY KEY, + job_id uuid NOT NULL REFERENCES attachment_jobs (job_id) ON DELETE CASCADE, + attempt integer NOT NULL CHECK (attempt >= 1), + kind text NOT NULL DEFAULT 'publish', + routing_key text NOT NULL, + payload jsonb NOT NULL, + available_at timestamptz NOT NULL DEFAULT now(), + published_at timestamptz, + claimed_by text, + claimed_until timestamptz, + publish_attempts integer NOT NULL DEFAULT 0, + last_error text, + created_at timestamptz NOT NULL DEFAULT now() +); + +CREATE INDEX outbox_due_idx + ON outbox_messages (available_at, id) + WHERE published_at IS NULL; + +CREATE INDEX outbox_claim_expiry_idx + ON outbox_messages (claimed_until) + WHERE published_at IS NULL AND claimed_by IS NOT NULL; + +-- Effect key (attachment_id, pipeline_version, name). The primary key is the +-- idempotency boundary for redelivery and versioned pipelines. +CREATE TABLE attachment_variants ( + attachment_id uuid NOT NULL REFERENCES attachments (id) ON DELETE CASCADE, + pipeline_version integer NOT NULL CHECK (pipeline_version >= 1), + name text NOT NULL CHECK (name IN ('thumbnail', 'crop', 'optimized')), + content_type text NOT NULL CHECK ( + content_type IN ('image/jpeg', 'image/png', 'image/webp') + ), + size_bytes bigint NOT NULL CHECK (size_bytes > 0), + width integer NOT NULL CHECK (width > 0), + height integer NOT NULL CHECK (height > 0), + sha256 text NOT NULL CHECK (sha256 ~ '^[0-9a-f]{64}$'), + object_key text NOT NULL UNIQUE, + created_at timestamptz NOT NULL DEFAULT now(), + + PRIMARY KEY (attachment_id, pipeline_version, name) +); + +CREATE TABLE attachment_job_events ( + id bigserial PRIMARY KEY, + job_id uuid NOT NULL REFERENCES attachment_jobs (job_id) ON DELETE CASCADE, + event text NOT NULL, + attempt integer, + detail jsonb, + created_at timestamptz NOT NULL DEFAULT now() +); + +CREATE INDEX attachment_job_events_job_idx + ON attachment_job_events (job_id, created_at); + +-- +goose Down +DROP TABLE attachment_job_events; +DROP TABLE attachment_variants; +DROP TABLE outbox_messages; +DROP TABLE attachment_jobs; + +DROP INDEX attachments_pipeline_status_idx; +DROP INDEX attachments_staging_key_key; + +ALTER TABLE attachments + DROP COLUMN failed_at, + DROP COLUMN ready_at, + DROP COLUMN staging_key, + DROP COLUMN pipeline_version; + +ALTER TABLE attachments DROP CONSTRAINT attachments_error_consistency; +ALTER TABLE attachments ADD CONSTRAINT attachments_error_consistency CHECK ( + (status = 'ready' AND error_code IS NULL) OR + (status = 'failed' AND error_code IS NOT NULL) OR + status = 'pending' +) NOT VALID; + +ALTER TABLE attachments DROP CONSTRAINT attachments_status_check; +ALTER TABLE attachments ADD CONSTRAINT attachments_status_check CHECK ( + status IN ('pending', 'ready', 'failed') +) NOT VALID; diff --git a/internal/storage/postgres/migrations/00006_job_trace_context.sql b/internal/storage/postgres/migrations/00006_job_trace_context.sql new file mode 100644 index 0000000..24403b5 --- /dev/null +++ b/internal/storage/postgres/migrations/00006_job_trace_context.sql @@ -0,0 +1,12 @@ +-- +goose Up +-- Preserve the originating request trace context on the durable job. The +-- lease reaper and reconciliation path need an original parent even after the +-- API span and the relay process have ended. +ALTER TABLE attachment_jobs + ADD COLUMN traceparent text NOT NULL DEFAULT '', + ADD COLUMN tracestate text NOT NULL DEFAULT ''; + +-- +goose Down +ALTER TABLE attachment_jobs + DROP COLUMN IF EXISTS tracestate, + DROP COLUMN IF EXISTS traceparent; diff --git a/internal/storage/postgres/migrations/00007_ttr_missed.sql b/internal/storage/postgres/migrations/00007_ttr_missed.sql new file mode 100644 index 0000000..1bbc063 --- /dev/null +++ b/internal/storage/postgres/migrations/00007_ttr_missed.sql @@ -0,0 +1,14 @@ +-- +goose Up +-- One-shot TTR miss marker. The relay (which does not stop with the worker) +-- sweeps old non-ready jobs and increments a counter, so the TTR SLI can fire +-- while the worker is down. +ALTER TABLE attachment_jobs + ADD COLUMN ttr_missed_at timestamptz; + +CREATE INDEX attachment_jobs_ttr_missed_idx + ON attachment_jobs (created_at) + WHERE ttr_missed_at IS NULL; + +-- +goose Down +DROP INDEX IF EXISTS attachment_jobs_ttr_missed_idx; +ALTER TABLE attachment_jobs DROP COLUMN IF EXISTS ttr_missed_at; diff --git a/internal/storage/postgres/migrations/00008_ttr_missed_indexes.sql b/internal/storage/postgres/migrations/00008_ttr_missed_indexes.sql new file mode 100644 index 0000000..56752ad --- /dev/null +++ b/internal/storage/postgres/migrations/00008_ttr_missed_indexes.sql @@ -0,0 +1,12 @@ +-- +goose Up +DROP INDEX IF EXISTS attachment_jobs_ttr_missed_idx; +CREATE INDEX attachment_jobs_ttr_open_idx + ON attachment_jobs (created_at) + WHERE ttr_missed_at IS NULL AND status IN ('queued', 'processing'); +CREATE INDEX attachment_jobs_ttr_completed_idx + ON attachment_jobs (completed_at) + WHERE ttr_missed_at IS NULL; + +-- +goose Down +DROP INDEX IF EXISTS attachment_jobs_ttr_completed_idx; +DROP INDEX IF EXISTS attachment_jobs_ttr_open_idx; diff --git a/internal/storage/postgres/migrations/migrations.go b/internal/storage/postgres/migrations/migrations.go new file mode 100644 index 0000000..91cca1c --- /dev/null +++ b/internal/storage/postgres/migrations/migrations.go @@ -0,0 +1,6 @@ +package migrations + +import "embed" + +//go:embed *.sql +var FS embed.FS diff --git a/internal/storage/postgres/pagination.go b/internal/storage/postgres/pagination.go new file mode 100644 index 0000000..63d54df --- /dev/null +++ b/internal/storage/postgres/pagination.go @@ -0,0 +1,25 @@ +package postgres + +import "mtusi-messenger/internal/domain" + +const ( + minPageSize = 1 + maxPageSize = 100 +) + +func clampLimit(limit int) int { + return min(max(limit, minPageSize), maxPageSize) +} + +func buildPage[T any](items []T, limit int, cursor func(item T) domain.Cursor) domain.Page[T] { + if len(items) > limit { + next := cursor(items[limit-1]) + + return domain.Page[T]{ + Items: append([]T(nil), items[:limit]...), + Next: &next, + } + } + + return domain.Page[T]{Items: append([]T(nil), items...)} +} diff --git a/internal/storage/postgres/pipeline_repository.go b/internal/storage/postgres/pipeline_repository.go new file mode 100644 index 0000000..9634b3d --- /dev/null +++ b/internal/storage/postgres/pipeline_repository.go @@ -0,0 +1,2156 @@ +package postgres + +import ( + "context" + "errors" + "fmt" + "time" + + "github.com/google/uuid" + "github.com/jackc/pgx/v5" + "github.com/jackc/pgx/v5/pgtype" + + "mtusi-messenger/internal/domain" + "mtusi-messenger/internal/telemetry" +) + +// PipelineRepository owns the durable job/outbox/variant state. Queries that +// need CAS semantics, FOR UPDATE SKIP LOCKED or multi-table transactions live +// here as explicit SQL instead of being spread across the service layer. +type PipelineRepository struct { + store *Store +} + +const attachmentReturning = `id, chat_id, owner_id, filename, content_type, size_bytes, + sha256, status, error_code, object_key, COALESCE(staging_key, ''), pipeline_version, + created_at, updated_at, ready_at, failed_at` + +const jobReturning = `job_id, attachment_id, pipeline_version, source_key, attempt, + max_attempts, status, available_at, lease_owner, lease_expires_at, last_error_code, + replay_count, created_at, updated_at, completed_at, + COALESCE(traceparent, ''), COALESCE(tracestate, '')` + +type rowScanner interface { + Scan(dest ...any) error +} + +func scanAttachmentRow(row rowScanner) (domain.Attachment, error) { + var ( + attachment domain.Attachment + status string + errCode pgtype.Text + readyAt pgtype.Timestamptz + failedAt pgtype.Timestamptz + ) + + err := row.Scan( + &attachment.ID, + &attachment.ChatID, + &attachment.OwnerID, + &attachment.Filename, + &attachment.ContentType, + &attachment.SizeBytes, + &attachment.SHA256, + &status, + &errCode, + &attachment.ObjectKey, + &attachment.StagingKey, + &attachment.PipelineVersion, + &attachment.CreatedAt, + &attachment.UpdatedAt, + &readyAt, + &failedAt, + ) + if err != nil { + return domain.Attachment{}, err + } + + attachment.Status = domain.AttachmentStatus(status) + attachment.CreatedAt = toUTCTime(attachment.CreatedAt) + attachment.UpdatedAt = toUTCTime(attachment.UpdatedAt) + if errCode.Valid { + code := errCode.String + attachment.ErrorCode = &code + } + if readyAt.Valid { + value := readyAt.Time.UTC() + attachment.ReadyAt = &value + } + if failedAt.Valid { + value := failedAt.Time.UTC() + attachment.FailedAt = &value + } + + return attachment, nil +} + +func scanJobRow(row rowScanner) (domain.Job, error) { + var ( + job domain.Job + status string + owner pgtype.Text + leaseEnds pgtype.Timestamptz + errCode pgtype.Text + completed pgtype.Timestamptz + ) + + err := row.Scan( + &job.ID, + &job.AttachmentID, + &job.PipelineVersion, + &job.SourceKey, + &job.Attempt, + &job.MaxAttempts, + &status, + &job.AvailableAt, + &owner, + &leaseEnds, + &errCode, + &job.ReplayCount, + &job.CreatedAt, + &job.UpdatedAt, + &completed, + &job.Traceparent, + &job.Tracestate, + ) + if err != nil { + return domain.Job{}, err + } + + job.Status = domain.JobStatus(status) + job.AvailableAt = toUTCTime(job.AvailableAt) + job.CreatedAt = toUTCTime(job.CreatedAt) + job.UpdatedAt = toUTCTime(job.UpdatedAt) + if owner.Valid { + job.LeaseOwner = owner.String + } + if leaseEnds.Valid { + value := leaseEnds.Time.UTC() + job.LeaseExpiresAt = &value + } + if errCode.Valid { + code := errCode.String + job.LastErrorCode = &code + } + if completed.Valid { + value := completed.Time.UTC() + job.CompletedAt = &value + } + + return job, nil +} + +func (r *PipelineRepository) withTx(ctx context.Context, fn func(pgx.Tx) error) error { + ctx, cancel := r.store.timeout(ctx) + defer cancel() + + tx, err := r.store.pool.BeginTx(ctx, pgx.TxOptions{}) + if err != nil { + return fmt.Errorf("begin transaction: %w", err) + } + + defer func() { _ = tx.Rollback(ctx) }() + + if err := fn(tx); err != nil { + return err + } + + if err := tx.Commit(ctx); err != nil { + return fmt.Errorf("commit transaction: %w", err) + } + + return nil +} + +// IsChatMember mirrors the existing repository port used by the service. +func (r *PipelineRepository) IsChatMember(ctx context.Context, chatID, userID uuid.UUID) (bool, error) { + ctx, cancel := r.store.timeout(ctx) + defer cancel() + + var member bool + + err := r.store.pool.QueryRow(ctx, ` + SELECT EXISTS ( + SELECT 1 FROM chat_members WHERE chat_id = $1 AND user_id = $2 + )`, chatID, userID).Scan(&member) + if err != nil { + return false, fmt.Errorf("check chat membership: %w", mapError(err)) + } + + return member, nil +} + +func (r *PipelineRepository) GetForMember( + ctx context.Context, + userID, id uuid.UUID, +) (domain.Attachment, error) { + ctx, cancel := r.store.timeout(ctx) + defer cancel() + + row := r.store.pool.QueryRow(ctx, ` + SELECT `+attachmentReturning+` + FROM attachments a + WHERE a.id = $1 + AND EXISTS ( + SELECT 1 FROM chat_members cm + WHERE cm.chat_id = a.chat_id AND cm.user_id = $2 + )`, id, userID) + + attachment, err := scanAttachmentRow(row) + if err != nil { + return domain.Attachment{}, fmt.Errorf("get attachment for member: %w", mapError(err)) + } + + return attachment, nil +} + +func (r *PipelineRepository) GetForOwner( + ctx context.Context, + ownerID, id uuid.UUID, +) (domain.Attachment, error) { + ctx, cancel := r.store.timeout(ctx) + defer cancel() + + row := r.store.pool.QueryRow(ctx, ` + SELECT `+attachmentReturning+` + FROM attachments a + WHERE a.id = $1 AND a.owner_id = $2`, id, ownerID) + + attachment, err := scanAttachmentRow(row) + if err != nil { + return domain.Attachment{}, fmt.Errorf("get attachment for owner: %w", mapError(err)) + } + + return attachment, nil +} + +func (r *PipelineRepository) ListStates( + ctx context.Context, + chatID uuid.UUID, + ids []uuid.UUID, +) ([]domain.AttachmentState, error) { + ctx, cancel := r.store.timeout(ctx) + defer cancel() + + rows, err := r.store.pool.Query(ctx, ` + SELECT id, status + FROM attachments + WHERE chat_id = $1 AND id = ANY($2::uuid[])`, chatID, ids) + if err != nil { + return nil, fmt.Errorf("list attachment states: %w", mapError(err)) + } + defer rows.Close() + + states := make([]domain.AttachmentState, 0, len(ids)) + + for rows.Next() { + var ( + state domain.AttachmentState + status string + ) + if err := rows.Scan(&state.ID, &status); err != nil { + return nil, fmt.Errorf("scan attachment state: %w", mapError(err)) + } + state.Status = domain.AttachmentStatus(status) + states = append(states, state) + } + + if err := rows.Err(); err != nil { + return nil, fmt.Errorf("list attachment states: %w", mapError(err)) + } + + return states, nil +} + +func (r *PipelineRepository) ListVariants( + ctx context.Context, + attachmentID uuid.UUID, + pipelineVersion int, +) ([]domain.Variant, error) { + ctx, cancel := r.store.timeout(ctx) + defer cancel() + + rows, err := r.store.pool.Query(ctx, ` + SELECT name, content_type, size_bytes, width, height, sha256, object_key + FROM attachment_variants + WHERE attachment_id = $1 AND pipeline_version = $2 + ORDER BY name`, attachmentID, pipelineVersion) + if err != nil { + return nil, fmt.Errorf("list variants: %w", mapError(err)) + } + defer rows.Close() + + variants := make([]domain.Variant, 0, 3) + + for rows.Next() { + var ( + variant domain.Variant + name string + ) + if err := rows.Scan( + &name, &variant.ContentType, &variant.SizeBytes, + &variant.Width, &variant.Height, &variant.SHA256, &variant.ObjectKey, + ); err != nil { + return nil, fmt.Errorf("scan variant: %w", mapError(err)) + } + variant.Name = domain.VariantName(name) + variants = append(variants, variant) + } + + if err := rows.Err(); err != nil { + return nil, fmt.Errorf("list variants: %w", mapError(err)) + } + + return variants, nil +} + +func (r *PipelineRepository) GetVariant( + ctx context.Context, + attachmentID uuid.UUID, + pipelineVersion int, + name domain.VariantName, +) (domain.Variant, error) { + ctx, cancel := r.store.timeout(ctx) + defer cancel() + + var variant domain.Variant + + err := r.store.pool.QueryRow(ctx, ` + SELECT name, content_type, size_bytes, width, height, sha256, object_key + FROM attachment_variants + WHERE attachment_id = $1 AND pipeline_version = $2 AND name = $3`, + attachmentID, pipelineVersion, string(name)).Scan( + &variant.Name, &variant.ContentType, &variant.SizeBytes, + &variant.Width, &variant.Height, &variant.SHA256, &variant.ObjectKey, + ) + if err != nil { + return domain.Variant{}, fmt.Errorf("get variant: %w", mapError(err)) + } + + return variant, nil +} + +func (r *PipelineRepository) Admission( + ctx context.Context, + ownerID uuid.UUID, +) (userPending, totalPending int, stagedBytes int64, err error) { + ctx, cancel := r.store.timeout(ctx) + defer cancel() + + err = r.store.pool.QueryRow(ctx, ` + SELECT + count(*) FILTER (WHERE owner_id = $1)::int, + count(*)::int, + COALESCE(sum(size_bytes), 0)::bigint + FROM attachments + WHERE status IN ('pending', 'queued', 'processing')`, ownerID).Scan( + &userPending, &totalPending, &stagedBytes, + ) + if err != nil { + return 0, 0, 0, fmt.Errorf("admission counts: %w", mapError(err)) + } + + return userPending, totalPending, stagedBytes, nil +} + +func insertOutboxTx( + ctx context.Context, + tx pgx.Tx, + job domain.Job, + attempt int, + kind string, + availableAt time.Time, +) error { + message := domain.NewJobMessage(domain.Job{ + ID: job.ID, + AttachmentID: job.AttachmentID, + PipelineVersion: job.PipelineVersion, + Attempt: attempt, + CreatedAt: job.CreatedAt, + }) + message.Traceparent, message.Tracestate = telemetry.Inject(ctx) + payload, err := message.MarshalPayload() + if err != nil { + return fmt.Errorf("marshal job message: %w", err) + } + + _, err = tx.Exec(ctx, ` + INSERT INTO outbox_messages (job_id, attempt, kind, routing_key, payload, available_at) + VALUES ($1, $2, $3, $4, $5::jsonb, $6)`, + job.ID, attempt, kind, defaultRoutingKey, string(payload), availableAt) + if err != nil { + return fmt.Errorf("insert outbox: %w", err) + } + + return nil +} + +func insertEventTx(ctx context.Context, tx pgx.Tx, jobID uuid.UUID, event string, attempt int, detail string) error { + _, err := tx.Exec(ctx, ` + INSERT INTO attachment_job_events (job_id, event, attempt, detail) + VALUES ($1, $2, $3, NULLIF($4, '')::jsonb)`, jobID, event, attempt, detail) + if err != nil { + return fmt.Errorf("insert job event: %w", err) + } + + return nil +} + +const defaultRoutingKey = "attachment.process.v1" + +// CreateQueued persists the attachment, its job and the outbox intent in one +// transaction. The caller has already written the durable staging object. +func (r *PipelineRepository) CreateQueued( + ctx context.Context, + draft domain.AttachmentDraft, + job domain.Job, + limits domain.AdmissionLimits, +) (domain.Attachment, error) { + var created domain.Attachment + + err := r.withTx(ctx, func(tx pgx.Tx) error { + if err := checkAdmissionTx(ctx, tx, draft.OwnerID, limits); err != nil { + return err + } + + row := tx.QueryRow(ctx, ` + INSERT INTO attachments ( + id, chat_id, owner_id, object_key, filename, content_type, + size_bytes, sha256, status, pipeline_version, staging_key + ) + VALUES ($1, $2, $3, $4, $5, $6, $7, $8, 'queued', $9, $10) + RETURNING `+attachmentReturning, + draft.ID, draft.ChatID, draft.OwnerID, draft.ObjectKey, draft.Filename, + draft.ContentType, draft.SizeBytes, draft.SHA256, draft.PipelineVersion, + draft.StagingKey, + ) + + attachment, err := scanAttachmentRow(row) + if err != nil { + return fmt.Errorf("create attachment: %w", mapError(err)) + } + + job.Traceparent, job.Tracestate = telemetry.Inject(ctx) + _, err = tx.Exec(ctx, ` + INSERT INTO attachment_jobs ( + job_id, attachment_id, pipeline_version, source_key, + attempt, max_attempts, status, available_at, traceparent, tracestate + ) + VALUES ($1, $2, $3, $4, 1, $5, 'queued', now(), $6, $7)`, + job.ID, draft.ID, job.PipelineVersion, job.SourceKey, job.MaxAttempts, + job.Traceparent, job.Tracestate) + if err != nil { + return fmt.Errorf("create job: %w", mapError(err)) + } + + if err := insertEventTx(ctx, tx, job.ID, domain.EventEnqueued, 1, ""); err != nil { + return err + } + + if err := insertOutboxTx( + ctx, tx, job, 1, "initial", time.Now().UTC(), + ); err != nil { + return err + } + + created = attachment + + return nil + }) + if err != nil { + return domain.Attachment{}, err + } + + return created, nil +} + +// CompletePresign moves a verified presign object into the queue. +func (r *PipelineRepository) CompletePresign( + ctx context.Context, + ownerID, attachmentID uuid.UUID, + verifiedKey, finalKey string, + pipelineVersion, maxAttempts int, + jobID uuid.UUID, +) (domain.Attachment, error) { + var completed domain.Attachment + + err := r.withTx(ctx, func(tx pgx.Tx) error { + row := tx.QueryRow(ctx, ` + UPDATE attachments + SET status = 'queued', + staging_key = $3, + object_key = $4, + pipeline_version = $5, + error_code = NULL, + failed_at = NULL, + updated_at = now() + WHERE id = $1 AND owner_id = $2 AND status = 'pending' + RETURNING `+attachmentReturning, + attachmentID, ownerID, verifiedKey, finalKey, pipelineVersion, + ) + + attachment, err := scanAttachmentRow(row) + if err != nil { + if errors.Is(mapError(err), domain.ErrNotFound) { + return fmt.Errorf("%w: attachment is not pending", domain.ErrConflict) + } + + return fmt.Errorf("queue presigned attachment: %w", mapError(err)) + } + + job := domain.Job{ + ID: jobID, + AttachmentID: attachmentID, + PipelineVersion: pipelineVersion, + SourceKey: verifiedKey, + Attempt: 1, + MaxAttempts: maxAttempts, + CreatedAt: time.Now().UTC(), + } + + job.Traceparent, job.Tracestate = telemetry.Inject(ctx) + _, err = tx.Exec(ctx, ` + INSERT INTO attachment_jobs ( + job_id, attachment_id, pipeline_version, source_key, + attempt, max_attempts, status, available_at, traceparent, tracestate + ) + VALUES ($1, $2, $3, $4, 1, $5, 'queued', now(), $6, $7)`, + job.ID, job.AttachmentID, job.PipelineVersion, job.SourceKey, job.MaxAttempts, + job.Traceparent, job.Tracestate) + if err != nil { + return fmt.Errorf("create presign job: %w", mapError(err)) + } + + if err := insertEventTx(ctx, tx, job.ID, domain.EventEnqueued, 1, ""); err != nil { + return err + } + + if err := insertOutboxTx( + ctx, tx, job, 1, "initial", time.Now().UTC(), + ); err != nil { + return err + } + + completed = attachment + + return nil + }) + if err != nil { + return domain.Attachment{}, err + } + + return completed, nil +} + +// ClaimJob atomically turns one delivery into the active processing attempt. +// The returned outcome is authoritative; the worker never guesses from message +// fields alone. +func (r *PipelineRepository) ClaimJob( + ctx context.Context, + message domain.JobMessage, + leaseOwner string, + leaseTTL time.Duration, +) (domain.ClaimResult, error) { + var result domain.ClaimResult + + err := r.withTx(ctx, func(tx pgx.Tx) error { + jobRow := tx.QueryRow(ctx, ` + SELECT `+jobReturning+` + FROM attachment_jobs + WHERE job_id = $1 + FOR UPDATE`, message.JobID) + + job, err := scanJobRow(jobRow) + if err != nil { + if errors.Is(mapError(err), domain.ErrNotFound) { + result = domain.ClaimResult{Outcome: domain.ClaimJobNotFound} + + return nil + } + + return fmt.Errorf("load job: %w", mapError(err)) + } + + result.Job = job + + attachmentRow := tx.QueryRow(ctx, ` + SELECT `+attachmentReturning+` + FROM attachments + WHERE id = $1 + FOR UPDATE`, job.AttachmentID) + + attachment, err := scanAttachmentRow(attachmentRow) + if err != nil { + return fmt.Errorf("load job attachment: %w", mapError(err)) + } + + result.Attachment = attachment + + switch { + case job.PipelineVersion < attachment.PipelineVersion: + // A queued job left behind by an older version (for example a + // replay accepted before the newer version committed) can never + // make progress. Retire it instead of acknowledging and + // republishing it through reconciliation forever. + if job.Status == domain.JobQueued { + if _, err := tx.Exec(ctx, ` + UPDATE attachment_jobs + SET status = 'superseded', updated_at = now(), completed_at = now() + WHERE job_id = $1 AND status = 'queued'`, job.ID); err != nil { + return fmt.Errorf("supersede version-stale job: %w", mapError(err)) + } + + if err := insertEventTx(ctx, tx, job.ID, domain.EventSuperseded, job.Attempt, ""); err != nil { + return err + } + } + + result.Outcome = domain.ClaimVersionStale + + return nil + case job.Status == domain.JobReady: + result.Outcome = domain.ClaimAlreadyReady + + return nil + case job.Status == domain.JobFailed: + result.Outcome = domain.ClaimAlreadyFailed + + return nil + case job.Status == domain.JobSuperseded: + result.Outcome = domain.ClaimSuperseded + + return nil + case message.Attempt < job.Attempt: + result.Outcome = domain.ClaimStaleAttempt + + return nil + case message.Attempt > job.Attempt: + result.Outcome = domain.ClaimFutureAttempt + + return nil + case job.Status == domain.JobProcessing: + // A live lease owns the effect; an expired one is requeued by the + // reaper, not by a duplicate delivery. + result.Outcome = domain.ClaimBusyLease + + return nil + case job.Status != domain.JobQueued: + result.Outcome = domain.ClaimJobNotFound + + return nil + } + + tag, err := tx.Exec(ctx, ` + UPDATE attachment_jobs + SET status = 'processing', + lease_owner = $2, + lease_expires_at = now() + $3::interval, + updated_at = now() + WHERE job_id = $1 AND status = 'queued' AND attempt = $4 + AND available_at <= now()`, + job.ID, leaseOwner, intervalString(leaseTTL), message.Attempt) + if err != nil { + return fmt.Errorf("claim job: %w", mapError(err)) + } + + if tag.RowsAffected() == 0 { + result.Outcome = domain.ClaimNotDue + + return nil + } + + if job.PipelineVersion == attachment.PipelineVersion && attachment.Status == domain.AttachmentQueued { + _, err = tx.Exec(ctx, ` + UPDATE attachments + SET status = 'processing', updated_at = now() + WHERE id = $1 AND status = 'queued' AND pipeline_version = $2`, + attachment.ID, job.PipelineVersion) + if err != nil { + return fmt.Errorf("mark attachment processing: %w", mapError(err)) + } + + attachment.Status = domain.AttachmentProcessing + result.Attachment = attachment + } + + if err := insertEventTx(ctx, tx, job.ID, domain.EventClaimed, message.Attempt, ""); err != nil { + return err + } + + job.Status = domain.JobProcessing + job.LeaseOwner = leaseOwner + expires := time.Now().Add(leaseTTL).UTC() + job.LeaseExpiresAt = &expires + result.Job = job + result.Outcome = domain.ClaimAcquired + + return nil + }) + if err != nil { + return domain.ClaimResult{}, err + } + + return result, nil +} + +func intervalString(d time.Duration) string { + return fmt.Sprintf("%d milliseconds", d.Milliseconds()) +} + +func (r *PipelineRepository) Heartbeat( + ctx context.Context, + jobID uuid.UUID, + attempt int, + leaseOwner string, + leaseTTL time.Duration, +) (bool, error) { + ctx, cancel := r.store.timeout(ctx) + defer cancel() + + tag, err := r.store.pool.Exec(ctx, ` + UPDATE attachment_jobs + SET lease_expires_at = now() + $4::interval, updated_at = now() + WHERE job_id = $1 AND attempt = $2 AND lease_owner = $3 + AND status = 'processing' AND lease_expires_at > now()`, + jobID, attempt, leaseOwner, intervalString(leaseTTL)) + if err != nil { + return false, fmt.Errorf("heartbeat: %w", mapError(err)) + } + + return tag.RowsAffected() == 1, nil +} + +// CompleteJob inserts the effect rows and publishes the result atomically. +// A newer serving pipeline version is never downgraded. +func (r *PipelineRepository) CompleteJob( + ctx context.Context, + jobID uuid.UUID, + attempt int, + leaseOwner string, + variants []domain.Variant, +) (bool, error) { + completed := false + + err := r.withTx(ctx, func(tx pgx.Tx) error { + job, attachment, err := lockJobAndAttachment(ctx, tx, jobID) + if err != nil { + return err + } + + if job.Status != domain.JobProcessing || job.Attempt != attempt || job.LeaseOwner != leaseOwner { + return nil + } + + if job.PipelineVersion < attachment.PipelineVersion { + if _, err := tx.Exec(ctx, ` + UPDATE attachment_jobs + SET status = 'superseded', updated_at = now(), completed_at = now() + WHERE job_id = $1`, job.ID); err != nil { + return fmt.Errorf("supersede stale job: %w", mapError(err)) + } + + if err := insertEventTx(ctx, tx, job.ID, domain.EventSuperseded, attempt, ""); err != nil { + return err + } + + return nil + } + + for _, variant := range variants { + tag, err := tx.Exec(ctx, ` + INSERT INTO attachment_variants ( + attachment_id, pipeline_version, name, content_type, + size_bytes, width, height, sha256, object_key + ) + VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9) + ON CONFLICT (attachment_id, pipeline_version, name) DO NOTHING`, + job.AttachmentID, job.PipelineVersion, string(variant.Name), + variant.ContentType, variant.SizeBytes, variant.Width, variant.Height, + variant.SHA256, variant.ObjectKey) + if err != nil { + return fmt.Errorf("insert variant: %w", mapError(err)) + } + + if tag.RowsAffected() == 0 { + existing, err := getVariantTx(ctx, tx, job.AttachmentID, job.PipelineVersion, variant.Name) + if err != nil { + return err + } + + if existing.ContentType != variant.ContentType || + existing.SizeBytes != variant.SizeBytes || + existing.Width != variant.Width || + existing.Height != variant.Height || + existing.SHA256 != variant.SHA256 || + existing.ObjectKey != variant.ObjectKey { + return fmt.Errorf("%w: variant %s already has different bytes", domain.ErrConflict, variant.Name) + } + } + } + + if job.PipelineVersion > attachment.PipelineVersion { + // Reprocess completed: atomically switch the published version. + _, err = tx.Exec(ctx, ` + UPDATE attachments + SET pipeline_version = $2, + status = 'ready', + error_code = NULL, + ready_at = now(), + failed_at = NULL, + updated_at = now() + WHERE id = $1`, attachment.ID, job.PipelineVersion) + } else { + _, err = tx.Exec(ctx, ` + UPDATE attachments + SET status = 'ready', + error_code = NULL, + ready_at = now(), + failed_at = NULL, + updated_at = now() + WHERE id = $1`, attachment.ID) + } + if err != nil { + return fmt.Errorf("mark attachment ready: %w", mapError(err)) + } + + _, err = tx.Exec(ctx, ` + UPDATE attachment_jobs + SET status = 'ready', + lease_owner = NULL, + lease_expires_at = NULL, + last_error_code = NULL, + completed_at = now(), + updated_at = now() + WHERE job_id = $1`, job.ID) + if err != nil { + return fmt.Errorf("mark job ready: %w", mapError(err)) + } + + if err := insertEventTx(ctx, tx, job.ID, domain.EventReady, attempt, ""); err != nil { + return err + } + + completed = true + + return nil + }) + if err != nil { + return false, err + } + + return completed, nil +} + +func lockJobAndAttachment( + ctx context.Context, + tx pgx.Tx, + jobID uuid.UUID, +) (domain.Job, domain.Attachment, error) { + jobRow := tx.QueryRow(ctx, ` + SELECT `+jobReturning+` + FROM attachment_jobs WHERE job_id = $1 FOR UPDATE`, jobID) + + job, err := scanJobRow(jobRow) + if err != nil { + return domain.Job{}, domain.Attachment{}, fmt.Errorf("load job: %w", mapError(err)) + } + + attachmentRow := tx.QueryRow(ctx, ` + SELECT `+attachmentReturning+` + FROM attachments WHERE id = $1 FOR UPDATE`, job.AttachmentID) + + attachment, err := scanAttachmentRow(attachmentRow) + if err != nil { + return domain.Job{}, domain.Attachment{}, fmt.Errorf("load attachment: %w", mapError(err)) + } + + return job, attachment, nil +} + +func getVariantTx( + ctx context.Context, + tx pgx.Tx, + attachmentID uuid.UUID, + pipelineVersion int, + name domain.VariantName, +) (domain.Variant, error) { + var variant domain.Variant + + err := tx.QueryRow(ctx, ` + SELECT name, content_type, size_bytes, width, height, sha256, object_key + FROM attachment_variants + WHERE attachment_id = $1 AND pipeline_version = $2 AND name = $3`, + attachmentID, pipelineVersion, string(name)).Scan( + &variant.Name, &variant.ContentType, &variant.SizeBytes, + &variant.Width, &variant.Height, &variant.SHA256, &variant.ObjectKey, + ) + if err != nil { + return domain.Variant{}, fmt.Errorf("load variant: %w", mapError(err)) + } + + return variant, nil +} + +// RetryJob schedules the next managed attempt. sameAttempt is used by graceful +// shutdown: infrastructure restarts must not consume the processing budget. +func (r *PipelineRepository) RetryJob( + ctx context.Context, + jobID uuid.UUID, + attempt int, + leaseOwner string, + errorCode string, + nextAvailable time.Time, + sameAttempt bool, + kind string, +) (failed bool, err error) { + err = r.withTx(ctx, func(tx pgx.Tx) error { + job, attachment, err := lockJobAndAttachment(ctx, tx, jobID) + if err != nil { + return err + } + + if job.Status != domain.JobProcessing || job.Attempt != attempt || job.LeaseOwner != leaseOwner { + return nil + } + + if !sameAttempt && job.Attempt >= job.MaxAttempts { + failed = true + + return failJobTx(ctx, tx, job, attachment, "retry_exhausted", false) + } + + nextAttempt := job.Attempt + if !sameAttempt { + nextAttempt++ + } + + _, err = tx.Exec(ctx, ` + UPDATE attachment_jobs + SET status = 'queued', + attempt = $2, + available_at = $3, + lease_owner = NULL, + lease_expires_at = NULL, + last_error_code = $4, + updated_at = now() + WHERE job_id = $1`, + job.ID, nextAttempt, nextAvailable, errorCode) + if err != nil { + return fmt.Errorf("schedule retry: %w", mapError(err)) + } + + if job.PipelineVersion == attachment.PipelineVersion && + (attachment.Status == domain.AttachmentProcessing || attachment.Status == domain.AttachmentQueued) { + _, err = tx.Exec(ctx, ` + UPDATE attachments + SET status = 'queued', updated_at = now() + WHERE id = $1 AND pipeline_version = $2`, + attachment.ID, job.PipelineVersion) + if err != nil { + return fmt.Errorf("requeue attachment: %w", mapError(err)) + } + } + + if err := insertEventTx(ctx, tx, job.ID, domain.EventRetried, nextAttempt, `{"error_code":"`+errorCode+`"}`); err != nil { + return err + } + + job.Attempt = nextAttempt + + if err := insertOutboxTx(ctx, tx, job, nextAttempt, kind, nextAvailable); err != nil { + return err + } + + return nil + }) + if err != nil { + return false, err + } + + return failed, nil +} + +func (r *PipelineRepository) FailJob( + ctx context.Context, + jobID uuid.UUID, + attempt int, + leaseOwner string, + errorCode string, +) (bool, error) { + failed := false + + err := r.withTx(ctx, func(tx pgx.Tx) error { + job, attachment, err := lockJobAndAttachment(ctx, tx, jobID) + if err != nil { + return err + } + + if job.Status != domain.JobProcessing || job.Attempt != attempt || job.LeaseOwner != leaseOwner { + return nil + } + + if err := failJobTx(ctx, tx, job, attachment, errorCode, false); err != nil { + return err + } + + failed = true + + return nil + }) + if err != nil { + return false, err + } + + return failed, nil +} + +func failJobTx( + ctx context.Context, + tx pgx.Tx, + job domain.Job, + attachment domain.Attachment, + errorCode string, + leaseExpired bool, +) error { + _, err := tx.Exec(ctx, ` + UPDATE attachment_jobs + SET status = 'failed', + lease_owner = NULL, + lease_expires_at = NULL, + last_error_code = $2, + completed_at = now(), + updated_at = now() + WHERE job_id = $1`, job.ID, errorCode) + if err != nil { + return fmt.Errorf("mark job failed: %w", mapError(err)) + } + + // A failed job settles the attachment when its version is the serving one, + // or when it is a newer version attempted before any version was + // published (reprocess from queued/processing/failed). A newer version + // failing while an older ready version is serving must not disturb the + // published version: it stays ready and downloadable. + settlesAttachment := job.PipelineVersion == attachment.PipelineVersion || + (job.PipelineVersion > attachment.PipelineVersion && attachment.Status != domain.AttachmentReady) + + if settlesAttachment { + _, err = tx.Exec(ctx, ` + UPDATE attachments + SET status = 'failed', + error_code = $2, + failed_at = now(), + updated_at = now() + WHERE id = $1`, attachment.ID, errorCode) + if err != nil { + return fmt.Errorf("mark attachment failed: %w", mapError(err)) + } + } + + detail := `{"error_code":"` + errorCode + `"}` + + if leaseExpired { + if err := insertEventTx(ctx, tx, job.ID, domain.EventLeaseExpired, job.Attempt, detail); err != nil { + return err + } + } + + return insertEventTx(ctx, tx, job.ID, domain.EventFailed, job.Attempt, detail) +} + +// ReapExpiredLeases requeues dead workers and terminates attempts that already +// exhausted their budget. The second branch is what makes retry bounded. +func (r *PipelineRepository) ReapExpiredLeases( + ctx context.Context, + limit int, +) (int, error) { + reaped := 0 + + err := r.withTx(ctx, func(tx pgx.Tx) error { + rows, err := tx.Query(ctx, ` + SELECT `+jobReturning+` + FROM attachment_jobs + WHERE status = 'processing' AND lease_expires_at < now() + ORDER BY lease_expires_at + LIMIT $1 + FOR UPDATE SKIP LOCKED`, limit) + if err != nil { + return fmt.Errorf("select expired leases: %w", mapError(err)) + } + + jobs := make([]domain.Job, 0, limit) + + for rows.Next() { + job, err := scanJobRow(rows) + if err != nil { + rows.Close() + + return fmt.Errorf("scan expired lease: %w", mapError(err)) + } + jobs = append(jobs, job) + } + + if err := rows.Err(); err != nil { + rows.Close() + + return fmt.Errorf("list expired leases: %w", mapError(err)) + } + rows.Close() + + for _, job := range jobs { + attachmentRow := tx.QueryRow(ctx, ` + SELECT `+attachmentReturning+` + FROM attachments WHERE id = $1 FOR UPDATE`, job.AttachmentID) + + attachment, err := scanAttachmentRow(attachmentRow) + if err != nil { + return fmt.Errorf("load lease attachment: %w", mapError(err)) + } + + if job.Attempt >= job.MaxAttempts { + if err := failJobTx(ctx, tx, job, attachment, "retry_exhausted", true); err != nil { + return err + } + reaped++ + + continue + } + + nextAttempt := job.Attempt + 1 + + _, err = tx.Exec(ctx, ` + UPDATE attachment_jobs + SET status = 'queued', + attempt = $2, + available_at = now(), + lease_owner = NULL, + lease_expires_at = NULL, + last_error_code = 'lease_expired', + updated_at = now() + WHERE job_id = $1`, job.ID, nextAttempt) + if err != nil { + return fmt.Errorf("reap lease: %w", mapError(err)) + } + + if job.PipelineVersion == attachment.PipelineVersion && + (attachment.Status == domain.AttachmentProcessing || attachment.Status == domain.AttachmentQueued) { + _, err = tx.Exec(ctx, ` + UPDATE attachments + SET status = 'queued', updated_at = now() + WHERE id = $1 AND pipeline_version = $2`, + attachment.ID, job.PipelineVersion) + if err != nil { + return fmt.Errorf("requeue reaped attachment: %w", mapError(err)) + } + } + + if err := insertEventTx(ctx, tx, job.ID, domain.EventLeaseExpired, job.Attempt, ""); err != nil { + return err + } + + job.Attempt = nextAttempt + job.AvailableAt = time.Now().UTC() + + jobCtx, span := telemetry.StartRequeueSpanForJob(ctx, job) + err = insertOutboxTx( + jobCtx, tx, job, nextAttempt, "lease_expired", time.Now().UTC(), + ) + span.End() + if err != nil { + return err + } + + reaped++ + } + + return nil + }) + if err != nil { + return 0, err + } + + return reaped, nil +} + +// MarkTTRMissed atomically marks jobs that missed the 30s objective. The +// UPDATE itself is the cross-replica lock; a job is counted at most once. +func (r *PipelineRepository) MarkTTRMissed(ctx context.Context, objective time.Duration) (int64, error) { + ctx, cancel := r.store.timeout(ctx) + defer cancel() + + tag, err := r.store.pool.Exec(ctx, ` + UPDATE attachment_jobs + SET ttr_missed_at = now() + WHERE ttr_missed_at IS NULL + AND ( + (status IN ('queued', 'processing') + AND created_at < now() - $1::interval) + OR (status = 'failed' + AND completed_at IS NOT NULL + AND completed_at > now() - interval '1 hour') + OR (status = 'ready' + AND completed_at IS NOT NULL + AND completed_at > created_at + $1::interval + AND completed_at > now() - interval '1 hour') + )`, intervalString(objective)) + if err != nil { + return 0, fmt.Errorf("mark TTR misses: %w", mapError(err)) + } + + return tag.RowsAffected(), nil +} + +// CountOverdueJobs returns queued/processing jobs older than the TTR objective. +func (r *PipelineRepository) CountOverdueJobs(ctx context.Context, olderThan time.Duration) (int64, error) { + ctx, cancel := r.store.timeout(ctx) + defer cancel() + + var count int64 + if err := r.store.pool.QueryRow(ctx, ` + SELECT count(*) FROM attachment_jobs + WHERE status IN ('queued', 'processing') + AND created_at < now() - $1::interval`, intervalString(olderThan)).Scan(&count); err != nil { + return 0, fmt.Errorf("count overdue jobs: %w", mapError(err)) + } + return count, nil +} + +// OldestActiveJobAge returns the age of the oldest queued/processing job. +// It is intentionally a small read-only query with the standard query timeout. +func (r *PipelineRepository) OldestActiveJobAge(ctx context.Context) (float64, error) { + ctx, cancel := r.store.timeout(ctx) + defer cancel() + + var seconds float64 + if err := r.store.pool.QueryRow(ctx, ` + SELECT COALESCE(EXTRACT(EPOCH FROM (now() - min(created_at))), 0) + FROM attachment_jobs + WHERE status IN ('queued', 'processing')`).Scan(&seconds); err != nil { + return 0, fmt.Errorf("oldest active job age: %w", mapError(err)) + } + return seconds, nil +} + +func (r *PipelineRepository) ClaimOutbox( + ctx context.Context, + owner string, + claimTTL time.Duration, + limit int, +) ([]domain.OutboxMessage, error) { + ctx, cancel := r.store.timeout(ctx) + defer cancel() + + rows, err := r.store.pool.Query(ctx, ` + WITH due AS ( + SELECT o.id + FROM outbox_messages o + WHERE o.published_at IS NULL + AND o.available_at <= now() + AND (o.claimed_until IS NULL OR o.claimed_until < now()) + AND NOT EXISTS ( + SELECT 1 FROM outbox_messages p + WHERE p.job_id = o.job_id + AND p.published_at IS NULL + AND p.id < o.id + ) + ORDER BY o.available_at, o.id + LIMIT $1 + FOR UPDATE SKIP LOCKED + ) + UPDATE outbox_messages o + SET claimed_by = $2, + claimed_until = now() + $3::interval + FROM due + WHERE o.id = due.id + RETURNING o.id, o.job_id, o.attempt, o.kind, o.routing_key, o.payload, + o.available_at, o.published_at, COALESCE(o.claimed_by, ''), + o.claimed_until, o.publish_attempts, o.last_error, o.created_at`, + limit, owner, intervalString(claimTTL)) + if err != nil { + return nil, fmt.Errorf("claim outbox: %w", mapError(err)) + } + defer rows.Close() + + messages := make([]domain.OutboxMessage, 0, limit) + + for rows.Next() { + var ( + message domain.OutboxMessage + claimEnd pgtype.Timestamptz + errCode pgtype.Text + pubAt pgtype.Timestamptz + ) + + if err := rows.Scan( + &message.ID, &message.JobID, &message.Attempt, &message.Kind, + &message.RoutingKey, &message.Payload, &message.AvailableAt, &pubAt, + &message.ClaimedBy, &claimEnd, &message.PublishAttempts, &errCode, + &message.CreatedAt, + ); err != nil { + return nil, fmt.Errorf("scan outbox: %w", mapError(err)) + } + + if pubAt.Valid { + value := pubAt.Time.UTC() + message.PublishedAt = &value + } + if claimEnd.Valid { + value := claimEnd.Time.UTC() + message.ClaimedUntil = &value + } + if errCode.Valid { + value := errCode.String + message.LastError = &value + } + + messages = append(messages, message) + } + + if err := rows.Err(); err != nil { + return nil, fmt.Errorf("claim outbox: %w", mapError(err)) + } + + return messages, nil +} + +func (r *PipelineRepository) MarkPublished(ctx context.Context, ids []int64) error { + if len(ids) == 0 { + return nil + } + + ctx, cancel := r.store.timeout(ctx) + defer cancel() + + _, err := r.store.pool.Exec(ctx, ` + UPDATE outbox_messages + SET published_at = now(), + claimed_by = NULL, + claimed_until = NULL + WHERE id = ANY($1::bigint[])`, ids) + if err != nil { + return fmt.Errorf("mark outbox published: %w", mapError(err)) + } + + return nil +} + +func (r *PipelineRepository) ReleaseOutbox(ctx context.Context, id int64, reason string) error { + ctx, cancel := r.store.timeout(ctx) + defer cancel() + + _, err := r.store.pool.Exec(ctx, ` + UPDATE outbox_messages + SET claimed_by = NULL, + claimed_until = NULL, + publish_attempts = publish_attempts + 1, + last_error = $2, + available_at = now() + interval '5 seconds' + WHERE id = $1`, id, reason) + if err != nil { + return fmt.Errorf("release outbox: %w", mapError(err)) + } + + return nil +} + +func (r *PipelineRepository) ReapOutboxClaims(ctx context.Context) error { + ctx, cancel := r.store.timeout(ctx) + defer cancel() + + _, err := r.store.pool.Exec(ctx, ` + UPDATE outbox_messages + SET claimed_by = NULL, claimed_until = NULL + WHERE published_at IS NULL AND claimed_until < now()`) + if err != nil { + return fmt.Errorf("reap outbox claims: %w", mapError(err)) + } + + return nil +} + +func (r *PipelineRepository) PruneOutbox(ctx context.Context, retention time.Duration) error { + ctx, cancel := r.store.timeout(ctx) + defer cancel() + + _, err := r.store.pool.Exec(ctx, ` + DELETE FROM outbox_messages + WHERE published_at IS NOT NULL AND published_at < now() - $1::interval`, + intervalString(retention)) + if err != nil { + return fmt.Errorf("prune outbox: %w", mapError(err)) + } + + return nil +} + +func (r *PipelineRepository) OldestUnpublished(ctx context.Context) (time.Time, error) { + ctx, cancel := r.store.timeout(ctx) + defer cancel() + + var oldest pgtype.Timestamptz + + err := r.store.pool.QueryRow(ctx, ` + SELECT min(created_at) FROM outbox_messages WHERE published_at IS NULL`).Scan(&oldest) + if err != nil { + return time.Time{}, fmt.Errorf("oldest unpublished: %w", mapError(err)) + } + + if !oldest.Valid { + return time.Time{}, nil + } + + return oldest.Time.UTC(), nil +} + +// Reprocess enqueues a new pipeline version without publishing it until the +// worker commits all variants. The serving version is switched atomically by +// CompleteJob. +func (r *PipelineRepository) Reprocess( + ctx context.Context, + attachmentID uuid.UUID, + targetVersion, maxAttempts int, + jobID uuid.UUID, +) (domain.Job, error) { + var created domain.Job + + err := r.withTx(ctx, func(tx pgx.Tx) error { + // Keep the global lock order job -> attachment, as in CompleteJob. + if _, err := tx.Exec(ctx, ` + SELECT 1 FROM attachment_jobs + WHERE attachment_id = $1 AND status IN ('queued', 'processing') + AND pipeline_version < $2 + FOR UPDATE`, attachmentID, targetVersion); err != nil { + return fmt.Errorf("lock superseded jobs: %w", mapError(err)) + } + + attachmentRow := tx.QueryRow(ctx, ` + SELECT `+attachmentReturning+` + FROM attachments WHERE id = $1 FOR UPDATE`, attachmentID) + + attachment, err := scanAttachmentRow(attachmentRow) + if err != nil { + return fmt.Errorf("load reprocess attachment: %w", mapError(err)) + } + + if targetVersion <= attachment.PipelineVersion { + return fmt.Errorf("%w: target pipeline version must be newer", domain.ErrConflict) + } + + if attachment.Status == domain.AttachmentPending { + return fmt.Errorf("%w: attachment upload is not complete", domain.ErrConflict) + } + + // The verified upload lives in staging until the first pipeline + // publishes the final original. A queued/processing/failed attachment + // must reprocess from staging: object_key points at a final original + // that may not exist yet (worker stopped before the first run), and + // choosing it would supersede v1 and leave the attachment queued with + // no jobs after v2 fails with source_missing. + sourceKey := attachment.StagingKey + if attachment.Status == domain.AttachmentReady { + // Ready means the final original was published; staging may have + // passed its retention window already. + sourceKey = attachment.ObjectKey + } + if sourceKey == "" { + sourceKey = attachment.ObjectKey + } + if sourceKey == "" { + return fmt.Errorf("%w: attachment has no source object", domain.ErrConflict) + } + + rows, err := tx.Query(ctx, ` + UPDATE attachment_jobs + SET status = 'superseded', updated_at = now(), completed_at = now() + WHERE attachment_id = $1 AND status IN ('queued', 'processing') + AND pipeline_version < $2 + RETURNING job_id, attempt`, attachmentID, targetVersion) + if err != nil { + return fmt.Errorf("supersede old jobs: %w", mapError(err)) + } + + type supersededJob struct { + id uuid.UUID + attempt int + } + + superseded := make([]supersededJob, 0, 2) + + for rows.Next() { + var old supersededJob + if err := rows.Scan(&old.id, &old.attempt); err != nil { + rows.Close() + + return fmt.Errorf("scan superseded job: %w", mapError(err)) + } + + superseded = append(superseded, old) + } + + if err := rows.Err(); err != nil { + rows.Close() + + return fmt.Errorf("list superseded jobs: %w", mapError(err)) + } + + rows.Close() + + for _, old := range superseded { + if err := insertEventTx(ctx, tx, old.id, domain.EventSuperseded, old.attempt, ""); err != nil { + return err + } + } + + if attachment.Status != domain.AttachmentReady { + _, err = tx.Exec(ctx, ` + UPDATE attachments + SET status = 'queued', error_code = NULL, failed_at = NULL, updated_at = now() + WHERE id = $1 AND status <> 'ready'`, attachmentID) + if err != nil { + return fmt.Errorf("mark reprocess attachment queued: %w", mapError(err)) + } + } + + job := domain.Job{ + ID: jobID, + AttachmentID: attachmentID, + PipelineVersion: targetVersion, + SourceKey: sourceKey, + Attempt: 1, + MaxAttempts: maxAttempts, + CreatedAt: time.Now().UTC(), + } + + job.Traceparent, job.Tracestate = telemetry.Inject(ctx) + _, err = tx.Exec(ctx, ` + INSERT INTO attachment_jobs ( + job_id, attachment_id, pipeline_version, source_key, + attempt, max_attempts, status, available_at, traceparent, tracestate + ) + VALUES ($1, $2, $3, $4, 1, $5, 'queued', now(), $6, $7)`, + job.ID, job.AttachmentID, job.PipelineVersion, job.SourceKey, job.MaxAttempts, + job.Traceparent, job.Tracestate) + if err != nil { + return fmt.Errorf("create reprocess job: %w", mapError(err)) + } + + if err := insertEventTx(ctx, tx, job.ID, domain.EventReprocessed, 1, ""); err != nil { + return err + } + + if err := insertOutboxTx( + ctx, tx, job, 1, "reprocess", time.Now().UTC(), + ); err != nil { + return err + } + + created = job + + return nil + }) + if err != nil { + return domain.Job{}, err + } + + return created, nil +} + +func (r *PipelineRepository) ReplayJob( + ctx context.Context, + jobID uuid.UUID, + extraAttempts int, +) (domain.Job, error) { + if extraAttempts < 1 { + return domain.Job{}, fmt.Errorf("%w: replay attempts must be >= 1", domain.ErrValidation) + } + + var replayed domain.Job + + err := r.withTx(ctx, func(tx pgx.Tx) error { + job, attachment, err := lockJobAndAttachment(ctx, tx, jobID) + if err != nil { + return err + } + + if job.Status != domain.JobFailed { + return fmt.Errorf("%w: only failed jobs can be replayed", domain.ErrConflict) + } + + if job.PipelineVersion < attachment.PipelineVersion { + return fmt.Errorf("%w: job is superseded by a newer pipeline version", domain.ErrConflict) + } + + // A newer version may still be unpublished (attachment.pipeline_version + // changes only when it commits), so compare against job rows too. An + // older replay must not compete with a newer job for the same staging + // source or return the attachment to an older state. + var newerJob bool + + if err := tx.QueryRow(ctx, ` + SELECT EXISTS ( + SELECT 1 FROM attachment_jobs + WHERE attachment_id = $1 AND pipeline_version > $2 + )`, job.AttachmentID, job.PipelineVersion).Scan(&newerJob); err != nil { + return fmt.Errorf("check newer pipeline version: %w", mapError(err)) + } + + if newerJob { + return fmt.Errorf("%w: a newer pipeline version already has a job", domain.ErrConflict) + } + + nextAttempt := job.Attempt + 1 + + _, err = tx.Exec(ctx, ` + UPDATE attachment_jobs + SET status = 'queued', + attempt = $2, + max_attempts = $2::int + $3::int - 1, + available_at = now(), + lease_owner = NULL, + lease_expires_at = NULL, + last_error_code = NULL, + replay_count = replay_count + 1, + completed_at = NULL, + updated_at = now() + WHERE job_id = $1`, job.ID, nextAttempt, extraAttempts) + if err != nil { + return fmt.Errorf("replay job: %w", mapError(err)) + } + + // Mirror failJobTx: a replay of a newer unpublished version returns + // the attachment to queued so the API does not keep showing a stale + // terminal state while the replayed job waits. A published ready + // version is never disturbed by a newer version's replay. + switch { + case job.PipelineVersion == attachment.PipelineVersion: + _, err = tx.Exec(ctx, ` + UPDATE attachments + SET status = 'queued', error_code = NULL, failed_at = NULL, updated_at = now() + WHERE id = $1 AND pipeline_version = $2`, + attachment.ID, job.PipelineVersion) + case job.PipelineVersion > attachment.PipelineVersion && attachment.Status != domain.AttachmentReady: + _, err = tx.Exec(ctx, ` + UPDATE attachments + SET status = 'queued', error_code = NULL, failed_at = NULL, updated_at = now() + WHERE id = $1 AND status <> 'ready'`, attachment.ID) + } + if err != nil { + return fmt.Errorf("replay attachment: %w", mapError(err)) + } + + if err := insertEventTx(ctx, tx, job.ID, domain.EventReplayed, nextAttempt, ""); err != nil { + return err + } + + job.Attempt = nextAttempt + job.MaxAttempts = nextAttempt + extraAttempts - 1 + + if err := insertOutboxTx( + ctx, tx, job, nextAttempt, "replay", time.Now().UTC(), + ); err != nil { + return err + } + + replayed = job + + return nil + }) + if err != nil { + return domain.Job{}, err + } + + return replayed, nil +} + +// Duplicate inserts another publication of the current job attempt. It exists +// only for deterministic duplicate-delivery evidence. +func (r *PipelineRepository) Duplicate(ctx context.Context, attachmentID uuid.UUID) (domain.OutboxMessage, error) { + var created domain.OutboxMessage + + err := r.withTx(ctx, func(tx pgx.Tx) error { + jobRow := tx.QueryRow(ctx, ` + SELECT `+jobReturning+` + FROM attachment_jobs + WHERE attachment_id = $1 + ORDER BY pipeline_version DESC + LIMIT 1`, attachmentID) + + job, err := scanJobRow(jobRow) + if err != nil { + return fmt.Errorf("load duplicate job: %w", mapError(err)) + } + + if err := insertOutboxTx( + ctx, tx, job, job.Attempt, "duplicate", time.Now().UTC(), + ); err != nil { + return err + } + + created = domain.OutboxMessage{ + JobID: job.ID, + Attempt: job.Attempt, + Kind: "duplicate", + RoutingKey: defaultRoutingKey, + } + + return nil + }) + if err != nil { + return domain.OutboxMessage{}, err + } + + return created, nil +} + +func (r *PipelineRepository) ListFailedJobs( + ctx context.Context, + limit int, +) ([]domain.Job, error) { + ctx, cancel := r.store.timeout(ctx) + defer cancel() + + rows, err := r.store.pool.Query(ctx, ` + SELECT `+jobReturning+` + FROM attachment_jobs + WHERE status = 'failed' + ORDER BY updated_at DESC + LIMIT $1`, limit) + if err != nil { + return nil, fmt.Errorf("list failed jobs: %w", mapError(err)) + } + defer rows.Close() + + jobs := make([]domain.Job, 0, limit) + + for rows.Next() { + job, err := scanJobRow(rows) + if err != nil { + return nil, fmt.Errorf("scan failed job: %w", mapError(err)) + } + jobs = append(jobs, job) + } + + if err := rows.Err(); err != nil { + return nil, fmt.Errorf("list failed jobs: %w", mapError(err)) + } + + return jobs, nil +} + +func (r *PipelineRepository) GetJob(ctx context.Context, jobID uuid.UUID) (domain.Job, error) { + ctx, cancel := r.store.timeout(ctx) + defer cancel() + + row := r.store.pool.QueryRow(ctx, ` + SELECT `+jobReturning+` FROM attachment_jobs WHERE job_id = $1`, jobID) + + job, err := scanJobRow(row) + if err != nil { + return domain.Job{}, fmt.Errorf("get job: %w", mapError(err)) + } + + return job, nil +} + +func (r *PipelineRepository) GetJobByAttachment( + ctx context.Context, + attachmentID uuid.UUID, + pipelineVersion int, +) (domain.Job, error) { + ctx, cancel := r.store.timeout(ctx) + defer cancel() + + row := r.store.pool.QueryRow(ctx, ` + SELECT `+jobReturning+` + FROM attachment_jobs + WHERE attachment_id = $1 AND pipeline_version = $2`, + attachmentID, pipelineVersion) + + job, err := scanJobRow(row) + if err != nil { + return domain.Job{}, fmt.Errorf("get job by attachment: %w", mapError(err)) + } + + return job, nil +} + +func (r *PipelineRepository) GetForID(ctx context.Context, id uuid.UUID) (domain.Attachment, error) { + ctx, cancel := r.store.timeout(ctx) + defer cancel() + + row := r.store.pool.QueryRow(ctx, ` + SELECT `+attachmentReturning+` FROM attachments a WHERE a.id = $1`, id) + + attachment, err := scanAttachmentRow(row) + if err != nil { + return domain.Attachment{}, fmt.Errorf("get attachment: %w", mapError(err)) + } + + return attachment, nil +} + +// MarkStagingDeleted clears the staging projection after the worker removed +// the object (or the sweeper verified it is gone). +func (r *PipelineRepository) MarkStagingDeleted( + ctx context.Context, + attachmentID uuid.UUID, + stagingKey string, +) error { + ctx, cancel := r.store.timeout(ctx) + defer cancel() + + _, err := r.store.pool.Exec(ctx, ` + UPDATE attachments + SET staging_key = NULL, updated_at = now() + WHERE id = $1 AND staging_key = $2`, attachmentID, stagingKey) + if err != nil { + return fmt.Errorf("clear staging key: %w", mapError(err)) + } + + return nil +} + +// ListReferencedKeys returns object keys that must never be collected: +// originals, variants, and staging of active jobs. +func (r *PipelineRepository) ListReferencedKeys( + ctx context.Context, + afterKey string, + limit int, +) ([]string, error) { + ctx, cancel := r.store.timeout(ctx) + defer cancel() + + rows, err := r.store.pool.Query(ctx, ` + SELECT key FROM ( + SELECT object_key AS key FROM attachments + UNION + SELECT object_key AS key FROM attachment_variants + UNION + SELECT staging_key AS key FROM attachments + WHERE staging_key IS NOT NULL AND status IN ('queued', 'processing', 'failed') + ) referenced + WHERE key > $1 + ORDER BY key + LIMIT $2`, afterKey, limit) + if err != nil { + return nil, fmt.Errorf("list referenced keys: %w", mapError(err)) + } + defer rows.Close() + + keys := make([]string, 0, limit) + + for rows.Next() { + var key string + if err := rows.Scan(&key); err != nil { + return nil, fmt.Errorf("scan referenced key: %w", mapError(err)) + } + keys = append(keys, key) + } + + if err := rows.Err(); err != nil { + return nil, fmt.Errorf("list referenced keys: %w", mapError(err)) + } + + return keys, nil +} + +func (r *PipelineRepository) ListStaleStaging( + ctx context.Context, + readyBefore, failedBefore time.Time, + limit int, +) ([]domain.StaleStaging, error) { + ctx, cancel := r.store.timeout(ctx) + defer cancel() + + rows, err := r.store.pool.Query(ctx, ` + SELECT id, staging_key, status + FROM attachments + WHERE staging_key IS NOT NULL + AND ( + (status = 'ready' AND updated_at < $1) OR + (status = 'failed' AND updated_at < $2) + ) + ORDER BY updated_at + LIMIT $3`, readyBefore, failedBefore, limit) + if err != nil { + return nil, fmt.Errorf("list stale staging: %w", mapError(err)) + } + defer rows.Close() + + stale := make([]domain.StaleStaging, 0, limit) + + for rows.Next() { + var ( + row domain.StaleStaging + status string + ) + if err := rows.Scan(&row.AttachmentID, &row.StagingKey, &status); err != nil { + return nil, fmt.Errorf("scan stale staging: %w", mapError(err)) + } + row.Status = domain.AttachmentStatus(status) + stale = append(stale, row) + } + + if err := rows.Err(); err != nil { + return nil, fmt.Errorf("list stale staging: %w", mapError(err)) + } + + return stale, nil +} + +func (r *PipelineRepository) ListPendingPresign( + ctx context.Context, + createdBefore time.Time, + limit int, +) ([]domain.Attachment, error) { + ctx, cancel := r.store.timeout(ctx) + defer cancel() + + rows, err := r.store.pool.Query(ctx, ` + SELECT `+attachmentReturning+` + FROM attachments a + WHERE status = 'pending' AND created_at < $1 + ORDER BY created_at + LIMIT $2`, createdBefore, limit) + if err != nil { + return nil, fmt.Errorf("list pending presign: %w", mapError(err)) + } + defer rows.Close() + + pending := make([]domain.Attachment, 0, limit) + + for rows.Next() { + attachment, err := scanAttachmentRow(rows) + if err != nil { + return nil, fmt.Errorf("scan pending presign: %w", mapError(err)) + } + pending = append(pending, attachment) + } + + if err := rows.Err(); err != nil { + return nil, fmt.Errorf("list pending presign: %w", mapError(err)) + } + + return pending, nil +} + +func (r *PipelineRepository) DeletePending(ctx context.Context, id uuid.UUID) error { + ctx, cancel := r.store.timeout(ctx) + defer cancel() + + _, err := r.store.pool.Exec(ctx, ` + DELETE FROM attachments WHERE id = $1 AND status = 'pending'`, id) + if err != nil { + return fmt.Errorf("delete pending attachment: %w", mapError(err)) + } + + return nil +} + +func (r *PipelineRepository) InsertRawOutbox( + ctx context.Context, + jobID uuid.UUID, + attempt int, + kind string, + payload []byte, + availableAt time.Time, +) error { + ctx, cancel := r.store.timeout(ctx) + defer cancel() + + _, err := r.store.pool.Exec(ctx, ` + INSERT INTO outbox_messages (job_id, attempt, kind, routing_key, payload, available_at) + VALUES ($1, $2, $3, $4, $5::jsonb, $6)`, + jobID, attempt, kind, defaultRoutingKey, string(payload), availableAt) + if err != nil { + return fmt.Errorf("insert raw outbox: %w", mapError(err)) + } + + return nil +} + +// CreatePresign stores the internal pending row before a direct upload. It is +// never exposed by the API. +func (r *PipelineRepository) CreatePresign( + ctx context.Context, + draft domain.AttachmentDraft, + limits domain.AdmissionLimits, +) (domain.Attachment, error) { + var attachment domain.Attachment + + err := r.withTx(ctx, func(tx pgx.Tx) error { + if err := checkAdmissionTx(ctx, tx, draft.OwnerID, limits); err != nil { + return err + } + + row := tx.QueryRow(ctx, ` + INSERT INTO attachments ( + id, chat_id, owner_id, object_key, filename, content_type, + size_bytes, sha256, status, pipeline_version, staging_key + ) + VALUES ($1, $2, $3, $4, $5, $6, $7, $8, 'pending', $9, $10) + RETURNING `+attachmentReturning, + draft.ID, draft.ChatID, draft.OwnerID, draft.ObjectKey, draft.Filename, + draft.ContentType, draft.SizeBytes, draft.SHA256, + draft.PipelineVersion, draft.StagingKey, + ) + + created, err := scanAttachmentRow(row) + if err != nil { + return fmt.Errorf("create presign attachment: %w", mapError(err)) + } + + attachment = created + + return nil + }) + if err != nil { + return domain.Attachment{}, err + } + + return attachment, nil +} + +const admissionLockKey int64 = 0x41444d31 // "ADM1" + +// checkAdmissionTx serializes upload admission across API replicas with a +// transaction-scoped advisory lock, then re-counts pending/queued/processing +// rows. This closes the check-then-act window before the row is inserted. +func checkAdmissionTx(ctx context.Context, tx pgx.Tx, ownerID uuid.UUID, limits domain.AdmissionLimits) error { + if limits.PerUser == 0 && limits.Total == 0 && limits.Bytes == 0 { + return nil + } + + if _, err := tx.Exec(ctx, `SELECT pg_advisory_xact_lock($1)`, admissionLockKey); err != nil { + return fmt.Errorf("lock admission: %w", mapError(err)) + } + + var ( + total int + bytes int64 + ) + + err := tx.QueryRow(ctx, ` + SELECT count(*)::int, COALESCE(sum(size_bytes), 0)::bigint + FROM attachments + WHERE status IN ('pending', 'queued', 'processing')`).Scan(&total, &bytes) + if err != nil { + return fmt.Errorf("admission count: %w", mapError(err)) + } + + perUser := 0 + if limits.PerUser > 0 { + if err := tx.QueryRow(ctx, ` + SELECT count(*)::int FROM attachments + WHERE status IN ('pending', 'queued', 'processing') + AND owner_id = $1`, ownerID).Scan(&perUser); err != nil { + return fmt.Errorf("admission per-user count: %w", mapError(err)) + } + } + + if (limits.PerUser > 0 && perUser >= limits.PerUser) || + (limits.Total > 0 && total >= limits.Total) || + (limits.Bytes > 0 && bytes >= limits.Bytes) { + return fmt.Errorf("%w: admission limit reached", domain.ErrRateLimited) + } + + return nil +} + +// DuplicateJob publishes another copy of a specific job attempt. It is used by +// the fault-injection evidence to simulate duplicate delivery of an old version. +func (r *PipelineRepository) DuplicateJob(ctx context.Context, jobID uuid.UUID) (domain.OutboxMessage, error) { + var created domain.OutboxMessage + + err := r.withTx(ctx, func(tx pgx.Tx) error { + jobRow := tx.QueryRow(ctx, ` + SELECT `+jobReturning+` FROM attachment_jobs WHERE job_id = $1`, jobID) + + job, err := scanJobRow(jobRow) + if err != nil { + return fmt.Errorf("load duplicate job: %w", mapError(err)) + } + + if err := insertOutboxTx( + ctx, tx, job, job.Attempt, "duplicate", time.Now().UTC(), + ); err != nil { + return err + } + + created = domain.OutboxMessage{ + JobID: job.ID, Attempt: job.Attempt, Kind: "duplicate", RoutingKey: defaultRoutingKey, + } + + return nil + }) + if err != nil { + return domain.OutboxMessage{}, err + } + + return created, nil +} + +// ReconcileQueuedJobs republishes jobs whose only broker delivery was lost +// (dead-lettered, dropped, or a broker data loss). The worker CAS makes an +// extra delivery a no-op. Only one unpublished outbox row is created per job. +func (r *PipelineRepository) ReconcileQueuedJobs( + ctx context.Context, + olderThan time.Duration, + limit int, + _ string, + _ string, +) (int, error) { + reconciled := 0 + + err := r.withTx(ctx, func(tx pgx.Tx) error { + rows, err := tx.Query(ctx, ` + SELECT `+jobReturning+` + FROM attachment_jobs + WHERE status = 'queued' + AND available_at <= now() - $1::interval + AND NOT EXISTS ( + SELECT 1 FROM outbox_messages o + WHERE o.job_id = attachment_jobs.job_id AND o.published_at IS NULL + ) + ORDER BY available_at + LIMIT $2 + FOR UPDATE SKIP LOCKED`, + intervalString(olderThan), limit) + if err != nil { + return fmt.Errorf("select lost queued jobs: %w", mapError(err)) + } + + jobs := make([]domain.Job, 0, limit) + for rows.Next() { + job, err := scanJobRow(rows) + if err != nil { + rows.Close() + + return fmt.Errorf("scan lost queued job: %w", mapError(err)) + } + jobs = append(jobs, job) + } + if err := rows.Err(); err != nil { + rows.Close() + + return fmt.Errorf("list lost queued jobs: %w", mapError(err)) + } + rows.Close() + + for _, job := range jobs { + jobCtx, span := telemetry.StartRequeueSpanForJob(ctx, job) + err := insertOutboxTx(jobCtx, tx, job, job.Attempt, "reconcile", time.Now().UTC()) + span.End() + if err != nil { + return err + } + reconciled++ + } + + return nil + }) + if err != nil { + return 0, err + } + + return reconciled, nil +} diff --git a/internal/storage/postgres/pipeline_repository_test.go b/internal/storage/postgres/pipeline_repository_test.go new file mode 100644 index 0000000..d0f9d6d --- /dev/null +++ b/internal/storage/postgres/pipeline_repository_test.go @@ -0,0 +1,586 @@ +//go:build integration + +package postgres_test + +import ( + "strings" + "testing" + "time" + + "github.com/google/uuid" + "github.com/stretchr/testify/suite" + + "mtusi-messenger/internal/domain" +) + +type PipelineSuite struct { + BaseSuite +} + +func TestPipelineSuite(t *testing.T) { + suite.Run(t, new(PipelineSuite)) +} + +func (s *PipelineSuite) attachmentDraft(chat domain.Chat, owner domain.User, version int) (domain.AttachmentDraft, domain.Job) { + s.T().Helper() + + id, err := uuid.NewV7() + s.Require().NoError(err) + jobID, err := uuid.NewV7() + s.Require().NoError(err) + + draft := domain.AttachmentDraft{ + ID: id, + ChatID: chat.ID, + OwnerID: owner.ID, + ObjectKey: domain.OriginalObjectKey(chat.ID, id), + StagingKey: domain.StagingUploadKey(chat.ID, id), + Filename: "photo.png", + ContentType: "image/png", + SizeBytes: 10, + SHA256: strings.Repeat("a", 64), + Status: domain.AttachmentQueued, + PipelineVersion: version, + } + + job := domain.Job{ + ID: jobID, + AttachmentID: id, + PipelineVersion: version, + SourceKey: draft.StagingKey, + Attempt: 1, + MaxAttempts: 5, + CreatedAt: time.Now().UTC(), + } + + return draft, job +} + +func (s *PipelineSuite) TestCreateClaimCompleteAndIdempotentRedelivery() { + alice := s.createUser("alice") + bob := s.createUser("bob") + chat := s.createChat(alice, bob) + + draft, job := s.attachmentDraft(chat, alice, 1) + repo := s.store.Pipeline() + + created, err := repo.CreateQueued(s.T().Context(), draft, job, domain.AdmissionLimits{}) + s.Require().NoError(err) + s.Equal(domain.AttachmentQueued, created.Status) + s.Equal(1, created.PipelineVersion) + + message := domain.NewJobMessage(job) + claim, err := repo.ClaimJob(s.T().Context(), message, "lease-1", time.Minute) + s.Require().NoError(err) + s.Equal(domain.ClaimAcquired, claim.Outcome) + s.Equal(domain.AttachmentProcessing, claim.Attachment.Status) + + duplicate, err := repo.ClaimJob(s.T().Context(), message, "lease-2", time.Minute) + s.Require().NoError(err) + s.Equal(domain.ClaimBusyLease, duplicate.Outcome) + + variants := []domain.Variant{ + { + Name: domain.VariantThumbnail, ContentType: "image/jpeg", SizeBytes: 11, + Width: 256, Height: 160, SHA256: strings.Repeat("b", 64), + ObjectKey: domain.VariantObjectKey(chat.ID, draft.ID, 1, domain.VariantThumbnail), + }, + } + + ok, err := repo.CompleteJob(s.T().Context(), job.ID, 1, "lease-1", variants) + s.Require().NoError(err) + s.True(ok) + + ready, err := repo.GetForMember(s.T().Context(), bob.ID, draft.ID) + s.Require().NoError(err) + s.Equal(domain.AttachmentReady, ready.Status) + + stored, err := repo.ListVariants(s.T().Context(), draft.ID, 1) + s.Require().NoError(err) + s.Require().Len(stored, 1) + s.Equal(domain.VariantThumbnail, stored[0].Name) + + // A redelivery after ready is a no-op, even with the same attempt. + again, err := repo.ClaimJob(s.T().Context(), message, "lease-3", time.Minute) + s.Require().NoError(err) + s.Equal(domain.ClaimAlreadyReady, again.Outcome) +} + +func (s *PipelineSuite) TestLeaseExpiryIsBoundedByMaxAttempts() { + alice := s.createUser("alice") + chat := s.createChat(alice) + + draft, job := s.attachmentDraft(chat, alice, 1) + job.MaxAttempts = 1 + + repo := s.store.Pipeline() + _, err := repo.CreateQueued(s.T().Context(), draft, job, domain.AdmissionLimits{}) + s.Require().NoError(err) + + claim, err := repo.ClaimJob(s.T().Context(), domain.NewJobMessage(job), "lease", time.Millisecond) + s.Require().NoError(err) + s.Equal(domain.ClaimAcquired, claim.Outcome) + + time.Sleep(10 * time.Millisecond) + + reaped, err := repo.ReapExpiredLeases(s.T().Context(), 10) + s.Require().NoError(err) + s.Equal(1, reaped) + + dead, err := repo.GetJob(s.T().Context(), job.ID) + s.Require().NoError(err) + s.Equal(domain.JobFailed, dead.Status) + s.NotNil(dead.LastErrorCode) + s.Equal("retry_exhausted", *dead.LastErrorCode) +} + +func (s *PipelineSuite) TestAdmissionCountsPendingPresignAndIsAtomic() { + alice := s.createUser("alice") + chat := s.createChat(alice) + repo := s.store.Pipeline() + + draft, _ := s.attachmentDraft(chat, alice, 1) + draft.ObjectKey = "staging/presign/" + chat.ID.String() + "/" + draft.ID.String() + draft.StagingKey = draft.ObjectKey + draft.Status = domain.AttachmentPending + + limits := domain.AdmissionLimits{PerUser: 1, Total: 10} + + _, err := repo.CreatePresign(s.T().Context(), draft, limits) + s.Require().NoError(err) + + second, _ := s.attachmentDraft(chat, alice, 1) + second.ObjectKey = "staging/presign/" + chat.ID.String() + "/" + second.ID.String() + second.StagingKey = second.ObjectKey + second.Status = domain.AttachmentPending + + _, err = repo.CreatePresign(s.T().Context(), second, limits) + s.Require().ErrorIs(err, domain.ErrRateLimited) +} + +// A queued upload whose worker never ran still has its verified bytes only in +// staging. Reprocessing it must use staging as the source; pointing at the +// not-yet-written final original left the attachment queued forever after the +// v1 job was superseded (v2 then failed with source_missing). +func (s *PipelineSuite) TestReprocessQueuedUsesStagingSource() { + alice := s.createUser("alice") + bob := s.createUser("bob") + chat := s.createChat(alice, bob) + + draft, job := s.attachmentDraft(chat, alice, 1) + repo := s.store.Pipeline() + + _, err := repo.CreateQueued(s.T().Context(), draft, job, domain.AdmissionLimits{}) + s.Require().NoError(err) + + reprocessID, err := uuid.NewV7() + s.Require().NoError(err) + + created, err := repo.Reprocess(s.T().Context(), draft.ID, 2, 5, reprocessID) + s.Require().NoError(err) + s.Equal(2, created.PipelineVersion) + s.Equal(draft.StagingKey, created.SourceKey) +} + +// Once a pipeline has published the final original, the staging copy may be +// past its retention window; a reprocess of a ready attachment must source +// from the final object that actually exists. +func (s *PipelineSuite) TestReprocessReadyUsesObjectSource() { + alice := s.createUser("alice") + chat := s.createChat(alice) + + draft, job := s.attachmentDraft(chat, alice, 1) + repo := s.store.Pipeline() + + _, err := repo.CreateQueued(s.T().Context(), draft, job, domain.AdmissionLimits{}) + s.Require().NoError(err) + + message := domain.NewJobMessage(job) + claim, err := repo.ClaimJob(s.T().Context(), message, "lease-1", time.Minute) + s.Require().NoError(err) + s.Equal(domain.ClaimAcquired, claim.Outcome) + + variants := []domain.Variant{ + { + Name: domain.VariantThumbnail, ContentType: "image/jpeg", SizeBytes: 11, + Width: 256, Height: 160, SHA256: strings.Repeat("b", 64), + ObjectKey: domain.VariantObjectKey(chat.ID, draft.ID, 1, domain.VariantThumbnail), + }, + } + + ok, err := repo.CompleteJob(s.T().Context(), job.ID, 1, "lease-1", variants) + s.Require().NoError(err) + s.True(ok) + + reprocessID, err := uuid.NewV7() + s.Require().NoError(err) + + created, err := repo.Reprocess(s.T().Context(), draft.ID, 2, 5, reprocessID) + s.Require().NoError(err) + s.Equal(2, created.PipelineVersion) + s.Equal(draft.ObjectKey, created.SourceKey) +} + +// A reprocess failure before any version was published must settle the +// attachment as failed instead of leaving it queued with no active jobs. +func (s *PipelineSuite) TestReprocessFailureSettlesUnpublishedAttachment() { + alice := s.createUser("alice") + chat := s.createChat(alice) + repo := s.store.Pipeline() + + draft, job := s.attachmentDraft(chat, alice, 1) + _, err := repo.CreateQueued(s.T().Context(), draft, job, domain.AdmissionLimits{}) + s.Require().NoError(err) + + reprocessID, err := uuid.NewV7() + s.Require().NoError(err) + + reprocess, err := repo.Reprocess(s.T().Context(), draft.ID, 2, 5, reprocessID) + s.Require().NoError(err) + + claim, err := repo.ClaimJob(s.T().Context(), domain.NewJobMessage(reprocess), "lease-2", time.Minute) + s.Require().NoError(err) + s.Equal(domain.ClaimAcquired, claim.Outcome) + + failed, err := repo.FailJob(s.T().Context(), reprocess.ID, 1, "lease-2", "invalid_image") + s.Require().NoError(err) + s.True(failed) + + current, err := repo.GetForOwner(s.T().Context(), alice.ID, draft.ID) + s.Require().NoError(err) + s.Equal(domain.AttachmentFailed, current.Status) + s.Require().NotNil(current.ErrorCode) + s.Equal("invalid_image", *current.ErrorCode) +} + +// A reprocess failure while an older ready version is serving must keep that +// version ready and downloadable; only the new job fails. +func (s *PipelineSuite) TestReprocessFailureKeepsReadyServingVersion() { + alice := s.createUser("alice") + chat := s.createChat(alice) + repo := s.store.Pipeline() + + draft, job := s.attachmentDraft(chat, alice, 1) + _, err := repo.CreateQueued(s.T().Context(), draft, job, domain.AdmissionLimits{}) + s.Require().NoError(err) + + claim, err := repo.ClaimJob(s.T().Context(), domain.NewJobMessage(job), "lease-1", time.Minute) + s.Require().NoError(err) + s.Equal(domain.ClaimAcquired, claim.Outcome) + + variants := []domain.Variant{ + { + Name: domain.VariantThumbnail, ContentType: "image/jpeg", SizeBytes: 11, + Width: 256, Height: 160, SHA256: strings.Repeat("b", 64), + ObjectKey: domain.VariantObjectKey(chat.ID, draft.ID, 1, domain.VariantThumbnail), + }, + } + + ok, err := repo.CompleteJob(s.T().Context(), job.ID, 1, "lease-1", variants) + s.Require().NoError(err) + s.True(ok) + + reprocessID, err := uuid.NewV7() + s.Require().NoError(err) + + reprocess, err := repo.Reprocess(s.T().Context(), draft.ID, 2, 5, reprocessID) + s.Require().NoError(err) + + claim, err = repo.ClaimJob(s.T().Context(), domain.NewJobMessage(reprocess), "lease-2", time.Minute) + s.Require().NoError(err) + s.Equal(domain.ClaimAcquired, claim.Outcome) + + failed, err := repo.FailJob(s.T().Context(), reprocess.ID, 1, "lease-2", "invalid_image") + s.Require().NoError(err) + s.True(failed) + + current, err := repo.GetForOwner(s.T().Context(), alice.ID, draft.ID) + s.Require().NoError(err) + s.Equal(domain.AttachmentReady, current.Status) + s.Equal(1, current.PipelineVersion) + s.Nil(current.ErrorCode) +} + +// Replaying a failed newer version must clear the stale terminal projection +// for an attachment that never published any version. +func (s *PipelineSuite) TestReplayNewerFailedVersionRequeuesUnpublishedAttachment() { + alice := s.createUser("alice") + chat := s.createChat(alice) + repo := s.store.Pipeline() + + draft, job := s.attachmentDraft(chat, alice, 1) + _, err := repo.CreateQueued(s.T().Context(), draft, job, domain.AdmissionLimits{}) + s.Require().NoError(err) + + reprocessID, err := uuid.NewV7() + s.Require().NoError(err) + + reprocess, err := repo.Reprocess(s.T().Context(), draft.ID, 2, 5, reprocessID) + s.Require().NoError(err) + + claim, err := repo.ClaimJob(s.T().Context(), domain.NewJobMessage(reprocess), "lease-2", time.Minute) + s.Require().NoError(err) + s.Equal(domain.ClaimAcquired, claim.Outcome) + + failed, err := repo.FailJob(s.T().Context(), reprocess.ID, 1, "lease-2", "invalid_image") + s.Require().NoError(err) + s.True(failed) + + current, err := repo.GetForOwner(s.T().Context(), alice.ID, draft.ID) + s.Require().NoError(err) + s.Equal(domain.AttachmentFailed, current.Status) + + replayed, err := repo.ReplayJob(s.T().Context(), reprocess.ID, 2) + s.Require().NoError(err) + s.Equal(2, replayed.Attempt) + + current, err = repo.GetForOwner(s.T().Context(), alice.ID, draft.ID) + s.Require().NoError(err) + s.Equal(domain.AttachmentQueued, current.Status) + s.Nil(current.ErrorCode) + + claim, err = repo.ClaimJob(s.T().Context(), domain.NewJobMessage(replayed), "lease-3", time.Minute) + s.Require().NoError(err) + s.Equal(domain.ClaimAcquired, claim.Outcome) + + variants := []domain.Variant{ + { + Name: domain.VariantThumbnail, ContentType: "image/jpeg", SizeBytes: 11, + Width: 256, Height: 160, SHA256: strings.Repeat("c", 64), + ObjectKey: domain.VariantObjectKey(chat.ID, draft.ID, 2, domain.VariantThumbnail), + }, + } + + ok, err := repo.CompleteJob(s.T().Context(), replayed.ID, replayed.Attempt, "lease-3", variants) + s.Require().NoError(err) + s.True(ok) + + current, err = repo.GetForOwner(s.T().Context(), alice.ID, draft.ID) + s.Require().NoError(err) + s.Equal(domain.AttachmentReady, current.Status) + s.Equal(2, current.PipelineVersion) +} + +// Replaying a failed newer version must not disturb a published ready +// serving version; only the new job returns to queued. +func (s *PipelineSuite) TestReplayNewerFailedVersionKeepsReadyServingVersion() { + alice := s.createUser("alice") + chat := s.createChat(alice) + repo := s.store.Pipeline() + + draft, job := s.attachmentDraft(chat, alice, 1) + _, err := repo.CreateQueued(s.T().Context(), draft, job, domain.AdmissionLimits{}) + s.Require().NoError(err) + + claim, err := repo.ClaimJob(s.T().Context(), domain.NewJobMessage(job), "lease-1", time.Minute) + s.Require().NoError(err) + s.Equal(domain.ClaimAcquired, claim.Outcome) + + variants := []domain.Variant{ + { + Name: domain.VariantThumbnail, ContentType: "image/jpeg", SizeBytes: 11, + Width: 256, Height: 160, SHA256: strings.Repeat("b", 64), + ObjectKey: domain.VariantObjectKey(chat.ID, draft.ID, 1, domain.VariantThumbnail), + }, + } + + ok, err := repo.CompleteJob(s.T().Context(), job.ID, 1, "lease-1", variants) + s.Require().NoError(err) + s.True(ok) + + reprocessID, err := uuid.NewV7() + s.Require().NoError(err) + + reprocess, err := repo.Reprocess(s.T().Context(), draft.ID, 2, 5, reprocessID) + s.Require().NoError(err) + + claim, err = repo.ClaimJob(s.T().Context(), domain.NewJobMessage(reprocess), "lease-2", time.Minute) + s.Require().NoError(err) + s.Equal(domain.ClaimAcquired, claim.Outcome) + + failed, err := repo.FailJob(s.T().Context(), reprocess.ID, 1, "lease-2", "invalid_image") + s.Require().NoError(err) + s.True(failed) + + replayed, err := repo.ReplayJob(s.T().Context(), reprocess.ID, 1) + s.Require().NoError(err) + s.Equal(2, replayed.Attempt) + + current, err := repo.GetForOwner(s.T().Context(), alice.ID, draft.ID) + s.Require().NoError(err) + s.Equal(domain.AttachmentReady, current.Status) + s.Equal(1, current.PipelineVersion) + s.Nil(current.ErrorCode) +} + +// Replaying an older failed version is refused while a newer job exists, +// even before that newer version becomes the published serving version. +func (s *PipelineSuite) TestReplayOlderFailedVersionRefusedWhenNewerJobExists() { + alice := s.createUser("alice") + chat := s.createChat(alice) + repo := s.store.Pipeline() + + draft, job := s.attachmentDraft(chat, alice, 1) + _, err := repo.CreateQueued(s.T().Context(), draft, job, domain.AdmissionLimits{}) + s.Require().NoError(err) + + claim, err := repo.ClaimJob(s.T().Context(), domain.NewJobMessage(job), "lease-1", time.Minute) + s.Require().NoError(err) + s.Equal(domain.ClaimAcquired, claim.Outcome) + + failed, err := repo.FailJob(s.T().Context(), job.ID, 1, "lease-1", "invalid_image") + s.Require().NoError(err) + s.True(failed) + + reprocessID, err := uuid.NewV7() + s.Require().NoError(err) + + _, err = repo.Reprocess(s.T().Context(), draft.ID, 2, 5, reprocessID) + s.Require().NoError(err) + + _, err = repo.ReplayJob(s.T().Context(), job.ID, 1) + s.Require().ErrorIs(err, domain.ErrConflict) + + var v1Status string + s.Require().NoError(s.pool.QueryRow(s.T().Context(), + `SELECT status FROM attachment_jobs WHERE job_id = $1`, job.ID).Scan(&v1Status)) + s.Equal(string(domain.JobFailed), v1Status) +} + +// A queued job for an older version is retired on claim instead of being +// acknowledged and republished by reconciliation forever. +func (s *PipelineSuite) TestClaimRetiresVersionStaleQueuedJob() { + alice := s.createUser("alice") + chat := s.createChat(alice) + repo := s.store.Pipeline() + + draft, job := s.attachmentDraft(chat, alice, 1) + _, err := repo.CreateQueued(s.T().Context(), draft, job, domain.AdmissionLimits{}) + s.Require().NoError(err) + + reprocessID, err := uuid.NewV7() + s.Require().NoError(err) + + reprocess, err := repo.Reprocess(s.T().Context(), draft.ID, 2, 5, reprocessID) + s.Require().NoError(err) + + claim, err := repo.ClaimJob(s.T().Context(), domain.NewJobMessage(reprocess), "lease-2", time.Minute) + s.Require().NoError(err) + s.Equal(domain.ClaimAcquired, claim.Outcome) + + variants := []domain.Variant{ + { + Name: domain.VariantThumbnail, ContentType: "image/jpeg", SizeBytes: 11, + Width: 256, Height: 160, SHA256: strings.Repeat("d", 64), + ObjectKey: domain.VariantObjectKey(chat.ID, draft.ID, 2, domain.VariantThumbnail), + }, + } + + ok, err := repo.CompleteJob(s.T().Context(), reprocess.ID, 1, "lease-2", variants) + s.Require().NoError(err) + s.True(ok) + + // Simulate a legacy/racing replay that left the old version queued. + _, err = s.pool.Exec(s.T().Context(), ` + UPDATE attachment_jobs + SET status = 'queued', attempt = 1, last_error_code = NULL + WHERE job_id = $1`, job.ID) + s.Require().NoError(err) + + stale, err := repo.ClaimJob(s.T().Context(), domain.NewJobMessage(job), "lease-3", time.Minute) + s.Require().NoError(err) + s.Equal(domain.ClaimVersionStale, stale.Outcome) + + var status string + s.Require().NoError(s.pool.QueryRow(s.T().Context(), + `SELECT status FROM attachment_jobs WHERE job_id = $1`, job.ID).Scan(&status)) + s.Equal(string(domain.JobSuperseded), status) + + var supersededEvents int + s.Require().NoError(s.pool.QueryRow(s.T().Context(), ` + SELECT count(*) FROM attachment_job_events + WHERE job_id = $1 AND event = $2`, + job.ID, string(domain.EventSuperseded)).Scan(&supersededEvents)) + s.Equal(2, supersededEvents) +} + +func (s *PipelineSuite) TestReconcileQueuedJobsRepublishesLostIntent() { + alice := s.createUser("alice") + chat := s.createChat(alice) + repo := s.store.Pipeline() + + draft, job := s.attachmentDraft(chat, alice, 1) + _, err := repo.CreateQueued(s.T().Context(), draft, job, domain.AdmissionLimits{}) + s.Require().NoError(err) + + claimed, err := repo.ClaimOutbox(s.T().Context(), "relay", time.Minute, 10) + s.Require().NoError(err) + s.Require().Len(claimed, 1) + s.Require().NoError(repo.MarkPublished(s.T().Context(), []int64{claimed[0].ID})) + + reconciled, err := repo.ReconcileQueuedJobs(s.T().Context(), 0, 10, "", "") + s.Require().NoError(err) + s.Equal(1, reconciled) + + pending, err := repo.ClaimOutbox(s.T().Context(), "relay", time.Minute, 10) + s.Require().NoError(err) + s.Require().Len(pending, 1) + s.Equal("reconcile", pending[0].Kind) + s.Equal(job.ID, pending[0].JobID) +} + +func (s *PipelineSuite) TestFailedStagingStaysReferencedUntilRetention() { + alice := s.createUser("alice") + chat := s.createChat(alice) + repo := s.store.Pipeline() + + draft, job := s.attachmentDraft(chat, alice, 1) + _, err := repo.CreateQueued(s.T().Context(), draft, job, domain.AdmissionLimits{}) + s.Require().NoError(err) + + claim, err := repo.ClaimJob(s.T().Context(), domain.NewJobMessage(job), "lease", time.Minute) + s.Require().NoError(err) + s.Equal(domain.ClaimAcquired, claim.Outcome) + + ok, err := repo.FailJob(s.T().Context(), job.ID, 1, "lease", "invalid_image") + s.Require().NoError(err) + s.True(ok) + + keys, err := repo.ListReferencedKeys(s.T().Context(), "", 100) + s.Require().NoError(err) + s.Contains(keys, draft.StagingKey) +} + +func (s *PipelineSuite) TestMarkTTRMissedCountsEachJobOnce() { + ctx := s.T().Context() + alice := s.createUser("alice") + chat := s.createChat(alice) + repo := s.store.Pipeline() + + makeJob := func(status string, createdAt, completedAt time.Time) uuid.UUID { + s.T().Helper() + draft, job := s.attachmentDraft(chat, alice, 1) + _, err := repo.CreateQueued(ctx, draft, job, domain.AdmissionLimits{}) + s.Require().NoError(err) + _, err = s.pool.Exec(ctx, `UPDATE attachment_jobs + SET status=$2, created_at=$3, completed_at=NULLIF($4, '0001-01-01'::timestamptz) + WHERE job_id=$1`, job.ID, status, createdAt, completedAt) + s.Require().NoError(err) + return job.ID + } + + now := time.Now().UTC() + old := now.Add(-40 * time.Second) + makeJob("queued", old, time.Time{}) + makeJob("ready", old, now) + makeJob("failed", now, now) + makeJob("ready", now, now) + makeJob("superseded", old, now) + + count, err := repo.MarkTTRMissed(ctx, 30*time.Second) + s.Require().NoError(err) + s.EqualValues(3, count) + again, err := repo.MarkTTRMissed(ctx, 30*time.Second) + s.Require().NoError(err) + s.Zero(again) +} diff --git a/internal/storage/postgres/queries/attachments.sql b/internal/storage/postgres/queries/attachments.sql new file mode 100644 index 0000000..930ffd0 --- /dev/null +++ b/internal/storage/postgres/queries/attachments.sql @@ -0,0 +1,9 @@ +-- name: AttachToMessage :exec +INSERT INTO message_attachments (message_id, attachment_id, position) +VALUES (sqlc.arg(message_id), sqlc.arg(attachment_id), sqlc.arg(position)); + +-- name: ListMessageAttachments :many +SELECT message_id, attachment_id +FROM message_attachments +WHERE message_id = ANY(sqlc.arg(message_ids)::uuid[]) +ORDER BY message_id, position; diff --git a/internal/storage/postgres/queries/chats.sql b/internal/storage/postgres/queries/chats.sql new file mode 100644 index 0000000..d404ef7 --- /dev/null +++ b/internal/storage/postgres/queries/chats.sql @@ -0,0 +1,75 @@ +-- name: CreateChat :one +INSERT INTO chats (title) +VALUES (sqlc.arg(title)) +RETURNING id, title, created_at; + +-- name: AddChatMembers :exec +INSERT INTO chat_members (chat_id, user_id) +SELECT sqlc.arg(chat_id), members.member_id +FROM unnest(sqlc.arg(user_ids)::uuid[]) AS members(member_id); + +-- name: ListMissingUserIDs :many +SELECT input.id::uuid AS missing_id +FROM unnest(sqlc.arg(user_ids)::uuid[]) AS input(id) +LEFT JOIN users u ON u.id = input.id +WHERE u.id IS NULL; + +-- name: BumpChatListVersions :exec +INSERT INTO user_chat_versions (user_id, version) +SELECT DISTINCT m, 1 +FROM unnest(sqlc.arg(user_ids)::uuid[]) AS m +ORDER BY m +ON CONFLICT (user_id) DO UPDATE SET version = user_chat_versions.version + 1; + +-- name: GetChatListVersion :one +SELECT COALESCE(MAX(version), 0)::bigint AS version +FROM user_chat_versions +WHERE user_id = sqlc.arg(user_id); + +-- name: GetChatForMember :one +SELECT + c.id, + c.title, + c.created_at, + ( + SELECT COALESCE(array_agg(m.user_id ORDER BY m.user_id), '{}') + FROM chat_members m + WHERE m.chat_id = c.id + )::uuid[] AS member_ids +FROM chats c +JOIN chat_members visible + ON visible.chat_id = c.id AND visible.user_id = sqlc.arg(user_id) +WHERE c.id = sqlc.arg(id); + +-- name: ListChatsForMember :many +SELECT + c.id, + c.title, + c.created_at, + ( + SELECT COALESCE(array_agg(m.user_id ORDER BY m.user_id), '{}') + FROM chat_members m + WHERE m.chat_id = c.id + )::uuid[] AS member_ids +FROM chats c +JOIN chat_members visible ON visible.chat_id = c.id +WHERE visible.user_id = sqlc.arg(user_id) +ORDER BY c.created_at, c.id +LIMIT sqlc.arg(row_limit); + +-- name: ListChatsForMemberAfter :many +SELECT + c.id, + c.title, + c.created_at, + ( + SELECT COALESCE(array_agg(m.user_id ORDER BY m.user_id), '{}') + FROM chat_members m + WHERE m.chat_id = c.id + )::uuid[] AS member_ids +FROM chats c +JOIN chat_members visible ON visible.chat_id = c.id +WHERE visible.user_id = sqlc.arg(user_id) + AND (c.created_at, c.id) > (sqlc.arg(after_created_at)::timestamptz, sqlc.arg(after_id)::uuid) +ORDER BY c.created_at, c.id +LIMIT sqlc.arg(row_limit); diff --git a/internal/storage/postgres/queries/idempotency.sql b/internal/storage/postgres/queries/idempotency.sql new file mode 100644 index 0000000..a45857b --- /dev/null +++ b/internal/storage/postgres/queries/idempotency.sql @@ -0,0 +1,50 @@ +-- Claims the key for this actor/chat and returns whether this request owns it. +-- A live record wins: the statement returns nothing and the caller replays the +-- stored message. An expired record is replaced in place. +-- name: ClaimMessageIdempotency :one +INSERT INTO message_idempotency (actor_id, chat_id, key, request_hash, expires_at) +VALUES ( + sqlc.arg(actor_id), + sqlc.arg(chat_id), + sqlc.arg(key), + sqlc.arg(request_hash), + sqlc.arg(expires_at) +) +ON CONFLICT (actor_id, chat_id, key) DO UPDATE + SET request_hash = EXCLUDED.request_hash, + expires_at = EXCLUDED.expires_at, + message_id = NULL + WHERE message_idempotency.expires_at <= now() +RETURNING key; + +-- Concurrent duplicates block here until the owner commits, then read the +-- result it stored in the same transaction. +-- name: GetMessageIdempotency :one +SELECT message_id, request_hash +FROM message_idempotency +WHERE actor_id = sqlc.arg(actor_id) + AND chat_id = sqlc.arg(chat_id) + AND key = sqlc.arg(key) +FOR UPDATE; + +-- name: CompleteMessageIdempotency :exec +UPDATE message_idempotency +SET message_id = sqlc.arg(message_id) +WHERE actor_id = sqlc.arg(actor_id) + AND chat_id = sqlc.arg(chat_id) + AND key = sqlc.arg(key); + +-- name: GetMessageByID :one +SELECT id, chat_id, sender_id, text, created_at +FROM messages +WHERE id = sqlc.arg(id); + +-- Read-only replay lookup used before attachment-state validation. A live key +-- returns the stored message; an expired key is ignored and may be claimed. +-- name: LookupMessageIdempotency :one +SELECT message_id, request_hash +FROM message_idempotency +WHERE actor_id = sqlc.arg(actor_id) + AND chat_id = sqlc.arg(chat_id) + AND key = sqlc.arg(key) + AND expires_at > now(); diff --git a/internal/storage/postgres/queries/messages.sql b/internal/storage/postgres/queries/messages.sql new file mode 100644 index 0000000..90e804d --- /dev/null +++ b/internal/storage/postgres/queries/messages.sql @@ -0,0 +1,39 @@ +-- name: CreateMessage :one +INSERT INTO messages (chat_id, sender_id, text) +SELECT sqlc.arg(chat_id), sqlc.arg(sender_id), sqlc.arg(text) +WHERE EXISTS ( + SELECT 1 + FROM chat_members + WHERE chat_id = sqlc.arg(chat_id) + AND user_id = sqlc.arg(sender_id) +) +RETURNING id, chat_id, sender_id, text, created_at; + +-- name: IsChatMember :one +SELECT EXISTS ( + SELECT 1 + FROM chat_members + WHERE chat_id = sqlc.arg(chat_id) + AND user_id = sqlc.arg(user_id) +) AS is_member; + +-- name: ListMessagesForChat :many +SELECT m.id, m.chat_id, m.sender_id, m.text, m.created_at +FROM messages m +JOIN chat_members cm + ON cm.chat_id = m.chat_id + AND cm.user_id = sqlc.arg(caller_id) +WHERE m.chat_id = sqlc.arg(chat_id) +ORDER BY m.created_at, m.id +LIMIT sqlc.arg(row_limit); + +-- name: ListMessagesForChatAfter :many +SELECT m.id, m.chat_id, m.sender_id, m.text, m.created_at +FROM messages m +JOIN chat_members cm + ON cm.chat_id = m.chat_id + AND cm.user_id = sqlc.arg(caller_id) +WHERE m.chat_id = sqlc.arg(chat_id) + AND (m.created_at, m.id) > (sqlc.arg(after_created_at)::timestamptz, sqlc.arg(after_id)::uuid) +ORDER BY m.created_at, m.id +LIMIT sqlc.arg(row_limit); diff --git a/internal/storage/postgres/queries/sessions.sql b/internal/storage/postgres/queries/sessions.sql new file mode 100644 index 0000000..a5564ee --- /dev/null +++ b/internal/storage/postgres/queries/sessions.sql @@ -0,0 +1,16 @@ +-- name: CreateSession :one +INSERT INTO sessions (token_hash, user_id, expires_at) +VALUES (sqlc.arg(token_hash), sqlc.arg(user_id), sqlc.arg(expires_at)) +RETURNING token_hash, user_id, expires_at; + +-- name: GetSessionUser :one +SELECT u.id, u.username, u.display_name, u.created_at, s.expires_at +FROM sessions s +JOIN users u ON u.id = s.user_id +WHERE s.token_hash = sqlc.arg(token_hash) + AND s.expires_at > now(); + +-- name: DeleteSession :exec +DELETE FROM sessions +WHERE token_hash = sqlc.arg(token_hash) + AND user_id = sqlc.arg(user_id); diff --git a/internal/storage/postgres/queries/users.sql b/internal/storage/postgres/queries/users.sql new file mode 100644 index 0000000..24e2b50 --- /dev/null +++ b/internal/storage/postgres/queries/users.sql @@ -0,0 +1,14 @@ +-- name: CreateUser :one +INSERT INTO users (username, display_name, password_hash) +VALUES (sqlc.arg(username), sqlc.arg(display_name), sqlc.arg(password_hash)) +RETURNING id, username, display_name, created_at, password_hash; + +-- name: GetUserByID :one +SELECT id, username, display_name, created_at, password_hash +FROM users +WHERE id = sqlc.arg(id); + +-- name: GetUserByUsername :one +SELECT id, username, display_name, created_at, password_hash +FROM users +WHERE username = sqlc.arg(username); diff --git a/internal/storage/postgres/session_repository.go b/internal/storage/postgres/session_repository.go new file mode 100644 index 0000000..1a20cea --- /dev/null +++ b/internal/storage/postgres/session_repository.go @@ -0,0 +1,94 @@ +package postgres + +import ( + "context" + "errors" + "fmt" + + "github.com/google/uuid" + "github.com/jackc/pgx/v5" + + "mtusi-messenger/internal/domain" + "mtusi-messenger/internal/storage/postgres/internal/sqlcgen" +) + +type SessionRepository struct { + store *Store +} + +func (r *SessionRepository) Credentials(ctx context.Context, username string) (domain.UserCredentials, error) { + ctx, cancel := r.store.timeout(ctx) + defer cancel() + + row, err := r.store.queries.GetUserByUsername(ctx, username) + if err != nil { + if errors.Is(err, pgx.ErrNoRows) { + return domain.UserCredentials{}, fmt.Errorf("%w", domain.ErrUnauthenticated) + } + + return domain.UserCredentials{}, fmt.Errorf("load credentials: %w", mapError(err)) + } + + return domain.UserCredentials{ + User: domain.User{ + ID: row.ID, + Username: row.Username, + DisplayName: row.DisplayName, + CreatedAt: toUTCTime(row.CreatedAt), + }, + PasswordHash: row.PasswordHash, + }, nil +} + +func (r *SessionRepository) Create(ctx context.Context, session domain.NewSession) (domain.Session, error) { + ctx, cancel := r.store.timeout(ctx) + defer cancel() + + row, err := r.store.queries.CreateSession(ctx, sqlcgen.CreateSessionParams{ + TokenHash: session.TokenHash, + UserID: session.UserID, + ExpiresAt: session.ExpiresAt, + }) + if err != nil { + return domain.Session{}, fmt.Errorf("create session: %w", mapError(err)) + } + + return domain.Session{ExpiresAt: toUTCTime(row.ExpiresAt)}, nil +} + +func (r *SessionRepository) Resolve(ctx context.Context, tokenHash []byte) (domain.Session, error) { + ctx, cancel := r.store.timeout(ctx) + defer cancel() + + row, err := r.store.queries.GetSessionUser(ctx, tokenHash) + if err != nil { + if errors.Is(err, pgx.ErrNoRows) { + return domain.Session{}, fmt.Errorf("%w: session not found or expired", domain.ErrUnauthenticated) + } + + return domain.Session{}, fmt.Errorf("resolve session: %w", mapError(err)) + } + + return domain.Session{ + ExpiresAt: toUTCTime(row.ExpiresAt), + User: domain.User{ + ID: row.ID, + Username: row.Username, + DisplayName: row.DisplayName, + CreatedAt: toUTCTime(row.CreatedAt), + }, + }, nil +} + +func (r *SessionRepository) Revoke(ctx context.Context, userID uuid.UUID, tokenHash []byte) error { + ctx, cancel := r.store.timeout(ctx) + defer cancel() + + if err := r.store.queries.DeleteSession( + ctx, sqlcgen.DeleteSessionParams{TokenHash: tokenHash, UserID: userID}, + ); err != nil { + return fmt.Errorf("revoke session: %w", mapError(err)) + } + + return nil +} diff --git a/internal/storage/postgres/session_repository_test.go b/internal/storage/postgres/session_repository_test.go new file mode 100644 index 0000000..1057c69 --- /dev/null +++ b/internal/storage/postgres/session_repository_test.go @@ -0,0 +1,81 @@ +//go:build integration + +package postgres_test + +import ( + "testing" + "time" + + "github.com/stretchr/testify/suite" + + "mtusi-messenger/internal/domain" + "mtusi-messenger/internal/platform/password" + "mtusi-messenger/internal/platform/token" +) + +type SessionRepositorySuite struct { + BaseSuite +} + +func TestSessionRepositorySuite(t *testing.T) { + suite.Run(t, new(SessionRepositorySuite)) +} + +func (s *SessionRepositorySuite) TestCredentials() { + alice := s.createUser("alice") + + credentials, err := s.store.Sessions().Credentials(s.T().Context(), "alice") + s.Require().NoError(err) + s.Equal(alice.ID, credentials.User.ID) + s.True(password.Verify("strong-test-password", credentials.PasswordHash)) + s.False(password.Verify("wrong-password-value", credentials.PasswordHash)) +} + +func (s *SessionRepositorySuite) TestCredentialsUnknownUser() { + _, err := s.store.Sessions().Credentials(s.T().Context(), "nobody") + s.Require().ErrorIs(err, domain.ErrUnauthenticated) +} + +func (s *SessionRepositorySuite) TestCreateResolveRevoke() { + alice := s.createUser("alice") + + _, hash, err := token.New().Generate() + s.Require().NoError(err) + + expiresAt := time.Now().UTC().Add(time.Hour).Truncate(time.Microsecond) + + created, err := s.store.Sessions().Create(s.T().Context(), domain.NewSession{ + TokenHash: hash, + UserID: alice.ID, + ExpiresAt: expiresAt, + }) + s.Require().NoError(err) + s.Equal(expiresAt, created.ExpiresAt) + + resolved, err := s.store.Sessions().Resolve(s.T().Context(), hash) + s.Require().NoError(err) + s.Equal(alice.ID, resolved.User.ID) + s.Equal(created.ExpiresAt, resolved.ExpiresAt) + + s.Require().NoError(s.store.Sessions().Revoke(s.T().Context(), alice.ID, hash)) + + _, err = s.store.Sessions().Resolve(s.T().Context(), hash) + s.Require().ErrorIs(err, domain.ErrUnauthenticated) +} + +func (s *SessionRepositorySuite) TestResolveRejectsExpiredToken() { + alice := s.createUser("alice") + + _, hash, err := token.New().Generate() + s.Require().NoError(err) + + _, err = s.store.Sessions().Create(s.T().Context(), domain.NewSession{ + TokenHash: hash, + UserID: alice.ID, + ExpiresAt: time.Now().UTC().Add(-time.Minute), + }) + s.Require().NoError(err) + + _, err = s.store.Sessions().Resolve(s.T().Context(), hash) + s.Require().ErrorIs(err, domain.ErrUnauthenticated) +} diff --git a/internal/storage/postgres/store.go b/internal/storage/postgres/store.go new file mode 100644 index 0000000..1c2d23c --- /dev/null +++ b/internal/storage/postgres/store.go @@ -0,0 +1,165 @@ +package postgres + +import ( + "context" + "fmt" + "time" + + "github.com/jackc/pgx/v5" + "github.com/jackc/pgx/v5/pgxpool" + + "mtusi-messenger/internal/config" + "mtusi-messenger/internal/storage/postgres/internal/sqlcgen" +) + +type Store struct { + pool *pgxpool.Pool + queries *sqlcgen.Queries + queryTimeout time.Duration + idempotencyTTL time.Duration + + users *UserRepository + chats *ChatRepository + messages *MessageRepository + sessions *SessionRepository + pipeline *PipelineRepository +} + +type options struct { + queryTracer pgx.QueryTracer +} + +// Option customizes the PostgreSQL store without leaking telemetry into the +// storage package's public API. +type Option func(*options) + +// WithQueryTracer installs a pgx tracer (nil means no tracing). +func WithQueryTracer(tracer pgx.QueryTracer) Option { + return func(o *options) { o.queryTracer = tracer } +} + +func New(ctx context.Context, cfg config.Postgres, idempotencyTTL time.Duration, opts ...Option) (*Store, error) { + options := options{} + for _, opt := range opts { + opt(&options) + } + + cfg, err := normalize(cfg) + if err != nil { + return nil, fmt.Errorf("normalize database config: %w", err) + } + + poolCfg, err := pgxpool.ParseConfig(cfg.DSN()) + if err != nil { + return nil, fmt.Errorf("parse database dsn: %w", err) + } + + poolCfg.MaxConns = cfg.MaxConns + poolCfg.MinConns = cfg.MinConns + poolCfg.MaxConnLifetime = cfg.MaxConnLifetime + poolCfg.MaxConnIdleTime = cfg.MaxConnIdleTime + poolCfg.ConnConfig.ConnectTimeout = cfg.ConnectTimeout + if options.queryTracer != nil { + poolCfg.ConnConfig.Tracer = options.queryTracer + } + + pool, err := pgxpool.NewWithConfig(ctx, poolCfg) + if err != nil { + return nil, fmt.Errorf("create pool: %w", err) + } + + pingCtx, cancel := context.WithTimeout(ctx, cfg.ConnectTimeout) + defer cancel() + + if err := pool.Ping(pingCtx); err != nil { + pool.Close() + + return nil, fmt.Errorf("ping database: %w", err) + } + + store := &Store{ + pool: pool, + queries: sqlcgen.New(pool), + queryTimeout: cfg.QueryTimeout, + idempotencyTTL: idempotencyTTL, + } + + store.users = &UserRepository{store: store} + store.chats = &ChatRepository{store: store} + store.messages = &MessageRepository{store: store} + store.sessions = &SessionRepository{store: store} + store.pipeline = &PipelineRepository{store: store} + + return store, nil +} + +func (s *Store) Users() *UserRepository { return s.users } + +func (s *Store) Chats() *ChatRepository { return s.chats } + +func (s *Store) Messages() *MessageRepository { return s.messages } + +func (s *Store) Sessions() *SessionRepository { return s.sessions } + +func (s *Store) Pipeline() *PipelineRepository { return s.pipeline } + +func (s *Store) Ping(ctx context.Context) error { + pingCtx, cancel := context.WithTimeout(ctx, 2*time.Second) + defer cancel() + + if err := s.pool.Ping(pingCtx); err != nil { + return fmt.Errorf("ping database: %w", err) + } + + return nil +} + +// PoolStats exposes a point-in-time pgxpool snapshot for telemetry callbacks. +func (s *Store) PoolStats() *pgxpool.Stat { return s.pool.Stat() } + +func (s *Store) Close() { s.pool.Close() } + +// sweepLockKey is a process-independent constant: every replica contends for the +// same PostgreSQL session lock, so only one sweeper runs at a time. +const sweepLockKey int64 = 0x4c414234 // "LAB4" + +// AcquireSweepLock holds a session-level advisory lock on a dedicated +// connection. The returned release function must be called on that same +// connection before it is returned to the pool. +func (s *Store) AcquireSweepLock(ctx context.Context) (func(), bool, error) { + conn, err := s.pool.Acquire(ctx) + if err != nil { + return nil, false, fmt.Errorf("acquire sweep connection: %w", err) + } + + var acquired bool + if err := conn.QueryRow(ctx, "SELECT pg_try_advisory_lock($1)", sweepLockKey).Scan(&acquired); err != nil { + conn.Release() + + return nil, false, fmt.Errorf("acquire sweep lock: %w", err) + } + + if !acquired { + conn.Release() + + return nil, false, nil + } + + release := func() { + unlockCtx, cancel := context.WithTimeout(context.WithoutCancel(ctx), 5*time.Second) + defer cancel() + + _, _ = conn.Exec(unlockCtx, "SELECT pg_advisory_unlock($1)", sweepLockKey) + conn.Release() + } + + return release, true, nil +} + +func (s *Store) timeout(ctx context.Context) (context.Context, context.CancelFunc) { + if s.queryTimeout <= 0 { + return context.WithCancel(ctx) + } + + return context.WithTimeout(ctx, s.queryTimeout) +} diff --git a/internal/storage/postgres/transaction.go b/internal/storage/postgres/transaction.go new file mode 100644 index 0000000..ab8fb5d --- /dev/null +++ b/internal/storage/postgres/transaction.go @@ -0,0 +1,32 @@ +package postgres + +import ( + "context" + "fmt" + + "github.com/jackc/pgx/v5" + + "mtusi-messenger/internal/storage/postgres/internal/sqlcgen" +) + +func (s *Store) RunInTx(ctx context.Context, fn func(queries *sqlcgen.Queries) error) error { + ctx, cancel := s.timeout(ctx) + defer cancel() + + tx, err := s.pool.BeginTx(ctx, pgx.TxOptions{}) + if err != nil { + return fmt.Errorf("begin transaction: %w", err) + } + + defer func() { _ = tx.Rollback(ctx) }() + + if err := fn(s.queries.WithTx(tx)); err != nil { + return err + } + + if err := tx.Commit(ctx); err != nil { + return fmt.Errorf("commit transaction: %w", err) + } + + return nil +} diff --git a/internal/storage/postgres/user_repository.go b/internal/storage/postgres/user_repository.go new file mode 100644 index 0000000..c9e6e98 --- /dev/null +++ b/internal/storage/postgres/user_repository.go @@ -0,0 +1,63 @@ +package postgres + +import ( + "context" + "errors" + "fmt" + + "github.com/google/uuid" + + "mtusi-messenger/internal/domain" + "mtusi-messenger/internal/storage/postgres/internal/sqlcgen" +) + +type UserRepository struct { + store *Store +} + +func (r *UserRepository) Create(ctx context.Context, draft domain.NewUser) (domain.User, error) { + ctx, cancel := r.store.timeout(ctx) + defer cancel() + + row, err := r.store.queries.CreateUser(ctx, sqlcgen.CreateUserParams{ + Username: draft.Username, + DisplayName: draft.DisplayName, + PasswordHash: draft.PasswordHash, + }) + if err != nil { + if isUniqueViolation(err) { + return domain.User{}, fmt.Errorf("%w: username %q", domain.ErrUsernameTaken, draft.Username) + } + + return domain.User{}, fmt.Errorf("create user: %w", mapError(err)) + } + + return domain.User{ + ID: row.ID, + Username: row.Username, + DisplayName: row.DisplayName, + CreatedAt: toUTCTime(row.CreatedAt), + }, nil +} + +func (r *UserRepository) GetByID(ctx context.Context, id uuid.UUID) (domain.User, error) { + ctx, cancel := r.store.timeout(ctx) + defer cancel() + + row, err := r.store.queries.GetUserByID(ctx, id) + if err != nil { + mapped := mapError(err) + if errors.Is(mapped, domain.ErrNotFound) { + return domain.User{}, fmt.Errorf("%w: user %s", domain.ErrNotFound, id) + } + + return domain.User{}, fmt.Errorf("get user: %w", mapped) + } + + return domain.User{ + ID: row.ID, + Username: row.Username, + DisplayName: row.DisplayName, + CreatedAt: toUTCTime(row.CreatedAt), + }, nil +} diff --git a/internal/storage/postgres/user_repository_test.go b/internal/storage/postgres/user_repository_test.go new file mode 100644 index 0000000..4ceb276 --- /dev/null +++ b/internal/storage/postgres/user_repository_test.go @@ -0,0 +1,114 @@ +//go:build integration + +package postgres_test + +import ( + "errors" + "sync" + "testing" + "time" + + "github.com/google/uuid" + "github.com/stretchr/testify/suite" + + "mtusi-messenger/internal/config" + "mtusi-messenger/internal/domain" + "mtusi-messenger/internal/platform/password" +) + +type UserRepositorySuite struct { + BaseSuite +} + +func TestUserRepositorySuite(t *testing.T) { + suite.Run(t, new(UserRepositorySuite)) +} + +func (s *UserRepositorySuite) TestCreateAndLookup() { + created := s.createUser("alice") + s.NotEqual(uuid.Nil, created.ID) + s.Equal(uuid.Version(7), created.ID.Version()) + s.Equal("alice", created.Username) + s.False(created.CreatedAt.IsZero()) + + found, err := s.store.Users().GetByID(s.T().Context(), created.ID) + s.Require().NoError(err) + s.Equal(created, found) + + _, err = s.store.Users().GetByID(s.T().Context(), uuid.New()) + s.Require().ErrorIs(err, domain.ErrNotFound) +} + +func (s *UserRepositorySuite) TestDuplicateUsernameConflicts() { + s.createUser("alice") + + hash, err := password.Hash("strong-test-password") + s.Require().NoError(err) + + _, err = s.store.Users().Create(s.T().Context(), domain.NewUser{ + Username: "alice", + DisplayName: "Другая Алиса", + PasswordHash: hash, + }) + s.Require().ErrorIs(err, domain.ErrUsernameTaken) +} + +func (s *UserRepositorySuite) TestConcurrentRegistrationCreatesSingleUser() { + hash, err := password.Hash("strong-test-password") + s.Require().NoError(err) + + const attempts = 8 + + var ( + wg sync.WaitGroup + mu sync.Mutex + successes int + failures []error + ) + + for range attempts { + wg.Go(func() { + _, err := s.store.Users().Create(s.T().Context(), domain.NewUser{ + Username: "racer", + DisplayName: "Racer", + PasswordHash: hash, + }) + + mu.Lock() + defer mu.Unlock() + + if err == nil { + successes++ + + return + } + + failures = append(failures, err) + }) + } + + wg.Wait() + + s.Equal(1, successes, "ровно одна регистрация выигрывает гонку") + s.Len(failures, attempts-1) + + for _, failure := range failures { + ok := errors.Is(failure, domain.ErrUsernameTaken) || errors.Is(failure, domain.ErrConflict) + s.True(ok, "проигравшая регистрация должна давать конфликт, получено: %v", failure) + } + + var count int + s.Require().NoError(s.pool.QueryRow(s.T().Context(), "SELECT count(*) FROM users WHERE username = 'racer'").Scan(&count)) + s.Equal(1, count) +} + +func (s *UserRepositorySuite) TestQueryTimeoutReturnsError() { + store := openStore(s.T(), s.db, func(cfg *config.Postgres) { + cfg.QueryTimeout = time.Nanosecond + }) + defer store.Close() + + _, err := store.Users().GetByID(s.T().Context(), uuid.New()) + s.Require().Error(err) + s.NotErrorIs(err, domain.ErrNotFound) +} diff --git a/internal/storage/redis/chat_repository.go b/internal/storage/redis/chat_repository.go new file mode 100644 index 0000000..9ce0c08 --- /dev/null +++ b/internal/storage/redis/chat_repository.go @@ -0,0 +1,183 @@ +package redis + +import ( + "context" + "encoding/json" + "errors" + "fmt" + "log/slog" + "time" + + "github.com/google/uuid" + + "mtusi-messenger/internal/domain" + "mtusi-messenger/internal/platform/cache" +) + +type ChatSource interface { + Create(ctx context.Context, draft domain.ChatDraft) (domain.Chat, error) + GetVisible(ctx context.Context, chatID, callerID uuid.UUID) (domain.Chat, error) + ListVersion(ctx context.Context, userID uuid.UUID) (int64, error) + ListVisible( + ctx context.Context, + callerID uuid.UUID, + after *domain.Cursor, + limit int, + ) (domain.Page[domain.Chat], error) +} + +type ChatRepository struct { + source ChatSource + cache *cache.DistributedCache + ttl time.Duration + log *slog.Logger +} + +func NewChatRepository( + source ChatSource, + cache *cache.DistributedCache, + ttl time.Duration, + log *slog.Logger, +) *ChatRepository { + return &ChatRepository{source: source, cache: cache, ttl: ttl, log: log} +} + +func (r *ChatRepository) Create(ctx context.Context, draft domain.ChatDraft) (domain.Chat, error) { + return r.source.Create(ctx, draft) +} + +func (r *ChatRepository) GetVisible(ctx context.Context, chatID, callerID uuid.UUID) (domain.Chat, error) { + return r.source.GetVisible(ctx, chatID, callerID) +} + +type sourceError struct{ err error } + +func (e sourceError) Error() string { return e.err.Error() } + +func (e sourceError) Unwrap() error { return e.err } + +const cacheOperationTimeout = 500 * time.Millisecond + +func (r *ChatRepository) ListVisible( + ctx context.Context, + callerID uuid.UUID, + after *domain.Cursor, + limit int, +) (domain.Page[domain.Chat], error) { + if after != nil { + return r.source.ListVisible(ctx, callerID, after, limit) + } + + version, err := r.source.ListVersion(ctx, callerID) + if err != nil { + return domain.Page[domain.Chat]{}, fmt.Errorf("chat list version: %w", err) + } + + key := chatListKey(callerID, version, limit) + + loader := func(ctx context.Context) ([]byte, error) { + page, err := r.source.ListVisible(ctx, callerID, nil, limit) + if err != nil { + return nil, sourceError{err} + } + + return json.Marshal(newChatPageDTO(page)) + } + + cctx, cancel := context.WithTimeout(ctx, cacheOperationTimeout) + defer cancel() + + encoded, err := r.cache.GetOrLoad(cctx, key, r.ttl, loader) + if err != nil { + var sourceErr sourceError + switch { + case errors.As(err, &sourceErr): + return domain.Page[domain.Chat]{}, sourceErr.err + case ctx.Err() != nil: + return domain.Page[domain.Chat]{}, ctx.Err() + } + } else { + var dto chatPageDTO + unmarshalErr := json.Unmarshal(encoded, &dto) + if unmarshalErr == nil { + return dto.toDomain(), nil + } + err = unmarshalErr + + _ = r.cache.Delete(ctx, key) + } + + if r.log != nil { + r.log.WarnContext(ctx, "chat list cache unavailable, falling back to source", slog.Any("error", err)) + } + + return r.source.ListVisible(ctx, callerID, nil, limit) +} + +func chatListKey(userID uuid.UUID, version int64, limit int) string { + return fmt.Sprintf("chat_list:%s:%d:%d", userID, version, limit) +} + +type chatPageDTO struct { + Items []chatDTO `json:"items"` + Next *cursorDTO `json:"next,omitempty"` +} + +type chatDTO struct { + ID uuid.UUID `json:"id"` + Title string `json:"title"` + MemberIDs []uuid.UUID `json:"member_ids"` + CreatedAt time.Time `json:"created_at"` +} + +type cursorDTO struct { + Scope uuid.UUID `json:"scope"` + CreatedAt time.Time `json:"created_at"` + ID uuid.UUID `json:"id"` +} + +func newChatPageDTO(page domain.Page[domain.Chat]) chatPageDTO { + items := make([]chatDTO, 0, len(page.Items)) + for _, chat := range page.Items { + items = append(items, chatDTO{ + ID: chat.ID, + Title: chat.Title, + MemberIDs: chat.MemberIDs, + CreatedAt: chat.CreatedAt, + }) + } + + var next *cursorDTO + if page.Next != nil { + next = &cursorDTO{ + Scope: page.Next.Scope, + CreatedAt: page.Next.CreatedAt, + ID: page.Next.ID, + } + } + + return chatPageDTO{Items: items, Next: next} +} + +func (d chatPageDTO) toDomain() domain.Page[domain.Chat] { + items := make([]domain.Chat, 0, len(d.Items)) + for _, chat := range d.Items { + items = append(items, domain.Chat{ + ID: chat.ID, + Title: chat.Title, + MemberIDs: chat.MemberIDs, + CreatedAt: chat.CreatedAt, + }) + } + + var next *domain.Cursor + if d.Next != nil { + next = &domain.Cursor{ + Scope: d.Next.Scope, + CreatedAt: d.Next.CreatedAt, + ID: d.Next.ID, + } + } + + return domain.Page[domain.Chat]{Items: items, Next: next} +} diff --git a/internal/storage/redis/chat_repository_test.go b/internal/storage/redis/chat_repository_test.go new file mode 100644 index 0000000..c06f10e --- /dev/null +++ b/internal/storage/redis/chat_repository_test.go @@ -0,0 +1,428 @@ +//go:build integration + +package redis_test + +import ( + "context" + "errors" + "sync" + "sync/atomic" + "testing" + "time" + + "github.com/google/uuid" + "github.com/stretchr/testify/mock" + "github.com/stretchr/testify/suite" + + "mtusi-messenger/internal/domain" + "mtusi-messenger/internal/platform/cache" + cachemocks "mtusi-messenger/internal/platform/cache/mocks" + storageredis "mtusi-messenger/internal/storage/redis" + storagemocks "mtusi-messenger/internal/storage/redis/mocks" +) + +type ChatRepositorySuite struct { + suite.Suite + + cache *cache.RedisCache +} + +func TestChatRepositorySuite(t *testing.T) { + suite.Run(t, new(ChatRepositorySuite)) +} + +func (s *ChatRepositorySuite) SetupSuite() { + var err error + + s.cache, err = cache.NewRedis(testRedisConfig()) + s.Require().NoError(err) + + s.Require().NoError(s.cache.Ping(s.T().Context())) + s.Require().NoError(flushRedisDB(s.T().Context())) +} + +func (s *ChatRepositorySuite) TearDownSuite() { + if s.cache != nil { + s.Require().NoError(s.cache.Close()) + } +} + +func (s *ChatRepositorySuite) newDistributed() *cache.DistributedCache { + s.T().Helper() + + dc, err := cache.NewDistributed(s.cache, cache.DistributedConfig{}, nil) + s.Require().NoError(err) + + return dc +} + +func (s *ChatRepositorySuite) newRepo(source storageredis.ChatSource) *storageredis.ChatRepository { + s.T().Helper() + + return storageredis.NewChatRepository(source, s.newDistributed(), time.Minute, nil) +} + +func (s *ChatRepositorySuite) TestFirstPageIsCached() { + ctx := s.T().Context() + alice := uuid.New() + page := domain.Page[domain.Chat]{Items: []domain.Chat{}} + + source := storagemocks.NewMockChatSource(s.T()) + source.EXPECT().ListVersion(mock.Anything, alice).Return(int64(0), nil).Twice() + source.EXPECT().ListVisible(mock.Anything, alice, (*domain.Cursor)(nil), 50).Return(page, nil).Once() + + repo := s.newRepo(source) + + first, err := repo.ListVisible(ctx, alice, nil, 50) + s.Require().NoError(err) + s.Empty(first.Items) + + second, err := repo.ListVisible(ctx, alice, nil, 50) + s.Require().NoError(err) + s.Empty(second.Items) +} + +func (s *ChatRepositorySuite) TestCreateInvalidatesMemberCaches() { + ctx := s.T().Context() + alice := uuid.New() + bob := uuid.New() + empty := domain.Page[domain.Chat]{Items: []domain.Chat{}} + chat := domain.Chat{ + ID: uuid.New(), + Title: "Чат", + MemberIDs: []uuid.UUID{alice, bob}, + CreatedAt: time.Now().UTC(), + } + page := domain.Page[domain.Chat]{Items: []domain.Chat{chat}} + + source := storagemocks.NewMockChatSource(s.T()) + source.EXPECT().ListVersion(mock.Anything, alice).Return(int64(0), nil).Once() + source.EXPECT().ListVersion(mock.Anything, bob).Return(int64(0), nil).Once() + source.EXPECT().ListVisible(mock.Anything, alice, (*domain.Cursor)(nil), 50).Return(empty, nil).Once() + source.EXPECT().ListVisible(mock.Anything, bob, (*domain.Cursor)(nil), 50).Return(empty, nil).Once() + source.EXPECT().Create(mock.Anything, mock.AnythingOfType("domain.ChatDraft")).Return(chat, nil).Once() + source.EXPECT().ListVersion(mock.Anything, alice).Return(int64(1), nil).Once() + source.EXPECT().ListVersion(mock.Anything, bob).Return(int64(1), nil).Once() + source.EXPECT().ListVisible(mock.Anything, alice, (*domain.Cursor)(nil), 50).Return(page, nil).Once() + source.EXPECT().ListVisible(mock.Anything, bob, (*domain.Cursor)(nil), 50).Return(page, nil).Once() + + repo := s.newRepo(source) + + _, err := repo.ListVisible(ctx, alice, nil, 50) + s.Require().NoError(err) + _, err = repo.ListVisible(ctx, bob, nil, 50) + s.Require().NoError(err) + + _, err = repo.Create(ctx, domain.ChatDraft{ + Title: "Чат", + MemberIDs: []uuid.UUID{alice, bob}, + CallerID: alice, + }) + s.Require().NoError(err) + + alicePage, err := repo.ListVisible(ctx, alice, nil, 50) + s.Require().NoError(err) + s.Len(alicePage.Items, 1, "creator must observe the new chat immediately") + + bobPage, err := repo.ListVisible(ctx, bob, nil, 50) + s.Require().NoError(err) + s.Len(bobPage.Items, 1, "other member must observe the new chat immediately") +} + +func (s *ChatRepositorySuite) TestEvictedCacheEntryReloadsFromSource() { + ctx := s.T().Context() + alice := uuid.New() + empty := domain.Page[domain.Chat]{Items: []domain.Chat{}} + + source := storagemocks.NewMockChatSource(s.T()) + source.EXPECT().ListVersion(mock.Anything, alice).Return(int64(0), nil).Twice() + source.EXPECT().ListVisible(mock.Anything, alice, (*domain.Cursor)(nil), 50).Return(empty, nil).Twice() + + repo := s.newRepo(source) + + _, err := repo.ListVisible(ctx, alice, nil, 50) + s.Require().NoError(err) + + // Simulate a Redis flush/restart by dropping all cache entries. + s.Require().NoError(flushRedisDB(ctx)) + + _, err = repo.ListVisible(ctx, alice, nil, 50) + s.Require().NoError(err) +} + +func (s *ChatRepositorySuite) TestDeeperPagesBypassCache() { + ctx := s.T().Context() + alice := uuid.New() + cursor := &domain.Cursor{Scope: alice, CreatedAt: time.Now().UTC(), ID: uuid.New()} + empty := domain.Page[domain.Chat]{Items: []domain.Chat{}} + + source := storagemocks.NewMockChatSource(s.T()) + source.EXPECT().ListVisible(mock.Anything, alice, cursor, 50).Return(empty, nil).Twice() + + repo := s.newRepo(source) + + _, err := repo.ListVisible(ctx, alice, cursor, 50) + s.Require().NoError(err) + _, err = repo.ListVisible(ctx, alice, cursor, 50) + s.Require().NoError(err) +} + +func (s *ChatRepositorySuite) TestLimitIsPartOfCacheKey() { + ctx := s.T().Context() + alice := uuid.New() + empty := domain.Page[domain.Chat]{Items: []domain.Chat{}} + + source := storagemocks.NewMockChatSource(s.T()) + source.EXPECT().ListVersion(mock.Anything, alice).Return(int64(0), nil).Twice() + source.EXPECT().ListVisible(mock.Anything, alice, (*domain.Cursor)(nil), 10).Return(empty, nil).Once() + source.EXPECT().ListVisible(mock.Anything, alice, (*domain.Cursor)(nil), 50).Return(empty, nil).Once() + + repo := s.newRepo(source) + + _, err := repo.ListVisible(ctx, alice, nil, 10) + s.Require().NoError(err) + _, err = repo.ListVisible(ctx, alice, nil, 50) + s.Require().NoError(err) +} + +func (s *ChatRepositorySuite) TestConcurrentColdReadsAreDeduplicated() { + ctx := s.T().Context() + alice := uuid.New() + empty := domain.Page[domain.Chat]{Items: []domain.Chat{}} + + source := storagemocks.NewMockChatSource(s.T()) + source.EXPECT().ListVersion(mock.Anything, alice).Return(int64(0), nil).Maybe() + source.EXPECT().ListVisible(mock.Anything, alice, (*domain.Cursor)(nil), 50). + RunAndReturn(func(context.Context, uuid.UUID, *domain.Cursor, int) (domain.Page[domain.Chat], error) { + time.Sleep(25 * time.Millisecond) + + return empty, nil + }).Once() + + repo := s.newRepo(source) + + const workers = 100 + + var ( + wg sync.WaitGroup + failures atomic.Int32 + ) + + wg.Add(workers) + + for range workers { + go func() { + defer wg.Done() + + if _, err := repo.ListVisible(ctx, alice, nil, 50); err != nil { + failures.Add(1) + } + }() + } + + wg.Wait() + + s.Require().Zero(failures.Load()) + s.T().Logf("distributed lock: %d concurrent cold reads -> 1 source load", workers) +} + +func (s *ChatRepositorySuite) TestMultipleInstancesShareDistributedLock() { + ctx := s.T().Context() + alice := uuid.New() + empty := domain.Page[domain.Chat]{Items: []domain.Chat{}} + + source := storagemocks.NewMockChatSource(s.T()) + source.EXPECT().ListVersion(mock.Anything, alice).Return(int64(0), nil).Maybe() + source.EXPECT().ListVisible(mock.Anything, alice, (*domain.Cursor)(nil), 50). + RunAndReturn(func(context.Context, uuid.UUID, *domain.Cursor, int) (domain.Page[domain.Chat], error) { + time.Sleep(25 * time.Millisecond) + + return empty, nil + }).Once() + + const ( + instances = 3 + workersPerInstance = 30 + ) + + repos := make([]*storageredis.ChatRepository, instances) + for i := range repos { + repos[i] = s.newRepo(source) + } + + var ( + wg sync.WaitGroup + failures atomic.Int32 + ) + + wg.Add(instances * workersPerInstance) + + for i := range repos { + repo := repos[i] + for range workersPerInstance { + go func() { + defer wg.Done() + + if _, err := repo.ListVisible(ctx, alice, nil, 50); err != nil { + failures.Add(1) + } + }() + } + } + + wg.Wait() + + s.Require().Zero(failures.Load()) + s.T().Logf("multi-instance distributed lock: %d instances x %d reads -> 1 source load", + instances, workersPerInstance) +} + +func (s *ChatRepositorySuite) TestCacheUnavailableFallsBackToSource() { + ctx := s.T().Context() + alice := uuid.New() + page := domain.Page[domain.Chat]{Items: []domain.Chat{}} + + source := storagemocks.NewMockChatSource(s.T()) + source.EXPECT().ListVersion(mock.Anything, alice).Return(int64(0), nil).Once() + source.EXPECT().ListVisible(mock.Anything, alice, (*domain.Cursor)(nil), 50).Return(page, nil).Once() + + lockStore := cachemocks.NewMockLockStore(s.T()) + lockStore.EXPECT().Get(mock.Anything, mock.Anything).Return(nil, errors.New("redis down")).Maybe() + + distributed, err := cache.NewDistributed(lockStore, cache.DistributedConfig{}, nil) + s.Require().NoError(err) + + repo := storageredis.NewChatRepository(source, distributed, time.Minute, nil) + + got, err := repo.ListVisible(ctx, alice, nil, 50) + s.Require().NoError(err, "cache failure must not fail the read") + s.Empty(got.Items) +} + +func (s *ChatRepositorySuite) TestBrokenCacheEntryIsDroppedAndRepopulated() { + ctx := s.T().Context() + alice := uuid.New() + page := domain.Page[domain.Chat]{Items: []domain.Chat{}} + + source := storagemocks.NewMockChatSource(s.T()) + source.EXPECT().ListVersion(mock.Anything, alice).Return(int64(0), nil).Times(3) + source.EXPECT().ListVisible(mock.Anything, alice, (*domain.Cursor)(nil), 50).Return(page, nil).Twice() + + repo := s.newRepo(source) + + key := "chat_list:" + alice.String() + ":0:50" + s.Require().NoError(s.cache.Set(ctx, key, []byte("{not json"), time.Minute)) + + // 1st: garbage -> dropped -> source. + first, err := repo.ListVisible(ctx, alice, nil, 50) + s.Require().NoError(err, "a corrupted cache entry must not fail the read") + + // 2nd: miss -> source -> repopulate. + second, err := repo.ListVisible(ctx, alice, nil, 50) + s.Require().NoError(err) + + // 3rd: served from cache, no source call. + third, err := repo.ListVisible(ctx, alice, nil, 50) + s.Require().NoError(err) + + s.Equal(first, second) + s.Equal(second, third) +} + +func (s *ChatRepositorySuite) TestSlowLoaderBeyondCacheBudgetReturnsData() { + ctx := s.T().Context() + alice := uuid.New() + page := domain.Page[domain.Chat]{Items: []domain.Chat{}} + + release := make(chan struct{}) + var calls atomic.Int32 + + source := storagemocks.NewMockChatSource(s.T()) + source.EXPECT().ListVersion(mock.Anything, alice).Return(int64(0), nil).Once() + source.EXPECT().ListVisible(mock.Anything, alice, (*domain.Cursor)(nil), 50). + RunAndReturn(func(context.Context, uuid.UUID, *domain.Cursor, int) (domain.Page[domain.Chat], error) { + if calls.Add(1) == 1 { + <-release // the loader outlives the caller's cache budget + } + + return page, nil + }).Maybe() + + repo := s.newRepo(source) + + started := time.Now() + got, err := repo.ListVisible(ctx, alice, nil, 50) + s.Require().NoError(err, "budget expiry must fall back to the source, not fail") + s.Empty(got.Items) + s.GreaterOrEqual(time.Since(started), 450*time.Millisecond, "the caller must be bounded by the cache budget") + + // Let the background loader finish before the test (and its mock) is torn down. + close(release) + time.Sleep(200 * time.Millisecond) +} + +func (s *ChatRepositorySuite) TestSourceErrorIsNotRetried() { + ctx := s.T().Context() + alice := uuid.New() + sentinel := errors.New("postgres down") + + source := storagemocks.NewMockChatSource(s.T()) + source.EXPECT().ListVersion(mock.Anything, alice).Return(int64(0), nil).Once() + source.EXPECT().ListVisible(mock.Anything, alice, (*domain.Cursor)(nil), 50). + Return(domain.Page[domain.Chat]{}, sentinel).Once() + + repo := s.newRepo(source) + + _, err := repo.ListVisible(ctx, alice, nil, 50) + s.Require().ErrorIs(err, sentinel, "source error must propagate") +} + +func (s *ChatRepositorySuite) TestConcurrentColdReadsWithoutProtectionStampede() { + ctx := s.T().Context() + alice := uuid.New() + key := "naive:" + alice.String() + empty := domain.Page[domain.Chat]{Items: []domain.Chat{}} + + var loads atomic.Int32 + + source := storagemocks.NewMockChatSource(s.T()) + source.EXPECT().ListVisible(mock.Anything, alice, (*domain.Cursor)(nil), 50). + RunAndReturn(func(context.Context, uuid.UUID, *domain.Cursor, int) (domain.Page[domain.Chat], error) { + loads.Add(1) + time.Sleep(2 * time.Millisecond) + + return empty, nil + }).Maybe() + + const workers = 100 + + var ( + wg sync.WaitGroup + failures atomic.Int32 + ) + + wg.Add(workers) + + for range workers { + go func() { + defer wg.Done() + + // Naive cache-aside without distributed coordination: every concurrent miss loads. + if _, err := s.cache.Get(ctx, key); err != nil { + if _, loadErr := source.ListVisible(ctx, alice, nil, 50); loadErr != nil { + failures.Add(1) + + return + } + + _ = s.cache.Set(ctx, key, []byte("page"), time.Minute) + } + }() + } + + wg.Wait() + + s.Require().Zero(failures.Load()) + s.Greater(loads.Load(), int32(1), "without distributed coordination concurrent misses stampede the source") + s.T().Logf("stampede demonstration: %d concurrent reads -> %d source loads", workers, loads.Load()) +} diff --git a/internal/storage/redis/main_test.go b/internal/storage/redis/main_test.go new file mode 100644 index 0000000..fabadf2 --- /dev/null +++ b/internal/storage/redis/main_test.go @@ -0,0 +1,66 @@ +//go:build integration + +package redis_test + +import ( + "context" + "os" + "strconv" + "time" + + goredis "github.com/redis/go-redis/v9" + + "mtusi-messenger/internal/platform/cache" +) + +const testRedisDB = 1 + +func redisEnv(key, fallback string) string { + if value := os.Getenv(key); value != "" { + return value + } + + return fallback +} + +func redisEnvInt(key string, fallback int) int { + value := os.Getenv(key) + if value == "" { + return fallback + } + + parsed, err := strconv.Atoi(value) + if err != nil { + return fallback + } + + return parsed +} + +func testRedisConfig() cache.RedisConfig { + return cache.RedisConfig{ + Host: redisEnv("TEST_REDIS_HOST", "localhost"), + Port: redisEnvInt("TEST_REDIS_PORT", 6379), + Password: os.Getenv("TEST_REDIS_PASSWORD"), + DB: redisEnvInt("TEST_REDIS_DB", testRedisDB), + MaxRetries: 3, + DialTimeout: 5 * time.Second, + ReadTimeout: 3 * time.Second, + WriteTimeout: 3 * time.Second, + PoolSize: 5, + } +} + +func flushRedisDB(ctx context.Context) error { + cfg := testRedisConfig() + + client := goredis.NewClient(&goredis.Options{ + Addr: cfg.Host + ":" + strconv.Itoa(cfg.Port), + Password: cfg.Password, + DB: cfg.DB, + }) + + defer func() { _ = client.Close() }() + + return client.FlushDB(ctx).Err() +} diff --git a/internal/storage/redis/mocks/ChatSource.go b/internal/storage/redis/mocks/ChatSource.go new file mode 100644 index 0000000..5d9d373 --- /dev/null +++ b/internal/storage/redis/mocks/ChatSource.go @@ -0,0 +1,331 @@ +// Code generated by mockery; DO NOT EDIT. +// github.com/vektra/mockery +// template: testify + +package mocks + +import ( + "context" + "mtusi-messenger/internal/domain" + + "github.com/google/uuid" + mock "github.com/stretchr/testify/mock" +) + +// NewMockChatSource creates a new instance of MockChatSource. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewMockChatSource(t interface { + mock.TestingT + Cleanup(func()) +}) *MockChatSource { + if helper, ok := t.(interface{ Helper() }); ok { + helper.Helper() + } + + mock := &MockChatSource{} + mock.Mock.Test(t) + + t.Cleanup(func() { + if helper, ok := t.(interface{ Helper() }); ok { + helper.Helper() + } + mock.AssertExpectations(t) + }) + + return mock +} + +// MockChatSource is an autogenerated mock type for the ChatSource type +type MockChatSource struct { + mock.Mock +} + +type MockChatSource_Expecter struct { + mock *mock.Mock +} + +func (_m *MockChatSource) EXPECT() *MockChatSource_Expecter { + return &MockChatSource_Expecter{mock: &_m.Mock} +} + +// Create provides a mock function for the type MockChatSource +func (_mock *MockChatSource) Create(ctx context.Context, draft domain.ChatDraft) (domain.Chat, error) { + ret := _mock.Called(ctx, draft) + + if len(ret) == 0 { + panic("no return value specified for Create") + } + + var r0 domain.Chat + var r1 error + if returnFunc, ok := ret.Get(0).(func(context.Context, domain.ChatDraft) (domain.Chat, error)); ok { + return returnFunc(ctx, draft) + } + if returnFunc, ok := ret.Get(0).(func(context.Context, domain.ChatDraft) domain.Chat); ok { + r0 = returnFunc(ctx, draft) + } else { + r0 = ret.Get(0).(domain.Chat) + } + if returnFunc, ok := ret.Get(1).(func(context.Context, domain.ChatDraft) error); ok { + r1 = returnFunc(ctx, draft) + } else { + r1 = ret.Error(1) + } + return r0, r1 +} + +// MockChatSource_Create_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Create' +type MockChatSource_Create_Call struct { + *mock.Call +} + +// Create is a helper method to define mock.On call +// - ctx context.Context +// - draft domain.ChatDraft +func (_e *MockChatSource_Expecter) Create(ctx any, draft any) *MockChatSource_Create_Call { + return &MockChatSource_Create_Call{Call: _e.mock.On("Create", ctx, draft)} +} + +func (_c *MockChatSource_Create_Call) Run(run func(ctx context.Context, draft domain.ChatDraft)) *MockChatSource_Create_Call { + _c.Call.Run(func(args mock.Arguments) { + var arg0 context.Context + if args[0] != nil { + arg0 = args[0].(context.Context) + } + var arg1 domain.ChatDraft + if args[1] != nil { + arg1 = args[1].(domain.ChatDraft) + } + run( + arg0, + arg1, + ) + }) + return _c +} + +func (_c *MockChatSource_Create_Call) Return(chat domain.Chat, err error) *MockChatSource_Create_Call { + _c.Call.Return(chat, err) + return _c +} + +func (_c *MockChatSource_Create_Call) RunAndReturn(run func(ctx context.Context, draft domain.ChatDraft) (domain.Chat, error)) *MockChatSource_Create_Call { + _c.Call.Return(run) + return _c +} + +// GetVisible provides a mock function for the type MockChatSource +func (_mock *MockChatSource) GetVisible(ctx context.Context, chatID uuid.UUID, callerID uuid.UUID) (domain.Chat, error) { + ret := _mock.Called(ctx, chatID, callerID) + + if len(ret) == 0 { + panic("no return value specified for GetVisible") + } + + var r0 domain.Chat + var r1 error + if returnFunc, ok := ret.Get(0).(func(context.Context, uuid.UUID, uuid.UUID) (domain.Chat, error)); ok { + return returnFunc(ctx, chatID, callerID) + } + if returnFunc, ok := ret.Get(0).(func(context.Context, uuid.UUID, uuid.UUID) domain.Chat); ok { + r0 = returnFunc(ctx, chatID, callerID) + } else { + r0 = ret.Get(0).(domain.Chat) + } + if returnFunc, ok := ret.Get(1).(func(context.Context, uuid.UUID, uuid.UUID) error); ok { + r1 = returnFunc(ctx, chatID, callerID) + } else { + r1 = ret.Error(1) + } + return r0, r1 +} + +// MockChatSource_GetVisible_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetVisible' +type MockChatSource_GetVisible_Call struct { + *mock.Call +} + +// GetVisible is a helper method to define mock.On call +// - ctx context.Context +// - chatID uuid.UUID +// - callerID uuid.UUID +func (_e *MockChatSource_Expecter) GetVisible(ctx any, chatID any, callerID any) *MockChatSource_GetVisible_Call { + return &MockChatSource_GetVisible_Call{Call: _e.mock.On("GetVisible", ctx, chatID, callerID)} +} + +func (_c *MockChatSource_GetVisible_Call) Run(run func(ctx context.Context, chatID uuid.UUID, callerID uuid.UUID)) *MockChatSource_GetVisible_Call { + _c.Call.Run(func(args mock.Arguments) { + var arg0 context.Context + if args[0] != nil { + arg0 = args[0].(context.Context) + } + var arg1 uuid.UUID + if args[1] != nil { + arg1 = args[1].(uuid.UUID) + } + var arg2 uuid.UUID + if args[2] != nil { + arg2 = args[2].(uuid.UUID) + } + run( + arg0, + arg1, + arg2, + ) + }) + return _c +} + +func (_c *MockChatSource_GetVisible_Call) Return(chat domain.Chat, err error) *MockChatSource_GetVisible_Call { + _c.Call.Return(chat, err) + return _c +} + +func (_c *MockChatSource_GetVisible_Call) RunAndReturn(run func(ctx context.Context, chatID uuid.UUID, callerID uuid.UUID) (domain.Chat, error)) *MockChatSource_GetVisible_Call { + _c.Call.Return(run) + return _c +} + +// ListVersion provides a mock function for the type MockChatSource +func (_mock *MockChatSource) ListVersion(ctx context.Context, userID uuid.UUID) (int64, error) { + ret := _mock.Called(ctx, userID) + + if len(ret) == 0 { + panic("no return value specified for ListVersion") + } + + var r0 int64 + var r1 error + if returnFunc, ok := ret.Get(0).(func(context.Context, uuid.UUID) (int64, error)); ok { + return returnFunc(ctx, userID) + } + if returnFunc, ok := ret.Get(0).(func(context.Context, uuid.UUID) int64); ok { + r0 = returnFunc(ctx, userID) + } else { + r0 = ret.Get(0).(int64) + } + if returnFunc, ok := ret.Get(1).(func(context.Context, uuid.UUID) error); ok { + r1 = returnFunc(ctx, userID) + } else { + r1 = ret.Error(1) + } + return r0, r1 +} + +// MockChatSource_ListVersion_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ListVersion' +type MockChatSource_ListVersion_Call struct { + *mock.Call +} + +// ListVersion is a helper method to define mock.On call +// - ctx context.Context +// - userID uuid.UUID +func (_e *MockChatSource_Expecter) ListVersion(ctx any, userID any) *MockChatSource_ListVersion_Call { + return &MockChatSource_ListVersion_Call{Call: _e.mock.On("ListVersion", ctx, userID)} +} + +func (_c *MockChatSource_ListVersion_Call) Run(run func(ctx context.Context, userID uuid.UUID)) *MockChatSource_ListVersion_Call { + _c.Call.Run(func(args mock.Arguments) { + var arg0 context.Context + if args[0] != nil { + arg0 = args[0].(context.Context) + } + var arg1 uuid.UUID + if args[1] != nil { + arg1 = args[1].(uuid.UUID) + } + run( + arg0, + arg1, + ) + }) + return _c +} + +func (_c *MockChatSource_ListVersion_Call) Return(n int64, err error) *MockChatSource_ListVersion_Call { + _c.Call.Return(n, err) + return _c +} + +func (_c *MockChatSource_ListVersion_Call) RunAndReturn(run func(ctx context.Context, userID uuid.UUID) (int64, error)) *MockChatSource_ListVersion_Call { + _c.Call.Return(run) + return _c +} + +// ListVisible provides a mock function for the type MockChatSource +func (_mock *MockChatSource) ListVisible(ctx context.Context, callerID uuid.UUID, after *domain.Cursor, limit int) (domain.Page[domain.Chat], error) { + ret := _mock.Called(ctx, callerID, after, limit) + + if len(ret) == 0 { + panic("no return value specified for ListVisible") + } + + var r0 domain.Page[domain.Chat] + var r1 error + if returnFunc, ok := ret.Get(0).(func(context.Context, uuid.UUID, *domain.Cursor, int) (domain.Page[domain.Chat], error)); ok { + return returnFunc(ctx, callerID, after, limit) + } + if returnFunc, ok := ret.Get(0).(func(context.Context, uuid.UUID, *domain.Cursor, int) domain.Page[domain.Chat]); ok { + r0 = returnFunc(ctx, callerID, after, limit) + } else { + r0 = ret.Get(0).(domain.Page[domain.Chat]) + } + if returnFunc, ok := ret.Get(1).(func(context.Context, uuid.UUID, *domain.Cursor, int) error); ok { + r1 = returnFunc(ctx, callerID, after, limit) + } else { + r1 = ret.Error(1) + } + return r0, r1 +} + +// MockChatSource_ListVisible_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ListVisible' +type MockChatSource_ListVisible_Call struct { + *mock.Call +} + +// ListVisible is a helper method to define mock.On call +// - ctx context.Context +// - callerID uuid.UUID +// - after *domain.Cursor +// - limit int +func (_e *MockChatSource_Expecter) ListVisible(ctx any, callerID any, after any, limit any) *MockChatSource_ListVisible_Call { + return &MockChatSource_ListVisible_Call{Call: _e.mock.On("ListVisible", ctx, callerID, after, limit)} +} + +func (_c *MockChatSource_ListVisible_Call) Run(run func(ctx context.Context, callerID uuid.UUID, after *domain.Cursor, limit int)) *MockChatSource_ListVisible_Call { + _c.Call.Run(func(args mock.Arguments) { + var arg0 context.Context + if args[0] != nil { + arg0 = args[0].(context.Context) + } + var arg1 uuid.UUID + if args[1] != nil { + arg1 = args[1].(uuid.UUID) + } + var arg2 *domain.Cursor + if args[2] != nil { + arg2 = args[2].(*domain.Cursor) + } + var arg3 int + if args[3] != nil { + arg3 = args[3].(int) + } + run( + arg0, + arg1, + arg2, + arg3, + ) + }) + return _c +} + +func (_c *MockChatSource_ListVisible_Call) Return(page domain.Page[domain.Chat], err error) *MockChatSource_ListVisible_Call { + _c.Call.Return(page, err) + return _c +} + +func (_c *MockChatSource_ListVisible_Call) RunAndReturn(run func(ctx context.Context, callerID uuid.UUID, after *domain.Cursor, limit int) (domain.Page[domain.Chat], error)) *MockChatSource_ListVisible_Call { + _c.Call.Return(run) + return _c +} diff --git a/internal/telemetry/db.go b/internal/telemetry/db.go new file mode 100644 index 0000000..4cff941 --- /dev/null +++ b/internal/telemetry/db.go @@ -0,0 +1,40 @@ +package telemetry + +import ( + "context" + + "github.com/exaring/otelpgx" + "github.com/jackc/pgx/v5" + "github.com/jackc/pgx/v5/pgxpool" + "go.opentelemetry.io/otel" + "go.opentelemetry.io/otel/metric" +) + +// NewPGXTracer returns a pgx tracer that records database spans without SQL +// text or connection details (those can contain identifiers and DSNs). +func NewPGXTracer() pgx.QueryTracer { + return otelpgx.NewTracer( + otelpgx.WithTracerProvider(otel.GetTracerProvider()), + otelpgx.WithDisableSQLStatementInAttributes(), + otelpgx.WithDisableConnectionDetailsInAttributes(), + ) +} + +// RegisterDBPool exposes pgxpool gauges. pgxpool has no current "waiting" +// counter; EmptyAcquireCount/WaitTime are the observable contention signal. +func RegisterDBPool(stats func() *pgxpool.Stat) error { + initMetrics() + _, err := otel.Meter("messenger").RegisterCallback(func(_ context.Context, o metric.Observer) error { + s := stats() + if s == nil { + return nil + } + o.ObserveInt64(dbUsed, int64(s.AcquiredConns())) + o.ObserveInt64(dbIdle, int64(s.IdleConns())) + o.ObserveInt64(dbMax, int64(s.MaxConns())) + o.ObserveInt64(dbEmptyAcquire, s.EmptyAcquireCount()) + o.ObserveFloat64(dbEmptyWait, s.EmptyAcquireWaitTime().Seconds()) + return nil + }, dbUsed, dbIdle, dbMax, dbEmptyAcquire, dbEmptyWait) + return err +} diff --git a/internal/telemetry/job.go b/internal/telemetry/job.go new file mode 100644 index 0000000..1da19a0 --- /dev/null +++ b/internal/telemetry/job.go @@ -0,0 +1,100 @@ +package telemetry + +import ( + "context" + "regexp" + + "go.opentelemetry.io/otel" + "go.opentelemetry.io/otel/attribute" + "go.opentelemetry.io/otel/propagation" + "go.opentelemetry.io/otel/trace" + + "mtusi-messenger/internal/domain" +) + +var traceparentPattern = regexp.MustCompile(`^00-[0-9a-f]{32}-[0-9a-f]{16}-[0-9a-f]{2}$`) + +// ValidTraceparent reports whether a broker-carried traceparent matches the +// closed schema before it is trusted as a parent context. +func ValidTraceparent(value string) bool { + return value == "" || (len(value) <= 512 && traceparentPattern.MatchString(value)) +} + +// Inject serializes the current span context for a durable outbox payload. +func Inject(ctx context.Context) (traceparent, tracestate string) { + carrier := propagation.MapCarrier{} + otel.GetTextMapPropagator().Inject(ctx, carrier) + tracestate = carrier["tracestate"] + if len(tracestate) > 512 { + tracestate = "" + } + return carrier["traceparent"], tracestate +} + +// Extract restores a parent context from a broker payload. Invalid values are +// ignored; the caller still gets a usable context. +func Extract(ctx context.Context, traceparent, tracestate string) context.Context { + if !ValidTraceparent(traceparent) || len(tracestate) > 512 { + return ctx + } + carrier := propagation.MapCarrier{"traceparent": traceparent} + if tracestate != "" { + carrier["tracestate"] = tracestate + } + return otel.GetTextMapPropagator().Extract(ctx, carrier) +} + +// StartPublishSpan starts the producer span for an outbox publication. The +// returned context carries the span that must be injected into the message. +func StartPublishSpan(ctx context.Context, message domain.JobMessage) (context.Context, trace.Span) { + parent := Extract(ctx, message.Traceparent, message.Tracestate) + return otel.Tracer("messenger/queue").Start(parent, "job.publish", + trace.WithSpanKind(trace.SpanKindProducer), + trace.WithAttributes( + attribute.String("messaging.system", "rabbitmq"), + attribute.String("messaging.operation", "publish"), + attribute.String("messaging.destination.name", message.Type), + attribute.String("job.id", message.JobID.String()), + attribute.String("job.type", message.Type), + attribute.Int("job.attempt", message.Attempt), + ), + ) +} + +// StartRequeueSpanForJob starts a per-job reaper/reconcile span. The durable +// job keeps the original upload trace context, so a retry remains linked to +// attempt 1 instead of the relay's batch-wide reaper span. +func StartRequeueSpanForJob(ctx context.Context, job domain.Job) (context.Context, trace.Span) { + parent := Extract(ctx, job.Traceparent, job.Tracestate) + return otel.Tracer("messenger/relay").Start(parent, "job.requeue", + trace.WithAttributes( + attribute.String("job.id", job.ID.String()), + attribute.String("job.type", domain.JobType), + attribute.Int("job.attempt", job.Attempt), + ), + ) +} + +// StartConsumerSpan starts the worker span as a child of the publish span. +func StartConsumerSpan(ctx context.Context, message domain.JobMessage) (context.Context, trace.Span) { + parent := Extract(ctx, message.Traceparent, message.Tracestate) + return otel.Tracer("messenger/worker").Start(parent, "job.process", + trace.WithSpanKind(trace.SpanKindConsumer), + trace.WithAttributes( + attribute.String("messaging.system", "rabbitmq"), + attribute.String("messaging.operation", "process"), + attribute.String("messaging.destination.name", message.Type), + attribute.String("job.id", message.JobID.String()), + attribute.String("job.type", message.Type), + attribute.Int("job.attempt", message.Attempt), + attribute.Int("pipeline.version", message.PipelineVersion), + ), + ) +} + +// StartRequeueSpan covers the relay's lease reaper / reconciliation path. +func StartRequeueSpan(ctx context.Context, operation string) (context.Context, trace.Span) { + return otel.Tracer("messenger/relay").Start(ctx, "job."+operation, + trace.WithAttributes(attribute.String("job.operation", operation)), + ) +} diff --git a/internal/telemetry/log.go b/internal/telemetry/log.go new file mode 100644 index 0000000..a0e07a1 --- /dev/null +++ b/internal/telemetry/log.go @@ -0,0 +1,220 @@ +package telemetry + +import ( + "context" + "log/slog" + "regexp" + + "go.opentelemetry.io/contrib/bridges/otelslog" + "go.opentelemetry.io/otel/trace" + + "mtusi-messenger/internal/platform/instanceid" +) + +var ( + allowKeys = map[string]struct{}{ + "event": {}, "operation": {}, "route": {}, "method": {}, "status": {}, + "status_class": {}, "duration": {}, "error_code": {}, "job_type": {}, + "outcome": {}, "attempt": {}, "pipeline_version": {}, "queue": {}, + "count": {}, "bytes": {}, "size": {}, "job_id": {}, + "service.name": {}, "service.instance.id": {}, + "deployment.environment.name": {}, "trace_id": {}, "span_id": {}, + "request_id": {}, "error": {}, + } + requestIDPattern = regexp.MustCompile(`^[A-Za-z0-9._:-]{1,64}$`) + jobIDPattern = regexp.MustCompile(`^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$`) + redactPatterns = []*regexp.Regexp{ + regexp.MustCompile(`(?i)(X-Amz-(?:Signature|Credential|Security-Token)=)[^&\s"]+`), + regexp.MustCompile(`(?i)(password|passwd|secret|token|authorization)=([^&\s"]+)`), + regexp.MustCompile(`://[^/\s:@]+:[^@\s]+@`), + regexp.MustCompile(`(?i)\b[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\b`), + regexp.MustCompile(`\b(?:attachments|staging|variants)/[^\s"']+`), + } +) + +// WrapLogger returns a logger that writes sanitized JSON to stdout and, when +// configured, also emits OTLP log records. The sanitizer is the boundary that +// prevents raw paths, filenames, user ids and credentials from reaching any +// telemetry backend. +func WrapLogger(base *slog.Logger, serviceName string, minLevel slog.Level) *slog.Logger { + if base == nil { + base = slog.Default() + } + + var otelHandler slog.Handler + if provider := GlobalLoggerProvider(); provider != nil { + otelHandler = otelslog.NewHandler("messenger", otelslog.WithLoggerProvider(provider)) + } + + return slog.New(&sanitizeHandler{ + inner: &fanoutHandler{handlers: []slog.Handler{base.Handler(), otelHandler}}, + service: serviceName, + instance: instanceid.FromEnvOrHostname(), + minLevel: minLevel, + }) +} + +type fanoutHandler struct { + handlers []slog.Handler +} + +func (h *fanoutHandler) Enabled(ctx context.Context, level slog.Level) bool { + for _, handler := range h.handlers { + if handler != nil && handler.Enabled(ctx, level) { + return true + } + } + return false +} + +func (h *fanoutHandler) Handle(ctx context.Context, record slog.Record) error { + for _, handler := range h.handlers { + if handler == nil { + continue + } + if err := handler.Handle(ctx, record.Clone()); err != nil { + return err + } + } + return nil +} + +func (h *fanoutHandler) WithAttrs(attrs []slog.Attr) slog.Handler { + next := &fanoutHandler{handlers: make([]slog.Handler, 0, len(h.handlers))} + for _, handler := range h.handlers { + if handler == nil { + next.handlers = append(next.handlers, nil) + continue + } + next.handlers = append(next.handlers, handler.WithAttrs(attrs)) + } + return next +} + +func (h *fanoutHandler) WithGroup(name string) slog.Handler { + next := &fanoutHandler{handlers: make([]slog.Handler, 0, len(h.handlers))} + for _, handler := range h.handlers { + if handler == nil { + next.handlers = append(next.handlers, nil) + continue + } + next.handlers = append(next.handlers, handler.WithGroup(name)) + } + return next +} + +type sanitizeHandler struct { + inner slog.Handler + service string + instance string + minLevel slog.Level +} + +func (h *sanitizeHandler) Enabled(ctx context.Context, level slog.Level) bool { + return level >= h.minLevel && h.inner.Enabled(ctx, level) +} + +func (h *sanitizeHandler) Handle(ctx context.Context, record slog.Record) error { + sanitized := slog.NewRecord(record.Time, record.Level, sanitizeText(record.Message), record.PC) + + seenEvent := false + record.Attrs(func(attr slog.Attr) bool { + if attr.Key == "event" { + seenEvent = true + } + if clean, ok := sanitizeAttr(attr); ok { + sanitized.AddAttrs(clean) + } + return true + }) + + if !seenEvent { + event := sanitizeText(record.Message) + if event == "" { + event = "log" + } + sanitized.AddAttrs(slog.String("event", event)) + } + if h.service != "" { + sanitized.AddAttrs(slog.String("service.name", h.service)) + } + if h.instance != "" { + sanitized.AddAttrs(slog.String("service.instance.id", h.instance)) + } + if spanContext := trace.SpanContextFromContext(ctx); spanContext.IsValid() { + sanitized.AddAttrs( + slog.String("trace_id", spanContext.TraceID().String()), + slog.String("span_id", spanContext.SpanID().String()), + ) + } + + return h.inner.Handle(ctx, sanitized) +} + +func (h *sanitizeHandler) WithAttrs(attrs []slog.Attr) slog.Handler { + clean := make([]slog.Attr, 0, len(attrs)) + for _, attr := range attrs { + if value, ok := sanitizeAttr(attr); ok { + clean = append(clean, value) + } + } + return &sanitizeHandler{inner: h.inner.WithAttrs(clean), service: h.service, instance: h.instance, minLevel: h.minLevel} +} + +func (h *sanitizeHandler) WithGroup(name string) slog.Handler { + return &sanitizeHandler{inner: h.inner.WithGroup(name), service: h.service, instance: h.instance, minLevel: h.minLevel} +} + +func sanitizeAttr(attr slog.Attr) (slog.Attr, bool) { + if _, ok := allowKeys[attr.Key]; !ok { + return slog.Attr{}, false + } + + value := attr.Value.Resolve() + switch attr.Key { + case "error": + return slog.String("error", Redact(value.String())), true + case "request_id": + id := value.String() + if !requestIDPattern.MatchString(id) { + id = "invalid" + } + return slog.String("request_id", id), true + case "job_id": + // job_id is an explicitly allowlisted synthetic/technical identifier. + // Unlike free-form error text, it is safe to keep for queue correlation. + id := value.String() + if !jobIDPattern.MatchString(id) { + id = "invalid" + } + return slog.String("job_id", id), true + } + + if value.Kind() == slog.KindGroup { + return slog.Attr{}, false + } + if value.Kind() == slog.KindString { + return slog.String(attr.Key, sanitizeText(value.String())), true + } + return slog.Attr{Key: attr.Key, Value: value}, true +} + +func sanitizeText(value string) string { + return truncate(Redact(value), 1024) +} + +// Redact removes credentials, signed-URL parameters, UUIDs and object keys from +// free-form error text before it reaches stdout, logs or trace exception events. +func Redact(value string) string { + for _, pattern := range redactPatterns { + value = pattern.ReplaceAllString(value, "$1***") + } + return truncate(value, 1024) +} + +func truncate(value string, limit int) string { + if len(value) <= limit { + return value + } + return value[:limit] + "..." +} diff --git a/internal/telemetry/log_test.go b/internal/telemetry/log_test.go new file mode 100644 index 0000000..c3ba5ef --- /dev/null +++ b/internal/telemetry/log_test.go @@ -0,0 +1,129 @@ +package telemetry + +import ( + "context" + "log/slog" + "strings" + "testing" + "time" + + "go.opentelemetry.io/otel" + "go.opentelemetry.io/otel/propagation" + "go.opentelemetry.io/otel/trace" +) + +type captureHandler struct { + attrs []slog.Attr +} + +func (h *captureHandler) Enabled(context.Context, slog.Level) bool { return true } +func (h *captureHandler) Handle(_ context.Context, record slog.Record) error { + record.Attrs(func(attr slog.Attr) bool { + h.attrs = append(h.attrs, attr) + return true + }) + return nil +} + +func (h *captureHandler) WithAttrs(attrs []slog.Attr) slog.Handler { + return &captureHandler{attrs: append(h.attrs, attrs...)} +} +func (h *captureHandler) WithGroup(string) slog.Handler { return h } + +func TestSanitizerDropsIdentifiersAndRedactsErrors(t *testing.T) { + capture := &captureHandler{} + handler := &sanitizeHandler{inner: capture, service: "messenger-api", instance: "instance-1", minLevel: slog.LevelDebug} + record := slog.NewRecord(time.Now(), slog.LevelInfo, "request handled", 0) + record.AddAttrs( + slog.String("event", "http.request.completed"), + slog.String("path", "/api/v1/chats/33333333-3333-4333-8333-333333333333/messages"), + slog.String("query", "filename=secret.png"), + slog.String("user_id", "aaaaaaaa-aaaa-4aaa-8aaa-aaaaaaaaaaaa"), + slog.String("object_key", "attachments/chat/attachment/original"), + slog.String("error", `parse "postgres://user:pass@db:5432/x": X-Amz-Signature=abc attachments/33333333-3333-4333-8333-333333333333/44444444-4444-4444-8444-444444444444/original`), + slog.String("request_id", "bad request id with spaces"), + ) + if err := handler.Handle(context.Background(), record); err != nil { + t.Fatal(err) + } + + seen := map[string]string{} + for _, attr := range capture.attrs { + seen[attr.Key] = attr.Value.String() + } + for _, forbidden := range []string{"path", "query", "user_id", "object_key"} { + if _, ok := seen[forbidden]; ok { + t.Fatalf("forbidden attribute %q was exported", forbidden) + } + } + if strings.Contains(seen["error"], "pass") || strings.Contains(seen["error"], "abc") { + t.Fatalf("error was not redacted: %q", seen["error"]) + } + if strings.Contains(seen["error"], "33333333") || strings.Contains(seen["error"], "attachments/") { + t.Fatalf("object key/uuid was not redacted: %q", seen["error"]) + } + if seen["request_id"] != "invalid" { + t.Fatalf("request_id was not normalized: %q", seen["request_id"]) + } + if seen["service.name"] != "messenger-api" || seen["service.instance.id"] != "instance-1" { + t.Fatalf("service attributes missing: %#v", seen) + } +} + +func TestValidTraceparent(t *testing.T) { + if !ValidTraceparent("00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-01") { + t.Fatal("valid traceparent rejected") + } + if ValidTraceparent("not-a-traceparent") || ValidTraceparent("00-X") { + t.Fatal("invalid traceparent accepted") + } +} + +func TestInjectDropsOversizedTracestate(t *testing.T) { + otel.SetTextMapPropagator(propagation.TraceContext{}) + ts, err := trace.ParseTraceState("a=" + strings.Repeat("a", 180) + ",b=" + strings.Repeat("b", 180) + ",c=" + strings.Repeat("c", 180)) + if err != nil { + t.Fatal(err) + } + sc := trace.NewSpanContext(trace.SpanContextConfig{ + TraceID: trace.TraceID{1}, + SpanID: trace.SpanID{1}, + TraceState: ts, + }) + traceparent, tracestate := Inject(trace.ContextWithSpanContext(context.Background(), sc)) + if traceparent == "" { + t.Fatal("traceparent missing") + } + if tracestate != "" { + t.Fatalf("oversized tracestate was persisted: %d bytes", len(tracestate)) + } +} + +func TestInjectPreservesValidTracestate(t *testing.T) { + otel.SetTextMapPropagator(propagation.TraceContext{}) + small, err := trace.ParseTraceState("vendor=abc123") + if err != nil { + t.Fatal(err) + } + sc := trace.NewSpanContext(trace.SpanContextConfig{ + TraceID: trace.TraceID{1}, + SpanID: trace.SpanID{1}, + TraceState: small, + }) + _, kept := Inject(trace.ContextWithSpanContext(context.Background(), sc)) + if kept != "vendor=abc123" { + t.Fatalf("valid tracestate dropped: %q", kept) + } +} + +func TestSanitizeKeepsAllowlistedJobID(t *testing.T) { + const id = "11111111-1111-4111-8111-111111111111" + attr := slog.String("job_id", id) + clean, ok := sanitizeAttr(attr) + if !ok || clean.Value.String() != id { + t.Fatalf("job_id = %#v, want %q", clean, id) + } + if clean, ok := sanitizeAttr(slog.String("job_id", "not-a-uuid")); !ok || clean.Value.String() != "invalid" { + t.Fatalf("invalid job_id = %#v", clean) + } +} diff --git a/internal/telemetry/metrics.go b/internal/telemetry/metrics.go new file mode 100644 index 0000000..bc85826 --- /dev/null +++ b/internal/telemetry/metrics.go @@ -0,0 +1,184 @@ +package telemetry + +import ( + "context" + "strconv" + "sync" + "time" + + "go.opentelemetry.io/otel" + "go.opentelemetry.io/otel/attribute" + "go.opentelemetry.io/otel/metric" +) + +var ( + metricsOnce sync.Once + + httpDuration metric.Float64Histogram + jobsProcessed metric.Int64Counter + jobDuration metric.Float64Histogram + jobsAccepted metric.Int64Counter + timeToReady metric.Float64Histogram + jobsReadyInBudget metric.Int64Counter + ttrMissed metric.Int64Counter + workerBusy metric.Int64ObservableGauge + workerCapacity metric.Int64ObservableGauge + dbUsed metric.Int64ObservableGauge + dbIdle metric.Int64ObservableGauge + dbMax metric.Int64ObservableGauge + dbEmptyAcquire metric.Int64ObservableCounter + dbEmptyWait metric.Float64ObservableCounter + processCPU metric.Float64ObservableCounter + processMemory metric.Int64ObservableGauge + processMemLimit metric.Int64ObservableGauge + oldestJobAge metric.Float64ObservableGauge + oldestOutboxAge metric.Float64ObservableGauge + jobsOverdue metric.Int64ObservableGauge +) + +func initMetrics() { + metricsOnce.Do(func() { + meter := otel.Meter("messenger") + + httpDuration, _ = meter.Float64Histogram("http.server.request.duration", + metric.WithDescription("HTTP server request duration"), + metric.WithUnit("s"), + metric.WithExplicitBucketBoundaries(0.005, 0.01, 0.025, 0.05, 0.1, 0.25, 0.5, 1, 2.5, 5, 10)) + jobsProcessed, _ = meter.Int64Counter("messenger.jobs.processed", + metric.WithDescription("Attachment job attempts by outcome")) + jobDuration, _ = meter.Float64Histogram("messenger.job.duration", + metric.WithDescription("Attachment job processing duration"), + metric.WithUnit("s"), + metric.WithExplicitBucketBoundaries(0.1, 0.25, 0.5, 1, 2.5, 5, 10, 30, 60, 120)) + jobsAccepted, _ = meter.Int64Counter("messenger.jobs.accepted", + metric.WithDescription("Durable attachment jobs accepted with 202")) + timeToReady, _ = meter.Float64Histogram("messenger.job.time_to_ready", + metric.WithDescription("Time from durable acceptance to ready"), + metric.WithUnit("s"), + metric.WithExplicitBucketBoundaries(1, 2.5, 5, 10, 20, 30, 60, 120, 300)) + jobsReadyInBudget, _ = meter.Int64Counter("messenger.jobs.ready_within_budget", + metric.WithDescription("Jobs ready within the 30s TTR objective")) + ttrMissed, _ = meter.Int64Counter("messenger.jobs.ttr_missed", + metric.WithDescription("Jobs that missed or failed the 30s TTR objective")) + workerBusy, _ = meter.Int64ObservableGauge("messenger.worker.busy", + metric.WithDescription("Worker slots currently processing a job")) + workerCapacity, _ = meter.Int64ObservableGauge("messenger.worker.capacity", + metric.WithDescription("Configured worker concurrency")) + dbUsed, _ = meter.Int64ObservableGauge("messenger.db.pool.used") + dbIdle, _ = meter.Int64ObservableGauge("messenger.db.pool.idle") + dbMax, _ = meter.Int64ObservableGauge("messenger.db.pool.max") + dbEmptyAcquire, _ = meter.Int64ObservableCounter("messenger.db.pool.empty_acquire", + metric.WithDescription("Acquisitions that had to wait for a free connection")) + dbEmptyWait, _ = meter.Float64ObservableCounter("messenger.db.pool.empty_acquire_wait_seconds", + metric.WithDescription("Cumulative wait time for empty pool acquisitions"), + metric.WithUnit("s")) + processCPU, _ = meter.Float64ObservableCounter("messenger.process.cpu_seconds", + metric.WithDescription("Cumulative process CPU time from cgroup or /proc"), + metric.WithUnit("s")) + processMemory, _ = meter.Int64ObservableGauge("messenger.process.memory_usage_bytes", + metric.WithDescription("Resident/current memory of this container"), + metric.WithUnit("By")) + processMemLimit, _ = meter.Int64ObservableGauge("messenger.process.memory_limit_bytes", + metric.WithDescription("Container memory limit, 0 when unknown"), + metric.WithUnit("By")) + oldestJobAge, _ = meter.Float64ObservableGauge("messenger.queue.oldest_job_age", + metric.WithDescription("Age of the oldest queued or processing job"), + metric.WithUnit("s")) + oldestOutboxAge, _ = meter.Float64ObservableGauge("messenger.outbox.oldest_unpublished_age", + metric.WithDescription("Age of the oldest unpublished outbox intent"), + metric.WithUnit("s")) + jobsOverdue, _ = meter.Int64ObservableGauge("messenger.jobs.overdue", + metric.WithDescription("Queued/processing jobs older than the 30s TTR objective")) + }) +} + +// RecordHTTP records one completed server request. route must be an OpenAPI +// template, never a raw path. +func RecordHTTP(ctx context.Context, method, route string, status int, duration time.Duration) { + initMetrics() + class := statusClass(status) + attrs := metric.WithAttributes( + attribute.String("http.request.method", method), + attribute.String("http.route", route), + attribute.Int("http.response.status_code", status), + attribute.String("http.response.status_class", class), + ) + httpDuration.Record(ctx, duration.Seconds(), attrs) +} + +// RecordJobAccepted counts a durable 202 acceptance. +func RecordJobAccepted(ctx context.Context, pipelineVersion int) { + initMetrics() + jobsAccepted.Add(ctx, 1, metric.WithAttributes(attribute.Int("pipeline.version", pipelineVersion))) +} + +// RecordJobAttempt records one processing attempt. +func RecordJobAttempt(ctx context.Context, jobType, outcome string, duration time.Duration) { + initMetrics() + attrs := metric.WithAttributes( + attribute.String("job.type", jobType), + attribute.String("outcome", outcome), + ) + jobsProcessed.Add(ctx, 1, attrs) + jobDuration.Record(ctx, duration.Seconds(), attrs) +} + +// RecordJobReady records a terminal ready result and its time-to-ready. +func RecordJobReady(ctx context.Context, pipelineVersion int, duration time.Duration) { + initMetrics() + attrs := metric.WithAttributes(attribute.Int("pipeline.version", pipelineVersion)) + timeToReady.Record(ctx, duration.Seconds(), attrs) + if duration <= 30*time.Second { + jobsReadyInBudget.Add(ctx, 1, attrs) + } +} + +// RegisterWorkerMetrics exposes the worker's in-flight slots and capacity. +// RegisterRelayMetrics exposes durable backlog age gauges computed in the relay. +func RegisterRelayMetrics(oldestJob func(context.Context) (float64, error), oldestOutbox func(context.Context) (time.Duration, error), overdue func(context.Context) (int64, error)) error { + initMetrics() + _, err := otel.Meter("messenger").RegisterCallback(func(ctx context.Context, o metric.Observer) error { + if oldestJob != nil { + if seconds, err := oldestJob(ctx); err == nil { + o.ObserveFloat64(oldestJobAge, seconds) + } + } + if oldestOutbox != nil { + if age, err := oldestOutbox(ctx); err == nil { + o.ObserveFloat64(oldestOutboxAge, age.Seconds()) + } + } + if overdue != nil { + if count, err := overdue(ctx); err == nil { + o.ObserveInt64(jobsOverdue, count) + } + } + return nil + }, oldestJobAge, oldestOutboxAge, jobsOverdue) + return err +} + +// RecordTTRMissed records jobs marked as TTR misses by the relay sweeper. +func RecordTTRMissed(ctx context.Context, count int64) { + initMetrics() + // Add zero at relay startup so the counter exists before the first miss; + // otherwise the first rate() window loses the initial increment. + ttrMissed.Add(ctx, count) +} + +func RegisterWorkerMetrics(busy func() int64, capacity int64) error { + initMetrics() + _, err := otel.Meter("messenger").RegisterCallback(func(_ context.Context, o metric.Observer) error { + o.ObserveInt64(workerBusy, busy()) + o.ObserveInt64(workerCapacity, capacity) + return nil + }, workerBusy, workerCapacity) + return err +} + +func statusClass(status int) string { + if status < 100 || status > 599 { + return "unknown" + } + return strconv.Itoa(status/100) + "xx" +} diff --git a/internal/telemetry/objectstore.go b/internal/telemetry/objectstore.go new file mode 100644 index 0000000..0a70e89 --- /dev/null +++ b/internal/telemetry/objectstore.go @@ -0,0 +1,107 @@ +package telemetry + +import ( + "context" + "errors" + "io" + "time" + + "go.opentelemetry.io/otel" + "go.opentelemetry.io/otel/attribute" + "go.opentelemetry.io/otel/trace" + + "mtusi-messenger/internal/platform/objectstore" +) + +type tracedStore struct { + inner objectstore.Store +} + +// WrapStore adds S3 client spans without recording object keys (keys contain +// chat_id) or presigned URLs. +func WrapStore(inner objectstore.Store) objectstore.Store { + if inner == nil { + return nil + } + return &tracedStore{inner: inner} +} + +func (s *tracedStore) start(ctx context.Context, operation string) (context.Context, trace.Span) { + return otel.Tracer("messenger/s3").Start(ctx, "S3."+operation, + trace.WithSpanKind(trace.SpanKindClient), + trace.WithAttributes( + attribute.String("rpc.system", "aws.s3"), + attribute.String("rpc.service", "S3"), + attribute.String("rpc.method", operation), + attribute.String("aws.s3.operation", operation), + ), + ) +} + +func (s *tracedStore) Ping(ctx context.Context) error { + ctx, span := s.start(ctx, "Ping") + defer span.End() + return s.inner.Ping(ctx) +} + +func (s *tracedStore) Put(ctx context.Context, key string, body io.ReadSeeker, size int64, contentType string, metadata map[string]string) error { + ctx, span := s.start(ctx, "PutObject") + defer span.End() + span.SetAttributes(attribute.Int64("aws.s3.object.size", size)) + return s.inner.Put(ctx, key, body, size, contentType, metadata) +} + +type spanReadCloser struct { + inner io.ReadCloser + span trace.Span +} + +func (r *spanReadCloser) Read(p []byte) (int, error) { return r.inner.Read(p) } +func (r *spanReadCloser) Close() error { + err := r.inner.Close() + r.span.End() + return err +} + +func (s *tracedStore) Open(ctx context.Context, key string) (io.ReadCloser, objectstore.Object, error) { + ctx, span := s.start(ctx, "GetObject") + body, object, err := s.inner.Open(ctx, key) + if err != nil { + span.RecordError(errors.New(Redact(err.Error()))) + span.End() + return nil, object, err + } + span.SetAttributes(attribute.Int64("aws.s3.object.size", object.Size)) + return &spanReadCloser{inner: body, span: span}, object, nil +} + +func (s *tracedStore) Head(ctx context.Context, key string) (objectstore.Object, error) { + ctx, span := s.start(ctx, "HeadObject") + defer span.End() + return s.inner.Head(ctx, key) +} + +func (s *tracedStore) Copy(ctx context.Context, src, dst, contentType string, metadata map[string]string) error { + ctx, span := s.start(ctx, "CopyObject") + defer span.End() + return s.inner.Copy(ctx, src, dst, contentType, metadata) +} + +func (s *tracedStore) Delete(ctx context.Context, key string) error { + ctx, span := s.start(ctx, "DeleteObject") + defer span.End() + return s.inner.Delete(ctx, key) +} + +func (s *tracedStore) List(ctx context.Context, prefix string) ([]objectstore.Object, error) { + ctx, span := s.start(ctx, "ListObjects") + defer span.End() + return s.inner.List(ctx, prefix) +} + +func (s *tracedStore) PresignPut(ctx context.Context, key string, size int64, ttl time.Duration) (string, time.Time, error) { + ctx, span := s.start(ctx, "PresignPut") + defer span.End() + span.SetAttributes(attribute.Int64("aws.s3.object.size", size), attribute.String("aws.s3.presign.ttl", ttl.String())) + return s.inner.PresignPut(ctx, key, size, ttl) +} diff --git a/internal/telemetry/process.go b/internal/telemetry/process.go new file mode 100644 index 0000000..a73b716 --- /dev/null +++ b/internal/telemetry/process.go @@ -0,0 +1,124 @@ +package telemetry + +import ( + "bufio" + "context" + "os" + "strconv" + "strings" + + "go.opentelemetry.io/otel" + "go.opentelemetry.io/otel/metric" +) + +// RegisterProcessMetrics exposes this process/container CPU and memory. It +// uses cgroup v2 when available and /proc as a fallback. The metrics are +// intentionally process-scoped: no Docker socket or host root is required. +func RegisterProcessMetrics() error { + initMetrics() + _, err := otel.Meter("messenger").RegisterCallback(func(_ context.Context, o metric.Observer) error { + cpu, memory, limit := readProcessStats() + o.ObserveFloat64(processCPU, cpu) + o.ObserveInt64(processMemory, memory) + o.ObserveInt64(processMemLimit, limit) + return nil + }, processCPU, processMemory, processMemLimit) + return err +} + +func readProcessStats() (cpuSeconds float64, memoryBytes, memoryLimit int64) { + if value, ok := readCgroupCPU(); ok { + cpuSeconds = value + } else { + cpuSeconds = readProcCPU() + } + memoryBytes = readCgroupMemory() + if memoryBytes == 0 { + memoryBytes = readProcRSS() + } + memoryLimit = readCgroupMemoryLimit() + return cpuSeconds, memoryBytes, memoryLimit +} + +func readCgroupCPU() (float64, bool) { + raw, err := os.ReadFile("/sys/fs/cgroup/cpu.stat") + if err != nil { + return 0, false + } + for _, line := range strings.Split(string(raw), "\n") { + fields := strings.Fields(line) + if len(fields) == 2 && fields[0] == "usage_usec" { + usec, err := strconv.ParseFloat(fields[1], 64) + if err == nil { + return usec / 1e6, true + } + } + } + return 0, false +} + +func readProcCPU() float64 { + raw, err := os.ReadFile("/proc/self/stat") + if err != nil { + return 0 + } + // comm may contain spaces; fields after the closing parenthesis are stable. + end := strings.LastIndexByte(string(raw), ')') + if end < 0 { + return 0 + } + fields := strings.Fields(string(raw)[end+1:]) + if len(fields) < 15 { + return 0 + } + utime, _ := strconv.ParseFloat(fields[11], 64) + stime, _ := strconv.ParseFloat(fields[12], 64) + return (utime + stime) / 100 // USER_HZ on Linux is 100 in the images used. +} + +func readCgroupMemory() int64 { + for _, path := range []string{"/sys/fs/cgroup/memory.current", "/sys/fs/cgroup/memory/memory.usage_in_bytes"} { + if raw, err := os.ReadFile(path); err == nil { + if value, err := strconv.ParseInt(strings.TrimSpace(string(raw)), 10, 64); err == nil { + return value + } + } + } + return 0 +} + +func readCgroupMemoryLimit() int64 { + for _, path := range []string{"/sys/fs/cgroup/memory.max", "/sys/fs/cgroup/memory/memory.limit_in_bytes"} { + raw, err := os.ReadFile(path) + if err != nil { + continue + } + value := strings.TrimSpace(string(raw)) + if value == "max" { + return 0 + } + if parsed, err := strconv.ParseInt(value, 10, 64); err == nil { + return parsed + } + } + return 0 +} + +func readProcRSS() int64 { + file, err := os.Open("/proc/self/status") + if err != nil { + return 0 + } + defer file.Close() + + scanner := bufio.NewScanner(file) + for scanner.Scan() { + fields := strings.Fields(scanner.Text()) + if len(fields) >= 2 && fields[0] == "VmRSS:" { + if kb, err := strconv.ParseInt(fields[1], 10, 64); err == nil { + return kb * 1024 + } + } + } + return 0 +} diff --git a/internal/telemetry/setup.go b/internal/telemetry/setup.go new file mode 100644 index 0000000..e1b5090 --- /dev/null +++ b/internal/telemetry/setup.go @@ -0,0 +1,185 @@ +// Package telemetry wires OpenTelemetry traces, metrics and logs to OTLP and +// provides the small set of instruments used by the application. Telemetry is +// best-effort: a missing Collector must never fail startup or readiness. +package telemetry + +import ( + "context" + "errors" + "fmt" + "os" + "strconv" + "strings" + "sync" + "time" + + "go.opentelemetry.io/otel" + "go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploghttp" + "go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp" + "go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp" + "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" + semconv "go.opentelemetry.io/otel/semconv/v1.37.0" + + "mtusi-messenger/internal/platform/instanceid" +) + +// Shutdown flushes and closes providers. It is safe to call once. +type Shutdown func(context.Context) error + +var ( + globalLogProvider *sdklog.LoggerProvider + shutdownOnce sync.Once +) + +// Enabled reports whether TELEMETRY_ENABLED is not explicitly disabled. +func Enabled() bool { + return strings.ToLower(strings.TrimSpace(os.Getenv("TELEMETRY_ENABLED"))) != "0" +} + +// Setup configures global OTel providers. Exporters are asynchronous and do +// not connect synchronously; an unreachable Collector only produces bounded +// background export failures. +func Setup(ctx context.Context, serviceName, version string) (Shutdown, error) { + if !Enabled() { + return func(context.Context) error { return nil }, nil + } + + // resource.Default carries the SDK's schema URL (currently 1.43.0); using a + // different semconv schema in NewWithAttributes conflicts. The code resource + // is schemaless, while the SDK still provides telemetry.sdk.* attributes. + res, err := resource.Merge( + resource.Default(), + resource.NewSchemaless( + semconv.ServiceName(serviceName), + semconv.ServiceVersion(defaultVersion(version)), + semconv.ServiceInstanceID(instanceid.FromEnvOrHostname()), + semconv.DeploymentEnvironmentName("lab"), + ), + ) + if err != nil { + return nil, fmt.Errorf("build telemetry resource: %w", err) + } + + traceExporter, err := otlptracehttp.New(ctx) + if err != nil { + return nil, fmt.Errorf("create trace exporter: %w", err) + } + metricExporter, err := otlpmetrichttp.New(ctx) + if err != nil { + return nil, fmt.Errorf("create metric exporter: %w", err) + } + logExporter, err := otlploghttp.New(ctx) + if err != nil { + return nil, fmt.Errorf("create log exporter: %w", err) + } + + tracerProvider := sdktrace.NewTracerProvider( + sdktrace.WithResource(res), + sdktrace.WithSampler(samplerFromEnv()), + sdktrace.WithBatcher(traceExporter, + sdktrace.WithMaxQueueSize(2048), + sdktrace.WithMaxExportBatchSize(512), + sdktrace.WithBatchTimeout(5*time.Second), + sdktrace.WithExportTimeout(5*time.Second), + ), + ) + + meterProvider := sdkmetric.NewMeterProvider( + sdkmetric.WithResource(res), + sdkmetric.WithReader(sdkmetric.NewPeriodicReader( + metricExporter, + sdkmetric.WithInterval(metricInterval()), + sdkmetric.WithTimeout(5*time.Second), + )), + ) + + loggerProvider := sdklog.NewLoggerProvider( + sdklog.WithResource(res), + sdklog.WithProcessor(sdklog.NewBatchProcessor( + logExporter, + sdklog.WithExportInterval(5*time.Second), + sdklog.WithExportTimeout(5*time.Second), + sdklog.WithMaxQueueSize(2048), + sdklog.WithExportMaxBatchSize(512), + )), + ) + + otel.SetTracerProvider(tracerProvider) + otel.SetMeterProvider(meterProvider) + otel.SetLoggerProvider(loggerProvider) + otel.SetTextMapPropagator(propagation.NewCompositeTextMapPropagator( + propagation.TraceContext{}, + propagation.Baggage{}, + )) + + globalLogProvider = loggerProvider + initMetrics() + + return func(shutdownCtx context.Context) error { + var errs []error + shutdownOnce.Do(func() { + // Each provider gets its own bounded budget. Sharing one short context + // lets a slow trace flush starve the metric/log flush on shutdown. + flush := func(fn func(context.Context) error) error { + ctx, cancel := context.WithTimeout(context.WithoutCancel(shutdownCtx), 2*time.Second) + defer cancel() + return fn(ctx) + } + errs = append(errs, + flush(tracerProvider.Shutdown), + flush(meterProvider.Shutdown), + flush(loggerProvider.Shutdown), + ) + }) + return errors.Join(errs...) + }, nil +} + +// GlobalLoggerProvider exposes the configured log provider for the slog fanout. +func GlobalLoggerProvider() *sdklog.LoggerProvider { + return globalLogProvider +} + +func defaultVersion(version string) string { + if strings.TrimSpace(version) == "" { + return "dev" + } + return version +} + +func metricInterval() time.Duration { + raw := strings.TrimSpace(os.Getenv("OTEL_METRIC_EXPORT_INTERVAL")) + if raw == "" { + return 15 * time.Second + } + ms, err := strconv.Atoi(raw) + if err != nil || ms <= 0 { + return 15 * time.Second + } + return time.Duration(ms) * time.Millisecond +} + +func samplerFromEnv() sdktrace.Sampler { + name := strings.ToLower(strings.TrimSpace(os.Getenv("OTEL_TRACES_SAMPLER"))) + ratio := 1.0 + if raw := strings.TrimSpace(os.Getenv("OTEL_TRACES_SAMPLER_ARG")); raw != "" { + if parsed, err := strconv.ParseFloat(raw, 64); err == nil { + ratio = parsed + } + } + switch name { + case "always_off": + return sdktrace.NeverSample() + case "traceidratio": + return sdktrace.TraceIDRatioBased(ratio) + case "parentbased_traceidratio": + return sdktrace.ParentBased(sdktrace.TraceIDRatioBased(ratio)) + default: + // The lab needs complete traces to prove the upload -> worker chain. + return sdktrace.ParentBased(sdktrace.AlwaysSample()) + } +} diff --git a/internal/transport/rest/attachments.go b/internal/transport/rest/attachments.go new file mode 100644 index 0000000..e9640f2 --- /dev/null +++ b/internal/transport/rest/attachments.go @@ -0,0 +1,183 @@ +package rest + +import ( + "context" + "fmt" + "io" + + "mtusi-messenger/internal/domain" + attachmentService "mtusi-messenger/internal/service/attachment" + "mtusi-messenger/internal/transport/rest/internal/oas" +) + +func (h *Handler) UploadAttachment( + ctx context.Context, + req oas.UploadAttachmentReq, + params oas.UploadAttachmentParams, +) (oas.UploadAttachmentRes, error) { + body, declared, err := uploadBody(req) + if err != nil { + return nil, err + } + + attachment, err := h.attachments.Upload(ctx, attachmentService.UploadInput{ + ChatID: params.ChatID, + OwnerID: caller(ctx), + Filename: params.Filename, + DeclaredContentType: declared, + Body: body, + }) + if err != nil { + return nil, err + } + + return &oas.AttachmentHeaders{ + XRequestID: oas.NewOptString(requestIDFromContext(ctx)), + Response: attachmentResponse(attachment), + }, nil +} + +func (h *Handler) GetAttachment( + ctx context.Context, + params oas.GetAttachmentParams, +) (oas.GetAttachmentRes, error) { + attachment, err := h.attachments.Get(ctx, caller(ctx), params.AttachmentID) + if err != nil { + return nil, err + } + + return &oas.AttachmentHeaders{ + XRequestID: oas.NewOptString(requestIDFromContext(ctx)), + Response: attachmentResponse(attachment), + }, nil +} + +func (h *Handler) DownloadAttachment( + ctx context.Context, + params oas.DownloadAttachmentParams, +) (oas.DownloadAttachmentRes, error) { + variant := domain.VariantOriginal + if requested, ok := params.Variant.Get(); ok { + variant = domain.VariantName(requested) + } + + attachment, metadata, body, err := h.attachments.OpenVariant( + ctx, caller(ctx), params.AttachmentID, variant, + ) + if err != nil { + return nil, err + } + + // The generated transport copies the body after the handler returns. Close + // the S3 stream when the client disconnects; closeOnEOF covers the normal + // path. + _ = context.AfterFunc(ctx, func() { _ = body.Close() }) + + requestID := oas.NewOptString(requestIDFromContext(ctx)) + reader := closeOnEOF{ReadCloser: body} + + switch metadata.ContentType { + case "image/png": + return &oas.DownloadAttachmentOKImagePNGHeaders{ + XRequestID: requestID, + Response: oas.DownloadAttachmentOKImagePNG{Data: reader}, + }, nil + case "image/jpeg": + return &oas.DownloadAttachmentOKImageJpegHeaders{ + XRequestID: requestID, + Response: oas.DownloadAttachmentOKImageJpeg{Data: reader}, + }, nil + case "image/webp": + return &oas.DownloadAttachmentOKImageWEBPHeaders{ + XRequestID: requestID, + Response: oas.DownloadAttachmentOKImageWEBP{Data: reader}, + }, nil + default: + _ = body.Close() + + return nil, fmt.Errorf("%w: unexpected content type %q", domain.ErrUnavailable, attachment.ContentType) + } +} + +func uploadBody(req oas.UploadAttachmentReq) (io.Reader, string, error) { + switch typed := req.(type) { + case *oas.UploadAttachmentReqImagePNG: + return typed.Data, "image/png", nil + case *oas.UploadAttachmentReqImageJpeg: + return typed.Data, "image/jpeg", nil + default: + return nil, "", fmt.Errorf("%w: request body must be image/png or image/jpeg", domain.ErrUnsupportedMedia) + } +} + +func attachmentResponse(attachment domain.Attachment) oas.Attachment { + response := oas.Attachment{ + ID: attachment.ID, + ChatID: attachment.ChatID, + OwnerID: attachment.OwnerID, + Filename: attachment.Filename, + SizeBytes: int(attachment.SizeBytes), + SHA256: attachment.SHA256, + Status: attachmentStatus(attachment.Status), + ErrorCode: oas.NilString{Null: true}, + CreatedAt: attachment.CreatedAt, + UpdatedAt: attachment.UpdatedAt, + Variants: make([]oas.Variant, 0, len(attachment.Variants)), + } + + switch attachment.ContentType { + case "image/png": + response.ContentType = oas.AttachmentContentTypeImagePNG + case "image/jpeg": + response.ContentType = oas.AttachmentContentTypeImageJpeg + default: + response.ContentType = oas.AttachmentContentType(attachment.ContentType) + } + + if attachment.ErrorCode != nil { + response.ErrorCode = oas.NilString{Value: *attachment.ErrorCode} + } + + for _, variant := range attachment.Variants { + response.Variants = append(response.Variants, oas.Variant{ + Name: oas.VariantName(variant.Name), + ContentType: oas.VariantContentType(variant.ContentType), + SizeBytes: int(variant.SizeBytes), + Width: variant.Width, + Height: variant.Height, + SHA256: variant.SHA256, + }) + } + + return response +} + +func attachmentStatus(status domain.AttachmentStatus) oas.AttachmentStatus { + switch status { + case domain.AttachmentQueued: + return oas.AttachmentStatusQueued + case domain.AttachmentProcessing: + return oas.AttachmentStatusProcessing + case domain.AttachmentReady: + return oas.AttachmentStatusReady + case domain.AttachmentFailed: + return oas.AttachmentStatusFailed + default: + // Pending is internal and never reaches the transport; map it to the + // closest public state rather than inventing a new enum value. + return oas.AttachmentStatusQueued + } +} + +type closeOnEOF struct { + io.ReadCloser +} + +func (r closeOnEOF) Read(p []byte) (int, error) { + n, err := r.ReadCloser.Read(p) + if err != nil { + _ = r.Close() + } + + return n, err +} diff --git a/internal/transport/rest/bodylimit.go b/internal/transport/rest/bodylimit.go new file mode 100644 index 0000000..5c8f989 --- /dev/null +++ b/internal/transport/rest/bodylimit.go @@ -0,0 +1,57 @@ +package rest + +import ( + "log/slog" + "net/http" + "regexp" +) + +// attachmentUploadPath matches POST /api/v1/chats/{chat_id}/attachments. The +// UUID syntax is not validated here; this middleware only selects a body limit, +// and the generated transport rejects malformed identifiers later. +var attachmentUploadPath = regexp.MustCompile(`^/api/v1/chats/[^/]+/attachments$`) + +// bodyLimitMiddleware bounds the request body before it reaches the generated +// transport. JSON endpoints keep the small default limit; the attachment upload +// gets its own larger limit. Without this split the 10 MiB upload would be +// rejected before the handler, and raising the global limit would let any +// public JSON endpoint read a 10 MiB body. +func bodyLimitMiddleware( + defaultLimit, uploadLimit int64, + log *slog.Logger, + next http.Handler, +) http.Handler { + if defaultLimit <= 0 && uploadLimit <= 0 { + return next + } + + return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + limit := limitForRequest(r, defaultLimit, uploadLimit) + if limit <= 0 { + next.ServeHTTP(w, r) + + return + } + + if r.ContentLength > limit { + logRejected(r.Context(), log, r, http.StatusRequestEntityTooLarge, nil) + writeError(r.Context(), log, w, r, http.StatusRequestEntityTooLarge) + + return + } + + if r.Body != nil { + r.Body = http.MaxBytesReader(w, r.Body, limit) + } + + next.ServeHTTP(w, r) + }) +} + +func limitForRequest(r *http.Request, defaultLimit, uploadLimit int64) int64 { + if r.Method == http.MethodPost && attachmentUploadPath.MatchString(r.URL.Path) { + return uploadLimit + } + + return defaultLimit +} diff --git a/internal/transport/rest/bodylimit_test.go b/internal/transport/rest/bodylimit_test.go new file mode 100644 index 0000000..b7ee3ff --- /dev/null +++ b/internal/transport/rest/bodylimit_test.go @@ -0,0 +1,65 @@ +package rest + +import ( + "io" + "net/http" + "net/http/httptest" + "strings" + "testing" + + "github.com/stretchr/testify/require" +) + +func TestLimitForRequest(t *testing.T) { + const ( + defaultLimit = 1024 + uploadLimit = 10 << 20 + ) + + upload, err := http.NewRequestWithContext(t.Context(), http.MethodPost, "/api/v1/chats/11111111-1111-4111-8111-111111111111/attachments", nil) + require.NoError(t, err) + require.Equal(t, int64(uploadLimit), limitForRequest(upload, defaultLimit, uploadLimit)) + + messages, err := http.NewRequestWithContext(t.Context(), http.MethodPost, "/api/v1/chats/11111111-1111-4111-8111-111111111111/messages", nil) + require.NoError(t, err) + require.Equal(t, int64(defaultLimit), limitForRequest(messages, defaultLimit, uploadLimit)) + + presign, err := http.NewRequestWithContext(t.Context(), http.MethodPost, "/api/v1/chats/11111111-1111-4111-8111-111111111111/attachments/presign", nil) + require.NoError(t, err) + require.Equal(t, int64(defaultLimit), limitForRequest(presign, defaultLimit, uploadLimit)) +} + +func TestBodyLimitMiddlewareSelectsUploadLimit(t *testing.T) { + const ( + defaultLimit = 16 + uploadLimit = 64 + ) + + next := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + body, err := io.ReadAll(r.Body) + if err != nil { + http.Error(w, err.Error(), http.StatusBadRequest) + return + } + _, _ = w.Write(body) + }) + handler := bodyLimitMiddleware(defaultLimit, uploadLimit, nil, next) + + upload := httptest.NewRequestWithContext( + t.Context(), http.MethodPost, + "/api/v1/chats/11111111-1111-4111-8111-111111111111/attachments", + strings.NewReader(strings.Repeat("x", 32)), + ) + uploadRecorder := httptest.NewRecorder() + handler.ServeHTTP(uploadRecorder, upload) + require.Equal(t, http.StatusOK, uploadRecorder.Code) + + jsonRequest := httptest.NewRequestWithContext( + t.Context(), http.MethodPost, + "/api/v1/chats/11111111-1111-4111-8111-111111111111/messages", + strings.NewReader(strings.Repeat("x", 32)), + ) + jsonRecorder := httptest.NewRecorder() + handler.ServeHTTP(jsonRecorder, jsonRequest) + require.Equal(t, http.StatusRequestEntityTooLarge, jsonRecorder.Code) +} diff --git a/internal/transport/rest/errors.go b/internal/transport/rest/errors.go new file mode 100644 index 0000000..f4f2b71 --- /dev/null +++ b/internal/transport/rest/errors.go @@ -0,0 +1,158 @@ +package rest + +import ( + "context" + "encoding/json" + "errors" + "log/slog" + "net/http" + + "github.com/ogen-go/ogen/ogenerrors" + + "mtusi-messenger/internal/domain" + "mtusi-messenger/internal/transport/rest/internal/oas" +) + +var fallbackErrorBody = []byte(`{"error":{"code":"internal_error","message":"Internal error","request_id":""}}`) + +func newErrorHandler(log *slog.Logger) oas.ErrorHandler { + return func(ctx context.Context, w http.ResponseWriter, r *http.Request, err error) { + status := statusForError(err) + + if preMiddlewareError(err) { + logRejected(ctx, log, r, status, err) + } + + writeError(ctx, log, w, r, status) + } +} + +func statusForError(err error) int { + var securityErr *ogenerrors.SecurityError + + if errors.As(err, &securityErr) { + // A SecurityError only means "the caller did not satisfy a security + // requirement". It must not hide a dependency outage behind 401: a + // session lookup can fail because PostgreSQL is unavailable. + if errors.Is(securityErr.Err, ErrUnauthenticated) || + errors.Is(securityErr.Err, domain.ErrUnauthenticated) || + errors.Is(securityErr.Err, ogenerrors.ErrSecurityRequirementIsNotSatisfied) || + securityErr.Err != nil && securityErr.Err.Error() == "invalid basic auth" { + return http.StatusUnauthorized + } + + if status := statusForDomainError(securityErr.Err); status != http.StatusInternalServerError { + return status + } + + return http.StatusInternalServerError + } + + if status := ogenerrors.ErrorCode(err); status != http.StatusInternalServerError { + return status + } + + return statusForDomainError(err) +} + +func statusForDomainError(err error) int { + switch { + case errors.Is(err, ErrUnauthenticated), errors.Is(err, domain.ErrUnauthenticated): + return http.StatusUnauthorized + case errors.Is(err, domain.ErrNotFound): + return http.StatusNotFound + case errors.Is(err, domain.ErrUsernameTaken), + errors.Is(err, domain.ErrConflict), + errors.Is(err, domain.ErrIdempotency), + errors.Is(err, domain.ErrIncomplete): + return http.StatusConflict + case errors.Is(err, domain.ErrValidation), + errors.Is(err, domain.ErrUnknownMember), + errors.Is(err, domain.ErrInvalidCursor): + return http.StatusBadRequest + case errors.Is(err, domain.ErrRateLimited): + return http.StatusTooManyRequests + case errors.Is(err, domain.ErrTooLarge): + return http.StatusRequestEntityTooLarge + case errors.Is(err, domain.ErrUnsupportedMedia): + return http.StatusUnsupportedMediaType + case errors.Is(err, domain.ErrUnavailable): + return http.StatusServiceUnavailable + default: + return http.StatusInternalServerError + } +} + +func newNotFoundHandler(log *slog.Logger) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + logRejected(r.Context(), log, r, http.StatusNotFound, nil) + writeError(r.Context(), log, w, r, http.StatusNotFound) + } +} + +func newMethodNotAllowedHandler(log *slog.Logger) func(http.ResponseWriter, *http.Request, string) { + return func(w http.ResponseWriter, r *http.Request, allowed string) { + w.Header().Set("Allow", allowed) + logRejected(r.Context(), log, r, http.StatusMethodNotAllowed, nil) + writeError(r.Context(), log, w, r, http.StatusMethodNotAllowed) + } +} + +func writeError(ctx context.Context, log *slog.Logger, w http.ResponseWriter, r *http.Request, status int) { + requestID := requestIDFromContext(ctx) + if requestID == "" { + requestID = r.Header.Get(requestIDHeader) + } + + body := oas.Error{ + Error: oas.ErrorError{ + Code: codeForStatus(status), + Message: http.StatusText(status), + RequestID: requestID, + }, + } + + payload, marshalErr := json.Marshal(body) + if marshalErr != nil { + status = http.StatusInternalServerError + payload = fallbackErrorBody + } + + w.Header().Set("Content-Type", "application/json; charset=utf-8") + w.Header().Set(requestIDHeader, requestID) + if status == http.StatusUnauthorized { + challenge := `Bearer realm="messenger"` + if r.URL.Path == "/api/v1/auth/sessions" { + challenge = `Basic realm="messenger", charset="UTF-8"` + } + w.Header().Set("WWW-Authenticate", challenge) + } + w.WriteHeader(status) + + if _, err := w.Write(payload); err != nil && log != nil { + log.WarnContext(ctx, "response write failed", slog.String("error", err.Error())) + } +} + +func codeForStatus(status int) oas.ErrorErrorCode { + switch status { + case http.StatusBadRequest, http.StatusMethodNotAllowed: + return oas.ErrorErrorCodeInvalidRequest + case http.StatusUnauthorized: + return oas.ErrorErrorCodeUnauthorized + case http.StatusNotFound: + return oas.ErrorErrorCodeNotFound + case http.StatusConflict: + return oas.ErrorErrorCodeConflict + case http.StatusRequestEntityTooLarge: + return oas.ErrorErrorCodePayloadTooLarge + case http.StatusUnsupportedMediaType: + return oas.ErrorErrorCodeUnsupportedMediaType + case http.StatusTooManyRequests: + return oas.ErrorErrorCodeRateLimited + case http.StatusServiceUnavailable: + return oas.ErrorErrorCodeUnavailable + default: + return oas.ErrorErrorCodeInternalError + } +} diff --git a/internal/transport/rest/errors_test.go b/internal/transport/rest/errors_test.go new file mode 100644 index 0000000..be47fb4 --- /dev/null +++ b/internal/transport/rest/errors_test.go @@ -0,0 +1,42 @@ +package rest + +import ( + "errors" + "fmt" + "net/http" + "testing" + + "github.com/ogen-go/ogen/ogenerrors" + + "mtusi-messenger/internal/domain" +) + +func TestStatusForErrorDoesNotTurnDatabaseOutageInto401(t *testing.T) { + t.Parallel() + + err := &ogenerrors.SecurityError{ + Security: "BearerAuth", + Err: fmt.Errorf("%w: %w", domain.ErrUnavailable, errors.New("57P03")), + } + if got := statusForError(err); got != http.StatusServiceUnavailable { + t.Fatalf("status = %d, want 503", got) + } +} + +func TestStatusForErrorKeepsMissingCredentials401(t *testing.T) { + t.Parallel() + + err := &ogenerrors.SecurityError{ + Security: "BearerAuth", + Err: ogenerrors.ErrSecurityRequirementIsNotSatisfied, + } + if got := statusForError(err); got != http.StatusUnauthorized { + t.Fatalf("status = %d, want 401", got) + } + if got := statusForError(&ogenerrors.SecurityError{Err: domain.ErrUnauthenticated}); got != http.StatusUnauthorized { + t.Fatalf("domain unauthenticated status = %d, want 401", got) + } + if got := statusForError(errors.New("unexpected")); got != http.StatusInternalServerError { + t.Fatalf("unknown error status = %d, want 500", got) + } +} diff --git a/internal/transport/rest/extensions.go b/internal/transport/rest/extensions.go new file mode 100644 index 0000000..7441e97 --- /dev/null +++ b/internal/transport/rest/extensions.go @@ -0,0 +1,251 @@ +package rest + +import ( + "context" + "encoding/json" + "errors" + "fmt" + "io" + "log/slog" + "mime" + "net/http" + "strings" + "time" + + "github.com/google/uuid" + + "mtusi-messenger/internal/domain" +) + +// SessionResolver is implemented by session.Service. Only token resolution is +// needed here; the generated security handler keeps its own interface. +type SessionResolver interface { + Resolve(ctx context.Context, token string) (domain.User, error) +} + +// Extensions implements the optional presigned-upload endpoints. They are +// mounted outside the ogen server so the mandatory OpenAPI contract remains +// untouched. +type Extensions struct { + attachments AttachmentService + sessions SessionResolver + log *slog.Logger +} + +func NewExtensions( + attachments AttachmentService, + sessions SessionResolver, + log *slog.Logger, +) *Extensions { + return &Extensions{attachments: attachments, sessions: sessions, log: log} +} + +func (e *Extensions) Presign() http.Handler { + return e.route(http.MethodPost, "presign", e.presign) +} + +func (e *Extensions) Complete() http.Handler { + return e.route(http.MethodPost, "complete", e.complete) +} + +type extensionHandler func(http.ResponseWriter, *http.Request, uuid.UUID) error + +func (e *Extensions) route(method, operation string, handler extensionHandler) http.Handler { + return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + started := time.Now() + writer := &statusWriter{ResponseWriter: w} + + if r.Method != method { + writer.Header().Set("Allow", method) + writeError(r.Context(), e.log, writer, r, http.StatusMethodNotAllowed) + + return + } + + userID, err := e.authenticate(r) + if err != nil { + e.fail(writer, r, err) + + return + } + + err = handler(writer, r, userID) + if err != nil { + e.fail(writer, r, err) + + return + } + + if e.log != nil { + e.log.InfoContext(r.Context(), "extension request handled", + slog.String("request_id", requestIDFromContext(r.Context())), + slog.String("operation", operation), + slog.String("method", r.Method), + slog.Int("status", writer.statusCode()), + slog.Duration("duration", time.Since(started)), + ) + } + }) +} + +func (e *Extensions) authenticate(r *http.Request) (uuid.UUID, error) { + header := r.Header.Get("Authorization") + const prefix = "Bearer " + + if !strings.HasPrefix(header, prefix) { + return uuid.Nil, fmt.Errorf("%w: bearer token is required", domain.ErrUnauthenticated) + } + + token := strings.TrimSpace(strings.TrimPrefix(header, prefix)) + if token == "" { + return uuid.Nil, fmt.Errorf("%w: bearer token is empty", domain.ErrUnauthenticated) + } + + user, err := e.sessions.Resolve(r.Context(), token) + if err != nil { + // session.Resolve already distinguishes an invalid session (401) from a + // database outage (503); do not collapse both into 401 here. + return uuid.Nil, err + } + + return user.ID, nil +} + +func (e *Extensions) presign(w http.ResponseWriter, r *http.Request, userID uuid.UUID) error { + chatID, err := uuid.Parse(r.PathValue("chat_id")) + if err != nil { + return fmt.Errorf("%w: chat_id is not a UUID", domain.ErrValidation) + } + + var request struct { + Filename string `json:"filename"` + ContentType string `json:"content_type"` + SizeBytes int64 `json:"size_bytes"` + SHA256 string `json:"sha256"` + } + if err := decodeJSON(r, &request); err != nil { + return err + } + + result, err := e.attachments.Presign(r.Context(), domain.PresignRequest{ + ChatID: chatID, + OwnerID: userID, + Filename: request.Filename, + ContentType: request.ContentType, + SizeBytes: request.SizeBytes, + SHA256: request.SHA256, + }) + if err != nil { + return err + } + + return writeJSON(w, http.StatusCreated, struct { + AttachmentID string `json:"attachment_id"` + Method string `json:"method"` + UploadURL string `json:"upload_url"` + ExpiresAt time.Time `json:"expires_at"` + SHA256 string `json:"sha256"` + SizeBytes int64 `json:"size_bytes"` + }{ + AttachmentID: result.AttachmentID.String(), + Method: http.MethodPut, + UploadURL: result.UploadURL, + ExpiresAt: result.ExpiresAt.UTC(), + SHA256: result.SHA256, + SizeBytes: result.SizeBytes, + }) +} + +func (e *Extensions) complete(w http.ResponseWriter, r *http.Request, userID uuid.UUID) error { + id, err := uuid.Parse(r.PathValue("attachment_id")) + if err != nil { + return fmt.Errorf("%w: attachment_id is not a UUID", domain.ErrValidation) + } + + var request struct { + SHA256 string `json:"sha256"` + } + if err := decodeJSON(r, &request); err != nil { + return err + } + + attachment, err := e.attachments.Complete(r.Context(), userID, id, request.SHA256) + if err != nil { + return err + } + + return writeJSON(w, http.StatusAccepted, attachmentResponse(attachment)) +} + +func decodeJSON(r *http.Request, target any) error { + mediaType, _, err := mime.ParseMediaType(r.Header.Get("Content-Type")) + if err != nil || mediaType != "application/json" { + return fmt.Errorf("%w: Content-Type must be application/json", domain.ErrUnsupportedMedia) + } + + decoder := json.NewDecoder(r.Body) + decoder.DisallowUnknownFields() + + if err := decoder.Decode(target); err != nil { + return fmt.Errorf("%w: decode JSON: %w", domain.ErrValidation, err) + } + + if err := decoder.Decode(&struct{}{}); !errors.Is(err, io.EOF) { + return fmt.Errorf("%w: trailing JSON data", domain.ErrValidation) + } + + return nil +} + +func (e *Extensions) fail(w http.ResponseWriter, r *http.Request, err error) { + status := statusForDomainError(err) + if status == http.StatusInternalServerError && e.log != nil { + e.log.ErrorContext(r.Context(), "extension request failed", + slog.String("request_id", requestIDFromContext(r.Context())), + slog.String("method", r.Method), + slog.Any("error", err), + ) + } + + writeError(r.Context(), e.log, w, r, status) +} + +func writeJSON(w http.ResponseWriter, status int, payload any) error { + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(status) + + if err := json.NewEncoder(w).Encode(payload); err != nil { + return fmt.Errorf("write JSON response: %w", err) + } + + return nil +} + +type statusWriter struct { + http.ResponseWriter + status int +} + +func (w *statusWriter) WriteHeader(status int) { + if w.status == 0 { + w.status = status + } + + w.ResponseWriter.WriteHeader(status) +} + +func (w *statusWriter) Write(body []byte) (int, error) { + if w.status == 0 { + w.status = http.StatusOK + } + + return w.ResponseWriter.Write(body) +} + +func (w *statusWriter) statusCode() int { + if w.status == 0 { + return http.StatusOK + } + + return w.status +} diff --git a/internal/transport/rest/extensions_test.go b/internal/transport/rest/extensions_test.go new file mode 100644 index 0000000..1e5e156 --- /dev/null +++ b/internal/transport/rest/extensions_test.go @@ -0,0 +1,64 @@ +package rest + +import ( + "context" + "net/http" + "net/http/httptest" + "testing" + + "github.com/stretchr/testify/require" + + "mtusi-messenger/internal/domain" +) + +type resolverFunc func(ctx context.Context, token string) (domain.User, error) + +func (f resolverFunc) Resolve(ctx context.Context, token string) (domain.User, error) { + return f(ctx, token) +} + +func TestExtensionPreservesDependencyErrors(t *testing.T) { + extensions := NewExtensions(nil, resolverFunc(func(context.Context, string) (domain.User, error) { + return domain.User{}, domain.ErrUnavailable + }), nil) + + request := httptest.NewRequestWithContext( + t.Context(), http.MethodPost, "/api/v1/chats/11111111-1111-4111-8111-111111111111/attachments/presign", nil, + ) + request.Header.Set("Authorization", "Bearer token") + recorder := httptest.NewRecorder() + + extensions.Presign().ServeHTTP(recorder, request) + + require.Equal(t, http.StatusServiceUnavailable, recorder.Code) +} + +func TestExtensionInvalidSessionIsUnauthorized(t *testing.T) { + extensions := NewExtensions(nil, resolverFunc(func(context.Context, string) (domain.User, error) { + return domain.User{}, domain.ErrUnauthenticated + }), nil) + + request := httptest.NewRequestWithContext( + t.Context(), http.MethodPost, "/api/v1/chats/11111111-1111-4111-8111-111111111111/attachments/presign", nil, + ) + request.Header.Set("Authorization", "Bearer token") + recorder := httptest.NewRecorder() + + extensions.Presign().ServeHTTP(recorder, request) + + require.Equal(t, http.StatusUnauthorized, recorder.Code) +} + +func TestExtensionWrongMethodIsNotAllowed(t *testing.T) { + extensions := NewExtensions(nil, nil, nil) + + request := httptest.NewRequestWithContext( + t.Context(), http.MethodGet, "/api/v1/chats/11111111-1111-4111-8111-111111111111/attachments/presign", nil, + ) + recorder := httptest.NewRecorder() + + extensions.Presign().ServeHTTP(recorder, request) + + require.Equal(t, http.StatusMethodNotAllowed, recorder.Code) + require.Equal(t, http.MethodPost, recorder.Header().Get("Allow")) +} diff --git a/internal/transport/rest/handler.go b/internal/transport/rest/handler.go new file mode 100644 index 0000000..9da56f2 --- /dev/null +++ b/internal/transport/rest/handler.go @@ -0,0 +1,435 @@ +package rest + +import ( + "bytes" + "context" + "crypto/sha256" + "encoding/base64" + "encoding/json" + "fmt" + "io" + "net/http" + "time" + + "github.com/google/uuid" + + "mtusi-messenger/internal/domain" + attachmentService "mtusi-messenger/internal/service/attachment" + "mtusi-messenger/internal/transport/rest/internal/oas" +) + +type UserService interface { + Register(ctx context.Context, draft domain.UserDraft) (domain.User, error) + GetByID(ctx context.Context, id uuid.UUID) (domain.User, error) +} + +type ChatService interface { + Create(ctx context.Context, draft domain.ChatDraft) (domain.Chat, error) + Get(ctx context.Context, callerID, chatID uuid.UUID) (domain.Chat, error) + List( + ctx context.Context, + callerID uuid.UUID, + after *domain.Cursor, + limit int, + ) (domain.Page[domain.Chat], error) +} + +type MessageService interface { + Send(ctx context.Context, draft domain.MessageDraft) (domain.Message, error) + History( + ctx context.Context, + callerID, chatID uuid.UUID, + after *domain.Cursor, + limit int, + ) (domain.Page[domain.Message], error) +} + +type HealthChecker interface { + Ping(ctx context.Context) error +} + +type SessionService interface { + Create(ctx context.Context, user domain.User) (domain.Session, error) + Revoke(ctx context.Context, userID uuid.UUID, token string) error +} + +type AttachmentService interface { + Upload(ctx context.Context, input attachmentService.UploadInput) (domain.Attachment, error) + Get(ctx context.Context, callerID, id uuid.UUID) (domain.Attachment, error) + OpenVariant( + ctx context.Context, + callerID, id uuid.UUID, + name domain.VariantName, + ) (domain.Attachment, domain.Variant, io.ReadCloser, error) + Presign(ctx context.Context, request domain.PresignRequest) (domain.PresignResult, error) + Complete(ctx context.Context, ownerID, id uuid.UUID, sha256 string) (domain.Attachment, error) +} + +type Handler struct { + oas.UnimplementedHandler + + users UserService + chats ChatService + messages MessageService + attachments AttachmentService + health HealthChecker + sessions SessionService +} + +var noCursor *domain.Cursor + +func NewHandler( + users UserService, + chats ChatService, + messages MessageService, + attachments AttachmentService, + health HealthChecker, + sessions SessionService, +) *Handler { + return &Handler{ + users: users, + chats: chats, + messages: messages, + attachments: attachments, + health: health, + sessions: sessions, + } +} + +func (h *Handler) CreateSession(ctx context.Context) (oas.CreateSessionRes, error) { + user, ok := ctx.Value(credentialsKey{}).(domain.User) + if !ok { + return nil, domain.ErrUnauthenticated + } + + created, err := h.sessions.Create(ctx, user) + if err != nil { + return nil, err + } + + return &oas.SessionHeaders{ + XRequestID: oas.NewOptString(requestIDFromContext(ctx)), + Response: oas.Session{ + Token: created.Token, TokenType: "Bearer", ExpiresAt: created.ExpiresAt, User: userResponse(created.User), + }, + }, nil +} + +func (h *Handler) RevokeSession(ctx context.Context) (oas.RevokeSessionRes, error) { + token, ok := ctx.Value(tokenKey{}).(string) + if !ok { + return nil, domain.ErrUnauthenticated + } + if err := h.sessions.Revoke(ctx, caller(ctx), token); err != nil { + return nil, err + } + return &oas.RevokeSessionNoContent{XRequestID: oas.NewOptString(requestIDFromContext(ctx))}, nil +} + +func (h *Handler) Liveness(ctx context.Context) (oas.LivenessRes, error) { + return &oas.HealthHeaders{ + XRequestID: oas.NewOptString(requestIDFromContext(ctx)), + Response: oas.Health{Status: oas.HealthStatusOk}, + }, nil +} + +func (h *Handler) Readiness(ctx context.Context) (oas.ReadinessRes, error) { + if h.health == nil || h.health.Ping(ctx) == nil { + return &oas.HealthHeaders{ + XRequestID: oas.NewOptString(requestIDFromContext(ctx)), + Response: oas.Health{Status: oas.HealthStatusOk}, + }, nil + } + + requestID := requestIDFromContext(ctx) + + return &oas.ReadinessServiceUnavailable{ + XRequestID: oas.NewOptString(requestID), + Response: oas.Error{Error: oas.ErrorError{ + Code: oas.ErrorErrorCodeUnavailable, + Message: http.StatusText(http.StatusServiceUnavailable), + RequestID: requestID, + }}, + }, nil +} + +func (h *Handler) RegisterUser(ctx context.Context, req *oas.CreateUser) (oas.RegisterUserRes, error) { + user, err := h.users.Register(ctx, domain.UserDraft{ + Username: req.Username, + DisplayName: req.DisplayName, + Password: req.Password, + }) + if err != nil { + return nil, err + } + + return &oas.UserHeaders{ + XRequestID: oas.NewOptString(requestIDFromContext(ctx)), + Response: userResponse(user), + }, nil +} + +func (h *Handler) CurrentUser(ctx context.Context) (oas.CurrentUserRes, error) { + callerID := caller(ctx) + + user, err := h.users.GetByID(ctx, callerID) + if err != nil { + return nil, err + } + + return &oas.UserHeaders{ + XRequestID: oas.NewOptString(requestIDFromContext(ctx)), + Response: userResponse(user), + }, nil +} + +func (h *Handler) CreateChat(ctx context.Context, req *oas.CreateChat) (oas.CreateChatRes, error) { + callerID := caller(ctx) + + chat, err := h.chats.Create(ctx, domain.ChatDraft{ + Title: req.Title, + MemberIDs: req.MemberIds, + CallerID: callerID, + }) + if err != nil { + return nil, err + } + + return &oas.ChatHeaders{ + XRequestID: oas.NewOptString(requestIDFromContext(ctx)), + Response: chatResponse(chat), + }, nil +} + +func (h *Handler) GetChat(ctx context.Context, params oas.GetChatParams) (oas.GetChatRes, error) { + callerID := caller(ctx) + + chat, err := h.chats.Get(ctx, callerID, params.ChatID) + if err != nil { + return nil, err + } + + return &oas.ChatHeaders{ + XRequestID: oas.NewOptString(requestIDFromContext(ctx)), + Response: chatResponse(chat), + }, nil +} + +func (h *Handler) ListChats(ctx context.Context, params oas.ListChatsParams) (oas.ListChatsRes, error) { + callerID := caller(ctx) + + after, err := parseCursor(params.Cursor) + if err != nil { + return nil, err + } + + page, err := h.chats.List(ctx, callerID, after, limitOrDefault(params.Limit)) + if err != nil { + return nil, err + } + + items := make([]oas.Chat, 0, len(page.Items)) + for _, chat := range page.Items { + items = append(items, chatResponse(chat)) + } + + return &oas.ChatPageHeaders{ + XRequestID: oas.NewOptString(requestIDFromContext(ctx)), + Response: oas.ChatPage{ + Items: items, + NextCursor: encodeCursor(page.Next), + }, + }, nil +} + +func (h *Handler) CreateMessage( + ctx context.Context, + req *oas.CreateMessage, + params oas.CreateMessageParams, +) (oas.CreateMessageRes, error) { + callerID := caller(ctx) + + fingerprint, err := messageFingerprint(req) + if err != nil { + return nil, err + } + + message, err := h.messages.Send(ctx, domain.MessageDraft{ + ChatID: params.ChatID, + SenderID: callerID, + Text: req.Text, + AttachmentIDs: req.AttachmentIds, + Idempotency: domain.MessageIdempotency{ + Key: params.IdempotencyKey, + RequestHash: fingerprint, + }, + }) + if err != nil { + return nil, err + } + + return &oas.MessageHeaders{ + XRequestID: oas.NewOptString(requestIDFromContext(ctx)), + Response: messageResponse(message), + }, nil +} + +// messageFingerprint canonicalises the create-message payload so that JSON key +// order cannot change the fingerprint, while a different payload (including a +// different attachment order) with the same Idempotency-Key can. Absent +// attachment_ids and [] are equivalent, as required by the contract. +func messageFingerprint(req *oas.CreateMessage) ([sha256.Size]byte, error) { + ids := req.AttachmentIds + if ids == nil { + ids = []uuid.UUID{} + } + + payload, err := json.Marshal(struct { + Text string `json:"text"` + AttachmentIDs []uuid.UUID `json:"attachment_ids"` + }{Text: req.Text, AttachmentIDs: ids}) + if err != nil { + return [sha256.Size]byte{}, fmt.Errorf("encode message payload: %w", err) + } + + return sha256.Sum256(payload), nil +} + +func (h *Handler) ListMessages(ctx context.Context, params oas.ListMessagesParams) (oas.ListMessagesRes, error) { + callerID := caller(ctx) + + after, err := parseCursor(params.Cursor) + if err != nil { + return nil, err + } + + page, err := h.messages.History(ctx, callerID, params.ChatID, after, limitOrDefault(params.Limit)) + if err != nil { + return nil, err + } + + items := make([]oas.Message, 0, len(page.Items)) + for _, message := range page.Items { + items = append(items, messageResponse(message)) + } + + return &oas.MessagePageHeaders{ + XRequestID: oas.NewOptString(requestIDFromContext(ctx)), + Response: oas.MessagePage{ + Items: items, + NextCursor: encodeCursor(page.Next), + }, + }, nil +} + +func parseCursor(raw oas.OptString) (*domain.Cursor, error) { + encoded, ok := raw.Get() + if !ok { + return noCursor, nil + } + + cursor, err := decodeCursor(encoded) + if err != nil { + return nil, err + } + + return &cursor, nil +} + +func encodeCursor(next *domain.Cursor) oas.NilString { + var out oas.NilString + + if next == nil { + out.SetToNull() + + return out + } + + out.SetTo(encodeCursorValue(*next)) + + return out +} + +type cursorWire struct { + Scope uuid.UUID `json:"scope"` + CreatedAt time.Time `json:"created_at"` + ID uuid.UUID `json:"id"` +} + +func encodeCursorValue(cursor domain.Cursor) string { + payload, err := json.Marshal(cursorWire{ + Scope: cursor.Scope, + CreatedAt: cursor.CreatedAt.UTC(), + ID: cursor.ID, + }) + if err != nil { + return "" + } + + return base64.RawURLEncoding.EncodeToString(payload) +} + +func decodeCursor(encoded string) (domain.Cursor, error) { + payload, err := base64.RawURLEncoding.DecodeString(encoded) + if err != nil { + return domain.Cursor{}, fmt.Errorf("decode cursor: %w", domain.ErrInvalidCursor) + } + + decoder := json.NewDecoder(bytes.NewReader(payload)) + decoder.DisallowUnknownFields() + + var wire cursorWire + if err := decoder.Decode(&wire); err != nil { + return domain.Cursor{}, fmt.Errorf("parse cursor: %w", domain.ErrInvalidCursor) + } + + if wire.ID == uuid.Nil { + return domain.Cursor{}, fmt.Errorf("cursor id is empty: %w", domain.ErrInvalidCursor) + } + + return domain.Cursor{ + Scope: wire.Scope, + CreatedAt: wire.CreatedAt.UTC(), + ID: wire.ID, + }, nil +} + +func limitOrDefault(limit oas.OptInt) int { + if value, ok := limit.Get(); ok { + return value + } + + return domain.DefaultPageLimit +} + +func userResponse(user domain.User) oas.User { + return oas.User{ + ID: user.ID, + Username: user.Username, + DisplayName: user.DisplayName, + CreatedAt: user.CreatedAt, + } +} + +func chatResponse(chat domain.Chat) oas.Chat { + return oas.Chat{ + ID: chat.ID, + Title: chat.Title, + MemberIds: chat.MemberIDs, + CreatedAt: chat.CreatedAt, + } +} + +func messageResponse(message domain.Message) oas.Message { + ids := make([]uuid.UUID, 0, len(message.AttachmentIDs)) + ids = append(ids, message.AttachmentIDs...) + + return oas.Message{ + ID: message.ID, + ChatID: message.ChatID, + SenderID: message.SenderID, + Text: message.Text, + AttachmentIds: ids, + CreatedAt: message.CreatedAt, + } +} diff --git a/internal/transport/rest/handler_test.go b/internal/transport/rest/handler_test.go new file mode 100644 index 0000000..09279a5 --- /dev/null +++ b/internal/transport/rest/handler_test.go @@ -0,0 +1,39 @@ +package rest + +import ( + "testing" + + "github.com/google/uuid" + "github.com/stretchr/testify/require" + + "mtusi-messenger/internal/transport/rest/internal/oas" +) + +func TestMessageFingerprintPreservesAttachmentOrder(t *testing.T) { + first, second := uuid.New(), uuid.New() + + forward, err := messageFingerprint(&oas.CreateMessage{ + Text: "x", + AttachmentIds: []uuid.UUID{first, second}, + }) + require.NoError(t, err) + + reverse, err := messageFingerprint(&oas.CreateMessage{ + Text: "x", + AttachmentIds: []uuid.UUID{second, first}, + }) + require.NoError(t, err) + + require.NotEqual(t, forward, reverse, + "reordered attachment_ids are a different payload and must not replay") +} + +func TestMessageFingerprintTreatsAbsentAndEmptyAsEqual(t *testing.T) { + absent, err := messageFingerprint(&oas.CreateMessage{Text: "x"}) + require.NoError(t, err) + + empty, err := messageFingerprint(&oas.CreateMessage{Text: "x", AttachmentIds: []uuid.UUID{}}) + require.NoError(t, err) + + require.Equal(t, absent, empty) +} diff --git a/internal/transport/rest/instance.go b/internal/transport/rest/instance.go new file mode 100644 index 0000000..5c10510 --- /dev/null +++ b/internal/transport/rest/instance.go @@ -0,0 +1,67 @@ +package rest + +import ( + "net/http" + "os" +) + +const ( + instanceIDEnv = "INSTANCE_ID" + instanceIDHeader = "X-Instance-Id" +) + +// InstanceID is the alias of this API process reported in the X-Instance-Id +// response header (contract 1.3.0). INSTANCE_ID wins when set; otherwise the +// hostname is used, which inside a container is the short container id the +// stand maps back to the replica that served the request. +func InstanceID() string { + if id := os.Getenv(instanceIDEnv); id != "" { + return id + } + + if host, err := os.Hostname(); err == nil && host != "" { + return host + } + + return "unknown" +} + +// instanceIDWriter injects the header on the first write of the response, so +// every API-generated response carries it — including errors produced by the +// router, the security handler and the error handler rather than by a handler. +// A value already set by the transport is never overwritten. +type instanceIDWriter struct { + http.ResponseWriter + + id string + sealed bool +} + +func (w *instanceIDWriter) inject() { + if w.sealed { + return + } + + w.sealed = true + + if w.Header().Get(instanceIDHeader) == "" { + w.Header().Set(instanceIDHeader, w.id) + } +} + +func (w *instanceIDWriter) WriteHeader(status int) { + w.inject() + w.ResponseWriter.WriteHeader(status) +} + +func (w *instanceIDWriter) Write(body []byte) (int, error) { + w.inject() + + return w.ResponseWriter.Write(body) +} + +func instanceIDMiddleware(id string, next http.Handler) http.Handler { + return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + next.ServeHTTP(&instanceIDWriter{ResponseWriter: w, id: id}, r) + }) +} diff --git a/internal/transport/rest/instance_test.go b/internal/transport/rest/instance_test.go new file mode 100644 index 0000000..342f7ae --- /dev/null +++ b/internal/transport/rest/instance_test.go @@ -0,0 +1,77 @@ +package rest + +import ( + "net/http" + "net/http/httptest" + "os" + "testing" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" +) + +func TestInstanceIDPrefersEnvironment(t *testing.T) { + t.Setenv(instanceIDEnv, "api-7") + + assert.Equal(t, "api-7", InstanceID()) +} + +func TestInstanceIDFallsBackToHostname(t *testing.T) { + t.Setenv(instanceIDEnv, "") + + host, err := os.Hostname() + require.NoError(t, err) + + assert.Equal(t, host, InstanceID()) +} + +func TestInstanceIDMiddleware(t *testing.T) { + tests := []struct { + name string + handler http.HandlerFunc + wantID string + wantCode int + }{ + { + name: "handler response", + handler: func(w http.ResponseWriter, _ *http.Request) { w.WriteHeader(http.StatusCreated) }, + wantID: "api-1", + wantCode: http.StatusCreated, + }, + { + name: "response without explicit status", + handler: func(w http.ResponseWriter, _ *http.Request) { _, _ = w.Write([]byte("ok")) }, + wantID: "api-1", + wantCode: http.StatusOK, + }, + { + name: "error produced outside a handler", + handler: func(w http.ResponseWriter, _ *http.Request) { w.WriteHeader(http.StatusMethodNotAllowed) }, + wantID: "api-1", + wantCode: http.StatusMethodNotAllowed, + }, + { + name: "header set by the transport is not overwritten", + handler: func(w http.ResponseWriter, _ *http.Request) { + w.Header().Set(instanceIDHeader, "explicit") + w.WriteHeader(http.StatusOK) + }, + wantID: "explicit", + wantCode: http.StatusOK, + }, + } + + for _, test := range tests { + t.Run(test.name, func(t *testing.T) { + recorder := httptest.NewRecorder() + + instanceIDMiddleware("api-1", test.handler).ServeHTTP( + recorder, + httptest.NewRequestWithContext(t.Context(), http.MethodGet, "/api/v1/users/me", nil), + ) + + assert.Equal(t, test.wantID, recorder.Header().Get(instanceIDHeader)) + assert.Equal(t, test.wantCode, recorder.Code) + }) + } +} diff --git a/internal/transport/rest/internal/oas/oas_cfg_gen.go b/internal/transport/rest/internal/oas/oas_cfg_gen.go new file mode 100644 index 0000000..1f7348c --- /dev/null +++ b/internal/transport/rest/internal/oas/oas_cfg_gen.go @@ -0,0 +1,175 @@ +// Code generated by ogen, DO NOT EDIT. + +package oas + +import ( + "net/http" + "strings" + + "github.com/ogen-go/ogen/middleware" + "github.com/ogen-go/ogen/ogenerrors" + "github.com/ogen-go/ogen/ogenregex" +) + +var regexMap = map[string]ogenregex.Regexp{ + "^[A-Za-z0-9._:-]+$": ogenregex.MustCompile("^[A-Za-z0-9._:-]+$"), + "^[a-f0-9]{64}$": ogenregex.MustCompile("^[a-f0-9]{64}$"), + "^[a-z0-9_]{3,32}$": ogenregex.MustCompile("^[a-z0-9_]{3,32}$"), +} + +type ( + optionFunc[C any] func(*C) +) + +// ErrorHandler is error handler. +type ErrorHandler = ogenerrors.ErrorHandler + +type serverConfig struct { + NotFound http.HandlerFunc + MethodNotAllowed func(w http.ResponseWriter, r *http.Request, allowed string) + ErrorHandler ErrorHandler + Prefix string + Middleware Middleware + MaxMultipartMemory int64 +} + +// ServerOption is server config option. +type ServerOption interface { + applyServer(*serverConfig) +} + +var _ ServerOption = (optionFunc[serverConfig])(nil) + +func (o optionFunc[C]) applyServer(c *C) { + o(c) +} + +func newServerConfig(opts ...ServerOption) serverConfig { + cfg := serverConfig{ + NotFound: http.NotFound, + MethodNotAllowed: nil, + ErrorHandler: ogenerrors.DefaultErrorHandler, + Middleware: nil, + MaxMultipartMemory: 32 << 20, // 32 MB + } + for _, opt := range opts { + opt.applyServer(&cfg) + } + return cfg +} + +type baseServer struct { + cfg serverConfig +} + +func (s baseServer) notFound(w http.ResponseWriter, r *http.Request) { + s.cfg.NotFound(w, r) +} + +type notAllowedParams struct { + allowedMethods string + allowedHeaders map[string]string + acceptPost string + acceptPatch string +} + +func (s baseServer) notAllowed(w http.ResponseWriter, r *http.Request, params notAllowedParams) { + h := w.Header() + isOptions := r.Method == "OPTIONS" + if isOptions { + h.Set("Access-Control-Allow-Methods", params.allowedMethods) + if params.allowedHeaders != nil { + m := r.Header.Get("Access-Control-Request-Method") + if m != "" { + allowedHeaders, ok := params.allowedHeaders[strings.ToUpper(m)] + if ok { + h.Set("Access-Control-Allow-Headers", allowedHeaders) + } + } + } + if params.acceptPost != "" { + h.Set("Accept-Post", params.acceptPost) + } + if params.acceptPatch != "" { + h.Set("Accept-Patch", params.acceptPatch) + } + } + if s.cfg.MethodNotAllowed != nil { + s.cfg.MethodNotAllowed(w, r, params.allowedMethods) + return + } + status := http.StatusNoContent + if !isOptions { + h.Set("Allow", params.allowedMethods) + status = http.StatusMethodNotAllowed + } + w.WriteHeader(status) +} + +func (cfg serverConfig) baseServer() (s baseServer, err error) { + s = baseServer{cfg: cfg} + return s, nil +} + +// Option is config option. +type Option interface { + ServerOption +} + +// WithNotFound specifies Not Found handler to use. +func WithNotFound(notFound http.HandlerFunc) ServerOption { + return optionFunc[serverConfig](func(cfg *serverConfig) { + if notFound != nil { + cfg.NotFound = notFound + } + }) +} + +// WithMethodNotAllowed specifies Method Not Allowed handler to use. +func WithMethodNotAllowed(methodNotAllowed func(w http.ResponseWriter, r *http.Request, allowed string)) ServerOption { + return optionFunc[serverConfig](func(cfg *serverConfig) { + if methodNotAllowed != nil { + cfg.MethodNotAllowed = methodNotAllowed + } + }) +} + +// WithErrorHandler specifies error handler to use. +func WithErrorHandler(h ErrorHandler) ServerOption { + return optionFunc[serverConfig](func(cfg *serverConfig) { + if h != nil { + cfg.ErrorHandler = h + } + }) +} + +// WithPathPrefix specifies server path prefix. +func WithPathPrefix(prefix string) ServerOption { + return optionFunc[serverConfig](func(cfg *serverConfig) { + cfg.Prefix = prefix + }) +} + +// WithMiddleware specifies middlewares to use. +func WithMiddleware(m ...Middleware) ServerOption { + return optionFunc[serverConfig](func(cfg *serverConfig) { + switch len(m) { + case 0: + cfg.Middleware = nil + case 1: + cfg.Middleware = m[0] + default: + cfg.Middleware = middleware.ChainMiddlewares(m...) + } + }) +} + +// WithMaxMultipartMemory specifies limit of memory for storing file parts. +// File parts which can't be stored in memory will be stored on disk in temporary files. +func WithMaxMultipartMemory(max int64) ServerOption { + return optionFunc[serverConfig](func(cfg *serverConfig) { + if max > 0 { + cfg.MaxMultipartMemory = max + } + }) +} diff --git a/internal/transport/rest/internal/oas/oas_defaults_gen.go b/internal/transport/rest/internal/oas/oas_defaults_gen.go new file mode 100644 index 0000000..8fc31d1 --- /dev/null +++ b/internal/transport/rest/internal/oas/oas_defaults_gen.go @@ -0,0 +1,15 @@ +// Code generated by ogen, DO NOT EDIT. + +package oas + +import ( + "github.com/google/uuid" +) + +// setDefaults set default value of fields. +func (s *CreateMessage) setDefaults() { + { + var defaultVal0 []uuid.UUID + s.AttachmentIds = defaultVal0 + } +} diff --git a/internal/transport/rest/internal/oas/oas_handlers_gen.go b/internal/transport/rest/internal/oas/oas_handlers_gen.go new file mode 100644 index 0000000..ba46ed0 --- /dev/null +++ b/internal/transport/rest/internal/oas/oas_handlers_gen.go @@ -0,0 +1,1660 @@ +// Code generated by ogen, DO NOT EDIT. + +package oas + +import ( + "context" + "net/http" + + "github.com/go-faster/errors" + ht "github.com/ogen-go/ogen/http" + "github.com/ogen-go/ogen/middleware" + "github.com/ogen-go/ogen/ogenerrors" +) + +type codeRecorder struct { + http.ResponseWriter + status int +} + +func (c *codeRecorder) WriteHeader(status int) { + c.status = status + c.ResponseWriter.WriteHeader(status) +} + +func (c *codeRecorder) Unwrap() http.ResponseWriter { + return c.ResponseWriter +} + +func recordError(string, error) {} + +// handleCreateChatRequest handles createChat operation. +// +// Создать чат; вызывающий должен входить в member_ids. +// +// POST /api/v1/chats +func (s *Server) handleCreateChatRequest(args [0]string, argsEscaped bool, w http.ResponseWriter, r *http.Request) { + statusWriter := &codeRecorder{ResponseWriter: w} + w = statusWriter + ctx := r.Context() + + var ( + err error + opErrContext = ogenerrors.OperationContext{ + Name: CreateChatOperation, + ID: "createChat", + } + ) + { + type bitset = [1]uint8 + var satisfied bitset + { + sctx, ok, err := s.securityBearerAuth(ctx, CreateChatOperation, r) + if err != nil { + err = &ogenerrors.SecurityError{ + OperationContext: opErrContext, + Security: "BearerAuth", + Err: err, + } + defer recordError("Security:BearerAuth", err) + s.cfg.ErrorHandler(ctx, w, r, err) + return + } + if ok { + satisfied[0] |= 1 << 0 + ctx = sctx + } + } + + if ok := func() bool { + nextRequirement: + for _, requirement := range []bitset{ + {0b00000001}, + } { + for i, mask := range requirement { + if satisfied[i]&mask != mask { + continue nextRequirement + } + } + return true + } + return false + }(); !ok { + err = &ogenerrors.SecurityError{ + OperationContext: opErrContext, + Err: ogenerrors.ErrSecurityRequirementIsNotSatisfied, + } + defer recordError("Security", err) + s.cfg.ErrorHandler(ctx, w, r, err) + return + } + } + + var rawBody []byte + request, rawBody, close, err := s.decodeCreateChatRequest(r) + if err != nil { + err = &ogenerrors.DecodeRequestError{ + OperationContext: opErrContext, + Err: err, + } + defer recordError("DecodeRequest", err) + s.cfg.ErrorHandler(ctx, w, r, err) + return + } + defer func() { + if err := close(); err != nil { + recordError("CloseRequest", err) + } + }() + + var response CreateChatRes + if m := s.cfg.Middleware; m != nil { + mreq := middleware.Request{ + Context: ctx, + OperationName: CreateChatOperation, + OperationSummary: "Создать чат; вызывающий должен входить в member_ids", + OperationID: "createChat", + Body: request, + RawBody: rawBody, + Params: middleware.Parameters{}, + Raw: r, + } + + type ( + Request = *CreateChat + Params = struct{} + Response = CreateChatRes + ) + response, err = middleware.HookMiddleware[ + Request, + Params, + Response, + ]( + m, + mreq, + nil, + func(ctx context.Context, request Request, params Params) (response Response, err error) { + response, err = s.h.CreateChat(ctx, request) + return response, err + }, + ) + } else { + response, err = s.h.CreateChat(ctx, request) + } + if err != nil { + defer recordError("Internal", err) + s.cfg.ErrorHandler(ctx, w, r, err) + return + } + + if err := encodeCreateChatResponse(response, w); err != nil { + defer recordError("EncodeResponse", err) + if !errors.Is(err, ht.ErrInternalServerErrorResponse) { + s.cfg.ErrorHandler(ctx, w, r, err) + } + return + } +} + +// handleCreateMessageRequest handles createMessage operation. +// +// Отправить сообщение. +// +// POST /api/v1/chats/{chat_id}/messages +func (s *Server) handleCreateMessageRequest(args [1]string, argsEscaped bool, w http.ResponseWriter, r *http.Request) { + statusWriter := &codeRecorder{ResponseWriter: w} + w = statusWriter + ctx := r.Context() + + var ( + err error + opErrContext = ogenerrors.OperationContext{ + Name: CreateMessageOperation, + ID: "createMessage", + } + ) + { + type bitset = [1]uint8 + var satisfied bitset + { + sctx, ok, err := s.securityBearerAuth(ctx, CreateMessageOperation, r) + if err != nil { + err = &ogenerrors.SecurityError{ + OperationContext: opErrContext, + Security: "BearerAuth", + Err: err, + } + defer recordError("Security:BearerAuth", err) + s.cfg.ErrorHandler(ctx, w, r, err) + return + } + if ok { + satisfied[0] |= 1 << 0 + ctx = sctx + } + } + + if ok := func() bool { + nextRequirement: + for _, requirement := range []bitset{ + {0b00000001}, + } { + for i, mask := range requirement { + if satisfied[i]&mask != mask { + continue nextRequirement + } + } + return true + } + return false + }(); !ok { + err = &ogenerrors.SecurityError{ + OperationContext: opErrContext, + Err: ogenerrors.ErrSecurityRequirementIsNotSatisfied, + } + defer recordError("Security", err) + s.cfg.ErrorHandler(ctx, w, r, err) + return + } + } + params, err := decodeCreateMessageParams(args, argsEscaped, r) + if err != nil { + err = &ogenerrors.DecodeParamsError{ + OperationContext: opErrContext, + Err: err, + } + defer recordError("DecodeParams", err) + s.cfg.ErrorHandler(ctx, w, r, err) + return + } + + var rawBody []byte + request, rawBody, close, err := s.decodeCreateMessageRequest(r) + if err != nil { + err = &ogenerrors.DecodeRequestError{ + OperationContext: opErrContext, + Err: err, + } + defer recordError("DecodeRequest", err) + s.cfg.ErrorHandler(ctx, w, r, err) + return + } + defer func() { + if err := close(); err != nil { + recordError("CloseRequest", err) + } + }() + + var response CreateMessageRes + if m := s.cfg.Middleware; m != nil { + mreq := middleware.Request{ + Context: ctx, + OperationName: CreateMessageOperation, + OperationSummary: "Отправить сообщение", + OperationID: "createMessage", + Body: request, + RawBody: rawBody, + Params: middleware.Parameters{ + { + Name: "chat_id", + In: "path", + }: params.ChatID, + { + Name: "Idempotency-Key", + In: "header", + }: params.IdempotencyKey, + }, + Raw: r, + } + + type ( + Request = *CreateMessage + Params = CreateMessageParams + Response = CreateMessageRes + ) + response, err = middleware.HookMiddleware[ + Request, + Params, + Response, + ]( + m, + mreq, + unpackCreateMessageParams, + func(ctx context.Context, request Request, params Params) (response Response, err error) { + response, err = s.h.CreateMessage(ctx, request, params) + return response, err + }, + ) + } else { + response, err = s.h.CreateMessage(ctx, request, params) + } + if err != nil { + defer recordError("Internal", err) + s.cfg.ErrorHandler(ctx, w, r, err) + return + } + + if err := encodeCreateMessageResponse(response, w); err != nil { + defer recordError("EncodeResponse", err) + if !errors.Is(err, ht.ErrInternalServerErrorResponse) { + s.cfg.ErrorHandler(ctx, w, r, err) + } + return + } +} + +// handleCreateSessionRequest handles createSession operation. +// +// Вход: Basic username:password; выдаёт сессию. +// +// POST /api/v1/auth/sessions +func (s *Server) handleCreateSessionRequest(args [0]string, argsEscaped bool, w http.ResponseWriter, r *http.Request) { + statusWriter := &codeRecorder{ResponseWriter: w} + w = statusWriter + ctx := r.Context() + + var ( + err error + opErrContext = ogenerrors.OperationContext{ + Name: CreateSessionOperation, + ID: "createSession", + } + ) + { + type bitset = [1]uint8 + var satisfied bitset + { + sctx, ok, err := s.securityBasicAuth(ctx, CreateSessionOperation, r) + if err != nil { + err = &ogenerrors.SecurityError{ + OperationContext: opErrContext, + Security: "BasicAuth", + Err: err, + } + defer recordError("Security:BasicAuth", err) + s.cfg.ErrorHandler(ctx, w, r, err) + return + } + if ok { + satisfied[0] |= 1 << 0 + ctx = sctx + } + } + + if ok := func() bool { + nextRequirement: + for _, requirement := range []bitset{ + {0b00000001}, + } { + for i, mask := range requirement { + if satisfied[i]&mask != mask { + continue nextRequirement + } + } + return true + } + return false + }(); !ok { + err = &ogenerrors.SecurityError{ + OperationContext: opErrContext, + Err: ogenerrors.ErrSecurityRequirementIsNotSatisfied, + } + defer recordError("Security", err) + s.cfg.ErrorHandler(ctx, w, r, err) + return + } + } + + var rawBody []byte + + var response CreateSessionRes + if m := s.cfg.Middleware; m != nil { + mreq := middleware.Request{ + Context: ctx, + OperationName: CreateSessionOperation, + OperationSummary: "Вход: Basic username:password; выдаёт сессию", + OperationID: "createSession", + Body: nil, + RawBody: rawBody, + Params: middleware.Parameters{}, + Raw: r, + } + + type ( + Request = struct{} + Params = struct{} + Response = CreateSessionRes + ) + response, err = middleware.HookMiddleware[ + Request, + Params, + Response, + ]( + m, + mreq, + nil, + func(ctx context.Context, request Request, params Params) (response Response, err error) { + response, err = s.h.CreateSession(ctx) + return response, err + }, + ) + } else { + response, err = s.h.CreateSession(ctx) + } + if err != nil { + defer recordError("Internal", err) + s.cfg.ErrorHandler(ctx, w, r, err) + return + } + + if err := encodeCreateSessionResponse(response, w); err != nil { + defer recordError("EncodeResponse", err) + if !errors.Is(err, ht.ErrInternalServerErrorResponse) { + s.cfg.ErrorHandler(ctx, w, r, err) + } + return + } +} + +// handleCurrentUserRequest handles currentUser operation. +// +// Текущий пользователь. +// +// GET /api/v1/users/me +func (s *Server) handleCurrentUserRequest(args [0]string, argsEscaped bool, w http.ResponseWriter, r *http.Request) { + statusWriter := &codeRecorder{ResponseWriter: w} + w = statusWriter + ctx := r.Context() + + var ( + err error + opErrContext = ogenerrors.OperationContext{ + Name: CurrentUserOperation, + ID: "currentUser", + } + ) + { + type bitset = [1]uint8 + var satisfied bitset + { + sctx, ok, err := s.securityBearerAuth(ctx, CurrentUserOperation, r) + if err != nil { + err = &ogenerrors.SecurityError{ + OperationContext: opErrContext, + Security: "BearerAuth", + Err: err, + } + defer recordError("Security:BearerAuth", err) + s.cfg.ErrorHandler(ctx, w, r, err) + return + } + if ok { + satisfied[0] |= 1 << 0 + ctx = sctx + } + } + + if ok := func() bool { + nextRequirement: + for _, requirement := range []bitset{ + {0b00000001}, + } { + for i, mask := range requirement { + if satisfied[i]&mask != mask { + continue nextRequirement + } + } + return true + } + return false + }(); !ok { + err = &ogenerrors.SecurityError{ + OperationContext: opErrContext, + Err: ogenerrors.ErrSecurityRequirementIsNotSatisfied, + } + defer recordError("Security", err) + s.cfg.ErrorHandler(ctx, w, r, err) + return + } + } + + var rawBody []byte + + var response CurrentUserRes + if m := s.cfg.Middleware; m != nil { + mreq := middleware.Request{ + Context: ctx, + OperationName: CurrentUserOperation, + OperationSummary: "Текущий пользователь", + OperationID: "currentUser", + Body: nil, + RawBody: rawBody, + Params: middleware.Parameters{}, + Raw: r, + } + + type ( + Request = struct{} + Params = struct{} + Response = CurrentUserRes + ) + response, err = middleware.HookMiddleware[ + Request, + Params, + Response, + ]( + m, + mreq, + nil, + func(ctx context.Context, request Request, params Params) (response Response, err error) { + response, err = s.h.CurrentUser(ctx) + return response, err + }, + ) + } else { + response, err = s.h.CurrentUser(ctx) + } + if err != nil { + defer recordError("Internal", err) + s.cfg.ErrorHandler(ctx, w, r, err) + return + } + + if err := encodeCurrentUserResponse(response, w); err != nil { + defer recordError("EncodeResponse", err) + if !errors.Is(err, ht.ErrInternalServerErrorResponse) { + s.cfg.ErrorHandler(ctx, w, r, err) + } + return + } +} + +// handleDownloadAttachmentRequest handles downloadAttachment operation. +// +// Скачать байты через авторизованный API. +// +// GET /api/v1/attachments/{attachment_id}/content +func (s *Server) handleDownloadAttachmentRequest(args [1]string, argsEscaped bool, w http.ResponseWriter, r *http.Request) { + statusWriter := &codeRecorder{ResponseWriter: w} + w = statusWriter + ctx := r.Context() + + var ( + err error + opErrContext = ogenerrors.OperationContext{ + Name: DownloadAttachmentOperation, + ID: "downloadAttachment", + } + ) + { + type bitset = [1]uint8 + var satisfied bitset + { + sctx, ok, err := s.securityBearerAuth(ctx, DownloadAttachmentOperation, r) + if err != nil { + err = &ogenerrors.SecurityError{ + OperationContext: opErrContext, + Security: "BearerAuth", + Err: err, + } + defer recordError("Security:BearerAuth", err) + s.cfg.ErrorHandler(ctx, w, r, err) + return + } + if ok { + satisfied[0] |= 1 << 0 + ctx = sctx + } + } + + if ok := func() bool { + nextRequirement: + for _, requirement := range []bitset{ + {0b00000001}, + } { + for i, mask := range requirement { + if satisfied[i]&mask != mask { + continue nextRequirement + } + } + return true + } + return false + }(); !ok { + err = &ogenerrors.SecurityError{ + OperationContext: opErrContext, + Err: ogenerrors.ErrSecurityRequirementIsNotSatisfied, + } + defer recordError("Security", err) + s.cfg.ErrorHandler(ctx, w, r, err) + return + } + } + params, err := decodeDownloadAttachmentParams(args, argsEscaped, r) + if err != nil { + err = &ogenerrors.DecodeParamsError{ + OperationContext: opErrContext, + Err: err, + } + defer recordError("DecodeParams", err) + s.cfg.ErrorHandler(ctx, w, r, err) + return + } + + var rawBody []byte + + var response DownloadAttachmentRes + if m := s.cfg.Middleware; m != nil { + mreq := middleware.Request{ + Context: ctx, + OperationName: DownloadAttachmentOperation, + OperationSummary: "Скачать байты через авторизованный API", + OperationID: "downloadAttachment", + Body: nil, + RawBody: rawBody, + Params: middleware.Parameters{ + { + Name: "attachment_id", + In: "path", + }: params.AttachmentID, + { + Name: "variant", + In: "query", + }: params.Variant, + }, + Raw: r, + } + + type ( + Request = struct{} + Params = DownloadAttachmentParams + Response = DownloadAttachmentRes + ) + response, err = middleware.HookMiddleware[ + Request, + Params, + Response, + ]( + m, + mreq, + unpackDownloadAttachmentParams, + func(ctx context.Context, request Request, params Params) (response Response, err error) { + response, err = s.h.DownloadAttachment(ctx, params) + return response, err + }, + ) + } else { + response, err = s.h.DownloadAttachment(ctx, params) + } + if err != nil { + defer recordError("Internal", err) + s.cfg.ErrorHandler(ctx, w, r, err) + return + } + + if err := encodeDownloadAttachmentResponse(response, w); err != nil { + defer recordError("EncodeResponse", err) + if !errors.Is(err, ht.ErrInternalServerErrorResponse) { + s.cfg.ErrorHandler(ctx, w, r, err) + } + return + } +} + +// handleGetAttachmentRequest handles getAttachment operation. +// +// Метаданные вложения, доступ участникам чата. +// +// GET /api/v1/attachments/{attachment_id} +func (s *Server) handleGetAttachmentRequest(args [1]string, argsEscaped bool, w http.ResponseWriter, r *http.Request) { + statusWriter := &codeRecorder{ResponseWriter: w} + w = statusWriter + ctx := r.Context() + + var ( + err error + opErrContext = ogenerrors.OperationContext{ + Name: GetAttachmentOperation, + ID: "getAttachment", + } + ) + { + type bitset = [1]uint8 + var satisfied bitset + { + sctx, ok, err := s.securityBearerAuth(ctx, GetAttachmentOperation, r) + if err != nil { + err = &ogenerrors.SecurityError{ + OperationContext: opErrContext, + Security: "BearerAuth", + Err: err, + } + defer recordError("Security:BearerAuth", err) + s.cfg.ErrorHandler(ctx, w, r, err) + return + } + if ok { + satisfied[0] |= 1 << 0 + ctx = sctx + } + } + + if ok := func() bool { + nextRequirement: + for _, requirement := range []bitset{ + {0b00000001}, + } { + for i, mask := range requirement { + if satisfied[i]&mask != mask { + continue nextRequirement + } + } + return true + } + return false + }(); !ok { + err = &ogenerrors.SecurityError{ + OperationContext: opErrContext, + Err: ogenerrors.ErrSecurityRequirementIsNotSatisfied, + } + defer recordError("Security", err) + s.cfg.ErrorHandler(ctx, w, r, err) + return + } + } + params, err := decodeGetAttachmentParams(args, argsEscaped, r) + if err != nil { + err = &ogenerrors.DecodeParamsError{ + OperationContext: opErrContext, + Err: err, + } + defer recordError("DecodeParams", err) + s.cfg.ErrorHandler(ctx, w, r, err) + return + } + + var rawBody []byte + + var response GetAttachmentRes + if m := s.cfg.Middleware; m != nil { + mreq := middleware.Request{ + Context: ctx, + OperationName: GetAttachmentOperation, + OperationSummary: "Метаданные вложения, доступ участникам чата", + OperationID: "getAttachment", + Body: nil, + RawBody: rawBody, + Params: middleware.Parameters{ + { + Name: "attachment_id", + In: "path", + }: params.AttachmentID, + }, + Raw: r, + } + + type ( + Request = struct{} + Params = GetAttachmentParams + Response = GetAttachmentRes + ) + response, err = middleware.HookMiddleware[ + Request, + Params, + Response, + ]( + m, + mreq, + unpackGetAttachmentParams, + func(ctx context.Context, request Request, params Params) (response Response, err error) { + response, err = s.h.GetAttachment(ctx, params) + return response, err + }, + ) + } else { + response, err = s.h.GetAttachment(ctx, params) + } + if err != nil { + defer recordError("Internal", err) + s.cfg.ErrorHandler(ctx, w, r, err) + return + } + + if err := encodeGetAttachmentResponse(response, w); err != nil { + defer recordError("EncodeResponse", err) + if !errors.Is(err, ht.ErrInternalServerErrorResponse) { + s.cfg.ErrorHandler(ctx, w, r, err) + } + return + } +} + +// handleGetChatRequest handles getChat operation. +// +// Получить доступный чат. +// +// GET /api/v1/chats/{chat_id} +func (s *Server) handleGetChatRequest(args [1]string, argsEscaped bool, w http.ResponseWriter, r *http.Request) { + statusWriter := &codeRecorder{ResponseWriter: w} + w = statusWriter + ctx := r.Context() + + var ( + err error + opErrContext = ogenerrors.OperationContext{ + Name: GetChatOperation, + ID: "getChat", + } + ) + { + type bitset = [1]uint8 + var satisfied bitset + { + sctx, ok, err := s.securityBearerAuth(ctx, GetChatOperation, r) + if err != nil { + err = &ogenerrors.SecurityError{ + OperationContext: opErrContext, + Security: "BearerAuth", + Err: err, + } + defer recordError("Security:BearerAuth", err) + s.cfg.ErrorHandler(ctx, w, r, err) + return + } + if ok { + satisfied[0] |= 1 << 0 + ctx = sctx + } + } + + if ok := func() bool { + nextRequirement: + for _, requirement := range []bitset{ + {0b00000001}, + } { + for i, mask := range requirement { + if satisfied[i]&mask != mask { + continue nextRequirement + } + } + return true + } + return false + }(); !ok { + err = &ogenerrors.SecurityError{ + OperationContext: opErrContext, + Err: ogenerrors.ErrSecurityRequirementIsNotSatisfied, + } + defer recordError("Security", err) + s.cfg.ErrorHandler(ctx, w, r, err) + return + } + } + params, err := decodeGetChatParams(args, argsEscaped, r) + if err != nil { + err = &ogenerrors.DecodeParamsError{ + OperationContext: opErrContext, + Err: err, + } + defer recordError("DecodeParams", err) + s.cfg.ErrorHandler(ctx, w, r, err) + return + } + + var rawBody []byte + + var response GetChatRes + if m := s.cfg.Middleware; m != nil { + mreq := middleware.Request{ + Context: ctx, + OperationName: GetChatOperation, + OperationSummary: "Получить доступный чат", + OperationID: "getChat", + Body: nil, + RawBody: rawBody, + Params: middleware.Parameters{ + { + Name: "chat_id", + In: "path", + }: params.ChatID, + }, + Raw: r, + } + + type ( + Request = struct{} + Params = GetChatParams + Response = GetChatRes + ) + response, err = middleware.HookMiddleware[ + Request, + Params, + Response, + ]( + m, + mreq, + unpackGetChatParams, + func(ctx context.Context, request Request, params Params) (response Response, err error) { + response, err = s.h.GetChat(ctx, params) + return response, err + }, + ) + } else { + response, err = s.h.GetChat(ctx, params) + } + if err != nil { + defer recordError("Internal", err) + s.cfg.ErrorHandler(ctx, w, r, err) + return + } + + if err := encodeGetChatResponse(response, w); err != nil { + defer recordError("EncodeResponse", err) + if !errors.Is(err, ht.ErrInternalServerErrorResponse) { + s.cfg.ErrorHandler(ctx, w, r, err) + } + return + } +} + +// handleListChatsRequest handles listChats operation. +// +// Чаты текущего пользователя. +// +// GET /api/v1/chats +func (s *Server) handleListChatsRequest(args [0]string, argsEscaped bool, w http.ResponseWriter, r *http.Request) { + statusWriter := &codeRecorder{ResponseWriter: w} + w = statusWriter + ctx := r.Context() + + var ( + err error + opErrContext = ogenerrors.OperationContext{ + Name: ListChatsOperation, + ID: "listChats", + } + ) + { + type bitset = [1]uint8 + var satisfied bitset + { + sctx, ok, err := s.securityBearerAuth(ctx, ListChatsOperation, r) + if err != nil { + err = &ogenerrors.SecurityError{ + OperationContext: opErrContext, + Security: "BearerAuth", + Err: err, + } + defer recordError("Security:BearerAuth", err) + s.cfg.ErrorHandler(ctx, w, r, err) + return + } + if ok { + satisfied[0] |= 1 << 0 + ctx = sctx + } + } + + if ok := func() bool { + nextRequirement: + for _, requirement := range []bitset{ + {0b00000001}, + } { + for i, mask := range requirement { + if satisfied[i]&mask != mask { + continue nextRequirement + } + } + return true + } + return false + }(); !ok { + err = &ogenerrors.SecurityError{ + OperationContext: opErrContext, + Err: ogenerrors.ErrSecurityRequirementIsNotSatisfied, + } + defer recordError("Security", err) + s.cfg.ErrorHandler(ctx, w, r, err) + return + } + } + params, err := decodeListChatsParams(args, argsEscaped, r) + if err != nil { + err = &ogenerrors.DecodeParamsError{ + OperationContext: opErrContext, + Err: err, + } + defer recordError("DecodeParams", err) + s.cfg.ErrorHandler(ctx, w, r, err) + return + } + + var rawBody []byte + + var response ListChatsRes + if m := s.cfg.Middleware; m != nil { + mreq := middleware.Request{ + Context: ctx, + OperationName: ListChatsOperation, + OperationSummary: "Чаты текущего пользователя", + OperationID: "listChats", + Body: nil, + RawBody: rawBody, + Params: middleware.Parameters{ + { + Name: "limit", + In: "query", + }: params.Limit, + { + Name: "cursor", + In: "query", + }: params.Cursor, + }, + Raw: r, + } + + type ( + Request = struct{} + Params = ListChatsParams + Response = ListChatsRes + ) + response, err = middleware.HookMiddleware[ + Request, + Params, + Response, + ]( + m, + mreq, + unpackListChatsParams, + func(ctx context.Context, request Request, params Params) (response Response, err error) { + response, err = s.h.ListChats(ctx, params) + return response, err + }, + ) + } else { + response, err = s.h.ListChats(ctx, params) + } + if err != nil { + defer recordError("Internal", err) + s.cfg.ErrorHandler(ctx, w, r, err) + return + } + + if err := encodeListChatsResponse(response, w); err != nil { + defer recordError("EncodeResponse", err) + if !errors.Is(err, ht.ErrInternalServerErrorResponse) { + s.cfg.ErrorHandler(ctx, w, r, err) + } + return + } +} + +// handleListMessagesRequest handles listMessages operation. +// +// Сообщения по (created_at, id) по возрастанию. +// +// GET /api/v1/chats/{chat_id}/messages +func (s *Server) handleListMessagesRequest(args [1]string, argsEscaped bool, w http.ResponseWriter, r *http.Request) { + statusWriter := &codeRecorder{ResponseWriter: w} + w = statusWriter + ctx := r.Context() + + var ( + err error + opErrContext = ogenerrors.OperationContext{ + Name: ListMessagesOperation, + ID: "listMessages", + } + ) + { + type bitset = [1]uint8 + var satisfied bitset + { + sctx, ok, err := s.securityBearerAuth(ctx, ListMessagesOperation, r) + if err != nil { + err = &ogenerrors.SecurityError{ + OperationContext: opErrContext, + Security: "BearerAuth", + Err: err, + } + defer recordError("Security:BearerAuth", err) + s.cfg.ErrorHandler(ctx, w, r, err) + return + } + if ok { + satisfied[0] |= 1 << 0 + ctx = sctx + } + } + + if ok := func() bool { + nextRequirement: + for _, requirement := range []bitset{ + {0b00000001}, + } { + for i, mask := range requirement { + if satisfied[i]&mask != mask { + continue nextRequirement + } + } + return true + } + return false + }(); !ok { + err = &ogenerrors.SecurityError{ + OperationContext: opErrContext, + Err: ogenerrors.ErrSecurityRequirementIsNotSatisfied, + } + defer recordError("Security", err) + s.cfg.ErrorHandler(ctx, w, r, err) + return + } + } + params, err := decodeListMessagesParams(args, argsEscaped, r) + if err != nil { + err = &ogenerrors.DecodeParamsError{ + OperationContext: opErrContext, + Err: err, + } + defer recordError("DecodeParams", err) + s.cfg.ErrorHandler(ctx, w, r, err) + return + } + + var rawBody []byte + + var response ListMessagesRes + if m := s.cfg.Middleware; m != nil { + mreq := middleware.Request{ + Context: ctx, + OperationName: ListMessagesOperation, + OperationSummary: "Сообщения по (created_at, id) по возрастанию", + OperationID: "listMessages", + Body: nil, + RawBody: rawBody, + Params: middleware.Parameters{ + { + Name: "chat_id", + In: "path", + }: params.ChatID, + { + Name: "limit", + In: "query", + }: params.Limit, + { + Name: "cursor", + In: "query", + }: params.Cursor, + }, + Raw: r, + } + + type ( + Request = struct{} + Params = ListMessagesParams + Response = ListMessagesRes + ) + response, err = middleware.HookMiddleware[ + Request, + Params, + Response, + ]( + m, + mreq, + unpackListMessagesParams, + func(ctx context.Context, request Request, params Params) (response Response, err error) { + response, err = s.h.ListMessages(ctx, params) + return response, err + }, + ) + } else { + response, err = s.h.ListMessages(ctx, params) + } + if err != nil { + defer recordError("Internal", err) + s.cfg.ErrorHandler(ctx, w, r, err) + return + } + + if err := encodeListMessagesResponse(response, w); err != nil { + defer recordError("EncodeResponse", err) + if !errors.Is(err, ht.ErrInternalServerErrorResponse) { + s.cfg.ErrorHandler(ctx, w, r, err) + } + return + } +} + +// handleLivenessRequest handles liveness operation. +// +// Процесс жив. +// +// GET /health/live +func (s *Server) handleLivenessRequest(args [0]string, argsEscaped bool, w http.ResponseWriter, r *http.Request) { + statusWriter := &codeRecorder{ResponseWriter: w} + w = statusWriter + ctx := r.Context() + + var ( + err error + ) + + var rawBody []byte + + var response LivenessRes + if m := s.cfg.Middleware; m != nil { + mreq := middleware.Request{ + Context: ctx, + OperationName: LivenessOperation, + OperationSummary: "Процесс жив", + OperationID: "liveness", + Body: nil, + RawBody: rawBody, + Params: middleware.Parameters{}, + Raw: r, + } + + type ( + Request = struct{} + Params = struct{} + Response = LivenessRes + ) + response, err = middleware.HookMiddleware[ + Request, + Params, + Response, + ]( + m, + mreq, + nil, + func(ctx context.Context, request Request, params Params) (response Response, err error) { + response, err = s.h.Liveness(ctx) + return response, err + }, + ) + } else { + response, err = s.h.Liveness(ctx) + } + if err != nil { + defer recordError("Internal", err) + s.cfg.ErrorHandler(ctx, w, r, err) + return + } + + if err := encodeLivenessResponse(response, w); err != nil { + defer recordError("EncodeResponse", err) + if !errors.Is(err, ht.ErrInternalServerErrorResponse) { + s.cfg.ErrorHandler(ctx, w, r, err) + } + return + } +} + +// handleReadinessRequest handles readiness operation. +// +// Готов принимать трафик. +// +// GET /health/ready +func (s *Server) handleReadinessRequest(args [0]string, argsEscaped bool, w http.ResponseWriter, r *http.Request) { + statusWriter := &codeRecorder{ResponseWriter: w} + w = statusWriter + ctx := r.Context() + + var ( + err error + ) + + var rawBody []byte + + var response ReadinessRes + if m := s.cfg.Middleware; m != nil { + mreq := middleware.Request{ + Context: ctx, + OperationName: ReadinessOperation, + OperationSummary: "Готов принимать трафик", + OperationID: "readiness", + Body: nil, + RawBody: rawBody, + Params: middleware.Parameters{}, + Raw: r, + } + + type ( + Request = struct{} + Params = struct{} + Response = ReadinessRes + ) + response, err = middleware.HookMiddleware[ + Request, + Params, + Response, + ]( + m, + mreq, + nil, + func(ctx context.Context, request Request, params Params) (response Response, err error) { + response, err = s.h.Readiness(ctx) + return response, err + }, + ) + } else { + response, err = s.h.Readiness(ctx) + } + if err != nil { + defer recordError("Internal", err) + s.cfg.ErrorHandler(ctx, w, r, err) + return + } + + if err := encodeReadinessResponse(response, w); err != nil { + defer recordError("EncodeResponse", err) + if !errors.Is(err, ht.ErrInternalServerErrorResponse) { + s.cfg.ErrorHandler(ctx, w, r, err) + } + return + } +} + +// handleRegisterUserRequest handles registerUser operation. +// +// Создать пользователя. +// +// POST /api/v1/users +func (s *Server) handleRegisterUserRequest(args [0]string, argsEscaped bool, w http.ResponseWriter, r *http.Request) { + statusWriter := &codeRecorder{ResponseWriter: w} + w = statusWriter + ctx := r.Context() + + var ( + err error + opErrContext = ogenerrors.OperationContext{ + Name: RegisterUserOperation, + ID: "registerUser", + } + ) + + var rawBody []byte + request, rawBody, close, err := s.decodeRegisterUserRequest(r) + if err != nil { + err = &ogenerrors.DecodeRequestError{ + OperationContext: opErrContext, + Err: err, + } + defer recordError("DecodeRequest", err) + s.cfg.ErrorHandler(ctx, w, r, err) + return + } + defer func() { + if err := close(); err != nil { + recordError("CloseRequest", err) + } + }() + + var response RegisterUserRes + if m := s.cfg.Middleware; m != nil { + mreq := middleware.Request{ + Context: ctx, + OperationName: RegisterUserOperation, + OperationSummary: "Создать пользователя", + OperationID: "registerUser", + Body: request, + RawBody: rawBody, + Params: middleware.Parameters{}, + Raw: r, + } + + type ( + Request = *CreateUser + Params = struct{} + Response = RegisterUserRes + ) + response, err = middleware.HookMiddleware[ + Request, + Params, + Response, + ]( + m, + mreq, + nil, + func(ctx context.Context, request Request, params Params) (response Response, err error) { + response, err = s.h.RegisterUser(ctx, request) + return response, err + }, + ) + } else { + response, err = s.h.RegisterUser(ctx, request) + } + if err != nil { + defer recordError("Internal", err) + s.cfg.ErrorHandler(ctx, w, r, err) + return + } + + if err := encodeRegisterUserResponse(response, w); err != nil { + defer recordError("EncodeResponse", err) + if !errors.Is(err, ht.ErrInternalServerErrorResponse) { + s.cfg.ErrorHandler(ctx, w, r, err) + } + return + } +} + +// handleRevokeSessionRequest handles revokeSession operation. +// +// Отозвать текущую сессию. +// +// DELETE /api/v1/auth/sessions/current +func (s *Server) handleRevokeSessionRequest(args [0]string, argsEscaped bool, w http.ResponseWriter, r *http.Request) { + statusWriter := &codeRecorder{ResponseWriter: w} + w = statusWriter + ctx := r.Context() + + var ( + err error + opErrContext = ogenerrors.OperationContext{ + Name: RevokeSessionOperation, + ID: "revokeSession", + } + ) + { + type bitset = [1]uint8 + var satisfied bitset + { + sctx, ok, err := s.securityBearerAuth(ctx, RevokeSessionOperation, r) + if err != nil { + err = &ogenerrors.SecurityError{ + OperationContext: opErrContext, + Security: "BearerAuth", + Err: err, + } + defer recordError("Security:BearerAuth", err) + s.cfg.ErrorHandler(ctx, w, r, err) + return + } + if ok { + satisfied[0] |= 1 << 0 + ctx = sctx + } + } + + if ok := func() bool { + nextRequirement: + for _, requirement := range []bitset{ + {0b00000001}, + } { + for i, mask := range requirement { + if satisfied[i]&mask != mask { + continue nextRequirement + } + } + return true + } + return false + }(); !ok { + err = &ogenerrors.SecurityError{ + OperationContext: opErrContext, + Err: ogenerrors.ErrSecurityRequirementIsNotSatisfied, + } + defer recordError("Security", err) + s.cfg.ErrorHandler(ctx, w, r, err) + return + } + } + + var rawBody []byte + + var response RevokeSessionRes + if m := s.cfg.Middleware; m != nil { + mreq := middleware.Request{ + Context: ctx, + OperationName: RevokeSessionOperation, + OperationSummary: "Отозвать текущую сессию", + OperationID: "revokeSession", + Body: nil, + RawBody: rawBody, + Params: middleware.Parameters{}, + Raw: r, + } + + type ( + Request = struct{} + Params = struct{} + Response = RevokeSessionRes + ) + response, err = middleware.HookMiddleware[ + Request, + Params, + Response, + ]( + m, + mreq, + nil, + func(ctx context.Context, request Request, params Params) (response Response, err error) { + response, err = s.h.RevokeSession(ctx) + return response, err + }, + ) + } else { + response, err = s.h.RevokeSession(ctx) + } + if err != nil { + defer recordError("Internal", err) + s.cfg.ErrorHandler(ctx, w, r, err) + return + } + + if err := encodeRevokeSessionResponse(response, w); err != nil { + defer recordError("EncodeResponse", err) + if !errors.Is(err, ht.ErrInternalServerErrorResponse) { + s.cfg.ErrorHandler(ctx, w, r, err) + } + return + } +} + +// handleUploadAttachmentRequest handles uploadAttachment operation. +// +// Принять один PNG/JPEG, до 10 MiB. +// +// POST /api/v1/chats/{chat_id}/attachments +func (s *Server) handleUploadAttachmentRequest(args [1]string, argsEscaped bool, w http.ResponseWriter, r *http.Request) { + statusWriter := &codeRecorder{ResponseWriter: w} + w = statusWriter + ctx := r.Context() + + var ( + err error + opErrContext = ogenerrors.OperationContext{ + Name: UploadAttachmentOperation, + ID: "uploadAttachment", + } + ) + { + type bitset = [1]uint8 + var satisfied bitset + { + sctx, ok, err := s.securityBearerAuth(ctx, UploadAttachmentOperation, r) + if err != nil { + err = &ogenerrors.SecurityError{ + OperationContext: opErrContext, + Security: "BearerAuth", + Err: err, + } + defer recordError("Security:BearerAuth", err) + s.cfg.ErrorHandler(ctx, w, r, err) + return + } + if ok { + satisfied[0] |= 1 << 0 + ctx = sctx + } + } + + if ok := func() bool { + nextRequirement: + for _, requirement := range []bitset{ + {0b00000001}, + } { + for i, mask := range requirement { + if satisfied[i]&mask != mask { + continue nextRequirement + } + } + return true + } + return false + }(); !ok { + err = &ogenerrors.SecurityError{ + OperationContext: opErrContext, + Err: ogenerrors.ErrSecurityRequirementIsNotSatisfied, + } + defer recordError("Security", err) + s.cfg.ErrorHandler(ctx, w, r, err) + return + } + } + params, err := decodeUploadAttachmentParams(args, argsEscaped, r) + if err != nil { + err = &ogenerrors.DecodeParamsError{ + OperationContext: opErrContext, + Err: err, + } + defer recordError("DecodeParams", err) + s.cfg.ErrorHandler(ctx, w, r, err) + return + } + + var rawBody []byte + request, rawBody, close, err := s.decodeUploadAttachmentRequest(r) + if err != nil { + err = &ogenerrors.DecodeRequestError{ + OperationContext: opErrContext, + Err: err, + } + defer recordError("DecodeRequest", err) + s.cfg.ErrorHandler(ctx, w, r, err) + return + } + defer func() { + if err := close(); err != nil { + recordError("CloseRequest", err) + } + }() + + var response UploadAttachmentRes + if m := s.cfg.Middleware; m != nil { + mreq := middleware.Request{ + Context: ctx, + OperationName: UploadAttachmentOperation, + OperationSummary: "Принять один PNG/JPEG, до 10 MiB", + OperationID: "uploadAttachment", + Body: request, + RawBody: rawBody, + Params: middleware.Parameters{ + { + Name: "chat_id", + In: "path", + }: params.ChatID, + { + Name: "filename", + In: "query", + }: params.Filename, + }, + Raw: r, + } + + type ( + Request = UploadAttachmentReq + Params = UploadAttachmentParams + Response = UploadAttachmentRes + ) + response, err = middleware.HookMiddleware[ + Request, + Params, + Response, + ]( + m, + mreq, + unpackUploadAttachmentParams, + func(ctx context.Context, request Request, params Params) (response Response, err error) { + response, err = s.h.UploadAttachment(ctx, request, params) + return response, err + }, + ) + } else { + response, err = s.h.UploadAttachment(ctx, request, params) + } + if err != nil { + defer recordError("Internal", err) + s.cfg.ErrorHandler(ctx, w, r, err) + return + } + + if err := encodeUploadAttachmentResponse(response, w); err != nil { + defer recordError("EncodeResponse", err) + if !errors.Is(err, ht.ErrInternalServerErrorResponse) { + s.cfg.ErrorHandler(ctx, w, r, err) + } + return + } +} diff --git a/internal/transport/rest/internal/oas/oas_interfaces_gen.go b/internal/transport/rest/internal/oas/oas_interfaces_gen.go new file mode 100644 index 0000000..113887e --- /dev/null +++ b/internal/transport/rest/internal/oas/oas_interfaces_gen.go @@ -0,0 +1,62 @@ +// Code generated by ogen, DO NOT EDIT. +package oas + +type CreateChatRes interface { + createChatRes() +} + +type CreateMessageRes interface { + createMessageRes() +} + +type CreateSessionRes interface { + createSessionRes() +} + +type CurrentUserRes interface { + currentUserRes() +} + +type DownloadAttachmentRes interface { + downloadAttachmentRes() +} + +type GetAttachmentRes interface { + getAttachmentRes() +} + +type GetChatRes interface { + getChatRes() +} + +type ListChatsRes interface { + listChatsRes() +} + +type ListMessagesRes interface { + listMessagesRes() +} + +type LivenessRes interface { + livenessRes() +} + +type ReadinessRes interface { + readinessRes() +} + +type RegisterUserRes interface { + registerUserRes() +} + +type RevokeSessionRes interface { + revokeSessionRes() +} + +type UploadAttachmentReq interface { + uploadAttachmentReq() +} + +type UploadAttachmentRes interface { + uploadAttachmentRes() +} diff --git a/internal/transport/rest/internal/oas/oas_json_gen.go b/internal/transport/rest/internal/oas/oas_json_gen.go new file mode 100644 index 0000000..6acaa49 --- /dev/null +++ b/internal/transport/rest/internal/oas/oas_json_gen.go @@ -0,0 +1,2369 @@ +// Code generated by ogen, DO NOT EDIT. + +package oas + +import ( + "math/bits" + "strconv" + + "github.com/go-faster/errors" + "github.com/go-faster/jx" + "github.com/google/uuid" + "github.com/ogen-go/ogen/json" + "github.com/ogen-go/ogen/validate" +) + +// Encode implements json.Marshaler. +func (s *Attachment) Encode(e *jx.Encoder) { + e.ObjStart() + s.encodeFields(e) + e.ObjEnd() +} + +// encodeFields encodes fields. +func (s *Attachment) encodeFields(e *jx.Encoder) { + { + e.FieldStart("chat_id") + json.EncodeUUID(e, s.ChatID) + } + { + e.FieldStart("content_type") + s.ContentType.Encode(e) + } + { + e.FieldStart("created_at") + json.EncodeDateTime(e, s.CreatedAt) + } + { + e.FieldStart("error_code") + s.ErrorCode.Encode(e) + } + { + e.FieldStart("filename") + e.Str(s.Filename) + } + { + e.FieldStart("id") + json.EncodeUUID(e, s.ID) + } + { + e.FieldStart("owner_id") + json.EncodeUUID(e, s.OwnerID) + } + { + e.FieldStart("sha256") + e.Str(s.SHA256) + } + { + e.FieldStart("size_bytes") + e.Int(s.SizeBytes) + } + { + e.FieldStart("status") + s.Status.Encode(e) + } + { + e.FieldStart("updated_at") + json.EncodeDateTime(e, s.UpdatedAt) + } + { + e.FieldStart("variants") + e.ArrStart() + for _, elem := range s.Variants { + elem.Encode(e) + } + e.ArrEnd() + } +} + +var jsonFieldsNameOfAttachment = [12]string{ + 0: "chat_id", + 1: "content_type", + 2: "created_at", + 3: "error_code", + 4: "filename", + 5: "id", + 6: "owner_id", + 7: "sha256", + 8: "size_bytes", + 9: "status", + 10: "updated_at", + 11: "variants", +} + +// Decode decodes Attachment from json. +func (s *Attachment) Decode(d *jx.Decoder) error { + if s == nil { + return errors.New("invalid: unable to decode Attachment to nil") + } + var requiredBitSet [2]uint8 + + if err := d.ObjBytes(func(d *jx.Decoder, k []byte) error { + switch string(k) { + case "chat_id": + requiredBitSet[0] |= 1 << 0 + if err := func() error { + v, err := json.DecodeUUID(d) + s.ChatID = v + if err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"chat_id\"") + } + case "content_type": + requiredBitSet[0] |= 1 << 1 + if err := func() error { + if err := s.ContentType.Decode(d); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"content_type\"") + } + case "created_at": + requiredBitSet[0] |= 1 << 2 + if err := func() error { + v, err := json.DecodeDateTime(d) + s.CreatedAt = v + if err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"created_at\"") + } + case "error_code": + requiredBitSet[0] |= 1 << 3 + if err := func() error { + if err := s.ErrorCode.Decode(d); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"error_code\"") + } + case "filename": + requiredBitSet[0] |= 1 << 4 + if err := func() error { + v, err := d.Str() + s.Filename = string(v) + if err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"filename\"") + } + case "id": + requiredBitSet[0] |= 1 << 5 + if err := func() error { + v, err := json.DecodeUUID(d) + s.ID = v + if err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"id\"") + } + case "owner_id": + requiredBitSet[0] |= 1 << 6 + if err := func() error { + v, err := json.DecodeUUID(d) + s.OwnerID = v + if err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"owner_id\"") + } + case "sha256": + requiredBitSet[0] |= 1 << 7 + if err := func() error { + v, err := d.Str() + s.SHA256 = string(v) + if err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"sha256\"") + } + case "size_bytes": + requiredBitSet[1] |= 1 << 0 + if err := func() error { + v, err := d.Int() + s.SizeBytes = int(v) + if err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"size_bytes\"") + } + case "status": + requiredBitSet[1] |= 1 << 1 + if err := func() error { + if err := s.Status.Decode(d); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"status\"") + } + case "updated_at": + requiredBitSet[1] |= 1 << 2 + if err := func() error { + v, err := json.DecodeDateTime(d) + s.UpdatedAt = v + if err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"updated_at\"") + } + case "variants": + requiredBitSet[1] |= 1 << 3 + if err := func() error { + s.Variants = make([]Variant, 0) + if err := d.Arr(func(d *jx.Decoder) error { + var elem Variant + if err := elem.Decode(d); err != nil { + return err + } + s.Variants = append(s.Variants, elem) + return nil + }); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"variants\"") + } + default: + return errors.Errorf("unexpected field %q", k) + } + return nil + }); err != nil { + return errors.Wrap(err, "decode Attachment") + } + // Validate required fields. + var failures []validate.FieldError + for i, mask := range [2]uint8{ + 0b11111111, + 0b00001111, + } { + if result := (requiredBitSet[i] & mask) ^ mask; result != 0 { + // Mask only required fields and check equality to mask using XOR. + // + // If XOR result is not zero, result is not equal to expected, so some fields are missed. + // Bits of fields which would be set are actually bits of missed fields. + missed := bits.OnesCount8(result) + for bitN := 0; bitN < missed; bitN++ { + bitIdx := bits.TrailingZeros8(result) + fieldIdx := i*8 + bitIdx + var name string + if fieldIdx < len(jsonFieldsNameOfAttachment) { + name = jsonFieldsNameOfAttachment[fieldIdx] + } else { + name = strconv.Itoa(fieldIdx) + } + failures = append(failures, validate.FieldError{ + Name: name, + Error: validate.ErrFieldRequired, + }) + // Reset bit. + result &^= 1 << bitIdx + } + } + } + if len(failures) > 0 { + return &validate.Error{Fields: failures} + } + + return nil +} + +// MarshalJSON implements stdjson.Marshaler. +func (s *Attachment) MarshalJSON() ([]byte, error) { + e := jx.Encoder{} + s.Encode(&e) + return e.Bytes(), nil +} + +// UnmarshalJSON implements stdjson.Unmarshaler. +func (s *Attachment) UnmarshalJSON(data []byte) error { + d := jx.DecodeBytes(data) + return s.Decode(d) +} + +// Encode encodes AttachmentContentType as json. +func (s AttachmentContentType) Encode(e *jx.Encoder) { + e.Str(string(s)) +} + +// Decode decodes AttachmentContentType from json. +func (s *AttachmentContentType) Decode(d *jx.Decoder) error { + if s == nil { + return errors.New("invalid: unable to decode AttachmentContentType to nil") + } + v, err := d.StrBytes() + if err != nil { + return err + } + // Try to use constant string. + switch AttachmentContentType(v) { + case AttachmentContentTypeImagePNG: + *s = AttachmentContentTypeImagePNG + case AttachmentContentTypeImageJpeg: + *s = AttachmentContentTypeImageJpeg + default: + *s = AttachmentContentType(v) + } + + return nil +} + +// MarshalJSON implements stdjson.Marshaler. +func (s AttachmentContentType) MarshalJSON() ([]byte, error) { + e := jx.Encoder{} + s.Encode(&e) + return e.Bytes(), nil +} + +// UnmarshalJSON implements stdjson.Unmarshaler. +func (s *AttachmentContentType) UnmarshalJSON(data []byte) error { + d := jx.DecodeBytes(data) + return s.Decode(d) +} + +// Encode encodes AttachmentStatus as json. +func (s AttachmentStatus) Encode(e *jx.Encoder) { + e.Str(string(s)) +} + +// Decode decodes AttachmentStatus from json. +func (s *AttachmentStatus) Decode(d *jx.Decoder) error { + if s == nil { + return errors.New("invalid: unable to decode AttachmentStatus to nil") + } + v, err := d.StrBytes() + if err != nil { + return err + } + // Try to use constant string. + switch AttachmentStatus(v) { + case AttachmentStatusQueued: + *s = AttachmentStatusQueued + case AttachmentStatusProcessing: + *s = AttachmentStatusProcessing + case AttachmentStatusReady: + *s = AttachmentStatusReady + case AttachmentStatusFailed: + *s = AttachmentStatusFailed + default: + *s = AttachmentStatus(v) + } + + return nil +} + +// MarshalJSON implements stdjson.Marshaler. +func (s AttachmentStatus) MarshalJSON() ([]byte, error) { + e := jx.Encoder{} + s.Encode(&e) + return e.Bytes(), nil +} + +// UnmarshalJSON implements stdjson.Unmarshaler. +func (s *AttachmentStatus) UnmarshalJSON(data []byte) error { + d := jx.DecodeBytes(data) + return s.Decode(d) +} + +// Encode implements json.Marshaler. +func (s *Chat) Encode(e *jx.Encoder) { + e.ObjStart() + s.encodeFields(e) + e.ObjEnd() +} + +// encodeFields encodes fields. +func (s *Chat) encodeFields(e *jx.Encoder) { + { + e.FieldStart("created_at") + json.EncodeDateTime(e, s.CreatedAt) + } + { + e.FieldStart("id") + json.EncodeUUID(e, s.ID) + } + { + e.FieldStart("member_ids") + e.ArrStart() + for _, elem := range s.MemberIds { + json.EncodeUUID(e, elem) + } + e.ArrEnd() + } + { + e.FieldStart("title") + e.Str(s.Title) + } +} + +var jsonFieldsNameOfChat = [4]string{ + 0: "created_at", + 1: "id", + 2: "member_ids", + 3: "title", +} + +// Decode decodes Chat from json. +func (s *Chat) Decode(d *jx.Decoder) error { + if s == nil { + return errors.New("invalid: unable to decode Chat to nil") + } + var requiredBitSet [1]uint8 + + if err := d.ObjBytes(func(d *jx.Decoder, k []byte) error { + switch string(k) { + case "created_at": + requiredBitSet[0] |= 1 << 0 + if err := func() error { + v, err := json.DecodeDateTime(d) + s.CreatedAt = v + if err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"created_at\"") + } + case "id": + requiredBitSet[0] |= 1 << 1 + if err := func() error { + v, err := json.DecodeUUID(d) + s.ID = v + if err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"id\"") + } + case "member_ids": + requiredBitSet[0] |= 1 << 2 + if err := func() error { + s.MemberIds = make([]uuid.UUID, 0) + if err := d.Arr(func(d *jx.Decoder) error { + var elem uuid.UUID + v, err := json.DecodeUUID(d) + elem = v + if err != nil { + return err + } + s.MemberIds = append(s.MemberIds, elem) + return nil + }); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"member_ids\"") + } + case "title": + requiredBitSet[0] |= 1 << 3 + if err := func() error { + v, err := d.Str() + s.Title = string(v) + if err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"title\"") + } + default: + return errors.Errorf("unexpected field %q", k) + } + return nil + }); err != nil { + return errors.Wrap(err, "decode Chat") + } + // Validate required fields. + var failures []validate.FieldError + for i, mask := range [1]uint8{ + 0b00001111, + } { + if result := (requiredBitSet[i] & mask) ^ mask; result != 0 { + // Mask only required fields and check equality to mask using XOR. + // + // If XOR result is not zero, result is not equal to expected, so some fields are missed. + // Bits of fields which would be set are actually bits of missed fields. + missed := bits.OnesCount8(result) + for bitN := 0; bitN < missed; bitN++ { + bitIdx := bits.TrailingZeros8(result) + fieldIdx := i*8 + bitIdx + var name string + if fieldIdx < len(jsonFieldsNameOfChat) { + name = jsonFieldsNameOfChat[fieldIdx] + } else { + name = strconv.Itoa(fieldIdx) + } + failures = append(failures, validate.FieldError{ + Name: name, + Error: validate.ErrFieldRequired, + }) + // Reset bit. + result &^= 1 << bitIdx + } + } + } + if len(failures) > 0 { + return &validate.Error{Fields: failures} + } + + return nil +} + +// MarshalJSON implements stdjson.Marshaler. +func (s *Chat) MarshalJSON() ([]byte, error) { + e := jx.Encoder{} + s.Encode(&e) + return e.Bytes(), nil +} + +// UnmarshalJSON implements stdjson.Unmarshaler. +func (s *Chat) UnmarshalJSON(data []byte) error { + d := jx.DecodeBytes(data) + return s.Decode(d) +} + +// Encode implements json.Marshaler. +func (s *ChatPage) Encode(e *jx.Encoder) { + e.ObjStart() + s.encodeFields(e) + e.ObjEnd() +} + +// encodeFields encodes fields. +func (s *ChatPage) encodeFields(e *jx.Encoder) { + { + e.FieldStart("items") + e.ArrStart() + for _, elem := range s.Items { + elem.Encode(e) + } + e.ArrEnd() + } + { + e.FieldStart("next_cursor") + s.NextCursor.Encode(e) + } +} + +var jsonFieldsNameOfChatPage = [2]string{ + 0: "items", + 1: "next_cursor", +} + +// Decode decodes ChatPage from json. +func (s *ChatPage) Decode(d *jx.Decoder) error { + if s == nil { + return errors.New("invalid: unable to decode ChatPage to nil") + } + var requiredBitSet [1]uint8 + + if err := d.ObjBytes(func(d *jx.Decoder, k []byte) error { + switch string(k) { + case "items": + requiredBitSet[0] |= 1 << 0 + if err := func() error { + s.Items = make([]Chat, 0) + if err := d.Arr(func(d *jx.Decoder) error { + var elem Chat + if err := elem.Decode(d); err != nil { + return err + } + s.Items = append(s.Items, elem) + return nil + }); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"items\"") + } + case "next_cursor": + requiredBitSet[0] |= 1 << 1 + if err := func() error { + if err := s.NextCursor.Decode(d); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"next_cursor\"") + } + default: + return errors.Errorf("unexpected field %q", k) + } + return nil + }); err != nil { + return errors.Wrap(err, "decode ChatPage") + } + // Validate required fields. + var failures []validate.FieldError + for i, mask := range [1]uint8{ + 0b00000011, + } { + if result := (requiredBitSet[i] & mask) ^ mask; result != 0 { + // Mask only required fields and check equality to mask using XOR. + // + // If XOR result is not zero, result is not equal to expected, so some fields are missed. + // Bits of fields which would be set are actually bits of missed fields. + missed := bits.OnesCount8(result) + for bitN := 0; bitN < missed; bitN++ { + bitIdx := bits.TrailingZeros8(result) + fieldIdx := i*8 + bitIdx + var name string + if fieldIdx < len(jsonFieldsNameOfChatPage) { + name = jsonFieldsNameOfChatPage[fieldIdx] + } else { + name = strconv.Itoa(fieldIdx) + } + failures = append(failures, validate.FieldError{ + Name: name, + Error: validate.ErrFieldRequired, + }) + // Reset bit. + result &^= 1 << bitIdx + } + } + } + if len(failures) > 0 { + return &validate.Error{Fields: failures} + } + + return nil +} + +// MarshalJSON implements stdjson.Marshaler. +func (s *ChatPage) MarshalJSON() ([]byte, error) { + e := jx.Encoder{} + s.Encode(&e) + return e.Bytes(), nil +} + +// UnmarshalJSON implements stdjson.Unmarshaler. +func (s *ChatPage) UnmarshalJSON(data []byte) error { + d := jx.DecodeBytes(data) + return s.Decode(d) +} + +// Encode implements json.Marshaler. +func (s *CreateChat) Encode(e *jx.Encoder) { + e.ObjStart() + s.encodeFields(e) + e.ObjEnd() +} + +// encodeFields encodes fields. +func (s *CreateChat) encodeFields(e *jx.Encoder) { + { + e.FieldStart("member_ids") + e.ArrStart() + for _, elem := range s.MemberIds { + json.EncodeUUID(e, elem) + } + e.ArrEnd() + } + { + e.FieldStart("title") + e.Str(s.Title) + } +} + +var jsonFieldsNameOfCreateChat = [2]string{ + 0: "member_ids", + 1: "title", +} + +// Decode decodes CreateChat from json. +func (s *CreateChat) Decode(d *jx.Decoder) error { + if s == nil { + return errors.New("invalid: unable to decode CreateChat to nil") + } + var requiredBitSet [1]uint8 + + if err := d.ObjBytes(func(d *jx.Decoder, k []byte) error { + switch string(k) { + case "member_ids": + requiredBitSet[0] |= 1 << 0 + if err := func() error { + s.MemberIds = make([]uuid.UUID, 0) + if err := d.Arr(func(d *jx.Decoder) error { + var elem uuid.UUID + v, err := json.DecodeUUID(d) + elem = v + if err != nil { + return err + } + s.MemberIds = append(s.MemberIds, elem) + return nil + }); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"member_ids\"") + } + case "title": + requiredBitSet[0] |= 1 << 1 + if err := func() error { + v, err := d.Str() + s.Title = string(v) + if err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"title\"") + } + default: + return errors.Errorf("unexpected field %q", k) + } + return nil + }); err != nil { + return errors.Wrap(err, "decode CreateChat") + } + // Validate required fields. + var failures []validate.FieldError + for i, mask := range [1]uint8{ + 0b00000011, + } { + if result := (requiredBitSet[i] & mask) ^ mask; result != 0 { + // Mask only required fields and check equality to mask using XOR. + // + // If XOR result is not zero, result is not equal to expected, so some fields are missed. + // Bits of fields which would be set are actually bits of missed fields. + missed := bits.OnesCount8(result) + for bitN := 0; bitN < missed; bitN++ { + bitIdx := bits.TrailingZeros8(result) + fieldIdx := i*8 + bitIdx + var name string + if fieldIdx < len(jsonFieldsNameOfCreateChat) { + name = jsonFieldsNameOfCreateChat[fieldIdx] + } else { + name = strconv.Itoa(fieldIdx) + } + failures = append(failures, validate.FieldError{ + Name: name, + Error: validate.ErrFieldRequired, + }) + // Reset bit. + result &^= 1 << bitIdx + } + } + } + if len(failures) > 0 { + return &validate.Error{Fields: failures} + } + + return nil +} + +// MarshalJSON implements stdjson.Marshaler. +func (s *CreateChat) MarshalJSON() ([]byte, error) { + e := jx.Encoder{} + s.Encode(&e) + return e.Bytes(), nil +} + +// UnmarshalJSON implements stdjson.Unmarshaler. +func (s *CreateChat) UnmarshalJSON(data []byte) error { + d := jx.DecodeBytes(data) + return s.Decode(d) +} + +// Encode implements json.Marshaler. +func (s *CreateMessage) Encode(e *jx.Encoder) { + e.ObjStart() + s.encodeFields(e) + e.ObjEnd() +} + +// encodeFields encodes fields. +func (s *CreateMessage) encodeFields(e *jx.Encoder) { + { + if s.AttachmentIds != nil { + e.FieldStart("attachment_ids") + e.ArrStart() + for _, elem := range s.AttachmentIds { + json.EncodeUUID(e, elem) + } + e.ArrEnd() + } + } + { + e.FieldStart("text") + e.Str(s.Text) + } +} + +var jsonFieldsNameOfCreateMessage = [2]string{ + 0: "attachment_ids", + 1: "text", +} + +// Decode decodes CreateMessage from json. +func (s *CreateMessage) Decode(d *jx.Decoder) error { + if s == nil { + return errors.New("invalid: unable to decode CreateMessage to nil") + } + var requiredBitSet [1]uint8 + s.setDefaults() + + if err := d.ObjBytes(func(d *jx.Decoder, k []byte) error { + switch string(k) { + case "attachment_ids": + if err := func() error { + s.AttachmentIds = make([]uuid.UUID, 0) + if err := d.Arr(func(d *jx.Decoder) error { + var elem uuid.UUID + v, err := json.DecodeUUID(d) + elem = v + if err != nil { + return err + } + s.AttachmentIds = append(s.AttachmentIds, elem) + return nil + }); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"attachment_ids\"") + } + case "text": + requiredBitSet[0] |= 1 << 1 + if err := func() error { + v, err := d.Str() + s.Text = string(v) + if err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"text\"") + } + default: + return errors.Errorf("unexpected field %q", k) + } + return nil + }); err != nil { + return errors.Wrap(err, "decode CreateMessage") + } + // Validate required fields. + var failures []validate.FieldError + for i, mask := range [1]uint8{ + 0b00000010, + } { + if result := (requiredBitSet[i] & mask) ^ mask; result != 0 { + // Mask only required fields and check equality to mask using XOR. + // + // If XOR result is not zero, result is not equal to expected, so some fields are missed. + // Bits of fields which would be set are actually bits of missed fields. + missed := bits.OnesCount8(result) + for bitN := 0; bitN < missed; bitN++ { + bitIdx := bits.TrailingZeros8(result) + fieldIdx := i*8 + bitIdx + var name string + if fieldIdx < len(jsonFieldsNameOfCreateMessage) { + name = jsonFieldsNameOfCreateMessage[fieldIdx] + } else { + name = strconv.Itoa(fieldIdx) + } + failures = append(failures, validate.FieldError{ + Name: name, + Error: validate.ErrFieldRequired, + }) + // Reset bit. + result &^= 1 << bitIdx + } + } + } + if len(failures) > 0 { + return &validate.Error{Fields: failures} + } + + return nil +} + +// MarshalJSON implements stdjson.Marshaler. +func (s *CreateMessage) MarshalJSON() ([]byte, error) { + e := jx.Encoder{} + s.Encode(&e) + return e.Bytes(), nil +} + +// UnmarshalJSON implements stdjson.Unmarshaler. +func (s *CreateMessage) UnmarshalJSON(data []byte) error { + d := jx.DecodeBytes(data) + return s.Decode(d) +} + +// Encode implements json.Marshaler. +func (s *CreateUser) Encode(e *jx.Encoder) { + e.ObjStart() + s.encodeFields(e) + e.ObjEnd() +} + +// encodeFields encodes fields. +func (s *CreateUser) encodeFields(e *jx.Encoder) { + { + e.FieldStart("display_name") + e.Str(s.DisplayName) + } + { + e.FieldStart("password") + e.Str(s.Password) + } + { + e.FieldStart("username") + e.Str(s.Username) + } +} + +var jsonFieldsNameOfCreateUser = [3]string{ + 0: "display_name", + 1: "password", + 2: "username", +} + +// Decode decodes CreateUser from json. +func (s *CreateUser) Decode(d *jx.Decoder) error { + if s == nil { + return errors.New("invalid: unable to decode CreateUser to nil") + } + var requiredBitSet [1]uint8 + + if err := d.ObjBytes(func(d *jx.Decoder, k []byte) error { + switch string(k) { + case "display_name": + requiredBitSet[0] |= 1 << 0 + if err := func() error { + v, err := d.Str() + s.DisplayName = string(v) + if err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"display_name\"") + } + case "password": + requiredBitSet[0] |= 1 << 1 + if err := func() error { + v, err := d.Str() + s.Password = string(v) + if err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"password\"") + } + case "username": + requiredBitSet[0] |= 1 << 2 + if err := func() error { + v, err := d.Str() + s.Username = string(v) + if err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"username\"") + } + default: + return errors.Errorf("unexpected field %q", k) + } + return nil + }); err != nil { + return errors.Wrap(err, "decode CreateUser") + } + // Validate required fields. + var failures []validate.FieldError + for i, mask := range [1]uint8{ + 0b00000111, + } { + if result := (requiredBitSet[i] & mask) ^ mask; result != 0 { + // Mask only required fields and check equality to mask using XOR. + // + // If XOR result is not zero, result is not equal to expected, so some fields are missed. + // Bits of fields which would be set are actually bits of missed fields. + missed := bits.OnesCount8(result) + for bitN := 0; bitN < missed; bitN++ { + bitIdx := bits.TrailingZeros8(result) + fieldIdx := i*8 + bitIdx + var name string + if fieldIdx < len(jsonFieldsNameOfCreateUser) { + name = jsonFieldsNameOfCreateUser[fieldIdx] + } else { + name = strconv.Itoa(fieldIdx) + } + failures = append(failures, validate.FieldError{ + Name: name, + Error: validate.ErrFieldRequired, + }) + // Reset bit. + result &^= 1 << bitIdx + } + } + } + if len(failures) > 0 { + return &validate.Error{Fields: failures} + } + + return nil +} + +// MarshalJSON implements stdjson.Marshaler. +func (s *CreateUser) MarshalJSON() ([]byte, error) { + e := jx.Encoder{} + s.Encode(&e) + return e.Bytes(), nil +} + +// UnmarshalJSON implements stdjson.Unmarshaler. +func (s *CreateUser) UnmarshalJSON(data []byte) error { + d := jx.DecodeBytes(data) + return s.Decode(d) +} + +// Encode implements json.Marshaler. +func (s *Error) Encode(e *jx.Encoder) { + e.ObjStart() + s.encodeFields(e) + e.ObjEnd() +} + +// encodeFields encodes fields. +func (s *Error) encodeFields(e *jx.Encoder) { + { + e.FieldStart("error") + s.Error.Encode(e) + } +} + +var jsonFieldsNameOfError = [1]string{ + 0: "error", +} + +// Decode decodes Error from json. +func (s *Error) Decode(d *jx.Decoder) error { + if s == nil { + return errors.New("invalid: unable to decode Error to nil") + } + var requiredBitSet [1]uint8 + + if err := d.ObjBytes(func(d *jx.Decoder, k []byte) error { + switch string(k) { + case "error": + requiredBitSet[0] |= 1 << 0 + if err := func() error { + if err := s.Error.Decode(d); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"error\"") + } + default: + return errors.Errorf("unexpected field %q", k) + } + return nil + }); err != nil { + return errors.Wrap(err, "decode Error") + } + // Validate required fields. + var failures []validate.FieldError + for i, mask := range [1]uint8{ + 0b00000001, + } { + if result := (requiredBitSet[i] & mask) ^ mask; result != 0 { + // Mask only required fields and check equality to mask using XOR. + // + // If XOR result is not zero, result is not equal to expected, so some fields are missed. + // Bits of fields which would be set are actually bits of missed fields. + missed := bits.OnesCount8(result) + for bitN := 0; bitN < missed; bitN++ { + bitIdx := bits.TrailingZeros8(result) + fieldIdx := i*8 + bitIdx + var name string + if fieldIdx < len(jsonFieldsNameOfError) { + name = jsonFieldsNameOfError[fieldIdx] + } else { + name = strconv.Itoa(fieldIdx) + } + failures = append(failures, validate.FieldError{ + Name: name, + Error: validate.ErrFieldRequired, + }) + // Reset bit. + result &^= 1 << bitIdx + } + } + } + if len(failures) > 0 { + return &validate.Error{Fields: failures} + } + + return nil +} + +// MarshalJSON implements stdjson.Marshaler. +func (s *Error) MarshalJSON() ([]byte, error) { + e := jx.Encoder{} + s.Encode(&e) + return e.Bytes(), nil +} + +// UnmarshalJSON implements stdjson.Unmarshaler. +func (s *Error) UnmarshalJSON(data []byte) error { + d := jx.DecodeBytes(data) + return s.Decode(d) +} + +// Encode implements json.Marshaler. +func (s *ErrorError) Encode(e *jx.Encoder) { + e.ObjStart() + s.encodeFields(e) + e.ObjEnd() +} + +// encodeFields encodes fields. +func (s *ErrorError) encodeFields(e *jx.Encoder) { + { + e.FieldStart("code") + s.Code.Encode(e) + } + { + e.FieldStart("message") + e.Str(s.Message) + } + { + e.FieldStart("request_id") + e.Str(s.RequestID) + } +} + +var jsonFieldsNameOfErrorError = [3]string{ + 0: "code", + 1: "message", + 2: "request_id", +} + +// Decode decodes ErrorError from json. +func (s *ErrorError) Decode(d *jx.Decoder) error { + if s == nil { + return errors.New("invalid: unable to decode ErrorError to nil") + } + var requiredBitSet [1]uint8 + + if err := d.ObjBytes(func(d *jx.Decoder, k []byte) error { + switch string(k) { + case "code": + requiredBitSet[0] |= 1 << 0 + if err := func() error { + if err := s.Code.Decode(d); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"code\"") + } + case "message": + requiredBitSet[0] |= 1 << 1 + if err := func() error { + v, err := d.Str() + s.Message = string(v) + if err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"message\"") + } + case "request_id": + requiredBitSet[0] |= 1 << 2 + if err := func() error { + v, err := d.Str() + s.RequestID = string(v) + if err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"request_id\"") + } + default: + return errors.Errorf("unexpected field %q", k) + } + return nil + }); err != nil { + return errors.Wrap(err, "decode ErrorError") + } + // Validate required fields. + var failures []validate.FieldError + for i, mask := range [1]uint8{ + 0b00000111, + } { + if result := (requiredBitSet[i] & mask) ^ mask; result != 0 { + // Mask only required fields and check equality to mask using XOR. + // + // If XOR result is not zero, result is not equal to expected, so some fields are missed. + // Bits of fields which would be set are actually bits of missed fields. + missed := bits.OnesCount8(result) + for bitN := 0; bitN < missed; bitN++ { + bitIdx := bits.TrailingZeros8(result) + fieldIdx := i*8 + bitIdx + var name string + if fieldIdx < len(jsonFieldsNameOfErrorError) { + name = jsonFieldsNameOfErrorError[fieldIdx] + } else { + name = strconv.Itoa(fieldIdx) + } + failures = append(failures, validate.FieldError{ + Name: name, + Error: validate.ErrFieldRequired, + }) + // Reset bit. + result &^= 1 << bitIdx + } + } + } + if len(failures) > 0 { + return &validate.Error{Fields: failures} + } + + return nil +} + +// MarshalJSON implements stdjson.Marshaler. +func (s *ErrorError) MarshalJSON() ([]byte, error) { + e := jx.Encoder{} + s.Encode(&e) + return e.Bytes(), nil +} + +// UnmarshalJSON implements stdjson.Unmarshaler. +func (s *ErrorError) UnmarshalJSON(data []byte) error { + d := jx.DecodeBytes(data) + return s.Decode(d) +} + +// Encode encodes ErrorErrorCode as json. +func (s ErrorErrorCode) Encode(e *jx.Encoder) { + e.Str(string(s)) +} + +// Decode decodes ErrorErrorCode from json. +func (s *ErrorErrorCode) Decode(d *jx.Decoder) error { + if s == nil { + return errors.New("invalid: unable to decode ErrorErrorCode to nil") + } + v, err := d.StrBytes() + if err != nil { + return err + } + // Try to use constant string. + switch ErrorErrorCode(v) { + case ErrorErrorCodeInvalidRequest: + *s = ErrorErrorCodeInvalidRequest + case ErrorErrorCodeUnauthorized: + *s = ErrorErrorCodeUnauthorized + case ErrorErrorCodeNotFound: + *s = ErrorErrorCodeNotFound + case ErrorErrorCodeConflict: + *s = ErrorErrorCodeConflict + case ErrorErrorCodePayloadTooLarge: + *s = ErrorErrorCodePayloadTooLarge + case ErrorErrorCodeUnsupportedMediaType: + *s = ErrorErrorCodeUnsupportedMediaType + case ErrorErrorCodeRateLimited: + *s = ErrorErrorCodeRateLimited + case ErrorErrorCodeUnavailable: + *s = ErrorErrorCodeUnavailable + case ErrorErrorCodeInternalError: + *s = ErrorErrorCodeInternalError + default: + *s = ErrorErrorCode(v) + } + + return nil +} + +// MarshalJSON implements stdjson.Marshaler. +func (s ErrorErrorCode) MarshalJSON() ([]byte, error) { + e := jx.Encoder{} + s.Encode(&e) + return e.Bytes(), nil +} + +// UnmarshalJSON implements stdjson.Unmarshaler. +func (s *ErrorErrorCode) UnmarshalJSON(data []byte) error { + d := jx.DecodeBytes(data) + return s.Decode(d) +} + +// Encode implements json.Marshaler. +func (s *Health) Encode(e *jx.Encoder) { + e.ObjStart() + s.encodeFields(e) + e.ObjEnd() +} + +// encodeFields encodes fields. +func (s *Health) encodeFields(e *jx.Encoder) { + { + e.FieldStart("status") + s.Status.Encode(e) + } +} + +var jsonFieldsNameOfHealth = [1]string{ + 0: "status", +} + +// Decode decodes Health from json. +func (s *Health) Decode(d *jx.Decoder) error { + if s == nil { + return errors.New("invalid: unable to decode Health to nil") + } + var requiredBitSet [1]uint8 + + if err := d.ObjBytes(func(d *jx.Decoder, k []byte) error { + switch string(k) { + case "status": + requiredBitSet[0] |= 1 << 0 + if err := func() error { + if err := s.Status.Decode(d); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"status\"") + } + default: + return errors.Errorf("unexpected field %q", k) + } + return nil + }); err != nil { + return errors.Wrap(err, "decode Health") + } + // Validate required fields. + var failures []validate.FieldError + for i, mask := range [1]uint8{ + 0b00000001, + } { + if result := (requiredBitSet[i] & mask) ^ mask; result != 0 { + // Mask only required fields and check equality to mask using XOR. + // + // If XOR result is not zero, result is not equal to expected, so some fields are missed. + // Bits of fields which would be set are actually bits of missed fields. + missed := bits.OnesCount8(result) + for bitN := 0; bitN < missed; bitN++ { + bitIdx := bits.TrailingZeros8(result) + fieldIdx := i*8 + bitIdx + var name string + if fieldIdx < len(jsonFieldsNameOfHealth) { + name = jsonFieldsNameOfHealth[fieldIdx] + } else { + name = strconv.Itoa(fieldIdx) + } + failures = append(failures, validate.FieldError{ + Name: name, + Error: validate.ErrFieldRequired, + }) + // Reset bit. + result &^= 1 << bitIdx + } + } + } + if len(failures) > 0 { + return &validate.Error{Fields: failures} + } + + return nil +} + +// MarshalJSON implements stdjson.Marshaler. +func (s *Health) MarshalJSON() ([]byte, error) { + e := jx.Encoder{} + s.Encode(&e) + return e.Bytes(), nil +} + +// UnmarshalJSON implements stdjson.Unmarshaler. +func (s *Health) UnmarshalJSON(data []byte) error { + d := jx.DecodeBytes(data) + return s.Decode(d) +} + +// Encode encodes HealthStatus as json. +func (s HealthStatus) Encode(e *jx.Encoder) { + e.Str(string(s)) +} + +// Decode decodes HealthStatus from json. +func (s *HealthStatus) Decode(d *jx.Decoder) error { + if s == nil { + return errors.New("invalid: unable to decode HealthStatus to nil") + } + v, err := d.StrBytes() + if err != nil { + return err + } + // Try to use constant string. + switch HealthStatus(v) { + case HealthStatusOk: + *s = HealthStatusOk + default: + *s = HealthStatus(v) + } + + return nil +} + +// MarshalJSON implements stdjson.Marshaler. +func (s HealthStatus) MarshalJSON() ([]byte, error) { + e := jx.Encoder{} + s.Encode(&e) + return e.Bytes(), nil +} + +// UnmarshalJSON implements stdjson.Unmarshaler. +func (s *HealthStatus) UnmarshalJSON(data []byte) error { + d := jx.DecodeBytes(data) + return s.Decode(d) +} + +// Encode implements json.Marshaler. +func (s *Message) Encode(e *jx.Encoder) { + e.ObjStart() + s.encodeFields(e) + e.ObjEnd() +} + +// encodeFields encodes fields. +func (s *Message) encodeFields(e *jx.Encoder) { + { + e.FieldStart("attachment_ids") + e.ArrStart() + for _, elem := range s.AttachmentIds { + json.EncodeUUID(e, elem) + } + e.ArrEnd() + } + { + e.FieldStart("chat_id") + json.EncodeUUID(e, s.ChatID) + } + { + e.FieldStart("created_at") + json.EncodeDateTime(e, s.CreatedAt) + } + { + e.FieldStart("id") + json.EncodeUUID(e, s.ID) + } + { + e.FieldStart("sender_id") + json.EncodeUUID(e, s.SenderID) + } + { + e.FieldStart("text") + e.Str(s.Text) + } +} + +var jsonFieldsNameOfMessage = [6]string{ + 0: "attachment_ids", + 1: "chat_id", + 2: "created_at", + 3: "id", + 4: "sender_id", + 5: "text", +} + +// Decode decodes Message from json. +func (s *Message) Decode(d *jx.Decoder) error { + if s == nil { + return errors.New("invalid: unable to decode Message to nil") + } + var requiredBitSet [1]uint8 + + if err := d.ObjBytes(func(d *jx.Decoder, k []byte) error { + switch string(k) { + case "attachment_ids": + requiredBitSet[0] |= 1 << 0 + if err := func() error { + s.AttachmentIds = make([]uuid.UUID, 0) + if err := d.Arr(func(d *jx.Decoder) error { + var elem uuid.UUID + v, err := json.DecodeUUID(d) + elem = v + if err != nil { + return err + } + s.AttachmentIds = append(s.AttachmentIds, elem) + return nil + }); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"attachment_ids\"") + } + case "chat_id": + requiredBitSet[0] |= 1 << 1 + if err := func() error { + v, err := json.DecodeUUID(d) + s.ChatID = v + if err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"chat_id\"") + } + case "created_at": + requiredBitSet[0] |= 1 << 2 + if err := func() error { + v, err := json.DecodeDateTime(d) + s.CreatedAt = v + if err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"created_at\"") + } + case "id": + requiredBitSet[0] |= 1 << 3 + if err := func() error { + v, err := json.DecodeUUID(d) + s.ID = v + if err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"id\"") + } + case "sender_id": + requiredBitSet[0] |= 1 << 4 + if err := func() error { + v, err := json.DecodeUUID(d) + s.SenderID = v + if err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"sender_id\"") + } + case "text": + requiredBitSet[0] |= 1 << 5 + if err := func() error { + v, err := d.Str() + s.Text = string(v) + if err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"text\"") + } + default: + return errors.Errorf("unexpected field %q", k) + } + return nil + }); err != nil { + return errors.Wrap(err, "decode Message") + } + // Validate required fields. + var failures []validate.FieldError + for i, mask := range [1]uint8{ + 0b00111111, + } { + if result := (requiredBitSet[i] & mask) ^ mask; result != 0 { + // Mask only required fields and check equality to mask using XOR. + // + // If XOR result is not zero, result is not equal to expected, so some fields are missed. + // Bits of fields which would be set are actually bits of missed fields. + missed := bits.OnesCount8(result) + for bitN := 0; bitN < missed; bitN++ { + bitIdx := bits.TrailingZeros8(result) + fieldIdx := i*8 + bitIdx + var name string + if fieldIdx < len(jsonFieldsNameOfMessage) { + name = jsonFieldsNameOfMessage[fieldIdx] + } else { + name = strconv.Itoa(fieldIdx) + } + failures = append(failures, validate.FieldError{ + Name: name, + Error: validate.ErrFieldRequired, + }) + // Reset bit. + result &^= 1 << bitIdx + } + } + } + if len(failures) > 0 { + return &validate.Error{Fields: failures} + } + + return nil +} + +// MarshalJSON implements stdjson.Marshaler. +func (s *Message) MarshalJSON() ([]byte, error) { + e := jx.Encoder{} + s.Encode(&e) + return e.Bytes(), nil +} + +// UnmarshalJSON implements stdjson.Unmarshaler. +func (s *Message) UnmarshalJSON(data []byte) error { + d := jx.DecodeBytes(data) + return s.Decode(d) +} + +// Encode implements json.Marshaler. +func (s *MessagePage) Encode(e *jx.Encoder) { + e.ObjStart() + s.encodeFields(e) + e.ObjEnd() +} + +// encodeFields encodes fields. +func (s *MessagePage) encodeFields(e *jx.Encoder) { + { + e.FieldStart("items") + e.ArrStart() + for _, elem := range s.Items { + elem.Encode(e) + } + e.ArrEnd() + } + { + e.FieldStart("next_cursor") + s.NextCursor.Encode(e) + } +} + +var jsonFieldsNameOfMessagePage = [2]string{ + 0: "items", + 1: "next_cursor", +} + +// Decode decodes MessagePage from json. +func (s *MessagePage) Decode(d *jx.Decoder) error { + if s == nil { + return errors.New("invalid: unable to decode MessagePage to nil") + } + var requiredBitSet [1]uint8 + + if err := d.ObjBytes(func(d *jx.Decoder, k []byte) error { + switch string(k) { + case "items": + requiredBitSet[0] |= 1 << 0 + if err := func() error { + s.Items = make([]Message, 0) + if err := d.Arr(func(d *jx.Decoder) error { + var elem Message + if err := elem.Decode(d); err != nil { + return err + } + s.Items = append(s.Items, elem) + return nil + }); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"items\"") + } + case "next_cursor": + requiredBitSet[0] |= 1 << 1 + if err := func() error { + if err := s.NextCursor.Decode(d); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"next_cursor\"") + } + default: + return errors.Errorf("unexpected field %q", k) + } + return nil + }); err != nil { + return errors.Wrap(err, "decode MessagePage") + } + // Validate required fields. + var failures []validate.FieldError + for i, mask := range [1]uint8{ + 0b00000011, + } { + if result := (requiredBitSet[i] & mask) ^ mask; result != 0 { + // Mask only required fields and check equality to mask using XOR. + // + // If XOR result is not zero, result is not equal to expected, so some fields are missed. + // Bits of fields which would be set are actually bits of missed fields. + missed := bits.OnesCount8(result) + for bitN := 0; bitN < missed; bitN++ { + bitIdx := bits.TrailingZeros8(result) + fieldIdx := i*8 + bitIdx + var name string + if fieldIdx < len(jsonFieldsNameOfMessagePage) { + name = jsonFieldsNameOfMessagePage[fieldIdx] + } else { + name = strconv.Itoa(fieldIdx) + } + failures = append(failures, validate.FieldError{ + Name: name, + Error: validate.ErrFieldRequired, + }) + // Reset bit. + result &^= 1 << bitIdx + } + } + } + if len(failures) > 0 { + return &validate.Error{Fields: failures} + } + + return nil +} + +// MarshalJSON implements stdjson.Marshaler. +func (s *MessagePage) MarshalJSON() ([]byte, error) { + e := jx.Encoder{} + s.Encode(&e) + return e.Bytes(), nil +} + +// UnmarshalJSON implements stdjson.Unmarshaler. +func (s *MessagePage) UnmarshalJSON(data []byte) error { + d := jx.DecodeBytes(data) + return s.Decode(d) +} + +// Encode encodes string as json. +func (o NilString) Encode(e *jx.Encoder) { + if o.Null { + e.Null() + return + } + e.Str(string(o.Value)) +} + +// Decode decodes string from json. +func (o *NilString) Decode(d *jx.Decoder) error { + if o == nil { + return errors.New("invalid: unable to decode NilString to nil") + } + if d.Next() == jx.Null { + if err := d.Null(); err != nil { + return err + } + + var v string + o.Value = v + o.Null = true + return nil + } + o.Null = false + v, err := d.Str() + if err != nil { + return err + } + o.Value = string(v) + return nil +} + +// MarshalJSON implements stdjson.Marshaler. +func (s NilString) MarshalJSON() ([]byte, error) { + e := jx.Encoder{} + s.Encode(&e) + return e.Bytes(), nil +} + +// UnmarshalJSON implements stdjson.Unmarshaler. +func (s *NilString) UnmarshalJSON(data []byte) error { + d := jx.DecodeBytes(data) + return s.Decode(d) +} + +// Encode implements json.Marshaler. +func (s *Session) Encode(e *jx.Encoder) { + e.ObjStart() + s.encodeFields(e) + e.ObjEnd() +} + +// encodeFields encodes fields. +func (s *Session) encodeFields(e *jx.Encoder) { + { + e.FieldStart("expires_at") + json.EncodeDateTime(e, s.ExpiresAt) + } + { + e.FieldStart("token") + e.Str(s.Token) + } + { + e.FieldStart("token_type") + e.Str("Bearer") + } + { + e.FieldStart("user") + s.User.Encode(e) + } +} + +var jsonFieldsNameOfSession = [4]string{ + 0: "expires_at", + 1: "token", + 2: "token_type", + 3: "user", +} + +// Decode decodes Session from json. +func (s *Session) Decode(d *jx.Decoder) error { + if s == nil { + return errors.New("invalid: unable to decode Session to nil") + } + var requiredBitSet [1]uint8 + + if err := d.ObjBytes(func(d *jx.Decoder, k []byte) error { + switch string(k) { + case "expires_at": + requiredBitSet[0] |= 1 << 0 + if err := func() error { + v, err := json.DecodeDateTime(d) + s.ExpiresAt = v + if err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"expires_at\"") + } + case "token": + requiredBitSet[0] |= 1 << 1 + if err := func() error { + v, err := d.Str() + s.Token = string(v) + if err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"token\"") + } + case "token_type": + requiredBitSet[0] |= 1 << 2 + if err := func() error { + v, err := d.Str() + s.TokenType = string(v) + if err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"token_type\"") + } + case "user": + requiredBitSet[0] |= 1 << 3 + if err := func() error { + if err := s.User.Decode(d); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"user\"") + } + default: + return errors.Errorf("unexpected field %q", k) + } + return nil + }); err != nil { + return errors.Wrap(err, "decode Session") + } + // Validate required fields. + var failures []validate.FieldError + for i, mask := range [1]uint8{ + 0b00001111, + } { + if result := (requiredBitSet[i] & mask) ^ mask; result != 0 { + // Mask only required fields and check equality to mask using XOR. + // + // If XOR result is not zero, result is not equal to expected, so some fields are missed. + // Bits of fields which would be set are actually bits of missed fields. + missed := bits.OnesCount8(result) + for bitN := 0; bitN < missed; bitN++ { + bitIdx := bits.TrailingZeros8(result) + fieldIdx := i*8 + bitIdx + var name string + if fieldIdx < len(jsonFieldsNameOfSession) { + name = jsonFieldsNameOfSession[fieldIdx] + } else { + name = strconv.Itoa(fieldIdx) + } + failures = append(failures, validate.FieldError{ + Name: name, + Error: validate.ErrFieldRequired, + }) + // Reset bit. + result &^= 1 << bitIdx + } + } + } + if len(failures) > 0 { + return &validate.Error{Fields: failures} + } + + return nil +} + +// MarshalJSON implements stdjson.Marshaler. +func (s *Session) MarshalJSON() ([]byte, error) { + e := jx.Encoder{} + s.Encode(&e) + return e.Bytes(), nil +} + +// UnmarshalJSON implements stdjson.Unmarshaler. +func (s *Session) UnmarshalJSON(data []byte) error { + d := jx.DecodeBytes(data) + return s.Decode(d) +} + +// Encode implements json.Marshaler. +func (s *User) Encode(e *jx.Encoder) { + e.ObjStart() + s.encodeFields(e) + e.ObjEnd() +} + +// encodeFields encodes fields. +func (s *User) encodeFields(e *jx.Encoder) { + { + e.FieldStart("created_at") + json.EncodeDateTime(e, s.CreatedAt) + } + { + e.FieldStart("display_name") + e.Str(s.DisplayName) + } + { + e.FieldStart("id") + json.EncodeUUID(e, s.ID) + } + { + e.FieldStart("username") + e.Str(s.Username) + } +} + +var jsonFieldsNameOfUser = [4]string{ + 0: "created_at", + 1: "display_name", + 2: "id", + 3: "username", +} + +// Decode decodes User from json. +func (s *User) Decode(d *jx.Decoder) error { + if s == nil { + return errors.New("invalid: unable to decode User to nil") + } + var requiredBitSet [1]uint8 + + if err := d.ObjBytes(func(d *jx.Decoder, k []byte) error { + switch string(k) { + case "created_at": + requiredBitSet[0] |= 1 << 0 + if err := func() error { + v, err := json.DecodeDateTime(d) + s.CreatedAt = v + if err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"created_at\"") + } + case "display_name": + requiredBitSet[0] |= 1 << 1 + if err := func() error { + v, err := d.Str() + s.DisplayName = string(v) + if err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"display_name\"") + } + case "id": + requiredBitSet[0] |= 1 << 2 + if err := func() error { + v, err := json.DecodeUUID(d) + s.ID = v + if err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"id\"") + } + case "username": + requiredBitSet[0] |= 1 << 3 + if err := func() error { + v, err := d.Str() + s.Username = string(v) + if err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"username\"") + } + default: + return errors.Errorf("unexpected field %q", k) + } + return nil + }); err != nil { + return errors.Wrap(err, "decode User") + } + // Validate required fields. + var failures []validate.FieldError + for i, mask := range [1]uint8{ + 0b00001111, + } { + if result := (requiredBitSet[i] & mask) ^ mask; result != 0 { + // Mask only required fields and check equality to mask using XOR. + // + // If XOR result is not zero, result is not equal to expected, so some fields are missed. + // Bits of fields which would be set are actually bits of missed fields. + missed := bits.OnesCount8(result) + for bitN := 0; bitN < missed; bitN++ { + bitIdx := bits.TrailingZeros8(result) + fieldIdx := i*8 + bitIdx + var name string + if fieldIdx < len(jsonFieldsNameOfUser) { + name = jsonFieldsNameOfUser[fieldIdx] + } else { + name = strconv.Itoa(fieldIdx) + } + failures = append(failures, validate.FieldError{ + Name: name, + Error: validate.ErrFieldRequired, + }) + // Reset bit. + result &^= 1 << bitIdx + } + } + } + if len(failures) > 0 { + return &validate.Error{Fields: failures} + } + + return nil +} + +// MarshalJSON implements stdjson.Marshaler. +func (s *User) MarshalJSON() ([]byte, error) { + e := jx.Encoder{} + s.Encode(&e) + return e.Bytes(), nil +} + +// UnmarshalJSON implements stdjson.Unmarshaler. +func (s *User) UnmarshalJSON(data []byte) error { + d := jx.DecodeBytes(data) + return s.Decode(d) +} + +// Encode implements json.Marshaler. +func (s *Variant) Encode(e *jx.Encoder) { + e.ObjStart() + s.encodeFields(e) + e.ObjEnd() +} + +// encodeFields encodes fields. +func (s *Variant) encodeFields(e *jx.Encoder) { + { + e.FieldStart("content_type") + s.ContentType.Encode(e) + } + { + e.FieldStart("height") + e.Int(s.Height) + } + { + e.FieldStart("name") + s.Name.Encode(e) + } + { + e.FieldStart("sha256") + e.Str(s.SHA256) + } + { + e.FieldStart("size_bytes") + e.Int(s.SizeBytes) + } + { + e.FieldStart("width") + e.Int(s.Width) + } +} + +var jsonFieldsNameOfVariant = [6]string{ + 0: "content_type", + 1: "height", + 2: "name", + 3: "sha256", + 4: "size_bytes", + 5: "width", +} + +// Decode decodes Variant from json. +func (s *Variant) Decode(d *jx.Decoder) error { + if s == nil { + return errors.New("invalid: unable to decode Variant to nil") + } + var requiredBitSet [1]uint8 + + if err := d.ObjBytes(func(d *jx.Decoder, k []byte) error { + switch string(k) { + case "content_type": + requiredBitSet[0] |= 1 << 0 + if err := func() error { + if err := s.ContentType.Decode(d); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"content_type\"") + } + case "height": + requiredBitSet[0] |= 1 << 1 + if err := func() error { + v, err := d.Int() + s.Height = int(v) + if err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"height\"") + } + case "name": + requiredBitSet[0] |= 1 << 2 + if err := func() error { + if err := s.Name.Decode(d); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"name\"") + } + case "sha256": + requiredBitSet[0] |= 1 << 3 + if err := func() error { + v, err := d.Str() + s.SHA256 = string(v) + if err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"sha256\"") + } + case "size_bytes": + requiredBitSet[0] |= 1 << 4 + if err := func() error { + v, err := d.Int() + s.SizeBytes = int(v) + if err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"size_bytes\"") + } + case "width": + requiredBitSet[0] |= 1 << 5 + if err := func() error { + v, err := d.Int() + s.Width = int(v) + if err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"width\"") + } + default: + return errors.Errorf("unexpected field %q", k) + } + return nil + }); err != nil { + return errors.Wrap(err, "decode Variant") + } + // Validate required fields. + var failures []validate.FieldError + for i, mask := range [1]uint8{ + 0b00111111, + } { + if result := (requiredBitSet[i] & mask) ^ mask; result != 0 { + // Mask only required fields and check equality to mask using XOR. + // + // If XOR result is not zero, result is not equal to expected, so some fields are missed. + // Bits of fields which would be set are actually bits of missed fields. + missed := bits.OnesCount8(result) + for bitN := 0; bitN < missed; bitN++ { + bitIdx := bits.TrailingZeros8(result) + fieldIdx := i*8 + bitIdx + var name string + if fieldIdx < len(jsonFieldsNameOfVariant) { + name = jsonFieldsNameOfVariant[fieldIdx] + } else { + name = strconv.Itoa(fieldIdx) + } + failures = append(failures, validate.FieldError{ + Name: name, + Error: validate.ErrFieldRequired, + }) + // Reset bit. + result &^= 1 << bitIdx + } + } + } + if len(failures) > 0 { + return &validate.Error{Fields: failures} + } + + return nil +} + +// MarshalJSON implements stdjson.Marshaler. +func (s *Variant) MarshalJSON() ([]byte, error) { + e := jx.Encoder{} + s.Encode(&e) + return e.Bytes(), nil +} + +// UnmarshalJSON implements stdjson.Unmarshaler. +func (s *Variant) UnmarshalJSON(data []byte) error { + d := jx.DecodeBytes(data) + return s.Decode(d) +} + +// Encode encodes VariantContentType as json. +func (s VariantContentType) Encode(e *jx.Encoder) { + e.Str(string(s)) +} + +// Decode decodes VariantContentType from json. +func (s *VariantContentType) Decode(d *jx.Decoder) error { + if s == nil { + return errors.New("invalid: unable to decode VariantContentType to nil") + } + v, err := d.StrBytes() + if err != nil { + return err + } + // Try to use constant string. + switch VariantContentType(v) { + case VariantContentTypeImageJpeg: + *s = VariantContentTypeImageJpeg + case VariantContentTypeImagePNG: + *s = VariantContentTypeImagePNG + case VariantContentTypeImageWEBP: + *s = VariantContentTypeImageWEBP + default: + *s = VariantContentType(v) + } + + return nil +} + +// MarshalJSON implements stdjson.Marshaler. +func (s VariantContentType) MarshalJSON() ([]byte, error) { + e := jx.Encoder{} + s.Encode(&e) + return e.Bytes(), nil +} + +// UnmarshalJSON implements stdjson.Unmarshaler. +func (s *VariantContentType) UnmarshalJSON(data []byte) error { + d := jx.DecodeBytes(data) + return s.Decode(d) +} + +// Encode encodes VariantName as json. +func (s VariantName) Encode(e *jx.Encoder) { + e.Str(string(s)) +} + +// Decode decodes VariantName from json. +func (s *VariantName) Decode(d *jx.Decoder) error { + if s == nil { + return errors.New("invalid: unable to decode VariantName to nil") + } + v, err := d.StrBytes() + if err != nil { + return err + } + // Try to use constant string. + switch VariantName(v) { + case VariantNameThumbnail: + *s = VariantNameThumbnail + case VariantNameCrop: + *s = VariantNameCrop + case VariantNameOptimized: + *s = VariantNameOptimized + default: + *s = VariantName(v) + } + + return nil +} + +// MarshalJSON implements stdjson.Marshaler. +func (s VariantName) MarshalJSON() ([]byte, error) { + e := jx.Encoder{} + s.Encode(&e) + return e.Bytes(), nil +} + +// UnmarshalJSON implements stdjson.Unmarshaler. +func (s *VariantName) UnmarshalJSON(data []byte) error { + d := jx.DecodeBytes(data) + return s.Decode(d) +} diff --git a/internal/transport/rest/internal/oas/oas_middleware_gen.go b/internal/transport/rest/internal/oas/oas_middleware_gen.go new file mode 100644 index 0000000..7ba299f --- /dev/null +++ b/internal/transport/rest/internal/oas/oas_middleware_gen.go @@ -0,0 +1,10 @@ +// Code generated by ogen, DO NOT EDIT. + +package oas + +import ( + "github.com/ogen-go/ogen/middleware" +) + +// Middleware is middleware type. +type Middleware = middleware.Middleware diff --git a/internal/transport/rest/internal/oas/oas_operations_gen.go b/internal/transport/rest/internal/oas/oas_operations_gen.go new file mode 100644 index 0000000..e078e47 --- /dev/null +++ b/internal/transport/rest/internal/oas/oas_operations_gen.go @@ -0,0 +1,23 @@ +// Code generated by ogen, DO NOT EDIT. + +package oas + +// OperationName is the ogen operation name +type OperationName = string + +const ( + CreateChatOperation OperationName = "CreateChat" + CreateMessageOperation OperationName = "CreateMessage" + CreateSessionOperation OperationName = "CreateSession" + CurrentUserOperation OperationName = "CurrentUser" + DownloadAttachmentOperation OperationName = "DownloadAttachment" + GetAttachmentOperation OperationName = "GetAttachment" + GetChatOperation OperationName = "GetChat" + ListChatsOperation OperationName = "ListChats" + ListMessagesOperation OperationName = "ListMessages" + LivenessOperation OperationName = "Liveness" + ReadinessOperation OperationName = "Readiness" + RegisterUserOperation OperationName = "RegisterUser" + RevokeSessionOperation OperationName = "RevokeSession" + UploadAttachmentOperation OperationName = "UploadAttachment" +) diff --git a/internal/transport/rest/internal/oas/oas_parameters_gen.go b/internal/transport/rest/internal/oas/oas_parameters_gen.go new file mode 100644 index 0000000..1cb4053 --- /dev/null +++ b/internal/transport/rest/internal/oas/oas_parameters_gen.go @@ -0,0 +1,942 @@ +// Code generated by ogen, DO NOT EDIT. + +package oas + +import ( + "net/http" + "net/url" + + "github.com/go-faster/errors" + "github.com/google/uuid" + "github.com/ogen-go/ogen/conv" + "github.com/ogen-go/ogen/middleware" + "github.com/ogen-go/ogen/ogenerrors" + "github.com/ogen-go/ogen/uri" + "github.com/ogen-go/ogen/validate" +) + +// CreateMessageParams is parameters of createMessage operation. +type CreateMessageParams struct { + ChatID uuid.UUID + // Обязателен с lab3. Область: пользователь + метод + путь + + // ключ; хранить результат не менее 24 ч. Повтор того же JSON + // возвращает исходный 201 и то же сообщение, другой JSON — + // 409. + IdempotencyKey string +} + +func unpackCreateMessageParams(packed middleware.Parameters) (params CreateMessageParams) { + { + key := middleware.ParameterKey{ + Name: "chat_id", + In: "path", + } + params.ChatID = packed[key].(uuid.UUID) + } + { + key := middleware.ParameterKey{ + Name: "Idempotency-Key", + In: "header", + } + params.IdempotencyKey = packed[key].(string) + } + return params +} + +func decodeCreateMessageParams(args [1]string, argsEscaped bool, r *http.Request) (params CreateMessageParams, _ error) { + h := uri.NewHeaderDecoder(r.Header) + // Decode path: chat_id. + if err := func() error { + param := args[0] + if argsEscaped { + unescaped, err := url.PathUnescape(args[0]) + if err != nil { + return errors.Wrap(err, "unescape path") + } + param = unescaped + } + if len(param) > 0 { + d := uri.NewPathDecoder(uri.PathDecoderConfig{ + Param: "chat_id", + Value: param, + Style: uri.PathStyleSimple, + Explode: false, + }) + + if err := func() error { + val, err := d.DecodeValue() + if err != nil { + return err + } + + c, err := conv.ToUUID(val) + if err != nil { + return err + } + + params.ChatID = c + return nil + }(); err != nil { + return err + } + } else { + return validate.ErrFieldRequired + } + return nil + }(); err != nil { + return params, &ogenerrors.DecodeParamError{ + Name: "chat_id", + In: "path", + Err: err, + } + } + // Decode header: Idempotency-Key. + if err := func() error { + cfg := uri.HeaderParameterDecodingConfig{ + Name: "Idempotency-Key", + Explode: false, + } + if err := h.HasParam(cfg); err == nil { + if err := h.DecodeParam(cfg, func(d uri.Decoder) error { + val, err := d.DecodeValue() + if err != nil { + return err + } + + c, err := conv.ToString(val) + if err != nil { + return err + } + + params.IdempotencyKey = c + return nil + }); err != nil { + return err + } + if err := func() error { + if err := (validate.String{ + MinLength: 1, + MinLengthSet: true, + MaxLength: 128, + MaxLengthSet: true, + Email: false, + Hostname: false, + Regex: regexMap["^[A-Za-z0-9._:-]+$"], + MinNumeric: 0, + MinNumericSet: false, + MaxNumeric: 0, + MaxNumericSet: false, + }).Validate(string(params.IdempotencyKey)); err != nil { + return errors.Wrap(err, "string") + } + return nil + }(); err != nil { + return err + } + } else { + return err + } + return nil + }(); err != nil { + return params, &ogenerrors.DecodeParamError{ + Name: "Idempotency-Key", + In: "header", + Err: err, + } + } + return params, nil +} + +// DownloadAttachmentParams is parameters of downloadAttachment operation. +type DownloadAttachmentParams struct { + AttachmentID uuid.UUID + Variant OptDownloadAttachmentVariant `json:",omitempty,omitzero"` +} + +func unpackDownloadAttachmentParams(packed middleware.Parameters) (params DownloadAttachmentParams) { + { + key := middleware.ParameterKey{ + Name: "attachment_id", + In: "path", + } + params.AttachmentID = packed[key].(uuid.UUID) + } + { + key := middleware.ParameterKey{ + Name: "variant", + In: "query", + } + if v, ok := packed[key]; ok { + params.Variant = v.(OptDownloadAttachmentVariant) + } + } + return params +} + +func decodeDownloadAttachmentParams(args [1]string, argsEscaped bool, r *http.Request) (params DownloadAttachmentParams, _ error) { + q := uri.NewQueryDecoder(r.URL.Query()) + // Decode path: attachment_id. + if err := func() error { + param := args[0] + if argsEscaped { + unescaped, err := url.PathUnescape(args[0]) + if err != nil { + return errors.Wrap(err, "unescape path") + } + param = unescaped + } + if len(param) > 0 { + d := uri.NewPathDecoder(uri.PathDecoderConfig{ + Param: "attachment_id", + Value: param, + Style: uri.PathStyleSimple, + Explode: false, + }) + + if err := func() error { + val, err := d.DecodeValue() + if err != nil { + return err + } + + c, err := conv.ToUUID(val) + if err != nil { + return err + } + + params.AttachmentID = c + return nil + }(); err != nil { + return err + } + } else { + return validate.ErrFieldRequired + } + return nil + }(); err != nil { + return params, &ogenerrors.DecodeParamError{ + Name: "attachment_id", + In: "path", + Err: err, + } + } + // Set default value for query: variant. + { + val := DownloadAttachmentVariant("original") + params.Variant.SetTo(val) + } + // Decode query: variant. + if err := func() error { + cfg := uri.QueryParameterDecodingConfig{ + Name: "variant", + Style: uri.QueryStyleForm, + Explode: true, + } + + if err := q.HasParam(cfg); err == nil { + if err := q.DecodeParam(cfg, func(d uri.Decoder) error { + var paramsDotVariantVal DownloadAttachmentVariant + if err := func() error { + val, err := d.DecodeValue() + if err != nil { + return err + } + + c, err := conv.ToString(val) + if err != nil { + return err + } + + paramsDotVariantVal = DownloadAttachmentVariant(c) + return nil + }(); err != nil { + return err + } + params.Variant.SetTo(paramsDotVariantVal) + return nil + }); err != nil { + return err + } + if err := func() error { + if value, ok := params.Variant.Get(); ok { + if err := func() error { + if err := value.Validate(); err != nil { + return err + } + return nil + }(); err != nil { + return err + } + } + return nil + }(); err != nil { + return err + } + } + return nil + }(); err != nil { + return params, &ogenerrors.DecodeParamError{ + Name: "variant", + In: "query", + Err: err, + } + } + return params, nil +} + +// GetAttachmentParams is parameters of getAttachment operation. +type GetAttachmentParams struct { + AttachmentID uuid.UUID +} + +func unpackGetAttachmentParams(packed middleware.Parameters) (params GetAttachmentParams) { + { + key := middleware.ParameterKey{ + Name: "attachment_id", + In: "path", + } + params.AttachmentID = packed[key].(uuid.UUID) + } + return params +} + +func decodeGetAttachmentParams(args [1]string, argsEscaped bool, r *http.Request) (params GetAttachmentParams, _ error) { + // Decode path: attachment_id. + if err := func() error { + param := args[0] + if argsEscaped { + unescaped, err := url.PathUnescape(args[0]) + if err != nil { + return errors.Wrap(err, "unescape path") + } + param = unescaped + } + if len(param) > 0 { + d := uri.NewPathDecoder(uri.PathDecoderConfig{ + Param: "attachment_id", + Value: param, + Style: uri.PathStyleSimple, + Explode: false, + }) + + if err := func() error { + val, err := d.DecodeValue() + if err != nil { + return err + } + + c, err := conv.ToUUID(val) + if err != nil { + return err + } + + params.AttachmentID = c + return nil + }(); err != nil { + return err + } + } else { + return validate.ErrFieldRequired + } + return nil + }(); err != nil { + return params, &ogenerrors.DecodeParamError{ + Name: "attachment_id", + In: "path", + Err: err, + } + } + return params, nil +} + +// GetChatParams is parameters of getChat operation. +type GetChatParams struct { + ChatID uuid.UUID +} + +func unpackGetChatParams(packed middleware.Parameters) (params GetChatParams) { + { + key := middleware.ParameterKey{ + Name: "chat_id", + In: "path", + } + params.ChatID = packed[key].(uuid.UUID) + } + return params +} + +func decodeGetChatParams(args [1]string, argsEscaped bool, r *http.Request) (params GetChatParams, _ error) { + // Decode path: chat_id. + if err := func() error { + param := args[0] + if argsEscaped { + unescaped, err := url.PathUnescape(args[0]) + if err != nil { + return errors.Wrap(err, "unescape path") + } + param = unescaped + } + if len(param) > 0 { + d := uri.NewPathDecoder(uri.PathDecoderConfig{ + Param: "chat_id", + Value: param, + Style: uri.PathStyleSimple, + Explode: false, + }) + + if err := func() error { + val, err := d.DecodeValue() + if err != nil { + return err + } + + c, err := conv.ToUUID(val) + if err != nil { + return err + } + + params.ChatID = c + return nil + }(); err != nil { + return err + } + } else { + return validate.ErrFieldRequired + } + return nil + }(); err != nil { + return params, &ogenerrors.DecodeParamError{ + Name: "chat_id", + In: "path", + Err: err, + } + } + return params, nil +} + +// ListChatsParams is parameters of listChats operation. +type ListChatsParams struct { + Limit OptInt `json:",omitempty,omitzero"` + Cursor OptString `json:",omitempty,omitzero"` +} + +func unpackListChatsParams(packed middleware.Parameters) (params ListChatsParams) { + { + key := middleware.ParameterKey{ + Name: "limit", + In: "query", + } + if v, ok := packed[key]; ok { + params.Limit = v.(OptInt) + } + } + { + key := middleware.ParameterKey{ + Name: "cursor", + In: "query", + } + if v, ok := packed[key]; ok { + params.Cursor = v.(OptString) + } + } + return params +} + +func decodeListChatsParams(args [0]string, argsEscaped bool, r *http.Request) (params ListChatsParams, _ error) { + q := uri.NewQueryDecoder(r.URL.Query()) + // Set default value for query: limit. + { + val := int(50) + params.Limit.SetTo(val) + } + // Decode query: limit. + if err := func() error { + cfg := uri.QueryParameterDecodingConfig{ + Name: "limit", + Style: uri.QueryStyleForm, + Explode: true, + } + + if err := q.HasParam(cfg); err == nil { + if err := q.DecodeParam(cfg, func(d uri.Decoder) error { + var paramsDotLimitVal int + if err := func() error { + val, err := d.DecodeValue() + if err != nil { + return err + } + + c, err := conv.ToInt(val) + if err != nil { + return err + } + + paramsDotLimitVal = c + return nil + }(); err != nil { + return err + } + params.Limit.SetTo(paramsDotLimitVal) + return nil + }); err != nil { + return err + } + if err := func() error { + if value, ok := params.Limit.Get(); ok { + if err := func() error { + if err := (validate.Int{ + MinSet: true, + Min: 1, + MaxSet: true, + Max: 100, + MinExclusive: false, + MaxExclusive: false, + MultipleOfSet: false, + MultipleOf: 0, + Pattern: nil, + }).Validate(int64(value)); err != nil { + return errors.Wrap(err, "int") + } + return nil + }(); err != nil { + return err + } + } + return nil + }(); err != nil { + return err + } + } + return nil + }(); err != nil { + return params, &ogenerrors.DecodeParamError{ + Name: "limit", + In: "query", + Err: err, + } + } + // Decode query: cursor. + if err := func() error { + cfg := uri.QueryParameterDecodingConfig{ + Name: "cursor", + Style: uri.QueryStyleForm, + Explode: true, + } + + if err := q.HasParam(cfg); err == nil { + if err := q.DecodeParam(cfg, func(d uri.Decoder) error { + var paramsDotCursorVal string + if err := func() error { + val, err := d.DecodeValue() + if err != nil { + return err + } + + c, err := conv.ToString(val) + if err != nil { + return err + } + + paramsDotCursorVal = c + return nil + }(); err != nil { + return err + } + params.Cursor.SetTo(paramsDotCursorVal) + return nil + }); err != nil { + return err + } + if err := func() error { + if value, ok := params.Cursor.Get(); ok { + if err := func() error { + if err := (validate.String{ + MinLength: 1, + MinLengthSet: true, + MaxLength: 0, + MaxLengthSet: false, + Email: false, + Hostname: false, + Regex: nil, + MinNumeric: 0, + MinNumericSet: false, + MaxNumeric: 0, + MaxNumericSet: false, + }).Validate(string(value)); err != nil { + return errors.Wrap(err, "string") + } + return nil + }(); err != nil { + return err + } + } + return nil + }(); err != nil { + return err + } + } + return nil + }(); err != nil { + return params, &ogenerrors.DecodeParamError{ + Name: "cursor", + In: "query", + Err: err, + } + } + return params, nil +} + +// ListMessagesParams is parameters of listMessages operation. +type ListMessagesParams struct { + ChatID uuid.UUID + Limit OptInt `json:",omitempty,omitzero"` + Cursor OptString `json:",omitempty,omitzero"` +} + +func unpackListMessagesParams(packed middleware.Parameters) (params ListMessagesParams) { + { + key := middleware.ParameterKey{ + Name: "chat_id", + In: "path", + } + params.ChatID = packed[key].(uuid.UUID) + } + { + key := middleware.ParameterKey{ + Name: "limit", + In: "query", + } + if v, ok := packed[key]; ok { + params.Limit = v.(OptInt) + } + } + { + key := middleware.ParameterKey{ + Name: "cursor", + In: "query", + } + if v, ok := packed[key]; ok { + params.Cursor = v.(OptString) + } + } + return params +} + +func decodeListMessagesParams(args [1]string, argsEscaped bool, r *http.Request) (params ListMessagesParams, _ error) { + q := uri.NewQueryDecoder(r.URL.Query()) + // Decode path: chat_id. + if err := func() error { + param := args[0] + if argsEscaped { + unescaped, err := url.PathUnescape(args[0]) + if err != nil { + return errors.Wrap(err, "unescape path") + } + param = unescaped + } + if len(param) > 0 { + d := uri.NewPathDecoder(uri.PathDecoderConfig{ + Param: "chat_id", + Value: param, + Style: uri.PathStyleSimple, + Explode: false, + }) + + if err := func() error { + val, err := d.DecodeValue() + if err != nil { + return err + } + + c, err := conv.ToUUID(val) + if err != nil { + return err + } + + params.ChatID = c + return nil + }(); err != nil { + return err + } + } else { + return validate.ErrFieldRequired + } + return nil + }(); err != nil { + return params, &ogenerrors.DecodeParamError{ + Name: "chat_id", + In: "path", + Err: err, + } + } + // Set default value for query: limit. + { + val := int(50) + params.Limit.SetTo(val) + } + // Decode query: limit. + if err := func() error { + cfg := uri.QueryParameterDecodingConfig{ + Name: "limit", + Style: uri.QueryStyleForm, + Explode: true, + } + + if err := q.HasParam(cfg); err == nil { + if err := q.DecodeParam(cfg, func(d uri.Decoder) error { + var paramsDotLimitVal int + if err := func() error { + val, err := d.DecodeValue() + if err != nil { + return err + } + + c, err := conv.ToInt(val) + if err != nil { + return err + } + + paramsDotLimitVal = c + return nil + }(); err != nil { + return err + } + params.Limit.SetTo(paramsDotLimitVal) + return nil + }); err != nil { + return err + } + if err := func() error { + if value, ok := params.Limit.Get(); ok { + if err := func() error { + if err := (validate.Int{ + MinSet: true, + Min: 1, + MaxSet: true, + Max: 100, + MinExclusive: false, + MaxExclusive: false, + MultipleOfSet: false, + MultipleOf: 0, + Pattern: nil, + }).Validate(int64(value)); err != nil { + return errors.Wrap(err, "int") + } + return nil + }(); err != nil { + return err + } + } + return nil + }(); err != nil { + return err + } + } + return nil + }(); err != nil { + return params, &ogenerrors.DecodeParamError{ + Name: "limit", + In: "query", + Err: err, + } + } + // Decode query: cursor. + if err := func() error { + cfg := uri.QueryParameterDecodingConfig{ + Name: "cursor", + Style: uri.QueryStyleForm, + Explode: true, + } + + if err := q.HasParam(cfg); err == nil { + if err := q.DecodeParam(cfg, func(d uri.Decoder) error { + var paramsDotCursorVal string + if err := func() error { + val, err := d.DecodeValue() + if err != nil { + return err + } + + c, err := conv.ToString(val) + if err != nil { + return err + } + + paramsDotCursorVal = c + return nil + }(); err != nil { + return err + } + params.Cursor.SetTo(paramsDotCursorVal) + return nil + }); err != nil { + return err + } + if err := func() error { + if value, ok := params.Cursor.Get(); ok { + if err := func() error { + if err := (validate.String{ + MinLength: 1, + MinLengthSet: true, + MaxLength: 0, + MaxLengthSet: false, + Email: false, + Hostname: false, + Regex: nil, + MinNumeric: 0, + MinNumericSet: false, + MaxNumeric: 0, + MaxNumericSet: false, + }).Validate(string(value)); err != nil { + return errors.Wrap(err, "string") + } + return nil + }(); err != nil { + return err + } + } + return nil + }(); err != nil { + return err + } + } + return nil + }(); err != nil { + return params, &ogenerrors.DecodeParamError{ + Name: "cursor", + In: "query", + Err: err, + } + } + return params, nil +} + +// UploadAttachmentParams is parameters of uploadAttachment operation. +type UploadAttachmentParams struct { + ChatID uuid.UUID + Filename string +} + +func unpackUploadAttachmentParams(packed middleware.Parameters) (params UploadAttachmentParams) { + { + key := middleware.ParameterKey{ + Name: "chat_id", + In: "path", + } + params.ChatID = packed[key].(uuid.UUID) + } + { + key := middleware.ParameterKey{ + Name: "filename", + In: "query", + } + params.Filename = packed[key].(string) + } + return params +} + +func decodeUploadAttachmentParams(args [1]string, argsEscaped bool, r *http.Request) (params UploadAttachmentParams, _ error) { + q := uri.NewQueryDecoder(r.URL.Query()) + // Decode path: chat_id. + if err := func() error { + param := args[0] + if argsEscaped { + unescaped, err := url.PathUnescape(args[0]) + if err != nil { + return errors.Wrap(err, "unescape path") + } + param = unescaped + } + if len(param) > 0 { + d := uri.NewPathDecoder(uri.PathDecoderConfig{ + Param: "chat_id", + Value: param, + Style: uri.PathStyleSimple, + Explode: false, + }) + + if err := func() error { + val, err := d.DecodeValue() + if err != nil { + return err + } + + c, err := conv.ToUUID(val) + if err != nil { + return err + } + + params.ChatID = c + return nil + }(); err != nil { + return err + } + } else { + return validate.ErrFieldRequired + } + return nil + }(); err != nil { + return params, &ogenerrors.DecodeParamError{ + Name: "chat_id", + In: "path", + Err: err, + } + } + // Decode query: filename. + if err := func() error { + cfg := uri.QueryParameterDecodingConfig{ + Name: "filename", + Style: uri.QueryStyleForm, + Explode: true, + } + + if err := q.HasParam(cfg); err == nil { + if err := q.DecodeParam(cfg, func(d uri.Decoder) error { + val, err := d.DecodeValue() + if err != nil { + return err + } + + c, err := conv.ToString(val) + if err != nil { + return err + } + + params.Filename = c + return nil + }); err != nil { + return err + } + if err := func() error { + if err := (validate.String{ + MinLength: 1, + MinLengthSet: true, + MaxLength: 255, + MaxLengthSet: true, + Email: false, + Hostname: false, + Regex: nil, + MinNumeric: 0, + MinNumericSet: false, + MaxNumeric: 0, + MaxNumericSet: false, + }).Validate(string(params.Filename)); err != nil { + return errors.Wrap(err, "string") + } + return nil + }(); err != nil { + return err + } + } else { + return err + } + return nil + }(); err != nil { + return params, &ogenerrors.DecodeParamError{ + Name: "filename", + In: "query", + Err: err, + } + } + return params, nil +} diff --git a/internal/transport/rest/internal/oas/oas_request_decoders_gen.go b/internal/transport/rest/internal/oas/oas_request_decoders_gen.go new file mode 100644 index 0000000..fa4fe50 --- /dev/null +++ b/internal/transport/rest/internal/oas/oas_request_decoders_gen.go @@ -0,0 +1,291 @@ +// Code generated by ogen, DO NOT EDIT. + +package oas + +import ( + "bytes" + "io" + "mime" + "net/http" + + "github.com/go-faster/errors" + "github.com/go-faster/jx" + "github.com/ogen-go/ogen/ogenerrors" + "github.com/ogen-go/ogen/validate" +) + +func (s *Server) decodeCreateChatRequest(r *http.Request) ( + req *CreateChat, + rawBody []byte, + close func() error, + rerr error, +) { + var closers []func() error + close = func() error { + var merr error + // Close in reverse order, to match defer behavior. + for i := len(closers) - 1; i >= 0; i-- { + c := closers[i] + merr = errors.Join(merr, c()) + } + return merr + } + defer func() { + if rerr != nil { + rerr = errors.Join(rerr, close()) + } + }() + ct, _, err := mime.ParseMediaType(r.Header.Get("Content-Type")) + if err != nil { + return req, rawBody, close, errors.Wrap(err, "parse media type") + } + switch { + case ct == "application/json": + if r.ContentLength == 0 { + return req, rawBody, close, validate.ErrBodyRequired + } + buf, err := io.ReadAll(r.Body) + defer func() { + _ = r.Body.Close() + }() + if err != nil { + return req, rawBody, close, err + } + + // Reset the body to allow for downstream reading. + r.Body = io.NopCloser(bytes.NewBuffer(buf)) + + if len(buf) == 0 { + return req, rawBody, close, validate.ErrBodyRequired + } + + rawBody = append(rawBody, buf...) + d := jx.DecodeBytes(buf) + + var request CreateChat + if err := func() error { + if err := request.Decode(d); err != nil { + return err + } + if err := d.Skip(); err != io.EOF { + return errors.New("unexpected trailing data") + } + return nil + }(); err != nil { + err = &ogenerrors.DecodeBodyError{ + ContentType: ct, + Body: buf, + Err: err, + } + return req, rawBody, close, err + } + if err := func() error { + if err := request.Validate(); err != nil { + return err + } + return nil + }(); err != nil { + return req, rawBody, close, errors.Wrap(err, "validate") + } + return &request, rawBody, close, nil + default: + return req, rawBody, close, validate.InvalidContentType(ct) + } +} + +func (s *Server) decodeCreateMessageRequest(r *http.Request) ( + req *CreateMessage, + rawBody []byte, + close func() error, + rerr error, +) { + var closers []func() error + close = func() error { + var merr error + // Close in reverse order, to match defer behavior. + for i := len(closers) - 1; i >= 0; i-- { + c := closers[i] + merr = errors.Join(merr, c()) + } + return merr + } + defer func() { + if rerr != nil { + rerr = errors.Join(rerr, close()) + } + }() + ct, _, err := mime.ParseMediaType(r.Header.Get("Content-Type")) + if err != nil { + return req, rawBody, close, errors.Wrap(err, "parse media type") + } + switch { + case ct == "application/json": + if r.ContentLength == 0 { + return req, rawBody, close, validate.ErrBodyRequired + } + buf, err := io.ReadAll(r.Body) + defer func() { + _ = r.Body.Close() + }() + if err != nil { + return req, rawBody, close, err + } + + // Reset the body to allow for downstream reading. + r.Body = io.NopCloser(bytes.NewBuffer(buf)) + + if len(buf) == 0 { + return req, rawBody, close, validate.ErrBodyRequired + } + + rawBody = append(rawBody, buf...) + d := jx.DecodeBytes(buf) + + var request CreateMessage + if err := func() error { + if err := request.Decode(d); err != nil { + return err + } + if err := d.Skip(); err != io.EOF { + return errors.New("unexpected trailing data") + } + return nil + }(); err != nil { + err = &ogenerrors.DecodeBodyError{ + ContentType: ct, + Body: buf, + Err: err, + } + return req, rawBody, close, err + } + if err := func() error { + if err := request.Validate(); err != nil { + return err + } + return nil + }(); err != nil { + return req, rawBody, close, errors.Wrap(err, "validate") + } + return &request, rawBody, close, nil + default: + return req, rawBody, close, validate.InvalidContentType(ct) + } +} + +func (s *Server) decodeRegisterUserRequest(r *http.Request) ( + req *CreateUser, + rawBody []byte, + close func() error, + rerr error, +) { + var closers []func() error + close = func() error { + var merr error + // Close in reverse order, to match defer behavior. + for i := len(closers) - 1; i >= 0; i-- { + c := closers[i] + merr = errors.Join(merr, c()) + } + return merr + } + defer func() { + if rerr != nil { + rerr = errors.Join(rerr, close()) + } + }() + ct, _, err := mime.ParseMediaType(r.Header.Get("Content-Type")) + if err != nil { + return req, rawBody, close, errors.Wrap(err, "parse media type") + } + switch { + case ct == "application/json": + if r.ContentLength == 0 { + return req, rawBody, close, validate.ErrBodyRequired + } + buf, err := io.ReadAll(r.Body) + defer func() { + _ = r.Body.Close() + }() + if err != nil { + return req, rawBody, close, err + } + + // Reset the body to allow for downstream reading. + r.Body = io.NopCloser(bytes.NewBuffer(buf)) + + if len(buf) == 0 { + return req, rawBody, close, validate.ErrBodyRequired + } + + rawBody = append(rawBody, buf...) + d := jx.DecodeBytes(buf) + + var request CreateUser + if err := func() error { + if err := request.Decode(d); err != nil { + return err + } + if err := d.Skip(); err != io.EOF { + return errors.New("unexpected trailing data") + } + return nil + }(); err != nil { + err = &ogenerrors.DecodeBodyError{ + ContentType: ct, + Body: buf, + Err: err, + } + return req, rawBody, close, err + } + if err := func() error { + if err := request.Validate(); err != nil { + return err + } + return nil + }(); err != nil { + return req, rawBody, close, errors.Wrap(err, "validate") + } + return &request, rawBody, close, nil + default: + return req, rawBody, close, validate.InvalidContentType(ct) + } +} + +func (s *Server) decodeUploadAttachmentRequest(r *http.Request) ( + req UploadAttachmentReq, + rawBody []byte, + close func() error, + rerr error, +) { + var closers []func() error + close = func() error { + var merr error + // Close in reverse order, to match defer behavior. + for i := len(closers) - 1; i >= 0; i-- { + c := closers[i] + merr = errors.Join(merr, c()) + } + return merr + } + defer func() { + if rerr != nil { + rerr = errors.Join(rerr, close()) + } + }() + ct, _, err := mime.ParseMediaType(r.Header.Get("Content-Type")) + if err != nil { + return req, rawBody, close, errors.Wrap(err, "parse media type") + } + switch { + case ct == "image/jpeg": + reader := r.Body + request := UploadAttachmentReqImageJpeg{Data: reader} + return &request, rawBody, close, nil + case ct == "image/png": + reader := r.Body + request := UploadAttachmentReqImagePNG{Data: reader} + return &request, rawBody, close, nil + default: + return req, rawBody, close, validate.InvalidContentType(ct) + } +} diff --git a/internal/transport/rest/internal/oas/oas_response_encoders_gen.go b/internal/transport/rest/internal/oas/oas_response_encoders_gen.go new file mode 100644 index 0000000..7da16d2 --- /dev/null +++ b/internal/transport/rest/internal/oas/oas_response_encoders_gen.go @@ -0,0 +1,5014 @@ +// Code generated by ogen, DO NOT EDIT. + +package oas + +import ( + "io" + "net/http" + + "github.com/go-faster/errors" + "github.com/go-faster/jx" + "github.com/ogen-go/ogen/conv" + "github.com/ogen-go/ogen/uri" +) + +func encodeCreateChatResponse(response CreateChatRes, w http.ResponseWriter) error { + switch response := response.(type) { + case *ChatHeaders: + w.Header().Set("Content-Type", "application/json; charset=utf-8") + w.Header().Set("Access-Control-Expose-Headers", "X-Instance-Id,X-Request-Id") + // Encoding response headers. + { + h := uri.NewHeaderEncoder(w.Header()) + // Encode "X-Instance-Id" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "X-Instance-Id", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.XInstanceID.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode X-Instance-Id header") + } + } + // Encode "X-Request-Id" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "X-Request-Id", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.XRequestID.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode X-Request-Id header") + } + } + } + w.WriteHeader(201) + + e := new(jx.Encoder) + response.Response.Encode(e) + if _, err := e.WriteTo(w); err != nil { + return errors.Wrap(err, "write") + } + + return nil + + case *CreateChatBadRequest: + w.Header().Set("Content-Type", "application/json; charset=utf-8") + w.Header().Set("Access-Control-Expose-Headers", "X-Instance-Id,X-Request-Id") + // Encoding response headers. + { + h := uri.NewHeaderEncoder(w.Header()) + // Encode "X-Instance-Id" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "X-Instance-Id", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.XInstanceID.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode X-Instance-Id header") + } + } + // Encode "X-Request-Id" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "X-Request-Id", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.XRequestID.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode X-Request-Id header") + } + } + } + w.WriteHeader(400) + + e := new(jx.Encoder) + response.Response.Encode(e) + if _, err := e.WriteTo(w); err != nil { + return errors.Wrap(err, "write") + } + + return nil + + case *GetAttachmentUnauthorizedHeaders: + w.Header().Set("Content-Type", "application/json; charset=utf-8") + w.Header().Set("Access-Control-Expose-Headers", "Www-Authenticate,X-Instance-Id,X-Request-Id") + // Encoding response headers. + { + h := uri.NewHeaderEncoder(w.Header()) + // Encode "WWW-Authenticate" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "WWW-Authenticate", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.WWWAuthenticate.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode WWW-Authenticate header") + } + } + // Encode "X-Instance-Id" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "X-Instance-Id", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.XInstanceID.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode X-Instance-Id header") + } + } + // Encode "X-Request-Id" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "X-Request-Id", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.XRequestID.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode X-Request-Id header") + } + } + } + w.WriteHeader(401) + + e := new(jx.Encoder) + response.Response.Encode(e) + if _, err := e.WriteTo(w); err != nil { + return errors.Wrap(err, "write") + } + + return nil + + case *CreateChatNotFound: + w.Header().Set("Content-Type", "application/json; charset=utf-8") + w.Header().Set("Access-Control-Expose-Headers", "X-Instance-Id,X-Request-Id") + // Encoding response headers. + { + h := uri.NewHeaderEncoder(w.Header()) + // Encode "X-Instance-Id" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "X-Instance-Id", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.XInstanceID.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode X-Instance-Id header") + } + } + // Encode "X-Request-Id" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "X-Request-Id", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.XRequestID.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode X-Request-Id header") + } + } + } + w.WriteHeader(404) + + e := new(jx.Encoder) + response.Response.Encode(e) + if _, err := e.WriteTo(w); err != nil { + return errors.Wrap(err, "write") + } + + return nil + + case *CreateChatConflict: + w.Header().Set("Content-Type", "application/json; charset=utf-8") + w.Header().Set("Access-Control-Expose-Headers", "X-Instance-Id,X-Request-Id") + // Encoding response headers. + { + h := uri.NewHeaderEncoder(w.Header()) + // Encode "X-Instance-Id" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "X-Instance-Id", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.XInstanceID.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode X-Instance-Id header") + } + } + // Encode "X-Request-Id" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "X-Request-Id", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.XRequestID.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode X-Request-Id header") + } + } + } + w.WriteHeader(409) + + e := new(jx.Encoder) + response.Response.Encode(e) + if _, err := e.WriteTo(w); err != nil { + return errors.Wrap(err, "write") + } + + return nil + + case *GetAttachmentTooManyRequestsHeaders: + w.Header().Set("Content-Type", "application/json; charset=utf-8") + w.Header().Set("Access-Control-Expose-Headers", "Retry-After,X-Instance-Id,X-Request-Id") + // Encoding response headers. + { + h := uri.NewHeaderEncoder(w.Header()) + // Encode "Retry-After" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "Retry-After", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.RetryAfter.Get(); ok { + return e.EncodeValue(conv.IntToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode Retry-After header") + } + } + // Encode "X-Instance-Id" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "X-Instance-Id", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.XInstanceID.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode X-Instance-Id header") + } + } + // Encode "X-Request-Id" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "X-Request-Id", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.XRequestID.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode X-Request-Id header") + } + } + } + w.WriteHeader(429) + + e := new(jx.Encoder) + response.Response.Encode(e) + if _, err := e.WriteTo(w); err != nil { + return errors.Wrap(err, "write") + } + + return nil + + case *CreateChatInternalServerError: + w.Header().Set("Content-Type", "application/json; charset=utf-8") + w.Header().Set("Access-Control-Expose-Headers", "X-Instance-Id,X-Request-Id") + // Encoding response headers. + { + h := uri.NewHeaderEncoder(w.Header()) + // Encode "X-Instance-Id" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "X-Instance-Id", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.XInstanceID.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode X-Instance-Id header") + } + } + // Encode "X-Request-Id" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "X-Request-Id", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.XRequestID.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode X-Request-Id header") + } + } + } + w.WriteHeader(500) + + e := new(jx.Encoder) + response.Response.Encode(e) + if _, err := e.WriteTo(w); err != nil { + return errors.Wrap(err, "write") + } + + return nil + + case *CreateChatServiceUnavailable: + w.Header().Set("Content-Type", "application/json; charset=utf-8") + w.Header().Set("Access-Control-Expose-Headers", "X-Instance-Id,X-Request-Id") + // Encoding response headers. + { + h := uri.NewHeaderEncoder(w.Header()) + // Encode "X-Instance-Id" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "X-Instance-Id", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.XInstanceID.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode X-Instance-Id header") + } + } + // Encode "X-Request-Id" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "X-Request-Id", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.XRequestID.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode X-Request-Id header") + } + } + } + w.WriteHeader(503) + + e := new(jx.Encoder) + response.Response.Encode(e) + if _, err := e.WriteTo(w); err != nil { + return errors.Wrap(err, "write") + } + + return nil + + default: + return errors.Errorf("unexpected response type: %T", response) + } +} + +func encodeCreateMessageResponse(response CreateMessageRes, w http.ResponseWriter) error { + switch response := response.(type) { + case *MessageHeaders: + w.Header().Set("Content-Type", "application/json; charset=utf-8") + w.Header().Set("Access-Control-Expose-Headers", "X-Instance-Id,X-Request-Id") + // Encoding response headers. + { + h := uri.NewHeaderEncoder(w.Header()) + // Encode "X-Instance-Id" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "X-Instance-Id", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.XInstanceID.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode X-Instance-Id header") + } + } + // Encode "X-Request-Id" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "X-Request-Id", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.XRequestID.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode X-Request-Id header") + } + } + } + w.WriteHeader(201) + + e := new(jx.Encoder) + response.Response.Encode(e) + if _, err := e.WriteTo(w); err != nil { + return errors.Wrap(err, "write") + } + + return nil + + case *CreateMessageBadRequest: + w.Header().Set("Content-Type", "application/json; charset=utf-8") + w.Header().Set("Access-Control-Expose-Headers", "X-Instance-Id,X-Request-Id") + // Encoding response headers. + { + h := uri.NewHeaderEncoder(w.Header()) + // Encode "X-Instance-Id" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "X-Instance-Id", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.XInstanceID.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode X-Instance-Id header") + } + } + // Encode "X-Request-Id" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "X-Request-Id", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.XRequestID.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode X-Request-Id header") + } + } + } + w.WriteHeader(400) + + e := new(jx.Encoder) + response.Response.Encode(e) + if _, err := e.WriteTo(w); err != nil { + return errors.Wrap(err, "write") + } + + return nil + + case *GetAttachmentUnauthorizedHeaders: + w.Header().Set("Content-Type", "application/json; charset=utf-8") + w.Header().Set("Access-Control-Expose-Headers", "Www-Authenticate,X-Instance-Id,X-Request-Id") + // Encoding response headers. + { + h := uri.NewHeaderEncoder(w.Header()) + // Encode "WWW-Authenticate" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "WWW-Authenticate", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.WWWAuthenticate.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode WWW-Authenticate header") + } + } + // Encode "X-Instance-Id" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "X-Instance-Id", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.XInstanceID.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode X-Instance-Id header") + } + } + // Encode "X-Request-Id" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "X-Request-Id", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.XRequestID.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode X-Request-Id header") + } + } + } + w.WriteHeader(401) + + e := new(jx.Encoder) + response.Response.Encode(e) + if _, err := e.WriteTo(w); err != nil { + return errors.Wrap(err, "write") + } + + return nil + + case *CreateMessageNotFound: + w.Header().Set("Content-Type", "application/json; charset=utf-8") + w.Header().Set("Access-Control-Expose-Headers", "X-Instance-Id,X-Request-Id") + // Encoding response headers. + { + h := uri.NewHeaderEncoder(w.Header()) + // Encode "X-Instance-Id" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "X-Instance-Id", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.XInstanceID.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode X-Instance-Id header") + } + } + // Encode "X-Request-Id" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "X-Request-Id", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.XRequestID.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode X-Request-Id header") + } + } + } + w.WriteHeader(404) + + e := new(jx.Encoder) + response.Response.Encode(e) + if _, err := e.WriteTo(w); err != nil { + return errors.Wrap(err, "write") + } + + return nil + + case *CreateMessageConflict: + w.Header().Set("Content-Type", "application/json; charset=utf-8") + w.Header().Set("Access-Control-Expose-Headers", "X-Instance-Id,X-Request-Id") + // Encoding response headers. + { + h := uri.NewHeaderEncoder(w.Header()) + // Encode "X-Instance-Id" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "X-Instance-Id", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.XInstanceID.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode X-Instance-Id header") + } + } + // Encode "X-Request-Id" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "X-Request-Id", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.XRequestID.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode X-Request-Id header") + } + } + } + w.WriteHeader(409) + + e := new(jx.Encoder) + response.Response.Encode(e) + if _, err := e.WriteTo(w); err != nil { + return errors.Wrap(err, "write") + } + + return nil + + case *GetAttachmentTooManyRequestsHeaders: + w.Header().Set("Content-Type", "application/json; charset=utf-8") + w.Header().Set("Access-Control-Expose-Headers", "Retry-After,X-Instance-Id,X-Request-Id") + // Encoding response headers. + { + h := uri.NewHeaderEncoder(w.Header()) + // Encode "Retry-After" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "Retry-After", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.RetryAfter.Get(); ok { + return e.EncodeValue(conv.IntToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode Retry-After header") + } + } + // Encode "X-Instance-Id" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "X-Instance-Id", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.XInstanceID.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode X-Instance-Id header") + } + } + // Encode "X-Request-Id" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "X-Request-Id", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.XRequestID.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode X-Request-Id header") + } + } + } + w.WriteHeader(429) + + e := new(jx.Encoder) + response.Response.Encode(e) + if _, err := e.WriteTo(w); err != nil { + return errors.Wrap(err, "write") + } + + return nil + + case *CreateMessageInternalServerError: + w.Header().Set("Content-Type", "application/json; charset=utf-8") + w.Header().Set("Access-Control-Expose-Headers", "X-Instance-Id,X-Request-Id") + // Encoding response headers. + { + h := uri.NewHeaderEncoder(w.Header()) + // Encode "X-Instance-Id" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "X-Instance-Id", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.XInstanceID.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode X-Instance-Id header") + } + } + // Encode "X-Request-Id" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "X-Request-Id", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.XRequestID.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode X-Request-Id header") + } + } + } + w.WriteHeader(500) + + e := new(jx.Encoder) + response.Response.Encode(e) + if _, err := e.WriteTo(w); err != nil { + return errors.Wrap(err, "write") + } + + return nil + + case *CreateMessageServiceUnavailable: + w.Header().Set("Content-Type", "application/json; charset=utf-8") + w.Header().Set("Access-Control-Expose-Headers", "X-Instance-Id,X-Request-Id") + // Encoding response headers. + { + h := uri.NewHeaderEncoder(w.Header()) + // Encode "X-Instance-Id" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "X-Instance-Id", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.XInstanceID.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode X-Instance-Id header") + } + } + // Encode "X-Request-Id" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "X-Request-Id", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.XRequestID.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode X-Request-Id header") + } + } + } + w.WriteHeader(503) + + e := new(jx.Encoder) + response.Response.Encode(e) + if _, err := e.WriteTo(w); err != nil { + return errors.Wrap(err, "write") + } + + return nil + + default: + return errors.Errorf("unexpected response type: %T", response) + } +} + +func encodeCreateSessionResponse(response CreateSessionRes, w http.ResponseWriter) error { + switch response := response.(type) { + case *SessionHeaders: + w.Header().Set("Content-Type", "application/json; charset=utf-8") + w.Header().Set("Access-Control-Expose-Headers", "X-Instance-Id,X-Request-Id") + // Encoding response headers. + { + h := uri.NewHeaderEncoder(w.Header()) + // Encode "X-Instance-Id" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "X-Instance-Id", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.XInstanceID.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode X-Instance-Id header") + } + } + // Encode "X-Request-Id" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "X-Request-Id", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.XRequestID.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode X-Request-Id header") + } + } + } + w.WriteHeader(201) + + e := new(jx.Encoder) + response.Response.Encode(e) + if _, err := e.WriteTo(w); err != nil { + return errors.Wrap(err, "write") + } + + return nil + + case *CreateSessionBadRequest: + w.Header().Set("Content-Type", "application/json; charset=utf-8") + w.Header().Set("Access-Control-Expose-Headers", "X-Instance-Id,X-Request-Id") + // Encoding response headers. + { + h := uri.NewHeaderEncoder(w.Header()) + // Encode "X-Instance-Id" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "X-Instance-Id", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.XInstanceID.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode X-Instance-Id header") + } + } + // Encode "X-Request-Id" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "X-Request-Id", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.XRequestID.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode X-Request-Id header") + } + } + } + w.WriteHeader(400) + + e := new(jx.Encoder) + response.Response.Encode(e) + if _, err := e.WriteTo(w); err != nil { + return errors.Wrap(err, "write") + } + + return nil + + case *GetAttachmentUnauthorizedHeaders: + w.Header().Set("Content-Type", "application/json; charset=utf-8") + w.Header().Set("Access-Control-Expose-Headers", "Www-Authenticate,X-Instance-Id,X-Request-Id") + // Encoding response headers. + { + h := uri.NewHeaderEncoder(w.Header()) + // Encode "WWW-Authenticate" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "WWW-Authenticate", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.WWWAuthenticate.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode WWW-Authenticate header") + } + } + // Encode "X-Instance-Id" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "X-Instance-Id", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.XInstanceID.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode X-Instance-Id header") + } + } + // Encode "X-Request-Id" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "X-Request-Id", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.XRequestID.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode X-Request-Id header") + } + } + } + w.WriteHeader(401) + + e := new(jx.Encoder) + response.Response.Encode(e) + if _, err := e.WriteTo(w); err != nil { + return errors.Wrap(err, "write") + } + + return nil + + case *GetAttachmentTooManyRequestsHeaders: + w.Header().Set("Content-Type", "application/json; charset=utf-8") + w.Header().Set("Access-Control-Expose-Headers", "Retry-After,X-Instance-Id,X-Request-Id") + // Encoding response headers. + { + h := uri.NewHeaderEncoder(w.Header()) + // Encode "Retry-After" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "Retry-After", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.RetryAfter.Get(); ok { + return e.EncodeValue(conv.IntToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode Retry-After header") + } + } + // Encode "X-Instance-Id" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "X-Instance-Id", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.XInstanceID.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode X-Instance-Id header") + } + } + // Encode "X-Request-Id" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "X-Request-Id", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.XRequestID.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode X-Request-Id header") + } + } + } + w.WriteHeader(429) + + e := new(jx.Encoder) + response.Response.Encode(e) + if _, err := e.WriteTo(w); err != nil { + return errors.Wrap(err, "write") + } + + return nil + + case *CreateSessionInternalServerError: + w.Header().Set("Content-Type", "application/json; charset=utf-8") + w.Header().Set("Access-Control-Expose-Headers", "X-Instance-Id,X-Request-Id") + // Encoding response headers. + { + h := uri.NewHeaderEncoder(w.Header()) + // Encode "X-Instance-Id" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "X-Instance-Id", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.XInstanceID.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode X-Instance-Id header") + } + } + // Encode "X-Request-Id" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "X-Request-Id", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.XRequestID.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode X-Request-Id header") + } + } + } + w.WriteHeader(500) + + e := new(jx.Encoder) + response.Response.Encode(e) + if _, err := e.WriteTo(w); err != nil { + return errors.Wrap(err, "write") + } + + return nil + + case *CreateSessionServiceUnavailable: + w.Header().Set("Content-Type", "application/json; charset=utf-8") + w.Header().Set("Access-Control-Expose-Headers", "X-Instance-Id,X-Request-Id") + // Encoding response headers. + { + h := uri.NewHeaderEncoder(w.Header()) + // Encode "X-Instance-Id" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "X-Instance-Id", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.XInstanceID.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode X-Instance-Id header") + } + } + // Encode "X-Request-Id" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "X-Request-Id", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.XRequestID.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode X-Request-Id header") + } + } + } + w.WriteHeader(503) + + e := new(jx.Encoder) + response.Response.Encode(e) + if _, err := e.WriteTo(w); err != nil { + return errors.Wrap(err, "write") + } + + return nil + + default: + return errors.Errorf("unexpected response type: %T", response) + } +} + +func encodeCurrentUserResponse(response CurrentUserRes, w http.ResponseWriter) error { + switch response := response.(type) { + case *UserHeaders: + w.Header().Set("Content-Type", "application/json; charset=utf-8") + w.Header().Set("Access-Control-Expose-Headers", "X-Instance-Id,X-Request-Id") + // Encoding response headers. + { + h := uri.NewHeaderEncoder(w.Header()) + // Encode "X-Instance-Id" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "X-Instance-Id", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.XInstanceID.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode X-Instance-Id header") + } + } + // Encode "X-Request-Id" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "X-Request-Id", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.XRequestID.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode X-Request-Id header") + } + } + } + w.WriteHeader(200) + + e := new(jx.Encoder) + response.Response.Encode(e) + if _, err := e.WriteTo(w); err != nil { + return errors.Wrap(err, "write") + } + + return nil + + case *CurrentUserBadRequest: + w.Header().Set("Content-Type", "application/json; charset=utf-8") + w.Header().Set("Access-Control-Expose-Headers", "X-Instance-Id,X-Request-Id") + // Encoding response headers. + { + h := uri.NewHeaderEncoder(w.Header()) + // Encode "X-Instance-Id" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "X-Instance-Id", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.XInstanceID.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode X-Instance-Id header") + } + } + // Encode "X-Request-Id" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "X-Request-Id", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.XRequestID.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode X-Request-Id header") + } + } + } + w.WriteHeader(400) + + e := new(jx.Encoder) + response.Response.Encode(e) + if _, err := e.WriteTo(w); err != nil { + return errors.Wrap(err, "write") + } + + return nil + + case *GetAttachmentUnauthorizedHeaders: + w.Header().Set("Content-Type", "application/json; charset=utf-8") + w.Header().Set("Access-Control-Expose-Headers", "Www-Authenticate,X-Instance-Id,X-Request-Id") + // Encoding response headers. + { + h := uri.NewHeaderEncoder(w.Header()) + // Encode "WWW-Authenticate" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "WWW-Authenticate", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.WWWAuthenticate.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode WWW-Authenticate header") + } + } + // Encode "X-Instance-Id" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "X-Instance-Id", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.XInstanceID.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode X-Instance-Id header") + } + } + // Encode "X-Request-Id" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "X-Request-Id", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.XRequestID.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode X-Request-Id header") + } + } + } + w.WriteHeader(401) + + e := new(jx.Encoder) + response.Response.Encode(e) + if _, err := e.WriteTo(w); err != nil { + return errors.Wrap(err, "write") + } + + return nil + + case *CurrentUserNotFound: + w.Header().Set("Content-Type", "application/json; charset=utf-8") + w.Header().Set("Access-Control-Expose-Headers", "X-Instance-Id,X-Request-Id") + // Encoding response headers. + { + h := uri.NewHeaderEncoder(w.Header()) + // Encode "X-Instance-Id" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "X-Instance-Id", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.XInstanceID.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode X-Instance-Id header") + } + } + // Encode "X-Request-Id" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "X-Request-Id", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.XRequestID.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode X-Request-Id header") + } + } + } + w.WriteHeader(404) + + e := new(jx.Encoder) + response.Response.Encode(e) + if _, err := e.WriteTo(w); err != nil { + return errors.Wrap(err, "write") + } + + return nil + + case *CurrentUserConflict: + w.Header().Set("Content-Type", "application/json; charset=utf-8") + w.Header().Set("Access-Control-Expose-Headers", "X-Instance-Id,X-Request-Id") + // Encoding response headers. + { + h := uri.NewHeaderEncoder(w.Header()) + // Encode "X-Instance-Id" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "X-Instance-Id", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.XInstanceID.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode X-Instance-Id header") + } + } + // Encode "X-Request-Id" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "X-Request-Id", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.XRequestID.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode X-Request-Id header") + } + } + } + w.WriteHeader(409) + + e := new(jx.Encoder) + response.Response.Encode(e) + if _, err := e.WriteTo(w); err != nil { + return errors.Wrap(err, "write") + } + + return nil + + case *GetAttachmentTooManyRequestsHeaders: + w.Header().Set("Content-Type", "application/json; charset=utf-8") + w.Header().Set("Access-Control-Expose-Headers", "Retry-After,X-Instance-Id,X-Request-Id") + // Encoding response headers. + { + h := uri.NewHeaderEncoder(w.Header()) + // Encode "Retry-After" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "Retry-After", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.RetryAfter.Get(); ok { + return e.EncodeValue(conv.IntToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode Retry-After header") + } + } + // Encode "X-Instance-Id" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "X-Instance-Id", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.XInstanceID.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode X-Instance-Id header") + } + } + // Encode "X-Request-Id" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "X-Request-Id", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.XRequestID.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode X-Request-Id header") + } + } + } + w.WriteHeader(429) + + e := new(jx.Encoder) + response.Response.Encode(e) + if _, err := e.WriteTo(w); err != nil { + return errors.Wrap(err, "write") + } + + return nil + + case *CurrentUserInternalServerError: + w.Header().Set("Content-Type", "application/json; charset=utf-8") + w.Header().Set("Access-Control-Expose-Headers", "X-Instance-Id,X-Request-Id") + // Encoding response headers. + { + h := uri.NewHeaderEncoder(w.Header()) + // Encode "X-Instance-Id" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "X-Instance-Id", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.XInstanceID.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode X-Instance-Id header") + } + } + // Encode "X-Request-Id" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "X-Request-Id", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.XRequestID.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode X-Request-Id header") + } + } + } + w.WriteHeader(500) + + e := new(jx.Encoder) + response.Response.Encode(e) + if _, err := e.WriteTo(w); err != nil { + return errors.Wrap(err, "write") + } + + return nil + + case *CurrentUserServiceUnavailable: + w.Header().Set("Content-Type", "application/json; charset=utf-8") + w.Header().Set("Access-Control-Expose-Headers", "X-Instance-Id,X-Request-Id") + // Encoding response headers. + { + h := uri.NewHeaderEncoder(w.Header()) + // Encode "X-Instance-Id" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "X-Instance-Id", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.XInstanceID.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode X-Instance-Id header") + } + } + // Encode "X-Request-Id" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "X-Request-Id", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.XRequestID.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode X-Request-Id header") + } + } + } + w.WriteHeader(503) + + e := new(jx.Encoder) + response.Response.Encode(e) + if _, err := e.WriteTo(w); err != nil { + return errors.Wrap(err, "write") + } + + return nil + + default: + return errors.Errorf("unexpected response type: %T", response) + } +} + +func encodeDownloadAttachmentResponse(response DownloadAttachmentRes, w http.ResponseWriter) error { + switch response := response.(type) { + case *DownloadAttachmentOKImageJpegHeaders: + w.Header().Set("Content-Type", "image/jpeg") + w.Header().Set("Access-Control-Expose-Headers", "X-Instance-Id,X-Request-Id") + // Encoding response headers. + { + h := uri.NewHeaderEncoder(w.Header()) + // Encode "X-Instance-Id" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "X-Instance-Id", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.XInstanceID.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode X-Instance-Id header") + } + } + // Encode "X-Request-Id" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "X-Request-Id", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.XRequestID.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode X-Request-Id header") + } + } + } + w.WriteHeader(200) + + writer := w + if closer, ok := response.Response.Data.(io.Closer); ok { + defer closer.Close() + } + if _, err := io.Copy(writer, response.Response); err != nil { + return errors.Wrap(err, "write") + } + + return nil + + case *DownloadAttachmentOKImagePNGHeaders: + w.Header().Set("Content-Type", "image/png") + w.Header().Set("Access-Control-Expose-Headers", "X-Instance-Id,X-Request-Id") + // Encoding response headers. + { + h := uri.NewHeaderEncoder(w.Header()) + // Encode "X-Instance-Id" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "X-Instance-Id", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.XInstanceID.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode X-Instance-Id header") + } + } + // Encode "X-Request-Id" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "X-Request-Id", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.XRequestID.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode X-Request-Id header") + } + } + } + w.WriteHeader(200) + + writer := w + if closer, ok := response.Response.Data.(io.Closer); ok { + defer closer.Close() + } + if _, err := io.Copy(writer, response.Response); err != nil { + return errors.Wrap(err, "write") + } + + return nil + + case *DownloadAttachmentOKImageWEBPHeaders: + w.Header().Set("Content-Type", "image/webp") + w.Header().Set("Access-Control-Expose-Headers", "X-Instance-Id,X-Request-Id") + // Encoding response headers. + { + h := uri.NewHeaderEncoder(w.Header()) + // Encode "X-Instance-Id" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "X-Instance-Id", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.XInstanceID.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode X-Instance-Id header") + } + } + // Encode "X-Request-Id" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "X-Request-Id", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.XRequestID.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode X-Request-Id header") + } + } + } + w.WriteHeader(200) + + writer := w + if closer, ok := response.Response.Data.(io.Closer); ok { + defer closer.Close() + } + if _, err := io.Copy(writer, response.Response); err != nil { + return errors.Wrap(err, "write") + } + + return nil + + case *DownloadAttachmentBadRequest: + w.Header().Set("Content-Type", "application/json; charset=utf-8") + w.Header().Set("Access-Control-Expose-Headers", "X-Instance-Id,X-Request-Id") + // Encoding response headers. + { + h := uri.NewHeaderEncoder(w.Header()) + // Encode "X-Instance-Id" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "X-Instance-Id", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.XInstanceID.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode X-Instance-Id header") + } + } + // Encode "X-Request-Id" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "X-Request-Id", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.XRequestID.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode X-Request-Id header") + } + } + } + w.WriteHeader(400) + + e := new(jx.Encoder) + response.Response.Encode(e) + if _, err := e.WriteTo(w); err != nil { + return errors.Wrap(err, "write") + } + + return nil + + case *GetAttachmentUnauthorizedHeaders: + w.Header().Set("Content-Type", "application/json; charset=utf-8") + w.Header().Set("Access-Control-Expose-Headers", "Www-Authenticate,X-Instance-Id,X-Request-Id") + // Encoding response headers. + { + h := uri.NewHeaderEncoder(w.Header()) + // Encode "WWW-Authenticate" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "WWW-Authenticate", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.WWWAuthenticate.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode WWW-Authenticate header") + } + } + // Encode "X-Instance-Id" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "X-Instance-Id", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.XInstanceID.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode X-Instance-Id header") + } + } + // Encode "X-Request-Id" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "X-Request-Id", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.XRequestID.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode X-Request-Id header") + } + } + } + w.WriteHeader(401) + + e := new(jx.Encoder) + response.Response.Encode(e) + if _, err := e.WriteTo(w); err != nil { + return errors.Wrap(err, "write") + } + + return nil + + case *DownloadAttachmentNotFound: + w.Header().Set("Content-Type", "application/json; charset=utf-8") + w.Header().Set("Access-Control-Expose-Headers", "X-Instance-Id,X-Request-Id") + // Encoding response headers. + { + h := uri.NewHeaderEncoder(w.Header()) + // Encode "X-Instance-Id" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "X-Instance-Id", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.XInstanceID.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode X-Instance-Id header") + } + } + // Encode "X-Request-Id" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "X-Request-Id", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.XRequestID.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode X-Request-Id header") + } + } + } + w.WriteHeader(404) + + e := new(jx.Encoder) + response.Response.Encode(e) + if _, err := e.WriteTo(w); err != nil { + return errors.Wrap(err, "write") + } + + return nil + + case *DownloadAttachmentConflict: + w.Header().Set("Content-Type", "application/json; charset=utf-8") + w.Header().Set("Access-Control-Expose-Headers", "X-Instance-Id,X-Request-Id") + // Encoding response headers. + { + h := uri.NewHeaderEncoder(w.Header()) + // Encode "X-Instance-Id" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "X-Instance-Id", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.XInstanceID.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode X-Instance-Id header") + } + } + // Encode "X-Request-Id" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "X-Request-Id", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.XRequestID.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode X-Request-Id header") + } + } + } + w.WriteHeader(409) + + e := new(jx.Encoder) + response.Response.Encode(e) + if _, err := e.WriteTo(w); err != nil { + return errors.Wrap(err, "write") + } + + return nil + + case *GetAttachmentTooManyRequestsHeaders: + w.Header().Set("Content-Type", "application/json; charset=utf-8") + w.Header().Set("Access-Control-Expose-Headers", "Retry-After,X-Instance-Id,X-Request-Id") + // Encoding response headers. + { + h := uri.NewHeaderEncoder(w.Header()) + // Encode "Retry-After" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "Retry-After", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.RetryAfter.Get(); ok { + return e.EncodeValue(conv.IntToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode Retry-After header") + } + } + // Encode "X-Instance-Id" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "X-Instance-Id", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.XInstanceID.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode X-Instance-Id header") + } + } + // Encode "X-Request-Id" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "X-Request-Id", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.XRequestID.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode X-Request-Id header") + } + } + } + w.WriteHeader(429) + + e := new(jx.Encoder) + response.Response.Encode(e) + if _, err := e.WriteTo(w); err != nil { + return errors.Wrap(err, "write") + } + + return nil + + case *DownloadAttachmentInternalServerError: + w.Header().Set("Content-Type", "application/json; charset=utf-8") + w.Header().Set("Access-Control-Expose-Headers", "X-Instance-Id,X-Request-Id") + // Encoding response headers. + { + h := uri.NewHeaderEncoder(w.Header()) + // Encode "X-Instance-Id" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "X-Instance-Id", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.XInstanceID.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode X-Instance-Id header") + } + } + // Encode "X-Request-Id" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "X-Request-Id", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.XRequestID.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode X-Request-Id header") + } + } + } + w.WriteHeader(500) + + e := new(jx.Encoder) + response.Response.Encode(e) + if _, err := e.WriteTo(w); err != nil { + return errors.Wrap(err, "write") + } + + return nil + + case *DownloadAttachmentServiceUnavailable: + w.Header().Set("Content-Type", "application/json; charset=utf-8") + w.Header().Set("Access-Control-Expose-Headers", "X-Instance-Id,X-Request-Id") + // Encoding response headers. + { + h := uri.NewHeaderEncoder(w.Header()) + // Encode "X-Instance-Id" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "X-Instance-Id", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.XInstanceID.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode X-Instance-Id header") + } + } + // Encode "X-Request-Id" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "X-Request-Id", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.XRequestID.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode X-Request-Id header") + } + } + } + w.WriteHeader(503) + + e := new(jx.Encoder) + response.Response.Encode(e) + if _, err := e.WriteTo(w); err != nil { + return errors.Wrap(err, "write") + } + + return nil + + default: + return errors.Errorf("unexpected response type: %T", response) + } +} + +func encodeGetAttachmentResponse(response GetAttachmentRes, w http.ResponseWriter) error { + switch response := response.(type) { + case *AttachmentHeaders: + w.Header().Set("Content-Type", "application/json; charset=utf-8") + w.Header().Set("Access-Control-Expose-Headers", "X-Instance-Id,X-Request-Id") + // Encoding response headers. + { + h := uri.NewHeaderEncoder(w.Header()) + // Encode "X-Instance-Id" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "X-Instance-Id", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.XInstanceID.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode X-Instance-Id header") + } + } + // Encode "X-Request-Id" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "X-Request-Id", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.XRequestID.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode X-Request-Id header") + } + } + } + w.WriteHeader(200) + + e := new(jx.Encoder) + response.Response.Encode(e) + if _, err := e.WriteTo(w); err != nil { + return errors.Wrap(err, "write") + } + + return nil + + case *GetAttachmentBadRequest: + w.Header().Set("Content-Type", "application/json; charset=utf-8") + w.Header().Set("Access-Control-Expose-Headers", "X-Instance-Id,X-Request-Id") + // Encoding response headers. + { + h := uri.NewHeaderEncoder(w.Header()) + // Encode "X-Instance-Id" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "X-Instance-Id", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.XInstanceID.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode X-Instance-Id header") + } + } + // Encode "X-Request-Id" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "X-Request-Id", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.XRequestID.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode X-Request-Id header") + } + } + } + w.WriteHeader(400) + + e := new(jx.Encoder) + response.Response.Encode(e) + if _, err := e.WriteTo(w); err != nil { + return errors.Wrap(err, "write") + } + + return nil + + case *GetAttachmentUnauthorizedHeaders: + w.Header().Set("Content-Type", "application/json; charset=utf-8") + w.Header().Set("Access-Control-Expose-Headers", "Www-Authenticate,X-Instance-Id,X-Request-Id") + // Encoding response headers. + { + h := uri.NewHeaderEncoder(w.Header()) + // Encode "WWW-Authenticate" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "WWW-Authenticate", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.WWWAuthenticate.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode WWW-Authenticate header") + } + } + // Encode "X-Instance-Id" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "X-Instance-Id", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.XInstanceID.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode X-Instance-Id header") + } + } + // Encode "X-Request-Id" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "X-Request-Id", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.XRequestID.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode X-Request-Id header") + } + } + } + w.WriteHeader(401) + + e := new(jx.Encoder) + response.Response.Encode(e) + if _, err := e.WriteTo(w); err != nil { + return errors.Wrap(err, "write") + } + + return nil + + case *GetAttachmentNotFound: + w.Header().Set("Content-Type", "application/json; charset=utf-8") + w.Header().Set("Access-Control-Expose-Headers", "X-Instance-Id,X-Request-Id") + // Encoding response headers. + { + h := uri.NewHeaderEncoder(w.Header()) + // Encode "X-Instance-Id" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "X-Instance-Id", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.XInstanceID.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode X-Instance-Id header") + } + } + // Encode "X-Request-Id" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "X-Request-Id", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.XRequestID.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode X-Request-Id header") + } + } + } + w.WriteHeader(404) + + e := new(jx.Encoder) + response.Response.Encode(e) + if _, err := e.WriteTo(w); err != nil { + return errors.Wrap(err, "write") + } + + return nil + + case *GetAttachmentConflict: + w.Header().Set("Content-Type", "application/json; charset=utf-8") + w.Header().Set("Access-Control-Expose-Headers", "X-Instance-Id,X-Request-Id") + // Encoding response headers. + { + h := uri.NewHeaderEncoder(w.Header()) + // Encode "X-Instance-Id" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "X-Instance-Id", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.XInstanceID.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode X-Instance-Id header") + } + } + // Encode "X-Request-Id" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "X-Request-Id", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.XRequestID.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode X-Request-Id header") + } + } + } + w.WriteHeader(409) + + e := new(jx.Encoder) + response.Response.Encode(e) + if _, err := e.WriteTo(w); err != nil { + return errors.Wrap(err, "write") + } + + return nil + + case *GetAttachmentTooManyRequestsHeaders: + w.Header().Set("Content-Type", "application/json; charset=utf-8") + w.Header().Set("Access-Control-Expose-Headers", "Retry-After,X-Instance-Id,X-Request-Id") + // Encoding response headers. + { + h := uri.NewHeaderEncoder(w.Header()) + // Encode "Retry-After" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "Retry-After", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.RetryAfter.Get(); ok { + return e.EncodeValue(conv.IntToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode Retry-After header") + } + } + // Encode "X-Instance-Id" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "X-Instance-Id", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.XInstanceID.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode X-Instance-Id header") + } + } + // Encode "X-Request-Id" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "X-Request-Id", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.XRequestID.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode X-Request-Id header") + } + } + } + w.WriteHeader(429) + + e := new(jx.Encoder) + response.Response.Encode(e) + if _, err := e.WriteTo(w); err != nil { + return errors.Wrap(err, "write") + } + + return nil + + case *GetAttachmentInternalServerError: + w.Header().Set("Content-Type", "application/json; charset=utf-8") + w.Header().Set("Access-Control-Expose-Headers", "X-Instance-Id,X-Request-Id") + // Encoding response headers. + { + h := uri.NewHeaderEncoder(w.Header()) + // Encode "X-Instance-Id" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "X-Instance-Id", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.XInstanceID.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode X-Instance-Id header") + } + } + // Encode "X-Request-Id" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "X-Request-Id", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.XRequestID.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode X-Request-Id header") + } + } + } + w.WriteHeader(500) + + e := new(jx.Encoder) + response.Response.Encode(e) + if _, err := e.WriteTo(w); err != nil { + return errors.Wrap(err, "write") + } + + return nil + + case *GetAttachmentServiceUnavailable: + w.Header().Set("Content-Type", "application/json; charset=utf-8") + w.Header().Set("Access-Control-Expose-Headers", "X-Instance-Id,X-Request-Id") + // Encoding response headers. + { + h := uri.NewHeaderEncoder(w.Header()) + // Encode "X-Instance-Id" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "X-Instance-Id", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.XInstanceID.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode X-Instance-Id header") + } + } + // Encode "X-Request-Id" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "X-Request-Id", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.XRequestID.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode X-Request-Id header") + } + } + } + w.WriteHeader(503) + + e := new(jx.Encoder) + response.Response.Encode(e) + if _, err := e.WriteTo(w); err != nil { + return errors.Wrap(err, "write") + } + + return nil + + default: + return errors.Errorf("unexpected response type: %T", response) + } +} + +func encodeGetChatResponse(response GetChatRes, w http.ResponseWriter) error { + switch response := response.(type) { + case *ChatHeaders: + w.Header().Set("Content-Type", "application/json; charset=utf-8") + w.Header().Set("Access-Control-Expose-Headers", "X-Instance-Id,X-Request-Id") + // Encoding response headers. + { + h := uri.NewHeaderEncoder(w.Header()) + // Encode "X-Instance-Id" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "X-Instance-Id", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.XInstanceID.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode X-Instance-Id header") + } + } + // Encode "X-Request-Id" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "X-Request-Id", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.XRequestID.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode X-Request-Id header") + } + } + } + w.WriteHeader(200) + + e := new(jx.Encoder) + response.Response.Encode(e) + if _, err := e.WriteTo(w); err != nil { + return errors.Wrap(err, "write") + } + + return nil + + case *GetChatBadRequest: + w.Header().Set("Content-Type", "application/json; charset=utf-8") + w.Header().Set("Access-Control-Expose-Headers", "X-Instance-Id,X-Request-Id") + // Encoding response headers. + { + h := uri.NewHeaderEncoder(w.Header()) + // Encode "X-Instance-Id" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "X-Instance-Id", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.XInstanceID.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode X-Instance-Id header") + } + } + // Encode "X-Request-Id" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "X-Request-Id", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.XRequestID.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode X-Request-Id header") + } + } + } + w.WriteHeader(400) + + e := new(jx.Encoder) + response.Response.Encode(e) + if _, err := e.WriteTo(w); err != nil { + return errors.Wrap(err, "write") + } + + return nil + + case *GetAttachmentUnauthorizedHeaders: + w.Header().Set("Content-Type", "application/json; charset=utf-8") + w.Header().Set("Access-Control-Expose-Headers", "Www-Authenticate,X-Instance-Id,X-Request-Id") + // Encoding response headers. + { + h := uri.NewHeaderEncoder(w.Header()) + // Encode "WWW-Authenticate" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "WWW-Authenticate", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.WWWAuthenticate.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode WWW-Authenticate header") + } + } + // Encode "X-Instance-Id" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "X-Instance-Id", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.XInstanceID.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode X-Instance-Id header") + } + } + // Encode "X-Request-Id" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "X-Request-Id", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.XRequestID.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode X-Request-Id header") + } + } + } + w.WriteHeader(401) + + e := new(jx.Encoder) + response.Response.Encode(e) + if _, err := e.WriteTo(w); err != nil { + return errors.Wrap(err, "write") + } + + return nil + + case *GetChatNotFound: + w.Header().Set("Content-Type", "application/json; charset=utf-8") + w.Header().Set("Access-Control-Expose-Headers", "X-Instance-Id,X-Request-Id") + // Encoding response headers. + { + h := uri.NewHeaderEncoder(w.Header()) + // Encode "X-Instance-Id" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "X-Instance-Id", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.XInstanceID.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode X-Instance-Id header") + } + } + // Encode "X-Request-Id" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "X-Request-Id", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.XRequestID.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode X-Request-Id header") + } + } + } + w.WriteHeader(404) + + e := new(jx.Encoder) + response.Response.Encode(e) + if _, err := e.WriteTo(w); err != nil { + return errors.Wrap(err, "write") + } + + return nil + + case *GetChatConflict: + w.Header().Set("Content-Type", "application/json; charset=utf-8") + w.Header().Set("Access-Control-Expose-Headers", "X-Instance-Id,X-Request-Id") + // Encoding response headers. + { + h := uri.NewHeaderEncoder(w.Header()) + // Encode "X-Instance-Id" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "X-Instance-Id", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.XInstanceID.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode X-Instance-Id header") + } + } + // Encode "X-Request-Id" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "X-Request-Id", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.XRequestID.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode X-Request-Id header") + } + } + } + w.WriteHeader(409) + + e := new(jx.Encoder) + response.Response.Encode(e) + if _, err := e.WriteTo(w); err != nil { + return errors.Wrap(err, "write") + } + + return nil + + case *GetAttachmentTooManyRequestsHeaders: + w.Header().Set("Content-Type", "application/json; charset=utf-8") + w.Header().Set("Access-Control-Expose-Headers", "Retry-After,X-Instance-Id,X-Request-Id") + // Encoding response headers. + { + h := uri.NewHeaderEncoder(w.Header()) + // Encode "Retry-After" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "Retry-After", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.RetryAfter.Get(); ok { + return e.EncodeValue(conv.IntToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode Retry-After header") + } + } + // Encode "X-Instance-Id" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "X-Instance-Id", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.XInstanceID.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode X-Instance-Id header") + } + } + // Encode "X-Request-Id" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "X-Request-Id", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.XRequestID.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode X-Request-Id header") + } + } + } + w.WriteHeader(429) + + e := new(jx.Encoder) + response.Response.Encode(e) + if _, err := e.WriteTo(w); err != nil { + return errors.Wrap(err, "write") + } + + return nil + + case *GetChatInternalServerError: + w.Header().Set("Content-Type", "application/json; charset=utf-8") + w.Header().Set("Access-Control-Expose-Headers", "X-Instance-Id,X-Request-Id") + // Encoding response headers. + { + h := uri.NewHeaderEncoder(w.Header()) + // Encode "X-Instance-Id" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "X-Instance-Id", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.XInstanceID.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode X-Instance-Id header") + } + } + // Encode "X-Request-Id" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "X-Request-Id", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.XRequestID.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode X-Request-Id header") + } + } + } + w.WriteHeader(500) + + e := new(jx.Encoder) + response.Response.Encode(e) + if _, err := e.WriteTo(w); err != nil { + return errors.Wrap(err, "write") + } + + return nil + + case *GetChatServiceUnavailable: + w.Header().Set("Content-Type", "application/json; charset=utf-8") + w.Header().Set("Access-Control-Expose-Headers", "X-Instance-Id,X-Request-Id") + // Encoding response headers. + { + h := uri.NewHeaderEncoder(w.Header()) + // Encode "X-Instance-Id" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "X-Instance-Id", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.XInstanceID.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode X-Instance-Id header") + } + } + // Encode "X-Request-Id" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "X-Request-Id", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.XRequestID.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode X-Request-Id header") + } + } + } + w.WriteHeader(503) + + e := new(jx.Encoder) + response.Response.Encode(e) + if _, err := e.WriteTo(w); err != nil { + return errors.Wrap(err, "write") + } + + return nil + + default: + return errors.Errorf("unexpected response type: %T", response) + } +} + +func encodeListChatsResponse(response ListChatsRes, w http.ResponseWriter) error { + switch response := response.(type) { + case *ChatPageHeaders: + w.Header().Set("Content-Type", "application/json; charset=utf-8") + w.Header().Set("Access-Control-Expose-Headers", "X-Instance-Id,X-Request-Id") + // Encoding response headers. + { + h := uri.NewHeaderEncoder(w.Header()) + // Encode "X-Instance-Id" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "X-Instance-Id", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.XInstanceID.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode X-Instance-Id header") + } + } + // Encode "X-Request-Id" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "X-Request-Id", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.XRequestID.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode X-Request-Id header") + } + } + } + w.WriteHeader(200) + + e := new(jx.Encoder) + response.Response.Encode(e) + if _, err := e.WriteTo(w); err != nil { + return errors.Wrap(err, "write") + } + + return nil + + case *ListChatsBadRequest: + w.Header().Set("Content-Type", "application/json; charset=utf-8") + w.Header().Set("Access-Control-Expose-Headers", "X-Instance-Id,X-Request-Id") + // Encoding response headers. + { + h := uri.NewHeaderEncoder(w.Header()) + // Encode "X-Instance-Id" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "X-Instance-Id", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.XInstanceID.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode X-Instance-Id header") + } + } + // Encode "X-Request-Id" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "X-Request-Id", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.XRequestID.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode X-Request-Id header") + } + } + } + w.WriteHeader(400) + + e := new(jx.Encoder) + response.Response.Encode(e) + if _, err := e.WriteTo(w); err != nil { + return errors.Wrap(err, "write") + } + + return nil + + case *GetAttachmentUnauthorizedHeaders: + w.Header().Set("Content-Type", "application/json; charset=utf-8") + w.Header().Set("Access-Control-Expose-Headers", "Www-Authenticate,X-Instance-Id,X-Request-Id") + // Encoding response headers. + { + h := uri.NewHeaderEncoder(w.Header()) + // Encode "WWW-Authenticate" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "WWW-Authenticate", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.WWWAuthenticate.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode WWW-Authenticate header") + } + } + // Encode "X-Instance-Id" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "X-Instance-Id", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.XInstanceID.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode X-Instance-Id header") + } + } + // Encode "X-Request-Id" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "X-Request-Id", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.XRequestID.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode X-Request-Id header") + } + } + } + w.WriteHeader(401) + + e := new(jx.Encoder) + response.Response.Encode(e) + if _, err := e.WriteTo(w); err != nil { + return errors.Wrap(err, "write") + } + + return nil + + case *ListChatsNotFound: + w.Header().Set("Content-Type", "application/json; charset=utf-8") + w.Header().Set("Access-Control-Expose-Headers", "X-Instance-Id,X-Request-Id") + // Encoding response headers. + { + h := uri.NewHeaderEncoder(w.Header()) + // Encode "X-Instance-Id" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "X-Instance-Id", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.XInstanceID.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode X-Instance-Id header") + } + } + // Encode "X-Request-Id" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "X-Request-Id", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.XRequestID.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode X-Request-Id header") + } + } + } + w.WriteHeader(404) + + e := new(jx.Encoder) + response.Response.Encode(e) + if _, err := e.WriteTo(w); err != nil { + return errors.Wrap(err, "write") + } + + return nil + + case *ListChatsConflict: + w.Header().Set("Content-Type", "application/json; charset=utf-8") + w.Header().Set("Access-Control-Expose-Headers", "X-Instance-Id,X-Request-Id") + // Encoding response headers. + { + h := uri.NewHeaderEncoder(w.Header()) + // Encode "X-Instance-Id" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "X-Instance-Id", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.XInstanceID.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode X-Instance-Id header") + } + } + // Encode "X-Request-Id" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "X-Request-Id", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.XRequestID.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode X-Request-Id header") + } + } + } + w.WriteHeader(409) + + e := new(jx.Encoder) + response.Response.Encode(e) + if _, err := e.WriteTo(w); err != nil { + return errors.Wrap(err, "write") + } + + return nil + + case *GetAttachmentTooManyRequestsHeaders: + w.Header().Set("Content-Type", "application/json; charset=utf-8") + w.Header().Set("Access-Control-Expose-Headers", "Retry-After,X-Instance-Id,X-Request-Id") + // Encoding response headers. + { + h := uri.NewHeaderEncoder(w.Header()) + // Encode "Retry-After" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "Retry-After", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.RetryAfter.Get(); ok { + return e.EncodeValue(conv.IntToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode Retry-After header") + } + } + // Encode "X-Instance-Id" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "X-Instance-Id", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.XInstanceID.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode X-Instance-Id header") + } + } + // Encode "X-Request-Id" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "X-Request-Id", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.XRequestID.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode X-Request-Id header") + } + } + } + w.WriteHeader(429) + + e := new(jx.Encoder) + response.Response.Encode(e) + if _, err := e.WriteTo(w); err != nil { + return errors.Wrap(err, "write") + } + + return nil + + case *ListChatsInternalServerError: + w.Header().Set("Content-Type", "application/json; charset=utf-8") + w.Header().Set("Access-Control-Expose-Headers", "X-Instance-Id,X-Request-Id") + // Encoding response headers. + { + h := uri.NewHeaderEncoder(w.Header()) + // Encode "X-Instance-Id" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "X-Instance-Id", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.XInstanceID.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode X-Instance-Id header") + } + } + // Encode "X-Request-Id" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "X-Request-Id", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.XRequestID.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode X-Request-Id header") + } + } + } + w.WriteHeader(500) + + e := new(jx.Encoder) + response.Response.Encode(e) + if _, err := e.WriteTo(w); err != nil { + return errors.Wrap(err, "write") + } + + return nil + + case *ListChatsServiceUnavailable: + w.Header().Set("Content-Type", "application/json; charset=utf-8") + w.Header().Set("Access-Control-Expose-Headers", "X-Instance-Id,X-Request-Id") + // Encoding response headers. + { + h := uri.NewHeaderEncoder(w.Header()) + // Encode "X-Instance-Id" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "X-Instance-Id", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.XInstanceID.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode X-Instance-Id header") + } + } + // Encode "X-Request-Id" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "X-Request-Id", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.XRequestID.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode X-Request-Id header") + } + } + } + w.WriteHeader(503) + + e := new(jx.Encoder) + response.Response.Encode(e) + if _, err := e.WriteTo(w); err != nil { + return errors.Wrap(err, "write") + } + + return nil + + default: + return errors.Errorf("unexpected response type: %T", response) + } +} + +func encodeListMessagesResponse(response ListMessagesRes, w http.ResponseWriter) error { + switch response := response.(type) { + case *MessagePageHeaders: + w.Header().Set("Content-Type", "application/json; charset=utf-8") + w.Header().Set("Access-Control-Expose-Headers", "X-Instance-Id,X-Request-Id") + // Encoding response headers. + { + h := uri.NewHeaderEncoder(w.Header()) + // Encode "X-Instance-Id" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "X-Instance-Id", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.XInstanceID.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode X-Instance-Id header") + } + } + // Encode "X-Request-Id" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "X-Request-Id", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.XRequestID.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode X-Request-Id header") + } + } + } + w.WriteHeader(200) + + e := new(jx.Encoder) + response.Response.Encode(e) + if _, err := e.WriteTo(w); err != nil { + return errors.Wrap(err, "write") + } + + return nil + + case *ListMessagesBadRequest: + w.Header().Set("Content-Type", "application/json; charset=utf-8") + w.Header().Set("Access-Control-Expose-Headers", "X-Instance-Id,X-Request-Id") + // Encoding response headers. + { + h := uri.NewHeaderEncoder(w.Header()) + // Encode "X-Instance-Id" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "X-Instance-Id", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.XInstanceID.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode X-Instance-Id header") + } + } + // Encode "X-Request-Id" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "X-Request-Id", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.XRequestID.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode X-Request-Id header") + } + } + } + w.WriteHeader(400) + + e := new(jx.Encoder) + response.Response.Encode(e) + if _, err := e.WriteTo(w); err != nil { + return errors.Wrap(err, "write") + } + + return nil + + case *GetAttachmentUnauthorizedHeaders: + w.Header().Set("Content-Type", "application/json; charset=utf-8") + w.Header().Set("Access-Control-Expose-Headers", "Www-Authenticate,X-Instance-Id,X-Request-Id") + // Encoding response headers. + { + h := uri.NewHeaderEncoder(w.Header()) + // Encode "WWW-Authenticate" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "WWW-Authenticate", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.WWWAuthenticate.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode WWW-Authenticate header") + } + } + // Encode "X-Instance-Id" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "X-Instance-Id", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.XInstanceID.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode X-Instance-Id header") + } + } + // Encode "X-Request-Id" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "X-Request-Id", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.XRequestID.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode X-Request-Id header") + } + } + } + w.WriteHeader(401) + + e := new(jx.Encoder) + response.Response.Encode(e) + if _, err := e.WriteTo(w); err != nil { + return errors.Wrap(err, "write") + } + + return nil + + case *ListMessagesNotFound: + w.Header().Set("Content-Type", "application/json; charset=utf-8") + w.Header().Set("Access-Control-Expose-Headers", "X-Instance-Id,X-Request-Id") + // Encoding response headers. + { + h := uri.NewHeaderEncoder(w.Header()) + // Encode "X-Instance-Id" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "X-Instance-Id", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.XInstanceID.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode X-Instance-Id header") + } + } + // Encode "X-Request-Id" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "X-Request-Id", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.XRequestID.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode X-Request-Id header") + } + } + } + w.WriteHeader(404) + + e := new(jx.Encoder) + response.Response.Encode(e) + if _, err := e.WriteTo(w); err != nil { + return errors.Wrap(err, "write") + } + + return nil + + case *ListMessagesConflict: + w.Header().Set("Content-Type", "application/json; charset=utf-8") + w.Header().Set("Access-Control-Expose-Headers", "X-Instance-Id,X-Request-Id") + // Encoding response headers. + { + h := uri.NewHeaderEncoder(w.Header()) + // Encode "X-Instance-Id" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "X-Instance-Id", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.XInstanceID.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode X-Instance-Id header") + } + } + // Encode "X-Request-Id" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "X-Request-Id", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.XRequestID.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode X-Request-Id header") + } + } + } + w.WriteHeader(409) + + e := new(jx.Encoder) + response.Response.Encode(e) + if _, err := e.WriteTo(w); err != nil { + return errors.Wrap(err, "write") + } + + return nil + + case *GetAttachmentTooManyRequestsHeaders: + w.Header().Set("Content-Type", "application/json; charset=utf-8") + w.Header().Set("Access-Control-Expose-Headers", "Retry-After,X-Instance-Id,X-Request-Id") + // Encoding response headers. + { + h := uri.NewHeaderEncoder(w.Header()) + // Encode "Retry-After" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "Retry-After", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.RetryAfter.Get(); ok { + return e.EncodeValue(conv.IntToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode Retry-After header") + } + } + // Encode "X-Instance-Id" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "X-Instance-Id", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.XInstanceID.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode X-Instance-Id header") + } + } + // Encode "X-Request-Id" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "X-Request-Id", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.XRequestID.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode X-Request-Id header") + } + } + } + w.WriteHeader(429) + + e := new(jx.Encoder) + response.Response.Encode(e) + if _, err := e.WriteTo(w); err != nil { + return errors.Wrap(err, "write") + } + + return nil + + case *ListMessagesInternalServerError: + w.Header().Set("Content-Type", "application/json; charset=utf-8") + w.Header().Set("Access-Control-Expose-Headers", "X-Instance-Id,X-Request-Id") + // Encoding response headers. + { + h := uri.NewHeaderEncoder(w.Header()) + // Encode "X-Instance-Id" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "X-Instance-Id", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.XInstanceID.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode X-Instance-Id header") + } + } + // Encode "X-Request-Id" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "X-Request-Id", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.XRequestID.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode X-Request-Id header") + } + } + } + w.WriteHeader(500) + + e := new(jx.Encoder) + response.Response.Encode(e) + if _, err := e.WriteTo(w); err != nil { + return errors.Wrap(err, "write") + } + + return nil + + case *ListMessagesServiceUnavailable: + w.Header().Set("Content-Type", "application/json; charset=utf-8") + w.Header().Set("Access-Control-Expose-Headers", "X-Instance-Id,X-Request-Id") + // Encoding response headers. + { + h := uri.NewHeaderEncoder(w.Header()) + // Encode "X-Instance-Id" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "X-Instance-Id", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.XInstanceID.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode X-Instance-Id header") + } + } + // Encode "X-Request-Id" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "X-Request-Id", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.XRequestID.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode X-Request-Id header") + } + } + } + w.WriteHeader(503) + + e := new(jx.Encoder) + response.Response.Encode(e) + if _, err := e.WriteTo(w); err != nil { + return errors.Wrap(err, "write") + } + + return nil + + default: + return errors.Errorf("unexpected response type: %T", response) + } +} + +func encodeLivenessResponse(response LivenessRes, w http.ResponseWriter) error { + switch response := response.(type) { + case *HealthHeaders: + w.Header().Set("Content-Type", "application/json; charset=utf-8") + w.Header().Set("Access-Control-Expose-Headers", "X-Instance-Id,X-Request-Id") + // Encoding response headers. + { + h := uri.NewHeaderEncoder(w.Header()) + // Encode "X-Instance-Id" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "X-Instance-Id", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.XInstanceID.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode X-Instance-Id header") + } + } + // Encode "X-Request-Id" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "X-Request-Id", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.XRequestID.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode X-Request-Id header") + } + } + } + w.WriteHeader(200) + + e := new(jx.Encoder) + response.Response.Encode(e) + if _, err := e.WriteTo(w); err != nil { + return errors.Wrap(err, "write") + } + + return nil + + case *ErrorHeaders: + w.Header().Set("Content-Type", "application/json; charset=utf-8") + w.Header().Set("Access-Control-Expose-Headers", "X-Instance-Id,X-Request-Id") + // Encoding response headers. + { + h := uri.NewHeaderEncoder(w.Header()) + // Encode "X-Instance-Id" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "X-Instance-Id", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.XInstanceID.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode X-Instance-Id header") + } + } + // Encode "X-Request-Id" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "X-Request-Id", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.XRequestID.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode X-Request-Id header") + } + } + } + w.WriteHeader(500) + + e := new(jx.Encoder) + response.Response.Encode(e) + if _, err := e.WriteTo(w); err != nil { + return errors.Wrap(err, "write") + } + + return nil + + default: + return errors.Errorf("unexpected response type: %T", response) + } +} + +func encodeReadinessResponse(response ReadinessRes, w http.ResponseWriter) error { + switch response := response.(type) { + case *HealthHeaders: + w.Header().Set("Content-Type", "application/json; charset=utf-8") + w.Header().Set("Access-Control-Expose-Headers", "X-Instance-Id,X-Request-Id") + // Encoding response headers. + { + h := uri.NewHeaderEncoder(w.Header()) + // Encode "X-Instance-Id" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "X-Instance-Id", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.XInstanceID.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode X-Instance-Id header") + } + } + // Encode "X-Request-Id" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "X-Request-Id", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.XRequestID.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode X-Request-Id header") + } + } + } + w.WriteHeader(200) + + e := new(jx.Encoder) + response.Response.Encode(e) + if _, err := e.WriteTo(w); err != nil { + return errors.Wrap(err, "write") + } + + return nil + + case *ReadinessInternalServerError: + w.Header().Set("Content-Type", "application/json; charset=utf-8") + w.Header().Set("Access-Control-Expose-Headers", "X-Instance-Id,X-Request-Id") + // Encoding response headers. + { + h := uri.NewHeaderEncoder(w.Header()) + // Encode "X-Instance-Id" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "X-Instance-Id", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.XInstanceID.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode X-Instance-Id header") + } + } + // Encode "X-Request-Id" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "X-Request-Id", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.XRequestID.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode X-Request-Id header") + } + } + } + w.WriteHeader(500) + + e := new(jx.Encoder) + response.Response.Encode(e) + if _, err := e.WriteTo(w); err != nil { + return errors.Wrap(err, "write") + } + + return nil + + case *ReadinessServiceUnavailable: + w.Header().Set("Content-Type", "application/json; charset=utf-8") + w.Header().Set("Access-Control-Expose-Headers", "X-Instance-Id,X-Request-Id") + // Encoding response headers. + { + h := uri.NewHeaderEncoder(w.Header()) + // Encode "X-Instance-Id" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "X-Instance-Id", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.XInstanceID.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode X-Instance-Id header") + } + } + // Encode "X-Request-Id" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "X-Request-Id", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.XRequestID.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode X-Request-Id header") + } + } + } + w.WriteHeader(503) + + e := new(jx.Encoder) + response.Response.Encode(e) + if _, err := e.WriteTo(w); err != nil { + return errors.Wrap(err, "write") + } + + return nil + + default: + return errors.Errorf("unexpected response type: %T", response) + } +} + +func encodeRegisterUserResponse(response RegisterUserRes, w http.ResponseWriter) error { + switch response := response.(type) { + case *UserHeaders: + w.Header().Set("Content-Type", "application/json; charset=utf-8") + w.Header().Set("Access-Control-Expose-Headers", "X-Instance-Id,X-Request-Id") + // Encoding response headers. + { + h := uri.NewHeaderEncoder(w.Header()) + // Encode "X-Instance-Id" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "X-Instance-Id", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.XInstanceID.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode X-Instance-Id header") + } + } + // Encode "X-Request-Id" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "X-Request-Id", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.XRequestID.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode X-Request-Id header") + } + } + } + w.WriteHeader(201) + + e := new(jx.Encoder) + response.Response.Encode(e) + if _, err := e.WriteTo(w); err != nil { + return errors.Wrap(err, "write") + } + + return nil + + case *RegisterUserBadRequest: + w.Header().Set("Content-Type", "application/json; charset=utf-8") + w.Header().Set("Access-Control-Expose-Headers", "X-Instance-Id,X-Request-Id") + // Encoding response headers. + { + h := uri.NewHeaderEncoder(w.Header()) + // Encode "X-Instance-Id" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "X-Instance-Id", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.XInstanceID.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode X-Instance-Id header") + } + } + // Encode "X-Request-Id" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "X-Request-Id", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.XRequestID.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode X-Request-Id header") + } + } + } + w.WriteHeader(400) + + e := new(jx.Encoder) + response.Response.Encode(e) + if _, err := e.WriteTo(w); err != nil { + return errors.Wrap(err, "write") + } + + return nil + + case *RegisterUserConflict: + w.Header().Set("Content-Type", "application/json; charset=utf-8") + w.Header().Set("Access-Control-Expose-Headers", "X-Instance-Id,X-Request-Id") + // Encoding response headers. + { + h := uri.NewHeaderEncoder(w.Header()) + // Encode "X-Instance-Id" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "X-Instance-Id", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.XInstanceID.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode X-Instance-Id header") + } + } + // Encode "X-Request-Id" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "X-Request-Id", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.XRequestID.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode X-Request-Id header") + } + } + } + w.WriteHeader(409) + + e := new(jx.Encoder) + response.Response.Encode(e) + if _, err := e.WriteTo(w); err != nil { + return errors.Wrap(err, "write") + } + + return nil + + case *GetAttachmentTooManyRequestsHeaders: + w.Header().Set("Content-Type", "application/json; charset=utf-8") + w.Header().Set("Access-Control-Expose-Headers", "Retry-After,X-Instance-Id,X-Request-Id") + // Encoding response headers. + { + h := uri.NewHeaderEncoder(w.Header()) + // Encode "Retry-After" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "Retry-After", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.RetryAfter.Get(); ok { + return e.EncodeValue(conv.IntToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode Retry-After header") + } + } + // Encode "X-Instance-Id" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "X-Instance-Id", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.XInstanceID.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode X-Instance-Id header") + } + } + // Encode "X-Request-Id" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "X-Request-Id", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.XRequestID.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode X-Request-Id header") + } + } + } + w.WriteHeader(429) + + e := new(jx.Encoder) + response.Response.Encode(e) + if _, err := e.WriteTo(w); err != nil { + return errors.Wrap(err, "write") + } + + return nil + + case *RegisterUserInternalServerError: + w.Header().Set("Content-Type", "application/json; charset=utf-8") + w.Header().Set("Access-Control-Expose-Headers", "X-Instance-Id,X-Request-Id") + // Encoding response headers. + { + h := uri.NewHeaderEncoder(w.Header()) + // Encode "X-Instance-Id" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "X-Instance-Id", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.XInstanceID.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode X-Instance-Id header") + } + } + // Encode "X-Request-Id" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "X-Request-Id", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.XRequestID.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode X-Request-Id header") + } + } + } + w.WriteHeader(500) + + e := new(jx.Encoder) + response.Response.Encode(e) + if _, err := e.WriteTo(w); err != nil { + return errors.Wrap(err, "write") + } + + return nil + + case *RegisterUserServiceUnavailable: + w.Header().Set("Content-Type", "application/json; charset=utf-8") + w.Header().Set("Access-Control-Expose-Headers", "X-Instance-Id,X-Request-Id") + // Encoding response headers. + { + h := uri.NewHeaderEncoder(w.Header()) + // Encode "X-Instance-Id" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "X-Instance-Id", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.XInstanceID.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode X-Instance-Id header") + } + } + // Encode "X-Request-Id" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "X-Request-Id", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.XRequestID.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode X-Request-Id header") + } + } + } + w.WriteHeader(503) + + e := new(jx.Encoder) + response.Response.Encode(e) + if _, err := e.WriteTo(w); err != nil { + return errors.Wrap(err, "write") + } + + return nil + + default: + return errors.Errorf("unexpected response type: %T", response) + } +} + +func encodeRevokeSessionResponse(response RevokeSessionRes, w http.ResponseWriter) error { + switch response := response.(type) { + case *RevokeSessionNoContent: + w.Header().Set("Access-Control-Expose-Headers", "X-Instance-Id,X-Request-Id") + // Encoding response headers. + { + h := uri.NewHeaderEncoder(w.Header()) + // Encode "X-Instance-Id" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "X-Instance-Id", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.XInstanceID.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode X-Instance-Id header") + } + } + // Encode "X-Request-Id" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "X-Request-Id", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.XRequestID.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode X-Request-Id header") + } + } + } + w.WriteHeader(204) + + return nil + + case *GetAttachmentUnauthorizedHeaders: + w.Header().Set("Content-Type", "application/json; charset=utf-8") + w.Header().Set("Access-Control-Expose-Headers", "Www-Authenticate,X-Instance-Id,X-Request-Id") + // Encoding response headers. + { + h := uri.NewHeaderEncoder(w.Header()) + // Encode "WWW-Authenticate" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "WWW-Authenticate", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.WWWAuthenticate.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode WWW-Authenticate header") + } + } + // Encode "X-Instance-Id" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "X-Instance-Id", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.XInstanceID.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode X-Instance-Id header") + } + } + // Encode "X-Request-Id" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "X-Request-Id", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.XRequestID.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode X-Request-Id header") + } + } + } + w.WriteHeader(401) + + e := new(jx.Encoder) + response.Response.Encode(e) + if _, err := e.WriteTo(w); err != nil { + return errors.Wrap(err, "write") + } + + return nil + + case *GetAttachmentTooManyRequestsHeaders: + w.Header().Set("Content-Type", "application/json; charset=utf-8") + w.Header().Set("Access-Control-Expose-Headers", "Retry-After,X-Instance-Id,X-Request-Id") + // Encoding response headers. + { + h := uri.NewHeaderEncoder(w.Header()) + // Encode "Retry-After" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "Retry-After", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.RetryAfter.Get(); ok { + return e.EncodeValue(conv.IntToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode Retry-After header") + } + } + // Encode "X-Instance-Id" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "X-Instance-Id", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.XInstanceID.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode X-Instance-Id header") + } + } + // Encode "X-Request-Id" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "X-Request-Id", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.XRequestID.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode X-Request-Id header") + } + } + } + w.WriteHeader(429) + + e := new(jx.Encoder) + response.Response.Encode(e) + if _, err := e.WriteTo(w); err != nil { + return errors.Wrap(err, "write") + } + + return nil + + case *RevokeSessionInternalServerError: + w.Header().Set("Content-Type", "application/json; charset=utf-8") + w.Header().Set("Access-Control-Expose-Headers", "X-Instance-Id,X-Request-Id") + // Encoding response headers. + { + h := uri.NewHeaderEncoder(w.Header()) + // Encode "X-Instance-Id" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "X-Instance-Id", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.XInstanceID.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode X-Instance-Id header") + } + } + // Encode "X-Request-Id" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "X-Request-Id", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.XRequestID.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode X-Request-Id header") + } + } + } + w.WriteHeader(500) + + e := new(jx.Encoder) + response.Response.Encode(e) + if _, err := e.WriteTo(w); err != nil { + return errors.Wrap(err, "write") + } + + return nil + + case *RevokeSessionServiceUnavailable: + w.Header().Set("Content-Type", "application/json; charset=utf-8") + w.Header().Set("Access-Control-Expose-Headers", "X-Instance-Id,X-Request-Id") + // Encoding response headers. + { + h := uri.NewHeaderEncoder(w.Header()) + // Encode "X-Instance-Id" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "X-Instance-Id", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.XInstanceID.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode X-Instance-Id header") + } + } + // Encode "X-Request-Id" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "X-Request-Id", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.XRequestID.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode X-Request-Id header") + } + } + } + w.WriteHeader(503) + + e := new(jx.Encoder) + response.Response.Encode(e) + if _, err := e.WriteTo(w); err != nil { + return errors.Wrap(err, "write") + } + + return nil + + default: + return errors.Errorf("unexpected response type: %T", response) + } +} + +func encodeUploadAttachmentResponse(response UploadAttachmentRes, w http.ResponseWriter) error { + switch response := response.(type) { + case *AttachmentHeaders: + w.Header().Set("Content-Type", "application/json; charset=utf-8") + w.Header().Set("Access-Control-Expose-Headers", "X-Instance-Id,X-Request-Id") + // Encoding response headers. + { + h := uri.NewHeaderEncoder(w.Header()) + // Encode "X-Instance-Id" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "X-Instance-Id", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.XInstanceID.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode X-Instance-Id header") + } + } + // Encode "X-Request-Id" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "X-Request-Id", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.XRequestID.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode X-Request-Id header") + } + } + } + w.WriteHeader(202) + + e := new(jx.Encoder) + response.Response.Encode(e) + if _, err := e.WriteTo(w); err != nil { + return errors.Wrap(err, "write") + } + + return nil + + case *UploadAttachmentBadRequest: + w.Header().Set("Content-Type", "application/json; charset=utf-8") + w.Header().Set("Access-Control-Expose-Headers", "X-Instance-Id,X-Request-Id") + // Encoding response headers. + { + h := uri.NewHeaderEncoder(w.Header()) + // Encode "X-Instance-Id" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "X-Instance-Id", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.XInstanceID.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode X-Instance-Id header") + } + } + // Encode "X-Request-Id" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "X-Request-Id", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.XRequestID.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode X-Request-Id header") + } + } + } + w.WriteHeader(400) + + e := new(jx.Encoder) + response.Response.Encode(e) + if _, err := e.WriteTo(w); err != nil { + return errors.Wrap(err, "write") + } + + return nil + + case *GetAttachmentUnauthorizedHeaders: + w.Header().Set("Content-Type", "application/json; charset=utf-8") + w.Header().Set("Access-Control-Expose-Headers", "Www-Authenticate,X-Instance-Id,X-Request-Id") + // Encoding response headers. + { + h := uri.NewHeaderEncoder(w.Header()) + // Encode "WWW-Authenticate" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "WWW-Authenticate", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.WWWAuthenticate.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode WWW-Authenticate header") + } + } + // Encode "X-Instance-Id" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "X-Instance-Id", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.XInstanceID.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode X-Instance-Id header") + } + } + // Encode "X-Request-Id" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "X-Request-Id", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.XRequestID.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode X-Request-Id header") + } + } + } + w.WriteHeader(401) + + e := new(jx.Encoder) + response.Response.Encode(e) + if _, err := e.WriteTo(w); err != nil { + return errors.Wrap(err, "write") + } + + return nil + + case *UploadAttachmentNotFound: + w.Header().Set("Content-Type", "application/json; charset=utf-8") + w.Header().Set("Access-Control-Expose-Headers", "X-Instance-Id,X-Request-Id") + // Encoding response headers. + { + h := uri.NewHeaderEncoder(w.Header()) + // Encode "X-Instance-Id" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "X-Instance-Id", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.XInstanceID.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode X-Instance-Id header") + } + } + // Encode "X-Request-Id" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "X-Request-Id", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.XRequestID.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode X-Request-Id header") + } + } + } + w.WriteHeader(404) + + e := new(jx.Encoder) + response.Response.Encode(e) + if _, err := e.WriteTo(w); err != nil { + return errors.Wrap(err, "write") + } + + return nil + + case *UploadAttachmentRequestEntityTooLarge: + w.Header().Set("Content-Type", "application/json; charset=utf-8") + w.Header().Set("Access-Control-Expose-Headers", "X-Instance-Id,X-Request-Id") + // Encoding response headers. + { + h := uri.NewHeaderEncoder(w.Header()) + // Encode "X-Instance-Id" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "X-Instance-Id", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.XInstanceID.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode X-Instance-Id header") + } + } + // Encode "X-Request-Id" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "X-Request-Id", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.XRequestID.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode X-Request-Id header") + } + } + } + w.WriteHeader(413) + + e := new(jx.Encoder) + response.Response.Encode(e) + if _, err := e.WriteTo(w); err != nil { + return errors.Wrap(err, "write") + } + + return nil + + case *UploadAttachmentUnsupportedMediaType: + w.Header().Set("Content-Type", "application/json; charset=utf-8") + w.Header().Set("Access-Control-Expose-Headers", "X-Instance-Id,X-Request-Id") + // Encoding response headers. + { + h := uri.NewHeaderEncoder(w.Header()) + // Encode "X-Instance-Id" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "X-Instance-Id", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.XInstanceID.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode X-Instance-Id header") + } + } + // Encode "X-Request-Id" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "X-Request-Id", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.XRequestID.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode X-Request-Id header") + } + } + } + w.WriteHeader(415) + + e := new(jx.Encoder) + response.Response.Encode(e) + if _, err := e.WriteTo(w); err != nil { + return errors.Wrap(err, "write") + } + + return nil + + case *GetAttachmentTooManyRequestsHeaders: + w.Header().Set("Content-Type", "application/json; charset=utf-8") + w.Header().Set("Access-Control-Expose-Headers", "Retry-After,X-Instance-Id,X-Request-Id") + // Encoding response headers. + { + h := uri.NewHeaderEncoder(w.Header()) + // Encode "Retry-After" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "Retry-After", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.RetryAfter.Get(); ok { + return e.EncodeValue(conv.IntToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode Retry-After header") + } + } + // Encode "X-Instance-Id" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "X-Instance-Id", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.XInstanceID.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode X-Instance-Id header") + } + } + // Encode "X-Request-Id" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "X-Request-Id", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.XRequestID.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode X-Request-Id header") + } + } + } + w.WriteHeader(429) + + e := new(jx.Encoder) + response.Response.Encode(e) + if _, err := e.WriteTo(w); err != nil { + return errors.Wrap(err, "write") + } + + return nil + + case *UploadAttachmentInternalServerError: + w.Header().Set("Content-Type", "application/json; charset=utf-8") + w.Header().Set("Access-Control-Expose-Headers", "X-Instance-Id,X-Request-Id") + // Encoding response headers. + { + h := uri.NewHeaderEncoder(w.Header()) + // Encode "X-Instance-Id" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "X-Instance-Id", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.XInstanceID.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode X-Instance-Id header") + } + } + // Encode "X-Request-Id" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "X-Request-Id", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.XRequestID.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode X-Request-Id header") + } + } + } + w.WriteHeader(500) + + e := new(jx.Encoder) + response.Response.Encode(e) + if _, err := e.WriteTo(w); err != nil { + return errors.Wrap(err, "write") + } + + return nil + + case *UploadAttachmentServiceUnavailable: + w.Header().Set("Content-Type", "application/json; charset=utf-8") + w.Header().Set("Access-Control-Expose-Headers", "X-Instance-Id,X-Request-Id") + // Encoding response headers. + { + h := uri.NewHeaderEncoder(w.Header()) + // Encode "X-Instance-Id" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "X-Instance-Id", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.XInstanceID.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode X-Instance-Id header") + } + } + // Encode "X-Request-Id" header. + { + cfg := uri.HeaderParameterEncodingConfig{ + Name: "X-Request-Id", + Explode: false, + } + if err := h.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := response.XRequestID.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode X-Request-Id header") + } + } + } + w.WriteHeader(503) + + e := new(jx.Encoder) + response.Response.Encode(e) + if _, err := e.WriteTo(w); err != nil { + return errors.Wrap(err, "write") + } + + return nil + + default: + return errors.Errorf("unexpected response type: %T", response) + } +} diff --git a/internal/transport/rest/internal/oas/oas_router_gen.go b/internal/transport/rest/internal/oas/oas_router_gen.go new file mode 100644 index 0000000..a52fc99 --- /dev/null +++ b/internal/transport/rest/internal/oas/oas_router_gen.go @@ -0,0 +1,996 @@ +// Code generated by ogen, DO NOT EDIT. + +package oas + +import ( + "net/http" + "net/url" + "strings" + + "github.com/ogen-go/ogen/uri" +) + +var ( + rn10AllowedHeaders = map[string]string{ + "GET": "Authorization", + } + rn11AllowedHeaders = map[string]string{ + "GET": "Authorization", + } + rn6AllowedHeaders = map[string]string{ + "POST": "Authorization", + } + rn17AllowedHeaders = map[string]string{ + "DELETE": "Authorization", + } + rn1AllowedHeaders = map[string]string{ + "GET": "Authorization", + "POST": "Authorization,Content-Type", + } + rn3AllowedHeaders = map[string]string{ + "GET": "Authorization", + } + rn19AllowedHeaders = map[string]string{ + "POST": "Authorization,Content-Type", + } + rn4AllowedHeaders = map[string]string{ + "GET": "Authorization", + "POST": "Authorization,Content-Type,Idempotency-Key", + } + rn16AllowedHeaders = map[string]string{ + "POST": "Content-Type", + } + rn7AllowedHeaders = map[string]string{ + "GET": "Authorization", + } +) + +func (s *Server) cutPrefix(path string) (string, bool) { + prefix := s.cfg.Prefix + if prefix == "" { + return path, true + } + if !strings.HasPrefix(path, prefix) { + // Prefix doesn't match. + return "", false + } + // Cut prefix from the path. + return strings.TrimPrefix(path, prefix), true +} + +// ServeHTTP serves http request as defined by OpenAPI v3 specification, +// calling handler that matches the path or returning not found error. +func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) { + elem := r.URL.Path + elemIsEscaped := false + if rawPath := r.URL.RawPath; rawPath != "" { + if normalized, ok := uri.NormalizeEscapedPath(rawPath); ok { + elem = normalized + elemIsEscaped = strings.ContainsRune(elem, '%') + } + } + + elem, ok := s.cutPrefix(elem) + if !ok || len(elem) == 0 { + s.notFound(w, r) + return + } + args := [1]string{} + + // Static code generated router with unwrapped path search. + switch { + default: + if len(elem) == 0 { + break + } + switch elem[0] { + case '/': // Prefix: "/" + + if l := len("/"); len(elem) >= l && elem[0:l] == "/" { + elem = elem[l:] + } else { + break + } + + if len(elem) == 0 { + break + } + switch elem[0] { + case 'a': // Prefix: "api/v1/" + + if l := len("api/v1/"); len(elem) >= l && elem[0:l] == "api/v1/" { + elem = elem[l:] + } else { + break + } + + if len(elem) == 0 { + break + } + switch elem[0] { + case 'a': // Prefix: "a" + + if l := len("a"); len(elem) >= l && elem[0:l] == "a" { + elem = elem[l:] + } else { + break + } + + if len(elem) == 0 { + break + } + switch elem[0] { + case 't': // Prefix: "ttachments/" + + if l := len("ttachments/"); len(elem) >= l && elem[0:l] == "ttachments/" { + elem = elem[l:] + } else { + break + } + + // Param: "attachment_id" + // Match until "/" + idx := strings.IndexByte(elem, '/') + if idx < 0 { + idx = len(elem) + } + args[0] = elem[:idx] + elem = elem[idx:] + + if len(elem) == 0 { + switch r.Method { + case "GET": + s.handleGetAttachmentRequest([1]string{ + args[0], + }, elemIsEscaped, w, r) + default: + s.notAllowed(w, r, notAllowedParams{ + allowedMethods: "GET", + allowedHeaders: rn10AllowedHeaders, + acceptPost: "", + acceptPatch: "", + }) + } + + return + } + switch elem[0] { + case '/': // Prefix: "/content" + + if l := len("/content"); len(elem) >= l && elem[0:l] == "/content" { + elem = elem[l:] + } else { + break + } + + if len(elem) == 0 { + // Leaf node. + switch r.Method { + case "GET": + s.handleDownloadAttachmentRequest([1]string{ + args[0], + }, elemIsEscaped, w, r) + default: + s.notAllowed(w, r, notAllowedParams{ + allowedMethods: "GET", + allowedHeaders: rn11AllowedHeaders, + acceptPost: "", + acceptPatch: "", + }) + } + + return + } + + } + + case 'u': // Prefix: "uth/sessions" + + if l := len("uth/sessions"); len(elem) >= l && elem[0:l] == "uth/sessions" { + elem = elem[l:] + } else { + break + } + + if len(elem) == 0 { + switch r.Method { + case "POST": + s.handleCreateSessionRequest([0]string{}, elemIsEscaped, w, r) + default: + s.notAllowed(w, r, notAllowedParams{ + allowedMethods: "POST", + allowedHeaders: rn6AllowedHeaders, + acceptPost: "", + acceptPatch: "", + }) + } + + return + } + switch elem[0] { + case '/': // Prefix: "/current" + + if l := len("/current"); len(elem) >= l && elem[0:l] == "/current" { + elem = elem[l:] + } else { + break + } + + if len(elem) == 0 { + // Leaf node. + switch r.Method { + case "DELETE": + s.handleRevokeSessionRequest([0]string{}, elemIsEscaped, w, r) + default: + s.notAllowed(w, r, notAllowedParams{ + allowedMethods: "DELETE", + allowedHeaders: rn17AllowedHeaders, + acceptPost: "", + acceptPatch: "", + }) + } + + return + } + + } + + } + + case 'c': // Prefix: "chats" + + if l := len("chats"); len(elem) >= l && elem[0:l] == "chats" { + elem = elem[l:] + } else { + break + } + + if len(elem) == 0 { + switch r.Method { + case "GET": + s.handleListChatsRequest([0]string{}, elemIsEscaped, w, r) + case "POST": + s.handleCreateChatRequest([0]string{}, elemIsEscaped, w, r) + default: + s.notAllowed(w, r, notAllowedParams{ + allowedMethods: "GET,POST", + allowedHeaders: rn1AllowedHeaders, + acceptPost: "application/json", + acceptPatch: "", + }) + } + + return + } + switch elem[0] { + case '/': // Prefix: "/" + + if l := len("/"); len(elem) >= l && elem[0:l] == "/" { + elem = elem[l:] + } else { + break + } + + // Param: "chat_id" + // Match until "/" + idx := strings.IndexByte(elem, '/') + if idx < 0 { + idx = len(elem) + } + args[0] = elem[:idx] + elem = elem[idx:] + + if len(elem) == 0 { + switch r.Method { + case "GET": + s.handleGetChatRequest([1]string{ + args[0], + }, elemIsEscaped, w, r) + default: + s.notAllowed(w, r, notAllowedParams{ + allowedMethods: "GET", + allowedHeaders: rn3AllowedHeaders, + acceptPost: "", + acceptPatch: "", + }) + } + + return + } + switch elem[0] { + case '/': // Prefix: "/" + + if l := len("/"); len(elem) >= l && elem[0:l] == "/" { + elem = elem[l:] + } else { + break + } + + if len(elem) == 0 { + break + } + switch elem[0] { + case 'a': // Prefix: "attachments" + + if l := len("attachments"); len(elem) >= l && elem[0:l] == "attachments" { + elem = elem[l:] + } else { + break + } + + if len(elem) == 0 { + // Leaf node. + switch r.Method { + case "POST": + s.handleUploadAttachmentRequest([1]string{ + args[0], + }, elemIsEscaped, w, r) + default: + s.notAllowed(w, r, notAllowedParams{ + allowedMethods: "POST", + allowedHeaders: rn19AllowedHeaders, + acceptPost: "image/jpeg,image/png", + acceptPatch: "", + }) + } + + return + } + + case 'm': // Prefix: "messages" + + if l := len("messages"); len(elem) >= l && elem[0:l] == "messages" { + elem = elem[l:] + } else { + break + } + + if len(elem) == 0 { + // Leaf node. + switch r.Method { + case "GET": + s.handleListMessagesRequest([1]string{ + args[0], + }, elemIsEscaped, w, r) + case "POST": + s.handleCreateMessageRequest([1]string{ + args[0], + }, elemIsEscaped, w, r) + default: + s.notAllowed(w, r, notAllowedParams{ + allowedMethods: "GET,POST", + allowedHeaders: rn4AllowedHeaders, + acceptPost: "application/json", + acceptPatch: "", + }) + } + + return + } + + } + + } + + } + + case 'u': // Prefix: "users" + + if l := len("users"); len(elem) >= l && elem[0:l] == "users" { + elem = elem[l:] + } else { + break + } + + if len(elem) == 0 { + switch r.Method { + case "POST": + s.handleRegisterUserRequest([0]string{}, elemIsEscaped, w, r) + default: + s.notAllowed(w, r, notAllowedParams{ + allowedMethods: "POST", + allowedHeaders: rn16AllowedHeaders, + acceptPost: "application/json", + acceptPatch: "", + }) + } + + return + } + switch elem[0] { + case '/': // Prefix: "/me" + + if l := len("/me"); len(elem) >= l && elem[0:l] == "/me" { + elem = elem[l:] + } else { + break + } + + if len(elem) == 0 { + // Leaf node. + switch r.Method { + case "GET": + s.handleCurrentUserRequest([0]string{}, elemIsEscaped, w, r) + default: + s.notAllowed(w, r, notAllowedParams{ + allowedMethods: "GET", + allowedHeaders: rn7AllowedHeaders, + acceptPost: "", + acceptPatch: "", + }) + } + + return + } + + } + + } + + case 'h': // Prefix: "health/" + + if l := len("health/"); len(elem) >= l && elem[0:l] == "health/" { + elem = elem[l:] + } else { + break + } + + if len(elem) == 0 { + break + } + switch elem[0] { + case 'l': // Prefix: "live" + + if l := len("live"); len(elem) >= l && elem[0:l] == "live" { + elem = elem[l:] + } else { + break + } + + if len(elem) == 0 { + // Leaf node. + switch r.Method { + case "GET": + s.handleLivenessRequest([0]string{}, elemIsEscaped, w, r) + default: + s.notAllowed(w, r, notAllowedParams{ + allowedMethods: "GET", + allowedHeaders: nil, + acceptPost: "", + acceptPatch: "", + }) + } + + return + } + + case 'r': // Prefix: "ready" + + if l := len("ready"); len(elem) >= l && elem[0:l] == "ready" { + elem = elem[l:] + } else { + break + } + + if len(elem) == 0 { + // Leaf node. + switch r.Method { + case "GET": + s.handleReadinessRequest([0]string{}, elemIsEscaped, w, r) + default: + s.notAllowed(w, r, notAllowedParams{ + allowedMethods: "GET", + allowedHeaders: nil, + acceptPost: "", + acceptPatch: "", + }) + } + + return + } + + } + + } + + } + } + s.notFound(w, r) +} + +// Route is route object. +type Route struct { + name string + summary string + operationID string + operationGroup string + pathPattern string + count int + args [1]string +} + +// Name returns ogen operation name. +// +// It is guaranteed to be unique and not empty. +func (r Route) Name() string { + return r.name +} + +// Summary returns OpenAPI summary. +func (r Route) Summary() string { + return r.summary +} + +// OperationID returns OpenAPI operationId. +func (r Route) OperationID() string { + return r.operationID +} + +// OperationGroup returns the x-ogen-operation-group value. +func (r Route) OperationGroup() string { + return r.operationGroup +} + +// PathPattern returns OpenAPI path. +func (r Route) PathPattern() string { + return r.pathPattern +} + +// Args returns parsed arguments. +func (r Route) Args() []string { + return r.args[:r.count] +} + +// FindRoute finds Route for given method and path. +// +// Note: this method does not unescape path or handle reserved characters in path properly. Use FindPath instead. +func (s *Server) FindRoute(method, path string) (Route, bool) { + return s.FindPath(method, &url.URL{Path: path}) +} + +// FindPath finds Route for given method and URL. +func (s *Server) FindPath(method string, u *url.URL) (r Route, _ bool) { + var ( + elem = u.Path + args = r.args + ) + if rawPath := u.RawPath; rawPath != "" { + if normalized, ok := uri.NormalizeEscapedPath(rawPath); ok { + elem = normalized + } + defer func() { + for i, arg := range r.args[:r.count] { + if unescaped, err := url.PathUnescape(arg); err == nil { + r.args[i] = unescaped + } + } + }() + } + + elem, ok := s.cutPrefix(elem) + if !ok { + return r, false + } + + // Static code generated router with unwrapped path search. + switch { + default: + if len(elem) == 0 { + break + } + switch elem[0] { + case '/': // Prefix: "/" + + if l := len("/"); len(elem) >= l && elem[0:l] == "/" { + elem = elem[l:] + } else { + break + } + + if len(elem) == 0 { + break + } + switch elem[0] { + case 'a': // Prefix: "api/v1/" + + if l := len("api/v1/"); len(elem) >= l && elem[0:l] == "api/v1/" { + elem = elem[l:] + } else { + break + } + + if len(elem) == 0 { + break + } + switch elem[0] { + case 'a': // Prefix: "a" + + if l := len("a"); len(elem) >= l && elem[0:l] == "a" { + elem = elem[l:] + } else { + break + } + + if len(elem) == 0 { + break + } + switch elem[0] { + case 't': // Prefix: "ttachments/" + + if l := len("ttachments/"); len(elem) >= l && elem[0:l] == "ttachments/" { + elem = elem[l:] + } else { + break + } + + // Param: "attachment_id" + // Match until "/" + idx := strings.IndexByte(elem, '/') + if idx < 0 { + idx = len(elem) + } + args[0] = elem[:idx] + elem = elem[idx:] + + if len(elem) == 0 { + switch method { + case "GET": + r.name = GetAttachmentOperation + r.summary = "Метаданные вложения, доступ участникам чата" + r.operationID = "getAttachment" + r.operationGroup = "" + r.pathPattern = "/api/v1/attachments/{attachment_id}" + r.args = args + r.count = 1 + return r, true + default: + return + } + } + switch elem[0] { + case '/': // Prefix: "/content" + + if l := len("/content"); len(elem) >= l && elem[0:l] == "/content" { + elem = elem[l:] + } else { + break + } + + if len(elem) == 0 { + // Leaf node. + switch method { + case "GET": + r.name = DownloadAttachmentOperation + r.summary = "Скачать байты через авторизованный API" + r.operationID = "downloadAttachment" + r.operationGroup = "" + r.pathPattern = "/api/v1/attachments/{attachment_id}/content" + r.args = args + r.count = 1 + return r, true + default: + return + } + } + + } + + case 'u': // Prefix: "uth/sessions" + + if l := len("uth/sessions"); len(elem) >= l && elem[0:l] == "uth/sessions" { + elem = elem[l:] + } else { + break + } + + if len(elem) == 0 { + switch method { + case "POST": + r.name = CreateSessionOperation + r.summary = "Вход: Basic username:password; выдаёт сессию" + r.operationID = "createSession" + r.operationGroup = "" + r.pathPattern = "/api/v1/auth/sessions" + r.args = args + r.count = 0 + return r, true + default: + return + } + } + switch elem[0] { + case '/': // Prefix: "/current" + + if l := len("/current"); len(elem) >= l && elem[0:l] == "/current" { + elem = elem[l:] + } else { + break + } + + if len(elem) == 0 { + // Leaf node. + switch method { + case "DELETE": + r.name = RevokeSessionOperation + r.summary = "Отозвать текущую сессию" + r.operationID = "revokeSession" + r.operationGroup = "" + r.pathPattern = "/api/v1/auth/sessions/current" + r.args = args + r.count = 0 + return r, true + default: + return + } + } + + } + + } + + case 'c': // Prefix: "chats" + + if l := len("chats"); len(elem) >= l && elem[0:l] == "chats" { + elem = elem[l:] + } else { + break + } + + if len(elem) == 0 { + switch method { + case "GET": + r.name = ListChatsOperation + r.summary = "Чаты текущего пользователя" + r.operationID = "listChats" + r.operationGroup = "" + r.pathPattern = "/api/v1/chats" + r.args = args + r.count = 0 + return r, true + case "POST": + r.name = CreateChatOperation + r.summary = "Создать чат; вызывающий должен входить в member_ids" + r.operationID = "createChat" + r.operationGroup = "" + r.pathPattern = "/api/v1/chats" + r.args = args + r.count = 0 + return r, true + default: + return + } + } + switch elem[0] { + case '/': // Prefix: "/" + + if l := len("/"); len(elem) >= l && elem[0:l] == "/" { + elem = elem[l:] + } else { + break + } + + // Param: "chat_id" + // Match until "/" + idx := strings.IndexByte(elem, '/') + if idx < 0 { + idx = len(elem) + } + args[0] = elem[:idx] + elem = elem[idx:] + + if len(elem) == 0 { + switch method { + case "GET": + r.name = GetChatOperation + r.summary = "Получить доступный чат" + r.operationID = "getChat" + r.operationGroup = "" + r.pathPattern = "/api/v1/chats/{chat_id}" + r.args = args + r.count = 1 + return r, true + default: + return + } + } + switch elem[0] { + case '/': // Prefix: "/" + + if l := len("/"); len(elem) >= l && elem[0:l] == "/" { + elem = elem[l:] + } else { + break + } + + if len(elem) == 0 { + break + } + switch elem[0] { + case 'a': // Prefix: "attachments" + + if l := len("attachments"); len(elem) >= l && elem[0:l] == "attachments" { + elem = elem[l:] + } else { + break + } + + if len(elem) == 0 { + // Leaf node. + switch method { + case "POST": + r.name = UploadAttachmentOperation + r.summary = "Принять один PNG/JPEG, до 10 MiB" + r.operationID = "uploadAttachment" + r.operationGroup = "" + r.pathPattern = "/api/v1/chats/{chat_id}/attachments" + r.args = args + r.count = 1 + return r, true + default: + return + } + } + + case 'm': // Prefix: "messages" + + if l := len("messages"); len(elem) >= l && elem[0:l] == "messages" { + elem = elem[l:] + } else { + break + } + + if len(elem) == 0 { + // Leaf node. + switch method { + case "GET": + r.name = ListMessagesOperation + r.summary = "Сообщения по (created_at, id) по возрастанию" + r.operationID = "listMessages" + r.operationGroup = "" + r.pathPattern = "/api/v1/chats/{chat_id}/messages" + r.args = args + r.count = 1 + return r, true + case "POST": + r.name = CreateMessageOperation + r.summary = "Отправить сообщение" + r.operationID = "createMessage" + r.operationGroup = "" + r.pathPattern = "/api/v1/chats/{chat_id}/messages" + r.args = args + r.count = 1 + return r, true + default: + return + } + } + + } + + } + + } + + case 'u': // Prefix: "users" + + if l := len("users"); len(elem) >= l && elem[0:l] == "users" { + elem = elem[l:] + } else { + break + } + + if len(elem) == 0 { + switch method { + case "POST": + r.name = RegisterUserOperation + r.summary = "Создать пользователя" + r.operationID = "registerUser" + r.operationGroup = "" + r.pathPattern = "/api/v1/users" + r.args = args + r.count = 0 + return r, true + default: + return + } + } + switch elem[0] { + case '/': // Prefix: "/me" + + if l := len("/me"); len(elem) >= l && elem[0:l] == "/me" { + elem = elem[l:] + } else { + break + } + + if len(elem) == 0 { + // Leaf node. + switch method { + case "GET": + r.name = CurrentUserOperation + r.summary = "Текущий пользователь" + r.operationID = "currentUser" + r.operationGroup = "" + r.pathPattern = "/api/v1/users/me" + r.args = args + r.count = 0 + return r, true + default: + return + } + } + + } + + } + + case 'h': // Prefix: "health/" + + if l := len("health/"); len(elem) >= l && elem[0:l] == "health/" { + elem = elem[l:] + } else { + break + } + + if len(elem) == 0 { + break + } + switch elem[0] { + case 'l': // Prefix: "live" + + if l := len("live"); len(elem) >= l && elem[0:l] == "live" { + elem = elem[l:] + } else { + break + } + + if len(elem) == 0 { + // Leaf node. + switch method { + case "GET": + r.name = LivenessOperation + r.summary = "Процесс жив" + r.operationID = "liveness" + r.operationGroup = "" + r.pathPattern = "/health/live" + r.args = args + r.count = 0 + return r, true + default: + return + } + } + + case 'r': // Prefix: "ready" + + if l := len("ready"); len(elem) >= l && elem[0:l] == "ready" { + elem = elem[l:] + } else { + break + } + + if len(elem) == 0 { + // Leaf node. + switch method { + case "GET": + r.name = ReadinessOperation + r.summary = "Готов принимать трафик" + r.operationID = "readiness" + r.operationGroup = "" + r.pathPattern = "/health/ready" + r.args = args + r.count = 0 + return r, true + default: + return + } + } + + } + + } + + } + } + return r, false +} diff --git a/internal/transport/rest/internal/oas/oas_schemas_gen.go b/internal/transport/rest/internal/oas/oas_schemas_gen.go new file mode 100644 index 0000000..e53b75a --- /dev/null +++ b/internal/transport/rest/internal/oas/oas_schemas_gen.go @@ -0,0 +1,2176 @@ +// Code generated by ogen, DO NOT EDIT. + +package oas + +import ( + "io" + "time" + + "github.com/go-faster/errors" + "github.com/google/uuid" +) + +// Ref: #/components/schemas/Attachment +type Attachment struct { + ChatID uuid.UUID `json:"chat_id"` + ContentType AttachmentContentType `json:"content_type"` + CreatedAt time.Time `json:"created_at"` + ErrorCode NilString `json:"error_code"` + Filename string `json:"filename"` + ID uuid.UUID `json:"id"` + OwnerID uuid.UUID `json:"owner_id"` + SHA256 string `json:"sha256"` + SizeBytes int `json:"size_bytes"` + Status AttachmentStatus `json:"status"` + UpdatedAt time.Time `json:"updated_at"` + Variants []Variant `json:"variants"` +} + +// GetChatID returns the value of ChatID. +func (s *Attachment) GetChatID() uuid.UUID { + return s.ChatID +} + +// GetContentType returns the value of ContentType. +func (s *Attachment) GetContentType() AttachmentContentType { + return s.ContentType +} + +// GetCreatedAt returns the value of CreatedAt. +func (s *Attachment) GetCreatedAt() time.Time { + return s.CreatedAt +} + +// GetErrorCode returns the value of ErrorCode. +func (s *Attachment) GetErrorCode() NilString { + return s.ErrorCode +} + +// GetFilename returns the value of Filename. +func (s *Attachment) GetFilename() string { + return s.Filename +} + +// GetID returns the value of ID. +func (s *Attachment) GetID() uuid.UUID { + return s.ID +} + +// GetOwnerID returns the value of OwnerID. +func (s *Attachment) GetOwnerID() uuid.UUID { + return s.OwnerID +} + +// GetSHA256 returns the value of SHA256. +func (s *Attachment) GetSHA256() string { + return s.SHA256 +} + +// GetSizeBytes returns the value of SizeBytes. +func (s *Attachment) GetSizeBytes() int { + return s.SizeBytes +} + +// GetStatus returns the value of Status. +func (s *Attachment) GetStatus() AttachmentStatus { + return s.Status +} + +// GetUpdatedAt returns the value of UpdatedAt. +func (s *Attachment) GetUpdatedAt() time.Time { + return s.UpdatedAt +} + +// GetVariants returns the value of Variants. +func (s *Attachment) GetVariants() []Variant { + return s.Variants +} + +// SetChatID sets the value of ChatID. +func (s *Attachment) SetChatID(val uuid.UUID) { + s.ChatID = val +} + +// SetContentType sets the value of ContentType. +func (s *Attachment) SetContentType(val AttachmentContentType) { + s.ContentType = val +} + +// SetCreatedAt sets the value of CreatedAt. +func (s *Attachment) SetCreatedAt(val time.Time) { + s.CreatedAt = val +} + +// SetErrorCode sets the value of ErrorCode. +func (s *Attachment) SetErrorCode(val NilString) { + s.ErrorCode = val +} + +// SetFilename sets the value of Filename. +func (s *Attachment) SetFilename(val string) { + s.Filename = val +} + +// SetID sets the value of ID. +func (s *Attachment) SetID(val uuid.UUID) { + s.ID = val +} + +// SetOwnerID sets the value of OwnerID. +func (s *Attachment) SetOwnerID(val uuid.UUID) { + s.OwnerID = val +} + +// SetSHA256 sets the value of SHA256. +func (s *Attachment) SetSHA256(val string) { + s.SHA256 = val +} + +// SetSizeBytes sets the value of SizeBytes. +func (s *Attachment) SetSizeBytes(val int) { + s.SizeBytes = val +} + +// SetStatus sets the value of Status. +func (s *Attachment) SetStatus(val AttachmentStatus) { + s.Status = val +} + +// SetUpdatedAt sets the value of UpdatedAt. +func (s *Attachment) SetUpdatedAt(val time.Time) { + s.UpdatedAt = val +} + +// SetVariants sets the value of Variants. +func (s *Attachment) SetVariants(val []Variant) { + s.Variants = val +} + +type AttachmentContentType string + +const ( + AttachmentContentTypeImagePNG AttachmentContentType = "image/png" + AttachmentContentTypeImageJpeg AttachmentContentType = "image/jpeg" +) + +// AllValues returns all AttachmentContentType values. +func (AttachmentContentType) AllValues() []AttachmentContentType { + return []AttachmentContentType{ + AttachmentContentTypeImagePNG, + AttachmentContentTypeImageJpeg, + } +} + +// MarshalText implements encoding.TextMarshaler. +func (s AttachmentContentType) MarshalText() ([]byte, error) { + switch s { + case AttachmentContentTypeImagePNG: + return []byte(s), nil + case AttachmentContentTypeImageJpeg: + return []byte(s), nil + default: + return nil, errors.Errorf("invalid value: %q", s) + } +} + +// UnmarshalText implements encoding.TextUnmarshaler. +func (s *AttachmentContentType) UnmarshalText(data []byte) error { + switch AttachmentContentType(data) { + case AttachmentContentTypeImagePNG: + *s = AttachmentContentTypeImagePNG + return nil + case AttachmentContentTypeImageJpeg: + *s = AttachmentContentTypeImageJpeg + return nil + default: + return errors.Errorf("invalid value: %q", data) + } +} + +// AttachmentHeaders wraps Attachment with response headers. +type AttachmentHeaders struct { + XInstanceID OptString + XRequestID OptString + Response Attachment +} + +// GetXInstanceID returns the value of XInstanceID. +func (s *AttachmentHeaders) GetXInstanceID() OptString { + return s.XInstanceID +} + +// GetXRequestID returns the value of XRequestID. +func (s *AttachmentHeaders) GetXRequestID() OptString { + return s.XRequestID +} + +// GetResponse returns the value of Response. +func (s *AttachmentHeaders) GetResponse() Attachment { + return s.Response +} + +// SetXInstanceID sets the value of XInstanceID. +func (s *AttachmentHeaders) SetXInstanceID(val OptString) { + s.XInstanceID = val +} + +// SetXRequestID sets the value of XRequestID. +func (s *AttachmentHeaders) SetXRequestID(val OptString) { + s.XRequestID = val +} + +// SetResponse sets the value of Response. +func (s *AttachmentHeaders) SetResponse(val Attachment) { + s.Response = val +} + +func (*AttachmentHeaders) getAttachmentRes() {} +func (*AttachmentHeaders) uploadAttachmentRes() {} + +type AttachmentStatus string + +const ( + AttachmentStatusQueued AttachmentStatus = "queued" + AttachmentStatusProcessing AttachmentStatus = "processing" + AttachmentStatusReady AttachmentStatus = "ready" + AttachmentStatusFailed AttachmentStatus = "failed" +) + +// AllValues returns all AttachmentStatus values. +func (AttachmentStatus) AllValues() []AttachmentStatus { + return []AttachmentStatus{ + AttachmentStatusQueued, + AttachmentStatusProcessing, + AttachmentStatusReady, + AttachmentStatusFailed, + } +} + +// MarshalText implements encoding.TextMarshaler. +func (s AttachmentStatus) MarshalText() ([]byte, error) { + switch s { + case AttachmentStatusQueued: + return []byte(s), nil + case AttachmentStatusProcessing: + return []byte(s), nil + case AttachmentStatusReady: + return []byte(s), nil + case AttachmentStatusFailed: + return []byte(s), nil + default: + return nil, errors.Errorf("invalid value: %q", s) + } +} + +// UnmarshalText implements encoding.TextUnmarshaler. +func (s *AttachmentStatus) UnmarshalText(data []byte) error { + switch AttachmentStatus(data) { + case AttachmentStatusQueued: + *s = AttachmentStatusQueued + return nil + case AttachmentStatusProcessing: + *s = AttachmentStatusProcessing + return nil + case AttachmentStatusReady: + *s = AttachmentStatusReady + return nil + case AttachmentStatusFailed: + *s = AttachmentStatusFailed + return nil + default: + return errors.Errorf("invalid value: %q", data) + } +} + +type BasicAuth struct { + Username string + Password string + Roles []string +} + +// GetUsername returns the value of Username. +func (s *BasicAuth) GetUsername() string { + return s.Username +} + +// GetPassword returns the value of Password. +func (s *BasicAuth) GetPassword() string { + return s.Password +} + +// GetRoles returns the value of Roles. +func (s *BasicAuth) GetRoles() []string { + return s.Roles +} + +// SetUsername sets the value of Username. +func (s *BasicAuth) SetUsername(val string) { + s.Username = val +} + +// SetPassword sets the value of Password. +func (s *BasicAuth) SetPassword(val string) { + s.Password = val +} + +// SetRoles sets the value of Roles. +func (s *BasicAuth) SetRoles(val []string) { + s.Roles = val +} + +type BearerAuth struct { + Token string + Roles []string +} + +// GetToken returns the value of Token. +func (s *BearerAuth) GetToken() string { + return s.Token +} + +// GetRoles returns the value of Roles. +func (s *BearerAuth) GetRoles() []string { + return s.Roles +} + +// SetToken sets the value of Token. +func (s *BearerAuth) SetToken(val string) { + s.Token = val +} + +// SetRoles sets the value of Roles. +func (s *BearerAuth) SetRoles(val []string) { + s.Roles = val +} + +// Ref: #/components/schemas/Chat +type Chat struct { + CreatedAt time.Time `json:"created_at"` + ID uuid.UUID `json:"id"` + MemberIds []uuid.UUID `json:"member_ids"` + Title string `json:"title"` +} + +// GetCreatedAt returns the value of CreatedAt. +func (s *Chat) GetCreatedAt() time.Time { + return s.CreatedAt +} + +// GetID returns the value of ID. +func (s *Chat) GetID() uuid.UUID { + return s.ID +} + +// GetMemberIds returns the value of MemberIds. +func (s *Chat) GetMemberIds() []uuid.UUID { + return s.MemberIds +} + +// GetTitle returns the value of Title. +func (s *Chat) GetTitle() string { + return s.Title +} + +// SetCreatedAt sets the value of CreatedAt. +func (s *Chat) SetCreatedAt(val time.Time) { + s.CreatedAt = val +} + +// SetID sets the value of ID. +func (s *Chat) SetID(val uuid.UUID) { + s.ID = val +} + +// SetMemberIds sets the value of MemberIds. +func (s *Chat) SetMemberIds(val []uuid.UUID) { + s.MemberIds = val +} + +// SetTitle sets the value of Title. +func (s *Chat) SetTitle(val string) { + s.Title = val +} + +// ChatHeaders wraps Chat with response headers. +type ChatHeaders struct { + XInstanceID OptString + XRequestID OptString + Response Chat +} + +// GetXInstanceID returns the value of XInstanceID. +func (s *ChatHeaders) GetXInstanceID() OptString { + return s.XInstanceID +} + +// GetXRequestID returns the value of XRequestID. +func (s *ChatHeaders) GetXRequestID() OptString { + return s.XRequestID +} + +// GetResponse returns the value of Response. +func (s *ChatHeaders) GetResponse() Chat { + return s.Response +} + +// SetXInstanceID sets the value of XInstanceID. +func (s *ChatHeaders) SetXInstanceID(val OptString) { + s.XInstanceID = val +} + +// SetXRequestID sets the value of XRequestID. +func (s *ChatHeaders) SetXRequestID(val OptString) { + s.XRequestID = val +} + +// SetResponse sets the value of Response. +func (s *ChatHeaders) SetResponse(val Chat) { + s.Response = val +} + +func (*ChatHeaders) createChatRes() {} +func (*ChatHeaders) getChatRes() {} + +// Ref: #/components/schemas/ChatPage +type ChatPage struct { + Items []Chat `json:"items"` + NextCursor NilString `json:"next_cursor"` +} + +// GetItems returns the value of Items. +func (s *ChatPage) GetItems() []Chat { + return s.Items +} + +// GetNextCursor returns the value of NextCursor. +func (s *ChatPage) GetNextCursor() NilString { + return s.NextCursor +} + +// SetItems sets the value of Items. +func (s *ChatPage) SetItems(val []Chat) { + s.Items = val +} + +// SetNextCursor sets the value of NextCursor. +func (s *ChatPage) SetNextCursor(val NilString) { + s.NextCursor = val +} + +// ChatPageHeaders wraps ChatPage with response headers. +type ChatPageHeaders struct { + XInstanceID OptString + XRequestID OptString + Response ChatPage +} + +// GetXInstanceID returns the value of XInstanceID. +func (s *ChatPageHeaders) GetXInstanceID() OptString { + return s.XInstanceID +} + +// GetXRequestID returns the value of XRequestID. +func (s *ChatPageHeaders) GetXRequestID() OptString { + return s.XRequestID +} + +// GetResponse returns the value of Response. +func (s *ChatPageHeaders) GetResponse() ChatPage { + return s.Response +} + +// SetXInstanceID sets the value of XInstanceID. +func (s *ChatPageHeaders) SetXInstanceID(val OptString) { + s.XInstanceID = val +} + +// SetXRequestID sets the value of XRequestID. +func (s *ChatPageHeaders) SetXRequestID(val OptString) { + s.XRequestID = val +} + +// SetResponse sets the value of Response. +func (s *ChatPageHeaders) SetResponse(val ChatPage) { + s.Response = val +} + +func (*ChatPageHeaders) listChatsRes() {} + +// Ref: #/components/schemas/CreateChat +type CreateChat struct { + MemberIds []uuid.UUID `json:"member_ids"` + Title string `json:"title"` +} + +// GetMemberIds returns the value of MemberIds. +func (s *CreateChat) GetMemberIds() []uuid.UUID { + return s.MemberIds +} + +// GetTitle returns the value of Title. +func (s *CreateChat) GetTitle() string { + return s.Title +} + +// SetMemberIds sets the value of MemberIds. +func (s *CreateChat) SetMemberIds(val []uuid.UUID) { + s.MemberIds = val +} + +// SetTitle sets the value of Title. +func (s *CreateChat) SetTitle(val string) { + s.Title = val +} + +type CreateChatBadRequest ErrorHeaders + +func (*CreateChatBadRequest) createChatRes() {} + +type CreateChatConflict ErrorHeaders + +func (*CreateChatConflict) createChatRes() {} + +type CreateChatInternalServerError ErrorHeaders + +func (*CreateChatInternalServerError) createChatRes() {} + +type CreateChatNotFound ErrorHeaders + +func (*CreateChatNotFound) createChatRes() {} + +type CreateChatServiceUnavailable ErrorHeaders + +func (*CreateChatServiceUnavailable) createChatRes() {} + +// Ref: #/components/schemas/CreateMessage +type CreateMessage struct { + AttachmentIds []uuid.UUID `json:"attachment_ids"` + Text string `json:"text"` +} + +// GetAttachmentIds returns the value of AttachmentIds. +func (s *CreateMessage) GetAttachmentIds() []uuid.UUID { + return s.AttachmentIds +} + +// GetText returns the value of Text. +func (s *CreateMessage) GetText() string { + return s.Text +} + +// SetAttachmentIds sets the value of AttachmentIds. +func (s *CreateMessage) SetAttachmentIds(val []uuid.UUID) { + s.AttachmentIds = val +} + +// SetText sets the value of Text. +func (s *CreateMessage) SetText(val string) { + s.Text = val +} + +type CreateMessageBadRequest ErrorHeaders + +func (*CreateMessageBadRequest) createMessageRes() {} + +type CreateMessageConflict ErrorHeaders + +func (*CreateMessageConflict) createMessageRes() {} + +type CreateMessageInternalServerError ErrorHeaders + +func (*CreateMessageInternalServerError) createMessageRes() {} + +type CreateMessageNotFound ErrorHeaders + +func (*CreateMessageNotFound) createMessageRes() {} + +type CreateMessageServiceUnavailable ErrorHeaders + +func (*CreateMessageServiceUnavailable) createMessageRes() {} + +type CreateSessionBadRequest ErrorHeaders + +func (*CreateSessionBadRequest) createSessionRes() {} + +type CreateSessionInternalServerError ErrorHeaders + +func (*CreateSessionInternalServerError) createSessionRes() {} + +type CreateSessionServiceUnavailable ErrorHeaders + +func (*CreateSessionServiceUnavailable) createSessionRes() {} + +// Ref: #/components/schemas/CreateUser +type CreateUser struct { + DisplayName string `json:"display_name"` + Password string `json:"password"` + Username string `json:"username"` +} + +// GetDisplayName returns the value of DisplayName. +func (s *CreateUser) GetDisplayName() string { + return s.DisplayName +} + +// GetPassword returns the value of Password. +func (s *CreateUser) GetPassword() string { + return s.Password +} + +// GetUsername returns the value of Username. +func (s *CreateUser) GetUsername() string { + return s.Username +} + +// SetDisplayName sets the value of DisplayName. +func (s *CreateUser) SetDisplayName(val string) { + s.DisplayName = val +} + +// SetPassword sets the value of Password. +func (s *CreateUser) SetPassword(val string) { + s.Password = val +} + +// SetUsername sets the value of Username. +func (s *CreateUser) SetUsername(val string) { + s.Username = val +} + +type CurrentUserBadRequest ErrorHeaders + +func (*CurrentUserBadRequest) currentUserRes() {} + +type CurrentUserConflict ErrorHeaders + +func (*CurrentUserConflict) currentUserRes() {} + +type CurrentUserInternalServerError ErrorHeaders + +func (*CurrentUserInternalServerError) currentUserRes() {} + +type CurrentUserNotFound ErrorHeaders + +func (*CurrentUserNotFound) currentUserRes() {} + +type CurrentUserServiceUnavailable ErrorHeaders + +func (*CurrentUserServiceUnavailable) currentUserRes() {} + +type DownloadAttachmentBadRequest ErrorHeaders + +func (*DownloadAttachmentBadRequest) downloadAttachmentRes() {} + +type DownloadAttachmentConflict ErrorHeaders + +func (*DownloadAttachmentConflict) downloadAttachmentRes() {} + +type DownloadAttachmentInternalServerError ErrorHeaders + +func (*DownloadAttachmentInternalServerError) downloadAttachmentRes() {} + +type DownloadAttachmentNotFound ErrorHeaders + +func (*DownloadAttachmentNotFound) downloadAttachmentRes() {} + +type DownloadAttachmentOKImageJpeg struct { + Data io.Reader +} + +// Read reads data from the Data reader. +// +// Kept to satisfy the io.Reader interface. +func (s DownloadAttachmentOKImageJpeg) Read(p []byte) (n int, err error) { + if s.Data == nil { + return 0, io.EOF + } + return s.Data.Read(p) +} + +// DownloadAttachmentOKImageJpegHeaders wraps DownloadAttachmentOKImageJpeg with response headers. +type DownloadAttachmentOKImageJpegHeaders struct { + XInstanceID OptString + XRequestID OptString + Response DownloadAttachmentOKImageJpeg +} + +// GetXInstanceID returns the value of XInstanceID. +func (s *DownloadAttachmentOKImageJpegHeaders) GetXInstanceID() OptString { + return s.XInstanceID +} + +// GetXRequestID returns the value of XRequestID. +func (s *DownloadAttachmentOKImageJpegHeaders) GetXRequestID() OptString { + return s.XRequestID +} + +// GetResponse returns the value of Response. +func (s *DownloadAttachmentOKImageJpegHeaders) GetResponse() DownloadAttachmentOKImageJpeg { + return s.Response +} + +// SetXInstanceID sets the value of XInstanceID. +func (s *DownloadAttachmentOKImageJpegHeaders) SetXInstanceID(val OptString) { + s.XInstanceID = val +} + +// SetXRequestID sets the value of XRequestID. +func (s *DownloadAttachmentOKImageJpegHeaders) SetXRequestID(val OptString) { + s.XRequestID = val +} + +// SetResponse sets the value of Response. +func (s *DownloadAttachmentOKImageJpegHeaders) SetResponse(val DownloadAttachmentOKImageJpeg) { + s.Response = val +} + +func (*DownloadAttachmentOKImageJpegHeaders) downloadAttachmentRes() {} + +type DownloadAttachmentOKImagePNG struct { + Data io.Reader +} + +// Read reads data from the Data reader. +// +// Kept to satisfy the io.Reader interface. +func (s DownloadAttachmentOKImagePNG) Read(p []byte) (n int, err error) { + if s.Data == nil { + return 0, io.EOF + } + return s.Data.Read(p) +} + +// DownloadAttachmentOKImagePNGHeaders wraps DownloadAttachmentOKImagePNG with response headers. +type DownloadAttachmentOKImagePNGHeaders struct { + XInstanceID OptString + XRequestID OptString + Response DownloadAttachmentOKImagePNG +} + +// GetXInstanceID returns the value of XInstanceID. +func (s *DownloadAttachmentOKImagePNGHeaders) GetXInstanceID() OptString { + return s.XInstanceID +} + +// GetXRequestID returns the value of XRequestID. +func (s *DownloadAttachmentOKImagePNGHeaders) GetXRequestID() OptString { + return s.XRequestID +} + +// GetResponse returns the value of Response. +func (s *DownloadAttachmentOKImagePNGHeaders) GetResponse() DownloadAttachmentOKImagePNG { + return s.Response +} + +// SetXInstanceID sets the value of XInstanceID. +func (s *DownloadAttachmentOKImagePNGHeaders) SetXInstanceID(val OptString) { + s.XInstanceID = val +} + +// SetXRequestID sets the value of XRequestID. +func (s *DownloadAttachmentOKImagePNGHeaders) SetXRequestID(val OptString) { + s.XRequestID = val +} + +// SetResponse sets the value of Response. +func (s *DownloadAttachmentOKImagePNGHeaders) SetResponse(val DownloadAttachmentOKImagePNG) { + s.Response = val +} + +func (*DownloadAttachmentOKImagePNGHeaders) downloadAttachmentRes() {} + +type DownloadAttachmentOKImageWEBP struct { + Data io.Reader +} + +// Read reads data from the Data reader. +// +// Kept to satisfy the io.Reader interface. +func (s DownloadAttachmentOKImageWEBP) Read(p []byte) (n int, err error) { + if s.Data == nil { + return 0, io.EOF + } + return s.Data.Read(p) +} + +// DownloadAttachmentOKImageWEBPHeaders wraps DownloadAttachmentOKImageWEBP with response headers. +type DownloadAttachmentOKImageWEBPHeaders struct { + XInstanceID OptString + XRequestID OptString + Response DownloadAttachmentOKImageWEBP +} + +// GetXInstanceID returns the value of XInstanceID. +func (s *DownloadAttachmentOKImageWEBPHeaders) GetXInstanceID() OptString { + return s.XInstanceID +} + +// GetXRequestID returns the value of XRequestID. +func (s *DownloadAttachmentOKImageWEBPHeaders) GetXRequestID() OptString { + return s.XRequestID +} + +// GetResponse returns the value of Response. +func (s *DownloadAttachmentOKImageWEBPHeaders) GetResponse() DownloadAttachmentOKImageWEBP { + return s.Response +} + +// SetXInstanceID sets the value of XInstanceID. +func (s *DownloadAttachmentOKImageWEBPHeaders) SetXInstanceID(val OptString) { + s.XInstanceID = val +} + +// SetXRequestID sets the value of XRequestID. +func (s *DownloadAttachmentOKImageWEBPHeaders) SetXRequestID(val OptString) { + s.XRequestID = val +} + +// SetResponse sets the value of Response. +func (s *DownloadAttachmentOKImageWEBPHeaders) SetResponse(val DownloadAttachmentOKImageWEBP) { + s.Response = val +} + +func (*DownloadAttachmentOKImageWEBPHeaders) downloadAttachmentRes() {} + +type DownloadAttachmentServiceUnavailable ErrorHeaders + +func (*DownloadAttachmentServiceUnavailable) downloadAttachmentRes() {} + +type DownloadAttachmentVariant string + +const ( + DownloadAttachmentVariantOriginal DownloadAttachmentVariant = "original" + DownloadAttachmentVariantThumbnail DownloadAttachmentVariant = "thumbnail" + DownloadAttachmentVariantCrop DownloadAttachmentVariant = "crop" + DownloadAttachmentVariantOptimized DownloadAttachmentVariant = "optimized" +) + +// AllValues returns all DownloadAttachmentVariant values. +func (DownloadAttachmentVariant) AllValues() []DownloadAttachmentVariant { + return []DownloadAttachmentVariant{ + DownloadAttachmentVariantOriginal, + DownloadAttachmentVariantThumbnail, + DownloadAttachmentVariantCrop, + DownloadAttachmentVariantOptimized, + } +} + +// MarshalText implements encoding.TextMarshaler. +func (s DownloadAttachmentVariant) MarshalText() ([]byte, error) { + switch s { + case DownloadAttachmentVariantOriginal: + return []byte(s), nil + case DownloadAttachmentVariantThumbnail: + return []byte(s), nil + case DownloadAttachmentVariantCrop: + return []byte(s), nil + case DownloadAttachmentVariantOptimized: + return []byte(s), nil + default: + return nil, errors.Errorf("invalid value: %q", s) + } +} + +// UnmarshalText implements encoding.TextUnmarshaler. +func (s *DownloadAttachmentVariant) UnmarshalText(data []byte) error { + switch DownloadAttachmentVariant(data) { + case DownloadAttachmentVariantOriginal: + *s = DownloadAttachmentVariantOriginal + return nil + case DownloadAttachmentVariantThumbnail: + *s = DownloadAttachmentVariantThumbnail + return nil + case DownloadAttachmentVariantCrop: + *s = DownloadAttachmentVariantCrop + return nil + case DownloadAttachmentVariantOptimized: + *s = DownloadAttachmentVariantOptimized + return nil + default: + return errors.Errorf("invalid value: %q", data) + } +} + +// Ref: #/components/schemas/Error +type Error struct { + Error ErrorError `json:"error"` +} + +// GetError returns the value of Error. +func (s *Error) GetError() ErrorError { + return s.Error +} + +// SetError sets the value of Error. +func (s *Error) SetError(val ErrorError) { + s.Error = val +} + +type ErrorError struct { + Code ErrorErrorCode `json:"code"` + Message string `json:"message"` + RequestID string `json:"request_id"` +} + +// GetCode returns the value of Code. +func (s *ErrorError) GetCode() ErrorErrorCode { + return s.Code +} + +// GetMessage returns the value of Message. +func (s *ErrorError) GetMessage() string { + return s.Message +} + +// GetRequestID returns the value of RequestID. +func (s *ErrorError) GetRequestID() string { + return s.RequestID +} + +// SetCode sets the value of Code. +func (s *ErrorError) SetCode(val ErrorErrorCode) { + s.Code = val +} + +// SetMessage sets the value of Message. +func (s *ErrorError) SetMessage(val string) { + s.Message = val +} + +// SetRequestID sets the value of RequestID. +func (s *ErrorError) SetRequestID(val string) { + s.RequestID = val +} + +type ErrorErrorCode string + +const ( + ErrorErrorCodeInvalidRequest ErrorErrorCode = "invalid_request" + ErrorErrorCodeUnauthorized ErrorErrorCode = "unauthorized" + ErrorErrorCodeNotFound ErrorErrorCode = "not_found" + ErrorErrorCodeConflict ErrorErrorCode = "conflict" + ErrorErrorCodePayloadTooLarge ErrorErrorCode = "payload_too_large" + ErrorErrorCodeUnsupportedMediaType ErrorErrorCode = "unsupported_media_type" + ErrorErrorCodeRateLimited ErrorErrorCode = "rate_limited" + ErrorErrorCodeUnavailable ErrorErrorCode = "unavailable" + ErrorErrorCodeInternalError ErrorErrorCode = "internal_error" +) + +// AllValues returns all ErrorErrorCode values. +func (ErrorErrorCode) AllValues() []ErrorErrorCode { + return []ErrorErrorCode{ + ErrorErrorCodeInvalidRequest, + ErrorErrorCodeUnauthorized, + ErrorErrorCodeNotFound, + ErrorErrorCodeConflict, + ErrorErrorCodePayloadTooLarge, + ErrorErrorCodeUnsupportedMediaType, + ErrorErrorCodeRateLimited, + ErrorErrorCodeUnavailable, + ErrorErrorCodeInternalError, + } +} + +// MarshalText implements encoding.TextMarshaler. +func (s ErrorErrorCode) MarshalText() ([]byte, error) { + switch s { + case ErrorErrorCodeInvalidRequest: + return []byte(s), nil + case ErrorErrorCodeUnauthorized: + return []byte(s), nil + case ErrorErrorCodeNotFound: + return []byte(s), nil + case ErrorErrorCodeConflict: + return []byte(s), nil + case ErrorErrorCodePayloadTooLarge: + return []byte(s), nil + case ErrorErrorCodeUnsupportedMediaType: + return []byte(s), nil + case ErrorErrorCodeRateLimited: + return []byte(s), nil + case ErrorErrorCodeUnavailable: + return []byte(s), nil + case ErrorErrorCodeInternalError: + return []byte(s), nil + default: + return nil, errors.Errorf("invalid value: %q", s) + } +} + +// UnmarshalText implements encoding.TextUnmarshaler. +func (s *ErrorErrorCode) UnmarshalText(data []byte) error { + switch ErrorErrorCode(data) { + case ErrorErrorCodeInvalidRequest: + *s = ErrorErrorCodeInvalidRequest + return nil + case ErrorErrorCodeUnauthorized: + *s = ErrorErrorCodeUnauthorized + return nil + case ErrorErrorCodeNotFound: + *s = ErrorErrorCodeNotFound + return nil + case ErrorErrorCodeConflict: + *s = ErrorErrorCodeConflict + return nil + case ErrorErrorCodePayloadTooLarge: + *s = ErrorErrorCodePayloadTooLarge + return nil + case ErrorErrorCodeUnsupportedMediaType: + *s = ErrorErrorCodeUnsupportedMediaType + return nil + case ErrorErrorCodeRateLimited: + *s = ErrorErrorCodeRateLimited + return nil + case ErrorErrorCodeUnavailable: + *s = ErrorErrorCodeUnavailable + return nil + case ErrorErrorCodeInternalError: + *s = ErrorErrorCodeInternalError + return nil + default: + return errors.Errorf("invalid value: %q", data) + } +} + +// ErrorHeaders wraps Error with response headers. +type ErrorHeaders struct { + XInstanceID OptString + XRequestID OptString + Response Error +} + +// GetXInstanceID returns the value of XInstanceID. +func (s *ErrorHeaders) GetXInstanceID() OptString { + return s.XInstanceID +} + +// GetXRequestID returns the value of XRequestID. +func (s *ErrorHeaders) GetXRequestID() OptString { + return s.XRequestID +} + +// GetResponse returns the value of Response. +func (s *ErrorHeaders) GetResponse() Error { + return s.Response +} + +// SetXInstanceID sets the value of XInstanceID. +func (s *ErrorHeaders) SetXInstanceID(val OptString) { + s.XInstanceID = val +} + +// SetXRequestID sets the value of XRequestID. +func (s *ErrorHeaders) SetXRequestID(val OptString) { + s.XRequestID = val +} + +// SetResponse sets the value of Response. +func (s *ErrorHeaders) SetResponse(val Error) { + s.Response = val +} + +func (*ErrorHeaders) livenessRes() {} + +type GetAttachmentBadRequest ErrorHeaders + +func (*GetAttachmentBadRequest) getAttachmentRes() {} + +type GetAttachmentConflict ErrorHeaders + +func (*GetAttachmentConflict) getAttachmentRes() {} + +type GetAttachmentInternalServerError ErrorHeaders + +func (*GetAttachmentInternalServerError) getAttachmentRes() {} + +type GetAttachmentNotFound ErrorHeaders + +func (*GetAttachmentNotFound) getAttachmentRes() {} + +type GetAttachmentServiceUnavailable ErrorHeaders + +func (*GetAttachmentServiceUnavailable) getAttachmentRes() {} + +// GetAttachmentTooManyRequestsHeaders wraps Error with response headers. +type GetAttachmentTooManyRequestsHeaders struct { + RetryAfter OptInt + XInstanceID OptString + XRequestID OptString + Response Error +} + +// GetRetryAfter returns the value of RetryAfter. +func (s *GetAttachmentTooManyRequestsHeaders) GetRetryAfter() OptInt { + return s.RetryAfter +} + +// GetXInstanceID returns the value of XInstanceID. +func (s *GetAttachmentTooManyRequestsHeaders) GetXInstanceID() OptString { + return s.XInstanceID +} + +// GetXRequestID returns the value of XRequestID. +func (s *GetAttachmentTooManyRequestsHeaders) GetXRequestID() OptString { + return s.XRequestID +} + +// GetResponse returns the value of Response. +func (s *GetAttachmentTooManyRequestsHeaders) GetResponse() Error { + return s.Response +} + +// SetRetryAfter sets the value of RetryAfter. +func (s *GetAttachmentTooManyRequestsHeaders) SetRetryAfter(val OptInt) { + s.RetryAfter = val +} + +// SetXInstanceID sets the value of XInstanceID. +func (s *GetAttachmentTooManyRequestsHeaders) SetXInstanceID(val OptString) { + s.XInstanceID = val +} + +// SetXRequestID sets the value of XRequestID. +func (s *GetAttachmentTooManyRequestsHeaders) SetXRequestID(val OptString) { + s.XRequestID = val +} + +// SetResponse sets the value of Response. +func (s *GetAttachmentTooManyRequestsHeaders) SetResponse(val Error) { + s.Response = val +} + +func (*GetAttachmentTooManyRequestsHeaders) createChatRes() {} +func (*GetAttachmentTooManyRequestsHeaders) createMessageRes() {} +func (*GetAttachmentTooManyRequestsHeaders) createSessionRes() {} +func (*GetAttachmentTooManyRequestsHeaders) currentUserRes() {} +func (*GetAttachmentTooManyRequestsHeaders) downloadAttachmentRes() {} +func (*GetAttachmentTooManyRequestsHeaders) getAttachmentRes() {} +func (*GetAttachmentTooManyRequestsHeaders) getChatRes() {} +func (*GetAttachmentTooManyRequestsHeaders) listChatsRes() {} +func (*GetAttachmentTooManyRequestsHeaders) listMessagesRes() {} +func (*GetAttachmentTooManyRequestsHeaders) registerUserRes() {} +func (*GetAttachmentTooManyRequestsHeaders) revokeSessionRes() {} +func (*GetAttachmentTooManyRequestsHeaders) uploadAttachmentRes() {} + +// GetAttachmentUnauthorizedHeaders wraps Error with response headers. +type GetAttachmentUnauthorizedHeaders struct { + WWWAuthenticate OptString + XInstanceID OptString + XRequestID OptString + Response Error +} + +// GetWWWAuthenticate returns the value of WWWAuthenticate. +func (s *GetAttachmentUnauthorizedHeaders) GetWWWAuthenticate() OptString { + return s.WWWAuthenticate +} + +// GetXInstanceID returns the value of XInstanceID. +func (s *GetAttachmentUnauthorizedHeaders) GetXInstanceID() OptString { + return s.XInstanceID +} + +// GetXRequestID returns the value of XRequestID. +func (s *GetAttachmentUnauthorizedHeaders) GetXRequestID() OptString { + return s.XRequestID +} + +// GetResponse returns the value of Response. +func (s *GetAttachmentUnauthorizedHeaders) GetResponse() Error { + return s.Response +} + +// SetWWWAuthenticate sets the value of WWWAuthenticate. +func (s *GetAttachmentUnauthorizedHeaders) SetWWWAuthenticate(val OptString) { + s.WWWAuthenticate = val +} + +// SetXInstanceID sets the value of XInstanceID. +func (s *GetAttachmentUnauthorizedHeaders) SetXInstanceID(val OptString) { + s.XInstanceID = val +} + +// SetXRequestID sets the value of XRequestID. +func (s *GetAttachmentUnauthorizedHeaders) SetXRequestID(val OptString) { + s.XRequestID = val +} + +// SetResponse sets the value of Response. +func (s *GetAttachmentUnauthorizedHeaders) SetResponse(val Error) { + s.Response = val +} + +func (*GetAttachmentUnauthorizedHeaders) createChatRes() {} +func (*GetAttachmentUnauthorizedHeaders) createMessageRes() {} +func (*GetAttachmentUnauthorizedHeaders) createSessionRes() {} +func (*GetAttachmentUnauthorizedHeaders) currentUserRes() {} +func (*GetAttachmentUnauthorizedHeaders) downloadAttachmentRes() {} +func (*GetAttachmentUnauthorizedHeaders) getAttachmentRes() {} +func (*GetAttachmentUnauthorizedHeaders) getChatRes() {} +func (*GetAttachmentUnauthorizedHeaders) listChatsRes() {} +func (*GetAttachmentUnauthorizedHeaders) listMessagesRes() {} +func (*GetAttachmentUnauthorizedHeaders) revokeSessionRes() {} +func (*GetAttachmentUnauthorizedHeaders) uploadAttachmentRes() {} + +type GetChatBadRequest ErrorHeaders + +func (*GetChatBadRequest) getChatRes() {} + +type GetChatConflict ErrorHeaders + +func (*GetChatConflict) getChatRes() {} + +type GetChatInternalServerError ErrorHeaders + +func (*GetChatInternalServerError) getChatRes() {} + +type GetChatNotFound ErrorHeaders + +func (*GetChatNotFound) getChatRes() {} + +type GetChatServiceUnavailable ErrorHeaders + +func (*GetChatServiceUnavailable) getChatRes() {} + +// Ref: #/components/schemas/Health +type Health struct { + Status HealthStatus `json:"status"` +} + +// GetStatus returns the value of Status. +func (s *Health) GetStatus() HealthStatus { + return s.Status +} + +// SetStatus sets the value of Status. +func (s *Health) SetStatus(val HealthStatus) { + s.Status = val +} + +// HealthHeaders wraps Health with response headers. +type HealthHeaders struct { + XInstanceID OptString + XRequestID OptString + Response Health +} + +// GetXInstanceID returns the value of XInstanceID. +func (s *HealthHeaders) GetXInstanceID() OptString { + return s.XInstanceID +} + +// GetXRequestID returns the value of XRequestID. +func (s *HealthHeaders) GetXRequestID() OptString { + return s.XRequestID +} + +// GetResponse returns the value of Response. +func (s *HealthHeaders) GetResponse() Health { + return s.Response +} + +// SetXInstanceID sets the value of XInstanceID. +func (s *HealthHeaders) SetXInstanceID(val OptString) { + s.XInstanceID = val +} + +// SetXRequestID sets the value of XRequestID. +func (s *HealthHeaders) SetXRequestID(val OptString) { + s.XRequestID = val +} + +// SetResponse sets the value of Response. +func (s *HealthHeaders) SetResponse(val Health) { + s.Response = val +} + +func (*HealthHeaders) livenessRes() {} +func (*HealthHeaders) readinessRes() {} + +type HealthStatus string + +const ( + HealthStatusOk HealthStatus = "ok" +) + +// AllValues returns all HealthStatus values. +func (HealthStatus) AllValues() []HealthStatus { + return []HealthStatus{ + HealthStatusOk, + } +} + +// MarshalText implements encoding.TextMarshaler. +func (s HealthStatus) MarshalText() ([]byte, error) { + switch s { + case HealthStatusOk: + return []byte(s), nil + default: + return nil, errors.Errorf("invalid value: %q", s) + } +} + +// UnmarshalText implements encoding.TextUnmarshaler. +func (s *HealthStatus) UnmarshalText(data []byte) error { + switch HealthStatus(data) { + case HealthStatusOk: + *s = HealthStatusOk + return nil + default: + return errors.Errorf("invalid value: %q", data) + } +} + +type ListChatsBadRequest ErrorHeaders + +func (*ListChatsBadRequest) listChatsRes() {} + +type ListChatsConflict ErrorHeaders + +func (*ListChatsConflict) listChatsRes() {} + +type ListChatsInternalServerError ErrorHeaders + +func (*ListChatsInternalServerError) listChatsRes() {} + +type ListChatsNotFound ErrorHeaders + +func (*ListChatsNotFound) listChatsRes() {} + +type ListChatsServiceUnavailable ErrorHeaders + +func (*ListChatsServiceUnavailable) listChatsRes() {} + +type ListMessagesBadRequest ErrorHeaders + +func (*ListMessagesBadRequest) listMessagesRes() {} + +type ListMessagesConflict ErrorHeaders + +func (*ListMessagesConflict) listMessagesRes() {} + +type ListMessagesInternalServerError ErrorHeaders + +func (*ListMessagesInternalServerError) listMessagesRes() {} + +type ListMessagesNotFound ErrorHeaders + +func (*ListMessagesNotFound) listMessagesRes() {} + +type ListMessagesServiceUnavailable ErrorHeaders + +func (*ListMessagesServiceUnavailable) listMessagesRes() {} + +// Ref: #/components/schemas/Message +type Message struct { + AttachmentIds []uuid.UUID `json:"attachment_ids"` + ChatID uuid.UUID `json:"chat_id"` + CreatedAt time.Time `json:"created_at"` + ID uuid.UUID `json:"id"` + SenderID uuid.UUID `json:"sender_id"` + Text string `json:"text"` +} + +// GetAttachmentIds returns the value of AttachmentIds. +func (s *Message) GetAttachmentIds() []uuid.UUID { + return s.AttachmentIds +} + +// GetChatID returns the value of ChatID. +func (s *Message) GetChatID() uuid.UUID { + return s.ChatID +} + +// GetCreatedAt returns the value of CreatedAt. +func (s *Message) GetCreatedAt() time.Time { + return s.CreatedAt +} + +// GetID returns the value of ID. +func (s *Message) GetID() uuid.UUID { + return s.ID +} + +// GetSenderID returns the value of SenderID. +func (s *Message) GetSenderID() uuid.UUID { + return s.SenderID +} + +// GetText returns the value of Text. +func (s *Message) GetText() string { + return s.Text +} + +// SetAttachmentIds sets the value of AttachmentIds. +func (s *Message) SetAttachmentIds(val []uuid.UUID) { + s.AttachmentIds = val +} + +// SetChatID sets the value of ChatID. +func (s *Message) SetChatID(val uuid.UUID) { + s.ChatID = val +} + +// SetCreatedAt sets the value of CreatedAt. +func (s *Message) SetCreatedAt(val time.Time) { + s.CreatedAt = val +} + +// SetID sets the value of ID. +func (s *Message) SetID(val uuid.UUID) { + s.ID = val +} + +// SetSenderID sets the value of SenderID. +func (s *Message) SetSenderID(val uuid.UUID) { + s.SenderID = val +} + +// SetText sets the value of Text. +func (s *Message) SetText(val string) { + s.Text = val +} + +// MessageHeaders wraps Message with response headers. +type MessageHeaders struct { + XInstanceID OptString + XRequestID OptString + Response Message +} + +// GetXInstanceID returns the value of XInstanceID. +func (s *MessageHeaders) GetXInstanceID() OptString { + return s.XInstanceID +} + +// GetXRequestID returns the value of XRequestID. +func (s *MessageHeaders) GetXRequestID() OptString { + return s.XRequestID +} + +// GetResponse returns the value of Response. +func (s *MessageHeaders) GetResponse() Message { + return s.Response +} + +// SetXInstanceID sets the value of XInstanceID. +func (s *MessageHeaders) SetXInstanceID(val OptString) { + s.XInstanceID = val +} + +// SetXRequestID sets the value of XRequestID. +func (s *MessageHeaders) SetXRequestID(val OptString) { + s.XRequestID = val +} + +// SetResponse sets the value of Response. +func (s *MessageHeaders) SetResponse(val Message) { + s.Response = val +} + +func (*MessageHeaders) createMessageRes() {} + +// Ref: #/components/schemas/MessagePage +type MessagePage struct { + Items []Message `json:"items"` + NextCursor NilString `json:"next_cursor"` +} + +// GetItems returns the value of Items. +func (s *MessagePage) GetItems() []Message { + return s.Items +} + +// GetNextCursor returns the value of NextCursor. +func (s *MessagePage) GetNextCursor() NilString { + return s.NextCursor +} + +// SetItems sets the value of Items. +func (s *MessagePage) SetItems(val []Message) { + s.Items = val +} + +// SetNextCursor sets the value of NextCursor. +func (s *MessagePage) SetNextCursor(val NilString) { + s.NextCursor = val +} + +// MessagePageHeaders wraps MessagePage with response headers. +type MessagePageHeaders struct { + XInstanceID OptString + XRequestID OptString + Response MessagePage +} + +// GetXInstanceID returns the value of XInstanceID. +func (s *MessagePageHeaders) GetXInstanceID() OptString { + return s.XInstanceID +} + +// GetXRequestID returns the value of XRequestID. +func (s *MessagePageHeaders) GetXRequestID() OptString { + return s.XRequestID +} + +// GetResponse returns the value of Response. +func (s *MessagePageHeaders) GetResponse() MessagePage { + return s.Response +} + +// SetXInstanceID sets the value of XInstanceID. +func (s *MessagePageHeaders) SetXInstanceID(val OptString) { + s.XInstanceID = val +} + +// SetXRequestID sets the value of XRequestID. +func (s *MessagePageHeaders) SetXRequestID(val OptString) { + s.XRequestID = val +} + +// SetResponse sets the value of Response. +func (s *MessagePageHeaders) SetResponse(val MessagePage) { + s.Response = val +} + +func (*MessagePageHeaders) listMessagesRes() {} + +// NewNilString returns new NilString with value set to v. +func NewNilString(v string) NilString { + return NilString{ + Value: v, + } +} + +// NilString is nullable string. +type NilString struct { + Value string + Null bool +} + +// SetTo sets value to v. +func (o *NilString) SetTo(v string) { + o.Null = false + o.Value = v +} + +// IsNull returns true if value is Null. +func (o NilString) IsNull() bool { return o.Null } + +// SetToNull sets value to null. +func (o *NilString) SetToNull() { + o.Null = true + var v string + o.Value = v +} + +// Get returns value and boolean that denotes whether value was set. +func (o NilString) Get() (v string, ok bool) { + if o.Null { + return v, false + } + return o.Value, true +} + +// Or returns value if set, or given parameter if does not. +func (o NilString) Or(d string) string { + if v, ok := o.Get(); ok { + return v + } + return d +} + +// NewOptDownloadAttachmentVariant returns new OptDownloadAttachmentVariant with value set to v. +func NewOptDownloadAttachmentVariant(v DownloadAttachmentVariant) OptDownloadAttachmentVariant { + return OptDownloadAttachmentVariant{ + Value: v, + Set: true, + } +} + +// OptDownloadAttachmentVariant is optional DownloadAttachmentVariant. +type OptDownloadAttachmentVariant struct { + Value DownloadAttachmentVariant + Set bool +} + +// IsSet returns true if OptDownloadAttachmentVariant was set. +func (o OptDownloadAttachmentVariant) IsSet() bool { return o.Set } + +// Reset unsets value. +func (o *OptDownloadAttachmentVariant) Reset() { + var v DownloadAttachmentVariant + o.Value = v + o.Set = false +} + +// SetTo sets value to v. +func (o *OptDownloadAttachmentVariant) SetTo(v DownloadAttachmentVariant) { + o.Set = true + o.Value = v +} + +// Get returns value and boolean that denotes whether value was set. +func (o OptDownloadAttachmentVariant) Get() (v DownloadAttachmentVariant, ok bool) { + if !o.Set { + return v, false + } + return o.Value, true +} + +// Or returns value if set, or given parameter if does not. +func (o OptDownloadAttachmentVariant) Or(d DownloadAttachmentVariant) DownloadAttachmentVariant { + if v, ok := o.Get(); ok { + return v + } + return d +} + +// NewOptInt returns new OptInt with value set to v. +func NewOptInt(v int) OptInt { + return OptInt{ + Value: v, + Set: true, + } +} + +// OptInt is optional int. +type OptInt struct { + Value int + Set bool +} + +// IsSet returns true if OptInt was set. +func (o OptInt) IsSet() bool { return o.Set } + +// Reset unsets value. +func (o *OptInt) Reset() { + var v int + o.Value = v + o.Set = false +} + +// SetTo sets value to v. +func (o *OptInt) SetTo(v int) { + o.Set = true + o.Value = v +} + +// Get returns value and boolean that denotes whether value was set. +func (o OptInt) Get() (v int, ok bool) { + if !o.Set { + return v, false + } + return o.Value, true +} + +// Or returns value if set, or given parameter if does not. +func (o OptInt) Or(d int) int { + if v, ok := o.Get(); ok { + return v + } + return d +} + +// NewOptString returns new OptString with value set to v. +func NewOptString(v string) OptString { + return OptString{ + Value: v, + Set: true, + } +} + +// OptString is optional string. +type OptString struct { + Value string + Set bool +} + +// IsSet returns true if OptString was set. +func (o OptString) IsSet() bool { return o.Set } + +// Reset unsets value. +func (o *OptString) Reset() { + var v string + o.Value = v + o.Set = false +} + +// SetTo sets value to v. +func (o *OptString) SetTo(v string) { + o.Set = true + o.Value = v +} + +// Get returns value and boolean that denotes whether value was set. +func (o OptString) Get() (v string, ok bool) { + if !o.Set { + return v, false + } + return o.Value, true +} + +// Or returns value if set, or given parameter if does not. +func (o OptString) Or(d string) string { + if v, ok := o.Get(); ok { + return v + } + return d +} + +type ReadinessInternalServerError ErrorHeaders + +func (*ReadinessInternalServerError) readinessRes() {} + +type ReadinessServiceUnavailable ErrorHeaders + +func (*ReadinessServiceUnavailable) readinessRes() {} + +type RegisterUserBadRequest ErrorHeaders + +func (*RegisterUserBadRequest) registerUserRes() {} + +type RegisterUserConflict ErrorHeaders + +func (*RegisterUserConflict) registerUserRes() {} + +type RegisterUserInternalServerError ErrorHeaders + +func (*RegisterUserInternalServerError) registerUserRes() {} + +type RegisterUserServiceUnavailable ErrorHeaders + +func (*RegisterUserServiceUnavailable) registerUserRes() {} + +type RevokeSessionInternalServerError ErrorHeaders + +func (*RevokeSessionInternalServerError) revokeSessionRes() {} + +// RevokeSessionNoContent is response for RevokeSession operation. +type RevokeSessionNoContent struct { + XInstanceID OptString + XRequestID OptString +} + +// GetXInstanceID returns the value of XInstanceID. +func (s *RevokeSessionNoContent) GetXInstanceID() OptString { + return s.XInstanceID +} + +// GetXRequestID returns the value of XRequestID. +func (s *RevokeSessionNoContent) GetXRequestID() OptString { + return s.XRequestID +} + +// SetXInstanceID sets the value of XInstanceID. +func (s *RevokeSessionNoContent) SetXInstanceID(val OptString) { + s.XInstanceID = val +} + +// SetXRequestID sets the value of XRequestID. +func (s *RevokeSessionNoContent) SetXRequestID(val OptString) { + s.XRequestID = val +} + +func (*RevokeSessionNoContent) revokeSessionRes() {} + +type RevokeSessionServiceUnavailable ErrorHeaders + +func (*RevokeSessionServiceUnavailable) revokeSessionRes() {} + +// Ref: #/components/schemas/Session +type Session struct { + ExpiresAt time.Time `json:"expires_at"` + Token string `json:"token"` + TokenType string `json:"token_type"` + User User `json:"user"` +} + +// GetExpiresAt returns the value of ExpiresAt. +func (s *Session) GetExpiresAt() time.Time { + return s.ExpiresAt +} + +// GetToken returns the value of Token. +func (s *Session) GetToken() string { + return s.Token +} + +// GetTokenType returns the value of TokenType. +func (s *Session) GetTokenType() string { + return s.TokenType +} + +// GetUser returns the value of User. +func (s *Session) GetUser() User { + return s.User +} + +// SetExpiresAt sets the value of ExpiresAt. +func (s *Session) SetExpiresAt(val time.Time) { + s.ExpiresAt = val +} + +// SetToken sets the value of Token. +func (s *Session) SetToken(val string) { + s.Token = val +} + +// SetTokenType sets the value of TokenType. +func (s *Session) SetTokenType(val string) { + s.TokenType = val +} + +// SetUser sets the value of User. +func (s *Session) SetUser(val User) { + s.User = val +} + +// SessionHeaders wraps Session with response headers. +type SessionHeaders struct { + XInstanceID OptString + XRequestID OptString + Response Session +} + +// GetXInstanceID returns the value of XInstanceID. +func (s *SessionHeaders) GetXInstanceID() OptString { + return s.XInstanceID +} + +// GetXRequestID returns the value of XRequestID. +func (s *SessionHeaders) GetXRequestID() OptString { + return s.XRequestID +} + +// GetResponse returns the value of Response. +func (s *SessionHeaders) GetResponse() Session { + return s.Response +} + +// SetXInstanceID sets the value of XInstanceID. +func (s *SessionHeaders) SetXInstanceID(val OptString) { + s.XInstanceID = val +} + +// SetXRequestID sets the value of XRequestID. +func (s *SessionHeaders) SetXRequestID(val OptString) { + s.XRequestID = val +} + +// SetResponse sets the value of Response. +func (s *SessionHeaders) SetResponse(val Session) { + s.Response = val +} + +func (*SessionHeaders) createSessionRes() {} + +type UploadAttachmentBadRequest ErrorHeaders + +func (*UploadAttachmentBadRequest) uploadAttachmentRes() {} + +type UploadAttachmentInternalServerError ErrorHeaders + +func (*UploadAttachmentInternalServerError) uploadAttachmentRes() {} + +type UploadAttachmentNotFound ErrorHeaders + +func (*UploadAttachmentNotFound) uploadAttachmentRes() {} + +type UploadAttachmentReqImageJpeg struct { + Data io.Reader +} + +// Read reads data from the Data reader. +// +// Kept to satisfy the io.Reader interface. +func (s UploadAttachmentReqImageJpeg) Read(p []byte) (n int, err error) { + if s.Data == nil { + return 0, io.EOF + } + return s.Data.Read(p) +} + +func (*UploadAttachmentReqImageJpeg) uploadAttachmentReq() {} + +type UploadAttachmentReqImagePNG struct { + Data io.Reader +} + +// Read reads data from the Data reader. +// +// Kept to satisfy the io.Reader interface. +func (s UploadAttachmentReqImagePNG) Read(p []byte) (n int, err error) { + if s.Data == nil { + return 0, io.EOF + } + return s.Data.Read(p) +} + +func (*UploadAttachmentReqImagePNG) uploadAttachmentReq() {} + +type UploadAttachmentRequestEntityTooLarge ErrorHeaders + +func (*UploadAttachmentRequestEntityTooLarge) uploadAttachmentRes() {} + +type UploadAttachmentServiceUnavailable ErrorHeaders + +func (*UploadAttachmentServiceUnavailable) uploadAttachmentRes() {} + +type UploadAttachmentUnsupportedMediaType ErrorHeaders + +func (*UploadAttachmentUnsupportedMediaType) uploadAttachmentRes() {} + +// Ref: #/components/schemas/User +type User struct { + CreatedAt time.Time `json:"created_at"` + DisplayName string `json:"display_name"` + ID uuid.UUID `json:"id"` + Username string `json:"username"` +} + +// GetCreatedAt returns the value of CreatedAt. +func (s *User) GetCreatedAt() time.Time { + return s.CreatedAt +} + +// GetDisplayName returns the value of DisplayName. +func (s *User) GetDisplayName() string { + return s.DisplayName +} + +// GetID returns the value of ID. +func (s *User) GetID() uuid.UUID { + return s.ID +} + +// GetUsername returns the value of Username. +func (s *User) GetUsername() string { + return s.Username +} + +// SetCreatedAt sets the value of CreatedAt. +func (s *User) SetCreatedAt(val time.Time) { + s.CreatedAt = val +} + +// SetDisplayName sets the value of DisplayName. +func (s *User) SetDisplayName(val string) { + s.DisplayName = val +} + +// SetID sets the value of ID. +func (s *User) SetID(val uuid.UUID) { + s.ID = val +} + +// SetUsername sets the value of Username. +func (s *User) SetUsername(val string) { + s.Username = val +} + +// UserHeaders wraps User with response headers. +type UserHeaders struct { + XInstanceID OptString + XRequestID OptString + Response User +} + +// GetXInstanceID returns the value of XInstanceID. +func (s *UserHeaders) GetXInstanceID() OptString { + return s.XInstanceID +} + +// GetXRequestID returns the value of XRequestID. +func (s *UserHeaders) GetXRequestID() OptString { + return s.XRequestID +} + +// GetResponse returns the value of Response. +func (s *UserHeaders) GetResponse() User { + return s.Response +} + +// SetXInstanceID sets the value of XInstanceID. +func (s *UserHeaders) SetXInstanceID(val OptString) { + s.XInstanceID = val +} + +// SetXRequestID sets the value of XRequestID. +func (s *UserHeaders) SetXRequestID(val OptString) { + s.XRequestID = val +} + +// SetResponse sets the value of Response. +func (s *UserHeaders) SetResponse(val User) { + s.Response = val +} + +func (*UserHeaders) currentUserRes() {} +func (*UserHeaders) registerUserRes() {} + +// Ref: #/components/schemas/Variant +type Variant struct { + ContentType VariantContentType `json:"content_type"` + Height int `json:"height"` + Name VariantName `json:"name"` + SHA256 string `json:"sha256"` + SizeBytes int `json:"size_bytes"` + Width int `json:"width"` +} + +// GetContentType returns the value of ContentType. +func (s *Variant) GetContentType() VariantContentType { + return s.ContentType +} + +// GetHeight returns the value of Height. +func (s *Variant) GetHeight() int { + return s.Height +} + +// GetName returns the value of Name. +func (s *Variant) GetName() VariantName { + return s.Name +} + +// GetSHA256 returns the value of SHA256. +func (s *Variant) GetSHA256() string { + return s.SHA256 +} + +// GetSizeBytes returns the value of SizeBytes. +func (s *Variant) GetSizeBytes() int { + return s.SizeBytes +} + +// GetWidth returns the value of Width. +func (s *Variant) GetWidth() int { + return s.Width +} + +// SetContentType sets the value of ContentType. +func (s *Variant) SetContentType(val VariantContentType) { + s.ContentType = val +} + +// SetHeight sets the value of Height. +func (s *Variant) SetHeight(val int) { + s.Height = val +} + +// SetName sets the value of Name. +func (s *Variant) SetName(val VariantName) { + s.Name = val +} + +// SetSHA256 sets the value of SHA256. +func (s *Variant) SetSHA256(val string) { + s.SHA256 = val +} + +// SetSizeBytes sets the value of SizeBytes. +func (s *Variant) SetSizeBytes(val int) { + s.SizeBytes = val +} + +// SetWidth sets the value of Width. +func (s *Variant) SetWidth(val int) { + s.Width = val +} + +type VariantContentType string + +const ( + VariantContentTypeImageJpeg VariantContentType = "image/jpeg" + VariantContentTypeImagePNG VariantContentType = "image/png" + VariantContentTypeImageWEBP VariantContentType = "image/webp" +) + +// AllValues returns all VariantContentType values. +func (VariantContentType) AllValues() []VariantContentType { + return []VariantContentType{ + VariantContentTypeImageJpeg, + VariantContentTypeImagePNG, + VariantContentTypeImageWEBP, + } +} + +// MarshalText implements encoding.TextMarshaler. +func (s VariantContentType) MarshalText() ([]byte, error) { + switch s { + case VariantContentTypeImageJpeg: + return []byte(s), nil + case VariantContentTypeImagePNG: + return []byte(s), nil + case VariantContentTypeImageWEBP: + return []byte(s), nil + default: + return nil, errors.Errorf("invalid value: %q", s) + } +} + +// UnmarshalText implements encoding.TextUnmarshaler. +func (s *VariantContentType) UnmarshalText(data []byte) error { + switch VariantContentType(data) { + case VariantContentTypeImageJpeg: + *s = VariantContentTypeImageJpeg + return nil + case VariantContentTypeImagePNG: + *s = VariantContentTypeImagePNG + return nil + case VariantContentTypeImageWEBP: + *s = VariantContentTypeImageWEBP + return nil + default: + return errors.Errorf("invalid value: %q", data) + } +} + +type VariantName string + +const ( + VariantNameThumbnail VariantName = "thumbnail" + VariantNameCrop VariantName = "crop" + VariantNameOptimized VariantName = "optimized" +) + +// AllValues returns all VariantName values. +func (VariantName) AllValues() []VariantName { + return []VariantName{ + VariantNameThumbnail, + VariantNameCrop, + VariantNameOptimized, + } +} + +// MarshalText implements encoding.TextMarshaler. +func (s VariantName) MarshalText() ([]byte, error) { + switch s { + case VariantNameThumbnail: + return []byte(s), nil + case VariantNameCrop: + return []byte(s), nil + case VariantNameOptimized: + return []byte(s), nil + default: + return nil, errors.Errorf("invalid value: %q", s) + } +} + +// UnmarshalText implements encoding.TextUnmarshaler. +func (s *VariantName) UnmarshalText(data []byte) error { + switch VariantName(data) { + case VariantNameThumbnail: + *s = VariantNameThumbnail + return nil + case VariantNameCrop: + *s = VariantNameCrop + return nil + case VariantNameOptimized: + *s = VariantNameOptimized + return nil + default: + return errors.Errorf("invalid value: %q", data) + } +} diff --git a/internal/transport/rest/internal/oas/oas_security_gen.go b/internal/transport/rest/internal/oas/oas_security_gen.go new file mode 100644 index 0000000..41d4c5c --- /dev/null +++ b/internal/transport/rest/internal/oas/oas_security_gen.go @@ -0,0 +1,134 @@ +// Code generated by ogen, DO NOT EDIT. + +package oas + +import ( + "context" + "net/http" + "strings" + + "github.com/go-faster/errors" + "github.com/ogen-go/ogen/ogenerrors" +) + +// SecurityHandler is handler for security parameters. +type SecurityHandler interface { + // HandleBasicAuth handles basicAuth security. + HandleBasicAuth(ctx context.Context, operationName OperationName, t BasicAuth) (context.Context, error) + // HandleBearerAuth handles bearerAuth security. + HandleBearerAuth(ctx context.Context, operationName OperationName, t BearerAuth) (context.Context, error) +} + +func findAuthorization(h http.Header, prefix string) (string, bool) { + v, ok := h["Authorization"] + if !ok { + return "", false + } + for _, vv := range v { + scheme, value, ok := strings.Cut(vv, " ") + if !ok || !strings.EqualFold(scheme, prefix) { + continue + } + return value, true + } + return "", false +} + +// operationRolesBasicAuth is a private map storing roles per operation. +var operationRolesBasicAuth = map[string][]string{ + CreateSessionOperation: []string{}, +} + +// GetRolesForBasicAuth returns the required roles for the given operation. +// +// This is useful for authorization scenarios where you need to know which roles +// are required for an operation. +// +// Example: +// +// requiredRoles := GetRolesForBasicAuth(AddPetOperation) +// +// Returns nil if the operation has no role requirements or if the operation is unknown. +func GetRolesForBasicAuth(operation string) []string { + roles, ok := operationRolesBasicAuth[operation] + if !ok { + return nil + } + // Return a copy to prevent external modification + result := make([]string, len(roles)) + copy(result, roles) + return result +} + +// operationRolesBearerAuth is a private map storing roles per operation. +var operationRolesBearerAuth = map[string][]string{ + CreateChatOperation: []string{}, + CreateMessageOperation: []string{}, + CurrentUserOperation: []string{}, + DownloadAttachmentOperation: []string{}, + GetAttachmentOperation: []string{}, + GetChatOperation: []string{}, + ListChatsOperation: []string{}, + ListMessagesOperation: []string{}, + RevokeSessionOperation: []string{}, + UploadAttachmentOperation: []string{}, +} + +// GetRolesForBearerAuth returns the required roles for the given operation. +// +// This is useful for authorization scenarios where you need to know which roles +// are required for an operation. +// +// Example: +// +// requiredRoles := GetRolesForBearerAuth(AddPetOperation) +// +// Returns nil if the operation has no role requirements or if the operation is unknown. +func GetRolesForBearerAuth(operation string) []string { + roles, ok := operationRolesBearerAuth[operation] + if !ok { + return nil + } + // Return a copy to prevent external modification + result := make([]string, len(roles)) + copy(result, roles) + return result +} + +func (s *Server) securityBasicAuth(ctx context.Context, operationName OperationName, req *http.Request) (context.Context, bool, error) { + var t BasicAuth + if _, ok := findAuthorization(req.Header, "Basic"); !ok { + return ctx, false, nil + } + username, password, ok := req.BasicAuth() + if !ok { + return nil, false, errors.New("invalid basic auth") + } + t.Username = username + t.Password = password + t.Roles = operationRolesBasicAuth[operationName] + rctx, err := s.sec.HandleBasicAuth(ctx, operationName, t) + if errors.Is(err, ogenerrors.ErrSkipServerSecurity) { + return nil, false, nil + } else if err != nil { + return nil, false, err + } + return rctx, true, err +} + +func (s *Server) securityBearerAuth(ctx context.Context, operationName OperationName, req *http.Request) (context.Context, bool, error) { + var t BearerAuth + token, ok := findAuthorization(req.Header, "Bearer") + if !ok { + return ctx, false, nil + } + t.Token = token + t.Roles = operationRolesBearerAuth[operationName] + rctx, err := s.sec.HandleBearerAuth(ctx, operationName, t) + if errors.Is(err, ogenerrors.ErrSkipServerSecurity) { + return nil, false, nil + } else if err != nil { + return nil, false, err + } + return rctx, true, err +} diff --git a/internal/transport/rest/internal/oas/oas_server_gen.go b/internal/transport/rest/internal/oas/oas_server_gen.go new file mode 100644 index 0000000..62a1b1d --- /dev/null +++ b/internal/transport/rest/internal/oas/oas_server_gen.go @@ -0,0 +1,116 @@ +// Code generated by ogen, DO NOT EDIT. + +package oas + +import ( + "context" +) + +// Handler handles operations described by OpenAPI v3 specification. +type Handler interface { + // CreateChat implements createChat operation. + // + // Создать чат; вызывающий должен входить в member_ids. + // + // POST /api/v1/chats + CreateChat(ctx context.Context, req *CreateChat) (CreateChatRes, error) + // CreateMessage implements createMessage operation. + // + // Отправить сообщение. + // + // POST /api/v1/chats/{chat_id}/messages + CreateMessage(ctx context.Context, req *CreateMessage, params CreateMessageParams) (CreateMessageRes, error) + // CreateSession implements createSession operation. + // + // Вход: Basic username:password; выдаёт сессию. + // + // POST /api/v1/auth/sessions + CreateSession(ctx context.Context) (CreateSessionRes, error) + // CurrentUser implements currentUser operation. + // + // Текущий пользователь. + // + // GET /api/v1/users/me + CurrentUser(ctx context.Context) (CurrentUserRes, error) + // DownloadAttachment implements downloadAttachment operation. + // + // Скачать байты через авторизованный API. + // + // GET /api/v1/attachments/{attachment_id}/content + DownloadAttachment(ctx context.Context, params DownloadAttachmentParams) (DownloadAttachmentRes, error) + // GetAttachment implements getAttachment operation. + // + // Метаданные вложения, доступ участникам чата. + // + // GET /api/v1/attachments/{attachment_id} + GetAttachment(ctx context.Context, params GetAttachmentParams) (GetAttachmentRes, error) + // GetChat implements getChat operation. + // + // Получить доступный чат. + // + // GET /api/v1/chats/{chat_id} + GetChat(ctx context.Context, params GetChatParams) (GetChatRes, error) + // ListChats implements listChats operation. + // + // Чаты текущего пользователя. + // + // GET /api/v1/chats + ListChats(ctx context.Context, params ListChatsParams) (ListChatsRes, error) + // ListMessages implements listMessages operation. + // + // Сообщения по (created_at, id) по возрастанию. + // + // GET /api/v1/chats/{chat_id}/messages + ListMessages(ctx context.Context, params ListMessagesParams) (ListMessagesRes, error) + // Liveness implements liveness operation. + // + // Процесс жив. + // + // GET /health/live + Liveness(ctx context.Context) (LivenessRes, error) + // Readiness implements readiness operation. + // + // Готов принимать трафик. + // + // GET /health/ready + Readiness(ctx context.Context) (ReadinessRes, error) + // RegisterUser implements registerUser operation. + // + // Создать пользователя. + // + // POST /api/v1/users + RegisterUser(ctx context.Context, req *CreateUser) (RegisterUserRes, error) + // RevokeSession implements revokeSession operation. + // + // Отозвать текущую сессию. + // + // DELETE /api/v1/auth/sessions/current + RevokeSession(ctx context.Context) (RevokeSessionRes, error) + // UploadAttachment implements uploadAttachment operation. + // + // Принять один PNG/JPEG, до 10 MiB. + // + // POST /api/v1/chats/{chat_id}/attachments + UploadAttachment(ctx context.Context, req UploadAttachmentReq, params UploadAttachmentParams) (UploadAttachmentRes, error) +} + +// Server implements http server based on OpenAPI v3 specification and +// calls Handler to handle requests. +type Server struct { + h Handler + sec SecurityHandler + baseServer +} + +// NewServer creates new Server. +func NewServer(h Handler, sec SecurityHandler, opts ...ServerOption) (*Server, error) { + s, err := newServerConfig(opts...).baseServer() + if err != nil { + return nil, err + } + return &Server{ + h: h, + sec: sec, + baseServer: s, + }, nil +} diff --git a/internal/transport/rest/internal/oas/oas_unimplemented_gen.go b/internal/transport/rest/internal/oas/oas_unimplemented_gen.go new file mode 100644 index 0000000..37cd214 --- /dev/null +++ b/internal/transport/rest/internal/oas/oas_unimplemented_gen.go @@ -0,0 +1,140 @@ +// Code generated by ogen, DO NOT EDIT. + +package oas + +import ( + "context" + + ht "github.com/ogen-go/ogen/http" +) + +// UnimplementedHandler is no-op Handler which returns http.ErrNotImplemented. +type UnimplementedHandler struct{} + +var _ Handler = UnimplementedHandler{} + +// CreateChat implements createChat operation. +// +// Создать чат; вызывающий должен входить в member_ids. +// +// POST /api/v1/chats +func (UnimplementedHandler) CreateChat(ctx context.Context, req *CreateChat) (r CreateChatRes, _ error) { + return r, ht.ErrNotImplemented +} + +// CreateMessage implements createMessage operation. +// +// Отправить сообщение. +// +// POST /api/v1/chats/{chat_id}/messages +func (UnimplementedHandler) CreateMessage(ctx context.Context, req *CreateMessage, params CreateMessageParams) (r CreateMessageRes, _ error) { + return r, ht.ErrNotImplemented +} + +// CreateSession implements createSession operation. +// +// Вход: Basic username:password; выдаёт сессию. +// +// POST /api/v1/auth/sessions +func (UnimplementedHandler) CreateSession(ctx context.Context) (r CreateSessionRes, _ error) { + return r, ht.ErrNotImplemented +} + +// CurrentUser implements currentUser operation. +// +// Текущий пользователь. +// +// GET /api/v1/users/me +func (UnimplementedHandler) CurrentUser(ctx context.Context) (r CurrentUserRes, _ error) { + return r, ht.ErrNotImplemented +} + +// DownloadAttachment implements downloadAttachment operation. +// +// Скачать байты через авторизованный API. +// +// GET /api/v1/attachments/{attachment_id}/content +func (UnimplementedHandler) DownloadAttachment(ctx context.Context, params DownloadAttachmentParams) (r DownloadAttachmentRes, _ error) { + return r, ht.ErrNotImplemented +} + +// GetAttachment implements getAttachment operation. +// +// Метаданные вложения, доступ участникам чата. +// +// GET /api/v1/attachments/{attachment_id} +func (UnimplementedHandler) GetAttachment(ctx context.Context, params GetAttachmentParams) (r GetAttachmentRes, _ error) { + return r, ht.ErrNotImplemented +} + +// GetChat implements getChat operation. +// +// Получить доступный чат. +// +// GET /api/v1/chats/{chat_id} +func (UnimplementedHandler) GetChat(ctx context.Context, params GetChatParams) (r GetChatRes, _ error) { + return r, ht.ErrNotImplemented +} + +// ListChats implements listChats operation. +// +// Чаты текущего пользователя. +// +// GET /api/v1/chats +func (UnimplementedHandler) ListChats(ctx context.Context, params ListChatsParams) (r ListChatsRes, _ error) { + return r, ht.ErrNotImplemented +} + +// ListMessages implements listMessages operation. +// +// Сообщения по (created_at, id) по возрастанию. +// +// GET /api/v1/chats/{chat_id}/messages +func (UnimplementedHandler) ListMessages(ctx context.Context, params ListMessagesParams) (r ListMessagesRes, _ error) { + return r, ht.ErrNotImplemented +} + +// Liveness implements liveness operation. +// +// Процесс жив. +// +// GET /health/live +func (UnimplementedHandler) Liveness(ctx context.Context) (r LivenessRes, _ error) { + return r, ht.ErrNotImplemented +} + +// Readiness implements readiness operation. +// +// Готов принимать трафик. +// +// GET /health/ready +func (UnimplementedHandler) Readiness(ctx context.Context) (r ReadinessRes, _ error) { + return r, ht.ErrNotImplemented +} + +// RegisterUser implements registerUser operation. +// +// Создать пользователя. +// +// POST /api/v1/users +func (UnimplementedHandler) RegisterUser(ctx context.Context, req *CreateUser) (r RegisterUserRes, _ error) { + return r, ht.ErrNotImplemented +} + +// RevokeSession implements revokeSession operation. +// +// Отозвать текущую сессию. +// +// DELETE /api/v1/auth/sessions/current +func (UnimplementedHandler) RevokeSession(ctx context.Context) (r RevokeSessionRes, _ error) { + return r, ht.ErrNotImplemented +} + +// UploadAttachment implements uploadAttachment operation. +// +// Принять один PNG/JPEG, до 10 MiB. +// +// POST /api/v1/chats/{chat_id}/attachments +func (UnimplementedHandler) UploadAttachment(ctx context.Context, req UploadAttachmentReq, params UploadAttachmentParams) (r UploadAttachmentRes, _ error) { + return r, ht.ErrNotImplemented +} diff --git a/internal/transport/rest/internal/oas/oas_validators_gen.go b/internal/transport/rest/internal/oas/oas_validators_gen.go new file mode 100644 index 0000000..4a372d9 --- /dev/null +++ b/internal/transport/rest/internal/oas/oas_validators_gen.go @@ -0,0 +1,2653 @@ +// Code generated by ogen, DO NOT EDIT. + +package oas + +import ( + "fmt" + + "github.com/go-faster/errors" + "github.com/ogen-go/ogen/validate" +) + +func (s *Attachment) Validate() error { + if s == nil { + return validate.ErrNilPointer + } + + var failures []validate.FieldError + if err := func() error { + if err := s.ContentType.Validate(); err != nil { + return err + } + return nil + }(); err != nil { + failures = append(failures, validate.FieldError{ + Name: "content_type", + Error: err, + }) + } + if err := func() error { + if err := (validate.String{ + MinLength: 1, + MinLengthSet: true, + MaxLength: 255, + MaxLengthSet: true, + Email: false, + Hostname: false, + Regex: nil, + MinNumeric: 0, + MinNumericSet: false, + MaxNumeric: 0, + MaxNumericSet: false, + }).Validate(string(s.Filename)); err != nil { + return errors.Wrap(err, "string") + } + return nil + }(); err != nil { + failures = append(failures, validate.FieldError{ + Name: "filename", + Error: err, + }) + } + if err := func() error { + if err := (validate.String{ + MinLength: 0, + MinLengthSet: false, + MaxLength: 0, + MaxLengthSet: false, + Email: false, + Hostname: false, + Regex: regexMap["^[a-f0-9]{64}$"], + MinNumeric: 0, + MinNumericSet: false, + MaxNumeric: 0, + MaxNumericSet: false, + }).Validate(string(s.SHA256)); err != nil { + return errors.Wrap(err, "string") + } + return nil + }(); err != nil { + failures = append(failures, validate.FieldError{ + Name: "sha256", + Error: err, + }) + } + if err := func() error { + if err := (validate.Int{ + MinSet: true, + Min: 1, + MaxSet: true, + Max: 10485760, + MinExclusive: false, + MaxExclusive: false, + MultipleOfSet: false, + MultipleOf: 0, + Pattern: nil, + }).Validate(int64(s.SizeBytes)); err != nil { + return errors.Wrap(err, "int") + } + return nil + }(); err != nil { + failures = append(failures, validate.FieldError{ + Name: "size_bytes", + Error: err, + }) + } + if err := func() error { + if err := s.Status.Validate(); err != nil { + return err + } + return nil + }(); err != nil { + failures = append(failures, validate.FieldError{ + Name: "status", + Error: err, + }) + } + if err := func() error { + if s.Variants == nil { + return errors.New("nil is invalid value") + } + var failures []validate.FieldError + for i, elem := range s.Variants { + if err := func() error { + if err := elem.Validate(); err != nil { + return err + } + return nil + }(); err != nil { + failures = append(failures, validate.FieldError{ + Name: fmt.Sprintf("[%d]", i), + Error: err, + }) + } + } + if len(failures) > 0 { + return &validate.Error{Fields: failures} + } + return nil + }(); err != nil { + failures = append(failures, validate.FieldError{ + Name: "variants", + Error: err, + }) + } + if len(failures) > 0 { + return &validate.Error{Fields: failures} + } + return nil +} + +func (s AttachmentContentType) Validate() error { + switch s { + case "image/png": + return nil + case "image/jpeg": + return nil + default: + return errors.Errorf("invalid value: %v", s) + } +} + +func (s *AttachmentHeaders) Validate() error { + if s == nil { + return validate.ErrNilPointer + } + + var failures []validate.FieldError + if err := func() error { + if value, ok := s.XInstanceID.Get(); ok { + if err := func() error { + if err := (validate.String{ + MinLength: 1, + MinLengthSet: true, + MaxLength: 0, + MaxLengthSet: false, + Email: false, + Hostname: false, + Regex: nil, + MinNumeric: 0, + MinNumericSet: false, + MaxNumeric: 0, + MaxNumericSet: false, + }).Validate(string(value)); err != nil { + return errors.Wrap(err, "string") + } + return nil + }(); err != nil { + return err + } + } + return nil + }(); err != nil { + failures = append(failures, validate.FieldError{ + Name: "XInstanceID", + Error: err, + }) + } + if err := func() error { + if value, ok := s.XRequestID.Get(); ok { + if err := func() error { + if err := (validate.String{ + MinLength: 1, + MinLengthSet: true, + MaxLength: 0, + MaxLengthSet: false, + Email: false, + Hostname: false, + Regex: nil, + MinNumeric: 0, + MinNumericSet: false, + MaxNumeric: 0, + MaxNumericSet: false, + }).Validate(string(value)); err != nil { + return errors.Wrap(err, "string") + } + return nil + }(); err != nil { + return err + } + } + return nil + }(); err != nil { + failures = append(failures, validate.FieldError{ + Name: "XRequestID", + Error: err, + }) + } + if err := func() error { + if err := s.Response.Validate(); err != nil { + return err + } + return nil + }(); err != nil { + failures = append(failures, validate.FieldError{ + Name: "Response", + Error: err, + }) + } + if len(failures) > 0 { + return &validate.Error{Fields: failures} + } + return nil +} + +func (s AttachmentStatus) Validate() error { + switch s { + case "queued": + return nil + case "processing": + return nil + case "ready": + return nil + case "failed": + return nil + default: + return errors.Errorf("invalid value: %v", s) + } +} + +func (s *Chat) Validate() error { + if s == nil { + return validate.ErrNilPointer + } + + var failures []validate.FieldError + if err := func() error { + if s.MemberIds == nil { + return errors.New("nil is invalid value") + } + if err := (validate.Array{ + MinLength: 1, + MinLengthSet: true, + MaxLength: 100, + MaxLengthSet: true, + }).ValidateLength(len(s.MemberIds)); err != nil { + return errors.Wrap(err, "array") + } + if err := validate.UniqueItems(s.MemberIds); err != nil { + return errors.Wrap(err, "array") + } + return nil + }(); err != nil { + failures = append(failures, validate.FieldError{ + Name: "member_ids", + Error: err, + }) + } + if err := func() error { + if err := (validate.String{ + MinLength: 1, + MinLengthSet: true, + MaxLength: 100, + MaxLengthSet: true, + Email: false, + Hostname: false, + Regex: nil, + MinNumeric: 0, + MinNumericSet: false, + MaxNumeric: 0, + MaxNumericSet: false, + }).Validate(string(s.Title)); err != nil { + return errors.Wrap(err, "string") + } + return nil + }(); err != nil { + failures = append(failures, validate.FieldError{ + Name: "title", + Error: err, + }) + } + if len(failures) > 0 { + return &validate.Error{Fields: failures} + } + return nil +} + +func (s *ChatHeaders) Validate() error { + if s == nil { + return validate.ErrNilPointer + } + + var failures []validate.FieldError + if err := func() error { + if value, ok := s.XInstanceID.Get(); ok { + if err := func() error { + if err := (validate.String{ + MinLength: 1, + MinLengthSet: true, + MaxLength: 0, + MaxLengthSet: false, + Email: false, + Hostname: false, + Regex: nil, + MinNumeric: 0, + MinNumericSet: false, + MaxNumeric: 0, + MaxNumericSet: false, + }).Validate(string(value)); err != nil { + return errors.Wrap(err, "string") + } + return nil + }(); err != nil { + return err + } + } + return nil + }(); err != nil { + failures = append(failures, validate.FieldError{ + Name: "XInstanceID", + Error: err, + }) + } + if err := func() error { + if value, ok := s.XRequestID.Get(); ok { + if err := func() error { + if err := (validate.String{ + MinLength: 1, + MinLengthSet: true, + MaxLength: 0, + MaxLengthSet: false, + Email: false, + Hostname: false, + Regex: nil, + MinNumeric: 0, + MinNumericSet: false, + MaxNumeric: 0, + MaxNumericSet: false, + }).Validate(string(value)); err != nil { + return errors.Wrap(err, "string") + } + return nil + }(); err != nil { + return err + } + } + return nil + }(); err != nil { + failures = append(failures, validate.FieldError{ + Name: "XRequestID", + Error: err, + }) + } + if err := func() error { + if err := s.Response.Validate(); err != nil { + return err + } + return nil + }(); err != nil { + failures = append(failures, validate.FieldError{ + Name: "Response", + Error: err, + }) + } + if len(failures) > 0 { + return &validate.Error{Fields: failures} + } + return nil +} + +func (s *ChatPage) Validate() error { + if s == nil { + return validate.ErrNilPointer + } + + var failures []validate.FieldError + if err := func() error { + if s.Items == nil { + return errors.New("nil is invalid value") + } + var failures []validate.FieldError + for i, elem := range s.Items { + if err := func() error { + if err := elem.Validate(); err != nil { + return err + } + return nil + }(); err != nil { + failures = append(failures, validate.FieldError{ + Name: fmt.Sprintf("[%d]", i), + Error: err, + }) + } + } + if len(failures) > 0 { + return &validate.Error{Fields: failures} + } + return nil + }(); err != nil { + failures = append(failures, validate.FieldError{ + Name: "items", + Error: err, + }) + } + if len(failures) > 0 { + return &validate.Error{Fields: failures} + } + return nil +} + +func (s *ChatPageHeaders) Validate() error { + if s == nil { + return validate.ErrNilPointer + } + + var failures []validate.FieldError + if err := func() error { + if value, ok := s.XInstanceID.Get(); ok { + if err := func() error { + if err := (validate.String{ + MinLength: 1, + MinLengthSet: true, + MaxLength: 0, + MaxLengthSet: false, + Email: false, + Hostname: false, + Regex: nil, + MinNumeric: 0, + MinNumericSet: false, + MaxNumeric: 0, + MaxNumericSet: false, + }).Validate(string(value)); err != nil { + return errors.Wrap(err, "string") + } + return nil + }(); err != nil { + return err + } + } + return nil + }(); err != nil { + failures = append(failures, validate.FieldError{ + Name: "XInstanceID", + Error: err, + }) + } + if err := func() error { + if value, ok := s.XRequestID.Get(); ok { + if err := func() error { + if err := (validate.String{ + MinLength: 1, + MinLengthSet: true, + MaxLength: 0, + MaxLengthSet: false, + Email: false, + Hostname: false, + Regex: nil, + MinNumeric: 0, + MinNumericSet: false, + MaxNumeric: 0, + MaxNumericSet: false, + }).Validate(string(value)); err != nil { + return errors.Wrap(err, "string") + } + return nil + }(); err != nil { + return err + } + } + return nil + }(); err != nil { + failures = append(failures, validate.FieldError{ + Name: "XRequestID", + Error: err, + }) + } + if err := func() error { + if err := s.Response.Validate(); err != nil { + return err + } + return nil + }(); err != nil { + failures = append(failures, validate.FieldError{ + Name: "Response", + Error: err, + }) + } + if len(failures) > 0 { + return &validate.Error{Fields: failures} + } + return nil +} + +func (s *CreateChat) Validate() error { + if s == nil { + return validate.ErrNilPointer + } + + var failures []validate.FieldError + if err := func() error { + if s.MemberIds == nil { + return errors.New("nil is invalid value") + } + if err := (validate.Array{ + MinLength: 1, + MinLengthSet: true, + MaxLength: 100, + MaxLengthSet: true, + }).ValidateLength(len(s.MemberIds)); err != nil { + return errors.Wrap(err, "array") + } + if err := validate.UniqueItems(s.MemberIds); err != nil { + return errors.Wrap(err, "array") + } + return nil + }(); err != nil { + failures = append(failures, validate.FieldError{ + Name: "member_ids", + Error: err, + }) + } + if err := func() error { + if err := (validate.String{ + MinLength: 1, + MinLengthSet: true, + MaxLength: 100, + MaxLengthSet: true, + Email: false, + Hostname: false, + Regex: nil, + MinNumeric: 0, + MinNumericSet: false, + MaxNumeric: 0, + MaxNumericSet: false, + }).Validate(string(s.Title)); err != nil { + return errors.Wrap(err, "string") + } + return nil + }(); err != nil { + failures = append(failures, validate.FieldError{ + Name: "title", + Error: err, + }) + } + if len(failures) > 0 { + return &validate.Error{Fields: failures} + } + return nil +} + +func (s *CreateChatBadRequest) Validate() error { + alias := (*ErrorHeaders)(s) + if err := alias.Validate(); err != nil { + return err + } + return nil +} + +func (s *CreateChatConflict) Validate() error { + alias := (*ErrorHeaders)(s) + if err := alias.Validate(); err != nil { + return err + } + return nil +} + +func (s *CreateChatInternalServerError) Validate() error { + alias := (*ErrorHeaders)(s) + if err := alias.Validate(); err != nil { + return err + } + return nil +} + +func (s *CreateChatNotFound) Validate() error { + alias := (*ErrorHeaders)(s) + if err := alias.Validate(); err != nil { + return err + } + return nil +} + +func (s *CreateChatServiceUnavailable) Validate() error { + alias := (*ErrorHeaders)(s) + if err := alias.Validate(); err != nil { + return err + } + return nil +} + +func (s *CreateMessage) Validate() error { + if s == nil { + return validate.ErrNilPointer + } + + var failures []validate.FieldError + if err := func() error { + if s.AttachmentIds == nil { + return nil // optional + } + if err := (validate.Array{ + MinLength: 0, + MinLengthSet: false, + MaxLength: 10, + MaxLengthSet: true, + }).ValidateLength(len(s.AttachmentIds)); err != nil { + return errors.Wrap(err, "array") + } + if err := validate.UniqueItems(s.AttachmentIds); err != nil { + return errors.Wrap(err, "array") + } + return nil + }(); err != nil { + failures = append(failures, validate.FieldError{ + Name: "attachment_ids", + Error: err, + }) + } + if err := func() error { + if err := (validate.String{ + MinLength: 0, + MinLengthSet: false, + MaxLength: 4000, + MaxLengthSet: true, + Email: false, + Hostname: false, + Regex: nil, + MinNumeric: 0, + MinNumericSet: false, + MaxNumeric: 0, + MaxNumericSet: false, + }).Validate(string(s.Text)); err != nil { + return errors.Wrap(err, "string") + } + return nil + }(); err != nil { + failures = append(failures, validate.FieldError{ + Name: "text", + Error: err, + }) + } + if len(failures) > 0 { + return &validate.Error{Fields: failures} + } + return nil +} + +func (s *CreateMessageBadRequest) Validate() error { + alias := (*ErrorHeaders)(s) + if err := alias.Validate(); err != nil { + return err + } + return nil +} + +func (s *CreateMessageConflict) Validate() error { + alias := (*ErrorHeaders)(s) + if err := alias.Validate(); err != nil { + return err + } + return nil +} + +func (s *CreateMessageInternalServerError) Validate() error { + alias := (*ErrorHeaders)(s) + if err := alias.Validate(); err != nil { + return err + } + return nil +} + +func (s *CreateMessageNotFound) Validate() error { + alias := (*ErrorHeaders)(s) + if err := alias.Validate(); err != nil { + return err + } + return nil +} + +func (s *CreateMessageServiceUnavailable) Validate() error { + alias := (*ErrorHeaders)(s) + if err := alias.Validate(); err != nil { + return err + } + return nil +} + +func (s *CreateSessionBadRequest) Validate() error { + alias := (*ErrorHeaders)(s) + if err := alias.Validate(); err != nil { + return err + } + return nil +} + +func (s *CreateSessionInternalServerError) Validate() error { + alias := (*ErrorHeaders)(s) + if err := alias.Validate(); err != nil { + return err + } + return nil +} + +func (s *CreateSessionServiceUnavailable) Validate() error { + alias := (*ErrorHeaders)(s) + if err := alias.Validate(); err != nil { + return err + } + return nil +} + +func (s *CreateUser) Validate() error { + if s == nil { + return validate.ErrNilPointer + } + + var failures []validate.FieldError + if err := func() error { + if err := (validate.String{ + MinLength: 1, + MinLengthSet: true, + MaxLength: 100, + MaxLengthSet: true, + Email: false, + Hostname: false, + Regex: nil, + MinNumeric: 0, + MinNumericSet: false, + MaxNumeric: 0, + MaxNumericSet: false, + }).Validate(string(s.DisplayName)); err != nil { + return errors.Wrap(err, "string") + } + return nil + }(); err != nil { + failures = append(failures, validate.FieldError{ + Name: "display_name", + Error: err, + }) + } + if err := func() error { + if err := (validate.String{ + MinLength: 12, + MinLengthSet: true, + MaxLength: 128, + MaxLengthSet: true, + Email: false, + Hostname: false, + Regex: nil, + MinNumeric: 0, + MinNumericSet: false, + MaxNumeric: 0, + MaxNumericSet: false, + }).Validate(string(s.Password)); err != nil { + return errors.Wrap(err, "string") + } + return nil + }(); err != nil { + failures = append(failures, validate.FieldError{ + Name: "password", + Error: err, + }) + } + if err := func() error { + if err := (validate.String{ + MinLength: 0, + MinLengthSet: false, + MaxLength: 0, + MaxLengthSet: false, + Email: false, + Hostname: false, + Regex: regexMap["^[a-z0-9_]{3,32}$"], + MinNumeric: 0, + MinNumericSet: false, + MaxNumeric: 0, + MaxNumericSet: false, + }).Validate(string(s.Username)); err != nil { + return errors.Wrap(err, "string") + } + return nil + }(); err != nil { + failures = append(failures, validate.FieldError{ + Name: "username", + Error: err, + }) + } + if len(failures) > 0 { + return &validate.Error{Fields: failures} + } + return nil +} + +func (s *CurrentUserBadRequest) Validate() error { + alias := (*ErrorHeaders)(s) + if err := alias.Validate(); err != nil { + return err + } + return nil +} + +func (s *CurrentUserConflict) Validate() error { + alias := (*ErrorHeaders)(s) + if err := alias.Validate(); err != nil { + return err + } + return nil +} + +func (s *CurrentUserInternalServerError) Validate() error { + alias := (*ErrorHeaders)(s) + if err := alias.Validate(); err != nil { + return err + } + return nil +} + +func (s *CurrentUserNotFound) Validate() error { + alias := (*ErrorHeaders)(s) + if err := alias.Validate(); err != nil { + return err + } + return nil +} + +func (s *CurrentUserServiceUnavailable) Validate() error { + alias := (*ErrorHeaders)(s) + if err := alias.Validate(); err != nil { + return err + } + return nil +} + +func (s *DownloadAttachmentBadRequest) Validate() error { + alias := (*ErrorHeaders)(s) + if err := alias.Validate(); err != nil { + return err + } + return nil +} + +func (s *DownloadAttachmentConflict) Validate() error { + alias := (*ErrorHeaders)(s) + if err := alias.Validate(); err != nil { + return err + } + return nil +} + +func (s *DownloadAttachmentInternalServerError) Validate() error { + alias := (*ErrorHeaders)(s) + if err := alias.Validate(); err != nil { + return err + } + return nil +} + +func (s *DownloadAttachmentNotFound) Validate() error { + alias := (*ErrorHeaders)(s) + if err := alias.Validate(); err != nil { + return err + } + return nil +} + +func (s *DownloadAttachmentOKImageJpegHeaders) Validate() error { + if s == nil { + return validate.ErrNilPointer + } + + var failures []validate.FieldError + if err := func() error { + if value, ok := s.XInstanceID.Get(); ok { + if err := func() error { + if err := (validate.String{ + MinLength: 1, + MinLengthSet: true, + MaxLength: 0, + MaxLengthSet: false, + Email: false, + Hostname: false, + Regex: nil, + MinNumeric: 0, + MinNumericSet: false, + MaxNumeric: 0, + MaxNumericSet: false, + }).Validate(string(value)); err != nil { + return errors.Wrap(err, "string") + } + return nil + }(); err != nil { + return err + } + } + return nil + }(); err != nil { + failures = append(failures, validate.FieldError{ + Name: "XInstanceID", + Error: err, + }) + } + if err := func() error { + if value, ok := s.XRequestID.Get(); ok { + if err := func() error { + if err := (validate.String{ + MinLength: 1, + MinLengthSet: true, + MaxLength: 0, + MaxLengthSet: false, + Email: false, + Hostname: false, + Regex: nil, + MinNumeric: 0, + MinNumericSet: false, + MaxNumeric: 0, + MaxNumericSet: false, + }).Validate(string(value)); err != nil { + return errors.Wrap(err, "string") + } + return nil + }(); err != nil { + return err + } + } + return nil + }(); err != nil { + failures = append(failures, validate.FieldError{ + Name: "XRequestID", + Error: err, + }) + } + if len(failures) > 0 { + return &validate.Error{Fields: failures} + } + return nil +} + +func (s *DownloadAttachmentOKImagePNGHeaders) Validate() error { + if s == nil { + return validate.ErrNilPointer + } + + var failures []validate.FieldError + if err := func() error { + if value, ok := s.XInstanceID.Get(); ok { + if err := func() error { + if err := (validate.String{ + MinLength: 1, + MinLengthSet: true, + MaxLength: 0, + MaxLengthSet: false, + Email: false, + Hostname: false, + Regex: nil, + MinNumeric: 0, + MinNumericSet: false, + MaxNumeric: 0, + MaxNumericSet: false, + }).Validate(string(value)); err != nil { + return errors.Wrap(err, "string") + } + return nil + }(); err != nil { + return err + } + } + return nil + }(); err != nil { + failures = append(failures, validate.FieldError{ + Name: "XInstanceID", + Error: err, + }) + } + if err := func() error { + if value, ok := s.XRequestID.Get(); ok { + if err := func() error { + if err := (validate.String{ + MinLength: 1, + MinLengthSet: true, + MaxLength: 0, + MaxLengthSet: false, + Email: false, + Hostname: false, + Regex: nil, + MinNumeric: 0, + MinNumericSet: false, + MaxNumeric: 0, + MaxNumericSet: false, + }).Validate(string(value)); err != nil { + return errors.Wrap(err, "string") + } + return nil + }(); err != nil { + return err + } + } + return nil + }(); err != nil { + failures = append(failures, validate.FieldError{ + Name: "XRequestID", + Error: err, + }) + } + if len(failures) > 0 { + return &validate.Error{Fields: failures} + } + return nil +} + +func (s *DownloadAttachmentOKImageWEBPHeaders) Validate() error { + if s == nil { + return validate.ErrNilPointer + } + + var failures []validate.FieldError + if err := func() error { + if value, ok := s.XInstanceID.Get(); ok { + if err := func() error { + if err := (validate.String{ + MinLength: 1, + MinLengthSet: true, + MaxLength: 0, + MaxLengthSet: false, + Email: false, + Hostname: false, + Regex: nil, + MinNumeric: 0, + MinNumericSet: false, + MaxNumeric: 0, + MaxNumericSet: false, + }).Validate(string(value)); err != nil { + return errors.Wrap(err, "string") + } + return nil + }(); err != nil { + return err + } + } + return nil + }(); err != nil { + failures = append(failures, validate.FieldError{ + Name: "XInstanceID", + Error: err, + }) + } + if err := func() error { + if value, ok := s.XRequestID.Get(); ok { + if err := func() error { + if err := (validate.String{ + MinLength: 1, + MinLengthSet: true, + MaxLength: 0, + MaxLengthSet: false, + Email: false, + Hostname: false, + Regex: nil, + MinNumeric: 0, + MinNumericSet: false, + MaxNumeric: 0, + MaxNumericSet: false, + }).Validate(string(value)); err != nil { + return errors.Wrap(err, "string") + } + return nil + }(); err != nil { + return err + } + } + return nil + }(); err != nil { + failures = append(failures, validate.FieldError{ + Name: "XRequestID", + Error: err, + }) + } + if len(failures) > 0 { + return &validate.Error{Fields: failures} + } + return nil +} + +func (s *DownloadAttachmentServiceUnavailable) Validate() error { + alias := (*ErrorHeaders)(s) + if err := alias.Validate(); err != nil { + return err + } + return nil +} + +func (s DownloadAttachmentVariant) Validate() error { + switch s { + case "original": + return nil + case "thumbnail": + return nil + case "crop": + return nil + case "optimized": + return nil + default: + return errors.Errorf("invalid value: %v", s) + } +} + +func (s *Error) Validate() error { + if s == nil { + return validate.ErrNilPointer + } + + var failures []validate.FieldError + if err := func() error { + if err := s.Error.Validate(); err != nil { + return err + } + return nil + }(); err != nil { + failures = append(failures, validate.FieldError{ + Name: "error", + Error: err, + }) + } + if len(failures) > 0 { + return &validate.Error{Fields: failures} + } + return nil +} + +func (s *ErrorError) Validate() error { + if s == nil { + return validate.ErrNilPointer + } + + var failures []validate.FieldError + if err := func() error { + if err := s.Code.Validate(); err != nil { + return err + } + return nil + }(); err != nil { + failures = append(failures, validate.FieldError{ + Name: "code", + Error: err, + }) + } + if err := func() error { + if err := (validate.String{ + MinLength: 1, + MinLengthSet: true, + MaxLength: 0, + MaxLengthSet: false, + Email: false, + Hostname: false, + Regex: nil, + MinNumeric: 0, + MinNumericSet: false, + MaxNumeric: 0, + MaxNumericSet: false, + }).Validate(string(s.Message)); err != nil { + return errors.Wrap(err, "string") + } + return nil + }(); err != nil { + failures = append(failures, validate.FieldError{ + Name: "message", + Error: err, + }) + } + if err := func() error { + if err := (validate.String{ + MinLength: 1, + MinLengthSet: true, + MaxLength: 0, + MaxLengthSet: false, + Email: false, + Hostname: false, + Regex: nil, + MinNumeric: 0, + MinNumericSet: false, + MaxNumeric: 0, + MaxNumericSet: false, + }).Validate(string(s.RequestID)); err != nil { + return errors.Wrap(err, "string") + } + return nil + }(); err != nil { + failures = append(failures, validate.FieldError{ + Name: "request_id", + Error: err, + }) + } + if len(failures) > 0 { + return &validate.Error{Fields: failures} + } + return nil +} + +func (s ErrorErrorCode) Validate() error { + switch s { + case "invalid_request": + return nil + case "unauthorized": + return nil + case "not_found": + return nil + case "conflict": + return nil + case "payload_too_large": + return nil + case "unsupported_media_type": + return nil + case "rate_limited": + return nil + case "unavailable": + return nil + case "internal_error": + return nil + default: + return errors.Errorf("invalid value: %v", s) + } +} + +func (s *ErrorHeaders) Validate() error { + if s == nil { + return validate.ErrNilPointer + } + + var failures []validate.FieldError + if err := func() error { + if value, ok := s.XInstanceID.Get(); ok { + if err := func() error { + if err := (validate.String{ + MinLength: 1, + MinLengthSet: true, + MaxLength: 0, + MaxLengthSet: false, + Email: false, + Hostname: false, + Regex: nil, + MinNumeric: 0, + MinNumericSet: false, + MaxNumeric: 0, + MaxNumericSet: false, + }).Validate(string(value)); err != nil { + return errors.Wrap(err, "string") + } + return nil + }(); err != nil { + return err + } + } + return nil + }(); err != nil { + failures = append(failures, validate.FieldError{ + Name: "XInstanceID", + Error: err, + }) + } + if err := func() error { + if value, ok := s.XRequestID.Get(); ok { + if err := func() error { + if err := (validate.String{ + MinLength: 1, + MinLengthSet: true, + MaxLength: 0, + MaxLengthSet: false, + Email: false, + Hostname: false, + Regex: nil, + MinNumeric: 0, + MinNumericSet: false, + MaxNumeric: 0, + MaxNumericSet: false, + }).Validate(string(value)); err != nil { + return errors.Wrap(err, "string") + } + return nil + }(); err != nil { + return err + } + } + return nil + }(); err != nil { + failures = append(failures, validate.FieldError{ + Name: "XRequestID", + Error: err, + }) + } + if err := func() error { + if err := s.Response.Validate(); err != nil { + return err + } + return nil + }(); err != nil { + failures = append(failures, validate.FieldError{ + Name: "Response", + Error: err, + }) + } + if len(failures) > 0 { + return &validate.Error{Fields: failures} + } + return nil +} + +func (s *GetAttachmentBadRequest) Validate() error { + alias := (*ErrorHeaders)(s) + if err := alias.Validate(); err != nil { + return err + } + return nil +} + +func (s *GetAttachmentConflict) Validate() error { + alias := (*ErrorHeaders)(s) + if err := alias.Validate(); err != nil { + return err + } + return nil +} + +func (s *GetAttachmentInternalServerError) Validate() error { + alias := (*ErrorHeaders)(s) + if err := alias.Validate(); err != nil { + return err + } + return nil +} + +func (s *GetAttachmentNotFound) Validate() error { + alias := (*ErrorHeaders)(s) + if err := alias.Validate(); err != nil { + return err + } + return nil +} + +func (s *GetAttachmentServiceUnavailable) Validate() error { + alias := (*ErrorHeaders)(s) + if err := alias.Validate(); err != nil { + return err + } + return nil +} + +func (s *GetAttachmentTooManyRequestsHeaders) Validate() error { + if s == nil { + return validate.ErrNilPointer + } + + var failures []validate.FieldError + if err := func() error { + if value, ok := s.RetryAfter.Get(); ok { + if err := func() error { + if err := (validate.Int{ + MinSet: true, + Min: 1, + MaxSet: false, + Max: 0, + MinExclusive: false, + MaxExclusive: false, + MultipleOfSet: false, + MultipleOf: 0, + Pattern: nil, + }).Validate(int64(value)); err != nil { + return errors.Wrap(err, "int") + } + return nil + }(); err != nil { + return err + } + } + return nil + }(); err != nil { + failures = append(failures, validate.FieldError{ + Name: "RetryAfter", + Error: err, + }) + } + if err := func() error { + if value, ok := s.XInstanceID.Get(); ok { + if err := func() error { + if err := (validate.String{ + MinLength: 1, + MinLengthSet: true, + MaxLength: 0, + MaxLengthSet: false, + Email: false, + Hostname: false, + Regex: nil, + MinNumeric: 0, + MinNumericSet: false, + MaxNumeric: 0, + MaxNumericSet: false, + }).Validate(string(value)); err != nil { + return errors.Wrap(err, "string") + } + return nil + }(); err != nil { + return err + } + } + return nil + }(); err != nil { + failures = append(failures, validate.FieldError{ + Name: "XInstanceID", + Error: err, + }) + } + if err := func() error { + if value, ok := s.XRequestID.Get(); ok { + if err := func() error { + if err := (validate.String{ + MinLength: 1, + MinLengthSet: true, + MaxLength: 0, + MaxLengthSet: false, + Email: false, + Hostname: false, + Regex: nil, + MinNumeric: 0, + MinNumericSet: false, + MaxNumeric: 0, + MaxNumericSet: false, + }).Validate(string(value)); err != nil { + return errors.Wrap(err, "string") + } + return nil + }(); err != nil { + return err + } + } + return nil + }(); err != nil { + failures = append(failures, validate.FieldError{ + Name: "XRequestID", + Error: err, + }) + } + if err := func() error { + if err := s.Response.Validate(); err != nil { + return err + } + return nil + }(); err != nil { + failures = append(failures, validate.FieldError{ + Name: "Response", + Error: err, + }) + } + if len(failures) > 0 { + return &validate.Error{Fields: failures} + } + return nil +} + +func (s *GetAttachmentUnauthorizedHeaders) Validate() error { + if s == nil { + return validate.ErrNilPointer + } + + var failures []validate.FieldError + if err := func() error { + if value, ok := s.XInstanceID.Get(); ok { + if err := func() error { + if err := (validate.String{ + MinLength: 1, + MinLengthSet: true, + MaxLength: 0, + MaxLengthSet: false, + Email: false, + Hostname: false, + Regex: nil, + MinNumeric: 0, + MinNumericSet: false, + MaxNumeric: 0, + MaxNumericSet: false, + }).Validate(string(value)); err != nil { + return errors.Wrap(err, "string") + } + return nil + }(); err != nil { + return err + } + } + return nil + }(); err != nil { + failures = append(failures, validate.FieldError{ + Name: "XInstanceID", + Error: err, + }) + } + if err := func() error { + if value, ok := s.XRequestID.Get(); ok { + if err := func() error { + if err := (validate.String{ + MinLength: 1, + MinLengthSet: true, + MaxLength: 0, + MaxLengthSet: false, + Email: false, + Hostname: false, + Regex: nil, + MinNumeric: 0, + MinNumericSet: false, + MaxNumeric: 0, + MaxNumericSet: false, + }).Validate(string(value)); err != nil { + return errors.Wrap(err, "string") + } + return nil + }(); err != nil { + return err + } + } + return nil + }(); err != nil { + failures = append(failures, validate.FieldError{ + Name: "XRequestID", + Error: err, + }) + } + if err := func() error { + if err := s.Response.Validate(); err != nil { + return err + } + return nil + }(); err != nil { + failures = append(failures, validate.FieldError{ + Name: "Response", + Error: err, + }) + } + if len(failures) > 0 { + return &validate.Error{Fields: failures} + } + return nil +} + +func (s *GetChatBadRequest) Validate() error { + alias := (*ErrorHeaders)(s) + if err := alias.Validate(); err != nil { + return err + } + return nil +} + +func (s *GetChatConflict) Validate() error { + alias := (*ErrorHeaders)(s) + if err := alias.Validate(); err != nil { + return err + } + return nil +} + +func (s *GetChatInternalServerError) Validate() error { + alias := (*ErrorHeaders)(s) + if err := alias.Validate(); err != nil { + return err + } + return nil +} + +func (s *GetChatNotFound) Validate() error { + alias := (*ErrorHeaders)(s) + if err := alias.Validate(); err != nil { + return err + } + return nil +} + +func (s *GetChatServiceUnavailable) Validate() error { + alias := (*ErrorHeaders)(s) + if err := alias.Validate(); err != nil { + return err + } + return nil +} + +func (s *Health) Validate() error { + if s == nil { + return validate.ErrNilPointer + } + + var failures []validate.FieldError + if err := func() error { + if err := s.Status.Validate(); err != nil { + return err + } + return nil + }(); err != nil { + failures = append(failures, validate.FieldError{ + Name: "status", + Error: err, + }) + } + if len(failures) > 0 { + return &validate.Error{Fields: failures} + } + return nil +} + +func (s *HealthHeaders) Validate() error { + if s == nil { + return validate.ErrNilPointer + } + + var failures []validate.FieldError + if err := func() error { + if value, ok := s.XInstanceID.Get(); ok { + if err := func() error { + if err := (validate.String{ + MinLength: 1, + MinLengthSet: true, + MaxLength: 0, + MaxLengthSet: false, + Email: false, + Hostname: false, + Regex: nil, + MinNumeric: 0, + MinNumericSet: false, + MaxNumeric: 0, + MaxNumericSet: false, + }).Validate(string(value)); err != nil { + return errors.Wrap(err, "string") + } + return nil + }(); err != nil { + return err + } + } + return nil + }(); err != nil { + failures = append(failures, validate.FieldError{ + Name: "XInstanceID", + Error: err, + }) + } + if err := func() error { + if value, ok := s.XRequestID.Get(); ok { + if err := func() error { + if err := (validate.String{ + MinLength: 1, + MinLengthSet: true, + MaxLength: 0, + MaxLengthSet: false, + Email: false, + Hostname: false, + Regex: nil, + MinNumeric: 0, + MinNumericSet: false, + MaxNumeric: 0, + MaxNumericSet: false, + }).Validate(string(value)); err != nil { + return errors.Wrap(err, "string") + } + return nil + }(); err != nil { + return err + } + } + return nil + }(); err != nil { + failures = append(failures, validate.FieldError{ + Name: "XRequestID", + Error: err, + }) + } + if err := func() error { + if err := s.Response.Validate(); err != nil { + return err + } + return nil + }(); err != nil { + failures = append(failures, validate.FieldError{ + Name: "Response", + Error: err, + }) + } + if len(failures) > 0 { + return &validate.Error{Fields: failures} + } + return nil +} + +func (s HealthStatus) Validate() error { + switch s { + case "ok": + return nil + default: + return errors.Errorf("invalid value: %v", s) + } +} + +func (s *ListChatsBadRequest) Validate() error { + alias := (*ErrorHeaders)(s) + if err := alias.Validate(); err != nil { + return err + } + return nil +} + +func (s *ListChatsConflict) Validate() error { + alias := (*ErrorHeaders)(s) + if err := alias.Validate(); err != nil { + return err + } + return nil +} + +func (s *ListChatsInternalServerError) Validate() error { + alias := (*ErrorHeaders)(s) + if err := alias.Validate(); err != nil { + return err + } + return nil +} + +func (s *ListChatsNotFound) Validate() error { + alias := (*ErrorHeaders)(s) + if err := alias.Validate(); err != nil { + return err + } + return nil +} + +func (s *ListChatsServiceUnavailable) Validate() error { + alias := (*ErrorHeaders)(s) + if err := alias.Validate(); err != nil { + return err + } + return nil +} + +func (s *ListMessagesBadRequest) Validate() error { + alias := (*ErrorHeaders)(s) + if err := alias.Validate(); err != nil { + return err + } + return nil +} + +func (s *ListMessagesConflict) Validate() error { + alias := (*ErrorHeaders)(s) + if err := alias.Validate(); err != nil { + return err + } + return nil +} + +func (s *ListMessagesInternalServerError) Validate() error { + alias := (*ErrorHeaders)(s) + if err := alias.Validate(); err != nil { + return err + } + return nil +} + +func (s *ListMessagesNotFound) Validate() error { + alias := (*ErrorHeaders)(s) + if err := alias.Validate(); err != nil { + return err + } + return nil +} + +func (s *ListMessagesServiceUnavailable) Validate() error { + alias := (*ErrorHeaders)(s) + if err := alias.Validate(); err != nil { + return err + } + return nil +} + +func (s *Message) Validate() error { + if s == nil { + return validate.ErrNilPointer + } + + var failures []validate.FieldError + if err := func() error { + if s.AttachmentIds == nil { + return errors.New("nil is invalid value") + } + if err := (validate.Array{ + MinLength: 0, + MinLengthSet: false, + MaxLength: 10, + MaxLengthSet: true, + }).ValidateLength(len(s.AttachmentIds)); err != nil { + return errors.Wrap(err, "array") + } + if err := validate.UniqueItems(s.AttachmentIds); err != nil { + return errors.Wrap(err, "array") + } + return nil + }(); err != nil { + failures = append(failures, validate.FieldError{ + Name: "attachment_ids", + Error: err, + }) + } + if err := func() error { + if err := (validate.String{ + MinLength: 0, + MinLengthSet: false, + MaxLength: 4000, + MaxLengthSet: true, + Email: false, + Hostname: false, + Regex: nil, + MinNumeric: 0, + MinNumericSet: false, + MaxNumeric: 0, + MaxNumericSet: false, + }).Validate(string(s.Text)); err != nil { + return errors.Wrap(err, "string") + } + return nil + }(); err != nil { + failures = append(failures, validate.FieldError{ + Name: "text", + Error: err, + }) + } + if len(failures) > 0 { + return &validate.Error{Fields: failures} + } + return nil +} + +func (s *MessageHeaders) Validate() error { + if s == nil { + return validate.ErrNilPointer + } + + var failures []validate.FieldError + if err := func() error { + if value, ok := s.XInstanceID.Get(); ok { + if err := func() error { + if err := (validate.String{ + MinLength: 1, + MinLengthSet: true, + MaxLength: 0, + MaxLengthSet: false, + Email: false, + Hostname: false, + Regex: nil, + MinNumeric: 0, + MinNumericSet: false, + MaxNumeric: 0, + MaxNumericSet: false, + }).Validate(string(value)); err != nil { + return errors.Wrap(err, "string") + } + return nil + }(); err != nil { + return err + } + } + return nil + }(); err != nil { + failures = append(failures, validate.FieldError{ + Name: "XInstanceID", + Error: err, + }) + } + if err := func() error { + if value, ok := s.XRequestID.Get(); ok { + if err := func() error { + if err := (validate.String{ + MinLength: 1, + MinLengthSet: true, + MaxLength: 0, + MaxLengthSet: false, + Email: false, + Hostname: false, + Regex: nil, + MinNumeric: 0, + MinNumericSet: false, + MaxNumeric: 0, + MaxNumericSet: false, + }).Validate(string(value)); err != nil { + return errors.Wrap(err, "string") + } + return nil + }(); err != nil { + return err + } + } + return nil + }(); err != nil { + failures = append(failures, validate.FieldError{ + Name: "XRequestID", + Error: err, + }) + } + if err := func() error { + if err := s.Response.Validate(); err != nil { + return err + } + return nil + }(); err != nil { + failures = append(failures, validate.FieldError{ + Name: "Response", + Error: err, + }) + } + if len(failures) > 0 { + return &validate.Error{Fields: failures} + } + return nil +} + +func (s *MessagePage) Validate() error { + if s == nil { + return validate.ErrNilPointer + } + + var failures []validate.FieldError + if err := func() error { + if s.Items == nil { + return errors.New("nil is invalid value") + } + var failures []validate.FieldError + for i, elem := range s.Items { + if err := func() error { + if err := elem.Validate(); err != nil { + return err + } + return nil + }(); err != nil { + failures = append(failures, validate.FieldError{ + Name: fmt.Sprintf("[%d]", i), + Error: err, + }) + } + } + if len(failures) > 0 { + return &validate.Error{Fields: failures} + } + return nil + }(); err != nil { + failures = append(failures, validate.FieldError{ + Name: "items", + Error: err, + }) + } + if len(failures) > 0 { + return &validate.Error{Fields: failures} + } + return nil +} + +func (s *MessagePageHeaders) Validate() error { + if s == nil { + return validate.ErrNilPointer + } + + var failures []validate.FieldError + if err := func() error { + if value, ok := s.XInstanceID.Get(); ok { + if err := func() error { + if err := (validate.String{ + MinLength: 1, + MinLengthSet: true, + MaxLength: 0, + MaxLengthSet: false, + Email: false, + Hostname: false, + Regex: nil, + MinNumeric: 0, + MinNumericSet: false, + MaxNumeric: 0, + MaxNumericSet: false, + }).Validate(string(value)); err != nil { + return errors.Wrap(err, "string") + } + return nil + }(); err != nil { + return err + } + } + return nil + }(); err != nil { + failures = append(failures, validate.FieldError{ + Name: "XInstanceID", + Error: err, + }) + } + if err := func() error { + if value, ok := s.XRequestID.Get(); ok { + if err := func() error { + if err := (validate.String{ + MinLength: 1, + MinLengthSet: true, + MaxLength: 0, + MaxLengthSet: false, + Email: false, + Hostname: false, + Regex: nil, + MinNumeric: 0, + MinNumericSet: false, + MaxNumeric: 0, + MaxNumericSet: false, + }).Validate(string(value)); err != nil { + return errors.Wrap(err, "string") + } + return nil + }(); err != nil { + return err + } + } + return nil + }(); err != nil { + failures = append(failures, validate.FieldError{ + Name: "XRequestID", + Error: err, + }) + } + if err := func() error { + if err := s.Response.Validate(); err != nil { + return err + } + return nil + }(); err != nil { + failures = append(failures, validate.FieldError{ + Name: "Response", + Error: err, + }) + } + if len(failures) > 0 { + return &validate.Error{Fields: failures} + } + return nil +} + +func (s *ReadinessInternalServerError) Validate() error { + alias := (*ErrorHeaders)(s) + if err := alias.Validate(); err != nil { + return err + } + return nil +} + +func (s *ReadinessServiceUnavailable) Validate() error { + alias := (*ErrorHeaders)(s) + if err := alias.Validate(); err != nil { + return err + } + return nil +} + +func (s *RegisterUserBadRequest) Validate() error { + alias := (*ErrorHeaders)(s) + if err := alias.Validate(); err != nil { + return err + } + return nil +} + +func (s *RegisterUserConflict) Validate() error { + alias := (*ErrorHeaders)(s) + if err := alias.Validate(); err != nil { + return err + } + return nil +} + +func (s *RegisterUserInternalServerError) Validate() error { + alias := (*ErrorHeaders)(s) + if err := alias.Validate(); err != nil { + return err + } + return nil +} + +func (s *RegisterUserServiceUnavailable) Validate() error { + alias := (*ErrorHeaders)(s) + if err := alias.Validate(); err != nil { + return err + } + return nil +} + +func (s *RevokeSessionInternalServerError) Validate() error { + alias := (*ErrorHeaders)(s) + if err := alias.Validate(); err != nil { + return err + } + return nil +} + +func (s *RevokeSessionNoContent) Validate() error { + if s == nil { + return validate.ErrNilPointer + } + + var failures []validate.FieldError + if err := func() error { + if value, ok := s.XInstanceID.Get(); ok { + if err := func() error { + if err := (validate.String{ + MinLength: 1, + MinLengthSet: true, + MaxLength: 0, + MaxLengthSet: false, + Email: false, + Hostname: false, + Regex: nil, + MinNumeric: 0, + MinNumericSet: false, + MaxNumeric: 0, + MaxNumericSet: false, + }).Validate(string(value)); err != nil { + return errors.Wrap(err, "string") + } + return nil + }(); err != nil { + return err + } + } + return nil + }(); err != nil { + failures = append(failures, validate.FieldError{ + Name: "XInstanceID", + Error: err, + }) + } + if err := func() error { + if value, ok := s.XRequestID.Get(); ok { + if err := func() error { + if err := (validate.String{ + MinLength: 1, + MinLengthSet: true, + MaxLength: 0, + MaxLengthSet: false, + Email: false, + Hostname: false, + Regex: nil, + MinNumeric: 0, + MinNumericSet: false, + MaxNumeric: 0, + MaxNumericSet: false, + }).Validate(string(value)); err != nil { + return errors.Wrap(err, "string") + } + return nil + }(); err != nil { + return err + } + } + return nil + }(); err != nil { + failures = append(failures, validate.FieldError{ + Name: "XRequestID", + Error: err, + }) + } + if len(failures) > 0 { + return &validate.Error{Fields: failures} + } + return nil +} + +func (s *RevokeSessionServiceUnavailable) Validate() error { + alias := (*ErrorHeaders)(s) + if err := alias.Validate(); err != nil { + return err + } + return nil +} + +func (s *Session) Validate() error { + if s == nil { + return validate.ErrNilPointer + } + + var failures []validate.FieldError + if err := func() error { + if err := (validate.String{ + MinLength: 32, + MinLengthSet: true, + MaxLength: 0, + MaxLengthSet: false, + Email: false, + Hostname: false, + Regex: nil, + MinNumeric: 0, + MinNumericSet: false, + MaxNumeric: 0, + MaxNumericSet: false, + }).Validate(string(s.Token)); err != nil { + return errors.Wrap(err, "string") + } + return nil + }(); err != nil { + failures = append(failures, validate.FieldError{ + Name: "token", + Error: err, + }) + } + if err := func() error { + if err := s.User.Validate(); err != nil { + return err + } + return nil + }(); err != nil { + failures = append(failures, validate.FieldError{ + Name: "user", + Error: err, + }) + } + if len(failures) > 0 { + return &validate.Error{Fields: failures} + } + return nil +} + +func (s *SessionHeaders) Validate() error { + if s == nil { + return validate.ErrNilPointer + } + + var failures []validate.FieldError + if err := func() error { + if value, ok := s.XInstanceID.Get(); ok { + if err := func() error { + if err := (validate.String{ + MinLength: 1, + MinLengthSet: true, + MaxLength: 0, + MaxLengthSet: false, + Email: false, + Hostname: false, + Regex: nil, + MinNumeric: 0, + MinNumericSet: false, + MaxNumeric: 0, + MaxNumericSet: false, + }).Validate(string(value)); err != nil { + return errors.Wrap(err, "string") + } + return nil + }(); err != nil { + return err + } + } + return nil + }(); err != nil { + failures = append(failures, validate.FieldError{ + Name: "XInstanceID", + Error: err, + }) + } + if err := func() error { + if value, ok := s.XRequestID.Get(); ok { + if err := func() error { + if err := (validate.String{ + MinLength: 1, + MinLengthSet: true, + MaxLength: 0, + MaxLengthSet: false, + Email: false, + Hostname: false, + Regex: nil, + MinNumeric: 0, + MinNumericSet: false, + MaxNumeric: 0, + MaxNumericSet: false, + }).Validate(string(value)); err != nil { + return errors.Wrap(err, "string") + } + return nil + }(); err != nil { + return err + } + } + return nil + }(); err != nil { + failures = append(failures, validate.FieldError{ + Name: "XRequestID", + Error: err, + }) + } + if err := func() error { + if err := s.Response.Validate(); err != nil { + return err + } + return nil + }(); err != nil { + failures = append(failures, validate.FieldError{ + Name: "Response", + Error: err, + }) + } + if len(failures) > 0 { + return &validate.Error{Fields: failures} + } + return nil +} + +func (s *UploadAttachmentBadRequest) Validate() error { + alias := (*ErrorHeaders)(s) + if err := alias.Validate(); err != nil { + return err + } + return nil +} + +func (s *UploadAttachmentInternalServerError) Validate() error { + alias := (*ErrorHeaders)(s) + if err := alias.Validate(); err != nil { + return err + } + return nil +} + +func (s *UploadAttachmentNotFound) Validate() error { + alias := (*ErrorHeaders)(s) + if err := alias.Validate(); err != nil { + return err + } + return nil +} + +func (s *UploadAttachmentRequestEntityTooLarge) Validate() error { + alias := (*ErrorHeaders)(s) + if err := alias.Validate(); err != nil { + return err + } + return nil +} + +func (s *UploadAttachmentServiceUnavailable) Validate() error { + alias := (*ErrorHeaders)(s) + if err := alias.Validate(); err != nil { + return err + } + return nil +} + +func (s *UploadAttachmentUnsupportedMediaType) Validate() error { + alias := (*ErrorHeaders)(s) + if err := alias.Validate(); err != nil { + return err + } + return nil +} + +func (s *User) Validate() error { + if s == nil { + return validate.ErrNilPointer + } + + var failures []validate.FieldError + if err := func() error { + if err := (validate.String{ + MinLength: 1, + MinLengthSet: true, + MaxLength: 100, + MaxLengthSet: true, + Email: false, + Hostname: false, + Regex: nil, + MinNumeric: 0, + MinNumericSet: false, + MaxNumeric: 0, + MaxNumericSet: false, + }).Validate(string(s.DisplayName)); err != nil { + return errors.Wrap(err, "string") + } + return nil + }(); err != nil { + failures = append(failures, validate.FieldError{ + Name: "display_name", + Error: err, + }) + } + if err := func() error { + if err := (validate.String{ + MinLength: 0, + MinLengthSet: false, + MaxLength: 0, + MaxLengthSet: false, + Email: false, + Hostname: false, + Regex: regexMap["^[a-z0-9_]{3,32}$"], + MinNumeric: 0, + MinNumericSet: false, + MaxNumeric: 0, + MaxNumericSet: false, + }).Validate(string(s.Username)); err != nil { + return errors.Wrap(err, "string") + } + return nil + }(); err != nil { + failures = append(failures, validate.FieldError{ + Name: "username", + Error: err, + }) + } + if len(failures) > 0 { + return &validate.Error{Fields: failures} + } + return nil +} + +func (s *UserHeaders) Validate() error { + if s == nil { + return validate.ErrNilPointer + } + + var failures []validate.FieldError + if err := func() error { + if value, ok := s.XInstanceID.Get(); ok { + if err := func() error { + if err := (validate.String{ + MinLength: 1, + MinLengthSet: true, + MaxLength: 0, + MaxLengthSet: false, + Email: false, + Hostname: false, + Regex: nil, + MinNumeric: 0, + MinNumericSet: false, + MaxNumeric: 0, + MaxNumericSet: false, + }).Validate(string(value)); err != nil { + return errors.Wrap(err, "string") + } + return nil + }(); err != nil { + return err + } + } + return nil + }(); err != nil { + failures = append(failures, validate.FieldError{ + Name: "XInstanceID", + Error: err, + }) + } + if err := func() error { + if value, ok := s.XRequestID.Get(); ok { + if err := func() error { + if err := (validate.String{ + MinLength: 1, + MinLengthSet: true, + MaxLength: 0, + MaxLengthSet: false, + Email: false, + Hostname: false, + Regex: nil, + MinNumeric: 0, + MinNumericSet: false, + MaxNumeric: 0, + MaxNumericSet: false, + }).Validate(string(value)); err != nil { + return errors.Wrap(err, "string") + } + return nil + }(); err != nil { + return err + } + } + return nil + }(); err != nil { + failures = append(failures, validate.FieldError{ + Name: "XRequestID", + Error: err, + }) + } + if err := func() error { + if err := s.Response.Validate(); err != nil { + return err + } + return nil + }(); err != nil { + failures = append(failures, validate.FieldError{ + Name: "Response", + Error: err, + }) + } + if len(failures) > 0 { + return &validate.Error{Fields: failures} + } + return nil +} + +func (s *Variant) Validate() error { + if s == nil { + return validate.ErrNilPointer + } + + var failures []validate.FieldError + if err := func() error { + if err := s.ContentType.Validate(); err != nil { + return err + } + return nil + }(); err != nil { + failures = append(failures, validate.FieldError{ + Name: "content_type", + Error: err, + }) + } + if err := func() error { + if err := (validate.Int{ + MinSet: true, + Min: 1, + MaxSet: false, + Max: 0, + MinExclusive: false, + MaxExclusive: false, + MultipleOfSet: false, + MultipleOf: 0, + Pattern: nil, + }).Validate(int64(s.Height)); err != nil { + return errors.Wrap(err, "int") + } + return nil + }(); err != nil { + failures = append(failures, validate.FieldError{ + Name: "height", + Error: err, + }) + } + if err := func() error { + if err := s.Name.Validate(); err != nil { + return err + } + return nil + }(); err != nil { + failures = append(failures, validate.FieldError{ + Name: "name", + Error: err, + }) + } + if err := func() error { + if err := (validate.String{ + MinLength: 0, + MinLengthSet: false, + MaxLength: 0, + MaxLengthSet: false, + Email: false, + Hostname: false, + Regex: regexMap["^[a-f0-9]{64}$"], + MinNumeric: 0, + MinNumericSet: false, + MaxNumeric: 0, + MaxNumericSet: false, + }).Validate(string(s.SHA256)); err != nil { + return errors.Wrap(err, "string") + } + return nil + }(); err != nil { + failures = append(failures, validate.FieldError{ + Name: "sha256", + Error: err, + }) + } + if err := func() error { + if err := (validate.Int{ + MinSet: true, + Min: 1, + MaxSet: false, + Max: 0, + MinExclusive: false, + MaxExclusive: false, + MultipleOfSet: false, + MultipleOf: 0, + Pattern: nil, + }).Validate(int64(s.SizeBytes)); err != nil { + return errors.Wrap(err, "int") + } + return nil + }(); err != nil { + failures = append(failures, validate.FieldError{ + Name: "size_bytes", + Error: err, + }) + } + if err := func() error { + if err := (validate.Int{ + MinSet: true, + Min: 1, + MaxSet: false, + Max: 0, + MinExclusive: false, + MaxExclusive: false, + MultipleOfSet: false, + MultipleOf: 0, + Pattern: nil, + }).Validate(int64(s.Width)); err != nil { + return errors.Wrap(err, "int") + } + return nil + }(); err != nil { + failures = append(failures, validate.FieldError{ + Name: "width", + Error: err, + }) + } + if len(failures) > 0 { + return &validate.Error{Fields: failures} + } + return nil +} + +func (s VariantContentType) Validate() error { + switch s { + case "image/jpeg": + return nil + case "image/png": + return nil + case "image/webp": + return nil + default: + return errors.Errorf("invalid value: %v", s) + } +} + +func (s VariantName) Validate() error { + switch s { + case "thumbnail": + return nil + case "crop": + return nil + case "optimized": + return nil + default: + return errors.Errorf("invalid value: %v", s) + } +} diff --git a/internal/transport/rest/logging.go b/internal/transport/rest/logging.go new file mode 100644 index 0000000..05f53b1 --- /dev/null +++ b/internal/transport/rest/logging.go @@ -0,0 +1,145 @@ +package rest + +import ( + "context" + "errors" + "fmt" + "log/slog" + "net/http" + "time" + + "github.com/ogen-go/ogen/middleware" + "github.com/ogen-go/ogen/ogenerrors" + "github.com/ogen-go/ogen/openapi" + + "mtusi-messenger/internal/transport/rest/internal/oas" +) + +func loggingMiddleware(log *slog.Logger) oas.Middleware { + return func(req middleware.Request, next middleware.Next) (middleware.Response, error) { + started := time.Now() + + base := []any{ + slog.String("request_id", requestIDFromContext(req.Context)), + slog.String("operation", req.OperationID), + slog.String("method", req.Raw.Method), + slog.String("path", req.Raw.URL.Path), + } + + accepted := make([]any, 0, len(base)+6) + accepted = append(accepted, base...) + accepted = append(accepted, + slog.String("query", req.Raw.URL.RawQuery), + slog.String("remote_addr", req.Raw.RemoteAddr), + slog.String("user_agent", req.Raw.UserAgent()), + slog.Int64("content_length", req.Raw.ContentLength), + slog.Any("params", loggedParams(req.Params)), + payloadAttr(req.RawBody), + ) + + log.InfoContext(req.Context, "request accepted", accepted...) + + resp, err := next(req) + + handled := make([]any, 0, len(base)+4) + handled = append(handled, base...) + handled = append(handled, slog.Duration("duration", time.Since(started))) + + if err != nil { + // Статус в логе должен совпадать с ответом клиенту: ogenerrors.ErrorCode + // возвращает 500 для доменных ошибок, поэтому используем ту же функцию, + // что и обработчик ошибок транспорта. + status := statusForError(err) + + handled = append(handled, + slog.Int("status", status), + slog.String("error", err.Error()), + ) + log.Log(req.Context, levelForStatus(status), "request failed", handled...) + + return resp, err + } + + handled = append(handled, slog.String("result", resultType(resp))) + log.InfoContext(req.Context, "request handled", handled...) + + return resp, nil + } +} + +func logRejected(ctx context.Context, log *slog.Logger, r *http.Request, status int, err error) { + if log == nil { + return + } + + attrs := []any{ + slog.String("request_id", requestIDFromContext(ctx)), + slog.String("method", r.Method), + slog.Int("status", status), + } + + if err != nil { + attrs = append(attrs, slog.String("error", err.Error())) + } + + log.Log(ctx, levelForStatus(status), "request rejected", attrs...) +} + +func preMiddlewareError(err error) bool { + return errors.As(err, new(*ogenerrors.SecurityError)) || + errors.As(err, new(*ogenerrors.DecodeParamsError)) || + errors.As(err, new(*ogenerrors.DecodeRequestError)) +} + +func levelForStatus(status int) slog.Level { + if status >= http.StatusInternalServerError { + return slog.LevelError + } + + return slog.LevelWarn +} + +func loggedParams(params middleware.Parameters) map[string]any { + if len(params) == 0 { + return nil + } + + out := make(map[string]any, len(params)) + + for key, value := range params { + name := string(key.In) + "." + key.Name + + if key.In == openapi.LocationHeader { + // Значения заголовков не попадают в лог: Idempotency-Key и подобные + // параметры — это долгоживущий след конкретного запроса, а для отладки + // достаточно факта наличия. + out[name] = "redacted" + + continue + } + + out[name] = value + } + + return out +} + +func payloadAttr(body []byte) slog.Attr { + size := len(body) + if size == 0 { + return slog.Attr{} + } + + return slog.Group("payload", + slog.Int("size", size), + slog.Bool("content_logged", false), + ) +} + +func resultType(resp middleware.Response) string { + if resp.Type == nil { + return "" + } + + return fmt.Sprintf("%T", resp.Type) +} diff --git a/internal/transport/rest/logging_test.go b/internal/transport/rest/logging_test.go new file mode 100644 index 0000000..2ff1645 --- /dev/null +++ b/internal/transport/rest/logging_test.go @@ -0,0 +1,228 @@ +package rest + +import ( + "encoding/json" + "errors" + "log/slog" + "net/http" + "net/http/httptest" + "strings" + "testing" + + "github.com/ogen-go/ogen/middleware" + "github.com/ogen-go/ogen/openapi" + "github.com/stretchr/testify/require" + "github.com/stretchr/testify/suite" + + "mtusi-messenger/internal/logger" + "mtusi-messenger/internal/transport/rest/internal/oas" +) + +type LoggingSuite struct { + suite.Suite + + sink *strings.Builder + log *slog.Logger +} + +func TestLoggingSuite(t *testing.T) { + t.Parallel() + suite.Run(t, new(LoggingSuite)) +} + +func (s *LoggingSuite) SetupTest() { + s.sink = &strings.Builder{} + s.log = logger.New( + logger.WithWriter(s.sink), + logger.WithLevel(slog.LevelDebug), + ) +} + +func (s *LoggingSuite) records() []map[string]any { + var out []map[string]any + + for line := range strings.SplitSeq(strings.TrimSpace(s.sink.String()), "\n") { + if line == "" { + continue + } + + var record map[string]any + s.Require().NoError(json.Unmarshal([]byte(line), &record)) + + out = append(out, record) + } + + return out +} + +func (s *LoggingSuite) request(method, target, body string) middleware.Request { + raw := httptest.NewRequestWithContext( + s.T().Context(), + method, + target, + strings.NewReader(body), + ) + raw.RemoteAddr = "192.0.2.10:54321" + raw.Header.Set("User-Agent", "smoke/1.0") + + ctx := withRequestID(raw.Context(), "req-42") + + return middleware.Request{ + Context: ctx, + OperationName: oas.CreateMessageOperation, + OperationID: "createMessage", + RawBody: []byte(body), + Params: middleware.Parameters{ + {Name: "chat_id", In: openapi.LocationPath}: "33333333-3333-4333-8333-333333333333", + {Name: "limit", In: openapi.LocationQuery}: 50, + }, + Raw: raw, + } +} + +func (s *LoggingSuite) TestHeaderParamsAreRedacted() { + req := s.request(http.MethodPost, "/api/v1/chats/33333333-3333-4333-8333-333333333333/messages", `{"text":"привет"}`) + req.Params = middleware.Parameters{ + {Name: "chat_id", In: openapi.LocationPath}: "33333333-3333-4333-8333-333333333333", + {Name: "Idempotency-Key", In: openapi.LocationHeader}: "secret-key-value", + } + + _, err := loggingMiddleware(s.log)(req, func(middleware.Request) (middleware.Response, error) { + return middleware.Response{}, nil + }) + s.Require().NoError(err) + + records := s.records() + s.Require().NotEmpty(records) + + params, ok := records[0]["params"].(map[string]any) + s.Require().True(ok, "params должны быть объектом") + s.Equal("redacted", params["header.Idempotency-Key"], "значение заголовка не логируется") + s.Equal("33333333-3333-4333-8333-333333333333", params["path.chat_id"]) + s.NotContains(s.sink.String(), "secret-key-value") +} + +func (s *LoggingSuite) TestLogsAcceptedAndHandled() { + req := s.request(http.MethodPost, "/api/v1/chats/33333333-3333-4333-8333-333333333333/messages?limit=50", `{"text":"привет"}`) + + response := middleware.Response{Type: &oas.Message{}} + + got, err := loggingMiddleware(s.log)(req, func(middleware.Request) (middleware.Response, error) { + return response, nil + }) + + s.Require().NoError(err) + s.Equal(response, got) + + records := s.records() + s.Require().Len(records, 2, "ожидаются записи о принятом и обработанном запросе") + + accepted, handled := records[0], records[1] + + s.Equal("request accepted", accepted["msg"]) + s.Equal("info", accepted["level"]) + s.Equal("req-42", accepted["request_id"]) + s.Equal("createMessage", accepted["operation"]) + s.Equal(http.MethodPost, accepted["method"]) + s.Equal("/api/v1/chats/33333333-3333-4333-8333-333333333333/messages", accepted["path"]) + s.Equal("limit=50", accepted["query"]) + s.Equal("192.0.2.10:54321", accepted["remote_addr"]) + s.Equal("smoke/1.0", accepted["user_agent"]) + + params, ok := accepted["params"].(map[string]any) + s.Require().True(ok, "params должны быть объектом") + s.Equal("33333333-3333-4333-8333-333333333333", params["path.chat_id"]) + s.InEpsilon(float64(50), params["query.limit"], 0.0001) + + payload, ok := accepted["payload"].(map[string]any) + s.Require().True(ok, "payload должен быть объектом") + + s.False(payload["content_logged"].(bool)) + s.NotContains(s.sink.String(), "привет") + + s.Equal("request handled", handled["msg"]) + s.Equal("info", handled["level"]) + s.Equal("req-42", handled["request_id"]) + s.Equal("*oas.Message", handled["result"]) + s.NotEmpty(handled["duration"], "длительность обработки обязательна") +} + +func (s *LoggingSuite) TestLogsFailure() { + req := s.request(http.MethodGet, "/api/v1/chats", "") + + wantErr := errors.New("storage unavailable") + + _, err := loggingMiddleware(s.log)(req, func(middleware.Request) (middleware.Response, error) { + return middleware.Response{}, wantErr + }) + + s.Require().ErrorIs(err, wantErr) + + records := s.records() + s.Require().Len(records, 2) + + failed := records[1] + s.Equal("request failed", failed["msg"]) + s.Equal("error", failed["level"]) + s.Equal("storage unavailable", failed["error"]) + s.NotEmpty(failed["duration"]) +} + +func (s *LoggingSuite) TestOmitsPayloadWhenBodyIsEmpty() { + req := s.request(http.MethodGet, "/api/v1/chats", "") + + _, err := loggingMiddleware(s.log)(req, func(middleware.Request) (middleware.Response, error) { + return middleware.Response{Type: &oas.ChatPage{}}, nil + }) + s.Require().NoError(err) + + accepted := s.records()[0] + s.NotContains(accepted, "payload", "у запроса без тела не должно быть payload") +} + +func (s *LoggingSuite) TestPayloadContentIsNeverLogged() { + body := strings.Repeat("s", 4096) + req := s.request(http.MethodPost, "/api/v1/chats/33333333-3333-4333-8333-333333333333/messages", body) + + _, err := loggingMiddleware(s.log)(req, func(middleware.Request) (middleware.Response, error) { + return middleware.Response{Type: &oas.Message{}}, nil + }) + s.Require().NoError(err) + + payload, ok := s.records()[0]["payload"].(map[string]any) + s.Require().True(ok) + + s.InEpsilon(float64(len(body)), payload["size"], 0.0001) + s.False(payload["content_logged"].(bool)) + s.NotContains(s.sink.String(), body) +} + +func TestRequestIDMiddlewareSetsHeaderBeforeSecurity(t *testing.T) { + t.Parallel() + + var seen string + + handler := requestIDMiddleware(http.HandlerFunc(func(_ http.ResponseWriter, r *http.Request) { + seen = requestIDFromContext(r.Context()) + })) + + rec := httptest.NewRecorder() + handler.ServeHTTP(rec, httptest.NewRequestWithContext(t.Context(), http.MethodGet, "/health/live", nil)) + + require.NotEmpty(t, seen, "идентификатор должен попадать в контекст") + require.Equal(t, seen, rec.Header().Get("X-Request-ID")) +} + +func TestRequestIDMiddlewarePreservesIncomingID(t *testing.T) { + t.Parallel() + + handler := requestIDMiddleware(http.HandlerFunc(func(http.ResponseWriter, *http.Request) {})) + + req := httptest.NewRequestWithContext(t.Context(), http.MethodGet, "/health/live", nil) + req.Header.Set("X-Request-ID", "from-client") + + rec := httptest.NewRecorder() + handler.ServeHTTP(rec, req) + + require.Equal(t, "from-client", rec.Header().Get("X-Request-ID")) +} diff --git a/internal/transport/rest/mocks/AttachmentService.go b/internal/transport/rest/mocks/AttachmentService.go new file mode 100644 index 0000000..76eecfb --- /dev/null +++ b/internal/transport/rest/mocks/AttachmentService.go @@ -0,0 +1,425 @@ +// Code generated by mockery; DO NOT EDIT. +// github.com/vektra/mockery +// template: testify + +package mocks + +import ( + "context" + "io" + "mtusi-messenger/internal/domain" + "mtusi-messenger/internal/service/attachment" + + "github.com/google/uuid" + mock "github.com/stretchr/testify/mock" +) + +// NewMockAttachmentService creates a new instance of MockAttachmentService. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewMockAttachmentService(t interface { + mock.TestingT + Cleanup(func()) +}) *MockAttachmentService { + if helper, ok := t.(interface{ Helper() }); ok { + helper.Helper() + } + + mock := &MockAttachmentService{} + mock.Mock.Test(t) + + t.Cleanup(func() { + if helper, ok := t.(interface{ Helper() }); ok { + helper.Helper() + } + mock.AssertExpectations(t) + }) + + return mock +} + +// MockAttachmentService is an autogenerated mock type for the AttachmentService type +type MockAttachmentService struct { + mock.Mock +} + +type MockAttachmentService_Expecter struct { + mock *mock.Mock +} + +func (_m *MockAttachmentService) EXPECT() *MockAttachmentService_Expecter { + return &MockAttachmentService_Expecter{mock: &_m.Mock} +} + +// Complete provides a mock function for the type MockAttachmentService +func (_mock *MockAttachmentService) Complete(ctx context.Context, ownerID uuid.UUID, id uuid.UUID, sha256 string) (domain.Attachment, error) { + ret := _mock.Called(ctx, ownerID, id, sha256) + + if len(ret) == 0 { + panic("no return value specified for Complete") + } + + var r0 domain.Attachment + var r1 error + if returnFunc, ok := ret.Get(0).(func(context.Context, uuid.UUID, uuid.UUID, string) (domain.Attachment, error)); ok { + return returnFunc(ctx, ownerID, id, sha256) + } + if returnFunc, ok := ret.Get(0).(func(context.Context, uuid.UUID, uuid.UUID, string) domain.Attachment); ok { + r0 = returnFunc(ctx, ownerID, id, sha256) + } else { + r0 = ret.Get(0).(domain.Attachment) + } + if returnFunc, ok := ret.Get(1).(func(context.Context, uuid.UUID, uuid.UUID, string) error); ok { + r1 = returnFunc(ctx, ownerID, id, sha256) + } else { + r1 = ret.Error(1) + } + return r0, r1 +} + +// MockAttachmentService_Complete_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Complete' +type MockAttachmentService_Complete_Call struct { + *mock.Call +} + +// Complete is a helper method to define mock.On call +// - ctx context.Context +// - ownerID uuid.UUID +// - id uuid.UUID +// - sha256 string +func (_e *MockAttachmentService_Expecter) Complete(ctx any, ownerID any, id any, sha256 any) *MockAttachmentService_Complete_Call { + return &MockAttachmentService_Complete_Call{Call: _e.mock.On("Complete", ctx, ownerID, id, sha256)} +} + +func (_c *MockAttachmentService_Complete_Call) Run(run func(ctx context.Context, ownerID uuid.UUID, id uuid.UUID, sha256 string)) *MockAttachmentService_Complete_Call { + _c.Call.Run(func(args mock.Arguments) { + var arg0 context.Context + if args[0] != nil { + arg0 = args[0].(context.Context) + } + var arg1 uuid.UUID + if args[1] != nil { + arg1 = args[1].(uuid.UUID) + } + var arg2 uuid.UUID + if args[2] != nil { + arg2 = args[2].(uuid.UUID) + } + var arg3 string + if args[3] != nil { + arg3 = args[3].(string) + } + run( + arg0, + arg1, + arg2, + arg3, + ) + }) + return _c +} + +func (_c *MockAttachmentService_Complete_Call) Return(attachment domain.Attachment, err error) *MockAttachmentService_Complete_Call { + _c.Call.Return(attachment, err) + return _c +} + +func (_c *MockAttachmentService_Complete_Call) RunAndReturn(run func(ctx context.Context, ownerID uuid.UUID, id uuid.UUID, sha256 string) (domain.Attachment, error)) *MockAttachmentService_Complete_Call { + _c.Call.Return(run) + return _c +} + +// Get provides a mock function for the type MockAttachmentService +func (_mock *MockAttachmentService) Get(ctx context.Context, callerID uuid.UUID, id uuid.UUID) (domain.Attachment, error) { + ret := _mock.Called(ctx, callerID, id) + + if len(ret) == 0 { + panic("no return value specified for Get") + } + + var r0 domain.Attachment + var r1 error + if returnFunc, ok := ret.Get(0).(func(context.Context, uuid.UUID, uuid.UUID) (domain.Attachment, error)); ok { + return returnFunc(ctx, callerID, id) + } + if returnFunc, ok := ret.Get(0).(func(context.Context, uuid.UUID, uuid.UUID) domain.Attachment); ok { + r0 = returnFunc(ctx, callerID, id) + } else { + r0 = ret.Get(0).(domain.Attachment) + } + if returnFunc, ok := ret.Get(1).(func(context.Context, uuid.UUID, uuid.UUID) error); ok { + r1 = returnFunc(ctx, callerID, id) + } else { + r1 = ret.Error(1) + } + return r0, r1 +} + +// MockAttachmentService_Get_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Get' +type MockAttachmentService_Get_Call struct { + *mock.Call +} + +// Get is a helper method to define mock.On call +// - ctx context.Context +// - callerID uuid.UUID +// - id uuid.UUID +func (_e *MockAttachmentService_Expecter) Get(ctx any, callerID any, id any) *MockAttachmentService_Get_Call { + return &MockAttachmentService_Get_Call{Call: _e.mock.On("Get", ctx, callerID, id)} +} + +func (_c *MockAttachmentService_Get_Call) Run(run func(ctx context.Context, callerID uuid.UUID, id uuid.UUID)) *MockAttachmentService_Get_Call { + _c.Call.Run(func(args mock.Arguments) { + var arg0 context.Context + if args[0] != nil { + arg0 = args[0].(context.Context) + } + var arg1 uuid.UUID + if args[1] != nil { + arg1 = args[1].(uuid.UUID) + } + var arg2 uuid.UUID + if args[2] != nil { + arg2 = args[2].(uuid.UUID) + } + run( + arg0, + arg1, + arg2, + ) + }) + return _c +} + +func (_c *MockAttachmentService_Get_Call) Return(attachment domain.Attachment, err error) *MockAttachmentService_Get_Call { + _c.Call.Return(attachment, err) + return _c +} + +func (_c *MockAttachmentService_Get_Call) RunAndReturn(run func(ctx context.Context, callerID uuid.UUID, id uuid.UUID) (domain.Attachment, error)) *MockAttachmentService_Get_Call { + _c.Call.Return(run) + return _c +} + +// OpenVariant provides a mock function for the type MockAttachmentService +func (_mock *MockAttachmentService) OpenVariant(ctx context.Context, callerID uuid.UUID, id uuid.UUID, name domain.VariantName) (domain.Attachment, domain.Variant, io.ReadCloser, error) { + ret := _mock.Called(ctx, callerID, id, name) + + if len(ret) == 0 { + panic("no return value specified for OpenVariant") + } + + var r0 domain.Attachment + var r1 domain.Variant + var r2 io.ReadCloser + var r3 error + if returnFunc, ok := ret.Get(0).(func(context.Context, uuid.UUID, uuid.UUID, domain.VariantName) (domain.Attachment, domain.Variant, io.ReadCloser, error)); ok { + return returnFunc(ctx, callerID, id, name) + } + if returnFunc, ok := ret.Get(0).(func(context.Context, uuid.UUID, uuid.UUID, domain.VariantName) domain.Attachment); ok { + r0 = returnFunc(ctx, callerID, id, name) + } else { + r0 = ret.Get(0).(domain.Attachment) + } + if returnFunc, ok := ret.Get(1).(func(context.Context, uuid.UUID, uuid.UUID, domain.VariantName) domain.Variant); ok { + r1 = returnFunc(ctx, callerID, id, name) + } else { + r1 = ret.Get(1).(domain.Variant) + } + if returnFunc, ok := ret.Get(2).(func(context.Context, uuid.UUID, uuid.UUID, domain.VariantName) io.ReadCloser); ok { + r2 = returnFunc(ctx, callerID, id, name) + } else { + if ret.Get(2) != nil { + r2 = ret.Get(2).(io.ReadCloser) + } + } + if returnFunc, ok := ret.Get(3).(func(context.Context, uuid.UUID, uuid.UUID, domain.VariantName) error); ok { + r3 = returnFunc(ctx, callerID, id, name) + } else { + r3 = ret.Error(3) + } + return r0, r1, r2, r3 +} + +// MockAttachmentService_OpenVariant_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'OpenVariant' +type MockAttachmentService_OpenVariant_Call struct { + *mock.Call +} + +// OpenVariant is a helper method to define mock.On call +// - ctx context.Context +// - callerID uuid.UUID +// - id uuid.UUID +// - name domain.VariantName +func (_e *MockAttachmentService_Expecter) OpenVariant(ctx any, callerID any, id any, name any) *MockAttachmentService_OpenVariant_Call { + return &MockAttachmentService_OpenVariant_Call{Call: _e.mock.On("OpenVariant", ctx, callerID, id, name)} +} + +func (_c *MockAttachmentService_OpenVariant_Call) Run(run func(ctx context.Context, callerID uuid.UUID, id uuid.UUID, name domain.VariantName)) *MockAttachmentService_OpenVariant_Call { + _c.Call.Run(func(args mock.Arguments) { + var arg0 context.Context + if args[0] != nil { + arg0 = args[0].(context.Context) + } + var arg1 uuid.UUID + if args[1] != nil { + arg1 = args[1].(uuid.UUID) + } + var arg2 uuid.UUID + if args[2] != nil { + arg2 = args[2].(uuid.UUID) + } + var arg3 domain.VariantName + if args[3] != nil { + arg3 = args[3].(domain.VariantName) + } + run( + arg0, + arg1, + arg2, + arg3, + ) + }) + return _c +} + +func (_c *MockAttachmentService_OpenVariant_Call) Return(attachment domain.Attachment, variant domain.Variant, readCloser io.ReadCloser, err error) *MockAttachmentService_OpenVariant_Call { + _c.Call.Return(attachment, variant, readCloser, err) + return _c +} + +func (_c *MockAttachmentService_OpenVariant_Call) RunAndReturn(run func(ctx context.Context, callerID uuid.UUID, id uuid.UUID, name domain.VariantName) (domain.Attachment, domain.Variant, io.ReadCloser, error)) *MockAttachmentService_OpenVariant_Call { + _c.Call.Return(run) + return _c +} + +// Presign provides a mock function for the type MockAttachmentService +func (_mock *MockAttachmentService) Presign(ctx context.Context, request domain.PresignRequest) (domain.PresignResult, error) { + ret := _mock.Called(ctx, request) + + if len(ret) == 0 { + panic("no return value specified for Presign") + } + + var r0 domain.PresignResult + var r1 error + if returnFunc, ok := ret.Get(0).(func(context.Context, domain.PresignRequest) (domain.PresignResult, error)); ok { + return returnFunc(ctx, request) + } + if returnFunc, ok := ret.Get(0).(func(context.Context, domain.PresignRequest) domain.PresignResult); ok { + r0 = returnFunc(ctx, request) + } else { + r0 = ret.Get(0).(domain.PresignResult) + } + if returnFunc, ok := ret.Get(1).(func(context.Context, domain.PresignRequest) error); ok { + r1 = returnFunc(ctx, request) + } else { + r1 = ret.Error(1) + } + return r0, r1 +} + +// MockAttachmentService_Presign_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Presign' +type MockAttachmentService_Presign_Call struct { + *mock.Call +} + +// Presign is a helper method to define mock.On call +// - ctx context.Context +// - request domain.PresignRequest +func (_e *MockAttachmentService_Expecter) Presign(ctx any, request any) *MockAttachmentService_Presign_Call { + return &MockAttachmentService_Presign_Call{Call: _e.mock.On("Presign", ctx, request)} +} + +func (_c *MockAttachmentService_Presign_Call) Run(run func(ctx context.Context, request domain.PresignRequest)) *MockAttachmentService_Presign_Call { + _c.Call.Run(func(args mock.Arguments) { + var arg0 context.Context + if args[0] != nil { + arg0 = args[0].(context.Context) + } + var arg1 domain.PresignRequest + if args[1] != nil { + arg1 = args[1].(domain.PresignRequest) + } + run( + arg0, + arg1, + ) + }) + return _c +} + +func (_c *MockAttachmentService_Presign_Call) Return(presignResult domain.PresignResult, err error) *MockAttachmentService_Presign_Call { + _c.Call.Return(presignResult, err) + return _c +} + +func (_c *MockAttachmentService_Presign_Call) RunAndReturn(run func(ctx context.Context, request domain.PresignRequest) (domain.PresignResult, error)) *MockAttachmentService_Presign_Call { + _c.Call.Return(run) + return _c +} + +// Upload provides a mock function for the type MockAttachmentService +func (_mock *MockAttachmentService) Upload(ctx context.Context, input attachment.UploadInput) (domain.Attachment, error) { + ret := _mock.Called(ctx, input) + + if len(ret) == 0 { + panic("no return value specified for Upload") + } + + var r0 domain.Attachment + var r1 error + if returnFunc, ok := ret.Get(0).(func(context.Context, attachment.UploadInput) (domain.Attachment, error)); ok { + return returnFunc(ctx, input) + } + if returnFunc, ok := ret.Get(0).(func(context.Context, attachment.UploadInput) domain.Attachment); ok { + r0 = returnFunc(ctx, input) + } else { + r0 = ret.Get(0).(domain.Attachment) + } + if returnFunc, ok := ret.Get(1).(func(context.Context, attachment.UploadInput) error); ok { + r1 = returnFunc(ctx, input) + } else { + r1 = ret.Error(1) + } + return r0, r1 +} + +// MockAttachmentService_Upload_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Upload' +type MockAttachmentService_Upload_Call struct { + *mock.Call +} + +// Upload is a helper method to define mock.On call +// - ctx context.Context +// - input attachment.UploadInput +func (_e *MockAttachmentService_Expecter) Upload(ctx any, input any) *MockAttachmentService_Upload_Call { + return &MockAttachmentService_Upload_Call{Call: _e.mock.On("Upload", ctx, input)} +} + +func (_c *MockAttachmentService_Upload_Call) Run(run func(ctx context.Context, input attachment.UploadInput)) *MockAttachmentService_Upload_Call { + _c.Call.Run(func(args mock.Arguments) { + var arg0 context.Context + if args[0] != nil { + arg0 = args[0].(context.Context) + } + var arg1 attachment.UploadInput + if args[1] != nil { + arg1 = args[1].(attachment.UploadInput) + } + run( + arg0, + arg1, + ) + }) + return _c +} + +func (_c *MockAttachmentService_Upload_Call) Return(attachment1 domain.Attachment, err error) *MockAttachmentService_Upload_Call { + _c.Call.Return(attachment1, err) + return _c +} + +func (_c *MockAttachmentService_Upload_Call) RunAndReturn(run func(ctx context.Context, input attachment.UploadInput) (domain.Attachment, error)) *MockAttachmentService_Upload_Call { + _c.Call.Return(run) + return _c +} diff --git a/internal/transport/rest/mocks/ChatService.go b/internal/transport/rest/mocks/ChatService.go new file mode 100644 index 0000000..09671a5 --- /dev/null +++ b/internal/transport/rest/mocks/ChatService.go @@ -0,0 +1,265 @@ +// Code generated by mockery; DO NOT EDIT. +// github.com/vektra/mockery +// template: testify + +package mocks + +import ( + "context" + "mtusi-messenger/internal/domain" + + "github.com/google/uuid" + mock "github.com/stretchr/testify/mock" +) + +// NewMockChatService creates a new instance of MockChatService. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewMockChatService(t interface { + mock.TestingT + Cleanup(func()) +}) *MockChatService { + if helper, ok := t.(interface{ Helper() }); ok { + helper.Helper() + } + + mock := &MockChatService{} + mock.Mock.Test(t) + + t.Cleanup(func() { + if helper, ok := t.(interface{ Helper() }); ok { + helper.Helper() + } + mock.AssertExpectations(t) + }) + + return mock +} + +// MockChatService is an autogenerated mock type for the ChatService type +type MockChatService struct { + mock.Mock +} + +type MockChatService_Expecter struct { + mock *mock.Mock +} + +func (_m *MockChatService) EXPECT() *MockChatService_Expecter { + return &MockChatService_Expecter{mock: &_m.Mock} +} + +// Create provides a mock function for the type MockChatService +func (_mock *MockChatService) Create(ctx context.Context, draft domain.ChatDraft) (domain.Chat, error) { + ret := _mock.Called(ctx, draft) + + if len(ret) == 0 { + panic("no return value specified for Create") + } + + var r0 domain.Chat + var r1 error + if returnFunc, ok := ret.Get(0).(func(context.Context, domain.ChatDraft) (domain.Chat, error)); ok { + return returnFunc(ctx, draft) + } + if returnFunc, ok := ret.Get(0).(func(context.Context, domain.ChatDraft) domain.Chat); ok { + r0 = returnFunc(ctx, draft) + } else { + r0 = ret.Get(0).(domain.Chat) + } + if returnFunc, ok := ret.Get(1).(func(context.Context, domain.ChatDraft) error); ok { + r1 = returnFunc(ctx, draft) + } else { + r1 = ret.Error(1) + } + return r0, r1 +} + +// MockChatService_Create_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Create' +type MockChatService_Create_Call struct { + *mock.Call +} + +// Create is a helper method to define mock.On call +// - ctx context.Context +// - draft domain.ChatDraft +func (_e *MockChatService_Expecter) Create(ctx any, draft any) *MockChatService_Create_Call { + return &MockChatService_Create_Call{Call: _e.mock.On("Create", ctx, draft)} +} + +func (_c *MockChatService_Create_Call) Run(run func(ctx context.Context, draft domain.ChatDraft)) *MockChatService_Create_Call { + _c.Call.Run(func(args mock.Arguments) { + var arg0 context.Context + if args[0] != nil { + arg0 = args[0].(context.Context) + } + var arg1 domain.ChatDraft + if args[1] != nil { + arg1 = args[1].(domain.ChatDraft) + } + run( + arg0, + arg1, + ) + }) + return _c +} + +func (_c *MockChatService_Create_Call) Return(chat domain.Chat, err error) *MockChatService_Create_Call { + _c.Call.Return(chat, err) + return _c +} + +func (_c *MockChatService_Create_Call) RunAndReturn(run func(ctx context.Context, draft domain.ChatDraft) (domain.Chat, error)) *MockChatService_Create_Call { + _c.Call.Return(run) + return _c +} + +// Get provides a mock function for the type MockChatService +func (_mock *MockChatService) Get(ctx context.Context, callerID uuid.UUID, chatID uuid.UUID) (domain.Chat, error) { + ret := _mock.Called(ctx, callerID, chatID) + + if len(ret) == 0 { + panic("no return value specified for Get") + } + + var r0 domain.Chat + var r1 error + if returnFunc, ok := ret.Get(0).(func(context.Context, uuid.UUID, uuid.UUID) (domain.Chat, error)); ok { + return returnFunc(ctx, callerID, chatID) + } + if returnFunc, ok := ret.Get(0).(func(context.Context, uuid.UUID, uuid.UUID) domain.Chat); ok { + r0 = returnFunc(ctx, callerID, chatID) + } else { + r0 = ret.Get(0).(domain.Chat) + } + if returnFunc, ok := ret.Get(1).(func(context.Context, uuid.UUID, uuid.UUID) error); ok { + r1 = returnFunc(ctx, callerID, chatID) + } else { + r1 = ret.Error(1) + } + return r0, r1 +} + +// MockChatService_Get_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Get' +type MockChatService_Get_Call struct { + *mock.Call +} + +// Get is a helper method to define mock.On call +// - ctx context.Context +// - callerID uuid.UUID +// - chatID uuid.UUID +func (_e *MockChatService_Expecter) Get(ctx any, callerID any, chatID any) *MockChatService_Get_Call { + return &MockChatService_Get_Call{Call: _e.mock.On("Get", ctx, callerID, chatID)} +} + +func (_c *MockChatService_Get_Call) Run(run func(ctx context.Context, callerID uuid.UUID, chatID uuid.UUID)) *MockChatService_Get_Call { + _c.Call.Run(func(args mock.Arguments) { + var arg0 context.Context + if args[0] != nil { + arg0 = args[0].(context.Context) + } + var arg1 uuid.UUID + if args[1] != nil { + arg1 = args[1].(uuid.UUID) + } + var arg2 uuid.UUID + if args[2] != nil { + arg2 = args[2].(uuid.UUID) + } + run( + arg0, + arg1, + arg2, + ) + }) + return _c +} + +func (_c *MockChatService_Get_Call) Return(chat domain.Chat, err error) *MockChatService_Get_Call { + _c.Call.Return(chat, err) + return _c +} + +func (_c *MockChatService_Get_Call) RunAndReturn(run func(ctx context.Context, callerID uuid.UUID, chatID uuid.UUID) (domain.Chat, error)) *MockChatService_Get_Call { + _c.Call.Return(run) + return _c +} + +// List provides a mock function for the type MockChatService +func (_mock *MockChatService) List(ctx context.Context, callerID uuid.UUID, after *domain.Cursor, limit int) (domain.Page[domain.Chat], error) { + ret := _mock.Called(ctx, callerID, after, limit) + + if len(ret) == 0 { + panic("no return value specified for List") + } + + var r0 domain.Page[domain.Chat] + var r1 error + if returnFunc, ok := ret.Get(0).(func(context.Context, uuid.UUID, *domain.Cursor, int) (domain.Page[domain.Chat], error)); ok { + return returnFunc(ctx, callerID, after, limit) + } + if returnFunc, ok := ret.Get(0).(func(context.Context, uuid.UUID, *domain.Cursor, int) domain.Page[domain.Chat]); ok { + r0 = returnFunc(ctx, callerID, after, limit) + } else { + r0 = ret.Get(0).(domain.Page[domain.Chat]) + } + if returnFunc, ok := ret.Get(1).(func(context.Context, uuid.UUID, *domain.Cursor, int) error); ok { + r1 = returnFunc(ctx, callerID, after, limit) + } else { + r1 = ret.Error(1) + } + return r0, r1 +} + +// MockChatService_List_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'List' +type MockChatService_List_Call struct { + *mock.Call +} + +// List is a helper method to define mock.On call +// - ctx context.Context +// - callerID uuid.UUID +// - after *domain.Cursor +// - limit int +func (_e *MockChatService_Expecter) List(ctx any, callerID any, after any, limit any) *MockChatService_List_Call { + return &MockChatService_List_Call{Call: _e.mock.On("List", ctx, callerID, after, limit)} +} + +func (_c *MockChatService_List_Call) Run(run func(ctx context.Context, callerID uuid.UUID, after *domain.Cursor, limit int)) *MockChatService_List_Call { + _c.Call.Run(func(args mock.Arguments) { + var arg0 context.Context + if args[0] != nil { + arg0 = args[0].(context.Context) + } + var arg1 uuid.UUID + if args[1] != nil { + arg1 = args[1].(uuid.UUID) + } + var arg2 *domain.Cursor + if args[2] != nil { + arg2 = args[2].(*domain.Cursor) + } + var arg3 int + if args[3] != nil { + arg3 = args[3].(int) + } + run( + arg0, + arg1, + arg2, + arg3, + ) + }) + return _c +} + +func (_c *MockChatService_List_Call) Return(page domain.Page[domain.Chat], err error) *MockChatService_List_Call { + _c.Call.Return(page, err) + return _c +} + +func (_c *MockChatService_List_Call) RunAndReturn(run func(ctx context.Context, callerID uuid.UUID, after *domain.Cursor, limit int) (domain.Page[domain.Chat], error)) *MockChatService_List_Call { + _c.Call.Return(run) + return _c +} diff --git a/internal/transport/rest/mocks/HealthChecker.go b/internal/transport/rest/mocks/HealthChecker.go new file mode 100644 index 0000000..a68e0f8 --- /dev/null +++ b/internal/transport/rest/mocks/HealthChecker.go @@ -0,0 +1,98 @@ +// Code generated by mockery; DO NOT EDIT. +// github.com/vektra/mockery +// template: testify + +package mocks + +import ( + "context" + + mock "github.com/stretchr/testify/mock" +) + +// NewMockHealthChecker creates a new instance of MockHealthChecker. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewMockHealthChecker(t interface { + mock.TestingT + Cleanup(func()) +}) *MockHealthChecker { + if helper, ok := t.(interface{ Helper() }); ok { + helper.Helper() + } + + mock := &MockHealthChecker{} + mock.Mock.Test(t) + + t.Cleanup(func() { + if helper, ok := t.(interface{ Helper() }); ok { + helper.Helper() + } + mock.AssertExpectations(t) + }) + + return mock +} + +// MockHealthChecker is an autogenerated mock type for the HealthChecker type +type MockHealthChecker struct { + mock.Mock +} + +type MockHealthChecker_Expecter struct { + mock *mock.Mock +} + +func (_m *MockHealthChecker) EXPECT() *MockHealthChecker_Expecter { + return &MockHealthChecker_Expecter{mock: &_m.Mock} +} + +// Ping provides a mock function for the type MockHealthChecker +func (_mock *MockHealthChecker) Ping(ctx context.Context) error { + ret := _mock.Called(ctx) + + if len(ret) == 0 { + panic("no return value specified for Ping") + } + + var r0 error + if returnFunc, ok := ret.Get(0).(func(context.Context) error); ok { + r0 = returnFunc(ctx) + } else { + r0 = ret.Error(0) + } + return r0 +} + +// MockHealthChecker_Ping_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Ping' +type MockHealthChecker_Ping_Call struct { + *mock.Call +} + +// Ping is a helper method to define mock.On call +// - ctx context.Context +func (_e *MockHealthChecker_Expecter) Ping(ctx any) *MockHealthChecker_Ping_Call { + return &MockHealthChecker_Ping_Call{Call: _e.mock.On("Ping", ctx)} +} + +func (_c *MockHealthChecker_Ping_Call) Run(run func(ctx context.Context)) *MockHealthChecker_Ping_Call { + _c.Call.Run(func(args mock.Arguments) { + var arg0 context.Context + if args[0] != nil { + arg0 = args[0].(context.Context) + } + run( + arg0, + ) + }) + return _c +} + +func (_c *MockHealthChecker_Ping_Call) Return(err error) *MockHealthChecker_Ping_Call { + _c.Call.Return(err) + return _c +} + +func (_c *MockHealthChecker_Ping_Call) RunAndReturn(run func(ctx context.Context) error) *MockHealthChecker_Ping_Call { + _c.Call.Return(run) + return _c +} diff --git a/internal/transport/rest/mocks/MessageService.go b/internal/transport/rest/mocks/MessageService.go new file mode 100644 index 0000000..83fe84a --- /dev/null +++ b/internal/transport/rest/mocks/MessageService.go @@ -0,0 +1,199 @@ +// Code generated by mockery; DO NOT EDIT. +// github.com/vektra/mockery +// template: testify + +package mocks + +import ( + "context" + "mtusi-messenger/internal/domain" + + "github.com/google/uuid" + mock "github.com/stretchr/testify/mock" +) + +// NewMockMessageService creates a new instance of MockMessageService. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewMockMessageService(t interface { + mock.TestingT + Cleanup(func()) +}) *MockMessageService { + if helper, ok := t.(interface{ Helper() }); ok { + helper.Helper() + } + + mock := &MockMessageService{} + mock.Mock.Test(t) + + t.Cleanup(func() { + if helper, ok := t.(interface{ Helper() }); ok { + helper.Helper() + } + mock.AssertExpectations(t) + }) + + return mock +} + +// MockMessageService is an autogenerated mock type for the MessageService type +type MockMessageService struct { + mock.Mock +} + +type MockMessageService_Expecter struct { + mock *mock.Mock +} + +func (_m *MockMessageService) EXPECT() *MockMessageService_Expecter { + return &MockMessageService_Expecter{mock: &_m.Mock} +} + +// History provides a mock function for the type MockMessageService +func (_mock *MockMessageService) History(ctx context.Context, callerID uuid.UUID, chatID uuid.UUID, after *domain.Cursor, limit int) (domain.Page[domain.Message], error) { + ret := _mock.Called(ctx, callerID, chatID, after, limit) + + if len(ret) == 0 { + panic("no return value specified for History") + } + + var r0 domain.Page[domain.Message] + var r1 error + if returnFunc, ok := ret.Get(0).(func(context.Context, uuid.UUID, uuid.UUID, *domain.Cursor, int) (domain.Page[domain.Message], error)); ok { + return returnFunc(ctx, callerID, chatID, after, limit) + } + if returnFunc, ok := ret.Get(0).(func(context.Context, uuid.UUID, uuid.UUID, *domain.Cursor, int) domain.Page[domain.Message]); ok { + r0 = returnFunc(ctx, callerID, chatID, after, limit) + } else { + r0 = ret.Get(0).(domain.Page[domain.Message]) + } + if returnFunc, ok := ret.Get(1).(func(context.Context, uuid.UUID, uuid.UUID, *domain.Cursor, int) error); ok { + r1 = returnFunc(ctx, callerID, chatID, after, limit) + } else { + r1 = ret.Error(1) + } + return r0, r1 +} + +// MockMessageService_History_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'History' +type MockMessageService_History_Call struct { + *mock.Call +} + +// History is a helper method to define mock.On call +// - ctx context.Context +// - callerID uuid.UUID +// - chatID uuid.UUID +// - after *domain.Cursor +// - limit int +func (_e *MockMessageService_Expecter) History(ctx any, callerID any, chatID any, after any, limit any) *MockMessageService_History_Call { + return &MockMessageService_History_Call{Call: _e.mock.On("History", ctx, callerID, chatID, after, limit)} +} + +func (_c *MockMessageService_History_Call) Run(run func(ctx context.Context, callerID uuid.UUID, chatID uuid.UUID, after *domain.Cursor, limit int)) *MockMessageService_History_Call { + _c.Call.Run(func(args mock.Arguments) { + var arg0 context.Context + if args[0] != nil { + arg0 = args[0].(context.Context) + } + var arg1 uuid.UUID + if args[1] != nil { + arg1 = args[1].(uuid.UUID) + } + var arg2 uuid.UUID + if args[2] != nil { + arg2 = args[2].(uuid.UUID) + } + var arg3 *domain.Cursor + if args[3] != nil { + arg3 = args[3].(*domain.Cursor) + } + var arg4 int + if args[4] != nil { + arg4 = args[4].(int) + } + run( + arg0, + arg1, + arg2, + arg3, + arg4, + ) + }) + return _c +} + +func (_c *MockMessageService_History_Call) Return(page domain.Page[domain.Message], err error) *MockMessageService_History_Call { + _c.Call.Return(page, err) + return _c +} + +func (_c *MockMessageService_History_Call) RunAndReturn(run func(ctx context.Context, callerID uuid.UUID, chatID uuid.UUID, after *domain.Cursor, limit int) (domain.Page[domain.Message], error)) *MockMessageService_History_Call { + _c.Call.Return(run) + return _c +} + +// Send provides a mock function for the type MockMessageService +func (_mock *MockMessageService) Send(ctx context.Context, draft domain.MessageDraft) (domain.Message, error) { + ret := _mock.Called(ctx, draft) + + if len(ret) == 0 { + panic("no return value specified for Send") + } + + var r0 domain.Message + var r1 error + if returnFunc, ok := ret.Get(0).(func(context.Context, domain.MessageDraft) (domain.Message, error)); ok { + return returnFunc(ctx, draft) + } + if returnFunc, ok := ret.Get(0).(func(context.Context, domain.MessageDraft) domain.Message); ok { + r0 = returnFunc(ctx, draft) + } else { + r0 = ret.Get(0).(domain.Message) + } + if returnFunc, ok := ret.Get(1).(func(context.Context, domain.MessageDraft) error); ok { + r1 = returnFunc(ctx, draft) + } else { + r1 = ret.Error(1) + } + return r0, r1 +} + +// MockMessageService_Send_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Send' +type MockMessageService_Send_Call struct { + *mock.Call +} + +// Send is a helper method to define mock.On call +// - ctx context.Context +// - draft domain.MessageDraft +func (_e *MockMessageService_Expecter) Send(ctx any, draft any) *MockMessageService_Send_Call { + return &MockMessageService_Send_Call{Call: _e.mock.On("Send", ctx, draft)} +} + +func (_c *MockMessageService_Send_Call) Run(run func(ctx context.Context, draft domain.MessageDraft)) *MockMessageService_Send_Call { + _c.Call.Run(func(args mock.Arguments) { + var arg0 context.Context + if args[0] != nil { + arg0 = args[0].(context.Context) + } + var arg1 domain.MessageDraft + if args[1] != nil { + arg1 = args[1].(domain.MessageDraft) + } + run( + arg0, + arg1, + ) + }) + return _c +} + +func (_c *MockMessageService_Send_Call) Return(message domain.Message, err error) *MockMessageService_Send_Call { + _c.Call.Return(message, err) + return _c +} + +func (_c *MockMessageService_Send_Call) RunAndReturn(run func(ctx context.Context, draft domain.MessageDraft) (domain.Message, error)) *MockMessageService_Send_Call { + _c.Call.Return(run) + return _c +} diff --git a/internal/transport/rest/mocks/SecSessionService.go b/internal/transport/rest/mocks/SecSessionService.go new file mode 100644 index 0000000..ad32249 --- /dev/null +++ b/internal/transport/rest/mocks/SecSessionService.go @@ -0,0 +1,186 @@ +// Code generated by mockery; DO NOT EDIT. +// github.com/vektra/mockery +// template: testify + +package mocks + +import ( + "context" + "mtusi-messenger/internal/domain" + + mock "github.com/stretchr/testify/mock" +) + +// NewMockSecSessionService creates a new instance of MockSecSessionService. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewMockSecSessionService(t interface { + mock.TestingT + Cleanup(func()) +}) *MockSecSessionService { + if helper, ok := t.(interface{ Helper() }); ok { + helper.Helper() + } + + mock := &MockSecSessionService{} + mock.Mock.Test(t) + + t.Cleanup(func() { + if helper, ok := t.(interface{ Helper() }); ok { + helper.Helper() + } + mock.AssertExpectations(t) + }) + + return mock +} + +// MockSecSessionService is an autogenerated mock type for the SecSessionService type +type MockSecSessionService struct { + mock.Mock +} + +type MockSecSessionService_Expecter struct { + mock *mock.Mock +} + +func (_m *MockSecSessionService) EXPECT() *MockSecSessionService_Expecter { + return &MockSecSessionService_Expecter{mock: &_m.Mock} +} + +// Authenticate provides a mock function for the type MockSecSessionService +func (_mock *MockSecSessionService) Authenticate(ctx context.Context, username string, password string) (domain.User, error) { + ret := _mock.Called(ctx, username, password) + + if len(ret) == 0 { + panic("no return value specified for Authenticate") + } + + var r0 domain.User + var r1 error + if returnFunc, ok := ret.Get(0).(func(context.Context, string, string) (domain.User, error)); ok { + return returnFunc(ctx, username, password) + } + if returnFunc, ok := ret.Get(0).(func(context.Context, string, string) domain.User); ok { + r0 = returnFunc(ctx, username, password) + } else { + r0 = ret.Get(0).(domain.User) + } + if returnFunc, ok := ret.Get(1).(func(context.Context, string, string) error); ok { + r1 = returnFunc(ctx, username, password) + } else { + r1 = ret.Error(1) + } + return r0, r1 +} + +// MockSecSessionService_Authenticate_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Authenticate' +type MockSecSessionService_Authenticate_Call struct { + *mock.Call +} + +// Authenticate is a helper method to define mock.On call +// - ctx context.Context +// - username string +// - password string +func (_e *MockSecSessionService_Expecter) Authenticate(ctx any, username any, password any) *MockSecSessionService_Authenticate_Call { + return &MockSecSessionService_Authenticate_Call{Call: _e.mock.On("Authenticate", ctx, username, password)} +} + +func (_c *MockSecSessionService_Authenticate_Call) Run(run func(ctx context.Context, username string, password string)) *MockSecSessionService_Authenticate_Call { + _c.Call.Run(func(args mock.Arguments) { + var arg0 context.Context + if args[0] != nil { + arg0 = args[0].(context.Context) + } + var arg1 string + if args[1] != nil { + arg1 = args[1].(string) + } + var arg2 string + if args[2] != nil { + arg2 = args[2].(string) + } + run( + arg0, + arg1, + arg2, + ) + }) + return _c +} + +func (_c *MockSecSessionService_Authenticate_Call) Return(user domain.User, err error) *MockSecSessionService_Authenticate_Call { + _c.Call.Return(user, err) + return _c +} + +func (_c *MockSecSessionService_Authenticate_Call) RunAndReturn(run func(ctx context.Context, username string, password string) (domain.User, error)) *MockSecSessionService_Authenticate_Call { + _c.Call.Return(run) + return _c +} + +// Resolve provides a mock function for the type MockSecSessionService +func (_mock *MockSecSessionService) Resolve(ctx context.Context, token string) (domain.User, error) { + ret := _mock.Called(ctx, token) + + if len(ret) == 0 { + panic("no return value specified for Resolve") + } + + var r0 domain.User + var r1 error + if returnFunc, ok := ret.Get(0).(func(context.Context, string) (domain.User, error)); ok { + return returnFunc(ctx, token) + } + if returnFunc, ok := ret.Get(0).(func(context.Context, string) domain.User); ok { + r0 = returnFunc(ctx, token) + } else { + r0 = ret.Get(0).(domain.User) + } + if returnFunc, ok := ret.Get(1).(func(context.Context, string) error); ok { + r1 = returnFunc(ctx, token) + } else { + r1 = ret.Error(1) + } + return r0, r1 +} + +// MockSecSessionService_Resolve_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Resolve' +type MockSecSessionService_Resolve_Call struct { + *mock.Call +} + +// Resolve is a helper method to define mock.On call +// - ctx context.Context +// - token string +func (_e *MockSecSessionService_Expecter) Resolve(ctx any, token any) *MockSecSessionService_Resolve_Call { + return &MockSecSessionService_Resolve_Call{Call: _e.mock.On("Resolve", ctx, token)} +} + +func (_c *MockSecSessionService_Resolve_Call) Run(run func(ctx context.Context, token string)) *MockSecSessionService_Resolve_Call { + _c.Call.Run(func(args mock.Arguments) { + var arg0 context.Context + if args[0] != nil { + arg0 = args[0].(context.Context) + } + var arg1 string + if args[1] != nil { + arg1 = args[1].(string) + } + run( + arg0, + arg1, + ) + }) + return _c +} + +func (_c *MockSecSessionService_Resolve_Call) Return(user domain.User, err error) *MockSecSessionService_Resolve_Call { + _c.Call.Return(user, err) + return _c +} + +func (_c *MockSecSessionService_Resolve_Call) RunAndReturn(run func(ctx context.Context, token string) (domain.User, error)) *MockSecSessionService_Resolve_Call { + _c.Call.Return(run) + return _c +} diff --git a/internal/transport/rest/mocks/SessionActions.go b/internal/transport/rest/mocks/SessionActions.go new file mode 100644 index 0000000..5457120 --- /dev/null +++ b/internal/transport/rest/mocks/SessionActions.go @@ -0,0 +1,316 @@ +// Code generated by mockery; DO NOT EDIT. +// github.com/vektra/mockery +// template: testify + +package mocks + +import ( + "context" + "mtusi-messenger/internal/domain" + + "github.com/google/uuid" + mock "github.com/stretchr/testify/mock" +) + +// NewMockSessionActions creates a new instance of MockSessionActions. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewMockSessionActions(t interface { + mock.TestingT + Cleanup(func()) +}) *MockSessionActions { + if helper, ok := t.(interface{ Helper() }); ok { + helper.Helper() + } + + mock := &MockSessionActions{} + mock.Mock.Test(t) + + t.Cleanup(func() { + if helper, ok := t.(interface{ Helper() }); ok { + helper.Helper() + } + mock.AssertExpectations(t) + }) + + return mock +} + +// MockSessionActions is an autogenerated mock type for the SessionActions type +type MockSessionActions struct { + mock.Mock +} + +type MockSessionActions_Expecter struct { + mock *mock.Mock +} + +func (_m *MockSessionActions) EXPECT() *MockSessionActions_Expecter { + return &MockSessionActions_Expecter{mock: &_m.Mock} +} + +// Authenticate provides a mock function for the type MockSessionActions +func (_mock *MockSessionActions) Authenticate(ctx context.Context, username string, password string) (domain.User, error) { + ret := _mock.Called(ctx, username, password) + + if len(ret) == 0 { + panic("no return value specified for Authenticate") + } + + var r0 domain.User + var r1 error + if returnFunc, ok := ret.Get(0).(func(context.Context, string, string) (domain.User, error)); ok { + return returnFunc(ctx, username, password) + } + if returnFunc, ok := ret.Get(0).(func(context.Context, string, string) domain.User); ok { + r0 = returnFunc(ctx, username, password) + } else { + r0 = ret.Get(0).(domain.User) + } + if returnFunc, ok := ret.Get(1).(func(context.Context, string, string) error); ok { + r1 = returnFunc(ctx, username, password) + } else { + r1 = ret.Error(1) + } + return r0, r1 +} + +// MockSessionActions_Authenticate_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Authenticate' +type MockSessionActions_Authenticate_Call struct { + *mock.Call +} + +// Authenticate is a helper method to define mock.On call +// - ctx context.Context +// - username string +// - password string +func (_e *MockSessionActions_Expecter) Authenticate(ctx any, username any, password any) *MockSessionActions_Authenticate_Call { + return &MockSessionActions_Authenticate_Call{Call: _e.mock.On("Authenticate", ctx, username, password)} +} + +func (_c *MockSessionActions_Authenticate_Call) Run(run func(ctx context.Context, username string, password string)) *MockSessionActions_Authenticate_Call { + _c.Call.Run(func(args mock.Arguments) { + var arg0 context.Context + if args[0] != nil { + arg0 = args[0].(context.Context) + } + var arg1 string + if args[1] != nil { + arg1 = args[1].(string) + } + var arg2 string + if args[2] != nil { + arg2 = args[2].(string) + } + run( + arg0, + arg1, + arg2, + ) + }) + return _c +} + +func (_c *MockSessionActions_Authenticate_Call) Return(user domain.User, err error) *MockSessionActions_Authenticate_Call { + _c.Call.Return(user, err) + return _c +} + +func (_c *MockSessionActions_Authenticate_Call) RunAndReturn(run func(ctx context.Context, username string, password string) (domain.User, error)) *MockSessionActions_Authenticate_Call { + _c.Call.Return(run) + return _c +} + +// Create provides a mock function for the type MockSessionActions +func (_mock *MockSessionActions) Create(ctx context.Context, user domain.User) (domain.Session, error) { + ret := _mock.Called(ctx, user) + + if len(ret) == 0 { + panic("no return value specified for Create") + } + + var r0 domain.Session + var r1 error + if returnFunc, ok := ret.Get(0).(func(context.Context, domain.User) (domain.Session, error)); ok { + return returnFunc(ctx, user) + } + if returnFunc, ok := ret.Get(0).(func(context.Context, domain.User) domain.Session); ok { + r0 = returnFunc(ctx, user) + } else { + r0 = ret.Get(0).(domain.Session) + } + if returnFunc, ok := ret.Get(1).(func(context.Context, domain.User) error); ok { + r1 = returnFunc(ctx, user) + } else { + r1 = ret.Error(1) + } + return r0, r1 +} + +// MockSessionActions_Create_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Create' +type MockSessionActions_Create_Call struct { + *mock.Call +} + +// Create is a helper method to define mock.On call +// - ctx context.Context +// - user domain.User +func (_e *MockSessionActions_Expecter) Create(ctx any, user any) *MockSessionActions_Create_Call { + return &MockSessionActions_Create_Call{Call: _e.mock.On("Create", ctx, user)} +} + +func (_c *MockSessionActions_Create_Call) Run(run func(ctx context.Context, user domain.User)) *MockSessionActions_Create_Call { + _c.Call.Run(func(args mock.Arguments) { + var arg0 context.Context + if args[0] != nil { + arg0 = args[0].(context.Context) + } + var arg1 domain.User + if args[1] != nil { + arg1 = args[1].(domain.User) + } + run( + arg0, + arg1, + ) + }) + return _c +} + +func (_c *MockSessionActions_Create_Call) Return(session domain.Session, err error) *MockSessionActions_Create_Call { + _c.Call.Return(session, err) + return _c +} + +func (_c *MockSessionActions_Create_Call) RunAndReturn(run func(ctx context.Context, user domain.User) (domain.Session, error)) *MockSessionActions_Create_Call { + _c.Call.Return(run) + return _c +} + +// Resolve provides a mock function for the type MockSessionActions +func (_mock *MockSessionActions) Resolve(ctx context.Context, token string) (domain.User, error) { + ret := _mock.Called(ctx, token) + + if len(ret) == 0 { + panic("no return value specified for Resolve") + } + + var r0 domain.User + var r1 error + if returnFunc, ok := ret.Get(0).(func(context.Context, string) (domain.User, error)); ok { + return returnFunc(ctx, token) + } + if returnFunc, ok := ret.Get(0).(func(context.Context, string) domain.User); ok { + r0 = returnFunc(ctx, token) + } else { + r0 = ret.Get(0).(domain.User) + } + if returnFunc, ok := ret.Get(1).(func(context.Context, string) error); ok { + r1 = returnFunc(ctx, token) + } else { + r1 = ret.Error(1) + } + return r0, r1 +} + +// MockSessionActions_Resolve_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Resolve' +type MockSessionActions_Resolve_Call struct { + *mock.Call +} + +// Resolve is a helper method to define mock.On call +// - ctx context.Context +// - token string +func (_e *MockSessionActions_Expecter) Resolve(ctx any, token any) *MockSessionActions_Resolve_Call { + return &MockSessionActions_Resolve_Call{Call: _e.mock.On("Resolve", ctx, token)} +} + +func (_c *MockSessionActions_Resolve_Call) Run(run func(ctx context.Context, token string)) *MockSessionActions_Resolve_Call { + _c.Call.Run(func(args mock.Arguments) { + var arg0 context.Context + if args[0] != nil { + arg0 = args[0].(context.Context) + } + var arg1 string + if args[1] != nil { + arg1 = args[1].(string) + } + run( + arg0, + arg1, + ) + }) + return _c +} + +func (_c *MockSessionActions_Resolve_Call) Return(user domain.User, err error) *MockSessionActions_Resolve_Call { + _c.Call.Return(user, err) + return _c +} + +func (_c *MockSessionActions_Resolve_Call) RunAndReturn(run func(ctx context.Context, token string) (domain.User, error)) *MockSessionActions_Resolve_Call { + _c.Call.Return(run) + return _c +} + +// Revoke provides a mock function for the type MockSessionActions +func (_mock *MockSessionActions) Revoke(ctx context.Context, userID uuid.UUID, token string) error { + ret := _mock.Called(ctx, userID, token) + + if len(ret) == 0 { + panic("no return value specified for Revoke") + } + + var r0 error + if returnFunc, ok := ret.Get(0).(func(context.Context, uuid.UUID, string) error); ok { + r0 = returnFunc(ctx, userID, token) + } else { + r0 = ret.Error(0) + } + return r0 +} + +// MockSessionActions_Revoke_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Revoke' +type MockSessionActions_Revoke_Call struct { + *mock.Call +} + +// Revoke is a helper method to define mock.On call +// - ctx context.Context +// - userID uuid.UUID +// - token string +func (_e *MockSessionActions_Expecter) Revoke(ctx any, userID any, token any) *MockSessionActions_Revoke_Call { + return &MockSessionActions_Revoke_Call{Call: _e.mock.On("Revoke", ctx, userID, token)} +} + +func (_c *MockSessionActions_Revoke_Call) Run(run func(ctx context.Context, userID uuid.UUID, token string)) *MockSessionActions_Revoke_Call { + _c.Call.Run(func(args mock.Arguments) { + var arg0 context.Context + if args[0] != nil { + arg0 = args[0].(context.Context) + } + var arg1 uuid.UUID + if args[1] != nil { + arg1 = args[1].(uuid.UUID) + } + var arg2 string + if args[2] != nil { + arg2 = args[2].(string) + } + run( + arg0, + arg1, + arg2, + ) + }) + return _c +} + +func (_c *MockSessionActions_Revoke_Call) Return(err error) *MockSessionActions_Revoke_Call { + _c.Call.Return(err) + return _c +} + +func (_c *MockSessionActions_Revoke_Call) RunAndReturn(run func(ctx context.Context, userID uuid.UUID, token string) error) *MockSessionActions_Revoke_Call { + _c.Call.Return(run) + return _c +} diff --git a/internal/transport/rest/mocks/SessionResolver.go b/internal/transport/rest/mocks/SessionResolver.go new file mode 100644 index 0000000..9779630 --- /dev/null +++ b/internal/transport/rest/mocks/SessionResolver.go @@ -0,0 +1,114 @@ +// Code generated by mockery; DO NOT EDIT. +// github.com/vektra/mockery +// template: testify + +package mocks + +import ( + "context" + "mtusi-messenger/internal/domain" + + mock "github.com/stretchr/testify/mock" +) + +// NewMockSessionResolver creates a new instance of MockSessionResolver. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewMockSessionResolver(t interface { + mock.TestingT + Cleanup(func()) +}) *MockSessionResolver { + if helper, ok := t.(interface{ Helper() }); ok { + helper.Helper() + } + + mock := &MockSessionResolver{} + mock.Mock.Test(t) + + t.Cleanup(func() { + if helper, ok := t.(interface{ Helper() }); ok { + helper.Helper() + } + mock.AssertExpectations(t) + }) + + return mock +} + +// MockSessionResolver is an autogenerated mock type for the SessionResolver type +type MockSessionResolver struct { + mock.Mock +} + +type MockSessionResolver_Expecter struct { + mock *mock.Mock +} + +func (_m *MockSessionResolver) EXPECT() *MockSessionResolver_Expecter { + return &MockSessionResolver_Expecter{mock: &_m.Mock} +} + +// Resolve provides a mock function for the type MockSessionResolver +func (_mock *MockSessionResolver) Resolve(ctx context.Context, token string) (domain.User, error) { + ret := _mock.Called(ctx, token) + + if len(ret) == 0 { + panic("no return value specified for Resolve") + } + + var r0 domain.User + var r1 error + if returnFunc, ok := ret.Get(0).(func(context.Context, string) (domain.User, error)); ok { + return returnFunc(ctx, token) + } + if returnFunc, ok := ret.Get(0).(func(context.Context, string) domain.User); ok { + r0 = returnFunc(ctx, token) + } else { + r0 = ret.Get(0).(domain.User) + } + if returnFunc, ok := ret.Get(1).(func(context.Context, string) error); ok { + r1 = returnFunc(ctx, token) + } else { + r1 = ret.Error(1) + } + return r0, r1 +} + +// MockSessionResolver_Resolve_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Resolve' +type MockSessionResolver_Resolve_Call struct { + *mock.Call +} + +// Resolve is a helper method to define mock.On call +// - ctx context.Context +// - token string +func (_e *MockSessionResolver_Expecter) Resolve(ctx any, token any) *MockSessionResolver_Resolve_Call { + return &MockSessionResolver_Resolve_Call{Call: _e.mock.On("Resolve", ctx, token)} +} + +func (_c *MockSessionResolver_Resolve_Call) Run(run func(ctx context.Context, token string)) *MockSessionResolver_Resolve_Call { + _c.Call.Run(func(args mock.Arguments) { + var arg0 context.Context + if args[0] != nil { + arg0 = args[0].(context.Context) + } + var arg1 string + if args[1] != nil { + arg1 = args[1].(string) + } + run( + arg0, + arg1, + ) + }) + return _c +} + +func (_c *MockSessionResolver_Resolve_Call) Return(user domain.User, err error) *MockSessionResolver_Resolve_Call { + _c.Call.Return(user, err) + return _c +} + +func (_c *MockSessionResolver_Resolve_Call) RunAndReturn(run func(ctx context.Context, token string) (domain.User, error)) *MockSessionResolver_Resolve_Call { + _c.Call.Return(run) + return _c +} diff --git a/internal/transport/rest/mocks/SessionService.go b/internal/transport/rest/mocks/SessionService.go new file mode 100644 index 0000000..62d6d43 --- /dev/null +++ b/internal/transport/rest/mocks/SessionService.go @@ -0,0 +1,178 @@ +// Code generated by mockery; DO NOT EDIT. +// github.com/vektra/mockery +// template: testify + +package mocks + +import ( + "context" + "mtusi-messenger/internal/domain" + + "github.com/google/uuid" + mock "github.com/stretchr/testify/mock" +) + +// NewMockSessionService creates a new instance of MockSessionService. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewMockSessionService(t interface { + mock.TestingT + Cleanup(func()) +}) *MockSessionService { + if helper, ok := t.(interface{ Helper() }); ok { + helper.Helper() + } + + mock := &MockSessionService{} + mock.Mock.Test(t) + + t.Cleanup(func() { + if helper, ok := t.(interface{ Helper() }); ok { + helper.Helper() + } + mock.AssertExpectations(t) + }) + + return mock +} + +// MockSessionService is an autogenerated mock type for the SessionService type +type MockSessionService struct { + mock.Mock +} + +type MockSessionService_Expecter struct { + mock *mock.Mock +} + +func (_m *MockSessionService) EXPECT() *MockSessionService_Expecter { + return &MockSessionService_Expecter{mock: &_m.Mock} +} + +// Create provides a mock function for the type MockSessionService +func (_mock *MockSessionService) Create(ctx context.Context, user domain.User) (domain.Session, error) { + ret := _mock.Called(ctx, user) + + if len(ret) == 0 { + panic("no return value specified for Create") + } + + var r0 domain.Session + var r1 error + if returnFunc, ok := ret.Get(0).(func(context.Context, domain.User) (domain.Session, error)); ok { + return returnFunc(ctx, user) + } + if returnFunc, ok := ret.Get(0).(func(context.Context, domain.User) domain.Session); ok { + r0 = returnFunc(ctx, user) + } else { + r0 = ret.Get(0).(domain.Session) + } + if returnFunc, ok := ret.Get(1).(func(context.Context, domain.User) error); ok { + r1 = returnFunc(ctx, user) + } else { + r1 = ret.Error(1) + } + return r0, r1 +} + +// MockSessionService_Create_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Create' +type MockSessionService_Create_Call struct { + *mock.Call +} + +// Create is a helper method to define mock.On call +// - ctx context.Context +// - user domain.User +func (_e *MockSessionService_Expecter) Create(ctx any, user any) *MockSessionService_Create_Call { + return &MockSessionService_Create_Call{Call: _e.mock.On("Create", ctx, user)} +} + +func (_c *MockSessionService_Create_Call) Run(run func(ctx context.Context, user domain.User)) *MockSessionService_Create_Call { + _c.Call.Run(func(args mock.Arguments) { + var arg0 context.Context + if args[0] != nil { + arg0 = args[0].(context.Context) + } + var arg1 domain.User + if args[1] != nil { + arg1 = args[1].(domain.User) + } + run( + arg0, + arg1, + ) + }) + return _c +} + +func (_c *MockSessionService_Create_Call) Return(session domain.Session, err error) *MockSessionService_Create_Call { + _c.Call.Return(session, err) + return _c +} + +func (_c *MockSessionService_Create_Call) RunAndReturn(run func(ctx context.Context, user domain.User) (domain.Session, error)) *MockSessionService_Create_Call { + _c.Call.Return(run) + return _c +} + +// Revoke provides a mock function for the type MockSessionService +func (_mock *MockSessionService) Revoke(ctx context.Context, userID uuid.UUID, token string) error { + ret := _mock.Called(ctx, userID, token) + + if len(ret) == 0 { + panic("no return value specified for Revoke") + } + + var r0 error + if returnFunc, ok := ret.Get(0).(func(context.Context, uuid.UUID, string) error); ok { + r0 = returnFunc(ctx, userID, token) + } else { + r0 = ret.Error(0) + } + return r0 +} + +// MockSessionService_Revoke_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Revoke' +type MockSessionService_Revoke_Call struct { + *mock.Call +} + +// Revoke is a helper method to define mock.On call +// - ctx context.Context +// - userID uuid.UUID +// - token string +func (_e *MockSessionService_Expecter) Revoke(ctx any, userID any, token any) *MockSessionService_Revoke_Call { + return &MockSessionService_Revoke_Call{Call: _e.mock.On("Revoke", ctx, userID, token)} +} + +func (_c *MockSessionService_Revoke_Call) Run(run func(ctx context.Context, userID uuid.UUID, token string)) *MockSessionService_Revoke_Call { + _c.Call.Run(func(args mock.Arguments) { + var arg0 context.Context + if args[0] != nil { + arg0 = args[0].(context.Context) + } + var arg1 uuid.UUID + if args[1] != nil { + arg1 = args[1].(uuid.UUID) + } + var arg2 string + if args[2] != nil { + arg2 = args[2].(string) + } + run( + arg0, + arg1, + arg2, + ) + }) + return _c +} + +func (_c *MockSessionService_Revoke_Call) Return(err error) *MockSessionService_Revoke_Call { + _c.Call.Return(err) + return _c +} + +func (_c *MockSessionService_Revoke_Call) RunAndReturn(run func(ctx context.Context, userID uuid.UUID, token string) error) *MockSessionService_Revoke_Call { + _c.Call.Return(run) + return _c +} diff --git a/internal/transport/rest/mocks/UserLookup.go b/internal/transport/rest/mocks/UserLookup.go new file mode 100644 index 0000000..8268fe4 --- /dev/null +++ b/internal/transport/rest/mocks/UserLookup.go @@ -0,0 +1,115 @@ +// Code generated by mockery; DO NOT EDIT. +// github.com/vektra/mockery +// template: testify + +package mocks + +import ( + "context" + "mtusi-messenger/internal/domain" + + "github.com/google/uuid" + mock "github.com/stretchr/testify/mock" +) + +// NewMockUserLookup creates a new instance of MockUserLookup. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewMockUserLookup(t interface { + mock.TestingT + Cleanup(func()) +}) *MockUserLookup { + if helper, ok := t.(interface{ Helper() }); ok { + helper.Helper() + } + + mock := &MockUserLookup{} + mock.Mock.Test(t) + + t.Cleanup(func() { + if helper, ok := t.(interface{ Helper() }); ok { + helper.Helper() + } + mock.AssertExpectations(t) + }) + + return mock +} + +// MockUserLookup is an autogenerated mock type for the UserLookup type +type MockUserLookup struct { + mock.Mock +} + +type MockUserLookup_Expecter struct { + mock *mock.Mock +} + +func (_m *MockUserLookup) EXPECT() *MockUserLookup_Expecter { + return &MockUserLookup_Expecter{mock: &_m.Mock} +} + +// GetByID provides a mock function for the type MockUserLookup +func (_mock *MockUserLookup) GetByID(ctx context.Context, id uuid.UUID) (domain.User, error) { + ret := _mock.Called(ctx, id) + + if len(ret) == 0 { + panic("no return value specified for GetByID") + } + + var r0 domain.User + var r1 error + if returnFunc, ok := ret.Get(0).(func(context.Context, uuid.UUID) (domain.User, error)); ok { + return returnFunc(ctx, id) + } + if returnFunc, ok := ret.Get(0).(func(context.Context, uuid.UUID) domain.User); ok { + r0 = returnFunc(ctx, id) + } else { + r0 = ret.Get(0).(domain.User) + } + if returnFunc, ok := ret.Get(1).(func(context.Context, uuid.UUID) error); ok { + r1 = returnFunc(ctx, id) + } else { + r1 = ret.Error(1) + } + return r0, r1 +} + +// MockUserLookup_GetByID_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetByID' +type MockUserLookup_GetByID_Call struct { + *mock.Call +} + +// GetByID is a helper method to define mock.On call +// - ctx context.Context +// - id uuid.UUID +func (_e *MockUserLookup_Expecter) GetByID(ctx any, id any) *MockUserLookup_GetByID_Call { + return &MockUserLookup_GetByID_Call{Call: _e.mock.On("GetByID", ctx, id)} +} + +func (_c *MockUserLookup_GetByID_Call) Run(run func(ctx context.Context, id uuid.UUID)) *MockUserLookup_GetByID_Call { + _c.Call.Run(func(args mock.Arguments) { + var arg0 context.Context + if args[0] != nil { + arg0 = args[0].(context.Context) + } + var arg1 uuid.UUID + if args[1] != nil { + arg1 = args[1].(uuid.UUID) + } + run( + arg0, + arg1, + ) + }) + return _c +} + +func (_c *MockUserLookup_GetByID_Call) Return(user domain.User, err error) *MockUserLookup_GetByID_Call { + _c.Call.Return(user, err) + return _c +} + +func (_c *MockUserLookup_GetByID_Call) RunAndReturn(run func(ctx context.Context, id uuid.UUID) (domain.User, error)) *MockUserLookup_GetByID_Call { + _c.Call.Return(run) + return _c +} diff --git a/internal/transport/rest/mocks/UserService.go b/internal/transport/rest/mocks/UserService.go new file mode 100644 index 0000000..a2dd6c1 --- /dev/null +++ b/internal/transport/rest/mocks/UserService.go @@ -0,0 +1,181 @@ +// Code generated by mockery; DO NOT EDIT. +// github.com/vektra/mockery +// template: testify + +package mocks + +import ( + "context" + "mtusi-messenger/internal/domain" + + "github.com/google/uuid" + mock "github.com/stretchr/testify/mock" +) + +// NewMockUserService creates a new instance of MockUserService. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewMockUserService(t interface { + mock.TestingT + Cleanup(func()) +}) *MockUserService { + if helper, ok := t.(interface{ Helper() }); ok { + helper.Helper() + } + + mock := &MockUserService{} + mock.Mock.Test(t) + + t.Cleanup(func() { + if helper, ok := t.(interface{ Helper() }); ok { + helper.Helper() + } + mock.AssertExpectations(t) + }) + + return mock +} + +// MockUserService is an autogenerated mock type for the UserService type +type MockUserService struct { + mock.Mock +} + +type MockUserService_Expecter struct { + mock *mock.Mock +} + +func (_m *MockUserService) EXPECT() *MockUserService_Expecter { + return &MockUserService_Expecter{mock: &_m.Mock} +} + +// GetByID provides a mock function for the type MockUserService +func (_mock *MockUserService) GetByID(ctx context.Context, id uuid.UUID) (domain.User, error) { + ret := _mock.Called(ctx, id) + + if len(ret) == 0 { + panic("no return value specified for GetByID") + } + + var r0 domain.User + var r1 error + if returnFunc, ok := ret.Get(0).(func(context.Context, uuid.UUID) (domain.User, error)); ok { + return returnFunc(ctx, id) + } + if returnFunc, ok := ret.Get(0).(func(context.Context, uuid.UUID) domain.User); ok { + r0 = returnFunc(ctx, id) + } else { + r0 = ret.Get(0).(domain.User) + } + if returnFunc, ok := ret.Get(1).(func(context.Context, uuid.UUID) error); ok { + r1 = returnFunc(ctx, id) + } else { + r1 = ret.Error(1) + } + return r0, r1 +} + +// MockUserService_GetByID_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetByID' +type MockUserService_GetByID_Call struct { + *mock.Call +} + +// GetByID is a helper method to define mock.On call +// - ctx context.Context +// - id uuid.UUID +func (_e *MockUserService_Expecter) GetByID(ctx any, id any) *MockUserService_GetByID_Call { + return &MockUserService_GetByID_Call{Call: _e.mock.On("GetByID", ctx, id)} +} + +func (_c *MockUserService_GetByID_Call) Run(run func(ctx context.Context, id uuid.UUID)) *MockUserService_GetByID_Call { + _c.Call.Run(func(args mock.Arguments) { + var arg0 context.Context + if args[0] != nil { + arg0 = args[0].(context.Context) + } + var arg1 uuid.UUID + if args[1] != nil { + arg1 = args[1].(uuid.UUID) + } + run( + arg0, + arg1, + ) + }) + return _c +} + +func (_c *MockUserService_GetByID_Call) Return(user domain.User, err error) *MockUserService_GetByID_Call { + _c.Call.Return(user, err) + return _c +} + +func (_c *MockUserService_GetByID_Call) RunAndReturn(run func(ctx context.Context, id uuid.UUID) (domain.User, error)) *MockUserService_GetByID_Call { + _c.Call.Return(run) + return _c +} + +// Register provides a mock function for the type MockUserService +func (_mock *MockUserService) Register(ctx context.Context, draft domain.UserDraft) (domain.User, error) { + ret := _mock.Called(ctx, draft) + + if len(ret) == 0 { + panic("no return value specified for Register") + } + + var r0 domain.User + var r1 error + if returnFunc, ok := ret.Get(0).(func(context.Context, domain.UserDraft) (domain.User, error)); ok { + return returnFunc(ctx, draft) + } + if returnFunc, ok := ret.Get(0).(func(context.Context, domain.UserDraft) domain.User); ok { + r0 = returnFunc(ctx, draft) + } else { + r0 = ret.Get(0).(domain.User) + } + if returnFunc, ok := ret.Get(1).(func(context.Context, domain.UserDraft) error); ok { + r1 = returnFunc(ctx, draft) + } else { + r1 = ret.Error(1) + } + return r0, r1 +} + +// MockUserService_Register_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Register' +type MockUserService_Register_Call struct { + *mock.Call +} + +// Register is a helper method to define mock.On call +// - ctx context.Context +// - draft domain.UserDraft +func (_e *MockUserService_Expecter) Register(ctx any, draft any) *MockUserService_Register_Call { + return &MockUserService_Register_Call{Call: _e.mock.On("Register", ctx, draft)} +} + +func (_c *MockUserService_Register_Call) Run(run func(ctx context.Context, draft domain.UserDraft)) *MockUserService_Register_Call { + _c.Call.Run(func(args mock.Arguments) { + var arg0 context.Context + if args[0] != nil { + arg0 = args[0].(context.Context) + } + var arg1 domain.UserDraft + if args[1] != nil { + arg1 = args[1].(domain.UserDraft) + } + run( + arg0, + arg1, + ) + }) + return _c +} + +func (_c *MockUserService_Register_Call) Return(user domain.User, err error) *MockUserService_Register_Call { + _c.Call.Return(user, err) + return _c +} + +func (_c *MockUserService_Register_Call) RunAndReturn(run func(ctx context.Context, draft domain.UserDraft) (domain.User, error)) *MockUserService_Register_Call { + _c.Call.Return(run) + return _c +} diff --git a/internal/transport/rest/requestid.go b/internal/transport/rest/requestid.go new file mode 100644 index 0000000..350e5f8 --- /dev/null +++ b/internal/transport/rest/requestid.go @@ -0,0 +1,38 @@ +package rest + +import ( + "context" + "net/http" + "regexp" + + "github.com/google/uuid" +) + +const requestIDHeader = "X-Request-ID" + +var requestIDPattern = regexp.MustCompile(`^[A-Za-z0-9._:-]{1,64}$`) + +type requestIDKey struct{} + +func requestIDFromContext(ctx context.Context) string { + id, _ := ctx.Value(requestIDKey{}).(string) + + return id +} + +func withRequestID(ctx context.Context, id string) context.Context { + return context.WithValue(ctx, requestIDKey{}, id) +} + +func requestIDMiddleware(next http.Handler) http.Handler { + return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + id := r.Header.Get(requestIDHeader) + if !requestIDPattern.MatchString(id) { + id = uuid.NewString() + } + + w.Header().Set(requestIDHeader, id) + + next.ServeHTTP(w, r.WithContext(withRequestID(r.Context(), id))) + }) +} diff --git a/internal/transport/rest/router.go b/internal/transport/rest/router.go new file mode 100644 index 0000000..680aa9e --- /dev/null +++ b/internal/transport/rest/router.go @@ -0,0 +1,45 @@ +package rest + +import ( + "log/slog" + "net/http" + + "mtusi-messenger/internal/transport/rest/internal/oas" +) + +func NewRouter( + handler oas.Handler, + security oas.SecurityHandler, + extensions *Extensions, + log *slog.Logger, + maxBodyBytes, maxUploadBytes int64, +) (http.Handler, error) { + server, err := oas.NewServer( + handler, + security, + oas.WithErrorHandler(newErrorHandler(log)), + oas.WithNotFound(newNotFoundHandler(log)), + oas.WithMethodNotAllowed(newMethodNotAllowedHandler(log)), + ) + if err != nil { + return nil, err + } + + mux := http.NewServeMux() + + if extensions != nil { + // These routes are an optional contract extension (presigned uploads). + // They live outside the generated server so contracts/openapi.json stays + // byte-identical to the mandatory contract. + mux.Handle("/api/v1/chats/{chat_id}/attachments/presign", extensions.Presign()) + mux.Handle("/api/v1/attachments/{attachment_id}/complete", extensions.Complete()) + } + + mux.Handle("/", server) + + limited := bodyLimitMiddleware(maxBodyBytes, maxUploadBytes, log, mux) + + return requestIDMiddleware( + instanceIDMiddleware(InstanceID(), telemetryMiddleware(log, server, mux, limited)), + ), nil +} diff --git a/internal/transport/rest/router_test.go b/internal/transport/rest/router_test.go new file mode 100644 index 0000000..489913f --- /dev/null +++ b/internal/transport/rest/router_test.go @@ -0,0 +1,483 @@ +package rest_test + +import ( + "bytes" + "crypto/sha256" + "encoding/base64" + "encoding/json" + "errors" + "io" + "log/slog" + "net/http" + "net/http/httptest" + "strings" + "testing" + "time" + + "github.com/google/uuid" + "github.com/stretchr/testify/mock" + "github.com/stretchr/testify/require" + + "mtusi-messenger/internal/domain" + "mtusi-messenger/internal/logger" + "mtusi-messenger/internal/transport/rest" + "mtusi-messenger/internal/transport/rest/mocks" +) + +const ( + requestIDHeader = "X-Request-ID" + instanceIDHeader = "X-Instance-Id" +) + +func basic(username, password string) string { + return base64.StdEncoding.EncodeToString([]byte(username + ":" + password)) +} + +func assertError(message string) error { + return errors.New(message) +} + +type httpResult struct { + status int + header http.Header + body []byte +} + +type routerFixture struct { + users *mocks.MockUserService + chats *mocks.MockChatService + messages *mocks.MockMessageService + attachments *mocks.MockAttachmentService + health *mocks.MockHealthChecker + sessions *mocks.MockSessionActions + + server *httptest.Server +} + +// testMaxBodyBytes is small on purpose: the limit test does not need a 256 KiB body. +const testMaxBodyBytes = 64 << 10 + +func newRouterFixture(t *testing.T) *routerFixture { + t.Helper() + + fixture := &routerFixture{ + users: mocks.NewMockUserService(t), + chats: mocks.NewMockChatService(t), + messages: mocks.NewMockMessageService(t), + attachments: mocks.NewMockAttachmentService(t), + health: mocks.NewMockHealthChecker(t), + sessions: mocks.NewMockSessionActions(t), + } + + router, err := rest.NewRouter( + rest.NewHandler( + fixture.users, + fixture.chats, + fixture.messages, + fixture.attachments, + fixture.health, + fixture.sessions, + ), + rest.NewSecurityHandler(fixture.sessions), + nil, + logger.New(logger.WithLevel(slog.LevelError)), + testMaxBodyBytes, + testMaxBodyBytes, + ) + require.NoError(t, err) + + fixture.server = httptest.NewServer(router) + t.Cleanup(fixture.server.Close) + + return fixture +} + +func (f *routerFixture) do(t *testing.T, method, path string, body []byte, headers map[string]string) httpResult { + t.Helper() + + var reader io.Reader + if body != nil { + reader = bytes.NewReader(body) + } + + req, err := http.NewRequestWithContext(t.Context(), method, f.server.URL+path, reader) + require.NoError(t, err) + + if body != nil { + req.Header.Set("Content-Type", "application/json") + } + + for key, value := range headers { + req.Header.Set(key, value) + } + + resp, err := f.server.Client().Do(req) + require.NoError(t, err) + + defer func() { _ = resp.Body.Close() }() + + payload, err := io.ReadAll(resp.Body) + require.NoError(t, err) + + return httpResult{status: resp.StatusCode, header: resp.Header, body: payload} +} + +func TestHealthEndpoints(t *testing.T) { + fixture := newRouterFixture(t) + fixture.health.EXPECT().Ping(mock.Anything).Return(nil).Maybe() + + result := fixture.do(t, http.MethodGet, "/health/live", nil, nil) + require.Equal(t, http.StatusOK, result.status) + require.NotEmpty(t, result.header.Get(requestIDHeader)) + require.JSONEq(t, `{"status":"ok"}`, string(result.body)) + + result = fixture.do(t, http.MethodGet, "/health/ready", nil, nil) + require.Equal(t, http.StatusOK, result.status) +} + +func TestReadinessReturns503WhenDependencyDown(t *testing.T) { + fixture := newRouterFixture(t) + fixture.health.EXPECT().Ping(mock.Anything).Return(assertError("down")).Maybe() + + result := fixture.do(t, http.MethodGet, "/health/ready", nil, nil) + require.Equal(t, http.StatusServiceUnavailable, result.status) + + var body struct { + Error struct { + Code string `json:"code"` + } `json:"error"` + } + require.NoError(t, json.Unmarshal(result.body, &body)) + require.Equal(t, "unavailable", body.Error.Code) +} + +func TestRequestIDEchoedFromClient(t *testing.T) { + fixture := newRouterFixture(t) + + result := fixture.do(t, http.MethodGet, "/health/live", nil, map[string]string{requestIDHeader: "from-client"}) + require.Equal(t, "from-client", result.header.Get(requestIDHeader)) +} + +func TestProtectedEndpointRequiresBearer(t *testing.T) { + tests := map[string]map[string]string{ + "без заголовка": nil, + "только X-User-Id": {"X-User-Id": uuid.NewString()}, + "basic вместо bearer": {"Authorization": "Basic dXNlcjpwYXNz"}, + } + + for name, headers := range tests { + t.Run(name, func(t *testing.T) { + fixture := newRouterFixture(t) + + result := fixture.do(t, http.MethodGet, "/api/v1/users/me", nil, headers) + require.Equal(t, http.StatusUnauthorized, result.status) + require.Contains(t, result.header.Get("WWW-Authenticate"), "Bearer") + }) + } +} + +func TestBearerSessionIsResolvedToCaller(t *testing.T) { + fixture := newRouterFixture(t) + + user := domain.User{ID: uuid.New(), Username: "alice", DisplayName: "Алиса", CreatedAt: time.Now().UTC()} + fixture.sessions.EXPECT().Resolve(mock.Anything, "opaque-token").Return(user, nil).Once() + fixture.users.EXPECT().GetByID(mock.Anything, user.ID).Return(user, nil).Once() + + result := fixture.do(t, http.MethodGet, "/api/v1/users/me", nil, map[string]string{"Authorization": "Bearer opaque-token"}) + require.Equal(t, http.StatusOK, result.status) + + var body map[string]any + require.NoError(t, json.Unmarshal(result.body, &body)) + require.Equal(t, user.ID.String(), body["id"]) +} + +func TestUnknownBearerIsRejected(t *testing.T) { + fixture := newRouterFixture(t) + fixture.sessions.EXPECT().Resolve(mock.Anything, "unknown").Return(domain.User{}, domain.ErrUnauthenticated).Once() + + result := fixture.do(t, http.MethodGet, "/api/v1/chats", nil, map[string]string{"Authorization": "Bearer unknown"}) + require.Equal(t, http.StatusUnauthorized, result.status) + require.Contains(t, result.header.Get("WWW-Authenticate"), "Bearer") +} + +func TestRegisterUserReturnsContractShape(t *testing.T) { + fixture := newRouterFixture(t) + + user := domain.User{ID: uuid.New(), Username: "alice", DisplayName: "Алиса", CreatedAt: time.Now().UTC()} + draft := domain.UserDraft{Username: "alice", DisplayName: "Алиса", Password: "very-secret-password"} + fixture.users.EXPECT().Register(mock.Anything, draft).Return(user, nil).Once() + + body, err := json.Marshal(map[string]string{"username": "alice", "display_name": "Алиса", "password": draft.Password}) + require.NoError(t, err) + + result := fixture.do(t, http.MethodPost, "/api/v1/users", body, nil) + require.Equal(t, http.StatusCreated, result.status) + require.NotContains(t, string(result.body), "password") + + var decoded map[string]any + require.NoError(t, json.Unmarshal(result.body, &decoded)) + require.Equal(t, user.ID.String(), decoded["id"]) + require.Len(t, decoded, 4) +} + +func TestRegisterDuplicateUsernameConflicts(t *testing.T) { + fixture := newRouterFixture(t) + fixture.users.EXPECT().Register(mock.Anything, mock.Anything).Return(domain.User{}, domain.ErrUsernameTaken).Once() + + body, err := json.Marshal(map[string]string{"username": "alice", "display_name": "Алиса", "password": "very-secret-password"}) + require.NoError(t, err) + + result := fixture.do(t, http.MethodPost, "/api/v1/users", body, nil) + require.Equal(t, http.StatusConflict, result.status) +} + +func TestCreateSessionFromBasicAuth(t *testing.T) { + fixture := newRouterFixture(t) + + user := domain.User{ID: uuid.New(), Username: "alice", DisplayName: "Алиса", CreatedAt: time.Now().UTC()} + session := domain.Session{Token: "opaque-token", ExpiresAt: time.Now().UTC().Add(time.Hour), User: user} + + fixture.sessions.EXPECT().Authenticate(mock.Anything, "alice", "very-secret-password").Return(user, nil).Once() + fixture.sessions.EXPECT().Create(mock.Anything, user).Return(session, nil).Once() + + result := fixture.do(t, http.MethodPost, "/api/v1/auth/sessions", nil, map[string]string{ + "Authorization": "Basic " + basic("alice", "very-secret-password"), + }) + require.Equal(t, http.StatusCreated, result.status) + + var body struct { + Token string `json:"token"` + TokenType string `json:"token_type"` + } + require.NoError(t, json.Unmarshal(result.body, &body)) + require.Equal(t, "opaque-token", body.Token) + require.Equal(t, "Bearer", body.TokenType) +} + +func TestCreateSessionRejectsBadCredentials(t *testing.T) { + fixture := newRouterFixture(t) + fixture.sessions.EXPECT().Authenticate(mock.Anything, mock.Anything, mock.Anything).Return(domain.User{}, domain.ErrUnauthenticated).Once() + + result := fixture.do(t, http.MethodPost, "/api/v1/auth/sessions", nil, map[string]string{ + "Authorization": "Basic " + basic("alice", "wrong-password-value"), + }) + require.Equal(t, http.StatusUnauthorized, result.status) + require.Contains(t, result.header.Get("WWW-Authenticate"), "Basic") +} + +func TestRevokeSession(t *testing.T) { + fixture := newRouterFixture(t) + + user := domain.User{ID: uuid.New(), Username: "alice", DisplayName: "Алиса", CreatedAt: time.Now().UTC()} + fixture.sessions.EXPECT().Resolve(mock.Anything, "opaque-token").Return(user, nil).Once() + fixture.sessions.EXPECT().Revoke(mock.Anything, user.ID, "opaque-token").Return(nil).Once() + + result := fixture.do(t, http.MethodDelete, "/api/v1/auth/sessions/current", nil, map[string]string{"Authorization": "Bearer opaque-token"}) + require.Equal(t, http.StatusNoContent, result.status) + require.Empty(t, result.body) +} + +func TestCursorRoundTrip(t *testing.T) { + fixture := newRouterFixture(t) + + user := domain.User{ID: uuid.New(), Username: "alice", DisplayName: "Алиса", CreatedAt: time.Now().UTC()} + chatID := uuid.New() + message := domain.Message{ID: uuid.New(), ChatID: chatID, SenderID: user.ID, Text: "первое", CreatedAt: time.Now().UTC()} + + fixture.sessions.EXPECT().Resolve(mock.Anything, "opaque-token").Return(user, nil).Maybe() + fixture.messages.EXPECT(). + History(mock.Anything, user.ID, chatID, (*domain.Cursor)(nil), 1). + Return(domain.Page[domain.Message]{ + Items: []domain.Message{message}, + Next: &domain.Cursor{Scope: chatID, CreatedAt: message.CreatedAt, ID: message.ID}, + }, nil). + Once() + + result := fixture.do(t, http.MethodGet, "/api/v1/chats/"+chatID.String()+"/messages?limit=1", nil, map[string]string{"Authorization": "Bearer opaque-token"}) + require.Equal(t, http.StatusOK, result.status) + + var body struct { + Items []json.RawMessage `json:"items"` + NextCursor *string `json:"next_cursor"` + } + require.NoError(t, json.Unmarshal(result.body, &body)) + require.Len(t, body.Items, 1) + require.NotNil(t, body.NextCursor) + + fixture.messages.EXPECT(). + History(mock.Anything, user.ID, chatID, mock.Anything, 1). + Return(domain.Page[domain.Message]{Items: []domain.Message{}}, nil). + Once() + + result = fixture.do( + t, + http.MethodGet, + "/api/v1/chats/"+chatID.String()+"/messages?limit=1&cursor="+*body.NextCursor, + nil, + map[string]string{"Authorization": "Bearer opaque-token"}, + ) + require.Equal(t, http.StatusOK, result.status) +} + +func TestInvalidCursorIsRejected(t *testing.T) { + fixture := newRouterFixture(t) + + user := domain.User{ID: uuid.New(), Username: "alice", DisplayName: "Алиса", CreatedAt: time.Now().UTC()} + fixture.sessions.EXPECT().Resolve(mock.Anything, mock.Anything).Return(user, nil).Maybe() + + result := fixture.do( + t, + http.MethodGet, + "/api/v1/chats/"+uuid.NewString()+"/messages?cursor=not-a-cursor", + nil, + map[string]string{"Authorization": "Bearer opaque-token"}, + ) + require.Equal(t, http.StatusBadRequest, result.status) +} + +func TestNotFoundAndMethodNotAllowed(t *testing.T) { + fixture := newRouterFixture(t) + + result := fixture.do(t, http.MethodGet, "/nope", nil, nil) + require.Equal(t, http.StatusNotFound, result.status) + + result = fixture.do(t, http.MethodDelete, "/health/live", nil, nil) + require.Equal(t, http.StatusMethodNotAllowed, result.status) +} + +func TestOversizedBodyIsRejectedWithPayloadTooLarge(t *testing.T) { + fixture := newRouterFixture(t) + + // Тело больше лимита не читается и не декодируется: отказ приходит сразу, + // до обращения к сервисам. + body, err := json.Marshal(map[string]string{ + "username": "alice", + "display_name": "Алиса", + "password": strings.Repeat("x", testMaxBodyBytes+1), + }) + require.NoError(t, err) + + result := fixture.do(t, http.MethodPost, "/api/v1/users", body, nil) + require.Equal(t, http.StatusRequestEntityTooLarge, result.status) + require.NotEmpty(t, result.header.Get(instanceIDHeader), "ответ об ошибке тоже помечен репликой") + require.NotEmpty(t, result.header.Get(requestIDHeader)) + + var decoded struct { + Error struct { + Code string `json:"code"` + } `json:"error"` + } + require.NoError(t, json.Unmarshal(result.body, &decoded)) + require.Equal(t, "payload_too_large", decoded.Error.Code) +} + +func TestCreateMessageRequiresIdempotencyKey(t *testing.T) { + fixture := newRouterFixture(t) + + user := domain.User{ID: uuid.New(), Username: "alice", DisplayName: "Алиса", CreatedAt: time.Now().UTC()} + fixture.sessions.EXPECT().Resolve(mock.Anything, "opaque-token").Return(user, nil).Maybe() + + result := fixture.do( + t, + http.MethodPost, + "/api/v1/chats/"+uuid.NewString()+"/messages", + []byte(`{"text":"привет"}`), + map[string]string{"Authorization": "Bearer opaque-token"}, + ) + require.Equal(t, http.StatusBadRequest, result.status) + require.NotEmpty(t, result.header.Get(instanceIDHeader), "ответ об ошибке тоже помечен репликой") +} + +func TestCreateMessageFingerprintIgnoresJSONFormatting(t *testing.T) { + fixture := newRouterFixture(t) + + user := domain.User{ID: uuid.New(), Username: "alice", DisplayName: "Алиса", CreatedAt: time.Now().UTC()} + chatID := uuid.New() + message := domain.Message{ID: uuid.New(), ChatID: chatID, SenderID: user.ID, Text: "привет", CreatedAt: time.Now().UTC()} + fixture.sessions.EXPECT().Resolve(mock.Anything, "opaque-token").Return(user, nil).Maybe() + + var fingerprints [][sha256.Size]byte + + fixture.messages.EXPECT(). + Send(mock.Anything, mock.MatchedBy(func(draft domain.MessageDraft) bool { + if draft.ChatID != chatID || draft.SenderID != user.ID || draft.Idempotency.Key != "key-1" { + return false + } + + fingerprints = append(fingerprints, draft.Idempotency.RequestHash) + + return true + })). + Return(message, nil) + + headers := map[string]string{"Authorization": "Bearer opaque-token", "Idempotency-Key": "key-1"} + path := "/api/v1/chats/" + chatID.String() + "/messages" + + first := fixture.do(t, http.MethodPost, path, []byte(`{"text":"привет"}`), headers) + replay := fixture.do(t, http.MethodPost, path, []byte(`{ "text" : "привет" }`), headers) + other := fixture.do(t, http.MethodPost, path, []byte(`{"text":"другое"}`), headers) + + require.Equal(t, http.StatusCreated, first.status) + require.Equal(t, http.StatusCreated, replay.status) + require.Equal(t, http.StatusCreated, other.status) + require.NotEmpty(t, first.header.Get(instanceIDHeader)) + require.Len(t, fingerprints, 3) + require.Equal(t, fingerprints[0], fingerprints[1], + "порядок ключей и пробелы в JSON не меняют отпечаток payload") + require.NotEqual(t, fingerprints[0], fingerprints[2], + "другой payload с тем же ключом — это конфликт, отпечатки обязаны различаться") +} + +func TestCreateMessageReplayConflictIsReportedAsConflict(t *testing.T) { + fixture := newRouterFixture(t) + + user := domain.User{ID: uuid.New(), Username: "alice", DisplayName: "Алиса", CreatedAt: time.Now().UTC()} + fixture.sessions.EXPECT().Resolve(mock.Anything, "opaque-token").Return(user, nil).Maybe() + fixture.messages.EXPECT(). + Send(mock.Anything, mock.Anything). + Return(domain.Message{}, domain.ErrIdempotency). + Once() + + result := fixture.do( + t, + http.MethodPost, + "/api/v1/chats/"+uuid.NewString()+"/messages", + []byte(`{"text":"другой"}`), + map[string]string{"Authorization": "Bearer opaque-token", "Idempotency-Key": "key-1"}, + ) + require.Equal(t, http.StatusConflict, result.status) + + var body struct { + Error struct { + Code string `json:"code"` + } `json:"error"` + } + require.NoError(t, json.Unmarshal(result.body, &body)) + require.Equal(t, "conflict", body.Error.Code) +} + +func TestEveryResponseCarriesInstanceID(t *testing.T) { + fixture := newRouterFixture(t) + + user := domain.User{ID: uuid.New(), Username: "alice", DisplayName: "Алиса", CreatedAt: time.Now().UTC()} + fixture.sessions.EXPECT().Resolve(mock.Anything, "opaque-token").Return(user, nil).Maybe() + + tests := map[string]httpResult{ + "успешный ответ": fixture.do(t, http.MethodGet, "/health/live", nil, nil), + "неизвестный маршрут": fixture.do(t, http.MethodGet, "/nope", nil, nil), + "неподдерживаемый метод": fixture.do(t, http.MethodDelete, "/health/live", nil, nil), + "ошибка валидации схемы": fixture.do( + t, + http.MethodPost, + "/api/v1/chats/"+uuid.NewString()+"/messages", + []byte(`{"text":"привет"}`), + map[string]string{"Authorization": "Bearer opaque-token"}, + ), + } + + for name, result := range tests { + t.Run(name, func(t *testing.T) { + require.NotEmpty(t, result.header.Get(instanceIDHeader)) + }) + } +} diff --git a/internal/transport/rest/security.go b/internal/transport/rest/security.go new file mode 100644 index 0000000..939ff1c --- /dev/null +++ b/internal/transport/rest/security.go @@ -0,0 +1,60 @@ +package rest + +import ( + "context" + "errors" + + "github.com/google/uuid" + + "mtusi-messenger/internal/domain" + "mtusi-messenger/internal/transport/rest/internal/oas" +) + +var ErrUnauthenticated = errors.New("caller is not identified") + +type ( + callerKey struct{} + tokenKey struct{} + credentialsKey struct{} +) + +func CallerFromContext(ctx context.Context) (uuid.UUID, bool) { + id, ok := ctx.Value(callerKey{}).(uuid.UUID) + return id, ok +} + +func caller(ctx context.Context) uuid.UUID { + id, _ := CallerFromContext(ctx) + return id +} + +type SecSessionService interface { + Authenticate(ctx context.Context, username, password string) (domain.User, error) + Resolve(ctx context.Context, token string) (domain.User, error) +} + +type SecurityHandler struct { + sessions SecSessionService +} + +func NewSecurityHandler(sessions SecSessionService) *SecurityHandler { + return &SecurityHandler{sessions: sessions} +} + +func (h *SecurityHandler) HandleBasicAuth(ctx context.Context, _ oas.OperationName, auth oas.BasicAuth) (context.Context, error) { + user, err := h.sessions.Authenticate(ctx, auth.Username, auth.Password) + if err != nil { + return ctx, err + } + ctx = context.WithValue(ctx, callerKey{}, user.ID) + return context.WithValue(ctx, credentialsKey{}, user), nil +} + +func (h *SecurityHandler) HandleBearerAuth(ctx context.Context, _ oas.OperationName, auth oas.BearerAuth) (context.Context, error) { + user, err := h.sessions.Resolve(ctx, auth.Token) + if err != nil { + return ctx, err + } + ctx = context.WithValue(ctx, callerKey{}, user.ID) + return context.WithValue(ctx, tokenKey{}, auth.Token), nil +} diff --git a/internal/transport/rest/telemetry.go b/internal/transport/rest/telemetry.go new file mode 100644 index 0000000..e4dfa7e --- /dev/null +++ b/internal/transport/rest/telemetry.go @@ -0,0 +1,90 @@ +package rest + +import ( + "log/slog" + "net/http" + "strings" + "time" + + "go.opentelemetry.io/otel" + "go.opentelemetry.io/otel/attribute" + "go.opentelemetry.io/otel/codes" + "go.opentelemetry.io/otel/propagation" + "go.opentelemetry.io/otel/trace" + + "mtusi-messenger/internal/telemetry" + "mtusi-messenger/internal/transport/rest/internal/oas" +) + +// telemetryMiddleware is the single source of HTTP spans, metrics and access +// logs. It resolves the OpenAPI template before the span is started: the +// generated ogen router does not set http.Request.Pattern for its routes. +func telemetryMiddleware(log *slog.Logger, server *oas.Server, mux *http.ServeMux, next http.Handler) http.Handler { + return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + route, operation := resolveRoute(server, mux, r) + if strings.HasPrefix(route, "/health/") { + next.ServeHTTP(w, r) + return + } + + ctx := otel.GetTextMapPropagator().Extract(r.Context(), propagation.HeaderCarrier(r.Header)) + method := normalizeMethod(r.Method) + started := time.Now() + ctx, span := otel.Tracer("messenger/http").Start(ctx, method+" "+route, + trace.WithSpanKind(trace.SpanKindServer), + trace.WithAttributes( + attribute.String("http.request.method", method), + attribute.String("http.route", route), + ), + ) + defer span.End() + + writer := &statusWriter{ResponseWriter: w} + next.ServeHTTP(writer, r.WithContext(ctx)) + + status := writer.statusCode() + span.SetAttributes(attribute.Int("http.response.status_code", status)) + if status >= http.StatusInternalServerError { + span.SetStatus(codes.Error, http.StatusText(status)) + } + telemetry.RecordHTTP(ctx, method, route, status, time.Since(started)) + + attrs := []any{ + slog.String("event", "http.request.completed"), + slog.String("operation", operation), + slog.String("route", route), + slog.String("method", method), + slog.Int("status", status), + slog.Duration("duration", time.Since(started)), + slog.String("request_id", requestIDFromContext(ctx)), + } + level := slog.LevelInfo + if status >= http.StatusInternalServerError { + level = slog.LevelError + } else if status >= http.StatusBadRequest { + level = slog.LevelWarn + } + log.Log(ctx, level, "http.request.completed", attrs...) + }) +} + +// normalizeMethod keeps the metric/span label set low-cardinality. Any method +// outside the standard set is deliberately collapsed to OTHER. +func normalizeMethod(method string) string { + switch method { + case http.MethodGet, http.MethodPost, http.MethodPut, http.MethodPatch, http.MethodDelete, http.MethodHead, http.MethodOptions: + return method + default: + return "OTHER" + } +} + +func resolveRoute(server *oas.Server, mux *http.ServeMux, r *http.Request) (route, operation string) { + if route, ok := server.FindPath(r.Method, r.URL); ok { + return route.PathPattern(), route.OperationID() + } + if _, pattern := mux.Handler(r); pattern != "" && pattern != "/" { + return pattern, "" + } + return "unmatched", "" +} diff --git a/internal/worker/worker.go b/internal/worker/worker.go new file mode 100644 index 0000000..4433c5f --- /dev/null +++ b/internal/worker/worker.go @@ -0,0 +1,614 @@ +// Package worker consumes attachment jobs, enforces the lease, produces the +// contract variants and acknowledges only after the durable result is +// committed. +package worker + +import ( + "bytes" + "context" + "crypto/sha256" + "encoding/hex" + "errors" + "fmt" + "io" + "log/slog" + "math/rand/v2" + "os" + "strings" + "sync" + "sync/atomic" + "time" + + "github.com/google/uuid" + amqp "github.com/rabbitmq/amqp091-go" + "go.opentelemetry.io/otel/attribute" + "go.opentelemetry.io/otel/codes" + "go.opentelemetry.io/otel/trace" + + "mtusi-messenger/internal/broker" + "mtusi-messenger/internal/domain" + "mtusi-messenger/internal/failpoint" + "mtusi-messenger/internal/imagecheck" + "mtusi-messenger/internal/imageproc" + "mtusi-messenger/internal/platform/objectstore" + "mtusi-messenger/internal/telemetry" +) + +type Repository interface { + ClaimJob( + ctx context.Context, + message domain.JobMessage, + leaseOwner string, + leaseTTL time.Duration, + ) (domain.ClaimResult, error) + Heartbeat(ctx context.Context, jobID uuid.UUID, attempt int, leaseOwner string, leaseTTL time.Duration) (bool, error) + CompleteJob(ctx context.Context, jobID uuid.UUID, attempt int, leaseOwner string, variants []domain.Variant) (bool, error) + RetryJob( + ctx context.Context, + jobID uuid.UUID, + attempt int, + leaseOwner, errorCode string, + nextAvailable time.Time, + sameAttempt bool, + kind string, + ) (failed bool, err error) + FailJob(ctx context.Context, jobID uuid.UUID, attempt int, leaseOwner, errorCode string) (bool, error) + MarkStagingDeleted(ctx context.Context, attachmentID uuid.UUID, stagingKey string) error +} + +type Store interface { + Open(ctx context.Context, key string) (io.ReadCloser, objectstore.Object, error) + Put(ctx context.Context, key string, body io.ReadSeeker, size int64, contentType string, metadata map[string]string) error + Delete(ctx context.Context, key string) error +} + +type Consumer interface { + Consume(ctx context.Context, handler broker.Handler) error + Connected() bool +} + +type Config struct { + Concurrency int + LeaseTTL time.Duration + Heartbeat time.Duration + JobTimeout time.Duration + RetryBase time.Duration + RetryCap time.Duration + MaxUploadBytes int64 + MaxImagePixels int64 + Owner string +} + +type Worker struct { + repo Repository + store Store + config Config + log *slog.Logger + consumer Consumer + + mu sync.RWMutex + running bool + busy atomic.Int64 +} + +func New(repo Repository, store Store, config Config, log *slog.Logger) *Worker { + if log == nil { + log = slog.Default() + } + + if config.Owner == "" { + config.Owner = "worker-" + uuid.NewString() + } + + return &Worker{repo: repo, store: store, config: config, log: log} +} + +// Run starts Concurrency consumer channels. It returns when the context is +// cancelled or one consumer fails; the caller recreates the broker connection. +func (w *Worker) Run(ctx context.Context, consumer Consumer) error { + w.consumer = consumer + w.setRunning(true) + defer w.setRunning(false) + + runCtx, cancel := context.WithCancel(ctx) + defer cancel() + + var ( + wg sync.WaitGroup + once sync.Once + firstErr error + ) + + for range w.config.Concurrency { + wg.Add(1) + + go func() { + defer wg.Done() + + if err := consumer.Consume(runCtx, w.handle); err != nil && runCtx.Err() == nil { + once.Do(func() { + firstErr = err + cancel() + }) + } + }() + } + + wg.Wait() + + return firstErr +} + +func (w *Worker) setRunning(value bool) { + w.mu.Lock() + defer w.mu.Unlock() + + w.running = value +} + +// Busy returns the number of worker slots currently processing a job. +func (w *Worker) Busy() int64 { return w.busy.Load() } + +// Capacity returns the configured worker concurrency. +func (w *Worker) Capacity() int { return w.config.Concurrency } + +func (w *Worker) Ready() (consumerRunning, brokerConnected bool) { + w.mu.RLock() + running := w.running + w.mu.RUnlock() + + if w.consumer == nil { + return running, false + } + + return running, w.consumer.Connected() +} + +func (w *Worker) handle(ctx context.Context, delivery amqp.Delivery) broker.Outcome { + message, err := domain.ParseJobMessage(delivery.Body) + if err != nil { + w.log.WarnContext(ctx, "invalid job payload moved to DLQ", slog.Any("error", err)) + + return broker.Drop + } + + ctx, span := telemetry.StartConsumerSpan(ctx, message) + defer span.End() + started := time.Now() + + result, err := w.repo.ClaimJob(ctx, message, w.config.Owner, w.config.LeaseTTL) + if err != nil { + span.SetAttributes(attribute.String("job.outcome", "claim_failed")) + span.SetStatus(codes.Error, "claim_failed") + telemetry.RecordJobAttempt(ctx, message.Type, "claim_failed", time.Since(started)) + w.log.WarnContext(ctx, "claim job failed", slog.String("job_id", message.JobID.String()), slog.Any("error", err)) + + return broker.Requeue + } + + switch result.Outcome { + case domain.ClaimAcquired: + w.log.InfoContext(ctx, "job claimed", + slog.String("job_id", message.JobID.String()), + slog.String("attachment_id", message.AttachmentID.String()), + slog.Int("attempt", message.Attempt), + slog.Int("pipeline_version", message.PipelineVersion), + ) + case domain.ClaimAlreadyReady, domain.ClaimAlreadyFailed, domain.ClaimSuperseded, + domain.ClaimStaleAttempt, domain.ClaimFutureAttempt, domain.ClaimBusyLease, + domain.ClaimNotDue, domain.ClaimVersionStale, domain.ClaimJobNotFound: + span.SetAttributes(attribute.String("job.outcome", string(result.Outcome))) + w.log.DebugContext(ctx, "job delivery is a no-op", + slog.String("job_id", message.JobID.String()), + slog.String("outcome", string(result.Outcome)), + ) + + return broker.Ack + default: + span.SetAttributes(attribute.String("job.outcome", string(result.Outcome))) + return broker.Ack + } + + outcome, label := w.process(ctx, result) + span.SetAttributes(attribute.String("job.outcome", label)) + if label == "failed" || label == "retried" { + span.SetStatus(codes.Error, label) + } + telemetry.RecordJobAttempt(ctx, message.Type, label, time.Since(started)) + + return outcome +} + +func (w *Worker) process( + ctx context.Context, + result domain.ClaimResult, +) (broker.Outcome, string) { + job := result.Job + w.busy.Add(1) + defer w.busy.Add(-1) + attachment := result.Attachment + + failpoint.Check("WORKER_AFTER_CLAIM", job.ID) + + switch failpoint.Mode("WORKER_FAIL", job.ID) { + case "permanent": + return w.fail(ctx, job, permanentError{code: "injected_failure", err: errors.New("injected permanent worker failure")}) + case "transient": + return w.fail(ctx, job, errors.New("injected transient worker failure")) + } + + jobCtx, cancel := context.WithTimeout(ctx, w.config.JobTimeout) + defer cancel() + + leaseLost := false + heartbeatDone := make(chan struct{}) + + go func() { + defer close(heartbeatDone) + + ticker := time.NewTicker(w.config.Heartbeat) + defer ticker.Stop() + + for { + select { + case <-jobCtx.Done(): + return + case <-ticker.C: + ok, err := w.repo.Heartbeat(jobCtx, job.ID, job.Attempt, w.config.Owner, w.config.LeaseTTL) + if err != nil { + // A DB blip is not proof that the lease is gone. Keep trying; + // the fencing CAS still prevents a stale commit. + w.log.WarnContext(jobCtx, "heartbeat failed", slog.Any("error", err)) + + continue + } + if !ok { + leaseLost = true + cancel() + + return + } + } + } + }() + + // The hook runs after the heartbeat starts: it can be paused to test a + // genuinely stuck (not merely slow) worker without consuming every attempt. + failpoint.Sleep("WORKER_SLEEP_AFTER_CLAIM", job.ID) + + watchdog := time.AfterFunc(w.config.JobTimeout+30*time.Second, func() { + w.log.ErrorContext(ctx, "worker job watchdog fired", + slog.String("job_id", job.ID.String()), + slog.String("attachment_id", job.AttachmentID.String()), + ) + os.Exit(70) + }) + defer watchdog.Stop() + + err := w.runJob(jobCtx, job, attachment) + cancel() + <-heartbeatDone + + if leaseLost { + w.log.WarnContext(ctx, "lease lost; reaper will requeue", + slog.String("job_id", job.ID.String()), + ) + + return broker.Ack, "superseded" + } + + if errors.Is(err, errCompletionCASLost) { + return broker.Ack, "superseded" + } + + if err == nil { + telemetry.RecordJobReady(ctx, job.PipelineVersion, time.Since(job.CreatedAt)) + failpoint.Check("WORKER_AFTER_COMMIT", job.ID) + + return broker.Ack, "succeeded" + } + + return w.fail(ctx, job, err) +} + +func (w *Worker) runJob( + ctx context.Context, + job domain.Job, + attachment domain.Attachment, +) error { + params, ok := imageproc.Pipeline(job.PipelineVersion) + if !ok { + return permanentError{code: "unsupported_pipeline", err: fmt.Errorf("pipeline %d", job.PipelineVersion)} + } + + sourceKey := job.SourceKey + if sourceKey == "" { + sourceKey = attachment.StagingKey + } + if sourceKey == "" { + sourceKey = attachment.ObjectKey + } + + file, size, sum, err := w.spoolSource(ctx, sourceKey) + if err != nil { + return err + } + + defer func() { _ = file.Close() }() + defer func() { _ = os.Remove(file.Name()) }() + + if size != attachment.SizeBytes || sum != attachment.SHA256 { + return permanentError{code: "source_corrupt", err: errors.New("source bytes do not match metadata")} + } + + if _, err := file.Seek(0, io.SeekStart); err != nil { + return fmt.Errorf("rewind source: %w", err) + } + + if _, err := imagecheck.Validate(file, w.config.MaxImagePixels); err != nil { + return permanentError{code: "invalid_image", err: err} + } + + if _, err := file.Seek(0, io.SeekStart); err != nil { + return fmt.Errorf("rewind source: %w", err) + } + + img, _, err := imageproc.Load(file.Name(), w.config.MaxImagePixels) + if err != nil { + return permanentError{code: "invalid_image", err: err} + } + + if sourceKey != attachment.ObjectKey { + if _, err := file.Seek(0, io.SeekStart); err != nil { + return fmt.Errorf("rewind original: %w", err) + } + + if err := w.store.Put( + ctx, attachment.ObjectKey, file, size, attachment.ContentType, + map[string]string{"sha256": sum}, + ); err != nil { + return fmt.Errorf("publish original: %w", err) + } + } + + variants := make([]domain.Variant, 0, 3) + + generated := []func() (imageproc.Image, error){ + func() (imageproc.Image, error) { return imageproc.Thumbnail(img, params) }, + func() (imageproc.Image, error) { return imageproc.Crop(img, params) }, + func() (imageproc.Image, error) { return imageproc.Optimized(img, params) }, + } + + for idx, generate := range generated { + variantImage, err := generate() + if err != nil { + return permanentError{code: "processing_failed", err: err} + } + + key := domain.VariantObjectKey(attachment.ChatID, attachment.ID, job.PipelineVersion, variantImage.Name) + + if err := w.store.Put( + ctx, key, bytes.NewReader(variantImage.Data), variantImage.SizeBytes, + variantImage.ContentType, map[string]string{"sha256": variantImage.SHA256}, + ); err != nil { + return fmt.Errorf("publish variant %s: %w", variantImage.Name, err) + } + + if idx == 0 { + failpoint.Check("WORKER_AFTER_FIRST_VARIANT", job.ID) + } + + variants = append(variants, domain.Variant{ + Name: variantImage.Name, + ContentType: variantImage.ContentType, + SizeBytes: variantImage.SizeBytes, + Width: variantImage.Width, + Height: variantImage.Height, + SHA256: variantImage.SHA256, + ObjectKey: key, + }) + } + + failpoint.Check("WORKER_AFTER_PUT", job.ID) + + completed, err := w.repo.CompleteJob(ctx, job.ID, job.Attempt, w.config.Owner, variants) + if err != nil { + return err + } + + if !completed { + w.log.WarnContext(ctx, "completion CAS lost", slog.String("job_id", job.ID.String())) + + return errCompletionCASLost + } + + w.log.InfoContext(ctx, "attachment ready", + slog.String("job_id", job.ID.String()), + slog.String("attachment_id", attachment.ID.String()), + slog.Int("pipeline_version", job.PipelineVersion), + ) + + if strings.HasPrefix(sourceKey, "staging/") && sourceKey != attachment.ObjectKey { + if err := w.store.Delete(ctx, sourceKey); err != nil && !errors.Is(err, domain.ErrNotFound) { + w.log.WarnContext(ctx, "staging delete failed", slog.String("object_key", sourceKey), slog.Any("error", err)) + + return nil + } + + if sourceKey == attachment.StagingKey { + if err := w.repo.MarkStagingDeleted(ctx, attachment.ID, sourceKey); err != nil { + w.log.WarnContext(ctx, "clear staging projection failed", slog.Any("error", err)) + } + } + } + + return nil +} + +func (w *Worker) spoolSource(ctx context.Context, key string) (*os.File, int64, string, error) { + body, _, err := w.store.Open(ctx, key) + if err != nil { + if errors.Is(err, domain.ErrNotFound) { + return nil, 0, "", permanentError{code: "source_missing", err: err} + } + + return nil, 0, "", fmt.Errorf("open source: %w", err) + } + defer body.Close() + + file, err := os.CreateTemp("", "lab5-worker-*") + if err != nil { + return nil, 0, "", fmt.Errorf("create worker spool: %w", err) + } + + cleanup := func() { + _ = file.Close() + _ = os.Remove(file.Name()) + } + + hasher := sha256.New() + limited := io.LimitReader(body, w.config.MaxUploadBytes+1) + buffer := make([]byte, 64<<10) + + size, err := io.CopyBuffer(io.MultiWriter(file, hasher), limited, buffer) + if err != nil { + cleanup() + + return nil, 0, "", fmt.Errorf("copy source: %w", err) + } + + if size > w.config.MaxUploadBytes { + cleanup() + + return nil, 0, "", permanentError{code: "source_too_large", err: fmt.Errorf("source exceeds %d bytes", w.config.MaxUploadBytes)} + } + + return file, size, hex.EncodeToString(hasher.Sum(nil)), nil +} + +func classifyFailure(err error) (code string, permanent bool) { + code = "processing_failed" + + var typed permanentError + if errors.As(err, &typed) { + code = typed.code + permanent = true + } + + if errors.Is(err, domain.ErrValidation) || errors.Is(err, domain.ErrUnsupportedMedia) || + errors.Is(err, domain.ErrTooLarge) || errors.Is(err, domain.ErrConflict) { + permanent = true + if code == "processing_failed" { + code = "invalid_image" + } + } + + if errors.Is(err, context.DeadlineExceeded) { + code = "processing_timeout" + permanent = false + } + + return code, permanent +} + +func (w *Worker) fail(ctx context.Context, job domain.Job, err error) (broker.Outcome, string) { + if ctx.Err() != nil { + // Parent cancellation means graceful shutdown. Keep the attempt number: + // an operator restart must not consume the processing budget. The job + // context is already cancelled, so use a short detached context for the + // durable requeue. + retryCtx, cancel := context.WithTimeout(context.WithoutCancel(ctx), 5*time.Second) + defer cancel() + + failed, retryErr := w.repo.RetryJob( + retryCtx, job.ID, job.Attempt, w.config.Owner, "shutdown", + time.Now().Add(time.Second), true, "shutdown", + ) + if retryErr != nil { + return broker.Requeue, "failed" + } + + _ = failed + + return broker.Ack, "shutdown" + } + + if span := trace.SpanFromContext(ctx); span.IsRecording() { + span.RecordError(errors.New(telemetry.Redact(err.Error()))) + } + + code, permanent := classifyFailure(err) + + if permanent { + w.log.WarnContext(ctx, "job permanently failed", + slog.String("job_id", job.ID.String()), + slog.String("error_code", code), + slog.Any("error", err), + ) + + ok, failErr := w.repo.FailJob(ctx, job.ID, job.Attempt, w.config.Owner, code) + if failErr != nil { + return broker.Requeue, "failed" + } + if !ok { + return broker.Ack, "failed" + } + + return broker.Drop, "failed" + } + + next := time.Now().Add(w.backoff(job.Attempt)) + w.log.WarnContext(ctx, "job retry scheduled", + slog.String("job_id", job.ID.String()), + slog.String("error_code", code), + slog.Time("available_at", next), + slog.Any("error", err), + ) + + failed, retryErr := w.repo.RetryJob( + ctx, job.ID, job.Attempt, w.config.Owner, code, next, false, "retry", + ) + if retryErr != nil { + return broker.Requeue, "retried" + } + + if failed { + return broker.Drop, "failed" + } + + return broker.Ack, "retried" +} + +func (w *Worker) backoff(attempt int) time.Duration { + if attempt < 1 { + attempt = 1 + } + + capDelay := w.config.RetryCap + base := w.config.RetryBase + + for range attempt - 1 { + base *= 2 + if base >= capDelay { + base = capDelay + + break + } + } + + if base <= 0 { + return time.Second + } + + return time.Duration(rand.Int64N(int64(base))) + time.Millisecond +} + +var errCompletionCASLost = errors.New("completion CAS lost") + +type permanentError struct { + code string + err error +} + +func (e permanentError) Error() string { return e.code + ": " + e.err.Error() } +func (e permanentError) Unwrap() error { return e.err } diff --git a/internal/worker/worker_test.go b/internal/worker/worker_test.go new file mode 100644 index 0000000..65f36e6 --- /dev/null +++ b/internal/worker/worker_test.go @@ -0,0 +1,34 @@ +package worker + +import ( + "context" + "errors" + "testing" + + "mtusi-messenger/internal/domain" +) + +func TestClassifyFailure(t *testing.T) { + t.Parallel() + + tests := []struct { + name string + err error + wantCode string + permanent bool + }{ + {name: "typed permanent", err: permanentError{code: "invalid_image", err: errors.New("bad")}, wantCode: "invalid_image", permanent: true}, + {name: "validation", err: domain.ErrValidation, wantCode: "invalid_image", permanent: true}, + {name: "deadline", err: context.DeadlineExceeded, wantCode: "processing_timeout", permanent: false}, + {name: "transient", err: errors.New("temporary"), wantCode: "processing_failed", permanent: false}, + } + for _, test := range tests { + t.Run(test.name, func(t *testing.T) { + t.Parallel() + code, permanent := classifyFailure(test.err) + if code != test.wantCode || permanent != test.permanent { + t.Fatalf("classifyFailure() = (%q, %v), want (%q, %v)", code, permanent, test.wantCode, test.permanent) + } + }) + } +} diff --git a/scripts/api_cache_performance.sh b/scripts/api_cache_performance.sh new file mode 100644 index 0000000..10c0354 --- /dev/null +++ b/scripts/api_cache_performance.sh @@ -0,0 +1,16 @@ +#!/bin/sh +set -eu + +ROOT_DIR=$(CDPATH= cd -- "$(dirname -- "$0")/.." && pwd) +cd "$ROOT_DIR" + +mkdir -p evidence/cache + +{ + echo "# API cache performance experiment" + echo "# generated: $(date -u +%Y-%m-%dT%H:%M:%SZ)" + env -u HTTP_PROXY -u HTTPS_PROXY -u ALL_PROXY -u http_proxy -u https_proxy -u all_proxy \ + NO_PROXY=localhost,127.0.0.1,::1 no_proxy=localhost,127.0.0.1,::1 \ + python3 student-tests/cache_api_performance.py +} > evidence/cache/api-performance.txt 2>&1 +cat evidence/cache/api-performance.txt diff --git a/scripts/cache_evidence.sh b/scripts/cache_evidence.sh new file mode 100644 index 0000000..b3f7628 --- /dev/null +++ b/scripts/cache_evidence.sh @@ -0,0 +1,21 @@ +#!/usr/bin/env bash +set -euo pipefail + +ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" +OUT="$ROOT/evidence/cache" +GO="${GO:-go}" + +cd "$ROOT" +mkdir -p "$OUT" + +{ + echo "# Cache consistency evidence (track 1)" + echo "# generated: $(date -u +%Y-%m-%dT%H:%M:%SZ)" + echo "# redis: ${TEST_REDIS_HOST:-localhost}:${TEST_REDIS_PORT:-6379} db=${TEST_REDIS_DB:-1}" + echo + "$GO" test -tags=integration -count=1 -v -timeout=5m \ + -run 'TestChatRepositorySuite|TestSessionRepositorySuite' \ + ./internal/storage/redis/... +} | tee "$OUT/consistency.txt" + +echo "wrote $OUT/consistency.txt" diff --git a/scripts/cache_latency_experiment.sh b/scripts/cache_latency_experiment.sh new file mode 100644 index 0000000..52438a3 --- /dev/null +++ b/scripts/cache_latency_experiment.sh @@ -0,0 +1,17 @@ +#!/bin/sh +set -eu + +ROOT_DIR=$(CDPATH= cd -- "$(dirname -- "$0")/.." && pwd) +cd "$ROOT_DIR" + +mkdir -p evidence/cache + +{ + echo "# Cache latency experiment" + echo "# generated: $(date -u +%Y-%m-%dT%H:%M:%SZ)" + go version + uname -sm + go test -tags=integration -count=3 -timeout=5m -v \ + -run '^TestCacheLatencyExperiment$' ./internal/storage/postgres/... +} > evidence/cache/latency.txt 2>&1 +cat evidence/cache/latency.txt diff --git a/scripts/cache_performance_experiment.sh b/scripts/cache_performance_experiment.sh new file mode 100644 index 0000000..b431bb6 --- /dev/null +++ b/scripts/cache_performance_experiment.sh @@ -0,0 +1,17 @@ +#!/bin/sh +set -eu + +ROOT_DIR=$(CDPATH= cd -- "$(dirname -- "$0")/.." && pwd) +cd "$ROOT_DIR" + +mkdir -p evidence/cache + +{ + echo "# Cache performance experiment" + echo "# generated: $(date -u +%Y-%m-%dT%H:%M:%SZ)" + go version + uname -sm + go test -tags=integration -count=3 -timeout=5m -v \ + -run '^TestCachePerformanceExperiment$' ./internal/storage/postgres/... +} > evidence/cache/performance.txt 2>&1 +cat evidence/cache/performance.txt diff --git a/scripts/check_evidence.py b/scripts/check_evidence.py new file mode 100755 index 0000000..31b24cd --- /dev/null +++ b/scripts/check_evidence.py @@ -0,0 +1,46 @@ +#!/usr/bin/env python3 +"""Scan committed evidence for credentials, signed URLs and raw identifiers.""" +import re +import sys +from pathlib import Path + +ROOT = Path(__file__).resolve().parents[1] +PATTERNS = { + 'aws signature': re.compile(r'X-Amz-(?:Signature|Credential|Security-Token)='), + 'inline password': re.compile(r'(?i)(password|passwd|secret|token)\s*[=:]\s*["\']?[^\s"\']{6,}'), + 'url credentials': re.compile(r'://[^/\s:@]+:[^@\s]+@'), + 'private key': re.compile(r'BEGIN (?:RSA |EC |OPENSSH )?PRIVATE KEY'), + 'bearer token': re.compile(r'Bearer\s+[A-Za-z0-9._-]{20,}'), +} +ALLOW = { + 'PASSWORD=messenger', + 'PASSWORD=messenger', + 'password: messenger', + 'POSTGRES_PASSWORD: messenger', +} + +def main(): + failures = [] + for path in (ROOT / 'evidence').rglob('*'): + if not path.is_file() or path.suffix in {'.png', '.jpg', '.jpeg', '.webp'}: + continue + try: + text = path.read_text(errors='replace') + except OSError: + continue + for name, pattern in PATTERNS.items(): + for match in pattern.finditer(text): + line = text[text.rfind('\n', 0, match.start()) + 1:text.find('\n', match.end())].strip() + if any(allowed in line for allowed in ALLOW): + continue + failures.append(f'{path.relative_to(ROOT)}: {name}: {line[:160]}') + if failures: + print('FAIL: evidence scanner found possible secrets/signatures') + for item in failures: + print(' ', item) + return 1 + print('PASS: evidence has no obvious secrets, signed URLs or bearer tokens') + return 0 + +if __name__ == '__main__': + raise SystemExit(main()) diff --git a/scripts/check_s3_creds.py b/scripts/check_s3_creds.py new file mode 100755 index 0000000..68b083d --- /dev/null +++ b/scripts/check_s3_creds.py @@ -0,0 +1,74 @@ +#!/usr/bin/env python3 +"""Fail when the SeaweedFS identities and the API environment disagree. + +The stand keeps synthetic credentials in two places on purpose: the identities +file is mounted into SeaweedFS, while the API receives the same values through +the environment. This check keeps the copies from drifting. +""" +from __future__ import annotations + +import json +import sys +from pathlib import Path + +ROOT = Path(__file__).resolve().parent.parent +IDENTITIES = ROOT / "infra/s3/s3.json" + + +def parse_env(path: Path) -> dict[str, str]: + values: dict[str, str] = {} + for raw in path.read_text().splitlines(): + line = raw.strip() + if not line or line.startswith("#") or "=" not in line: + continue + key, value = line.split("=", 1) + values[key.strip()] = value.strip().strip('"').strip("'") + return values + + +def main() -> int: + identities = json.loads(IDENTITIES.read_text()) + by_name = {item["name"]: item for item in identities.get("identities", [])} + + source = ROOT / ".env" + if not source.is_file(): + source = ROOT / ".env.example" + env = parse_env(source) + + expected = { + "app": ("S3_ACCESS_KEY_ID", "S3_SECRET_ACCESS_KEY"), + } + + failures: list[str] = [] + for name, (key_var, secret_var) in expected.items(): + identity = by_name.get(name) + if identity is None: + failures.append(f"{IDENTITIES}: identity {name!r} is missing") + continue + credentials = identity.get("credentials") or [] + if not credentials: + failures.append(f"{IDENTITIES}: identity {name!r} has no credentials") + continue + access_key = credentials[0].get("accessKey") + secret_key = credentials[0].get("secretKey") + if env.get(key_var) != access_key: + failures.append(f"{source.name}: {key_var} does not match identity {name!r}") + if env.get(secret_var) != secret_key: + failures.append(f"{source.name}: {secret_var} does not match identity {name!r}") + + if failures: + print("FAIL: S3 credentials are inconsistent") + for failure in failures: + print(" -", failure) + return 1 + + if "admin" not in by_name: + print("FAIL: infra/s3/s3.json has no admin identity for s3-init") + return 1 + + print(f"PASS: S3 app identity matches {source.name}; admin stays in s3.json/s3-init") + return 0 + + +if __name__ == "__main__": + sys.exit(main()) diff --git a/scripts/init-secrets.sh b/scripts/init-secrets.sh new file mode 100755 index 0000000..fb6a699 --- /dev/null +++ b/scripts/init-secrets.sh @@ -0,0 +1,8 @@ +#!/bin/sh +set -eu +ROOT_DIR=$(CDPATH= cd -- "$(dirname -- "$0")/.." && pwd) +mkdir -p "$ROOT_DIR/secrets" +if [ ! -s "$ROOT_DIR/secrets/grafana.env" ]; then + (umask 077; printf 'GF_SECURITY_ADMIN_PASSWORD=%s\n' "$(openssl rand -hex 16)" > "$ROOT_DIR/secrets/grafana.env") + echo "created secrets/grafana.env" +fi diff --git a/scripts/lab4_memory_experiment.py b/scripts/lab4_memory_experiment.py new file mode 100755 index 0000000..f350ad0 --- /dev/null +++ b/scripts/lab4_memory_experiment.py @@ -0,0 +1,147 @@ +#!/usr/bin/env python3 +"""Measure API memory under concurrent 9 MiB uploads (lab4 level 4). + +Run against a live stand. Writes raw CSV samples and a summary under +evidence/lab4/memory/. The primary metric is cgroup anon memory: memory.current +also includes page cache from the temporary spool files. + + python3 scripts/lab4_memory_experiment.py --base-url http://localhost:8080 +""" +from __future__ import annotations + +import argparse +import csv +import os +import struct +import sys +import threading +import time +import zlib +from concurrent.futures import ThreadPoolExecutor +from pathlib import Path + +ROOT = Path(__file__).resolve().parent.parent +sys.path.insert(0, str(ROOT / 'tests')) + +from client import Client # noqa: E402 + +OUTPUT = ROOT / 'evidence/lab4/memory' + + +def png_of_size(width: int, height: int, seed: int) -> bytes: + """Build a valid, poorly compressible PNG (random RGB scanlines).""" + rng = __import__('random').Random(seed) + raw = bytearray() + for _ in range(height): + raw.append(0) # filter: None + raw.extend(rng.randbytes(width * 3)) + + def chunk(kind: bytes, data: bytes) -> bytes: + return struct.pack('>I', len(data)) + kind + data + struct.pack('>I', zlib.crc32(kind + data) & 0xFFFFFFFF) + + ihdr = struct.pack('>IIBBBBB', width, height, 8, 2, 0, 0, 0) + return b'\x89PNG\r\n\x1a\n' + chunk(b'IHDR', ihdr) + chunk(b'IDAT', zlib.compress(bytes(raw), 6)) + chunk(b'IEND', b'') + + +def containers(service: str) -> list[str]: + output = os.popen(f'docker compose ps -q {service}').read().split() + if not output: + raise SystemExit(f'no running containers for service {service}') + return output + + +def read_number(container: str, path: str) -> int: + output = os.popen(f'docker exec {container} cat {path} 2>/dev/null').read().strip() + return int(output) if output.isdigit() else 0 + + +def memory_snapshot() -> dict[str, int]: + api = containers('api') + anon = current = 0 + for container in api: + stats = os.popen(f'docker exec {container} cat /sys/fs/cgroup/memory.stat 2>/dev/null').read() + for line in stats.splitlines(): + if line.startswith('anon '): + anon += int(line.split()[1]) + current += read_number(container, '/sys/fs/cgroup/memory.current') + return {'anon': anon, 'current': current} + + +def main() -> None: + parser = argparse.ArgumentParser() + parser.add_argument('--base-url', default='http://localhost:8080') + parser.add_argument('--concurrency', type=int, default=10) + parser.add_argument('--width', type=int, default=2100) + parser.add_argument('--height', type=int, default=1500) + parser.add_argument('--rounds', type=int, default=3) + args = parser.parse_args() + + content = png_of_size(args.width, args.height, 42) + if len(content) > 10 * 1024 * 1024: + raise SystemExit(f'generated PNG is {len(content)} bytes, above the 10 MiB contract limit') + + client = Client(args.base_url, timeout=120) + alice, _, _, chat = client.bootstrap() + + OUTPUT.mkdir(parents=True, exist_ok=True) + samples: list[dict[str, int | float | str]] = [] + stop = threading.Event() + + def sample(phase: str = 'during') -> None: + started = time.monotonic() + while not stop.is_set(): + snapshot = memory_snapshot() + samples.append({'elapsed': round(time.monotonic() - started, 3), 'phase': phase, **snapshot}) + time.sleep(0.2) + + baseline = memory_snapshot() + sampler = threading.Thread(target=sample, daemon=True) + sampler.start() + + def upload(_: int) -> None: + path = '/api/v1/chats/' + chat['id'] + '/attachments?filename=memory.png' + client.call( + 'POST', path, 201, actor=alice, raw=content, + headers={'Content-Type': 'image/png'}, schema='Attachment', + ) + + started = time.monotonic() + for _ in range(args.rounds): + with ThreadPoolExecutor(max_workers=args.concurrency) as pool: + list(pool.map(upload, range(args.concurrency))) + elapsed = time.monotonic() - started + + stop.set() + sampler.join(timeout=2) + after = memory_snapshot() + + peak_anon = max((int(item['anon']) for item in samples), default=after['anon']) + peak_current = max((int(item['current']) for item in samples), default=after['current']) + + csv_path = OUTPUT / 'samples.csv' + with csv_path.open('w', newline='') as handle: + writer = csv.DictWriter(handle, fieldnames=['elapsed', 'phase', 'anon', 'current']) + writer.writeheader() + writer.writerows(samples) + + summary = OUTPUT / 'summary.txt' + summary.write_text( + 'Lab4 memory experiment\n' + f'concurrency: {args.concurrency}\n' + f'file_size_bytes: {len(content)}\n' + f'uploads: {args.concurrency * args.rounds}\n' + f'rounds: {args.rounds}\n' + f'elapsed_seconds: {elapsed:.3f}\n' + f'baseline_anon_bytes: {baseline["anon"]}\n' + f'peak_anon_bytes: {peak_anon}\n' + f'anon_delta_bytes: {peak_anon - baseline["anon"]}\n' + f'peak_memory_current_bytes: {peak_current}\n' + 'note: memory.current includes page cache from temporary spool files; anon is the primary metric\n' + ) + + print(summary.read_text()) + print('CSV:', csv_path) + + +if __name__ == '__main__': + main() diff --git a/scripts/lab4_track1.py b/scripts/lab4_track1.py new file mode 100755 index 0000000..4a86e8c --- /dev/null +++ b/scripts/lab4_track1.py @@ -0,0 +1,179 @@ +#!/usr/bin/env python3 +"""Compare proxy upload with presigned direct upload (lab4 track 1). + +Measures client-facing LB traffic, API traffic, API anon memory and latency for +two file sizes. Run against a live stand from the repository root. + + python3 scripts/lab4_track1.py --base-url http://localhost:8080 +""" +from __future__ import annotations + +import argparse +import csv +import os +import statistics +import sys +import threading +import time +from pathlib import Path + +ROOT = Path(__file__).resolve().parent.parent +sys.path.insert(0, str(ROOT / 'tests')) +sys.path.insert(0, str(ROOT / 'student-tests')) + +from client import Client # noqa: E402 +from presign_flow import complete, presign, put # noqa: E402 +from lab4_memory_experiment import png_of_size # noqa: E402 + +OUTPUT = ROOT / 'evidence/lab4/track1' + + +def containers(service: str) -> list[str]: + ids = os.popen(f'docker compose ps -q {service}').read().split() + if not ids: + raise SystemExit(f'no running containers for service {service}') + return ids + + +def read_net(service: str) -> tuple[int, int]: + rx = tx = 0 + for container in containers(service): + for direction, path in (('rx', 'rx_bytes'), ('tx', 'tx_bytes')): + value = os.popen( + f'docker exec {container} cat /sys/class/net/eth0/statistics/{path} 2>/dev/null' + ).read().strip() + if value.isdigit(): + if direction == 'rx': + rx += int(value) + else: + tx += int(value) + return rx, tx + + +def read_anon() -> int: + total = 0 + for container in containers('api'): + stats = os.popen(f'docker exec {container} cat /sys/fs/cgroup/memory.stat 2>/dev/null').read() + for line in stats.splitlines(): + if line.startswith('anon '): + total += int(line.split()[1]) + return total + + +class Sampler: + def __init__(self) -> None: + self.stop = threading.Event() + self.peak = 0 + self.thread = threading.Thread(target=self.run, daemon=True) + + def run(self) -> None: + while not self.stop.is_set(): + self.peak = max(self.peak, read_anon()) + time.sleep(0.1) + + def __enter__(self) -> 'Sampler': + self.thread.start() + return self + + def __exit__(self, *_args: object) -> None: + self.stop.set() + self.thread.join(timeout=2) + + +def proxy_upload(client: Client, actor: dict, chat: dict, content: bytes) -> None: + path = '/api/v1/chats/' + chat['id'] + '/attachments?filename=track1.png' + client.call( + 'POST', path, 201, actor=actor, raw=content, + headers={'Content-Type': 'image/png'}, schema='Attachment', + ) + + +def presign_upload(client: Client, actor: dict, chat: dict, content: bytes) -> None: + prepared = presign(client, actor, chat, content) + status = put(prepared['upload_url'], content) + if status != 200: + raise SystemExit(f'presigned PUT failed with {status}') + complete(client, actor, prepared['attachment_id'], prepared['sha256']) + + +def main() -> None: + parser = argparse.ArgumentParser() + parser.add_argument('--base-url', default='http://localhost:8080') + parser.add_argument('--iterations', type=int, default=5) + args = parser.parse_args() + + client = Client(args.base_url, timeout=180) + alice, _, _, chat = client.bootstrap() + + files = { + '~1MiB': png_of_size(700, 500, 11), + '~9MiB': png_of_size(2100, 1500, 12), + } + + OUTPUT.mkdir(parents=True, exist_ok=True) + rows: list[dict[str, object]] = [] + + for label, content in files.items(): + for flow, operation in (('proxy', proxy_upload), ('presign', presign_upload)): + for iteration in range(args.iterations): + lb_before, lb_tx_before = read_net('lb') + api_before, api_tx_before = read_net('api') + started = time.monotonic() + + with Sampler() as sampler: + operation(client, alice, chat, content) + + latency = time.monotonic() - started + lb_after, lb_tx_after = read_net('lb') + api_after, api_tx_after = read_net('api') + + rows.append({ + 'size': label, + 'bytes': len(content), + 'flow': flow, + 'iteration': iteration, + 'latency_s': round(latency, 4), + 'lb_rx_bytes': lb_after - lb_before, + 'lb_tx_bytes': lb_tx_after - lb_tx_before, + 'api_rx_bytes': api_after - api_before, + 'api_tx_bytes': api_tx_after - api_tx_before, + 'api_anon_peak': sampler.peak, + }) + + csv_path = OUTPUT / 'results.csv' + with csv_path.open('w', newline='') as handle: + writer = csv.DictWriter(handle, fieldnames=list(rows[0])) + writer.writeheader() + writer.writerows(rows) + + lines = ['Lab4 track 1: proxy vs presigned upload', ''] + lines.append('| size | flow | median latency, s | p95 latency, s | LB rx, bytes | API rx, bytes | API anon peak, bytes |') + lines.append('|---|---|---:|---:|---:|---:|---:|') + for label in files: + for flow in ('proxy', 'presign'): + group = [row for row in rows if row['size'] == label and row['flow'] == flow] + latencies = sorted(float(row['latency_s']) for row in group) + median = statistics.median(latencies) + p95 = latencies[min(len(latencies) - 1, int(round(0.95 * (len(latencies) - 1))))] + lb_rx = sum(int(row['lb_rx_bytes']) for row in group) / len(group) + api_rx = sum(int(row['api_rx_bytes']) for row in group) / len(group) + peak = max(int(row['api_anon_peak']) for row in group) + lines.append( + f'| {label} | {flow} | {median:.3f} | {p95:.3f} | {lb_rx:.0f} | {api_rx:.0f} | {peak} |' + ) + + lines += [ + '', + 'Note: presigned upload keeps the file body off the API request path and off the load balancer.', + 'Completion still streams the object from S3 once to verify its SHA-256, so api_rx stays close to', + 'the file size; the saving is in the client-facing LB leg and in not accepting/buffering the body.', + '', + ] + summary = OUTPUT / 'summary.txt' + summary.write_text('\n'.join(lines)) + print(summary.read_text()) + print('CSV:', csv_path) + + +if __name__ == '__main__': + main() diff --git a/scripts/lab5_track2.py b/scripts/lab5_track2.py new file mode 100755 index 0000000..fc3d35b --- /dev/null +++ b/scripts/lab5_track2.py @@ -0,0 +1,165 @@ +#!/usr/bin/env python3 +"""Track 2 evidence: versioned pipeline, duplicate delivery, stale-version guard. + +Runs N repetitions against the live stand and writes raw CSV/Markdown evidence. +This is a correctness harness, not a load test. + + python3 scripts/lab5_track2.py --reps 5 +""" +import argparse +import csv +import hashlib +import json +import sys +import time +from pathlib import Path + +ROOT = Path(__file__).resolve().parents[1] +sys.path.insert(0, str(ROOT / 'tests')) +sys.path.insert(0, str(ROOT / 'student-tests')) + +from client import Client, Failure, check # noqa: E402 +from tests_helpers import compose, jobctl, psql # noqa: E402 + +FIXTURE = ROOT / 'tests/fixtures/sample.png' +EVIDENCE = ROOT / 'evidence/lab5/track2' + + +def wait_ready(client, actor, attachment, timeout=90): + deadline = time.monotonic() + timeout + while time.monotonic() < deadline: + current = client.call('GET', '/api/v1/attachments/' + attachment['id'], actor=actor, schema='Attachment')['json'] + check(current['status'] != 'failed', 'attachment failed: ' + str(current.get('error_code'))) + if current['status'] == 'ready': + return current + time.sleep(0.2) + raise Failure('attachment did not become ready') + + +def wait_version(attachment_id, version, timeout=90): + deadline = time.monotonic() + timeout + while time.monotonic() < deadline: + row = psql("select pipeline_version || '|' || status from attachments where id='%s'" % attachment_id) + if row == str(version) + '|ready': + return + time.sleep(0.2) + raise Failure('attachment did not reach pipeline version %d' % version) + + +def variants_by_name(attachment): + return {v['name']: v for v in attachment['variants']} + + +def scenario_duplicate_before_effect(client, actor, chat): + compose('stop', 'worker') + try: + attached, _ = client.attachment(actor, chat) + time.sleep(1) + job = psql("select job_id from attachment_jobs where attachment_id='%s'" % attached['id']) + check(bool(job), 'job id missing') + jobctl('duplicate', '-job', job) + jobctl('duplicate', '-job', job) + finally: + compose('up', '-d', '--no-deps', 'worker', check=False) + + ready = wait_ready(client, actor, attached) + names = sorted(variants_by_name(ready)) + check(names == ['crop', 'optimized', 'thumbnail'], 'duplicate delivery changed the variant set') + check(psql("select count(*) from attachment_variants where attachment_id='%s'" % attached['id']) == '3', + 'duplicate delivery created extra variant rows') + + return 'duplicate_before_effect', True, 'attempts=' + psql( + "select attempt from attachment_jobs where attachment_id='%s'" % attached['id']) + + +def scenario_stale_version(client, actor, chat): + attached, content = client.attachment(actor, chat) + v1 = wait_ready(client, actor, attached) + v1_variants = variants_by_name(v1) + original_sha = hashlib.sha256(content).hexdigest() + check(v1['sha256'] == original_sha, 'original checksum changed before reprocess') + + v1_job = psql("select job_id from attachment_jobs where attachment_id='%s' and pipeline_version=1" % attached['id']) + check(bool(v1_job), 'v1 job missing') + + reprocess = jobctl('reprocess', '-attachment', attached['id'], '-pipeline', '2') + check(reprocess.returncode == 0, 'reprocess failed: ' + reprocess.stderr) + wait_version(attached['id'], 2) + v2 = wait_ready(client, actor, attached) + v2_variants = variants_by_name(v2) + check(sorted(v2_variants) == ['crop', 'optimized', 'thumbnail'], 'v2 variant set incomplete') + check(v2_variants['thumbnail']['sha256'] != v1_variants['thumbnail']['sha256'], + 'v2 bytes must differ from v1 (pipeline parameters changed)') + check(v2['sha256'] == original_sha, 'original changed during reprocess') + before = json.dumps(v2_variants, sort_keys=True) + + # Deliver the old v1 message after v2 is published. It must be acknowledged + # without touching the serving version or its artifacts. + jobctl('duplicate', '-job', v1_job) + time.sleep(2) + + after_attachment = client.call('GET', '/api/v1/attachments/' + attached['id'], actor=actor, schema='Attachment')['json'] + after_variants = variants_by_name(after_attachment) + check(json.dumps(after_variants, sort_keys=True) == before, 'stale v1 delivery overwrote v2 variants') + check(psql("select pipeline_version from attachments where id='%s'" % attached['id']) == '2', + 'serving pipeline version regressed') + check(psql("select status from attachment_jobs where job_id='%s'" % v1_job) == 'ready', + 'v1 job state changed unexpectedly') + + return 'stale_version_after_v2', True, 'v1_job=' + v1_job + + +def main(): + parser = argparse.ArgumentParser(description='Lab5 track 2 correctness harness') + parser.add_argument('--base-url', default='http://localhost:8080') + parser.add_argument('--reps', type=int, default=3) + args = parser.parse_args() + + EVIDENCE.mkdir(parents=True, exist_ok=True) + rows = [] + + client = Client(args.base_url, None) + + for rep in range(1, args.reps + 1): + alice, _, _, chat = client.bootstrap() + for scenario in (scenario_duplicate_before_effect, scenario_stale_version): + name, passed, detail = scenario(client, alice, chat) + rows.append({'scenario': name, 'rep': rep, 'pass': int(passed), 'detail': detail}) + print('D%s rep=%d: %s' % (name, rep, 'PASS' if passed else 'FAIL')) + + with (EVIDENCE / 'runs.csv').open('w', newline='') as handle: + writer = csv.DictWriter(handle, fieldnames=['scenario', 'rep', 'pass', 'detail']) + writer.writeheader() + writer.writerows(rows) + + summary = [ + '# Track 2 — versioned pipeline and duplicate/stale delivery', + '', + 'Hypothesis: with the effect key `(attachment_id, pipeline_version, variant)`,', + 'deterministic object keys, a serving version that changes only when all v2', + 'variants are committed, and stale-version acknowledgements, an at-least-once', + 'pipeline loses no accepted work and never overwrites a newer result with an', + 'older duplicate.', + '', + 'Method: N=%d repetitions. Each repetition creates fresh users/chat and runs:' % args.reps, + '- duplicate pipeline publication while the worker is stopped, followed by recovery;', + '- v1 ready -> explicit reprocess to v2 -> old v1 message delivered after v2 ready.', + '', + 'Invariants checked: unique variant rows per effect key; ready remains ready;', + 'serving pipeline version never regresses; original bytes/checksum unchanged;', + 'stale job state is not rewritten.', + '', + 'Limitations: this harness covers duplicate and stale/reorder delivery. Crash', + 'windows (before/after side effect, before/after ack, outbox gap) and lease', + 'takeover are covered by student-tests/lab5_faults.py; both are single-node', + 'Compose evidence, not a production availability claim. Delivery is', + 'at-least-once; exactly-once is not claimed.', + ] + (EVIDENCE / 'summary.md').write_text('\n'.join(summary) + '\n') + + passed = sum(row['pass'] for row in rows) + print('PASS: track2 %d/%d scenarios' % (passed, len(rows))) + + +if __name__ == '__main__': + main() diff --git a/scripts/lab6_alert_audit.py b/scripts/lab6_alert_audit.py new file mode 100644 index 0000000..764df4f --- /dev/null +++ b/scripts/lab6_alert_audit.py @@ -0,0 +1,81 @@ +#!/usr/bin/env python3 +"""Summarize firing episodes and unfired pending alerts by Track 2 phase.""" +import argparse +import csv +import json +from collections import defaultdict +from datetime import datetime +from pathlib import Path + +PAGE = {"APIErrorBudgetFastBurn", "TTRErrorBudgetFastBurn", "QueueOldestJobAgeCritical", "APISLIMissing"} +TICKET = {"APIErrorBudgetSlowBurn", "TTRErrorBudgetSlowBurn"} + + +def ts(value): + return datetime.fromisoformat(value.replace("Z", "+00:00")) + + +def main(): + parser = argparse.ArgumentParser() + parser.add_argument("--alerts", default="evidence/lab6/track2/full/alerts.csv") + parser.add_argument("--phases", default="evidence/lab6/track2/full/phases.json") + parser.add_argument("--out", default="evidence/lab6/checks/alert-audit.json") + args = parser.parse_args() + + phases = json.loads(Path(args.phases).read_text()) + rows = sorted(csv.DictReader(open(args.alerts)), key=lambda r: r["observed_utc"]) + by_alert = defaultdict(list) + for row in rows: + label = row.get("labels", "") + key = row["alert"] if not label else row["alert"] + "|" + label + by_alert[key].append(row) + + result = [] + for phase in phases: + start, end = ts(phase["started_utc"]), ts(phase["finished_utc"]) + firing = defaultdict(int) + pending_not_fired = defaultdict(int) + for key, events in by_alert.items(): + name = key.split("|", 1)[0] + prev_state = None + for row in events: + if ts(row["observed_utc"]) < start: + prev_state = row["state"] + pending_in_phase = [] + for row in events: + at = ts(row["observed_utc"]) + state = row["state"] + if start <= at <= end: + if state == "firing" and prev_state != "firing": + firing[key] += 1 + if state == "pending": + pending_in_phase.append(row) + if state == "firing" and pending_in_phase: + pending_in_phase.clear() + if state == "resolved": + pending_in_phase.clear() + prev_state = state + pending_not_fired[key] += len(pending_in_phase) + entry = { + "phase": phase["phase"], + "started_utc": phase["started_utc"], + "finished_utc": phase["finished_utc"], + "firing": dict(sorted(firing.items())), + "pending_not_fired": {k: v for k, v in sorted(pending_not_fired.items()) if v}, + } + entry["page"] = sum(v for k, v in firing.items() if k.split("|", 1)[0] in PAGE) + entry["ticket"] = sum(v for k, v in firing.items() if k.split("|", 1)[0] in TICKET) + result.append(entry) + + out = Path(args.out) + out.parent.mkdir(parents=True, exist_ok=True) + out.write_text(json.dumps(result, indent=2) + "\n") + text = "# Alert episodes by phase\n\n| phase | page | ticket | firing | pending-not-fired |\n|---|---:|---:|---|---|\n" + for x in result: + text += f"| {x['phase']} | {x['page']} | {x['ticket']} | {x['firing']} | {x['pending_not_fired']} |\n" + out.with_suffix(".md").write_text(text) + print(text) + + +if __name__ == "__main__": + main() diff --git a/scripts/lab6_alerts.py b/scripts/lab6_alerts.py new file mode 100755 index 0000000..7dd0a70 --- /dev/null +++ b/scripts/lab6_alerts.py @@ -0,0 +1,72 @@ +#!/usr/bin/env python3 +"""Poll Prometheus alert state and write a firing/resolved timeline.""" +import argparse +import os +import csv +import json +import time +import urllib.parse +import urllib.request +from pathlib import Path + + +# The lab tools always target loopback; ignore ambient corporate proxies. +for _proxy_key in ('HTTP_PROXY', 'HTTPS_PROXY', 'ALL_PROXY', 'http_proxy', 'https_proxy', 'all_proxy'): + os.environ.pop(_proxy_key, None) +os.environ['NO_PROXY'] = 'localhost,127.0.0.1,::1' +os.environ['no_proxy'] = 'localhost,127.0.0.1,::1' +urllib.request.getproxies = lambda: {} + + +def get(url): + with urllib.request.urlopen(url, timeout=5) as response: + return json.loads(response.read()) + + +def main(): + parser = argparse.ArgumentParser(description='Poll Prometheus alerts') + parser.add_argument('--prometheus', default='http://localhost:9090') + parser.add_argument('--duration', type=float, default=600) + parser.add_argument('--interval', type=float, default=5) + parser.add_argument('--output', default='evidence/lab6/alerts.csv') + parser.add_argument('--injection-utc', default='') + args = parser.parse_args() + path = Path(args.output) + path.parent.mkdir(parents=True, exist_ok=True) + started = time.time() + active = set() + had_error = False + with path.open('w', newline='') as handle: + writer = csv.writer(handle) + writer.writerow(['observed_utc', 'alert', 'state', 'active_at', 'value', 'injection_utc']) + while time.time() - started < args.duration: + try: + payload = get(args.prometheus.rstrip('/') + '/api/v1/alerts') + current = set() + for alert in payload.get('data', {}).get('alerts', []): + name = alert.get('labels', {}).get('alertname', '') + state = alert.get('state', '') + current.add((name, state)) + if (name, state) not in active: + writer.writerow([ + time.strftime('%Y-%m-%dT%H:%M:%SZ', time.gmtime()), + name, state, alert.get('activeAt', ''), + json.dumps(alert.get('value', ''), separators=(',', ':')), args.injection_utc, + ]) + for name, state in sorted(active - current): + writer.writerow([ + time.strftime('%Y-%m-%dT%H:%M:%SZ', time.gmtime()), + name, 'resolved', '', '', args.injection_utc, + ]) + active = current + handle.flush() + except Exception as exc: + had_error = True + print('WARN: alert poll failed:', exc) + time.sleep(args.interval) + print('alert timeline:', path) + return 1 if had_error else 0 + + +if __name__ == '__main__': + raise SystemExit(main()) diff --git a/scripts/lab6_collector_down.py b/scripts/lab6_collector_down.py new file mode 100644 index 0000000..22b5192 --- /dev/null +++ b/scripts/lab6_collector_down.py @@ -0,0 +1,96 @@ +#!/usr/bin/env python3 +"""Isolated collector outage under load with labeled probes and alert timeline.""" +import argparse +import json +import os +import subprocess +import time +import urllib.parse +import urllib.request +from pathlib import Path + +ROOT = Path(__file__).resolve().parents[1] +for key in ('HTTP_PROXY','HTTPS_PROXY','ALL_PROXY','http_proxy','https_proxy','all_proxy'): + os.environ.pop(key, None) +OPENER = urllib.request.build_opener(urllib.request.ProxyHandler({})) + + +def query(expr): + url = 'http://localhost:9090/api/v1/query?' + urllib.parse.urlencode({'query': expr}) + with OPENER.open(url, timeout=10) as response: + result = json.loads(response.read()).get('data', {}).get('result', []) + return result[0]['value'][1] if result else 'MISSING' + + +def alerts(): + with OPENER.open('http://localhost:9090/api/v1/alerts', timeout=10) as response: + data = json.loads(response.read()).get('data', {}).get('alerts', []) + return [(a['labels'].get('alertname', ''), a['state']) for a in data] + + +def compose(*args, check=True): + return subprocess.run(['docker','compose','--env-file','.env',*args], cwd=ROOT, + capture_output=True, text=True, check=check) + + +def sample(label): + print(label, + 'up=' + query('up{job="otel-collector"}'), + 'api_p99=' + query('histogram_quantile(0.99, sum by (le) (rate(http_server_request_duration_seconds_bucket[5m])))'), + 'api_error_5m=' + query('slo:api_error_ratio:5m'), + 'queue_logs=' + query('max(otelcol_exporter_queue_size{data_type="logs"})'), + 'queue_traces=' + query('max(otelcol_exporter_queue_size{data_type="traces"})'), + 'alerts=' + json.dumps(alerts()), flush=True) + + +def main(): + parser = argparse.ArgumentParser() + parser.add_argument('--duration', type=int, default=300) + args = parser.parse_args() + print('UTC', time.strftime('%Y-%m-%dT%H:%M:%SZ', time.gmtime()), flush=True) + print('HEAD', subprocess.run(['git','rev-parse','HEAD'], cwd=ROOT, capture_output=True, text=True, check=True).stdout.strip(), flush=True) + print('pre_alerts=', json.dumps(alerts()), flush=True) + load_path = ROOT/'evidence/lab6/checks/collector-down-load.json' + load_path.unlink(missing_ok=True) + load_duration = args.duration + 300 + 60 + load = subprocess.Popen([ + 'python3', str(ROOT/'scripts/lab6_load.py'), '--base-url', 'http://localhost:8080', + '--rate', '0.2', '--duration', str(load_duration), '--upload-ratio', '0.2', + '--deadline', '60', '--output', str(load_path), + ], cwd=ROOT, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) + time.sleep(10) + print('$ docker compose ps -a', flush=True) + print(compose('ps','-a').stdout, flush=True) + print('$ docker compose stop otel-collector', flush=True) + print(compose('stop','otel-collector').stdout.strip(), flush=True) + started = time.monotonic() + while time.monotonic() - started < args.duration: + time.sleep(30) + sample('down t=%ss' % int(time.monotonic() - started)) + print('$ docker compose ps -a (down)', flush=True) + print(compose('ps','-a').stdout, flush=True) + print('$ docker compose start otel-collector', flush=True) + print(compose('start','otel-collector').stdout.strip(), flush=True) + started = time.monotonic() + while time.monotonic() - started < 300: + time.sleep(30) + sample('recovery t=%ss' % int(time.monotonic() - started)) + current = alerts() + if not any(name in ('TelemetryCollectorDown', 'CollectorDroppedTelemetry') for name, _ in current): + print('telemetry alerts inactive', flush=True) + break + try: + load.wait(timeout=load_duration + 120) + except subprocess.TimeoutExpired: + load.kill() + load.wait() + print('load_exit=', load.returncode, flush=True) + if load_path.exists(): + data = json.loads(load_path.read_text()) + print('load_summary=', json.dumps({k: data.get(k) for k in ('counters','failures','failures_by_reason','duration_s')}), flush=True) + print('$ docker compose ps -a (final)', flush=True) + print(compose('ps','-a').stdout, flush=True) + + +if __name__ == '__main__': + main() diff --git a/scripts/lab6_load.py b/scripts/lab6_load.py new file mode 100755 index 0000000..abe4a9c --- /dev/null +++ b/scripts/lab6_load.py @@ -0,0 +1,184 @@ +#!/usr/bin/env python3 +"""Open-loop lab6 load: fixed arrival rate, messages and attachment uploads. + +Unlike tests/load.py this schedules arrivals instead of running a closed loop, +so a degraded server cannot reduce the offered rate. It is intentionally small +and standard-library only; use k6/wrk2 for capacity claims. +""" +import argparse +import base64 +import os +import json +import math +import re +import sys +import threading +import time +import urllib.request +import uuid +from pathlib import Path + +# The lab tools always target loopback; ignore ambient corporate proxies. +for _proxy_key in ('HTTP_PROXY', 'HTTPS_PROXY', 'ALL_PROXY', 'http_proxy', 'https_proxy', 'all_proxy'): + os.environ.pop(_proxy_key, None) +os.environ['NO_PROXY'] = 'localhost,127.0.0.1,::1' +os.environ['no_proxy'] = 'localhost,127.0.0.1,::1' +urllib.request.getproxies = lambda: {} + +ROOT = Path(__file__).resolve().parents[1] +sys.path.insert(0, str(ROOT / 'tests')) + + +def percentile(values, p): + if not values: + return None + values = sorted(values) + rank = max(0, min(len(values) - 1, int(math.ceil(p / 100.0 * len(values))) - 1)) + return values[rank] + + +def main(): + parser = argparse.ArgumentParser(description='Open-loop lab6 load') + parser.add_argument('--base-url', default='http://localhost:8080') + parser.add_argument('--rate', type=float, default=1.0, help='arrivals per second') + parser.add_argument('--duration', type=float, default=60.0, help='seconds') + parser.add_argument('--upload-ratio', type=float, default=0.25) + parser.add_argument('--deadline', type=float, default=60.0) + parser.add_argument('--workers', type=int, default=32) + parser.add_argument('--output', default=None) + parser.add_argument('--token-refresh-seconds', type=float, default=2400.0) + args = parser.parse_args() + + from client import Client, Failure + bootstrap = Client(args.base_url, timeout=args.deadline) + alice, _, _, chat = bootstrap.bootstrap() + + lock = threading.Lock() + token_lock = threading.Lock() + last_refresh = [time.monotonic()] + + def refresh_session(): + # Sessions live one hour; refresh well before expiry so a 70m warmup + # does not turn into 401s halfway through. + if time.monotonic() - last_refresh[0] < args.token_refresh_seconds: + return + with token_lock: + if time.monotonic() - last_refresh[0] < args.token_refresh_seconds: + return + registration = alice['registration'] + credential = base64.b64encode( + (registration['username'] + ':' + registration['password']).encode()).decode() + refresher = Client(args.base_url, timeout=args.deadline) + session = refresher.call( + 'POST', '/api/v1/auth/sessions', 201, + headers={'Authorization': 'Basic ' + credential}, schema='Session')['json'] + alice['token'] = session['token'] + last_refresh[0] = time.monotonic() + latencies, ttr, failures = [], [], [] + counters = {'accepted': 0, 'ready': 0, 'failed': 0, 'messages': 0, 'uploads': 0, 'dropped': 0} + failures_by_reason = {} + sem = threading.Semaphore(args.workers) + + def failure_reason(detail): + match = re.search(r'received (\d{3})', detail) + if match: + return 'http_' + match.group(1) + return detail.split(':', 1)[0].strip() or 'unknown' + + def record(kind, elapsed, ok, detail=''): + with lock: + if kind == 'message': + counters['messages'] += 1 + if ok: + latencies.append(elapsed) + else: + reason = failure_reason(detail) + counters['failed'] += 1 + failures_by_reason[reason] = failures_by_reason.get(reason, 0) + 1 + failures.append(detail) + else: + if ok: + counters['ready'] += 1 + ttr.append(elapsed) + else: + reason = failure_reason(detail) + counters['failed'] += 1 + failures_by_reason[reason] = failures_by_reason.get(reason, 0) + 1 + failures.append(detail) + + def run_one(kind, index): + client = Client(args.base_url, timeout=args.deadline) + started = time.monotonic() + try: + refresh_session() + if kind == 'message': + client.message(alice, chat, 'lab6 load %d %s' % (index, uuid.uuid4().hex[:8])) + record(kind, time.monotonic() - started, True) + else: + att, _ = client.attachment(alice, chat) + with lock: + counters['uploads'] += 1 + counters['accepted'] += 1 + try: + client.wait_ready(alice, att, wait_seconds=args.deadline) + record(kind, time.monotonic() - started, True) + except Exception as exc: + with lock: + reason = failure_reason(str(exc)) + counters['failed'] += 1 + failures_by_reason[reason] = failures_by_reason.get(reason, 0) + 1 + failures.append('ready: ' + type(exc).__name__ + ': ' + str(exc)[:120]) + except Exception as exc: + record(kind, time.monotonic() - started, False, type(exc).__name__ + ': ' + str(exc)[:120]) + finally: + sem.release() + + total = max(0, int(args.rate * args.duration)) + started = time.monotonic() + threads = [] + for index in range(total): + target = started + index / max(args.rate, 0.001) + delay = target - time.monotonic() + if delay > 0: + time.sleep(delay) + if not sem.acquire(blocking=False): + with lock: + counters['dropped'] += 1 + continue + kind = 'upload' if ((index * 37) % 100) < int(args.upload_ratio * 100) else 'message' + thread = threading.Thread(target=run_one, args=(kind, index), daemon=True) + threads.append(thread) + thread.start() + + for thread in threads: + thread.join() + + summary = { + 'base_url': args.base_url, + 'rate': args.rate, + 'duration_s': round(time.monotonic() - started, 2), + 'scheduled': total, + 'counters': counters, + 'failures': len(failures), + 'failures_by_reason': dict(sorted(failures_by_reason.items())), + 'failure_samples': failures[:10], + 'latency_ms': { + 'p50': round(percentile(latencies, 50) * 1000, 1) if latencies else None, + 'p95': round(percentile(latencies, 95) * 1000, 1) if latencies else None, + 'p99': round(percentile(latencies, 99) * 1000, 1) if latencies else None, + }, + 'ttr_ms': { + 'p50': round(percentile(ttr, 50) * 1000, 1) if ttr else None, + 'p95': round(percentile(ttr, 95) * 1000, 1) if ttr else None, + 'p99': round(percentile(ttr, 99) * 1000, 1) if ttr else None, + }, + } + if args.output: + Path(args.output).parent.mkdir(parents=True, exist_ok=True) + Path(args.output).write_text(json.dumps(summary, indent=2) + '\n') + print(json.dumps(summary, indent=2)) + return 0 if not failures else 1 + + +if __name__ == '__main__': + raise SystemExit(main()) diff --git a/scripts/lab6_storage_down_series.py b/scripts/lab6_storage_down_series.py new file mode 100644 index 0000000..766e6d4 --- /dev/null +++ b/scripts/lab6_storage_down_series.py @@ -0,0 +1,123 @@ +#!/usr/bin/env python3 +"""Isolated telemetry-storage outage under load, with baseline/recovery and cgroup data.""" +import argparse +import json +import os +import subprocess +import time +import urllib.parse +import urllib.request +from pathlib import Path + +ROOT = Path(__file__).resolve().parents[1] +for key in ('HTTP_PROXY','HTTPS_PROXY','ALL_PROXY','http_proxy','https_proxy','all_proxy'): + os.environ.pop(key, None) +OPENER = urllib.request.build_opener(urllib.request.ProxyHandler({})) + + +def prom(expr): + url = 'http://localhost:9090/api/v1/query?' + urllib.parse.urlencode({'query': expr}) + with OPENER.open(url, timeout=10) as response: + result = json.loads(response.read()).get('data', {}).get('result', []) + return result[0]['value'][1] if result else 'MISSING' + + +def labels(expr, label): + url = 'http://localhost:9090/api/v1/query?' + urllib.parse.urlencode({'query': expr}) + with OPENER.open(url, timeout=10) as response: + result = json.loads(response.read()).get('data', {}).get('result', []) + return [r['metric'].get(label, '') for r in result] + + +def compose(*args, check=True): + return subprocess.run(['docker','compose','--env-file','.env',*args], cwd=ROOT, + capture_output=True, text=True, check=check) + + +def cgroup_stats(): + output = subprocess.run(['docker','stats','--no-stream','--format','{{.Name}} {{.MemUsage}} {{.MemPerc}}',], + capture_output=True, text=True, check=True).stdout + return [line.strip() for line in output.splitlines() if any(s in line for s in ('api-','collector'))] + + +def sample(phase): + return { + 'phase': phase, + 'utc': time.strftime('%Y-%m-%dT%H:%M:%SZ', time.gmtime()), + 'api_memory': prom('max by (service_instance_id) (messenger_process_memory_usage_bytes{service_name="messenger-api"})'), + 'collector_rss': prom('max(otelcol_process_memory_rss)'), + 'collector_heap': prom('max(otelcol_process_runtime_heap_alloc_bytes)'), + 'queue_logs': prom('max(otelcol_exporter_queue_size{data_type="logs"})'), + 'queue_traces': prom('max(otelcol_exporter_queue_size{data_type="traces"})'), + 'sent_spans': prom('sum(rate(otelcol_exporter_sent_spans[5m]))'), + 'send_failed_spans': prom('sum(rate(otelcol_exporter_send_failed_spans[5m]))'), + 'enqueue_failed_spans': prom('sum(rate(otelcol_exporter_enqueue_failed_spans[5m]))'), + 'accepted_logs': prom('sum(rate(otelcol_receiver_accepted_log_records[5m]))'), + 'api_error_5m': prom('slo:api_error_ratio:5m'), + 'api_p99': prom('histogram_quantile(0.99, sum by (le) (rate(http_server_request_duration_seconds_bucket[5m])))'), + 'api_instances': labels('messenger_process_memory_usage_bytes{service_name="messenger-api"}', 'service_instance_id'), + 'cgroup': cgroup_stats(), + } + + +def main(): + parser = argparse.ArgumentParser() + parser.add_argument('--baseline', type=int, default=60) + parser.add_argument('--duration', type=int, default=300) + parser.add_argument('--recovery', type=int, default=300) + parser.add_argument('--out', default='evidence/lab6/storage-down-series.json') + args = parser.parse_args() + load_path = ROOT/'evidence/lab6/checks/storage-down-load.json' + load_path.unlink(missing_ok=True) + load_duration = args.baseline + args.duration + args.recovery + 120 + load = subprocess.Popen([ + 'python3', str(ROOT/'scripts/lab6_load.py'), '--base-url', 'http://localhost:8080', + '--rate', '0.2', '--duration', str(load_duration), + '--upload-ratio', '0.2', '--deadline', '60', + '--output', str(load_path), + ], cwd=ROOT, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) + samples = [] + try: + for _ in range(args.baseline // 10): + time.sleep(10) + samples.append(sample('baseline')) + compose('stop','loki','tempo') + samples.append(sample('down-start')) + started = time.monotonic() + while time.monotonic() - started < args.duration: + time.sleep(10) + samples.append(sample('down')) + compose('start','loki','tempo') + samples.append(sample('recovery-start')) + started = time.monotonic() + zero_streak = 0 + while time.monotonic() - started < args.recovery: + time.sleep(10) + samples.append(sample('recovery')) + logs_zero = prom('max(otelcol_exporter_queue_size{data_type="logs"})') in ('0','0.0') + traces_zero = prom('max(otelcol_exporter_queue_size{data_type="traces"})') in ('0','0.0') + if logs_zero and traces_zero: + zero_streak += 1 + if zero_streak >= 2: + break + else: + zero_streak = 0 + finally: + compose('start','loki','tempo') + try: + load.wait(timeout=load_duration + 120) + except subprocess.TimeoutExpired: + load.kill() + load.wait() + print('load_exit=', load.returncode, flush=True) + if load_path.exists(): + data = json.loads(load_path.read_text()) + print('load_summary=', json.dumps({k: data.get(k) for k in ('counters','failures','failures_by_reason','duration_s')}), flush=True) + out = ROOT / args.out + out.parent.mkdir(parents=True, exist_ok=True) + out.write_text(json.dumps(samples, indent=2) + '\n') + print(json.dumps(samples, indent=2)) + + +if __name__ == '__main__': + main() diff --git a/scripts/lab6_track2.py b/scripts/lab6_track2.py new file mode 100755 index 0000000..9966b51 --- /dev/null +++ b/scripts/lab6_track2.py @@ -0,0 +1,91 @@ +#!/usr/bin/env python3 +"""Lab6 track 2 scenario driver: burst, sustained outage and false-positive phases. + +It starts the open-loop load, injects a PostgreSQL fault, records alert state and +restores the stand. Use --quick for a short evidence run; the full 15-minute +sustained phase is the graded scenario. +""" +import argparse +import os +import json +import subprocess +import sys +import time +from pathlib import Path + +# The lab tools always target loopback; ignore ambient corporate proxies. +for _proxy_key in ('HTTP_PROXY', 'HTTPS_PROXY', 'ALL_PROXY', 'http_proxy', 'https_proxy', 'all_proxy'): + os.environ.pop(_proxy_key, None) +os.environ['NO_PROXY'] = 'localhost,127.0.0.1,::1' +os.environ['no_proxy'] = 'localhost,127.0.0.1,::1' + +ROOT = Path(__file__).resolve().parents[1] + + +def compose(*args, check=True): + command = ['docker', 'compose', '--env-file', '.env', '-f', 'compose.yaml', *args] + return subprocess.run(command, cwd=ROOT, check=check) + + +def stamp(): + return time.strftime('%Y-%m-%dT%H:%M:%SZ', time.gmtime()) + + +def main(): + parser = argparse.ArgumentParser(description='Lab6 track 2 scenarios') + parser.add_argument('--scenario', choices=['burst', 'sustained', 'false-positive'], default='burst') + parser.add_argument('--quick', action='store_true', help='short 20s phases') + parser.add_argument('--base-url', default='http://localhost:8080') + parser.add_argument('--load-rate', type=float, default=0.5) + parser.add_argument('--output-dir', default='evidence/lab6/track2') + args = parser.parse_args() + out = ROOT / args.output_dir + out.mkdir(parents=True, exist_ok=True) + duration = 20 if args.quick else (120 if args.scenario == 'burst' else 900) + if args.scenario == 'false-positive': + duration = 20 if args.quick else 300 + + load = subprocess.Popen([ + sys.executable, str(ROOT / 'scripts/lab6_load.py'), + '--base-url', args.base_url, '--rate', str(args.load_rate), + '--duration', str(duration + 20), '--upload-ratio', '0.2', + '--output', str(out / (args.scenario + '-load.json')), + ], cwd=ROOT) + alerts = subprocess.Popen([ + sys.executable, str(ROOT / 'scripts/lab6_alerts.py'), + '--duration', str(duration + 20), '--output', str(out / (args.scenario + '-alerts.csv')), + ], cwd=ROOT) + + time.sleep(5) + injection = stamp() + try: + if args.scenario == 'burst': + compose('pause', 'postgres') + elif args.scenario == 'sustained': + compose('stop', 'worker') + compose('stop', 'postgres') + time.sleep(duration) + finally: + if args.scenario == 'burst': + compose('unpause', 'postgres', check=False) + elif args.scenario == 'sustained': + compose('start', 'postgres', check=False) + time.sleep(5) + compose('up', '-d', '--no-deps', 'worker', check=False) + restore = stamp() + Path(out / (args.scenario + '-phases.json')).write_text(json.dumps({ + 'scenario': args.scenario, + 'injection_utc': injection, + 'restore_utc': restore, + 'duration_seconds': duration, + }, indent=2) + '\n') + time.sleep(10) + + load_rc = load.wait(timeout=duration + 60) + alerts_rc = alerts.wait(timeout=duration + 60) + print('track2 evidence:', out, 'load_rc=', load_rc, 'alerts_rc=', alerts_rc) + return 1 if alerts_rc != 0 else 0 + + +if __name__ == '__main__': + raise SystemExit(main()) diff --git a/scripts/lab6_track2_full.py b/scripts/lab6_track2_full.py new file mode 100755 index 0000000..774c75d --- /dev/null +++ b/scripts/lab6_track2_full.py @@ -0,0 +1,395 @@ +#!/usr/bin/env python3 +"""Full Track 2 timeline with fail-fast, preflight and guaranteed restore. + +Warmup >= 70m, baseline, 2m burst, 15m sustained outage, resolution, TTR and +false-positive phases. The script records injection/restore timestamps, alert +transitions and Prometheus snapshots before and after each fault. +""" +import argparse +import csv +import json +import os +import signal +import subprocess +import sys +import threading +import time +import urllib.parse +import urllib.request +from pathlib import Path + +for _key in ('HTTP_PROXY', 'HTTPS_PROXY', 'ALL_PROXY', 'http_proxy', 'https_proxy', 'all_proxy'): + os.environ.pop(_key, None) +os.environ['NO_PROXY'] = 'localhost,127.0.0.1,::1' +os.environ['no_proxy'] = 'localhost,127.0.0.1,::1' +# tests/client.py builds its own opener; make it ignore macOS system proxies too. +urllib.request.getproxies = lambda: {} +OPENER = urllib.request.build_opener(urllib.request.ProxyHandler({})) + +ROOT = Path(__file__).resolve().parents[1] +ACTIVE_LOAD = [None] + + +def utc(ts=None): + return time.strftime('%Y-%m-%dT%H:%M:%SZ', time.gmtime(ts if ts is not None else time.time())) + + +def http_json(url, timeout=15): + with OPENER.open(url, timeout=timeout) as response: + return json.loads(response.read()) + + +def prom(expr): + url = 'http://localhost:9090/api/v1/query?' + urllib.parse.urlencode({'query': expr}) + return http_json(url).get('data', {}).get('result', []) + + +def alerts(): + return http_json('http://localhost:9090/api/v1/alerts').get('data', {}).get('alerts', []) + + +def compose(*args, check=True): + result = subprocess.run( + ['docker', 'compose', '--env-file', '.env', '-f', 'compose.yaml', *args], + cwd=ROOT, capture_output=True, text=True, check=False, + ) + (ROOT / 'evidence/lab6/track2').mkdir(parents=True, exist_ok=True) + with (ROOT / 'evidence/lab6/track2/full-compose.log').open('a') as log: + log.write(utc() + ' docker compose ' + ' '.join(args) + ' rc=' + str(result.returncode) + '\n') + if result.stderr: + log.write(result.stderr[-2000:] + '\n') + if check and result.returncode != 0: + raise RuntimeError('docker compose %s failed rc=%d: %s' % (' '.join(args), result.returncode, result.stderr[-500:])) + return result + + +def wait_ready(timeout=120): + deadline = time.time() + timeout + while time.time() < deadline: + try: + with OPENER.open('http://localhost:8080/health/ready', timeout=5) as response: + if response.status == 200: + return True + except Exception: + pass + time.sleep(2) + return False + + +class AlertTimeline: + def __init__(self, path): + self.path = path + self.stop = threading.Event() + self.active = {} + self.changes = [] + self.injection = '' + self.lock = threading.Lock() + path.parent.mkdir(parents=True, exist_ok=True) + self.handle = path.open('w', newline='') + self.writer = csv.writer(self.handle) + self.writer.writerow(['observed_utc', 'alert', 'state', 'active_at', 'value', 'injection_utc', 'labels']) + self.thread = threading.Thread(target=self.run, daemon=True) + + def start(self): + self.thread.start() + + def run(self): + while not self.stop.is_set(): + try: + current = {} + for alert in alerts(): + state = alert.get('state', '') + if state not in ('pending', 'firing'): + continue + labels = alert.get('labels', {}) + name = labels.get('alertname', '') + key = name + '|' + json.dumps(labels, sort_keys=True, separators=(',', ':')) + current[key] = (name, state, alert.get('activeAt', ''), alert.get('value', ''), labels) + for key, (name, state, active_at, value, labels) in current.items(): + previous = self.active.get(key) + if previous is None or previous[1] != state: + row = [utc(), name, state, active_at, value, self.injection, json.dumps(labels, sort_keys=True, separators=(',', ':'))] + with self.lock: + self.changes.append(row) + self.writer.writerow(row) + self.handle.flush() + for key in sorted(set(self.active) - set(current)): + name, state, _, _, labels = self.active[key] + if state != 'firing': + continue + row = [utc(), name, 'resolved', '', '', self.injection, json.dumps(labels, sort_keys=True, separators=(',', ':'))] + with self.lock: + self.changes.append(row) + self.writer.writerow(row) + self.handle.flush() + self.active = current + except Exception as exc: + with self.lock: + self.writer.writerow([utc(), 'POLL_ERROR', str(exc)[:160], '', '', self.injection]) + self.handle.flush() + self.stop.wait(5) + + def finish(self): + self.stop.set() + self.thread.join(timeout=20) + self.handle.close() + return self.changes + + +def snapshot(out, label): + values = {} + errors = [] + for name, expr in { + 'api_error_5m': 'slo:api_error_ratio:5m', + 'api_error_1h': 'slo:api_error_ratio:1h', + 'api_error_30m': 'slo:api_error_ratio:30m', + 'api_error_6h': 'slo:api_error_ratio:6h', + 'ttr_bad_5m': 'slo:job_ttr_bad_ratio:5m', + 'ttr_bad_1h': 'slo:job_ttr_bad_ratio:1h', + 'queue_oldest': 'max(messenger_queue_oldest_job_age_seconds)', + 'queue_depth': 'max(rabbitmq_queue_messages_ready{queue="attachment.process.v1"})', + 'jobs_overdue': 'max(messenger_jobs_overdue)', + 'worker_busy': 'max(messenger_worker_busy)', + }.items(): + try: + result = prom(expr) + values[name] = result[0]['value'][1] if result else None + except Exception as exc: + values[name] = None + errors.append(name + ': ' + str(exc)[:100]) + (out / 'snapshots').mkdir(parents=True, exist_ok=True) + (out / 'snapshots' / (label + '-' + utc().replace(':', '-') + '.json')).write_text(json.dumps(values, indent=2) + '\n') + if errors: + raise RuntimeError('Prometheus snapshot failed: ' + '; '.join(errors)) + return values + + +def run_load(out, label, duration, ratio=0.2, rate=0.2): + log_path = out / (label + '-load.log') + output_path = out / (label + '-load.json') + cmd = [sys.executable, str(ROOT / 'scripts/lab6_load.py'), + '--base-url', 'http://localhost:8080', '--rate', str(rate), + '--duration', str(duration), '--upload-ratio', str(ratio), + '--deadline', '60', '--output', str(output_path)] + log = log_path.open('w') + process = subprocess.Popen(cmd, cwd=ROOT, stdout=log, stderr=subprocess.STDOUT) + ACTIVE_LOAD[0] = (process, log, output_path) + return process, log, output_path + + +def finish_load(process, log, output_path, label, expected_s, allow_failures=False): + try: + rc = process.wait(timeout=expected_s + 300) + except subprocess.TimeoutExpired: + process.kill() + rc = process.wait() + log.close() + ACTIVE_LOAD[0] = None + if not output_path.exists(): + raise RuntimeError(label + ': load produced no JSON (rc=' + str(rc) + ')') + summary = json.loads(output_path.read_text()) + minimum = 0.85 * expected_s if expected_s >= 30 else 0.5 * expected_s + if summary.get('duration_s', 0) < minimum: + raise RuntimeError(label + ': load ran only ' + str(summary.get('duration_s')) + 's, expected ~' + str(expected_s)) + if not allow_failures and (rc != 0 or summary.get('failures', 0)): + raise RuntimeError(label + ': load failed rc=' + str(rc) + ' failures=' + str(summary.get('failures'))) + return summary + + +def restore_stand(): + compose('unpause', 'postgres', check=False) + compose('start', 'postgres', check=False) + compose('up', '-d', '--wait', '--no-deps', 'worker', check=False) + return wait_ready(120) + + +def phase(out, phases, name, started, injection='', restore=''): + value = { + 'phase': name, + 'started_utc': utc(started), + 'finished_utc': utc(), + 'duration_s': round(time.time() - started, 1), + 'injection_utc': injection, + 'restore_utc': restore, + } + phases.append(value) + (out / 'phases.json').write_text(json.dumps(phases, indent=2) + '\n') + + +def main(): + parser = argparse.ArgumentParser(description='Full lab6 Track 2 timeline') + parser.add_argument('--warmup', type=int, default=4200) + parser.add_argument('--baseline', type=int, default=1200) + parser.add_argument('--burst', type=int, default=120) + parser.add_argument('--settle', type=int, default=600) + parser.add_argument('--sustained', type=int, default=900) + parser.add_argument('--resolution', type=int, default=3600) + parser.add_argument('--ttr', type=int, default=900) + parser.add_argument('--false-positive', type=int, default=1200) + parser.add_argument('--out', default='evidence/lab6/track2/full') + args = parser.parse_args() + out = ROOT / args.out + out.mkdir(parents=True, exist_ok=True) + phases = [] + timeline = AlertTimeline(out / 'alerts.csv') + timeline.start() + interrupted = False + exit_code = 0 + try: + def on_signal(signum, _frame): + raise KeyboardInterrupt('signal %d' % signum) + signal.signal(signal.SIGINT, on_signal) + signal.signal(signal.SIGTERM, on_signal) + + if not wait_ready(120): + raise RuntimeError('preflight: /health/ready is not ready') + preflight = run_load(out, 'preflight', 3, ratio=0.5, rate=1.0) + finish_load(*preflight, 'preflight', 3, allow_failures=False) + print(utc(), 'preflight OK; start full track', flush=True) + + t = time.time() + load = run_load(out, 'warmup', args.warmup) + print(utc(), 'warmup started', flush=True) + finish_load(*load, 'warmup', args.warmup) + phase(out, phases, 'warmup', t) + snapshot(out, 'warmup') + + t = time.time() + load = run_load(out, 'baseline', args.baseline) + print(utc(), 'baseline started', flush=True) + finish_load(*load, 'baseline', args.baseline) + phase(out, phases, 'baseline', t) + (out / 'baseline.json').write_text(json.dumps(snapshot(out, 'baseline'), indent=2) + '\n') + + t = time.time() + load = run_load(out, 'burst', args.burst + args.settle) + time.sleep(10) + injection = utc() + timeline.injection = injection + print(utc(), 'burst: pause postgres', flush=True) + compose('pause', 'postgres') + time.sleep(min(30, args.burst)) + burst_active = snapshot(out, 'burst-active') + if args.burst > 30: + time.sleep(args.burst - 30) + compose('unpause', 'postgres') + restore = utc() + print(utc(), 'burst: unpause postgres', flush=True) + finish_load(*load, 'burst', args.burst + args.settle, allow_failures=True) + phase(out, phases, 'burst', t, injection, restore) + burst_after = snapshot(out, 'burst-after') + (out / 'burst.json').write_text(json.dumps({'active': burst_active, 'after': burst_after}, indent=2) + '\n') + + t = time.time() + load = run_load(out, 'sustained', args.sustained + 300) + time.sleep(10) + injection = utc() + timeline.injection = injection + print(utc(), 'sustained: stop postgres', flush=True) + compose('stop', 'postgres') + time.sleep(min(30, args.sustained)) + sustained_active = snapshot(out, 'sustained-active') + if args.sustained > 30: + time.sleep(args.sustained - 30) + compose('start', 'postgres') + if not wait_ready(180): + raise RuntimeError('sustained: readiness did not recover') + restore = utc() + print(utc(), 'sustained: postgres restored', flush=True) + finish_load(*load, 'sustained', args.sustained + 300, allow_failures=True) + drained = wait_queue_drain(300) + phase(out, phases, 'sustained', t, injection, restore) + sustained_after = snapshot(out, 'sustained-after') + (out / 'sustained.json').write_text(json.dumps({'active': sustained_active, 'after': sustained_after, 'queue_drained': drained}, indent=2) + '\n') + + print(utc(), 'resolution under normal load', flush=True) + t = time.time() + load = run_load(out, 'resolution', args.resolution) + finish_load(*load, 'resolution', args.resolution) + phase(out, phases, 'resolution_wait', t) + snapshot(out, 'resolution') + + t = time.time() + compose('stop', 'worker') + load = run_load(out, 'ttr', args.ttr, ratio=1.0) + time.sleep(10) + injection = utc() + timeline.injection = injection + print(utc(), 'ttr: worker stopped and uploads started', flush=True) + time.sleep(args.ttr) + compose('up', '-d', '--no-deps', 'worker') + restore = utc() + finish_load(*load, 'ttr', args.ttr, allow_failures=True) + wait_queue_drain(300) + phase(out, phases, 'ttr', t, injection, restore) + snapshot(out, 'ttr-after') + + t = time.time() + load = run_load(out, 'false-positive', args.false_positive) + print(utc(), 'false-positive phase started', flush=True) + finish_load(*load, 'false-positive', args.false_positive) + phase(out, phases, 'false-positive', t) + final = snapshot(out, 'final') + (out / 'final.json').write_text(json.dumps(final, indent=2) + '\n') + + except BaseException as exc: + interrupted = True + (out / 'aborted.json').write_text(json.dumps({'aborted_utc': utc(), 'error': repr(exc)}, indent=2) + '\n') + print(utc(), 'ABORT', repr(exc), flush=True) + raise + finally: + if ACTIVE_LOAD[0] is not None: + process, log, _ = ACTIVE_LOAD[0] + if process.poll() is None: + process.terminate() + try: + process.wait(timeout=10) + except subprocess.TimeoutExpired: + process.kill() + process.wait() + log.close() + ACTIVE_LOAD[0] = None + restored = restore_stand() + if not restored and not interrupted: + exit_code = 1 + changes = timeline.finish() + (out / 'alerts.json').write_text(json.dumps(changes, indent=2) + '\n') + try: + final_summary = snapshot(out, 'final-summary') + except Exception as exc: + final_summary = {'error': str(exc)[:200]} + (out / 'summary.md').write_text( + '# Full Track 2 run\n\nPhases:\n```json\n' + json.dumps(phases, indent=2) + + '\n```\n\nFinal snapshot:\n```json\n' + json.dumps(final_summary, indent=2) + + '\n```\n\nAborted: ' + str(interrupted) + '\nRestored: ' + str(restored) + '\n') + print(utc(), 'done; evidence', out, flush=True) + return exit_code + + +def wait_queue_drain(timeout=300): + deadline = time.time() + timeout + good = 0 + while time.time() < deadline: + try: + oldest = prom('max(messenger_queue_oldest_job_age_seconds)') + depth = prom('max(rabbitmq_queue_messages_ready{queue="attachment.process.v1"})') + if not oldest or not depth: + good = 0 + time.sleep(10) + continue + oldest_v = float(oldest[0]['value'][1]) + depth_v = float(depth[0]['value'][1]) + if oldest_v < 5 and depth_v < 5: + good += 1 + if good >= 2: + return True + else: + good = 0 + except Exception: + good = 0 + time.sleep(10) + return False + + +if __name__ == '__main__': + raise SystemExit(main()) diff --git a/scripts/lab6_ttr_worker_down.py b/scripts/lab6_ttr_worker_down.py new file mode 100644 index 0000000..6b719d3 --- /dev/null +++ b/scripts/lab6_ttr_worker_down.py @@ -0,0 +1,110 @@ +#!/usr/bin/env python3 +"""Isolated 15-minute worker outage with TTR/queue/alert samples.""" +import argparse +import json +import os +import subprocess +import time +import urllib.parse +import urllib.request +from pathlib import Path + +ROOT = Path(__file__).resolve().parents[1] +for key in ('HTTP_PROXY','HTTPS_PROXY','ALL_PROXY','http_proxy','https_proxy','all_proxy'): + os.environ.pop(key, None) +OPENER = urllib.request.build_opener(urllib.request.ProxyHandler({})) + + +def prom(expr): + url = 'http://localhost:9090/api/v1/query?' + urllib.parse.urlencode({'query': expr}) + with OPENER.open(url, timeout=10) as response: + result = json.loads(response.read()).get('data', {}).get('result', []) + return result[0]['value'][1] if result else 'MISSING' + + +def alerts(): + with OPENER.open('http://localhost:9090/api/v1/alerts', timeout=10) as response: + data = json.loads(response.read()).get('data', {}).get('alerts', []) + return [(a['labels'].get('alertname', ''), a['state']) for a in data] + + +def compose(*args, check=True): + return subprocess.run(['docker','compose','--env-file','.env',*args], cwd=ROOT, + capture_output=True, text=True, check=check) + + +def main(): + parser = argparse.ArgumentParser() + parser.add_argument('--duration', type=int, default=930, help='sampling window seconds') + parser.add_argument('--loads', type=int, default=1, help='initial load users') + parser.add_argument('--spawn-every', type=int, default=90, help='start a new load user every N seconds') + args = parser.parse_args() + print('UTC', time.strftime('%Y-%m-%dT%H:%M:%SZ', time.gmtime()), flush=True) + print('HEAD', subprocess.run(['git','rev-parse','HEAD'], cwd=ROOT, capture_output=True, text=True, check=True).stdout.strip(), flush=True) + print('$ /api/v1/rules (contains or vector(0))', flush=True) + with OPENER.open('http://localhost:9090/api/v1/rules', timeout=10) as response: + rules = response.read().decode() + print('or_vector_0=', 'or vector(0)' in rules, flush=True) + print('json_len=', len(rules), flush=True) + print('$ pre ALERTS', alerts(), flush=True) + + loads = [] + + def start_load(): + index = len(loads) + loads.append(subprocess.Popen([ + 'python3', str(ROOT/'scripts/lab6_load.py'), '--base-url', 'http://localhost:8080', + '--rate', '0.2', '--duration', '1000', '--upload-ratio', '1', + '--deadline', '60', '--output', '/tmp/lab6-ttr-worker-load-%d.json' % index, + ], cwd=ROOT, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)) + + for _ in range(args.loads): + start_load() + time.sleep(5) + print('$ stop worker', flush=True) + print(compose('stop','worker').stdout.strip(), flush=True) + + started = time.monotonic() + while time.monotonic() - started < args.duration: + time.sleep(30) + elapsed = int(time.monotonic() - started) + if args.spawn_every > 0 and elapsed and elapsed % args.spawn_every == 0: + start_load() + print( + 't=%ss '%elapsed + + 'ratio5=' + prom('slo:job_ttr_bad_ratio:5m') + + ' ratio1h=' + prom('slo:job_ttr_bad_ratio:1h') + + ' missed_total=' + prom('sum(messenger_jobs_ttr_missed_total)') + + ' missed_inc5=' + prom('sum(increase(messenger_jobs_ttr_missed_total[5m]))') + + ' bucket_count=' + prom('count(messenger_job_time_to_ready_seconds_bucket)') + + ' overdue=' + prom('max(messenger_jobs_overdue)') + + ' oldest=' + prom('max(messenger_queue_oldest_job_age_seconds)') + + ' alerts=' + json.dumps(alerts()), + flush=True, + ) + + print('$ start worker', flush=True) + print(compose('start','worker').stdout.strip(), flush=True) + for elapsed in (30, 60, 120, 180, 240, 300): + time.sleep(30 if elapsed == 30 else 30) + print( + 'recovery t=%ss '%elapsed + + 'ratio5=' + prom('slo:job_ttr_bad_ratio:5m') + + ' ratio1h=' + prom('slo:job_ttr_bad_ratio:1h') + + ' missed_total=' + prom('sum(messenger_jobs_ttr_missed_total)') + + ' overdue=' + prom('max(messenger_jobs_overdue)') + + ' oldest=' + prom('max(messenger_queue_oldest_job_age_seconds)') + + ' alerts=' + json.dumps(alerts()), + flush=True, + ) + for load in loads: + load.terminate() + for load in loads: + try: + load.wait(timeout=15) + except subprocess.TimeoutExpired: + load.kill() + + +if __name__ == '__main__': + main() diff --git a/scripts/lab6_verify.py b/scripts/lab6_verify.py new file mode 100755 index 0000000..a2ef391 --- /dev/null +++ b/scripts/lab6_verify.py @@ -0,0 +1,314 @@ +#!/usr/bin/env python3 +"""Strict lab6 observability gate. + +It creates a fresh message and attachment, waits for all three signals, checks +route/template cardinality, Grafana provisioning and rules, and verifies that +user content and credentials never reached Loki. A missing signal is a failure, +not a warning. +""" +import argparse +import os +import base64 +import json +import re +import sys +import time +import urllib.error +import urllib.parse +import urllib.request +import uuid +from pathlib import Path + +# The lab tools always target loopback; ignore ambient corporate proxies. +for _proxy_key in ('HTTP_PROXY', 'HTTPS_PROXY', 'ALL_PROXY', 'http_proxy', 'https_proxy', 'all_proxy'): + os.environ.pop(_proxy_key, None) +os.environ['NO_PROXY'] = 'localhost,127.0.0.1,::1' +os.environ['no_proxy'] = 'localhost,127.0.0.1,::1' +urllib.request.getproxies = lambda: {} + +ROOT = Path(__file__).resolve().parents[1] +UUID_RE = re.compile(r'[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}', re.I) +FORBIDDEN_LABELS = {'user_id', 'chat_id', 'message_id', 'attachment_id', 'filename', 'request_id', 'object_key', 'path', 'query'} + + +def request(url, auth=None, timeout=10): + headers = {'Accept': 'application/json'} + if auth: + headers['Authorization'] = 'Basic ' + base64.b64encode(auth.encode()).decode() + req = urllib.request.Request(url, headers=headers) + with urllib.request.urlopen(req, timeout=timeout) as response: + return response.status, response.read() + + +def prom(base, expr): + url = base.rstrip('/') + '/api/v1/query?' + urllib.parse.urlencode({'query': expr}) + _, raw = request(url) + return json.loads(raw).get('data', {}).get('result', []) + + +def prom_series(base, match): + url = base.rstrip('/') + '/api/v1/series?' + urllib.parse.urlencode({'match[]': match}) + _, raw = request(url) + return json.loads(raw).get('data', []) + + +def loki_query(base, query, start_ns, end_ns, limit=20): + params = urllib.parse.urlencode({'query': query, 'start': start_ns, 'end': end_ns, 'limit': limit}) + _, raw = request(base.rstrip('/') + '/loki/api/v1/query_range?' + params) + return json.loads(raw).get('data', {}).get('result', []) + + +def grafana_password(): + path = ROOT / 'secrets/grafana.env' + if not path.exists(): + return None + for line in path.read_text().splitlines(): + if '=' in line and line.split('=', 1)[0].strip() == 'GF_SECURITY_ADMIN_PASSWORD': + return line.split('=', 1)[1].strip() + return None + + +def wait_for(fn, attempts=30, delay=2): + last = None + for _ in range(attempts): + try: + value = fn() + if value: + return value + except Exception as exc: # noqa: BLE001 - retry the external endpoint + last = exc + time.sleep(delay) + if last: + raise last + return None + + +def main(): + parser = argparse.ArgumentParser(description='Strict lab6 telemetry gate') + parser.add_argument('--base-url', default='http://localhost:8080') + parser.add_argument('--prometheus', default='http://localhost:9090') + parser.add_argument('--loki', default='http://localhost:3100') + parser.add_argument('--tempo', default='http://localhost:3200') + parser.add_argument('--grafana', default='http://localhost:3000') + parser.add_argument('--wait-seconds', type=int, default=60) + args = parser.parse_args() + failures = [] + notes = [] + + # 1. Generate a controlled request, a message and a job. + sys.path.insert(0, str(ROOT / 'tests')) + from client import Client + client = Client(args.base_url, timeout=15) + alice, _, _, chat = client.bootstrap() + request_id = 'lab6-verify-' + uuid.uuid4().hex + sentinel = 'SENTINEL-TELEMETRY-' + uuid.uuid4().hex + client.call('POST', '/api/v1/chats/' + chat['id'] + '/messages', 201, actor=alice, + body={'text': sentinel}, headers={'Idempotency-Key': uuid.uuid4().hex, 'X-Request-ID': request_id}) + att, content = client.attachment(alice, chat) + client.wait_ready(alice, att, wait_seconds=60) + filename = 'sentinel-' + uuid.uuid4().hex + '.png' + from urllib.parse import quote + client.call('POST', '/api/v1/chats/' + chat['id'] + '/attachments?filename=' + quote(filename), 202, + actor=alice, raw=content, headers={'Content-Type': 'image/png'}, schema='Attachment') + token = alice.get('token', '') + notes.append('created request_id=' + request_id) + + # 2. Required metric series. Counter/histogram series can take one export + # and one scrape interval to appear. + required = [ + ('http_server_request_duration_seconds_count', 'HTTP request histogram count'), + ('http_server_request_duration_seconds_bucket', 'HTTP duration histogram'), + ('messenger_jobs_processed_total', 'job attempt counter'), + ('messenger_jobs_accepted_total', 'accepted jobs'), + ('messenger_jobs_ready_within_budget_total', 'ready-within-budget'), + ('messenger_job_duration_seconds_bucket', 'job duration histogram'), + ('messenger_job_time_to_ready_seconds_bucket', 'time-to-ready histogram'), + ('messenger_jobs_overdue', 'overdue jobs'), + ('messenger_worker_busy', 'worker saturation'), + ('messenger_db_pool_used', 'DB pool'), + ('messenger_queue_oldest_job_age_seconds', 'oldest job age'), + ('messenger_outbox_oldest_unpublished_age_seconds', 'outbox age'), + ('messenger_process_cpu_seconds_total', 'process CPU'), + ('rabbitmq_queue_messages_ready', 'RabbitMQ queue depth'), + ('otelcol_exporter_queue_size', 'collector queue self-metric'), + ] + try: + if not wait_for(lambda: prom(args.prometheus, 'sum(rate(messenger_job_time_to_ready_seconds_bucket{le="30.0"}[5m]))'), attempts=20, delay=3): + failures.append('TTR good-event selector le="30.0" is empty') + except Exception as exc: + failures.append('TTR selector: ' + str(exc)) + + for metric, label in required: + try: + found = wait_for(lambda m=metric: prom(args.prometheus, 'count(' + m + ')'), attempts=max(1, args.wait_seconds // 3), delay=3) + if not found: + failures.append(label + ': no samples (' + metric + ')') + except Exception as exc: + failures.append(label + ': ' + str(exc)) + + try: + up = prom(args.prometheus, 'up{job=~"otel-collector|haproxy|rabbitmq"} == 1') + jobs = {item.get('metric', {}).get('job') for item in up} + for job in ('otel-collector', 'haproxy', 'rabbitmq'): + if job not in jobs: + failures.append('Prometheus target is not up: ' + job) + except Exception as exc: + failures.append('Prometheus targets: ' + str(exc)) + + try: + series = prom_series(args.prometheus, 'http_server_request_duration_seconds_count') + routes = [item.get('http_route', '') for item in series] + if not series: + failures.append('HTTP metric has no series') + for route in routes: + if not route: + failures.append('HTTP metric has an empty http_route label') + if UUID_RE.search(route): + failures.append('HTTP route label contains a UUID: ' + route) + labels = {key for item in series for key in item} + forbidden = labels & FORBIDDEN_LABELS + if forbidden: + failures.append('HTTP metric has forbidden labels: ' + ', '.join(sorted(forbidden))) + methods = {item.get('http_request_method', '') for item in series} + if len(methods) > 7: + failures.append('HTTP method label cardinality is too high: ' + str(len(methods))) + for method in methods: + if method not in {'GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'HEAD', 'OPTIONS', 'OTHER'}: + failures.append('HTTP method is not normalized: ' + method) + except Exception as exc: + failures.append('HTTP label check: ' + str(exc)) + + # 3. Loki must contain the access log for the controlled request and must + # not contain the message text, session token or file bytes. + end = int(time.time() * 1e9) + start = end - 15 * 60 * int(1e9) + try: + found = wait_for(lambda: loki_query(args.loki, '{service_name=~"messenger-api|messenger-worker|messenger-relay"} | request_id="' + request_id + '"', start, end), attempts=20, delay=2) + if not found: + failures.append('Loki: no log with the generated request_id (trace/log correlation)') + for needle, label in ((sentinel, 'message text'), (token, 'session token'), (filename, 'filename')): + if needle and loki_query(args.loki, '{service_name=~"messenger-api|messenger-worker|messenger-relay"} |= "' + needle + '"', start, end): + failures.append('Loki contains forbidden ' + label) + except Exception as exc: + failures.append('Loki query: ' + str(exc)) + + # 4. Tempo must contain real application traces, including the worker span. + # Tempo's search `name=` matches root spans only. job.process is a child of + # the controlled API trace, so resolve its trace_id from the worker log and + # fetch that trace directly. + try: + def tempo_search(tag): + q = urllib.parse.quote(tag) + _, raw = request(args.tempo.rstrip('/') + '/api/search?tags=' + q + '&limit=20') + return json.loads(raw).get('traces', []) + + def worker_job_trace(): + result = loki_query( + args.loki, + '{service_name="messenger-worker"} | event="attachment ready"', + start, end, limit=50, + ) + for stream in result: + for _, line in stream.get('values', []): + try: + entry = json.loads(line) + except json.JSONDecodeError: + entry = {} + trace_id = entry.get('trace_id') or stream.get('stream', {}).get('trace_id', '') + if not re.fullmatch(r'[0-9a-f]{32}', trace_id): + continue + try: + _, raw = request(args.tempo.rstrip('/') + '/api/traces/' + trace_id) + except Exception: + continue + try: + payload = json.loads(raw) + except json.JSONDecodeError: + continue + spans = [] + for batch in payload.get('batches', []): + for scope in batch.get('scopeSpans', []): + spans.extend(scope.get('spans', [])) + publishes = [s for s in spans if s.get('name') == 'job.publish' + and s.get('kind') == 'SPAN_KIND_PRODUCER'] + processes = [s for s in spans if s.get('name') == 'job.process' + and s.get('kind') == 'SPAN_KIND_CONSUMER'] + if any(p.get('parentSpanId') == pub.get('spanId') + for p in processes for pub in publishes): + return trace_id + return None + + if not wait_for(lambda: tempo_search('service.name=messenger-api'), attempts=15, delay=2): + failures.append('Tempo: no messenger-api traces') + retry_path = ROOT / 'evidence/lab6/trace-retry.json' + if retry_path.exists(): + retry = json.loads(retry_path.read_text()) + spans = [] + for batch in retry.get('batches', []): + for scope in batch.get('scopeSpans', []): + spans.extend(scope.get('spans', [])) + processes = [s for s in spans if s.get('name') == 'job.process'] + attempts = set() + for span in processes: + for attr in span.get('attributes', []): + if attr.get('key') == 'job.attempt': + value = attr.get('value', {}) + if 'intValue' in value: + attempts.add(int(value['intValue'])) + outcomes = set() + for span in processes: + for attr in span.get('attributes', []): + if attr.get('key') == 'job.outcome': + value = attr.get('value', {}).get('stringValue') + if value: + outcomes.add(value) + if (len(attempts) < 2 or 'retried' not in outcomes + or not any(s.get('name') == 'job.requeue' for s in spans)): + failures.append('Tempo: retry trace lacks two attempts, retried outcome or job.requeue') + if not wait_for(worker_job_trace, attempts=20, delay=2): + failures.append('Tempo: no worker job.process trace linked to worker log') + except Exception as exc: + failures.append('Tempo query: ' + str(exc)) + + # 5. Grafana provisioning and rules. + try: + password = grafana_password() + if not password: + failures.append('Grafana admin secret is missing (secrets/grafana.env)') + else: + _, raw = request(args.grafana.rstrip('/') + '/api/health') + if json.loads(raw).get('database') != 'ok': + failures.append('Grafana health is not ok') + _, raw = request(args.grafana.rstrip('/') + '/api/datasources', auth='admin:' + password) + names = {item.get('name') for item in json.loads(raw)} + for required_name in ('Prometheus', 'Loki', 'Tempo'): + if required_name not in names: + failures.append('Grafana datasource missing: ' + required_name) + for uid in ('lab6-overview', 'lab6-jobs', 'lab6-infra'): + _, raw = request(args.grafana.rstrip('/') + '/api/dashboards/uid/' + uid, auth='admin:' + password) + if json.loads(raw).get('dashboard', {}).get('uid') != uid: + failures.append('Grafana dashboard missing: ' + uid) + except Exception as exc: + failures.append('Grafana: ' + str(exc)) + + try: + _, raw = request(args.prometheus.rstrip('/') + '/api/v1/rules') + rule_names = {r.get('name') for g in json.loads(raw).get('data', {}).get('groups', []) for r in g.get('rules', [])} + for name in ('APIErrorBudgetFastBurn', 'APIErrorBudgetSlowBurn', 'QueueOldestJobAgeHigh', 'TTRErrorBudgetFastBurn'): + if name not in rule_names: + failures.append('Prometheus rule missing: ' + name) + except Exception as exc: + failures.append('Prometheus rules: ' + str(exc)) + + for note in notes: + print('NOTE:', note) + if failures: + for item in failures: + print('FAIL:', item) + return 1 + print('PASS: lab6 strict telemetry gate (signals, trace/log correlation, labels, Grafana, rules, privacy sentinels)') + return 0 + + +if __name__ == '__main__': + raise SystemExit(main()) diff --git a/scripts/lb_readiness_check.sh b/scripts/lb_readiness_check.sh new file mode 100755 index 0000000..a69697f --- /dev/null +++ b/scripts/lb_readiness_check.sh @@ -0,0 +1,200 @@ +#!/bin/sh +# Проверка критерия «LB исключает неготовую реплику» (lab5). +# +# Рядом с рабочими репликами поднимается третья с тем же сетевым alias, но её +# доступ к БД идёт через временный TCP-прокси. Пока прокси жив, реплика готова и +# получает трафик через LB. После остановки прокси реплика остаётся доступной по +# сети (процесс жив, порт открыт), но /health/ready отвечает 503 — и балансировщик +# обязан убрать её из ротации и не отправлять ей ни одного запроса. +# +# scripts/lb_readiness_check.sh # стенд поднят (make up) +# OUT=evidence/lb-readiness.txt scripts/lb_readiness_check.sh +set -eu + +ROOT_DIR=$(CDPATH= cd -- "$(dirname -- "$0")/.." && pwd) +cd "$ROOT_DIR" + +# .env определяет, на каком порту публикуется LB (compose.yaml) и какие креды у +# хранилищ, поэтому значения берём оттуда же, а не из окружения вызывающего. +if [ -f .env ]; then + set -a + # shellcheck disable=SC1091 + . ./.env + set +a +fi + +OUT=${OUT:-evidence/lab5/lb-readiness-detail.txt} +PROJECT=${COMPOSE_PROJECT_NAME:-mtusi-messenger-lab6} +NET=${PROJECT}_default +IMAGE=${IMAGE:-mtusi-messenger:lab6} +STATS=${STATS:-http://127.0.0.1:${LB_STATS_PORT:-8404}/stats;csv} +BASE_URL=${BASE_URL:-http://localhost:${SERVER_PORT:-8080}} +CANDIDATE=lb-readiness-candidate +PROXY=lb-readiness-pgproxy +REQUESTS=${REQUESTS:-40} + +NO_PROXY_ENV="env -u HTTP_PROXY -u HTTPS_PROXY -u ALL_PROXY -u http_proxy -u https_proxy -u all_proxy" +NO_PROXY_ENV="$NO_PROXY_ENV NO_PROXY=localhost,127.0.0.1,::1 no_proxy=localhost,127.0.0.1,::1" + +cleanup() { + docker rm -f "$CANDIDATE" "$PROXY" >/dev/null 2>&1 || true +} + +trap cleanup EXIT INT TERM +cleanup + +instances() { + tries=${1:-$REQUESTS} + i=0 + + while [ "$i" -lt "$tries" ]; do + curl -fsS --noproxy '*' -D - -o /dev/null "$BASE_URL/health/live" 2>/dev/null \ + | awk 'tolower($1) == "x-instance-id:" { print $2 }' + i=$((i + 1)) + done | sort | uniq -c +} + +stats() { + curl -s --noproxy '*' "$STATS" | awk -F, '$1 ~ /^api/ { printf "%s=%s ", $2, $18 }' +} + +readiness() { + docker exec "$CANDIDATE" wget -qO- -S -T 3 http://127.0.0.1:8080/health/ready 2>&1 \ + | awk '/^ HTTP\//{print $2; exit}' +} + +wait_readiness() { + want=$1 + attempt=0 + + while [ "$attempt" -lt 30 ]; do + [ "$(readiness)" = "$want" ] && return 0 + attempt=$((attempt + 1)) + sleep 1 + done + + return 1 +} + +up_slots() { + curl -s --noproxy '*' "$STATS" | awk -F, '$1 ~ /^api/ && $18 ~ /^UP/ && $2 != "BACKEND" { printf "%s ", $2 }' +} + +wait_new_up_slot() { + before=$1 + attempt=0 + + while [ "$attempt" -lt 30 ]; do + for slot in $(up_slots); do + case " $before " in + *" $slot "*) ;; + *) echo "$slot"; return 0 ;; + esac + done + + attempt=$((attempt + 1)) + sleep 1 + done + + return 1 +} + +wait_slot_status() { + slot=$1 + want=$2 + attempt=0 + + while [ "$attempt" -lt 60 ]; do + status=$(curl -s --noproxy '*' "$STATS" | awk -F, -v s="$slot" '$1 ~ /^api/ && $2 == s { print $18; exit }') + + if [ "$status" = "$want" ]; then + SWAIT_SECONDS=$((attempt / 2)) + return 0 + fi + + attempt=$((attempt + 1)) + sleep 0.5 + done + + return 1 +} + +{ + echo "# LB excludes a not-ready but reachable replica (lab5)" + echo "# generated: $(date -u +%Y-%m-%dT%H:%M:%SZ)" + echo "# lb: $(docker inspect -f '{{.Config.Image}}' "$(docker ps -q --filter label=com.docker.compose.service=lb)" 2>/dev/null)" + echo + echo "## 1. baseline: requests through LB by replica" + instances + baseline_slots=$(up_slots) + echo " stats: $(stats)" + echo + echo "## 2. start a temporary TCP proxy to postgres and a candidate replica behind the same network alias" + docker run -d --name "$PROXY" --network "$NET" alpine/socat@sha256:fb3862c949af7c79996d0e514ee96128644d840835ed5368eeecb14a869de361 \ + tcp-listen:5432,fork,reuseaddr tcp-connect:postgres:5432 >/dev/null + docker run -d --name "$CANDIDATE" --network "$NET" --network-alias api-replica \ + -e APP_CONFIG=/etc/messenger/dev/config.yaml \ + -e POSTGRES_HOST="$PROXY" -e POSTGRES_PORT=5432 \ + -e POSTGRES_DATABASE="${POSTGRES_DATABASE:-messenger}" \ + -e POSTGRES_USER="${POSTGRES_USER:-messenger}" \ + -e POSTGRES_PASSWORD="${POSTGRES_PASSWORD:-messenger}" -e POSTGRES_SSL_MODE=disable \ + -e REDIS_ENABLED=true -e REDIS_HOST=redis -e CACHE_ENABLED=true \ + -e S3_ENDPOINT=http://seaweedfs:8333 -e S3_REGION="${S3_REGION:-us-east-1}" \ + -e S3_BUCKET="${S3_BUCKET:-messenger-attachments}" \ + -e S3_ACCESS_KEY_ID="${S3_ACCESS_KEY_ID:-lab4app}" \ + -e S3_SECRET_ACCESS_KEY="${S3_SECRET_ACCESS_KEY:-lab4app-secret}" \ + -e S3_USE_PATH_STYLE=true \ + "$IMAGE" >/dev/null + + if ! wait_readiness 200; then + echo " candidate did not become ready" >&2 + exit 1 + fi + + echo " instance-id: $(docker inspect -f '{{.Config.Hostname}}' "$CANDIDATE"), readiness while its database is reachable: 200" + + slot=$(wait_new_up_slot "$baseline_slots" || true) + if [ -z "$slot" ]; then + echo " candidate did not appear UP in the load balancer" >&2 + exit 1 + fi + + echo " load balancer slot for the candidate: $slot, stats: $(stats)" + echo + echo "## 3. cut the candidate's database access (stop only the TCP proxy)" + docker stop "$PROXY" >/dev/null + + if ! wait_readiness 503; then + echo " candidate readiness did not become 503" >&2 + exit 1 + fi + + echo " candidate is still running: $(docker inspect -f '{{.State.Status}}' "$CANDIDATE"), readiness: 503" + echo " waiting for the load balancer to mark $slot DOWN" + + if wait_slot_status "$slot" DOWN; then + echo " $slot went DOWN ${SWAIT_SECONDS}s after its database was cut (check: inter 2s fall 2)" + else + echo " FAIL: $slot is still not DOWN" >&2 + exit 1 + fi + + echo " stats after failure: $(stats)" + echo + echo "## 4. ${REQUESTS} requests through LB while the candidate is not ready" + instances + echo " (the candidate must not appear above)" + echo + echo "## 5. business writes through LB during the exclusion" + # shellcheck disable=SC2086 + $NO_PROXY_ENV python3 tests/load.py --base-url "$BASE_URL" --duration 5 --concurrency 2 \ + | grep -E '"successful_rps"|"failed_requests"|"error_ratio"' + echo + echo "## 6. cleanup" + cleanup + sleep 5 + echo " stats after cleanup: $(stats)" +} > "$OUT" 2>&1 + +cat "$OUT" +printf 'lb_readiness_check.sh: evidence in %s\n' "$OUT" diff --git a/scripts/memory_experiment.py b/scripts/memory_experiment.py new file mode 100644 index 0000000..6e370cc --- /dev/null +++ b/scripts/memory_experiment.py @@ -0,0 +1,271 @@ +import argparse +import json +import os +import subprocess +import threading +import time +import urllib.error +import urllib.request +import uuid + +import matplotlib + +matplotlib.use("Agg") +import matplotlib.pyplot as plt + + +def request(base_url, method, path, body=None, user_id=None): + payload = json.dumps(body, ensure_ascii=False).encode() if body is not None else None + headers = {"Content-Type": "application/json"} if payload else {} + if user_id: + headers["X-User-Id"] = user_id + request = urllib.request.Request( + base_url + path, + data=payload, + headers=headers, + method=method, + ) + with urllib.request.urlopen(request, timeout=3) as response: + return json.loads(response.read()) + + +def wait_ready(base_url): + deadline = time.monotonic() + 20 + while time.monotonic() < deadline: + try: + request(base_url, "GET", "/health/live") + return + except OSError: + time.sleep(0.1) + raise RuntimeError("container did not become ready") + + +def process_alive(container): + result = subprocess.run( + ["docker", "inspect", "--format", "{{.State.Running}}", container], + capture_output=True, + text=True, + check=False, + ) + return result.stdout.strip() == "true" + + +def sample_stats(container, samples, stop): + while not stop.is_set(): + result = subprocess.run( + ["docker", "stats", "--no-stream", "--format", "{{json .}}", container], + capture_output=True, + text=True, + check=False, + ) + if result.returncode == 0 and result.stdout.strip(): + try: + value = json.loads(result.stdout) + memory = value.get("MemUsage", "").split("/")[0].strip() + if memory == "0B" or not process_alive(container): + continue + samples.append({ + "time_seconds": time.monotonic(), + "memory": memory, + "memory_mib": parse_memory(memory), + }) + except (ValueError, IndexError): + pass + stop.wait(0.1) + + +def parse_memory(value): + units = {"B": 1 / 1024 / 1024, "KiB": 1 / 1024, "MiB": 1, "GiB": 1024} + for unit, factor in sorted(units.items(), key=lambda item: -len(item[0])): + if value.endswith(unit): + return float(value[:-len(unit)].strip()) * factor + raise ValueError(value) + + +def make_plot(data, output): + samples = [sample for sample in data["memory_samples"] if sample["memory_mib"] > 0] + start = samples[0]["time_seconds"] if samples else 0 + x = [sample["time_seconds"] - start for sample in samples] + memory = [sample["memory_mib"] for sample in samples] + + fig, memory_axis = plt.subplots(figsize=(11, 6)) + memory_axis.plot(x, memory, color="tab:red", label="RSS / container memory") + memory_axis.axhline(data["memory_limit_mib"], color="black", linestyle="--", label="memory limit") + memory_axis.set_xlabel("Time, seconds") + memory_axis.set_ylabel("Memory, MiB") + memory_axis.grid(True, alpha=0.25) + + message_axis = memory_axis.twinx() + message_axis.plot( + data["message_points_x"], + data["message_points_y"], + color="tab:blue", + label="successful messages", + ) + message_axis.set_ylabel("Successful messages") + + lines, labels = memory_axis.get_legend_handles_labels() + other_lines, other_labels = message_axis.get_legend_handles_labels() + memory_axis.legend(lines + other_lines, labels + other_labels, loc="upper left") + memory_axis.set_title("In-memory messenger: memory exhaustion point") + if data["oom_killed"] and data["failure_time_seconds"] is not None: + memory_axis.axvline( + data["failure_time_seconds"], + color="tab:purple", + linestyle=":", + label="container OOMKilled", + ) + memory_axis.annotate( + "OOMKilled", + (data["failure_time_seconds"], data["memory_limit_mib"]), + xytext=(8, -18), + textcoords="offset points", + color="tab:purple", + ) + fig.tight_layout() + fig.savefig(output, dpi=160) + plt.close(fig) + + +def main(): + parser = argparse.ArgumentParser() + parser.add_argument("--image", required=True) + parser.add_argument("--memory", default="32m") + parser.add_argument("--output", default="evidence/memory-experiment.json") + parser.add_argument("--plot", default="evidence/memory-experiment.png") + parser.add_argument("--max-messages", type=int, default=100000) + args = parser.parse_args() + + container = "mtusi-memory-experiment-" + uuid.uuid4().hex[:8] + port = 18081 + base_url = f"http://127.0.0.1:{port}" + subprocess.run( + [ + "docker", "run", "-d", "--name", container, + "--memory", args.memory, "--memory-swap", args.memory, + "-p", f"127.0.0.1:{port}:8080", args.image, + ], + check=True, + capture_output=True, + text=True, + ) + + samples = [] + stop_sampling = threading.Event() + sampler = threading.Thread(target=sample_stats, args=(container, samples, stop_sampling)) + successful = 0 + failures = 0 + fatal_error = None + started = time.monotonic() + message_points_x = [] + message_points_y = [] + failure_time = None + oom_killed = False + last_error = None + last_state = {} + logs = "" + + try: + wait_ready(base_url) + user = request(base_url, "POST", "/api/v1/users", { + "username": "memory_" + uuid.uuid4().hex[:16], + "display_name": "Memory experiment", + }) + chat = request(base_url, "POST", "/api/v1/chats", { + "title": "Memory experiment", + "member_ids": [user["id"]], + }, user["id"]) + sampler.start() + time.sleep(0.5) + + body = "x" * 4000 + for index in range(args.max_messages): + try: + request( + base_url, + "POST", + f"/api/v1/chats/{chat['id']}/messages", + {"text": body}, + user["id"], + ) + successful += 1 + message_points_x.append(time.monotonic() - started) + message_points_y.append(successful) + except (OSError, urllib.error.HTTPError, ValueError) as exc: + last_error = type(exc).__name__ + ": " + str(exc) + failures += 1 + failure_time = time.monotonic() - started + break + + time.sleep(0.5) + if not process_alive(container): + failure_time = failure_time or (time.monotonic() - started) + inspect = subprocess.run( + ["docker", "inspect", "--format", "{{json .State}}", container], + capture_output=True, + text=True, + check=False, + ) + state = json.loads(inspect.stdout) if inspect.stdout.strip() else {} + if not state: + state_result = subprocess.run( + ["docker", "inspect", "--format", "{{json .State}}", container], + capture_output=True, + text=True, + check=False, + ) + state = json.loads(state_result.stdout) if state_result.stdout.strip() else {} + last_state = state + logs_result = subprocess.run(["docker", "logs", container], capture_output=True, text=True, check=False) + logs = logs_result.stdout + logs_result.stderr + oom_killed = bool(state.get("OOMKilled")) + if failure_time is None and failures: + failure_time = time.monotonic() - started + except Exception as exc: + fatal_error = type(exc).__name__ + ": " + str(exc) + failure_time = failure_time or (time.monotonic() - started) + finally: + stop_sampling.set() + if sampler.is_alive(): + sampler.join(timeout=2) + + memory_limit_mib = float(args.memory.rstrip("mM")) if args.memory.lower().endswith("m") else 0 + if not oom_killed: + inspect = subprocess.run( + ["docker", "inspect", "--format", "{{json .State}}", container], + capture_output=True, + text=True, + check=False, + ) + state = json.loads(inspect.stdout) if inspect.stdout.strip() else {} + last_state = state + oom_killed = bool(state.get("OOMKilled")) + + result = { + "image": args.image, + "memory_limit": args.memory, + "memory_limit_mib": memory_limit_mib, + "successful_messages": successful, + "failed_requests": failures, + "oom_killed": oom_killed, + "last_error": last_error, + "fatal_error": fatal_error, + "container_state": last_state, + "container_logs_tail": logs[-20000:], + "failure_time_seconds": failure_time, + "memory_samples": samples, + "message_points_x": message_points_x, + "message_points_y": message_points_y, + "reason": "process stopped after the container memory limit was reached" if oom_killed else "request processing did not reach the memory limit", + } + with open(args.output, "w", encoding="utf-8") as output: + json.dump(result, output, ensure_ascii=False, indent=2) + make_plot(result, args.plot) + print(json.dumps({key: result[key] for key in ( + "memory_limit", "successful_messages", "failed_requests", "oom_killed", "failure_time_seconds", "reason", + )}, ensure_ascii=False, indent=2)) + subprocess.run(["docker", "rm", "-f", container], capture_output=True, check=False) + + +if __name__ == "__main__": + main() diff --git a/scripts/path_overhead_check.sh b/scripts/path_overhead_check.sh new file mode 100755 index 0000000..a9538c4 --- /dev/null +++ b/scripts/path_overhead_check.sh @@ -0,0 +1,68 @@ +#!/bin/sh +# Контроль пути «хост -> Colima VM -> LB»: тот же генератор и тот же профиль +# запускаются дважды — с хоста через опубликованный порт и изнутри VM, где +# клиент говорит с балансировщиком напрямую по docker-сети. Разница показывает +# вклад этого пути в потолок closed-loop профиля, а не приписывает его по +# догадке. Стенд должен быть поднят (`make up`). +# +# scripts/path_overhead_check.sh +# +# Артефакт: evidence/path-overhead/{inside,outside}.txt + summary.txt +set -eu + +ROOT_DIR=$(CDPATH= cd -- "$(dirname -- "$0")/.." && pwd) +cd "$ROOT_DIR" + +COMPOSE_BIN=${COMPOSE_BIN:-docker compose} +OUT=${OUT:-evidence/path-overhead} +DURATION=${DURATION:-60} +CONCURRENCY=${CONCURRENCY:-8} +WARMUP=${WARMUP:-15} +CLIENT_IMAGE=${CLIENT_IMAGE:-python:3.12-alpine} + +compose() { + # shellcheck disable=SC2086 + $COMPOSE_BIN --env-file .env -f compose.yaml "$@" +} + +NO_PROXY_ENV="env -u HTTP_PROXY -u HTTPS_PROXY -u ALL_PROXY -u http_proxy -u https_proxy -u all_proxy" +NO_PROXY_ENV="$NO_PROXY_ENV NO_PROXY=localhost,127.0.0.1,::1 no_proxy=localhost,127.0.0.1,::1" + +mkdir -p "$OUT" + +network=$(docker inspect "$(compose ps -q api | head -1)" \ + --format '{{range $name, $network := .NetworkSettings.Networks}}{{$name}}{{end}}') + +printf '# Контроль пути к балансировщику\n' > "$OUT/summary.txt" +{ + printf '# generated: %s\n' "$(date -u +%Y-%m-%dT%H:%M:%SZ)" + printf '# profile: tests/load.py duration=%s concurrency=%s warmup=%s\n' "$DURATION" "$CONCURRENCY" "$WARMUP" + printf '# docker network: %s\n' "$network" + printf '# клиент в VM: %s\n\n' "$CLIENT_IMAGE" +} >> "$OUT/summary.txt" + +# Клиент с хоста: путь «хост -> проброс порта -> VM -> LB». +printf '=== извне: клиент на хосте, http://127.0.0.1:8080 ===\n' | tee -a "$OUT/summary.txt" +# shellcheck disable=SC2086 +$NO_PROXY_ENV python3 tests/load.py --base-url http://127.0.0.1:8080 \ + --duration "$WARMUP" --concurrency "$CONCURRENCY" >/dev/null +# shellcheck disable=SC2086 +$NO_PROXY_ENV python3 tests/load.py --base-url http://127.0.0.1:8080 \ + --duration "$DURATION" --concurrency "$CONCURRENCY" \ + --output "$OUT/load-outside.json" | tee "$OUT/outside.txt" | tail -12 + +# Клиент внутри VM: тот же генератор и профиль, но без проброса порта и без +# сетевого стека хоста. Генератор делит 2 vCPU VM со стендом, поэтому его +# результат — нижняя оценка, а не потолок. +printf '\n=== изнутри: клиент в VM, http://lb ===\n' | tee -a "$OUT/summary.txt" +docker run --rm -i --network "$network" -v "$ROOT_DIR:/repo:ro" -v "$ROOT_DIR/$OUT:/out" \ + -e NO_PROXY='lb,localhost,127.0.0.1' -e no_proxy='lb,localhost,127.0.0.1' \ + "$CLIENT_IMAGE" python /repo/tests/load.py --base-url http://lb \ + --duration "$WARMUP" --concurrency "$CONCURRENCY" >/dev/null +docker run --rm -i --network "$network" -v "$ROOT_DIR:/repo:ro" -v "$ROOT_DIR/$OUT:/out" \ + -e NO_PROXY='lb,localhost,127.0.0.1' -e no_proxy='lb,localhost,127.0.0.1' \ + "$CLIENT_IMAGE" python /repo/tests/load.py --base-url http://lb \ + --duration "$DURATION" --concurrency "$CONCURRENCY" \ + --output /out/load-inside.json | tee "$OUT/inside.txt" | tail -12 + +printf 'path_overhead_check.sh: артефакты в %s\n' "$OUT" diff --git a/scripts/redis_outage_check.py b/scripts/redis_outage_check.py new file mode 100644 index 0000000..966dcc9 --- /dev/null +++ b/scripts/redis_outage_check.py @@ -0,0 +1,132 @@ +#!/usr/bin/env python3 +"""Reproducible Redis-outage check: stop and pause, latency budget, create-during-outage. + +Exit code is non-zero when any assertion fails. Always unpauses/starts Redis. +""" +import concurrent.futures +import json +import os +import statistics +import subprocess +import sys +import time +import urllib.error +import urllib.request +import uuid +import base64 + +for proxy in ('HTTP_PROXY', 'HTTPS_PROXY', 'ALL_PROXY', 'http_proxy', 'https_proxy', 'all_proxy'): + os.environ.pop(proxy, None) +os.environ['NO_PROXY'] = 'localhost,127.0.0.1,::1' +os.environ['no_proxy'] = os.environ['NO_PROXY'] + +BASE_URL = os.environ.get('BASE_URL', 'http://localhost:8080') +COMPOSE = os.environ.get('COMPOSE_BIN', 'docker-compose') +COMPOSE_FILE = 'docker-compose.local.yaml' +BUDGET_MS = int(os.environ.get('OUTAGE_BUDGET_MS', '2000')) +PARALLEL = int(os.environ.get('OUTAGE_PARALLEL', '30')) + + +def compose(*args): + subprocess.run([COMPOSE, '-f', COMPOSE_FILE, *args], check=True, + stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) + + +def call(method, path, body=None, headers=None): + data = json.dumps(body).encode() if body is not None else None + h = {'Accept': 'application/json'} + if body is not None: + h['Content-Type'] = 'application/json' + h.update(headers or {}) + req = urllib.request.Request(BASE_URL + path, data=data, headers=h, method=method) + started = time.monotonic() + try: + resp = urllib.request.urlopen(req, timeout=10) + return resp.status, resp.read(), (time.monotonic() - started) * 1000 + except urllib.error.HTTPError as exc: + return exc.code, exc.read(), (time.monotonic() - started) * 1000 + + +def user(label): + username = label + '_' + uuid.uuid4().hex[:8] + password = 'T3st-' + uuid.uuid4().hex + call('POST', '/api/v1/users', {'username': username, 'display_name': label, 'password': password}) + credential = base64.b64encode((username + ':' + password).encode()).decode() + _, body, _ = call('POST', '/api/v1/auth/sessions', headers={'Authorization': 'Basic ' + credential}) + return json.loads(body) + + +def list_chats(actor): + status, body, ms = call('GET', '/api/v1/chats?limit=50', headers={'Authorization': 'Bearer ' + actor['token']}) + assert status == 200, 'GET /chats expected 200, got %d' % status + return json.loads(body)['items'], ms + + +def assert_budget(label, samples): + worst = max(samples) + p95 = sorted(samples)[max(0, (len(samples) * 95 + 99) // 100 - 1)] + print(' %s: n=%d max=%.0fms p95=%.0fms budget=%dms' % (label, len(samples), worst, p95, BUDGET_MS)) + assert worst <= BUDGET_MS, '%s exceeded budget: %.0fms > %dms' % (label, worst, BUDGET_MS) + + +def main(): + alice = user('alice') + bob = user('bob') + ah = {'Authorization': 'Bearer ' + alice['token']} + + try: + _, ms = list_chats(alice) + print('baseline: %.0fms' % ms) + + compose('stop', 'redis') + _, ms = list_chats(alice) + print('after stop: %.0fms' % ms) + assert_budget('stop', [ms]) + + compose('start', 'redis') + time.sleep(2) + compose('pause', 'redis') + + with concurrent.futures.ThreadPoolExecutor(max_workers=PARALLEL) as pool: + results = [f for f in pool.map(lambda _: list_chats(alice), range(PARALLEL))] + assert_budget('pause parallel', [ms for _, ms in results]) + + title = 'during-outage-' + uuid.uuid4().hex[:8] + status, _, _ = call('POST', '/api/v1/chats', { + 'title': title, + 'member_ids': [alice['user']['id'], bob['user']['id']], + }, headers=ah) + assert status == 201, 'chat create during pause expected 201, got %d' % status + print('create during pause: 201') + + compose('unpause', 'redis') + time.sleep(2) + + chats, ms = list_chats(alice) + assert any(c['title'] == title for c in chats), 'new chat missing after recovery (stale cache)' + print('after recovery: new chat visible, %.0fms' % ms) + + stuck = subprocess.run( + [COMPOSE, '-f', COMPOSE_FILE, 'exec', '-T', 'redis', 'redis-cli', '--scan', '--pattern', 'lock:*'], + check=True, capture_output=True, text=True, + ).stdout.split() + for key in stuck: + ttl = subprocess.run( + [COMPOSE, '-f', COMPOSE_FILE, 'exec', '-T', 'redis', 'redis-cli', 'ttl', key], + check=True, capture_output=True, text=True, + ).stdout.strip() + assert ttl != '-1', 'stuck lock without TTL: %s' % key + print('lock keys without TTL: 0') + print('PASS: redis outage handled within budget') + finally: + for action in ('unpause', 'start'): + subprocess.run([COMPOSE, '-f', COMPOSE_FILE, action, 'redis'], + stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) + + +if __name__ == '__main__': + try: + main() + except AssertionError as exc: + print('FAIL: %s' % exc) + sys.exit(1) diff --git a/scripts/restart.sh b/scripts/restart.sh new file mode 100755 index 0000000..70c3226 --- /dev/null +++ b/scripts/restart.sh @@ -0,0 +1,58 @@ +#!/bin/sh +set -eu +# Restart hook: bounce API replicas, worker/relay and every state store of the lab5 stand. +# +# scripts/restart.sh +# +# Persistent volumes are kept: no `down -v`, no flush, no re-seed. The one-shot +# `migrate` service is not re-run (schema stays as it is, data and sessions +# survive). The script exits 0 only after /health/ready answers through the LB. +# No credentials are printed. +ROOT_DIR=$(CDPATH= cd -- "$(dirname -- "$0")/.." && pwd) +cd "$ROOT_DIR" + +# .env определяет, на каком порту публикуется LB (compose.yaml) и какие креды у +# хранилищ, поэтому значения берём оттуда же, а не из окружения вызывающего. +if [ -f .env ]; then + set -a + # shellcheck disable=SC1091 + . ./.env + set +a +fi + +COMPOSE_BIN=${COMPOSE_BIN:-docker compose} +PORT=${SERVER_PORT:-8080} + +# shellcheck disable=SC2086 +compose() { + # shellcheck disable=SC2086 + $COMPOSE_BIN --env-file .env -f compose.yaml "$@" +} + +# 1. State stores and broker: restart the running ones, then make sure they are +# healthy. Volumes are attached as before, nothing is dropped or re-seeded. +compose up -d --wait postgres redis seaweedfs broker +compose restart postgres redis seaweedfs broker +compose up -d --wait postgres redis seaweedfs broker + +# 2. API replicas, worker and relay: restart in place and bring back any replica +# stopped by a fault-injection hook. The worker reconnects to the broker. +compose restart api worker relay +compose up -d --wait --no-deps api worker relay + +# 3. Load balancer keeps its upstream; re-resolve in case addresses changed. +compose restart lb + +# 4. Wait for readiness through the public entry point. +attempt=0 +while [ "$attempt" -lt 60 ]; do + if curl -fsS --noproxy '*' -o /dev/null "http://127.0.0.1:${PORT}/health/ready"; then + printf 'restart.sh: stack restarted, http://127.0.0.1:%s/health/ready is ready\n' "$PORT" + exit 0 + fi + attempt=$((attempt + 1)) + sleep 1 +done + +printf 'restart.sh: /health/ready did not become ready through the LB\n' >&2 +exit 1 diff --git a/scripts/rolling_update.sh b/scripts/rolling_update.sh new file mode 100755 index 0000000..934a9ba --- /dev/null +++ b/scripts/rolling_update.sh @@ -0,0 +1,231 @@ +#!/bin/sh +# Rolling update of the API replicas under load (lab3, level 4). +# +# Замена идёт «наплывом» и строго по одной реплике: сначала рядом поднимается +# контейнер новой ревизии с тем же сетевым alias, затем снимается ОДИН старый. +# Каждый шаг гейтится состоянием балансировщика: новый слот должен стать UP +# (активная проверка /health/ready), снятый — перестать быть UP. Гейт по +# статистике LB, а не по наблюдению X-Instance-Id в ответах, потому что HAProxy +# переиспользует keepalive-соединения к уже работающим репликам и свежая реплика +# может какое-то время не получать трафик, оставаясь при этом готовой. +# +# В конце стенд возвращается под управление compose: поднимаются штатные реплики +# из новой ревизии, затем по одной снимаются временные контейнеры наплыва. +# +# scripts/rolling_update.sh # профиль лимитов берётся из .env/compose.yaml +# DURATION=60 CONCURRENCY=8 scripts/rolling_update.sh +set -eu + +ROOT_DIR=$(CDPATH= cd -- "$(dirname -- "$0")/.." && pwd) +cd "$ROOT_DIR" + +COMPOSE_BIN=${COMPOSE_BIN:-docker compose} +PYTHON=${PYTHON:-python3} +DURATION=${DURATION:-60} +CONCURRENCY=${CONCURRENCY:-8} +BASE_URL=${BASE_URL:-http://localhost:8080} +OUT=${OUT:-evidence/rolling-update} +IMAGE=${IMAGE:-mtusi-messenger:lab4} +PROJECT=${COMPOSE_PROJECT_NAME:-mtusi-messenger-lab4} +NET=${PROJECT}_default +STATS=${STATS:-http://127.0.0.1:8404/stats;csv} +PREFIX=lb-rollout + +NO_PROXY_ENV="env -u HTTP_PROXY -u HTTPS_PROXY -u ALL_PROXY -u http_proxy -u https_proxy -u all_proxy" +NO_PROXY_ENV="$NO_PROXY_ENV NO_PROXY=localhost,127.0.0.1,::1 no_proxy=localhost,127.0.0.1,::1" + +mkdir -p "$OUT" +rm -f "$OUT/load.json" "$OUT/load.txt" + +compose() { + # shellcheck disable=SC2086 + $COMPOSE_BIN --env-file .env -f compose.yaml "$@" +} + +api_containers() { + docker ps -q \ + --filter "label=com.docker.compose.project=$PROJECT" \ + --filter 'label=com.docker.compose.service=api' +} + +rollout_containers() { + docker ps -q --filter "name=^$PREFIX" +} + +restarts() { + for container in $(api_containers) $(rollout_containers); do + printf '%s=%s ' "$(docker inspect --format '{{.Name}}' "$container" | sed 's|^/||')" \ + "$(docker inspect --format '{{.RestartCount}}' "$container")" + done +} + +stats_rows() { + curl -s --noproxy '*' "$STATS" +} + +# В CSV-выгрузке HAProxy колонка addr приходит пустой, поэтому привязка слота к +# конкретному контейнеру идёт по двум наблюдаемым фактам: контейнер отвечает на +# /health/ready, а число UP-слотов соответствует ожидаемому. +container_ready() { + docker exec "$1" wget -qO- -T 3 http://127.0.0.1:8080/health/ready 2>/dev/null | grep -q '"status":"ok"' +} + +wait_container_ready() { + name=$1 + attempt=0 + + while [ "$attempt" -lt 45 ]; do + container_ready "$name" && return 0 + attempt=$((attempt + 1)) + sleep 1 + done + + return 1 +} + +up_slots() { + stats_rows | awk -F, ' + NR == 1 { for (i = 1; i <= NF; i++) if ($i == "status") s = i; next } + $1 ~ /^api/ && $s == "UP" { count++ } END { print count + 0 }' +} + +wait_up_slots() { + want=$1 + attempt=0 + + while [ "$attempt" -lt 45 ]; do + [ "$(up_slots)" -ge "$want" ] && return 0 + attempt=$((attempt + 1)) + sleep 1 + done + + return 1 +} + +lb_5xx() { + stats_rows | awk -F, ' + NR == 1 { for (i = 1; i <= NF; i++) if ($i == "hrsp_5xx") column = i; next } + $1 == "http_front" && $2 == "FRONTEND" && column { print $column; exit }' +} + +{ + echo "# Rolling update under load (surge, one replica at a time)" + echo "# generated: $(date -u +%Y-%m-%dT%H:%M:%SZ)" + echo "# load: tolerant loader, duration=${DURATION}s concurrency=${CONCURRENCY}" + echo "# проверки готовности LB: httpchk /health/ready, inter 2s fall 2 rise 2, timeout check 1s" + echo + + # Сборка пишет много строк; в артефакт они не нужны. + compose build api >/dev/null 2>&1 || compose build api + + before_containers=$(api_containers) + replicas=$(printf '%s\n' "$before_containers" | wc -l | tr -d ' ') + [ "$replicas" -ge 2 ] || { echo "нужно не менее двух API-реплик" >&2; exit 1; } + + old_image=$(docker inspect --format '{{.Image}}' "$(printf '%s\n' "$before_containers" | head -1)") + new_image=$(docker image inspect --format '{{.Id}}' "$IMAGE") + echo "реплик до обновления: ${replicas}" + echo "образ старых реплик: ${old_image}" + echo "образ новой ревизии: ${new_image}" + echo "ревизия меняется: $([ "$old_image" = "$new_image" ] && echo 'нет (образ не изменился)' || echo 'да')" + echo "слотов UP до: $(up_slots); restarts до: $(restarts)" + echo + + envfile=$(mktemp) + trap 'rm -f "$envfile"; docker rm -f $(rollout_containers) >/dev/null 2>&1 || true' EXIT INT TERM + docker inspect --format '{{range .Config.Env}}{{println .}}{{end}}' \ + "$(printf '%s\n' "$before_containers" | head -1)" > "$envfile" + + # Перед измерением убеждаемся, что все ожидаемые реплики видит сам LB: после + # экспериментов с отказом хранилищ слоты могут быть в переходном состоянии. + if ! wait_up_slots "$replicas"; then + echo "перед обновлением LB видит меньше ${replicas} реплик" >&2 + exit 1 + fi + + five_before=$(lb_5xx) + # shellcheck disable=SC2086 + $NO_PROXY_ENV $PYTHON student-tests/rolling_update_load.py --base-url "$BASE_URL" \ + --duration "$DURATION" --concurrency "$CONCURRENCY" \ + --output "$OUT/load.json" > "$OUT/load.txt" 2>&1 & + load_pid=$! + + step=0 + for container in $before_containers; do + step=$((step + 1)) + name="$PREFIX-$step" + old_instance=$(docker inspect --format '{{.Config.Hostname}}' "$container") + started=$(date -u +%Y-%m-%dT%H:%M:%SZ) + + # 1. поднять реплику новой ревизии рядом со старыми; дождаться, что она + # сама готова и что LB видит на один слот больше + docker run -d --name "$name" --network "$NET" --network-alias api-replica \ + --env-file "$envfile" "$IMAGE" >/dev/null + new_instance=$(docker inspect --format '{{.Config.Hostname}}' "$name") + new_container_image=$(docker inspect --format '{{.Image}}' "$name") + + if ! wait_container_ready "$name"; then + echo " step ${step}: реплика ${name} не стала готова" >&2 + echo " diagnostics: status=$(docker inspect --format '{{.State.Status}}' "$name" 2>&1); stats: $(stats_rows | awk -F, '$1 ~ /^api/ { printf "%s=%s ", $2, $18 }')" >&2 + docker logs --tail 20 "$name" >&2 2>&1 || true + + exit 1 + fi + + if ! wait_up_slots "$((replicas + step))"; then + echo " step ${step}: UP-слотов меньше ожидаемого ($(up_slots) вместо $((replicas + step)))" >&2 + exit 1 + fi + + # 2. снять одну старую реплику и дождаться, что UP-слотов снова ровно + # столько, сколько реплик должно остаться + docker rm -f "$container" >/dev/null + + if ! wait_up_slots "$((replicas + step - 1))"; then + echo " step ${step}: после снятия UP-слотов больше ожидаемого" >&2 + exit 1 + fi + + printf ' step %s: %s обслуживает (образ %s, instance %s), старый контейнер %s (%s) снят; UP-слотов %s; 5xx накоплено %s; старт шага %s\n' \ + "$step" "$name" "${new_container_image#sha256:}" "$new_instance" \ + "${container:0:12}" "$old_instance" "$(up_slots)" "$(lb_5xx)" "$started" + done + + wait "$load_pid" || true + + five_after=$(lb_5xx) + echo + echo "load summary (tolerant generator):" + cat "$OUT/load.txt" + echo + echo "5xx от LB за время обновления (hrsp_5xx frontend): $((${five_after:-0} - ${five_before:-0}))" + echo "restarts после: $(restarts)" + + # 3. вернуть стенд под управление compose и убрать временные контейнеры + echo + echo "возврат стенда под управление compose:" + compose up -d --no-deps api + wait_up_slots "$replicas" || true + + remaining=$(printf '%s\n' $(rollout_containers) | wc -l | tr -d ' ') + for container in $(rollout_containers); do + docker rm -f "$container" >/dev/null + remaining=$((remaining - 1)) + + if ! wait_up_slots "$((replicas + remaining))"; then + echo " после снятия ${container} UP-слотов больше ожидаемого" >&2 + exit 1 + fi + done + + echo "снято временных контейнеров наплыва: проверено" + + echo "UP-слотов после: $(up_slots); restarts в конце: $(restarts)" + echo "API containers после обновления:" + docker ps --format '{{.Names}} {{.Status}}' \ + --filter "label=com.docker.compose.project=$PROJECT" \ + --filter 'label=com.docker.compose.service=api' +} > "$OUT/rolling-update.txt" 2>&1 + +cat "$OUT/rolling-update.txt" +printf 'rolling_update.sh: evidence in %s\n' "$OUT" diff --git a/scripts/start-broker.sh b/scripts/start-broker.sh new file mode 100755 index 0000000..5708295 --- /dev/null +++ b/scripts/start-broker.sh @@ -0,0 +1,6 @@ +#!/bin/sh +set -eu +ROOT_DIR=$(CDPATH= cd -- "$(dirname -- "$0")/.." && pwd) +cd "$ROOT_DIR" +COMPOSE_BIN=${COMPOSE_BIN:-docker compose} +$COMPOSE_BIN --env-file .env -f compose.yaml up -d --wait --no-deps broker diff --git a/scripts/start-worker.sh b/scripts/start-worker.sh new file mode 100755 index 0000000..3c2b170 --- /dev/null +++ b/scripts/start-worker.sh @@ -0,0 +1,6 @@ +#!/bin/sh +set -eu +ROOT_DIR=$(CDPATH= cd -- "$(dirname -- "$0")/.." && pwd) +cd "$ROOT_DIR" +COMPOSE_BIN=${COMPOSE_BIN:-docker compose} +$COMPOSE_BIN --env-file .env -f compose.yaml up -d --wait --no-deps worker diff --git a/scripts/stop-broker.sh b/scripts/stop-broker.sh new file mode 100755 index 0000000..5aa1d0b --- /dev/null +++ b/scripts/stop-broker.sh @@ -0,0 +1,6 @@ +#!/bin/sh +set -eu +ROOT_DIR=$(CDPATH= cd -- "$(dirname -- "$0")/.." && pwd) +cd "$ROOT_DIR" +COMPOSE_BIN=${COMPOSE_BIN:-docker compose} +$COMPOSE_BIN --env-file .env -f compose.yaml stop broker diff --git a/scripts/stop-one.sh b/scripts/stop-one.sh new file mode 100755 index 0000000..4a7f71e --- /dev/null +++ b/scripts/stop-one.sh @@ -0,0 +1,72 @@ +#!/bin/sh +set -eu +# Fault-injection hook: stop exactly ONE api replica of the lab5 stand. +# +# TARGET_INSTANCE_ID= scripts/stop-one.sh +# +# The task value is the instance alias the API reports in X-Instance-Id, i.e. +# the container hostname (docker's default = short container id). Container +# names of the api service are matched too. The container is only stopped +# (docker stop); databases, the load balancer and volumes are left untouched, +# and the replica stays down until it is started again explicitly, e.g. +# docker compose --env-file .env up -d --no-deps api +# No credentials are printed. +: "${TARGET_INSTANCE_ID:?test provides target API instance alias}" + +PROJECT=${COMPOSE_PROJECT_NAME:-mtusi-messenger-lab6} + +candidates=$(docker ps -q \ + --filter "label=com.docker.compose.project=${PROJECT}" \ + --filter "label=com.docker.compose.service=api") + +if [ -z "$candidates" ]; then + printf 'stop-one.sh: no api containers of project %s are running\n' "$PROJECT" >&2 + exit 1 +fi + +# Matches the requested alias against every reasonable identifier of a replica: +# container hostname (= X-Instance-Id), full/short container id, full container +# name (mtusi-messenger-lab4-api-1) and the service-local suffix (api-1). +match_replica() { + target=$1 + full_id=$2 + short_id=$3 + name=$4 + hostname=$5 + suffix=${name#${PROJECT}-} + + [ "$target" = "$hostname" ] && return 0 + [ "$target" = "$full_id" ] && return 0 + [ "$target" = "$short_id" ] && return 0 + [ "$target" = "$name" ] && return 0 + [ "$target" = "$suffix" ] && return 0 + return 1 +} + +matched="" +matched_names="" +for id in $candidates; do + info=$(docker inspect --format '{{.Id}} {{.Name}} {{.Config.Hostname}}' "$id") + full_id=$(printf '%s' "$info" | cut -d' ' -f1) + name=$(printf '%s' "$info" | cut -d' ' -f2 | sed 's|^/||') + hostname=$(printf '%s' "$info" | cut -d' ' -f3) + short_id=$(printf '%s' "$full_id" | cut -c1-12) + + if match_replica "$TARGET_INSTANCE_ID" "$full_id" "$short_id" "$name" "$hostname"; then + matched="$matched $id" + matched_names="$matched_names $name" + fi +done + +if [ -z "$matched" ]; then + printf 'stop-one.sh: no api replica matches TARGET_INSTANCE_ID=%s\n' "$TARGET_INSTANCE_ID" >&2 + exit 1 +fi + +# Shut down cleanly (SIGTERM) but never hang the caller for long. +for id in $matched; do + docker stop --time 5 "$id" >/dev/null +done + +printf 'stop-one.sh: stopped api replica(s):%s\n' "$matched_names" +exit 0 diff --git a/scripts/stop-worker.sh b/scripts/stop-worker.sh new file mode 100755 index 0000000..26a1691 --- /dev/null +++ b/scripts/stop-worker.sh @@ -0,0 +1,7 @@ +#!/bin/sh +set -eu +# Fault-injection hook: stop the lab5 worker and leave it stopped. +ROOT_DIR=$(CDPATH= cd -- "$(dirname -- "$0")/.." && pwd) +cd "$ROOT_DIR" +COMPOSE_BIN=${COMPOSE_BIN:-docker compose} +$COMPOSE_BIN --env-file .env -f compose.yaml stop worker diff --git a/scripts/track1_controls.sh b/scripts/track1_controls.sh new file mode 100755 index 0000000..829bfd5 --- /dev/null +++ b/scripts/track1_controls.sh @@ -0,0 +1,48 @@ +#!/bin/sh +# Контроль бюджетов БД и балансировщика, перемежённый с эталоном. +# +# По ходу серии пропускная способность дрейфует: таблица сообщений растёт +# (~95 тыс. строк на профиль), а вместе с ней и стоимость записи. Поэтому +# сравнивать профиль с бюджетом БД 1.00 CPU с эталоном, снятым четверть часа +# назад, нельзя — разница бюджетов утонет в дрейфе. Здесь эталон (2 реплики, +# PostgreSQL 0.50 CPU, LB 0.25 CPU) повторяется дважды, а каждая контролируемая +# ручка меняется ровно в одном профиле рядом с эталоном: +# +# ctl1base -> ctl2pg (БД 1.00) -> ctl3base -> ctl4lb (LB 1.00) +# +# Пара ctl1base/ctl3base даёт масштаб дрейфа за два профиля. +# +# scripts/track1_controls.sh +# rm evidence/track1/{load,stats,profile}-ctl*.{json,csv} # перемерить +set -eu + +ROOT_DIR=$(CDPATH= cd -- "$(dirname -- "$0")/.." && pwd) +cd "$ROOT_DIR" + +SCALING=scripts/track1_scaling.sh +OUT=${OUT:-evidence/track1} +export OUT + +export CLIENT=${CLIENT:-vm} +export TOTAL_CPU=1.0 TOTAL_MEM_MB=768 DURATION=60 CONCURRENCY=8 WARMUP=15 +export POSTGRES_CPU_LIMIT=0.50 POSTGRES_MEM_LIMIT=384M POSTGRES_MAX_CONNS=10 LB_CPU_LIMIT=0.25 + +run() { + label=$1 + shift + + if [ -f "$OUT/profile-$label.json" ] && [ -f "$OUT/load-$label.json" ]; then + printf 'track1_controls.sh: профиль %s пропущен — артефакты уже есть\n' "$label" + + return 0 + fi + + LABEL="$label" env "$@" "$SCALING" +} + +run ctl1base REPLICAS=2 +run ctl2pg REPLICAS=2 POSTGRES_CPU_LIMIT=1.00 +run ctl3base REPLICAS=2 +run ctl4lb REPLICAS=2 LB_CPU_LIMIT=1.00 + +printf 'track1_controls.sh: готово, сводка — python3 scripts/track1_report.py\n' diff --git a/scripts/track1_report.py b/scripts/track1_report.py new file mode 100755 index 0000000..867f2e1 --- /dev/null +++ b/scripts/track1_report.py @@ -0,0 +1,209 @@ +#!/usr/bin/env python3 +"""Сводка трека 1: артефакты `evidence/track1/*` -> таблица и графики. + +Читает `load-