Skip to content
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
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@

*.out
**/*ipa-collector-results-combined.log
**/*metric-collection-results.json
**/*metric-collection-results.parquet
**/*spectral-output.txt
**/*spectral-report.xml
9 changes: 8 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
"apache-arrow": "^19.0.0",
"dotenv": "^16.4.7",
"eslint-plugin-jest": "^28.10.0",
"openapi-to-postmanv2": "4.24.0"
"openapi-to-postmanv2": "4.24.0",
"parquet-wasm": "^0.6.1"
},
"devDependencies": {
"@babel/preset-env": "^7.26.0",
Expand Down
5 changes: 4 additions & 1 deletion tools/spectral/ipa/metrics/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ const config = {
defaultOutputsDir: path.join(dirname, 'outputs'),
};

config.defaultMetricCollectionResultsFilePath = path.join(config.defaultOutputsDir, 'metric-collection-results.json');
config.defaultMetricCollectionResultsFilePath = path.join(
config.defaultOutputsDir,
'metric-collection-results.parquet'
);

export default config;
14 changes: 4 additions & 10 deletions tools/spectral/ipa/metrics/metricS3Upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { PutObjectCommand, S3ServiceException } from '@aws-sdk/client-s3';
import config from './config.js';
import path from 'path';
import fs from 'node:fs';
import { tableFromJSON, tableToIPC } from 'apache-arrow';
import { getS3Client, getS3FilePath } from './utils/dataDumpUtils.js';

/**
Expand All @@ -11,14 +10,9 @@ import { getS3Client, getS3FilePath } from './utils/dataDumpUtils.js';
*/
export async function uploadMetricCollectionDataToS3(filePath = config.defaultMetricCollectionResultsFilePath) {
console.log('Loading metrics collection data from', filePath);
const metricsCollectionData = JSON.parse(fs.readFileSync(filePath, 'utf8'));
if (metricsCollectionData === undefined || metricsCollectionData.length === 0) {
throw new Error('Loaded metrics collection data is empty');
}

const table = tableFromJSON(metricsCollectionData);
if (table === undefined) {
throw new Error('Unable to transform metrics collection data to table');
const metricsData = await fs.readFileSync(filePath);
if (metricsData === undefined) {
throw new Error('Loaded metrics collection data is undefined');
}

try {
Expand All @@ -32,7 +26,7 @@ export async function uploadMetricCollectionDataToS3(filePath = config.defaultMe
const command = new PutObjectCommand({
Bucket: s3fileProps.bucketName,
Key: path.join(s3fileProps.key, formattedDate, 'metric-collection-results.parquet'),
Body: tableToIPC(table, 'stream'),
Body: metricsData,
});

console.log('Dumping data to S3...');
Expand Down
10 changes: 9 additions & 1 deletion tools/spectral/ipa/metrics/scripts/runMetricCollection.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import fs from 'node:fs';
import { spawnSync } from 'child_process';
import spectral from '@stoplight/spectral-core';
import { Compression, Table, writeParquet, WriterPropertiesBuilder } from 'parquet-wasm';
import { tableFromJSON, tableToIPC } from 'apache-arrow';
import config from '../config.js';
import { runMetricCollectionJob } from '../metricCollection.js';

Expand Down Expand Up @@ -51,6 +53,12 @@ runMetricCollectionJob(
)
.then((results) => {
console.log('Writing results');
fs.writeFileSync(config.defaultMetricCollectionResultsFilePath, JSON.stringify(results));
const table = tableFromJSON(results);
const wasmTable = Table.fromIPCStream(tableToIPC(table, 'stream'));
const parquetUint8Array = writeParquet(
wasmTable,
new WriterPropertiesBuilder().setCompression(Compression.GZIP).build()
);
fs.writeFileSync(config.defaultMetricCollectionResultsFilePath, parquetUint8Array);
})
.catch((error) => console.error(error.message));
Loading