Skip to content
This repository has been archived by the owner on Nov 12, 2019. It is now read-only.

Commit

Permalink
Bug 1522097 - [ec2-manager] Show error messages on the error endpoint…
Browse files Browse the repository at this point in the history
…s instead of placeholder ----- HIDDEN ----- (#77)
  • Loading branch information
jhford authored Jan 23, 2019
1 parent 90de68e commit bfc9a31
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 4 deletions.
5 changes: 4 additions & 1 deletion lib/state.js
Original file line number Diff line number Diff line change
Expand Up @@ -1111,8 +1111,11 @@ class State {
let result = await this.runQuery({query, values});

let recentErrors = result.rows || [];

return recentErrors.map(x => {
x.message = '----- HIDDEN -----';
if (x.code === 'UnauthorizedOperation') {
x.message = '----- HIDDEN -----';
}
return x;
});
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"license": "MPL-2.0",
"engines": {
"node": "8.12.0",
"yarn": "1.9.4"
"yarn": ">=1.9.4"
},
"scripts": {
"heroku-prebuild": "echo $SOURCE_VERSION > .git-version",
Expand Down
4 changes: 2 additions & 2 deletions test/api_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ describe('Api', () => {
assume(result.errors[0]).has.property('az');
assume(result.errors[0]).has.property('instanceType');
assume(result.errors[0]).has.property('workerType');
assume(result.errors[0]).has.property('message', '----- HIDDEN -----');
assume(result.errors[0]).has.property('message');

});

Expand All @@ -508,7 +508,7 @@ describe('Api', () => {
assume(result.errors[0]).has.property('az');
assume(result.errors[0]).has.property('instanceType');
assume(result.errors[0]).has.property('workerType');
assume(result.errors[0]).has.property('message', '----- HIDDEN -----');
assume(result.errors[0]).has.property('message');

});

Expand Down
84 changes: 84 additions & 0 deletions test/state_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -700,6 +700,90 @@ describe('State', () => {
assume(actual[0]).has.property('reason', 'Reason');
});

describe('showing recent errors', () => {
it('show expected terminations and request errors', async () => {
let termination = new Date();
let request1 = new Date();
let request2 = new Date();

termination.setMinutes(termination.getMinutes() - 30);
request1.setMinutes(request1.getMinutes() - 20);
request2.setMinutes(request2.getMinutes() - 10);

await db.insertTermination({
region: 'us-east-1',
az: 'us-east-1a',
workerType: 'worker-1',
imageId: 'ami-123456789',
instanceType: 'm3.medium',
id: 'i-0',
code: 'Server.SpotInstanceTermination',
reason: 'Server.SpotInstanceTermination: test',
lastEvent: termination,
launched: termination,
terminated: termination,
});

await db.logAWSRequest({
region: 'us-east-1',
requestId: 'request1',
duration: 1000, // Remember this is us not ms
method: 'runInstances',
service: 'dunky',
error: true,
code: 'RequestLimitExceeded',
message: 'RequestLimitExceeded: test',
called: request1,
});

// We don't want to show any of these errors through the API, since
// they're encyrpted authorization errors.
await db.logAWSRequest({
region: 'us-east-1',
requestId: 'request2',
duration: 1000, // Remember this is us not ms
method: 'runInstances',
service: 'dunky',
error: true,
code: 'UnauthorizedOperation',
message: 'UnauthorizedOperation: test2',
called: request2,
});

assume(await db.getRecentErrors()).deeply.equals([
{
type: 'termination',
region: 'us-east-1',
az: 'us-east-1a',
instanceType: 'm3.medium',
workerType: 'worker-1',
code: 'Server.SpotInstanceTermination',
time: termination,
message: 'Server.SpotInstanceTermination: test',
}, {
type: 'instance-request',
region: 'us-east-1',
az: null,
instanceType: null,
workerType: null,
code: 'RequestLimitExceeded',
time: request1,
message: 'RequestLimitExceeded: test',
}, {
type: 'instance-request',
region: 'us-east-1',
az: null,
instanceType: null,
workerType: null,
code: 'UnauthorizedOperation',
time: request2,
message: '----- HIDDEN -----',
},
]);

});
});

describe('determining health of ec2 account', () => {

it('should work with empty state', async () => {
Expand Down

0 comments on commit bfc9a31

Please sign in to comment.