Repository navigation
feat(routing): honor X-SMG-Routing-Key on any policy (#1843) #1848
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,6 +21,7 @@ use tracing::info; | |
|
|
||
| use super::{ | ||
| get_healthy_worker_indices, utils::PeriodicTask, LoadBalancingPolicy, SelectWorkerInfo, | ||
| WorkerLeg, | ||
| }; | ||
| use crate::{ | ||
| config::ManualAssignmentMode, observability::metrics::Metrics, | ||
|
|
@@ -202,7 +203,15 @@ impl ManualPolicy { | |
| } | ||
|
|
||
| if let Some(routing_id) = extract_routing_key(info.headers) { | ||
| let (idx, branch) = self.select_by_routing_id(workers, routing_id, &healthy_indices); | ||
| // Single is the common leg; route on the bare key to skip the | ||
| // per-request allocation. PD legs namespace so prefill and decode | ||
| // stick independently. | ||
| let (idx, branch) = if info.leg == WorkerLeg::Single { | ||
| self.select_by_routing_id(workers, routing_id, &healthy_indices) | ||
| } else { | ||
| let namespaced = format!("{}{}", info.leg.routing_id_prefix(), routing_id); | ||
| self.select_by_routing_id(workers, &namespaced, &healthy_indices) | ||
| }; | ||
| return (Some(idx), branch); | ||
| } | ||
|
Comment on lines
205
to
216
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Since if let Some(routing_id) = extract_routing_key(info.headers) {
let (idx, branch) = if info.leg == crate::policies::WorkerLeg::Single {
self.select_by_routing_id(workers, routing_id, &healthy_indices)
} else {
let namespaced = format!("{}{}", info.leg.routing_id_prefix(), routing_id);
self.select_by_routing_id(workers, &namespaced, &healthy_indices)
};
return (Some(idx), branch);
}References
|
||
|
|
||
|
|
@@ -330,6 +339,34 @@ mod tests { | |
| headers | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_manual_leg_namespaces_sticky_entries() { | ||
| let policy = ManualPolicy::new(); | ||
| let workers = create_workers(&["http://w1:8000", "http://w2:8000", "http://w3:8000"]); | ||
| let headers = headers_with_routing_key("user-123"); | ||
|
|
||
| let prefill = SelectWorkerInfo { | ||
| headers: Some(&headers), | ||
| leg: WorkerLeg::Prefill, | ||
| ..Default::default() | ||
| }; | ||
| let decode = SelectWorkerInfo { | ||
| headers: Some(&headers), | ||
| leg: WorkerLeg::Decode, | ||
| ..Default::default() | ||
| }; | ||
|
|
||
| let (p1, _) = policy.select_worker_impl(&workers, &prefill); | ||
| let (d1, _) = policy.select_worker_impl(&workers, &decode); | ||
|
|
||
| // Same key under two legs -> two independent sticky entries. | ||
| assert_eq!(policy.routing_map.len(), 2); | ||
| for _ in 0..5 { | ||
| assert_eq!(policy.select_worker_impl(&workers, &prefill).0, p1); | ||
| assert_eq!(policy.select_worker_impl(&workers, &decode).0, d1); | ||
| } | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_manual_consistent_routing() { | ||
| let policy = ManualPolicy::new(); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.