Skip to content

Commit 07e8f00

Browse files
committed
refactor: StatRow structure
1 parent 8495180 commit 07e8f00

File tree

2 files changed

+13
-13
lines changed

2 files changed

+13
-13
lines changed

crates/http-service/src/lib.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ use runtime::{
2525
};
2626
use secret::SecretStrategy;
2727
use smol_str::SmolStr;
28+
#[cfg(feature = "stats")]
29+
use smol_str::ToSmolStr;
2830
use state::HttpState;
2931
use tokio::{net::TcpListener, time::error::Elapsed};
3032
pub use wasmtime_wasi_http::body::HyperOutgoingBody;
@@ -311,11 +313,11 @@ where
311313
let start_ = std::time::Instant::now();
312314

313315
let response_handler = {
314-
let app_name = app_name.to_string();
316+
let app_name = app_name.clone();
315317
#[cfg(feature = "stats")]
316-
let billing_plan = cfg.plan.to_string();
318+
let billing_plan = cfg.plan.clone();
317319
#[cfg(feature = "stats")]
318-
let request_id = request_id.to_string();
320+
let request_id = request_id.to_smolstr();
319321
#[cfg(feature = "stats")]
320322
let context = self.context.clone();
321323

@@ -340,7 +342,6 @@ where
340342
time_elapsed: time_elapsed.as_micros() as u64,
341343
memory_used: mem_used.as_u64(),
342344
request_id,
343-
..Default::default()
344345
};
345346
context.write_stats(stat_row);
346347
}
@@ -377,14 +378,13 @@ where
377378
app_id: cfg.app_id,
378379
client_id: cfg.client_id,
379380
timestamp: timestamp as u32,
380-
app_name: app_name.to_string(),
381+
app_name: app_name,
381382
status_code: status_code as u32,
382383
fail_reason: fail_reason as u32,
383-
billing_plan: cfg.plan.to_string(),
384+
billing_plan: cfg.plan.clone(),
384385
time_elapsed: time_elapsed.as_micros() as u64,
385386
memory_used: 0,
386-
request_id: request_id.to_string(),
387-
..Default::default()
387+
request_id: request_id.to_smolstr(),
388388
};
389389
self.context.write_stats(stat_row);
390390
}

crates/runtime/src/util/stats.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,22 @@
22
use clickhouse::Row;
33
#[cfg(feature = "stats")]
44
use serde::Serialize;
5+
#[cfg(feature = "stats")]
6+
use smol_str::SmolStr;
57

68
#[cfg(feature = "stats")]
79
#[derive(Row, Debug, Serialize, Default)]
810
pub struct StatRow {
911
pub app_id: u64,
1012
pub client_id: u64,
1113
pub timestamp: u32,
12-
pub app_name: String,
14+
pub app_name: SmolStr,
1315
pub status_code: u32,
1416
pub fail_reason: u32,
15-
pub billing_plan: String,
17+
pub billing_plan: SmolStr,
1618
pub time_elapsed: u64,
1719
pub memory_used: u64,
18-
pub pop: String,
19-
pub region: String,
20-
pub request_id: String,
20+
pub request_id: SmolStr,
2121
}
2222

2323
#[cfg(not(feature = "stats"))]

0 commit comments

Comments
 (0)