Pass log level & target to host log_utf8_string (#37)

This commit is contained in:
folex 2020-10-26 13:08:53 +03:00 committed by GitHub
parent 7f89ba5054
commit eb5dfafa5e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 70 additions and 51 deletions

86
Cargo.lock generated
View File

@ -248,6 +248,12 @@ version = "0.7.8"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "475bd7aa7680b4ed8f6bb59745e882bcbaeb39326532bb79ffb1716480d9a274" checksum = "475bd7aa7680b4ed8f6bb59745e882bcbaeb39326532bb79ffb1716480d9a274"
[[package]]
name = "const_fn"
version = "0.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ce90df4c658c62f12d78f7508cf92f9173e5184a539c10bfe54a3107b3ffd0f2"
[[package]] [[package]]
name = "constant_time_eq" name = "constant_time_eq"
version = "0.1.5" version = "0.1.5"
@ -332,36 +338,35 @@ dependencies = [
[[package]] [[package]]
name = "crossbeam-channel" name = "crossbeam-channel"
version = "0.4.4" version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b153fe7cbef478c567df0f972e02e6d736db11affe43dfc9c56a9374d1adfb87" checksum = "dca26ee1f8d361640700bde38b2c37d8c22b3ce2d360e1fc1c74ea4b0aa7d775"
dependencies = [ dependencies = [
"crossbeam-utils", "cfg-if 1.0.0",
"maybe-uninit", "crossbeam-utils 0.8.0",
] ]
[[package]] [[package]]
name = "crossbeam-deque" name = "crossbeam-deque"
version = "0.7.3" version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9f02af974daeee82218205558e51ec8768b48cf524bd01d550abe5573a608285" checksum = "94af6efb46fef72616855b036a624cf27ba656ffc9be1b9a3c931cfc7749a9a9"
dependencies = [ dependencies = [
"cfg-if 1.0.0",
"crossbeam-epoch", "crossbeam-epoch",
"crossbeam-utils", "crossbeam-utils 0.8.0",
"maybe-uninit",
] ]
[[package]] [[package]]
name = "crossbeam-epoch" name = "crossbeam-epoch"
version = "0.8.2" version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "058ed274caafc1f60c4997b5fc07bf7dc7cca454af7c6e81edffe5f33f70dace" checksum = "ec0f606a85340376eef0d6d8fec399e6d4a544d648386c6645eb6d0653b27d9f"
dependencies = [ dependencies = [
"autocfg", "cfg-if 1.0.0",
"cfg-if 0.1.10", "const_fn",
"crossbeam-utils", "crossbeam-utils 0.8.0",
"lazy_static", "lazy_static",
"maybe-uninit",
"memoffset", "memoffset",
"scopeguard", "scopeguard",
] ]
@ -377,6 +382,18 @@ dependencies = [
"lazy_static", "lazy_static",
] ]
[[package]]
name = "crossbeam-utils"
version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ec91540d98355f690a86367e566ecad2e9e579f230230eb7c21398372be73ea5"
dependencies = [
"autocfg",
"cfg-if 1.0.0",
"const_fn",
"lazy_static",
]
[[package]] [[package]]
name = "crypto-mac" name = "crypto-mac"
version = "0.8.0" version = "0.8.0"
@ -1005,9 +1022,9 @@ checksum = "aaf91faf136cb47367fa430cd46e37a788775e7fa104f8b4bcb3861dc389b724"
[[package]] [[package]]
name = "h2" name = "h2"
version = "0.2.6" version = "0.2.7"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "993f9e0baeed60001cf565546b0d3dbe6a6ad23f2bd31644a133c641eccf6d53" checksum = "5e4728fd124914ad25e99e3d15a9361a879f6620f63cb56bbb08f95abb97a535"
dependencies = [ dependencies = [
"bytes", "bytes",
"fnv", "fnv",
@ -1020,6 +1037,7 @@ dependencies = [
"tokio", "tokio",
"tokio-util", "tokio-util",
"tracing", "tracing",
"tracing-futures",
] ]
[[package]] [[package]]
@ -1329,12 +1347,6 @@ version = "0.1.8"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7ffc5c5338469d4d3ea17d269fa8ea3512ad247247c30bd2df69e68309ed0a08" checksum = "7ffc5c5338469d4d3ea17d269fa8ea3512ad247247c30bd2df69e68309ed0a08"
[[package]]
name = "maybe-uninit"
version = "2.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "60302e4db3a61da70c0cb7991976248362f30319e88850c487b9b95bbf059e00"
[[package]] [[package]]
name = "memchr" name = "memchr"
version = "2.3.3" version = "2.3.3"
@ -1784,9 +1796,9 @@ dependencies = [
[[package]] [[package]]
name = "rayon" name = "rayon"
version = "1.4.1" version = "1.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dcf6960dc9a5b4ee8d3e4c5787b4a112a8818e0290a42ff664ad60692fdf2032" checksum = "8b0d8e0819fadc20c74ea8373106ead0600e3a67ef1fe8da56e39b9ae7275674"
dependencies = [ dependencies = [
"autocfg", "autocfg",
"crossbeam-deque", "crossbeam-deque",
@ -1796,13 +1808,13 @@ dependencies = [
[[package]] [[package]]
name = "rayon-core" name = "rayon-core"
version = "1.8.1" version = "1.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e8c4fec834fb6e6d2dd5eece3c7b432a52f0ba887cf40e595190c4107edc08bf" checksum = "9ab346ac5921dc62ffa9f89b7a773907511cdfa5490c572ae9be1be33e8afa4a"
dependencies = [ dependencies = [
"crossbeam-channel", "crossbeam-channel",
"crossbeam-deque", "crossbeam-deque",
"crossbeam-utils", "crossbeam-utils 0.8.0",
"lazy_static", "lazy_static",
"num_cpus", "num_cpus",
] ]
@ -1911,14 +1923,14 @@ dependencies = [
"base64", "base64",
"blake2b_simd", "blake2b_simd",
"constant_time_eq", "constant_time_eq",
"crossbeam-utils", "crossbeam-utils 0.7.2",
] ]
[[package]] [[package]]
name = "rustc-demangle" name = "rustc-demangle"
version = "0.1.17" version = "0.1.18"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b2610b7f643d18c87dff3b489950269617e6601a51f1f05aa5daefee36f64f0b" checksum = "6e3bad0ee36814ca07d7968269dd4b7ec89ec2da10c4bb613928d3077083c232"
[[package]] [[package]]
name = "rustc_version" name = "rustc_version"
@ -2183,9 +2195,9 @@ checksum = "343f3f510c2915908f155e94f17220b19ccfacf2a64a2a5d8004f2c3e311e7fd"
[[package]] [[package]]
name = "syn" name = "syn"
version = "1.0.45" version = "1.0.46"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ea9c5432ff16d6152371f808fb5a871cd67368171b09bb21b43df8e4a47a3556" checksum = "5ad5de3220ea04da322618ded2c42233d02baca219d6f160a3e9c87cda16c942"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
@ -2404,6 +2416,16 @@ dependencies = [
"lazy_static", "lazy_static",
] ]
[[package]]
name = "tracing-futures"
version = "0.2.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ab7bb6f14721aa00656086e9335d363c5c8747bae02ebe32ea2c7dece5689b4c"
dependencies = [
"pin-project",
"tracing",
]
[[package]] [[package]]
name = "try-lock" name = "try-lock"
version = "0.2.3" version = "0.2.3"

View File

@ -114,6 +114,7 @@ impl AquamarineVM {
logger_enabled: true, logger_enabled: true,
host_imports, host_imports,
wasi: None, wasi: None,
logging_mask: i64::max_value(),
} }
}; };

View File

@ -47,6 +47,9 @@ pub struct FaaSModuleConfig {
/// A WASI config. /// A WASI config.
pub wasi: Option<FaaSWASIConfig>, pub wasi: Option<FaaSWASIConfig>,
/// Mask used to filter logs, for details see `log_utf8_string`
pub logging_mask: i64,
} }
impl FaaSModuleConfig { impl FaaSModuleConfig {

View File

@ -18,18 +18,13 @@ use wasmer_core::vm::Ctx;
use wasmer_core::memory::ptr::{Array, WasmPtr}; use wasmer_core::memory::ptr::{Array, WasmPtr};
pub(super) fn log_utf8_string_closure( pub(super) fn log_utf8_string_closure(
logging_mask: i64,
module: String, module: String,
) -> impl for<'a> Fn(&'a mut Ctx, i32, i32, i32, i32, i32) { ) -> impl for<'a> Fn(&'a mut Ctx, i32, i64, i32, i32) {
move |ctx, level, target_offset, target_size, msg_offset, msg_size| { move |ctx, level, target, msg_offset, msg_size| {
log_utf8_string( if target == 0 || target & logging_mask != 0 {
&module, log_utf8_string(&module, ctx, level, msg_offset, msg_size)
ctx, }
level,
target_offset,
target_size,
msg_offset,
msg_size,
)
} }
} }
@ -37,24 +32,18 @@ pub(super) fn log_utf8_string(
module: &str, module: &str,
ctx: &mut Ctx, ctx: &mut Ctx,
level: i32, level: i32,
target_offset: i32,
target_size: i32,
msg_offset: i32, msg_offset: i32,
msg_size: i32, msg_size: i32,
) { ) {
let level = level_from_i32(level); let level = level_from_i32(level);
let target = read_string(ctx, target_offset, target_size);
let msg = read_string(ctx, msg_offset, msg_size); let msg = read_string(ctx, msg_offset, msg_size);
let module_path = target.map(|t| format!("{}::{}", module, t));
let module_path = module_path.as_deref().unwrap_or(module);
match msg { match msg {
Some(msg) => log::logger().log( Some(msg) => log::logger().log(
&log::Record::builder() &log::Record::builder()
.args(format_args!("{}", msg)) .args(format_args!("{}", msg))
.level(level) .level(level)
.module_path(module_path.into()) .module_path(module.into())
.build(), .build(),
), ),
None => log::warn!("logger: incorrect UTF8 string's been supplied to logger"), None => log::warn!("logger: incorrect UTF8 string's been supplied to logger"),

View File

@ -120,9 +120,10 @@ pub(crate) fn make_fce_config(
let mut namespace = Namespace::new(); let mut namespace = Namespace::new();
if faas_module_config.logger_enabled { if faas_module_config.logger_enabled {
let logging_mask = faas_module_config.logging_mask;
namespace.insert( namespace.insert(
"log_utf8_string", "log_utf8_string",
func!(log_utf8_string_closure(module_name)), func!(log_utf8_string_closure(logging_mask, module_name)),
); );
} }

View File

@ -115,6 +115,7 @@ pub struct TomlFaaSModuleConfig {
pub logger_enabled: Option<bool>, pub logger_enabled: Option<bool>,
pub wasi: Option<TomlWASIConfig>, pub wasi: Option<TomlWASIConfig>,
pub mounted_binaries: Option<toml::value::Table>, pub mounted_binaries: Option<toml::value::Table>,
pub logging_mask: Option<i64>,
} }
impl TomlFaaSNamedModuleConfig { impl TomlFaaSNamedModuleConfig {
@ -181,6 +182,7 @@ pub fn from_toml_module_config(config: TomlFaaSModuleConfig) -> Result<FaaSModul
logger_enabled: config.logger_enabled.unwrap_or(true), logger_enabled: config.logger_enabled.unwrap_or(true),
host_imports: host_cli_imports, host_imports: host_cli_imports,
wasi, wasi,
logging_mask: config.logging_mask.unwrap_or(i64::max_value()),
}) })
} }
@ -243,6 +245,7 @@ mod tests {
mapped_dirs: None, mapped_dirs: None,
}), }),
mounted_binaries: None, mounted_binaries: None,
logging_mask: None,
}, },
}; };