Skip to content
Snippets Groups Projects
Unverified Commit 021c6708 authored by Mark Bastian's avatar Mark Bastian Committed by GitHub
Browse files

Ban println/printf via clj-kondo config (#27997)

Added bans for print and friends. Fixed issues in kondo config where a macroexpansion put in a print by replacing with (constantly nil) as a no-op.
parent 10a56f06
No related branches found
No related tags found
No related merge requests found
Showing
with 118 additions and 96 deletions
...@@ -24,22 +24,22 @@ ...@@ -24,22 +24,22 @@
(taoensso.nippy/extend-freeze) (taoensso.nippy/extend-freeze)
(taoensso.nippy/extend-thaw)]} (taoensso.nippy/extend-thaw)]}
:refer-all {:level :warning :refer-all {:level :warning
:exclude [clojure.test]} :exclude [clojure.test]}
;; TODO (cam): I think we just need to tell it how to handle MBQL match and we can enable this? ;; TODO (cam): I think we just need to tell it how to handle MBQL match and we can enable this?
:unexpected-recur {:level :off} :unexpected-recur {:level :off}
;; TODO (cam): can we fix these? ;; TODO (cam): can we fix these?
:unused-referred-var {:exclude {compojure.core [GET DELETE POST PUT]}} :unused-referred-var {:exclude {compojure.core [GET DELETE POST PUT]}}
:missing-else-branch {:level :warning} :missing-else-branch {:level :warning}
:misplaced-docstring {:level :warning} :misplaced-docstring {:level :warning}
:non-arg-vec-return-type-hint {:level :warning} :non-arg-vec-return-type-hint {:level :warning}
:missing-body-in-when {:level :warning} :missing-body-in-when {:level :warning}
:missing-docstring {:level :warning} :missing-docstring {:level :warning}
;; TODO (braden): This is useful, but it doesn't grok eg. enterprise/backend/src ;; TODO (braden): This is useful, but it doesn't grok eg. enterprise/backend/src
:namespace-name-mismatch {:level :off} :namespace-name-mismatch {:level :off}
:use {:level :warning} :use {:level :warning}
:redundant-fn-wrapper {:level :warning} :redundant-fn-wrapper {:level :warning}
:invalid-arity {:skip-args [metabase.mbql.util.match/match]} :invalid-arity {:skip-args [metabase.mbql.util.match/match]}
;; TODO (cam): here are some more linters we should experiment with enabling -- some might be useful. ;; TODO (cam): here are some more linters we should experiment with enabling -- some might be useful.
;; :docstring-no-summary {:level :warning} ;; :docstring-no-summary {:level :warning}
;; :docstring-leading-trailing-whitespace {:level :warning} ;; :docstring-leading-trailing-whitespace {:level :warning}
...@@ -83,7 +83,12 @@ ...@@ -83,7 +83,12 @@
schema.core/either {:namespaces ["metabase.*"]}}} schema.core/either {:namespaces ["metabase.*"]}}}
:discouraged-var :discouraged-var
{clojure.string/lower-case {:message "Use metabase.util/lower-case-en instead of clojure.string/lower-case"} {clojure.core/print {:message "Use clojure.tools.logging instead of clojure.core/print"}
clojure.core/println {:message "Use clojure.tools.logging instead of clojure.core/println"}
clojure.core/printf {:message "Use clojure.tools.logging instead of clojure.core/printf"}
clojure.core/prn {:message "Use clojure.tools.logging instead of clojure.core/prn"}
clojure.core/pr {:message "Use clojure.tools.logging instead of clojure.core/pr"}
clojure.string/lower-case {:message "Use metabase.util/lower-case-en instead of clojure.string/lower-case"}
clojure.string/upper-case {:message "Use metabase.util/upper-case-en instead of clojure.string/upper-case"} clojure.string/upper-case {:message "Use metabase.util/upper-case-en instead of clojure.string/upper-case"}
honeysql.core/call {:message "Use hx/call instead because it is Honey SQL 2 friendly"} honeysql.core/call {:message "Use hx/call instead because it is Honey SQL 2 friendly"}
honeysql.core/raw {:message "Use hx/raw instead because it is Honey SQL 2 friendly"} honeysql.core/raw {:message "Use hx/raw instead because it is Honey SQL 2 friendly"}
...@@ -94,12 +99,13 @@ ...@@ -94,12 +99,13 @@
{:exclude {:exclude
[colorize.core]} [colorize.core]}
:unsorted-required-namespaces {:level :warning} :unsorted-required-namespaces {:level :warning}
:consistent-alias :consistent-alias
{:aliases {:aliases
{buddy.core.hash buddy-hash {buddy.core.hash buddy-hash
cheshire.generate json.generate cheshire.generate json.generate
clojure.tools.logging log
clj-http.client http clj-http.client http
clj-ldap.client ldap clj-ldap.client ldap
clj-time.coerce time.coerce clj-time.coerce time.coerce
...@@ -659,14 +665,19 @@ ...@@ -659,14 +665,19 @@
;; this list isn't exhaustive because it misses some stuff like the test runner and HTTP client but it's easier to go ;; this list isn't exhaustive because it misses some stuff like the test runner and HTTP client but it's easier to go
;; fix those namespaces than it is to make this regex super hairy. ;; fix those namespaces than it is to make this regex super hairy.
[{:pattern "(?:.*-test(?:\\..*)?$)|(?:.*test-util$)|(?:^metabase\\.test.*)" [{:pattern "(?:.*-test(?:\\..*)?$)|(?:.*test-util$)|(?:^metabase\\.test.*)"
:name test-namespaces}] :name test-namespaces}
{:pattern "metabase\\.cmd.*"
:name printable-namespaces}]
:config-in-ns :config-in-ns
{test-namespaces {test-namespaces
{:linters {:linters
{:inline-def {:level :off} {:inline-def {:level :off}
:missing-docstring {:level :off} :missing-docstring {:level :off}
:private-call {:level :off} :private-call {:level :off}
;; custom linters ;; custom linters
:hooks.metabase.test.data/mbql-query-first-arg {:level :error}}}}} :hooks.metabase.test.data/mbql-query-first-arg {:level :error}}}
printable-namespaces
{:linters
{:discouraged-var {:level :off}}}}}
...@@ -44,11 +44,12 @@ ...@@ -44,11 +44,12 @@
"This is the same idea as [[clojure.core/do]] but doesn't cause Kondo to complain about redundant dos." "This is the same idea as [[clojure.core/do]] but doesn't cause Kondo to complain about redundant dos."
;; This used to use `do` as the token-node, but as of version 2022.10.14 that resulted in warnings about ;; This used to use `do` as the token-node, but as of version 2022.10.14 that resulted in warnings about
;; unused variables since Kondo was smart enough to realize that we sometimes were calling pure functions early in ;; unused variables since Kondo was smart enough to realize that we sometimes were calling pure functions early in
;; the `do` and the value was getting thrown away. `print` tricks Kondo into thinking everything is used. ;; the `do` and the value was getting thrown away. `noop` tricks Kondo into thinking everything is used.
[{{[_ & args] :children} :node}] [{{[_ & args] :children} :node}]
(let [node* (hooks/list-node (let [noop (constantly nil)
node* (hooks/list-node
(list* (list*
(hooks/token-node 'print) (hooks/token-node noop)
args))] args))]
{:node node*})) {:node node*}))
......
...@@ -43,7 +43,8 @@ ...@@ -43,7 +43,8 @@
(defn dataset (defn dataset
[{{[_ dataset & body] :children} :node}] [{{[_ dataset & body] :children} :node}]
(let [body (case (dataset-type dataset) (let [noop (constantly nil)
body (case (dataset-type dataset)
;; non-symbol, qualified symbols, and unqualified symbols from the current namespace/let-bound can all ;; non-symbol, qualified symbols, and unqualified symbols from the current namespace/let-bound can all
;; get converted from something like ;; get converted from something like
;; ;;
...@@ -67,7 +68,7 @@ ...@@ -67,7 +68,7 @@
;; (this used to be a `do` form (which makes a lot more semantic sense), but that resulted in warnings ;; (this used to be a `do` form (which makes a lot more semantic sense), but that resulted in warnings
;; about unused values ;; about unused values
(:unqualified/from-dataset-defs-namespace :unqualified/unknown) (:unqualified/from-dataset-defs-namespace :unqualified/unknown)
(list* (hooks/token-node 'print) (list* (hooks/token-node noop)
body))] body))]
{:node (with-meta (hooks/list-node (with-meta body {:node (with-meta (hooks/list-node (with-meta body
(meta dataset))) (meta dataset)))
......
(ns macros.metabase.test.util) (ns macros.metabase.test.util)
(defmacro with-temp-env-var-value [bindings & body] (defmacro with-temp-env-var-value [bindings & body]
`(print `((constantly nil)
~@(map second (partition-all 2 bindings)) ~@(map second (partition-all 2 bindings))
~@body)) ~@body))
(defmacro with-temporary-raw-setting-values [bindings & body] (defmacro with-temporary-raw-setting-values [bindings & body]
`(print `((constantly nil)
~@(map second (partition-all 2 bindings)) ~@(map second (partition-all 2 bindings))
~@body)) ~@body))
...@@ -34,10 +34,10 @@ ...@@ -34,10 +34,10 @@
(when *compile-files* (when *compile-files*
(defonce previous-compilation-trace (atom nil)) (defonce previous-compilation-trace (atom nil))
(when @previous-compilation-trace (when @previous-compilation-trace
(println "THIS FILE HAS ALREADY BEEN COMPILED!!!!!") (log/info "THIS FILE HAS ALREADY BEEN COMPILED!!!!!")
(println "This compilation trace:") (log/info "This compilation trace:")
((requiring-resolve 'clojure.pprint/pprint) (vec (.getStackTrace (Thread/currentThread)))) ((requiring-resolve 'clojure.pprint/pprint) (vec (.getStackTrace (Thread/currentThread))))
(println "Previous compilation trace:") (log/info "Previous compilation trace:")
((requiring-resolve 'clojure.pprint/pprint) @previous-compilation-trace) ((requiring-resolve 'clojure.pprint/pprint) @previous-compilation-trace)
(throw (ex-info "THIS FILE HAS ALREADY BEEN COMPILED!!!!!" {}))) (throw (ex-info "THIS FILE HAS ALREADY BEEN COMPILED!!!!!" {})))
(reset! previous-compilation-trace (vec (.getStackTrace (Thread/currentThread))))) (reset! previous-compilation-trace (vec (.getStackTrace (Thread/currentThread)))))
......
...@@ -132,25 +132,25 @@ ...@@ -132,25 +132,25 @@
"Given the analysis map from [[escape-analysis]], report the results in a human-readable format with Card titles etc." "Given the analysis map from [[escape-analysis]], report the results in a human-readable format with Card titles etc."
[{:keys [escaped-dashcards escaped-questions]}] [{:keys [escaped-dashcards escaped-questions]}]
(when-not (empty? escaped-dashcards) (when-not (empty? escaped-dashcards)
(println "Dashboard cards outside the collection") (log/info "Dashboard cards outside the collection")
(println "======================================") (log/info "======================================")
(doseq [[dash-id card-ids] escaped-dashcards (doseq [[dash-id card-ids] escaped-dashcards
:let [dash-name (db/select-one-field :name Dashboard :id dash-id)]] :let [dash-name (db/select-one-field :name Dashboard :id dash-id)]]
(printf "Dashboard %d: %s\n" dash-id dash-name) (log/infof "Dashboard %d: %s\n" dash-id dash-name)
(doseq [card_id card-ids (doseq [card_id card-ids
:let [card (db/select-one [Card :collection_id :name] :id card_id)]] :let [card (db/select-one [Card :collection_id :name] :id card_id)]]
(printf " \tCard %d: %s\n" card_id (:name card)) (log/infof " \tCard %d: %s\n" card_id (:name card))
(printf " from collection %s\n" (collection-label (:collection_id card)))))) (log/infof " from collection %s\n" (collection-label (:collection_id card))))))
(when-not (empty? escaped-questions) (when-not (empty? escaped-questions)
(println "Questions based on outside questions") (log/info "Questions based on outside questions")
(println "====================================") (log/info "====================================")
(doseq [[curated-id alien-id] escaped-questions (doseq [[curated-id alien-id] escaped-questions
:let [curated-card (db/select-one [Card :collection_id :name] :id curated-id) :let [curated-card (db/select-one [Card :collection_id :name] :id curated-id)
alien-card (db/select-one [Card :collection_id :name] :id alien-id)]] alien-card (db/select-one [Card :collection_id :name] :id alien-id)]]
(printf "%-4d %s (%s)\n -> %-4d %s (%s)\n" (log/infof "%-4d %s (%s)\n -> %-4d %s (%s)\n"
curated-id (:name curated-card) (collection-label (:collection_id curated-card)) curated-id (:name curated-card) (collection-label (:collection_id curated-card))
alien-id (:name alien-card) (collection-label (:collection_id alien-card)))))) alien-id (:name alien-card) (collection-label (:collection_id alien-card))))))
(defn extract-subtrees (defn extract-subtrees
"Extracts the targeted entities and all their descendants into a reducible stream of extracted maps. "Extracts the targeted entities and all their descendants into a reducible stream of extracted maps.
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
[clojure.core.async :as a] [clojure.core.async :as a]
[clojure.string :as str] [clojure.string :as str]
[clojure.test :refer :all] [clojure.test :refer :all]
[clojure.tools.logging :as log]
[honeysql.core :as hsql] [honeysql.core :as hsql]
[medley.core :as m] [medley.core :as m]
[metabase-enterprise.sandbox.models.group-table-access-policy [metabase-enterprise.sandbox.models.group-table-access-policy
...@@ -426,7 +427,7 @@ ...@@ -426,7 +427,7 @@
(reset! remark <>)))] (reset! remark <>)))]
(let [results (run-query-fn)] (let [results (run-query-fn)]
(or (some-> @remark (str/replace #"queryHash: \w+" "queryHash: <hash>")) (or (some-> @remark (str/replace #"queryHash: \w+" "queryHash: <hash>"))
(println "NO REMARK FOUND:\n" (u/pprint-to-str 'red results)) (log/infof "NO REMARK FOUND:\n %s" (u/pprint-to-str 'red results))
(throw (ex-info "No remark found!" {:results results}))))))) (throw (ex-info "No remark found!" {:results results})))))))
(deftest remark-test (deftest remark-test
......
(ns metabase.test.data.bigquery-cloud-sdk (ns metabase.test.data.bigquery-cloud-sdk
(:require [clojure.string :as str] (:require [clojure.string :as str]
[clojure.tools.logging :as log]
[flatland.ordered.map :as ordered-map] [flatland.ordered.map :as ordered-map]
[java-time :as t] [java-time :as t]
[medley.core :as m] [medley.core :as m]
...@@ -92,14 +93,14 @@ ...@@ -92,14 +93,14 @@
(defn- create-dataset! [^String dataset-id] (defn- create-dataset! [^String dataset-id]
{:pre [(seq dataset-id)]} {:pre [(seq dataset-id)]}
(.create (bigquery) (DatasetInfo/of (DatasetId/of (project-id) dataset-id)) (u/varargs BigQuery$DatasetOption)) (.create (bigquery) (DatasetInfo/of (DatasetId/of (project-id) dataset-id)) (u/varargs BigQuery$DatasetOption))
(println (u/format-color 'blue "Created BigQuery dataset `%s.%s`." (project-id) dataset-id))) (log/info (u/format-color 'blue "Created BigQuery dataset `%s.%s`." (project-id) dataset-id)))
(defn- destroy-dataset! [^String dataset-id] (defn- destroy-dataset! [^String dataset-id]
{:pre [(seq dataset-id)]} {:pre [(seq dataset-id)]}
(.delete (bigquery) dataset-id (u/varargs (.delete (bigquery) dataset-id (u/varargs
BigQuery$DatasetDeleteOption BigQuery$DatasetDeleteOption
[(BigQuery$DatasetDeleteOption/deleteContents)])) [(BigQuery$DatasetDeleteOption/deleteContents)]))
(println (u/format-color 'red "Deleted BigQuery dataset `%s.%s`." (project-id) dataset-id))) (log/error (u/format-color 'red "Deleted BigQuery dataset `%s.%s`." (project-id) dataset-id)))
(defn execute! (defn execute!
"Execute arbitrary (presumably DDL) SQL statements against the test project. Waits for statement to complete, throwing "Execute arbitrary (presumably DDL) SQL statements against the test project. Waits for statement to complete, throwing
...@@ -107,7 +108,7 @@ ...@@ -107,7 +108,7 @@
^TableResult [format-string & args] ^TableResult [format-string & args]
(driver/with-driver :bigquery-cloud-sdk (driver/with-driver :bigquery-cloud-sdk
(let [sql (apply format format-string args)] (let [sql (apply format format-string args)]
(printf "[BigQuery] %s\n" sql) (log/infof "[BigQuery] %s\n" sql)
(flush) (flush)
(#'bigquery/execute-bigquery-on-db (data/db) sql nil nil nil)))) (#'bigquery/execute-bigquery-on-db (data/db) sql nil nil nil))))
...@@ -121,7 +122,7 @@ ...@@ -121,7 +122,7 @@
(s/defn ^:private delete-table! (s/defn ^:private delete-table!
[dataset-id :- su/NonBlankString, table-id :- su/NonBlankString] [dataset-id :- su/NonBlankString, table-id :- su/NonBlankString]
(.delete (bigquery) (TableId/of dataset-id table-id)) (.delete (bigquery) (TableId/of dataset-id table-id))
(println (u/format-color 'red "Deleted table `%s.%s.%s`" (project-id) dataset-id table-id))) (log/error (u/format-color 'red "Deleted table `%s.%s.%s`" (project-id) dataset-id table-id)))
(s/defn ^:private create-table! (s/defn ^:private create-table!
[^String dataset-id :- su/NonBlankString [^String dataset-id :- su/NonBlankString
...@@ -139,7 +140,7 @@ ...@@ -139,7 +140,7 @@
(.create (bigquery) tbl (u/varargs BigQuery$TableOption))) (.create (bigquery) tbl (u/varargs BigQuery$TableOption)))
;; now verify that the Table was created ;; now verify that the Table was created
(.listTables (bigquery) dataset-id (u/varargs BigQuery$TableListOption)) (.listTables (bigquery) dataset-id (u/varargs BigQuery$TableListOption))
(println (u/format-color 'blue "Created BigQuery table `%s.%s.%s`." (project-id) dataset-id table-id))) (log/info (u/format-color 'blue "Created BigQuery table `%s.%s.%s`." (project-id) dataset-id table-id)))
(defn- table-row-count ^Integer [^String dataset-id, ^String table-id] (defn- table-row-count ^Integer [^String dataset-id, ^String table-id]
(let [sql (format "SELECT count(*) FROM `%s.%s.%s`" (project-id) dataset-id table-id) (let [sql (format "SELECT count(*) FROM `%s.%s.%s`" (project-id) dataset-id table-id)
...@@ -204,17 +205,16 @@ ...@@ -204,17 +205,16 @@
(defn- insert-data! [^String dataset-id ^String table-id row-maps] (defn- insert-data! [^String dataset-id ^String table-id row-maps]
{:pre [(seq dataset-id) (seq table-id) (sequential? row-maps) (seq row-maps) (every? map? row-maps)]} {:pre [(seq dataset-id) (seq table-id) (sequential? row-maps) (seq row-maps) (every? map? row-maps)]}
(doseq [chunk (partition-all max-rows-per-request row-maps) (doseq [chunk (partition-all max-rows-per-request row-maps)
:let [_ (println (format :let [_ (log/infof "Inserting %d rows like\n%s"
"Inserting %d rows like\n%s"
(count chunk) (count chunk)
(u/pprint-to-str (first chunk)))) (u/pprint-to-str (first chunk)))
req (rows->request dataset-id table-id chunk) req (rows->request dataset-id table-id chunk)
^InsertAllResponse response (.insertAll (bigquery) req)]] ^InsertAllResponse response (.insertAll (bigquery) req)]]
(println (u/format-color 'blue "Sent request to insert %d rows into `%s.%s.%s`" (log/info (u/format-color 'blue "Sent request to insert %d rows into `%s.%s.%s`"
(count (.getRows req)) (count (.getRows req))
(project-id) dataset-id table-id)) (project-id) dataset-id table-id))
(when (seq (.getInsertErrors response)) (when (seq (.getInsertErrors response))
(println "Error inserting rows:" (u/pprint-to-str (seq (.getInsertErrors response)))) (log/errorf "Error inserting rows: %s" (u/pprint-to-str (seq (.getInsertErrors response))))
(throw (ex-info "Error inserting rows" (throw (ex-info "Error inserting rows"
{:errors (seq (.getInsertErrors response)) {:errors (seq (.getInsertErrors response))
:metabase.util/no-auto-retry? true :metabase.util/no-auto-retry? true
...@@ -223,25 +223,24 @@ ...@@ -223,25 +223,24 @@
;; Wait up to 120 seconds for all the rows to be loaded and become available by BigQuery ;; Wait up to 120 seconds for all the rows to be loaded and become available by BigQuery
(let [max-wait-seconds 120 (let [max-wait-seconds 120
expected-row-count (count row-maps)] expected-row-count (count row-maps)]
(println (format "Waiting for %d rows to be loaded..." expected-row-count)) (log/infof "Waiting for %d rows to be loaded..." expected-row-count)
(loop [seconds-to-wait-for-load max-wait-seconds] (loop [seconds-to-wait-for-load max-wait-seconds]
(let [actual-row-count (table-row-count dataset-id table-id)] (let [actual-row-count (table-row-count dataset-id table-id)]
(cond (cond
(= expected-row-count actual-row-count) (= expected-row-count actual-row-count)
(do (do
(println (format "Loaded %d rows in %d seconds." expected-row-count (- max-wait-seconds seconds-to-wait-for-load))) (log/infof "Loaded %d rows in %d seconds." expected-row-count (- max-wait-seconds seconds-to-wait-for-load))
:ok) :ok)
(> seconds-to-wait-for-load 0) (> seconds-to-wait-for-load 0)
(do (Thread/sleep 1000) (do (Thread/sleep 1000)
(print ".") (log/info ".")
(flush)
(recur (dec seconds-to-wait-for-load))) (recur (dec seconds-to-wait-for-load)))
:else :else
(let [error-message (format "Failed to load table data for `%s.%s.%s`: expected %d rows, loaded %d" (let [error-message (format "Failed to load table data for `%s.%s.%s`: expected %d rows, loaded %d"
(project-id) dataset-id table-id expected-row-count actual-row-count)] (project-id) dataset-id table-id expected-row-count actual-row-count)]
(println (u/format-color 'red error-message)) (log/error (u/format-color 'red error-message))
(throw (ex-info error-message {:metabase.util/no-auto-retry? true})))))))) (throw (ex-info error-message {:metabase.util/no-auto-retry? true}))))))))
(defn base-type->bigquery-type [base-type] (defn base-type->bigquery-type [base-type]
...@@ -269,7 +268,7 @@ ...@@ -269,7 +268,7 @@
(for [{:keys [field-name base-type]} field-definitions] (for [{:keys [field-name base-type]} field-definitions]
[field-name (or (base-type->bigquery-type base-type) [field-name (or (base-type->bigquery-type base-type)
(let [message (format "Don't know what BigQuery type to use for base type: %s" base-type)] (let [message (format "Don't know what BigQuery type to use for base type: %s" base-type)]
(println (u/format-color 'red message)) (log/error (u/format-color 'red message))
(throw (ex-info message {:metabase.util/no-auto-retry? true}))))])))) (throw (ex-info message {:metabase.util/no-auto-retry? true}))))]))))
(defn- tabledef->prepared-rows (defn- tabledef->prepared-rows
...@@ -327,12 +326,12 @@ ...@@ -327,12 +326,12 @@
(let [{transient-datasets true non-transient-datasets false} (group-by transient-dataset? (let [{transient-datasets true non-transient-datasets false} (group-by transient-dataset?
(existing-dataset-names))] (existing-dataset-names))]
(reset! existing-datasets (set non-transient-datasets)) (reset! existing-datasets (set non-transient-datasets))
(println "These BigQuery datasets have already been loaded:\n" (u/pprint-to-str (sort @existing-datasets))) (log/infof "These BigQuery datasets have already been loaded:\n%s" (u/pprint-to-str (sort @existing-datasets)))
(when-let [outdated-transient-datasets (seq (filter transient-dataset-outdated? transient-datasets))] (when-let [outdated-transient-datasets (seq (filter transient-dataset-outdated? transient-datasets))]
(println (u/format-color (log/info (u/format-color
'blue 'blue
"These BigQuery datasets are transient, and more than two hours old; deleting them: %s`." "These BigQuery datasets are transient, and more than two hours old; deleting them: %s`."
(u/pprint-to-str (sort outdated-transient-datasets)))) (u/pprint-to-str (sort outdated-transient-datasets))))
(doseq [delete-ds outdated-transient-datasets] (doseq [delete-ds outdated-transient-datasets]
(u/ignore-exceptions (u/ignore-exceptions
(destroy-dataset! delete-ds)))))) (destroy-dataset! delete-ds))))))
...@@ -343,7 +342,7 @@ ...@@ -343,7 +342,7 @@
(destroy-dataset! database-name)) (destroy-dataset! database-name))
(u/auto-retry 2 (u/auto-retry 2
(try (try
(println (format "Creating dataset %s..." (pr-str database-name))) (log/infof "Creating dataset %s..." (pr-str database-name))
;; if the dataset failed to load successfully last time around, destroy whatever was loaded so we start ;; if the dataset failed to load successfully last time around, destroy whatever was loaded so we start
;; again from a blank slate ;; again from a blank slate
(destroy-dataset! database-name) (destroy-dataset! database-name)
...@@ -354,10 +353,10 @@ ...@@ -354,10 +353,10 @@
(doseq [tabledef table-definitions] (doseq [tabledef table-definitions]
(load-tabledef! database-name tabledef)) (load-tabledef! database-name tabledef))
(swap! existing-datasets conj database-name) (swap! existing-datasets conj database-name)
(println (u/format-color 'green "Successfully created %s." (pr-str database-name))) (log/info (u/format-color 'green "Successfully created %s." (pr-str database-name)))
(catch Throwable e (catch Throwable e
(println (u/format-color 'red "Failed to load BigQuery dataset %s." (pr-str database-name))) (log/error (u/format-color 'red "Failed to load BigQuery dataset %s." (pr-str database-name)))
(println (u/pprint-to-str 'red (Throwable->map e))) (log/error (u/pprint-to-str 'red (Throwable->map e)))
;; if creating the dataset ultimately fails to complete, then delete it so it will hopefully ;; if creating the dataset ultimately fails to complete, then delete it so it will hopefully
;; work next time around ;; work next time around
(u/ignore-exceptions (u/ignore-exceptions
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
"Tests for Mongo driver." "Tests for Mongo driver."
(:require [cheshire.core :as json] (:require [cheshire.core :as json]
[clojure.test :refer :all] [clojure.test :refer :all]
[clojure.tools.logging :as log]
[medley.core :as m] [medley.core :as m]
[metabase.automagic-dashboards.core :as magic] [metabase.automagic-dashboards.core :as magic]
[metabase.db.metadata-queries :as metadata-queries] [metabase.db.metadata-queries :as metadata-queries]
...@@ -438,8 +439,8 @@ ...@@ -438,8 +439,8 @@
(throw (ex-info (format "Error inserting row: %s" (ex-message e)) (throw (ex-info (format "Error inserting row: %s" (ex-message e))
{:database database-name, :collection collection-name, :details details, :row row} {:database database-name, :collection collection-name, :details details, :row row}
e))))) e)))))
(println (format "Inserted %d rows into %s collection %s." (log/infof "Inserted %d rows into %s collection %s."
(count row-maps) (pr-str database-name) (pr-str collection-name)))) (count row-maps) (pr-str database-name) (pr-str collection-name)))
;; now sync the Database. ;; now sync the Database.
(let [db (db/insert! Database {:name database-name, :engine "mongo", :details details})] (let [db (db/insert! Database {:name database-name, :engine "mongo", :details details})]
(sync/sync-database! db) (sync/sync-database! db)
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
[clojure.java.jdbc :as jdbc] [clojure.java.jdbc :as jdbc]
[clojure.string :as str] [clojure.string :as str]
[clojure.test :refer :all] [clojure.test :refer :all]
[clojure.tools.logging :as log]
[metabase.api.common :as api] [metabase.api.common :as api]
[metabase.driver :as driver] [metabase.driver :as driver]
[metabase.driver.oracle :as oracle] [metabase.driver.oracle :as oracle]
...@@ -363,10 +364,10 @@ ...@@ -363,10 +364,10 @@
te/*test-drivers* (constantly #{:oracle})] te/*test-drivers* (constantly #{:oracle})]
(testing " and execute a query correctly" (testing " and execute a query correctly"
(qp-test.order-by-test/order-by-test)))))))))))) (qp-test.order-by-test/order-by-test))))))))))))
(println (u/format-color 'yellow (log/warn (u/format-color 'yellow
"Skipping %s because %s env var is not set" "Skipping %s because %s env var is not set"
"oracle-connect-with-ssl-test" "oracle-connect-with-ssl-test"
"MB_ORACLE_SSL_TEST_SSL"))))) "MB_ORACLE_SSL_TEST_SSL")))))
(deftest text-equals-empty-string-test (deftest text-equals-empty-string-test
(mt/test-driver :oracle (mt/test-driver :oracle
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
(:require [clojure.java.jdbc :as jdbc] (:require [clojure.java.jdbc :as jdbc]
[clojure.set :as set] [clojure.set :as set]
[clojure.string :as str] [clojure.string :as str]
[clojure.tools.logging :as log]
[honeysql.format :as hformat] [honeysql.format :as hformat]
[medley.core :as m] [medley.core :as m]
[metabase.db :as mdb] [metabase.db :as mdb]
...@@ -128,14 +129,14 @@ ...@@ -128,14 +129,14 @@
(let [existing-db-id (u/the-id existing-db) (let [existing-db-id (u/the-id existing-db)
all-schemas (db/select-field :schema Table :db_id existing-db-id)] all-schemas (db/select-field :schema Table :db_id existing-db-id)]
(when-not (= all-schemas #{session-schema}) (when-not (= all-schemas #{session-schema})
(println (u/format-color 'yellow (log/warn (u/format-color 'yellow
(str "[oracle] At least one table's schema for the existing '%s' Database" (str "[oracle] At least one table's schema for the existing '%s' Database"
" (id %d), which include all of [%s], does not match current session-schema" " (id %d), which include all of [%s], does not match current session-schema"
" of %s; deleting this DB so it can be recreated") " of %s; deleting this DB so it can be recreated")
database-name database-name
existing-db-id existing-db-id
(str/join "," all-schemas) (str/join "," all-schemas)
session-schema)) session-schema))
(db/delete! Database :id existing-db-id)))) (db/delete! Database :id existing-db-id))))
(swap! oracle-test-dbs-created-by-this-instance conj database-name))))) (swap! oracle-test-dbs-created-by-this-instance conj database-name)))))
...@@ -215,9 +216,9 @@ ...@@ -215,9 +216,9 @@
;; TL;DR Oracle schema == Oracle user. Create new user for session-schema ;; TL;DR Oracle schema == Oracle user. Create new user for session-schema
(defn- execute! [format-string & args] (defn- execute! [format-string & args]
(let [sql (apply format format-string args)] (let [sql (apply format format-string args)]
(println (u/format-color 'blue "[oracle] %s" sql)) (log/info (u/format-color 'blue "[oracle] %s" sql))
(jdbc/execute! (dbspec) sql)) (jdbc/execute! (dbspec) sql))
(println (u/format-color 'blue "[ok]"))) (log/info (u/format-color 'blue "[ok]")))
(defn create-user! (defn create-user!
;; default to using session-password for all users created this session ;; default to using session-password for all users created this session
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
"Presto JDBC driver test extensions." "Presto JDBC driver test extensions."
(:require [clojure.string :as str] (:require [clojure.string :as str]
[clojure.test :refer :all] [clojure.test :refer :all]
[clojure.tools.logging :as log]
[metabase.config :as config] [metabase.config :as config]
[metabase.connection-pool :as connection-pool] [metabase.connection-pool :as connection-pool]
[metabase.driver :as driver] [metabase.driver :as driver]
...@@ -119,7 +120,7 @@ ...@@ -119,7 +120,7 @@
(sql-jdbc.execute/set-parameters! driver stmt params) (sql-jdbc.execute/set-parameters! driver stmt params)
(let [tbl-nm ((comp last :components) (into {} table-identifier)) (let [tbl-nm ((comp last :components) (into {} table-identifier))
rows-affected (.executeUpdate stmt)] rows-affected (.executeUpdate stmt)]
(println (format "[%s] Inserted %d rows into %s." driver rows-affected tbl-nm)))) (log/infof "[%s] Inserted %d rows into %s." driver rows-affected tbl-nm)))
(catch Throwable e (catch Throwable e
(throw (ex-info (format "[%s] Error executing SQL: %s" driver (ex-message e)) (throw (ex-info (format "[%s] Error executing SQL: %s" driver (ex-message e))
{:driver driver, :sql sql, :params params} {:driver driver, :sql sql, :params params}
......
...@@ -127,9 +127,9 @@ ...@@ -127,9 +127,9 @@
(let [details (tx/dbdef->connection-details driver :db dbdef) (let [details (tx/dbdef->connection-details driver :db dbdef)
execute! (partial #'presto/execute-query-for-sync details)] execute! (partial #'presto/execute-query-for-sync details)]
(doseq [{:keys [table-name], :as tabledef} table-definitions] (doseq [{:keys [table-name], :as tabledef} table-definitions]
(println (format "[Presto] destroying %s.%s" (pr-str database-name) (pr-str table-name))) (log/infof "[Presto] destroying %s.%s" (pr-str database-name) (pr-str table-name))
(execute! (sql.tx/drop-table-if-exists-sql driver dbdef tabledef)) (execute! (sql.tx/drop-table-if-exists-sql driver dbdef tabledef))
(println "[Presto] [ok]")))) (log/info "[Presto] [ok]"))))
(defmethod ddl.i/format-name :presto (defmethod ddl.i/format-name :presto
[_ s] [_ s]
......
(ns metabase.test.data.redshift (ns metabase.test.data.redshift
(:require [clojure.java.jdbc :as jdbc] (:require [clojure.java.jdbc :as jdbc]
[clojure.tools.logging :as log]
[metabase.driver.sql-jdbc.connection :as sql-jdbc.conn] [metabase.driver.sql-jdbc.connection :as sql-jdbc.conn]
[metabase.driver.sql-jdbc.sync :as sql-jdbc.sync] [metabase.driver.sql-jdbc.sync :as sql-jdbc.sync]
[metabase.test.data.interface :as tx] [metabase.test.data.interface :as tx]
...@@ -76,9 +77,9 @@ ...@@ -76,9 +77,9 @@
(defn execute! [format-string & args] (defn execute! [format-string & args]
(let [sql (apply format format-string args) (let [sql (apply format format-string args)
spec (sql-jdbc.conn/connection-details->spec :redshift @db-connection-details)] spec (sql-jdbc.conn/connection-details->spec :redshift @db-connection-details)]
(println (u/format-color 'blue "[redshift] %s" sql)) (log/info (u/format-color 'blue "[redshift] %s" sql))
(jdbc/execute! spec sql)) (jdbc/execute! spec sql))
(println (u/format-color 'blue "[ok]"))) (log/info (u/format-color 'blue "[ok]")))
(defmethod tx/before-run :redshift (defmethod tx/before-run :redshift
[_] [_]
......
(ns metabase.test.data.snowflake (ns metabase.test.data.snowflake
(:require [clojure.java.jdbc :as jdbc] (:require [clojure.java.jdbc :as jdbc]
[clojure.string :as str] [clojure.string :as str]
[clojure.tools.logging :as log]
[metabase.driver.sql-jdbc.connection :as sql-jdbc.conn] [metabase.driver.sql-jdbc.connection :as sql-jdbc.conn]
[metabase.driver.sql-jdbc.sync :as sql-jdbc.sync] [metabase.driver.sql-jdbc.sync :as sql-jdbc.sync]
[metabase.driver.sql.util.unprepare :as unprepare] [metabase.driver.sql.util.unprepare :as unprepare]
...@@ -80,7 +81,7 @@ ...@@ -80,7 +81,7 @@
(defn- existing-datasets [] (defn- existing-datasets []
(when-not (seq @datasets) (when-not (seq @datasets)
(reset! datasets (existing-dataset-names)) (reset! datasets (existing-dataset-names))
(println "These Snowflake datasets have already been loaded:\n" (u/pprint-to-str (sort @datasets)))) (log/infof "These Snowflake datasets have already been loaded:\n%s" (u/pprint-to-str (sort @datasets))))
@datasets) @datasets)
(defn- add-existing-dataset! [database-name] (defn- add-existing-dataset! [database-name]
...@@ -94,7 +95,7 @@ ...@@ -94,7 +95,7 @@
(let [{:keys [database-name], :as db-def} (update db-def :database-name qualified-db-name)] (let [{:keys [database-name], :as db-def} (update db-def :database-name qualified-db-name)]
;; ok, now check if already created. If already created, no-op ;; ok, now check if already created. If already created, no-op
(when-not (contains? (existing-datasets) database-name) (when-not (contains? (existing-datasets) database-name)
(println (format "Creating new Snowflake database %s..." (pr-str database-name))) (log/infof "Creating new Snowflake database %s..." (pr-str database-name))
;; if not created, create the DB... ;; if not created, create the DB...
(try (try
;; call the default impl for SQL JDBC drivers ;; call the default impl for SQL JDBC drivers
...@@ -105,8 +106,8 @@ ...@@ -105,8 +106,8 @@
;; load it next time around ;; load it next time around
(catch Throwable e (catch Throwable e
(let [drop-db-sql (format "DROP DATABASE \"%s\";" database-name)] (let [drop-db-sql (format "DROP DATABASE \"%s\";" database-name)]
(println "Creating DB failed:" e) (log/errorf "Creating DB failed: %s" e)
(println "[Snowflake]" drop-db-sql) (log/errorf "[Snowflake] %s" drop-db-sql)
(jdbc/execute! (no-db-connection-spec) [drop-db-sql])) (jdbc/execute! (no-db-connection-spec) [drop-db-sql]))
(throw e)))))) (throw e))))))
...@@ -114,7 +115,7 @@ ...@@ -114,7 +115,7 @@
[_ {:keys [database-name]}] [_ {:keys [database-name]}]
(let [database-name (qualified-db-name database-name) (let [database-name (qualified-db-name database-name)
sql (format "DROP DATABASE \"%s\";" database-name)] sql (format "DROP DATABASE \"%s\";" database-name)]
(println "[Snowflake]" sql) (log/infof "[Snowflake] %s" sql)
(jdbc/execute! (no-db-connection-spec) [sql]) (jdbc/execute! (no-db-connection-spec) [sql])
(remove-existing-dataset! database-name))) (remove-existing-dataset! database-name)))
......
(ns metabase.test.data.sparksql (ns metabase.test.data.sparksql
(:require [clojure.java.jdbc :as jdbc] (:require [clojure.java.jdbc :as jdbc]
[clojure.string :as str] [clojure.string :as str]
[clojure.tools.logging :as log]
[honeysql.core :as hsql] [honeysql.core :as hsql]
[honeysql.format :as hformat] [honeysql.format :as hformat]
[metabase.config :as config] [metabase.config :as config]
...@@ -74,7 +75,7 @@ ...@@ -74,7 +75,7 @@
(doseq [sql+args statements] (doseq [sql+args statements]
(jdbc/execute! {:connection conn} sql+args {:transaction? false})) (jdbc/execute! {:connection conn} sql+args {:transaction? false}))
(catch java.sql.SQLException e (catch java.sql.SQLException e
(println "Error inserting data:" (u/pprint-to-str 'red statements)) (log/infof "Error inserting data: %s" (u/pprint-to-str 'red statements))
(jdbc/print-sql-exception-chain e) (jdbc/print-sql-exception-chain e)
(throw e)))))) (throw e))))))
......
...@@ -225,6 +225,7 @@ ...@@ -225,6 +225,7 @@
[(t/zoned-date-time date time (t/zone-id "America/Los_Angeles")) [(t/zoned-date-time date time (t/zone-id "America/Los_Angeles"))
(t/offset-date-time (t/local-date-time date time) (t/zone-offset -8))]]] (t/offset-date-time (t/local-date-time date time) (t/zone-offset -8))]]]
(let [expected (or expected t)] (let [expected (or expected t)]
#_{:clj-kondo/ignore [:discouraged-var]}
(testing (format "Convert %s to SQL literal" (colorize/magenta (with-out-str (pr t)))) (testing (format "Convert %s to SQL literal" (colorize/magenta (with-out-str (pr t))))
(let [sql (format "SELECT %s AS t;" (unprepare/unprepare-value :sqlserver t))] (let [sql (format "SELECT %s AS t;" (unprepare/unprepare-value :sqlserver t))]
(with-open [conn (sql-jdbc.execute/connection-with-timezone :sqlserver (mt/db) nil) (with-open [conn (sql-jdbc.execute/connection-with-timezone :sqlserver (mt/db) nil)
......
...@@ -570,7 +570,7 @@ ...@@ -570,7 +570,7 @@
existing-hash (some-> varr meta ::defmodel-hash) existing-hash (some-> varr meta ::defmodel-hash)
has-same-hash? (= existing-hash (hash &form))] has-same-hash? (= existing-hash (hash &form))]
(when has-same-hash? (when has-same-hash?
(println model "has not changed, skipping redefinition")) (log/infof "%s has not changed, skipping redefinition" model))
(when-not has-same-hash? (when-not has-same-hash?
`(do `(do
~(apply original-defmodel &form &env model args) ~(apply original-defmodel &form &env model args)
......
(ns metabase.server.handler (ns metabase.server.handler
"Top-level Metabase Ring handler." "Top-level Metabase Ring handler."
(:require (:require
[clojure.tools.logging :as log]
[metabase.config :as config] [metabase.config :as config]
[metabase.server.middleware.auth :as mw.auth] [metabase.server.middleware.auth :as mw.auth]
[metabase.server.middleware.browser-cookie :as mw.browser-cookie] [metabase.server.middleware.browser-cookie :as mw.browser-cookie]
...@@ -85,5 +86,5 @@ ...@@ -85,5 +86,5 @@
(doseq [varr (cons #'routes/routes middleware) (doseq [varr (cons #'routes/routes middleware)
:when (instance? clojure.lang.IRef varr)] :when (instance? clojure.lang.IRef varr)]
(add-watch varr ::reload (fn [_ _ _ _] (add-watch varr ::reload (fn [_ _ _ _]
(printf "%s changed, rebuilding %s" varr #'app) (log/infof "%s changed, rebuilding %s" varr #'app)
(alter-var-root #'app (constantly (apply-middleware routes/routes))))))) (alter-var-root #'app (constantly (apply-middleware routes/routes)))))))
...@@ -233,7 +233,7 @@ ...@@ -233,7 +233,7 @@
(str frame n unit "-from-0" unit2)]) (str frame n unit "-from-0" unit2)])
(gen/tuple (gen/tuple
(gen/elements #{"next" "past"}) (gen/elements #{"next" "past"})
(gen/such-that #(not= % 0) gen/pos-int) (gen/such-that #(not= % 0) gen/nat)
(gen/elements time-units) (gen/elements time-units)
(gen/elements time-units))))) (gen/elements time-units)))))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment