Skip to content

Commit fb5420f

Browse files
author
Kerkesni
committed
make showing crr location replication status configurable
- added a config param to allow enabling/disabling display of the crr site's replication status - Checking if a location is CRR is done in two ways: 1. In zenko, CRR destinations are actual locations and have the `isCRR` flag in their details. 2. S3C doesn't have the concept of locations, so when we don't find the location with `config.getLocationConstraint()` we know we are in S3C. The locations set in the replication info in the MD is built by Cloudserver after making sure all the locations there exist. Issue: CLDSRV-737
1 parent 4c30e14 commit fb5420f

4 files changed

Lines changed: 95 additions & 0 deletions

File tree

lib/Config.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1756,6 +1756,8 @@ class Config extends EventEmitter {
17561756
}
17571757
}
17581758

1759+
this.includeCrrStatusMetadata = config.includeCrrStatusMetadata ?? true;
1760+
17591761
return config;
17601762
}
17611763

lib/utilities/collectResponseHeaders.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,11 @@ function collectResponseHeaders(objectMD, corsHeaders, versioningCfg,
106106
}
107107
if (Array.isArray(objectMD?.replicationInfo?.backends)) {
108108
objectMD.replicationInfo.backends.forEach(backend => {
109+
const locationConstraint = config.getLocationConstraint(backend.site);
110+
if (!config.includeCrrStatusMetadata &&
111+
(!locationConstraint || locationConstraint.isCRR)) {
112+
return;
113+
}
109114
const { status, site, dataStoreVersionId } = backend;
110115
responseMetaHeaders[`x-amz-meta-${site}-replication-status`] =
111116
status;

tests/unit/Config.js

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -933,4 +933,49 @@ describe('Config', () => {
933933
);
934934
});
935935
});
936+
937+
describe('includeCrrStatusMetadata', () => {
938+
let defaultConfig;
939+
940+
before(() => {
941+
setEnv('S3_CONFIG_FILE', 'tests/unit/testConfigs/allOptsConfig/config.json');
942+
const defaultConfigPath = path.join(__dirname, './testConfigs/allOptsConfig/config.json');
943+
defaultConfig = require(defaultConfigPath);
944+
});
945+
946+
afterEach(() => {
947+
sinon.restore();
948+
});
949+
950+
it('should be enabled by default', () => {
951+
const config = new ConfigObject();
952+
assert.strictEqual(config.includeCrrStatusMetadata, true);
953+
});
954+
955+
it('should be enabled when set to true in config file', () => {
956+
const originalReadFileSync = fs.readFileSync;
957+
const readFileSyncStub = sinon.stub(fs, 'readFileSync');
958+
readFileSyncStub
959+
.withArgs(sinon.match(/\/config\.json$/))
960+
.returns(JSON.stringify({ ...defaultConfig, includeCrrStatusMetadata: true }));
961+
readFileSyncStub
962+
.callsFake((filePath, ...args) => originalReadFileSync(filePath, ...args));
963+
964+
const config = new ConfigObject();
965+
assert.strictEqual(config.includeCrrStatusMetadata, true);
966+
});
967+
968+
it('should be disabled when set to false in config file', () => {
969+
const originalReadFileSync = fs.readFileSync;
970+
const readFileSyncStub = sinon.stub(fs, 'readFileSync');
971+
readFileSyncStub
972+
.withArgs(sinon.match(/\/config\.json$/))
973+
.returns(JSON.stringify({ ...defaultConfig, includeCrrStatusMetadata: false }));
974+
readFileSyncStub
975+
.callsFake((filePath, ...args) => originalReadFileSync(filePath, ...args));
976+
977+
const config = new ConfigObject();
978+
assert.strictEqual(config.includeCrrStatusMetadata, false);
979+
});
980+
});
936981
});

tests/unit/utils/collectResponseHeaders.js

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,27 @@
11
const assert = require('assert');
2+
const sinon = require('sinon');
23
const collectResponseHeaders =
34
require('../../../lib/utilities/collectResponseHeaders');
5+
const { config } = require('../../../lib/Config');
46

57
describe('Middleware: Collect Response Headers', () => {
8+
afterEach(() => {
9+
sinon.restore();
10+
});
11+
612
it('should be able to set replication status when config is set', () => {
713
const objectMD = { replicationInfo: { status: 'REPLICA' } };
814
const headers = collectResponseHeaders(objectMD);
915
assert.deepStrictEqual(headers['x-amz-replication-status'], 'REPLICA');
1016
});
1117

1218
it('should set the replication status of each site', () => {
19+
sinon.stub(config, 'includeCrrStatusMetadata')
20+
.value(true);
21+
sinon.stub(config, 'getLocationConstraint')
22+
.onCall(0).returns({ isCRR: false })
23+
.onCall(1).returns({ isCRR: true });
24+
1325
const objectMD = {
1426
replicationInfo: {
1527
status: 'COMPLETED',
@@ -28,6 +40,37 @@ describe('Middleware: Collect Response Headers', () => {
2840
'COMPLETED');
2941
assert.deepStrictEqual(headers['x-amz-meta-us-west-2-version-id'], undefined);
3042
});
43+
44+
it('should skip the replication status for CRR sites', () => {
45+
sinon.stub(config, 'includeCrrStatusMetadata')
46+
.value(false);
47+
sinon.stub(config, 'getLocationConstraint')
48+
.onCall(0).returns({ isCRR: false })
49+
.onCall(1).returns({ isCRR: true })
50+
.onCall(1).returns(undefined);
51+
52+
const objectMD = {
53+
replicationInfo: {
54+
status: 'COMPLETED',
55+
backends: [
56+
{ site: 'us-east-1', status: 'COMPLETED', dataStoreVersionId: '123' },
57+
{ site: 'crr', status: 'COMPLETED', dataStoreVersionId: '' },
58+
{ site: 'crr-s3c', status: 'COMPLETED', dataStoreVersionId: '' },
59+
],
60+
},
61+
};
62+
const headers = collectResponseHeaders(objectMD);
63+
assert.deepStrictEqual(headers['x-amz-replication-status'], 'COMPLETED');
64+
assert.deepStrictEqual(headers['x-amz-meta-us-east-1-replication-status'],
65+
'COMPLETED');
66+
assert.deepStrictEqual(headers['x-amz-meta-us-east-1-version-id'], '123');
67+
assert.deepStrictEqual(headers['x-amz-meta-crr-replication-status'],
68+
undefined);
69+
assert.deepStrictEqual(headers['x-amz-meta-crr-version-id'], undefined);
70+
assert.deepStrictEqual(headers['x-amz-meta-crr-s3c-replication-status'],
71+
undefined);
72+
assert.deepStrictEqual(headers['x-amz-meta-crr-s3c-version-id'], undefined);
73+
});
3174

3275
[
3376
{ md: { replicationInfo: null }, test: 'when config is not set' },

0 commit comments

Comments
 (0)