diff --git a/commons/zenoh-config/src/lib.rs b/commons/zenoh-config/src/lib.rs index e2713104c6..aa1a536347 100644 --- a/commons/zenoh-config/src/lib.rs +++ b/commons/zenoh-config/src/lib.rs @@ -1050,6 +1050,7 @@ fn load_external_plugin_config(title: &str, value: &mut Value) -> ZResult<()> { #[derive(Debug, Clone)] pub struct PluginLoad { + pub id: String, pub name: String, pub paths: Option>, pub required: bool, @@ -1068,22 +1069,27 @@ impl PluginsConfig { Ok(()) } pub fn load_requests(&'_ self) -> impl Iterator + '_ { - self.values.as_object().unwrap().iter().map(|(name, value)| { + self.values.as_object().unwrap().iter().map(|(id, value)| { let value = value.as_object().expect("Plugin configurations must be objects"); let required = match value.get("__required__") { None => false, Some(Value::Bool(b)) => *b, - _ => panic!("Plugin '{}' has an invalid '__required__' configuration property (must be a boolean)", name) + _ => panic!("Plugin '{}' has an invalid '__required__' configuration property (must be a boolean)", id) }; + let name = match value.get("__plugin__") { + Some(Value::String(p)) => p, + _ => id, + }; + if let Some(paths) = value.get("__path__"){ let paths = match paths { Value::String(s) => vec![s.clone()], - Value::Array(a) => a.iter().map(|s| if let Value::String(s) = s {s.clone()} else {panic!("Plugin '{}' has an invalid '__path__' configuration property (must be either string or array of strings)", name)}).collect(), - _ => panic!("Plugin '{}' has an invalid '__path__' configuration property (must be either string or array of strings)", name) + Value::Array(a) => a.iter().map(|s| if let Value::String(s) = s {s.clone()} else {panic!("Plugin '{}' has an invalid '__path__' configuration property (must be either string or array of strings)", id)}).collect(), + _ => panic!("Plugin '{}' has an invalid '__path__' configuration property (must be either string or array of strings)", id) }; - PluginLoad {name: name.clone(), paths: Some(paths), required} + PluginLoad {id: id.clone(), name: name.clone(), paths: Some(paths), required} } else { - PluginLoad {name: name.clone(), paths: None, required} + PluginLoad {id: id.clone(), name: name.clone(), paths: None, required} } }) } diff --git a/commons/zenoh-core/src/lib.rs b/commons/zenoh-core/src/lib.rs index 8d6fbfcc0a..434d0e6740 100644 --- a/commons/zenoh-core/src/lib.rs +++ b/commons/zenoh-core/src/lib.rs @@ -58,8 +58,12 @@ pub trait Wait: Resolvable { pub trait AsyncResolve: Resolvable { type Future: Future + Send; + #[allow(deprecated)] + #[deprecated = "use `.await` directly instead"] fn res_async(self) -> Self::Future; + #[allow(deprecated)] + #[deprecated = "use `.wait()` instead`"] fn res(self) -> Self::Future where Self: Sized, @@ -83,8 +87,11 @@ where #[deprecated = "use `.wait()` instead`"] pub trait SyncResolve: Resolvable { + #[deprecated = "use `.wait()` instead`"] fn res_sync(self) -> Self::To; + #[allow(deprecated)] + #[deprecated = "use `.wait()` instead`"] fn res(self) -> Self::To where Self: Sized, diff --git a/commons/zenoh-util/src/std_only/log.rs b/commons/zenoh-util/src/std_only/log.rs index 07d66d9233..d9498b9cb3 100644 --- a/commons/zenoh-util/src/std_only/log.rs +++ b/commons/zenoh-util/src/std_only/log.rs @@ -11,9 +11,16 @@ // Contributors: // ZettaScale Zenoh Team, // -use tracing_subscriber::EnvFilter; +use std::{fmt, thread, thread::ThreadId}; -/// This is an utility function to enable the tracing formatting subscriber from +use tracing::{field::Field, span, Event, Subscriber}; +use tracing_subscriber::{ + layer::{Context, SubscriberExt}, + registry::LookupSpan, + EnvFilter, +}; + +/// This is a utility function to enable the tracing formatting subscriber from /// the `RUST_LOG` environment variable. If `RUST_LOG` is not set, then logging is not enabled. /// /// # Safety @@ -27,7 +34,7 @@ pub fn try_init_log_from_env() { } } -/// This is an utility function to enable the tracing formatting subscriber from +/// This is a utility function to enable the tracing formatting subscriber from /// the environment variable. If `RUST_LOG` is not set, then fallback directives are used. /// /// # Safety @@ -55,6 +62,79 @@ fn init_env_filter(env_filter: EnvFilter) { let _ = tracing::subscriber::set_global_default(subscriber); } +pub struct LogRecord { + pub target: String, + pub level: tracing::Level, + pub file: Option<&'static str>, + pub line: Option, + pub thread_id: ThreadId, + pub thread_name: Option, + pub message: Option, + pub attributes: Vec<(&'static str, String)>, +} + +#[derive(Clone)] +struct SpanFields(Vec<(&'static str, String)>); + +struct Layer(F); + +impl tracing_subscriber::Layer for Layer +where + S: Subscriber + for<'a> LookupSpan<'a>, + F: Fn(LogRecord) + 'static, +{ + fn on_new_span(&self, attrs: &span::Attributes<'_>, id: &span::Id, ctx: Context<'_, S>) { + let span = ctx.span(id).unwrap(); + let mut extensions = span.extensions_mut(); + let mut fields = vec![]; + attrs.record(&mut |field: &Field, value: &dyn fmt::Debug| { + fields.push((field.name(), format!("{value:?}"))) + }); + extensions.insert(SpanFields(fields)); + } + fn on_record(&self, id: &span::Id, values: &span::Record<'_>, ctx: Context<'_, S>) { + let span = ctx.span(id).unwrap(); + let mut extensions = span.extensions_mut(); + let fields = extensions.get_mut::().unwrap(); + values.record(&mut |field: &Field, value: &dyn fmt::Debug| { + fields.0.push((field.name(), format!("{value:?}"))) + }); + } + fn on_event(&self, event: &Event<'_>, ctx: Context<'_, S>) { + let thread = thread::current(); + let mut record = LogRecord { + target: event.metadata().target().into(), + level: *event.metadata().level(), + file: event.metadata().file(), + line: event.metadata().line(), + thread_id: thread.id(), + thread_name: thread.name().map(Into::into), + message: None, + attributes: vec![], + }; + if let Some(scope) = ctx.event_scope(event) { + for span in scope.from_root() { + let extensions = span.extensions(); + let fields = extensions.get::().unwrap(); + record.attributes.extend(fields.0.iter().cloned()); + } + } + event.record(&mut |field: &Field, value: &dyn fmt::Debug| { + if field.name() == "message" { + record.message = Some(format!("{value:?}")); + } else { + record.attributes.push((field.name(), format!("{value:?}"))) + } + }); + self.0(record); + } +} + +pub fn init_log_with_callback(cb: impl Fn(LogRecord) + Send + Sync + 'static) { + let subscriber = tracing_subscriber::registry().with(Layer(cb)); + let _ = tracing::subscriber::set_global_default(subscriber); +} + #[cfg(feature = "test")] // Used to verify memory leaks for valgrind CI. // `EnvFilter` internally uses a static reference that is not cleaned up yielding to false positive in valgrind. diff --git a/examples/examples/z_alloc_shm.rs b/examples/examples/z_alloc_shm.rs index abdbb2e443..4423e0b07a 100644 --- a/examples/examples/z_alloc_shm.rs +++ b/examples/examples/z_alloc_shm.rs @@ -23,7 +23,7 @@ use zenoh::{ #[tokio::main] async fn main() { // Initiate logging - zenoh_util::try_init_log_from_env(); + zenoh::try_init_log_from_env(); run().await.unwrap() } diff --git a/examples/examples/z_delete.rs b/examples/examples/z_delete.rs index 294d1b850a..090aadac48 100644 --- a/examples/examples/z_delete.rs +++ b/examples/examples/z_delete.rs @@ -18,7 +18,7 @@ use zenoh_examples::CommonArgs; #[tokio::main] async fn main() { // initiate logging - zenoh_util::try_init_log_from_env(); + zenoh::try_init_log_from_env(); let (config, key_expr) = parse_args(); diff --git a/examples/examples/z_forward.rs b/examples/examples/z_forward.rs index deb82a2a7f..be9df7e2b0 100644 --- a/examples/examples/z_forward.rs +++ b/examples/examples/z_forward.rs @@ -19,7 +19,7 @@ use zenoh_ext::SubscriberForward; #[tokio::main] async fn main() { // Initiate logging - zenoh_util::try_init_log_from_env(); + zenoh::try_init_log_from_env(); let (config, key_expr, forward) = parse_args(); diff --git a/examples/examples/z_get.rs b/examples/examples/z_get.rs index e04fc8bcf6..d4fc416f9c 100644 --- a/examples/examples/z_get.rs +++ b/examples/examples/z_get.rs @@ -20,7 +20,7 @@ use zenoh_examples::CommonArgs; #[tokio::main] async fn main() { // initiate logging - zenoh_util::try_init_log_from_env(); + zenoh::try_init_log_from_env(); let (config, selector, value, target, timeout) = parse_args(); diff --git a/examples/examples/z_get_liveliness.rs b/examples/examples/z_get_liveliness.rs index 150308aea4..53f7abc92a 100644 --- a/examples/examples/z_get_liveliness.rs +++ b/examples/examples/z_get_liveliness.rs @@ -20,7 +20,7 @@ use zenoh_examples::CommonArgs; #[tokio::main] async fn main() { // initiate logging - zenoh_util::try_init_log_from_env(); + zenoh::try_init_log_from_env(); let (config, key_expr, timeout) = parse_args(); diff --git a/examples/examples/z_get_shm.rs b/examples/examples/z_get_shm.rs index bfb9213ab5..942ec0e34e 100644 --- a/examples/examples/z_get_shm.rs +++ b/examples/examples/z_get_shm.rs @@ -31,7 +31,7 @@ const N: usize = 10; #[tokio::main] async fn main() { // initiate logging - zenoh_util::try_init_log_from_env(); + zenoh::try_init_log_from_env(); let (mut config, selector, mut value, target, timeout) = parse_args(); diff --git a/examples/examples/z_info.rs b/examples/examples/z_info.rs index 281532e236..9d3f1bb223 100644 --- a/examples/examples/z_info.rs +++ b/examples/examples/z_info.rs @@ -18,7 +18,7 @@ use zenoh_examples::CommonArgs; #[tokio::main] async fn main() { // initiate logging - zenoh_util::try_init_log_from_env(); + zenoh::try_init_log_from_env(); let config = parse_args(); diff --git a/examples/examples/z_liveliness.rs b/examples/examples/z_liveliness.rs index 71b1fe4e4e..7bc8e857fe 100644 --- a/examples/examples/z_liveliness.rs +++ b/examples/examples/z_liveliness.rs @@ -18,7 +18,7 @@ use zenoh_examples::CommonArgs; #[tokio::main] async fn main() { // Initiate logging - zenoh_util::try_init_log_from_env(); + zenoh::try_init_log_from_env(); let (config, key_expr) = parse_args(); diff --git a/examples/examples/z_ping.rs b/examples/examples/z_ping.rs index 56ba47b7f5..96454da614 100644 --- a/examples/examples/z_ping.rs +++ b/examples/examples/z_ping.rs @@ -19,7 +19,7 @@ use zenoh_examples::CommonArgs; fn main() { // initiate logging - zenoh_util::try_init_log_from_env(); + zenoh::try_init_log_from_env(); let (config, warmup, size, n, express) = parse_args(); let session = zenoh::open(config).wait().unwrap(); diff --git a/examples/examples/z_ping_shm.rs b/examples/examples/z_ping_shm.rs index 20d2c0f540..c0cc20127d 100644 --- a/examples/examples/z_ping_shm.rs +++ b/examples/examples/z_ping_shm.rs @@ -26,7 +26,7 @@ use zenoh_examples::CommonArgs; fn main() { // Initiate logging - zenoh_util::try_init_log_from_env(); + zenoh::try_init_log_from_env(); let (mut config, warmup, size, n) = parse_args(); diff --git a/examples/examples/z_pong.rs b/examples/examples/z_pong.rs index ecf2aa1643..6a1b8580c7 100644 --- a/examples/examples/z_pong.rs +++ b/examples/examples/z_pong.rs @@ -17,7 +17,7 @@ use zenoh_examples::CommonArgs; fn main() { // initiate logging - zenoh_util::try_init_log_from_env(); + zenoh::try_init_log_from_env(); let (mut config, express) = parse_args(); diff --git a/examples/examples/z_pub.rs b/examples/examples/z_pub.rs index 6812246cfa..74a9c2898e 100644 --- a/examples/examples/z_pub.rs +++ b/examples/examples/z_pub.rs @@ -20,7 +20,7 @@ use zenoh_examples::CommonArgs; #[tokio::main] async fn main() { // Initiate logging - zenoh_util::try_init_log_from_env(); + zenoh::try_init_log_from_env(); let (config, key_expr, value, attachment) = parse_args(); diff --git a/examples/examples/z_pub_shm.rs b/examples/examples/z_pub_shm.rs index 93ce1df553..9c4e64c496 100644 --- a/examples/examples/z_pub_shm.rs +++ b/examples/examples/z_pub_shm.rs @@ -28,7 +28,7 @@ const N: usize = 10; #[tokio::main] async fn main() -> Result<(), ZError> { // Initiate logging - zenoh_util::try_init_log_from_env(); + zenoh::try_init_log_from_env(); let (mut config, path, value) = parse_args(); diff --git a/examples/examples/z_pub_shm_thr.rs b/examples/examples/z_pub_shm_thr.rs index 35e6b81441..fca2994d33 100644 --- a/examples/examples/z_pub_shm_thr.rs +++ b/examples/examples/z_pub_shm_thr.rs @@ -24,7 +24,7 @@ use zenoh_examples::CommonArgs; #[tokio::main] async fn main() { // initiate logging - zenoh_util::try_init_log_from_env(); + zenoh::try_init_log_from_env(); let (mut config, sm_size, size) = parse_args(); // A probing procedure for shared memory is performed upon session opening. To enable `z_pub_shm_thr` to operate diff --git a/examples/examples/z_pub_thr.rs b/examples/examples/z_pub_thr.rs index 817d0ee0d1..359e375203 100644 --- a/examples/examples/z_pub_thr.rs +++ b/examples/examples/z_pub_thr.rs @@ -20,7 +20,7 @@ use zenoh_examples::CommonArgs; fn main() { // initiate logging - zenoh_util::try_init_log_from_env(); + zenoh::try_init_log_from_env(); let args = Args::parse(); let mut prio = Priority::DEFAULT; diff --git a/examples/examples/z_pull.rs b/examples/examples/z_pull.rs index 3127e76c14..6716ef8cc5 100644 --- a/examples/examples/z_pull.rs +++ b/examples/examples/z_pull.rs @@ -20,7 +20,7 @@ use zenoh_examples::CommonArgs; #[tokio::main] async fn main() { // initiate logging - zenoh_util::try_init_log_from_env(); + zenoh::try_init_log_from_env(); let (config, key_expr, size, interval) = parse_args(); diff --git a/examples/examples/z_put.rs b/examples/examples/z_put.rs index f56fbf2c8c..4fb6e0ca2a 100644 --- a/examples/examples/z_put.rs +++ b/examples/examples/z_put.rs @@ -18,7 +18,7 @@ use zenoh_examples::CommonArgs; #[tokio::main] async fn main() { // initiate logging - zenoh_util::try_init_log_from_env(); + zenoh::try_init_log_from_env(); let (config, key_expr, value) = parse_args(); diff --git a/examples/examples/z_put_float.rs b/examples/examples/z_put_float.rs index 234579b8d5..89100b3731 100644 --- a/examples/examples/z_put_float.rs +++ b/examples/examples/z_put_float.rs @@ -18,7 +18,7 @@ use zenoh_examples::CommonArgs; #[tokio::main] async fn main() { // initiate logging - zenoh_util::try_init_log_from_env(); + zenoh::try_init_log_from_env(); let (config, key_expr, value) = parse_args(); diff --git a/examples/examples/z_queryable.rs b/examples/examples/z_queryable.rs index eb950766ab..ede3eff635 100644 --- a/examples/examples/z_queryable.rs +++ b/examples/examples/z_queryable.rs @@ -18,7 +18,7 @@ use zenoh_examples::CommonArgs; #[tokio::main] async fn main() { // initiate logging - zenoh_util::try_init_log_from_env(); + zenoh::try_init_log_from_env(); let (mut config, key_expr, value, complete) = parse_args(); diff --git a/examples/examples/z_queryable_shm.rs b/examples/examples/z_queryable_shm.rs index 5cc8e301d3..ec2058c897 100644 --- a/examples/examples/z_queryable_shm.rs +++ b/examples/examples/z_queryable_shm.rs @@ -28,7 +28,7 @@ const N: usize = 10; #[tokio::main] async fn main() { // initiate logging - zenoh_util::try_init_log_from_env(); + zenoh::try_init_log_from_env(); let (mut config, key_expr, value, complete) = parse_args(); diff --git a/examples/examples/z_scout.rs b/examples/examples/z_scout.rs index f099beae46..1d485991fd 100644 --- a/examples/examples/z_scout.rs +++ b/examples/examples/z_scout.rs @@ -16,7 +16,7 @@ use zenoh::{config::WhatAmI, scout, Config}; #[tokio::main] async fn main() { // initiate logging - zenoh_util::try_init_log_from_env(); + zenoh::try_init_log_from_env(); println!("Scouting..."); let receiver = scout(WhatAmI::Peer | WhatAmI::Router, Config::default()) diff --git a/examples/examples/z_storage.rs b/examples/examples/z_storage.rs index 86d73da2bb..83a2dee66d 100644 --- a/examples/examples/z_storage.rs +++ b/examples/examples/z_storage.rs @@ -28,7 +28,7 @@ use zenoh_examples::CommonArgs; #[tokio::main] async fn main() { // initiate logging - zenoh_util::try_init_log_from_env(); + zenoh::try_init_log_from_env(); let (config, key_expr, complete) = parse_args(); diff --git a/examples/examples/z_sub.rs b/examples/examples/z_sub.rs index 95cd5f8988..47432cf9cb 100644 --- a/examples/examples/z_sub.rs +++ b/examples/examples/z_sub.rs @@ -18,7 +18,7 @@ use zenoh_examples::CommonArgs; #[tokio::main] async fn main() { // Initiate logging - zenoh_util::try_init_log_from_env(); + zenoh::try_init_log_from_env(); let (mut config, key_expr) = parse_args(); diff --git a/examples/examples/z_sub_liveliness.rs b/examples/examples/z_sub_liveliness.rs index 86420381e1..bb91c9f491 100644 --- a/examples/examples/z_sub_liveliness.rs +++ b/examples/examples/z_sub_liveliness.rs @@ -18,7 +18,7 @@ use zenoh_examples::CommonArgs; #[tokio::main] async fn main() { // Initiate logging - zenoh_util::try_init_log_from_env(); + zenoh::try_init_log_from_env(); let (config, key_expr) = parse_args(); diff --git a/examples/examples/z_sub_shm.rs b/examples/examples/z_sub_shm.rs index 04ba8e9753..4cc797d8b4 100644 --- a/examples/examples/z_sub_shm.rs +++ b/examples/examples/z_sub_shm.rs @@ -18,7 +18,7 @@ use zenoh_examples::CommonArgs; #[tokio::main] async fn main() { // Initiate logging - zenoh_util::try_init_log_from_env(); + zenoh::try_init_log_from_env(); let (mut config, key_expr) = parse_args(); diff --git a/examples/examples/z_sub_thr.rs b/examples/examples/z_sub_thr.rs index bee15ada2b..0e9f53f36b 100644 --- a/examples/examples/z_sub_thr.rs +++ b/examples/examples/z_sub_thr.rs @@ -69,7 +69,7 @@ impl Drop for Stats { fn main() { // initiate logging - zenoh_util::try_init_log_from_env(); + zenoh::try_init_log_from_env(); let (mut config, m, n) = parse_args(); diff --git a/io/zenoh-links/zenoh-link-udp/src/lib.rs b/io/zenoh-links/zenoh-link-udp/src/lib.rs index c89708fe5d..0e3a5f26dc 100644 --- a/io/zenoh-links/zenoh-link-udp/src/lib.rs +++ b/io/zenoh-links/zenoh-link-udp/src/lib.rs @@ -41,14 +41,16 @@ use zenoh_result::{zerror, ZResult}; // $ sysctl -w net.core.rmem_max=4194304 // $ sysctl -w net.core.rmem_default=4194304 -// Maximum MTU (UDP PDU) in bytes. -// NOTE: The UDP field size sets a theoretical limit of 65,535 bytes (8 byte header + 65,527 bytes of -// data) for a UDP datagram. However the actual limit for the data length, which is imposed by -// the underlying IPv4 protocol, is 65,507 bytes (65,535 − 8 byte UDP header − 20 byte IP header). -// Although in IPv6 it is possible to have UDP datagrams of size greater than 65,535 bytes via -// IPv6 Jumbograms, its usage in Zenoh is discouraged unless the consequences are very well -// understood. -const UDP_MAX_MTU: BatchSize = 65_507; +/// Maximum MTU (UDP PDU) in bytes. +/// +/// # Note +/// +/// The theoretical Maximum Transmission Unit (MTU) of UDP is `u16::MAX`. From that we substract the +/// size of a UDP header (8 bytes) and the size of IPv4/IPv6 headers (resp. 20 and 40 bytes). +/// +/// Although in IPv6 it is possible to have UDP datagrams of size greater than 65,535 bytes via IPv6 +/// Jumbograms, its usage in Zenoh is discouraged unless the consequences are very well understood. +const UDP_MAX_MTU: BatchSize = u16::MAX - 8 - 40; pub const UDP_LOCATOR_PREFIX: &str = "udp"; diff --git a/plugins/zenoh-plugin-rest/src/config.rs b/plugins/zenoh-plugin-rest/src/config.rs index 719dc79fbf..a785eec094 100644 --- a/plugins/zenoh-plugin-rest/src/config.rs +++ b/plugins/zenoh-plugin-rest/src/config.rs @@ -31,6 +31,7 @@ pub struct Config { __path__: Option>, __required__: Option, __config__: Option, + __plugin__: Option, } impl From<&Config> for serde_json::Value { diff --git a/plugins/zenoh-plugin-storage-manager/src/lib.rs b/plugins/zenoh-plugin-storage-manager/src/lib.rs index 26cd58a093..027fd0af91 100644 --- a/plugins/zenoh-plugin-storage-manager/src/lib.rs +++ b/plugins/zenoh-plugin-storage-manager/src/lib.rs @@ -113,8 +113,9 @@ impl StorageRuntimeInner { .map(|search_dirs| LibLoader::new(&search_dirs, false)) .unwrap_or_default(); - let plugins_manager = PluginsManager::dynamic(lib_loader.clone(), BACKEND_LIB_PREFIX) - .declare_static_plugin::(true); + let plugins_manager = + PluginsManager::dynamic(lib_loader.clone(), BACKEND_LIB_PREFIX) + .declare_static_plugin::(MEMORY_BACKEND_NAME, true); let session = Arc::new(zenoh::session::init(runtime.clone()).wait()?); @@ -196,17 +197,22 @@ impl StorageRuntimeInner { volume_id, backend_name ); - let declared = if let Some(declared) = self.plugins_manager.plugin_mut(volume_id) { + let declared = if let Some(declared) = self.plugins_manager.plugin_mut(backend_name) { declared } else if let Some(paths) = config.paths() { - self.plugins_manager - .declare_dynamic_plugin_by_paths(volume_id, paths, true)? + self.plugins_manager.declare_dynamic_plugin_by_paths( + backend_name, + volume_id, + paths, + true, + )? } else { self.plugins_manager .declare_dynamic_plugin_by_name(volume_id, backend_name, true)? }; let loaded = declared.load()?; loaded.start(config)?; + Ok(()) } fn kill_storage(&mut self, config: &StorageConfig) { @@ -317,7 +323,7 @@ impl RunningPluginTrait for StorageRuntime { let guard = self.0.lock().unwrap(); with_extended_string(&mut key, &["/volumes/"], |key| { for plugin in guard.plugins_manager.started_plugins_iter() { - with_extended_string(key, &[plugin.name()], |key| { + with_extended_string(key, &[plugin.id()], |key| { with_extended_string(key, &["/__path__"], |key| { if keyexpr::new(key.as_str()) .unwrap() diff --git a/plugins/zenoh-plugin-trait/src/manager.rs b/plugins/zenoh-plugin-trait/src/manager.rs index 2f5336d1fc..5c9c9e8bd2 100644 --- a/plugins/zenoh-plugin-trait/src/manager.rs +++ b/plugins/zenoh-plugin-trait/src/manager.rs @@ -60,6 +60,11 @@ impl PluginStatus fn name(&self) -> &str { self.0.name() } + + fn id(&self) -> &str { + self.0.id() + } + fn version(&self) -> Option<&str> { self.0.version() } @@ -110,7 +115,7 @@ impl PluginsManager { default_lib_prefix: default_lib_prefix.into(), loader: Some(loader), - plugins: Vec::new(), + plugins: Default::default(), } } /// Constructs a new plugin manager with dynamic library loading disabled. @@ -118,21 +123,33 @@ impl PluginsManager { default_lib_prefix: String::new(), loader: None, - plugins: Vec::new(), + plugins: Default::default(), } } /// Adds a statically linked plugin to the manager. pub fn declare_static_plugin< P: Plugin + Send + Sync, + S: Into, >( mut self, + id: S, required: bool, ) -> Self { - let plugin_loader: StaticPlugin = StaticPlugin::new(required); + let id = id.into(); + let plugin_loader: StaticPlugin = + StaticPlugin::new(id.clone(), required); + + if self.get_plugin_index(&id).is_some() { + tracing::warn!( + "Duplicate plugin with ID: {id}, only the last declared one will be loaded" + ) + } + self.plugins.push(PluginRecord::new(plugin_loader)); tracing::debug!( - "Declared static plugin {}", + "Declared static plugin Id:{} - Name:{}", + self.plugins.last().unwrap().id(), self.plugins.last().unwrap().name() ); self @@ -141,23 +158,35 @@ impl /// Add dynamic plugin to the manager by name, automatically prepending the default library prefix pub fn declare_dynamic_plugin_by_name>( &mut self, - name: S, - plugin_name: &str, + id: S, + plugin_name: S, required: bool, ) -> ZResult<&mut dyn DeclaredPlugin> { - let name = name.into(); - let plugin_name = format!("{}{}", self.default_lib_prefix, plugin_name); + let plugin_name = plugin_name.into(); + let id = id.into(); + let libplugin_name = format!("{}{}", self.default_lib_prefix, plugin_name); let libloader = self .loader .as_ref() .ok_or("Dynamic plugin loading is disabled")? .clone(); - tracing::debug!("Declared dynamic plugin {} by name {}", &name, &plugin_name); + tracing::debug!( + "Declared dynamic plugin {} by name {}", + &id, + &libplugin_name + ); let loader = DynamicPlugin::new( - name, - DynamicPluginSource::ByName((libloader, plugin_name)), + plugin_name, + id.clone(), + DynamicPluginSource::ByName((libloader, libplugin_name)), required, ); + + if self.get_plugin_index(&id).is_some() { + tracing::warn!( + "Duplicate plugin with ID: {id}, only the last declared one will be loaded" + ) + } self.plugins.push(PluginRecord::new(loader)); Ok(self.plugins.last_mut().unwrap()) } @@ -166,19 +195,33 @@ impl pub fn declare_dynamic_plugin_by_paths, P: AsRef + std::fmt::Debug>( &mut self, name: S, + id: S, paths: &[P], required: bool, ) -> ZResult<&mut dyn DeclaredPlugin> { let name = name.into(); + let id = id.into(); let paths = paths.iter().map(|p| p.as_ref().into()).collect(); - tracing::debug!("Declared dynamic plugin {} by paths {:?}", &name, &paths); - let loader = DynamicPlugin::new(name, DynamicPluginSource::ByPaths(paths), required); + tracing::debug!("Declared dynamic plugin {} by paths {:?}", &id, &paths); + let loader = DynamicPlugin::new( + name, + id.clone(), + DynamicPluginSource::ByPaths(paths), + required, + ); + + if self.get_plugin_index(&id).is_some() { + tracing::warn!( + "Duplicate plugin with ID: {id}, only the last declared one will be loaded" + ) + } + self.plugins.push(PluginRecord::new(loader)); Ok(self.plugins.last_mut().unwrap()) } - fn get_plugin_index(&self, name: &str) -> Option { - self.plugins.iter().position(|p| p.name() == name) + fn get_plugin_index(&self, id: &str) -> Option { + self.plugins.iter().position(|p| p.id() == id) } /// Lists all plugins @@ -210,7 +253,6 @@ impl pub fn loaded_plugins_iter_mut( &mut self, ) -> impl Iterator> + '_ { - // self.plugins_mut().filter_map(|p| p.loaded_mut()) self.declared_plugins_iter_mut() .filter_map(|p| p.loaded_mut()) } @@ -230,45 +272,42 @@ impl .filter_map(|p| p.started_mut()) } - /// Returns single plugin record by name - pub fn plugin(&self, name: &str) -> Option<&dyn DeclaredPlugin> { - let index = self.get_plugin_index(name)?; + /// Returns single plugin record by id + pub fn plugin(&self, id: &str) -> Option<&dyn DeclaredPlugin> { + let index = self.get_plugin_index(id)?; Some(&self.plugins[index]) } - /// Returns mutable plugin record by name - pub fn plugin_mut( - &mut self, - name: &str, - ) -> Option<&mut dyn DeclaredPlugin> { - let index = self.get_plugin_index(name)?; + /// Returns mutable plugin record by id + pub fn plugin_mut(&mut self, id: &str) -> Option<&mut dyn DeclaredPlugin> { + let index = self.get_plugin_index(id)?; Some(&mut self.plugins[index]) } - /// Returns loaded plugin record by name - pub fn loaded_plugin(&self, name: &str) -> Option<&dyn LoadedPlugin> { - self.plugin(name)?.loaded() + /// Returns loaded plugin record by id + pub fn loaded_plugin(&self, id: &str) -> Option<&dyn LoadedPlugin> { + self.plugin(id)?.loaded() } - /// Returns mutable loaded plugin record by name + /// Returns mutable loaded plugin record by id pub fn loaded_plugin_mut( &mut self, - name: &str, + id: &str, ) -> Option<&mut dyn LoadedPlugin> { - self.plugin_mut(name)?.loaded_mut() + self.plugin_mut(id)?.loaded_mut() } - /// Returns started plugin record by name - pub fn started_plugin(&self, name: &str) -> Option<&dyn StartedPlugin> { - self.loaded_plugin(name)?.started() + /// Returns started plugin record by id + pub fn started_plugin(&self, id: &str) -> Option<&dyn StartedPlugin> { + self.loaded_plugin(id)?.started() } - /// Returns mutable started plugin record by name + /// Returns mutable started plugin record by id pub fn started_plugin_mut( &mut self, - name: &str, + id: &str, ) -> Option<&mut dyn StartedPlugin> { - self.loaded_plugin_mut(name)?.started_mut() + self.loaded_plugin_mut(id)?.started_mut() } } @@ -283,21 +322,21 @@ impl P ); let mut plugins = Vec::new(); for plugin in self.declared_plugins_iter() { - let name = unsafe { keyexpr::from_str_unchecked(plugin.name()) }; - if names.includes(name) { + let id = unsafe { keyexpr::from_str_unchecked(plugin.id()) }; + if names.includes(id) { let status = PluginStatusRec::new(plugin.as_status()); plugins.push(status); } // for running plugins append their subplugins prepended with the running plugin name if let Some(plugin) = plugin.loaded() { if let Some(plugin) = plugin.started() { - if let [names, ..] = names.strip_prefix(name)[..] { + if let [names, ..] = names.strip_prefix(id)[..] { plugins.append( &mut plugin .instance() .plugins_status(names) .into_iter() - .map(|s| s.prepend_name(name)) + .map(|s| s.prepend_name(id)) .collect(), ); } diff --git a/plugins/zenoh-plugin-trait/src/manager/dynamic_plugin.rs b/plugins/zenoh-plugin-trait/src/manager/dynamic_plugin.rs index 89a0032fc1..24c873814e 100644 --- a/plugins/zenoh-plugin-trait/src/manager/dynamic_plugin.rs +++ b/plugins/zenoh-plugin-trait/src/manager/dynamic_plugin.rs @@ -107,6 +107,7 @@ impl pub struct DynamicPlugin { name: String, + id: String, required: bool, report: PluginReport, source: DynamicPluginSource, @@ -115,9 +116,10 @@ pub struct DynamicPlugin { } impl DynamicPlugin { - pub fn new(name: String, source: DynamicPluginSource, required: bool) -> Self { + pub fn new(name: String, id: String, source: DynamicPluginSource, required: bool) -> Self { Self { name, + id, required, report: PluginReport::new(), source, @@ -133,6 +135,11 @@ impl PluginStatus fn name(&self) -> &str { self.name.as_str() } + + fn id(&self) -> &str { + self.id.as_str() + } + fn version(&self) -> Option<&str> { self.starter.as_ref().map(|v| v.vtable.plugin_version) } @@ -216,9 +223,7 @@ impl LoadedPlugin, required: bool, phantom: PhantomData

, + id: String, } impl StaticPlugin where P: Plugin, { - pub fn new(required: bool) -> Self { + pub fn new(id: String, required: bool) -> Self { Self { instance: None, required, phantom: PhantomData, + id, } } } @@ -46,6 +48,11 @@ where fn name(&self) -> &str { P::DEFAULT_NAME } + + fn id(&self) -> &str { + self.id.as_str() + } + fn version(&self) -> Option<&str> { Some(P::PLUGIN_VERSION) } @@ -101,10 +108,10 @@ where } fn start(&mut self, args: &StartArgs) -> ZResult<&mut dyn StartedPlugin> { if self.instance.is_none() { - tracing::debug!("Plugin `{}` started", self.name()); - self.instance = Some(P::start(self.name(), args)?); + tracing::debug!("Plugin `{}` started", self.id()); + self.instance = Some(P::start(self.id(), args)?); } else { - tracing::warn!("Plugin `{}` already started", self.name()); + tracing::warn!("Plugin `{}` already started", self.id()); } Ok(self) } diff --git a/plugins/zenoh-plugin-trait/src/plugin.rs b/plugins/zenoh-plugin-trait/src/plugin.rs index 703f4fb0b1..373da64634 100644 --- a/plugins/zenoh-plugin-trait/src/plugin.rs +++ b/plugins/zenoh-plugin-trait/src/plugin.rs @@ -64,6 +64,8 @@ pub struct PluginReport { pub trait PluginStatus { /// Returns the name of the plugin fn name(&self) -> &str; + /// Returns the ID of the plugin + fn id(&self) -> &str; /// Returns the version of the loaded plugin (usually the version of the plugin's crate) fn version(&self) -> Option<&str>; /// Returns the long version of the loaded plugin (usually the version of the plugin's crate + git commit hash) @@ -81,6 +83,7 @@ pub trait PluginStatus { #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] pub struct PluginStatusRec<'a> { pub name: Cow<'a, str>, + pub id: Cow<'a, str>, #[serde(skip_serializing_if = "Option::is_none")] pub version: Option>, pub long_version: Option>, @@ -93,6 +96,11 @@ impl PluginStatus for PluginStatusRec<'_> { fn name(&self) -> &str { &self.name } + + fn id(&self) -> &str { + &self.id + } + fn version(&self) -> Option<&str> { self.version.as_deref() } @@ -115,6 +123,7 @@ impl<'a> PluginStatusRec<'a> { pub fn new(plugin: &'a T) -> Self { Self { name: Cow::Borrowed(plugin.name()), + id: Cow::Borrowed(plugin.id()), version: plugin.version().map(Cow::Borrowed), long_version: plugin.long_version().map(Cow::Borrowed), path: Cow::Borrowed(plugin.path()), @@ -126,6 +135,7 @@ impl<'a> PluginStatusRec<'a> { pub fn into_owned(self) -> PluginStatusRec<'static> { PluginStatusRec { name: Cow::Owned(self.name.into_owned()), + id: Cow::Owned(self.id.into_owned()), version: self.version.map(|v| Cow::Owned(v.into_owned())), long_version: self.long_version.map(|v| Cow::Owned(v.into_owned())), path: Cow::Owned(self.path.into_owned()), diff --git a/zenoh-ext/examples/examples/z_member.rs b/zenoh-ext/examples/examples/z_member.rs index 5ddd6e3141..90129ca21e 100644 --- a/zenoh-ext/examples/examples/z_member.rs +++ b/zenoh-ext/examples/examples/z_member.rs @@ -19,7 +19,7 @@ use zenoh_ext::group::*; #[tokio::main] async fn main() { - zenoh_util::try_init_log_from_env(); + zenoh::try_init_log_from_env(); let z = Arc::new(zenoh::open(Config::default()).await.unwrap()); let member = Member::new(z.zid().to_string()) .unwrap() diff --git a/zenoh-ext/examples/examples/z_pub_cache.rs b/zenoh-ext/examples/examples/z_pub_cache.rs index 56de7b2fbc..0c5a60751b 100644 --- a/zenoh-ext/examples/examples/z_pub_cache.rs +++ b/zenoh-ext/examples/examples/z_pub_cache.rs @@ -24,7 +24,7 @@ use zenoh_ext_examples::CommonArgs; #[tokio::main] async fn main() { // Initiate logging - zenoh_util::try_init_log_from_env(); + zenoh::try_init_log_from_env(); let (config, key_expr, value, history, prefix, complete) = parse_args(); diff --git a/zenoh-ext/examples/examples/z_query_sub.rs b/zenoh-ext/examples/examples/z_query_sub.rs index 513ac3ca58..c819a2a831 100644 --- a/zenoh-ext/examples/examples/z_query_sub.rs +++ b/zenoh-ext/examples/examples/z_query_sub.rs @@ -19,7 +19,7 @@ use zenoh_ext_examples::CommonArgs; #[tokio::main] async fn main() { // Initiate logging - zenoh_util::try_init_log_from_env(); + zenoh::try_init_log_from_env(); let (config, key_expr, query) = parse_args(); diff --git a/zenoh-ext/examples/examples/z_view_size.rs b/zenoh-ext/examples/examples/z_view_size.rs index fd8220d506..a38120cfb4 100644 --- a/zenoh-ext/examples/examples/z_view_size.rs +++ b/zenoh-ext/examples/examples/z_view_size.rs @@ -20,7 +20,7 @@ use zenoh_ext_examples::CommonArgs; #[tokio::main] async fn main() { - zenoh_util::try_init_log_from_env(); + zenoh::try_init_log_from_env(); let (config, group_name, id, size, timeout) = parse_args(); diff --git a/zenoh/src/api/loader.rs b/zenoh/src/api/loader.rs index ad4dac61fb..fe2420cf01 100644 --- a/zenoh/src/api/loader.rs +++ b/zenoh/src/api/loader.rs @@ -20,22 +20,23 @@ use crate::runtime::Runtime; pub(crate) fn load_plugin( plugin_mgr: &mut PluginsManager, name: &str, + id: &str, paths: &Option>, required: bool, ) -> ZResult<()> { let declared = if let Some(declared) = plugin_mgr.plugin_mut(name) { - tracing::warn!("Plugin `{}` was already declared", declared.name()); + tracing::warn!("Plugin `{}` was already declared", declared.id()); declared } else if let Some(paths) = paths { - plugin_mgr.declare_dynamic_plugin_by_paths(name, paths, required)? + plugin_mgr.declare_dynamic_plugin_by_paths(name, id, paths, required)? } else { - plugin_mgr.declare_dynamic_plugin_by_name(name, name, required)? + plugin_mgr.declare_dynamic_plugin_by_name(id, name, required)? }; if let Some(loaded) = declared.loaded_mut() { tracing::warn!( "Plugin `{}` was already loaded from {}", - loaded.name(), + loaded.id(), loaded.path() ); } else { @@ -49,15 +50,16 @@ pub(crate) fn load_plugins(config: &Config) -> PluginsManager { // Static plugins are to be added here, with `.add_static::()` for plugin_load in config.plugins().load_requests() { let PluginLoad { + id, name, paths, required, } = plugin_load; tracing::info!( - "Loading {req} plugin \"{name}\"", + "Loading {req} plugin \"{id}\"", req = if required { "required" } else { "" } ); - if let Err(e) = load_plugin(&mut manager, &name, &paths, required) { + if let Err(e) = load_plugin(&mut manager, &name, &id, &paths, required) { if required { panic!("Plugin load failure: {}", e) } else { @@ -75,13 +77,13 @@ pub(crate) fn start_plugins(runtime: &Runtime) { tracing::info!( "Starting {req} plugin \"{name}\"", req = if required { "required" } else { "" }, - name = plugin.name() + name = plugin.id() ); match plugin.start(runtime) { Ok(_) => { tracing::info!( "Successfully started plugin {} from {:?}", - plugin.name(), + plugin.id(), plugin.path() ); } @@ -93,7 +95,7 @@ pub(crate) fn start_plugins(runtime: &Runtime) { if required { panic!( "Plugin \"{}\" failed to start: {}", - plugin.name(), + plugin.id(), if report.is_empty() { "no details provided" } else { @@ -103,7 +105,7 @@ pub(crate) fn start_plugins(runtime: &Runtime) { } else { tracing::error!( "Required plugin \"{}\" failed to start: {}", - plugin.name(), + plugin.id(), if report.is_empty() { "no details provided" } else { diff --git a/zenoh/src/lib.rs b/zenoh/src/lib.rs index 1ae9645a8f..ccbaba6402 100644 --- a/zenoh/src/lib.rs +++ b/zenoh/src/lib.rs @@ -112,11 +112,14 @@ pub const FEATURES: &str = zenoh_util::concat_enabled_features!( ); #[doc(inline)] -pub use crate::{ - config::Config, - core::{Error, Result}, - scouting::scout, - session::{open, Session}, +pub use { + crate::{ + config::Config, + core::{Error, Result}, + scouting::scout, + session::{open, Session}, + }, + zenoh_util::try_init_log_from_env, }; pub mod prelude; diff --git a/zenoh/src/net/runtime/adminspace.rs b/zenoh/src/net/runtime/adminspace.rs index dcc5af05d6..d62700b142 100644 --- a/zenoh/src/net/runtime/adminspace.rs +++ b/zenoh/src/net/runtime/adminspace.rs @@ -113,20 +113,21 @@ impl AdminSpace { start_args: &Runtime, required: bool, ) -> ZResult<()> { + let id = &config.id; let name = &config.name; - let declared = if let Some(declared) = plugin_mgr.plugin_mut(name) { - tracing::warn!("Plugin `{}` was already declared", declared.name()); + let declared = if let Some(declared) = plugin_mgr.plugin_mut(id) { + tracing::warn!("Plugin `{}` was already declared", declared.id()); declared } else if let Some(paths) = &config.paths { - plugin_mgr.declare_dynamic_plugin_by_paths(name, paths, required)? + plugin_mgr.declare_dynamic_plugin_by_paths(id, name, paths, required)? } else { - plugin_mgr.declare_dynamic_plugin_by_name(name, name, required)? + plugin_mgr.declare_dynamic_plugin_by_name(id, name, required)? }; let loaded = if let Some(loaded) = declared.loaded_mut() { tracing::warn!( "Plugin `{}` was already loaded from {}", - loaded.name(), + loaded.id(), loaded.path() ); loaded @@ -135,12 +136,12 @@ impl AdminSpace { }; if let Some(started) = loaded.started_mut() { - tracing::warn!("Plugin `{}` was already started", started.name()); + tracing::warn!("Plugin `{}` was already started", started.id()); } else { let started = loaded.start(start_args)?; tracing::info!( "Successfully started plugin `{}` from {}", - started.name(), + started.id(), started.path() ); }; @@ -214,7 +215,7 @@ impl AdminSpace { let mut active_plugins = runtime .plugins_manager() .started_plugins_iter() - .map(|rec| (rec.name().to_string(), rec.path().to_string())) + .map(|rec| (rec.id().to_string(), rec.path().to_string())) .collect::>(); let context = Arc::new(AdminContext { @@ -252,12 +253,12 @@ impl AdminSpace { }; let mut diffs = Vec::new(); for plugin in active_plugins.keys() { - if !requested_plugins.iter().any(|r| &r.name == plugin) { + if !requested_plugins.iter().any(|r| &r.id == plugin) { diffs.push(PluginDiff::Delete(plugin.clone())) } } for request in requested_plugins { - if let Some(active) = active_plugins.get(&request.name) { + if let Some(active) = active_plugins.get(&request.id) { if request .paths .as_ref() @@ -266,16 +267,16 @@ impl AdminSpace { { continue; } - diffs.push(PluginDiff::Delete(request.name.clone())) + diffs.push(PluginDiff::Delete(request.id.clone())) } diffs.push(PluginDiff::Start(request)) } let mut plugins_mgr = admin.context.runtime.plugins_manager(); for diff in diffs { match diff { - PluginDiff::Delete(name) => { - active_plugins.remove(name.as_str()); - if let Some(running) = plugins_mgr.started_plugin_mut(&name) { + PluginDiff::Delete(id) => { + active_plugins.remove(id.as_str()); + if let Some(running) = plugins_mgr.started_plugin_mut(&id) { running.stop() } } @@ -287,11 +288,11 @@ impl AdminSpace { plugin.required, ) { if plugin.required { - panic!("Failed to load plugin `{}`: {}", plugin.name, e) + panic!("Failed to load plugin `{}`: {}", plugin.id, e) } else { tracing::error!( "Failed to load plugin `{}`: {}", - plugin.name, + plugin.id, e ) } @@ -550,7 +551,7 @@ fn local_data(context: &AdminContext, query: Query) { let plugins_mgr = context.runtime.plugins_manager(); plugins_mgr .started_plugins_iter() - .map(|rec| (rec.name(), json!({ "path": rec.path() }))) + .map(|rec| (rec.id(), json!({"name":rec.name(), "path": rec.path() }))) .collect() }; #[cfg(not(all(feature = "unstable", feature = "plugins")))] @@ -768,7 +769,7 @@ fn plugins_data(context: &AdminContext, query: Query) { let statuses = guard.plugins_status(names); for status in statuses { tracing::debug!("plugin status: {:?}", status); - let key = root_key.join(status.name()).unwrap(); + let key = root_key.join(status.id()).unwrap(); let status = serde_json::to_value(status).unwrap(); match ZBytes::try_from(status) { Ok(zbuf) => { @@ -794,7 +795,7 @@ fn plugins_status(context: &AdminContext, query: Query) { ); for plugin in guard.started_plugins_iter() { - with_extended_string(&mut root_key, &[plugin.name()], |plugin_key| { + with_extended_string(&mut root_key, &[plugin.id()], |plugin_key| { // @TODO: response to "__version__", this need not to be implemented by each plugin with_extended_string(plugin_key, &["/__path__"], |plugin_path_key| { if let Ok(key_expr) = KeyExpr::try_from(plugin_path_key.clone()) { @@ -838,15 +839,15 @@ fn plugins_status(context: &AdminContext, query: Query) { } } Ok(Err(e)) => { - tracing::error!("Plugin {} bailed from responding to {}: {}", plugin.name(), query.key_expr(), e) + tracing::error!("Plugin {} bailed from responding to {}: {}", plugin.id(), query.key_expr(), e) } Err(e) => match e .downcast_ref::() .map(|s| s.as_str()) .or_else(|| e.downcast_ref::<&str>().copied()) { - Some(e) => tracing::error!("Plugin {} panicked while responding to {}: {}", plugin.name(), query.key_expr(), e), - None => tracing::error!("Plugin {} panicked while responding to {}. The panic message couldn't be recovered.", plugin.name(), query.key_expr()), + Some(e) => tracing::error!("Plugin {} panicked while responding to {}: {}", plugin.id(), query.key_expr(), e), + None => tracing::error!("Plugin {} panicked while responding to {}. The panic message couldn't be recovered.", plugin.id(), query.key_expr()), }, } }); diff --git a/zenoh/tests/acl.rs b/zenoh/tests/acl.rs index b78a9ac888..31294b1359 100644 --- a/zenoh/tests/acl.rs +++ b/zenoh/tests/acl.rs @@ -34,7 +34,7 @@ mod test { #[tokio::test(flavor = "multi_thread", worker_threads = 4)] async fn test_acl() { - zenoh_util::try_init_log_from_env(); + zenoh::try_init_log_from_env(); test_pub_sub_deny().await; test_pub_sub_allow().await; test_pub_sub_deny_then_allow().await; diff --git a/zenoh/tests/interceptors.rs b/zenoh/tests/interceptors.rs index 32001f1875..3ee2c51828 100644 --- a/zenoh/tests/interceptors.rs +++ b/zenoh/tests/interceptors.rs @@ -182,7 +182,7 @@ fn downsampling_by_keyexpr_impl(flow: InterceptorFlow) { #[test] fn downsampling_by_keyexpr() { - zenoh_util::try_init_log_from_env(); + zenoh::try_init_log_from_env(); downsampling_by_keyexpr_impl(InterceptorFlow::Ingress); downsampling_by_keyexpr_impl(InterceptorFlow::Egress); } @@ -235,7 +235,7 @@ fn downsampling_by_interface_impl(flow: InterceptorFlow) { #[cfg(unix)] #[test] fn downsampling_by_interface() { - zenoh_util::try_init_log_from_env(); + zenoh::try_init_log_from_env(); downsampling_by_interface_impl(InterceptorFlow::Ingress); downsampling_by_interface_impl(InterceptorFlow::Egress); } @@ -243,7 +243,7 @@ fn downsampling_by_interface() { #[test] #[should_panic(expected = "unknown variant `down`")] fn downsampling_config_error_wrong_strategy() { - zenoh_util::try_init_log_from_env(); + zenoh::try_init_log_from_env(); let mut config = Config::default(); config diff --git a/zenoh/tests/open_time.rs b/zenoh/tests/open_time.rs index 87c080bc97..dec41d1558 100644 --- a/zenoh/tests/open_time.rs +++ b/zenoh/tests/open_time.rs @@ -135,7 +135,7 @@ async fn time_lowlatency_open(endpoint: &EndPoint, mode: WhatAmI) { #[tokio::test(flavor = "multi_thread", worker_threads = 4)] #[ignore] async fn time_tcp_only_open() { - zenoh_util::try_init_log_from_env(); + zenoh::try_init_log_from_env(); let endpoint: EndPoint = format!("tcp/127.0.0.1:{}", 14000).parse().unwrap(); time_universal_open(&endpoint, WhatAmI::Client).await; } @@ -144,7 +144,7 @@ async fn time_tcp_only_open() { #[tokio::test(flavor = "multi_thread", worker_threads = 4)] #[ignore] async fn time_tcp_only_with_lowlatency_open() { - zenoh_util::try_init_log_from_env(); + zenoh::try_init_log_from_env(); let endpoint: EndPoint = format!("tcp/127.0.0.1:{}", 14100).parse().unwrap(); time_lowlatency_open(&endpoint, WhatAmI::Client).await; } @@ -153,7 +153,7 @@ async fn time_tcp_only_with_lowlatency_open() { #[tokio::test(flavor = "multi_thread", worker_threads = 4)] #[ignore] async fn time_udp_only_open() { - zenoh_util::try_init_log_from_env(); + zenoh::try_init_log_from_env(); let endpoint: EndPoint = format!("udp/127.0.0.1:{}", 14010).parse().unwrap(); time_universal_open(&endpoint, WhatAmI::Client).await; } @@ -162,7 +162,7 @@ async fn time_udp_only_open() { #[tokio::test(flavor = "multi_thread", worker_threads = 4)] #[ignore] async fn time_udp_only_with_lowlatency_open() { - zenoh_util::try_init_log_from_env(); + zenoh::try_init_log_from_env(); let endpoint: EndPoint = format!("udp/127.0.0.1:{}", 14110).parse().unwrap(); time_lowlatency_open(&endpoint, WhatAmI::Client).await; } @@ -171,7 +171,7 @@ async fn time_udp_only_with_lowlatency_open() { // #[tokio::test(flavor = "multi_thread", worker_threads = 4)] // #[ignore] // async fn time_ws_only_open() { -// zenoh_util::try_init_log_from_env(); +// zenoh::try_init_log_from_env(); // let endpoint: EndPoint = format!("ws/127.0.0.1:{}", 14020).parse().unwrap(); // time_universal_open(&endpoint, WhatAmI::Client).await; // } @@ -180,7 +180,7 @@ async fn time_udp_only_with_lowlatency_open() { // #[tokio::test(flavor = "multi_thread", worker_threads = 4)] // #[ignore] // async fn time_ws_only_with_lowlatency_open() { -// zenoh_util::try_init_log_from_env(); +// zenoh::try_init_log_from_env(); // let endpoint: EndPoint = format!("ws/127.0.0.1:{}", 14120).parse().unwrap(); // time_lowlatency_open(&endpoint, WhatAmI::Client).await; // } @@ -189,7 +189,7 @@ async fn time_udp_only_with_lowlatency_open() { #[tokio::test(flavor = "multi_thread", worker_threads = 4)] #[ignore] async fn time_unixpipe_only_open() { - zenoh_util::try_init_log_from_env(); + zenoh::try_init_log_from_env(); let endpoint: EndPoint = "unixpipe/time_unixpipe_only_open".parse().unwrap(); time_universal_open(&endpoint, WhatAmI::Client).await; } @@ -198,7 +198,7 @@ async fn time_unixpipe_only_open() { #[tokio::test(flavor = "multi_thread", worker_threads = 4)] #[ignore] async fn time_unixpipe_only_with_lowlatency_open() { - zenoh_util::try_init_log_from_env(); + zenoh::try_init_log_from_env(); let endpoint: EndPoint = "unixpipe/time_unixpipe_only_with_lowlatency_open" .parse() .unwrap(); @@ -209,7 +209,7 @@ async fn time_unixpipe_only_with_lowlatency_open() { #[tokio::test(flavor = "multi_thread", worker_threads = 4)] #[ignore] async fn time_unix_only_open() { - zenoh_util::try_init_log_from_env(); + zenoh::try_init_log_from_env(); let f1 = "zenoh-test-unix-socket-9-open.sock"; let _ = std::fs::remove_file(f1); let endpoint: EndPoint = format!("unixsock-stream/{f1}").parse().unwrap(); @@ -224,7 +224,7 @@ async fn time_unix_only_open() { async fn time_tls_only_open() { use zenoh_link::tls::config::*; - zenoh_util::try_init_log_from_env(); + zenoh::try_init_log_from_env(); // NOTE: this an auto-generated pair of certificate and key. // The target domain is localhost, so it has no real // mapping to any existing domain. The certificate and key @@ -420,7 +420,7 @@ R+IdLiXcyIkg0m9N8I17p0ljCSkbrgGMD3bbePRTfg== #[tokio::test(flavor = "multi_thread", worker_threads = 4)] #[ignore] async fn time_vsock_only_open() { - zenoh_util::try_init_log_from_env(); + zenoh::try_init_log_from_env(); let endpoint: EndPoint = "vsock/VMADDR_CID_LOCAL:18000".parse().unwrap(); time_lowlatency_open(&endpoint, WhatAmI::Client).await; } diff --git a/zenoh/tests/routing.rs b/zenoh/tests/routing.rs index 123ff24201..b72f2d560c 100644 --- a/zenoh/tests/routing.rs +++ b/zenoh/tests/routing.rs @@ -362,7 +362,7 @@ impl Recipe { // And the message transmission should work even if the common node disappears after a while. #[tokio::test(flavor = "multi_thread", worker_threads = 4)] async fn gossip() -> Result<()> { - zenoh_util::try_init_log_from_env(); + zenoh::try_init_log_from_env(); let locator = String::from("tcp/127.0.0.1:17446"); let ke = String::from("testKeyExprGossip"); @@ -430,7 +430,7 @@ async fn gossip() -> Result<()> { // Simulate two peers connecting to a router but not directly reachable to each other can exchange messages via the brokering by the router. #[tokio::test(flavor = "multi_thread", worker_threads = 4)] async fn static_failover_brokering() -> Result<()> { - zenoh_util::try_init_log_from_env(); + zenoh::try_init_log_from_env(); let locator = String::from("tcp/127.0.0.1:17449"); let ke = String::from("testKeyExprStaticFailoverBrokering"); let msg_size = 8; @@ -491,7 +491,7 @@ async fn static_failover_brokering() -> Result<()> { // Total cases = 2 x 4 x 6 = 48 #[tokio::test(flavor = "multi_thread", worker_threads = 9)] async fn three_node_combination() -> Result<()> { - zenoh_util::try_init_log_from_env(); + zenoh::try_init_log_from_env(); let modes = [WhatAmI::Peer, WhatAmI::Client]; let delay_in_secs = [ (0, 1, 2), @@ -622,7 +622,7 @@ async fn three_node_combination() -> Result<()> { // Total cases = 2 x 8 = 16 #[tokio::test(flavor = "multi_thread", worker_threads = 8)] async fn two_node_combination() -> Result<()> { - zenoh_util::try_init_log_from_env(); + zenoh::try_init_log_from_env(); #[derive(Clone, Copy)] struct IsFirstListen(bool); diff --git a/zenoh/tests/session.rs b/zenoh/tests/session.rs index 5201be24a2..3c22d16b3f 100644 --- a/zenoh/tests/session.rs +++ b/zenoh/tests/session.rs @@ -245,7 +245,7 @@ async fn test_session_qryrep(peer01: &Session, peer02: &Session, reliability: Re #[tokio::test(flavor = "multi_thread", worker_threads = 4)] async fn zenoh_session_unicast() { - zenoh_util::try_init_log_from_env(); + zenoh::try_init_log_from_env(); let (peer01, peer02) = open_session_unicast(&["tcp/127.0.0.1:17447"]).await; test_session_pubsub(&peer01, &peer02, Reliability::Reliable).await; test_session_qryrep(&peer01, &peer02, Reliability::Reliable).await; @@ -254,7 +254,7 @@ async fn zenoh_session_unicast() { #[tokio::test(flavor = "multi_thread", worker_threads = 4)] async fn zenoh_session_multicast() { - zenoh_util::try_init_log_from_env(); + zenoh::try_init_log_from_env(); let (peer01, peer02) = open_session_multicast("udp/224.0.0.1:17448", "udp/224.0.0.1:17448").await; test_session_pubsub(&peer01, &peer02, Reliability::BestEffort).await; diff --git a/zenoh/tests/shm.rs b/zenoh/tests/shm.rs index a969af4dbe..81e5fdece1 100644 --- a/zenoh/tests/shm.rs +++ b/zenoh/tests/shm.rs @@ -182,7 +182,7 @@ async fn test_session_pubsub(peer01: &Session, peer02: &Session, reliability: Re fn zenoh_shm_unicast() { tokio::runtime::Runtime::new().unwrap().block_on(async { // Initiate logging - zenoh_util::try_init_log_from_env(); + zenoh::try_init_log_from_env(); let (peer01, peer02) = open_session_unicast(&["tcp/127.0.0.1:19447"]).await; test_session_pubsub(&peer01, &peer02, Reliability::Reliable).await; @@ -194,7 +194,7 @@ fn zenoh_shm_unicast() { fn zenoh_shm_multicast() { tokio::runtime::Runtime::new().unwrap().block_on(async { // Initiate logging - zenoh_util::try_init_log_from_env(); + zenoh::try_init_log_from_env(); let (peer01, peer02) = open_session_multicast("udp/224.0.0.1:19448", "udp/224.0.0.1:19448").await; diff --git a/zenoh/tests/unicity.rs b/zenoh/tests/unicity.rs index 70a70c5dce..35725a1abb 100644 --- a/zenoh/tests/unicity.rs +++ b/zenoh/tests/unicity.rs @@ -257,7 +257,7 @@ async fn test_unicity_qryrep(s01: &Session, s02: &Session, s03: &Session) { #[tokio::test(flavor = "multi_thread", worker_threads = 4)] async fn zenoh_unicity_p2p() { - zenoh_util::try_init_log_from_env(); + zenoh::try_init_log_from_env(); let (s01, s02, s03) = open_p2p_sessions().await; test_unicity_pubsub(&s01, &s02, &s03).await; @@ -267,7 +267,7 @@ async fn zenoh_unicity_p2p() { #[tokio::test(flavor = "multi_thread", worker_threads = 4)] async fn zenoh_unicity_brokered() { - zenoh_util::try_init_log_from_env(); + zenoh::try_init_log_from_env(); let r = open_router_session().await; let (s01, s02, s03) = open_client_sessions().await;