Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(config): print config [fixes NET-796] #2161

Merged
merged 14 commits into from
Mar 12, 2024
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
231 changes: 41 additions & 190 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -149,11 +149,11 @@ maplit = "1.0.2"
log = "0.4.20"
tracing = { version = "0.1.40", default-features = false, features = ["log"] }
tracing-subscriber = "0.3.18"
console-subscriber = "0.2.0"
futures = "0.3.30"
thiserror = "1.0.56"
serde = "1.0.196"
toml = "0.5.11"
toml_edit = "0.22.6"
itertools = "0.12.1"
humantime-serde = "1.1.1"
cid = "0.11.0"
Expand Down
1 change: 0 additions & 1 deletion aquamarine/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ edition = "2021"
[dependencies]
particle-protocol = { workspace = true }
particle-services = { workspace = true }
particle-builtins = { workspace = true }

now-millis = { workspace = true }
fluence-libp2p = { workspace = true }
Expand Down
4 changes: 2 additions & 2 deletions aquamarine/src/plumber.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,10 +239,10 @@ impl<RT: AquaRuntime, F: ParticleFunctionStatic> Plumber<RT, F> {
}
}

fn create_actor<'p, 'a>(
fn create_actor<'p>(
actors: &'p mut HashMap<ActorKey, Actor<RT, F>>,
plumber_params: PlumberParams<'p, F>,
actor_params: ActorParams<'a>,
actor_params: ActorParams<'_>,
) -> eyre::Result<&'p mut Actor<RT, F>> {
let entry = actors.entry(actor_params.key);
let actor = match entry {
Expand Down
1 change: 0 additions & 1 deletion connection-pool/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ serde = { workspace = true }
tokio = { workspace = true }
tokio-stream = { workspace = true }
tokio-util = {workspace = true }
itertools = { workspace = true }

[dev-dependencies]
parking_lot = { workspace = true }
2 changes: 0 additions & 2 deletions crates/chain-listener/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ types = { workspace = true }
libipld = "0.16.0"

fluence-libp2p = { workspace = true }
tempfile = { workspace = true }
fs-utils = { workspace = true }
log-utils = { workspace = true }
futures = { workspace = true }
core-manager = { workspace = true }
ccp-rpc-client = { workspace = true }
Expand Down
1 change: 0 additions & 1 deletion crates/cid-utils/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ edition = "2021"
serde = { workspace = true }
libipld = "0.16.0"
bytes = "1.5.0"
base64 = { workspace = true }
quick-protobuf = "0.8.1"
eyre = { workspace = true }

Expand Down
2 changes: 0 additions & 2 deletions crates/core-manager/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ num_cpus.workspace = true
parking_lot.workspace = true
thiserror.workspace = true
serde = { workspace = true, features = ["derive"] }
types.workspace = true
tracing.workspace = true
serde_with.workspace = true
tokio-stream.workspace = true
futures.workspace = true
rand = "0.8.5"
Expand Down
1 change: 0 additions & 1 deletion crates/fs-utils/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ version = "0.1.0"
edition = "2021"

[dependencies]
rand = { workspace = true }
eyre = { workspace = true }
tokio = { workspace = true, features = ["fs"] }
tokio-stream = { workspace = true, features = ["fs"] }
Expand Down
1 change: 0 additions & 1 deletion crates/json-utils/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,3 @@ edition = "2021"
serde = { workspace = true }
serde_json = { workspace = true }
base64 = { workspace = true }
itertools = { workspace = true }
2 changes: 0 additions & 2 deletions crates/kademlia/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ libp2p-metrics = { workspace = true, features = ["kad"] }
prometheus-client = { workspace = true }
multihash = { workspace = true }
once_cell = { workspace = true }

prost = "0.12.3"
smallvec = "1.13.1"
serde_json = { workspace = true }
log = { workspace = true }
Expand Down
5 changes: 1 addition & 4 deletions crates/libp2p/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,10 @@ futures = { workspace = true }
futures-util = { workspace = true }
tokio = { workspace = true, optional = true }
serde = { workspace = true, features = ["derive"] }
serde_json = { workspace = true }
bs58 = { workspace = true }

failure = "0.1.8"
base64 = { workspace = true }
log = { workspace = true }
rand = { workspace = true }

[dev-dependencies]
rand = { workspace = true }
serde_json = { workspace = true }
5 changes: 0 additions & 5 deletions crates/local-vm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ authors = ["Fluence Labs"]
edition = "2021"

[dependencies]
ivalue-utils = { workspace = true }
particle-args = { workspace = true }
particle-protocol = { workspace = true }
particle-execution = { workspace = true }
Expand All @@ -15,13 +14,9 @@ fs-utils = { workspace = true }
aquamarine = { workspace = true }
air-interpreter-fs = { workspace = true }
fluence-keypair = { workspace = true }
tempfile = { workspace = true }

air-interpreter-wasm = { workspace = true }
avm-server = { workspace = true }

libp2p = { workspace = true }

fstrings = { workspace = true }
serde_json = { workspace = true }
parking_lot = { workspace = true }
Expand Down
2 changes: 0 additions & 2 deletions crates/log-utils/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,3 @@ edition = "2021"
log = { workspace = true }
tracing = { workspace = true, features = ["async-await", "log"] }
tracing-subscriber = { workspace = true, features = ["parking_lot", "env-filter"] }
console-subscriber = { workspace = true, features = ["parking_lot"] }
tracing-logfmt = "0.3.3"
4 changes: 0 additions & 4 deletions crates/log-utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,6 @@ pub fn enable_logs() {
enable_logs_for(LogSpec::default())
}

pub fn enable_console() {
console_subscriber::init();
}

pub struct LogSpec {
level: tracing::metadata::Level,
directives: Vec<Directive>,
Expand Down
3 changes: 0 additions & 3 deletions crates/particle-args/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,9 @@ authors = ["Fluence Labs"]
edition = "2021"

[dependencies]
ivalue-utils = { workspace = true }
json-utils = { workspace = true }
control-macro = { workspace = true }

avm-server = { workspace = true }

serde_json = { workspace = true }
serde = { workspace = true }
bs58 = { workspace = true }
Expand Down
1 change: 1 addition & 0 deletions crates/server-config/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ serde_with = { workspace = true }
config = { version = "0.13.4", default-features = false, features = ["toml"] }
clarity = { workspace = true }
maplit = { workspace = true }
url = { version = "2.4.1", features = ["serde"] }

[dev-dependencies]
temp-env = "0.3.6"
Expand Down
16 changes: 0 additions & 16 deletions crates/server-config/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
*/

use crate::system_services_config::ServiceKey;
use crate::LogFormat;
use clap::error::ErrorKind;
use clap::{Args, Parser};
use config::{ConfigError, Map, Source, Value};
Expand Down Expand Up @@ -108,18 +107,6 @@ impl Serialize for RootKeyPairArgs {
}
}

#[derive(Args, Debug, Clone, Serialize)]
pub struct LogArgs {
#[arg(
long("log-format"),
id = "LOG_FORMAT",
help = "logging format",
help_heading = "Node configuration",
display_order = 24
)]
pub format: Option<LogFormat>,
}

#[derive(Args, Debug, Clone, Serialize)]
pub struct TracingArgs {
#[arg(
Expand Down Expand Up @@ -448,9 +435,6 @@ pub(crate) struct DerivedArgs {
#[command(flatten)]
system_services: Option<SystemServicesArgs>,

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

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

Expand Down
3 changes: 0 additions & 3 deletions crates/server-config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,6 @@ pub use bootstrap_config::BootstrapConfig;
pub use kademlia_config::KademliaConfig;
pub use network_config::NetworkConfig;
pub use node_config::{ChainConfig, ChainListenerConfig, 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;
Expand Down
96 changes: 11 additions & 85 deletions crates/server-config/src/resolved_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ use std::ffi::OsString;
use std::net::SocketAddr;
use std::ops::{Deref, DerefMut};
use std::path::PathBuf;
use std::str::FromStr;

use clap::{Args, Command, FromArgMatches};
use config::{Config, Environment, File, FileFormat, FileSourceFile};
use libp2p::core::{multiaddr::Protocol, Multiaddr};
use serde::{Deserialize, Serialize};
use url::Url;

use crate::args;
use crate::args::DerivedArgs;
Expand All @@ -34,13 +34,14 @@ use crate::node_config::{NodeConfig, UnresolvedNodeConfig};
pub struct UnresolvedConfig {
#[serde(flatten)]
dir_config: UnresolvedDirConfig,

#[serde(flatten)]
pub node_config: UnresolvedNodeConfig,

pub log: Option<LogConfig>,
pub tracing: Option<TracingConfig>,
pub console: Option<ConsoleConfig>,

pub no_banner: Option<bool>,

pub print_config: Option<bool>,
}

Expand All @@ -56,30 +57,6 @@ impl UnresolvedConfig {
}
}

#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct LogConfig {
pub format: LogFormat,
}

#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
#[serde(rename_all = "lowercase")]
pub enum LogFormat {
Logfmt,
Default,
}

impl FromStr for LogFormat {
type Err = String;

fn from_str(s: &str) -> Result<Self, Self::Err> {
match s.trim().to_ascii_lowercase().as_str() {
"logfmt" => Ok(LogFormat::Logfmt),
"default" => Ok(LogFormat::Default),
_ => Err("Unsupported log format".to_string()),
}
}
}

#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
#[serde(tag = "type")]
pub enum TracingConfig {
Expand All @@ -89,20 +66,11 @@ pub enum TracingConfig {
Stdout,
#[serde(rename = "otlp")]
Otlp {
endpoint: String,
endpoint: Url,
sample_ratio: Option<f64>,
},
}

#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
#[serde(tag = "type")]
pub enum ConsoleConfig {
#[serde(rename = "disabled")]
Disabled,
#[serde(rename = "enabled")]
Enabled { bind: String },
}

#[derive(Clone, Debug)]
pub struct ResolvedConfig {
pub dir_config: ResolvedDirConfig,
Expand Down Expand Up @@ -567,48 +535,6 @@ mod tests {
});
}

#[test]
fn load_log_format_with_env() {
temp_env::with_var("FLUENCE_LOG__FORMAT", Some("logfmt"), || {
let config = load_config_with_args(vec![], None).expect("Could not load config");
let log_fmt = config.log.map(|x| x.format);
assert_eq!(log_fmt, Some(LogFormat::Logfmt));
});
}

#[test]
fn load_log_format_with_args() {
let args = vec![
OsString::from("nox"),
OsString::from("--log-format"),
OsString::from("logfmt"),
];
let config = load_config_with_args(args, None).expect("Could not load config");
let log_fmt = config.log.map(|x| x.format);
assert_eq!(log_fmt, Some(LogFormat::Logfmt));
}

#[test]
fn load_log_format_with_file() {
let mut file = NamedTempFile::new().expect("Could not create temp file");
write!(
file,
r#"
[log]
format = "logfmt"
"#
)
.expect("Could not write in file");

let path = file.path().display().to_string();

temp_env::with_var("FLUENCE_CONFIG", Some(path), || {
let config = load_config_with_args(vec![], None).expect("Could not load config");
let log_fmt = config.log.map(|x| x.format);
assert_eq!(log_fmt, Some(LogFormat::Logfmt));
});
}

#[test]
fn load_allowed_binaries_with_file() {
let mut file = NamedTempFile::new().expect("Could not create temp file");
Expand Down Expand Up @@ -659,7 +585,7 @@ mod tests {
r#"
[tracing]
type = "otlp"
endpoint = "test"
endpoint = "grpc://10.10.10.10:122"
sample_ratio = 0.1
"#
)
Expand All @@ -672,7 +598,7 @@ mod tests {
assert_eq!(
config.tracing,
Some(TracingConfig::Otlp {
endpoint: "test".to_string(),
endpoint: Url::parse("grpc://10.10.10.10:122").unwrap(),
sample_ratio: Some(0.1)
})
);
Expand All @@ -692,14 +618,14 @@ mod tests {
temp_env::with_vars(
[
("FLUENCE_TRACING__TYPE", Some("otlp")),
("FLUENCE_TRACING__ENDPOINT", Some("test")),
("FLUENCE_TRACING__ENDPOINT", Some("grpc://10.10.10.10:122")),
],
|| {
let config = load_config_with_args(vec![], None).expect("Could not load config");
assert_eq!(
config.tracing,
Some(TracingConfig::Otlp {
endpoint: "test".to_string(),
endpoint: Url::parse("grpc://10.10.10.10:122").unwrap(),
sample_ratio: None
})
);
Expand Down Expand Up @@ -734,13 +660,13 @@ mod tests {
OsString::from("--tracing-type"),
OsString::from("otlp"),
OsString::from("--tracing-otlp-endpoint"),
OsString::from("test"),
OsString::from("grpc://10.10.10.10:122"),
];
let config = load_config_with_args(args, None).expect("Could not load config");
assert_eq!(
config.tracing,
Some(TracingConfig::Otlp {
endpoint: "test".to_string(),
endpoint: Url::parse("grpc://10.10.10.10:122").unwrap(),
sample_ratio: None
})
);
Expand Down
Loading
Loading