Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improvement/s3 utils 163 #316

Merged
merged 3 commits into from
May 17, 2024
Merged
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
9 changes: 7 additions & 2 deletions CountItems/utils/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ function consolidateDataMetrics(target, source) {
_currentRestoring: 0,
_nonCurrentRestored: 0,
_nonCurrentRestoring: 0,
_inflightsPreScan: 0,
},
});
}
Expand All @@ -38,7 +39,7 @@ function consolidateDataMetrics(target, source) {
if (!source) {
return resTarget;
}
const { usedCapacity, objectCount } = source;
const { usedCapacity, objectCount, accountOwnerID } = source;
resTarget.usedCapacity.current += usedCapacity && usedCapacity.current ? usedCapacity.current : 0;
resTarget.usedCapacity.nonCurrent += usedCapacity && usedCapacity.nonCurrent ? usedCapacity.nonCurrent : 0;
resTarget.usedCapacity._currentCold += usedCapacity && usedCapacity._currentCold ? usedCapacity._currentCold : 0;
Expand All @@ -58,7 +59,11 @@ function consolidateDataMetrics(target, source) {
resTarget.objectCount._nonCurrentRestoring += objectCount && objectCount._nonCurrentRestoring ? objectCount._nonCurrentRestoring : 0;
resTarget.objectCount._nonCurrentRestored += objectCount && objectCount._nonCurrentRestored ? objectCount._nonCurrentRestored : 0;

// Current and NonCurrent are the total of all other metrics
resTarget.usedCapacity._inflightsPreScan += usedCapacity && usedCapacity._inflightsPreScan ? usedCapacity._inflightsPreScan : 0;
francoisferrand marked this conversation as resolved.
Show resolved Hide resolved
if (accountOwnerID) {
resTarget.accountOwnerID = accountOwnerID;
}

resTarget.usedCapacity.current += usedCapacity
? usedCapacity._currentCold + usedCapacity._currentRestored + usedCapacity._currentRestoring : 0;
resTarget.usedCapacity.nonCurrent += usedCapacity
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "s3utils",
"version": "1.14.7",
"version": "1.14.8",
"engines": {
"node": ">= 16"
},
Expand Down
232 changes: 232 additions & 0 deletions tests/unit/CountItems/CountManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ describe('CountItems::CountManager', () => {
usedCapacity: {
current: 200,
nonCurrent: 100,
_inflightsPreScan: 0,
_currentCold: 0,
_nonCurrentCold: 0,
_currentRestored: 100,
Expand All @@ -222,6 +223,7 @@ describe('CountItems::CountManager', () => {
usedCapacity: {
current: 200,
nonCurrent: 100,
_inflightsPreScan: 0,
_currentCold: 0,
_nonCurrentCold: 0,
_currentRestored: 100,
Expand Down Expand Up @@ -249,6 +251,7 @@ describe('CountItems::CountManager', () => {
usedCapacity: {
current: 200,
nonCurrent: 100,
_inflightsPreScan: 0,
_currentCold: 0,
_nonCurrentCold: 0,
_currentRestored: 100,
Expand All @@ -274,6 +277,235 @@ describe('CountItems::CountManager', () => {
usedCapacity: {
current: 200,
nonCurrent: 100,
_inflightsPreScan: 0,
_currentCold: 0,
_nonCurrentCold: 0,
_currentRestored: 100,
_currentRestoring: 0,
_nonCurrentRestored: 0,
_nonCurrentRestoring: 0,
},
},
},
});
});

test('should update dataMetrics with inflights', () => {
const workers = createWorkers(1);
const m = new CountManager({
log: new DummyLogger(),
workers,
maxConcurrent: 1,
});
expect(m.dataMetrics).toEqual({
account: {},
bucket: {},
location: {},
});
m._consolidateData({
dataMetrics: {
account: {
account1: {
objectCount: {
current: 10,
deleteMarker: 0,
nonCurrent: 10,
_currentCold: 0,
_nonCurrentCold: 0,
_currentRestored: 1,
_currentRestoring: 0,
_nonCurrentRestored: 0,
_nonCurrentRestoring: 0,
},
usedCapacity: {
current: 100,
nonCurrent: 100,
_inflightsPreScan: 1000,
_currentCold: 0,
_nonCurrentCold: 0,
_currentRestored: 100,
_currentRestoring: 0,
_nonCurrentRestored: 0,
_nonCurrentRestoring: 0,
},
locations: {
location1: {
objectCount: {
current: 10,
deleteMarker: 0,
nonCurrent: 10,
_currentCold: 0,
_nonCurrentCold: 0,
_currentRestored: 1,
_currentRestoring: 0,
_nonCurrentRestored: 0,
_nonCurrentRestoring: 0,
},
usedCapacity: {
current: 100,
nonCurrent: 100,
_inflightsPreScan: 1000,
_currentCold: 0,
_nonCurrentCold: 0,
_currentRestored: 100,
_currentRestoring: 0,
_nonCurrentRestored: 0,
_nonCurrentRestoring: 0,
},
},
},
},
},
bucket: {
bucket1: {
objectCount: {
current: 10,
deleteMarker: 0,
nonCurrent: 10,
_currentCold: 0,
_nonCurrentCold: 0,
_currentRestored: 1,
_currentRestoring: 0,
_nonCurrentRestored: 0,
_nonCurrentRestoring: 0,
},
usedCapacity: {
current: 100,
nonCurrent: 100,
_inflightsPreScan: 1000,
_currentCold: 0,
_nonCurrentCold: 0,
_currentRestored: 100,
_currentRestoring: 0,
_nonCurrentRestored: 0,
_nonCurrentRestoring: 0,
},
},
},
location: {
location1: {
objectCount: {
current: 10,
deleteMarker: 0,
nonCurrent: 10,
_currentCold: 0,
_nonCurrentCold: 0,
_currentRestored: 1,
_currentRestoring: 0,
_nonCurrentRestored: 0,
_nonCurrentRestoring: 0,
},
usedCapacity: {
current: 100,
nonCurrent: 100,
_inflightsPreScan: 1000,
_currentCold: 0,
_nonCurrentCold: 0,
_currentRestored: 100,
_currentRestoring: 0,
_nonCurrentRestored: 0,
_nonCurrentRestoring: 0,
},
},
},
},
});
expect(m.dataMetrics).toEqual({
account: {
account1: {
objectCount: {
current: 11,
deleteMarker: 0,
nonCurrent: 10,
_currentCold: 0,
_nonCurrentCold: 0,
_currentRestored: 1,
_currentRestoring: 0,
_nonCurrentRestored: 0,
_nonCurrentRestoring: 0,
},
usedCapacity: {
current: 200,
nonCurrent: 100,
_inflightsPreScan: 1000,
_currentCold: 0,
_nonCurrentCold: 0,
_currentRestored: 100,
_currentRestoring: 0,
_nonCurrentRestored: 0,
_nonCurrentRestoring: 0,
},
locations: {
location1: {
objectCount: {
current: 11,
deleteMarker: 0,
nonCurrent: 10,
_currentCold: 0,
_nonCurrentCold: 0,
_currentRestored: 1,
_currentRestoring: 0,
_nonCurrentRestored: 0,
_nonCurrentRestoring: 0,
},
usedCapacity: {
current: 200,
nonCurrent: 100,
_inflightsPreScan: 1000,
_currentCold: 0,
_nonCurrentCold: 0,
_currentRestored: 100,
_currentRestoring: 0,
_nonCurrentRestored: 0,
_nonCurrentRestoring: 0,
},
},
},
},
},
bucket: {
bucket1: {
objectCount: {
current: 11,
deleteMarker: 0,
nonCurrent: 10,
_currentCold: 0,
_nonCurrentCold: 0,
_currentRestored: 1,
_currentRestoring: 0,
_nonCurrentRestored: 0,
_nonCurrentRestoring: 0,
},
usedCapacity: {
current: 200,
nonCurrent: 100,
_inflightsPreScan: 1000,
_currentCold: 0,
_nonCurrentCold: 0,
_currentRestored: 100,
_currentRestoring: 0,
_nonCurrentRestored: 0,
_nonCurrentRestoring: 0,
},
},
},
location: {
location1: {
objectCount: {
current: 11,
deleteMarker: 0,
nonCurrent: 10,
_currentCold: 0,
_nonCurrentCold: 0,
_currentRestored: 1,
_currentRestoring: 0,
_nonCurrentRestored: 0,
_nonCurrentRestoring: 0,
},
usedCapacity: {
current: 200,
nonCurrent: 100,
_inflightsPreScan: 1000,
_currentCold: 0,
_nonCurrentCold: 0,
_currentRestored: 100,
Expand Down
60 changes: 60 additions & 0 deletions tests/unit/CountItems/utils/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ describe('CountItems::utils::consolidateDataMetrics', () => {
usedCapacity: {
current: 0,
nonCurrent: 0,
_inflightsPreScan: 0,
_currentCold: 0,
_nonCurrentCold: 0,
_currentRestored: 0,
Expand All @@ -29,6 +30,7 @@ describe('CountItems::utils::consolidateDataMetrics', () => {
usedCapacity: {
current: 10,
nonCurrent: 10,
_inflightsPreScan: 0,
_currentCold: 0,
_nonCurrentCold: 0,
_currentRestored: 0,
Expand All @@ -53,6 +55,7 @@ describe('CountItems::utils::consolidateDataMetrics', () => {
usedCapacity: {
current: 20,
nonCurrent: 20,
_inflightsPreScan: 0,
_currentCold: 0,
_nonCurrentCold: 0,
_currentRestored: 0,
Expand All @@ -73,6 +76,56 @@ describe('CountItems::utils::consolidateDataMetrics', () => {
},
};

const exampleWithInflights = {
usedCapacity: {
current: 20,
nonCurrent: 20,
_inflightsPreScan: 1000,
_currentCold: 0,
_nonCurrentCold: 0,
_currentRestored: 0,
_currentRestoring: 0,
_nonCurrentRestored: 0,
_nonCurrentRestoring: 0,
},
objectCount: {
current: 20,
nonCurrent: 20,
deleteMarker: 20,
_currentCold: 0,
_nonCurrentCold: 0,
_currentRestored: 0,
_currentRestoring: 0,
_nonCurrentRestored: 0,
_nonCurrentRestoring: 0,
},
};

const expectedResponseWithInflights = {
usedCapacity: {
current: 40,
nonCurrent: 40,
_inflightsPreScan: 1000,
_currentCold: 0,
_nonCurrentCold: 0,
_currentRestored: 0,
_currentRestoring: 0,
_nonCurrentRestored: 0,
_nonCurrentRestoring: 0,
},
objectCount: {
current: 40,
nonCurrent: 40,
deleteMarker: 40,
_currentCold: 0,
_nonCurrentCold: 0,
_currentRestored: 0,
_currentRestoring: 0,
_nonCurrentRestored: 0,
_nonCurrentRestoring: 0,
},
};

test('should return zero-value if target and source are both undefined', () => {
const res = consolidateDataMetrics(undefined, undefined);
expect(res).toEqual(zeroValueRes);
Expand Down Expand Up @@ -114,4 +167,11 @@ describe('CountItems::utils::consolidateDataMetrics', () => {
const res = consolidateDataMetrics(target, source);
expect(res).toEqual(zeroValueRes);
});

test('should consolidate inflight delta metrics', () => {
const source = exampleWithInflights;
const target = example1;
const res = consolidateDataMetrics(target, source);
expect(res).toEqual(expectedResponseWithInflights);
});
});
Loading