-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move
oxql
from oxdb
to mainline omdb
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: * Moves `oxql_shell` into the oximeter_db lib for use by both omdb and 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
1 parent
30b6713
commit e6e052d
Showing
23 changed files
with
793 additions
and
498 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 |
---|---|---|
|
@@ -17,3 +17,4 @@ tags | |
.falcon/* | ||
.img/* | ||
connectivity-report.json | ||
*.local |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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
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 |
---|---|---|
@@ -0,0 +1,92 @@ | ||
// 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, Client, DbWrite}; | ||
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 metrics database. | ||
#[arg( | ||
long, | ||
env = "OMDB_METRICS_DB_URL", | ||
global = true, | ||
help_heading = CONNECTION_OPTIONS_HEADING, | ||
)] | ||
metrics_db_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 { | ||
async fn client( | ||
&self, | ||
omdb: &Omdb, | ||
log: &Logger, | ||
) -> Result<Client, anyhow::Error> { | ||
let socket_addr = match &self.metrics_db_url { | ||
Some(cli_or_env_url) => Url::parse(&cli_or_env_url) | ||
.context("Failed to parse metrics DB URL")? | ||
.socket_addrs(|| None) | ||
.context("Failed to resolve metrics DB URL")? | ||
.drain(..) | ||
.next() | ||
.context("Failed to resolve metrics DB URL")?, | ||
_ => { | ||
eprintln!( | ||
"note: Metrics DB address/port not specified. Will pick one from DNS." | ||
); | ||
SocketAddr::V6( | ||
omdb.dns_lookup_one( | ||
log.clone(), | ||
internal_dns::ServiceName::Clickhouse, | ||
) | ||
.await?, | ||
) | ||
} | ||
}; | ||
eprintln!("note: using Metrics DB socket address: {}", &socket_addr); | ||
|
||
let client = Client::new(socket_addr, log); | ||
|
||
client | ||
.init_single_node_db() | ||
.await | ||
.context("Failed to initialize timeseries database")?; | ||
Ok(client) | ||
} | ||
|
||
/// Run the OxQL shell via the `omdb oxql` subcommand. | ||
pub async fn run_cmd( | ||
&self, | ||
omdb: &Omdb, | ||
log: &Logger, | ||
) -> anyhow::Result<()> { | ||
let client = self.client(omdb, log).await?; | ||
oximeter_db::oxql::oxql_shell( | ||
client, | ||
self.print_summaries, | ||
self.print_elapsed, | ||
) | ||
.await?; | ||
Ok(()) | ||
} | ||
} |
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
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.