Skip to content

Commit

Permalink
Remove the Service Metrics alert
Browse files Browse the repository at this point in the history
This removes the annoying alert when a service is not recognised. This
causes a lot of churn and there's no need for it. next-metrics now
guesses the service name based on the request URL's host name
(Financial-Times/next-metrics#583) and so this
alert will never fire.

This also allows us to do a lot of simplification because we don't have
to handle undefined services.

For all the removed things (e.g. types/options):
a) these was never part of the public API for n-express
b) we don't seem to be using them anywhere

See-also: https://financialtimes.atlassian.net/browse/CPREL-1123
  • Loading branch information
rowanmanning committed Jul 31, 2024
1 parent bf8b58b commit fed34b2
Show file tree
Hide file tree
Showing 8 changed files with 12 additions and 125 deletions.
3 changes: 1 addition & 2 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ const consentMiddleware = require('./src/middleware/consent');

// logging and monitoring
const metrics = require('next-metrics');
const serviceMetrics = require('./src/lib/service-metrics');
const logger = require('@dotcom-reliability-kit/logger');

// utils
Expand Down Expand Up @@ -132,7 +131,7 @@ const getAppContainer = (options) => {
);

if (options.withServiceMetrics) {
instrumentListen.addMetrics(serviceMetrics.init());
metrics.fetch.instrument();
}

if (options.withBackendAuthentication) {
Expand Down
20 changes: 10 additions & 10 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"express": "^4.17.3",
"isomorphic-fetch": "^3.0.0",
"n-health": "^13.0.0",
"next-metrics": "^12.12.0",
"next-metrics": "^12.15.0",
"semver": "^7.3.7"
},
"devDependencies": {
Expand Down
2 changes: 0 additions & 2 deletions src/lib/health-checks.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ const logger = require('@dotcom-reliability-kit/logger');
const herokuLogDrainCheck = require('./heroku-log-drain-check');
const metricsHealthCheck = require('./metrics-healthcheck');
const supportedNodeJsVersionCheck = require('./supported-node-js-version-check');
const unRegisteredServicesHealthCheck = require('./unregistered-services-healthCheck');

/**
* @param {ExpressApp} app
Expand All @@ -34,7 +33,6 @@ module.exports = (app, options, meta) => {
/** @type {Healthcheck[]} */
const defaultChecks = [
...tickingMetricChecks,
unRegisteredServicesHealthCheck.setAppName(meta.name),
metricsHealthCheck(meta.name),
supportedNodeJsVersionCheck(meta.name)
];
Expand Down
34 changes: 0 additions & 34 deletions src/lib/service-metrics.js

This file was deleted.

49 changes: 0 additions & 49 deletions src/lib/unregistered-services-healthCheck.js

This file was deleted.

22 changes: 0 additions & 22 deletions test/app/clear-interval.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,9 @@ const nextExpress = require('../../main');
const InstrumentListen = require('../../src/lib/instrument-listen');
const expect = require('chai').expect;
const healthChecks = require('../../src/lib/health-checks');
const serviceMetrics = require('../../src/lib/service-metrics');
const sinon = require('sinon');

describe('clears intervals', () => {
it('should return object with stop function in service-metrics', () => {
const result = serviceMetrics.init();
expect(result.stop).to.not.be.undefined;
result.stop();
});

it('should return an array of objects with stop functions in health-checks', () => {
const app = express();

Expand All @@ -29,21 +22,6 @@ describe('clears intervals', () => {
}, 0);
});

it('should call stop() which clears all intervals if a metric is added to instrumentListen', () => {
const app = express();
const instrumentListen = new InstrumentListen(app, {}, []);
const spy = sinon.spy();
const stub = sinon.stub(serviceMetrics, 'init');
stub.returns({
stop: spy
});
instrumentListen.addMetrics(serviceMetrics.init());

app.close();

expect(spy.called).to.be.true;
});

it('should close server in app.close if there is a live server', () => {
const app = express();
const instrumentListen = new InstrumentListen(app, {}, [Promise.resolve()]);
Expand Down
5 changes: 0 additions & 5 deletions typings/metrics.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,3 @@ export type TickingMetric = {
export type Healthcheck = {
getStatus: () => HealthcheckStatus;
};

export interface InitHealthCheck {
setAppName: (appName: string) => Metrics.Healthcheck;
updateCheck: (unregisteredServices: Record<string, any>) => void;
}

0 comments on commit fed34b2

Please sign in to comment.