Skip to content

feat(serving): API-usage + session analytics behind ControlPlaneStore (ADR 0010 slice 4) - #134

Merged
brownjuly2003-code merged 1 commit into
mainfrom
feature/control-plane-slice4-usage
Jul 2, 2026
Merged

brownjuly2003-code merged 1 commit into
mainfrom
feature/control-plane-slice4-usage

Conversation

@brownjuly2003-code

Copy link
Copy Markdown
Owner

Summary

  • api_usage (per-tenant/per-key request counters) and api_sessions (per-request latency/entity/query telemetry) move behind ControlPlaneStore.
  • Unlike slices 1-3, this state never shared query_engine._conn — AuthManager.db_path always resolves to its own DuckDB file. EmbeddedControlPlaneStore gains a second, orthogonal usage_db_path_provider alongside conn_provider/alert_rules_path_provider; AuthManager builds a private embedded store around its own path (mirrors OutboxProcessor's additive-store pattern) rather than sharing the app-wide store.
  • Scope widened past usage_table.py + analytics.py: KeyRotator (key_rotation.py) queried api_usage directly for old-key-usage stats, and the admin dashboard (admin_ui.py) queried api_sessions directly for its QPS tile — both bypassed every prior slice's port. Covered here so slice 5's PostgreSQL swap doesn't leave two call sites hard-wired to a local DuckDB file.
  • All pre-port public/test-facing function signatures preserved (ensure_usage_table(manager), record_usage(manager, tenant_key, endpoint), usage_by_tenant(manager), the 5 analytics read functions taking db_path, _insert_session(db_path, request_id, record)) — only the SQL/connection handling moved into EmbeddedControlPlaneStore.
  • Windows file-lock fallback (record_usage's temp-path rename on duckdb.IOException) and the best-effort log-and-return-on-exhaustion behavior for session writes (vs. record_api_usage's raise, which record_usage depends on to skip its post-insert audit publish) both moved verbatim.

Test plan

  • ruff check / ruff format --check clean on src + tests
  • mypy src — no issues (114 files)
  • Full unit + property suite: 1575 passed
  • Full integration suite (excluding docker/live): 206 passed, 19 skipped, 5 deselected
  • Verified on the rebased branch (post slice-3 merge), not just in isolation

🤖 Generated with Claude Code

… (ADR 0010 slice 4)

api_usage/api_sessions never shared query_engine._conn (AuthManager.db_path
is always its own file), so EmbeddedControlPlaneStore gains a second,
orthogonal usage_db_path_provider alongside conn_provider. Scope widened past
usage_table.py/analytics.py: key_rotation.py's old-key-usage queries and
admin_ui.py's QPS tile also queried these tables directly and are covered
here too, so slice 5's PostgreSQL swap doesn't leave two call sites hard-wired
to a local DuckDB file. All pre-port public/test-facing signatures preserved.
@github-actions

github-actions Bot commented Jul 2, 2026

Copy link
Copy Markdown

DORA Metrics

  • Window: last 30 days
  • Branch: main
  • Deployment frequency: 128 total / 29.87 per week
  • Lead time for changes: avg 0.4h / median 0.0h
  • Change failure rate: 75.78% (97/128)
  • MTTR: 0.25h across 3 incident(s)

@brownjuly2003-code
brownjuly2003-code merged commit b901b5d into main Jul 2, 2026
23 checks passed
@brownjuly2003-code
brownjuly2003-code deleted the feature/control-plane-slice4-usage branch July 2, 2026 19:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants