-
Notifications
You must be signed in to change notification settings - Fork 22
Misc Cleanups #33
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
Misc Cleanups #33
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -32,7 +32,6 @@ use crate::{ | |
| }, | ||
| secrets::{TlsConfigurator, WantsToBuildClient}, | ||
| thread_local::{LocalBuilder, LocalObject}, | ||
| utils::tokio::TokioExecutor, | ||
| Error, PolyBody, Result, | ||
| }; | ||
| use http::{ | ||
|
|
@@ -42,11 +41,11 @@ use http::{ | |
| use http_body_util::BodyExt; | ||
| use hyper::{body::Incoming, Request, Uri}; | ||
| use hyper_rustls::{FixedServerNameResolver, HttpsConnector}; | ||
| use opentelemetry::KeyValue; | ||
| use orion_client::{ | ||
| use hyper_util::{ | ||
| client::legacy::{connect::Connect, Builder, Client}, | ||
| rt::tokio::TokioTimer, | ||
| rt::tokio::{TokioExecutor, TokioTimer}, | ||
| }; | ||
| use opentelemetry::KeyValue; | ||
| use orion_configuration::config::{ | ||
| cluster::http_protocol_options::{Codec, HttpProtocolOptions}, | ||
| network_filters::http_connection_manager::RetryPolicy, | ||
|
|
@@ -71,10 +70,11 @@ use webpki::types::ServerName; | |
|
|
||
| #[cfg(feature = "metrics")] | ||
| use { | ||
| orion_client::client::legacy::pool::{ConnectionEvent, EventHandler, Tag}, | ||
| orion_client::client::legacy::PoolKey, | ||
| hyper_util::client::legacy::pool::{ConnectionEvent, EventHandler, Tag}, | ||
| hyper_util::client::legacy::PoolKey, | ||
| std::any::Any, | ||
| }; | ||
| const DEFAULT_IDLE_TIMEOUT: Duration = Duration::from_secs(30); | ||
|
|
||
| type IncomingResult = (std::result::Result<Response<Incoming>, Error>, Duration); | ||
|
|
||
|
|
@@ -118,6 +118,7 @@ impl HttpChannelClient { | |
| } | ||
| } | ||
|
|
||
| #[derive(Default)] | ||
| pub struct HttpChannelBuilder { | ||
| tls: Option<TlsConfigurator<ClientConfig, WantsToBuildClient>>, | ||
| authority: Option<Authority>, | ||
|
|
@@ -142,15 +143,7 @@ impl LocalBuilder<HttpsConnector<LocalConnectorWithDNSResolver>, Arc<HttpsClient | |
|
|
||
| impl HttpChannelBuilder { | ||
| pub fn new(bind_device: Option<BindDevice>) -> Self { | ||
| Self { | ||
| tls: None, | ||
| authority: None, | ||
| cluster_name: None, | ||
| bind_device, | ||
| http_protocol_options: HttpProtocolOptions::default(), | ||
| server_name: None, | ||
| connection_timeout: None, | ||
| } | ||
| Self { bind_device, ..Default::default() } | ||
| } | ||
|
|
||
| pub fn with_tls(self, tls_configurator: Option<TlsConfigurator<ClientConfig, WantsToBuildClient>>) -> Self { | ||
|
|
@@ -179,96 +172,98 @@ impl HttpChannelBuilder { | |
|
|
||
| #[allow(clippy::cast_sign_loss)] | ||
| pub fn build(self) -> crate::Result<HttpChannel> { | ||
| let authority = self.authority.clone().ok_or("Authority is mandatory")?; | ||
| let mut client_builder = Client::builder(TokioExecutor); | ||
|
|
||
| let _cluster_name = self.cluster_name.unwrap_or_default(); | ||
|
|
||
| client_builder.timer(TokioTimer::new()); // note: legacy client builder is not persistent struct (&mut Self -> &mut Self) | ||
| client_builder | ||
| // Set an optional timeout for idle sockets being kept-alive. A Timer is required for this to take effect. | ||
| .pool_idle_timeout( | ||
| self.http_protocol_options.common.idle_timeout.unwrap_or(std::time::Duration::from_secs(30)), | ||
| ) | ||
| // Pass a timer for the timeout... | ||
| .pool_timer(TokioTimer::new()) | ||
| .pool_max_idle_per_host(usize::MAX) | ||
| .set_host(false); | ||
|
|
||
| let configured_upstream_http_version = self.http_protocol_options.codec; | ||
|
|
||
| if matches!(configured_upstream_http_version, Codec::Http2) { | ||
| client_builder.http2_only(true); | ||
| let http2_options = self.http_protocol_options.http2_options; | ||
| if let Some(settings) = &http2_options.keep_alive_settings { | ||
| client_builder.http2_keep_alive_interval(settings.keep_alive_interval); | ||
| if let Some(timeout) = settings.keep_alive_timeout { | ||
| client_builder.http2_keep_alive_timeout(timeout); | ||
| } | ||
| client_builder.http2_keep_alive_while_idle(true); | ||
| } | ||
| client_builder.http2_initial_connection_window_size(http2_options.initial_connection_window_size()); | ||
| client_builder.http2_initial_stream_window_size(http2_options.initial_stream_window_size()); | ||
| //fixme(hayley): this is not max_concurrent_streams! this is reset streams | ||
| if let Some(max) = http2_options.max_concurrent_streams() { | ||
| client_builder.http2_max_concurrent_reset_streams(max); | ||
| } | ||
| } | ||
|
|
||
| #[cfg(feature = "metrics")] | ||
| client_builder.event_handler(EventHandler::new(update_upstream_stats, _cluster_name)); | ||
| let authority = self.authority.clone().ok_or_else(|| Error::from("Authority is mandatory"))?; | ||
| let client_builder = self.configure_hyper_client(); | ||
|
|
||
| if let Some(tls_context) = self.tls { | ||
| let builder = hyper_rustls::HttpsConnectorBuilder::new(); | ||
| let builder = builder.with_tls_config(tls_context.into_inner()); | ||
| let builder = builder.https_or_http(); | ||
| let builder = if let Some(server_name) = self.server_name { | ||
| // Build TLS client inline to avoid ownership issues | ||
| let mut builder = | ||
| hyper_rustls::HttpsConnectorBuilder::new().with_tls_config(tls_context.into_inner()).https_or_http(); | ||
|
|
||
| builder = if let Some(server_name) = self.server_name { | ||
| builder.with_server_name_resolver(FixedServerNameResolver::new(server_name)) | ||
| } else { | ||
| let server_name = ServerName::try_from(authority.host().to_owned())?; | ||
| debug!("Server name is not configured in bootstrap.. using endpoint authority {:?}", server_name); | ||
| builder.with_server_name_resolver(FixedServerNameResolver::new(server_name)) | ||
| }; | ||
|
|
||
| let connector = LocalConnectorWithDNSResolver { | ||
| addr: authority.clone(), | ||
| cluster_name: self.cluster_name.unwrap_or_default(), | ||
| bind_device: self.bind_device, | ||
| timeout: self.connection_timeout, | ||
| }; | ||
|
|
||
| let tls_connector = match self.http_protocol_options.codec { | ||
| Codec::Http2 => builder.enable_http2().wrap_connector(LocalConnectorWithDNSResolver { | ||
| addr: authority.clone(), | ||
| cluster_name: self.cluster_name.unwrap_or_default(), | ||
| bind_device: self.bind_device, | ||
| timeout: self.connection_timeout, | ||
| }), | ||
|
|
||
| Codec::Http1 => builder.enable_http1().wrap_connector(LocalConnectorWithDNSResolver { | ||
| addr: authority.clone(), | ||
| cluster_name: self.cluster_name.unwrap_or_default(), | ||
| bind_device: self.bind_device, | ||
| timeout: self.connection_timeout, | ||
| }), | ||
| Codec::Http2 => builder.enable_http2().wrap_connector(connector), | ||
| Codec::Http1 => builder.enable_http1().wrap_connector(connector), | ||
| }; | ||
|
|
||
| Ok(HttpChannel { | ||
| client: HttpChannelClient::Tls(ClientContext::new( | ||
| configured_upstream_http_version, | ||
| self.http_protocol_options.codec, | ||
| Arc::new(LocalObject::new(client_builder, tls_connector)), | ||
| )), | ||
| http_version: configured_upstream_http_version, | ||
| http_version: self.http_protocol_options.codec, | ||
| upstream_authority: authority, | ||
| cluster_name: self.cluster_name.unwrap_or_default(), | ||
| }) | ||
| } else { | ||
| // Build plain client inline | ||
| let connector = LocalConnectorWithDNSResolver { | ||
| addr: authority.clone(), | ||
| cluster_name: self.cluster_name.unwrap_or_default(), | ||
| bind_device: self.bind_device, | ||
| timeout: self.connection_timeout, | ||
| cluster_name: self.cluster_name.unwrap_or_default(), | ||
| }; | ||
|
|
||
| Ok(HttpChannel { | ||
| client: HttpChannelClient::Plain(Arc::new(LocalObject::new(client_builder, connector))), | ||
| http_version: configured_upstream_http_version, | ||
| http_version: self.http_protocol_options.codec, | ||
| upstream_authority: authority, | ||
| cluster_name: self.cluster_name.unwrap_or_default(), | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| fn configure_hyper_client(&self) -> Builder { | ||
| let mut client_builder = Client::builder(TokioExecutor::new()); | ||
| client_builder | ||
| .timer(TokioTimer::new()) | ||
| .pool_idle_timeout(self.http_protocol_options.common.idle_timeout.unwrap_or(DEFAULT_IDLE_TIMEOUT)) | ||
| .pool_timer(TokioTimer::new()) | ||
| .pool_max_idle_per_host(usize::MAX) | ||
| .set_host(false); | ||
|
|
||
| let configured_upstream_http_version = self.http_protocol_options.codec; | ||
|
|
||
| self.configure_http2_if_needed(&mut client_builder, configured_upstream_http_version); | ||
|
|
||
| client_builder | ||
| } | ||
|
|
||
| fn configure_http2_if_needed(&self, client_builder: &mut Builder, version: Codec) { | ||
| if matches!(version, Codec::Http2) { | ||
| client_builder.http2_only(true); | ||
| let http2_options = &self.http_protocol_options.http2_options; | ||
|
|
||
| if let Some(settings) = &http2_options.keep_alive_settings { | ||
| client_builder.http2_keep_alive_interval(settings.keep_alive_interval); | ||
| if let Some(timeout) = settings.keep_alive_timeout { | ||
| client_builder.http2_keep_alive_timeout(timeout); | ||
| } | ||
| client_builder.http2_keep_alive_while_idle(true); | ||
| } | ||
|
|
||
| client_builder.http2_initial_connection_window_size(http2_options.initial_connection_window_size()); | ||
| client_builder.http2_initial_stream_window_size(http2_options.initial_stream_window_size()); | ||
|
|
||
| if let Some(max) = http2_options.max_concurrent_streams() { | ||
| client_builder.http2_max_concurrent_reset_streams(max); | ||
| } | ||
|
Comment on lines
+262
to
+264
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The configuration option Using the value for one to configure the other is a bug and will lead to unexpected behavior. The To fix this, the field in
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ignore |
||
| } | ||
| } | ||
| } | ||
|
|
||
| #[cfg(feature = "metrics")] | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,4 +20,3 @@ | |
|
|
||
| pub mod http; | ||
| pub mod rewindable_stream; | ||
| pub mod tokio; | ||
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed typo: 'boostrap' should be 'bootstrap'