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(BOUN-1156): Integration of Discovery Library #3

Merged
merged 9 commits into from
Jun 7, 2024

Conversation

nikolay-komarevskiy
Copy link
Contributor

@nikolay-komarevskiy nikolay-komarevskiy commented Jun 3, 2024

Incorporate HealthCheckRouteProvider to ic-gateway for dynamic routing mode.

@nikolay-komarevskiy nikolay-komarevskiy force-pushed the BOUN-1156-integrate-discovery-library branch 3 times, most recently from acd7193 to 78af939 Compare June 3, 2024 18:26
@nikolay-komarevskiy nikolay-komarevskiy force-pushed the BOUN-1156-integrate-discovery-library branch from 78af939 to 3ca5234 Compare June 5, 2024 15:33
@nikolay-komarevskiy nikolay-komarevskiy marked this pull request as ready for review June 5, 2024 15:51
src/cli.rs Outdated

/// Whether to use static URLs or dynamically discovered URLs for routing.
/// For the dynamic routing case, provided argument ic-url: Vec<Url> is used as a seed list of API Nodes.
#[clap(long = "use_dynamic_routing")]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change to ic-use-dynamic-routing or better ic-use-discovery maybe...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

const SERVICE_NAME: &str = "HealthCheckImpl";

#[derive(Debug)]
pub struct HealthCheckImpl {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd call that HealthChecker or smth like this, I don't understand those -Impl suffixes :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

.map_err(|err| TransportProviderError::UnableToGetTransport(err.to_string()))?,
);

Ok(transport as Arc<dyn Transport>)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as Arc<dyn Transport> isn't needed here I think

src/tasks.rs Outdated
S: Send + Sync + Debug + Clone + Snapshot + 'static,
{
async fn run(&self, token: CancellationToken) -> Result<(), Error> {
self.0.run().await;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will get stuck on this await forever and will not stop when the token is cancelled. You need select! here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought about using select! when implementing it, but it felt unnecessary. self.0.run().await; is designed to return immediately. So the token cancellation will be awaited right away and will let the stop() be called after.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i can put select! though to make it even more robust

Copy link
Contributor Author

@nikolay-komarevskiy nikolay-komarevskiy Jun 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

on the other hand, calling self.0.stop() before this nearly instantself.0.run().await finishes can be IMO ungraceful, as this is rather start() actually

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if run() does not block on await then it's ok as-is, I thought it just blocks there.

src/tasks.rs Outdated
@@ -63,3 +64,18 @@ impl Run for ocsp_stapler::Stapler {
Ok(())
}
}

pub struct TaskRouteProvider<S>(pub Arc<HealthCheckRouteProvider<S>>);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Btw do we even need a newtype around it? Maybe just implement Run directly?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not necessary indeed, i thought having the same run() method would be confusing for the compiler, but it seems not

@nikolay-komarevskiy nikolay-komarevskiy force-pushed the BOUN-1156-integrate-discovery-library branch from e82d9b4 to 1cbeb82 Compare June 6, 2024 12:32
return Err(anyhow!("Seed list of API Nodes can't be empty"));
}

let route_provider = {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we maybe move this stuff along with the constants somewhere to the ic module? To keep setup_router() shorter and cleaner.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure, done

let route_provider = Arc::new(
RoundRobinRouteProvider::new(vec![url.as_str()])
.map_err(|err| TransportProviderError::UnableToGetTransport(err.to_string()))?,
) as Arc<dyn RouteProvider>;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again as Arc<dyn RouteProvider> isn't needed, Rust is smart enough to figure out :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clippy is needed here

@nikolay-komarevskiy nikolay-komarevskiy force-pushed the BOUN-1156-integrate-discovery-library branch from 23d3c84 to 85ee156 Compare June 7, 2024 05:46
@nikolay-komarevskiy nikolay-komarevskiy force-pushed the BOUN-1156-integrate-discovery-library branch from 85ee156 to a784363 Compare June 7, 2024 05:48
@blind-oracle
Copy link
Collaborator

Hey I guess let's merge it, though I made some changes to the router but I guess it should merge w/o conflicts.

@nikolay-komarevskiy nikolay-komarevskiy merged commit 4765ffb into main Jun 7, 2024
3 checks passed
@nikolay-komarevskiy nikolay-komarevskiy deleted the BOUN-1156-integrate-discovery-library branch June 7, 2024 18:14
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