Skip to content
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

feat: add fn n_routes() to RouteProvider trait #584

Conversation

nikolay-komarevskiy
Copy link
Contributor

@nikolay-komarevskiy nikolay-komarevskiy commented Aug 19, 2024

Description

RouteProvider trait is extended with fn n_routes(), which generates up to n different routing urls:

pub trait RouteProvider: std::fmt::Debug + Send + Sync {
    /// Generates the next routing URL based on the internal routing logic.
    ///
    /// This method returns a single `Url` that can be used for routing.
    /// The logic behind determining the next URL can vary depending on the implementation
    fn route(&self) -> Result<Url, AgentError>;

    /// Generates up to `n` different routing URLs in order of priority.
    ///
    /// This method returns a vector of `Url` instances, each representing a routing
    /// endpoint. The URLs are ordered by priority, with the most preferred route
    /// appearing first. The returned vector can contain fewer than `n` URLs if
    /// fewer are available.
    fn n_ordered_routes(&self, n: usize) -> Result<Vec<Url>, AgentError>;
}

This newly introduced method should facilitate retry logic, in case routing url is unhealthy.
Calling the fn route() for retries was (and still is) possible. However, implementations do not provide guarantees that urls returned in sequential invocations are unique. Function fn n_routes() comes at rescue and returns up to n unique routing urls, which are also ordered by priority.

How Has This Been Tested?

Additional tests have been added.

Checklist:

  • The title of this PR complies with Conventional Commits.
  • I have edited the CHANGELOG accordingly.
  • I have made corresponding changes to the documentation.

@nikolay-komarevskiy nikolay-komarevskiy changed the base branch from main to dynamic_route August 19, 2024 11:16
@nikolay-komarevskiy nikolay-komarevskiy marked this pull request as ready for review August 19, 2024 14:00
@nikolay-komarevskiy nikolay-komarevskiy requested a review from a team as a code owner August 19, 2024 14:00
@adamspofford-dfinity adamspofford-dfinity merged commit 6099348 into dfinity:dynamic_route Aug 19, 2024
24 checks passed
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.

2 participants