Skip to content

Commit

Permalink
separate test db init from normal init in DbWrite
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewjstone committed Jul 22, 2024
1 parent 9013532 commit dbf9484
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 4 deletions.
23 changes: 22 additions & 1 deletion oximeter/db/src/client/dbwrite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ impl DbWrite for Client {
debug!(self.log, "initializing ClickHouse database");
self.run_many_sql_statements(include_str!(concat!(
env!("CARGO_MANIFEST_DIR"),
"/schema/replicated/db-init-test.sql"
"/schema/replicated/db-init.sql"
)))
.await
}
Expand Down Expand Up @@ -99,6 +99,27 @@ impl DbWrite for Client {
}
}

/// Allow initializing a minimal subset of db tables for replicated cluster
/// testing
#[async_trait::async_trait]
pub trait TestDbWrite {
/// Initialize the replicated telemetry database, creating a subset of tables.
async fn init_test_minimal_replicated_db(&self) -> Result<(), Error>;
}

#[async_trait::async_trait]
impl TestDbWrite for Client {
/// Initialize the replicated telemetry database, creating tables as needed.
async fn init_test_minimal_replicated_db(&self) -> Result<(), Error> {
debug!(self.log, "initializing ClickHouse database");
self.run_many_sql_statements(include_str!(concat!(
env!("CARGO_MANIFEST_DIR"),
"/schema/replicated/db-init-test.sql"
)))
.await
}
}

impl Client {
// Unroll each sample into its consituent rows, after verifying the schema.
//
Expand Down
1 change: 1 addition & 0 deletions oximeter/db/src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ pub(crate) mod query_summary;
mod sql;

pub use self::dbwrite::DbWrite;
pub use self::dbwrite::TestDbWrite;
use crate::client::query_summary::QuerySummary;
use crate::model;
use crate::query;
Expand Down
1 change: 1 addition & 0 deletions oximeter/db/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ pub use client::query_summary::QuerySummary;
pub use client::Client;
pub use client::DbWrite;
pub use client::RawSql;
pub use client::TestDbWrite;
pub use model::OXIMETER_VERSION;

#[derive(Debug, Error)]
Expand Down
12 changes: 9 additions & 3 deletions oximeter/db/tests/integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use dropshot::test_util::log_prefix_for_test;
use omicron_test_utils::dev::poll;
use omicron_test_utils::dev::test_setup_log;
use oximeter::test_util;
use oximeter_db::{Client, DbWrite, OxqlResult, Sample};
use oximeter_db::{Client, DbWrite, OxqlResult, Sample, TestDbWrite};
use std::default::Default;
use std::time::Duration;

Expand Down Expand Up @@ -67,7 +67,10 @@ async fn test_cluster() -> anyhow::Result<()> {
println!("deploy setup time = {:?}", end - start);

let start = tokio::time::Instant::now();
client1.init_replicated_db().await.context("failed to initialize db")?;
client1
.init_test_minimal_replicated_db()
.await
.context("failed to initialize db")?;
let end = tokio::time::Instant::now();
println!("init replicated db time = {:?}", end - start);

Expand Down Expand Up @@ -124,7 +127,10 @@ async fn test_cluster() -> anyhow::Result<()> {

// We need to initiate copying from existing replicated tables by creating
// the DB and those tables on the new node.
client3.init_replicated_db().await.expect("failed to initialized db");
client3
.init_test_minimal_replicated_db()
.await
.expect("failed to initialized db");

// Wait for all the data to be copied to node 3
let start = tokio::time::Instant::now();
Expand Down

0 comments on commit dbf9484

Please sign in to comment.