Skip to content

Commit 0122557

Browse files
committed
Add XTDB_QUERY_DEBUG env variable to log query details
1 parent ae787ad commit 0122557

File tree

3 files changed

+20
-11
lines changed

3 files changed

+20
-11
lines changed

README.adoc

+4
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ container it will automatically migrate that node to be the first node of the
5757
multinode container with the name specified by XTDB_MIGRATION_NODE_NAME. If the
5858
environment variable isn't specified it will default to "_dev".
5959

60+
=== XTDB_QUERY_DEBUG
61+
62+
Setting this variable will log the duration of every query.
63+
6064
=== JAVA_TOOL_OPTIONS
6165

6266
This are the options for the JVM. This by default set to `-Xms128M -Xmx512M

src/xtdb_http_multinode/core.clj

+2
Original file line numberDiff line numberDiff line change
@@ -568,6 +568,8 @@
568568
(when (:help options)
569569
(println summary)
570570
(System/exit 0))
571+
(when (System/getenv "XTDB_QUERY_DEBUG")
572+
(.setLevel (org.slf4j.LoggerFactory/getLogger "xtdb-http-multinode.query") (ch.qos.logback.classic.Level/valueOf "debug")))
571573
(let [port (:port options)
572574
host (:host options)
573575
server (j/run-jetty (rr/ring-handler (->xtdb-router {:http-options {}})

src/xtdb_http_multinode/query.clj

+14-11
Original file line numberDiff line numberDiff line change
@@ -199,17 +199,20 @@
199199
(let [{query-params :query body-params :body} (get-in req [:parameters])
200200
{:keys [valid-time tx-time tx-id query-edn in-args-edn in-args-json]} query-params
201201
query (or query-edn (get body-params :query))
202-
in-args (or in-args-edn in-args-json (get body-params :in-args))]
203-
(-> (if (nil? query)
204-
(assoc options :no-query? true)
205-
(run-query (transform-req query req)
206-
in-args
207-
(assoc options
208-
:valid-time valid-time
209-
:tx-time tx-time
210-
:tx-id tx-id
211-
:xtdb-node (get req :xtdb-node))))
212-
(transform-query-resp req)))
202+
in-args (or in-args-edn in-args-json (get body-params :in-args))
203+
start-time (System/currentTimeMillis)
204+
result (-> (if (nil? query)
205+
(assoc options :no-query? true)
206+
(run-query (transform-req query req)
207+
in-args
208+
(assoc options
209+
:valid-time valid-time
210+
:tx-time tx-time
211+
:tx-id tx-id
212+
:xtdb-node (get req :xtdb-node))))
213+
(transform-query-resp req))]
214+
(log/debug "duration:" (- (System/currentTimeMillis) start-time) "ms query:" query)
215+
result)
213216

214217
(catch java.lang.AssertionError e
215218
(log/debug e)

0 commit comments

Comments
 (0)