Skip to content

Commit

Permalink
Merge pull request #218 from Financial-Times/reliability-kit-logger
Browse files Browse the repository at this point in the history
Breaking: replace n-logger with Reliability Kit logger
  • Loading branch information
rowanmanning committed Aug 7, 2023
2 parents 1b98e8c + 7eebb85 commit 6a3a781
Show file tree
Hide file tree
Showing 11 changed files with 804 additions and 104 deletions.
868 changes: 785 additions & 83 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"snyk": "^1.167.2"
},
"dependencies": {
"@financial-times/n-logger": "^10.2.0",
"@dotcom-reliability-kit/logger": "^2.2.6",
"aws-sdk": "^2.6.10",
"fetchres": "^1.5.1",
"moment": "^2.29.4",
Expand Down
2 changes: 1 addition & 1 deletion src/checks/check.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';
const status = require('./status');
const ms = require('ms');
const logger = require('@financial-times/n-logger').default;
const logger = require('@dotcom-reliability-kit/logger');

const isOfficeHoursNow = () => {
const date = new Date();
Expand Down
4 changes: 2 additions & 2 deletions src/checks/cloudWatchAlarm.check.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

const AWS = require('aws-sdk');
const log = require('@financial-times/n-logger').default;
const logger = require('@dotcom-reliability-kit/logger');
const status = require('./status');
const Check = require('./check');

Expand Down Expand Up @@ -53,7 +53,7 @@ class CloudWatchAlarmCheck extends Check {
this.checkOutput = output;
})
.catch(err => {
log.error('Failed to get CloudWatch alarm data', err);
logger.error('Failed to get CloudWatch alarm data', err);
this.status = status.FAILED;
this.checkOutput = `Cloudwatch alarm check failed to fetch data: ${err.message}`;
});
Expand Down
4 changes: 2 additions & 2 deletions src/checks/cloudWatchThreshold.check.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

const AWS = require('aws-sdk');
const moment = require('moment');
const log = require('@financial-times/n-logger').default;
const logger = require('@dotcom-reliability-kit/logger');
const status = require('./status');
const Check = require('./check');

Expand Down Expand Up @@ -61,7 +61,7 @@ class CloudWatchThresholdCheck extends Check {
this.status = ok ? status.PASSED : status.FAILED;
this.checkOutput = ok ? `No threshold change detected in CloudWatch data. Current value: ${value}` : `CloudWatch data ${this.direction} required threshold. Current value: ${value}`;
} catch(err) {
log.error('Failed to get CloudWatch data', err);
logger.error('Failed to get CloudWatch data', err);
this.status = status.FAILED;
this.checkOutput = `Cloudwatch threshold check failed to fetch data: ${err.message}`;
}
Expand Down
2 changes: 1 addition & 1 deletion src/checks/fastlyKeyExpiration.check.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const fetch = require('node-fetch');
const moment = require('moment');
const logger = require('@financial-times/n-logger').default;
const logger = require('@dotcom-reliability-kit/logger');
const Check = require('./check');
const status = require('./status');

Expand Down
2 changes: 1 addition & 1 deletion src/checks/graphiteSpike.check.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* direction: Whether you care about sample metric increases (up) or decreases (down).
*/

const logger = require('@financial-times/n-logger').default;
const logger = require('@dotcom-reliability-kit/logger');
const status = require('./status');
const Check = require('./check');
const fetch = require('node-fetch');
Expand Down
2 changes: 1 addition & 1 deletion src/checks/graphiteThreshold.check.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

const logger = require('@financial-times/n-logger').default;
const logger = require('@dotcom-reliability-kit/logger');
const status = require('./status');
const Check = require('./check');
const fetch = require('node-fetch');
Expand Down
8 changes: 4 additions & 4 deletions src/checks/graphiteWorking.check.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
const status = require('./status');
const Check = require('./check');
const fetch = require('node-fetch');
const log = require('@financial-times/n-logger').default;
const logger = require('@dotcom-reliability-kit/logger');
const fetchres = require('fetchres');

const logEventPrefix = 'GRAPHITE_WORKING_CHECK';

function badJSON(message, json) {
const err = new Error(message);
log.error({ event: `${logEventPrefix}_BAD_JSON` }, err);
logger.error({ event: `${logEventPrefix}_BAD_JSON` }, err);
throw err;
}

Expand Down Expand Up @@ -66,7 +66,7 @@ class GraphiteWorkingCheck extends Check {
}

const simplifiedResult = { target: result.target, nullsForHowManySeconds };
log.debug({ event: `${logEventPrefix}_NULLS_FOR_HOW_LONG` }, simplifiedResult);
logger.debug({ event: `${logEventPrefix}_NULLS_FOR_HOW_LONG` }, simplifiedResult);
return simplifiedResult;
});

Expand All @@ -80,7 +80,7 @@ class GraphiteWorkingCheck extends Check {
this.checkOutput = failedResults.map(r => `${r.target} has been null for ${Math.round(r.nullsForHowManySeconds / 60)} minutes.`).join(' ');
}
} catch(err) {
log.error({ event: `${logEventPrefix}_ERROR`, url: this.url }, err);
logger.error({ event: `${logEventPrefix}_ERROR`, url: this.url }, err);
this.status = status.FAILED;
this.checkOutput = err.toString();
}
Expand Down
2 changes: 1 addition & 1 deletion test/fastlyKeyExpiration.check.spec.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const sinon = require('sinon');
const { expect } = require('chai');
const proxyquire = require('proxyquire').noCallThru().noPreserveCache();
const logger = require('@financial-times/n-logger').default;
const logger = require('@dotcom-reliability-kit/logger');
const FastlyCheck = require('../src/checks/fastlyKeyExpiration.check');
const status = require('../src/checks/status');

Expand Down
12 changes: 5 additions & 7 deletions test/graphiteThreshold.check.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,10 @@ function getCheckConfig (conf) {
}

const mockLogger = {
default: {
error: function() {},
info: function() {},
debug: function() {},
}
}
error: function() {},
info: function() {},
debug: function() {},
};

let mockFetch;
let Check;
Expand All @@ -30,7 +28,7 @@ function mockGraphite (results) {
}));

Check = proxyquire('../src/checks/graphiteThreshold.check', {
'@financial-times/n-logger': mockLogger,
'@dotcom-reliability-kit/logger': mockLogger,
'node-fetch': mockFetch,
});
}
Expand Down

0 comments on commit 6a3a781

Please sign in to comment.