Skip to content

Commit

Permalink
Merge main into next
Browse files Browse the repository at this point in the history
  • Loading branch information
simonecorsi authored Dec 18, 2023
2 parents 733c8f9 + 170beb3 commit 2f90657
Show file tree
Hide file tree
Showing 22 changed files with 396 additions and 357 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/automerge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
runs-on: ubuntu-latest
if: ${{ github.actor == 'dependabot[bot]' }}
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Dependabot metadata
id: metadata
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/backmerge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
persist-credentials: false

Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/bench.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
ref: ${{ github.base_ref }}
Expand All @@ -28,7 +28,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
- name: Setup Node
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
with:
# codfish/semantic-release-action@v2 needs 18+
node-version: 18
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
persist-credentials: false
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
name: Conventional Commit Checker
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
- uses: webiny/[email protected]
Expand All @@ -19,7 +19,7 @@ jobs:
node-version: [14.x, 16.x, 18.x]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
- uses: actions/setup-node@v3
Expand Down
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
# [6.0.0](https://github.com/immobiliare/fastify-metrics/compare/v5.1.1...v6.0.0) (2023-12-18)


### Bug Fixes

* fastify deprecation notice ([e53acd7](https://github.com/immobiliare/fastify-metrics/commit/e53acd71409edeeadcba89284858e34765c37636))


### BREAKING CHANGES

* we now use routeOptions to store metrics data.

## [5.1.1](https://github.com/immobiliare/fastify-metrics/compare/v5.1.0...v5.1.1) (2023-07-07)


Expand Down
56 changes: 40 additions & 16 deletions MIGRATION_GUIDE.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,48 @@


<!-- toc -->

- [Migrating from v4 to v5](#migrating-from-v4-to-v5)
- [`.context.config.metrics` access](#contextconfigmetrics-access)
- [V4](#v4)
- [V5](#v5)
- [Migrating from v1 to v2](#migrating-from-v1-to-v2)
- [`Dats` client options](#dats-client-options)
- [V1](#v1)
- [V2](#v2)
- [Metrics collections setup](#metrics-collections-setup)
- [V1](#v1-1)
- [V2](#v2-1)
- [`health` metric](#health-metric)
- [`routes` metrics](#routes-metrics)
- [Route id configuration](#route-id-configuration)
- [V1](#v1-2)
- [V2](#v2-2)
- [Migrating from v5 to v6](#migrating-from-v5-to-v6)
* [`.routeConfig.metrics` access](#routeconfigmetrics-access)
+ [V5](#v5)
+ [V6](#v6)
- [Migrating from v4 to v5](#migrating-from-v4-to-v5)
* [`.context.config.metrics` access](#contextconfigmetrics-access)
+ [V4](#v4)
+ [V5](#v5-1)
- [Migrating from v1 to v2](#migrating-from-v1-to-v2)
* [`Dats` client options](#dats-client-options)
+ [V1](#v1)
+ [V2](#v2)
* [Metrics collections setup](#metrics-collections-setup)
+ [V1](#v1-1)
+ [V2](#v2-1)
- [`health` metric](#health-metric)
- [`routes` metrics](#routes-metrics)
* [Route id configuration](#route-id-configuration)
+ [V1](#v1-2)
+ [V2](#v2-2)

<!-- tocstop -->

# Migrating from v5 to v6

## `<Request>.routeConfig.metrics` access

### V5

```js
const metrics = request.routeConfig.metrics;
const metrics = reply.request.routeConfig.metrics;
```

### V6

```js
const metrics = request.routeOptions.metrics;
const metrics = reply.request.routeOptions.metrics;
```

# Migrating from v4 to v5

## `<Request|Reply>.context.config.metrics` access
Expand Down
89 changes: 44 additions & 45 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,48 +20,47 @@ It automatically collects Node.js process metrics along with routes stats like h

<!-- toc -->

- [Fastify Version Support](#fastify-version-support)

* [Installation](#installation)
- [`npm`](#npm)
- [`yarn`](#yarn)
* [Migrating from version 1](#migrating-from-version-1)
* [Usage](#usage)
* [Route Configuration](#route-configuration)
- [Note](#note)
* [Metrics collected](#metrics-collected)
* [Decorators](#decorators)
- [Fastify decorators](#fastify-decorators)
- [`metrics`](#metrics)
- [`metrics.namespace`](#metricsnamespace)
- [`metrics.fastifyPrefix`](#metricsfastifyprefix)
- [`metrics.routesPrefix`](#metricsroutesprefix)
- [`metrics.client`](#metricsclient)
- [`metrics.sampler`](#metricssampler)
- [`metrics.hrtime2us`](#metricshrtime2us)
- [`metrics.hrtime2ns`](#metricshrtime2ns)
- [`metrics.hrtime2ms`](#metricshrtime2ms)
- [`metrics.hrtime2s`](#metricshrtime2s)
- [Request and Reply decorators](#request-and-reply-decorators)
- [`getMetricLabel()`](#getmetriclabel)
- [`sendTimingMetric(name[, value])`](#sendtimingmetricname-value)
- [`sendCounterMetric(name[, value])`](#sendcountermetricname-value)
- [`sendGaugeMetric(name, value)`](#sendgaugemetricname-value)
- [`sendSetMetric(name, value)`](#sendsetmetricname-value)
* [Hooks](#hooks)
* [Request and Reply routeConfig](#request-and-reply-routeconfig)
* [API](#api)
- [Configuration `options`](#configuration-options)
- [Routes labels generation modes](#routes-labels-generation-modes)
- [computedPrefix](#computedprefix)
* [`static` mode](#static-mode)
- [`getLabel(options)`](#getlabeloptions)
* [`dynamic` mode](#dynamic-mode)
- [`getLabel(request, reply)`](#getlabelrequest-reply)
- [Example](#example)
* [Powered Apps](#powered-apps)
* [Support & Contribute](#support--contribute)
* [License](#license)
* [Fastify Version Support](#fastify-version-support)
- [Installation](#installation)
* [`npm`](#npm)
* [`yarn`](#yarn)
- [Migrating from version 1](#migrating-from-version-1)
- [Usage](#usage)
- [Route Configuration](#route-configuration)
* [Note](#note)
- [Metrics collected](#metrics-collected)
- [Decorators](#decorators)
* [Fastify decorators](#fastify-decorators)
+ [`metrics`](#metrics)
- [`metrics.namespace`](#metricsnamespace)
- [`metrics.fastifyPrefix`](#metricsfastifyprefix)
- [`metrics.routesPrefix`](#metricsroutesprefix)
- [`metrics.client`](#metricsclient)
- [`metrics.sampler`](#metricssampler)
- [`metrics.hrtime2us`](#metricshrtime2us)
- [`metrics.hrtime2ns`](#metricshrtime2ns)
- [`metrics.hrtime2ms`](#metricshrtime2ms)
- [`metrics.hrtime2s`](#metricshrtime2s)
* [Request and Reply decorators](#request-and-reply-decorators)
+ [`getMetricLabel()`](#getmetriclabel)
+ [`sendTimingMetric(name[, value])`](#sendtimingmetricname-value)
+ [`sendCounterMetric(name[, value])`](#sendcountermetricname-value)
+ [`sendGaugeMetric(name, value)`](#sendgaugemetricname-value)
+ [`sendSetMetric(name, value)`](#sendsetmetricname-value)
- [Hooks](#hooks)
- [Request and Reply routeConfig](#request-and-reply-routeconfig)
- [API](#api)
* [Configuration `options`](#configuration-options)
* [Routes labels generation modes](#routes-labels-generation-modes)
- [computedPrefix](#computedprefix)
+ [`static` mode](#static-mode)
- [`getLabel(options)`](#getlabeloptions)
+ [`dynamic` mode](#dynamic-mode)
- [`getLabel(request, reply)`](#getlabelrequest-reply)
- [Example](#example)
- [Powered Apps](#powered-apps)
- [Support & Contribute](#support--contribute)
- [License](#license)

<!-- tocstop -->

Expand Down Expand Up @@ -138,7 +137,7 @@ There are more usage examples in the [`examples`](./examples) folder.

### Note

The plugin internally uses the `routeId` key in the `metrics` object of the `Request.routeConfig` or `Reply.request.routeConfig` object to build the label of the metric of a route.
The plugin internally uses the `routeId` key in the `metrics` object of the `Request.routeOptions` or `Reply.request.routeOptions` object to build the label of the metric of a route.

See

Expand Down Expand Up @@ -275,7 +274,7 @@ The plugin uses the following hooks:

## Request and Reply routeConfig

The plugin adds a `metrics` object to the `Request.routeConfig` and `Reply.request.routeConfig` for convenience with the following properties:
The plugin adds a `metrics` object to the `Request.routeOptions` and `Reply.request.routeOptions` for convenience with the following properties:

- `routeId` <`string`> The id for the current route
- `fastifyPrefix` <`string`> The prefix of the fastify instance registering the route, with the `/` replaced with `.` and without the `.` at the beginning.
Expand Down Expand Up @@ -379,7 +378,7 @@ await fastify.register(require('@immobiliarelabs/fastify-metrics'), {
mode: 'dynamic',
getLabel: function (request, reply) {
const auth = request.user ? 'user' : 'anonim';
const { metrics } = request.routeConfig.config;
const { metrics } = request.routeOptions.config;
const routesPrefix = metrics.routesPrefix
? `${metrics.routesPrefix}.`
: '';
Expand Down
53 changes: 26 additions & 27 deletions examples/default_tcp.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,38 +30,37 @@ app.register(plugin, {
host: `tcp://127.0.0.1:${tcpPort}`,
namespace: 'tcp',
},
});

app.get(
'/with-metrics',
{
config: {
metrics: {
routeId: 'getMetrics',
}).then(() => {
app.get(
'/with-metrics',
{
config: {
metrics: {
routeId: 'getMetrics',
},
},
},
},
async function () {
return { metrics: true };
}
);
async function () {
return { metrics: true };
}
);

app.post(
'/with-metrics',
{
config: {
metrics: {
routeId: 'postMetrics',
app.post(
'/with-metrics',
{
config: {
metrics: {
routeId: 'postMetrics',
},
},
},
},
async function () {
return { metrics: true };
}
);
async function () {
return { metrics: true };
}
);

app.get('/no-metrics', async function () {
return { metrics: false };
app.get('/no-metrics', async function () {
return { metrics: false };
});
});

start(app, mock, fastifyPort, tcpPort);
52 changes: 26 additions & 26 deletions examples/default_udp.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,38 +30,38 @@ app.register(plugin, {
host: `udp://127.0.0.1:${udpPort}`,
namespace: 'default_upd_test',
},
});

app.get(
'/with-metrics',
{
config: {
metrics: {
routeId: 'getMetrics',
}).then(() => {
app.get(
'/with-metrics',
{
config: {
metrics: {
routeId: 'getMetrics',
},
},
},
},
async function () {
return { metrics: true };
}
);
async function () {
return { metrics: true };
}
);

app.post(
'/with-metrics',
{
config: {
metrics: {
routeId: 'postMetrics',
app.post(
'/with-metrics',
{
config: {
metrics: {
routeId: 'postMetrics',
},
},
},
},
async function () {
return { metrics: true };
}
);
async function () {
return { metrics: true };
}
);

app.get('/no-metrics', async function () {
return { metrics: false };
app.get('/no-metrics', async function () {
return { metrics: false };
});
});

start(app, mock, fastifyPort, udpPort);
Loading

0 comments on commit 2f90657

Please sign in to comment.