Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add metrics middleware to spar. #498

Merged
merged 3 commits into from
Oct 24, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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