Skip to content
This repository was archived by the owner on May 27, 2020. It is now read-only.

Commit

Permalink
Fail healthchecks if any on multiple data backends fail
Browse files Browse the repository at this point in the history
  • Loading branch information
rachedbenmustapha authored and dora-korpar committed Apr 6, 2017
1 parent 3c67970 commit db4e00f
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 40 deletions.
4 changes: 2 additions & 2 deletions DOCKER.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ First add a new key-value pair in the restEndpoints section of your config.json.
The key in the key-value pair should be the host name you would like to add
and the value is the default location_constraint for this endpoint.

For example, `s3.example.com` is mapping to `scality-us-west-1` which is one of
For example, `s3.example.com` is mapped to `us-east-1` which is one of
the `location_constraints` listed in your locationConfig.json file
[here](https://github.com/scality/S3/blob/master/locationConfig.json).

Expand All @@ -142,7 +142,7 @@ More information about location configuration
"localhost": "file",
"127.0.0.1": "file",
...
"s3.example.com": "scality-us-west-1"
"s3.example.com": "us-east-1"
},
```

Expand Down
6 changes: 3 additions & 3 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
"restEndpoints": {
"localhost": "file",
"127.0.0.1": "file",
"s3.docker.test": "scality-us-west-1",
"127.0.0.2": "scality-us-west-1",
"s3.amazonaws.com": "scality-us-west-1"
"s3.docker.test": "us-east-1",
"127.0.0.2": "us-east-1",
"s3.amazonaws.com": "us-east-1"
},
"websiteEndpoints": ["s3-website-us-east-1.amazonaws.com",
"s3-website.us-east-2.amazonaws.com",
Expand Down
4 changes: 2 additions & 2 deletions lib/data/wrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ const data = {
return cb(null, defResp);
}
return client.healthcheck(log, (err, result) => {
const respBody = {};
let respBody = {};
if (err) {
log.error(`error from ${implName}`, { error: err });
respBody[implName] = {
Expand All @@ -197,7 +197,7 @@ const data = {
return cb(null, respBody);
}
if (implName === 'multipleBackends') {
respBody.dataBackends = result;
respBody = result;
return cb(null, respBody);
}
respBody[implName] = {
Expand Down
5 changes: 4 additions & 1 deletion lib/utilities/healthcheckHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ export function clientCheck(log, cb) {
});
async.parallel(clientTasks, (err, results) => {
let fail = false;
// makes S3 return 500 error if any backend fails
// obj will be an object of the healthcheck results of
// every backends. No errors were returned directly to
// async.parallel in order to complete the check, so a
// manual check makes S3 return 500 error if any backend failed
const obj = results.reduce((obj, item) => Object.assign(obj, item), {});
fail = Object.keys(obj).some(k => obj[k].error);
if (fail) {
Expand Down
28 changes: 5 additions & 23 deletions locationConfig.json
Original file line number Diff line number Diff line change
@@ -1,27 +1,4 @@
{
"scality-us-east-1": {
"type": "scality",
"legacyAwsBehavior": true,
"details": {
"connector": {
"sproxyd": {
"bootstrap": ["localhost:8181"]
}
}
}
},
"scality-us-west-1": {
"type": "scality",
"legacyAwsBehavior": false,
"details": {
"connector": {
"sproxyd": {
"bootstrap": ["localhost:8182"],
"path": "/proxy/arc/"
}
}
}
},
"us-east-1": {
"type": "file",
"legacyAwsBehavior": true,
Expand All @@ -41,5 +18,10 @@
"type": "mem",
"legacyAwsBehavior": false,
"details": {}
},
"scality-us-west-1": {
"type": "mem",
"legacyAwsBehavior": false,
"details": {}
}
}
12 changes: 5 additions & 7 deletions tests/multipleBackend/backendHealthcheckResponse.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,18 @@ const log = new DummyRequestLogger();
const locConstraints = Object.keys(config.locationConstraints);

describe('Healthcheck response', () => {
it('should return object containing dataBackends key', done => {
clientCheck(log, (err, results) => {
assert.strictEqual(err, null, `Unexpected error ${err}`);
assert.notEqual(
Object.keys(results).indexOf('dataBackends'), -1);
it('should return no error', done => {
clientCheck(log, err => {
assert.strictEqual(err, null,
`Expected success but got error ${err}`);
done();
});
});
it('should return result for every location constraint in ' +
'locationConfig', done => {
clientCheck(log, (err, results) => {
assert.strictEqual(err, null, `Unexpected error ${err}`);
locConstraints.forEach(constraint => {
assert.notEqual(Object.keys(results.dataBackends).
assert.notEqual(Object.keys(results).
indexOf(constraint), -1);
});
done();
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/api/multipartDelete.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const initiateRequest = {
url: `/${objectKey}?uploads`,
};
const eastLocation = 'us-east-1';
const westLocation = 'scality-us-west-1';
const westLocation = 'file';

function _createAndAbortMpu(usEastSetting, fakeUploadID, locationConstraint,
callback) {
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/bucket/bucketCreation.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const log = new DummyRequestLogger();
const headers = {};
const authInfo = makeAuthInfo('accessKey1');

const normalBehaviorLocationConstraint = 'scality-us-west-1';
const normalBehaviorLocationConstraint = 'file';
const specialBehaviorLocationConstraint = 'us-east-1';

describe('bucket creation', () => {
Expand Down

0 comments on commit db4e00f

Please sign in to comment.