Skip to content

Commit

Permalink
feat: rename routes.timing in responseTime
Browse files Browse the repository at this point in the history
Rename timing to responseTime to be consistent with the other routes metrics.

BREAKING CHANGE: timing is renamed to responseTime.
  • Loading branch information
dnlup committed Mar 9, 2022
1 parent 74444b9 commit 44fe70a
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 32 deletions.
6 changes: 3 additions & 3 deletions MIGRATION_GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ fastify.register(require('@immobiliarelabs/fastify-metrics'), {
sampleInterval: 1000,
collect: {
hits: true,
timings: true,
timing: true,
errors: true,
health: true,
},
Expand Down Expand Up @@ -76,14 +76,14 @@ fastify.register(require('@immobiliarelabs/fastify-metrics'), {
});
```

#### `routes` metric
#### `routes` metrics

```js
const fastify = require('fastify')();

fastify.register(require('@immobiliarelabs/fastify-metrics'), {
routes: {
timings: true,
responseTime: true,
hits: true,
errors: true,
},
Expand Down
2 changes: 1 addition & 1 deletion index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ type GetStaticRouteLabel = (

type CommonRouteOptions = {
prefix?: string;
timing?: boolean;
hits?: boolean;
requestSize?: boolean;
responseTime?: boolean;
responseSize?: boolean;
errors?: boolean;
};
Expand Down
25 changes: 12 additions & 13 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,22 +58,21 @@ const DEFAULT_CONFIG_OPTIONS = {
mode: 'static',
prefix: '',
/**
* Response time
* TODO: rename in responseTime
*/
timing: true,
/**
* Route response size
* Route hit counter
*/
responseSize: false,
hits: true,
/**
* Route request size
*/
requestSize: false,
/**
* Route hit counter
* Response time
*/
hits: true,
responseTime: true,
/**
* Route response size
*/
responseSize: false,
/**
* Route errors counter
*/
Expand Down Expand Up @@ -101,10 +100,10 @@ module.exports = fp(
};

for (const key of [
'timing',
'responseSize',
'requestSize',
'hits',
'requestSize',
'responseTime',
'responseSize',
'errors',
]) {
if (typeof config.routes[key] !== 'boolean') {
Expand Down Expand Up @@ -229,7 +228,7 @@ module.exports = fp(
if (config.routes.hits) {
fastify.addHook('onRequest', hooks.onRequest);
}
if (config.routes.timing) {
if (config.routes.responseTime) {
fastify.addHook('onResponse', hooks.onResponse);
}
if (config.routes.errors) {
Expand Down
4 changes: 2 additions & 2 deletions tests/configuration.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,10 @@ tap.test('invalid options', async (t) => {
{
value: {
routes: {
timing: 'true',
responseTime: 'true',
},
},
message: '"timing" must be a boolean.',
message: '"responseTime" must be a boolean.',
},
{
value: {
Expand Down
26 changes: 13 additions & 13 deletions tests/metrics-collection.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,15 +137,15 @@ tap.test('disabling process health metrics', async (t) => {
]);
});

tap.test('disabling routes timings metric', async (t) => {
tap.test('disabling routes responseTime metric', async (t) => {
const server = await setupRoutes(
{
client: {
host: `udp://127.0.0.1:${t.context.address.port}`,
namespace: 'disable_routes_timings_test',
namespace: 'disable_routes_responseTime_test',
},
routes: {
timing: false,
responseTime: false,
},
},
routes,
Expand All @@ -162,17 +162,17 @@ tap.test('disabling routes timings metric', async (t) => {
}),
new Promise((resolve) => {
const regexes = [
/disable_routes_timings_test\.noId\.requests:1\|c/,
/disable_routes_timings_test\.process\.mem\.external:\d+(\.\d+)?\|g/,
/disable_routes_timings_test\.process\.mem\.rss:\d+(\.\d+)?\|g/,
/disable_routes_timings_test\.process\.mem\.heapUsed:\d+(\.\d+)?\|g/,
/disable_routes_timings_test\.process\.mem\.heapTotal:\d+(\.\d+)?\|g/,
/disable_routes_timings_test\.process\.eventLoopDelay:\d+(\.\d+)?\|g/,
/disable_routes_timings_test\.process\.eventLoopUtilization:\d+(\.\d+)?\|g/,
/disable_routes_timings_test\.process\.cpu:\d+(\.\d+)?\|g/,
/disable_routes_responseTime_test\.noId\.requests:1\|c/,
/disable_routes_responseTime_test\.process\.mem\.external:\d+(\.\d+)?\|g/,
/disable_routes_responseTime_test\.process\.mem\.rss:\d+(\.\d+)?\|g/,
/disable_routes_responseTime_test\.process\.mem\.heapUsed:\d+(\.\d+)?\|g/,
/disable_routes_responseTime_test\.process\.mem\.heapTotal:\d+(\.\d+)?\|g/,
/disable_routes_responseTime_test\.process\.eventLoopDelay:\d+(\.\d+)?\|g/,
/disable_routes_responseTime_test\.process\.eventLoopUtilization:\d+(\.\d+)?\|g/,
/disable_routes_responseTime_test\.process\.cpu:\d+(\.\d+)?\|g/,
];
const notExpected =
/disable_routes_timings_test\.noId:\d+(\.\d+)?\|ms/;
/disable_routes_responseTime_test\.noId:\d+(\.\d+)?\|ms/;
let cursor = 0;
t.context.statsd.on('metric', (buffer) => {
const metric = buffer.toString();
Expand Down Expand Up @@ -348,7 +348,7 @@ tap.test('disabling all default metrics', async (t) => {
namespace: 'disabling_all_metrics_test',
},
routes: {
timing: false,
responseTime: false,
hits: false,
errors: false,
},
Expand Down

0 comments on commit 44fe70a

Please sign in to comment.