Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into ixi/remove-service-ba…
Browse files Browse the repository at this point in the history
…re-ip-resolution
  • Loading branch information
iximeow committed Aug 16, 2024
2 parents 9a75ff6 + 66ac7b3 commit 7694909
Show file tree
Hide file tree
Showing 85 changed files with 2,827 additions and 662 deletions.
658 changes: 402 additions & 256 deletions Cargo.lock

Large diffs are not rendered by default.

20 changes: 12 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ members = [
"api_identity",
"bootstore",
"certificates",
"clickhouse-admin",
"clickhouse-admin/api",
"clients/bootstrap-agent-client",
"clients/cockroach-admin-client",
"clients/ddm-admin-client",
Expand Down Expand Up @@ -112,6 +114,8 @@ default-members = [
"api_identity",
"bootstore",
"certificates",
"clickhouse-admin",
"clickhouse-admin/api",
"clients/bootstrap-agent-client",
"clients/cockroach-admin-client",
"clients/ddm-admin-client",
Expand Down Expand Up @@ -294,6 +298,7 @@ cfg-if = "1.0"
chrono = { version = "0.4", features = [ "serde" ] }
ciborium = "0.2.2"
clap = { version = "4.5", features = ["cargo", "derive", "env", "wrap_help"] }
clickhouse-admin-api = { path = "clickhouse-admin/api" }
clickward = { git = "https://github.com/oxidecomputer/clickward", rev = "ceec762e6a87d2a22bf56792a3025e145caa095e" }
cockroach-admin-api = { path = "cockroach-admin/api" }
cockroach-admin-client = { path = "clients/cockroach-admin-client" }
Expand Down Expand Up @@ -357,6 +362,10 @@ headers = "0.3.9"
heck = "0.5"
hex = "0.4.3"
hex-literal = "0.4.1"
hickory-client = "0.24.1"
hickory-proto = "0.24.1"
hickory-resolver = "0.24.1"
hickory-server = "0.24.1"
highway = "1.2.0"
hkdf = "0.12.4"
http = "0.2.12"
Expand All @@ -368,7 +377,7 @@ hyper-rustls = "0.26.0"
hyper-staticfile = "0.9.5"
illumos-utils = { path = "illumos-utils" }
indent_write = "2.2.0"
indexmap = "2.3.0"
indexmap = "2.4.0"
indicatif = { version = "0.17.8", features = ["rayon"] }
installinator = { path = "installinator" }
installinator-api = { path = "installinator-api" }
Expand Down Expand Up @@ -417,6 +426,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-clickhouse-admin = { path = "clickhouse-admin" }
omicron-certificates = { path = "certificates" }
omicron-cockroach-admin = { path = "cockroach-admin" }
omicron-common = { path = "common" }
Expand Down Expand Up @@ -501,7 +511,7 @@ secrecy = "0.8.0"
semver = { version = "1.0.23", features = ["std", "serde"] }
serde = { version = "1.0", default-features = false, features = [ "derive", "rc" ] }
serde_human_bytes = { git = "https://github.com/oxidecomputer/serde_human_bytes", branch = "main" }
serde_json = "1.0.124"
serde_json = "1.0.125"
serde_path_to_error = "0.1.16"
serde_tokenstream = "0.2"
serde_urlencoded = "0.7.1"
Expand Down Expand Up @@ -566,10 +576,6 @@ tokio-util = { version = "0.7.11", features = ["io", "io-util"] }
toml = "0.8.19"
toml_edit = "0.22.20"
tough = { version = "0.17.1", features = [ "http" ] }
trust-dns-client = "0.22"
trust-dns-proto = "0.22"
trust-dns-resolver = "0.22"
trust-dns-server = "0.22"
trybuild = "1.0.99"
tufaceous = { path = "tufaceous" }
tufaceous-lib = { path = "tufaceous-lib" }
Expand Down Expand Up @@ -728,8 +734,6 @@ opt-level = 3
opt-level = 3
[profile.dev.package.rand_core]
opt-level = 3
[profile.dev.package.rand_hc]
opt-level = 3
[profile.dev.package.rand_xorshift]
opt-level = 3
[profile.dev.package.rsa]
Expand Down
42 changes: 42 additions & 0 deletions clickhouse-admin/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
[package]
name = "omicron-clickhouse-admin"
version = "0.1.0"
edition = "2021"
license = "MPL-2.0"

[dependencies]
anyhow.workspace = true
camino.workspace = true
chrono.workspace = true
clap.workspace = true
clickhouse-admin-api.workspace = true
dropshot.workspace = true
http.workspace = true
illumos-utils.workspace = true
omicron-common.workspace = true
omicron-uuid-kinds.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
tokio-postgres.workspace = true
toml.workspace = true

omicron-workspace-hack.workspace = true

[dev-dependencies]
expectorate.workspace = true
nexus-test-utils.workspace = true
omicron-test-utils.workspace = true
openapi-lint.workspace = true
openapiv3.workspace = true
serde_json.workspace = true
subprocess.workspace = true
url.workspace = true

[lints]
workspace = true
16 changes: 16 additions & 0 deletions clickhouse-admin/api/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[package]
name = "clickhouse-admin-api"
version = "0.1.0"
edition = "2021"
license = "MPL-2.0"

[lints]
workspace = true

[dependencies]
dropshot.workspace = true
omicron-common.workspace = true
omicron-uuid-kinds.workspace = true
omicron-workspace-hack.workspace = true
schemars.workspace = true
serde.workspace = true
28 changes: 28 additions & 0 deletions clickhouse-admin/api/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// 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/.

use dropshot::{HttpError, HttpResponseOk, RequestContext};
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use std::net::SocketAddrV6;

#[dropshot::api_description]
pub trait ClickhouseAdminApi {
type Context;

/// Retrieve the address the ClickHouse server or keeper node is listening on
#[endpoint {
method = GET,
path = "/node/address",
}]
async fn clickhouse_address(
rqctx: RequestContext<Self::Context>,
) -> Result<HttpResponseOk<ClickhouseAddress>, HttpError>;
}

#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub struct ClickhouseAddress {
pub clickhouse_address: SocketAddrV6,
}
68 changes: 68 additions & 0 deletions clickhouse-admin/src/bin/clickhouse-admin.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// 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 ClickHouse admin interface
use anyhow::anyhow;
use camino::Utf8PathBuf;
use clap::Parser;
use omicron_clickhouse_admin::{Clickward, Config};
use omicron_common::cmd::fatal;
use omicron_common::cmd::CmdError;
use std::net::{SocketAddr, SocketAddrV6};

#[derive(Debug, Parser)]
#[clap(
name = "clickhouse-admin",
about = "Omicron ClickHouse cluster admin server"
)]
enum Args {
/// Start the ClickHouse admin server
Run {
// TODO: This address is solely for testing now. We should remove it
// once we have more endpoints up and running.
/// Socket address for a running clickhouse server or keeper instance
#[clap(long, short = 'a', action)]
clickhouse_address: SocketAddrV6,

/// Address on which this server should run
#[clap(long, short = 'H', action)]
http_address: SocketAddrV6,

/// Path to the server configuration file
#[clap(long, short, action)]
config: 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::Run { clickhouse_address, http_address, config } => {
let mut config = Config::from_file(&config)
.map_err(|err| CmdError::Failure(anyhow!(err)))?;
config.dropshot.bind_address = SocketAddr::V6(http_address);

let clickward = Clickward::new(clickhouse_address);

let server =
omicron_clickhouse_admin::start_server(clickward, config)
.await
.map_err(|err| CmdError::Failure(anyhow!(err)))?;
server.await.map_err(|err| {
CmdError::Failure(anyhow!(
"server failed after starting: {err}"
))
})
}
}
}
51 changes: 51 additions & 0 deletions clickhouse-admin/src/clickward.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// 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/.

use clickhouse_admin_api::ClickhouseAddress;
use dropshot::HttpError;
use slog_error_chain::{InlineErrorChain, SlogInlineError};
use std::io;
use std::net::SocketAddrV6;

#[derive(Debug, thiserror::Error, SlogInlineError)]
pub enum ClickwardError {
#[error("clickward failure")]
Failure {
#[source]
err: io::Error,
},
}

impl From<ClickwardError> for HttpError {
fn from(err: ClickwardError) -> Self {
match err {
ClickwardError::Failure { .. } => {
let message = InlineErrorChain::new(&err).to_string();
HttpError {
status_code: http::StatusCode::INTERNAL_SERVER_ERROR,
error_code: Some(String::from("Internal")),
external_message: message.clone(),
internal_message: message,
}
}
}
}
}

#[derive(Debug)]
pub struct Clickward {
clickhouse_address: SocketAddrV6,
}

impl Clickward {
pub fn new(clickhouse_address: SocketAddrV6) -> Self {
Self { clickhouse_address }
}

pub fn clickhouse_address(
&self,
) -> Result<ClickhouseAddress, ClickwardError> {
Ok(ClickhouseAddress { clickhouse_address: self.clickhouse_address })
}
}
43 changes: 43 additions & 0 deletions clickhouse-admin/src/config.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// 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/.

use camino::Utf8Path;
use camino::Utf8PathBuf;
use dropshot::ConfigDropshot;
use dropshot::ConfigLogging;
use serde::Deserialize;
use serde::Serialize;
use slog_error_chain::SlogInlineError;
use std::io;

#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
pub struct Config {
pub dropshot: ConfigDropshot,
pub log: ConfigLogging,
}
impl Config {
/// Load a `Config` from the given TOML file
pub fn from_file(path: &Utf8Path) -> Result<Self, LoadError> {
let contents = std::fs::read_to_string(path)
.map_err(|err| LoadError::Read { path: path.to_owned(), err })?;
toml::de::from_str(&contents)
.map_err(|err| LoadError::Parse { path: path.to_owned(), err })
}
}

#[derive(Debug, thiserror::Error, SlogInlineError)]
pub enum LoadError {
#[error("failed to read {path}")]
Read {
path: Utf8PathBuf,
#[source]
err: io::Error,
},
#[error("failed to parse {path} as TOML")]
Parse {
path: Utf8PathBuf,
#[source]
err: toml::de::Error,
},
}
21 changes: 21 additions & 0 deletions clickhouse-admin/src/context.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// 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/.

use crate::Clickward;
use slog::Logger;

pub struct ServerContext {
clickward: Clickward,
_log: Logger,
}

impl ServerContext {
pub fn new(clickward: Clickward, _log: Logger) -> Self {
Self { clickward, _log }
}

pub fn clickward(&self) -> &Clickward {
&self.clickward
}
}
31 changes: 31 additions & 0 deletions clickhouse-admin/src/http_entrypoints.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// 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/.

use crate::context::ServerContext;
use clickhouse_admin_api::*;
use dropshot::HttpError;
use dropshot::HttpResponseOk;
use dropshot::RequestContext;
use std::sync::Arc;

type ClickhouseApiDescription = dropshot::ApiDescription<Arc<ServerContext>>;

pub fn api() -> ClickhouseApiDescription {
clickhouse_admin_api_mod::api_description::<ClickhouseAdminImpl>()
.expect("registered entrypoints")
}

enum ClickhouseAdminImpl {}

impl ClickhouseAdminApi for ClickhouseAdminImpl {
type Context = Arc<ServerContext>;

async fn clickhouse_address(
rqctx: RequestContext<Self::Context>,
) -> Result<HttpResponseOk<ClickhouseAddress>, HttpError> {
let ctx = rqctx.context();
let output = ctx.clickward().clickhouse_address()?;
Ok(HttpResponseOk(output))
}
}
Loading

0 comments on commit 7694909

Please sign in to comment.