Skip to content

Commit

Permalink
refactor: StatRow structure
Browse files Browse the repository at this point in the history
  • Loading branch information
ruslanti committed Feb 20, 2025
1 parent 8495180 commit 07e8f00
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
16 changes: 8 additions & 8 deletions crates/http-service/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ use runtime::{
};
use secret::SecretStrategy;
use smol_str::SmolStr;
#[cfg(feature = "stats")]
use smol_str::ToSmolStr;
use state::HttpState;
use tokio::{net::TcpListener, time::error::Elapsed};
pub use wasmtime_wasi_http::body::HyperOutgoingBody;
Expand Down Expand Up @@ -311,11 +313,11 @@ where
let start_ = std::time::Instant::now();

let response_handler = {
let app_name = app_name.to_string();
let app_name = app_name.clone();
#[cfg(feature = "stats")]
let billing_plan = cfg.plan.to_string();
let billing_plan = cfg.plan.clone();
#[cfg(feature = "stats")]
let request_id = request_id.to_string();
let request_id = request_id.to_smolstr();
#[cfg(feature = "stats")]
let context = self.context.clone();

Expand All @@ -340,7 +342,6 @@ where
time_elapsed: time_elapsed.as_micros() as u64,
memory_used: mem_used.as_u64(),
request_id,
..Default::default()
};
context.write_stats(stat_row);
}
Expand Down Expand Up @@ -377,14 +378,13 @@ where
app_id: cfg.app_id,
client_id: cfg.client_id,
timestamp: timestamp as u32,
app_name: app_name.to_string(),
app_name: app_name,
status_code: status_code as u32,
fail_reason: fail_reason as u32,
billing_plan: cfg.plan.to_string(),
billing_plan: cfg.plan.clone(),
time_elapsed: time_elapsed.as_micros() as u64,
memory_used: 0,
request_id: request_id.to_string(),
..Default::default()
request_id: request_id.to_smolstr(),
};
self.context.write_stats(stat_row);
}
Expand Down
10 changes: 5 additions & 5 deletions crates/runtime/src/util/stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,22 @@
use clickhouse::Row;
#[cfg(feature = "stats")]
use serde::Serialize;
#[cfg(feature = "stats")]
use smol_str::SmolStr;

#[cfg(feature = "stats")]
#[derive(Row, Debug, Serialize, Default)]
pub struct StatRow {
pub app_id: u64,
pub client_id: u64,
pub timestamp: u32,
pub app_name: String,
pub app_name: SmolStr,
pub status_code: u32,
pub fail_reason: u32,
pub billing_plan: String,
pub billing_plan: SmolStr,
pub time_elapsed: u64,
pub memory_used: u64,
pub pop: String,
pub region: String,
pub request_id: String,
pub request_id: SmolStr,
}

#[cfg(not(feature = "stats"))]
Expand Down

0 comments on commit 07e8f00

Please sign in to comment.