Compare commits
3 Commits
developmen
...
bugfix/uta
Author | SHA1 | Date |
---|---|---|
Taylor McKinnon | 900ff95f59 | |
Taylor McKinnon | 4503578269 | |
Taylor McKinnon | 9b631613bc |
|
@ -99,6 +99,9 @@ const constants = {
|
|||
migrationOpTranslationMap: {
|
||||
listBucketMultipartUploads: 'listMultipartUploads',
|
||||
},
|
||||
ingestionOpTranslationMap: {
|
||||
putDeleteMarkerObject: 'deleteObject',
|
||||
},
|
||||
expirationChunkDuration: 900000000, // 15 minutes in microseconds
|
||||
};
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@ const errors = require('../../../errors');
|
|||
const { UtapiMetric } = require('../../../models');
|
||||
const { client: cacheClient } = require('../../../cache');
|
||||
const { convertTimestamp } = require('../../../utils');
|
||||
const { ingestionOpTranslationMap } = require('../../../constants');
|
||||
|
||||
async function ingestMetric(ctx, params) {
|
||||
let metrics;
|
||||
|
@ -9,6 +10,7 @@ async function ingestMetric(ctx, params) {
|
|||
metrics = params.body.map(m => new UtapiMetric({
|
||||
...m,
|
||||
timestamp: convertTimestamp(m.timestamp),
|
||||
operationId: ingestionOpTranslationMap[m.operationId] || m.operationId,
|
||||
}));
|
||||
} catch (error) {
|
||||
throw errors.InvalidRequest;
|
||||
|
|
|
@ -76,10 +76,8 @@ function errorMiddleware(err, req, res, next) {
|
|||
}
|
||||
|
||||
res.status(code).send({
|
||||
error: {
|
||||
code: code.toString(),
|
||||
message,
|
||||
},
|
||||
code: code.toString(),
|
||||
message,
|
||||
});
|
||||
responseLoggerMiddleware(req, res);
|
||||
}
|
||||
|
|
|
@ -30,10 +30,15 @@ const emptyOperationsResponse = Object.values(operationToResponse)
|
|||
|
||||
async function listMetrics(level, resources, start, end, force403 = false) {
|
||||
const body = {
|
||||
timeRange: [start, end],
|
||||
[level]: resources,
|
||||
};
|
||||
|
||||
if (end !== undefined) {
|
||||
body.timeRange = [start, end];
|
||||
} else {
|
||||
body.timeRange = [start];
|
||||
}
|
||||
|
||||
const headers = {
|
||||
host: 'localhost',
|
||||
port: 8100,
|
||||
|
@ -207,4 +212,9 @@ describe('Test listMetric', function () {
|
|||
const resp = await listMetrics('buckets', ['test'], getTs(-1), getTs(1), true);
|
||||
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);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -43,4 +43,19 @@ describe('Test ingestMetric', () => {
|
|||
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),
|
||||
}),
|
||||
));
|
||||
});
|
||||
});
|
||||
|
|
|
@ -124,7 +124,6 @@ const eventTemplateToOperation = {
|
|||
'getObjectRetention',
|
||||
'getObjectTagging',
|
||||
'headObject',
|
||||
'putDeleteMarkerObject',
|
||||
'putObjectAcl',
|
||||
'putObjectLegalHold',
|
||||
'putObjectRetention',
|
||||
|
|
Loading…
Reference in New Issue