diff --git a/src/bind.rs b/src/bind.rs index 6a01f0106..8bd01ce86 100644 --- a/src/bind.rs +++ b/src/bind.rs @@ -2,7 +2,6 @@ use std::error::Error; use std::fmt; use std::marker::PhantomData; use std::net::SocketAddr; -use std::sync::Arc; use futures::{Async, Future, Poll, future, task}; use http::{self, uri}; @@ -53,7 +52,7 @@ where B: tower_h2::Body + Send + 'static, ::Buf: Send, { - bind: Bind, B>, + bind: Bind, binding: Binding, /// Prevents logging repeated connect errors. /// @@ -132,7 +131,7 @@ pub struct NormalizeUri { } pub struct RebindTls { - bind: Bind, B>, + bind: Bind, protocol: Protocol, endpoint: Endpoint, } @@ -219,7 +218,7 @@ impl Clone for Bind { } } -impl Bind, B> +impl Bind where B: tower_h2::Body + Send + 'static, ::Buf: Send, @@ -255,7 +254,7 @@ where }); let client_ctx = ctx::transport::Client::new( - &self.ctx, + self.ctx, &addr, ep.metadata().clone(), TlsStatus::from(&tls), @@ -267,7 +266,7 @@ where &client_ctx, ); - let log = ::logging::Client::proxy(&self.ctx, addr) + let log = ::logging::Client::proxy(self.ctx, addr) .with_protocol(protocol.clone()); let client = transparency::Client::new( protocol, @@ -361,7 +360,7 @@ impl Bind { } } -impl control::destination::Bind for BindProtocol, B> +impl control::destination::Bind for BindProtocol where B: tower_h2::Body + Send + 'static, ::Buf: Send, diff --git a/src/control/pb.rs b/src/control/pb.rs index 95ffa47c2..9491d6cfd 100644 --- a/src/control/pb.rs +++ b/src/control/pb.rs @@ -193,10 +193,9 @@ impl ctx::transport::Server { } fn direction(&self) -> tap::tap_event::ProxyDirection { - if self.proxy.is_outbound() { - tap::tap_event::ProxyDirection::Outbound - } else { - tap::tap_event::ProxyDirection::Inbound + match self.proxy { + ctx::Proxy::Outbound => tap::tap_event::ProxyDirection::Outbound, + ctx::Proxy::Inbound => tap::tap_event::ProxyDirection::Inbound, } } } diff --git a/src/ctx/http.rs b/src/ctx/http.rs index a83651079..462ec9177 100644 --- a/src/ctx/http.rs +++ b/src/ctx/http.rs @@ -83,14 +83,11 @@ impl Request { /// Returns a `TlsStatus` indicating if the request was sent was over TLS. pub fn tls_status(&self) -> ctx::transport::TlsStatus { - if self.server.proxy.is_outbound() { - // If the request is in the outbound direction, then we opened the - // client connection, so check if it was secured. - self.client.tls_status - } else { - // Otherwise, the request is inbound, so check if we accepted it - // over TLS. - self.server.tls_status + use ctx::Proxy::*; + // The proxy only handles TLS on one side of each proxy. + match self.server.proxy { + Outbound => self.client.tls_status, + Inbound => self.server.tls_status, } } diff --git a/src/ctx/mod.rs b/src/ctx/mod.rs index 156390e93..cc0976de4 100644 --- a/src/ctx/mod.rs +++ b/src/ctx/mod.rs @@ -1,80 +1,26 @@ -//! Describes proxy traffic. -//! -//! Contexts are primarily intended to describe traffic contexts for the purposes of -//! telemetry. They may also be useful for, for instance, -//! routing/rate-limiting/policy/etc. -//! -//! As a rule, context types should implement `Clone + Send + Sync`. This allows them to -//! be stored in `http::Extensions`, for instance. Furthermore, because these contexts -//! will be sent to a telemetry processing thread, we want to avoid excessive cloning. -use config; -use std::time::SystemTime; -use std::sync::Arc; - pub mod http; pub mod transport; -/// Describes a single running proxy instance. -#[derive(Clone, Debug)] -pub struct Process { - /// Identifies the Kubernetes namespace in which this proxy is process. - pub scheduled_namespace: String, - - pub start_time: SystemTime, -} - /// Indicates the orientation of traffic, relative to a sidecar proxy. /// /// Each process exposes two proxies: /// - The _inbound_ proxy receives traffic from another services forwards it to within the /// local instance. /// - The _outbound_ proxy receives traffic from the local instance and forwards it to a -/// remove service. -#[derive(Clone, Debug)] +/// remote service. +#[derive(Clone, Copy, Debug, Hash, PartialEq, Eq)] pub enum Proxy { - Inbound(Arc), - Outbound(Arc), -} - -impl Process { - // Test-only, but we can't use `#[cfg(test)]` because it is used by the - // benchmarks - pub fn test(ns: &str) -> Arc { - Arc::new(Self { - scheduled_namespace: ns.into(), - start_time: SystemTime::now(), - }) - } - - /// Construct a new `Process` from environment variables. - pub fn new(config: &config::Config) -> Arc { - let start_time = SystemTime::now(); - Arc::new(Self { - scheduled_namespace: config.namespaces.pod.clone(), - start_time, - }) - } + Inbound, + Outbound, } impl Proxy { - pub fn inbound(p: &Arc) -> Arc { - Arc::new(Proxy::Inbound(Arc::clone(p))) - } - - pub fn outbound(p: &Arc) -> Arc { - Arc::new(Proxy::Outbound(Arc::clone(p))) - } - - pub fn is_inbound(&self) -> bool { + pub fn as_str(&self) -> &'static str { match *self { - Proxy::Inbound(_) => true, - Proxy::Outbound(_) => false, + Proxy::Inbound => "in", + Proxy::Outbound => "out", } } - - pub fn is_outbound(&self) -> bool { - !self.is_inbound() - } } #[cfg(test)] @@ -96,19 +42,15 @@ pub mod test_util { ([1, 2, 3, 4], 5678).into() } - pub fn process() -> Arc { - ctx::Process::test("test") - } - pub fn server( - proxy: &Arc, + proxy: ctx::Proxy, tls: ctx::transport::TlsStatus ) -> Arc { - ctx::transport::Server::new(&proxy, &addr(), &addr(), &Some(addr()), tls) + ctx::transport::Server::new(proxy, &addr(), &addr(), &Some(addr()), tls) } pub fn client( - proxy: &Arc, + proxy: ctx::Proxy, labels: L, tls: ctx::transport::TlsStatus, ) -> Arc @@ -119,7 +61,7 @@ pub mod test_util { let meta = destination::Metadata::new(DstLabels::new(labels), destination::ProtocolHint::Unknown, Conditional::None(tls::ReasonForNoIdentity::NotProvidedByServiceDiscovery)); - ctx::transport::Client::new(&proxy, &addr(), meta, tls) + ctx::transport::Client::new(proxy, &addr(), meta, tls) } pub fn request( diff --git a/src/ctx/transport.rs b/src/ctx/transport.rs index 3ebdf0a64..2d089032b 100644 --- a/src/ctx/transport.rs +++ b/src/ctx/transport.rs @@ -19,7 +19,7 @@ pub enum Ctx { /// Identifies a connection from another process to a proxy listener. #[derive(Debug)] pub struct Server { - pub proxy: Arc, + pub proxy: ctx::Proxy, pub remote: SocketAddr, pub local: SocketAddr, pub orig_dst: Option, @@ -29,7 +29,7 @@ pub struct Server { /// Identifies a connection from the proxy to another process. #[derive(Debug)] pub struct Client { - pub proxy: Arc, + pub proxy: ctx::Proxy, pub remote: SocketAddr, pub metadata: destination::Metadata, pub tls_status: TlsStatus, @@ -63,16 +63,16 @@ impl fmt::Display for TlsStatus { impl Ctx { - pub fn proxy(&self) -> &Arc { + pub fn proxy(&self) -> ctx::Proxy { match *self { - Ctx::Client(ref ctx) => &ctx.proxy, - Ctx::Server(ref ctx) => &ctx.proxy, + Ctx::Client(ref ctx) => ctx.proxy, + Ctx::Server(ref ctx) => ctx.proxy, } } pub fn tls_status(&self) -> TlsStatus { match self { - Ctx::Client(ctx) => ctx.tls_status, + Ctx::Client(ctx) => ctx.tls_status, Ctx::Server(ctx) => ctx.tls_status, } } @@ -80,14 +80,14 @@ impl Ctx { impl Server { pub fn new( - proxy: &Arc, + proxy: ctx::Proxy, local: &SocketAddr, remote: &SocketAddr, orig_dst: &Option, tls_status: TlsStatus, ) -> Arc { let s = Server { - proxy: Arc::clone(proxy), + proxy, local: *local, remote: *remote, orig_dst: *orig_dst, @@ -123,13 +123,13 @@ fn same_addr(a0: &SocketAddr, a1: &SocketAddr) -> bool { impl Client { pub fn new( - proxy: &Arc, + proxy: ctx::Proxy, remote: &SocketAddr, metadata: destination::Metadata, tls_status: TlsStatus, ) -> Arc { let c = Client { - proxy: Arc::clone(proxy), + proxy, remote: *remote, metadata, tls_status, diff --git a/src/inbound.rs b/src/inbound.rs index 2fa31f754..a9c440282 100644 --- a/src/inbound.rs +++ b/src/inbound.rs @@ -12,7 +12,7 @@ use bind; use ctx; use transparency::orig_proto; -type Bind = bind::Bind, B>; +type Bind = bind::Bind; pub struct Inbound { default_addr: Option, @@ -103,7 +103,6 @@ where #[cfg(test)] mod tests { use std::net; - use std::sync::Arc; use http; use linkerd2_proxy_router::Recognize; @@ -114,8 +113,8 @@ mod tests { use conditional::Conditional; use tls; - fn new_inbound(default: Option, ctx: &Arc) -> Inbound<()> { - let bind = Bind::new(tls::ClientConfig::no_tls()).with_ctx(ctx.clone()); + fn new_inbound(default: Option, ctx: ctx::Proxy) -> Inbound<()> { + let bind = Bind::new(tls::ClientConfig::no_tls()).with_ctx(ctx); Inbound::new(default, bind) } @@ -137,12 +136,12 @@ mod tests { local: net::SocketAddr, remote: net::SocketAddr ) -> bool { - let ctx = ctx::Proxy::inbound(&ctx::Process::test("test")); + let ctx = ctx::Proxy::Inbound; - let inbound = new_inbound(None, &ctx); + let inbound = new_inbound(None, ctx); let srv_ctx = ctx::transport::Server::new( - &ctx, &local, &remote, &Some(orig_dst), TLS_DISABLED); + ctx, &local, &remote, &Some(orig_dst), TLS_DISABLED); let rec = srv_ctx.orig_dst_if_not_local().map(make_key_http1); @@ -158,14 +157,14 @@ mod tests { local: net::SocketAddr, remote: net::SocketAddr ) -> bool { - let ctx = ctx::Proxy::inbound(&ctx::Process::test("test")); + let ctx = ctx::Proxy::Inbound; - let inbound = new_inbound(default, &ctx); + let inbound = new_inbound(default, ctx); let mut req = http::Request::new(()); req.extensions_mut() .insert(ctx::transport::Server::new( - &ctx, + ctx, &local, &remote, &None, @@ -176,9 +175,9 @@ mod tests { } fn recognize_default_no_ctx(default: Option) -> bool { - let ctx = ctx::Proxy::inbound(&ctx::Process::test("test")); + let ctx = ctx::Proxy::Inbound; - let inbound = new_inbound(default, &ctx); + let inbound = new_inbound(default, ctx); let req = http::Request::new(()); @@ -190,14 +189,14 @@ mod tests { local: net::SocketAddr, remote: net::SocketAddr ) -> bool { - let ctx = ctx::Proxy::inbound(&ctx::Process::test("test")); + let ctx = ctx::Proxy::Inbound; - let inbound = new_inbound(default, &ctx); + let inbound = new_inbound(default, ctx); let mut req = http::Request::new(()); req.extensions_mut() .insert(ctx::transport::Server::new( - &ctx, + ctx, &local, &remote, &Some(local), diff --git a/src/lib.rs b/src/lib.rs index 0546c3121..3876e568c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -60,7 +60,7 @@ use std::io; use std::net::SocketAddr; use std::sync::Arc; use std::thread; -use std::time::Duration; +use std::time::{Duration, SystemTime}; use indexmap::IndexSet; use tokio::{ @@ -122,6 +122,8 @@ pub struct Main { config: config::Config, tls_config_watch: tls::ConfigWatch, + start_time: SystemTime, + control_listener: BoundPort, inbound_listener: BoundPort, outbound_listener: BoundPort, @@ -144,6 +146,8 @@ where where R: Into, { + let start_time = SystemTime::now(); + let tls_config_watch = tls::ConfigWatch::new(config.tls_settings.clone()); // TODO: Serve over TLS. @@ -180,6 +184,7 @@ where Main { config, + start_time, tls_config_watch, control_listener, inbound_listener, @@ -211,10 +216,9 @@ where where F: Future + Send + 'static, { - let process_ctx = ctx::Process::new(&self.config); - let Main { config, + start_time, tls_config_watch, control_listener, inbound_listener, @@ -248,7 +252,7 @@ where let (taps, observe) = control::Observe::new(100); let (sensors, tls_config_sensor, metrics_server) = telemetry::new( - &process_ctx, + start_time, config.metrics_retain_idle, &taps, ); @@ -288,8 +292,8 @@ where // address and listen for inbound connections that should be forwarded // to the managed application (private destination). let inbound = { - let ctx = ctx::Proxy::inbound(&process_ctx); - let bind = bind.clone().with_ctx(ctx.clone()); + let ctx = ctx::Proxy::Inbound; + let bind = bind.clone().with_ctx(ctx); let default_addr = config.private_forward.map(|a| a.into()); let router = Router::new( @@ -313,8 +317,8 @@ where // address and listen for outbound requests that should be routed // to a remote service (public destination). let outbound = { - let ctx = ctx::Proxy::outbound(&process_ctx); - let bind = bind.clone().with_ctx(ctx.clone()); + let ctx = ctx::Proxy::Outbound; + let bind = bind.clone().with_ctx(ctx); let router = Router::new( Outbound::new(bind, resolver, config.bind_timeout), config.outbound_router_capacity, @@ -387,7 +391,7 @@ fn serve( router: Router, tcp_connect_timeout: Duration, disable_protocol_detection_ports: IndexSet, - proxy_ctx: Arc, + proxy_ctx: ctx::Proxy, sensors: telemetry::Sensors, get_orig_dst: G, drain_rx: drain::Watch, @@ -448,7 +452,7 @@ where let listen_addr = bound_port.local_addr(); let server = Server::new( listen_addr, - proxy_ctx.clone(), + proxy_ctx, sensors, get_orig_dst, stack, diff --git a/src/logging.rs b/src/logging.rs index 11daa1864..29604c973 100644 --- a/src/logging.rs +++ b/src/logging.rs @@ -276,13 +276,8 @@ pub type ServerExecutor = ContextualExecutor; pub type ServerFuture = ContextualFuture; impl Server { - pub fn proxy(ctx: &::ctx::Proxy, listen: SocketAddr) -> Self { - let name = if ctx.is_inbound() { - "in" - } else { - "out" - }; - Section::Proxy.server(name, listen) + pub fn proxy(ctx: ::ctx::Proxy, listen: SocketAddr) -> Self { + Section::Proxy.server(ctx.as_str(), listen) } pub fn with_remote(self, remote: SocketAddr) -> Self { @@ -312,13 +307,8 @@ impl fmt::Display for Server { } impl Client<&'static str, D> { - pub fn proxy(ctx: &::ctx::Proxy, dst: D) -> Self { - let name = if ctx.is_inbound() { - "in" - } else { - "out" - }; - Section::Proxy.client(name, dst) + pub fn proxy(ctx: ::ctx::Proxy, dst: D) -> Self { + Section::Proxy.client(ctx.as_str(), dst) } } diff --git a/src/outbound.rs b/src/outbound.rs index 2f5581a43..c6f7b0ecf 100644 --- a/src/outbound.rs +++ b/src/outbound.rs @@ -22,10 +22,10 @@ use timeout::Timeout; use transparency::{h1, HttpBody}; use transport::{DnsNameAndPort, Host, HostAndPort}; -type BindProtocol = bind::BindProtocol, B>; +type BindProtocol = bind::BindProtocol; pub struct Outbound { - bind: Bind, B>, + bind: Bind, discovery: destination::Resolver, bind_timeout: Duration, } @@ -48,7 +48,7 @@ pub enum Destination { // ===== impl Outbound ===== impl Outbound { - pub fn new(bind: Bind, B>, + pub fn new(bind: Bind, discovery: destination::Resolver, bind_timeout: Duration) -> Outbound { diff --git a/src/telemetry/metrics/labels.rs b/src/telemetry/metrics/labels.rs index 54cd3251b..df35b4239 100644 --- a/src/telemetry/metrics/labels.rs +++ b/src/telemetry/metrics/labels.rs @@ -52,10 +52,7 @@ pub enum Classification { } #[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)] -pub enum Direction { - Inbound, - Outbound, -} +pub struct Direction(ctx::Proxy); #[derive(Clone, Debug, Eq, PartialEq)] pub struct DstLabels { @@ -70,7 +67,7 @@ pub struct TlsStatus(ctx::transport::TlsStatus); impl RequestLabels { pub fn new(req: &ctx::http::Request) -> Self { - let direction = Direction::from_context(req.server.proxy.as_ref()); + let direction = Direction::new(req.server.proxy); let outbound_labels = req.dst_labels().cloned(); @@ -205,19 +202,16 @@ impl fmt::Display for Classification { // ===== impl Direction ===== impl Direction { - pub fn from_context(context: &ctx::Proxy) -> Self { - match context { - &ctx::Proxy::Inbound(_) => Direction::Inbound, - &ctx::Proxy::Outbound(_) => Direction::Outbound, - } + pub fn new(ctx: ctx::Proxy) -> Self { + Direction(ctx) } } impl fmt::Display for Direction { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - match self { - &Direction::Inbound => f.pad("direction=\"inbound\""), - &Direction::Outbound => f.pad("direction=\"outbound\""), + match self.0 { + ctx::Proxy::Inbound => f.pad("direction=\"inbound\""), + ctx::Proxy::Outbound => f.pad("direction=\"outbound\""), } } } diff --git a/src/telemetry/metrics/mod.rs b/src/telemetry/metrics/mod.rs index 2d6524f92..f9926f2e6 100644 --- a/src/telemetry/metrics/mod.rs +++ b/src/telemetry/metrics/mod.rs @@ -30,9 +30,8 @@ use std::default::Default; use std::fmt::{self, Display}; use std::marker::PhantomData; use std::sync::{Arc, Mutex}; -use std::time::{Duration, Instant}; +use std::time::{Duration, Instant, SystemTime}; -use ctx; mod counter; mod gauge; mod histogram; @@ -109,10 +108,10 @@ struct Stamped { /// is a Hyper service which can be used to create the server for the /// scrape endpoint, while the `Record` side can receive updates to the /// metrics by calling `record_event`. -pub fn new(process: &Arc, idle_retain: Duration, tls: tls_config_reload::Report) +pub fn new(start_time: SystemTime, idle_retain: Duration, tls: tls_config_reload::Report) -> (Record, Serve) { - let metrics = Arc::new(Mutex::new(Root::new(process, tls))); + let metrics = Arc::new(Mutex::new(Root::new(start_time, tls))); (Record::new(&metrics), Serve::new(&metrics, idle_retain)) } @@ -154,9 +153,9 @@ impl<'a, M: FmtMetric> Metric<'a, M> { // ===== impl Root ===== impl Root { - pub fn new(process: &Arc, tls_config_reload: tls_config_reload::Report) -> Self { + pub fn new(start_time: SystemTime, tls_config_reload: tls_config_reload::Report) -> Self { Self { - process: process::Report::new(&process), + process: process::Report::new(start_time), tls_config_reload, .. Root::default() } @@ -225,6 +224,7 @@ impl ::std::ops::Deref for Stamped { #[cfg(test)] mod tests { + use ctx; use ctx::test_util::*; use super::*; use conditional::Conditional; @@ -235,11 +235,11 @@ mod tests { fn mock_route( root: &mut Root, - proxy: &Arc, + proxy: ctx::Proxy, server: &Arc, team: &str ) { - let client = client(&proxy, vec![("team", team)], TLS_DISABLED); + let client = client(proxy, vec![("team", team)], TLS_DISABLED); let (req, rsp) = request("http://nba.com", &server, &client); let client_transport = Arc::new(ctx::transport::Ctx::Client(client)); @@ -254,10 +254,9 @@ mod tests { #[test] fn expiry() { - let process = process(); - let proxy = ctx::Proxy::outbound(&process); + let proxy = ctx::Proxy::Outbound; - let server = server(&proxy, TLS_DISABLED); + let server = server(proxy, TLS_DISABLED); let server_transport = Arc::new(ctx::transport::Ctx::Server(server.clone())); let mut root = Root::default(); @@ -265,10 +264,10 @@ mod tests { let t0 = Instant::now(); root.transports().open(&server_transport); - mock_route(&mut root, &proxy, &server, "warriors"); + mock_route(&mut root, proxy, &server, "warriors"); let t1 = Instant::now(); - mock_route(&mut root, &proxy, &server, "sixers"); + mock_route(&mut root, proxy, &server, "sixers"); let t2 = Instant::now(); assert_eq!(root.requests.len(), 2); diff --git a/src/telemetry/metrics/record.rs b/src/telemetry/metrics/record.rs index 1f2a63242..9fd75f9f7 100644 --- a/src/telemetry/metrics/record.rs +++ b/src/telemetry/metrics/record.rs @@ -97,7 +97,7 @@ mod test { Event, }; use ctx::{self, test_util::*, transport::TlsStatus}; - use std::time::{Duration, Instant}; + use std::time::{Duration, Instant, SystemTime}; use conditional::Conditional; use tls; @@ -106,11 +106,10 @@ mod test { Conditional::None(tls::ReasonForNoTls::Disabled); fn test_record_response_end_outbound(client_tls: TlsStatus, server_tls: TlsStatus) { - let process = process(); - let proxy = ctx::Proxy::outbound(&process); - let server = server(&proxy, server_tls); + let proxy = ctx::Proxy::Outbound; + let server = server(proxy, server_tls); - let client = client(&proxy, vec![ + let client = client(proxy, vec![ ("service", "draymond"), ("deployment", "durant"), ("pod", "klay"), @@ -132,7 +131,7 @@ mod test { frames_sent: 0, }; - let (mut r, _) = metrics::new(&process, Duration::from_secs(100), Default::default()); + let (mut r, _) = metrics::new(SystemTime::now(), Duration::from_secs(100), Default::default()); let ev = Event::StreamResponseEnd(rsp.clone(), end.clone()); let labels = labels::ResponseLabels::new(&rsp, None); @@ -168,11 +167,10 @@ mod test { use self::labels::*; use std::sync::Arc; - let process = process(); - let proxy = ctx::Proxy::outbound(&process); - let server = server(&proxy, server_tls); + let proxy = ctx::Proxy::Outbound; + let server = server(proxy, server_tls); - let client = client(&proxy, vec![ + let client = client(proxy, vec![ ("service", "draymond"), ("deployment", "durant"), ("pod", "klay"), @@ -228,7 +226,7 @@ mod test { ), ]; - let (mut r, _) = metrics::new(&process, Duration::from_secs(1000), Default::default()); + let (mut r, _) = metrics::new(SystemTime::now(), Duration::from_secs(1000), Default::default()); let req_labels = RequestLabels::new(&req); let rsp_labels = ResponseLabels::new(&rsp, None); diff --git a/src/telemetry/metrics/transport.rs b/src/telemetry/metrics/transport.rs index 2369b9d81..0f1e01061 100644 --- a/src/telemetry/metrics/transport.rs +++ b/src/telemetry/metrics/transport.rs @@ -189,7 +189,7 @@ impl fmt::Display for Key { impl Key { fn new(ctx: &ctx::transport::Ctx) -> Self { Self { - direction: Direction::from_context(ctx.proxy().as_ref()), + direction: Direction::new(ctx.proxy()), peer: match *ctx { ctx::transport::Ctx::Server(_) => Peer::Src, ctx::transport::Ctx::Client(_) => Peer::Dst, diff --git a/src/telemetry/mod.rs b/src/telemetry/mod.rs index 62c3df59e..c2173e2c3 100644 --- a/src/telemetry/mod.rs +++ b/src/telemetry/mod.rs @@ -1,7 +1,5 @@ use std::sync::{Arc, Mutex}; -use std::time::Duration; - -use ctx; +use std::time::{Duration, SystemTime}; macro_rules! metrics { { $( $name:ident : $kind:ty { $help:expr } ),+ } => { @@ -31,12 +29,12 @@ pub use self::metrics::{DstLabels, Serve as ServeMetrics}; pub use self::sensor::Sensors; pub fn new( - process: &Arc, + start_time: SystemTime, metrics_retain_idle: Duration, taps: &Arc>, ) -> (Sensors, tls_config_reload::Sensor, ServeMetrics) { let (tls_config_sensor, tls_config_fmt) = tls_config_reload::new(); - let (metrics_record, metrics_serve) = metrics::new(process, metrics_retain_idle, tls_config_fmt); + let (metrics_record, metrics_serve) = metrics::new(start_time, metrics_retain_idle, tls_config_fmt); let s = Sensors::new(metrics_record, taps); (s, tls_config_sensor, metrics_serve) } diff --git a/src/telemetry/process.rs b/src/telemetry/process.rs index 9d13d507e..44d04d89a 100644 --- a/src/telemetry/process.rs +++ b/src/telemetry/process.rs @@ -1,7 +1,6 @@ use std::fmt; -use std::time::UNIX_EPOCH; +use std::time::{SystemTime, UNIX_EPOCH}; -use ctx; use super::metrics::Gauge; use self::system::System; @@ -19,8 +18,8 @@ pub struct Report { } impl Report { - pub fn new(process: &ctx::Process) -> Self { - let t0 = process.start_time + pub fn new(start_time: SystemTime) -> Self { + let t0 = start_time .duration_since(UNIX_EPOCH) .expect("process start time") .as_secs(); diff --git a/src/telemetry/sensor/transport.rs b/src/telemetry/sensor/transport.rs index eca793d5b..2444110a8 100644 --- a/src/telemetry/sensor/transport.rs +++ b/src/telemetry/sensor/transport.rs @@ -240,7 +240,7 @@ where let io = try_ready!(self.underlying.poll()); debug!("client connection open"); let ctx = ctx::transport::Client::new( - &self.ctx.proxy, + self.ctx.proxy, &self.ctx.remote, self.ctx.metadata.clone(), io.tls_status(), diff --git a/src/transparency/server.rs b/src/transparency/server.rs index d714a412c..f9ecdf4bc 100644 --- a/src/transparency/server.rs +++ b/src/transparency/server.rs @@ -46,7 +46,7 @@ where >, listen_addr: SocketAddr, new_service: S, - proxy_ctx: Arc, + proxy_ctx: ProxyCtx, sensors: Sensors, tcp: tcp::Proxy, log: ::logging::Server, @@ -75,7 +75,7 @@ where /// Creates a new `Server`. pub fn new( listen_addr: SocketAddr, - proxy_ctx: Arc, + proxy_ctx: ProxyCtx, sensors: Sensors, get_orig_dst: G, stack: S, @@ -85,7 +85,7 @@ where ) -> Self { let recv_body_svc = HttpBodyNewSvc::new(stack.clone()); let tcp = tcp::Proxy::new(tcp_connect_timeout, sensors.clone()); - let log = ::logging::Server::proxy(&proxy_ctx, listen_addr); + let log = ::logging::Server::proxy(proxy_ctx, listen_addr); Server { disable_protocol_detection_ports, drain_signal, @@ -124,7 +124,7 @@ where let orig_dst = connection.original_dst_addr(&self.get_orig_dst); let local_addr = connection.local_addr().unwrap_or(self.listen_addr); let srv_ctx = ServerCtx::new( - &self.proxy_ctx, + self.proxy_ctx, &local_addr, &remote_addr, &orig_dst, diff --git a/src/transparency/tcp.rs b/src/transparency/tcp.rs index 2a8f520c3..e04b8862f 100644 --- a/src/transparency/tcp.rs +++ b/src/transparency/tcp.rs @@ -63,7 +63,7 @@ impl Proxy { let tls = Conditional::None(tls::ReasonForNoIdentity::NotHttp.into()); // TODO let client_ctx = ClientCtx::new( - &srv_ctx.proxy, + srv_ctx.proxy, &orig_dst, destination::Metadata::no_metadata(), TlsStatus::from(&tls),