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

Koa middleware doesn't return stats on /metrics if your aplication has a default handler #47

Open
maherma-adg opened this issue Jul 15, 2020 · 1 comment
Labels
bug Something isn't working

Comments

@maherma-adg
Copy link

My application has a default handler to catch any request not fullfilled by previous middlewares (koa-static, koa-routes) in order log those requests and return a custom 404 page.

After install prometheus-api-metrics, I was surprised when request on /metrics and /metrics.json url are logged by the default handler.

Looking into middleware function I think there is a error because after fulfill the /metrics and /metrics.json queries, the function call next() to drill down on middleware chain. IMHO request must be finished in this point, don't propagate the request and return the stats.

As workaround, you can define these paths in your router and do nothing. This allow the response generated by the middleware to be returned and not be overwritten by default handler.

router.get('/metrics', async (ctx) => {})
router.get('/metrics.json', async (ctx) => {})

Regards,
Manuel

@kobik
Copy link
Collaborator

kobik commented Oct 18, 2020

@maherma-adg , thanks for reporting this.

I agree that for /metrics endpoint, next should not be called in when using Koa

@kobik kobik added the bug Something isn't working label Oct 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Development

No branches or pull requests

2 participants