Created
September 17, 2015 23:07
-
-
Save Samstiles/f302bd2e668797551f81 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (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