From 538938420cb707f6b13215ed5d24789317b46f91 Mon Sep 17 00:00:00 2001 From: Ruslan Pislari Date: Fri, 6 Sep 2024 10:45:58 +0300 Subject: [PATCH] fix: change wasm memory usage metric type --- crates/http-service/src/lib.rs | 4 ++-- crates/runtime/src/util/metrics.rs | 13 +++++++++---- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/crates/http-service/src/lib.rs b/crates/http-service/src/lib.rs index 3a5ca73..62e8f8c 100644 --- a/crates/http-service/src/lib.rs +++ b/crates/http-service/src/lib.rs @@ -304,7 +304,7 @@ where self.context.write_stats(stat_row).await; } #[cfg(feature = "metrics")] - metrics::metrics(AppResult::SUCCESS, &["http"], Some((time_elapsed.as_micros() as f64) / 1_000_000f64), Some(memory_used.as_u64() as f64)); + metrics::metrics(AppResult::SUCCESS, &["http"], Some(time_elapsed.as_micros() as u64), Some(memory_used.as_u64())); response.headers_mut().extend(app_res_headers(cfg)); response @@ -391,7 +391,7 @@ where tracing::debug!(?fail_reason, request_id, "stats"); #[cfg(feature = "metrics")] - metrics::metrics(fail_reason, HTTP_LABEL, Some((time_elapsed.as_micros() as f64) / 1_000_000f64), None); + metrics::metrics(fail_reason, HTTP_LABEL, Some(time_elapsed.as_micros() as u64), None); let builder = Response::builder().status(status_code); let res_headers = app_res_headers(cfg); diff --git a/crates/runtime/src/util/metrics.rs b/crates/runtime/src/util/metrics.rs index d675c5b..46e829f 100644 --- a/crates/runtime/src/util/metrics.rs +++ b/crates/runtime/src/util/metrics.rs @@ -14,10 +14,15 @@ lazy_static! { .unwrap(); static ref REQUEST_DURATION: HistogramVec = register_histogram_vec!("fastedge_request_duration", "Request duration", &["executor"]).unwrap(); - static ref MEMORY_USAGE: HistogramVec = register_histogram_vec!("fastedge_wasm_memory_used", "WASM Memory usage", &["executor"]).unwrap(); + + static ref MEMORY_USAGE: IntCounterVec = register_int_counter_vec!( + "fastedge_wasm_memory_used", + "WASM Memory usage", &["executor"] + ) + .unwrap(); } -pub fn metrics(result: AppResult, label: &[&str], duration: Option, memory_used: Option) { +pub fn metrics(result: AppResult, label: &[&str], duration: Option, memory_used: Option) { TOTAL_COUNT.with_label_values(label).inc(); if result != AppResult::SUCCESS { @@ -34,9 +39,9 @@ pub fn metrics(result: AppResult, label: &[&str], duration: Option, memory_ } if let Some(duration) = duration { - REQUEST_DURATION.with_label_values(label).observe(duration); + REQUEST_DURATION.with_label_values(label).observe((duration as f64)/ 1_000_000.0); } if let Some(memory_used) = memory_used { - MEMORY_USAGE.with_label_values(label).observe(memory_used); + MEMORY_USAGE.with_label_values(label).inc_by(memory_used); } }