-
Notifications
You must be signed in to change notification settings - Fork 49
Global state to app.state to enable multiple APIs in a single process
#2313
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
Conversation
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #2313 +/- ##
==========================================
- Coverage 90.66% 90.66% -0.01%
==========================================
Files 75 75
Lines 4981 5022 +41
==========================================
+ Hits 4516 4553 +37
- Misses 465 469 +4
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
cc34495 to
2ade55d
Compare
|
@ml-evs i think this is ready for review. The only thing failing is the build of |
|
You should be able to ignore the validator action errors, I'll make an effort to merge some thing on that end today and we'll see if this turns green. |
aa93eac to
64ee79e
Compare
|
(Just rebased with the changes from #2308) |
55a8f62 to
01fbae2
Compare
Somehow the validator now touches the server config when called via the validator action, whereas before it didn't (and thus didnt need yaml). Might have to be careful when unpicking that one... |
ml-evs
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @eimrek, got about halfway through a review.
Some general comments:
- The mapper stuff is definitely a breaking change (at least for my usage in odbx etc.) and I'd want to double-check the effect on performance before merging (i.e., needing to create a mapper instance every request just to parse the query params). If its minimal (likely it is) then I'm happy to include this as it does simplify things.
- This PR removes the functionality for
CONFIG.VALIDATE_API_RESPONSE, which was added to allow non-compliant databases to still host their best guess at OPTIMADE data, for example NOMAD including a "D" in chemical formulae. I'm not sure if its possible to override this in a way that works with the new config (e.g., if there's a FastAPI-native setting we can use to disable validation on a per API basis) but I think this is still required. - Can you also write a little docs page about this under the "Deployment" section for running multiple APIs that use different dbs/collections?
84205f9 to
65c5b64
Compare
|
@ml-evs I think now it's in a better shape. Would be great to have another review. The idea is that the main way of using is still the same - config is read either from the ENV variables or the JSON file. However, now, with the I also re-did logging such that you can specify a tag that allows one to differentiate logs from different apps. Finally, I also updates a bit the docs and added some description on how to run multiple apps. |
db845b3 to
287ef4e
Compare
|
@ml-evs Ok, so now all of Materials Cloud OPTIMADE APIs are running on this PR (see https://github.com/materialscloud-org/optimade-server/tree/main/multi-optimade-server) and everything is much more resource-efficient :). Would be great to have this merged in the near future. |
36327b2 to
734520d
Compare
ml-evs
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @eimrek, thanks again for this! You running in production is a better review than I can give, so I'm happy to merge and call this a release candidate.
I'll try it out with my servers and note any config changes I have to make, if any.
734520d to
93bff82
Compare
…ocess - fix tests - fix tests for real mongodb - fix tests for elasticsearch
ci: update optimade-validator-action Revert "ci: update optimade-validator-action" This reverts commit 92fd22d. Unpin validator-action Promote pyyaml back to core dep Update optimade/server/config.py Co-authored-by: Matthew Evans <[email protected]> Update optimade/server/create_app.py Co-authored-by: Matthew Evans <[email protected]> Update optimade/server/create_app.py Co-authored-by: Matthew Evans <[email protected]> dont import elasticsearch; tiny fix rm unused variable store base_resource_mapper in app.state restore CONFIG.validate_api_response restore config.debug tests
93bff82 to
9770f6b
Compare
|
Awesome! Thanks a lot @ml-evs! |
|
There's a GH release for v1.4.0-rc.1 but our PyPI release pipeline isn't set up to handle pre-releases, and I don't have time to faff around with it atm. Will test this out next week and hopefully release a proper 1.4.0 soon. |
Fixes #2307
This PR moves the global
CONFIGsingleton andENTRY_COLLECTIONSto the Fastapiapp.state. This required quite a large refactor, but the default functionality should be retained (so it's fully backwards compatible).Now, there is the
create_appfunction that allows to create multiple apps with different configs. So one could use something likewhich starts two different optimade APIs and an index metadb API.