Skip to content

Commit

Permalink
Show all schac-homes; rename metrics (#233)
Browse files Browse the repository at this point in the history
* Show all schac-homes; rename metrics

* Added comment
  • Loading branch information
mdemare authored Aug 22, 2023
1 parent b07210d commit 479b5fd
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 9 deletions.
5 changes: 3 additions & 2 deletions src/nl/surf/eduhub_rio_mapper/api.clj
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
[nl.jomco.http-status-codes :as http-status]
[nl.jomco.ring-trace-context :refer [wrap-trace-context]]
[nl.surf.eduhub-rio-mapper.api.authentication :as authentication]
[nl.surf.eduhub-rio-mapper.clients-info :refer [wrap-client-info]]
[nl.surf.eduhub-rio-mapper.clients-info :refer [wrap-client-info] :as clients-info]
[nl.surf.eduhub-rio-mapper.job :as job]
[nl.surf.eduhub-rio-mapper.logging :refer [wrap-logging with-mdc]]
[nl.surf.eduhub-rio-mapper.metrics :as metrics]
Expand Down Expand Up @@ -178,7 +178,8 @@
(wrap-callback-extractor)
(wrap-job-enqueuer (partial worker/enqueue! config))
(wrap-status-getter config)
(wrap-metrics-getter (fn [] (metrics/count-queues #(worker/queue-counts-by-key % config))))
(wrap-metrics-getter (fn [] (metrics/count-queues #(worker/queue-counts-by-key % config)
(clients-info/institution-schac-homes clients))))
(wrap-client-info clients)
(authentication/wrap-authentication (-> (authentication/make-token-authenticator auth-config)
(authentication/cache-token-authenticator {:ttl-minutes 10})))
Expand Down
13 changes: 8 additions & 5 deletions src/nl/surf/eduhub_rio_mapper/metrics.clj
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,16 @@
{:pre [(map? queue-count)
(every? string? (keys queue-count))
(every? integer? (vals queue-count))]}
(str/join "\n" (map (fn [[k v]] (format "active_and_queued_job_count{schac_home=\"%s\"} %s" k v))
(str/join "\n" (map (fn [[k v]] (format "rio_mapper_active_and_queued_job_count{schac_home=\"%s\"} %s" k v))
queue-count)))

(defn count-queues [grouped-queue-counter]
(defn count-queues [grouped-queue-counter client-schac-homes]
{:post [(map? %)
(every? string? (keys %))
(every? integer? (vals %))]}
(merge-with +
(grouped-queue-counter :queue)
(grouped-queue-counter :busy-queue)))
;; For all keys in client-schac-homes, add value 0 in map if not already in map
(reduce (fn [m k] (assoc m k (get m k 0)))
(merge-with +
(grouped-queue-counter :queue)
(grouped-queue-counter :busy-queue))
client-schac-homes))
2 changes: 1 addition & 1 deletion test/nl/surf/eduhub_rio_mapper/api_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@
(let [app (api/wrap-metrics-getter api/routes (constantly {"foo" 1, "bar" 2}))
{:keys [status body]} (app (request :get "/metrics"))]
(is (= http-status/ok status))
(is (= "active_and_queued_job_count{schac_home=\"foo\"} 1\nactive_and_queued_job_count{schac_home=\"bar\"} 2"
(is (= "rio_mapper_active_and_queued_job_count{schac_home=\"foo\"} 1\nrio_mapper_active_and_queued_job_count{schac_home=\"bar\"} 2"
body))))

(deftest wrap-job-queuer
Expand Down
2 changes: 1 addition & 1 deletion test/nl/surf/eduhub_rio_mapper/metrics_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@

(deftest render-metrics
(is (= (metrics/render-metrics {"google" 12 "meta" 32})
"active_and_queued_job_count{schac_home=\"google\"} 12\nactive_and_queued_job_count{schac_home=\"meta\"} 32")))
"rio_mapper_active_and_queued_job_count{schac_home=\"google\"} 12\nrio_mapper_active_and_queued_job_count{schac_home=\"meta\"} 32")))

0 comments on commit 479b5fd

Please sign in to comment.