Skip to content
This repository has been archived by the owner on May 3, 2024. It is now read-only.

Commit

Permalink
feat(metrics): switch to fastify-metrics (#1034)
Browse files Browse the repository at this point in the history
* feat(metrics): switch to fastify-metrics

* test(integration): update metric snapshot
  • Loading branch information
JAdshead authored Jun 26, 2023
1 parent ad92ba2 commit b531606
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 163 deletions.
3 changes: 2 additions & 1 deletion __tests__/integration/__snapshots__/one-app.spec.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ exports[`Tests that require Docker setup one-app successfully started metrics ha
[
"circuit",
"circuit_perf",
"http_request_duration_seconds",
"http_request_summary_seconds",
"nodejs_active_handles",
"nodejs_active_handles_total",
"nodejs_active_requests",
Expand Down Expand Up @@ -74,7 +76,6 @@ exports[`Tests that require Docker setup one-app successfully started metrics ha
"oneapp_holocron_module_map_poll_wait_seconds",
"oneapp_holocron_module_map_updated_total",
"oneapp_intl_cache_size_total",
"oneapp_route_response_time_seconds",
"oneapp_ssr_react_rendering_seconds",
"oneapp_version_info",
"process_cpu_seconds_total",
Expand Down
61 changes: 0 additions & 61 deletions __tests__/server/plugins/addRequestMetrics.spec.js

This file was deleted.

60 changes: 32 additions & 28 deletions __tests__/server/ssrServer.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import fastifyFormbody from '@fastify/formbody';
import fastifyStatic from '@fastify/static';
import fastifyHelmet from '@fastify/helmet';
import fastifySensible from '@fastify/sensible';
import fastifyMetrics from 'fastify-metrics';

import ensureCorrelationId from '../../src/server/plugins/ensureCorrelationId';
import setAppVersionHeader from '../../src/server/plugins/setAppVersionHeader';
Expand Down Expand Up @@ -49,6 +50,8 @@ jest.mock('@fastify/formbody');
jest.mock('@fastify/static');
jest.mock('@fastify/helmet');
jest.mock('@fastify/sensible');
jest.mock('fastify-metrics');

jest.mock('../../src/server/plugins/ensureCorrelationId');
jest.mock('../../src/server/plugins/setAppVersionHeader');
jest.mock('../../src/server/plugins/addSecurityHeaders');
Expand Down Expand Up @@ -115,35 +118,36 @@ describe('ssrServer', () => {
bodyLimit: 10485760,
});

expect(register).toHaveBeenCalledTimes(12);
expect(register).toHaveBeenCalledTimes(13);
expect(register.mock.calls[0][0]).toEqual(fastifySensible);
expect(register.mock.calls[1][0]).toEqual(ensureCorrelationId);
expect(register.mock.calls[2][0]).toEqual(fastifyCookie);
expect(register.mock.calls[3][0]).toEqual(logging);
expect(register.mock.calls[4]).toEqual([compress, {
expect(register.mock.calls[4][0]).toEqual(fastifyMetrics);
expect(register.mock.calls[5]).toEqual([compress, {
zlibOptions: {
level: 1,
},
encodings: [
'gzip',
],
}]);
expect(register.mock.calls[5][0]).toEqual(fastifyFormbody);
expect(register.mock.calls[6]).toEqual([addSecurityHeadersPlugin, {
expect(register.mock.calls[6][0]).toEqual(fastifyFormbody);
expect(register.mock.calls[7]).toEqual([addSecurityHeadersPlugin, {
matchGetRoutes: [
'/_/status',
'/_/pwa/service-worker.js',
'/_/pwa/manifest.webmanifest',
],
}]);
expect(register.mock.calls[7][0]).toEqual(setAppVersionHeader);
expect(register.mock.calls[8][0]).toEqual(forwardedHeaderParser);
expect(register.mock.calls[9][0]).toEqual(expect.any(Function)); // abstraction
expect(register.mock.calls[8][0]).toEqual(setAppVersionHeader);
expect(register.mock.calls[9][0]).toEqual(forwardedHeaderParser);
expect(register.mock.calls[10][0]).toEqual(expect.any(Function)); // abstraction
expect(register.mock.calls[11][0]).toEqual(expect.any(Function)); // abstraction
expect(register.mock.calls[12][0]).toEqual(expect.any(Function)); // abstraction

const staticRegister = jest.fn();
register.mock.calls[9][0]({
register.mock.calls[10][0]({
register: staticRegister,
get: jest.fn(),
}, null, jest.fn());
Expand All @@ -158,7 +162,7 @@ describe('ssrServer', () => {
]);

const pwaRegister = jest.fn();
register.mock.calls[10][0]({
register.mock.calls[11][0]({
register: pwaRegister,
get: jest.fn(),
post: jest.fn(),
Expand All @@ -168,7 +172,7 @@ describe('ssrServer', () => {
expect(pwaRegister.mock.calls[1][0]).toEqual(csp);

const renderRegister = jest.fn();
register.mock.calls[11][0]({
register.mock.calls[12][0]({
register: renderRegister,
get: jest.fn(),
post: jest.fn(),
Expand Down Expand Up @@ -222,7 +226,7 @@ describe('ssrServer', () => {

const get = jest.fn();

register.mock.calls[9][0]({
register.mock.calls[10][0]({
register: jest.fn(),
get,
}, null, jest.fn());
Expand All @@ -244,7 +248,7 @@ describe('ssrServer', () => {

const get = jest.fn();

register.mock.calls[9][0]({
register.mock.calls[10][0]({
register: jest.fn(),
get,
}, null, jest.fn());
Expand All @@ -265,7 +269,7 @@ describe('ssrServer', () => {

const get = jest.fn();

register.mock.calls[10][0]({
register.mock.calls[11][0]({
register: jest.fn(),
get,
post: jest.fn(),
Expand All @@ -287,7 +291,7 @@ describe('ssrServer', () => {

const post = jest.fn();

register.mock.calls[10][0]({
register.mock.calls[11][0]({
register: jest.fn(),
get: jest.fn(),
post,
Expand All @@ -314,7 +318,7 @@ describe('ssrServer', () => {

const post = jest.fn();

register.mock.calls[10][0]({
register.mock.calls[11][0]({
register: jest.fn(),
get: jest.fn(),
post,
Expand Down Expand Up @@ -342,7 +346,7 @@ describe('ssrServer', () => {

const post = jest.fn();

register.mock.calls[10][0]({
register.mock.calls[11][0]({
register: jest.fn(),
get: jest.fn(),
post,
Expand Down Expand Up @@ -378,7 +382,7 @@ describe('ssrServer', () => {

const post = jest.fn();

register.mock.calls[10][0]({
register.mock.calls[11][0]({
register: jest.fn(),
get: jest.fn(),
post,
Expand Down Expand Up @@ -408,7 +412,7 @@ describe('ssrServer', () => {

const post = jest.fn();

register.mock.calls[10][0]({
register.mock.calls[11][0]({
register: jest.fn(),
get: jest.fn(),
post,
Expand Down Expand Up @@ -438,7 +442,7 @@ describe('ssrServer', () => {

const post = jest.fn();

register.mock.calls[10][0]({
register.mock.calls[11][0]({
register: jest.fn(),
get: jest.fn(),
post,
Expand Down Expand Up @@ -473,7 +477,7 @@ describe('ssrServer', () => {

const post = jest.fn();

register.mock.calls[10][0]({
register.mock.calls[11][0]({
register: jest.fn(),
get: jest.fn(),
post,
Expand Down Expand Up @@ -505,7 +509,7 @@ describe('ssrServer', () => {

const post = jest.fn();

register.mock.calls[10][0]({
register.mock.calls[11][0]({
register: jest.fn(),
get: jest.fn(),
post,
Expand Down Expand Up @@ -540,7 +544,7 @@ describe('ssrServer', () => {

const post = jest.fn();

register.mock.calls[10][0]({
register.mock.calls[11][0]({
register: jest.fn(),
get: jest.fn(),
post,
Expand Down Expand Up @@ -581,7 +585,7 @@ describe('ssrServer', () => {

const post = jest.fn();

register.mock.calls[10][0]({
register.mock.calls[11][0]({
register: jest.fn(),
get: jest.fn(),
post,
Expand Down Expand Up @@ -635,7 +639,7 @@ describe('ssrServer', () => {
await ssrServer();

const get = jest.fn();
register.mock.calls[11][0]({
register.mock.calls[12][0]({
register: jest.fn(),
get,
}, null, jest.fn());
Expand All @@ -658,7 +662,7 @@ describe('ssrServer', () => {
await ssrServer();

const get = jest.fn();
register.mock.calls[11][0]({
register.mock.calls[12][0]({
register: jest.fn(),
get,
}, null, jest.fn());
Expand All @@ -679,7 +683,7 @@ describe('ssrServer', () => {
await ssrServer();

const get = jest.fn();
register.mock.calls[11][0]({
register.mock.calls[12][0]({
register: jest.fn(),
get,
}, null, jest.fn());
Expand All @@ -698,7 +702,7 @@ describe('ssrServer', () => {
await ssrServer();

const post = jest.fn();
register.mock.calls[11][0]({
register.mock.calls[12][0]({
register: jest.fn(),
get: jest.fn(),
post,
Expand All @@ -713,7 +717,7 @@ describe('ssrServer', () => {
await ssrServer();

const post = jest.fn();
register.mock.calls[11][0]({
register.mock.calls[12][0]({
register: jest.fn(),
get: jest.fn(),
post,
Expand Down
13 changes: 13 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@
"create-shared-react-context": "^1.0.5",
"cross-fetch": "^3.1.5",
"fastify": "^4.18.0",
"fastify-metrics": "^10.3.0",
"fastify-plugin": "^4.2.0",
"helmet": "^6.0.0",
"holocron": "^1.7.0",
Expand Down
2 changes: 0 additions & 2 deletions src/server/metrics/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import holocron from './holocron';
import intlCache from './intl-cache';
import * as appVersion from './app-version';
import ssr from './ssr';
import route from './route';

export {
// counters
Expand All @@ -41,5 +40,4 @@ export {
appVersion,
intlCache,
ssr,
route,
};
28 changes: 0 additions & 28 deletions src/server/metrics/route.js

This file was deleted.

Loading

0 comments on commit b531606

Please sign in to comment.