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

♻️✨ ⚠️ [DEVOPS] maintenance new settings (final round) #2836

Merged
merged 131 commits into from
Feb 21, 2022

Conversation

pcrespov
Copy link
Member

@pcrespov pcrespov commented Feb 15, 2022

What do these changes do?

This is the last of a series of PRs that progressively introduced the new-settings (i.e. moving from trafaret-based config to settings_library-based settings ) in the entire repo . Here is a summary of the PRs preceding this one:

  1. PR ♻️ Maintenance/new settings (1st round) #2736 unifies and extends settings_library with new common settings and utils
  2. PR ♻️ Maintenance/new settings (2nd round) #2739 focuses on web-server: modules with dependencies to trafaret are isolated (e.g. splitting each plugin's configurations in _schema.py, _config.py ).
  3. PR ♻️ Enhances BaseCustomSettings in settings_library #2750 fixes design issue and refactors settings_library.base.BaseCustomSettings
  4. PR ✨ ♻️ ⚠️ [DEVOPS] Maintenance/new settings (round 3) #2744 updates all plugin's settings in the web-server to use the new settings_library. The trafaret-based config is marked as deprecated but is still used to run the app. We also introduced many runtime checks to ensure no configuration is lost with the new settings.

Finally, this PR completely removes the deprecated trafaret-based config and activates the new settings to run the app 🎉 (long live to trafaret! it served us very well!). These changes also facilitate managing the plugin mechanism of the app using env vars. For that reason, all the plugins in the webserver were also carefully reviewed and reorganized ensuring at every step that the changes were covered by the tests.

In order to simplify the review, some descriptions of the changes and the ideas behind follow.

Changes in the webserver

There are a lot of small changes throughout the webserver modules but they all follow certain guidelines. Here are the hightlights:

  • 🗑️ requirements: trafaret removed
  • 🗑️ config all yaml configurations removed
  • 🗑️ all *_schema and *config modules including all config dependencies (separated during PR ♻️ Maintenance/new settings (2nd round) #2739) removed. Replaced by settings
  • ♻️ plugin layout unified throughout the entire service ( see skeleton in ♻️ gc as a service (preparation) #2828 ) and actively removed module dependencies. A plugin consists of a group of python modules that include
    • ✨ a settings module that defines the plugin settings. An instance of these settings is created from env vars at startup and stored in the app settings under ApplicationSettings.WEBSERVER_MYPLUGIN. Note that the plugin can be disabled by simply settings the env var WEBSERVER_MYPLUGIN=null.
    • ✨ plugin module that include a setup function decorated with @app_module_setup where it inits the plugin and "merges with the app". Typical operations are
      • add app.routes or app.middlewares
      • appends events to app signals (app.on_startup, app.cleanup_ctx, ...)
      • inits and stores instances in app context (app[MY_INSTANCE] = obj). E.g. creates clients and waits a particular service to connect.
  • ♻️ Some plugins/settings were split:
    • WEBSERVER_RESOURCE_MANAGER now does not include settings of WEBSERVER_GARBAGE_COLLECTOR
    • WEBSERVER_SCICRUNCH it's a plugin on its own
  • ♻️ Some plugins/settings were merged
    • studies_access modules -> studies_dispatcher (WEBSERVER_STUDIES_DISPATCHER)
  • ♻️ webserver/tests were carefully refactored side-by-side with the plugins. These are some of the criteria used
    • tests of a plugin must have its name as prefix, e.g. for myplugin, all associated tests must be test_myplugin*.py regardless of the folder where it is.
    • Most of our test fixtures create a TestClient (typically denoted client) and connects to a client.app that is configured in each case overriding app_config fixture that would represent the trafaret-based config file. With the new settings design, the app is not configured anymore from file (i.e. app_config) but it uses instead env vars, as recommended in the 12-factor app. In order to overcome this change, we created some tools that would transform trafaret-based config into env-vars. The latter are then mocked using monkeypatch.setenv to produce the same effect on the new app setting (see application_settings_utils.py and also monkeypatch_setenv_from_app_config fixture). This approach, not only saved us from a huge refactoring but also guarantees that the TestClient.app fixtures remain the same as they were before.
    • Common/useful helpers moved to pytest_simcore (reusability and reduce local module helpers)
    • All non-code files moved to test/data (easily accessible using test_data_dir fixture)

Changes outside the webserver

Screen Shot 2022-02-19 at 20 06 40

  • models_library
    • 🗑️ deprecated modules models_library.settings.rabbit and models_library.settings.redis removed (replaced by new settings_library counterparts
  • pytest_simcore:
    • helpers:
      • ♻️utils_dict minor
      • 🐛 utils_docker fixes on safe_docker_infos due to long names produces when creating test_failures reports
      • ♻️utils_login: adapted to new settings for login plugin. Removed global config. Further refactoring might be necessary to access users with aiopg. This is a very old fixture
      • ♻️utils_projects moved some of the helpers with projects here to reduce redundancy in project test suites
    • ♻️rabbit_service fixtures to use new service_settings.rabbit
    • ♻️redis_service fixtures to use new service_settings.redis
  • servicelib
    • application_setup enhances plugin initialization. Now decorator relies on application settings (instead of configs) and ensures a that the plugin setup is only executed once. NOTE: @GitHK @sanderegg I will add the dependency feature we discussed in a separate PR.
  • settings_library
    • utils_service: simplified composing URLs from host, port ... (see test_utils_service.py)
    • utils_session: New mixin to check fernet keys. Used in both the web-server and api-server session settings

Screen Shot 2022-02-19 at 20 33 29

  • api-server
    • settings uses new mixin from servicelib.utils_session.
    • ♻️ webserver module adapted to use new settings . Fixes communication due to changes in webserver
  • director-v2:
    • 🗑️/tests refactored due to deprecation of models_library.settings.rabbit and models_library.settings.redis
  • director
    • 📝 /tests highlighted in doc that changes in pytest_simcore that are not python 3.6 compliant will break these tests (it happened during this PR and errors were quite cryptic)
  • dynamic-sidecar
    • 🗑️ /tests same as above

⚠️ [DEVOPS]: Note: This PR makes setting the Env-Var REST_SWAGGER_API_DOC_ENABLED necessary if the swaggerAPI docs are to be exposed

Related issue/s

How to test

Take any plugin (e.g. exporter), then type

pytest --pdb --ff -vv tests/**/test_exporter*.py

NOTE: we could create a make recipe to test plugins

Checklist

  • Replace config by settings in plugins:
    • activity/module_setup.py | pytest --pdb tests/unit/**/test_activ*.py
    • catalog.py | pytest --pdb -vv --ff tests/unit/**/test_catalog*.py
    • clusters/module_setup.py | pytest --pdb -vv tests/unit/with_dbs/**/test_clust*.py
    • computation.py
    • db.py:97
    • diagnostics.py:25
    • director_v2.py:19
    • director/module_setup.py:22
    • email.py:24
    • exporter/module_setup.py:21
    • garbage_collector.py:12
    • groups.py:21
    • scicrunch
    • login/module_setup.py:69
    • meta_modeling.py:23
    • products.py:102
    • projects/module_setup.py:58
    • publications.py:20 -> has NO TESTS!
    • redis.py:102
    • remote_debug.py:16
    • resource_manager/module_setup.py:21
    • rest.py:29
    • security.py:25
    • session.py:40
    • socketio/module_setup.py:17 -> NO TESTS
    • statics.py:186
    • storage.py:17
    • studies_access.py:283
    • studies_dispatcher/module_setup.py:18
    • tags.py:20
    • tracing.py:24
    • users.py:20
    • version_control.py:21
  • version_control.py:21
  • rm config-based boot
  • rm schemas and config modules
  • rm config files
  • rm config tests / replace config with comprehensive environs
  • rm trafaret dependency
  • Openapi changes? make openapi-specs, git commit ... and then make version-*)
  • Database migration script? cd packages/postgres-database, make setup-commit, sc-pg review -m "my changes"
  • Unit tests for the changes exist
  • Runs in the swarm
  • Documentation reflects the changes
  • New module? Add your github username to .github/CODEOWNERS

@codecov
Copy link

codecov bot commented Feb 15, 2022

Codecov Report

Merging #2836 (f152225) into master (4c35a9e) will increase coverage by 1.3%.
The diff coverage is 85.0%.

Impacted file tree graph

@@           Coverage Diff            @@
##           master   #2836     +/-   ##
========================================
+ Coverage    77.8%   79.1%   +1.3%     
========================================
  Files         674     659     -15     
  Lines       27352   27181    -171     
  Branches     3182    3147     -35     
========================================
+ Hits        21284   21510    +226     
+ Misses       5322    4933    -389     
+ Partials      746     738      -8     
Flag Coverage Δ
integrationtests 65.8% <71.0%> (+3.6%) ⬆️
unittests 74.6% <82.2%> (+0.2%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
...s/settings-library/src/settings_library/tracing.py 0.0% <0.0%> (ø)
...ings-library/src/settings_library/utils_session.py 0.0% <0.0%> (ø)
...er/src/simcore_service_webserver/catalog_models.py 88.8% <ø> (ø)
.../web/server/src/simcore_service_webserver/email.py 80.0% <ø> (-1.3%) ⬇️
...imcore_service_webserver/garbage_collector_core.py 68.2% <16.6%> (-2.0%) ⬇️
...es/web/server/src/simcore_service_webserver/cli.py 53.1% <28.5%> (+1.2%) ⬆️
...eb/server/src/simcore_service_webserver/tracing.py 50.0% <30.7%> (-11.2%) ⬇️
.../src/simcore_service_webserver/statics_handlers.py 34.7% <34.7%> (ø)
.../src/simcore_service_webserver/statics_settings.py 81.8% <42.8%> (-11.6%) ⬇️
...er/src/simcore_service_webserver/statics_events.py 44.4% <44.4%> (ø)
... and 114 more

@pcrespov pcrespov self-assigned this Feb 17, 2022
@pcrespov pcrespov added this to the R.Schumann milestone Feb 17, 2022
@pcrespov pcrespov added a:webserver issue related to the webserver service changelog:⚰️deprecation t:maintenance Some planned maintenance work labels Feb 19, 2022
@pcrespov pcrespov marked this pull request as ready for review February 19, 2022 21:33
@pcrespov pcrespov requested a review from GitHK as a code owner February 19, 2022 21:33
@pcrespov pcrespov changed the title ♻️✨ maintenance new settings (round 4) ♻️✨ maintenance new settings (final round) Feb 19, 2022
Copy link
Member

@sanderegg sanderegg left a comment

Choose a reason for hiding this comment

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

RIP trafaret! very nice work that will simplify a lot the development on the webserver! Thanks!

monkeypatch.setenv(
"RABBIT_PASSWORD", rabbit_settings.RABBIT_PASSWORD.get_secret_value()
)
monkeypatch.setenv("RABBIT_CHANNELS", json.dumps(rabbit_settings.RABBIT_CHANNELS))
Copy link
Member

Choose a reason for hiding this comment

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

minor: are these monkeypatch necessary? since the rabbit_settings are already setting them? but the port ok.

Copy link
Member Author

Choose a reason for hiding this comment

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

This was the design in place. The way I understood is:

  • start stack and wait until is up
  • wait until given service is responsive (e.g. redis, rabbit, etc)
  • fill settings to create a client for that service
    and then, there are two types of fixtures
  1. *_service guarantees services is up and running, and env vars to use it are in monkeypatched
  2. *_client guarantees services is up and running, and returns a client ready to interact with it

class URLPart(Enum):
EXCLUDE = auto()
OPTIONAL = auto()
REQUIRED = auto()
Copy link
Member

Choose a reason for hiding this comment

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

just wondering about this auto method.. just checked in the documentation. how does that work if we add another value? it has to be appended right? at least if the value goes somewhere?

Copy link
Member Author

Choose a reason for hiding this comment

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

it just adds a different value.
the way i use it is: if the enum is not going to be stored , then I just care that they are different and leave it to auto to choose them. If it is persisted, then I am the one settings the values explicitly

# NOTE app_settings.WEBSERVER_STUDIES_ACCESS_ENABLED did not apply
"studies_dispatcher": {"enabled": app_settings.WEBSERVER_STUDIES_DISPATCHER},
"studies_dispatcher": {
Copy link
Member

Choose a reason for hiding this comment

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

is this still needed without trafaret?

Copy link
Member Author

Choose a reason for hiding this comment

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

yes. what i did was moving studis_access into studies_dispatch. These utils here is simply to convert the configs in the tests into env-vars. It is not used in the code. There is an explanation about these utils in the description above under the tests section.

Copy link
Member

@mguidon mguidon left a comment

Choose a reason for hiding this comment

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

Outstanding refactoring work in all 5 PRs. Thanks!

Copy link
Contributor

@GitHK GitHK left a comment

Choose a reason for hiding this comment

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

Thanks for now. Will have a better look at it later in the future.

@pcrespov pcrespov merged commit bb60d87 into ITISFoundation:master Feb 21, 2022
@pcrespov pcrespov deleted the maintenance/new-settings-4 branch February 21, 2022 15:59
@mrnicegyu11
Copy link
Member

Note: This PR makes setting the Env-Var REST_SWAGGER_API_DOC_ENABLED necessary if the swaggerAPI docs are to be exposed

@mrnicegyu11 mrnicegyu11 changed the title ♻️✨ maintenance new settings (final round) ♻️✨ ⚠️ [DEVOPS] maintenance new settings (final round) Feb 23, 2022
@pcrespov
Copy link
Member Author

Note: This PR makes setting the Env-Var REST_SWAGGER_API_DOC_ENABLED necessary if the swaggerAPI docs are to be exposed

yes. @mrnicegyu11 check rules of the reverse proxy as well in case the /dev/doc is filtered out

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a:webserver issue related to the webserver service t:maintenance Some planned maintenance work
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants