Garden-AI / garden

https://garden-ai.readthedocs.io
MIT License
16 stars 4 forks source link

@backend_toggle feature flags decorator #458

Closed OwenPriceSkelly closed 2 months ago

OwenPriceSkelly commented 2 months ago

closes #457

Overview

This gives us a nice way to point certain backend client methods at instances of the revamp-in-progress backend for the sake of testing. This is controlled by the values of a new GARDEN_BACKEND_TOGGLES environment variable and the old GARDEN_ENV variable.

Note that these are left unset by default if you've e.g. installed garden from PyPI. Default behavior for anyone outside of a poetry shell is still always to target the current prod backend. Default behavior for anyone inside a poetry shell (or someone who manually sets these variables) has changed.

The new GARDEN_BACKEND_TOGGLES variable should be a list of methods to point at revamp resources instead of the usual ones. For example, because I've added a default value of GARDEN_BACKEND_TOGGLES=mint_doi_on_datacite,update_doi_on_datacite to the .env.shared, if you're running garden from poetry shell it will default to the dev lambda (as usual) for every method except the two doi methods, which will now target the dev lightsail deployment.

The existing GARDEN_ENV variable can now be "local" in addition to "dev" and "prod". If set to dev or prod, the toggled methods will target the respective lightsail deployments instead of the respective dev/prod lambdas. Note that only explicitly setting GARDEN_ENV=prod has this behavior; if GARDEN_ENV is unset then everything is still the old prod resources.

If set to "local", toggled methods will target localhost:5500 to play nicely with the revamp's run-dev-server.sh script. un-toggled methods will target the dev lambda when GARDEN_ENV=local.

Discussion

The decorator was probably more fun to write than to read. But it works pretty well and will be nice and easy to delete when we're done with the revamp.

Testing

Manually, both by exercising backend methods directly from a repl and by using the CLI in a poetry shell.

Documentation

No docs


📚 Documentation preview 📚: https://garden-ai--458.org.readthedocs.build/en/458/

codecov-commenter commented 2 months ago

Codecov Report

Attention: Patch coverage is 58.62069% with 12 lines in your changes are missing coverage. Please review.

Project coverage is 75.26%. Comparing base (a9b1f92) to head (f6ef004).

Files Patch % Lines
garden_ai/backend_client.py 58.62% 12 Missing :warning:

:exclamation: Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #458 +/- ## ========================================== - Coverage 75.41% 75.26% -0.16% ========================================== Files 50 50 Lines 3197 3226 +29 ========================================== + Hits 2411 2428 +17 - Misses 786 798 +12 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.