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

[Refactoring] Consolidate multiple create Tonic channel functions #2469

Merged
merged 3 commits into from
Jan 10, 2025

Conversation

pcholakov
Copy link
Contributor

@pcholakov pcholakov commented Jan 6, 2025

Eliminates some duplication across test and prod code for creating GRPC channels.

@pcholakov pcholakov changed the base branch from main to feat/trim-gap-e2e-test January 6, 2025 16:07
}

fn keep_alive_interval(&self) -> Duration {
Duration::from_secs(60)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hard-coding this for the CLI should be okay; wanted to keep the trait as-is to avoid changing prod code.

@@ -63,7 +67,7 @@ pub(crate) struct ConfirmMode {
}

#[derive(Args, Clone, Default)]
pub(crate) struct NetworkOpts {
pub struct NetworkOpts {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We now need to export this struct to make this work.

Comment on lines 340 to 341
connect_timeout: 1000,
request_timeout: 5000,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Seemed reasonable for tests.

@pcholakov pcholakov requested a review from tillrohrmann January 6, 2025 16:09
@pcholakov pcholakov marked this pull request as ready for review January 6, 2025 16:10
Copy link

github-actions bot commented Jan 6, 2025

Test Results

  7 files  ±0    7 suites  ±0   4m 24s ⏱️ +4s
 47 tests ±0   46 ✅ ±0  1 💤 ±0  0 ❌ ±0 
182 runs  ±0  179 ✅ ±0  3 💤 ±0  0 ❌ ±0 

Results for commit d661cd7. ± Comparison against base commit 483dcd6.

♻️ This comment has been updated with latest results.

Copy link
Contributor

@tillrohrmann tillrohrmann left a comment

Choose a reason for hiding this comment

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

Thanks for creating this PR @pcholakov. This is a good clean up! The one question I have is whether we want to enable create_tonic_channel_from_advertised_address to also accept a request timeout so that we don't have to change the semantics of restatectl?

Comment on lines 88 to 94
fn keep_alive_timeout(&self) -> Duration {
Duration::from_millis(self.request_timeout)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Isn't this a different meaning than before? Before request_timeout defined a timeout for the overall request.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you for pointing this out, I was very sloppy here! I totally mixed up request timeout and connect timeout. Fixed now by introducing a dedicated optional request_timeout() method on the config trait.

I'm still defaulting keep-alive timeout to the connect_timeout with a very large fixed interval for the CLI. Previously we didn't set it but I think this is benign because:

  • a keep-alive should be cheap for the peer to process; we should receive a response much faster than a typical request as it requires effectively zero "service time"
  • CLI connections are in any event unlikely to live longer than the (hard-coded to 60s) keep-alive interval

It feels kludgey but I didn't want to make these optional in the common config trait.

Comment on lines 355 to 350
fn keep_alive_timeout(&self) -> Duration {
Duration::from_millis(self.request_timeout)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Same question here. Before we seem to have set Channel::builder().timeout(request_timeout) which is no longer the case with this change.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed now; I was being blind - I've added a dedicated request_timeout property. I messed up when merging the logic of the cli/test-only and production code endpoint building.

AdvertisedAddress::Http(uri) => {
Channel::builder(uri)
.connect_timeout(ctx.connect_timeout())
.timeout(ctx.request_timeout())
Copy link
Contributor

Choose a reason for hiding this comment

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

How are we setting the overall timeout now? Or is this no longer needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added back! My mistake!

@pcholakov pcholakov force-pushed the feat/trim-gap-e2e-test branch 6 times, most recently from 5200c2a to 81d3b2e Compare January 8, 2025 08:42
@pcholakov pcholakov force-pushed the refactor/consolidate-create-tonic-channel-copies branch 2 times, most recently from 3aca5aa to df3d0bd Compare January 8, 2025 10:34
Comment on lines 88 to 94
fn keep_alive_timeout(&self) -> Duration {
Duration::from_millis(self.request_timeout)
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you for pointing this out, I was very sloppy here! I totally mixed up request timeout and connect timeout. Fixed now by introducing a dedicated optional request_timeout() method on the config trait.

I'm still defaulting keep-alive timeout to the connect_timeout with a very large fixed interval for the CLI. Previously we didn't set it but I think this is benign because:

  • a keep-alive should be cheap for the peer to process; we should receive a response much faster than a typical request as it requires effectively zero "service time"
  • CLI connections are in any event unlikely to live longer than the (hard-coded to 60s) keep-alive interval

It feels kludgey but I didn't want to make these optional in the common config trait.

Comment on lines 355 to 350
fn keep_alive_timeout(&self) -> Duration {
Duration::from_millis(self.request_timeout)
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed now; I was being blind - I've added a dedicated request_timeout property. I messed up when merging the logic of the cli/test-only and production code endpoint building.

AdvertisedAddress::Http(uri) => {
Channel::builder(uri)
.connect_timeout(ctx.connect_timeout())
.timeout(ctx.request_timeout())
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added back! My mistake!

@@ -30,36 +30,47 @@ use restate_types::net::{AdvertisedAddress, BindAddress};

use crate::{cancellation_watcher, ShutdownError, TaskCenter, TaskKind};

pub fn create_tonic_channel_from_advertised_address<T: CommonClientConnectionOptions>(
pub fn create_tonic_channel<T: CommonClientConnectionOptions>(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

An approach where we accept a closure to customize the endpoint might be a nicer alternative if CommonClientConnectionOptions gets any more complex, but I'm punting on that for now.

@pcholakov pcholakov requested a review from tillrohrmann January 8, 2025 10:37
@pcholakov pcholakov force-pushed the feat/trim-gap-e2e-test branch from 81d3b2e to 9592d6a Compare January 8, 2025 13:48
Base automatically changed from feat/trim-gap-e2e-test to main January 8, 2025 16:07
Copy link
Contributor

@tillrohrmann tillrohrmann left a comment

Choose a reason for hiding this comment

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

Nice work @pcholakov. This is a good improvement and clean up :-) LGTM. +1 for merging.

@pcholakov pcholakov force-pushed the refactor/consolidate-create-tonic-channel-copies branch from df3d0bd to 6ef9a2a Compare January 10, 2025 14:36
@pcholakov pcholakov merged commit a5e1503 into main Jan 10, 2025
15 checks passed
@pcholakov pcholakov deleted the refactor/consolidate-create-tonic-channel-copies branch January 10, 2025 15:19
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