Skip to content

Commit

Permalink
Merge pull request #84 from Financial-Times/CPP-456-rename-dynamodb-t…
Browse files Browse the repository at this point in the history
…ables

CPP-456 Rename dynamodb tables
  • Loading branch information
emortong authored May 13, 2021
2 parents 951fe77 + 6431048 commit e53dd25
Show file tree
Hide file tree
Showing 10 changed files with 43 additions and 43 deletions.
10 changes: 5 additions & 5 deletions lib/active.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const surviver = require('./promise-surviver');

const HEALTHCHECK_URL = 'https://www.ft.com/__$HEALTHCHECK';

let dynamoInUse = 'master';
let dynamoInUse = 'primary';
let totalFailure = false;
let metrics;

Expand All @@ -17,15 +17,15 @@ module.exports.totalFailure = () => totalFailure;

function raceDynamos () {
return surviver([
get({ dynamo: dynamos.get('master').instance, table: dynamos.get('master').table, fromURL: HEALTHCHECK_URL, metrics: metrics }).then(() => 'master'),
get({ dynamo: dynamos.get('slave').instance, table: dynamos.get('slave').table, fromURL: HEALTHCHECK_URL, metrics: metrics }).then(() => 'slave')
get({ dynamo: dynamos.get('primary').instance, table: dynamos.get('primary').table, fromURL: HEALTHCHECK_URL, metrics: metrics }).then(() => 'primary'),
get({ dynamo: dynamos.get('replica').instance, table: dynamos.get('replica').table, fromURL: HEALTHCHECK_URL, metrics: metrics }).then(() => 'replica')
])
.then(fasterDynamo => {
dynamoInUse = fasterDynamo;
logger.info({ event: 'RACE_DYNAMOS_WINNER', dynamoInUse: dynamoInUse });
totalFailure = false;
}, () => {
dynamoInUse = 'master';
dynamoInUse = 'primary';
logger.warn({ event: 'RACE_DYNAMOS_NO_WINNERS', dynamoInUse: dynamoInUse });
totalFailure = true;
});
Expand All @@ -35,7 +35,7 @@ function raceDynamos () {
function init (opts) {
dynamos.init(opts);
metrics = opts.metrics;
dynamoInUse = 'master';
dynamoInUse = 'primary';
totalFailure = false;
if (!opts.raceOnce) {
setInterval(raceDynamos, 2*60*1000);
Expand Down
4 changes: 2 additions & 2 deletions lib/dynamos.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ const dynamos = {};

module.exports.init = function (opts) {
opts = opts || {};
dynamos.master = dynamo('urlmgmtapi_master', 'eu-west-1', opts);
dynamos.slave = dynamo('urlmgmtapi_slave', 'us-east-1', opts)
dynamos.primary = dynamo('urlmgmtapi_primary', 'eu-west-1', opts);
dynamos.replica = dynamo('urlmgmtapi_replica', 'us-east-1', opts)
}

module.exports.get = name => dynamos[name];
Expand Down
2 changes: 1 addition & 1 deletion lib/health.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ exports.check = opts => {
name: 'n-url-management-api-read-client health check',
id: 'nUrlManagementApiRC-failureMode',
ok: !active.totalFailure(),
checkOutput: `Total failure mode (can't reach either master or slave DynamoDBs) when following is true: ${active.totalFailure()}. Currently using ${active()} table.`,
checkOutput: `Total failure mode (can't reach either primary or replica DynamoDBs) when following is true: ${active.totalFailure()}. Currently using ${active()} table.`,
lastUpdated: new Date(),
panicGuide: `Try checking the \`URLMGMTAPI_AWS_ACCESS/SECRET_KEY\`s and the status of DynamoDB in both eu-west-1 and us-east-1`,
severity: opts.severity,
Expand Down
16 changes: 8 additions & 8 deletions test/active.single-region-failure.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@ const active = proxyquire('../lib/active', {
get: function (name) {
return this[name];
},
master: {
table: 'urlmgmtapi_master',
primary: {
table: 'urlmgmtapi_primary',
instance: {
getItem: (opts, cb) => {
setTimeout(() => cb(new Error('master failure')), 100);
setTimeout(() => cb(new Error('primary failure')), 100);
}
}
},
slave: {
table: 'urlmgmtapi_slave',
replica: {
table: 'urlmgmtapi_replica',
instance: {
getItem: (opts, cb) => {
setTimeout(() => cb(null, itemFixture), 300);
Expand All @@ -34,13 +34,13 @@ describe('#active in a single region failure mode', () => {

before(() => active.init({ metrics: metricsMock }));

it('should start off being ‘master’', () => {
expect(active()).to.eql('master');
it('should start off being ‘primary’', () => {
expect(active()).to.eql('primary');
});

it('should use the healthy region', done => {
setTimeout(() => {
expect(active()).to.eql('slave');
expect(active()).to.eql('replica');
expect(active.totalFailure()).to.be.false;
done();
}, 500);
Expand Down
14 changes: 7 additions & 7 deletions test/active.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@ const active = proxyquire('../lib/active', {
get: function (name) {
return this[name];
},
master: {
table: 'urlmgmtapi_master',
primary: {
table: 'urlmgmtapi_primary',
instance: {
getItem: (opts, cb) => {
setTimeout(() => cb(null, itemFixture), 300);
}
}
},
slave: {
table: 'urlmgmtapi_slave',
replica: {
table: 'urlmgmtapi_replica',
instance: {
getItem: (opts, cb) => {
setTimeout(() => cb(null, itemFixture), 100);
Expand All @@ -40,13 +40,13 @@ describe('#active', () => {
expect(dynamosInitStub.calledWith(opts)).to.be.true;
});

it('should start off being ‘master’', () => {
expect(active()).to.eql('master');
it('should start off being ‘primary’', () => {
expect(active()).to.eql('primary');
});

it('should prefer the faster region after the healthcheck has run', done => {
setTimeout(() => {
expect(active()).to.eql('slave');
expect(active()).to.eql('replica');
expect(active.totalFailure()).to.be.false;
done();
}, 500);
Expand Down
20 changes: 10 additions & 10 deletions test/active.total-failure.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,19 @@ const active = proxyquire('../lib/active', {
get: function (name) {
return this[name];
},
master: {
table: 'urlmgmtapi_master',
primary: {
table: 'urlmgmtapi_primary',
instance: {
getItem: (opts, cb) => {
setTimeout(() => cb(new Error('master failure')), 150)
setTimeout(() => cb(new Error('primary failure')), 150)
}
}
},
slave: {
table: 'urlmgmtapi_slave',
replica: {
table: 'urlmgmtapi_replica',
instance: {
getItem: (opts, cb) => {
setTimeout(() => cb(new Error('slave failure')), 100)
setTimeout(() => cb(new Error('replica failure')), 100)
}
}
}
Expand All @@ -34,13 +34,13 @@ describe('#active in a total failure mode', () => {

before(() => active.init({ metrics: metricsMock }));

it('should start off being ‘master’', () => {
expect(active()).to.eql('master');
it('should start off being ‘primary’', () => {
expect(active()).to.eql('primary');
});

it('should just use master and hope for the best', done => {
it('should just use primary and hope for the best', done => {
setTimeout(() => {
expect(active()).to.eql('master');
expect(active()).to.eql('primary');
expect(active.totalFailure()).to.be.true;
done();
}, 200);
Expand Down
6 changes: 3 additions & 3 deletions test/batch-get.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const mockInstance = {
batchGetItem: (opts, cb) => {
cb(null, {
Responses: {
urlmgmtapi_master: [
urlmgmtapi_primary: [
fastFtFixture.Item,
justasFastFtFixture.Item
]
Expand All @@ -25,8 +25,8 @@ const main = proxyquire('..', {
get: function (name) {
return this[name];
},
master: { table: 'urlmgmtapi_master', instance: mockInstance },
slave: { table: 'urlmgmtapi_slave', instance: mockInstance }
primary: { table: 'urlmgmtapi_primary', instance: mockInstance },
replica: { table: 'urlmgmtapi_replica', instance: mockInstance }
}
});

Expand Down
8 changes: 4 additions & 4 deletions test/dynamos.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ describe('#dynamos', () => {
beforeEach(() => sinon.stub(dynamos, '_createDynamoDBInstance'));
afterEach(() => dynamos._createDynamoDBInstance.restore())

it('should initialise master and slave instances', () => {
it('should initialise primary and replica instances', () => {
dynamos.init();
expect(dynamos._createDynamoDBInstance.args[0][0]).to.deep.equal({
region: 'eu-west-1',
Expand All @@ -26,9 +26,9 @@ describe('#dynamos', () => {
})
})

it('should be possible to get master or slave', () => {
expect(dynamos.get('master').table).to.equal('urlmgmtapi_master')
expect(dynamos.get('slave').table).to.equal('urlmgmtapi_slave')
it('should be possible to get primary or replica', () => {
expect(dynamos.get('primary').table).to.equal('urlmgmtapi_primary')
expect(dynamos.get('replica').table).to.equal('urlmgmtapi_replica')
});

it('should pass http options', () => {
Expand Down
4 changes: 2 additions & 2 deletions test/get.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ const main = proxyquire('..', {
get: function (name) {
return this[name];
},
master: { table: 'urlmgmtapi_master', instance: mockInstance },
slave: { table: 'urlmgmtapi_slave', instance: mockInstance }
primary: { table: 'urlmgmtapi_primary', instance: mockInstance },
replica: { table: 'urlmgmtapi_replica', instance: mockInstance }
}
});

Expand Down
2 changes: 1 addition & 1 deletion test/lib/get.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ describe('#get', () => {
fromURL: 'https://www.ft.com/unknown',
dynamo: mockInstance,
metrics: metricsMock,
table: 'urlmgmtapi_master',
table: 'urlmgmtapi_primary',
timeout: 500
})
.then(() => {
Expand Down

0 comments on commit e53dd25

Please sign in to comment.