Skip to content

Commit

Permalink
rebase
Browse files Browse the repository at this point in the history
Created using spr 1.3.6-beta.1
  • Loading branch information
sunshowers committed Apr 26, 2024
2 parents 74cb252 + 154ac22 commit 6ec688a
Show file tree
Hide file tree
Showing 53 changed files with 3,933 additions and 8,572 deletions.
6 changes: 6 additions & 0 deletions Cargo.lock

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

15 changes: 12 additions & 3 deletions common/src/api/internal/nexus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,8 @@ pub struct ProducerEndpoint {
/// The IP address and port at which `oximeter` can collect metrics from the
/// producer.
pub address: SocketAddr,
/// The API base route from which `oximeter` can collect metrics.
///
/// The full route is `{base_route}/{id}`.
/// NOTE: This field is deprecated, and will be ignored. It will be removed
/// in future releases.
pub base_route: String,
/// The interval on which `oximeter` should collect metrics.
pub interval: Duration,
Expand All @@ -125,6 +124,16 @@ impl ProducerEndpoint {
}
}

/// Response to a successful producer registration.
#[derive(Clone, Debug, Deserialize, JsonSchema, PartialEq, Serialize)]
pub struct ProducerRegistrationResponse {
/// Period within which producers must renew their lease.
///
/// Producers are required to periodically re-register with Nexus, to ensure
/// that they are still collected from by `oximeter`.
pub lease_duration: Duration,
}

/// An identifier for a single update artifact.
#[derive(
Clone,
Expand Down
32 changes: 27 additions & 5 deletions dev-tools/omdb/src/bin/omdb/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ use nexus_types::deployment::BlueprintZoneDisposition;
use nexus_types::deployment::BlueprintZoneFilter;
use nexus_types::deployment::BlueprintZoneType;
use nexus_types::deployment::SledFilter;
use nexus_types::external_api::views::SledPolicy;
use nexus_types::external_api::views::SledState;
use nexus_types::identity::Resource;
use nexus_types::internal_api::params::DnsRecord;
use nexus_types::internal_api::params::Srv;
Expand Down Expand Up @@ -253,7 +255,7 @@ enum DbCommands {
/// Save the current Reconfigurator inputs to a file
ReconfiguratorSave(ReconfiguratorSaveArgs),
/// Print information about sleds
Sleds,
Sleds(SledsArgs),
/// Print information about customer instances
Instances(InstancesOptions),
/// Print information about the network
Expand Down Expand Up @@ -398,6 +400,13 @@ struct ReconfiguratorSaveArgs {
output_file: Utf8PathBuf,
}

#[derive(Debug, Args)]
struct SledsArgs {
/// Show sleds that match the given filter
#[clap(short = 'F', long, value_enum)]
filter: Option<SledFilter>,
}

#[derive(Debug, Args)]
struct NetworkArgs {
#[command(subcommand)]
Expand Down Expand Up @@ -506,8 +515,8 @@ impl DbArgs {
)
.await
}
DbCommands::Sleds => {
cmd_db_sleds(&opctx, &datastore, &self.fetch_opts).await
DbCommands::Sleds(args) => {
cmd_db_sleds(&opctx, &datastore, &self.fetch_opts, args).await
}
DbCommands::Instances(instances_options) => {
cmd_db_instances(
Expand Down Expand Up @@ -1417,6 +1426,8 @@ struct SledRow {
serial: String,
ip: String,
role: &'static str,
policy: SledPolicy,
state: SledState,
id: Uuid,
}

Expand All @@ -1427,6 +1438,8 @@ impl From<Sled> for SledRow {
serial: s.serial_number().to_string(),
ip: s.address().to_string(),
role: if s.is_scrimlet() { "scrimlet" } else { "-" },
policy: s.policy(),
state: s.state().into(),
}
}
}
Expand All @@ -1436,18 +1449,27 @@ async fn cmd_db_sleds(
opctx: &OpContext,
datastore: &DataStore,
fetch_opts: &DbFetchOptions,
args: &SledsArgs,
) -> Result<(), anyhow::Error> {
let limit = fetch_opts.fetch_limit;
let filter = match args.filter {
Some(filter) => filter,
None => {
eprintln!("note: listing all sleds (use -F to filter, e.g. -F in-service)");
SledFilter::All
}
};

let sleds = datastore
.sled_list(&opctx, &first_page(limit), SledFilter::All)
.sled_list(&opctx, &first_page(limit), filter)
.await
.context("listing sleds")?;
check_limit(&sleds, limit, || String::from("listing sleds"));

let rows = sleds.into_iter().map(|s| SledRow::from(s));
let table = tabled::Table::new(rows)
.with(tabled::settings::Style::empty())
.with(tabled::settings::Padding::new(0, 1, 0, 0))
.with(tabled::settings::Padding::new(1, 1, 0, 0))
.to_string();

println!("{}", table);
Expand Down
66 changes: 65 additions & 1 deletion dev-tools/omdb/src/bin/omdb/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,16 @@
//! find strange things when debugging but we need our tools to tell us as
//! much as they can!)
use anyhow::anyhow;
use anyhow::ensure;
use anyhow::Context;
use clap::Parser;
use clap::Subcommand;
use futures::StreamExt;
use omicron_common::address::Ipv6Subnet;
use std::net::SocketAddr;
use std::net::SocketAddrV6;
use tokio::net::TcpSocket;

mod crucible_agent;
mod db;
Expand Down Expand Up @@ -87,7 +91,7 @@ struct Omdb {
dns_server: Option<SocketAddr>,

/// Allow potentially-destructive subcommands.
#[arg(short = 'w', long = "destructive", global = true)]
#[arg(short = 'w', long = "destructive")]
allow_destructive: bool,

#[command(subcommand)]
Expand Down Expand Up @@ -117,6 +121,7 @@ mod check_allow_destructive {
}

impl Omdb {
/// Return the socket addresses of all instances of a service in DNS
async fn dns_lookup_all(
&self,
log: slog::Logger,
Expand All @@ -129,6 +134,65 @@ impl Omdb {
.with_context(|| format!("looking up {:?} in DNS", service_name))
}

/// Return the socket address of one instance of a service that we can at
/// least successfully connect to
async fn dns_lookup_one(
&self,
log: slog::Logger,
service_name: internal_dns::ServiceName,
) -> Result<SocketAddrV6, anyhow::Error> {
let addrs = self.dns_lookup_all(log, service_name).await?;
ensure!(
!addrs.is_empty(),
"expected at least one address from successful DNS lookup for {:?}",
service_name
);

// The caller is going to pick one of these addresses to connect to.
// Let's try to pick one that's at least not obviously broken by
// attempting to connect to whatever we found and returning any that we
// successfully connected to. It'd be nice if we could return the
// socket directly, but our callers are creating reqwest clients that
// cannot easily consume a socket directly.
//
// This approach scales poorly and there are many failure modes that
// this does not cover. But in the absence of better connection
// management, and with the risks in `omdb` being pretty low, and the
// value of it working pretty high, here we are. This approach should
// not be replicated elsewhere.
async fn try_connect(
sockaddr_v6: SocketAddrV6,
) -> Result<(), anyhow::Error> {
let _ = TcpSocket::new_v6()
.context("creating socket")?
.connect(SocketAddr::from(sockaddr_v6))
.await
.with_context(|| format!("connect \"{}\"", sockaddr_v6))?;
Ok(())
}

let mut socket_stream = futures::stream::iter(addrs)
.map(|sockaddr_v6| async move {
(sockaddr_v6, try_connect(sockaddr_v6).await)
})
.buffer_unordered(3);

while let Some((sockaddr, connect_result)) = socket_stream.next().await
{
match connect_result {
Ok(()) => return Ok(sockaddr),
Err(error) => {
eprintln!(
"warning: failed to connect to {:?} at {}: {:#}",
service_name, sockaddr, error
);
}
}
}

Err(anyhow!("failed to connect to any instances of {:?}", service_name))
}

async fn dns_resolver(
&self,
log: slog::Logger,
Expand Down
8 changes: 2 additions & 6 deletions dev-tools/omdb/src/bin/omdb/mgs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,16 +66,12 @@ impl MgsArgs {
eprintln!(
"note: MGS URL not specified. Will pick one from DNS."
);
let addrs = omdb
.dns_lookup_all(
let addr = omdb
.dns_lookup_one(
log.clone(),
internal_dns::ServiceName::ManagementGatewayService,
)
.await?;
let addr = addrs.into_iter().next().expect(
"expected at least one MGS address from \
successful DNS lookup",
);
format!("http://{}", addr)
}
};
Expand Down
8 changes: 2 additions & 6 deletions dev-tools/omdb/src/bin/omdb/nexus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,16 +282,12 @@ impl NexusArgs {
eprintln!(
"note: Nexus URL not specified. Will pick one from DNS."
);
let addrs = omdb
.dns_lookup_all(
let addr = omdb
.dns_lookup_one(
log.clone(),
internal_dns::ServiceName::Nexus,
)
.await?;
let addr = addrs.into_iter().next().expect(
"expected at least one Nexus address from \
successful DNS lookup",
);
format!("http://{}", addr)
}
};
Expand Down
21 changes: 12 additions & 9 deletions dev-tools/omdb/tests/env.out
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ EXECUTING COMMAND: omdb ["db", "--db-url", "postgresql://root@[::1]:REDACTED_POR
termination: Exited(0)
---------------------------------------------
stdout:
SERIAL IP ROLE ID
sim-039be560 [::1]:REDACTED_PORT scrimlet ..........<REDACTED_UUID>...........
sim-b6d65341 [::1]:REDACTED_PORT scrimlet ..........<REDACTED_UUID>...........
SERIAL IP ROLE POLICY STATE ID
sim-039be560 [::1]:REDACTED_PORT scrimlet not provisionable active ..........<REDACTED_UUID>...........
sim-b6d65341 [::1]:REDACTED_PORT scrimlet in service active ..........<REDACTED_UUID>...........
---------------------------------------------
stderr:
note: using database URL postgresql://root@[::1]:REDACTED_PORT/omicron?sslmode=disable
note: database schema version matches expected (<redacted database version>)
note: listing all sleds (use -F to filter, e.g. -F in-service)
=============================================
EXECUTING COMMAND: omdb ["db", "--db-url", "junk", "sleds"]
termination: Exited(2)
Expand Down Expand Up @@ -304,27 +305,29 @@ EXECUTING COMMAND: omdb ["db", "sleds"]
termination: Exited(0)
---------------------------------------------
stdout:
SERIAL IP ROLE ID
sim-039be560 [::1]:REDACTED_PORT scrimlet ..........<REDACTED_UUID>...........
sim-b6d65341 [::1]:REDACTED_PORT scrimlet ..........<REDACTED_UUID>...........
SERIAL IP ROLE POLICY STATE ID
sim-039be560 [::1]:REDACTED_PORT scrimlet not provisionable active ..........<REDACTED_UUID>...........
sim-b6d65341 [::1]:REDACTED_PORT scrimlet in service active ..........<REDACTED_UUID>...........
---------------------------------------------
stderr:
note: database URL not specified. Will search DNS.
note: (override with --db-url or OMDB_DB_URL)
note: using database URL postgresql://root@[::1]:REDACTED_PORT/omicron?sslmode=disable
note: database schema version matches expected (<redacted database version>)
note: listing all sleds (use -F to filter, e.g. -F in-service)
=============================================
EXECUTING COMMAND: omdb ["--dns-server", "[::1]:REDACTED_PORT", "db", "sleds"]
termination: Exited(0)
---------------------------------------------
stdout:
SERIAL IP ROLE ID
sim-039be560 [::1]:REDACTED_PORT scrimlet ..........<REDACTED_UUID>...........
sim-b6d65341 [::1]:REDACTED_PORT scrimlet ..........<REDACTED_UUID>...........
SERIAL IP ROLE POLICY STATE ID
sim-039be560 [::1]:REDACTED_PORT scrimlet not provisionable active ..........<REDACTED_UUID>...........
sim-b6d65341 [::1]:REDACTED_PORT scrimlet in service active ..........<REDACTED_UUID>...........
---------------------------------------------
stderr:
note: database URL not specified. Will search DNS.
note: (override with --db-url or OMDB_DB_URL)
note: using database URL postgresql://root@[::1]:REDACTED_PORT/omicron?sslmode=disable
note: database schema version matches expected (<redacted database version>)
note: listing all sleds (use -F to filter, e.g. -F in-service)
=============================================
20 changes: 16 additions & 4 deletions dev-tools/omdb/tests/successes.out
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,21 @@ EXECUTING COMMAND: omdb ["db", "sleds"]
termination: Exited(0)
---------------------------------------------
stdout:
SERIAL IP ROLE ID
sim-039be560 [::1]:REDACTED_PORT scrimlet ..........<REDACTED_UUID>...........
sim-b6d65341 [::1]:REDACTED_PORT scrimlet ..........<REDACTED_UUID>...........
SERIAL IP ROLE POLICY STATE ID
sim-039be560 [::1]:REDACTED_PORT scrimlet not provisionable active ..........<REDACTED_UUID>...........
sim-b6d65341 [::1]:REDACTED_PORT scrimlet in service active ..........<REDACTED_UUID>...........
---------------------------------------------
stderr:
note: using database URL postgresql://root@[::1]:REDACTED_PORT/omicron?sslmode=disable
note: database schema version matches expected (<redacted database version>)
note: listing all sleds (use -F to filter, e.g. -F in-service)
=============================================
EXECUTING COMMAND: omdb ["db", "sleds", "-F", "discretionary"]
termination: Exited(0)
---------------------------------------------
stdout:
SERIAL IP ROLE POLICY STATE ID
sim-b6d65341 [::1]:REDACTED_PORT scrimlet in service active ..........<REDACTED_UUID>...........
---------------------------------------------
stderr:
note: using database URL postgresql://root@[::1]:REDACTED_PORT/omicron?sslmode=disable
Expand Down Expand Up @@ -436,7 +448,7 @@ warning: unknown background task: "switch_port_config_manager" (don't know how t
stderr:
note: using Nexus URL http://127.0.0.1:REDACTED_PORT/
=============================================
EXECUTING COMMAND: omdb ["nexus", "background-tasks", "activate", "inventory_collection", "--destructive"]
EXECUTING COMMAND: omdb ["--destructive", "nexus", "background-tasks", "activate", "inventory_collection"]
termination: Exited(0)
---------------------------------------------
stdout:
Expand Down
Loading

0 comments on commit 6ec688a

Please sign in to comment.