From 4e9ac1a09d7f170352419a0454093146af405b18 Mon Sep 17 00:00:00 2001 From: Andrzej Ressel Date: Fri, 8 Mar 2024 00:58:03 +0100 Subject: [PATCH] Save --- pulumi_rust/src/lib.rs | 1 - pulumi_rust/src/pulumi.rs | 21 +-------------- pulumi_rust/src/pulumi_logger.rs | 46 -------------------------------- pulumi_wasm/src/lib.rs | 27 ++++++++++++++----- src/main.rs | 4 --- 5 files changed, 21 insertions(+), 78 deletions(-) delete mode 100644 pulumi_rust/src/pulumi_logger.rs diff --git a/pulumi_rust/src/lib.rs b/pulumi_rust/src/lib.rs index 1fa7d7f94..2aa1cfa6a 100644 --- a/pulumi_rust/src/lib.rs +++ b/pulumi_rust/src/lib.rs @@ -1,3 +1,2 @@ mod grpc; pub mod pulumi; -pub mod pulumi_logger; diff --git a/pulumi_rust/src/pulumi.rs b/pulumi_rust/src/pulumi.rs index 52edebc7d..00c72ba64 100644 --- a/pulumi_rust/src/pulumi.rs +++ b/pulumi_rust/src/pulumi.rs @@ -52,16 +52,9 @@ impl server::component::pulumi_wasm::external_world::Host for MyState { } } -fn extract_file_name(path: &String) -> String { - let file_name_regex: Regex = Regex::new(r"^.*src\\(.*)").unwrap(); - file_name_regex.captures(path).unwrap().get(1).unwrap().as_str().to_string() -} - #[async_trait] impl crate::pulumi::server::component::pulumi_wasm::log::Host for MyState { async fn log(&mut self, content: crate::pulumi::server::component::pulumi_wasm::log::Content) -> wasmtime::Result<()> { - let normalized_file_name = content.file.map(|s| extract_file_name(&s)); - log::logger().log(&log::Record::builder() .metadata(log::Metadata::builder() .level(match content.level { @@ -76,7 +69,7 @@ impl crate::pulumi::server::component::pulumi_wasm::log::Host for MyState { ) .args(format_args!("{}", content.args)) .module_path(content.module_path.as_deref()) - .file(normalized_file_name.as_deref()) + .file(content.file.as_deref()) .line(content.line) .key_values(&content.key_values.iter().map(|(k, v)| (k.as_str(), v.as_str())).collect::>()) .build()); @@ -188,15 +181,3 @@ impl Pulumi { Ok(()) } } - -#[cfg(test)] -mod test { - use crate::pulumi::extract_file_name; - - #[test] - fn should_extract_file_name() { - assert_eq!(extract_file_name(&"src\\main.rs".to_string()), "main.rs"); - assert_eq!(extract_file_name(&"pulumi_wasm\\src\\lib.rs".to_string()), "lib.rs"); - } - -} \ No newline at end of file diff --git a/pulumi_rust/src/pulumi_logger.rs b/pulumi_rust/src/pulumi_logger.rs deleted file mode 100644 index 7d9ce6706..000000000 --- a/pulumi_rust/src/pulumi_logger.rs +++ /dev/null @@ -1,46 +0,0 @@ -// use log::{Record, Level, Metadata, SetLoggerError, error, LevelFilter}; -// use pulumi_wasm::PulumiLogSeverity; -// -// pub struct PulumiLogger { -// pub engine_url: String -// } -// -// impl log::Log for PulumiLogger { -// fn enabled(&self, metadata: &Metadata) -> bool { -// true -// } -// -// fn log(&self, record: &Record) { -// if self.enabled(record.metadata()) { -// let severity = match record.level() { -// Level::Error => PulumiLogSeverity::Error, -// Level::Warn => PulumiLogSeverity::Warning, -// Level::Info => PulumiLogSeverity::Info, -// Level::Debug => PulumiLogSeverity::Debug, -// Level::Trace => PulumiLogSeverity::Debug -// }; -// let message = record.args().to_string(); -// let engine_url = self.engine_url.clone(); -// tokio::spawn(async { -// let _ = crate::log(engine_url, severity, message).await; -// }); -// } -// } -// -// fn flush(&self) {} -// } -// -// impl PulumiLogger { -// -// pub fn init(self) -> Result<(), SetLoggerError> { -// log::set_max_level(LevelFilter::Trace); -// log::set_boxed_logger(Box::new(self)) -// } -// } - -pub enum PulumiLogSeverity { - Debug, - Info, - Warning, - Error, -} diff --git a/pulumi_wasm/src/lib.rs b/pulumi_wasm/src/lib.rs index 5e6685722..79091ee8d 100644 --- a/pulumi_wasm/src/lib.rs +++ b/pulumi_wasm/src/lib.rs @@ -4,7 +4,7 @@ use std::fmt::Formatter; use std::ops::Deref; use futures::SinkExt; use lazy_static::lazy_static; -use log::{info, log}; +use log::{error, info, log}; use prost::Message; use prost_types::value::Kind; use rmpv::{Utf8String, Value}; @@ -162,8 +162,12 @@ impl GuestOutput for Output { fn get_field(&self, field: String) -> WasmOutput { wasm_common::setup_logger(); + + info!("Getting field [{field}] from Output [TODO]"); + let o = output::map_internal(vec![self.output.clone()], move |v| { let v = v[0].clone(); + info!("Value is [{v}]"); let v = match v { Value::Map(m) => { @@ -185,6 +189,8 @@ impl GuestOutput for Output { Value::Ext(_, _) => todo!(), }; + info!("Result is [{v}]"); + v }); @@ -263,15 +269,18 @@ impl function_reverse_callback::Guest for Component { } fn messagepack_to_protoc(v: &Value) -> prost_types::Value { - match v { + info!("Converting value [{v}] to protoc value"); + let result = match v { Value::Integer(i) => prost_types::Value { kind: Option::from(prost_types::value::Kind::NumberValue(i.as_f64().unwrap())), }, _ => { - eprintln!("Cannot convert [{v}]"); + error!("Cannot convert [{v}]"); todo!("Cannot convert [{v}]") } - } + }; + info!("Result: [{result:?}]"); + result } impl register_interface::Guest for Component { @@ -283,6 +292,8 @@ impl register_interface::Guest for Component { let new_output = output::map_internal(values, move |v| { + info!("Converting values [{v:?}] with names [{names:?}]"); + let pairs = names.iter().zip(v.iter()).map(|(name, value)| { let v = messagepack_to_protoc(value); (name.clone(), v) @@ -292,6 +303,8 @@ impl register_interface::Guest for Component { fields: BTreeMap::from_iter(pairs) }; + info!("Resulting object: [{object:?}]"); + let request = grpc::RegisterResourceRequest { r#type: request.type_.clone(), name: request.name.clone(), @@ -332,12 +345,12 @@ impl register_interface::Guest for Component { let result_vec = external_world::register_resource(vec_request.as_slice()); - let result = grpc::RegisterResourceResponse::decode(&mut result_vec.as_slice()).unwrap(); + let response = grpc::RegisterResourceResponse::decode(&mut result_vec.as_slice()).unwrap(); - info!("Result: {result:?}"); + info!("Response: [{response:?}]"); let result = if (!is_in_preview()) { - let result = result.object.unwrap().fields.get("result").unwrap().clone().kind.unwrap(); + let result = response.object.unwrap().fields.get("result").unwrap().clone().kind.unwrap(); match result { Kind::NullValue(_) => todo!(), diff --git a/src/main.rs b/src/main.rs index 5ceb009cc..13aa56838 100644 --- a/src/main.rs +++ b/src/main.rs @@ -60,10 +60,6 @@ async fn main() -> Result<(), Error> { let _pulumi_engine_url = std::env::var("PULUMI_ENGINE")?; let pulumi_monitor_url = std::env::var("PULUMI_MONITOR")?; - info!("INFO LOG"); - warn!("WARN LOG"); - error!("ERROR LOG"); - match &args.command { Command::Run => { let pulumi = Pulumi::create(&args.global_opts.wasm, &Some(pulumi_monitor_url)).await?;