Hello community,
here is the log from the commit of package ghc-wai-middleware-prometheus for
openSUSE:Factory checked in at 2017-06-04 01:55:57
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Comparing /work/SRC/openSUSE:Factory/ghc-wai-middleware-prometheus (Old)
and /work/SRC/openSUSE:Factory/.ghc-wai-middleware-prometheus.new (New)
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "ghc-wai-middleware-prometheus"
Sun Jun 4 01:55:57 2017 rev:2 rq:494200 version:0.1.1
Changes:
--------
---
/work/SRC/openSUSE:Factory/ghc-wai-middleware-prometheus/ghc-wai-middleware-prometheus.changes
2017-03-09 01:57:35.644540432 +0100
+++
/work/SRC/openSUSE:Factory/.ghc-wai-middleware-prometheus.new/ghc-wai-middleware-prometheus.changes
2017-06-04 01:56:00.420597890 +0200
@@ -1,0 +2,5 @@
+Wed May 3 08:24:06 UTC 2017 - [email protected]
+
+- Update to version 0.1.1 with cabal2obs.
+
+-------------------------------------------------------------------
Old:
----
wai-middleware-prometheus-0.1.0.1.tar.gz
New:
----
wai-middleware-prometheus-0.1.1.tar.gz
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Other differences:
------------------
++++++ ghc-wai-middleware-prometheus.spec ++++++
--- /var/tmp/diff_new_pack.VynbGn/_old 2017-06-04 01:56:00.956522175 +0200
+++ /var/tmp/diff_new_pack.VynbGn/_new 2017-06-04 01:56:00.960521610 +0200
@@ -1,7 +1,7 @@
#
# spec file for package ghc-wai-middleware-prometheus
#
-# Copyright (c) 2016 SUSE LINUX GmbH, Nuernberg, Germany.
+# Copyright (c) 2017 SUSE LINUX GmbH, Nuernberg, Germany.
#
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
@@ -19,7 +19,7 @@
%global pkg_name wai-middleware-prometheus
%bcond_with tests
Name: ghc-%{pkg_name}
-Version: 0.1.0.1
+Version: 0.1.1
Release: 0
Summary: WAI middlware for exposing http://prometheus.io metrics
License: Apache-2.0
++++++ wai-middleware-prometheus-0.1.0.1.tar.gz ->
wai-middleware-prometheus-0.1.1.tar.gz ++++++
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore'
old/wai-middleware-prometheus-0.1.0.1/src/Network/Wai/Middleware/Prometheus.hs
new/wai-middleware-prometheus-0.1.1/src/Network/Wai/Middleware/Prometheus.hs
---
old/wai-middleware-prometheus-0.1.0.1/src/Network/Wai/Middleware/Prometheus.hs
2015-06-28 21:08:14.000000000 +0200
+++
new/wai-middleware-prometheus-0.1.1/src/Network/Wai/Middleware/Prometheus.hs
2017-04-30 00:58:18.000000000 +0200
@@ -8,11 +8,14 @@
, Default.def
, instrumentApp
, instrumentIO
+, metricsApp
) where
-import Data.Time.Clock (diffUTCTime, getCurrentTime)
+import Data.Time.Clock (UTCTime, diffUTCTime, getCurrentTime)
import qualified Data.ByteString.Builder as BS
+import qualified Data.ByteString.Char8 as BS
import qualified Data.Default as Default
+import Data.Maybe (fromMaybe)
import qualified Data.Text as T
import qualified Network.HTTP.Types as HTTP
import qualified Network.Wai as Wai
@@ -43,8 +46,10 @@
}
{-# NOINLINE requestLatency #-}
-requestLatency :: Prom.Metric (Prom.Vector Prom.Label1 Prom.Summary)
-requestLatency = Prom.unsafeRegisterIO $ Prom.vector "handler"
+-- XXX: https://prometheus.io/docs/practices/naming/ says this should be
+-- _seconds, not _microseconds.
+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."
@@ -57,8 +62,14 @@
instrumentApp :: String -- ^ The label used to identify this app
-> Wai.Application -- ^ The app to instrument
-> Wai.Application -- ^ The instrumented app
-instrumentApp handler app req respond =
- observeMicroSeconds handler (app req respond)
+instrumentApp handler app req respond = do
+ start <- getCurrentTime
+ app req $ \res -> do
+ end <- getCurrentTime
+ let method = Just $ BS.unpack (Wai.requestMethod req)
+ let status = Just $ show (HTTP.statusCode (Wai.responseStatus res))
+ observeMicroSeconds handler method status start end
+ respond res
-- | Instrument an IO action with timing metrics. This function can be used if
-- you would like to get more fine grained metrics, for instance this can be
@@ -70,31 +81,36 @@
instrumentIO :: String -- ^ The label used to identify this IO operation
-> IO a -- ^ The IO action to instrument
-> IO a -- ^ The instrumented app
-instrumentIO = observeMicroSeconds
-
-observeMicroSeconds :: String -> IO a -> IO a
-observeMicroSeconds handler io = do
+instrumentIO label io = do
start <- getCurrentTime
result <- io
end <- getCurrentTime
- let latency = fromRational $ toRational (end `diffUTCTime` start) * 1000000
- Prom.withLabel handler (Prom.observe latency) requestLatency
+ observeMicroSeconds label Nothing Nothing start end
return result
+observeMicroSeconds :: String -> Maybe String -> Maybe String -> UTCTime ->
UTCTime -> IO ()
+observeMicroSeconds handler method status start end = do
+ let latency = fromRational $ toRational (end `diffUTCTime` start) * 1000000
+ Prom.withLabel (handler, fromMaybe "" method, fromMaybe "" status)
+ (Prom.observe latency)
+ requestLatency
+
-- | Expose Prometheus metrics and instrument an application with some basic
-- metrics (e.g. request latency).
prometheus :: PrometheusSettings -> Wai.Middleware
prometheus PrometheusSettings{..} app req respond =
if Wai.requestMethod req == HTTP.methodGet
&& Wai.pathInfo req == prometheusEndPoint
- then measure measureMetrics "prometheus" $ respondWithMetrics respond
- else measure measureApp "app" $ app req respond
- where
- measureMetrics = prometheusInstrumentPrometheus
- measureApp = prometheusInstrumentApp
- measure shouldInstrument handler io
- | shouldInstrument = observeMicroSeconds handler io
- | otherwise = io
+ -- XXX: Should probably be "metrics" rather than "prometheus", since
+ -- "prometheus" can be confused with actual prometheus.
+ then instrumentApp "prometheus" (const respondWithMetrics) req respond
+ else instrumentApp "app" app req respond
+
+
+-- | WAI Application that serves the Prometheus metrics page regardless of
+-- what the request is.
+metricsApp :: Wai.Application
+metricsApp = const respondWithMetrics
respondWithMetrics :: (Wai.Response -> IO Wai.ResponseReceived)
-> IO Wai.ResponseReceived
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore'
old/wai-middleware-prometheus-0.1.0.1/wai-middleware-prometheus.cabal
new/wai-middleware-prometheus-0.1.1/wai-middleware-prometheus.cabal
--- old/wai-middleware-prometheus-0.1.0.1/wai-middleware-prometheus.cabal
2015-06-28 21:08:14.000000000 +0200
+++ new/wai-middleware-prometheus-0.1.1/wai-middleware-prometheus.cabal
2017-04-30 23:30:12.000000000 +0200
@@ -1,5 +1,5 @@
name: wai-middleware-prometheus
-version: 0.1.0.1
+version: 0.1.1
synopsis:
WAI middlware for exposing http://prometheus.io metrics.
description: