Skip to content

Commit

Permalink
Add metrics middleware to spar. (#498)
Browse files Browse the repository at this point in the history
  • Loading branch information
fisx committed Oct 24, 2018
1 parent 3d0645c commit 8881b52
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
1 change: 1 addition & 0 deletions services/spar/package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ dependencies:
- uri-bytestring
- uuid
- wai
- wai-middleware-prometheus
- wai-utilities
- warp
- x509
Expand Down
5 changes: 2 additions & 3 deletions services/spar/src/Spar/Run.hs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import Util.Options (casEndpoint, casKeyspace, epHost, epPort)
import qualified Cassandra.Schema as Cas
import qualified Cassandra.Settings as Cas
import qualified Network.Wai.Handler.Warp as Warp
import qualified Network.Wai.Middleware.Prometheus as Promth
import qualified Network.Wai.Utilities.Server as WU
import qualified SAML2.WebSSO as SAML
import qualified Spar.Data as Data
Expand Down Expand Up @@ -98,10 +99,8 @@ runServer sparCtxOpts = do
. Bilge.port (sparCtxOpts ^. to brig . epPort)
$ Bilge.empty
let wrappedApp
-- . WU.measureRequests mx _
-- TODO: we need the swagger sitemap from servant for this. we also want this to be
-- prometheus-compatible. not sure about the order in which to do these.
= WU.catchErrors sparCtxLogger mx
. Promth.prometheus Promth.def { Promth.prometheusEndPoint = ["i", "monitoring"] }
. SAML.setHttpCachePolicy
. lookupRequestIdMiddleware
$ \sparCtxRequestId -> app Env {..}
Expand Down
13 changes: 13 additions & 0 deletions services/spar/test-integration/Test/Spar/APISpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,19 @@ specMisc = do
ping (env ^. teSpar) `shouldRespondWith` (== ())


describe "metrics" $ do
it "spar /i/monitoring" $ do
env <- ask
get ((env ^. teSpar) . path "/i/monitoring")
`shouldRespondWith` (\(responseBody -> Just (cs -> bdy)) -> all (`isInfixOf` bdy)
[ "http_request_duration_seconds_bucket"
, "handler="
, "method="
, "status_code="
, "le="
])


specMetadata :: SpecWith TestEnv
specMetadata = do
describe "metadata" $ do
Expand Down

0 comments on commit 8881b52

Please sign in to comment.