Merge pull request #4304 from influxdata/crepererum/ng_end2end_tests_schema_names

test: use random catalog schema name for NG end2end tests
pull/24376/head
kodiakhq[bot] 2022-04-13 16:05:05 +00:00 committed by GitHub
commit 06118b50be
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 64 additions and 20 deletions

View File

@ -38,6 +38,14 @@ pub struct CatalogDsnConfig {
default_value = "10" default_value = "10"
)] )]
pub max_catalog_connections: u32, pub max_catalog_connections: u32,
/// Schema name for PostgreSQL-based catalogs.
#[clap(
long = "--catalog-postgres-schema-name",
env = "INFLUXDB_IOX_CATALOG_POSTGRES_SCHEMA_NAME",
default_value = iox_catalog::postgres::SCHEMA_NAME,
)]
pub postgres_schema_name: String,
} }
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, clap::ArgEnum)] #[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, clap::ArgEnum)]
@ -56,7 +64,7 @@ impl CatalogDsnConfig {
CatalogType::Postgres => Arc::new( CatalogType::Postgres => Arc::new(
PostgresCatalog::connect( PostgresCatalog::connect(
app_name, app_name,
iox_catalog::postgres::SCHEMA_NAME, &self.postgres_schema_name,
self.dsn.as_ref().context(ConnectionStringRequiredSnafu)?, self.dsn.as_ref().context(ConnectionStringRequiredSnafu)?,
self.max_catalog_connections, self.max_catalog_connections,
metrics, metrics,

View File

@ -1,6 +1,7 @@
use std::{collections::HashMap, sync::Arc}; use std::{collections::HashMap, sync::Arc};
use http::{header::HeaderName, HeaderValue}; use http::{header::HeaderName, HeaderValue};
use rand::Rng;
use tempfile::TempDir; use tempfile::TempDir;
use crate::addrs::BindAddresses; use crate::addrs::BindAddresses;
@ -22,6 +23,9 @@ pub struct TestConfig {
/// Catalog DSN value /// Catalog DSN value
dsn: String, dsn: String,
/// Catalog schema name
catalog_schema_name: String,
/// Write buffer directory, if needed /// Write buffer directory, if needed
write_buffer_dir: Option<Arc<TempDir>>, write_buffer_dir: Option<Arc<TempDir>>,
@ -35,12 +39,17 @@ pub struct TestConfig {
impl TestConfig { impl TestConfig {
/// Create a new TestConfig (tests should use one of the specific /// Create a new TestConfig (tests should use one of the specific
/// configuration setup below, such as [new_router2] /// configuration setup below, such as [new_router2]
fn new(server_type: ServerType, dsn: impl Into<String>) -> Self { fn new(
server_type: ServerType,
dsn: impl Into<String>,
catalog_schema_name: impl Into<String>,
) -> Self {
Self { Self {
env: HashMap::new(), env: HashMap::new(),
client_headers: vec![], client_headers: vec![],
server_type, server_type,
dsn: dsn.into(), dsn: dsn.into(),
catalog_schema_name: catalog_schema_name.into(),
write_buffer_dir: None, write_buffer_dir: None,
object_store_dir: None, object_store_dir: None,
addrs: Arc::new(BindAddresses::default()), addrs: Arc::new(BindAddresses::default()),
@ -49,7 +58,7 @@ impl TestConfig {
/// Create a minimal router2 configuration /// Create a minimal router2 configuration
pub fn new_router2(dsn: impl Into<String>) -> Self { pub fn new_router2(dsn: impl Into<String>) -> Self {
Self::new(ServerType::Router2, dsn) Self::new(ServerType::Router2, dsn, random_catalog_schema_name())
.with_new_write_buffer() .with_new_write_buffer()
.with_new_object_store() .with_new_object_store()
} }
@ -57,10 +66,14 @@ impl TestConfig {
/// Create a minimal ingester configuration, using the dsn and /// Create a minimal ingester configuration, using the dsn and
/// write buffer configuration from other /// write buffer configuration from other
pub fn new_ingester(other: &TestConfig) -> Self { pub fn new_ingester(other: &TestConfig) -> Self {
Self::new(ServerType::Ingester, other.dsn()) Self::new(
.with_existing_write_buffer(other) ServerType::Ingester,
.with_existing_object_store(other) other.dsn(),
.with_default_ingester_options() other.catalog_schema_name(),
)
.with_existing_write_buffer(other)
.with_existing_object_store(other)
.with_default_ingester_options()
} }
/// Create a minimal querier configuration from the specified /// Create a minimal querier configuration from the specified
@ -80,13 +93,17 @@ impl TestConfig {
/// Create a minimal querier configuration from the specified /// Create a minimal querier configuration from the specified
/// ingester configuration, using the same dsn and object store /// ingester configuration, using the same dsn and object store
pub fn new_querier_without_ingester(ingester_config: &TestConfig) -> Self { pub fn new_querier_without_ingester(ingester_config: &TestConfig) -> Self {
Self::new(ServerType::Querier, ingester_config.dsn()) Self::new(
.with_existing_object_store(ingester_config) ServerType::Querier,
ingester_config.dsn(),
ingester_config.catalog_schema_name(),
)
.with_existing_object_store(ingester_config)
} }
/// Create a minimal all in one configuration /// Create a minimal all in one configuration
pub fn new_all_in_one(dsn: impl Into<String>) -> Self { pub fn new_all_in_one(dsn: impl Into<String>) -> Self {
Self::new(ServerType::AllInOne, dsn) Self::new(ServerType::AllInOne, dsn, random_catalog_schema_name())
.with_new_write_buffer() .with_new_write_buffer()
.with_new_object_store() .with_new_object_store()
.with_default_ingester_options() .with_default_ingester_options()
@ -104,6 +121,11 @@ impl TestConfig {
&self.dsn &self.dsn
} }
// Get the catalog postgres schema name
pub fn catalog_schema_name(&self) -> &str {
&self.catalog_schema_name
}
/// Adds default ingester options /// Adds default ingester options
fn with_default_ingester_options(self) -> Self { fn with_default_ingester_options(self) -> Self {
self.with_env("INFLUXDB_IOX_PAUSE_INGEST_SIZE_BYTES", "20") self.with_env("INFLUXDB_IOX_PAUSE_INGEST_SIZE_BYTES", "20")
@ -220,3 +242,14 @@ impl TestConfig {
&self.addrs &self.addrs
} }
} }
fn random_catalog_schema_name() -> String {
let mut rng = rand::thread_rng();
(&mut rng)
.sample_iter(rand::distributions::Alphanumeric)
.filter(|c| c.is_ascii_alphabetic())
.take(20)
.map(char::from)
.collect::<String>()
}

View File

@ -3,19 +3,18 @@
use assert_cmd::Command; use assert_cmd::Command;
use once_cell::sync::Lazy; use once_cell::sync::Lazy;
use sqlx::{migrate::MigrateDatabase, Postgres}; use sqlx::{migrate::MigrateDatabase, Postgres};
use std::sync::Mutex; use std::{collections::BTreeSet, sync::Mutex};
// I really do want to block everything until the database is initialized... // I really do want to block everything until the database is initialized...
#[allow(clippy::await_holding_lock)] #[allow(clippy::await_holding_lock)]
#[allow(clippy::mutex_atomic)] static DB_INITIALIZED: Lazy<Mutex<BTreeSet<String>>> = Lazy::new(|| Mutex::new(BTreeSet::new()));
static DB_INITIALIZED: Lazy<Mutex<bool>> = Lazy::new(|| Mutex::new(false));
/// Performs once-per-process database initialization, if necessary /// Performs once-per-process database initialization, if necessary
pub async fn initialize_db(dsn: &str) { pub async fn initialize_db(dsn: &str, schema_name: &str) {
let mut init = DB_INITIALIZED.lock().expect("Mutex poisoned"); let mut init = DB_INITIALIZED.lock().expect("Mutex poisoned");
// already done // already done
if *init { if init.contains(schema_name) {
return; return;
} }
@ -32,7 +31,8 @@ pub async fn initialize_db(dsn: &str) {
.unwrap() .unwrap()
.arg("catalog") .arg("catalog")
.arg("setup") .arg("setup")
.env("INFLUXDB_IOX_CATALOG_DSN", &dsn) .env("INFLUXDB_IOX_CATALOG_DSN", dsn)
.env("INFLUXDB_IOX_CATALOG_POSTGRES_SCHEMA_NAME", schema_name)
.ok() .ok()
.unwrap(); .unwrap();
@ -43,9 +43,10 @@ pub async fn initialize_db(dsn: &str) {
.arg("topic") .arg("topic")
.arg("update") .arg("update")
.arg("iox-shared") .arg("iox-shared")
.env("INFLUXDB_IOX_CATALOG_DSN", &dsn) .env("INFLUXDB_IOX_CATALOG_DSN", dsn)
.env("INFLUXDB_IOX_CATALOG_POSTGRES_SCHEMA_NAME", schema_name)
.ok() .ok()
.unwrap(); .unwrap();
*init = true; init.insert(schema_name.into());
} }

View File

@ -268,7 +268,8 @@ impl TestServer {
let run_command = server_type.run_command(); let run_command = server_type.run_command();
let dsn = test_config.dsn(); let dsn = test_config.dsn();
initialize_db(dsn).await; let schema_name = test_config.catalog_schema_name();
initialize_db(dsn, schema_name).await;
// This will inherit environment from the test runner // This will inherit environment from the test runner
// in particular `LOG_FILTER` // in particular `LOG_FILTER`
@ -277,7 +278,8 @@ impl TestServer {
.arg("run") .arg("run")
.arg(run_command) .arg(run_command)
.env("LOG_FILTER", log_filter) .env("LOG_FILTER", log_filter)
.env("INFLUXDB_IOX_CATALOG_DSN", &dsn) .env("INFLUXDB_IOX_CATALOG_DSN", dsn)
.env("INFLUXDB_IOX_CATALOG_POSTGRES_SCHEMA_NAME", schema_name)
// add http/grpc address information // add http/grpc address information
.add_addr_env(server_type, test_config.addrs()) .add_addr_env(server_type, test_config.addrs())
.envs(test_config.env()) .envs(test_config.env())