Skip to content

feat: expose k_top_nodes in DynamicRouteProviderBuilder#716

Open
shilingwang wants to merge 3 commits intodfinity:mainfrom
shilingwang:shiling/top-k
Open

feat: expose k_top_nodes in DynamicRouteProviderBuilder#716
shilingwang wants to merge 3 commits intodfinity:mainfrom
shilingwang:shiling/top-k

Conversation

@shilingwang
Copy link
Contributor

Background

LatencyRoutingSnapshot has long supported a k_top_nodes option that limits routing to only the top k nodes ranked by latency score. However, this option became inaccessible after #694 removed the generic snapshot parameter from DynamicRouteProviderBuilder, leaving set_k_top_nodes effectively dead code.

Changes

Added k_top_nodes: Option<usize> as an explicit parameter to both DynamicRouteProviderBuilder::new() and DynamicRouteProviderBuilder::from_components(). Pass Some(k) to cap routing to the top k nodes by latency score, or None to use all healthy nodes (existing default behaviour).

Removed #[allow(unused)] from LatencyRoutingSnapshot::set_k_top_nodes, since it is now called from the builder.
Updated all internal call sites to pass None.

Usage

// Limit routing to the 5 lowest-latency nodes
DynamicRouteProviderBuilder::new(seeds, client, Some(5)).build()
// Use all healthy nodes (unchanged default)
DynamicRouteProviderBuilder::new(seeds, client, None).build()

@shilingwang shilingwang marked this pull request as ready for review March 19, 2026 15:33
@shilingwang shilingwang requested a review from a team as a code owner March 19, 2026 15:33
@shilingwang shilingwang requested a review from lwshang March 20, 2026 08:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants