Skip to content

Commit bd828df

Browse files
committed
instrument instead of manually entering spans
1 parent ff41adc commit bd828df

File tree

2 files changed

+29
-23
lines changed
  • phd-tests

2 files changed

+29
-23
lines changed

phd-tests/framework/src/test_vm/mod.rs

+27-18
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,6 @@ pub struct TestVm {
145145
data_dir: Utf8PathBuf,
146146

147147
guest_os: Box<dyn GuestOs>,
148-
tracing_span: tracing::Span,
149148

150149
state: VmState,
151150

@@ -229,9 +228,6 @@ impl TestVm {
229228
)
230229
})?;
231230

232-
let span =
233-
info_span!(parent: None, "VM", vm = %vm_spec.vm_name, %vm_id);
234-
235231
let data_dir = params.data_dir.to_path_buf();
236232
let server_addr = params.server_addr;
237233
let server = server::PropolisServer::new(
@@ -250,7 +246,6 @@ impl TestVm {
250246
environment_spec,
251247
data_dir,
252248
guest_os,
253-
tracing_span: span,
254249
state: VmState::New,
255250
cleanup_task_tx,
256251
})
@@ -274,12 +269,12 @@ impl TestVm {
274269

275270
/// Sends an instance ensure request to this VM's server, allowing it to
276271
/// transition into the running state.
272+
#[instrument(skip_all, fields(vm = self.spec.vm_name, vm_id = %self.id))]
277273
async fn instance_ensure_internal<'a>(
278274
&self,
279275
migrate: Option<InstanceMigrateInitiateRequest>,
280276
console_source: InstanceConsoleSource<'a>,
281277
) -> Result<SerialConsole> {
282-
let _span = self.tracing_span.enter();
283278
let (vcpus, memory_mib) = match self.state {
284279
VmState::New => (
285280
self.spec.instance_spec.devices.board.cpus,
@@ -435,18 +430,18 @@ impl TestVm {
435430
self.put_instance_state(InstanceStateRequested::Reboot).await
436431
}
437432

433+
#[instrument(skip_all, fields(vm = self.spec.vm_name, vm_id = %self.id))]
438434
async fn put_instance_state(
439435
&self,
440436
state: InstanceStateRequested,
441437
) -> PropolisClientResult<()> {
442-
let _span = self.tracing_span.enter();
443438
info!(?state, "Requesting instance state change");
444439
self.client.instance_state_put().body(state).send().await
445440
}
446441

447442
/// Issues a Propolis client `instance_get` request.
443+
#[instrument(skip_all, fields(vm = self.spec.vm_name, vm_id = %self.id))]
448444
pub async fn get(&self) -> Result<InstanceGetResponse> {
449-
let _span = self.tracing_span.enter();
450445
info!("Sending instance get request to server");
451446
self.client
452447
.instance_get()
@@ -456,8 +451,8 @@ impl TestVm {
456451
.with_context(|| anyhow!("failed to query instance properties"))
457452
}
458453

454+
#[instrument(skip_all, fields(vm = self.spec.vm_name, vm_id = %self.id))]
459455
pub async fn get_spec(&self) -> Result<InstanceSpecGetResponse> {
460-
let _span = self.tracing_span.enter();
461456
info!("Sending instance spec get request to server");
462457
self.client
463458
.instance_spec_get()
@@ -469,6 +464,15 @@ impl TestVm {
469464

470465
/// Starts this instance by issuing an ensure request that specifies a
471466
/// migration from `source` and then running the target.
467+
#[instrument(
468+
skip_all,
469+
fields(
470+
source = source.spec.vm_name,
471+
target = self.spec.vm_name,
472+
source_id = %source.id,
473+
target_id = %self.id
474+
)
475+
)]
472476
pub async fn migrate_from(
473477
&mut self,
474478
source: &Self,
@@ -485,7 +489,6 @@ impl TestVm {
485489
}
486490
};
487491

488-
let _vm_guard = self.tracing_span.enter();
489492
match self.state {
490493
VmState::New => {
491494
let server_addr = source
@@ -582,12 +585,12 @@ impl TestVm {
582585
.into_inner())
583586
}
584587

588+
#[instrument(skip_all, fields(vm = self.spec.vm_name, vm_id = %self.id))]
585589
pub async fn wait_for_state(
586590
&self,
587591
target: InstanceState,
588592
timeout_duration: Duration,
589593
) -> Result<()> {
590-
let _span = self.tracing_span.enter();
591594
info!(
592595
"Waiting {:?} for server to reach state {:?}",
593596
timeout_duration, target
@@ -633,11 +636,15 @@ impl TestVm {
633636
/// initial login prompt and the login prompt itself.
634637
pub async fn wait_to_boot(&self) -> Result<()> {
635638
let timeout_duration = Duration::from_secs(300);
636-
let _span = self.tracing_span.enter();
637-
info!("Waiting {:?} for guest to boot", timeout_duration);
638-
639639
let boot_sequence = self.guest_os.get_login_sequence();
640640
let boot = async move {
641+
info!(
642+
vm = self.spec.vm_name,
643+
vm_id = %self.id,
644+
?timeout_duration,
645+
"waiting for guest to boot"
646+
);
647+
641648
for step in boot_sequence.0 {
642649
debug!(?step, "executing command in boot sequence");
643650
match step {
@@ -660,6 +667,8 @@ impl TestVm {
660667
}
661668
}
662669
}
670+
671+
info!("Guest has booted");
663672
Ok::<(), anyhow::Error>(())
664673
}
665674
.instrument(info_span!("wait_to_boot"));
@@ -671,19 +680,18 @@ impl TestVm {
671680
}
672681
};
673682

674-
info!("Guest has booted");
675683
Ok(())
676684
}
677685

678686
/// Waits for up to `timeout_duration` for `line` to appear on the guest
679687
/// serial console, then returns the unconsumed portion of the serial
680688
/// console buffer that preceded the requested string.
689+
#[instrument(skip_all, fields(vm = self.spec.vm_name, vm_id = %self.id))]
681690
pub async fn wait_for_serial_output(
682691
&self,
683692
line: &str,
684693
timeout_duration: impl Into<SerialOutputTimeout>,
685694
) -> Result<String> {
686-
let _span = self.tracing_span.enter();
687695
let timeout_duration: SerialOutputTimeout = timeout_duration.into();
688696
info!(
689697
target = line,
@@ -825,7 +833,6 @@ impl Drop for TestVm {
825833
// for all under-destruction VMs to be reaped before exiting.
826834
let client = self.client.clone();
827835
let server = self.server.take();
828-
let span = self.tracing_span.clone();
829836
let task = tokio::spawn(
830837
async move {
831838
let _server = server;
@@ -890,7 +897,9 @@ impl Drop for TestVm {
890897
error!(%e, "dropped VM not destroyed after 5 seconds");
891898
}
892899
}
893-
.instrument(span),
900+
.instrument(
901+
info_span!("VM cleanup", vm = self.spec.vm_name, vm_id = %self.id),
902+
),
894903
);
895904

896905
let _ = self.cleanup_task_tx.send(task);

phd-tests/testcase_macro/src/lib.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,12 @@ pub fn phd_testcase(_attrib: TokenStream, input: TokenStream) -> TokenStream {
4646
let fn_block = item_fn.block.stmts;
4747

4848
let remade_fn = quote! {
49-
#[tracing::instrument(level = "info",
50-
name = #fn_name,
51-
fields(module = module_path!()),
52-
skip_all)]
5349
#fn_vis #fn_sig -> TestOutcome {
50+
use tracing::Instrument;
5451
let res: phd_testcase::Result<()> = async {
5552
#(#fn_block)*
5653
Ok(())
57-
}.await;
54+
}.instrument(tracing::info_span!(#fn_name, module = module_path!())).await;
5855
match res {
5956
Ok(()) => phd_testcase::TestOutcome::Passed,
6057
Err(e) => {

0 commit comments

Comments
 (0)