Skip to content

Commit

Permalink
Merge branch 'bugfix/ZENKO-745-uniqueLocationMetricsRedisKeys' into q…
Browse files Browse the repository at this point in the history
…/8.0
  • Loading branch information
bert-e committed Jul 23, 2018
2 parents 486abd4 + 23c016d commit 0c3763d
Show file tree
Hide file tree
Showing 8 changed files with 182 additions and 38 deletions.
10 changes: 10 additions & 0 deletions lib/Config.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,16 @@ function locationConstraintAssert(locationConstraints) {
assert(supportedBackends.indexOf(locationConstraints[l].type) > -1,
'bad config: locationConstraints[region].type must ' +
`be one of ${supportedBackends}`);
assert(typeof locationConstraints[l].objectId === 'string',
'bad config: locationConstraints[region].objectId is ' +
'mandatory and must be a unique string across locations');
assert(Object.keys(locationConstraints)
.filter(loc => (locationConstraints[loc].objectId ===
locationConstraints[l].objectId))
.length === 1,
'bad config: location constraint objectId ' +
`"${locationConstraints[l].objectId}" is not unique across ` +
'configured locations');
assert(typeof locationConstraints[l].legacyAwsBehavior
=== 'boolean',
'bad config: locationConstraints[region]' +
Expand Down
1 change: 1 addition & 0 deletions lib/management/configuration.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ function patchConfiguration(newConf, log, cb) {
Object.keys(newConf.locations || {}).forEach(k => {
const l = newConf.locations[k];
const location = {
objectId: l.objectId,
details: {},
};
let supportsVersioning = false;
Expand Down
16 changes: 14 additions & 2 deletions lib/utapi/utilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,16 @@ function pushMetric(action, log, metricObj) {
return utapi.pushMetric(action, log.getSerializedUids(), utapiObj);
}

/**
* internal: get the unique location ID from the location name
*
* @param {string} location - location name
* @return {string} - location unique ID
*/
function _getLocationId(location) {
return _config.locationConstraints[location].objectId;
}

/**
* Call the Utapi Client 'getLocationMetric' method with the
* associated parameters
Expand All @@ -225,7 +235,8 @@ function pushMetric(action, log, metricObj) {
* @return {function} - `utapi.getLocationMetric`
*/
function getLocationMetric(location, log, cb) {
return utapi.getLocationMetric(location, log.getSerializedUids(), cb);
const locationId = _getLocationId(location);
return utapi.getLocationMetric(locationId, log.getSerializedUids(), cb);
}

/**
Expand All @@ -238,7 +249,8 @@ function getLocationMetric(location, log, cb) {
* @return {function} - `utapi.pushLocationMetric`
*/
function pushLocationMetric(location, byteLength, log, cb) {
return utapi.pushLocationMetric(location, byteLength,
const locationId = _getLocationId(location);
return utapi.pushLocationMetric(locationId, byteLength,
log.getSerializedUids(), cb);
}

Expand Down
16 changes: 16 additions & 0 deletions locationConfig.json
Original file line number Diff line number Diff line change
@@ -1,81 +1,97 @@
{
"us-east-1": {
"type": "file",
"objectId": "us-east-1",
"legacyAwsBehavior": true,
"details": {}
},
"us-east-2": {
"type": "file",
"objectId": "us-east-2",
"legacyAwsBehavior": false,
"details": {}
},
"us-west-1": {
"type": "file",
"objectId": "us-west-1",
"legacyAwsBehavior": false,
"details": {}
},
"us-west-2": {
"type": "file",
"objectId": "us-west-2",
"legacyAwsBehavior": false,
"details": {}
},
"ca-central-1": {
"type": "file",
"objectId": "ca-central-1",
"legacyAwsBehavior": false,
"details": {}
},
"cn-north-1": {
"type": "file",
"objectId": "cn-north-1",
"legacyAwsBehavior": false,
"details": {}
},
"ap-south-1": {
"type": "file",
"objectId": "ap-south-1",
"legacyAwsBehavior": false,
"details": {}
},
"ap-northeast-1": {
"type": "file",
"objectId": "ap-northeast-1",
"legacyAwsBehavior": false,
"details": {}
},
"ap-northeast-2": {
"type": "file",
"objectId": "ap-northeast-2",
"legacyAwsBehavior": false,
"details": {}
},
"ap-southeast-1": {
"type": "file",
"objectId": "ap-southeast-1",
"legacyAwsBehavior": false,
"details": {}
},
"ap-southeast-2": {
"type": "file",
"objectId": "ap-southeast-2",
"legacyAwsBehavior": false,
"details": {}
},
"eu-central-1": {
"type": "file",
"objectId": "eu-central-1",
"legacyAwsBehavior": false,
"details": {}
},
"eu-west-1": {
"type": "file",
"objectId": "eu-west-1",
"legacyAwsBehavior": false,
"details": {}
},
"eu-west-2": {
"type": "file",
"objectId": "eu-west-2",
"legacyAwsBehavior": false,
"details": {}
},
"EU": {
"type": "file",
"objectId": "EU",
"legacyAwsBehavior": false,
"details": {}
},
"sa-east-1": {
"type": "file",
"objectId": "sa-east-1",
"legacyAwsBehavior": false,
"details": {}
}
Expand Down
19 changes: 19 additions & 0 deletions tests/locationConfig/locationConfigLegacy.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,42 +2,50 @@
{
"legacy": {
"type": "mem",
"objectId": "legacy",
"legacyAwsBehavior": false,
"details": {}
},
"us-east-1": {
"type": "file",
"objectId": "us-east-1",
"legacyAwsBehavior": true,

"details": {}
},
"us-east-2": {
"type": "file",
"objectId": "us-east-2",
"legacyAwsBehavior": true,
"details": {}
},
"scality-internal-file": {
"type": "file",
"objectId": "scality-internal-file",
"legacyAwsBehavior": false,
"details": {}
},
"dataFile": {
"type": "file",
"objectId": "dataFile",
"legacyAwsBehavior": false,
"details": {}
},
"scality-internal-mem": {
"type": "mem",
"objectId": "scality-internal-mem",
"legacyAwsBehavior": false,
"details": {}
},
"scality-us-west-1": {
"type": "mem",
"objectId": "scality-us-west-1",
"legacyAwsBehavior": false,
"details": {}
},
"awsbackendencryption": {
"type": "aws_s3",
"objectId": "awsbackendencryption",
"legacyAwsBehavior": true,
"details": {
"awsEndpoint": "s3.amazonaws.com",
Expand All @@ -49,6 +57,7 @@
},
"awsbackend": {
"type": "aws_s3",
"objectId": "awsbackend",
"legacyAwsBehavior": true,
"details": {
"awsEndpoint": "s3.amazonaws.com",
Expand All @@ -59,6 +68,7 @@
},
"awsbackendmismatch": {
"type": "aws_s3",
"objectId": "awsbackendmismatch",
"legacyAwsBehavior": true,
"details": {
"awsEndpoint": "s3.amazonaws.com",
Expand All @@ -69,6 +79,7 @@
},
"awsbackendhttp": {
"type": "aws_s3",
"objectId": "awsbackendhttp",
"legacyAwsBehavior": true,
"details": {
"awsEndpoint": "s3.amazonaws.com",
Expand All @@ -80,6 +91,7 @@
},
"awsbackend2": {
"type": "aws_s3",
"objectId": "awsbackend2",
"legacyAwsBehavior": true,
"details": {
"awsEndpoint": "s3.amazonaws.com",
Expand All @@ -90,6 +102,7 @@
},
"azurebackend": {
"type": "azure",
"objectId": "azurebackend",
"legacyAwsBehavior": true,
"details": {
"azureStorageEndpoint": "https://fakeaccountname.blob.core.fake.net/",
Expand All @@ -101,6 +114,7 @@
},
"azurebackend2": {
"type": "azure",
"objectId": "azurebackend2",
"legacyAwsBehavior": true,
"details": {
"azureStorageEndpoint": "https://fakeaccountname2.blob.core.fake.net/",
Expand All @@ -112,6 +126,7 @@
},
"azurebackendmismatch": {
"type": "azure",
"objectId": "azurebackendmismatch",
"legacyAwsBehavior": true,
"details": {
"azureStorageEndpoint": "https://fakeaccountname.blob.core.fake.net/",
Expand All @@ -123,6 +138,7 @@
},
"gcpbackend": {
"type": "gcp",
"objectId": "gcpbackend",
"legacyAwsBehavior": true,
"details": {
"gcpEndpoint": "storage.googleapis.com",
Expand All @@ -134,6 +150,7 @@
},
"withversioning": {
"type": "aws_s3",
"objectId": "withversioning",
"legacyAwsBehavior": true,
"details": {
"awsEndpoint": "s3.amazonaws.com",
Expand All @@ -145,6 +162,7 @@
},
"withoutversioning": {
"type": "aws_s3",
"objectId": "withoutversioning",
"legacyAwsBehavior": true,
"details": {
"awsEndpoint": "s3.amazonaws.com",
Expand All @@ -156,6 +174,7 @@
},
"transientfile": {
"type": "file",
"objectId": "transientfile",
"legacyAwsBehavior": false,
"details": {},
"isTransient": true
Expand Down
Loading

0 comments on commit 0c3763d

Please sign in to comment.