-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
224 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,15 +10,17 @@ use clap::Parser; | |
use omicron_common::cmd::fatal; | ||
use omicron_common::cmd::CmdError; | ||
use oximeter_collector::oximeter_api; | ||
use oximeter_collector::standalone_nexus_api; | ||
use oximeter_collector::Config; | ||
use oximeter_collector::Oximeter; | ||
use oximeter_collector::OximeterArguments; | ||
use oximeter_collector::ProducerInfo; | ||
use std::net::Ipv6Addr; | ||
use std::net::SocketAddr; | ||
use std::net::SocketAddrV6; | ||
use std::path::PathBuf; | ||
use uuid::Uuid; | ||
use oximeter_collector::StandaloneNexus; | ||
use oximeter_collector::Error; | ||
|
||
pub fn run_openapi() -> Result<(), String> { | ||
oximeter_api() | ||
|
@@ -30,6 +32,16 @@ pub fn run_openapi() -> Result<(), String> { | |
.map_err(|e| e.to_string()) | ||
} | ||
|
||
pub fn run_standalone_openapi() -> Result<(), String> { | ||
standalone_nexus_api() | ||
.openapi("Oxide Nexus API", "0.0.1") | ||
.description("API for interacting with Nexus") | ||
.contact_url("https://oxide.computer") | ||
.contact_email("[email protected]") | ||
.write(&mut std::io::stdout()) | ||
.map_err(|e| e.to_string()) | ||
} | ||
|
||
/// Run an oximeter metric collection server in the Oxide Control Plane. | ||
#[derive(Parser)] | ||
#[clap(name = "oximeter", about = "See README.adoc for more information")] | ||
|
@@ -60,13 +72,6 @@ enum Args { | |
/// producers to collect from, and optionally the location of a ClickHouse | ||
/// database in which to insert records. | ||
Standalone { | ||
/// A list of producers to start collecting data from automatically. | ||
/// | ||
/// Producers are listed as a set of comma-delimited strings. Each item | ||
/// is formatted like `<uuid>@<address>`. | ||
#[arg(value_delimiter = ',', num_args = 0..)] | ||
producers: Vec<ProducerInfo>, | ||
|
||
/// The ID for the collector. | ||
/// | ||
/// Default is to generate a new, random UUID. | ||
|
@@ -83,13 +88,28 @@ enum Args { | |
)] | ||
address: SocketAddrV6, | ||
|
||
/// The address for the fake Nexus server used to register. | ||
/// | ||
/// This program starts a fake version of Nexus, which is used only to | ||
/// register the producers and collectors. This allows them to operate | ||
/// as they usually would, registering each other with Nexus so that an | ||
/// assignment between them can be made. | ||
#[arg( | ||
long, | ||
default_value_t = SocketAddrV6::new(Ipv6Addr::LOCALHOST, 0, 0, 0) | ||
)] | ||
nexus: SocketAddrV6, | ||
|
||
/// The address for ClickHouse. | ||
/// | ||
/// If not provided, `oximeter` will not attempt to insert records into | ||
/// the database at all. | ||
#[arg(short, long)] | ||
#[arg(long)] | ||
clickhouse: Option<SocketAddr>, | ||
}, | ||
|
||
/// Print the fake Nexus's standalone API. | ||
StandaloneOpenapi, | ||
} | ||
|
||
#[tokio::main] | ||
|
@@ -113,14 +133,29 @@ async fn do_run() -> Result<(), CmdError> { | |
.await | ||
.map_err(|e| CmdError::Failure(e.to_string())) | ||
} | ||
Args::Standalone { producers, id, address, clickhouse } => { | ||
Args::Standalone { id, address, nexus, clickhouse } => { | ||
// Start the standalone Nexus server, for registration of both the | ||
// collector and producers. | ||
let nexus_server = run_standalone_nexus(nexus).await.map_err(|e| CmdError::Failure(e.to_string()))?; | ||
let args = OximeterArguments { id, address }; | ||
Oximeter::new_standalone(&args, clickhouse, &producers) | ||
Oximeter::new_standalone( | ||
nexus_server.log(), | ||
&args, | ||
nexus_server.local_addr(), | ||
clickhouse | ||
) | ||
.await | ||
.unwrap() | ||
.serve_forever() | ||
.await | ||
.map_err(|e| CmdError::Failure(e.to_string())) | ||
} | ||
Args::StandaloneOpenapi => { | ||
run_standalone_openapi().map_err(CmdError::Failure) | ||
} | ||
} | ||
} | ||
|
||
async fn run_standalone_nexus(addr: SocketAddrV6) -> Result<StandaloneNexus, Error> { | ||
StandaloneNexus::new(addr.into()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.