Skip to content

Commit

Permalink
Introduce tower service into clients
Browse files Browse the repository at this point in the history
Signed-off-by: Paul Scoropan <[email protected]>

Co-authored-by: Evaline Ju <[email protected]>
  • Loading branch information
pscoro and evaline-ju committed Dec 5, 2024
1 parent 746dbaf commit 05b8f2c
Show file tree
Hide file tree
Showing 4 changed files with 113 additions and 55 deletions.
103 changes: 74 additions & 29 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ http-body-util = "0.1.2"
http-serde = "2.1.1"
hyper = { version = "1.4.1", features = ["http1", "http2", "server"] }
hyper-rustls = { version = "0.27.3", features = ["ring"]}
hyper-timeout = "0.5.2"
hyper-util = { version = "0.1.7", features = ["server-auto", "server-graceful", "tokio"] }
mime = "0.3.17"
mio = "1.0.2"
Expand All @@ -52,14 +53,15 @@ tokio = { version = "1.39.2", features = ["rt", "rt-multi-thread", "parking_lot"
tokio-rustls = { version = "0.26.0", features = ["ring"]}
tokio-stream = { version = "0.1.15", features = ["sync"] }
tonic = { version = "0.12.1", features = ["tls", "tls-roots", "tls-webpki-roots"] }
tower = "0.5.1"
tower-http = { version = "0.5.2", features = ["trace"] }
tower-service = "0.3"
tower-timeout = "0.3.0"
tracing = "0.1.40"
tracing-opentelemetry = "0.25.0"
tracing-subscriber = { version = "0.3.18", features = ["json", "env-filter"] }
url = "2.5.2"
uuid = { version = "1.10.0", features = ["v4", "fast-rng"] }
hyper-timeout = "0.5.2"

[build-dependencies]
tonic-build = "0.12.1"
Expand Down
9 changes: 8 additions & 1 deletion src/clients.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ use ginepro::LoadBalancedChannel;
use hyper_timeout::TimeoutConnector;
use hyper_util::rt::TokioExecutor;
use tonic::{metadata::MetadataMap, Request};
use tower::ServiceBuilder;
use tower_timeout::TimeoutLayer;
use tracing::{debug, instrument, Span};
use tracing_opentelemetry::OpenTelemetrySpanExt;
use url::Url;
Expand Down Expand Up @@ -244,7 +246,10 @@ pub async fn create_http_client(

let client =
hyper_util::client::legacy::Client::builder(TokioExecutor::new()).build(timeout_conn);
Ok(HttpClient::new(base_url, request_timeout, client))
let client = ServiceBuilder::new()
.layer(TimeoutLayer::new(request_timeout))
.service(client);
Ok(HttpClient::new(base_url, client))
}

#[instrument(skip_all, fields(hostname = service_config.hostname))]
Expand Down Expand Up @@ -306,6 +311,8 @@ pub async fn create_grpc_client<C>(
.channel()
.await
.unwrap_or_else(|error| panic!("error creating grpc client: {error}"));

let channel = ServiceBuilder::new().service(channel);
new(channel)
}

Expand Down
Loading

0 comments on commit 05b8f2c

Please sign in to comment.