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

Confused about usage with Koa #66

Open
robross0606 opened this issue Feb 26, 2021 · 1 comment
Open

Confused about usage with Koa #66

robross0606 opened this issue Feb 26, 2021 · 1 comment

Comments

@robross0606
Copy link

I've been trying to get this going with Koa, but I'm unsure how to proceed based on the README. Doing just this as per the README doesn't seem to expose the /metrics endpoint and results in a 404 error:

  const { koaMiddleware } = require('prometheus-api-metrics')
  app.use(koaMiddleware())

Doing this:

  const { koaMiddleware } = require('prometheus-api-metrics')
  const bodyParser = require('koa-bodyparser')
  app.use(bodyParser())
  app.use(koaMiddleware())

Also results in a 404 error.

A more fully fleshed out example would be much appreciated.

@robross0606
Copy link
Author

I figured it out. Unlike other middleware which intercepts and exposes /metrics regardless of what we have in our router filters, this one appears to prevent us from doing something like:

  ///Return 404s for all other paths
  apiRouter.get('/(.*)', async ctx => {
    ctx.body = '404: Not found'
    ctx.response.status = 404
  })

We would have to specifically accommodate /metrics in our router config. I'm unclear why this doesn't work when something like @echo-health/koa-prometheus-exporter exposes the endpoint regardless of what we have in the rest of our router config.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant