tk_pool/metrics.rs
1//! Metrics trait and no-op implementation
2
3/// An object implementing trait may collect metrics of a connection pool
4pub trait Collect: Clone + Send + Sync {
5 /// We started establishing connection
6 ///
7 /// This pairs either with ``connection`` on success
8 /// or ``connection_abort`` and ``connection_error`` on error
9 fn connection_attempt(&self) {}
10 /// Error establishing connection
11 fn connection_error(&self) {}
12
13 /// Aborted connection attempt (name changed, and doesn't include address)
14 fn connection_abort(&self) {}
15 /// Connection established successfully
16 fn connection(&self) {}
17 /// Connection closed (usully means name changed)
18 fn disconnect(&self) {}
19
20 /// Host address added to a blacklist (i.e. connection error)
21 fn blacklist_add(&self) {}
22 /// Host address removed from a blacklist
23 ///
24 /// Note this callback is only called when we're searching for a new
25 /// connection and all others are busy. I.e. unlisting a host from a
26 /// blacklist may be delayed arbitrarily when not under backpressure.
27 /// This may be fixed in future.
28 fn blacklist_remove(&self) {}
29
30 /// Request queued in the internal queue
31 fn request_queued(&self) {}
32 /// Request unqueued from the internal queue and forwarded to a sink
33 ///
34 /// Note: this might not mean that request is already sent as we can't
35 /// control the underlying sinks used.
36 fn request_forwarded(&self) {}
37
38 /// Connection pool is closed
39 fn pool_closed(&self) {}
40}
41
42
43/// A object implementing Collect which is not interested in actual metrics
44#[derive(Debug, Clone)]
45pub struct Noop;
46
47impl Collect for Noop {}