From 1f0d7fc536171117306702583adab9968864647b Mon Sep 17 00:00:00 2001 From: Patrick Date: Fri, 8 Mar 2024 19:31:48 +0100 Subject: [PATCH 1/2] refactor!: upgrade to prom-client 15.1.0 BREAKING CHANGE: drop support for node 16 --- .github/workflows/release.yml | 2 +- .github/workflows/verify.yml | 2 +- README.md | 2 +- .../api/fastify-metrics.idefaultmetricsconfig.md | 4 ++-- etc/fastify-metrics.api.md | 2 +- package.json | 2 +- pnpm-lock.yaml | 16 +++++++++++----- src/__tests__/edge-cases.spec.ts | 2 +- src/fastify-metrics.ts | 7 +++++-- src/types.ts | 2 +- 10 files changed, 25 insertions(+), 16 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 8d11c5e..aeb000b 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -12,7 +12,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - node-version: [16.x, 18.x, 20.x] + node-version: [18.x, 20.x] steps: - uses: actions/checkout@v2 - name: Use Node.js ${{ matrix.node-version }} diff --git a/.github/workflows/verify.yml b/.github/workflows/verify.yml index 396c8dc..0779a8f 100644 --- a/.github/workflows/verify.yml +++ b/.github/workflows/verify.yml @@ -10,7 +10,7 @@ jobs: strategy: matrix: - node-version: [16.x, 18.x, 20.x] + node-version: [18.x, 20.x] steps: - uses: actions/checkout@v2 diff --git a/README.md b/README.md index a4a5874..a2ac0cf 100644 --- a/README.md +++ b/README.md @@ -97,7 +97,7 @@ pnpm i fastify-metrics --save --- - Requires fastify `>=4.0.0`. -- Node.js `>=16.0.0`. +- Node.js `>=18.0.0`. [Back to top](#toc) diff --git a/docs/api/fastify-metrics.idefaultmetricsconfig.md b/docs/api/fastify-metrics.idefaultmetricsconfig.md index 3250450..e84d09c 100644 --- a/docs/api/fastify-metrics.idefaultmetricsconfig.md +++ b/docs/api/fastify-metrics.idefaultmetricsconfig.md @@ -9,10 +9,10 @@ Default prom-client metrics config Signature: ```typescript -export interface IDefaultMetricsConfig extends DefaultMetricsCollectorConfiguration +export interface IDefaultMetricsConfig extends DefaultMetricsCollectorConfiguration<'text/plain; version=0.0.4; charset=utf-8'> ``` -Extends: DefaultMetricsCollectorConfiguration +Extends: DefaultMetricsCollectorConfiguration<'text/plain; version=0.0.4; charset=utf-8'> ## Remarks diff --git a/etc/fastify-metrics.api.md b/etc/fastify-metrics.api.md index 947c6d2..8e6f48e 100644 --- a/etc/fastify-metrics.api.md +++ b/etc/fastify-metrics.api.md @@ -27,7 +27,7 @@ export default _default; // @public export interface IDefaultMetricsConfig - extends DefaultMetricsCollectorConfiguration { + extends DefaultMetricsCollectorConfiguration<'text/plain; version=0.0.4; charset=utf-8'> { enabled: boolean; } diff --git a/package.json b/package.json index ec19e57..f698873 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,7 @@ }, "dependencies": { "fastify-plugin": "^4.3.0", - "prom-client": "^14.2.0" + "prom-client": "^15.1.0" }, "devDependencies": { "@commitlint/cli": "^17.1.2", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 4f6abe6..63cf24b 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -9,8 +9,8 @@ dependencies: specifier: ^4.3.0 version: 4.3.0 prom-client: - specifier: ^14.2.0 - version: 14.2.0 + specifier: ^15.1.0 + version: 15.1.0 devDependencies: '@commitlint/cli': @@ -1242,6 +1242,11 @@ packages: '@octokit/openapi-types': 16.0.0 dev: true + /@opentelemetry/api@1.8.0: + resolution: {integrity: sha512-I/s6F7yKUDdtMsoBWXJe8Qz40Tui5vsuKCWJEWVL+5q9sSWRzzx6v2KeNsOBEwd94j0eWkpWCH4yB6rZg9Mf0w==} + engines: {node: '>=8.0.0'} + dev: false + /@pnpm/config.env-replace@1.1.0: resolution: {integrity: sha512-htyl8TWnKL7K/ESFa1oW2UB5lVDxuF5DpM7tBi6Hu2LNL3mWkIzNLG6N4zoCUP1lCKNxWy/3iu8mS8MvToGd6w==} engines: {node: '>=12.22.0'} @@ -5606,10 +5611,11 @@ packages: engines: {node: '>= 0.6.0'} dev: true - /prom-client@14.2.0: - resolution: {integrity: sha512-sF308EhTenb/pDRPakm+WgiN+VdM/T1RaHj1x+MvAuT8UiQP8JmOEbxVqtkbfR4LrvOg5n7ic01kRBDGXjYikA==} - engines: {node: '>=10'} + /prom-client@15.1.0: + resolution: {integrity: sha512-cCD7jLTqyPdjEPBo/Xk4Iu8jxjuZgZJ3e/oET3L+ZwOuap/7Cw3dH/TJSsZKs1TQLZ2IHpIlRAKw82ef06kmMw==} + engines: {node: ^16 || ^18 || >=20} dependencies: + '@opentelemetry/api': 1.8.0 tdigest: 0.1.2 dev: false diff --git a/src/__tests__/edge-cases.spec.ts b/src/__tests__/edge-cases.spec.ts index 9acb95b..19b28b4 100644 --- a/src/__tests__/edge-cases.spec.ts +++ b/src/__tests__/edge-cases.spec.ts @@ -144,7 +144,7 @@ describe('edge cases', () => { expect.stringMatching( /process_cpu_user_seconds_total\{foo="bar"\} \d+/ ), - 'http_request_duration_seconds_count{method="GET",route="/test",status_code="200",foo="bar"} 1', + 'http_request_duration_seconds_count{foo="bar",method="GET",route="/test",status_code="200"} 1', 'http_request_summary_seconds_count{method="GET",route="/test",status_code="200",foo="bar"} 1', ]) ); diff --git a/src/fastify-metrics.ts b/src/fastify-metrics.ts index 37d8dbc..f5a2a6d 100644 --- a/src/fastify-metrics.ts +++ b/src/fastify-metrics.ts @@ -7,6 +7,7 @@ import { import promClient, { Histogram, LabelValues, + PrometheusContentType, Registry, Summary, } from 'prom-client'; @@ -191,8 +192,10 @@ export class FastifyMetrics implements IFastifyMetrics { return []; } return [ - ...(routeMetrics.overrides?.histogram?.registers ?? []), - ...(routeMetrics.overrides?.summary?.registers ?? []), + ...((routeMetrics.overrides?.histogram?.registers ?? + []) as Registry[]), + ...((routeMetrics.overrides?.summary?.registers ?? + []) as Registry[]), ]; } diff --git a/src/types.ts b/src/types.ts index e379818..0931bd9 100644 --- a/src/types.ts +++ b/src/types.ts @@ -33,7 +33,7 @@ export interface IMetricsRouteContextConfig { * @see {@link https://github.com/siimon/prom-client#default-metrics | prom-client} for extra options */ export interface IDefaultMetricsConfig - extends DefaultMetricsCollectorConfiguration { + extends DefaultMetricsCollectorConfiguration<'text/plain; version=0.0.4; charset=utf-8'> { /** * Enables collection of default prom-client metrics (e.g. node.js vitals like * cpu, memory, etc.) From 5ab6090cb71ae955625534f3e0b80dc86b1d6957 Mon Sep 17 00:00:00 2001 From: Patrick Date: Fri, 8 Mar 2024 19:32:06 +0100 Subject: [PATCH 2/2] chore: update missing doc generation --- README.md | 3 +-- etc/fastify-metrics.api.md | 1 + 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index a2ac0cf..f2b9e96 100644 --- a/README.md +++ b/README.md @@ -133,8 +133,7 @@ See for details [docs](docs/api/fastify-metrics.imetricspluginoptions.md) | [endpoint?](./docs/api/fastify-metrics.imetricspluginoptions.endpoint.md) | string \| null \| [`Fastify.RouteOptions`](https://www.fastify.io/docs/api/latest/Reference/Routes/#routes-options) | `'/metrics'` | | [name?](./docs/api/fastify-metrics.imetricspluginoptions.name.md) | string | `'metrics'` | | [routeMetrics?](./docs/api/fastify-metrics.imetricspluginoptions.routemetrics.md) | [IRouteMetricsConfig](./docs/api/fastify-metrics.iroutemetricsconfig.md) | `{ enabled: true }` | -| [promClient?](./docs/api/fastify-metrics.imetricspluginoptions.promclient.md) | `prom-client` instance \| null | `null` | - +| [promClient?](./docs/api/fastify-metrics.imetricspluginoptions.promclient.md) | `prom-client` instance \| null | `null` | #### Route metrics diff --git a/etc/fastify-metrics.api.md b/etc/fastify-metrics.api.md index 8e6f48e..03cca86 100644 --- a/etc/fastify-metrics.api.md +++ b/etc/fastify-metrics.api.md @@ -51,6 +51,7 @@ export interface IMetricsPluginOptions { defaultMetrics: IDefaultMetricsConfig; endpoint: string | null | RouteOptions; name: string; + promClient: typeof client | null; routeMetrics: IRouteMetricsConfig; }