Skip to content

Commit

Permalink
add initial cockroach-admin server
Browse files Browse the repository at this point in the history
  • Loading branch information
jgallagher committed May 24, 2024
1 parent 27e6b34 commit 66ba1b3
Show file tree
Hide file tree
Showing 13 changed files with 786 additions and 0 deletions.
25 changes: 25 additions & 0 deletions Cargo.lock

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

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ members = [
"clients/oximeter-client",
"clients/sled-agent-client",
"clients/wicketd-client",
"cockroach-admin",
"common",
"dev-tools/crdb-seed",
"dev-tools/omdb",
Expand Down Expand Up @@ -96,6 +97,7 @@ default-members = [
"clients/oximeter-client",
"clients/sled-agent-client",
"clients/wicketd-client",
"cockroach-admin",
"common",
"dev-tools/crdb-seed",
"dev-tools/omdb",
Expand Down Expand Up @@ -338,6 +340,7 @@ nexus-test-utils = { path = "nexus/test-utils" }
nexus-types = { path = "nexus/types" }
num-integer = "0.1.46"
num = { version = "0.4.3", default-features = false, features = [ "libm" ] }
omicron-cockroach-admin = { path = "cockroach-admin" }
omicron-common = { path = "common" }
omicron-gateway = { path = "gateway" }
omicron-nexus = { path = "nexus" }
Expand Down
30 changes: 30 additions & 0 deletions cockroach-admin/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
[package]
name = "omicron-cockroach-admin"
version = "0.1.0"
edition = "2021"
license = "MPL-2.0"

[dependencies]
anyhow.workspace = true
camino.workspace = true
chrono.workspace = true
clap.workspace = true
csv.workspace = true
dropshot.workspace = true
http.workspace = true
illumos-utils.workspace = true
omicron-common.workspace = true
schemars.workspace = true
slog.workspace = true
slog-async.workspace = true
slog-dtrace.workspace = true
slog-error-chain.workspace = true
serde.workspace = true
thiserror.workspace = true
tokio.workspace = true
toml.workspace = true

omicron-workspace-hack.workspace = true

[lints]
workspace = true
79 changes: 79 additions & 0 deletions cockroach-admin/src/bin/cockroach-admin.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
// 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/.

//! Executable program to run the Omicron CockroachDb admin interface (not to be
//! confused with CockroachDb's built-in HTTP API)
use anyhow::anyhow;
use camino::Utf8PathBuf;
use clap::Parser;
use omicron_cockroach_admin::CockroachCli;
use omicron_cockroach_admin::Config;
use omicron_common::cmd::fatal;
use omicron_common::cmd::CmdError;
use std::net::SocketAddr;
use std::net::SocketAddrV6;

#[derive(Debug, Parser)]
#[clap(name = "cockroach-admin", about = "Omicron CRDB cluster admin server")]
enum Args {
/// Print the OpenAPI Spec document and exit
Openapi,

/// Start the CRDB admin server
Run {
/// Path to the `cockroach` CLI
#[clap(long, action)]
path_to_cockroach_binary: Utf8PathBuf,

/// Socket address for a running cockroach server instance
#[clap(long, action)]
cockroach_address: SocketAddrV6,

/// Address on which this server should bin
#[clap(long, action)]
http_address: SocketAddrV6,

/// Path to the server config file
#[clap(long, action)]
config_file_path: Utf8PathBuf,
},
}

#[tokio::main]
async fn main() {
if let Err(err) = main_impl().await {
fatal(err);
}
}

async fn main_impl() -> Result<(), CmdError> {
let args = Args::parse();

match args {
Args::Openapi => omicron_cockroach_admin::run_openapi()
.map_err(|e| CmdError::Failure(anyhow!(e))),
Args::Run {
path_to_cockroach_binary,
cockroach_address,
http_address,
config_file_path,
} => {
let cockroach_cli =
CockroachCli::new(path_to_cockroach_binary, cockroach_address);
let mut config = Config::from_file(&config_file_path)
.map_err(|err| CmdError::Failure(anyhow!(err)))?;
config.dropshot.bind_address = SocketAddr::V6(http_address);
let server =
omicron_cockroach_admin::start_server(cockroach_cli, config)
.await
.map_err(|err| CmdError::Failure(anyhow!(err)))?;
server.await.map_err(|err| {
CmdError::Failure(anyhow!(
"server failed after starting: {err}"
))
})
}
}
}
Loading

0 comments on commit 66ba1b3

Please sign in to comment.