Skip to content

Commit

Permalink
Make custom-tracing settings
Browse files Browse the repository at this point in the history
  • Loading branch information
macpie committed May 13, 2024
1 parent 527b8b3 commit 4993bb9
Show file tree
Hide file tree
Showing 26 changed files with 40 additions and 90 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion boost_manager/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?;
Expand Down
8 changes: 1 addition & 7 deletions boost_manager/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions custom_tracing/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
Expand Down
6 changes: 4 additions & 2 deletions custom_tracing/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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::{
Expand All @@ -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()));

Expand All @@ -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 {
Expand Down
12 changes: 12 additions & 0 deletions custom_tracing/src/settings.rs
Original file line number Diff line number Diff line change
@@ -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()
}
2 changes: 1 addition & 1 deletion ingest/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?;
Expand Down
8 changes: 1 addition & 7 deletions ingest/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
}
Expand Down
2 changes: 1 addition & 1 deletion iot_config/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?;
Expand Down
8 changes: 1 addition & 7 deletions iot_config/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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()
}
Expand Down
2 changes: 1 addition & 1 deletion iot_packet_verifier/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down
8 changes: 1 addition & 7 deletions iot_packet_verifier/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion iot_verifier/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?;
Expand Down
8 changes: 1 addition & 7 deletions iot_verifier/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion mobile_config/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?;
Expand Down
8 changes: 1 addition & 7 deletions mobile_config/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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()
}
Expand Down
2 changes: 1 addition & 1 deletion mobile_packet_verifier/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down
8 changes: 1 addition & 7 deletions mobile_packet_verifier/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion mobile_verifier/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down
8 changes: 1 addition & 7 deletions mobile_verifier/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion poc_entropy/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down
8 changes: 1 addition & 7 deletions poc_entropy/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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()
}
Expand Down
2 changes: 1 addition & 1 deletion price/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
8 changes: 1 addition & 7 deletions price/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion reward_index/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down
8 changes: 1 addition & 7 deletions reward_index/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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.
Expand Down

0 comments on commit 4993bb9

Please sign in to comment.