Code related to capturing diagnostic information for JDBC connection pools at execution time. | (ns metabase.driver.sql-jdbc.execute.diagnostic (:import (com.mchange.v2.c3p0 PoolBackedDataSource))) |
(set! *warn-on-reflection* true) | |
Atom used to hold diagnostic info for the current query execution, to be made available via a helper macro/fn below. | (def ^:private ^:dynamic *diagnostic-info* nil) |
Execute | (defn do-with-diagnostic-info [f] (binding [*diagnostic-info* (atom {})] (f (partial deref *diagnostic-info*)))) |
Execute ```
(sql-jdbc.execute.diagnostic/capturing-diagnostic-info [diag-info-fn]
;; various body forms
;; fetch the diagnostic info, which should be available if execute code called | (defmacro capturing-diagnostic-info {:style/indent 1} [[diagnostic-info-fn-binding] & body] `(do-with-diagnostic-info (fn [~diagnostic-info-fn-binding] ~@body))) |
Captures diagnostic info related to the given
| (defn record-diagnostic-info-for-pool! [driver database-id ^PoolBackedDataSource datasource] (when *diagnostic-info* (swap! *diagnostic-info* #(assoc % ::database-id database-id ::driver driver ::active-connections (.getNumBusyConnectionsAllUsers datasource) ::total-connections (.getNumConnectionsAllUsers datasource) ::threads-waiting (.getNumThreadsAwaitingCheckoutDefaultUser datasource))))) |