refactor(server): move the dashboard, limits and log-forwarding handlers' SQL into repositories - #46
Merged
Conversation
…ers' SQL into repositories The 40 Postgres statements in the dashboard, health, route-health, analytics, chargeback, gateway-log, limits, log-forwarder and webhook-outbox handlers move into five repositories under `services/`: observability, analytics, limits, log_forwarder and webhook_outbox. SQL text, binds and fetch kinds are unchanged; six statements that were written out twice are now one function each. Callers that word database errors themselves keep getting a raw `sqlx::Error`. `WebhookOutboxRow` moves into its repository. New integration tests (admin_observability.rs) cover the endpoints that had none; they pass on the code before and after the move. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Part of moving the server handlers' raw SQL into repositories under
crates/server/src/services/(same approach as #45). No behaviour change.What moved
All 40 Postgres
sqlx::query*calls in these handlers now live in five repositories:observability_repositorydashboard/stats.rs(6),dashboard/live.rs(4),dashboard/scope.rs(2),dashboard/layout.rs(2),health.rs(3),route_observability.rs(1)analytics_repositoryanalytics.rs(4),chargeback.rs(1),gateway_logs.rs(1),limits.rs(1)log_forwarder_repositorylog_forwarders.rs(8)webhook_outbox_repositorywebhook_outbox.rs(5)limits_repositorylimits_bulk.rs(2, the per-row lookup and mutation onrate_limit_rules/budget_caps)SELECT 1, the log-forwarder lookup, the cost-center lookup, and the API-key lineage lookup).sqlx::Errorso the message is unchanged. Everything else returnsAppErrorexactly as?did before.WebhookOutboxRow(aFromRowtype) moves intowebhook_outbox_repository; the route-health row type moves intoobservability_repository.Evidence of no behaviour change
New
crates/test-support/tests/admin_observability.rs(9 tests) covers what the suite did not reach before: dashboard stats (PG fallback and the team-scoped ClickHouse path), live snapshot (provider/MCP rows, rpm reference line), layout save/replace,/health/readyand/api/health, route health ordering, API-key limits stored on the key lineage, log forwarder CRUD / toggle / reset-stats / test, webhook outbox list / counts / delete / retry, and analytics cost breakdowns by user and cost center with team scoping.git stashofcrates/server) and against this change.Checks run locally
cargo fmt --all --checkcargo clippy --workspace --all-targets -- -D warningsandcargo clippy --workspace --lib -- -D warningscargo nextest run --workspace --lib --bins --tests: 687 passed--run-ignored only --profile ci) with local pg/redis/clickhouse: 292 passedadmin_observability,admin_catalogandopenapi_contractbinaries again🤖 Generated with Claude Code