Skip to content
Snippets Groups Projects
Unverified Commit 8d8517f8 authored by Dennis Schridde's avatar Dennis Schridde Committed by GitHub
Browse files

Improve tests of prometheus metrics for emails sent (#32467)

Replace Java interop with iapetos functions.

Fixes: 5bfd21b7
parent 0dbe0b3e
No related branches found
Tags v0.30.4
No related merge requests found
......@@ -4,13 +4,12 @@
[clojure.set :as set]
[clojure.string :as str]
[clojure.test :refer :all]
[iapetos.operations :as ops]
[iapetos.registry :as registry]
[metabase.analytics.prometheus :as prometheus]
[metabase.test.fixtures :as fixtures])
(:import
(iapetos.registry IapetosRegistry)
(io.prometheus.client Collector Collector$MetricFamilySamples CollectorRegistry GaugeMetricFamily)
(metabase.analytics.prometheus PrometheusSystem)
(io.prometheus.client Collector GaugeMetricFamily)
(org.eclipse.jetty.server Server)))
(set! *warn-on-reflection* true)
......@@ -157,18 +156,15 @@
(deftest email-collector-test
(testing "Registry has email metrics registered"
(with-prometheus-system [_ system]
(let [sample-names (set (for [metric-family-samples (enumeration-seq (.metricFamilySamples ^CollectorRegistry (.raw ^IapetosRegistry (.-registry system))))
sample-name (.getNames ^Collector$MetricFamilySamples metric-family-samples)]
sample-name))]
(is (contains? sample-names "metabase_email_messages") "messages sample not found")
(is (contains? sample-names "metabase_email_message_errors") "message_errors sample not found")))))
(defn- get-sample-value
[^PrometheusSystem system ^String metric]
(.getSampleValue ^CollectorRegistry (registry/raw (.-registry system)) metric))
(with-prometheus-system [port _]
(is (= #{"metabase_email_messages_total" "metabase_email_messages_created" "metabase_email_message_errors_total" "metabase_email_message_errors_created"}
(->> (metric-lines port)
(map #(str/split % #"\s+"))
(map first)
(filter #(str/starts-with? % "metabase_email_"))
set))))))
(deftest inc-server-test
(deftest inc-test
(testing "inc has no effect if system is not setup"
(prometheus/inc :metabase-email/messages)) ; << Does not throw.
(testing "inc has no effect when called with unknown metric"
......@@ -177,4 +173,4 @@
(testing "inc is recorded for known metrics"
(with-prometheus-system [_ system]
(prometheus/inc :metabase-email/messages)
(is (< 0 (get-sample-value system "metabase_email_messages_total"))))))
(is (< 0 (-> system :registry :metabase-email/messages ops/read-value))))))
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