-
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.
## 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. --------- Co-authored-by: Benjamin Naecker <[email protected]>
- Loading branch information
1 parent
d7a5c1c
commit dcfac83
Showing
23 changed files
with
879 additions
and
469 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
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,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")?, | ||
)) | ||
} | ||
} | ||
} | ||
} |
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.