Skip to content

Commit 2fff66c

Browse files
committed
remove TimingRecorder, as we can now use metrics
1 parent 25f7bb6 commit 2fff66c

File tree

2 files changed

+1
-56
lines changed

2 files changed

+1
-56
lines changed

src/controllers.rs

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ mod prelude {
1919

2020
pub use crate::db::RequestTransaction;
2121
pub use crate::middleware::app::RequestApp;
22-
pub use crate::middleware::log_request::TimingRecorder;
2322
pub use crate::util::errors::{cargo_err, AppError, AppResult, ChainError}; // TODO: Remove cargo_err from here
2423
pub use crate::util::{AppResponse, EndpointResult};
2524

@@ -39,7 +38,6 @@ mod prelude {
3938
fn query_with_params(&self, params: IndexMap<String, String>) -> String;
4039

4140
fn log_metadata<V: std::fmt::Display>(&mut self, key: &'static str, value: V);
42-
fn timing_recorder(&mut self) -> TimingRecorder;
4341
}
4442

4543
impl<'a> RequestUtils for dyn RequestExt + 'a {
@@ -80,17 +78,6 @@ mod prelude {
8078
fn log_metadata<V: std::fmt::Display>(&mut self, key: &'static str, value: V) {
8179
crate::middleware::log_request::add_custom_metadata(self, key, value);
8280
}
83-
84-
fn timing_recorder(&mut self) -> TimingRecorder {
85-
if let Some(recorder) = self.extensions().find::<TimingRecorder>() {
86-
recorder.clone()
87-
} else {
88-
let recorder = TimingRecorder::new();
89-
self.mut_extensions()
90-
.insert::<TimingRecorder>(recorder.clone());
91-
recorder
92-
}
93-
}
9481
}
9582
}
9683

src/middleware/log_request.rs

Lines changed: 1 addition & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,8 @@ use conduit::{header, Host, RequestExt, Scheme, StatusCode};
88
use conduit_cookie::RequestSession;
99
use sentry::Level;
1010

11-
use std::cell::RefCell;
12-
use std::collections::HashMap;
1311
use std::fmt::{self, Display, Formatter};
14-
use std::rc::Rc;
15-
use std::time::{Duration, Instant, SystemTime, UNIX_EPOCH};
12+
use std::time::{SystemTime, UNIX_EPOCH};
1613

1714
const SLOW_REQUEST_THRESHOLD_MS: u64 = 1000;
1815

@@ -94,34 +91,6 @@ pub fn add_custom_metadata<V: Display>(req: &mut dyn RequestExt, key: &'static s
9491
}
9592
}
9693

97-
#[derive(Debug, Clone)]
98-
pub struct TimingRecorder {
99-
sections: Rc<RefCell<HashMap<&'static str, Duration>>>,
100-
}
101-
102-
impl TimingRecorder {
103-
pub fn new() -> Self {
104-
Self {
105-
sections: Rc::new(RefCell::new(HashMap::new())),
106-
}
107-
}
108-
109-
pub fn record<R>(&self, name: &'static str, f: impl FnOnce() -> R) -> R {
110-
let start = Instant::now();
111-
let res = f();
112-
self.sections
113-
.borrow_mut()
114-
.insert(name, Instant::now() - start);
115-
res
116-
}
117-
}
118-
119-
impl Default for TimingRecorder {
120-
fn default() -> Self {
121-
Self::new()
122-
}
123-
}
124-
12594
fn report_to_sentry(req: &dyn RequestExt, res: &AfterResult, response_time: u64) {
12695
let (message, level) = match res {
12796
Err(e) => (e.to_string(), Level::Error),
@@ -255,17 +224,6 @@ impl Display for RequestLine<'_> {
255224

256225
if self.response_time > SLOW_REQUEST_THRESHOLD_MS {
257226
line.add_marker("SLOW REQUEST")?;
258-
259-
if let Some(timings) = self.req.extensions().find::<TimingRecorder>() {
260-
for (section, duration) in timings.sections.borrow().iter() {
261-
line.add_quoted_field(
262-
format!("timing_{}", section),
263-
// Debug formatting rounds the duration to the most useful unit and adds
264-
// the unit suffix. For example: 1.20s, 10.00ms, 8.35ns
265-
format!("{:.2?}", duration),
266-
)?;
267-
}
268-
}
269227
}
270228

271229
Ok(())

0 commit comments

Comments
 (0)