-
- Downloads
Fixes #8396 "Postgres sync not respecting SSH tunneling" (#13391)
* Use db pool connection rather than raw details connection pool is correctly setup with ssh tunneling information (if any) * Don't error when getting postgres enum types this was throwing errors when we allowed our pooled connections to close underneath us. But this particular step just isn't important enough for that. If we don't have a connection available to us, let the more robust query stuff fail it rather than this one off * Set idleConnectionTestPeriod to 120 when ssh tunneling The ssh tunnelling apparatus needs some work. The tunnels are created and put in the spec details map but then this is tossed away when we create the pool. ```clojure (defn- create-pool! "Create a new C3P0 `ComboPooledDataSource` for connecting to the given `database`." [{:keys [id details], driver :engine, :as database}] {:pre [(map? database)]} (log/debug (u/format-color 'cyan (trs "Creating new connection pool for {0} database {1} ..." driver id))) (let [details-with-tunnel (ssh/include-ssh-tunnel details) ;; If the tunnel is disabled this returned unchanged spec (connection-details->spec driver details-with-tunnel) properties (data-warehouse-connection-pool-properties driver)] (connection-pool/connection-pool-spec spec (merge properties (when (ssh/use-ssh-tunnel? details) {"idleConnectionTestPeriod" 120}))))) ``` this is swapped into an atom of {db_id -> pooleddatasource} but this means we don't have the :tunnel-session and :tunnel-tracker info from `start-ssh-tunnel`. * Remove connection pool keys when set to nil our connection pool would end up with {db_id nil ...} for no reason. Add tests to ensure. This change is largely driven by the codox testing requirement. There's no good way to test that the ssh tunneling options includes (when (ssh/use-ssh-tunnel? details) {"idleConnectionTestPeriod" 120}) and the test coverage checker was unhappy * Correct ns form in test file * Remove try/catch around enum types there's already error handling around this sync step so let it happen. The issue was that this check didn't use the correct connection to respect tunnelling and therefore would throw an error in getting enum types and fail the database sync step. That is now done correctly so if this step fails the other steps would as well and we no longer need to handle an error here specifically * Move ssh heartbeat into ssh.clj and not use jdbc jdbc had a way to test idle connections but other non-jdbc datasources obviously wouldn't benefit. Luckily our ssh connection can handle this on its own
Showing
- src/metabase/driver/postgres.clj 7 additions, 7 deletionssrc/metabase/driver/postgres.clj
- src/metabase/driver/sql_jdbc/connection.clj 3 additions, 1 deletionsrc/metabase/driver/sql_jdbc/connection.clj
- src/metabase/util/ssh.clj 8 additions, 1 deletionsrc/metabase/util/ssh.clj
- test/metabase/driver/postgres_test.clj 2 additions, 1 deletiontest/metabase/driver/postgres_test.clj
- test/metabase/driver/sql_jdbc/connection_test.clj 43 additions, 1 deletiontest/metabase/driver/sql_jdbc/connection_test.clj
Please register or sign in to comment