Skip to content

Commit

Permalink
Add teaclave logger
Browse files Browse the repository at this point in the history
  • Loading branch information
sunhe05 committed Mar 3, 2023
1 parent 80101df commit 5e74240
Show file tree
Hide file tree
Showing 23 changed files with 427 additions and 66 deletions.
65 changes: 38 additions & 27 deletions cmake/tomls/Cargo.sgx_trusted_lib.lock
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,7 @@ version = "0.9.3"
source = "registry+/~https://github.com/rust-lang/crates.io-index"
checksum = "a12e6657c4c97ebab115a42dcee77225f7f482cdd841cf7088c657a42e9e00e7"
dependencies = [
"humantime",
"log",
"regex",
"termcolor",
]

[[package]]
Expand Down Expand Up @@ -230,12 +227,6 @@ version = "1.8.0"
source = "registry+/~https://github.com/rust-lang/crates.io-index"
checksum = "d897f394bad6a705d5f4104762e116a75639e470d80901eed05a860a95cb1904"

[[package]]
name = "humantime"
version = "2.1.0"
source = "registry+/~https://github.com/rust-lang/crates.io-index"
checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4"

[[package]]
name = "idna"
version = "0.3.0"
Expand Down Expand Up @@ -357,6 +348,7 @@ source = "registry+/~https://github.com/rust-lang/crates.io-index"
checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e"
dependencies = [
"cfg-if 1.0.0",
"value-bag",
]

[[package]]
Expand Down Expand Up @@ -1001,6 +993,12 @@ version = "0.5.2"
source = "registry+/~https://github.com/rust-lang/crates.io-index"
checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d"

[[package]]
name = "sval"
version = "1.0.0-alpha.5"
source = "registry+/~https://github.com/rust-lang/crates.io-index"
checksum = "45f6ee7c7b87caf59549e9fe45d6a69c75c8019e79e212a835c5da0e92f0ba08"

[[package]]
name = "syn"
version = "0.15.44"
Expand Down Expand Up @@ -1322,6 +1320,17 @@ dependencies = [
"thiserror",
]

[[package]]
name = "teaclave_logger"
version = "0.4.0"
dependencies = [
"anyhow",
"log",
"sgx_cov",
"sgx_types",
"teaclave_test_utils",
]

[[package]]
name = "teaclave_management_service_enclave"
version = "0.4.0"
Expand Down Expand Up @@ -1442,6 +1451,8 @@ dependencies = [
"sgx_macros",
"teaclave_attestation",
"teaclave_config",
"teaclave_logger",
"teaclave_proto",
"teaclave_rpc",
"teaclave_service_enclave_utils_proc_macro",
"teaclave_types",
Expand Down Expand Up @@ -1552,6 +1563,7 @@ dependencies = [
"teaclave_executor_context",
"teaclave_frontend_service_enclave",
"teaclave_function",
"teaclave_logger",
"teaclave_management_service_enclave",
"teaclave_rpc",
"teaclave_runtime",
Expand Down Expand Up @@ -1580,15 +1592,6 @@ dependencies = [
"thiserror",
]

[[package]]
name = "termcolor"
version = "1.1.3"
source = "registry+/~https://github.com/rust-lang/crates.io-index"
checksum = "bab24d30b911b2376f3a13cc2cd443142f0c81dda04c118693e35b3835757755"
dependencies = [
"winapi-util",
]

[[package]]
name = "thiserror"
version = "1.0.38"
Expand Down Expand Up @@ -1698,6 +1701,23 @@ dependencies = [
"sha1",
]

[[package]]
name = "value-bag"
version = "1.0.0-alpha.9"
source = "registry+/~https://github.com/rust-lang/crates.io-index"
checksum = "2209b78d1249f7e6f3293657c9779fe31ced465df091bbd433a1cf88e916ec55"
dependencies = [
"ctor",
"sval",
"version_check",
]

[[package]]
name = "version_check"
version = "0.9.4"
source = "registry+/~https://github.com/rust-lang/crates.io-index"
checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f"

[[package]]
name = "wasi"
version = "0.10.2+wasi-snapshot-preview1"
Expand Down Expand Up @@ -1803,15 +1823,6 @@ version = "0.4.0"
source = "registry+/~https://github.com/rust-lang/crates.io-index"
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"

[[package]]
name = "winapi-util"
version = "0.1.5"
source = "registry+/~https://github.com/rust-lang/crates.io-index"
checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178"
dependencies = [
"winapi",
]

[[package]]
name = "winapi-x86_64-pc-windows-gnu"
version = "0.4.0"
Expand Down
2 changes: 1 addition & 1 deletion examples/rust/builtin_echo/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ fn echo(message: &str) -> Result<Vec<u8>> {

println!("[+] getting result");
let response = client.get_task_result(&task_id)?;
Ok(response)
Ok(response.0)
}

fn main() -> Result<()> {
Expand Down
18 changes: 13 additions & 5 deletions examples/rust/builtin_ordered_set_intersect/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ impl Client {
"Native Private Set Intersection.",
"builtin",
None,
Some(&["order"]),
Some(&["order", "save_log"]),
Some(vec![
teaclave_client_sdk::FunctionInput::new("input_data1", "Client 0 data.", false),
teaclave_client_sdk::FunctionInput::new("input_data2", "Client 1 data.", false),
Expand All @@ -129,7 +129,7 @@ impl Client {
]),
)?;
self.client.get_function(&function_id)?;
let function_arguments = hashmap!("order" => "ascending"); // Order can be ascending or desending
let function_arguments = hashmap!("order" => "ascending", "save_log" => "true"); // Order can be ascending or desending
let inputs_ownership = hashmap!(&self.user_data.input_label => vec![self.user_data.user_id.to_string()], &self.user_data.peer_input_label => vec![self.user_data.peer_id.to_string()]);
let outputs_ownership = hashmap!(&self.user_data.output_label => vec![self.user_data.user_id.to_string()], &self.user_data.peer_output_label => vec![self.user_data.peer_id.to_string()]);

Expand Down Expand Up @@ -193,7 +193,7 @@ impl Client {
Ok(())
}

fn get_task_result(&mut self, task_id: &str) -> Result<Vec<u8>> {
fn get_task_result(&mut self, task_id: &str) -> Result<(Vec<u8>, Vec<String>)> {
println!("[+] {} getting result", self.user_data.user_id);
let response = self.client.get_task_result(&task_id)?;
Ok(response)
Expand Down Expand Up @@ -260,11 +260,19 @@ fn main() -> Result<()> {

let result_user0 = user0.get_task_result(&task_id)?;

println!("[+] User 0 result: {:?}", String::from_utf8(result_user0));
println!(
"[+] User 0 result: {:?} log: {:?} ",
String::from_utf8(result_user0.0),
result_user0.1
);

let result_user1 = user1.get_task_result(&task_id)?;

println!("[+] User 1 result: {:?}", String::from_utf8(result_user1));
println!(
"[+] User 1 result: {:?} log {:?}",
String::from_utf8(result_user1.0),
result_user1.1
);

println!("[+] done");
Ok(())
Expand Down
6 changes: 6 additions & 0 deletions function/src/echo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ impl Echo {
_runtime: FunctionRuntime,
) -> anyhow::Result<String> {
let message = EchoArguments::try_from(arguments)?.message;

#[cfg(test_mode)]
log::info!("{}", message);
#[cfg(test_mode)]
log::debug!("{}", message);

Ok(message)
}
}
Expand Down
3 changes: 3 additions & 0 deletions function/src/ordered_set_intersect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ impl OrderedSetIntersect {
for item in result2 {
write!(&mut output2, "{}", item as u32)?;
}

log::trace!("{}", common_sets);

Ok(format!("{} common items", common_sets))
}
}
Expand Down
45 changes: 45 additions & 0 deletions logger/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

[package]
name = "teaclave_logger"
version = "0.4.0"
authors = ["Teaclave Contributors <dev@teaclave.apache.org>"]
description = "Teaclave worker"
license = "Apache-2.0"
edition = "2021"

[lib]
name = "teaclave_logger"
crate-type = ["staticlib", "rlib"]

[features]
default = ["mesalock_sgx"]
mesalock_sgx = []
cov = ["sgx_cov"]
enclave_unit_test = ["teaclave_test_utils/mesalock_sgx"]

[dependencies]
anyhow = { version = "1.0.26" }
log = { version = "0.4.17", features = ["release_max_level_info", "kv_unstable_std"] }

teaclave_test_utils = { path = "../tests/utils", optional = true }

sgx_cov = { version = "2.0.0", optional = true }

[target.'cfg(not(target_vendor = "teaclave"))'.dependencies]
sgx_types = { version = "2.0.0" }
19 changes: 19 additions & 0 deletions logger/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
permalink: /docs/codebase/logger
---

# Logger

A logger for Teaclave services. It can collect logs to a buffer.
Logs not saved to buffer can be logged by another logger that
implements `log` trait.

## Task logging

When the logger is imported in the `execution service`, it can send the logs
during a task to a buffer. The `kv_unstable` feature in the `log` crate is used
to pass the pointer to the buffer to the logger. After the buffer is set, the
logger will save logs to the buffer. The logger will drop the task logger after
receiving a null pointer. Another logger which we call `secondary logger` will
handle the logs coming afterwards if it is set. The logs before the task starts
are sent to the secondary logger as well.
Loading

0 comments on commit 5e74240

Please sign in to comment.