From 4993bb99a1c969a97abec0c93e8eefc59e153805 Mon Sep 17 00:00:00 2001 From: Macpie Date: Mon, 13 May 2024 10:34:34 -0700 Subject: [PATCH] Make custom-tracing settings --- Cargo.lock | 1 + boost_manager/src/main.rs | 2 +- boost_manager/src/settings.rs | 8 +------- custom_tracing/Cargo.toml | 1 + custom_tracing/src/lib.rs | 6 ++++-- custom_tracing/src/settings.rs | 12 ++++++++++++ ingest/src/main.rs | 2 +- ingest/src/settings.rs | 8 +------- iot_config/src/main.rs | 2 +- iot_config/src/settings.rs | 8 +------- iot_packet_verifier/src/main.rs | 2 +- iot_packet_verifier/src/settings.rs | 8 +------- iot_verifier/src/main.rs | 2 +- iot_verifier/src/settings.rs | 8 +------- mobile_config/src/main.rs | 2 +- mobile_config/src/settings.rs | 8 +------- mobile_packet_verifier/src/main.rs | 2 +- mobile_packet_verifier/src/settings.rs | 8 +------- mobile_verifier/src/main.rs | 2 +- mobile_verifier/src/settings.rs | 8 +------- poc_entropy/src/main.rs | 2 +- poc_entropy/src/settings.rs | 8 +------- price/src/main.rs | 2 +- price/src/settings.rs | 8 +------- reward_index/src/main.rs | 2 +- reward_index/src/settings.rs | 8 +------- 26 files changed, 40 insertions(+), 90 deletions(-) create mode 100644 custom_tracing/src/settings.rs diff --git a/Cargo.lock b/Cargo.lock index 5df226b74..32bb7523a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2335,6 +2335,7 @@ dependencies = [ "helium-proto", "http 0.2.11", "notify", + "serde", "tokio", "tower-http", "tower-layer", diff --git a/boost_manager/src/main.rs b/boost_manager/src/main.rs index ad5fc82e5..82c128ffb 100644 --- a/boost_manager/src/main.rs +++ b/boost_manager/src/main.rs @@ -53,7 +53,7 @@ pub struct Server {} impl Server { pub async fn run(&self, settings: &Settings) -> Result<()> { - custom_tracing::init(settings.log.clone(), settings.tracing_cfg_file.clone()).await?; + custom_tracing::init(settings.log.clone(), settings.custom_tracing.clone()).await?; // Install the prometheus metrics exporter poc_metrics::start_metrics(&settings.metrics)?; diff --git a/boost_manager/src/settings.rs b/boost_manager/src/settings.rs index c0b1db3c1..40ffabfa5 100644 --- a/boost_manager/src/settings.rs +++ b/boost_manager/src/settings.rs @@ -9,9 +9,7 @@ pub struct Settings { /// "poc_entropy=debug,poc_store=info" #[serde(default = "default_log")] pub log: String, - /// File name to be watched by custom tracing - #[serde(default = "default_tracing_cfg_file")] - pub tracing_cfg_file: String, + pub custom_tracing: custom_tracing::Settings, /// Cache location for generated verified reports pub cache: String, /// Reward files check interval in seconds. (Default is 900; 15 minutes) @@ -63,10 +61,6 @@ pub fn default_log() -> String { "boost_manager=info".to_string() } -pub fn default_tracing_cfg_file() -> String { - "tracing.cfg".to_string() -} - impl Settings { /// Load Settings from a given path. Settings are loaded from a given /// optional path and can be overriden with environment variables. diff --git a/custom_tracing/Cargo.toml b/custom_tracing/Cargo.toml index 83ba8bd3a..21568dab6 100644 --- a/custom_tracing/Cargo.toml +++ b/custom_tracing/Cargo.toml @@ -6,6 +6,7 @@ license.workspace = true edition.workspace = true [dependencies] +serde = { version = "1", features = ["derive"] } notify = { version = "6", default-features = false } anyhow = "1" tokio = { version = "1", features = ["rt-multi-thread", "sync", "signal"] } diff --git a/custom_tracing/src/lib.rs b/custom_tracing/src/lib.rs index 03a4e03c3..aa9a5600e 100644 --- a/custom_tracing/src/lib.rs +++ b/custom_tracing/src/lib.rs @@ -1,5 +1,7 @@ use anyhow::Result; use notify::{event::DataChange, Config, RecommendedWatcher, RecursiveMode, Watcher}; +mod settings; +pub use settings::Settings; use std::{fs, path::Path}; use tracing::Span; use tracing_subscriber::{ @@ -14,7 +16,7 @@ pub mod grpc_layer; #[cfg(feature = "http-1")] pub mod http_layer; -pub async fn init(og_filter: String, tracing_cfg_file: String) -> Result<()> { +pub async fn init(og_filter: String, settings: Settings) -> Result<()> { let (filtered_layer, reload_handle) = reload::Layer::new(tracing_subscriber::EnvFilter::new(og_filter.clone())); @@ -26,7 +28,7 @@ pub async fn init(og_filter: String, tracing_cfg_file: String) -> Result<()> { tokio::spawn(async move { let state = State { og_filter: og_filter.clone(), - tracing_cfg_file, + tracing_cfg_file: settings.tracing_cfg_file, reload_handle, }; if let Err(err) = state.watch().await { diff --git a/custom_tracing/src/settings.rs b/custom_tracing/src/settings.rs new file mode 100644 index 000000000..d00be59dc --- /dev/null +++ b/custom_tracing/src/settings.rs @@ -0,0 +1,12 @@ +use serde::{Deserialize, Serialize}; + +#[derive(Debug, Serialize, Deserialize, Clone)] +pub struct Settings { + /// File name to be watched by custom tracing + #[serde(default = "default_tracing_cfg_file")] + pub tracing_cfg_file: String, +} + +pub fn default_tracing_cfg_file() -> String { + "tracing.cfg".to_string() +} diff --git a/ingest/src/main.rs b/ingest/src/main.rs index 9bd6b117b..4a7f24681 100644 --- a/ingest/src/main.rs +++ b/ingest/src/main.rs @@ -40,7 +40,7 @@ pub struct Server {} impl Server { pub async fn run(&self, settings: &Settings) -> Result<()> { - custom_tracing::init(settings.log.clone(), settings.tracing_cfg_file.clone()).await?; + custom_tracing::init(settings.log.clone(), settings.custom_tracing.clone()).await?; // Install the prometheus metrics exporter poc_metrics::start_metrics(&settings.metrics)?; diff --git a/ingest/src/settings.rs b/ingest/src/settings.rs index 6dc041a4b..7b55185ab 100644 --- a/ingest/src/settings.rs +++ b/ingest/src/settings.rs @@ -13,9 +13,7 @@ pub struct Settings { /// "ingest=debug,poc_store=info" #[serde(default = "default_log")] pub log: String, - /// File name to be watched by custom tracing - #[serde(default = "default_tracing_cfg_file")] - pub tracing_cfg_file: String, + pub custom_tracing: custom_tracing::Settings, /// Mode to run the server in (iot or mobile). Required pub mode: Mode, /// Listen address. Required. Default is 0.0.0.0:9081 @@ -57,10 +55,6 @@ pub fn default_log() -> String { "ingest=debug,poc_store=info".to_string() } -pub fn default_tracing_cfg_file() -> String { - "tracing.cfg".to_string() -} - pub fn default_sink() -> String { "/var/data/ingest".to_string() } diff --git a/iot_config/src/main.rs b/iot_config/src/main.rs index f3825413c..08ecb24bb 100644 --- a/iot_config/src/main.rs +++ b/iot_config/src/main.rs @@ -51,7 +51,7 @@ pub struct Daemon; impl Daemon { pub async fn run(&self, settings: &Settings) -> Result<()> { - custom_tracing::init(settings.log.clone(), settings.tracing_cfg_file.clone()).await?; + custom_tracing::init(settings.log.clone(), settings.custom_tracing.clone()).await?; // Install prometheus metrics exporter poc_metrics::start_metrics(&settings.metrics)?; diff --git a/iot_config/src/settings.rs b/iot_config/src/settings.rs index 071a48a05..56be9b09a 100644 --- a/iot_config/src/settings.rs +++ b/iot_config/src/settings.rs @@ -13,9 +13,7 @@ pub struct Settings { /// "iot_config=info" #[serde(default = "default_log")] pub log: String, - /// File name to be watched by custom tracing - #[serde(default = "default_tracing_cfg_file")] - pub tracing_cfg_file: String, + pub custom_tracing: custom_tracing::Settings, /// Listen address. Required. Default is 0.0.0.0:8080 #[serde(default = "default_listen_addr")] pub listen: String, @@ -36,10 +34,6 @@ pub fn default_log() -> String { "iot_config=debug".to_string() } -pub fn default_tracing_cfg_file() -> String { - "tracing.cfg".to_string() -} - pub fn default_listen_addr() -> String { "0.0.0.0:8080".to_string() } diff --git a/iot_packet_verifier/src/main.rs b/iot_packet_verifier/src/main.rs index 446f2fa64..f84ff8dac 100644 --- a/iot_packet_verifier/src/main.rs +++ b/iot_packet_verifier/src/main.rs @@ -20,7 +20,7 @@ pub struct Cli { impl Cli { pub async fn run(self) -> Result<()> { let settings = Settings::new(self.config)?; - custom_tracing::init(settings.log.clone(), settings.tracing_cfg_file.clone()).await?; + custom_tracing::init(settings.log.clone(), settings.custom_tracing.clone()).await?; self.cmd.run(settings).await } } diff --git a/iot_packet_verifier/src/settings.rs b/iot_packet_verifier/src/settings.rs index 9e506eec2..321d1806c 100644 --- a/iot_packet_verifier/src/settings.rs +++ b/iot_packet_verifier/src/settings.rs @@ -9,9 +9,7 @@ pub struct Settings { /// "iot_packet_verifier=debug,poc_store=info" #[serde(default = "default_log")] pub log: String, - /// File name to be watched by custom tracing - #[serde(default = "default_tracing_cfg_file")] - pub tracing_cfg_file: String, + pub custom_tracing: custom_tracing::Settings, /// Cache location for generated verified reports pub cache: String, /// Data credit burn period in minutes. Default is 1. @@ -48,10 +46,6 @@ pub fn default_log() -> String { "iot_packet_verifier=debug".to_string() } -pub fn default_tracing_cfg_file() -> String { - "tracing.cfg".to_string() -} - pub fn default_minimum_allowed_balance() -> u64 { 3_500_000 } diff --git a/iot_verifier/src/main.rs b/iot_verifier/src/main.rs index 976298e25..d80d19555 100644 --- a/iot_verifier/src/main.rs +++ b/iot_verifier/src/main.rs @@ -56,7 +56,7 @@ pub struct Server {} impl Server { pub async fn run(&self, settings: &Settings) -> Result<()> { - custom_tracing::init(settings.log.clone(), settings.tracing_cfg_file.clone()).await?; + custom_tracing::init(settings.log.clone(), settings.custom_tracing.clone()).await?; // Install the prometheus metrics exporter poc_metrics::start_metrics(&settings.metrics)?; diff --git a/iot_verifier/src/settings.rs b/iot_verifier/src/settings.rs index 064c822fe..e8a1e6327 100644 --- a/iot_verifier/src/settings.rs +++ b/iot_verifier/src/settings.rs @@ -11,9 +11,7 @@ pub struct Settings { /// "iot_verifier=debug,poc_store=info" #[serde(default = "default_log")] pub log: String, - /// File name to be watched by custom tracing - #[serde(default = "default_tracing_cfg_file")] - pub tracing_cfg_file: String, + pub custom_tracing: custom_tracing::Settings, /// Cache location for generated verified reports pub cache: String, /// the base_stale period in seconds @@ -162,10 +160,6 @@ pub fn default_log() -> String { "iot_verifier=debug,poc_store=info".to_string() } -pub fn default_tracing_cfg_file() -> String { - "tracing.cfg".to_string() -} - pub fn default_base_stale_period() -> i64 { 0 } diff --git a/mobile_config/src/main.rs b/mobile_config/src/main.rs index 4cb859498..e9cd26898 100644 --- a/mobile_config/src/main.rs +++ b/mobile_config/src/main.rs @@ -55,7 +55,7 @@ pub struct Daemon; impl Daemon { pub async fn run(&self, settings: &Settings) -> Result<()> { - custom_tracing::init(settings.log.clone(), settings.tracing_cfg_file.clone()).await?; + custom_tracing::init(settings.log.clone(), settings.custom_tracing.clone()).await?; // Install prometheus metrics exporter poc_metrics::start_metrics(&settings.metrics)?; diff --git a/mobile_config/src/settings.rs b/mobile_config/src/settings.rs index 4a911c9fe..451d5f1d7 100644 --- a/mobile_config/src/settings.rs +++ b/mobile_config/src/settings.rs @@ -13,9 +13,7 @@ pub struct Settings { /// "mobile_config=info" #[serde(default = "default_log")] pub log: String, - /// File name to be watched by custom tracing - #[serde(default = "default_tracing_cfg_file")] - pub tracing_cfg_file: String, + pub custom_tracing: custom_tracing::Settings, /// Listen address. Required. Default to 0.0.0.0::8080 #[serde(default = "default_listen_addr")] pub listen: String, @@ -36,10 +34,6 @@ pub fn default_log() -> String { "mobile_config=debug".to_string() } -pub fn default_tracing_cfg_file() -> String { - "tracing.cfg".to_string() -} - pub fn default_listen_addr() -> String { "0.0.0.0:8080".to_string() } diff --git a/mobile_packet_verifier/src/main.rs b/mobile_packet_verifier/src/main.rs index 4c6866af7..ede970221 100644 --- a/mobile_packet_verifier/src/main.rs +++ b/mobile_packet_verifier/src/main.rs @@ -20,7 +20,7 @@ pub struct Cli { impl Cli { pub async fn run(self) -> Result<()> { let settings = Settings::new(self.config)?; - custom_tracing::init(settings.log.clone(), settings.tracing_cfg_file.clone()).await?; + custom_tracing::init(settings.log.clone(), settings.custom_tracing.clone()).await?; self.cmd.run(settings).await } } diff --git a/mobile_packet_verifier/src/settings.rs b/mobile_packet_verifier/src/settings.rs index abef7c863..7f4f826dd 100644 --- a/mobile_packet_verifier/src/settings.rs +++ b/mobile_packet_verifier/src/settings.rs @@ -9,9 +9,7 @@ pub struct Settings { /// "mobile_verifier=debug,poc_store=info" #[serde(default = "default_log")] pub log: String, - /// File name to be watched by custom tracing - #[serde(default = "default_tracing_cfg_file")] - pub tracing_cfg_file: String, + pub custom_tracing: custom_tracing::Settings, /// Cache location for generated verified reports pub cache: String, /// Burn period in hours. (Default is 1) @@ -56,10 +54,6 @@ pub fn default_log() -> String { "mobile_packet_verifier=debug,poc_store=info".to_string() } -pub fn default_tracing_cfg_file() -> String { - "tracing.cfg".to_string() -} - pub fn default_burn_period() -> i64 { 1 } diff --git a/mobile_verifier/src/main.rs b/mobile_verifier/src/main.rs index 23d8d278e..3b3c991b7 100644 --- a/mobile_verifier/src/main.rs +++ b/mobile_verifier/src/main.rs @@ -23,7 +23,7 @@ pub struct Cli { impl Cli { pub async fn run(self) -> Result<()> { let settings = Settings::new(self.config)?; - custom_tracing::init(settings.log.clone(), settings.tracing_cfg_file.clone()).await?; + custom_tracing::init(settings.log.clone(), settings.custom_tracing.clone()).await?; self.cmd.run(settings).await } } diff --git a/mobile_verifier/src/settings.rs b/mobile_verifier/src/settings.rs index 63452cd11..d1ea819d7 100644 --- a/mobile_verifier/src/settings.rs +++ b/mobile_verifier/src/settings.rs @@ -9,9 +9,7 @@ pub struct Settings { /// "mobile_verifier=debug,poc_store=info" #[serde(default = "default_log")] pub log: String, - /// File name to be watched by custom tracing - #[serde(default = "default_tracing_cfg_file")] - pub tracing_cfg_file: String, + pub custom_tracing: custom_tracing::Settings, /// Cache location for generated verified reports pub cache: String, /// Reward period in hours. (Default is 24) @@ -67,10 +65,6 @@ pub fn default_log() -> String { "mobile_verifier=debug,poc_store=info".to_string() } -pub fn default_tracing_cfg_file() -> String { - "tracing.cfg".to_string() -} - pub fn default_start_after() -> u64 { 0 } diff --git a/poc_entropy/src/main.rs b/poc_entropy/src/main.rs index 596e495be..1879ab59d 100644 --- a/poc_entropy/src/main.rs +++ b/poc_entropy/src/main.rs @@ -26,7 +26,7 @@ pub struct Cli { impl Cli { pub async fn run(self) -> Result<()> { let settings = Settings::new(self.config)?; - custom_tracing::init(settings.log.clone(), settings.tracing_cfg_file.clone()).await?; + custom_tracing::init(settings.log.clone(), settings.custom_tracing.clone()).await?; self.cmd.run(settings).await } } diff --git a/poc_entropy/src/settings.rs b/poc_entropy/src/settings.rs index 513bc63a3..4967c5847 100644 --- a/poc_entropy/src/settings.rs +++ b/poc_entropy/src/settings.rs @@ -8,9 +8,7 @@ pub struct Settings { /// "poc_entropy=debug,poc_store=info" #[serde(default = "default_log")] pub log: String, - /// File name to be watched by custom tracing - #[serde(default = "default_tracing_cfg_file")] - pub tracing_cfg_file: String, + pub custom_tracing: custom_tracing::Settings, /// Listen address for http requests for entropy. Default "0.0.0.0:8080" #[serde(default = "default_listen_addr")] pub listen: String, @@ -29,10 +27,6 @@ pub fn default_log() -> String { "poc_entropy=debug,poc_store=info".to_string() } -pub fn default_tracing_cfg_file() -> String { - "tracing.cfg".to_string() -} - pub fn default_cache() -> String { "/var/data/entropy".to_string() } diff --git a/price/src/main.rs b/price/src/main.rs index 56242b3b7..9f94d17ca 100644 --- a/price/src/main.rs +++ b/price/src/main.rs @@ -40,7 +40,7 @@ impl Cmd { match self { Self::Server(cmd) => { let settings = Settings::new(config)?; - custom_tracing::init(settings.log.clone(), settings.tracing_cfg_file.clone()) + custom_tracing::init(settings.log.clone(), settings.custom_tracing.clone()) .await?; cmd.run(&settings).await } diff --git a/price/src/settings.rs b/price/src/settings.rs index 321511742..4396fe49d 100644 --- a/price/src/settings.rs +++ b/price/src/settings.rs @@ -37,9 +37,7 @@ pub struct Settings { /// "price=debug" #[serde(default = "default_log")] pub log: String, - /// File name to be watched by custom tracing - #[serde(default = "default_tracing_cfg_file")] - pub tracing_cfg_file: String, + pub custom_tracing: custom_tracing::Settings, /// Source URL for price data. Required #[serde(default = "default_source")] pub source: String, @@ -76,10 +74,6 @@ pub fn default_log() -> String { "price=debug".to_string() } -pub fn default_tracing_cfg_file() -> String { - "tracing.cfg".to_string() -} - pub fn default_interval() -> i64 { 60 } diff --git a/reward_index/src/main.rs b/reward_index/src/main.rs index f31bf0fec..1bacebebd 100644 --- a/reward_index/src/main.rs +++ b/reward_index/src/main.rs @@ -27,7 +27,7 @@ pub struct Cli { impl Cli { pub async fn run(self) -> Result<()> { let settings = Settings::new(self.config)?; - custom_tracing::init(settings.log.clone(), settings.tracing_cfg_file.clone()).await?; + custom_tracing::init(settings.log.clone(), settings.custom_tracing.clone()).await?; self.cmd.run(settings).await } } diff --git a/reward_index/src/settings.rs b/reward_index/src/settings.rs index 0ba5ab9fe..99fba9976 100644 --- a/reward_index/src/settings.rs +++ b/reward_index/src/settings.rs @@ -27,9 +27,7 @@ pub struct Settings { /// "poc_entropy=debug,poc_store=info" #[serde(default = "default_log")] pub log: String, - /// File name to be watched by custom tracing - #[serde(default = "default_tracing_cfg_file")] - pub tracing_cfg_file: String, + pub custom_tracing: custom_tracing::Settings, /// Check interval in seconds. (Default is 900; 15 minutes) #[serde(default = "default_interval")] pub interval: i64, @@ -52,10 +50,6 @@ pub fn default_log() -> String { "reward_index=debug,poc_store=info".to_string() } -pub fn default_tracing_cfg_file() -> String { - "tracing.cfg".to_string() -} - impl Settings { /// Load Settings from a given path. Settings are loaded from a given /// optional path and can be overriden with environment variables.