feat(routing): add provider metrics to routing metadata - #1257
Conversation
Include uptime, latency, and throughput metrics in routing metadata for direct provider selection and low-uptime fallback cases, providing full visibility into provider scores and performance characteristics. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
WalkthroughThe PR enhances provider routing logic in the gateway's chat service by adding retrieval and propagation of provider metrics (price, uptime, latency, throughput) across multiple routing paths. It enriches routing metadata with originalProviderScore and providerScores containing metrics for both the original provider and fallback providers in low-uptime scenarios, and extends direct-provider routing to include fetched provider metrics. Changes
Sequence DiagramsequenceDiagram
participant Chat as Chat Handler
participant Metrics as Metrics Service
participant Router as Router
participant Metadata as Routing Metadata
Chat->>Metrics: Fetch original provider metrics<br/>(price, uptime, latency, throughput)
Metrics-->>Chat: Provider metrics
alt Low Uptime Detected
Chat->>Metrics: Fetch fallback provider metrics
Metrics-->>Chat: Fallback metrics
Chat->>Chat: Create originalProviderScore
Chat->>Router: Build providerScores array<br/>(original + fallback)
Chat->>Metadata: Enrich with metrics<br/>(uptime, latency, throughput)
else Direct Provider Selected
Chat->>Metrics: Fetch selected provider metrics
Metrics-->>Chat: Provider metrics
Chat->>Metadata: Attach provider metrics<br/>to routing data
end
Chat->>Router: Route request with enriched metadata
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes
Possibly related PRs
Suggested reviewers
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
🧰 Additional context used📓 Path-based instructions (4)**/*.{js,ts,jsx,tsx}📄 CodeRabbit inference engine (AGENTS.md)
Files:
**/*.{ts,tsx,js,jsx}📄 CodeRabbit inference engine (AGENTS.md)
Files:
**/*.{ts,tsx}📄 CodeRabbit inference engine (AGENTS.md)
Files:
apps/{gateway,api}/**/*.{ts,tsx}📄 CodeRabbit inference engine (AGENTS.md)
Files:
🧬 Code graph analysis (1)apps/gateway/src/chat/chat.ts (2)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (9)
🔇 Additional comments (2)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Include uptime, latency, and throughput metrics in routing metadata for direct provider selection and low-uptime fallback cases. This provides full visibility into provider scores and performance characteristics in the routing logs.
For direct provider selection (
direct-provider-specified,single-provider-available,fallback-first-available), metrics are now fetched and included. For low-uptime fallback, the original requested provider is added to the scores array with a negative score indicating it was skipped due to low uptime.Summary by CodeRabbit
Release Notes
✏️ Tip: You can customize this high-level summary in your review settings.