From b3d31c73a9479481246940a2cfdfd96eab23fb6b Mon Sep 17 00:00:00 2001 From: karencfv Date: Mon, 12 Aug 2024 20:11:33 +1200 Subject: [PATCH 01/10] skeleton for clickhouse admin --- Cargo.lock | 78 ++++++++++++++++++++ Cargo.toml | 11 +++ clickhouse-admin/Cargo.toml | 46 ++++++++++++ clickhouse-admin/api/Cargo.toml | 17 +++++ clickhouse-admin/api/src/lib.rs | 3 + clickhouse-admin/src/bin/clickhouse-admin.rs | 19 +++++ clickhouse-admin/types/Cargo.toml | 18 +++++ clickhouse-admin/types/src/lib.rs | 0 clients/clickhouse-admin-client/Cargo.toml | 18 +++++ clients/clickhouse-admin-client/src/lib.rs | 25 +++++++ 10 files changed, 235 insertions(+) create mode 100644 clickhouse-admin/Cargo.toml create mode 100644 clickhouse-admin/api/Cargo.toml create mode 100644 clickhouse-admin/api/src/lib.rs create mode 100644 clickhouse-admin/src/bin/clickhouse-admin.rs create mode 100644 clickhouse-admin/types/Cargo.toml create mode 100644 clickhouse-admin/types/src/lib.rs create mode 100644 clients/clickhouse-admin-client/Cargo.toml create mode 100644 clients/clickhouse-admin-client/src/lib.rs diff --git a/Cargo.lock b/Cargo.lock index 5b575be25a..fa2714f3f3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1108,6 +1108,45 @@ version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "98cc8fbded0c607b7ba9dd60cd98df59af97e84d24e49c8557331cfc26d301ce" +[[package]] +name = "clickhouse-admin-api" +version = "0.1.0" +dependencies = [ + "clickhouse-admin-types", + "dropshot", + "omicron-common", + "omicron-uuid-kinds", + "omicron-workspace-hack", + "schemars", + "serde", +] + +[[package]] +name = "clickhouse-admin-client" +version = "0.1.0" +dependencies = [ + "chrono", + "omicron-uuid-kinds", + "omicron-workspace-hack", + "progenitor", + "reqwest", + "schemars", + "serde", + "slog", +] + +[[package]] +name = "clickhouse-admin-types" +version = "0.1.0" +dependencies = [ + "omicron-common", + "omicron-workspace-hack", + "proptest", + "schemars", + "serde", + "test-strategy", +] + [[package]] name = "clickward" version = "0.1.0" @@ -5537,6 +5576,45 @@ dependencies = [ "thiserror", ] +[[package]] +name = "omicron-clickhouse-admin" +version = "0.1.0" +dependencies = [ + "anyhow", + "camino", + "chrono", + "clap", + "clickhouse-admin-api", + "clickhouse-admin-types", + "dropshot", + "expectorate", + "http 0.2.12", + "illumos-utils", + "nexus-test-utils", + "omicron-common", + "omicron-test-utils", + "omicron-uuid-kinds", + "omicron-workspace-hack", + "once_cell", + "openapi-lint", + "openapiv3", + "proptest", + "schemars", + "serde", + "serde_json", + "slog", + "slog-async", + "slog-dtrace", + "slog-error-chain", + "subprocess", + "test-strategy", + "thiserror", + "tokio", + "tokio-postgres", + "toml 0.8.19", + "url", +] + [[package]] name = "omicron-cockroach-admin" version = "0.1.0" diff --git a/Cargo.toml b/Cargo.toml index c8ba9490b2..092883cabf 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,7 +3,11 @@ members = [ "api_identity", "bootstore", "certificates", + "clickhouse-admin", + "clickhouse-admin/api", + "clickhouse-admin/types", "clients/bootstrap-agent-client", + "clients/clickhouse-admin-client", "clients/cockroach-admin-client", "clients/ddm-admin-client", "clients/dns-service-client", @@ -111,7 +115,11 @@ default-members = [ "api_identity", "bootstore", "certificates", + "clickhouse-admin", + "clickhouse-admin/api", + "clickhouse-admin/types", "clients/bootstrap-agent-client", + "clients/clickhouse-admin-client", "clients/cockroach-admin-client", "clients/ddm-admin-client", "clients/dns-service-client", @@ -292,6 +300,9 @@ 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" } +clickhouse-admin-client = { path = "clients/clickhouse-admin-client" } +clickhouse-admin-types = { path = "clickhouse-admin/types" } clickward = { git = "https://github.com/oxidecomputer/clickward", rev = "ceec762e6a87d2a22bf56792a3025e145caa095e" } cockroach-admin-api = { path = "cockroach-admin/api" } cockroach-admin-client = { path = "clients/cockroach-admin-client" } diff --git a/clickhouse-admin/Cargo.toml b/clickhouse-admin/Cargo.toml new file mode 100644 index 0000000000..d5fd674786 --- /dev/null +++ b/clickhouse-admin/Cargo.toml @@ -0,0 +1,46 @@ +[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 +clickhouse-admin-types.workspace = true +dropshot.workspace = true +http.workspace = true +illumos-utils.workspace = true +omicron-common.workspace = true +omicron-uuid-kinds.workspace = true +once_cell.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 +proptest.workspace = true +serde_json.workspace = true +subprocess.workspace = true +test-strategy.workspace = true +url.workspace = true + +[lints] +workspace = true diff --git a/clickhouse-admin/api/Cargo.toml b/clickhouse-admin/api/Cargo.toml new file mode 100644 index 0000000000..a5d1dca202 --- /dev/null +++ b/clickhouse-admin/api/Cargo.toml @@ -0,0 +1,17 @@ +[package] +name = "clickhouse-admin-api" +version = "0.1.0" +edition = "2021" +license = "MPL-2.0" + +[lints] +workspace = true + +[dependencies] +clickhouse-admin-types.workspace = true +dropshot.workspace = true +omicron-common.workspace = true +omicron-uuid-kinds.workspace = true +omicron-workspace-hack.workspace = true +schemars.workspace = true +serde.workspace = true diff --git a/clickhouse-admin/api/src/lib.rs b/clickhouse-admin/api/src/lib.rs new file mode 100644 index 0000000000..b87b0a286d --- /dev/null +++ b/clickhouse-admin/api/src/lib.rs @@ -0,0 +1,3 @@ +// 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/. \ No newline at end of file diff --git a/clickhouse-admin/src/bin/clickhouse-admin.rs b/clickhouse-admin/src/bin/clickhouse-admin.rs new file mode 100644 index 0000000000..abff3d3dd7 --- /dev/null +++ b/clickhouse-admin/src/bin/clickhouse-admin.rs @@ -0,0 +1,19 @@ +// 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 omicron_common::cmd::fatal; +use omicron_common::cmd::CmdError; + +#[tokio::main] +async fn main() { + if let Err(err) = main_impl().await { + fatal(err); + } +} + +async fn main_impl() -> Result<(), CmdError> { + todo!(); +} \ No newline at end of file diff --git a/clickhouse-admin/types/Cargo.toml b/clickhouse-admin/types/Cargo.toml new file mode 100644 index 0000000000..ce99e9ed76 --- /dev/null +++ b/clickhouse-admin/types/Cargo.toml @@ -0,0 +1,18 @@ +[package] +name = "clickhouse-admin-types" +version = "0.1.0" +edition = "2021" +license = "MPL-2.0" + +[lints] +workspace = true + +[dependencies] +omicron-common.workspace = true +omicron-workspace-hack.workspace = true +schemars.workspace = true +serde.workspace = true + +[dev-dependencies] +proptest.workspace = true +test-strategy.workspace = true diff --git a/clickhouse-admin/types/src/lib.rs b/clickhouse-admin/types/src/lib.rs new file mode 100644 index 0000000000..e69de29bb2 diff --git a/clients/clickhouse-admin-client/Cargo.toml b/clients/clickhouse-admin-client/Cargo.toml new file mode 100644 index 0000000000..1491cd0134 --- /dev/null +++ b/clients/clickhouse-admin-client/Cargo.toml @@ -0,0 +1,18 @@ +[package] +name = "clickhouse-admin-client" +version = "0.1.0" +edition = "2021" +license = "MPL-2.0" + +[lints] +workspace = true + +[dependencies] +chrono.workspace = true +omicron-uuid-kinds.workspace = true +progenitor.workspace = true +reqwest = { workspace = true, features = [ "json", "rustls-tls", "stream" ] } +schemars.workspace = true +serde.workspace = true +slog.workspace = true +omicron-workspace-hack.workspace = true diff --git a/clients/clickhouse-admin-client/src/lib.rs b/clients/clickhouse-admin-client/src/lib.rs new file mode 100644 index 0000000000..4f5aa9d2ce --- /dev/null +++ b/clients/clickhouse-admin-client/src/lib.rs @@ -0,0 +1,25 @@ +// 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/. + +//! Interface for making API requests to an Omicron ClickHouse admin server + +// TODO: Is this necessary yet? +// progenitor::generate_api!( +// spec = "../../openapi/clickhouse-admin.json", +// inner_type = slog::Logger, +// pre_hook = (|log: &slog::Logger, request: &reqwest::Request| { +// slog::debug!(log, "client request"; +// "method" => %request.method(), +// "uri" => %request.url(), +// "body" => ?&request.body(), +// ); +// }), +// post_hook = (|log: &slog::Logger, result: &Result<_, _>| { +// slog::debug!(log, "client response"; "result" => ?result); +// }), +// derives = [schemars::JsonSchema], +// replace = { +// TypedUuidForOmicronZoneKind = omicron_uuid_kinds::OmicronZoneUuid, +// } +// ); From 45f8ae586992b9b188bc4eb8eb31137875c7aeb6 Mon Sep 17 00:00:00 2001 From: karencfv Date: Tue, 13 Aug 2024 16:13:25 +1200 Subject: [PATCH 02/10] Working dropshot server --- Cargo.toml | 1 + clickhouse-admin/api/src/lib.rs | 26 +++++++- clickhouse-admin/dummy-config.toml | 10 +++ clickhouse-admin/src/bin/clickhouse-admin.rs | 54 ++++++++++++++- clickhouse-admin/src/clickward.rs | 49 ++++++++++++++ clickhouse-admin/src/config.rs | 43 ++++++++++++ clickhouse-admin/src/context.rs | 21 ++++++ clickhouse-admin/src/http_entrypoints.rs | 31 +++++++++ clickhouse-admin/src/lib.rs | 70 ++++++++++++++++++++ clickhouse-admin/types/src/lib.rs | 1 + 10 files changed, 303 insertions(+), 3 deletions(-) create mode 100644 clickhouse-admin/dummy-config.toml create mode 100644 clickhouse-admin/src/clickward.rs create mode 100644 clickhouse-admin/src/config.rs create mode 100644 clickhouse-admin/src/context.rs create mode 100644 clickhouse-admin/src/http_entrypoints.rs create mode 100644 clickhouse-admin/src/lib.rs diff --git a/Cargo.toml b/Cargo.toml index 092883cabf..ef8845e12a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -425,6 +425,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" } diff --git a/clickhouse-admin/api/src/lib.rs b/clickhouse-admin/api/src/lib.rs index b87b0a286d..4c72b1f576 100644 --- a/clickhouse-admin/api/src/lib.rs +++ b/clickhouse-admin/api/src/lib.rs @@ -1,3 +1,27 @@ // 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/. \ No newline at end of file +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +use dropshot::{HttpError, HttpResponseOk, RequestContext}; +use schemars::JsonSchema; +use serde::{Deserialize, Serialize}; + +#[dropshot::api_description] +pub trait ClickhouseAdminApi { + type Context; + + /// Get the status of all nodes in the ClickHouse cluster. + #[endpoint { + method = GET, + path = "/test", + }] + async fn ch_test( + rqctx: RequestContext, + ) -> Result, HttpError>; +} + +#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize, JsonSchema)] +#[serde(rename_all = "snake_case")] +pub struct ChTest { + pub result: String, +} diff --git a/clickhouse-admin/dummy-config.toml b/clickhouse-admin/dummy-config.toml new file mode 100644 index 0000000000..86ee2c5d4b --- /dev/null +++ b/clickhouse-admin/dummy-config.toml @@ -0,0 +1,10 @@ +[dropshot] +# 1 MiB; we don't expect any requests of more than nominal size. +request_body_max_bytes = 1048576 + +[log] +# Show log messages of this level and more severe +level = "info" +mode = "file" +path = "/dev/stdout" +if_exists = "append" diff --git a/clickhouse-admin/src/bin/clickhouse-admin.rs b/clickhouse-admin/src/bin/clickhouse-admin.rs index abff3d3dd7..85567ff376 100644 --- a/clickhouse-admin/src/bin/clickhouse-admin.rs +++ b/clickhouse-admin/src/bin/clickhouse-admin.rs @@ -4,8 +4,35 @@ //! 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::{Ipv6Addr, SocketAddr, SocketAddrV6}; + +#[derive(Debug, Parser)] +#[clap( + name = "clickhouse-admin", + about = "Omicron ClickHouse cluster admin server" +)] +enum Args { + /// Start the ClickHouse admin server + Run { + // TODO: take the clickhouse address as an argument + /// Address on which this server should run + #[clap(long, action)] + http_address: SocketAddrV6, + + /// Path to the server config file + #[clap(long, action)] + config_file_path: Utf8PathBuf, + }, +} + +// TODO: Remove this comment and move config file to smf/clickhouse-admin +// Test with clickhouse-admin run --http-address [::1]:8888 --config-file-path ./clickhouse-admin/dummy-config.toml #[tokio::main] async fn main() { @@ -15,5 +42,28 @@ async fn main() { } async fn main_impl() -> Result<(), CmdError> { - todo!(); -} \ No newline at end of file + let args = Args::parse(); + + match args { + Args::Run { http_address, config_file_path } => { + let mut config = Config::from_file(&config_file_path) + .map_err(|err| CmdError::Failure(anyhow!(err)))?; + config.dropshot.bind_address = SocketAddr::V6(http_address); + + // TODO: Change for the actual clickhouse address + let dummy_address = + SocketAddrV6::new(Ipv6Addr::LOCALHOST, 8080, 0, 0); + let clickward = Clickward::new(dummy_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}" + )) + }) + } + } +} diff --git a/clickhouse-admin/src/clickward.rs b/clickhouse-admin/src/clickward.rs new file mode 100644 index 0000000000..be90ee2791 --- /dev/null +++ b/clickhouse-admin/src/clickward.rs @@ -0,0 +1,49 @@ +// 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::ChTest; +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 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 noop(&self) -> Result { + Ok(ChTest { result: format!("it works!: {}", self.clickhouse_address) }) + } +} diff --git a/clickhouse-admin/src/config.rs b/clickhouse-admin/src/config.rs new file mode 100644 index 0000000000..77a624835c --- /dev/null +++ b/clickhouse-admin/src/config.rs @@ -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 { + 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, + }, +} diff --git a/clickhouse-admin/src/context.rs b/clickhouse-admin/src/context.rs new file mode 100644 index 0000000000..cab875fe1d --- /dev/null +++ b/clickhouse-admin/src/context.rs @@ -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 + } +} diff --git a/clickhouse-admin/src/http_entrypoints.rs b/clickhouse-admin/src/http_entrypoints.rs new file mode 100644 index 0000000000..4a5062b053 --- /dev/null +++ b/clickhouse-admin/src/http_entrypoints.rs @@ -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>; + +pub fn api() -> ClickhouseApiDescription { + clickhouse_admin_api_mod::api_description::() + .expect("registered entrypoints") +} + +enum ClickhouseAdminImpl {} + +impl ClickhouseAdminApi for ClickhouseAdminImpl { + type Context = Arc; + + async fn ch_test( + rqctx: RequestContext, + ) -> Result, HttpError> { + let ctx = rqctx.context(); + let output = ctx.clickward().noop()?; + Ok(HttpResponseOk(output)) + } +} diff --git a/clickhouse-admin/src/lib.rs b/clickhouse-admin/src/lib.rs new file mode 100644 index 0000000000..a48588c544 --- /dev/null +++ b/clickhouse-admin/src/lib.rs @@ -0,0 +1,70 @@ +// 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 context::ServerContext; +use omicron_common::FileKv; +use slog::{debug, error, Drain}; +use slog_dtrace::ProbeRegistration; +use slog_error_chain::SlogInlineError; +use std::error::Error; +use std::io; +use std::sync::Arc; + +mod clickward; +mod config; +mod context; +mod http_entrypoints; + +pub use clickward::Clickward; +pub use config::Config; + +#[derive(Debug, thiserror::Error, SlogInlineError)] +pub enum StartError { + #[error("failed to initialize logger")] + InitializeLogger(#[source] io::Error), + #[error("failed to register dtrace probes: {0}")] + RegisterDtraceProbes(String), + #[error("failed to initialize HTTP server")] + InitializeHttpServer(#[source] Box), +} + +pub type Server = dropshot::HttpServer>; + +/// Start the dropshot server +pub async fn start_server( + clickward: Clickward, + server_config: Config, +) -> Result { + let (drain, registration) = slog_dtrace::with_drain( + server_config + .log + .to_logger("clickhouse-admin") + .map_err(StartError::InitializeLogger)?, + ); + let log = slog::Logger::root(drain.fuse(), slog::o!(FileKv)); + match registration { + ProbeRegistration::Success => { + debug!(log, "registered DTrace probes"); + } + ProbeRegistration::Failed(err) => { + let err = StartError::RegisterDtraceProbes(err); + error!(log, "failed to register DTrace probes"; &err); + return Err(err); + } + } + + let context = ServerContext::new( + clickward, + log.new(slog::o!("component" => "ServerContext")), + ); + let http_server_starter = dropshot::HttpServerStarter::new( + &server_config.dropshot, + http_entrypoints::api(), + Arc::new(context), + &log.new(slog::o!("component" => "dropshot")), + ) + .map_err(StartError::InitializeHttpServer)?; + + Ok(http_server_starter.start()) +} diff --git a/clickhouse-admin/types/src/lib.rs b/clickhouse-admin/types/src/lib.rs index e69de29bb2..8b13789179 100644 --- a/clickhouse-admin/types/src/lib.rs +++ b/clickhouse-admin/types/src/lib.rs @@ -0,0 +1 @@ + From 9e424e56b88e3a741662de1e5f67ab5c48f9c643 Mon Sep 17 00:00:00 2001 From: karencfv Date: Tue, 13 Aug 2024 16:15:24 +1200 Subject: [PATCH 03/10] fix cmd --- clickhouse-admin/src/bin/clickhouse-admin.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clickhouse-admin/src/bin/clickhouse-admin.rs b/clickhouse-admin/src/bin/clickhouse-admin.rs index 85567ff376..5a0d83410d 100644 --- a/clickhouse-admin/src/bin/clickhouse-admin.rs +++ b/clickhouse-admin/src/bin/clickhouse-admin.rs @@ -32,7 +32,7 @@ enum Args { } // TODO: Remove this comment and move config file to smf/clickhouse-admin -// Test with clickhouse-admin run --http-address [::1]:8888 --config-file-path ./clickhouse-admin/dummy-config.toml +// Test with cargo run --bin=clickhouse-admin -- run --http-address [::1]:8888 --config-file-path ./clickhouse-admin/dummy-config.toml #[tokio::main] async fn main() { From ddb45a500cd9d00da261b59cd68761a0ede76f8b Mon Sep 17 00:00:00 2001 From: karencfv Date: Wed, 14 Aug 2024 12:40:21 +1200 Subject: [PATCH 04/10] Generate OpenAPI json spec --- Cargo.lock | 1 + dev-tools/openapi-manager/Cargo.toml | 1 + dev-tools/openapi-manager/src/spec.rs | 11 ++++ openapi/clickhouse-admin.json | 84 +++++++++++++++++++++++++++ 4 files changed, 97 insertions(+) create mode 100644 openapi/clickhouse-admin.json diff --git a/Cargo.lock b/Cargo.lock index fa2714f3f3..21291d2337 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6431,6 +6431,7 @@ dependencies = [ "bootstrap-agent-api", "camino", "clap", + "clickhouse-admin-api", "cockroach-admin-api", "dns-server-api", "dropshot", diff --git a/dev-tools/openapi-manager/Cargo.toml b/dev-tools/openapi-manager/Cargo.toml index e60000cc06..df078d6fdf 100644 --- a/dev-tools/openapi-manager/Cargo.toml +++ b/dev-tools/openapi-manager/Cargo.toml @@ -12,6 +12,7 @@ anyhow.workspace = true atomicwrites.workspace = true bootstrap-agent-api.workspace = true camino.workspace = true +clickhouse-admin-api.workspace = true cockroach-admin-api.workspace = true clap.workspace = true dns-server-api.workspace = true diff --git a/dev-tools/openapi-manager/src/spec.rs b/dev-tools/openapi-manager/src/spec.rs index f991d35ec4..b616cd1c99 100644 --- a/dev-tools/openapi-manager/src/spec.rs +++ b/dev-tools/openapi-manager/src/spec.rs @@ -24,6 +24,17 @@ pub fn all_apis() -> Vec { filename: "bootstrap-agent.json", extra_validation: None, }, + ApiSpec { + title: "ClickHouse Cluster Admin API", + version: "0.0.1", + description: "API for interacting with the Oxide \ + control plane's ClickHouse cluster", + boundary: ApiBoundary::Internal, + api_description: + clickhouse_admin_api::clickhouse_admin_api_mod::stub_api_description, + filename: "clickhouse-admin.json", + extra_validation: None, + }, ApiSpec { title: "CockroachDB Cluster Admin API", version: "0.0.1", diff --git a/openapi/clickhouse-admin.json b/openapi/clickhouse-admin.json new file mode 100644 index 0000000000..20ee1d3083 --- /dev/null +++ b/openapi/clickhouse-admin.json @@ -0,0 +1,84 @@ +{ + "openapi": "3.0.3", + "info": { + "title": "ClickHouse Cluster Admin API", + "description": "API for interacting with the Oxide control plane's ClickHouse cluster", + "contact": { + "url": "https://oxide.computer", + "email": "api@oxide.computer" + }, + "version": "0.0.1" + }, + "paths": { + "/test": { + "get": { + "summary": "Get the status of all nodes in the ClickHouse cluster.", + "operationId": "ch_test", + "responses": { + "200": { + "description": "successful operation", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ChTest" + } + } + } + }, + "4XX": { + "$ref": "#/components/responses/Error" + }, + "5XX": { + "$ref": "#/components/responses/Error" + } + } + } + } + }, + "components": { + "schemas": { + "ChTest": { + "type": "object", + "properties": { + "result": { + "type": "string" + } + }, + "required": [ + "result" + ] + }, + "Error": { + "description": "Error information from a response.", + "type": "object", + "properties": { + "error_code": { + "type": "string" + }, + "message": { + "type": "string" + }, + "request_id": { + "type": "string" + } + }, + "required": [ + "message", + "request_id" + ] + } + }, + "responses": { + "Error": { + "description": "Error", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/Error" + } + } + } + } + } + } +} From f6d299491e30e2cbc72823113db19cb3f0405e0d Mon Sep 17 00:00:00 2001 From: karencfv Date: Wed, 14 Aug 2024 15:37:20 +1200 Subject: [PATCH 05/10] Create clickhouse-admin service and include it in clickhouse and keeper zones --- clickhouse-admin/src/bin/clickhouse-admin.rs | 14 +++--- common/src/address.rs | 1 + package-manifest.toml | 14 ++++++ sled-agent/src/services.rs | 50 +++++++++++++++++++- 4 files changed, 70 insertions(+), 9 deletions(-) diff --git a/clickhouse-admin/src/bin/clickhouse-admin.rs b/clickhouse-admin/src/bin/clickhouse-admin.rs index 5a0d83410d..7208dc2d57 100644 --- a/clickhouse-admin/src/bin/clickhouse-admin.rs +++ b/clickhouse-admin/src/bin/clickhouse-admin.rs @@ -22,17 +22,17 @@ enum Args { Run { // TODO: take the clickhouse address as an argument /// Address on which this server should run - #[clap(long, action)] + #[clap(long, short = 'H', action)] http_address: SocketAddrV6, - /// Path to the server config file - #[clap(long, action)] - config_file_path: Utf8PathBuf, + /// Path to the server configuration file + #[clap(long, short, action)] + config: Utf8PathBuf, }, } // TODO: Remove this comment and move config file to smf/clickhouse-admin -// Test with cargo run --bin=clickhouse-admin -- run --http-address [::1]:8888 --config-file-path ./clickhouse-admin/dummy-config.toml +// Test with cargo run --bin=clickhouse-admin -- run -H [::1]:8888 -c ./clickhouse-admin/dummy-config.toml #[tokio::main] async fn main() { @@ -45,8 +45,8 @@ async fn main_impl() -> Result<(), CmdError> { let args = Args::parse(); match args { - Args::Run { http_address, config_file_path } => { - let mut config = Config::from_file(&config_file_path) + Args::Run { 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); diff --git a/common/src/address.rs b/common/src/address.rs index 5ed5689289..ba1193c7f0 100644 --- a/common/src/address.rs +++ b/common/src/address.rs @@ -59,6 +59,7 @@ pub const COCKROACH_ADMIN_PORT: u16 = 32222; pub const CRUCIBLE_PORT: u16 = 32345; pub const CLICKHOUSE_PORT: u16 = 8123; pub const CLICKHOUSE_KEEPER_PORT: u16 = 9181; +pub const CLICKHOUSE_ADMIN_PORT: u16 = 8888; pub const OXIMETER_PORT: u16 = 12223; pub const DENDRITE_PORT: u16 = 12224; pub const LLDP_PORT: u16 = 12230; diff --git a/package-manifest.toml b/package-manifest.toml index 5ee81e722b..3229105815 100644 --- a/package-manifest.toml +++ b/package-manifest.toml @@ -153,6 +153,7 @@ source.type = "composite" source.packages = [ "clickhouse_svc.tar.gz", "internal-dns-cli.tar.gz", + "omicron-clickhouse-admin.tar.gz", "zone-setup.tar.gz", "zone-network-install.tar.gz" ] @@ -179,6 +180,7 @@ source.type = "composite" source.packages = [ "clickhouse_keeper_svc.tar.gz", "internal-dns-cli.tar.gz", + "omicron-clickhouse-admin.tar.gz", "zone-setup.tar.gz", "zone-network-install.tar.gz" ] @@ -198,6 +200,18 @@ output.type = "zone" output.intermediate_only = true setup_hint = "Run `cargo xtask download clickhouse` to download the necessary binaries" +[package.omicron-clickhouse-admin] +service_name = "clickhouse-admin" +only_for_targets.image = "standard" +source.type = "local" +source.rust.binary_names = ["clickhouse-admin"] +source.rust.release = true +source.paths = [ + { from = "smf/clickhouse-admin", to = "/var/svc/manifest/site/clickhouse-admin" }, +] +output.type = "zone" +output.intermediate_only = true + [package.cockroachdb] service_name = "cockroachdb" only_for_targets.image = "standard" diff --git a/sled-agent/src/services.rs b/sled-agent/src/services.rs index a79d5b68e7..cc2599d2b2 100644 --- a/sled-agent/src/services.rs +++ b/sled-agent/src/services.rs @@ -68,6 +68,7 @@ use nexus_config::{ConfigDropshotWithTls, DeploymentConfig}; use nexus_sled_agent_shared::inventory::{ OmicronZoneConfig, OmicronZoneType, OmicronZonesConfig, ZoneKind, }; +use omicron_common::address::CLICKHOUSE_ADMIN_PORT; use omicron_common::address::CLICKHOUSE_KEEPER_PORT; use omicron_common::address::CLICKHOUSE_PORT; use omicron_common::address::COCKROACH_PORT; @@ -1549,6 +1550,11 @@ impl ServiceManager { let listen_addr = *underlay_address; let listen_port = &CLICKHOUSE_PORT.to_string(); + let admin_address = SocketAddr::new( + IpAddr::V6(listen_addr), + CLICKHOUSE_ADMIN_PORT, + ) + .to_string(); let nw_setup_service = Self::zone_network_setup_install( Some(&info.underlay_address), @@ -1572,12 +1578,29 @@ impl ServiceManager { .add_property_group(config), ); + let clickhouse_admin_config = + PropertyGroupBuilder::new("config") + // TODO: Add zone ID? + //.add_property("zone_id", "astring", zone_id.to_string()) + .add_property( + "clickhouse_address", + "astring", + listen_addr.to_string(), + ) + .add_property("http_address", "astring", admin_address); + let clickhouse_admin_service = + ServiceBuilder::new("oxide/clickhouse-admin").add_instance( + ServiceInstanceBuilder::new("default") + .add_property_group(clickhouse_admin_config), + ); + let profile = ProfileBuilder::new("omicron") .add_service(nw_setup_service) .add_service(disabled_ssh_service) .add_service(clickhouse_service) .add_service(dns_service) - .add_service(enabled_dns_client_service); + .add_service(enabled_dns_client_service) + .add_service(clickhouse_admin_service); profile .add_to_zone(&self.inner.log, &installed_zone) .await @@ -1602,6 +1625,11 @@ impl ServiceManager { let listen_addr = *underlay_address; let listen_port = &CLICKHOUSE_KEEPER_PORT.to_string(); + let admin_address = SocketAddr::new( + IpAddr::V6(listen_addr), + CLICKHOUSE_ADMIN_PORT, + ) + .to_string(); let nw_setup_service = Self::zone_network_setup_install( Some(&info.underlay_address), @@ -1625,12 +1653,30 @@ impl ServiceManager { ServiceInstanceBuilder::new("default") .add_property_group(config), ); + + let clickhouse_admin_config = + PropertyGroupBuilder::new("config") + // TODO: Add zone ID? + //.add_property("zone_id", "astring", zone_id.to_string()) + .add_property( + "clickhouse_address", + "astring", + listen_addr.to_string(), + ) + .add_property("http_address", "astring", admin_address); + let clickhouse_admin_service = + ServiceBuilder::new("oxide/clickhouse-admin").add_instance( + ServiceInstanceBuilder::new("default") + .add_property_group(clickhouse_admin_config), + ); + let profile = ProfileBuilder::new("omicron") .add_service(nw_setup_service) .add_service(disabled_ssh_service) .add_service(clickhouse_keeper_service) .add_service(dns_service) - .add_service(enabled_dns_client_service); + .add_service(enabled_dns_client_service) + .add_service(clickhouse_admin_service); profile .add_to_zone(&self.inner.log, &installed_zone) .await From cb8e98d0b2e6d4b6e9c1397e118b55aa77f2701a Mon Sep 17 00:00:00 2001 From: karencfv Date: Wed, 14 Aug 2024 15:39:52 +1200 Subject: [PATCH 06/10] Add new files --- smf/clickhouse-admin/config.toml | 10 +++++++ smf/clickhouse-admin/manifest.xml | 46 +++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 smf/clickhouse-admin/config.toml create mode 100644 smf/clickhouse-admin/manifest.xml diff --git a/smf/clickhouse-admin/config.toml b/smf/clickhouse-admin/config.toml new file mode 100644 index 0000000000..86ee2c5d4b --- /dev/null +++ b/smf/clickhouse-admin/config.toml @@ -0,0 +1,10 @@ +[dropshot] +# 1 MiB; we don't expect any requests of more than nominal size. +request_body_max_bytes = 1048576 + +[log] +# Show log messages of this level and more severe +level = "info" +mode = "file" +path = "/dev/stdout" +if_exists = "append" diff --git a/smf/clickhouse-admin/manifest.xml b/smf/clickhouse-admin/manifest.xml new file mode 100644 index 0000000000..90efa28f11 --- /dev/null +++ b/smf/clickhouse-admin/manifest.xml @@ -0,0 +1,46 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + From a487b63b291c8cb8e3b55269b82a3babf5d8d527 Mon Sep 17 00:00:00 2001 From: karencfv Date: Wed, 14 Aug 2024 18:12:38 +1200 Subject: [PATCH 07/10] Endpoint to retrieve node listen address --- clickhouse-admin/api/src/lib.rs | 13 +++--- clickhouse-admin/src/bin/clickhouse-admin.rs | 17 ++++---- clickhouse-admin/src/clickward.rs | 6 +-- clickhouse-admin/src/http_entrypoints.rs | 6 +-- openapi/clickhouse-admin.json | 14 +++---- sled-agent/src/services.rs | 42 ++++++++++++-------- smf/clickhouse-admin/manifest.xml | 3 +- 7 files changed, 57 insertions(+), 44 deletions(-) diff --git a/clickhouse-admin/api/src/lib.rs b/clickhouse-admin/api/src/lib.rs index 4c72b1f576..9a011d4387 100644 --- a/clickhouse-admin/api/src/lib.rs +++ b/clickhouse-admin/api/src/lib.rs @@ -5,23 +5,24 @@ use dropshot::{HttpError, HttpResponseOk, RequestContext}; use schemars::JsonSchema; use serde::{Deserialize, Serialize}; +use std::net::SocketAddrV6; #[dropshot::api_description] pub trait ClickhouseAdminApi { type Context; - /// Get the status of all nodes in the ClickHouse cluster. + /// Retrieve the address the ClickHouse server or keeper node is listening on #[endpoint { method = GET, - path = "/test", + path = "/node/address", }] - async fn ch_test( + async fn clickhouse_address( rqctx: RequestContext, - ) -> Result, HttpError>; + ) -> Result, HttpError>; } #[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize, JsonSchema)] #[serde(rename_all = "snake_case")] -pub struct ChTest { - pub result: String, +pub struct ClickhouseAddress { + pub clickhouse_address: SocketAddrV6, } diff --git a/clickhouse-admin/src/bin/clickhouse-admin.rs b/clickhouse-admin/src/bin/clickhouse-admin.rs index 7208dc2d57..8ba430b7bf 100644 --- a/clickhouse-admin/src/bin/clickhouse-admin.rs +++ b/clickhouse-admin/src/bin/clickhouse-admin.rs @@ -10,7 +10,7 @@ use clap::Parser; use omicron_clickhouse_admin::{Clickward, Config}; use omicron_common::cmd::fatal; use omicron_common::cmd::CmdError; -use std::net::{Ipv6Addr, SocketAddr, SocketAddrV6}; +use std::net::{SocketAddr, SocketAddrV6}; #[derive(Debug, Parser)] #[clap( @@ -20,7 +20,10 @@ use std::net::{Ipv6Addr, SocketAddr, SocketAddrV6}; enum Args { /// Start the ClickHouse admin server Run { - // TODO: take the clickhouse address as an argument + /// Socket address for a running clickhouse server orr 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, @@ -32,7 +35,7 @@ enum Args { } // TODO: Remove this comment and move config file to smf/clickhouse-admin -// Test with cargo run --bin=clickhouse-admin -- run -H [::1]:8888 -c ./clickhouse-admin/dummy-config.toml +// Test with cargo run --bin=clickhouse-admin -- run -a [fd00:1122:3344:101::e]:8888 -H [::1]:8888 -c ./clickhouse-admin/dummy-config.toml #[tokio::main] async fn main() { @@ -45,15 +48,15 @@ async fn main_impl() -> Result<(), CmdError> { let args = Args::parse(); match args { - Args::Run { http_address, config } => { + 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); // TODO: Change for the actual clickhouse address - let dummy_address = - SocketAddrV6::new(Ipv6Addr::LOCALHOST, 8080, 0, 0); - let clickward = Clickward::new(dummy_address); + // let dummy_address = + // SocketAddrV6::new(Ipv6Addr::LOCALHOST, 8080, 0, 0); + let clickward = Clickward::new(clickhouse_address); let server = omicron_clickhouse_admin::start_server(clickward, config) diff --git a/clickhouse-admin/src/clickward.rs b/clickhouse-admin/src/clickward.rs index be90ee2791..fe87adc523 100644 --- a/clickhouse-admin/src/clickward.rs +++ b/clickhouse-admin/src/clickward.rs @@ -2,7 +2,7 @@ // 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::ChTest; +use clickhouse_admin_api::ClickhouseAddress; use dropshot::HttpError; use slog_error_chain::{InlineErrorChain, SlogInlineError}; use std::io; @@ -43,7 +43,7 @@ impl Clickward { Self { clickhouse_address } } - pub fn noop(&self) -> Result { - Ok(ChTest { result: format!("it works!: {}", self.clickhouse_address) }) + pub fn clickhouse_address(&self) -> Result { + Ok(ClickhouseAddress { clickhouse_address: self.clickhouse_address }) } } diff --git a/clickhouse-admin/src/http_entrypoints.rs b/clickhouse-admin/src/http_entrypoints.rs index 4a5062b053..05988a73b0 100644 --- a/clickhouse-admin/src/http_entrypoints.rs +++ b/clickhouse-admin/src/http_entrypoints.rs @@ -21,11 +21,11 @@ enum ClickhouseAdminImpl {} impl ClickhouseAdminApi for ClickhouseAdminImpl { type Context = Arc; - async fn ch_test( + async fn clickhouse_address( rqctx: RequestContext, - ) -> Result, HttpError> { + ) -> Result, HttpError> { let ctx = rqctx.context(); - let output = ctx.clickward().noop()?; + let output = ctx.clickward().clickhouse_address()?; Ok(HttpResponseOk(output)) } } diff --git a/openapi/clickhouse-admin.json b/openapi/clickhouse-admin.json index 20ee1d3083..6bb5367712 100644 --- a/openapi/clickhouse-admin.json +++ b/openapi/clickhouse-admin.json @@ -10,17 +10,17 @@ "version": "0.0.1" }, "paths": { - "/test": { + "/node/address": { "get": { - "summary": "Get the status of all nodes in the ClickHouse cluster.", - "operationId": "ch_test", + "summary": "Retrieve the address the ClickHouse server or keeper node is listening on", + "operationId": "clickhouse_address", "responses": { "200": { "description": "successful operation", "content": { "application/json": { "schema": { - "$ref": "#/components/schemas/ChTest" + "$ref": "#/components/schemas/ClickhouseAddress" } } } @@ -37,15 +37,15 @@ }, "components": { "schemas": { - "ChTest": { + "ClickhouseAddress": { "type": "object", "properties": { - "result": { + "clickhouse_address": { "type": "string" } }, "required": [ - "result" + "clickhouse_address" ] }, "Error": { diff --git a/sled-agent/src/services.rs b/sled-agent/src/services.rs index cc2599d2b2..d579f39d72 100644 --- a/sled-agent/src/services.rs +++ b/sled-agent/src/services.rs @@ -1550,11 +1550,6 @@ impl ServiceManager { let listen_addr = *underlay_address; let listen_port = &CLICKHOUSE_PORT.to_string(); - let admin_address = SocketAddr::new( - IpAddr::V6(listen_addr), - CLICKHOUSE_ADMIN_PORT, - ) - .to_string(); let nw_setup_service = Self::zone_network_setup_install( Some(&info.underlay_address), @@ -1578,14 +1573,24 @@ impl ServiceManager { .add_property_group(config), ); + let ch_address = SocketAddr::new( + IpAddr::V6(listen_addr), + CLICKHOUSE_PORT, + ) + .to_string(); + + let admin_address = SocketAddr::new( + IpAddr::V6(listen_addr), + CLICKHOUSE_ADMIN_PORT, + ) + .to_string(); + let clickhouse_admin_config = PropertyGroupBuilder::new("config") - // TODO: Add zone ID? - //.add_property("zone_id", "astring", zone_id.to_string()) .add_property( "clickhouse_address", "astring", - listen_addr.to_string(), + ch_address, ) .add_property("http_address", "astring", admin_address); let clickhouse_admin_service = @@ -1625,11 +1630,6 @@ impl ServiceManager { let listen_addr = *underlay_address; let listen_port = &CLICKHOUSE_KEEPER_PORT.to_string(); - let admin_address = SocketAddr::new( - IpAddr::V6(listen_addr), - CLICKHOUSE_ADMIN_PORT, - ) - .to_string(); let nw_setup_service = Self::zone_network_setup_install( Some(&info.underlay_address), @@ -1654,14 +1654,24 @@ impl ServiceManager { .add_property_group(config), ); + let ch_address = SocketAddr::new( + IpAddr::V6(listen_addr), + CLICKHOUSE_PORT, + ) + .to_string(); + + let admin_address = SocketAddr::new( + IpAddr::V6(listen_addr), + CLICKHOUSE_ADMIN_PORT, + ) + .to_string(); + let clickhouse_admin_config = PropertyGroupBuilder::new("config") - // TODO: Add zone ID? - //.add_property("zone_id", "astring", zone_id.to_string()) .add_property( "clickhouse_address", "astring", - listen_addr.to_string(), + ch_address, ) .add_property("http_address", "astring", admin_address); let clickhouse_admin_service = diff --git a/smf/clickhouse-admin/manifest.xml b/smf/clickhouse-admin/manifest.xml index 90efa28f11..435f8a86ac 100644 --- a/smf/clickhouse-admin/manifest.xml +++ b/smf/clickhouse-admin/manifest.xml @@ -17,12 +17,11 @@ - From f2ba87e8060c4b91c613bc85e75ba20c99f728fb Mon Sep 17 00:00:00 2001 From: karencfv Date: Wed, 14 Aug 2024 18:57:02 +1200 Subject: [PATCH 08/10] Clean up --- Cargo.lock | 30 ---------------- Cargo.toml | 6 ---- clickhouse-admin/Cargo.toml | 3 -- clickhouse-admin/api/Cargo.toml | 1 - clickhouse-admin/dummy-config.toml | 10 ------ clickhouse-admin/src/bin/clickhouse-admin.rs | 6 ---- clickhouse-admin/src/clickward.rs | 4 ++- clickhouse-admin/types/Cargo.toml | 18 ---------- clickhouse-admin/types/src/lib.rs | 1 - clients/clickhouse-admin-client/Cargo.toml | 18 ---------- clients/clickhouse-admin-client/src/lib.rs | 25 -------------- sled-agent/src/services.rs | 36 +++++++++----------- 12 files changed, 19 insertions(+), 139 deletions(-) delete mode 100644 clickhouse-admin/dummy-config.toml delete mode 100644 clickhouse-admin/types/Cargo.toml delete mode 100644 clickhouse-admin/types/src/lib.rs delete mode 100644 clients/clickhouse-admin-client/Cargo.toml delete mode 100644 clients/clickhouse-admin-client/src/lib.rs diff --git a/Cargo.lock b/Cargo.lock index 21291d2337..cf1339d7c9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1112,7 +1112,6 @@ checksum = "98cc8fbded0c607b7ba9dd60cd98df59af97e84d24e49c8557331cfc26d301ce" name = "clickhouse-admin-api" version = "0.1.0" dependencies = [ - "clickhouse-admin-types", "dropshot", "omicron-common", "omicron-uuid-kinds", @@ -1121,32 +1120,6 @@ dependencies = [ "serde", ] -[[package]] -name = "clickhouse-admin-client" -version = "0.1.0" -dependencies = [ - "chrono", - "omicron-uuid-kinds", - "omicron-workspace-hack", - "progenitor", - "reqwest", - "schemars", - "serde", - "slog", -] - -[[package]] -name = "clickhouse-admin-types" -version = "0.1.0" -dependencies = [ - "omicron-common", - "omicron-workspace-hack", - "proptest", - "schemars", - "serde", - "test-strategy", -] - [[package]] name = "clickward" version = "0.1.0" @@ -5585,7 +5558,6 @@ dependencies = [ "chrono", "clap", "clickhouse-admin-api", - "clickhouse-admin-types", "dropshot", "expectorate", "http 0.2.12", @@ -5598,7 +5570,6 @@ dependencies = [ "once_cell", "openapi-lint", "openapiv3", - "proptest", "schemars", "serde", "serde_json", @@ -5607,7 +5578,6 @@ dependencies = [ "slog-dtrace", "slog-error-chain", "subprocess", - "test-strategy", "thiserror", "tokio", "tokio-postgres", diff --git a/Cargo.toml b/Cargo.toml index ef8845e12a..bdc682664b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,9 +5,7 @@ members = [ "certificates", "clickhouse-admin", "clickhouse-admin/api", - "clickhouse-admin/types", "clients/bootstrap-agent-client", - "clients/clickhouse-admin-client", "clients/cockroach-admin-client", "clients/ddm-admin-client", "clients/dns-service-client", @@ -117,9 +115,7 @@ default-members = [ "certificates", "clickhouse-admin", "clickhouse-admin/api", - "clickhouse-admin/types", "clients/bootstrap-agent-client", - "clients/clickhouse-admin-client", "clients/cockroach-admin-client", "clients/ddm-admin-client", "clients/dns-service-client", @@ -301,8 +297,6 @@ 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" } -clickhouse-admin-client = { path = "clients/clickhouse-admin-client" } -clickhouse-admin-types = { path = "clickhouse-admin/types" } clickward = { git = "https://github.com/oxidecomputer/clickward", rev = "ceec762e6a87d2a22bf56792a3025e145caa095e" } cockroach-admin-api = { path = "cockroach-admin/api" } cockroach-admin-client = { path = "clients/cockroach-admin-client" } diff --git a/clickhouse-admin/Cargo.toml b/clickhouse-admin/Cargo.toml index d5fd674786..8517eb44af 100644 --- a/clickhouse-admin/Cargo.toml +++ b/clickhouse-admin/Cargo.toml @@ -10,7 +10,6 @@ camino.workspace = true chrono.workspace = true clap.workspace = true clickhouse-admin-api.workspace = true -clickhouse-admin-types.workspace = true dropshot.workspace = true http.workspace = true illumos-utils.workspace = true @@ -36,10 +35,8 @@ nexus-test-utils.workspace = true omicron-test-utils.workspace = true openapi-lint.workspace = true openapiv3.workspace = true -proptest.workspace = true serde_json.workspace = true subprocess.workspace = true -test-strategy.workspace = true url.workspace = true [lints] diff --git a/clickhouse-admin/api/Cargo.toml b/clickhouse-admin/api/Cargo.toml index a5d1dca202..ceec09f6c8 100644 --- a/clickhouse-admin/api/Cargo.toml +++ b/clickhouse-admin/api/Cargo.toml @@ -8,7 +8,6 @@ license = "MPL-2.0" workspace = true [dependencies] -clickhouse-admin-types.workspace = true dropshot.workspace = true omicron-common.workspace = true omicron-uuid-kinds.workspace = true diff --git a/clickhouse-admin/dummy-config.toml b/clickhouse-admin/dummy-config.toml deleted file mode 100644 index 86ee2c5d4b..0000000000 --- a/clickhouse-admin/dummy-config.toml +++ /dev/null @@ -1,10 +0,0 @@ -[dropshot] -# 1 MiB; we don't expect any requests of more than nominal size. -request_body_max_bytes = 1048576 - -[log] -# Show log messages of this level and more severe -level = "info" -mode = "file" -path = "/dev/stdout" -if_exists = "append" diff --git a/clickhouse-admin/src/bin/clickhouse-admin.rs b/clickhouse-admin/src/bin/clickhouse-admin.rs index 8ba430b7bf..26c37086cc 100644 --- a/clickhouse-admin/src/bin/clickhouse-admin.rs +++ b/clickhouse-admin/src/bin/clickhouse-admin.rs @@ -34,9 +34,6 @@ enum Args { }, } -// TODO: Remove this comment and move config file to smf/clickhouse-admin -// Test with cargo run --bin=clickhouse-admin -- run -a [fd00:1122:3344:101::e]:8888 -H [::1]:8888 -c ./clickhouse-admin/dummy-config.toml - #[tokio::main] async fn main() { if let Err(err) = main_impl().await { @@ -53,9 +50,6 @@ async fn main_impl() -> Result<(), CmdError> { .map_err(|err| CmdError::Failure(anyhow!(err)))?; config.dropshot.bind_address = SocketAddr::V6(http_address); - // TODO: Change for the actual clickhouse address - // let dummy_address = - // SocketAddrV6::new(Ipv6Addr::LOCALHOST, 8080, 0, 0); let clickward = Clickward::new(clickhouse_address); let server = diff --git a/clickhouse-admin/src/clickward.rs b/clickhouse-admin/src/clickward.rs index fe87adc523..114201e44b 100644 --- a/clickhouse-admin/src/clickward.rs +++ b/clickhouse-admin/src/clickward.rs @@ -43,7 +43,9 @@ impl Clickward { Self { clickhouse_address } } - pub fn clickhouse_address(&self) -> Result { + pub fn clickhouse_address( + &self, + ) -> Result { Ok(ClickhouseAddress { clickhouse_address: self.clickhouse_address }) } } diff --git a/clickhouse-admin/types/Cargo.toml b/clickhouse-admin/types/Cargo.toml deleted file mode 100644 index ce99e9ed76..0000000000 --- a/clickhouse-admin/types/Cargo.toml +++ /dev/null @@ -1,18 +0,0 @@ -[package] -name = "clickhouse-admin-types" -version = "0.1.0" -edition = "2021" -license = "MPL-2.0" - -[lints] -workspace = true - -[dependencies] -omicron-common.workspace = true -omicron-workspace-hack.workspace = true -schemars.workspace = true -serde.workspace = true - -[dev-dependencies] -proptest.workspace = true -test-strategy.workspace = true diff --git a/clickhouse-admin/types/src/lib.rs b/clickhouse-admin/types/src/lib.rs deleted file mode 100644 index 8b13789179..0000000000 --- a/clickhouse-admin/types/src/lib.rs +++ /dev/null @@ -1 +0,0 @@ - diff --git a/clients/clickhouse-admin-client/Cargo.toml b/clients/clickhouse-admin-client/Cargo.toml deleted file mode 100644 index 1491cd0134..0000000000 --- a/clients/clickhouse-admin-client/Cargo.toml +++ /dev/null @@ -1,18 +0,0 @@ -[package] -name = "clickhouse-admin-client" -version = "0.1.0" -edition = "2021" -license = "MPL-2.0" - -[lints] -workspace = true - -[dependencies] -chrono.workspace = true -omicron-uuid-kinds.workspace = true -progenitor.workspace = true -reqwest = { workspace = true, features = [ "json", "rustls-tls", "stream" ] } -schemars.workspace = true -serde.workspace = true -slog.workspace = true -omicron-workspace-hack.workspace = true diff --git a/clients/clickhouse-admin-client/src/lib.rs b/clients/clickhouse-admin-client/src/lib.rs deleted file mode 100644 index 4f5aa9d2ce..0000000000 --- a/clients/clickhouse-admin-client/src/lib.rs +++ /dev/null @@ -1,25 +0,0 @@ -// 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/. - -//! Interface for making API requests to an Omicron ClickHouse admin server - -// TODO: Is this necessary yet? -// progenitor::generate_api!( -// spec = "../../openapi/clickhouse-admin.json", -// inner_type = slog::Logger, -// pre_hook = (|log: &slog::Logger, request: &reqwest::Request| { -// slog::debug!(log, "client request"; -// "method" => %request.method(), -// "uri" => %request.url(), -// "body" => ?&request.body(), -// ); -// }), -// post_hook = (|log: &slog::Logger, result: &Result<_, _>| { -// slog::debug!(log, "client response"; "result" => ?result); -// }), -// derives = [schemars::JsonSchema], -// replace = { -// TypedUuidForOmicronZoneKind = omicron_uuid_kinds::OmicronZoneUuid, -// } -// ); diff --git a/sled-agent/src/services.rs b/sled-agent/src/services.rs index d579f39d72..94205871f6 100644 --- a/sled-agent/src/services.rs +++ b/sled-agent/src/services.rs @@ -1573,17 +1573,15 @@ impl ServiceManager { .add_property_group(config), ); - let ch_address = SocketAddr::new( - IpAddr::V6(listen_addr), - CLICKHOUSE_PORT, - ) - .to_string(); + let ch_address = + SocketAddr::new(IpAddr::V6(listen_addr), CLICKHOUSE_PORT) + .to_string(); - let admin_address = SocketAddr::new( - IpAddr::V6(listen_addr), - CLICKHOUSE_ADMIN_PORT, - ) - .to_string(); + let admin_address = SocketAddr::new( + IpAddr::V6(listen_addr), + CLICKHOUSE_ADMIN_PORT, + ) + .to_string(); let clickhouse_admin_config = PropertyGroupBuilder::new("config") @@ -1654,18 +1652,16 @@ impl ServiceManager { .add_property_group(config), ); - let ch_address = SocketAddr::new( - IpAddr::V6(listen_addr), - CLICKHOUSE_PORT, - ) - .to_string(); - - let admin_address = SocketAddr::new( - IpAddr::V6(listen_addr), - CLICKHOUSE_ADMIN_PORT, - ) + let ch_address = + SocketAddr::new(IpAddr::V6(listen_addr), CLICKHOUSE_PORT) .to_string(); + let admin_address = SocketAddr::new( + IpAddr::V6(listen_addr), + CLICKHOUSE_ADMIN_PORT, + ) + .to_string(); + let clickhouse_admin_config = PropertyGroupBuilder::new("config") .add_property( From 5097bfb758f47ef7567799b01ad1762f0b600047 Mon Sep 17 00:00:00 2001 From: karencfv Date: Wed, 14 Aug 2024 19:01:27 +1200 Subject: [PATCH 09/10] typo --- clickhouse-admin/src/bin/clickhouse-admin.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clickhouse-admin/src/bin/clickhouse-admin.rs b/clickhouse-admin/src/bin/clickhouse-admin.rs index 26c37086cc..6b21d2f622 100644 --- a/clickhouse-admin/src/bin/clickhouse-admin.rs +++ b/clickhouse-admin/src/bin/clickhouse-admin.rs @@ -20,7 +20,7 @@ use std::net::{SocketAddr, SocketAddrV6}; enum Args { /// Start the ClickHouse admin server Run { - /// Socket address for a running clickhouse server orr keeper instance + /// Socket address for a running clickhouse server or keeper instance #[clap(long, short = 'a', action)] clickhouse_address: SocketAddrV6, From eeab72cf9d7a8201ca2bf3a9df690e2579146c3f Mon Sep 17 00:00:00 2001 From: karencfv Date: Thu, 15 Aug 2024 09:51:21 +1200 Subject: [PATCH 10/10] Address comments --- Cargo.lock | 1 - clickhouse-admin/Cargo.toml | 1 - clickhouse-admin/src/bin/clickhouse-admin.rs | 2 ++ package-manifest.toml | 2 ++ 4 files changed, 4 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index cf1339d7c9..078fc88f61 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5567,7 +5567,6 @@ dependencies = [ "omicron-test-utils", "omicron-uuid-kinds", "omicron-workspace-hack", - "once_cell", "openapi-lint", "openapiv3", "schemars", diff --git a/clickhouse-admin/Cargo.toml b/clickhouse-admin/Cargo.toml index 8517eb44af..033836dfe0 100644 --- a/clickhouse-admin/Cargo.toml +++ b/clickhouse-admin/Cargo.toml @@ -15,7 +15,6 @@ http.workspace = true illumos-utils.workspace = true omicron-common.workspace = true omicron-uuid-kinds.workspace = true -once_cell.workspace = true schemars.workspace = true slog.workspace = true slog-async.workspace = true diff --git a/clickhouse-admin/src/bin/clickhouse-admin.rs b/clickhouse-admin/src/bin/clickhouse-admin.rs index 6b21d2f622..6f28a82804 100644 --- a/clickhouse-admin/src/bin/clickhouse-admin.rs +++ b/clickhouse-admin/src/bin/clickhouse-admin.rs @@ -20,6 +20,8 @@ use std::net::{SocketAddr, SocketAddrV6}; 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, diff --git a/package-manifest.toml b/package-manifest.toml index 3229105815..d43a53bced 100644 --- a/package-manifest.toml +++ b/package-manifest.toml @@ -153,6 +153,8 @@ source.type = "composite" source.packages = [ "clickhouse_svc.tar.gz", "internal-dns-cli.tar.gz", + # TODO: This package is for solely for testing purposes. + # Remove once replicated clickhouse is up and running. "omicron-clickhouse-admin.tar.gz", "zone-setup.tar.gz", "zone-network-install.tar.gz"