Skip to content

Commit

Permalink
Move oxql from oxdb to mainline omdb
Browse files Browse the repository at this point in the history
Why?:

Concerning [network observability work](https://github.com/orgs/oxidecomputer/projects/55/views/1?filterQuery=&pane=issue&itemId=68336554),
this makes the [`oxql`](https://rfd.shared.oxide.computer/rfd/0463) interactive query repl accessible via omdb, as we start to give users and
ourselves the ability to query timeseries and metrics more easily. Additionally, in the "now", this aids in debugging through our metrics
set and makes it available, via omdb, throughout our ecosystem/a4x2.

Includes:
  * Removes `oxql` from `oxdb`.
  * If no URL is given to `omdb oxql`, it will leverage internal DNS.
  * Update the oximeter omdb call (for listing producers) to leverage internal.
    DNS if no URL is given.
  * Update command/output tests/generations and collector specific tests for list producers.

Notes:
  * The oxql client still expects an socket address as liked it typed
    specifically v.s. a String. Instead, upon running the `omdb oxql` command,
    we take in a URL String and parse it into the socket address directly.
  • Loading branch information
zeeshanlakhani committed Jul 3, 2024
1 parent 599fe72 commit 03ab429
Show file tree
Hide file tree
Showing 19 changed files with 574 additions and 307 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ tags
.falcon/*
.img/*
connectivity-report.json
*.local
2 changes: 2 additions & 0 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions dev-tools/omdb/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ nexus-types.workspace = true
omicron-common.workspace = true
omicron-uuid-kinds.workspace = true
oximeter-client.workspace = true
oximeter-db.workspace = true
# See omicron-rpaths for more about the "pq-sys" dependency.
pq-sys = "*"
ratatui.workspace = true
Expand All @@ -51,6 +52,7 @@ tabled.workspace = true
textwrap.workspace = true
tokio = { workspace = true, features = [ "full" ] }
unicode-width.workspace = true
url.workspace = true
uuid.workspace = true
ipnetwork.workspace = true
omicron-workspace-hack.workspace = true
Expand Down
6 changes: 5 additions & 1 deletion dev-tools/omdb/src/bin/omdb/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ mod helpers;
mod mgs;
mod nexus;
mod oximeter;
mod oxql;
mod sled_agent;

#[tokio::main]
Expand All @@ -66,7 +67,8 @@ async fn main() -> Result<(), anyhow::Error> {
OmdbCommands::Db(db) => db.run_cmd(&args, &log).await,
OmdbCommands::Mgs(mgs) => mgs.run_cmd(&args, &log).await,
OmdbCommands::Nexus(nexus) => nexus.run_cmd(&args, &log).await,
OmdbCommands::Oximeter(oximeter) => oximeter.run_cmd(&log).await,
OmdbCommands::Oximeter(oximeter) => oximeter.run_cmd(&args, &log).await,
OmdbCommands::Oxql(oxql) => oxql.run_cmd(&args, &log).await,
OmdbCommands::SledAgent(sled) => sled.run_cmd(&args, &log).await,
OmdbCommands::CrucibleAgent(crucible) => crucible.run_cmd(&args).await,
}
Expand Down Expand Up @@ -269,6 +271,8 @@ enum OmdbCommands {
Nexus(nexus::NexusArgs),
/// Query oximeter collector state
Oximeter(oximeter::OximeterArgs),
/// Enter the Oximeter Query Language shell for interactive querying.
Oxql(oxql::OxqlArgs),
/// Debug a specific Sled
SledAgent(sled_agent::SledAgentArgs),
}
Expand Down
49 changes: 37 additions & 12 deletions dev-tools/omdb/src/bin/omdb/oximeter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
//! omdb commands that query oximeter
use crate::helpers::CONNECTION_OPTIONS_HEADING;
use crate::Omdb;
use anyhow::Context;
use clap::Args;
use clap::Subcommand;
Expand All @@ -24,34 +25,58 @@ pub struct OximeterArgs {
#[arg(
long,
env = "OMDB_OXIMETER_URL",
// This can't be global = true (i.e. passed in later in the
// command-line) because global options can't be required. If this
// changes to being optional, we should set global = true.
global = true,
help_heading = CONNECTION_OPTIONS_HEADING,
)]
oximeter_url: String,
oximeter_url: Option<String>,

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

/// Subcommands that query oximeter collector state
/// Subcommands that query oximeter collector state.
#[derive(Debug, Subcommand)]
enum OximeterCommands {
/// List the producers the collector is assigned to poll
/// List the producers the collector is assigned to poll.
ListProducers,
}

impl OximeterArgs {
fn client(&self, log: &Logger) -> Client {
Client::new(
&self.oximeter_url,
async fn client(
&self,
omdb: &Omdb,
log: &Logger,
) -> Result<Client, anyhow::Error> {
let oximeter_url = match &self.oximeter_url {
Some(cli_or_env_url) => cli_or_env_url.clone(),
None => {
eprintln!(
"note: Oximeter URL not specified. Will pick one from DNS."
);
let addr = omdb
.dns_lookup_one(
log.clone(),
internal_dns::ServiceName::Oximeter,
)
.await?;
format!("http://{}", addr)
}
};
eprintln!("note: using Oximeter URL {}", &oximeter_url);

let client = Client::new(
&oximeter_url,
log.new(slog::o!("component" => "oximeter-client")),
)
);
Ok(client)
}

pub async fn run_cmd(&self, log: &Logger) -> anyhow::Result<()> {
let client = self.client(log);
pub async fn run_cmd(
&self,
omdb: &Omdb,
log: &Logger,
) -> anyhow::Result<()> {
let client = self.client(omdb, log).await?;
match self.command {
OximeterCommands::ListProducers => {
self.list_producers(client).await
Expand Down
Loading

0 comments on commit 03ab429

Please sign in to comment.