-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Pre-generate the OpenAPI schema #6423
Comments
This really got worse on 2.11 - my webserver even times out while generating the spec. Is there a console command you can run to get the openapi json? |
I haven't noticed any difference from v2.10, and I can't recall any changes we've made that would have a significant impact on it. |
While serving a static version of the spec seems harmless since it's version bound anyway, I'm not sure that it makes sense to request the complete schema each time the plugin starts? No matter how fast netbox spits out the file, is that a roundtrip we can avoid? |
There are two ways to bite the cherry.
Whilst both are possible, (1) gives the maximum benefit:
Ideally, Netbox would pregenerate the spec and give an ETag - then smart clients can check and don't have to refetch unless it has changed. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. NetBox is governed by a small group of core maintainers which means not all opened issues may receive direct feedback. Please see our contributing guide. |
I don't think we can pre-generate the full API spec as part of the release process, given that it contains some values unique to the installation (i.e. the base API URL). We also can't generate this at the time of installation because such values may change as the configuration is modified (e.g. if What we can do is specify a cache timeout for the rendered page. This isn't perfect, but it should at least greatly reduce load times for bringing up the API docs. I'm going to try a 24-hour timeout for the rendered specs. |
I think it would be reasonable to require the user to re-run some command like |
It would be very difficult to convey that to the user and ensure that it's undertaken consistently. IMO it's not worth the additional overhead for such a minor impact. |
IMO this is a reasonable optimization that avoids introducing any additional overhead. Just wanted to make some progress on this as no one else has volunteered to own this. I'm happy to consider further improvements, though it's worth noting that we're somewhat limited by the capabilities of the |
Given that the solution turns out to be just a case of adding |
NetBox version
v2.11.3
Feature type
Change to existing functionality
Proposed functionality
A feature like "collectstatic" which builds the openapi schema once in
./upgrade.sh
, then serves it as a static file.Currently it's served dynamically and is very slow, taking consistently 7-8 seconds on my system:
Alternatively, cache it in redis (it will take nearly a megabyte of RAM, but worth it)
Use case
ansible netbox inventory
The ansible netbox inventory fetches the whole openapi schema each time it runs. When combined with the actual data queries it does for devices, vms etc, this gives around a 10-second lead time to any playbook which is hitting the netbox API.
Whilst this inventory module has a feature to cache the results of the inventory (if you configure a suitable cache plugin), I want to get the "real-time" up-to-the-minute data from Netbox. The plugin can't be configured to cache the openapi schema only, whilst still making data queries to Netbox.
pynetbox
Any code which uses pynetbox, and calls
nb.openapi()
, will also benefit.Database changes
None
External dependencies
None
The text was updated successfully, but these errors were encountered: