From e8d94da661f62a76adc49209322f58a23dc91732 Mon Sep 17 00:00:00 2001 From: _ <> Date: Sun, 20 Dec 2020 17:44:03 +0000 Subject: [PATCH] :recycle: refactor: change PerInstance to Startup --- crates/ptth_file_server_bin/src/main.rs | 4 ++-- crates/ptth_server/src/file_server/metrics.rs | 9 +++++---- crates/ptth_server/src/file_server/mod.rs | 8 ++++---- crates/ptth_server/src/lib.rs | 4 ++-- 4 files changed, 13 insertions(+), 12 deletions(-) diff --git a/crates/ptth_file_server_bin/src/main.rs b/crates/ptth_file_server_bin/src/main.rs index 5921497..561072b 100644 --- a/crates/ptth_file_server_bin/src/main.rs +++ b/crates/ptth_file_server_bin/src/main.rs @@ -40,7 +40,7 @@ pub struct Config { struct ServerState <'a> { config: Config, handlebars: handlebars::Handlebars <'a>, - instance_metrics: metrics::PerInstance, + instance_metrics: metrics::Startup, hidden_path: Option , } @@ -105,7 +105,7 @@ async fn main () -> Result <(), anyhow::Error> { let handlebars = file_server::load_templates (&PathBuf::new ())?; - let instance_metrics = metrics::PerInstance::new ( + let instance_metrics = metrics::Startup::new ( config_file.name.unwrap_or_else (|| "PTTH File Server".to_string ()) ); diff --git a/crates/ptth_server/src/file_server/metrics.rs b/crates/ptth_server/src/file_server/metrics.rs index 9db8d51..eb6ae0c 100644 --- a/crates/ptth_server/src/file_server/metrics.rs +++ b/crates/ptth_server/src/file_server/metrics.rs @@ -12,7 +12,7 @@ fn serialize_ulid (t: &Ulid, s: S) // They don't change after that. #[derive (Debug, serde::Serialize)] -pub struct PerInstance { +pub struct Startup { // D-Bus machine ID, if we're on Linux pub machine_id: Option , @@ -28,6 +28,7 @@ pub struct PerInstance { #[serde (serialize_with = "serialize_ulid")] pub instance_id: Ulid, + // System UTC pub startup_utc: DateTime , } @@ -54,7 +55,7 @@ fn get_machine_id () -> Option { Some (s) } -impl PerInstance { +impl Startup { #[must_use] pub fn new (server_name: String) -> Self { @@ -74,8 +75,8 @@ mod tests { #[test] fn ulid_null () { - let a = PerInstance::new ("bogus".to_string ()); - let b = PerInstance::new ("bogus".to_string ()); + let a = Startup::new ("bogus".to_string ()); + let b = Startup::new ("bogus".to_string ()); assert_ne! (a.instance_id, b.instance_id); } diff --git a/crates/ptth_server/src/file_server/mod.rs b/crates/ptth_server/src/file_server/mod.rs index 37ee6a0..78481c4 100644 --- a/crates/ptth_server/src/file_server/mod.rs +++ b/crates/ptth_server/src/file_server/mod.rs @@ -89,7 +89,7 @@ struct DirEntryHtml { #[derive (Serialize)] struct DirHtml <'a> { #[serde (flatten)] - instance_metrics: &'a metrics::PerInstance, + instance_metrics: &'a metrics::Startup, path: Cow <'a, str>, entries: Vec , @@ -187,7 +187,7 @@ async fn read_dir_entry_json (entry: DirEntry) -> Option async fn serve_root ( handlebars: &Handlebars <'static>, - instance_metrics: &metrics::PerInstance + instance_metrics: &metrics::Startup ) -> Result { let s = handlebars.render ("file_server_root", &instance_metrics)?; @@ -232,7 +232,7 @@ async fn serve_dir_json ( #[instrument (level = "debug", skip (handlebars, instance_metrics, dir))] async fn serve_dir_html ( handlebars: &Handlebars <'static>, - instance_metrics: &metrics::PerInstance, + instance_metrics: &metrics::Startup, path: Cow <'_, str>, mut dir: ReadDir ) -> Result @@ -358,7 +358,7 @@ async fn serve_file ( #[instrument (level = "debug", skip (handlebars, headers, instance_metrics))] pub async fn serve_all ( handlebars: &Handlebars <'static>, - instance_metrics: &metrics::PerInstance, + instance_metrics: &metrics::Startup, root: &Path, method: Method, uri: &str, diff --git a/crates/ptth_server/src/lib.rs b/crates/ptth_server/src/lib.rs index 0bf214e..0f2ae0b 100644 --- a/crates/ptth_server/src/lib.rs +++ b/crates/ptth_server/src/lib.rs @@ -54,7 +54,7 @@ pub fn password_is_bad (mut password: String) -> bool { struct ServerState { config: Config, handlebars: Handlebars <'static>, - instance_metrics: file_server::metrics::PerInstance, + instance_metrics: file_server::metrics::Startup, gauges: RwLock , client: Client, hidden_path: Option , @@ -205,7 +205,7 @@ pub async fn run_server ( .build ().map_err (ServerError::CantBuildHttpClient)?; let handlebars = file_server::load_templates (&asset_root)?; - let instance_metrics = file_server::metrics::PerInstance::new (config_file.name); + let instance_metrics = file_server::metrics::Startup::new (config_file.name); let state = Arc::new (ServerState { config: Config {