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

feat: add support for validating OpenAPI specs against test runs #19955

Merged
merged 4 commits into from
Oct 24, 2023

Conversation

sennyeya
Copy link
Contributor

Hey, I just made a Pull Request!

Optic has a command called optic capture that supports making requests through a proxy that can be validated against the written OpenAPI spec afterwards. It also supports a --update flag for automated updates. Wanting to add this into catalog-backend and search-backend as an initial test.

✔️ Checklist

  • A changeset describing the change and affected packages. (more info)
  • Added or updated documentation
  • Tests for new functionality and regression tests for bug fixes
  • Screenshots attached (for UI changes)
  • All your commits have a Signed-off-by line in the message. (more info)

@github-actions github-actions bot added area:catalog Related to the Catalog Project Area search Things related to Search area:discoverability Related to the Discoverability Project Area labels Sep 14, 2023
@backstage-goalie
Copy link
Contributor

backstage-goalie bot commented Sep 14, 2023

Changed Packages

Package Name Package Path Changeset Bump Current Version
@backstage/backend-openapi-utils packages/backend-openapi-utils patch v0.0.5
@backstage/repo-tools packages/repo-tools minor v0.3.5
@backstage/plugin-catalog-backend plugins/catalog-backend patch v1.14.0
@backstage/plugin-search-backend plugins/search-backend patch v1.4.6

@sennyeya sennyeya changed the title Optic integration oa feat: add support for validating OpenAPI specs against test runs Sep 14, 2023
@github-actions
Copy link
Contributor

github-actions bot commented Sep 14, 2023

Uffizzi Preview deployment-36006 was deleted.

@github-actions github-actions bot added the documentation Improvements or additions to documentation label Sep 18, 2023
@sennyeya
Copy link
Contributor Author

@sennyeya sennyeya marked this pull request as ready for review September 18, 2023 23:24
Copy link
Member

@jhaals jhaals left a comment

Choose a reason for hiding this comment

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

Cool! Very nice to get this output in ci 👏

I took a peak and added some questions!

optic.yml Outdated Show resolved Hide resolved
package.json Outdated Show resolved Hide resolved
plugins/search-backend/package.json Outdated Show resolved Hide resolved
packages/repo-tools/package.json Show resolved Hide resolved
@jhaals
Copy link
Member

jhaals commented Sep 25, 2023

Looks like we run into some OOM errors in CI 😬

Run yarn backstage-repo-tools schema openapi test
## Processing packages/app
## Processing packages/app-defaults
## Processing packages/app-next

<--- Last few GCs --->

[25510:0x6603670]   262858 ms: Mark-sweep 4050.8 (4[13](https://github.com/backstage/backstage/actions/runs/6267509682/job/17020797745?pr=19955#step:9:14)7.8) -> 4039.9 (4[14](https://github.com/backstage/backstage/actions/runs/6267509682/job/17020797745?pr=19955#step:9:15)2.6) MB, 4531.0 / 0.0 ms  (average mu = 0.692, current mu = 0.189) allocation failure; scavenge might not succeed
[25510:0x6603670]   269931 ms: Mark-sweep 4056.1 (4143.1) -> 4045.1 (4148.1) MB, 6[17](https://github.com/backstage/backstage/actions/runs/6267509682/job/17020797745?pr=19955#step:9:18)7.8 / 0.0 ms  (average mu = 0.487, current mu = 0.127) allocation failure; scavenge might not succeed


<--- JS stacktrace --->

FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory
 1: 0xb83f50 node::Abort() [/opt/hostedtoolcache/node/[18](https://github.com/backstage/backstage/actions/runs/6267509682/job/17020797745?pr=19955#step:9:19).17.1/x64/bin/node]
 2: 0xa94834  [/opt/hostedtoolcache/node/18.17.1/x64/bin/node]
 3: 0xd647c0 v8::Utils::ReportOOMFailure(v8::internal::Isolate*, char const*, bool) [/opt/hostedtoolcache/node/18.17.1/x64/bin/node]
 4: 0xd64b67 v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*, bool) [/opt/hostedtoolcache/node/18.17.1/x64/bin/node]
 5: 0xf42265  [/opt/hostedtoolcache/node/18.17.1/x64/bin/node]
 6: 0xf5474d v8::internal::Heap::CollectGarbage(v8::internal::AllocationSpace, v8::internal::GarbageCollectionReason, v8::GCCallbackFlags) [/opt/hostedtoolcache/node/18.17.1/x64/bin/node]
 7: 0xf2ee4e v8::internal::HeapAllocator::AllocateRawWithLightRetrySlowPath(int, v8::internal::AllocationType, v8::internal::AllocationOrigin, v8::internal::AllocationAlignment) [/opt/hostedtoolcache/node/18.17.1/x64/bin/node]
 8: 0xf30[21](https://github.com/backstage/backstage/actions/runs/6267509682/job/17020797745?pr=19955#step:9:22)7 v8::internal::HeapAllocator::AllocateRawWithRetryOrFailSlowPath(int, v8::internal::AllocationType, v8::internal::AllocationOrigin, v8::internal::AllocationAlignment) [/opt/hostedtoolcache/node/18.17.1/x64/bin/node]
 9: 0xf113ea v8::internal::Factory::NewFillerObject(int, v8::internal::AllocationAlignment, v8::internal::AllocationType, v8::internal::AllocationOrigin) [/opt/hostedtoolcache/node/18.17.1/x64/bin/node]
10: 0x12d674f v8::internal::Runtime_AllocateInYoungGeneration(int, unsigned long*, v8::internal::Isolate*) [/opt/hostedtoolcache/node/18.17.1/x64/bin/node]
11: 0x170[35](https://github.com/backstage/backstage/actions/runs/6267509682/job/17020797745?pr=19955#step:9:36)b9  [/opt/hostedtoolcache/node/18.17.1/x64/bin/node]

@sennyeya
Copy link
Contributor Author

@jhaals I think the GC error is due to running the test command in a sub shell? As is, I think we're running 25 node workers. I can adjust this down to 1 for CI as I wasn't hitting this locally.

@sennyeya
Copy link
Contributor Author

sennyeya commented Oct 2, 2023

@Rugvip This should be ready for a re-review when you get a chance!

Copy link
Member

@freben freben left a comment

Choose a reason for hiding this comment

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

Alright, some rough review comments

schemas:
Error:
Copy link
Member

Choose a reason for hiding this comment

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

This mimics ErrorResponseBody right? If so, it needs some double checking I think. The request field is not required, and the error field has optional stack and code. Check the same in the catalog one of course too

Copy link
Member

Choose a reason for hiding this comment

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

This also raises an interesting question about sharing common schemas across packages, since this is such a central type

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah yup, will update to match that type.

I've been thinking about the shared common schemas for a while, but kicking it down the road. Entities were the one I was primarily thinking about, but this should also be added to the stack. Interested to hear any ideas here, haven't been able to come up with a solution as yet.

return execPromise(
[
command,
...options.filter(e => e).map(e => (e.startsWith('-') ? e : `"${e}"`)),
Copy link
Member

Choose a reason for hiding this comment

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

Hm, manual quoting is a bit unfortunate. Can this be rewritten to use the spawn('a', ['b', 'c'], { windowsVerbatimArguments: true } form or so?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thoughts on using the CLI's run command here? I think it would require extracting into cli-node or cli-common, but would come with other benefits like stdout forwarding.

docs/openapi/test-case-validation.md Show resolved Hide resolved
packages/backend-openapi-utils/README.md Outdated Show resolved Hide resolved
Copy link
Contributor

@alde alde left a comment

Choose a reason for hiding this comment

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

LGTM for the files belonging to catalog

@sennyeya sennyeya added the area:openapi-tooling Related to the OpenAPI Tooling Project Area label Oct 5, 2023
@freben
Copy link
Member

freben commented Oct 9, 2023

@sennyeya Seems the builds got real confused here ... things have been improved a lot lately, you may want to rebase (maybe squash too? see if the changeset warning clears up) and force push to kick the tires a bit, until a review gets in

@sennyeya sennyeya requested a review from a team as a code owner October 9, 2023 16:34
@sennyeya
Copy link
Contributor Author

@freben It should be updated now, the yarn file conflicts are going to be the death of me...

@backstage-goalie
Copy link
Contributor

Thanks for the contribution!
All commits need to be DCO signed before they are reviewed. Please refer to the the DCO section in CONTRIBUTING.md or the DCO status for more info.

return;
}

const opticLocation = (
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@freben When you get a chance, one thing that I've been thinking about on top of this one is where to install optic. I think repo-tools is the best place for it, so had to add this to get the binary location to then run in the context of other directories. Hopefully, there's a better way to do this...

one kind of weird thing with Optic is they derive the config file based on context and you can't override it with a passed in value, opticdev/optic#2256. Ideally, we could just run optic in repo-tools and point to each directory, but for now that's a bit of a pipe dream.

Copy link
Member

Choose a reason for hiding this comment

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

What we could do is leave optic as a peer dependency and require the target repo to install it through the root package.json instead. That'd skip the installation for anyone that doesn't use it as well.

Another option to the way it's run is if optic expose a JS API as well that allows us to run these equivalent command straight through JS instead. A bit like we do with Jest here

Copy link
Member

@Rugvip Rugvip left a comment

Choose a reason for hiding this comment

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

👍, more or less good to go imo, just need to get deps in order. Rest I think can be future improvements

return;
}

const opticLocation = (
Copy link
Member

Choose a reason for hiding this comment

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

What we could do is leave optic as a peer dependency and require the target repo to install it through the root package.json instead. That'd skip the installation for anyone that doesn't use it as well.

Another option to the way it's run is if optic expose a JS API as well that allows us to run these equivalent command straight through JS instead. A bit like we do with Jest here

yarn.lock Outdated Show resolved Hide resolved
packages/repo-tools/package.json Outdated Show resolved Hide resolved
sennyeya and others added 3 commits October 23, 2023 13:45
… OpenAPI schema feedback.

Signed-off-by: Aramis Sennyey <aramiss@spotify.com>
Signed-off-by: Aramis <sennyeyaramis@gmail.com>
Signed-off-by: Aramis <sennyeyaramis@gmail.com>
Signed-off-by: Aramis Sennyey <aramiss@spotify.com>
Signed-off-by: Aramis Sennyey <aramiss@spotify.com>
Signed-off-by: Aramis Sennyey <aramiss@spotify.com>
@sennyeya
Copy link
Contributor Author

@Rugvip I can try and get Optic to update their set up upstream, but currently they only support using it through the CLI. Would we want it to be installed as a dependency per your comment on the size of the dependency tree?

Copy link
Member

@Rugvip Rugvip left a comment

Choose a reason for hiding this comment

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

Nice! 👍

Let's :shipit:

@Rugvip Rugvip merged commit 46f92a6 into backstage:master Oct 24, 2023
36 of 37 checks passed
@github-actions
Copy link
Contributor

Thank you for contributing to Backstage! The changes in this pull request will be part of the 1.20.0 release, scheduled for Tue, 14 Nov 2023.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:catalog Related to the Catalog Project Area area:discoverability Related to the Discoverability Project Area area:openapi-tooling Related to the OpenAPI Tooling Project Area documentation Improvements or additions to documentation search Things related to Search
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants