mirror of
https://github.com/fawney19/Aether.git
synced 2026-10-08 18:37:46 +08:00
Improve gateway transport and usage runtime
This commit is contained in:
@@ -17,6 +17,7 @@ pub(crate) struct RequestDiagnostics {
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
struct RequestDiagnosticsInner {
|
||||
request_accepted_at: Option<Instant>,
|
||||
db_operations: BTreeMap<&'static str, DbOperationTiming>,
|
||||
db_pool: Option<DbPoolObservation>,
|
||||
}
|
||||
@@ -38,6 +39,20 @@ struct DbPoolObservation {
|
||||
}
|
||||
|
||||
impl RequestDiagnostics {
|
||||
fn record_request_accepted_at(&self, accepted_at: Instant) {
|
||||
let Ok(mut inner) = self.inner.lock() else {
|
||||
return;
|
||||
};
|
||||
inner.request_accepted_at = Some(accepted_at);
|
||||
}
|
||||
|
||||
pub(crate) fn request_accepted_at(&self) -> Option<Instant> {
|
||||
let Ok(inner) = self.inner.lock() else {
|
||||
return None;
|
||||
};
|
||||
inner.request_accepted_at
|
||||
}
|
||||
|
||||
fn record_db_timing_ms(&self, operation: &'static str, elapsed_ms: u64) {
|
||||
let Ok(mut inner) = self.inner.lock() else {
|
||||
return;
|
||||
@@ -145,6 +160,12 @@ pub(crate) fn current_request_diagnostics() -> Option<Arc<RequestDiagnostics>> {
|
||||
REQUEST_DIAGNOSTICS.try_with(Arc::clone).ok()
|
||||
}
|
||||
|
||||
pub(crate) fn record_request_accepted_at(accepted_at: Instant) {
|
||||
if let Some(diagnostics) = current_request_diagnostics() {
|
||||
diagnostics.record_request_accepted_at(accepted_at);
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) async fn observe_db_operation<F>(
|
||||
operation: &'static str,
|
||||
pool_summary: Option<DatabasePoolSummary>,
|
||||
|
||||
Reference in New Issue
Block a user