Skip to content

Commit

Permalink
fix: exclude healthcheck from response-time metric
Browse files Browse the repository at this point in the history
  • Loading branch information
antongolub committed Nov 23, 2022
1 parent 5e0e64e commit d40303d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
5 changes: 3 additions & 2 deletions src/main/js/firewall/middleware.js
Expand Up @@ -32,10 +32,10 @@ const warmupDepPackuments = (name, deps, boundContext, rules) => {
try {
warmupPipeline(pipeline, {name, registry, org})

const {deps: _deps} = await getPackument({ boundContext: {cache, registry, authorization, entrypoint, name, org, pipeline}, rules })
const {deps: _deps} = await getPackument({ boundContext: {registry, authorization, entrypoint, name, org, pipeline}, rules })
warmupDepPackuments(name, _deps, boundContext, rules)
} catch (e) {
logger.warn('warmup error', e)
logger.warn('warmup error', e.message, e.stack)
}
})
}
Expand All @@ -48,6 +48,7 @@ const getAuth = (token, auth) => token

export const firewall = ({registry, rules, entrypoint: _entrypoint, token}) => async (req, res, next) => {
const {routeParams: {name, version, org}, base, method} = req
req.timed = true

if (method !== 'GET' && method !== 'HEAD') {
return next(httpError(METHOD_NOT_ALLOWED))
Expand Down
4 changes: 3 additions & 1 deletion src/main/js/mwares/trace.js
Expand Up @@ -23,7 +23,9 @@ export const trace = async (req, res, next) => {
const isErr = statusCode < 200 || (statusCode >= 400 && statusCode !== 404)
const delay = Date.now() - startedAt

pushMetric('response-time', delay)
if (req.timed) {
pushMetric('response-time', delay)
}
logger[isErr ? 'error' : 'info']('HTTP', statusCode, `${delay}ms`, req.method, req.url)

return end.call(this, ...args)
Expand Down

0 comments on commit d40303d

Please sign in to comment.