Skip to content

Commit

Permalink
Merge branch 'dev/1.0.0' into internal_unstable
Browse files Browse the repository at this point in the history
  • Loading branch information
milyin committed Jun 4, 2024
2 parents 73bf9cb + e92f146 commit efaa910
Show file tree
Hide file tree
Showing 50 changed files with 333 additions and 164 deletions.
18 changes: 12 additions & 6 deletions commons/zenoh-config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Vec<String>>,
pub required: bool,
Expand All @@ -1068,22 +1069,27 @@ impl PluginsConfig {
Ok(())
}
pub fn load_requests(&'_ self) -> impl Iterator<Item = PluginLoad> + '_ {
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}
}
})
}
Expand Down
7 changes: 7 additions & 0 deletions commons/zenoh-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,12 @@ pub trait Wait: Resolvable {
pub trait AsyncResolve: Resolvable {
type Future: Future<Output = Self::To> + 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,
Expand All @@ -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,
Expand Down
86 changes: 83 additions & 3 deletions commons/zenoh-util/src/std_only/log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,16 @@
// Contributors:
// ZettaScale Zenoh Team, <[email protected]>
//
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
Expand All @@ -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
Expand Down Expand Up @@ -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<u32>,
pub thread_id: ThreadId,
pub thread_name: Option<String>,
pub message: Option<String>,
pub attributes: Vec<(&'static str, String)>,
}

#[derive(Clone)]
struct SpanFields(Vec<(&'static str, String)>);

struct Layer<F>(F);

impl<S, F> tracing_subscriber::Layer<S> for Layer<F>
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::<SpanFields>().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::<SpanFields>().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.
Expand Down
2 changes: 1 addition & 1 deletion examples/examples/z_alloc_shm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}

Expand Down
2 changes: 1 addition & 1 deletion examples/examples/z_delete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
2 changes: 1 addition & 1 deletion examples/examples/z_forward.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
2 changes: 1 addition & 1 deletion examples/examples/z_get.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
2 changes: 1 addition & 1 deletion examples/examples/z_get_liveliness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
2 changes: 1 addition & 1 deletion examples/examples/z_get_shm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
2 changes: 1 addition & 1 deletion examples/examples/z_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
2 changes: 1 addition & 1 deletion examples/examples/z_liveliness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
2 changes: 1 addition & 1 deletion examples/examples/z_ping.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion examples/examples/z_ping_shm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
2 changes: 1 addition & 1 deletion examples/examples/z_pong.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
2 changes: 1 addition & 1 deletion examples/examples/z_pub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
2 changes: 1 addition & 1 deletion examples/examples/z_pub_shm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
2 changes: 1 addition & 1 deletion examples/examples/z_pub_shm_thr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion examples/examples/z_pub_thr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion examples/examples/z_pull.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
2 changes: 1 addition & 1 deletion examples/examples/z_put.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
2 changes: 1 addition & 1 deletion examples/examples/z_put_float.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
2 changes: 1 addition & 1 deletion examples/examples/z_queryable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
2 changes: 1 addition & 1 deletion examples/examples/z_queryable_shm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
2 changes: 1 addition & 1 deletion examples/examples/z_scout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
2 changes: 1 addition & 1 deletion examples/examples/z_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
2 changes: 1 addition & 1 deletion examples/examples/z_sub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
2 changes: 1 addition & 1 deletion examples/examples/z_sub_liveliness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
2 changes: 1 addition & 1 deletion examples/examples/z_sub_shm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
Loading

0 comments on commit efaa910

Please sign in to comment.