Skip to content

Commit

Permalink
Track request errors in addition to aborted
Browse files Browse the repository at this point in the history
  • Loading branch information
shepmaster committed Jul 31, 2024
1 parent c425581 commit c0da5dd
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
12 changes: 10 additions & 2 deletions ui/src/request_database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ pub struct Id(i64);
pub enum How {
Complete = 0,
Abandoned = 1,
Error = 2,
}

impl Database {
Expand Down Expand Up @@ -222,11 +223,18 @@ impl Handle {
pub struct EndGuard(Option<EndGuardInner>);

impl EndGuard {
pub fn complete_now(mut self) {
pub fn complete_now<T, E>(mut self, result: Result<T, E>) -> Result<T, E>{
if let Some(mut inner) = self.0.take() {
inner.1 = How::Complete;
inner.1 = if result.is_err() {
How::Error
} else {
How::Complete
};

drop(inner);
}

result
}
}

Expand Down
8 changes: 3 additions & 5 deletions ui/src/server_axum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,20 +191,18 @@ async fn rewrite_help_as_index(
next.run(req).await
}

async fn attempt_record_request<T, RFut, R>(db: Handle, req: T, f: impl FnOnce(T) -> RFut) -> R
async fn attempt_record_request<T, RFut, RT, RE>(db: Handle, req: T, f: impl FnOnce(T) -> RFut) -> Result<RT, RE>
where
T: HasEndpoint + serde::Serialize,
RFut: Future<Output = R>,
RFut: Future<Output = Result<RT, RE>>,
{
let category = format!("http.{}", <&str>::from(T::ENDPOINT));
let payload = serde_json::to_string(&req).unwrap_or_else(|_| String::from("<invalid JSON>"));
let guard = db.start_with_guard(category, payload).await;

let r = f(req).await;

guard.complete_now();

r
guard.complete_now(r)
}

// This is a backwards compatibilty shim. The Rust documentation uses
Expand Down
4 changes: 1 addition & 3 deletions ui/src/server_axum/websocket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -544,9 +544,7 @@ async fn handle_msg(
.map_err(|e| (e, Some(meta)))
.await;

guard.complete_now();

r
guard.complete_now(r)
}
})
.await
Expand Down

0 comments on commit c0da5dd

Please sign in to comment.