From 6e3676590228d3f955f1055f590230b013f70e0d Mon Sep 17 00:00:00 2001 From: Jonathan Lange Date: Sun, 2 Jul 2017 10:35:11 +0100 Subject: [PATCH] Measure seconds, not microseconds in WAI instrumentation Brings us in line with Prometheus best practices: https://prometheus.io/docs/practices/naming/#metric-names --- .../src/Network/Wai/Middleware/Prometheus.hs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/wai-middleware-prometheus/src/Network/Wai/Middleware/Prometheus.hs b/wai-middleware-prometheus/src/Network/Wai/Middleware/Prometheus.hs index d881a6a..ce6203e 100644 --- a/wai-middleware-prometheus/src/Network/Wai/Middleware/Prometheus.hs +++ b/wai-middleware-prometheus/src/Network/Wai/Middleware/Prometheus.hs @@ -52,8 +52,8 @@ instance Default.Default PrometheusSettings where requestLatency :: Prom.Metric (Prom.Vector Prom.Label3 Prom.Summary) requestLatency = Prom.unsafeRegisterIO $ Prom.vector ("handler", "method", "status_code") $ Prom.summary info Prom.defaultQuantiles - where info = Prom.Info "http_request_duration_microseconds" - "The HTTP request latencies in microseconds." + where info = Prom.Info "http_request_duration_seconds" + "The HTTP request latencies in seconds." -- | Instrument a WAI app with the default WAI metrics. -- @@ -69,7 +69,7 @@ instrumentApp handler app req respond = do end <- getTime Monotonic let method = Just $ BS.unpack (Wai.requestMethod req) let status = Just $ show (HTTP.statusCode (Wai.responseStatus res)) - observeMicroSeconds handler method status start end + observeSeconds handler method status start end respond res -- | Instrument an IO action with timing metrics. This function can be used if @@ -86,12 +86,12 @@ instrumentIO label io = do start <- getTime Monotonic result <- io end <- getTime Monotonic - observeMicroSeconds label Nothing Nothing start end + observeSeconds label Nothing Nothing start end return result -observeMicroSeconds :: String -> Maybe String -> Maybe String -> TimeSpec -> TimeSpec -> IO () -observeMicroSeconds handler method status start end = do - let latency = fromRational $ toRational (toNanoSecs (end `diffTimeSpec` start) % 1000) +observeSeconds :: String -> Maybe String -> Maybe String -> TimeSpec -> TimeSpec -> IO () +observeSeconds handler method status start end = do + let latency = fromRational $ toRational (toNanoSecs (end `diffTimeSpec` start) % 1000000000) Prom.withLabel (handler, fromMaybe "" method, fromMaybe "" status) (Prom.observe latency) requestLatency