Skip to content

feat(analytics): PR-A -- Usage Analytics v1 event pipeline foundation - #37

Merged
man4ish merged 1 commit into
mainfrom
feature/analytics-a-event-pipeline
Aug 12, 2026
Merged

feat(analytics): PR-A -- Usage Analytics v1 event pipeline foundation#37
man4ish merged 1 commit into
mainfrom
feature/analytics-a-event-pipeline

Conversation

@man4ish

@man4ish man4ish commented Aug 12, 2026

Copy link
Copy Markdown
Collaborator

Summary

First of four sub-PRs implementing Usage Analytics v1 (control-center-local, no separate service -- see the full task brief/plan). This PR ships only the Redis Streams ingestion pipeline: no HTTP surface yet.

  • analytics/schemas.py -- normalized AnalyticsEvent contract + mapping from omnibioai-auth's real InteractionEvent wire shape.
  • analytics/consumer.py -- Redis Streams consumer-group worker, mirroring omnibioai-auth/app/workers/interaction_consumer.py's proven pattern (stable consumer identity, own-pending crash recovery, ack-only-after-durable-write). Reads both interactions:events and audit:events in one process under one consumer group.
  • analytics/aggregator.py -- idempotent write-side aggregation + stream-free read-side. audit:events has no organization_id, so anything derived from it is written only to platform-wide keys, never org-scoped.
  • analytics/cache.py, analytics/metrics.py -- cache-aside helper + the 8 analytics_* observability counters on the existing /metrics endpoint.
  • New control-center-analytics-worker compose service (same image, command override only).

Architecture notes (read before reviewing PR-C/D)

Two real gaps in the actual deployed platform, discovered by reading the code rather than assumed from the task brief:

  1. No Prometheus server is deployed anywhere in this workspace (per-service /metrics endpoints exist, nothing scrapes them).
  2. interactions:events has exactly one real producer today (RAG's /v1/query) -- no workflow.*/api.* events exist yet, and the event has no team_id/duration_ms/request_id.

Both are designed around explicitly, not hidden -- see the plan doc and this PR's own module docstrings.

Test plan

  • python -m pytest (backend): 1029 passed, 99.82% coverage (gate: 98%). New analytics package: 100% coverage.
  • Consumer test matrix per the task brief: valid event, malformed event, missing user ID, missing organization ID, duplicate event, Redis failure, consumer restart, stream offset persistence -- see test_analytics_consumer.py.

🤖 Generated with Claude Code

Redis Streams consumer + aggregator for the new Usage Analytics
capability (control-center-local, no separate service). No HTTP surface
yet -- this PR only builds and proves the ingestion pipeline; the API
layer, RBAC, and frontend follow in separate PRs.

- analytics/schemas.py: normalized AnalyticsEvent contract + the mapping
  from omnibioai-auth's real InteractionEvent wire shape (the only
  producer today is RAG's /v1/query -- no workflow.*/api.* events exist
  anywhere in this workspace yet, confirmed by reading every producer).
- analytics/consumer.py: a Redis Streams consumer-group worker mirroring
  omnibioai-auth/app/workers/interaction_consumer.py's proven shape
  (stable consumer name, own-pending crash recovery, ack-only-after-
  durable-write, fail-open on malformed payloads/Redis errors). Reads
  both interactions:events and audit:events under one consumer group
  in a single process.
- analytics/aggregator.py: write-side (idempotent HINCRBY-based Redis
  aggregates, deduped on event id) + read-side (pure aggregate reads,
  never replays a stream). audit:events has no organization_id
  (confirmed by reading omnibioai-api-gateway's audit_client.py), so its
  counters/latency histogram are written ONLY to the platform-wide
  bare-date keys, never under an org_id-keyed one.
- analytics/cache.py, analytics/metrics.py: Redis cache-aside helper and
  the 8 analytics_* observability counters (registered on the existing
  /metrics endpoint via prometheus_client, already a transitive dep).
- New control-center-analytics-worker compose service, same image as
  control-center, command override only -- no new Dockerfile.

100% coverage on the new package; full existing suite (1029 tests)
still green at 99.82% overall, above the 98% gate.
@man4ish
man4ish merged commit ae43675 into main Aug 12, 2026
1 check passed
@man4ish
man4ish deleted the feature/analytics-a-event-pipeline branch August 12, 2026 03:37
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.

1 participant