summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorStuart Stock <stuart@int08h.com>2019-01-26 07:03:13 -0600
committerStuart Stock <stuart@int08h.com>2019-01-26 07:03:13 -0600
commit8e70a74928466538671066538a2774cc3d97cb26 (patch)
treeed9ad97e7453eef141b2a536323567f5aa1f61c8 /src
parent387d2967ccf27659bd0c9b67125a6de97f62a53d (diff)
downloadroughenough-8e70a74928466538671066538a2774cc3d97cb26.zip
Add a noop implementation of stats tracking
Diffstat (limited to 'src')
-rw-r--r--src/stats.rs62
1 files changed, 62 insertions, 0 deletions
diff --git a/src/stats.rs b/src/stats.rs
index 0a39710..d296e40 100644
--- a/src/stats.rs
+++ b/src/stats.rs
@@ -225,6 +225,68 @@ impl ClientStats for SimpleStats {
}
}
+///
+/// A no-op implementation that does not track anything and has no runtime cost
+///
+#[allow(dead_code)]
+pub struct NoOpStats {
+ empty_map: HashMap<IpAddr, StatEntry>
+}
+
+impl NoOpStats {
+
+ #[allow(dead_code)]
+ pub fn new() -> Self {
+ NoOpStats {
+ empty_map: HashMap::new()
+ }
+ }
+}
+
+impl ClientStats for NoOpStats {
+ fn add_valid_request(&mut self, _addr: &IpAddr) {}
+
+ fn add_invalid_request(&mut self, _addr: &IpAddr) {}
+
+ fn add_health_check(&mut self, _addr: &IpAddr) {}
+
+ fn add_response(&mut self, _addr: &IpAddr, _bytes_sent: usize) {}
+
+ fn total_valid_requests(&self) -> u64 {
+ 0
+ }
+
+ fn total_invalid_requests(&self) -> u64 {
+ 0
+ }
+
+ fn total_health_checks(&self) -> u64 {
+ 0
+ }
+
+ fn total_responses_sent(&self) -> u64 {
+ 0
+ }
+
+ fn total_bytes_sent(&self) -> usize {
+ 0
+ }
+
+ fn total_unique_clients(&self) -> u64 {
+ 0
+ }
+
+ fn get_stats(&self, _addr: &IpAddr) -> Option<&StatEntry> {
+ None
+ }
+
+ fn iter(&self) -> Iter<IpAddr, StatEntry> {
+ self.empty_map.iter()
+ }
+
+ fn clear(&mut self) {}
+}
+
#[cfg(test)]
mod test {
use crate::stats::{ClientStats, SimpleStats};