Require Sensors for Bind (#78)
`Bind` was initially written so that a `Sensors` implementation is optional. Over time, this hasn't proven to be very useful. In preparation for further changes to HTTP telemetry, this change simplifies the Bind and Sensors types so that an HTTP sensor is always required to construct `Bind`. Test-only constructors have been added to satisfy the case where Sensors were omitted.
This commit is contained in:
parent
447f3320a7
commit
40e9ffcaf8
10
src/bind.rs
10
src/bind.rs
|
@ -183,25 +183,19 @@ impl Error for BufferSpawnError {
|
||||||
|
|
||||||
impl<B> Bind<(), B> {
|
impl<B> Bind<(), B> {
|
||||||
pub fn new(
|
pub fn new(
|
||||||
|
sensors: telemetry::Sensors,
|
||||||
transport_registry: telemetry::transport::Registry,
|
transport_registry: telemetry::transport::Registry,
|
||||||
tls_client_config: tls::ClientConfigWatch
|
tls_client_config: tls::ClientConfigWatch
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Self {
|
Self {
|
||||||
ctx: (),
|
ctx: (),
|
||||||
sensors: telemetry::Sensors::null(),
|
sensors,
|
||||||
transport_registry,
|
transport_registry,
|
||||||
tls_client_config,
|
tls_client_config,
|
||||||
_p: PhantomData,
|
_p: PhantomData,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn with_sensors(self, sensors: telemetry::Sensors) -> Self {
|
|
||||||
Self {
|
|
||||||
sensors,
|
|
||||||
..self
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn with_ctx<C>(self, ctx: C) -> Bind<C, B> {
|
pub fn with_ctx<C>(self, ctx: C) -> Bind<C, B> {
|
||||||
Bind {
|
Bind {
|
||||||
ctx,
|
ctx,
|
||||||
|
|
|
@ -115,6 +115,7 @@ mod tests {
|
||||||
|
|
||||||
fn new_inbound(default: Option<net::SocketAddr>, ctx: ctx::Proxy) -> Inbound<()> {
|
fn new_inbound(default: Option<net::SocketAddr>, ctx: ctx::Proxy) -> Inbound<()> {
|
||||||
let bind = Bind::new(
|
let bind = Bind::new(
|
||||||
|
::telemetry::Sensors::for_test(),
|
||||||
::telemetry::transport::Registry::default(),
|
::telemetry::transport::Registry::default(),
|
||||||
tls::ClientConfig::no_tls()
|
tls::ClientConfig::no_tls()
|
||||||
);
|
);
|
||||||
|
|
|
@ -286,8 +286,11 @@ where
|
||||||
|
|
||||||
let (drain_tx, drain_rx) = drain::channel();
|
let (drain_tx, drain_rx) = drain::channel();
|
||||||
|
|
||||||
let bind = Bind::new(transport_registry.clone(), tls_client_config)
|
let bind = Bind::new(
|
||||||
.with_sensors(sensors.clone());
|
sensors.clone(),
|
||||||
|
transport_registry.clone(),
|
||||||
|
tls_client_config
|
||||||
|
);
|
||||||
|
|
||||||
// Setup the public listener. This will listen on a publicly accessible
|
// Setup the public listener. This will listen on a publicly accessible
|
||||||
// address and listen for inbound connections that should be forwarded
|
// address and listen for inbound connections that should be forwarded
|
||||||
|
|
|
@ -20,6 +20,11 @@ impl Record {
|
||||||
Self { metrics: metrics.clone() }
|
Self { metrics: metrics.clone() }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
pub fn for_test() -> Self {
|
||||||
|
Self { metrics: Default::default() }
|
||||||
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn update<F: Fn(&mut Root)>(&mut self, f: F) {
|
fn update<F: Fn(&mut Root)>(&mut self, f: F) {
|
||||||
let mut lock = self.metrics.lock()
|
let mut lock = self.metrics.lock()
|
||||||
|
|
|
@ -20,40 +20,39 @@ struct Inner {
|
||||||
|
|
||||||
/// Accepts events from sensors.
|
/// Accepts events from sensors.
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
struct Handle(Option<Inner>);
|
struct Handle(Inner);
|
||||||
|
|
||||||
/// Supports the creation of telemetry scopes.
|
/// Supports the creation of telemetry scopes.
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct Sensors(Option<Inner>);
|
pub struct Sensors(Inner);
|
||||||
|
|
||||||
impl Handle {
|
impl Handle {
|
||||||
fn send<F>(&mut self, mk: F)
|
fn send<F>(&mut self, mk: F)
|
||||||
where
|
where
|
||||||
F: FnOnce() -> event::Event,
|
F: FnOnce() -> event::Event,
|
||||||
{
|
{
|
||||||
if let Some(inner) = self.0.as_mut() {
|
let ev = mk();
|
||||||
let ev = mk();
|
trace!("event: {:?}", ev);
|
||||||
trace!("event: {:?}", ev);
|
|
||||||
|
|
||||||
if let Ok(mut taps) = inner.taps.lock() {
|
if let Ok(mut taps) = self.0.taps.lock() {
|
||||||
taps.inspect(&ev);
|
taps.inspect(&ev);
|
||||||
}
|
|
||||||
|
|
||||||
inner.metrics.record_event(&ev);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
self.0.metrics.record_event(&ev);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Sensors {
|
impl Sensors {
|
||||||
pub(super) fn new(metrics: metrics::Record, taps: &Arc<Mutex<tap::Taps>>) -> Self {
|
pub(super) fn new(metrics: metrics::Record, taps: &Arc<Mutex<tap::Taps>>) -> Self {
|
||||||
Sensors(Some(Inner {
|
Sensors(Inner {
|
||||||
metrics,
|
metrics,
|
||||||
taps: taps.clone(),
|
taps: taps.clone(),
|
||||||
}))
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn null() -> Sensors {
|
#[cfg(test)]
|
||||||
Sensors(None)
|
pub fn for_test() -> Self {
|
||||||
|
Self::new(metrics::Record::for_test(), &Default::default())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn http<N, A, B>(
|
pub fn http<N, A, B>(
|
||||||
|
|
Loading…
Reference in New Issue