Skip to content

Commit

Permalink
feat(config)!: Introduce tracing config, change allowed_binaries list…
Browse files Browse the repository at this point in the history
… format (#1608)

* fix(config): fixed env splitting
  • Loading branch information
gurinderu authored May 16, 2023
1 parent a3d37c9 commit 6f7c684
Show file tree
Hide file tree
Showing 13 changed files with 597 additions and 306 deletions.
228 changes: 119 additions & 109 deletions Cargo.lock

Large diffs are not rendered by default.

9 changes: 6 additions & 3 deletions crates/server-config/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ fluence-libp2p = { workspace = true, features = ["tokio"] }
air-interpreter-fs = { workspace = true }
peer-metrics = { workspace = true }
fluence-keypair = { workspace = true }
log = "0.4.17"
toml = "0.7.3"

libp2p = { workspace = true }
libp2p-metrics = { workspace = true }
Expand All @@ -27,8 +29,9 @@ num_cpus = "1.15.0"
eyre = { workspace = true }
derivative = { workspace = true }
bytesize = { version = "1.2.0", features = ["serde"] }
serde_with = "2.3.3"
figment = { version = "0.10.8", features = ["parking_lot", "toml", "yaml", "json", "env"] }
serde_with = "3.0.0"
config = { version = "0.13.3", default-features = false, features = ["toml"] }

[dev-dependencies]
figment = { version = "0.10.8", features = ["test"] }
temp-env = "0.3.0"
tempfile = "3.5.0"
69 changes: 47 additions & 22 deletions crates/server-config/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@

use crate::LogFormat;
use clap::{Args, Parser};
use figment::error::Kind::InvalidType;
use figment::value::{Dict, Map, Value};
use figment::{Error, Metadata, Profile};
use config::{ConfigError, Map, Source, Value};
use serde::ser::SerializeStruct;
use serde::{Serialize, Serializer};
use std::fmt::Debug;
Expand Down Expand Up @@ -113,10 +111,43 @@ pub struct LogArgs {
#[arg(
long("log-format"),
id = "LOG_FORMAT",
help = "logging format",
help_heading = "Node configuration",
display_order = 24
)]
pub(crate) format: Option<LogFormat>,
pub format: Option<LogFormat>,
}

#[derive(Args, Debug, Clone, Serialize)]
pub struct TracingArgs {
#[arg(
long("tracing-type"),
id = "TRACING_TYPE",
help = "Tracing type",
help_heading = "Node configuration",
display_order = 25,
value_enum
)]
#[serde(rename = "type")]
tpe: Option<TracingType>,

#[arg(
long("tracing-otlp-endpoint"),
id = "TRACING_OTLP_ENDPOINT",
value_name = "URL",
help = "oltp endpoint",
help_heading = "Node configuration",
display_order = 26
)]
pub endpoint: Option<String>,
}

#[derive(clap::ValueEnum, Debug, Clone, Serialize)]
pub enum TracingType {
#[serde(rename = "disabled")]
Disabled,
#[serde(rename = "otlp")]
Otlp,
}

#[derive(Parser, Debug, Serialize, Clone)]
Expand Down Expand Up @@ -301,27 +332,21 @@ pub(crate) struct DerivedArgs {

#[command(flatten)]
log: Option<LogArgs>,

#[command(flatten)]
tracing: Option<TracingArgs>,
}

impl figment::Provider for DerivedArgs {
fn metadata(&self) -> Metadata {
Metadata::named("Args")
impl Source for DerivedArgs {
fn clone_into_box(&self) -> Box<dyn Source + Send + Sync> {
Box::new(self.clone())
}

fn data(&self) -> Result<Map<Profile, Dict>, Error> {
let value = Value::serialize(self)?;

let error = InvalidType(value.to_actual(), "map".into());
let dict = value
.into_dict()
.map(|dict| {
let a = dict.into_iter().filter_map(|(key, value)| match value {
Value::Empty(_, _) => None,
value => Some((key, value)),
});
a.collect::<Dict>()
})
.ok_or(error)?;
Ok(Map::from([(Profile::Default, dict)]))
fn collect(&self) -> Result<Map<String, Value>, ConfigError> {
let source_str =
toml::to_string(&self).map_err(|e| config::ConfigError::Foreign(Box::new(e)))?;
let result = toml::de::from_str(&source_str)
.map_err(|e| config::ConfigError::Foreign(Box::new(e)))?;
Ok(result)
}
}
2 changes: 1 addition & 1 deletion crates/server-config/src/defaults.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ pub fn default_management_peer_id() -> PeerId {
let public_key = PublicKey::Ed25519(kp.public());
let peer_id = PeerId::from(public_key);

println!(
log::info!(
"New management key generated. ed25519 private key in base64 = {}",
base64.encode(kp.secret()),
);
Expand Down
2 changes: 1 addition & 1 deletion crates/server-config/src/kademlia_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ impl KademliaConfig {
if let Some(replication_factor) = std::num::NonZeroUsize::new(replication_factor) {
cfg.set_replication_factor(replication_factor);
} else {
println!(
log::warn!(
"Invalid config value: replication_factor must be > 0, was {:?}",
self.replication_factor
)
Expand Down
2 changes: 1 addition & 1 deletion crates/server-config/src/keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ pub fn load_key(
) -> eyre::Result<KeyPair> {
if !key_path.exists() {
return if generate_on_absence {
println!("Generating a new key to {:?}", key_path);
log::info!("Generating a new key to {:?}", key_path);
Ok(create_new_key_pair(
&key_path,
KeyFormat::from_str(&key_format)?,
Expand Down
4 changes: 3 additions & 1 deletion crates/server-config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,16 @@ mod services_config;

pub use defaults::{builtins_base_dir, *};
pub use resolved_config::load_config;
pub use resolved_config::resolve_config;
pub use resolved_config::load_config_with_args;
pub use resolved_config::ConfigData;

pub use bootstrap_config::BootstrapConfig;
pub use kademlia_config::KademliaConfig;
pub use network_config::NetworkConfig;
pub use node_config::{NodeConfig, TransportConfig};
pub use resolved_config::ConsoleConfig;
pub use resolved_config::LogConfig;
pub use resolved_config::LogFormat;
pub use resolved_config::TracingConfig;
pub use resolved_config::{ResolvedConfig, UnresolvedConfig};
pub use services_config::ServicesConfig;
Loading

0 comments on commit 6f7c684

Please sign in to comment.