From df738e8ac8e17103b1656a0de77feb6945bd00e7 Mon Sep 17 00:00:00 2001 From: Richard Meissner Date: Mon, 23 Nov 2020 13:04:29 +0100 Subject: [PATCH] Monitoring status code (#194) * Add status code to monitoring * Bump app version to 1.5.1 --- Cargo.toml | 2 +- src/main.rs | 2 +- src/monitoring/mod.rs | 2 +- src/monitoring/{request_timer.rs => performance.rs} | 11 ++++++----- 4 files changed, 9 insertions(+), 8 deletions(-) rename src/monitoring/{request_timer.rs => performance.rs} (70%) diff --git a/Cargo.toml b/Cargo.toml index 655f08140..80294821b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "safe-client-gateway" -version = "1.5.0" +version = "1.5.1" authors = ["jpalvarezl "] edition = "2018" diff --git a/src/main.rs b/src/main.rs index ea91b7d68..7ea8affa8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -37,7 +37,7 @@ fn main() { rocket::ignite() .mount("/", active_routes()) .manage(reqwest::blocking::Client::new()) - .attach(monitoring::request_timer::RequestTimer()) + .attach(monitoring::performance::PerformanceMonitor()) .attach(CORS()) .attach(ServiceCache::fairing()) .register(error_catchers()) diff --git a/src/monitoring/mod.rs b/src/monitoring/mod.rs index dfdaa3f5f..570d8417f 100644 --- a/src/monitoring/mod.rs +++ b/src/monitoring/mod.rs @@ -1 +1 @@ -pub mod request_timer; +pub mod performance; diff --git a/src/monitoring/request_timer.rs b/src/monitoring/performance.rs similarity index 70% rename from src/monitoring/request_timer.rs rename to src/monitoring/performance.rs index 056be736e..617fc8a3c 100644 --- a/src/monitoring/request_timer.rs +++ b/src/monitoring/performance.rs @@ -2,12 +2,12 @@ use chrono::Utc; use rocket::fairing::{Fairing, Info, Kind}; use rocket::{Data, Request, Response}; -pub struct RequestTimer(); +pub struct PerformanceMonitor(); -impl Fairing for RequestTimer { +impl Fairing for PerformanceMonitor { fn info(&self) -> Info { Info { - name: "RequestTimer", + name: "PerformanceMonitor", kind: Kind::Request | Kind::Response, } } @@ -16,7 +16,7 @@ impl Fairing for RequestTimer { request.local_cache(|| Utc::now().timestamp_millis()); } - fn on_response(&self, request: &Request, _response: &mut Response) { + fn on_response(&self, request: &Request, response: &mut Response) { let path_data = request .route() .map(|route| route.uri.to_string()) @@ -25,7 +25,8 @@ impl Fairing for RequestTimer { .local_cache(|| Utc::now().timestamp_millis()) .to_owned(); let method = request.method().as_str(); + let status_code = response.status().code; let delta = Utc::now().timestamp_millis() - cached; - log::info!("MT::{}::{}::{}", method, path_data, delta) + log::info!("MT::{}::{}::{}::{}", method, path_data, delta, status_code) } }