From e6cb51efd92e3b4c0ba94ace100bae740ebf6749 Mon Sep 17 00:00:00 2001 From: Benjamin Naecker Date: Thu, 31 Oct 2024 12:13:22 -0700 Subject: [PATCH] Update to qorb 0.2.0, now with USDT probes! --- Cargo.lock | 37 +++++++++-- Cargo.toml | 2 +- nexus/db-queries/src/db/pool.rs | 48 +++++++++----- .../app/sagas/common_storage/pantry_pool.rs | 7 +- oximeter/collector/src/lib.rs | 13 +++- oximeter/db/src/client/mod.rs | 64 +++++++++++++------ 6 files changed, 127 insertions(+), 44 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 4f3f315330..33e6e54b76 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4459,7 +4459,7 @@ dependencies = [ "omicron-uuid-kinds", "omicron-workspace-hack", "progenitor", - "qorb", + "qorb 0.2.0", "reqwest 0.12.8", "serde", "serde_json", @@ -5534,7 +5534,7 @@ dependencies = [ "pq-sys", "predicates", "pretty_assertions", - "qorb", + "qorb 0.2.0", "rand", "rcgen", "ref-cast", @@ -6639,7 +6639,7 @@ dependencies = [ "pretty_assertions", "progenitor-client", "propolis-client 0.1.0 (git+https://github.com/oxidecomputer/propolis?rev=86101eaf80b55e7f405b5cafe9b0de0e9f331656)", - "qorb", + "qorb 0.2.0", "rand", "rcgen", "ref-cast", @@ -7078,7 +7078,7 @@ dependencies = [ "postgres-types", "predicates", "proc-macro2", - "qorb", + "qorb 0.1.2", "quote", "rand", "regex", @@ -7470,7 +7470,7 @@ dependencies = [ "oximeter-api", "oximeter-client", "oximeter-db", - "qorb", + "qorb 0.2.0", "rand", "reqwest 0.12.8", "schemars", @@ -7525,7 +7525,7 @@ dependencies = [ "oximeter-test-utils", "oxql-types", "peg", - "qorb", + "qorb 0.2.0", "reedline", "regex", "reqwest 0.12.8", @@ -8743,6 +8743,31 @@ dependencies = [ "tracing", ] +[[package]] +name = "qorb" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9cd19ad8fae9abd8da01d8f435b633b567d53835cf3bce89d6f616617d10583c" +dependencies = [ + "anyhow", + "async-trait", + "debug-ignore", + "derive-where", + "dropshot", + "futures", + "hickory-resolver", + "rand", + "schemars", + "serde", + "serde_json", + "thiserror", + "tokio", + "tokio-stream", + "tokio-tungstenite 0.24.0", + "tracing", + "usdt", +] + [[package]] name = "quick-error" version = "1.2.3" diff --git a/Cargo.toml b/Cargo.toml index 84d93a1ec7..28e249f0ce 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -520,7 +520,7 @@ propolis_api_types = { git = "https://github.com/oxidecomputer/propolis", rev = propolis-client = { git = "https://github.com/oxidecomputer/propolis", rev = "86101eaf80b55e7f405b5cafe9b0de0e9f331656" } propolis-mock-server = { git = "https://github.com/oxidecomputer/propolis", rev = "86101eaf80b55e7f405b5cafe9b0de0e9f331656" } proptest = "1.5.0" -qorb = "0.1.2" +qorb = "0.2.0" quote = "1.0" rand = "0.8.5" rand_core = "0.6.4" diff --git a/nexus/db-queries/src/db/pool.rs b/nexus/db-queries/src/db/pool.rs index c42158a64f..61e1c91db1 100644 --- a/nexus/db-queries/src/db/pool.rs +++ b/nexus/db-queries/src/db/pool.rs @@ -89,12 +89,18 @@ impl Pool { let resolver = resolver.for_service(ServiceName::Cockroach); let connector = make_postgres_connector(log); - let policy = Policy::default(); - Pool { - inner: qorb::pool::Pool::new(resolver, connector, policy), - terminated: std::sync::atomic::AtomicBool::new(false), - } + let inner = match qorb::pool::Pool::new(resolver, connector, policy) { + Ok(pool) => { + debug!(log, "registered USDT probes"); + pool + } + Err(err) => { + error!(log, "failed to register USDT probes"); + err.into_inner() + } + }; + Pool { inner, terminated: std::sync::atomic::AtomicBool::new(false) } } /// Creates a new qorb-backed connection pool to a single instance of the @@ -110,12 +116,18 @@ impl Pool { let resolver = make_single_host_resolver(db_config); let connector = make_postgres_connector(log); - let policy = Policy::default(); - Pool { - inner: qorb::pool::Pool::new(resolver, connector, policy), - terminated: std::sync::atomic::AtomicBool::new(false), - } + let inner = match qorb::pool::Pool::new(resolver, connector, policy) { + Ok(pool) => { + debug!(log, "registered USDT probes"); + pool + } + Err(err) => { + error!(log, "failed to register USDT probes"); + err.into_inner() + } + }; + Pool { inner, terminated: std::sync::atomic::AtomicBool::new(false) } } /// Creates a new qorb-backed connection pool which returns an error @@ -134,15 +146,21 @@ impl Pool { let resolver = make_single_host_resolver(db_config); let connector = make_postgres_connector(log); - let policy = Policy { claim_timeout: tokio::time::Duration::from_millis(1), ..Default::default() }; - Pool { - inner: qorb::pool::Pool::new(resolver, connector, policy), - terminated: std::sync::atomic::AtomicBool::new(false), - } + let inner = match qorb::pool::Pool::new(resolver, connector, policy) { + Ok(pool) => { + debug!(log, "registered USDT probes"); + pool + } + Err(err) => { + error!(log, "failed to register USDT probes"); + err.into_inner() + } + }; + Pool { inner, terminated: std::sync::atomic::AtomicBool::new(false) } } /// Returns a connection from the pool diff --git a/nexus/src/app/sagas/common_storage/pantry_pool.rs b/nexus/src/app/sagas/common_storage/pantry_pool.rs index 9d1e76d27d..ae0ee3ce2a 100644 --- a/nexus/src/app/sagas/common_storage/pantry_pool.rs +++ b/nexus/src/app/sagas/common_storage/pantry_pool.rs @@ -84,9 +84,12 @@ impl backend::Connector for PantryConnector { pub(crate) fn make_pantry_connection_pool( qorb_resolver: &QorbResolver, ) -> pool::Pool { - pool::Pool::new( + match pool::Pool::new( qorb_resolver.for_service(ServiceName::CruciblePantry), Arc::new(PantryConnector), qorb::policy::Policy::default(), - ) + ) { + Ok(pool) => pool, + Err(e) => e.into_inner(), + } } diff --git a/oximeter/collector/src/lib.rs b/oximeter/collector/src/lib.rs index 6b10cf31cd..68fff4cbf0 100644 --- a/oximeter/collector/src/lib.rs +++ b/oximeter/collector/src/lib.rs @@ -344,11 +344,20 @@ impl Oximeter { )) }; - qorb::pool::Pool::new( + match qorb::pool::Pool::new( nexus_resolver, Arc::new(NexusConnector { log: log.clone() }), qorb::policy::Policy::default(), - ) + ) { + Ok(pool) => { + debug!(log, "registered USDT probes"); + pool + } + Err(err) => { + error!(log, "failed to register USDT probes"); + err.into_inner() + } + } }; let notify_nexus = || async { diff --git a/oximeter/db/src/client/mod.rs b/oximeter/db/src/client/mod.rs index 04caa13bd9..a4e73172cb 100644 --- a/oximeter/db/src/client/mod.rs +++ b/oximeter/db/src/client/mod.rs @@ -193,21 +193,39 @@ impl Client { )); let schema = Mutex::new(BTreeMap::new()); let request_timeout = DEFAULT_REQUEST_TIMEOUT; + let pool = match Pool::new( + http_resolver, + Arc::new(ReqwestConnector {}), + qorb::policy::Policy::default(), + ) { + Ok(pool) => { + debug!(log, "registered USDT probes"); + pool + } + Err(err) => { + error!(log, "failed to register USDT probes"); + err.into_inner() + } + }; + let native_pool = match Pool::new( + native_resolver, + Arc::new(native::connection::Connector), + qorb::policy::Policy::default(), + ) { + Ok(pool) => { + debug!(log, "registered USDT probes"); + pool + } + Err(err) => { + error!(log, "failed to register USDT probes"); + err.into_inner() + } + }; Self { _id: id, log, - source: ClientSource::Pool { - pool: DebugIgnore(Pool::new( - http_resolver, - Arc::new(ReqwestConnector {}), - qorb::policy::Policy::default(), - )), - }, - native_pool: DebugIgnore(Pool::new( - native_resolver, - Arc::new(native::connection::Connector), - Default::default(), - )), + source: ClientSource::Pool { pool: DebugIgnore(pool) }, + native_pool: DebugIgnore(native_pool), schema, request_timeout, } @@ -243,15 +261,25 @@ impl Client { let client = reqwest::Client::new(); let url = format!("http://{}", http_address); let schema = Mutex::new(BTreeMap::new()); + let native_pool = match Pool::new( + Box::new(SingleHostResolver::new(native_address)), + Arc::new(native::connection::Connector), + Default::default(), + ) { + Ok(pool) => { + debug!(log, "registered USDT probes"); + pool + } + Err(err) => { + error!(log, "failed to register USDT probes"); + err.into_inner() + } + }; Self { _id: id, log, source: ClientSource::Static(ReqwestClient { url, client }), - native_pool: DebugIgnore(Pool::new( - Box::new(SingleHostResolver::new(native_address)), - Arc::new(native::connection::Connector), - Default::default(), - )), + native_pool: DebugIgnore(native_pool), schema, request_timeout, } @@ -1787,7 +1815,7 @@ mod tests { .ping() .await .expect_err("Should fail to ping non-existent server"); - let Error::Connection(qorb::pool::Error::TimedOut) = &e else { + let Error::Connection(_) = &e else { panic!("Expected connection error, found {e:?}"); }; logctx.cleanup_successful();