Closed bhovhannes closed 2 years ago
Configuration object in v9 changed and there's no compatibility between v8 and v9. See https://github.com/SkeLLLa/fastify-metrics/blob/master/docs/fastify-metrics.idefaultmetricsconfig.md, it extends DefaultMetricsCollectorConfiguration
from prom-client where prefix is configured.
After looking into sources of both fastify-metrics
and prom-client
I figured out how to configure what I want. Posting it here in case someone will face the same problems as me during upgrade.
So, if with v8 we wrote:
app.register(require(fastify-metrics), {
prefix: 'app_',
blacklist: [
`/internal/metrics`,
`/internal/health/readiness`
],
enableDefaultMetrics: true,
enableRouteMetrics: true
})
in v9 this should be written as:
app.register(require("fastify-metrics"), {
defaultMetrics: {
enabled: true, // this is the default value and can be omitted
prefix: 'app_'
},
routeMetrics: {
enabled: true, // this is the default value and can be omitted
routeBlacklist: [
`/internal/metrics`,
`/internal/health/readiness`
],
overrides: {
histogram: {
name: `app_http_request_duration_seconds`
},
summary: {
name: `app_http_request_summary_seconds`
}
},
}
})
defaultMetrics
key are being passed to prom-client
, including prefix
.overrides
key and provide a prefixed name. v9 does not use prefix passed for default metrics for request histogram and summary.
Hello,
I upgraded
fastify-metrics
from8.0.0
to9.2.1
. Changed plugin registration code to use new configuration options. Metrics are being collected and exposed under the route I want. However, I didn't found any way to add custom prefix to default metric names.prefix
option available in8.0.0
no longer works.I am wondering if this is an expected behavior? And if so, what is the rationale behind this breaking change or maybe there are some workarounds?
With custom metrics everything is fine. I've included code and endpoint output in sections below.
After upgrade
Code:
Endpoint output:
Before upgrade
Code:
Endpoint output: