Skip to content

The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:

Pick random host when testing Redshift from `MB_REDSHIFT_TEST_HOSTS` (#72498)

Cam Saul1af01d8489f2
diff --git a/.github/workflows/drivers.yml b/.github/workflows/drivers.yml
index 5313a2704db..e34c9a3b8eb 100644
--- a/.github/workflows/drivers.yml
+++ b/.github/workflows/drivers.yml
@@ -1205,7 +1205,7 @@ jobs:
MB_REDSHIFT_TEST_USER: metabase_ci
MB_REDSHIFT_TEST_DB: testdb
MB_REDSHIFT_TEST_DB_ROUTING: dev
- MB_REDSHIFT_TEST_HOST: ${{ secrets.MB_REDSHIFT_TEST_HOST }}
+ MB_REDSHIFT_TEST_HOSTS: ${{ secrets.MB_REDSHIFT_TEST_HOSTS }}
MB_REDSHIFT_TEST_PASSWORD: ${{ secrets.MB_REDSHIFT_TEST_PASSWORD }}
name: ${{ matrix.job.name }}
steps:
diff --git a/modules/drivers/redshift/test/metabase/test/data/redshift.clj b/modules/drivers/redshift/test/metabase/test/data/redshift.clj
index 3534a0d2486..37f63a7b0a4 100644
--- a/modules/drivers/redshift/test/metabase/test/data/redshift.clj
+++ b/modules/drivers/redshift/test/metabase/test/data/redshift.clj
@@ -66,23 +66,45 @@
(defn unique-session-schema []
(str (sql.tu.unique-prefix/unique-prefix) "schema"))
+;;; `MB_REDSHIFT_TEST_HOSTS`
+;;;
+;;; We've had lots of problems with Redshift timing out because of too much CPU load on our single cluster in the past;
+;;; instead of continuing to increase the size of the cluster (which doesn't seem to help much) we're switching to a
+;;; handful of smaller clusters, and picking one randomly; there is nothing shared between test runs and no reason they
+;;; all need to be done on a single cluster anyway. Other than the `:host` these are all configured identically with the
+;;; same user, password, and database name.
+
+(defonce ^:private hosts
+ (delay
+ (when-let [hosts (not-empty (tx/db-test-env-var :redshift :hosts))]
+ (str/split hosts #","))))
+
+(defn- random-host
+ "Pick a random host to test against from `MB_REDSHIFT_TEST_HOSTS` if it's set; otherwise fall back to the host in
+ `MB_REDSHIFT_TEST_HOST`."
+ []
+ (u/prog1 (if (seq @hosts)
+ (rand-nth @hosts)
+ (tx/db-test-env-var-or-throw :redshift :host))
+ ;; using println on purpose here for purposes of debugging CI, we can remove in the future when we're happy that
+ ;; multiple hosts works as expected
+ #_{:clj-kondo/ignore [:discouraged-var]}
+ (println "Using Redshift host" (pr-str (first (str/split <> #"\."))))))
+
+(defonce ^:private host (delay (random-host)))
+
(def db-connection-details
- (delay {:host (tx/db-test-env-var-or-throw :redshift :host)
+ (delay {:host @host
:port (parse-long (tx/db-test-env-var :redshift :port "5439"))
- :db (tx/db-test-env-var-or-throw :redshift :db)
- :user (tx/db-test-env-var-or-throw :redshift :user)
+ :db (tx/db-test-env-var :redshift :db "testdb")
+ :user (tx/db-test-env-var :redshift :user "metabase_ci")
:password (tx/db-test-env-var-or-throw :redshift :password)
:schema-filters-type "inclusion"
:schema-filters-patterns (str "spectrum," (unique-session-schema))}))
(def db-routing-connection-details
- (delay {:host (tx/db-test-env-var-or-throw :redshift :host)
- :port (parse-long (tx/db-test-env-var :redshift :port "5439"))
- :db (tx/db-test-env-var :redshift :db-routing "dev")
- :user (tx/db-test-env-var-or-throw :redshift :user)
- :password (tx/db-test-env-var-or-throw :redshift :password)
- :schema-filters-type "inclusion"
- :schema-filters-patterns (str "spectrum," (unique-session-schema))}))
+ (delay
+ (assoc @db-connection-details :db (tx/db-test-env-var :redshift :db-routing "dev"))))
(defmethod tx/dbdef->connection-details :redshift
[& _]