Skip to content

Commit 9b39069

Browse files
authored
Prometheus: Exclude ResponseRaw responses from metrics (#2108)
This PR makes the `servantPrometheusMiddleware` ignore all `ResponseRaw` responses. The implementation of wai and prometheus lead to `ResponseRaw` being tracked with `statusCode` `500` irrespective if the handler was successful or not (see documentation of `wai-middleware-prometheus`'s `ignoreRawResponses` or note `[Raw Response]` in the codebase). This would remove all metrics for these endpoints, however looking at `observeSeconds` of `wai-middleware-prometheus` suggests that the status is optional, so maybe reporting duration without status is possible. This PR is a followup to #2081 which lead to `cannon`'s `"await-notifications"` endpoint erroneously reporting 500s metrics. This will also affect future potential future endpoints in `spar` and `carghold` as they also use `servantPrometheusMiddleware`.
1 parent 8a57938 commit 9b39069

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Prometheus: Ignore RawResponses (e.g. cannon's await responses) from metrics

libs/metrics-wai/src/Data/Metrics/Servant.hs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,17 @@ import Servant.Multipart
4444

4545
-- | This does not catch errors, so it must be called outside of 'WU.catchErrors'.
4646
servantPrometheusMiddleware :: forall proxy api. (RoutesToPaths api) => proxy api -> Wai.Middleware
47-
servantPrometheusMiddleware _ = Promth.prometheus conf . Promth.instrumentHandlerValue promthNormalize
47+
servantPrometheusMiddleware _ = Promth.prometheus conf . instrument promthNormalize
4848
where
4949
promthNormalize :: Wai.Request -> Text
5050
promthNormalize req = pathInfo
5151
where
5252
mPathInfo = Metrics.treeLookup (routesToPaths @api) $ cs <$> Wai.pathInfo req
5353
pathInfo = cs $ fromMaybe "N/A" mPathInfo
5454

55+
-- See Note [Raw Response]
56+
instrument = Promth.instrumentHandlerValueWithFilter Promth.ignoreRawResponses
57+
5558
servantPlusWAIPrometheusMiddleware :: forall proxy api a m b. (RoutesToPaths api, Monad m) => Routes a m b -> proxy api -> Wai.Middleware
5659
servantPlusWAIPrometheusMiddleware routes _ = do
5760
Promth.prometheus conf . instrument (normalizeWaiRequestRoute paths)

0 commit comments

Comments
 (0)