Skip to content

Instantly share code, notes, and snippets.

@Samstiles
Created September 17, 2015 23:07
Show Gist options
  • Select an option

  • Save Samstiles/f302bd2e668797551f81 to your computer and use it in GitHub Desktop.

Select an option

Save Samstiles/f302bd2e668797551f81 to your computer and use it in GitHub Desktop.
(s/defn execute-queue-length
[request]
(try
(m/mark! @queue-length-request-meter)
(let [at (time/now)
tenant-id (:tenant-id request)
start (or (:start request) default-start)
end (or (:end request) default-end)]
(if (and (date-valid start) (date-valid end))
(let [filters (cond-> [(filter-base ":queue-duration" "event-type")]
tenant-id (conj (filter-base tenant-id "tenant-id")))
query (merge queue-length-query {:filter {:type :and :fields filters}
:intervals [(str start "/" end)]})
response (execute-druid-query query)
response-data (cheshire/parse-string (:body response) true)]
{:status 200 :body (cheshire/generate-string (format-queue-length-output
at
tenant-id
start
end
response-data))})
{:status 417 :body "Invalid start and/or end dates."}))
(catch Throwable e
(println (str "CAUGHT AN ERROR PERFORMING DRUID QUERY FOR QUEUE LENGTH" (pr-str e)))
{:status 500 :body (.getMessage e)})))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment