Skip to content

Commit

Permalink
move metrics stuff to the config file
Browse files Browse the repository at this point in the history
  • Loading branch information
hawkw committed Aug 18, 2024
1 parent 62c1e7c commit 756002c
Show file tree
Hide file tree
Showing 12 changed files with 303 additions and 146 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions dev-tools/mgs-dev/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ futures.workspace = true
gateway-messages.workspace = true
gateway-test-utils.workspace = true
libc.workspace = true
omicron-gateway.workspace = true
omicron-workspace-hack.workspace = true
signal-hook-tokio.workspace = true
tokio.workspace = true
32 changes: 23 additions & 9 deletions dev-tools/mgs-dev/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use clap::{Args, Parser, Subcommand};
use futures::StreamExt;
use libc::SIGINT;
use signal_hook_tokio::Signals;
use std::net::SocketAddr;

#[tokio::main]
async fn main() -> anyhow::Result<()> {
Expand Down Expand Up @@ -37,8 +38,10 @@ enum MgsDevCmd {

#[derive(Clone, Debug, Args)]
struct MgsRunArgs {
#[clap(flatten)]
mgs_metrics_args: gateway_test_utils::setup::MgsMetricsArgs,
/// Override the address of the Nexus instance to use when registering the
/// Oximeter producer.
#[clap(long)]
nexus_address: Option<SocketAddr>,
}

impl MgsRunArgs {
Expand All @@ -49,13 +52,24 @@ impl MgsRunArgs {
let mut signal_stream = signals.fuse();

println!("mgs-dev: setting up MGS ... ");
let gwtestctx =
gateway_test_utils::setup::test_setup_with_metrics_args(
"mgs-dev",
gateway_messages::SpPort::One,
self.mgs_metrics_args,
)
.await;
let (mut mgs_config, sp_sim_config) =
gateway_test_utils::setup::load_test_config();
if let Some(addr) = self.nexus_address {
mgs_config.metrics.dev =
Some(omicron_gateway::metrics::DevConfig {
bind_loopback: true,
nexus_address: Some(addr),
});
}

let gwtestctx = gateway_test_utils::setup::test_setup_with_config(
"mgs-dev",
gateway_messages::SpPort::One,
mgs_config,
&sp_sim_config,
None,
)
.await;
println!("mgs-dev: MGS is running.");

let addr = gwtestctx.client.bind_address;
Expand Down
11 changes: 11 additions & 0 deletions gateway-test-utils/configs/config.test.toml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,17 @@ addr = "[::1]:0"
ignition-target = 3
location = { switch0 = ["sled", 1], switch1 = ["sled", 1] }

#
# Configuration for SP sensor metrics polling
#
[metrics]
# Bryan wants to try polling SP sensors at 1Hz.
sp_poll_interval_ms = 1000
# Tell Oximeter to collect our metrics every 10 seconds.
oximeter_collection_interval_secs = 10
# Allow binding the metrics server on localhost.
dev = { bind_loopback = true }

#
# NOTE: for the test suite, if mode = "file", the file path MUST be the sentinel
# string "UNUSED". The actual path will be generated by the test suite for each
Expand Down
23 changes: 1 addition & 22 deletions gateway-test-utils/src/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use camino::Utf8Path;
use dropshot::test_util::ClientTestContext;
use dropshot::test_util::LogContext;
use gateway_messages::SpPort;
pub use omicron_gateway::metrics::Args as MgsMetricsArgs;
use omicron_gateway::MgsArguments;
use omicron_gateway::SpType;
use omicron_gateway::SwitchPortConfig;
Expand Down Expand Up @@ -70,24 +69,6 @@ pub async fn test_setup(
server_config,
&sp_sim_config,
None,
Default::default(),
)
.await
}

pub async fn test_setup_with_metrics_args(
test_name: &str,
sp_port: SpPort,
metrics_args: MgsMetricsArgs,
) -> GatewayTestContext {
let (server_config, sp_sim_config) = load_test_config();
test_setup_with_config(
test_name,
sp_port,
server_config,
&sp_sim_config,
None,
metrics_args,
)
.await
}
Expand Down Expand Up @@ -118,7 +99,6 @@ pub async fn test_setup_with_config(
mut server_config: omicron_gateway::Config,
sp_sim_config: &sp_sim::Config,
listen_addr: Option<SocketAddrV6>,
metrics_args: MgsMetricsArgs,
) -> GatewayTestContext {
// Can't be `const` because `SocketAddrV6::new()` isn't const yet
let localhost_port_0 = SocketAddrV6::new(Ipv6Addr::LOCALHOST, 0, 0, 0);
Expand Down Expand Up @@ -164,8 +144,7 @@ pub async fn test_setup_with_config(
// Start gateway server
let rack_id = Some(Uuid::parse_str(RACK_UUID).unwrap());

let args =
MgsArguments { id: Uuid::new_v4(), addresses, rack_id, metrics_args };
let args = MgsArguments { id: Uuid::new_v4(), addresses, rack_id };
let server = omicron_gateway::Server::start(
server_config.clone(),
args,
Expand Down
9 changes: 9 additions & 0 deletions gateway/examples/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,15 @@ addr = "[::1]:33320"
ignition-target = 3
location = { switch0 = ["sled", 1], switch1 = ["sled", 1] }

#
# Configuration for SP sensor metrics polling
#
[metrics]
# Bryan wants to try polling SP sensors at 1Hz.
sp_poll_interval_ms = 1000
# Tell Oximeter to collect our metrics every 10 seconds.
oximeter_collection_interval_secs = 10

[log]
# Show log messages of this level and more severe
level = "debug"
Expand Down
6 changes: 1 addition & 5 deletions gateway/src/bin/mgs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,6 @@ enum Args {
required_unless_present = "id_and_address_from_smf"
)]
address: Option<SocketAddrV6>,

#[clap(flatten)]
metrics_args: omicron_gateway::metrics::Args,
},
}

Expand All @@ -76,7 +73,6 @@ async fn do_run() -> Result<(), CmdError> {
id_and_address_from_smf,
id,
address,
metrics_args,
} => {
let config = Config::from_file(&config_file_path)
.map_err(anyhow::Error::new)
Expand All @@ -96,7 +92,7 @@ async fn do_run() -> Result<(), CmdError> {
// `id_and_address_from_smf` is false, so we can safely unwrap.
(id.unwrap(), vec![address.unwrap()], rack_id)
};
let args = MgsArguments { id, addresses, rack_id, metrics_args };
let args = MgsArguments { id, addresses, rack_id };
let mut server = start_server(config, args)
.await
.map_err(|e| CmdError::Failure(anyhow!(e)))?;
Expand Down
3 changes: 3 additions & 0 deletions gateway/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
//! configuration
use crate::management_switch::SwitchConfig;
use crate::metrics::MetricsConfig;
use camino::Utf8Path;
use camino::Utf8PathBuf;
use dropshot::ConfigLogging;
Expand All @@ -25,6 +26,8 @@ pub struct Config {
pub switch: SwitchConfig,
/// Server-wide logging configuration.
pub log: ConfigLogging,
/// Configuration for SP sensor metrics.
pub metrics: MetricsConfig,
}

impl Config {
Expand Down
10 changes: 5 additions & 5 deletions gateway/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ pub struct MgsArguments {
pub id: Uuid,
pub addresses: Vec<SocketAddrV6>,
pub rack_id: Option<Uuid>,
pub metrics_args: metrics::Args,
}

type HttpServer = dropshot::HttpServer<Arc<ServerContext>>;
Expand Down Expand Up @@ -155,10 +154,11 @@ impl Server {
let mut http_servers = HashMap::with_capacity(args.addresses.len());
let all_servers_shutdown = FuturesUnordered::new();

let metrics = metrics::Metrics::new(&log, &args, apictx.clone())
.map_err(|err| {
format!("failed to initialize metrics subsystem: {err}")
})?;
let metrics =
metrics::Metrics::new(&log, &args, config.metrics, apictx.clone())
.map_err(|err| {
format!("failed to initialize metrics subsystem: {err}")
})?;

for addr in args.addresses {
start_dropshot_server(
Expand Down
Loading

0 comments on commit 756002c

Please sign in to comment.