From 0e03a1a2d49dff54c6e4b572159fdfa617e735a3 Mon Sep 17 00:00:00 2001 From: Hansie Odendaal Date: Tue, 19 Nov 2024 15:04:56 +0200 Subject: [PATCH] cucumber logging --- .../log4rs_sample.yml | 2 +- .../minotari_merge_mining_proxy/src/proxy.rs | 2 +- .../src/run_merge_miner.rs | 3 + integration_tests/log4rs/cucumber.yml | 22 +++++- integration_tests/src/base_node_process.rs | 2 +- integration_tests/src/merge_mining_proxy.rs | 69 ++++++++++--------- integration_tests/tests/steps/wallet_steps.rs | 2 +- 7 files changed, 63 insertions(+), 39 deletions(-) diff --git a/applications/minotari_merge_mining_proxy/log4rs_sample.yml b/applications/minotari_merge_mining_proxy/log4rs_sample.yml index e4ce789a82..187ee0071e 100644 --- a/applications/minotari_merge_mining_proxy/log4rs_sample.yml +++ b/applications/minotari_merge_mining_proxy/log4rs_sample.yml @@ -37,7 +37,7 @@ appenders: # root (to proxy) root: - level: debug + level: trace appenders: - stdout - proxy diff --git a/applications/minotari_merge_mining_proxy/src/proxy.rs b/applications/minotari_merge_mining_proxy/src/proxy.rs index 5d95452c81..b6a5ded9cb 100644 --- a/applications/minotari_merge_mining_proxy/src/proxy.rs +++ b/applications/minotari_merge_mining_proxy/src/proxy.rs @@ -1141,7 +1141,7 @@ mod test { "id": "0", "method": rpc_method, "params": { - "wallet_address": "489r43gR8bDMJNBf4Q6sL9CNERvZQrTqjRCSESqgWQEWWq2UGAfj2voaw3zBtD7U8CQ391Nc1PDHUHiN85yhbZnCDasqzyX", + "wallet_address": "44AFFq5kSiGBoZ4NMDwYtN18obc8AemS33DBLWs3H7otXft3XjrpDtQGv7SqSsaBYBb98uNbr2VBBEt7f2wfn3RVGQBEP3A", } }), Method::GetVersion => json!({ diff --git a/applications/minotari_merge_mining_proxy/src/run_merge_miner.rs b/applications/minotari_merge_mining_proxy/src/run_merge_miner.rs index 571c77f464..54cf88eecf 100644 --- a/applications/minotari_merge_mining_proxy/src/run_merge_miner.rs +++ b/applications/minotari_merge_mining_proxy/src/run_merge_miner.rs @@ -57,10 +57,13 @@ const LOG_TARGET: &str = "minotari_mm_proxy::proxy"; #[allow(clippy::too_many_lines)] pub async fn start_merge_miner(cli: Cli) -> Result<(), anyhow::Error> { + trace!(target: LOG_TARGET, "{:?}", cli); let config_path = cli.common.config_path(); let cfg = load_configuration(&config_path, true, cli.non_interactive_mode, &cli, cli.common.network)?; + trace!(target: LOG_TARGET, "{:?}", cfg); let mut config = MergeMiningProxyConfig::load_from(&cfg)?; config.set_base_path(cli.common.get_base_path()); + trace!(target: LOG_TARGET, "{:?}", config); // Get reputable monerod URLs let mut assigned_dynamic_fail = false; diff --git a/integration_tests/log4rs/cucumber.yml b/integration_tests/log4rs/cucumber.yml index e015173db8..bf8042aa82 100644 --- a/integration_tests/log4rs/cucumber.yml +++ b/integration_tests/log4rs/cucumber.yml @@ -145,6 +145,22 @@ appenders: pattern: "{{log_dir}}/log/libp2p.{}.log" encoder: pattern: "{d(%Y-%m-%d %H:%M:%S.%f)} {f}.{L} {i} [{t}] {l:5} {m}{n}" + # An appender named "cucumber_detail" that writes to a file with a custom pattern encoder + cucumber_detail: + kind: rolling_file + path: "{{log_dir}}/log/cucumber_detail.log" + policy: + kind: compound + trigger: + kind: size + limit: 100mb + roller: + kind: fixed_window + base: 1 + count: 5 + pattern: "{{log_dir}}/log/cucumber_detail.{}.log" + encoder: + pattern: "{d(%Y-%m-%d %H:%M:%S.%f)} {f}.{L} {i} [{t}] {l:5} {m}{n}" # We don't want prints during cucumber test, everything useful will in logs. # root: @@ -167,6 +183,10 @@ loggers: level: info # we have only single print, and it's info appenders: - stdout + cucumber_detail: + level: debug + appenders: + - cucumber_detail c: level: debug #trace #debug appenders: @@ -210,7 +230,7 @@ loggers: # merge mining proxy minotari_mm_proxy::proxy: - level: debug + level: debug #trace #debug appenders: - proxy additive: false diff --git a/integration_tests/src/base_node_process.rs b/integration_tests/src/base_node_process.rs index 4a66a956a0..6762725d4c 100644 --- a/integration_tests/src/base_node_process.rs +++ b/integration_tests/src/base_node_process.rs @@ -47,7 +47,7 @@ use tonic::transport::Channel; use crate::{get_peer_seeds, get_port, wait_for_service, ServiceType, TariWorld}; -const LOG_TARGET: &str = "cucumber::bas_node_process"; +const LOG_TARGET: &str = "cucumber_detail::base_node_process"; #[derive(Clone)] pub struct BaseNodeProcess { diff --git a/integration_tests/src/merge_mining_proxy.rs b/integration_tests/src/merge_mining_proxy.rs index 44d79535cd..a6c0951a4e 100644 --- a/integration_tests/src/merge_mining_proxy.rs +++ b/integration_tests/src/merge_mining_proxy.rs @@ -22,6 +22,7 @@ use std::{convert::TryInto, thread}; +use log::*; use minotari_app_utilities::common_cli_args::CommonCliArgs; use minotari_merge_mining_proxy::{merge_miner, Cli}; use minotari_wallet_grpc_client::{grpc, WalletGrpcClient}; @@ -35,6 +36,8 @@ use tonic::transport::Channel; use super::get_port; use crate::TariWorld; +const LOG_TARGET: &str = "cucumber_detail::merge_mining_process"; + #[derive(Clone, Debug)] pub struct MergeMiningProxyProcess { pub name: String, @@ -104,20 +107,6 @@ impl MergeMiningProxyProcess { "merge_mining_proxy.base_node_grpc_address".to_string(), format!("/ip4/127.0.0.1/tcp/{}", base_node_grpc_port), ), - ( - "merge_mining_proxy.monerod_url".to_string(), - [ - "http://stagenet.xmr-tw.org:38081", - "http://node.monerodevs.org:38089", - "http://node3.monerodevs.org:38089", - "http://xmr-lux.boldsuck.org:38081", - "http://singapore.node.xmr.pm:38081", - ] - .join(","), - ), - ("merge_mining_proxy.monerod_use_auth".to_string(), "false".to_string()), - ("merge_mining_proxy.monerod_username".to_string(), "".to_string()), - ("merge_mining_proxy.monerod_password".to_string(), "".to_string()), ( "merge_mining_proxy.wait_for_initial_sync_at_startup".to_string(), "false".to_string(), @@ -138,9 +127,10 @@ impl MergeMiningProxyProcess { }, non_interactive_mode: false, }; + debug!(target: LOG_TARGET, "{:?}", cli); let rt = runtime::Builder::new_multi_thread().enable_all().build().unwrap(); if let Err(e) = rt.block_on(merge_miner(cli)) { - println!("Error running merge mining proxy : {:?}", e); + println!("Error running merge mining proxy : {}", e); panic!("Error running merge mining proxy"); } }); @@ -148,12 +138,19 @@ impl MergeMiningProxyProcess { async fn get_response(&self, path: &str) -> Value { let full_address = format!("http://127.0.0.1:{}", self.port); - reqwest::get(format!("{}/{}", full_address, path)) - .await - .unwrap() - .json::() - .await - .unwrap() + match reqwest::get(format!("{}/{}", full_address, path)).await { + Ok(response) => match response.json::().await { + Ok(value) => value, + Err(err) => { + error!(target: LOG_TARGET, "response.json ({})", err); + panic!("Error parsing response ({})", err); + }, + }, + Err(err) => { + error!(target: LOG_TARGET, "reqwest::get ({})", err); + panic!("Error reqwest::get ({})", err); + }, + } } async fn json_rpc_call(&mut self, method_name: &str, params: &Value) -> Value { @@ -164,19 +161,24 @@ impl MergeMiningProxyProcess { "params": params, "id":self.id} ); - println!("json_rpc_call {}", method_name); - println!("json payload {}", json); + debug!(target: LOG_TARGET, "json_rpc_call {}", method_name); + debug!(target: LOG_TARGET, "json payload {}", json); self.id += 1; let full_address = format!("http://127.0.0.1:{}/json_rpc", self.port); - client - .post(full_address) - .json(&json) - .send() - .await - .unwrap() - .json() - .await - .unwrap() + + match client.post(full_address).json(&json).send().await { + Ok(response) => match response.json().await { + Ok(value) => value, + Err(err) => { + error!(target: LOG_TARGET, "response.json() {}", err); + panic!("Error parsing response ({})", err); + }, + }, + Err(err) => { + error!(target: LOG_TARGET, "client.post ({})", err); + panic!("Error client.post ({})", err); + }, + } } pub async fn get_height(&self) -> Value { @@ -185,8 +187,7 @@ impl MergeMiningProxyProcess { pub async fn get_block_template(&mut self) -> Value { let params = json!({ - "wallet_address":"5AUoj81i63cBUbiKY5jybsZXRDYb9CppmSjiZXC8ZYT6HZH6ebsQvBecYfRKDYoyzKF2uML9FKkTAc7nJvHKdoDYQEeteRW", - "reserve_size":60 + "wallet_address": "44AFFq5kSiGBoZ4NMDwYtN18obc8AemS33DBLWs3H7otXft3XjrpDtQGv7SqSsaBYBb98uNbr2VBBEt7f2wfn3RVGQBEP3A" }); self.json_rpc_call("getblocktemplate", ¶ms).await } diff --git a/integration_tests/tests/steps/wallet_steps.rs b/integration_tests/tests/steps/wallet_steps.rs index a14fa10348..4688592e4f 100644 --- a/integration_tests/tests/steps/wallet_steps.rs +++ b/integration_tests/tests/steps/wallet_steps.rs @@ -77,7 +77,7 @@ use tari_utilities::hex::Hex; use crate::steps::{mining_steps::create_miner, CONFIRMATION_PERIOD, HALF_SECOND, TWO_MINUTES_WITH_HALF_SECOND_SLEEP}; -const LOG_TARGET: &str = "cucumber::wallet_steps"; +const LOG_TARGET: &str = "cucumber_detail::wallet_steps"; #[given(expr = "a wallet {word} connected to base node {word}")] async fn start_wallet(world: &mut TariWorld, wallet_name: String, node_name: String) {