Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 14 additions & 20 deletions lib/UtapiClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -592,34 +592,28 @@ class UtapiClient {
* on the number of objects.
*/
actionCounter -= 1;
cmds2.push(
['decr', generateCounter(p, 'numberOfObjectsCounter')],
['decrby', generateCounter(p, 'storageUtilizedCounter'), params.byteLength],
);

const byteArr = results[index + commandsGroupSize - 1][1];
if (byteArr) {
const oldByteLength = parseInt(byteArr[0], 10);
const newByteLength = member.serialize(Math.max(0, oldByteLength - params.byteLength));
cmds2.push(
['zremrangebyscore', generateStateKey(p, 'storageUtilized'), timestamp, timestamp],
['zadd', generateStateKey(p, 'storageUtilized'), timestamp, newByteLength],
);
}
}

const key = generateStateKey(p, 'numberOfObjects');

const byteArr = results[index + commandsGroupSize - 1][1];
const oldByteLength = byteArr ? parseInt(byteArr[0], 10) : 0;
const newByteLength = member.serialize(Math.max(0, oldByteLength - params.byteLength));

cmds2.push(
['zremrangebyscore', key, timestamp, timestamp],
['zadd', key, timestamp, member.serialize(actionCounter)],

);

if (Number.isInteger(params.byteLength)) {
cmds2.push(
['decr', generateCounter(p, 'numberOfObjectsCounter')],
['decrby', generateCounter(p, 'storageUtilizedCounter'), params.byteLength],
);
}

if (byteArr) {
cmds2.push(
['zremrangebyscore', generateStateKey(p, 'storageUtilized'), timestamp, timestamp],
['zadd', generateStateKey(p, 'storageUtilized'), timestamp, newByteLength],
);
}

return true;
});

Expand Down
39 changes: 39 additions & 0 deletions tests/unit/testUtapiClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -694,6 +694,7 @@ tests.forEach(test => {
const expected = buildExpectedResult({
action: 'DeleteObject',
numberOfObjects: '1',
storageUtilized: '0',
});
testMetric('putDeleteMarkerObject', metricTypes, expected, done);
});
Expand All @@ -702,6 +703,7 @@ tests.forEach(test => {
const expected = buildExpectedResult({
action: 'PutObject',
numberOfObjects: '1',
storageUtilized: '258',
});
const metrics = {
bucket: '5741-repro',
Expand All @@ -717,6 +719,7 @@ tests.forEach(test => {
const expected = buildExpectedResult({
action: 'DeleteObject',
numberOfObjects: '1',
storageUtilized: '0',
});
const metrics2 = {
bucket: '5741-repro',
Expand All @@ -732,6 +735,42 @@ tests.forEach(test => {
});
});

it('should push putDeleteMarkerObject metrics and have correct bytes and number of objects', done => {
const expected = buildExpectedResult({
action: 'PutObject',
numberOfObjects: '1',
storageUtilized: '258',
});
const metrics = {
bucket: '10699-repro',
keys: ['foo2'],
byteLength: undefined,
newByteLength: 258,
oldByteLength: null,
numberOfObjects: 1,
accountId: '79a59df900b949e55d96a1e698fbacedfd6e09d98eacf8f8d5218e7cd47ef2be',
userId: undefined,
};
testMetric('putObject', Object.assign(metrics, metricTypes), expected, () => {
const expected = buildExpectedResult({
action: 'DeleteObject',
numberOfObjects: '2',
storageUtilized: '258',
});
const metrics2 = {
bucket: '10699-repro',
keys: ['foo2'],
byteLength: undefined,
newByteLength: undefined,
oldByteLength: undefined,
numberOfObjects: undefined,
accountId: '79a59df900b949e55d96a1e698fbacedfd6e09d98eacf8f8d5218e7cd47ef2be',
userId: undefined,
};
testMetric('putDeleteMarkerObject', Object.assign(metrics2, metricTypes), expected, done);
});
});

it('should push putBucketReplication metrics', done => {
const expected = buildExpectedResult({
action: 'PutBucketReplication',
Expand Down
Loading