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

[omdb] Add a couple simple Sled Agent queries #4126

Merged
merged 4 commits into from
Sep 21, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
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 omdb/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ omicron-common.workspace = true
pq-sys = "*"
serde.workspace = true
serde_json.workspace = true
sled-agent-client.workspace = true
slog.workspace = true
strum.workspace = true
tabled.workspace = true
Expand Down
6 changes: 5 additions & 1 deletion omdb/src/bin/omdb/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ use clap::Subcommand;

mod db;
mod nexus;
mod sled;

#[tokio::main]
async fn main() -> Result<(), anyhow::Error> {
Expand All @@ -35,8 +36,9 @@ async fn main() -> Result<(), anyhow::Error> {
.context("failed to create logger")?;

match args.command {
OmdbCommands::Nexus(nexus) => nexus.run_cmd(&log).await,
OmdbCommands::Db(db) => db.run_cmd(&log).await,
OmdbCommands::Nexus(nexus) => nexus.run_cmd(&log).await,
OmdbCommands::Sled(sled) => sled.run_cmd(&log).await,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I only wonder if this should be sled-agent (there are other things on the sled). If you do I'd carry that through everywhere -- e.g., the URL env var name too.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

}
}

Expand Down Expand Up @@ -67,6 +69,8 @@ enum OmdbCommands {
Db(db::DbArgs),
/// Debug a specific Nexus instance
Nexus(nexus::NexusArgs),
/// Debug a specific Sled
Sled(sled::SledArgs),
}

fn parse_dropshot_log_level(
Expand Down
2 changes: 1 addition & 1 deletion omdb/src/bin/omdb/nexus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ impl NexusArgs {
&self,
log: &slog::Logger,
) -> Result<(), anyhow::Error> {
// This is a little goofy. The database URL is required, but can come
// This is a little goofy. The nexus URL is required, but can come
// from the environment, in which case it won't be on the command line.
let Some(nexus_url) = &self.nexus_internal_url else {
bail!(
Expand Down
109 changes: 109 additions & 0 deletions omdb/src/bin/omdb/sled.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
// This Source Code Form is subject to the terms of the Mozilla Public
// 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/.

//! omdb commands that query or update specific Sleds

use anyhow::bail;
use anyhow::Context;
use clap::Args;
use clap::Subcommand;

/// Arguments to the "omdb sled" subcommand
#[derive(Debug, Args)]
pub struct SledArgs {
/// URL of the Sled internal API
#[clap(long, env("OMDB_SLED_URL"))]
sled_url: Option<String>,

#[command(subcommand)]
command: SledCommands,
}

/// Subcommands for the "omdb sled" subcommand
#[derive(Debug, Subcommand)]
enum SledCommands {
/// print information about zones
#[clap(subcommand)]
Zones(ZoneCommands),

/// print information about zpools
#[clap(subcommand)]
Zpools(ZpoolCommands),
}

#[derive(Debug, Subcommand)]
enum ZoneCommands {
/// Print list of all zones
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// Print list of all zones
/// Print list of control plane zones that the sled agent is configured to run

(just trying to be precise about what it's printing so that someone doesn't interpret this as the same as zoneadm list)

edit: I just checked and it looks like this is only the running zones that are the subset of zones the sled agent is configured to run, I think.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated, specifying that these are "running control plane zones". I think we could also expose the set of zones the sled was told to run, but this will require modifying the sled agent API.

List,
}

#[derive(Debug, Subcommand)]
enum ZpoolCommands {
/// Print list of all zpools
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// Print list of all zpools
/// Print list of all zpools managed by the sled agent

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

List,
}

impl SledArgs {
/// Run a `omdb sled` subcommand.
pub async fn run_cmd(
&self,
log: &slog::Logger,
) -> Result<(), anyhow::Error> {
// This is a little goofy. The sled URL is required, but can come
// from the environment, in which case it won't be on the command line.
let Some(sled_url) = &self.sled_url else {
bail!(
"sled URL must be specified with --sled-url or \
OMDB_SLED_URL"
);
};
let client = sled_agent_client::Client::new(sled_url, log.clone());

match &self.command {
SledCommands::Zones(ZoneCommands::List) => {
cmd_zones_list(&client).await
}
SledCommands::Zpools(ZpoolCommands::List) => {
cmd_zpools_list(&client).await
}
}
}
}

/// Runs `omdb sled zones list`
async fn cmd_zones_list(
client: &sled_agent_client::Client,
) -> Result<(), anyhow::Error> {
let response = client.zones_list().await.context("listing zones")?;
let zones = response.into_inner();
let zones: Vec<_> = zones.into_iter().collect();

println!("zones:");
if zones.is_empty() {
println!(" <none>");
}
for zone in &zones {
println!(" {:?}", zone);
}

Ok(())
}

/// Runs `omdb sled zpools list`
async fn cmd_zpools_list(
client: &sled_agent_client::Client,
) -> Result<(), anyhow::Error> {
let response = client.zpools_get().await.context("listing zpools")?;
let zpools = response.into_inner();

println!("zpools:");
if zpools.is_empty() {
println!(" <none>");
}
for zpool in &zpools {
println!(" {:?}", zpool);
}

Ok(())
}