Skip to content

Commit

Permalink
mk-sql: better logging
Browse files Browse the repository at this point in the history
Change-Id: Id9b4cd19dc4111e8f6257641c1e080129b4973be
  • Loading branch information
s-kipnis committed Jan 13, 2025
1 parent 40d8453 commit d007313
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 11 deletions.
31 changes: 24 additions & 7 deletions packages/mk-sql/src/config/ms_sql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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::<Vec<String>>()
.join(", ")
}
let auth = Authentication::default();
let conn = Connection::default();
let found: Vec<CustomInstance> = 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<CustomInstance> = vec![CustomInstance {
Expand Down
7 changes: 3 additions & 4 deletions packages/mk-sql/src/ms_sql/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,8 @@ pub async fn run_custom_query<T: AsRef<str>>(
}
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
}

Expand Down Expand Up @@ -209,12 +210,10 @@ async fn exec_sql(client: &mut UniClient, query: &str) -> Result<Vec<UniAnswer>>
}
}

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<Option<ComputerName>> {
Expand Down

0 comments on commit d007313

Please sign in to comment.