Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test oximeter metrics end to end #855

Merged
merged 15 commits into from
Mar 14, 2025
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 16 additions & 2 deletions phd-tests/framework/src/test_vm/environment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.

use std::net::{Ipv4Addr, SocketAddrV4};
use std::net::{Ipv4Addr, SocketAddr, SocketAddrV4};

use anyhow::Context;

Expand All @@ -20,11 +20,16 @@ pub enum VmLocation {
pub struct EnvironmentSpec {
pub(crate) location: VmLocation,
pub(crate) propolis_artifact: String,
pub(crate) metrics_addr: Option<SocketAddr>,
}

impl EnvironmentSpec {
pub(crate) fn new(location: VmLocation, propolis_artifact: &str) -> Self {
Self { location, propolis_artifact: propolis_artifact.to_owned() }
Self {
location,
propolis_artifact: propolis_artifact.to_owned(),
metrics_addr: None,
}
}

pub fn location(&mut self, location: VmLocation) -> &mut Self {
Expand All @@ -37,6 +42,14 @@ impl EnvironmentSpec {
self
}

pub fn metrics_addr(
&mut self,
metrics_addr: Option<SocketAddr>,
) -> &mut Self {
self.metrics_addr = metrics_addr;
self
}

pub(crate) async fn build<'a>(
&self,
framework: &'a Framework,
Expand Down Expand Up @@ -82,6 +95,7 @@ impl<'a> Environment<'a> {
Ipv4Addr::new(127, 0, 0, 1),
server_port,
),
metrics_addr: builder.metrics_addr,
vnc_addr: SocketAddrV4::new(
Ipv4Addr::new(127, 0, 0, 1),
vnc_port,
Expand Down
22 changes: 13 additions & 9 deletions phd-tests/framework/src/test_vm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,15 @@ impl TestVm {
self.environment_spec.clone()
}

pub fn instance_properties(&self) -> InstanceProperties {
InstanceProperties {
id: self.id,
name: format!("phd-vm-{}", self.id),
metadata: self.spec.metadata.clone(),
description: "Pheidippides-managed VM".to_string(),
}
}

/// Sends an instance ensure request to this VM's server, allowing it to
/// transition into the running state.
#[instrument(skip_all, fields(vm = self.spec.vm_name, vm_id = %self.id))]
Expand All @@ -282,13 +291,6 @@ impl TestVm {
return Err(VmStateError::InstanceAlreadyEnsured.into());
}

let properties = InstanceProperties {
id: self.id,
name: format!("phd-vm-{}", self.id),
metadata: self.spec.metadata.clone(),
description: "Pheidippides-managed VM".to_string(),
};

let init = match migrate {
None => InstanceInitializationMethod::Spec {
spec: self.spec.instance_spec.clone(),
Expand All @@ -299,8 +301,10 @@ impl TestVm {
src_addr: info.src_addr.to_string(),
},
};
let ensure_req =
InstanceEnsureRequest { properties: properties.clone(), init };
let ensure_req = InstanceEnsureRequest {
properties: self.instance_properties(),
init,
};

// There is a brief period where the Propolis server process has begun
// to run but hasn't started its Dropshot server yet. Ensure requests
Expand Down
37 changes: 26 additions & 11 deletions phd-tests/framework/src/test_vm/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@

//! Routines and data structures for working with Propolis server processes.

use std::{fmt::Debug, net::SocketAddrV4, os::unix::process::CommandExt};
use std::{
fmt::Debug,
net::{SocketAddr, SocketAddrV4},
os::unix::process::CommandExt,
};

use anyhow::Result;
use camino::{Utf8Path, Utf8PathBuf};
Expand All @@ -27,6 +31,10 @@ pub struct ServerProcessParameters<'a> {
/// The address at which the server should serve.
pub server_addr: SocketAddrV4,

/// The address of HTTP server with which the spawned server should register
/// as an Oximeter producer.
pub metrics_addr: Option<SocketAddr>,

/// The address at which the server should offer its VNC server.
pub vnc_addr: SocketAddrV4,

Expand All @@ -48,6 +56,7 @@ impl PropolisServer {
server_path,
data_dir,
server_addr,
metrics_addr,
vnc_addr,
log_mode,
} = process_params;
Expand All @@ -62,17 +71,23 @@ impl PropolisServer {
let (server_stdout, server_stderr) =
log_mode.get_handles(&data_dir, vm_name)?;

let mut args = vec![server_path.into_string(), "run".to_string()];

if let Some(metrics_addr) = metrics_addr {
args.extend_from_slice(&[
"--metric-addr".to_string(),
metrics_addr.to_string(),
]);
}

args.extend_from_slice(&[
bootrom_path.as_str().to_string(),
server_addr.to_string(),
vnc_addr.to_string(),
]);

let mut server_cmd = std::process::Command::new("pfexec");
server_cmd
.args([
server_path.as_str(),
"run",
bootrom_path.as_str(),
server_addr.to_string().as_str(),
vnc_addr.to_string().as_str(),
])
.stdout(server_stdout)
.stderr(server_stderr);
server_cmd.args(args).stdout(server_stdout).stderr(server_stderr);

// Gracefully shutting down a Propolis server requires PHD to send an
// instance stop request to the server before it is actually terminated.
Expand Down
14 changes: 12 additions & 2 deletions phd-tests/tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,23 @@ doctest = false

[dependencies]
anyhow.workspace = true
backoff.workspace = true
byteorder.workspace = true
chrono.workspace = true
cpuid_utils.workspace = true
dropshot.workspace = true
futures.workspace = true
itertools.workspace = true
http.workspace = true
propolis-client.workspace = true
itertools.workspace = true
omicron-common.workspace = true
oximeter-producer.workspace = true
oximeter.workspace = true
phd-testcase.workspace = true
propolis-client.workspace = true
reqwest.workspace = true
slog-term.workspace = true
slog.workspace = true
strum.workspace = true
tokio.workspace = true
tracing.workspace = true
uuid.workspace = true
1 change: 1 addition & 0 deletions phd-tests/tests/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ mod hw;
mod migrate;
mod server_state_machine;
mod smoke;
mod stats;
Loading
Loading