Skip to content

Commit

Permalink
fix(env, log)!: RUST_LOG and other envs parsing (#1755)
Browse files Browse the repository at this point in the history
  • Loading branch information
folex committed Aug 14, 2023
1 parent da7b8b0 commit ea172c1
Show file tree
Hide file tree
Showing 9 changed files with 66 additions and 41 deletions.
60 changes: 33 additions & 27 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,32 +10,32 @@ test:
server:
WASM_LOG="trace" \
RUST_LOG="debug,\
aquamarine::aqua_runtime=off,\
ipfs_effector=off,\
ipfs_pure=off,\
system_services=debug,\
marine_core::module::marine_module=info,\
aquamarine=warn,\
tokio_threadpool=info,\
tokio_reactor=info,\
mio=info,\
tokio_io=info,\
soketto=info,\
yamux=info,\
multistream_select=info,\
libp2p_secio=info,\
libp2p_websocket::framed=info,\
libp2p_ping=info,\
libp2p_core::upgrade::apply=info,\
libp2p_kad::kbucket=info,\
cranelift_codegen=info,\
wasmer_wasi=info,\
cranelift_codegen=info,\
wasmer_wasi=info,\
run-console=trace,\
wasmtime_cranelift=off,\
wasmtime_jit=off,\
particle_reap=off" \
aquamarine::aqua_runtime=off,\
ipfs_effector=off,\
ipfs_pure=off,\
system_services=debug,\
marine_core::module::marine_module=info,\
aquamarine=warn,\
tokio_threadpool=info,\
tokio_reactor=info,\
mio=info,\
tokio_io=info,\
soketto=info,\
yamux=info,\
multistream_select=info,\
libp2p_secio=info,\
libp2p_websocket::framed=info,\
libp2p_ping=info,\
libp2p_core::upgrade::apply=info,\
libp2p_kad::kbucket=info,\
cranelift_codegen=info,\
wasmer_wasi=info,\
cranelift_codegen=info,\
wasmer_wasi=info,\
run-console=trace,\
wasmtime_cranelift=off,\
wasmtime_jit=off,\
particle_reap=off" \
cargo run --release -p nox

local-env:
Expand All @@ -50,6 +50,8 @@ local-nox:
FLUENCE_ENV_CONNECTOR_CONTRACT_ADDRESS="0xea6777e8c011E7968605fd012A9Dd49401ec386C" \
FLUENCE_ENV_CONNECTOR_FROM_BLOCK=earliest \
FLUENCE_ENV_AQUA_IPFS_LOCAL_API_MULTIADDR="/ip4/127.0.0.1/tcp/5001" \
FLUENCE_SYSTEM_SERVICES__AQUA_IPFS__IPFS_BINARY_PATH="$(shell which ipfs)" \
FLUENCE_SYSTEM_SERVICES__ENABLE="aqua-ipfs" \
WASM_LOG="trace" \
RUST_LOG="debug,\
aquamarine::aqua_runtime=error,\
Expand Down Expand Up @@ -77,7 +79,11 @@ local-nox:
run-console=trace,\
wasmtime_cranelift=off,\
wasmtime_jit=off,\
libp2p_tcp=off,\
libp2p_swarm=off,\
particle_protocol::libp2p_protocol::upgrade=info,\
libp2p_mplex=off,\
particle_reap=off" \
cargo run --release -p nox
cargo run -p nox -- --secret-key "74c9Fl8I+XFwlTRnLAyYlSML+Jk6zIkZgtQoo5deuGk="

.PHONY: server server-debug test release build deploy local-nox local-env local-env-logs
12 changes: 11 additions & 1 deletion aquamarine/src/particle_functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ use futures::future::BoxFuture;
use futures::stream::FuturesUnordered;
use futures::{FutureExt, StreamExt};
use humantime::format_duration as pretty;
use log::Level;
use serde_json::json;
use serde_json::Value as JValue;
use tokio::runtime::Handle;
Expand Down Expand Up @@ -148,7 +149,16 @@ impl<F: ParticleFunctionStatic> Functions<F> {
}
};

let log_args = format!("{:?} {:?}", args.service_id, args.function_name);
let log_args = format!("{:?} {:?} {}", args.service_id, args.function_name, {
if log::max_level() >= Level::Debug {
args.function_args
.first()
.map(|v| v.to_string())
.unwrap_or(String::new())
} else {
String::new()
}
});
let service_id = args.service_id.clone();
let start = Instant::now();

Expand Down
6 changes: 4 additions & 2 deletions crates/log-utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ fn default_directives() -> Vec<Directive> {
namespaces
.into_iter()
.map(|ns| {
ns.parse()
ns.trim()
.parse()
.unwrap_or_else(|e| panic!("cannot parse {ns} to Directive: {e}"))
})
.collect()
Expand Down Expand Up @@ -143,7 +144,8 @@ pub fn enable_logs_for(spec: LogSpec) {

let mut filter = tracing_subscriber::EnvFilter::builder()
.with_default_directive(spec.level.into())
.from_env_lossy();
.from_env()
.expect("invalid RUST_LOG");

for d in spec.directives {
filter = filter.add_directive(d);
Expand Down
9 changes: 7 additions & 2 deletions crates/server-config/src/resolved_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,11 @@ pub fn load_config_with_args(
.prefix_separator("_")
.separator("__")
.list_separator(",")
.with_list_parse_key("allowed_binaries");
.with_list_parse_key("allowed_binaries")
.with_list_parse_key("external_multiaddresses")
.with_list_parse_key("bootstrap_nodes")
.with_list_parse_key("listen_config.listen_multiaddrs")
.with_list_parse_key("system_services.enable");

let config = Config::builder()
.add_source(file_source)
Expand All @@ -221,9 +225,10 @@ pub fn load_config_with_args(

#[cfg(test)]
mod tests {
use std::io::Write;

use base64::{engine::general_purpose::STANDARD as base64, Engine};
use fluence_keypair::KeyPair;
use std::io::Write;
use tempfile::{tempdir, NamedTempFile};

use super::*;
Expand Down
4 changes: 2 additions & 2 deletions crates/system-services/src/deployer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ impl Deployer {
tracing::debug!(
spell_name,
spell_id,
"found existing spell that don't need to be updated; will not update",
"found existing spell that doesn't need to be updated; will not update",
);
Ok(ServiceStatus::Existing(spell_id))
}
Expand Down Expand Up @@ -603,7 +603,7 @@ impl Deployer {
tracing::debug!(
service_name,
service_id,
"found existing service that don't need to be updated; will skip update"
"found existing service that doesn't need to be updated; will skip update"
);
return Ok(ServiceStatus::Existing(service_id));
}
Expand Down
3 changes: 2 additions & 1 deletion nox/src/behaviour/identify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,11 @@ impl FluenceNetworkBehaviour {
}

if supports_fluence {
let protocols = info.protocols.iter().map(|p| p.to_string());
log::debug!(
target: "network",
"Found fluence peer {}: protocols: {:?} version: {} listen addrs {:?}",
peer_id, info.protocols, info.protocol_version, addresses
peer_id, protocols, info.protocol_version, addresses
);
// Add addresses to connection pool disregarding whether it supports kademlia or not
// we want to have full info on non-kademlia peers as well
Expand Down
6 changes: 5 additions & 1 deletion nox/src/layers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,13 @@ pub fn log_layer<S>(log_config: &Option<LogConfig>) -> impl Layer<S>
where
S: Subscriber + for<'span> LookupSpan<'span>,
{
let rust_log = std::env::var("RUST_LOG")
.unwrap_or_default()
.replace(char::is_whitespace, "");

let env_filter = tracing_subscriber::EnvFilter::builder()
.with_default_directive(LevelFilter::INFO.into())
.from_env_lossy()
.parse_lossy(rust_log)
.add_directive("cranelift_codegen=off".parse().unwrap())
.add_directive("walrus=off".parse().unwrap())
.add_directive("polling=off".parse().unwrap())
Expand Down
3 changes: 0 additions & 3 deletions nox/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ use tokio::signal;
use tokio::sync::oneshot;
use tracing_subscriber::layer::SubscriberExt;
use tracing_subscriber::util::SubscriberInitExt;
use tracing_subscriber::EnvFilter;

use air_interpreter_fs::write_default_air_interpreter;
use aquamarine::{VmConfig, AVM};
Expand Down Expand Up @@ -96,8 +95,6 @@ fn main() -> eyre::Result<()> {
.expect("Could not make tokio runtime")
.block_on(async {
tracing_subscriber::registry()
//takes log levels from env variable RUST_LOG
.with(EnvFilter::from_default_env())
.with(log_layer(&config.log))
.with(tokio_console_layer(&config.console)?)
.with(tracing_layer(&config.tracing)?)
Expand Down
4 changes: 2 additions & 2 deletions sorcerer/src/spell_builtins.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ pub(crate) async fn spell_install(
let mut args = sargs.function_args.clone().into_iter();
let script: String = Args::next("script", &mut args)?;
let init_data: JValue = Args::next("data", &mut args)?;
let user_config: TriggerConfig = Args::next("config", &mut args)?;
let trigger_config: TriggerConfig = Args::next("trigger_config", &mut args)?;
let init_peer_id = params.init_peer_id;

let is_management = key_manager.is_management(init_peer_id);
Expand All @@ -235,7 +235,7 @@ pub(crate) async fn spell_install(
worker_id,
params.id,
params.ttl as u64,
user_config,
trigger_config,
script,
init_data,
)
Expand Down

0 comments on commit ea172c1

Please sign in to comment.