Compare commits

...

3 Commits

Author SHA1 Message Date
Taylor McKinnon 900ff95f59 bf(S3C-4137): Add operationId translsation to ingestion route for v1 compat 2021-03-15 11:34:00 -07:00
Taylor McKinnon 4503578269 add test 2021-03-15 11:32:39 -07:00
Taylor McKinnon 9b631613bc bf(S3C-4145): Fix error response 2021-03-15 11:21:03 -07:00
6 changed files with 33 additions and 6 deletions

View File

@ -99,6 +99,9 @@ const constants = {
migrationOpTranslationMap: { migrationOpTranslationMap: {
listBucketMultipartUploads: 'listMultipartUploads', listBucketMultipartUploads: 'listMultipartUploads',
}, },
ingestionOpTranslationMap: {
putDeleteMarkerObject: 'deleteObject',
},
expirationChunkDuration: 900000000, // 15 minutes in microseconds expirationChunkDuration: 900000000, // 15 minutes in microseconds
}; };

View File

@ -2,6 +2,7 @@ const errors = require('../../../errors');
const { UtapiMetric } = require('../../../models'); const { UtapiMetric } = require('../../../models');
const { client: cacheClient } = require('../../../cache'); const { client: cacheClient } = require('../../../cache');
const { convertTimestamp } = require('../../../utils'); const { convertTimestamp } = require('../../../utils');
const { ingestionOpTranslationMap } = require('../../../constants');
async function ingestMetric(ctx, params) { async function ingestMetric(ctx, params) {
let metrics; let metrics;
@ -9,6 +10,7 @@ async function ingestMetric(ctx, params) {
metrics = params.body.map(m => new UtapiMetric({ metrics = params.body.map(m => new UtapiMetric({
...m, ...m,
timestamp: convertTimestamp(m.timestamp), timestamp: convertTimestamp(m.timestamp),
operationId: ingestionOpTranslationMap[m.operationId] || m.operationId,
})); }));
} catch (error) { } catch (error) {
throw errors.InvalidRequest; throw errors.InvalidRequest;

View File

@ -76,10 +76,8 @@ function errorMiddleware(err, req, res, next) {
} }
res.status(code).send({ res.status(code).send({
error: { code: code.toString(),
code: code.toString(), message,
message,
},
}); });
responseLoggerMiddleware(req, res); responseLoggerMiddleware(req, res);
} }

View File

@ -30,10 +30,15 @@ const emptyOperationsResponse = Object.values(operationToResponse)
async function listMetrics(level, resources, start, end, force403 = false) { async function listMetrics(level, resources, start, end, force403 = false) {
const body = { const body = {
timeRange: [start, end],
[level]: resources, [level]: resources,
}; };
if (end !== undefined) {
body.timeRange = [start, end];
} else {
body.timeRange = [start];
}
const headers = { const headers = {
host: 'localhost', host: 'localhost',
port: 8100, port: 8100,
@ -207,4 +212,9 @@ describe('Test listMetric', function () {
const resp = await listMetrics('buckets', ['test'], getTs(-1), getTs(1), true); const resp = await listMetrics('buckets', ['test'], getTs(-1), getTs(1), true);
assert.strictEqual(resp.statusCode, 403); assert.strictEqual(resp.statusCode, 403);
}); });
it('should use the current timestamp for "end" if it is not provided', async () => {
const resp = await listMetrics('buckets', ['test'], getTs(-1));
assert.strictEqual(resp.timeRange.length, 2);
});
}); });

View File

@ -43,4 +43,19 @@ describe('Test ingestMetric', () => {
err => err.code === 503 && err.ServiceUnavailable, err => err.code === 503 && err.ServiceUnavailable,
); );
}); });
it('should translate putDeleteMarkerObject to deleteObject', async () => {
const spy = sinon.spy(cacheClient, 'pushMetric');
const metric = new UtapiMetric({
operationId: 'putDeleteMarkerObject',
});
await ingestMetric(ctx, { body: [metric.getValue()] });
assert.strictEqual(ctx.results.statusCode, 200);
assert(spy.calledWith(
new UtapiMetric({
operationId: 'deleteObject',
timestamp: convertTimestamp(metric.timestamp),
}),
));
});
}); });

View File

@ -124,7 +124,6 @@ const eventTemplateToOperation = {
'getObjectRetention', 'getObjectRetention',
'getObjectTagging', 'getObjectTagging',
'headObject', 'headObject',
'putDeleteMarkerObject',
'putObjectAcl', 'putObjectAcl',
'putObjectLegalHold', 'putObjectLegalHold',
'putObjectRetention', 'putObjectRetention',