From b84f065c72cc97dea6888dadfa7b20399e9370a0 Mon Sep 17 00:00:00 2001 From: Maha Benzekri Date: Wed, 22 Jan 2025 16:57:05 +0100 Subject: [PATCH] fixup --- package.json | 2 +- utils/S3UtilsMongoClient.js | 30 ++++++++++++++++++------------ 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/package.json b/package.json index 5bf176a..ef70733 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,7 @@ "scripts": { "lint": "eslint $(git ls-files '*.js')", "test:unit": "LOCATION_CONFIG_FILE='tests/conf/locationConfig.json' yarn jest --verbose --logHeapUsage --projects jest.config.js --coverage --testPathPattern='tests/unit/[\\w/-]+\\.[tj]s'", - "test:functional": "LOCATION_CONFIG_FILE='tests/conf/locationConfig.json' yarn jest --verbose --logHeapUsage --projects jest.config.js --coverage --testPathPattern='tests/functional/[\\w/-]+\\.[tj]s'" + "test:functional": "LOCATION_CONFIG_FILE='tests/conf/locationConfig.json' yarn jest --verbose --logHeapUsage --projects jest.config.js --coverage --testPathPattern='tests/functional/collectBucketMetricsAndUpdateBucketCapacityInfo.js'" }, "repository": { "type": "git", diff --git a/utils/S3UtilsMongoClient.js b/utils/S3UtilsMongoClient.js index 669c4d7..fb6174c 100644 --- a/utils/S3UtilsMongoClient.js +++ b/utils/S3UtilsMongoClient.js @@ -65,8 +65,10 @@ class S3UtilsMongoClient extends MongoClientInterface { 'value.creationDate': 1, }, }); - const TEST = await this.getCollection(USERSBUCKET).find({}); - console.log('TEST', TEST); + const TEST = await this.getCollection(USERSBUCKET).countDocuments({}); + const TEST2 = await this.getCollection(METASTORE).countDocuments({}); + const TEST3 = await this.getCollection(INFOSTORE).countDocuments({}); + console.log('TEST', { TEST, TEST2, TEST3 }); const usersBucketCreationDatesArray = await cursorUsersBucketCreationDates.toArray(); console.log('USERS BUCKET CREATION DATES ARRAY', usersBucketCreationDatesArray); return usersBucketCreationDatesArray @@ -85,6 +87,7 @@ class S3UtilsMongoClient extends MongoClientInterface { async updateInflightDeltas(allMetrics, log) { let cursor; + console.log('WE ARE HEEEEEEEEERE'); try { if (!allMetrics || !Array.isArray(allMetrics) || allMetrics.length === 0) { return allMetrics; @@ -95,7 +98,8 @@ class S3UtilsMongoClient extends MongoClientInterface { 'usedCapacity._inflight': 1, }, }); - + + console.log('CURSOR', cursor); const inflights = await cursor.toArray(); // convert inflights to a map with _id: usedCapacity._inflight const inflightsMap = inflights.reduce((map, obj) => { @@ -822,20 +826,20 @@ class S3UtilsMongoClient extends MongoClientInterface { } static convertNumberToLong(obj) { - console.log('ON EST ICIIII SA RACE'); if (typeof obj !== 'object' || obj === null) { - return obj; + console.log('THIS IS THE OBJ', obj); + return obj; } + const newObj = {}; for (const key in obj) { - if (typeof obj[key] === 'number') { - // convert number to Long - newObj[key] = Long.fromNumber(obj[key]); - } else { - // recursively convert nested object properties to Long - newObj[key] = S3UtilsMongoClient.convertNumberToLong(obj[key]); - } + if (typeof obj[key] === 'bigint') { + newObj[key] = Long.fromString(obj[key].toString()); + } else { + newObj[key] = S3UtilsMongoClient.convertNumberToLong(obj[key]); + } } + console.log('NEW OBJ', newObj); return newObj; } @@ -856,6 +860,7 @@ class S3UtilsMongoClient extends MongoClientInterface { log.info('updateStorageConsumptionMetrics: updating storage metrics'); // update the inflights + console.log('updatedStorageMetricsList', updatedStorageMetricsList); updatedStorageMetricsList = await this.updateInflightDeltas(updatedStorageMetricsList, log); // Drop the temporary collection if it exists @@ -863,6 +868,7 @@ class S3UtilsMongoClient extends MongoClientInterface { await this.getCollection(INFOSTORE_TMP).drop(); } catch (err) { if (err.codeName !== 'NamespaceNotFound') { + console.log('we are actually heeeere'); throw err; } }