Skip to content

Conversation

yelizhenden-mdb
Copy link
Collaborator

@yelizhenden-mdb yelizhenden-mdb commented Jan 14, 2025

Proposed changes

Jira ticket: CLOUDP-294461

metricCollectionJob implements the workflow for metric collection:

  1. Run the Spectral command with IPA ruleset
  2. Load OpenAPI file
  3. Extract team ownership
  4. Get rule severities
  5. Load Collector results
  6. Merge all the results into the metric-collection-results.json

metricCollectionJob allows custom OAS files, but the default is the v2.json
Example: node metricCollection.js <path-to-OAS-file>

metricCollectionJob produces a couple of output files:

  • /outputs/metric-collection-results.json : The data collected for metrics
  • /outputs/spectral-output.txt: Output of spectral command
  • /outputs/spectral-report.xml: Report for the errors
  • ipa-collector-results-combined.log: This file is intended to store the collector results. However, it does not appear to be populated when metricCollection.js is executed, even though metric-collection-results.json, which is constructed using this file, is populated correctly.

Testing

Example output file:
metric-collection-results.json

Checklist

  • I have signed the MongoDB CLA
  • I have added tests that prove my fix is effective or that my feature works

Changes to Spectral

  • I have read the README file for Spectral Updates

@yelizhenden-mdb yelizhenden-mdb marked this pull request as ready for review January 15, 2025 12:57
@yelizhenden-mdb yelizhenden-mdb requested a review from a team as a code owner January 15, 2025 12:57
@lovisaberggren
Copy link
Collaborator

Ran the code locally and noticed I had to run the script twice, the first time I got this error:

Error during metric collection: Failed to load Collector Results file: ENOENT: no such file or directory, open '/Users/lovisa.berggren/openapi/tools/spectral/ipa/metrics/ipa-collector-results-combined.log'
Failed to load Collector Results file: ENOENT: no such file or directory, open '/Users/lovisa.berggren/openapi/tools/spectral/ipa/metrics/ipa-collector-results-combined.log'

With some debugging it seems like flushToFile() in collector.js isn't run until the workflow finishes, so the file isn't found when loading the collector results the first time

Comment on lines 7 to 12
const config = {
defaultOasFilePath: path.join(rootDir, 'openapi', 'v2.json'),
defaultCollectorResultsFilePath: path.join(dirname, 'ipa-collector-results-combined.log'),
defaultRulesetFilePath: path.join(dirname, '..', 'ipa-spectral.yaml'),
defaultMetricCollectionResultsFilePath: path.join(dirname, 'metric-collection-results.json'),
};
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you give an example how we can set different configurations? For the GH action later on we'd like to point to the generated FOAS for example

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The script currently supports providing a custom OAS file only, which must be in JSON format.

For example, you can run the script using:
node metricCollection.js "<path_to_oas_file>" to specify a custom OAS file.

@yelizhenden-mdb yelizhenden-mdb marked this pull request as draft January 15, 2025 14:43
@yelizhenden-mdb yelizhenden-mdb marked this pull request as ready for review January 15, 2025 18:06
Copy link
Collaborator

@lovisaberggren lovisaberggren left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, LGTM!

@yelizhenden-mdb yelizhenden-mdb merged commit 95064a2 into main Jan 16, 2025
13 checks passed
@yelizhenden-mdb yelizhenden-mdb deleted the CLOUDP-294461 branch January 16, 2025 11:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants