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: {
|
migrationOpTranslationMap: {
|
||||||
listBucketMultipartUploads: 'listMultipartUploads',
|
listBucketMultipartUploads: 'listMultipartUploads',
|
||||||
},
|
},
|
||||||
|
ingestionOpTranslationMap: {
|
||||||
|
putDeleteMarkerObject: 'deleteObject',
|
||||||
|
},
|
||||||
expirationChunkDuration: 900000000, // 15 minutes in microseconds
|
expirationChunkDuration: 900000000, // 15 minutes in microseconds
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -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;
|
||||||
|
|
|
@ -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);
|
||||||
}
|
}
|
||||||
|
|
|
@ -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);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -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),
|
||||||
|
}),
|
||||||
|
));
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -124,7 +124,6 @@ const eventTemplateToOperation = {
|
||||||
'getObjectRetention',
|
'getObjectRetention',
|
||||||
'getObjectTagging',
|
'getObjectTagging',
|
||||||
'headObject',
|
'headObject',
|
||||||
'putDeleteMarkerObject',
|
|
||||||
'putObjectAcl',
|
'putObjectAcl',
|
||||||
'putObjectLegalHold',
|
'putObjectLegalHold',
|
||||||
'putObjectRetention',
|
'putObjectRetention',
|
||||||
|
|
Loading…
Reference in New Issue