refactor: remove analytics channel, use outlet batch dispatch directly#867
refactor: remove analytics channel, use outlet batch dispatch directly#867fergusfinn wants to merge 1 commit into
Conversation
The analytics pipeline previously had two batching layers: 1. outlet accumulated responses and dispatched batches 2. AnalyticsHandler scattered items into a 10k channel 3. AnalyticsBatcher re-accumulated from the channel and flushed Now that outlet handles batching natively (0.8.0), this simplifies to: 1. outlet accumulates and dispatches batches 2. AnalyticsHandler.handle_response_batch extracts records 3. AnalyticsWriter.flush does enrichment + transactional write directly Changes: - Rename AnalyticsBatcher → AnalyticsWriter, remove channel/accumulation loop - Override handle_response_batch on AnalyticsHandler for direct batch processing - Remove analytics background task from BackgroundServices - Increase outlet channel_capacity to 16384 (sole buffer for billing data)
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
Deploying control-layer with
|
| Latest commit: |
199b9df
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://14fcb0df.control-layer.pages.dev |
| Branch Preview URL: | https://refactor-analytics-direct-ba.control-layer.pages.dev |
There was a problem hiding this comment.
Pull request overview
This PR refactors the Rust backend analytics/billing pipeline to remove the intermediate analytics channel + background batcher task, and instead process outlet’s response batches directly via an AnalyticsWriter that enriches and writes records transactionally.
Changes:
- Remove the analytics channel and background “analytics-batcher” task; rely on outlet batch dispatch.
- Rename
AnalyticsBatcher→AnalyticsWriterand expose aflush(&[RawAnalyticsRecord])API for batched writes. - Update router/background service wiring to enable analytics without passing around an analytics sender; increase outlet buffer capacity.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 8 comments.
Show a summary per file
| File | Description |
|---|---|
dwctl/src/test/mod.rs |
Updates build_router call sites to match the new signature. |
dwctl/src/request_logging/mod.rs |
Stops re-exporting the removed AnalyticsBatcher. |
dwctl/src/request_logging/batcher.rs |
Refactors the former batcher into AnalyticsWriter and updates integration tests to call flush. |
dwctl/src/request_logging/analytics_handler.rs |
Implements direct handle_response_batch processing and delegates to AnalyticsWriter. |
dwctl/src/lib.rs |
Wires analytics handler directly in build_router, removes batcher background task setup, and increases outlet channel_capacity. |
Comments suppressed due to low confidence (2)
dwctl/src/request_logging/batcher.rs:55
- The doc comment for
RawAnalyticsRecordstill says the record is "sent through the channel" and that enrichment happens in the "batcher", but this PR removes the channel and renames the component toAnalyticsWriter. Updating this comment will prevent confusion when reading the new architecture.
/// Raw analytics record sent through the channel (unenriched).
///
/// This contains only data that can be extracted from the request/response
/// without any database lookups. Enrichment happens in the batcher.
#[derive(Debug, Clone)]
dwctl/src/request_logging/mod.rs:10
request_loggingno longer re-exports the renamed writer type. PreviouslyAnalyticsBatcherwas exported from this module; after the rename, consider re-exportingAnalyticsWriter(or documenting the intended access path) to avoid an accidental public API breaking change.
pub use analytics_handler::AnalyticsHandler;
pub use models::{AiRequest, AiResponse, ParsedAIRequest};
You can also share your feedback on Copilot code review. Take the survey.
Summary
AnalyticsBatcher→AnalyticsWriter(no longer batches, just enriches + writes)handle_response_batchonAnalyticsHandlerfor direct batch processinganalytics-batcherbackground task fromBackgroundServiceschannel_capacityfrom 4096 → 16384 since outlet is now the sole buffer for billing dataBefore
After
Net result: -161 lines, one fewer background task, one fewer channel, same enrichment/write/retry logic.
Test plan
just lint rustpassesjust test rustpasses (1053 tests, 0 failures)