From d007313195b281a5f111bf9b89bebb7113289343 Mon Sep 17 00:00:00 2001 From: Sergey Kipnis Date: Mon, 13 Jan 2025 13:14:50 +0100 Subject: [PATCH] mk-sql: better logging Change-Id: Id9b4cd19dc4111e8f6257641c1e080129b4973be --- packages/mk-sql/src/config/ms_sql.rs | 31 +++++++++++++++++++++------- packages/mk-sql/src/ms_sql/query.rs | 7 +++---- 2 files changed, 27 insertions(+), 11 deletions(-) diff --git a/packages/mk-sql/src/config/ms_sql.rs b/packages/mk-sql/src/config/ms_sql.rs index 9d9a3e8546d..9ed9cd6895e 100644 --- a/packages/mk-sql/src/config/ms_sql.rs +++ b/packages/mk-sql/src/config/ms_sql.rs @@ -508,12 +508,19 @@ impl ConnectionTls { if tls.is_badvalue() { return Ok(None); } + let ca = tls.get_pathbuf(keys::CA).context("Bad/Missing CA")?; + let client_certificate = tls + .get_string(keys::CLIENT_CERTIFICATE) + .map(|s| s.into()) + .context("bad/Missing CLIENT_CERTIFICATE")?; + log::info!( + "Using ca '{}' client certificate: '{}'", + ca.display(), + client_certificate, + ); Ok(Some(Self { - ca: tls.get_pathbuf(keys::CA).context("Bad/Missing CA")?, - client_certificate: tls - .get_string(keys::CLIENT_CERTIFICATE) - .map(|s| s.into()) - .context("bad/Missing CLIENT_CERTIFICATE")?, + ca, + client_certificate, })) } pub fn ca(&self) -> &Path { @@ -1512,14 +1519,24 @@ connection: #[test] fn test_get_additional_registry_instances() { // nothing found + fn print_array(a: &[CustomInstance]) -> String { + a.iter() + .map(|i| format!("{}: {}-{}", i.name(), i.conn().port(), i.is_tcp())) + .collect::>() + .join(", ") + } let auth = Authentication::default(); let conn = Connection::default(); let found: Vec = vec![]; let full = get_additional_registry_instances(&found, &auth, &conn); let full = filter_from_custom_instances(full); assert_eq!(full.len(), 3); - assert!(full.iter().all(|i| i.is_tcp())); - assert!(full.iter().all(|i| i.conn().port() >= Port(1433))); + assert!(full.iter().all(|i| i.is_tcp()), "{:?}", print_array(&full)); + assert!( + full.iter().all(|i| i.conn().port() >= Port(1433)), + "{:?}", + print_array(&full) + ); // one is found let found: Vec = vec![CustomInstance { diff --git a/packages/mk-sql/src/ms_sql/query.rs b/packages/mk-sql/src/ms_sql/query.rs index d1e78871252..2df5bd54497 100644 --- a/packages/mk-sql/src/ms_sql/query.rs +++ b/packages/mk-sql/src/ms_sql/query.rs @@ -162,7 +162,8 @@ pub async fn run_custom_query>( } let start = Instant::now(); let result = exec_sql(client, query).await; - log_query(start, &result, &make_short_query(query)); + log_query(start, &result, make_short_query(query)); + log::trace!("Full query: `{}`", query); result } @@ -209,12 +210,10 @@ async fn exec_sql(client: &mut UniClient, query: &str) -> Result> } } -fn make_short_query(query: &str) -> String { +fn make_short_query(query: &str) -> &str { query .get(0..std::cmp::min(16, query.len() - 1)) .unwrap_or_default() - .to_string() - + "..." } pub async fn obtain_computer_name(client: &mut UniClient) -> Result> {