Skip to content

Commit

Permalink
rebase, update dropshot, remove openapi-internal command, update readme
Browse files Browse the repository at this point in the history
Created using spr 1.3.6-beta.1
  • Loading branch information
sunshowers committed Jul 11, 2024
2 parents 8c3b443 + da2218b commit 027ed90
Show file tree
Hide file tree
Showing 77 changed files with 2,779 additions and 1,150 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/hakari.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
with:
toolchain: stable
- name: Install cargo-hakari
uses: taiki-e/install-action@2335425120e645291d84cec8194c63983a0c8ee5 # v2
uses: taiki-e/install-action@ef2fb5af7d19da8885ee368c6bde2ae6d0758e3d # v2
with:
tool: cargo-hakari
- name: Check workspace-hack Cargo.toml is up-to-date
Expand Down
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
22 changes: 12 additions & 10 deletions Cargo.lock

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

10 changes: 5 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ approx = "0.5.1"
assert_matches = "1.5.0"
assert_cmd = "2.0.14"
async-bb8-diesel = { git = "https://github.com/oxidecomputer/async-bb8-diesel", rev = "ed7ab5ef0513ba303d33efd41d3e9e381169d59b" }
async-trait = "0.1.80"
async-trait = "0.1.81"
atomicwrites = "0.4.3"
authz-macros = { path = "nexus/authz-macros" }
backoff = { version = "0.4.0", features = [ "tokio" ] }
Expand Down Expand Up @@ -338,8 +338,8 @@ macaddr = { version = "1.0.1", features = ["serde_std"] }
maplit = "1.0.2"
mockall = "0.12"
newtype_derive = "0.1.6"
mg-admin-client = { git = "https://github.com/oxidecomputer/maghemite", rev = "6e0a232fd0b443c19f61f94bf02b7695505aa8e3" }
ddm-admin-client = { git = "https://github.com/oxidecomputer/maghemite", rev = "6e0a232fd0b443c19f61f94bf02b7695505aa8e3" }
mg-admin-client = { git = "https://github.com/oxidecomputer/maghemite", rev = "d1686c86f92ead77e07ddc6024837dee4a401d6d" }
ddm-admin-client = { git = "https://github.com/oxidecomputer/maghemite", rev = "d1686c86f92ead77e07ddc6024837dee4a401d6d" }
multimap = "0.10.0"
nexus-auth = { path = "nexus/auth" }
nexus-client = { path = "clients/nexus-client" }
Expand Down Expand Up @@ -390,7 +390,7 @@ oso = "0.27"
owo-colors = "4.0.0"
oximeter = { path = "oximeter/oximeter" }
oximeter-client = { path = "clients/oximeter-client" }
oximeter-db = { path = "oximeter/db/" }
oximeter-db = { path = "oximeter/db/", default-features = false }
oximeter-collector = { path = "oximeter/collector" }
oximeter-impl = { path = "oximeter/impl" }
oximeter-instruments = { path = "oximeter/instruments" }
Expand Down Expand Up @@ -439,7 +439,7 @@ rustls = "0.22.2"
rustls-pemfile = "2.1.2"
rustyline = "14.0.0"
samael = { version = "0.0.15", features = ["xmlsec"] }
schemars = "0.8.16"
schemars = "0.8.21"
secrecy = "0.8.0"
semver = { version = "1.0.23", features = ["std", "serde"] }
serde = { version = "1.0", default-features = false, features = [ "derive", "rc" ] }
Expand Down
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, default-features = false, features = [ "oxql" ] }
# 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: 38 additions & 11 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 @@ -18,18 +19,17 @@ use tabled::Table;
use tabled::Tabled;
use uuid::Uuid;

/// Arguments for the oximeter subcommand.
#[derive(Debug, Args)]
pub struct OximeterArgs {
/// URL of the oximeter collector to query
#[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,
Expand All @@ -38,20 +38,47 @@ pub struct OximeterArgs {
/// 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);
/// Run the command.
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
97 changes: 97 additions & 0 deletions dev-tools/omdb/src/bin/omdb/oxql.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
// 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 OxQL shell for interactive queries on metrics/timeseries.
// Copyright 2024 Oxide Computer

use crate::helpers::CONNECTION_OPTIONS_HEADING;
use crate::Omdb;
use anyhow::Context;
use clap::Args;
use oximeter_db::{
self,
shells::oxql::{self, ShellOptions},
};
use slog::Logger;
use std::net::SocketAddr;
use url::Url;

/// Command-line arguments for the OxQL shell.
#[derive(Debug, Args)]
pub struct OxqlArgs {
/// URL of the ClickHouse server to connect to.
#[arg(
long,
env = "OMDB_CLICKHOUSE_URL",
global = true,
help_heading = CONNECTION_OPTIONS_HEADING,
)]
clickhouse_url: Option<String>,

/// Print summaries of each SQL query run against the database.
#[clap(long = "summaries")]
print_summaries: bool,

/// Print the total elapsed query duration.
#[clap(long = "elapsed")]
print_elapsed: bool,
}

impl OxqlArgs {
/// Run the OxQL shell via the `omdb oxql` subcommand.
pub async fn run_cmd(
&self,
omdb: &Omdb,
log: &Logger,
) -> anyhow::Result<()> {
let addr = self.addr(omdb, log).await?;

let opts = ShellOptions {
print_summaries: self.print_summaries,
print_elapsed: self.print_elapsed,
};

oxql::shell(
addr.ip(),
addr.port(),
log.new(slog::o!("component" => "clickhouse-client")),
opts,
)
.await
}

/// Resolve the ClickHouse URL to a socket address.
async fn addr(
&self,
omdb: &Omdb,
log: &Logger,
) -> anyhow::Result<SocketAddr> {
match &self.clickhouse_url {
Some(cli_or_env_url) => Url::parse(&cli_or_env_url)
.context(
"failed parsing URL from command-line or environment variable",
)?
.socket_addrs(|| None)
.context("failed resolving socket addresses")?
.into_iter()
.next()
.context("failed resolving socket addresses"),
None => {
eprintln!(
"note: ClickHouse URL not specified. Will pick one from DNS."
);

Ok(SocketAddr::V6(
omdb.dns_lookup_one(
log.clone(),
internal_dns::ServiceName::Clickhouse,
)
.await
.context("failed looking up ClickHouse internal DNS entry")?,
))
}
}
}
}
25 changes: 25 additions & 0 deletions dev-tools/omdb/tests/env.out
Original file line number Diff line number Diff line change
Expand Up @@ -433,3 +433,28 @@ note: using database URL postgresql://root@[::1]:REDACTED_PORT/omicron?sslmode=d
note: database schema version matches expected (<redacted database version>)
note: listing all commissioned sleds (use -F to filter, e.g. -F in-service)
=============================================
EXECUTING COMMAND: omdb ["oximeter", "--oximeter-url", "junk", "list-producers"]
termination: Exited(1)
---------------------------------------------
stdout:
---------------------------------------------
stderr:
note: using Oximeter URL junk
Error: failed to fetch collector info

Caused by:
0: Communication Error: builder error: relative URL without a base
1: builder error: relative URL without a base
2: relative URL without a base
=============================================
EXECUTING COMMAND: omdb ["oxql", "--clickhouse-url", "junk"]
termination: Exited(1)
---------------------------------------------
stdout:
---------------------------------------------
stderr:
Error: failed parsing URL from command-line or environment variable

Caused by:
relative URL without a base
=============================================
Loading

0 comments on commit 027ed90

Please sign in to comment.