PayU/prometheus-api-metrics

Confused about usage with Koa

Opened this issue · 1 comments

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.

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.