Skip to content

Commit 90d2906

Browse files
1 parent 03356cd commit 90d2906

File tree

2 files changed

+20
-7
lines changed

2 files changed

+20
-7
lines changed

tools/spectral/ipa/metrics/metricS3Upload.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,21 @@ import { getS3Client, getS3FilePath } from './utils/dataDumpUtils.js';
1010
* @param filePath file path to the metrics collection results, uses config.js by default
1111
*/
1212
export async function uploadMetricCollectionDataToS3(filePath = config.defaultMetricCollectionResultsFilePath) {
13+
console.log('Loading metrics collection data from', filePath);
14+
const metricsCollectionData = JSON.parse(fs.readFileSync(filePath, 'utf8'));
15+
if (metricsCollectionData === undefined || metricsCollectionData.length === 0) {
16+
throw new Error('Loaded metrics collection data is empty');
17+
}
18+
1319
try {
1420
console.log('Creating S3 Client...');
1521
const client = getS3Client();
1622
const formattedDate = new Date().toISOString().split('T')[0];
1723

18-
console.log('Loading metrics collection data from', filePath);
19-
const metricsCollectionData = JSON.parse(fs.readFileSync(filePath, 'utf8'));
20-
const table = tableFromJSON(metricsCollectionData);
21-
2224
console.log('Getting S3 file path...');
2325
const s3fileProps = getS3FilePath();
26+
27+
const table = tableFromJSON(metricsCollectionData);
2428
const command = new PutObjectCommand({
2529
Bucket: s3fileProps.bucketName,
2630
Key: path.join(s3fileProps.key, formattedDate, 'metric-collection-results.parquet'),
@@ -30,6 +34,7 @@ export async function uploadMetricCollectionDataToS3(filePath = config.defaultMe
3034
console.log('Dumping data to S3...');
3135
const response = await client.send(command);
3236
console.log(response);
37+
return response;
3338
} catch (caught) {
3439
if (caught instanceof S3ServiceException && caught.name === 'EntityTooLarge') {
3540
console.error(

tools/spectral/ipa/metrics/scripts/dataDump.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,14 @@ import { uploadMetricCollectionDataToS3 } from '../metricS3Upload.js';
33
const args = process.argv.slice(2);
44
const filePath = args[0];
55

6-
uploadMetricCollectionDataToS3(filePath)
7-
.then(() => console.log('Data dump to S3 completed successfully.'))
8-
.catch((error) => console.error(error.message));
6+
const response = await uploadMetricCollectionDataToS3(filePath).catch((error) => {
7+
console.error(error.message);
8+
process.exit(1);
9+
});
10+
11+
if (!response) {
12+
console.error('PutObject response is undefined');
13+
process.exit(1);
14+
}
15+
16+
console.log('Data dump to S3 completed successfully.');

0 commit comments

Comments
 (0)