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

Unable to prefix names of default metrics in v9 as prefix option from v8.0.0 is not a thing in v9 #60

Closed
bhovhannes opened this issue Aug 8, 2022 · 2 comments

Comments

@bhovhannes
Copy link

Hello,

I upgraded fastify-metrics from 8.0.0 to 9.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 in 8.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:

app.register(require("fastify-metrics"), {
    prefix: 'app_', // this no longer works. I failed to find an equivalent for this
    routeBlacklist: [
        `/internal/metrics`,
        `/internal/health/readiness`
    ]
})

Endpoint output:

# HELP nodejs_version_info Node.js version info.
# TYPE nodejs_version_info gauge
nodejs_version_info{version="v16.15.0",major="16",minor="15",patch="0"} 1

Before upgrade

Code:

app.register(require("fastify-metrics"), {
    prefix: 'app_',
    blacklist: [
        `/internal/metrics`,
        `/internal/health/readiness`
    ],
    enableDefaultMetrics: true,
    enableRouteMetrics: true
})

Endpoint output:

# HELP nodejs_version_info Node.js version info.
# TYPE nodejs_version_info gauge
app_nodejs_version_info{version="v16.15.0",major="16",minor="15",patch="0"} 1
@SkeLLLa
Copy link
Owner

SkeLLLa commented Aug 14, 2022

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.

@SkeLLLa SkeLLLa closed this as completed Aug 14, 2022
@bhovhannes
Copy link
Author

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`
            }
        },
    }
})
  • Essentially, all options under defaultMetrics key are being passed to prom-client, including prefix.
  • To add prefix to request histogram and summary, one should use overrides key and provide a prefixed name. v9 does not use prefix passed for default metrics for request histogram and summary.

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

No branches or pull requests

2 participants