-
Notifications
You must be signed in to change notification settings - Fork 41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use one Oximeter client per admin server #7171
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,10 +15,8 @@ use dropshot::{ | |
HttpResponseUpdatedNoContent, Path, Query, RequestContext, TypedBody, | ||
}; | ||
use illumos_utils::svcadm::Svcadm; | ||
use omicron_common::address::CLICKHOUSE_TCP_PORT; | ||
use oximeter_db::{Client as OximeterClient, OXIMETER_VERSION}; | ||
use slog::debug; | ||
use std::net::SocketAddrV6; | ||
use oximeter_db::OXIMETER_VERSION; | ||
use slog::info; | ||
use std::sync::Arc; | ||
|
||
pub fn clickhouse_admin_server_api() -> ApiDescription<Arc<ServerContext>> { | ||
|
@@ -146,28 +144,40 @@ impl ClickhouseAdminSingleApi for ClickhouseAdminSingleImpl { | |
) -> Result<HttpResponseUpdatedNoContent, HttpError> { | ||
let log = &rqctx.log; | ||
let ctx = rqctx.context(); | ||
let ip = ctx.clickhouse_cli().listen_address.ip(); | ||
let address = SocketAddrV6::new(*ip, CLICKHOUSE_TCP_PORT, 0, 0); | ||
let client = OximeterClient::new(address.into(), log); | ||
debug!( | ||
log, | ||
"initializing single-node ClickHouse \ | ||
at {address} to version {OXIMETER_VERSION}" | ||
); | ||
|
||
// Database initialization is idempotent, but not concurrency-safe. | ||
// Use a mutex to serialize requests. | ||
let lock = ctx.initialization_lock(); | ||
let _guard = lock.lock().await; | ||
client | ||
.initialize_db_with_version(false, OXIMETER_VERSION) | ||
.await | ||
.map_err(|e| { | ||
HttpError::for_internal_error(format!( | ||
"can't initialize single-node ClickHouse \ | ||
at {address} to version {OXIMETER_VERSION}: {e}", | ||
)) | ||
})?; | ||
|
||
// Initialize the database only if it was not previously initialized. | ||
// TODO: Migrate schema to newer version without wiping data. | ||
let client = ctx.oximeter_client(); | ||
let version = client.read_latest_version().await.map_err(|e| { | ||
HttpError::for_internal_error(format!( | ||
"can't read ClickHouse version: {e}", | ||
)) | ||
})?; | ||
if version == 0 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. With apologies for this question possibly being more relevant to #6903 - how does this interact with Oximeter doing almost exactly (or maybe exactly exactly) this same check-if-0-and-initialize on startup, given the notes about initialization not being concurrency-safe? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We'll take this as a follow-up: #7173. |
||
info!( | ||
log, | ||
"initializing single-node ClickHouse to version {OXIMETER_VERSION}" | ||
); | ||
ctx.oximeter_client() | ||
.initialize_db_with_version(false, OXIMETER_VERSION) | ||
.await | ||
.map_err(|e| { | ||
HttpError::for_internal_error(format!( | ||
"can't initialize single-node ClickHouse \ | ||
to version {OXIMETER_VERSION}: {e}", | ||
)) | ||
})?; | ||
} else { | ||
info!( | ||
log, | ||
"skipping initialization of single-node ClickHouse at version {version}" | ||
); | ||
} | ||
|
||
Ok(HttpResponseUpdatedNoContent()) | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems fishy to me; can we make
clickhouse_cli.log
not optional so we don't need this unwrap? Or alternatively, could we accept aLogger
that we pass through to the client instead of relying on getting it fromclickhouse_cli
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seemed fishy because it was; thanks. 922157b makes
ClickhouseCli.log
non-optional.