Skip to content

Commit

Permalink
Throw in some DTrace probes
Browse files Browse the repository at this point in the history
  • Loading branch information
bnaecker committed Oct 20, 2023
1 parent 386708d commit 36c0b6e
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
14 changes: 13 additions & 1 deletion nexus/db-queries/src/db/datastore/vpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,10 @@ impl DataStore {
let vnis = VniSearchIter::new(vpc.vni.0);
for (i, vni) in vnis.enumerate() {
vpc.vni = Vni(vni);
let id = usdt::UniqueId::new();
crate::probes::vni__search__range__start!(|| {
(&id, u32::from(vni), VniSearchIter::STEP_SIZE)
});
match self
.project_create_vpc_raw(
opctx,
Expand All @@ -310,9 +314,15 @@ impl DataStore {
)
.await
{
Ok(Some(vpcs)) => return Ok(vpcs),
Ok(Some((authz_vpc, vpc))) => {
crate::probes::vni__search__range__found!(|| {
(&id, u32::from(vpc.vni.0))
});
return Ok((authz_vpc, vpc));
}
Err(e) => return Err(e),
Ok(None) => {
crate::probes::vni__search__range__empty!(|| (&id));
debug!(
opctx.log,
"No VNIs available within current search range, retrying";
Expand Down Expand Up @@ -1172,6 +1182,7 @@ mod tests {
// `project_create_vpc_raw` call.
#[tokio::test]
async fn test_project_create_vpc_raw_returns_none_on_vni_exhaustion() {
usdt::register_probes().unwrap();
let logctx = dev::test_setup_log(
"test_project_create_vpc_raw_returns_none_on_vni_exhaustion",
);
Expand Down Expand Up @@ -1277,6 +1288,7 @@ mod tests {
// and then check that we correctly retry
#[tokio::test]
async fn test_project_create_vpc_retries() {
usdt::register_probes().unwrap();
let logctx = dev::test_setup_log("test_project_create_vpc_retries");
let log = &logctx.log;
let mut db = test_setup_database(&logctx.log).await;
Expand Down
2 changes: 2 additions & 0 deletions nexus/db-queries/src/db/queries/vpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,8 @@ pub struct VniSearchIter {
}

impl VniSearchIter {
pub const STEP_SIZE: u32 = MAX_VNI_SEARCH_RANGE_SIZE;

/// Create a search range, starting from the provided VNI.
pub fn new(start: external::Vni) -> Self {
let start = u32::from(start);
Expand Down
14 changes: 14 additions & 0 deletions nexus/db-queries/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,17 @@ extern crate newtype_derive;
#[cfg(test)]
#[macro_use]
extern crate diesel;

#[usdt::provider(provider = "nexus__db__queries")]
mod probes {
// Fires before we start a search over a range for a VNI.
//
// Includes the starting VNI and the size of the range being searched.
fn vni__search__range__start(_: &usdt::UniqueId, start_vni: u32, size: u32) {}

// Fires when we successfully find a VNI.
fn vni__search__range__found(_: &usdt::UniqueId, vni: u32) {}

// Fires when we fail to find a VNI in the provided range.
fn vni__search__range__empty(_: &usdt::UniqueId) {}
}

0 comments on commit 36c0b6e

Please sign in to comment.