Skip to content

Commit

Permalink
fix: change wasm memory usage metric type
Browse files Browse the repository at this point in the history
  • Loading branch information
ruslanti committed Sep 6, 2024
1 parent 7d3e508 commit 5389384
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
4 changes: 2 additions & 2 deletions crates/http-service/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down
13 changes: 9 additions & 4 deletions crates/runtime/src/util/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<f64>, memory_used: Option<f64>) {
pub fn metrics(result: AppResult, label: &[&str], duration: Option<u64>, memory_used: Option<u64>) {
TOTAL_COUNT.with_label_values(label).inc();

if result != AppResult::SUCCESS {
Expand All @@ -34,9 +39,9 @@ pub fn metrics(result: AppResult, label: &[&str], duration: Option<f64>, 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);
}
}

0 comments on commit 5389384

Please sign in to comment.