Skip to content

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

better development against audit db (#80349)

dpsutton4917982a2d4b
diff --git a/.clj-kondo/config/modules/config.edn b/.clj-kondo/config/modules/config.edn
index 23c497dfc87..a6c59259871 100644
--- a/.clj-kondo/config/modules/config.edn
+++ b/.clj-kondo/config/modules/config.edn
@@ -878,6 +878,7 @@
:uses #{analytics-interface
app-db
appearance
+ audit-app
auth-provider
classloader
config
diff --git a/.clj-kondo/ratchets.edn b/.clj-kondo/ratchets.edn
index 6553def3ac3..f6f4da08394 100644
--- a/.clj-kondo/ratchets.edn
+++ b/.clj-kondo/ratchets.edn
@@ -12,7 +12,7 @@
:deprecated-namespace 95
:deprecated-var 84
:discouraged-java-method 3
- :discouraged-namespace 80
+ :discouraged-namespace 81
:discouraged-var 111
:equals-true 1
:main-without-gen-class 1
diff --git a/src/metabase/driver/sql_jdbc/connection.clj b/src/metabase/driver/sql_jdbc/connection.clj
index a49b6d3abbd..5c6922706a5 100644
--- a/src/metabase/driver/sql_jdbc/connection.clj
+++ b/src/metabase/driver/sql_jdbc/connection.clj
@@ -4,6 +4,8 @@
(:refer-clojure :exclude [get-in mapv select-keys])
(:require
[clojure.java.jdbc :as jdbc]
+ ^{:clj-kondo/ignore [:discouraged-namespace]}
+ [metabase.audit-app.core :as audit-app]
[metabase.driver :as driver]
[metabase.driver-api.core :as driver-api]
[metabase.driver.connection :as driver.conn]
@@ -452,7 +454,9 @@
;; for the audit db, we pass the datasource for the app-db. This lets us use fewer db
;; connections with *application-db* and 1 less connection pool. Note: This data-source is
;; not in [[pool-cache-key->connection-pool]].
- (or (:is-audit db) (get-in db [:details :is-audit-dev]))
+ (or (:is-audit db)
+ (and (audit-app/analytics-dev-mode)
+ (get-in db [:details :is-audit-dev])))
{:datasource (driver-api/data-source)}
:else
diff --git a/test/metabase/driver/sql_jdbc/connection_test.clj b/test/metabase/driver/sql_jdbc/connection_test.clj
index 602fdf936bb..aa1f29e427a 100644
--- a/test/metabase/driver/sql_jdbc/connection_test.clj
+++ b/test/metabase/driver/sql_jdbc/connection_test.clj
@@ -377,6 +377,20 @@
(is (= ::audit-db-not-in-cache!
(get @#'sql-jdbc.conn/pool-cache-key->connection-pool audit-db-id ::audit-db-not-in-cache!)))))))
+(deftest is-audit-dev-routing-requires-dev-mode-test
+ (testing "a user-supplied :is-audit-dev detail only routes to the app DB under analytics-dev-mode"
+ (mt/with-temp [:model/Database db {:engine :h2 :details {:is-audit-dev true}
+ :is_audit false}]
+ (let [routes-to-app-db? (fn []
+ (= {:datasource (mdb/data-source)}
+ (sql-jdbc.conn/db->pooled-connection-spec (:id db))))]
+ (testing "dev mode off: the flag is ignored, so it does NOT route to the app DB"
+ (mt/with-temporary-setting-values [analytics-dev-mode false]
+ (is (not (routes-to-app-db?)))))
+ (testing "dev mode on: the flag is honored (the legitimate local-dev path still works)"
+ (mt/with-temporary-setting-values [analytics-dev-mode true]
+ (is (routes-to-app-db?))))))))
+
(deftest ^:parallel include-unreturned-connection-timeout-test
(testing "We should be setting unreturnedConnectionTimeout; it should be the same as the query timeout (#33646)"
(is (=? {"unreturnedConnectionTimeout" integer?}