From 7d52bf7e5195557ddf3439f097848f04e2f2ee5f Mon Sep 17 00:00:00 2001 From: Matus Drobuliak <60785969+matusdrobuliak66@users.noreply.github.com> Date: Mon, 4 Nov 2024 17:49:47 +0100 Subject: [PATCH 1/2] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20introduce=20webserver?= =?UTF-8?q?=204=20tests=20(#6663)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/ci-testing-deploy.yml | 46 +++++++++++++++++++ .../server/tests/unit/with_dbs/04/conftest.py | 15 ++++++ .../with_dbs/{01 => 04}/folders/conftest.py | 0 .../{01 => 04}/folders/test_folders.py | 0 .../test_resource_manager.py | 0 ...fications__db_comp_tasks_listening_task.py | 0 .../with_dbs/{01 => 04}/products/conftest.py | 0 .../{01 => 04}/products/test_products_db.py | 0 .../products/test_products_handlers.py | 0 .../{01 => 04}/products/test_products_rpc.py | 0 .../{01 => 04}/studies_dispatcher/conftest.py | 0 .../test_studies_dispatcher_handlers.py | 0 .../test_studies_dispatcher_projects.py | 0 .../test_studies_dispatcher_studies_access.py | 0 .../with_dbs/{01 => 04}/wallets/conftest.py | 0 .../{01 => 04}/wallets/payments/conftest.py | 0 .../wallets/payments/test_payments.py | 0 .../wallets/payments/test_payments_methods.py | 0 .../wallets/payments/test_payments_rpc.py | 0 .../{01 => 04}/wallets/test_wallets.py | 0 .../{01 => 04}/wallets/test_wallets_groups.py | 0 .../{01 => 04}/workspaces/conftest.py | 0 .../{01 => 04}/workspaces/test_workspaces.py | 0 ...t_workspaces__folders_and_projects_crud.py | 0 ...t_workspaces__list_projects_full_search.py | 0 ...ces__moving_projects_between_workspaces.py | 0 .../workspaces/test_workspaces_groups.py | 0 27 files changed, 61 insertions(+) create mode 100644 services/web/server/tests/unit/with_dbs/04/conftest.py rename services/web/server/tests/unit/with_dbs/{01 => 04}/folders/conftest.py (100%) rename services/web/server/tests/unit/with_dbs/{01 => 04}/folders/test_folders.py (100%) rename services/web/server/tests/unit/with_dbs/{01 => 04}/garbage_collector/test_resource_manager.py (100%) rename services/web/server/tests/unit/with_dbs/{01 => 04}/notifications/test_notifications__db_comp_tasks_listening_task.py (100%) rename services/web/server/tests/unit/with_dbs/{01 => 04}/products/conftest.py (100%) rename services/web/server/tests/unit/with_dbs/{01 => 04}/products/test_products_db.py (100%) rename services/web/server/tests/unit/with_dbs/{01 => 04}/products/test_products_handlers.py (100%) rename services/web/server/tests/unit/with_dbs/{01 => 04}/products/test_products_rpc.py (100%) rename services/web/server/tests/unit/with_dbs/{01 => 04}/studies_dispatcher/conftest.py (100%) rename services/web/server/tests/unit/with_dbs/{01 => 04}/studies_dispatcher/test_studies_dispatcher_handlers.py (100%) rename services/web/server/tests/unit/with_dbs/{01 => 04}/studies_dispatcher/test_studies_dispatcher_projects.py (100%) rename services/web/server/tests/unit/with_dbs/{01 => 04}/studies_dispatcher/test_studies_dispatcher_studies_access.py (100%) rename services/web/server/tests/unit/with_dbs/{01 => 04}/wallets/conftest.py (100%) rename services/web/server/tests/unit/with_dbs/{01 => 04}/wallets/payments/conftest.py (100%) rename services/web/server/tests/unit/with_dbs/{01 => 04}/wallets/payments/test_payments.py (100%) rename services/web/server/tests/unit/with_dbs/{01 => 04}/wallets/payments/test_payments_methods.py (100%) rename services/web/server/tests/unit/with_dbs/{01 => 04}/wallets/payments/test_payments_rpc.py (100%) rename services/web/server/tests/unit/with_dbs/{01 => 04}/wallets/test_wallets.py (100%) rename services/web/server/tests/unit/with_dbs/{01 => 04}/wallets/test_wallets_groups.py (100%) rename services/web/server/tests/unit/with_dbs/{01 => 04}/workspaces/conftest.py (100%) rename services/web/server/tests/unit/with_dbs/{01 => 04}/workspaces/test_workspaces.py (100%) rename services/web/server/tests/unit/with_dbs/{01 => 04}/workspaces/test_workspaces__folders_and_projects_crud.py (100%) rename services/web/server/tests/unit/with_dbs/{01 => 04}/workspaces/test_workspaces__list_projects_full_search.py (100%) rename services/web/server/tests/unit/with_dbs/{01 => 04}/workspaces/test_workspaces__moving_projects_between_workspaces.py (100%) rename services/web/server/tests/unit/with_dbs/{01 => 04}/workspaces/test_workspaces_groups.py (100%) diff --git a/.github/workflows/ci-testing-deploy.yml b/.github/workflows/ci-testing-deploy.yml index 38163963d6d..34f17a07d85 100644 --- a/.github/workflows/ci-testing-deploy.yml +++ b/.github/workflows/ci-testing-deploy.yml @@ -450,6 +450,51 @@ jobs: with: token: ${{ secrets.CODECOV_TOKEN }} + unit-test-webserver-04: + needs: changes + if: ${{ needs.changes.outputs.webserver == 'true' || github.event_name == 'push' }} + timeout-minutes: 25 # if this timeout gets too small, then split the tests + name: "[unit] webserver 04" + runs-on: ${{ matrix.os }} + strategy: + matrix: + python: ["3.11"] + os: [ubuntu-22.04] + fail-fast: false + steps: + - uses: actions/checkout@v4 + - name: setup docker buildx + id: buildx + uses: docker/setup-buildx-action@v3 + with: + driver: docker-container + - name: setup python environment + uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python }} + - name: install uv + uses: astral-sh/setup-uv@v3 + with: + version: "0.4.x" + enable-cache: false + cache-dependency-glob: "**/web/server/requirements/ci.txt" + - name: show system version + run: ./ci/helpers/show_system_versions.bash + - name: install webserver + run: ./ci/github/unit-testing/webserver.bash install + - name: test + run: ./ci/github/unit-testing/webserver.bash test_with_db 04 + - uses: codecov/codecov-action@v4.6.0 + env: + CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} + with: + flags: unittests #optional + - name: Upload test results to Codecov + if: ${{ !cancelled() }} + uses: codecov/test-results-action@v1 + with: + token: ${{ secrets.CODECOV_TOKEN }} + unit-test-storage: needs: changes if: ${{ needs.changes.outputs.storage == 'true' || github.event_name == 'push' }} @@ -1875,6 +1920,7 @@ jobs: unit-test-webserver-01, unit-test-webserver-02, unit-test-webserver-03, + unit-test-webserver-04, ] runs-on: ubuntu-latest steps: diff --git a/services/web/server/tests/unit/with_dbs/04/conftest.py b/services/web/server/tests/unit/with_dbs/04/conftest.py new file mode 100644 index 00000000000..0d136f20637 --- /dev/null +++ b/services/web/server/tests/unit/with_dbs/04/conftest.py @@ -0,0 +1,15 @@ +# pylint: disable=redefined-outer-name +# pylint: disable=unused-argument +# pylint: disable=unused-variable + + +import pytest + + +@pytest.fixture +def app_environment( + app_environment: dict[str, str], monkeypatch: pytest.MonkeyPatch +) -> dict[str, str]: + # NOTE: overrides app_environment + monkeypatch.setenv("WEBSERVER_GARBAGE_COLLECTOR", "null") + return app_environment | {"WEBSERVER_GARBAGE_COLLECTOR": "null"} diff --git a/services/web/server/tests/unit/with_dbs/01/folders/conftest.py b/services/web/server/tests/unit/with_dbs/04/folders/conftest.py similarity index 100% rename from services/web/server/tests/unit/with_dbs/01/folders/conftest.py rename to services/web/server/tests/unit/with_dbs/04/folders/conftest.py diff --git a/services/web/server/tests/unit/with_dbs/01/folders/test_folders.py b/services/web/server/tests/unit/with_dbs/04/folders/test_folders.py similarity index 100% rename from services/web/server/tests/unit/with_dbs/01/folders/test_folders.py rename to services/web/server/tests/unit/with_dbs/04/folders/test_folders.py diff --git a/services/web/server/tests/unit/with_dbs/01/garbage_collector/test_resource_manager.py b/services/web/server/tests/unit/with_dbs/04/garbage_collector/test_resource_manager.py similarity index 100% rename from services/web/server/tests/unit/with_dbs/01/garbage_collector/test_resource_manager.py rename to services/web/server/tests/unit/with_dbs/04/garbage_collector/test_resource_manager.py diff --git a/services/web/server/tests/unit/with_dbs/01/notifications/test_notifications__db_comp_tasks_listening_task.py b/services/web/server/tests/unit/with_dbs/04/notifications/test_notifications__db_comp_tasks_listening_task.py similarity index 100% rename from services/web/server/tests/unit/with_dbs/01/notifications/test_notifications__db_comp_tasks_listening_task.py rename to services/web/server/tests/unit/with_dbs/04/notifications/test_notifications__db_comp_tasks_listening_task.py diff --git a/services/web/server/tests/unit/with_dbs/01/products/conftest.py b/services/web/server/tests/unit/with_dbs/04/products/conftest.py similarity index 100% rename from services/web/server/tests/unit/with_dbs/01/products/conftest.py rename to services/web/server/tests/unit/with_dbs/04/products/conftest.py diff --git a/services/web/server/tests/unit/with_dbs/01/products/test_products_db.py b/services/web/server/tests/unit/with_dbs/04/products/test_products_db.py similarity index 100% rename from services/web/server/tests/unit/with_dbs/01/products/test_products_db.py rename to services/web/server/tests/unit/with_dbs/04/products/test_products_db.py diff --git a/services/web/server/tests/unit/with_dbs/01/products/test_products_handlers.py b/services/web/server/tests/unit/with_dbs/04/products/test_products_handlers.py similarity index 100% rename from services/web/server/tests/unit/with_dbs/01/products/test_products_handlers.py rename to services/web/server/tests/unit/with_dbs/04/products/test_products_handlers.py diff --git a/services/web/server/tests/unit/with_dbs/01/products/test_products_rpc.py b/services/web/server/tests/unit/with_dbs/04/products/test_products_rpc.py similarity index 100% rename from services/web/server/tests/unit/with_dbs/01/products/test_products_rpc.py rename to services/web/server/tests/unit/with_dbs/04/products/test_products_rpc.py diff --git a/services/web/server/tests/unit/with_dbs/01/studies_dispatcher/conftest.py b/services/web/server/tests/unit/with_dbs/04/studies_dispatcher/conftest.py similarity index 100% rename from services/web/server/tests/unit/with_dbs/01/studies_dispatcher/conftest.py rename to services/web/server/tests/unit/with_dbs/04/studies_dispatcher/conftest.py diff --git a/services/web/server/tests/unit/with_dbs/01/studies_dispatcher/test_studies_dispatcher_handlers.py b/services/web/server/tests/unit/with_dbs/04/studies_dispatcher/test_studies_dispatcher_handlers.py similarity index 100% rename from services/web/server/tests/unit/with_dbs/01/studies_dispatcher/test_studies_dispatcher_handlers.py rename to services/web/server/tests/unit/with_dbs/04/studies_dispatcher/test_studies_dispatcher_handlers.py diff --git a/services/web/server/tests/unit/with_dbs/01/studies_dispatcher/test_studies_dispatcher_projects.py b/services/web/server/tests/unit/with_dbs/04/studies_dispatcher/test_studies_dispatcher_projects.py similarity index 100% rename from services/web/server/tests/unit/with_dbs/01/studies_dispatcher/test_studies_dispatcher_projects.py rename to services/web/server/tests/unit/with_dbs/04/studies_dispatcher/test_studies_dispatcher_projects.py diff --git a/services/web/server/tests/unit/with_dbs/01/studies_dispatcher/test_studies_dispatcher_studies_access.py b/services/web/server/tests/unit/with_dbs/04/studies_dispatcher/test_studies_dispatcher_studies_access.py similarity index 100% rename from services/web/server/tests/unit/with_dbs/01/studies_dispatcher/test_studies_dispatcher_studies_access.py rename to services/web/server/tests/unit/with_dbs/04/studies_dispatcher/test_studies_dispatcher_studies_access.py diff --git a/services/web/server/tests/unit/with_dbs/01/wallets/conftest.py b/services/web/server/tests/unit/with_dbs/04/wallets/conftest.py similarity index 100% rename from services/web/server/tests/unit/with_dbs/01/wallets/conftest.py rename to services/web/server/tests/unit/with_dbs/04/wallets/conftest.py diff --git a/services/web/server/tests/unit/with_dbs/01/wallets/payments/conftest.py b/services/web/server/tests/unit/with_dbs/04/wallets/payments/conftest.py similarity index 100% rename from services/web/server/tests/unit/with_dbs/01/wallets/payments/conftest.py rename to services/web/server/tests/unit/with_dbs/04/wallets/payments/conftest.py diff --git a/services/web/server/tests/unit/with_dbs/01/wallets/payments/test_payments.py b/services/web/server/tests/unit/with_dbs/04/wallets/payments/test_payments.py similarity index 100% rename from services/web/server/tests/unit/with_dbs/01/wallets/payments/test_payments.py rename to services/web/server/tests/unit/with_dbs/04/wallets/payments/test_payments.py diff --git a/services/web/server/tests/unit/with_dbs/01/wallets/payments/test_payments_methods.py b/services/web/server/tests/unit/with_dbs/04/wallets/payments/test_payments_methods.py similarity index 100% rename from services/web/server/tests/unit/with_dbs/01/wallets/payments/test_payments_methods.py rename to services/web/server/tests/unit/with_dbs/04/wallets/payments/test_payments_methods.py diff --git a/services/web/server/tests/unit/with_dbs/01/wallets/payments/test_payments_rpc.py b/services/web/server/tests/unit/with_dbs/04/wallets/payments/test_payments_rpc.py similarity index 100% rename from services/web/server/tests/unit/with_dbs/01/wallets/payments/test_payments_rpc.py rename to services/web/server/tests/unit/with_dbs/04/wallets/payments/test_payments_rpc.py diff --git a/services/web/server/tests/unit/with_dbs/01/wallets/test_wallets.py b/services/web/server/tests/unit/with_dbs/04/wallets/test_wallets.py similarity index 100% rename from services/web/server/tests/unit/with_dbs/01/wallets/test_wallets.py rename to services/web/server/tests/unit/with_dbs/04/wallets/test_wallets.py diff --git a/services/web/server/tests/unit/with_dbs/01/wallets/test_wallets_groups.py b/services/web/server/tests/unit/with_dbs/04/wallets/test_wallets_groups.py similarity index 100% rename from services/web/server/tests/unit/with_dbs/01/wallets/test_wallets_groups.py rename to services/web/server/tests/unit/with_dbs/04/wallets/test_wallets_groups.py diff --git a/services/web/server/tests/unit/with_dbs/01/workspaces/conftest.py b/services/web/server/tests/unit/with_dbs/04/workspaces/conftest.py similarity index 100% rename from services/web/server/tests/unit/with_dbs/01/workspaces/conftest.py rename to services/web/server/tests/unit/with_dbs/04/workspaces/conftest.py diff --git a/services/web/server/tests/unit/with_dbs/01/workspaces/test_workspaces.py b/services/web/server/tests/unit/with_dbs/04/workspaces/test_workspaces.py similarity index 100% rename from services/web/server/tests/unit/with_dbs/01/workspaces/test_workspaces.py rename to services/web/server/tests/unit/with_dbs/04/workspaces/test_workspaces.py diff --git a/services/web/server/tests/unit/with_dbs/01/workspaces/test_workspaces__folders_and_projects_crud.py b/services/web/server/tests/unit/with_dbs/04/workspaces/test_workspaces__folders_and_projects_crud.py similarity index 100% rename from services/web/server/tests/unit/with_dbs/01/workspaces/test_workspaces__folders_and_projects_crud.py rename to services/web/server/tests/unit/with_dbs/04/workspaces/test_workspaces__folders_and_projects_crud.py diff --git a/services/web/server/tests/unit/with_dbs/01/workspaces/test_workspaces__list_projects_full_search.py b/services/web/server/tests/unit/with_dbs/04/workspaces/test_workspaces__list_projects_full_search.py similarity index 100% rename from services/web/server/tests/unit/with_dbs/01/workspaces/test_workspaces__list_projects_full_search.py rename to services/web/server/tests/unit/with_dbs/04/workspaces/test_workspaces__list_projects_full_search.py diff --git a/services/web/server/tests/unit/with_dbs/01/workspaces/test_workspaces__moving_projects_between_workspaces.py b/services/web/server/tests/unit/with_dbs/04/workspaces/test_workspaces__moving_projects_between_workspaces.py similarity index 100% rename from services/web/server/tests/unit/with_dbs/01/workspaces/test_workspaces__moving_projects_between_workspaces.py rename to services/web/server/tests/unit/with_dbs/04/workspaces/test_workspaces__moving_projects_between_workspaces.py diff --git a/services/web/server/tests/unit/with_dbs/01/workspaces/test_workspaces_groups.py b/services/web/server/tests/unit/with_dbs/04/workspaces/test_workspaces_groups.py similarity index 100% rename from services/web/server/tests/unit/with_dbs/01/workspaces/test_workspaces_groups.py rename to services/web/server/tests/unit/with_dbs/04/workspaces/test_workspaces_groups.py From dac26e1915a946e07f0ce1ba153be09a2918da70 Mon Sep 17 00:00:00 2001 From: Matus Drobuliak <60785969+matusdrobuliak66@users.noreply.github.com> Date: Mon, 4 Nov 2024 18:36:51 +0100 Subject: [PATCH 2/2] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20Refactor=20RUT=20(rena?= =?UTF-8?q?ming/rearranging/error=20handling)=20(#6648)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../resource_usage_tracker/errors.py | 9 - .../core/settings.py | 2 +- .../resource-usage-tracker/docker/boot.sh | 2 +- .../api/rest/_health.py | 2 +- .../api/rest/_resource_tracker.py | 16 +- .../api/rest/dependencies.py | 2 +- .../api/rpc/_resource_tracker.py | 37 +- .../api/rpc/routes.py | 2 +- .../core/application.py | 51 +- .../core/errors.py | 20 - .../{modules => exceptions}/__init__.py | 0 .../exceptions/errors.py | 70 +++ .../exceptions/handlers/__init__.py | 20 + .../exceptions/handlers/_http_error.py | 61 +++ .../{web_main.py => main.py} | 0 ...transactions.py => credit_transactions.py} | 0 ...cker_pricing_plans.py => pricing_plans.py} | 0 ...ng_unit_costs.py => pricing_unit_costs.py} | 0 ...cker_pricing_units.py => pricing_units.py} | 0 ...racker_service_runs.py => service_runs.py} | 0 .../modules/prometheus.py | 73 --- ...ckground_task_periodic_heartbeat_check.py} | 10 +- ...und_task_periodic_heartbeat_check_setup.py | 74 +++ ...transactions.py => credit_transactions.py} | 8 +- .../services/modules/__init__.py | 0 .../{ => services}/modules/db/__init__.py | 0 .../modules/db/repositories/__init__.py | 0 .../modules/db/repositories/_base.py | 0 .../db/repositories/resource_tracker.py | 66 ++- .../{ => services}/modules/rabbitmq.py | 2 +- .../{ => services}/modules/redis.py | 2 +- .../{ => services}/modules/s3.py | 2 +- ...cker_pricing_plans.py => pricing_plans.py} | 17 +- ...cker_pricing_units.py => pricing_units.py} | 2 +- .../process_message_running_service.py} | 6 +- .../process_message_running_service_setup.py} | 23 +- ...racker_service_runs.py => service_runs.py} | 9 +- .../utils.py} | 0 .../tests/unit/api_rest/test_api_meta.py | 4 +- .../tests/unit/conftest.py | 1 + .../tests/unit/modules/test_rabbitmq.py | 4 +- .../tests/unit/modules/test_redis.py | 6 +- .../tests/unit/test_computation_of_credits.py | 2 +- .../unit/{test_web_main.py => test_main.py} | 2 +- .../tests/unit/with_dbs/conftest.py | 6 +- .../list_of_prometheus_mocked_outputs.json | 496 ------------------ ...i_resource_tracker_service_runs__export.py | 4 +- ...rce_tracker_service_runs__list_billable.py | 7 +- ...ckground_task_periodic_heartbeat_check.py} | 12 +- .../with_dbs/test_process_rabbitmq_message.py | 4 +- ...t_process_rabbitmq_message_with_billing.py | 4 +- ...ss_rabbitmq_message_with_billing_cost_0.py | 4 +- .../_pricing_plans_admin_handlers.py | 10 +- 53 files changed, 369 insertions(+), 785 deletions(-) delete mode 100644 packages/service-library/src/servicelib/rabbitmq/rpc_interfaces/resource_usage_tracker/errors.py delete mode 100644 services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/core/errors.py rename services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/{modules => exceptions}/__init__.py (100%) create mode 100644 services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/exceptions/errors.py create mode 100644 services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/exceptions/handlers/__init__.py create mode 100644 services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/exceptions/handlers/_http_error.py rename services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/{web_main.py => main.py} (100%) rename services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/models/{resource_tracker_credit_transactions.py => credit_transactions.py} (100%) rename services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/models/{resource_tracker_pricing_plans.py => pricing_plans.py} (100%) rename services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/models/{resource_tracker_pricing_unit_costs.py => pricing_unit_costs.py} (100%) rename services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/models/{resource_tracker_pricing_units.py => pricing_units.py} (100%) rename services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/models/{resource_tracker_service_runs.py => service_runs.py} (100%) delete mode 100644 services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/modules/prometheus.py rename services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/{resource_tracker_background_task.py => services/background_task_periodic_heartbeat_check.py} (94%) create mode 100644 services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/services/background_task_periodic_heartbeat_check_setup.py rename services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/services/{resource_tracker_credit_transactions.py => credit_transactions.py} (89%) create mode 100644 services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/services/modules/__init__.py rename services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/{ => services}/modules/db/__init__.py (100%) rename services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/{ => services}/modules/db/repositories/__init__.py (100%) rename services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/{ => services}/modules/db/repositories/_base.py (100%) rename services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/{ => services}/modules/db/repositories/resource_tracker.py (96%) rename services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/{ => services}/modules/rabbitmq.py (97%) rename services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/{ => services}/modules/redis.py (94%) rename services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/{ => services}/modules/s3.py (97%) rename services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/services/{resource_tracker_pricing_plans.py => pricing_plans.py} (93%) rename services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/services/{resource_tracker_pricing_units.py => pricing_units.py} (97%) rename services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/{resource_tracker_process_messages.py => services/process_message_running_service.py} (98%) rename services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/{resource_tracker.py => services/process_message_running_service_setup.py} (61%) rename services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/services/{resource_tracker_service_runs.py => service_runs.py} (96%) rename services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/{resource_tracker_utils.py => services/utils.py} (100%) rename services/resource-usage-tracker/tests/unit/{test_web_main.py => test_main.py} (75%) delete mode 100644 services/resource-usage-tracker/tests/unit/with_dbs/data/list_of_prometheus_mocked_outputs.json rename services/resource-usage-tracker/tests/unit/with_dbs/{test_background_task.py => test_background_task_periodic_heartbeat_check.py} (95%) diff --git a/packages/service-library/src/servicelib/rabbitmq/rpc_interfaces/resource_usage_tracker/errors.py b/packages/service-library/src/servicelib/rabbitmq/rpc_interfaces/resource_usage_tracker/errors.py deleted file mode 100644 index 44549841802..00000000000 --- a/packages/service-library/src/servicelib/rabbitmq/rpc_interfaces/resource_usage_tracker/errors.py +++ /dev/null @@ -1,9 +0,0 @@ -from pydantic.errors import PydanticErrorMixin - - -class ResourceUsageTrackerRuntimeError(PydanticErrorMixin, RuntimeError): - msg_template: str = "Resource-usage-tracker unexpected error" - - -class CustomResourceUsageTrackerError(ResourceUsageTrackerRuntimeError): - msg_template: str = "Error: {msg}" diff --git a/services/dynamic-sidecar/src/simcore_service_dynamic_sidecar/core/settings.py b/services/dynamic-sidecar/src/simcore_service_dynamic_sidecar/core/settings.py index cf6f636622a..214d51ad11b 100644 --- a/services/dynamic-sidecar/src/simcore_service_dynamic_sidecar/core/settings.py +++ b/services/dynamic-sidecar/src/simcore_service_dynamic_sidecar/core/settings.py @@ -135,7 +135,7 @@ class ApplicationSettings(BaseCustomSettings, MixinLoggingSettings): description="Enables local development log format. WARNING: make sure it is disabled if you want to have structured logs!", ) DY_SIDECAR_LOG_FILTER_MAPPING: dict[LoggerName, list[MessageSubstring]] = Field( - default={}, + default_factory=dict, env=["DY_SIDECAR_LOG_FILTER_MAPPING", "LOG_FILTER_MAPPING"], description="is a dictionary that maps specific loggers (such as 'uvicorn.access' or 'gunicorn.access') to a list of log message patterns that should be filtered out.", ) diff --git a/services/resource-usage-tracker/docker/boot.sh b/services/resource-usage-tracker/docker/boot.sh index d6e54f8f347..d3aa7606d03 100755 --- a/services/resource-usage-tracker/docker/boot.sh +++ b/services/resource-usage-tracker/docker/boot.sh @@ -56,7 +56,7 @@ if [ "${SC_BOOT_MODE}" = "debug" ]; then --log-level \"${SERVER_LOG_LEVEL}\" " else - exec uvicorn simcore_service_resource_usage_tracker.web_main:the_app \ + exec uvicorn simcore_service_resource_usage_tracker.main:the_app \ --host 0.0.0.0 \ --log-level "${SERVER_LOG_LEVEL}" fi diff --git a/services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/api/rest/_health.py b/services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/api/rest/_health.py index c49f8e218dd..720d51b3ad5 100644 --- a/services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/api/rest/_health.py +++ b/services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/api/rest/_health.py @@ -7,7 +7,7 @@ from models_library.errors import RABBITMQ_CLIENT_UNHEALTHY_MSG from servicelib.rabbitmq import RabbitMQClient -from ...modules.rabbitmq import get_rabbitmq_client_from_request +from ...services.modules.rabbitmq import get_rabbitmq_client_from_request logger = logging.getLogger(__name__) diff --git a/services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/api/rest/_resource_tracker.py b/services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/api/rest/_resource_tracker.py index c12acad3d49..fc20977e3aa 100644 --- a/services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/api/rest/_resource_tracker.py +++ b/services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/api/rest/_resource_tracker.py @@ -12,11 +12,7 @@ ) from models_library.resource_tracker import CreditTransactionId -from ...services import ( - resource_tracker_credit_transactions, - resource_tracker_pricing_plans, - resource_tracker_pricing_units, -) +from ...services import credit_transactions, pricing_plans, pricing_units _logger = logging.getLogger(__name__) @@ -38,9 +34,7 @@ async def get_credit_transactions_sum( wallet_total_credits: Annotated[ WalletTotalCredits, - Depends( - resource_tracker_credit_transactions.sum_credit_transactions_by_product_and_wallet - ), + Depends(credit_transactions.sum_credit_transactions_by_product_and_wallet), ], ): return wallet_total_credits @@ -56,7 +50,7 @@ async def get_credit_transactions_sum( async def create_credit_transaction( transaction_id: Annotated[ CreditTransactionId, - Depends(resource_tracker_credit_transactions.create_credit_transaction), + Depends(credit_transactions.create_credit_transaction), ], ): return {"credit_transaction_id": transaction_id} @@ -77,7 +71,7 @@ async def create_credit_transaction( async def get_service_default_pricing_plan( service_pricing_plans: Annotated[ PricingPlanGet, - Depends(resource_tracker_pricing_plans.get_service_default_pricing_plan), + Depends(pricing_plans.get_service_default_pricing_plan), ], ): return service_pricing_plans @@ -93,7 +87,7 @@ async def get_service_default_pricing_plan( async def get_pricing_plan_unit( pricing_unit: Annotated[ PricingUnitGet, - Depends(resource_tracker_pricing_units.get_pricing_unit), + Depends(pricing_units.get_pricing_unit), ] ): return pricing_unit diff --git a/services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/api/rest/dependencies.py b/services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/api/rest/dependencies.py index b005829b011..49ce9523cfe 100644 --- a/services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/api/rest/dependencies.py +++ b/services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/api/rest/dependencies.py @@ -12,7 +12,7 @@ from servicelib.fastapi.dependencies import get_app, get_reverse_url_mapper from sqlalchemy.ext.asyncio import AsyncEngine -from ...modules.db.repositories._base import BaseRepository +from ...services.modules.db.repositories._base import BaseRepository logger = logging.getLogger(__name__) diff --git a/services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/api/rpc/_resource_tracker.py b/services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/api/rpc/_resource_tracker.py index cae70b1152c..d7e9a5ca74d 100644 --- a/services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/api/rpc/_resource_tracker.py +++ b/services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/api/rpc/_resource_tracker.py @@ -26,16 +26,13 @@ from models_library.wallets import WalletID from pydantic import AnyUrl from servicelib.rabbitmq import RPCRouter -from servicelib.rabbitmq.rpc_interfaces.resource_usage_tracker.errors import ( - CustomResourceUsageTrackerError, -) from ...core.settings import ApplicationSettings -from ...modules.db.repositories.resource_tracker import ResourceTrackerRepository -from ...modules.s3 import get_s3_client -from ...services import resource_tracker_pricing_plans as pricing_plans -from ...services import resource_tracker_pricing_units as pricing_units -from ...services import resource_tracker_service_runs as service_runs +from ...services import pricing_plans, pricing_units, service_runs +from ...services.modules.db.repositories.resource_tracker import ( + ResourceTrackerRepository, +) +from ...services.modules.s3 import get_s3_client router = RPCRouter() @@ -43,7 +40,7 @@ ## Service runs -@router.expose(reraise_if_error_type=(CustomResourceUsageTrackerError,)) +@router.expose(reraise_if_error_type=()) async def get_service_run_page( app: FastAPI, *, @@ -69,7 +66,7 @@ async def get_service_run_page( ) -@router.expose(reraise_if_error_type=(CustomResourceUsageTrackerError,)) +@router.expose(reraise_if_error_type=()) async def export_service_runs( app: FastAPI, *, @@ -98,7 +95,7 @@ async def export_service_runs( ) -@router.expose(reraise_if_error_type=(CustomResourceUsageTrackerError,)) +@router.expose(reraise_if_error_type=()) async def get_osparc_credits_aggregated_usages_page( app: FastAPI, *, @@ -127,7 +124,7 @@ async def get_osparc_credits_aggregated_usages_page( ## Pricing plans -@router.expose(reraise_if_error_type=(CustomResourceUsageTrackerError,)) +@router.expose(reraise_if_error_type=()) async def get_pricing_plan( app: FastAPI, *, @@ -141,7 +138,7 @@ async def get_pricing_plan( ) -@router.expose(reraise_if_error_type=(CustomResourceUsageTrackerError,)) +@router.expose(reraise_if_error_type=()) async def list_pricing_plans( app: FastAPI, *, @@ -153,7 +150,7 @@ async def list_pricing_plans( ) -@router.expose(reraise_if_error_type=(CustomResourceUsageTrackerError,)) +@router.expose(reraise_if_error_type=()) async def create_pricing_plan( app: FastAPI, *, @@ -165,7 +162,7 @@ async def create_pricing_plan( ) -@router.expose(reraise_if_error_type=(CustomResourceUsageTrackerError,)) +@router.expose(reraise_if_error_type=()) async def update_pricing_plan( app: FastAPI, *, @@ -182,7 +179,7 @@ async def update_pricing_plan( ## Pricing units -@router.expose(reraise_if_error_type=(CustomResourceUsageTrackerError,)) +@router.expose(reraise_if_error_type=()) async def get_pricing_unit( app: FastAPI, *, @@ -198,7 +195,7 @@ async def get_pricing_unit( ) -@router.expose(reraise_if_error_type=(CustomResourceUsageTrackerError,)) +@router.expose(reraise_if_error_type=()) async def create_pricing_unit( app: FastAPI, *, @@ -212,7 +209,7 @@ async def create_pricing_unit( ) -@router.expose(reraise_if_error_type=(CustomResourceUsageTrackerError,)) +@router.expose(reraise_if_error_type=()) async def update_pricing_unit( app: FastAPI, *, @@ -229,7 +226,7 @@ async def update_pricing_unit( ## Pricing plan to service -@router.expose(reraise_if_error_type=(CustomResourceUsageTrackerError,)) +@router.expose(reraise_if_error_type=()) async def list_connected_services_to_pricing_plan_by_pricing_plan( app: FastAPI, *, @@ -246,7 +243,7 @@ async def list_connected_services_to_pricing_plan_by_pricing_plan( return output -@router.expose(reraise_if_error_type=(CustomResourceUsageTrackerError,)) +@router.expose(reraise_if_error_type=()) async def connect_service_to_pricing_plan( app: FastAPI, *, diff --git a/services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/api/rpc/routes.py b/services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/api/rpc/routes.py index 3cd6220b9e7..c15175e2564 100644 --- a/services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/api/rpc/routes.py +++ b/services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/api/rpc/routes.py @@ -4,7 +4,7 @@ ) from servicelib.rabbitmq import RPCRouter -from ...modules.rabbitmq import get_rabbitmq_rpc_server +from ...services.modules.rabbitmq import get_rabbitmq_rpc_server from . import _resource_tracker ROUTERS: list[RPCRouter] = [ diff --git a/services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/core/application.py b/services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/core/application.py index a97db0170ae..34db96d40ee 100644 --- a/services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/core/application.py +++ b/services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/core/application.py @@ -2,13 +2,7 @@ from fastapi import FastAPI from servicelib.fastapi.openapi import override_fastapi_openapi_method -from servicelib.fastapi.prometheus_instrumentation import ( - setup_prometheus_instrumentation, -) from servicelib.fastapi.tracing import setup_tracing -from servicelib.rabbitmq.rpc_interfaces.resource_usage_tracker.errors import ( - CustomResourceUsageTrackerError, -) from .._meta import ( API_VERSION, @@ -20,12 +14,17 @@ ) from ..api.rest.routes import setup_api_routes from ..api.rpc.routes import setup_rpc_api_routes -from ..modules.db import setup as setup_db -from ..modules.rabbitmq import setup as setup_rabbitmq -from ..modules.redis import setup as setup_redis -from ..modules.s3 import setup as setup_s3 -from ..resource_tracker import setup as setup_resource_tracker -from .errors import http404_error_handler +from ..exceptions.handlers import setup_exception_handlers +from ..services.background_task_periodic_heartbeat_check_setup import ( + setup as setup_background_task_periodic_heartbeat_check, +) +from ..services.modules.db import setup as setup_db +from ..services.modules.rabbitmq import setup as setup_rabbitmq +from ..services.modules.redis import setup as setup_redis +from ..services.modules.s3 import setup as setup_s3 +from ..services.process_message_running_service_setup import ( + setup as setup_process_message_running_service, +) from .settings import ApplicationSettings _logger = logging.getLogger(__name__) @@ -52,18 +51,6 @@ def create_app(settings: ApplicationSettings) -> FastAPI: # PLUGINS SETUP setup_api_routes(app) - if app.state.settings.RESOURCE_USAGE_TRACKER_PROMETHEUS_INSTRUMENTATION_ENABLED: - setup_prometheus_instrumentation(app) - if app.state.settings.RESOURCE_USAGE_TRACKER_TRACING: - setup_tracing( - app, - app.state.settings.RESOURCE_USAGE_TRACKER_TRACING, - app.state.settings.APP_NAME, - ) - - # ERROR HANDLERS - app.add_exception_handler(CustomResourceUsageTrackerError, http404_error_handler) - if settings.RESOURCE_USAGE_TRACKER_POSTGRES: setup_db(app) setup_redis(app) @@ -72,8 +59,20 @@ def create_app(settings: ApplicationSettings) -> FastAPI: # Needed for CSV export functionality setup_s3(app) - setup_resource_tracker(app) - setup_rpc_api_routes(app) + setup_rpc_api_routes(app) # Requires Rabbit, S3 + setup_background_task_periodic_heartbeat_check(app) # Requires Redis, DB + + setup_process_message_running_service(app) # Requires Rabbit + + if app.state.settings.RESOURCE_USAGE_TRACKER_TRACING: + setup_tracing( + app, + app.state.settings.RESOURCE_USAGE_TRACKER_TRACING, + app.state.settings.APP_NAME, + ) + + # ERROR HANDLERS + setup_exception_handlers(app) # EVENTS async def _on_startup() -> None: diff --git a/services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/core/errors.py b/services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/core/errors.py deleted file mode 100644 index 298e63aef71..00000000000 --- a/services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/core/errors.py +++ /dev/null @@ -1,20 +0,0 @@ -from fastapi import Request, status -from fastapi.responses import JSONResponse -from servicelib.rabbitmq.rpc_interfaces.resource_usage_tracker.errors import ( - CustomResourceUsageTrackerError, - ResourceUsageTrackerRuntimeError, -) - - -class ConfigurationError(ResourceUsageTrackerRuntimeError): - msg_template: str = "Application misconfiguration: {msg}" - - -def http404_error_handler( - request: Request, # pylint: disable=unused-argument - error: CustomResourceUsageTrackerError, -) -> JSONResponse: - return JSONResponse( - status_code=status.HTTP_404_NOT_FOUND, - content={"message": f"{error.msg_template}"}, - ) diff --git a/services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/modules/__init__.py b/services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/exceptions/__init__.py similarity index 100% rename from services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/modules/__init__.py rename to services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/exceptions/__init__.py diff --git a/services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/exceptions/errors.py b/services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/exceptions/errors.py new file mode 100644 index 00000000000..533bec1b114 --- /dev/null +++ b/services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/exceptions/errors.py @@ -0,0 +1,70 @@ +from models_library.errors_classes import OsparcErrorMixin + + +class ResourceUsageTrackerBaseError(OsparcErrorMixin, Exception): + msg_template = "Resource usage Tracker Service Error" + + +class ConfigurationError(ResourceUsageTrackerBaseError): + ... + + +### NotCreatedDBError + + +class NotCreatedDBError(ResourceUsageTrackerBaseError): + msg_template = "Data was not inserted to the DB. Data: {data}" + + +class ServiceRunNotCreatedDBError(NotCreatedDBError): + ... + + +class CreditTransactionNotCreatedDBError(NotCreatedDBError): + ... + + +class PricingPlanNotCreatedDBError(NotCreatedDBError): + ... + + +class PricingUnitNotCreatedDBError(NotCreatedDBError): + ... + + +class PricingUnitCostNotCreatedDBError(NotCreatedDBError): + ... + + +class PricingPlanToServiceNotCreatedDBError(NotCreatedDBError): + ... + + +### DoesNotExistsDBError + + +class PricingPlanDoesNotExistsDBError(ResourceUsageTrackerBaseError): + msg_template = "Pricing plan {pricing_plan_id} does not exists" + + +class PricingPlanAndPricingUnitCombinationDoesNotExistsDBError( + ResourceUsageTrackerBaseError +): + msg_template = "Pricing plan {pricing_plan_id} and pricing unit {pricing_unit_id} does not exists in product {product_name}" + + +class PricingUnitCostDoesNotExistsDBError(ResourceUsageTrackerBaseError): + msg_template = "Pricing unit cost id {pricing_unit_cost_id} does not exists" + + +### NotFoundError + + +class RutNotFoundError(ResourceUsageTrackerBaseError): + ... + + +class PricingPlanNotFoundForServiceError(RutNotFoundError): + msg_template = ( + "Pricing plan not found for service key {service_key} version {service_version}" + ) diff --git a/services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/exceptions/handlers/__init__.py b/services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/exceptions/handlers/__init__.py new file mode 100644 index 00000000000..8be40a236cf --- /dev/null +++ b/services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/exceptions/handlers/__init__.py @@ -0,0 +1,20 @@ +from fastapi import FastAPI, HTTPException, status + +from ..errors import RutNotFoundError +from ._http_error import ( + http404_error_handler, + http_error_handler, + make_http_error_handler_for_exception, +) + + +def setup_exception_handlers(app: FastAPI) -> None: + app.add_exception_handler(HTTPException, http_error_handler) + app.add_exception_handler(RutNotFoundError, http404_error_handler) + + app.add_exception_handler( + Exception, + make_http_error_handler_for_exception( + status.HTTP_500_INTERNAL_SERVER_ERROR, Exception + ), + ) diff --git a/services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/exceptions/handlers/_http_error.py b/services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/exceptions/handlers/_http_error.py new file mode 100644 index 00000000000..7879d27ae6f --- /dev/null +++ b/services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/exceptions/handlers/_http_error.py @@ -0,0 +1,61 @@ +import logging +from collections.abc import Callable +from typing import Awaitable + +from fastapi import HTTPException, Request, status +from fastapi.encoders import jsonable_encoder +from servicelib.logging_errors import create_troubleshotting_log_kwargs +from servicelib.status_codes_utils import is_5xx_server_error +from starlette.responses import JSONResponse + +from ...exceptions.errors import RutNotFoundError + +_logger = logging.getLogger(__name__) + + +async def http_error_handler(request: Request, exc: Exception) -> JSONResponse: + assert isinstance(exc, HTTPException) # nosec + + if is_5xx_server_error(exc.status_code): + _logger.exception( + **create_troubleshotting_log_kwargs( + "Unexpected error happened in the Resource Usage Tracker. Please contact support.", + error=exc, + error_context={ + "request": request, + "request.method": f"{request.method}", + }, + ) + ) + return JSONResponse( + content=jsonable_encoder({"errors": [exc.detail]}), status_code=exc.status_code + ) + + +def http404_error_handler( + _: Request, # pylint: disable=unused-argument + exc: RutNotFoundError, +) -> JSONResponse: + return JSONResponse( + status_code=status.HTTP_404_NOT_FOUND, + content={"message": f"{exc.msg_template}"}, + ) + + +def make_http_error_handler_for_exception( + status_code: int, exception_cls: type[BaseException] +) -> Callable[[Request, type[BaseException]], Awaitable[JSONResponse]]: + """ + Produces a handler for BaseException-type exceptions which converts them + into an error JSON response with a given status code + + SEE https://docs.python.org/3/library/exceptions.html#concrete-exceptions + """ + + async def _http_error_handler(_: Request, exc: type[BaseException]) -> JSONResponse: + assert isinstance(exc, exception_cls) # nosec + return JSONResponse( + content=jsonable_encoder({"errors": [str(exc)]}), status_code=status_code + ) + + return _http_error_handler diff --git a/services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/web_main.py b/services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/main.py similarity index 100% rename from services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/web_main.py rename to services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/main.py diff --git a/services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/models/resource_tracker_credit_transactions.py b/services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/models/credit_transactions.py similarity index 100% rename from services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/models/resource_tracker_credit_transactions.py rename to services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/models/credit_transactions.py diff --git a/services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/models/resource_tracker_pricing_plans.py b/services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/models/pricing_plans.py similarity index 100% rename from services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/models/resource_tracker_pricing_plans.py rename to services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/models/pricing_plans.py diff --git a/services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/models/resource_tracker_pricing_unit_costs.py b/services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/models/pricing_unit_costs.py similarity index 100% rename from services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/models/resource_tracker_pricing_unit_costs.py rename to services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/models/pricing_unit_costs.py diff --git a/services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/models/resource_tracker_pricing_units.py b/services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/models/pricing_units.py similarity index 100% rename from services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/models/resource_tracker_pricing_units.py rename to services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/models/pricing_units.py diff --git a/services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/models/resource_tracker_service_runs.py b/services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/models/service_runs.py similarity index 100% rename from services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/models/resource_tracker_service_runs.py rename to services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/models/service_runs.py diff --git a/services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/modules/prometheus.py b/services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/modules/prometheus.py deleted file mode 100644 index 5421c1e8749..00000000000 --- a/services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/modules/prometheus.py +++ /dev/null @@ -1,73 +0,0 @@ -import logging -from typing import cast - -import requests -from fastapi import FastAPI -from prometheus_api_client import PrometheusConnect # type: ignore[import-untyped] -from servicelib.logging_utils import log_context -from settings_library.prometheus import PrometheusSettings -from tenacity import retry -from tenacity.before_sleep import before_sleep_log -from tenacity.retry import retry_if_exception_type -from tenacity.stop import stop_after_delay -from tenacity.wait import wait_random_exponential - -from ..core.errors import ConfigurationError - -_logger = logging.getLogger(__name__) - - -@retry( - reraise=True, - retry=retry_if_exception_type(ConfigurationError), - before_sleep=before_sleep_log(_logger, logging.WARNING), - stop=stop_after_delay(120), - wait=wait_random_exponential(max=30), -) -async def _wait_till_prometheus_responsive(client: PrometheusConnect) -> bool: - try: - connected: bool = client.check_prometheus_connection() - return connected - except requests.ConnectionError as exc: - raise ConfigurationError( - msg="Prometheus API client could not be reached. TIP: check configuration" - ) from exc - - -async def create_client(settings: PrometheusSettings) -> PrometheusConnect: - with log_context(_logger, logging.INFO, msg="connect with prometheus"): - client = PrometheusConnect(f"{settings.api_url}") - if await _wait_till_prometheus_responsive(client) is False: - raise ConfigurationError( - msg="Prometheus API client could be reached but returned value is not expected. TIP: check configuration" - ) - return client - - -def setup(app: FastAPI) -> None: - async def on_startup() -> None: - app.state.prometheus_api_client = None - settings: PrometheusSettings | None = ( - app.state.settings.RESOURCE_USAGE_TRACKER_PROMETHEUS - ) - if not settings: - _logger.warning("Prometheus API client is de-activated in the settings") - return - - app.state.prometheus_api_client = await create_client(settings) - - async def on_shutdown() -> None: - if app.state.prometheus_api_client: - with log_context(_logger, logging.INFO, msg="disconnect with prometheus"): - del app.state.prometheus_api_client - - app.add_event_handler("startup", on_startup) - app.add_event_handler("shutdown", on_shutdown) - - -def get_prometheus_api_client(app: FastAPI) -> PrometheusConnect: - if not app.state.prometheus_api_client: - raise ConfigurationError( - msg="Prometheus API client is not available. Please check the configuration." - ) - return cast(PrometheusConnect, app.state.prometheus_api_client) diff --git a/services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/resource_tracker_background_task.py b/services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/services/background_task_periodic_heartbeat_check.py similarity index 94% rename from services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/resource_tracker_background_task.py rename to services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/services/background_task_periodic_heartbeat_check.py index 213dd706582..256b737d479 100644 --- a/services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/resource_tracker_background_task.py +++ b/services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/services/background_task_periodic_heartbeat_check.py @@ -11,13 +11,11 @@ ) from pydantic import NonNegativeInt, PositiveInt -from .core.settings import ApplicationSettings -from .models.resource_tracker_credit_transactions import ( - CreditTransactionCreditsAndStatusUpdate, -) -from .models.resource_tracker_service_runs import ServiceRunStoppedAtUpdate +from ..core.settings import ApplicationSettings +from ..models.credit_transactions import CreditTransactionCreditsAndStatusUpdate +from ..models.service_runs import ServiceRunStoppedAtUpdate from .modules.db.repositories.resource_tracker import ResourceTrackerRepository -from .resource_tracker_utils import compute_service_run_credit_costs, make_negative +from .utils import compute_service_run_credit_costs, make_negative _logger = logging.getLogger(__name__) diff --git a/services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/services/background_task_periodic_heartbeat_check_setup.py b/services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/services/background_task_periodic_heartbeat_check_setup.py new file mode 100644 index 00000000000..9f022e863e5 --- /dev/null +++ b/services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/services/background_task_periodic_heartbeat_check_setup.py @@ -0,0 +1,74 @@ +import logging +from collections.abc import Awaitable, Callable +from typing import TypedDict + +from fastapi import FastAPI +from servicelib.background_task import stop_periodic_task +from servicelib.logging_utils import log_catch, log_context +from servicelib.redis_utils import start_exclusive_periodic_task + +from ..core.settings import ApplicationSettings +from .background_task_periodic_heartbeat_check import ( + periodic_check_of_running_services_task, +) +from .modules.redis import get_redis_lock_client + +_logger = logging.getLogger(__name__) + + +_TASK_NAME_PERIODICALY_CHECK_RUNNING_SERVICES = "periodic_check_of_running_services" + + +class RutBackgroundTask(TypedDict): + name: str + task_func: Callable + + +def _on_app_startup(app: FastAPI) -> Callable[[], Awaitable[None]]: + async def _startup() -> None: + with log_context( + _logger, + logging.INFO, + msg="RUT background task Periodic check of running services startup..", + ), log_catch(_logger, reraise=False): + app_settings: ApplicationSettings = app.state.settings + + app.state.rut_background_task__periodic_check_of_running_services = None + + # Setup periodic task + exclusive_task = start_exclusive_periodic_task( + get_redis_lock_client(app), + periodic_check_of_running_services_task, + task_period=app_settings.RESOURCE_USAGE_TRACKER_MISSED_HEARTBEAT_INTERVAL_SEC, + retry_after=app_settings.RESOURCE_USAGE_TRACKER_MISSED_HEARTBEAT_INTERVAL_SEC, + task_name=_TASK_NAME_PERIODICALY_CHECK_RUNNING_SERVICES, + app=app, + ) + app.state.rut_background_task__periodic_check_of_running_services = ( + exclusive_task + ) + + return _startup + + +def _on_app_shutdown( + _app: FastAPI, +) -> Callable[[], Awaitable[None]]: + async def _stop() -> None: + with log_context( + _logger, + logging.INFO, + msg="RUT background tasks Periodic check of running services shutdown..", + ), log_catch(_logger, reraise=False): + assert _app # nosec + if _app.state.rut_background_task__periodic_check_of_running_services: + await stop_periodic_task( + _app.state.rut_background_task__periodic_check_of_running_services + ) + + return _stop + + +def setup(app: FastAPI) -> None: + app.add_event_handler("startup", _on_app_startup(app)) + app.add_event_handler("shutdown", _on_app_shutdown(app)) diff --git a/services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/services/resource_tracker_credit_transactions.py b/services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/services/credit_transactions.py similarity index 89% rename from services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/services/resource_tracker_credit_transactions.py rename to services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/services/credit_transactions.py index 8cd0bf9f647..0d4362e9748 100644 --- a/services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/services/resource_tracker_credit_transactions.py +++ b/services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/services/credit_transactions.py @@ -15,10 +15,10 @@ from servicelib.rabbitmq import RabbitMQClient from ..api.rest.dependencies import get_repository -from ..models.resource_tracker_credit_transactions import CreditTransactionCreate -from ..modules.db.repositories.resource_tracker import ResourceTrackerRepository -from ..modules.rabbitmq import get_rabbitmq_client_from_request -from ..resource_tracker_utils import sum_credit_transactions_and_publish_to_rabbitmq +from ..models.credit_transactions import CreditTransactionCreate +from .modules.db.repositories.resource_tracker import ResourceTrackerRepository +from .modules.rabbitmq import get_rabbitmq_client_from_request +from .utils import sum_credit_transactions_and_publish_to_rabbitmq async def create_credit_transaction( diff --git a/services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/services/modules/__init__.py b/services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/services/modules/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/modules/db/__init__.py b/services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/services/modules/db/__init__.py similarity index 100% rename from services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/modules/db/__init__.py rename to services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/services/modules/db/__init__.py diff --git a/services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/modules/db/repositories/__init__.py b/services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/services/modules/db/repositories/__init__.py similarity index 100% rename from services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/modules/db/repositories/__init__.py rename to services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/services/modules/db/repositories/__init__.py diff --git a/services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/modules/db/repositories/_base.py b/services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/services/modules/db/repositories/_base.py similarity index 100% rename from services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/modules/db/repositories/_base.py rename to services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/services/modules/db/repositories/_base.py diff --git a/services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/modules/db/repositories/resource_tracker.py b/services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/services/modules/db/repositories/resource_tracker.py similarity index 96% rename from services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/modules/db/repositories/resource_tracker.py rename to services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/services/modules/db/repositories/resource_tracker.py index 231c97502fb..33a3e58d137 100644 --- a/services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/modules/db/repositories/resource_tracker.py +++ b/services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/services/modules/db/repositories/resource_tracker.py @@ -28,9 +28,6 @@ from models_library.users import UserID from models_library.wallets import WalletID from pydantic import PositiveInt -from servicelib.rabbitmq.rpc_interfaces.resource_usage_tracker.errors import ( - CustomResourceUsageTrackerError, -) from simcore_postgres_database.models.resource_tracker_credit_transactions import ( resource_tracker_credit_transactions, ) @@ -51,19 +48,30 @@ ) from sqlalchemy.dialects.postgresql import ARRAY, INTEGER -from ....models.resource_tracker_credit_transactions import ( +from .....exceptions.errors import ( + CreditTransactionNotCreatedDBError, + PricingPlanAndPricingUnitCombinationDoesNotExistsDBError, + PricingPlanDoesNotExistsDBError, + PricingPlanNotCreatedDBError, + PricingPlanToServiceNotCreatedDBError, + PricingUnitCostDoesNotExistsDBError, + PricingUnitCostNotCreatedDBError, + PricingUnitNotCreatedDBError, + ServiceRunNotCreatedDBError, +) +from .....models.credit_transactions import ( CreditTransactionCreate, CreditTransactionCreditsAndStatusUpdate, CreditTransactionCreditsUpdate, ) -from ....models.resource_tracker_pricing_plans import ( +from .....models.pricing_plans import ( PricingPlansDB, PricingPlansWithServiceDefaultPlanDB, PricingPlanToServiceDB, ) -from ....models.resource_tracker_pricing_unit_costs import PricingUnitCostsDB -from ....models.resource_tracker_pricing_units import PricingUnitsDB -from ....models.resource_tracker_service_runs import ( +from .....models.pricing_unit_costs import PricingUnitCostsDB +from .....models.pricing_units import PricingUnitsDB +from .....models.service_runs import ( OsparcCreditsAggregatedByServiceKeyDB, ServiceRunCreate, ServiceRunDB, @@ -125,9 +133,7 @@ async def create_service_run(self, data: ServiceRunCreate) -> ServiceRunId: result = await conn.execute(insert_stmt) row = result.first() if row is None: - raise CustomResourceUsageTrackerError( - msg=f"Service was not created: {data}" - ) + raise ServiceRunNotCreatedDBError(data=data) return cast(ServiceRunId, row[0]) async def update_service_run_last_heartbeat( @@ -655,9 +661,7 @@ async def create_credit_transaction( result = await conn.execute(insert_stmt) row = result.first() if row is None: - raise CustomResourceUsageTrackerError( - msg=f"Transaction was not created: {data}" - ) + raise CreditTransactionNotCreatedDBError(data=data) return cast(CreditTransactionId, row[0]) async def update_credit_transaction_credits( @@ -870,9 +874,7 @@ async def get_pricing_plan( result = await conn.execute(select_stmt) row = result.first() if row is None: - raise CustomResourceUsageTrackerError( - msg=f"Pricing plan does not exists: {pricing_plan_id}" - ) + raise PricingPlanDoesNotExistsDBError(pricing_plan_id=pricing_plan_id) return PricingPlansDB.from_orm(row) async def list_pricing_plans_by_product( @@ -921,9 +923,7 @@ async def create_pricing_plan(self, data: PricingPlanCreate) -> PricingPlansDB: result = await conn.execute(insert_stmt) row = result.first() if row is None: - raise CustomResourceUsageTrackerError( - msg=f"Pricing plan was not created: {data}" - ) + raise PricingPlanNotCreatedDBError(data=data) return PricingPlansDB.from_orm(row) async def update_pricing_plan( @@ -1084,8 +1084,8 @@ async def upsert_service_to_pricing_plan( result = await conn.execute(insert_stmt) row = result.first() if row is None: - raise CustomResourceUsageTrackerError( - msg="Pricing plan to service record was not created" + raise PricingPlanToServiceNotCreatedDBError( + data=f"pricing_plan_id {pricing_plan_id}, service_key {service_key}, service_version {service_version}" ) return PricingPlanToServiceDB.from_orm(row) @@ -1194,8 +1194,10 @@ async def get_valid_pricing_unit( row = result.first() if row is None: - raise CustomResourceUsageTrackerError( - msg=f"Pricing plan {pricing_plan_id} and pricing unit {pricing_unit_id} for product {product_name} not found" + raise PricingPlanAndPricingUnitCombinationDoesNotExistsDBError( + pricing_plan_id=pricing_plan_id, + pricing_unit_id=pricing_unit_id, + product_name=product_name, ) return PricingUnitsDB.from_orm(row) @@ -1220,9 +1222,7 @@ async def create_pricing_unit_with_cost( result = await conn.execute(insert_stmt) row = result.first() if row is None: - raise CustomResourceUsageTrackerError( - msg=f"Pricing unit was not created: {data}" - ) + raise PricingUnitNotCreatedDBError(data=data) _pricing_unit_id = row[0] # pricing unit cost table @@ -1245,9 +1245,7 @@ async def create_pricing_unit_with_cost( result = await conn.execute(insert_stmt) row = result.first() if row is None: - raise CustomResourceUsageTrackerError( - msg=f"Pricing unit cost was not created: {data}" - ) + raise PricingUnitCostNotCreatedDBError(data=data) _pricing_unit_cost_id = row[0] return (_pricing_unit_id, _pricing_unit_cost_id) @@ -1313,9 +1311,7 @@ async def update_pricing_unit_with_cost( result = await conn.execute(insert_stmt) row = result.first() if row is None: - raise CustomResourceUsageTrackerError( - msg=f"Pricing unit cost was not created: {data}" - ) + raise PricingUnitCostNotCreatedDBError(data=data) ################################# # Pricing unit-costs @@ -1345,7 +1341,7 @@ async def get_pricing_unit_cost_by_id( row = result.first() if row is None: - raise CustomResourceUsageTrackerError( - msg=f"Pricing unit cost id {pricing_unit_cost_id} not found in the resource_tracker_pricing_unit_costs table", + raise PricingUnitCostDoesNotExistsDBError( + pricing_unit_cost_id=pricing_unit_cost_id ) return PricingUnitCostsDB.from_orm(row) diff --git a/services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/modules/rabbitmq.py b/services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/services/modules/rabbitmq.py similarity index 97% rename from services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/modules/rabbitmq.py rename to services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/services/modules/rabbitmq.py index 9bb4ec3d2b7..57fb01bdcbf 100644 --- a/services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/modules/rabbitmq.py +++ b/services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/services/modules/rabbitmq.py @@ -10,7 +10,7 @@ ) from settings_library.rabbit import RabbitSettings -from ..core.errors import ConfigurationError +from ...exceptions.errors import ConfigurationError logger = logging.getLogger(__name__) diff --git a/services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/modules/redis.py b/services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/services/modules/redis.py similarity index 94% rename from services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/modules/redis.py rename to services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/services/modules/redis.py index 354f2fea5d2..922b0e7e49e 100644 --- a/services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/modules/redis.py +++ b/services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/services/modules/redis.py @@ -25,5 +25,5 @@ async def on_shutdown() -> None: app.add_event_handler("shutdown", on_shutdown) -def get_redis_client(app: FastAPI) -> RedisClientSDK: +def get_redis_lock_client(app: FastAPI) -> RedisClientSDK: return cast(RedisClientSDK, app.state.redis_client_sdk) diff --git a/services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/modules/s3.py b/services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/services/modules/s3.py similarity index 97% rename from services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/modules/s3.py rename to services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/services/modules/s3.py index 889b8cfcd1c..cc41206c256 100644 --- a/services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/modules/s3.py +++ b/services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/services/modules/s3.py @@ -12,7 +12,7 @@ wait_random_exponential, ) -from ..core.errors import ConfigurationError +from ...exceptions.errors import ConfigurationError _logger = logging.getLogger(__name__) diff --git a/services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/services/resource_tracker_pricing_plans.py b/services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/services/pricing_plans.py similarity index 93% rename from services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/services/resource_tracker_pricing_plans.py rename to services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/services/pricing_plans.py index d37f244dbc9..e597806d98c 100644 --- a/services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/services/resource_tracker_pricing_plans.py +++ b/services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/services/pricing_plans.py @@ -13,17 +13,12 @@ PricingPlanUpdate, ) from models_library.services import ServiceKey, ServiceVersion -from servicelib.rabbitmq.rpc_interfaces.resource_usage_tracker.errors import ( - CustomResourceUsageTrackerError, -) from ..api.rest.dependencies import get_repository -from ..models.resource_tracker_pricing_plans import ( - PricingPlansDB, - PricingPlanToServiceDB, -) -from ..models.resource_tracker_pricing_units import PricingUnitsDB -from ..modules.db.repositories.resource_tracker import ResourceTrackerRepository +from ..exceptions.errors import PricingPlanNotFoundForServiceError +from ..models.pricing_plans import PricingPlansDB, PricingPlanToServiceDB +from ..models.pricing_units import PricingUnitsDB +from .modules.db.repositories.resource_tracker import ResourceTrackerRepository async def _create_pricing_plan_get( @@ -71,8 +66,8 @@ async def get_service_default_pricing_plan( break if default_pricing_plan is None: - raise CustomResourceUsageTrackerError( - msg="No default pricing plan for the specified service" + raise PricingPlanNotFoundForServiceError( + service_key=service_key, service_version=service_version ) pricing_plan_unit_db = ( diff --git a/services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/services/resource_tracker_pricing_units.py b/services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/services/pricing_units.py similarity index 97% rename from services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/services/resource_tracker_pricing_units.py rename to services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/services/pricing_units.py index 0194cc0f699..f2aee53dd80 100644 --- a/services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/services/resource_tracker_pricing_units.py +++ b/services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/services/pricing_units.py @@ -13,7 +13,7 @@ ) from ..api.rest.dependencies import get_repository -from ..modules.db.repositories.resource_tracker import ResourceTrackerRepository +from .modules.db.repositories.resource_tracker import ResourceTrackerRepository async def get_pricing_unit( diff --git a/services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/resource_tracker_process_messages.py b/services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/services/process_message_running_service.py similarity index 98% rename from services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/resource_tracker_process_messages.py rename to services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/services/process_message_running_service.py index 4cb024b3b7c..4352e327266 100644 --- a/services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/resource_tracker_process_messages.py +++ b/services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/services/process_message_running_service.py @@ -22,19 +22,19 @@ from models_library.services import ServiceType from pydantic import parse_raw_as -from .models.resource_tracker_credit_transactions import ( +from ..models.credit_transactions import ( CreditTransactionCreate, CreditTransactionCreditsAndStatusUpdate, CreditTransactionCreditsUpdate, ) -from .models.resource_tracker_service_runs import ( +from ..models.service_runs import ( ServiceRunCreate, ServiceRunLastHeartbeatUpdate, ServiceRunStoppedAtUpdate, ) from .modules.db.repositories.resource_tracker import ResourceTrackerRepository from .modules.rabbitmq import RabbitMQClient, get_rabbitmq_client -from .resource_tracker_utils import ( +from .utils import ( compute_service_run_credit_costs, make_negative, publish_to_rabbitmq_wallet_credits_limit_reached, diff --git a/services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/resource_tracker.py b/services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/services/process_message_running_service_setup.py similarity index 61% rename from services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/resource_tracker.py rename to services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/services/process_message_running_service_setup.py index 6bee4c87add..3624eb1254d 100644 --- a/services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/resource_tracker.py +++ b/services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/services/process_message_running_service_setup.py @@ -4,22 +4,16 @@ from fastapi import FastAPI from models_library.rabbitmq_messages import RabbitResourceTrackingBaseMessage -from servicelib.background_task import stop_periodic_task from servicelib.logging_utils import log_catch, log_context from servicelib.rabbitmq import RabbitMQClient -from servicelib.redis_utils import start_exclusive_periodic_task from settings_library.rabbit import RabbitSettings -from .core.settings import ApplicationSettings +from ..core.settings import ApplicationSettings from .modules.rabbitmq import get_rabbitmq_client -from .modules.redis import get_redis_client -from .resource_tracker_background_task import periodic_check_of_running_services_task -from .resource_tracker_process_messages import process_message +from .process_message_running_service import process_message _logger = logging.getLogger(__name__) -_TASK_NAME_PERIODICALY_CHECK_RUNNING_SERVICES = "periodic_check_of_running_services" - _RUT_MESSAGE_TTL_IN_MS = 2 * 60 * 60 * 1000 # 2 hours @@ -42,7 +36,6 @@ async def _startup() -> None: ), log_catch(_logger, reraise=False): app_settings: ApplicationSettings = app.state.settings app.state.resource_tracker_rabbitmq_consumer = None - app.state.resource_tracker_background_task = None settings: RabbitSettings | None = ( app_settings.RESOURCE_USAGE_TRACKER_RABBITMQ ) @@ -52,16 +45,6 @@ async def _startup() -> None: app.state.resource_tracker_rabbitmq_consumer = await _subscribe_to_rabbitmq( app ) - # Setup periodic task that will try to run "periodic_check_of_running_services_task" - if app_settings.RESOURCE_USAGE_TRACKER_MISSED_HEARTBEAT_CHECK_ENABLED: - app.state.resource_tracker_background_task = start_exclusive_periodic_task( - get_redis_client(app), - periodic_check_of_running_services_task, - task_period=app_settings.RESOURCE_USAGE_TRACKER_MISSED_HEARTBEAT_INTERVAL_SEC, - retry_after=app_settings.RESOURCE_USAGE_TRACKER_MISSED_HEARTBEAT_INTERVAL_SEC, - task_name=_TASK_NAME_PERIODICALY_CHECK_RUNNING_SERVICES, - app=app, - ) return _startup @@ -72,8 +55,6 @@ def on_app_shutdown( async def _stop() -> None: # NOTE: We want to have persistent queue, therefore we will not unsubscribe assert _app # nosec - if _app.state.resource_tracker_background_task: - await stop_periodic_task(_app.state.resource_tracker_background_task) return _stop diff --git a/services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/services/resource_tracker_service_runs.py b/services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/services/service_runs.py similarity index 96% rename from services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/services/resource_tracker_service_runs.py rename to services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/services/service_runs.py index 3f2167e3d77..782b084c789 100644 --- a/services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/services/resource_tracker_service_runs.py +++ b/services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/services/service_runs.py @@ -19,12 +19,9 @@ from models_library.users import UserID from models_library.wallets import WalletID from pydantic import AnyUrl, PositiveInt -from servicelib.rabbitmq.rpc_interfaces.resource_usage_tracker.errors import ( - CustomResourceUsageTrackerError, -) -from ..models.resource_tracker_service_runs import ServiceRunWithCreditsDB -from ..modules.db.repositories.resource_tracker import ResourceTrackerRepository +from ..models.service_runs import ServiceRunWithCreditsDB +from .modules.db.repositories.resource_tracker import ResourceTrackerRepository _PRESIGNED_LINK_EXPIRATION_SEC = 7200 @@ -111,7 +108,7 @@ async def list_service_runs( ) else: msg = "wallet_id and access_all_wallet_usage parameters must be specified together" - raise CustomResourceUsageTrackerError(msg=msg) + raise ValueError(msg) service_runs_api_model: list[ServiceRunGet] = [] for service in service_runs_db_model: diff --git a/services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/resource_tracker_utils.py b/services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/services/utils.py similarity index 100% rename from services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/resource_tracker_utils.py rename to services/resource-usage-tracker/src/simcore_service_resource_usage_tracker/services/utils.py diff --git a/services/resource-usage-tracker/tests/unit/api_rest/test_api_meta.py b/services/resource-usage-tracker/tests/unit/api_rest/test_api_meta.py index cffb606fae5..66052119d72 100644 --- a/services/resource-usage-tracker/tests/unit/api_rest/test_api_meta.py +++ b/services/resource-usage-tracker/tests/unit/api_rest/test_api_meta.py @@ -27,7 +27,7 @@ def test_healthcheck( rabbitmq_mock = mocker.Mock(spec=RabbitMQClient) rabbitmq_mock.healthy = True mocker.patch( - "simcore_service_resource_usage_tracker.modules.rabbitmq.get_rabbitmq_client", + "simcore_service_resource_usage_tracker.services.modules.rabbitmq.get_rabbitmq_client", return_value=rabbitmq_mock, ) @@ -50,7 +50,7 @@ def test_healthcheck__unhealthy( rabbitmq_mock = mocker.Mock(spec=RabbitMQClient) rabbitmq_mock.healthy = False mocker.patch( - "simcore_service_resource_usage_tracker.modules.rabbitmq.get_rabbitmq_client", + "simcore_service_resource_usage_tracker.services.modules.rabbitmq.get_rabbitmq_client", return_value=rabbitmq_mock, ) diff --git a/services/resource-usage-tracker/tests/unit/conftest.py b/services/resource-usage-tracker/tests/unit/conftest.py index 6d70142d5e4..6e4bfcd6b98 100644 --- a/services/resource-usage-tracker/tests/unit/conftest.py +++ b/services/resource-usage-tracker/tests/unit/conftest.py @@ -68,6 +68,7 @@ def app_environment( "PROMETHEUS_USERNAME": faker.user_name(), "PROMETHEUS_PASSWORD": faker.password(special_chars=False), "RESOURCE_USAGE_TRACKER_MISSED_HEARTBEAT_CHECK_ENABLED": "0", + "RESOURCE_USAGE_TRACKER_TRACING": "null", }, ) diff --git a/services/resource-usage-tracker/tests/unit/modules/test_rabbitmq.py b/services/resource-usage-tracker/tests/unit/modules/test_rabbitmq.py index dde606241e4..f69d8989b24 100644 --- a/services/resource-usage-tracker/tests/unit/modules/test_rabbitmq.py +++ b/services/resource-usage-tracker/tests/unit/modules/test_rabbitmq.py @@ -5,7 +5,9 @@ from fastapi import FastAPI from settings_library.rabbit import RabbitSettings -from simcore_service_resource_usage_tracker.modules.rabbitmq import get_rabbitmq_client +from simcore_service_resource_usage_tracker.services.modules.rabbitmq import ( + get_rabbitmq_client, +) # Selection of core and tool services started in this swarm fixture (integration) pytest_simcore_core_services_selection = [ diff --git a/services/resource-usage-tracker/tests/unit/modules/test_redis.py b/services/resource-usage-tracker/tests/unit/modules/test_redis.py index 1a7d79b202d..e518c589c79 100644 --- a/services/resource-usage-tracker/tests/unit/modules/test_redis.py +++ b/services/resource-usage-tracker/tests/unit/modules/test_redis.py @@ -6,7 +6,9 @@ from unittest import mock from fastapi import FastAPI -from simcore_service_resource_usage_tracker.modules.redis import get_redis_client +from simcore_service_resource_usage_tracker.services.modules.redis import ( + get_redis_lock_client, +) async def test_redis_raises_if_missing( @@ -17,5 +19,5 @@ async def test_redis_raises_if_missing( mocked_redis_server: None, initialized_app: FastAPI, ): - client = get_redis_client(initialized_app) + client = get_redis_lock_client(initialized_app) assert await client.ping() is True diff --git a/services/resource-usage-tracker/tests/unit/test_computation_of_credits.py b/services/resource-usage-tracker/tests/unit/test_computation_of_credits.py index 5264b799f33..bd48460457c 100644 --- a/services/resource-usage-tracker/tests/unit/test_computation_of_credits.py +++ b/services/resource-usage-tracker/tests/unit/test_computation_of_credits.py @@ -7,7 +7,7 @@ from decimal import Decimal import pytest -from simcore_service_resource_usage_tracker.resource_tracker_utils import ( +from simcore_service_resource_usage_tracker.services.utils import ( compute_service_run_credit_costs, ) diff --git a/services/resource-usage-tracker/tests/unit/test_web_main.py b/services/resource-usage-tracker/tests/unit/test_main.py similarity index 75% rename from services/resource-usage-tracker/tests/unit/test_web_main.py rename to services/resource-usage-tracker/tests/unit/test_main.py index a58f4a6139a..6d9addd8ee2 100644 --- a/services/resource-usage-tracker/tests/unit/test_web_main.py +++ b/services/resource-usage-tracker/tests/unit/test_main.py @@ -7,6 +7,6 @@ def test_main_app(app_environment: EnvVarsDict): - from simcore_service_resource_usage_tracker.web_main import the_app, the_settings + from simcore_service_resource_usage_tracker.main import the_app, the_settings assert the_app.state.settings == the_settings diff --git a/services/resource-usage-tracker/tests/unit/with_dbs/conftest.py b/services/resource-usage-tracker/tests/unit/with_dbs/conftest.py index 6f240d658ee..581952e1100 100644 --- a/services/resource-usage-tracker/tests/unit/with_dbs/conftest.py +++ b/services/resource-usage-tracker/tests/unit/with_dbs/conftest.py @@ -31,12 +31,10 @@ ) from simcore_service_resource_usage_tracker.core.application import create_app from simcore_service_resource_usage_tracker.core.settings import ApplicationSettings -from simcore_service_resource_usage_tracker.models.resource_tracker_credit_transactions import ( +from simcore_service_resource_usage_tracker.models.credit_transactions import ( CreditTransactionDB, ) -from simcore_service_resource_usage_tracker.models.resource_tracker_service_runs import ( - ServiceRunDB, -) +from simcore_service_resource_usage_tracker.models.service_runs import ServiceRunDB from tenacity.asyncio import AsyncRetrying from tenacity.retry import retry_if_exception_type from tenacity.stop import stop_after_delay diff --git a/services/resource-usage-tracker/tests/unit/with_dbs/data/list_of_prometheus_mocked_outputs.json b/services/resource-usage-tracker/tests/unit/with_dbs/data/list_of_prometheus_mocked_outputs.json deleted file mode 100644 index eec1a5cca04..00000000000 --- a/services/resource-usage-tracker/tests/unit/with_dbs/data/list_of_prometheus_mocked_outputs.json +++ /dev/null @@ -1,496 +0,0 @@ -[ - { - "metric": { - "container_label_com_docker_compose_oneoff": "False", - "container_label_com_docker_compose_project_working_dir": "/tmp/tmpb1ztyf6m", - "container_label_com_docker_compose_version": "1.29.1", - "container_label_io_simcore_runtime_product_name": "osparc", - "container_label_simcore_service_settings": "[{\"name\": \"ports\", \"type\": \"int\", \"value\": 8888}, {\"name\": \"env\", \"type\": \"string\", \"value\": [\"DISPLAY=:0\"]}, {\"name\": \"env\", \"type\": \"string\", \"value\": [\"SYM_SERVER_HOSTNAME=sym-server_%service_uuid%\"]}, {\"name\": \"mount\", \"type\": \"object\", \"value\": [{\"ReadOnly\": true, \"Source\": \"/tmp/.X11-unix\", \"Target\": \"/tmp/.X11-unix\", \"Type\": \"bind\"}]}, {\"name\": \"constraints\", \"type\": \"string\", \"value\": [\"node.platform.os == linux\"]}, {\"name\": \"Resources\", \"type\": \"Resources\", \"value\": {\"Limits\": {\"NanoCPUs\": 4000000000, \"MemoryBytes\": 17179869184}, \"Reservations\": {\"NanoCPUs\": 100000000, \"MemoryBytes\": 536870912, \"GenericResources\": [{\"DiscreteResourceSpec\": {\"Kind\": \"VRAM\", \"Value\": 1}}]}}}]", - "container_label_io_simcore_runtime_simcore_user_agent": "puppeteer", - "container_label_io_simcore_runtime_project_id": "df604058-0c26-11ee-994f-02420a0b0fc8", - "container_label_io_simcore_runtime_user_id": "43819", - "container_label_io_simcore_runtime_node_id": "14387f03-4a37-5187-b8e0-0e491389ade4", - "container_label_io_simcore_runtime_cpu_limit": "3.5", - "container_label_io_simcore_runtime_memory_limit": "17179869184", - "id": "/docker/ec08331c8658286a384cfa6e57f3b4daa59c9e9a369ed42401f621c142042f40", - "image": "registry.osparc.io/simcore/services/dynamic/jupyter-smash:3.0.7", - "instance": "gpu1", - "job": "cadvisor", - "name": "dy-sidecar-11177106-2302-5461-9017-e495145858b6-0-jupyter-smash" - }, - "values": [ - [ - 1686907140, - "2.5380915280000007" - ], - [ - 1686907200, - "18.057210595000004" - ], - [ - 1686907260, - "18.057210595000004" - ], - [ - 1686907320, - "18.057210595000004" - ], - [ - 1686907380, - "18.057210595000004" - ], - [ - 1686907440, - "18.057210595000004" - ] - ] - }, - { - "metric": { - "container_label_com_docker_compose_oneoff": "False", - "container_label_com_docker_compose_project_working_dir": "/tmp/tmpqg_rpq7e", - "container_label_com_docker_compose_version": "1.29.1", - "container_label_io_simcore_runtime_product_name": "osparc", - "container_label_simcore_service_settings": "[{\"name\": \"ports\", \"type\": \"int\", \"value\": 8888}, {\"name\": \"env\", \"type\": \"string\", \"value\": [\"DISPLAY=:0\"]}, {\"name\": \"env\", \"type\": \"string\", \"value\": [\"SYM_SERVER_HOSTNAME=sym-server_%service_uuid%\"]}, {\"name\": \"mount\", \"type\": \"object\", \"value\": [{\"ReadOnly\": true, \"Source\": \"/tmp/.X11-unix\", \"Target\": \"/tmp/.X11-unix\", \"Type\": \"bind\"}]}, {\"name\": \"constraints\", \"type\": \"string\", \"value\": [\"node.platform.os == linux\"]}, {\"name\": \"Resources\", \"type\": \"Resources\", \"value\": {\"Limits\": {\"NanoCPUs\": 4000000000, \"MemoryBytes\": 17179869184}, \"Reservations\": {\"NanoCPUs\": 100000000, \"MemoryBytes\": 536870912, \"GenericResources\": [{\"DiscreteResourceSpec\": {\"Kind\": \"VRAM\", \"Value\": 1}}]}}}]", - "container_label_io_simcore_runtime_simcore_user_agent": "puppeteer", - "container_label_io_simcore_runtime_project_id": "df604058-0c26-11ee-994f-02420a0b0fc8", - "container_label_io_simcore_runtime_user_id": "43819", - "container_label_io_simcore_runtime_node_id": "14387f03-4a37-5187-b8e0-0e491389ade4", - "container_label_io_simcore_runtime_cpu_limit": "3.5", - "container_label_io_simcore_runtime_memory_limit": "17179869184", - "id": "/docker/2873c8bee46543f059d4c2c2500ba658d24bdf0abdfcdc2b7eccc955e9538c43", - "image": "registry.osparc.io/simcore/services/dynamic/jupyter-smash:3.0.7", - "instance": "gpu1", - "job": "cadvisor", - "name": "dy-sidecar-9069c179-c3d7-58a6-8431-8cb19339c847-0-jupyter-smash" - }, - "values": [ - [ - 1686907080, - "2.5288082430000003" - ], - [ - 1686907140, - "16.675726328" - ], - [ - 1686907200, - "17.503259114" - ], - [ - 1686907260, - "17.503259114" - ], - [ - 1686907320, - "17.503259114" - ], - [ - 1686907380, - "17.503259114" - ], - [ - 1686907440, - "17.503259114" - ] - ] - }, - { - "metric": { - "container_label_com_docker_compose_oneoff": "False", - "container_label_com_docker_compose_project_working_dir": "/tmp/tmp0m7ijyoy", - "container_label_com_docker_compose_version": "1.29.1", - "container_label_io_simcore_runtime_product_name": "osparc", - "container_label_simcore_service_settings": "[{\"name\": \"ports\", \"type\": \"int\", \"value\": 8888}, {\"name\": \"env\", \"type\": \"string\", \"value\": [\"DISPLAY=:0\"]}, {\"name\": \"env\", \"type\": \"string\", \"value\": [\"SYM_SERVER_HOSTNAME=sym-server_%service_uuid%\"]}, {\"name\": \"mount\", \"type\": \"object\", \"value\": [{\"ReadOnly\": true, \"Source\": \"/tmp/.X11-unix\", \"Target\": \"/tmp/.X11-unix\", \"Type\": \"bind\"}]}, {\"name\": \"constraints\", \"type\": \"string\", \"value\": [\"node.platform.os == linux\"]}, {\"name\": \"Resources\", \"type\": \"Resources\", \"value\": {\"Limits\": {\"NanoCPUs\": 4000000000, \"MemoryBytes\": 17179869184}, \"Reservations\": {\"NanoCPUs\": 100000000, \"MemoryBytes\": 536870912, \"GenericResources\": [{\"DiscreteResourceSpec\": {\"Kind\": \"VRAM\", \"Value\": 1}}]}}}]", - "container_label_io_simcore_runtime_simcore_user_agent": "puppeteer", - "container_label_io_simcore_runtime_project_id": "df604058-0c26-11ee-994f-02420a0b0fc8", - "container_label_io_simcore_runtime_user_id": "43819", - "container_label_io_simcore_runtime_node_id": "14387f03-4a37-5187-b8e0-0e491389ade4", - "container_label_io_simcore_runtime_cpu_limit": "3.5", - "container_label_io_simcore_runtime_memory_limit": "17179869184", - "id": "/docker/b6cd6d013763a34795aaac8402b7f8943df80c2f63ba4f90f95c5b7235dbbc4e", - "image": "registry.osparc.io/simcore/services/dynamic/jupyter-smash:3.0.7", - "instance": "gpu1", - "job": "cadvisor", - "name": "dy-sidecar-8f1a908e-8b4b-5011-a42c-98abd141fc50-0-jupyter-smash" - }, - "values": [ - [ - 1686907140, - "5.765171485000001" - ], - [ - 1686907200, - "5.835658748999999" - ], - [ - 1686907260, - "5.835658748999999" - ], - [ - 1686907320, - "5.835658748999999" - ], - [ - 1686907380, - "5.835658748999999" - ], - [ - 1686907440, - "5.835658748999999" - ] - ] - }, - { - "metric": { - "container_label_com_docker_compose_oneoff": "False", - "container_label_com_docker_compose_project_working_dir": "/tmp/tmp3o6q4v5e", - "container_label_com_docker_compose_version": "1.29.1", - "container_label_io_simcore_runtime_product_name": "osparc", - "container_label_simcore_service_settings": "[{\"name\": \"ports\", \"type\": \"int\", \"value\": 8888}, {\"name\": \"env\", \"type\": \"string\", \"value\": [\"DISPLAY=:0\"]}, {\"name\": \"env\", \"type\": \"string\", \"value\": [\"SYM_SERVER_HOSTNAME=sym-server_%service_uuid%\"]}, {\"name\": \"mount\", \"type\": \"object\", \"value\": [{\"ReadOnly\": true, \"Source\": \"/tmp/.X11-unix\", \"Target\": \"/tmp/.X11-unix\", \"Type\": \"bind\"}]}, {\"name\": \"constraints\", \"type\": \"string\", \"value\": [\"node.platform.os == linux\"]}, {\"name\": \"Resources\", \"type\": \"Resources\", \"value\": {\"Limits\": {\"NanoCPUs\": 4000000000, \"MemoryBytes\": 17179869184}, \"Reservations\": {\"NanoCPUs\": 100000000, \"MemoryBytes\": 536870912, \"GenericResources\": [{\"DiscreteResourceSpec\": {\"Kind\": \"VRAM\", \"Value\": 1}}]}}}]", - "container_label_io_simcore_runtime_simcore_user_agent": "puppeteer", - "container_label_io_simcore_runtime_project_id": "df604058-0c26-11ee-994f-02420a0b0fc8", - "container_label_io_simcore_runtime_user_id": "43819", - "container_label_io_simcore_runtime_node_id": "14387f03-4a37-5187-b8e0-0e491389ade4", - "container_label_io_simcore_runtime_cpu_limit": "3.5", - "container_label_io_simcore_runtime_memory_limit": "17179869184", - "id": "/docker/22394ffafb00907311fc6b76423875411f1084009f89fe77bc618f48f06053eb", - "image": "registry.osparc.io/simcore/services/dynamic/jupyter-smash:3.0.7", - "instance": "gpu1", - "job": "cadvisor", - "name": "dy-sidecar-14387f03-4a37-5187-b8e0-0e491389ade4-0-jupyter-smash" - }, - "values": [ - [ - 1686907200, - "2.500054865" - ], - [ - 1686907260, - "7.3528712789999995" - ], - [ - 1686907320, - "17.330580469999997" - ], - [ - 1686907380, - "17.330580469999997" - ], - [ - 1686907440, - "17.330580469999997" - ], - [ - 1686907500, - "17.330580469999997" - ], - [ - 1686907560, - "17.330580469999997" - ] - ] - }, - { - "metric": { - "container_label_com_docker_compose_oneoff": "False", - "container_label_com_docker_compose_project_working_dir": "/tmp/tmpfgfyp7n5", - "container_label_com_docker_compose_version": "1.29.1", - "container_label_io_simcore_runtime_product_name": "osparc", - "container_label_simcore_service_settings": "[{\"name\": \"ports\", \"type\": \"int\", \"value\": 8888}, {\"name\": \"env\", \"type\": \"string\", \"value\": [\"DISPLAY=:0\"]}, {\"name\": \"env\", \"type\": \"string\", \"value\": [\"SYM_SERVER_HOSTNAME=sym-server_%service_uuid%\"]}, {\"name\": \"mount\", \"type\": \"object\", \"value\": [{\"ReadOnly\": true, \"Source\": \"/tmp/.X11-unix\", \"Target\": \"/tmp/.X11-unix\", \"Type\": \"bind\"}]}, {\"name\": \"constraints\", \"type\": \"string\", \"value\": [\"node.platform.os == linux\"]}, {\"name\": \"Resources\", \"type\": \"Resources\", \"value\": {\"Limits\": {\"NanoCPUs\": 4000000000, \"MemoryBytes\": 17179869184}, \"Reservations\": {\"NanoCPUs\": 100000000, \"MemoryBytes\": 536870912, \"GenericResources\": [{\"DiscreteResourceSpec\": {\"Kind\": \"VRAM\", \"Value\": 1}}]}}}]", - "container_label_io_simcore_runtime_simcore_user_agent": "puppeteer", - "container_label_io_simcore_runtime_project_id": "df604058-0c26-11ee-994f-02420a0b0fc8", - "container_label_io_simcore_runtime_user_id": "43819", - "container_label_io_simcore_runtime_node_id": "14387f03-4a37-5187-b8e0-0e491389ade4", - "container_label_io_simcore_runtime_cpu_limit": "3.5", - "container_label_io_simcore_runtime_memory_limit": "17179869184", - "id": "/docker/fecc93800827e3fbdaee9a51842ff2001d010f809c46e806f74611bada02b7b1", - "image": "registry.osparc.io/simcore/services/dynamic/jupyter-smash:3.0.7", - "instance": "gpu1", - "job": "cadvisor", - "name": "dy-sidecar-32f3c80d-7cbc-58d3-840e-fedae5252dd0-0-jupyter-smash" - }, - "values": [ - [ - 1686906660, - "4.4991374429999995" - ], - [ - 1686906720, - "5.768837835" - ], - [ - 1686906780, - "5.815829203" - ], - [ - 1686906840, - "5.815829203" - ], - [ - 1686906900, - "5.815829203" - ], - [ - 1686906960, - "5.815829203" - ], - [ - 1686907020, - "5.815829203" - ] - ] - }, - { - "metric": { - "container_label_com_docker_compose_oneoff": "False", - "container_label_com_docker_compose_project_working_dir": "/tmp/tmpyugvc3z8", - "container_label_com_docker_compose_version": "1.29.1", - "container_label_io_simcore_runtime_product_name": "osparc", - "container_label_simcore_service_settings": "[{\"name\": \"ports\", \"type\": \"int\", \"value\": 8888}, {\"name\": \"env\", \"type\": \"string\", \"value\": [\"DISPLAY=:0\"]}, {\"name\": \"env\", \"type\": \"string\", \"value\": [\"SYM_SERVER_HOSTNAME=sym-server_%service_uuid%\"]}, {\"name\": \"mount\", \"type\": \"object\", \"value\": [{\"ReadOnly\": true, \"Source\": \"/tmp/.X11-unix\", \"Target\": \"/tmp/.X11-unix\", \"Type\": \"bind\"}]}, {\"name\": \"constraints\", \"type\": \"string\", \"value\": [\"node.platform.os == linux\"]}, {\"name\": \"Resources\", \"type\": \"Resources\", \"value\": {\"Limits\": {\"NanoCPUs\": 4000000000, \"MemoryBytes\": 17179869184}, \"Reservations\": {\"NanoCPUs\": 100000000, \"MemoryBytes\": 536870912, \"GenericResources\": [{\"DiscreteResourceSpec\": {\"Kind\": \"VRAM\", \"Value\": 1}}]}}}]", - "container_label_io_simcore_runtime_simcore_user_agent": "puppeteer", - "container_label_io_simcore_runtime_project_id": "df604058-0c26-11ee-994f-02420a0b0fc8", - "container_label_io_simcore_runtime_user_id": "43819", - "container_label_io_simcore_runtime_node_id": "14387f03-4a37-5187-b8e0-0e491389ade4", - "container_label_io_simcore_runtime_cpu_limit": "3.5", - "container_label_io_simcore_runtime_memory_limit": "17179869184", - "id": "/docker/38179a390b273788cba9a7b33860f0606c4d4c45d13d63f9d1920509e05d2054", - "image": "registry.osparc.io/simcore/services/dynamic/jupyter-smash:3.0.7", - "instance": "gpu1", - "job": "cadvisor", - "name": "dy-sidecar-f7c6e801-d8a0-5f57-8283-850adf128613-0-jupyter-smash" - }, - "values": [ - [ - 1686907080, - "5.086436862999999" - ], - [ - 1686907140, - "5.778702072999999" - ], - [ - 1686907200, - "5.795705571" - ], - [ - 1686907260, - "5.795705571" - ], - [ - 1686907320, - "5.795705571" - ], - [ - 1686907380, - "5.795705571" - ], - [ - 1686907440, - "5.795705571" - ] - ] - }, - { - "metric": { - "container_label_com_docker_compose_oneoff": "False", - "container_label_com_docker_compose_project_working_dir": "/tmp/tmpehms8dgc", - "container_label_com_docker_compose_version": "1.29.1", - "container_label_io_simcore_runtime_product_name": "osparc", - "container_label_simcore_service_settings": "[{\"name\": \"ports\", \"type\": \"int\", \"value\": 8888}, {\"name\": \"env\", \"type\": \"string\", \"value\": [\"DISPLAY=:0\"]}, {\"name\": \"env\", \"type\": \"string\", \"value\": [\"SYM_SERVER_HOSTNAME=sym-server_%service_uuid%\"]}, {\"name\": \"mount\", \"type\": \"object\", \"value\": [{\"ReadOnly\": true, \"Source\": \"/tmp/.X11-unix\", \"Target\": \"/tmp/.X11-unix\", \"Type\": \"bind\"}]}, {\"name\": \"constraints\", \"type\": \"string\", \"value\": [\"node.platform.os == linux\"]}, {\"name\": \"Resources\", \"type\": \"Resources\", \"value\": {\"Limits\": {\"NanoCPUs\": 4000000000, \"MemoryBytes\": 17179869184}, \"Reservations\": {\"NanoCPUs\": 100000000, \"MemoryBytes\": 536870912, \"GenericResources\": [{\"DiscreteResourceSpec\": {\"Kind\": \"VRAM\", \"Value\": 1}}]}}}]", - "container_label_io_simcore_runtime_simcore_user_agent": "puppeteer", - "container_label_io_simcore_runtime_project_id": "df604058-0c26-11ee-994f-02420a0b0fc8", - "container_label_io_simcore_runtime_user_id": "43819", - "container_label_io_simcore_runtime_node_id": "14387f03-4a37-5187-b8e0-0e491389ade4", - "container_label_io_simcore_runtime_cpu_limit": "3.5", - "container_label_io_simcore_runtime_memory_limit": "17179869184", - "id": "/docker/98f90bfd2e28861247f550da8dcf09ebcfa3e5304d15f470708f67f84e724a8f", - "image": "registry.osparc.io/simcore/services/dynamic/jupyter-smash:3.0.7", - "instance": "gpu1", - "job": "cadvisor", - "name": "dy-sidecar-d283967b-11db-5d91-a484-af570f32d5e7-0-jupyter-smash" - }, - "values": [ - [ - 1686907440, - "5.755467759" - ], - [ - 1686907500, - "5.801798311000001" - ], - [ - 1686907560, - "5.801798311000001" - ] - ] - }, - { - "metric": { - "container_label_com_docker_compose_oneoff": "False", - "container_label_com_docker_compose_project_working_dir": "/tmp/tmpdkm5klhn", - "container_label_com_docker_compose_version": "1.29.1", - "container_label_io_simcore_runtime_product_name": "osparc", - "container_label_simcore_service_settings": "[{\"name\": \"ports\", \"type\": \"int\", \"value\": 8888}, {\"name\": \"env\", \"type\": \"string\", \"value\": [\"DISPLAY=:0\"]}, {\"name\": \"env\", \"type\": \"string\", \"value\": [\"SYM_SERVER_HOSTNAME=sym-server_%service_uuid%\"]}, {\"name\": \"mount\", \"type\": \"object\", \"value\": [{\"ReadOnly\": true, \"Source\": \"/tmp/.X11-unix\", \"Target\": \"/tmp/.X11-unix\", \"Type\": \"bind\"}]}, {\"name\": \"constraints\", \"type\": \"string\", \"value\": [\"node.platform.os == linux\"]}, {\"name\": \"Resources\", \"type\": \"Resources\", \"value\": {\"Limits\": {\"NanoCPUs\": 4000000000, \"MemoryBytes\": 17179869184}, \"Reservations\": {\"NanoCPUs\": 100000000, \"MemoryBytes\": 536870912, \"GenericResources\": [{\"DiscreteResourceSpec\": {\"Kind\": \"VRAM\", \"Value\": 1}}]}}}]", - "container_label_io_simcore_runtime_simcore_user_agent": "puppeteer", - "container_label_io_simcore_runtime_project_id": "df604058-0c26-11ee-994f-02420a0b0fc8", - "container_label_io_simcore_runtime_user_id": "43819", - "container_label_io_simcore_runtime_node_id": "14387f03-4a37-5187-b8e0-0e491389ade4", - "container_label_io_simcore_runtime_cpu_limit": "3.5", - "container_label_io_simcore_runtime_memory_limit": "17179869184", - "id": "/docker/e468fa476815d843e3d3dcf4c7988c8846107be02959a2ef1fd41584b18c18ee", - "image": "registry.osparc.io/simcore/services/dynamic/jupyter-smash:3.0.7", - "instance": "gpu1", - "job": "cadvisor", - "name": "dy-sidecar-fee6dbfe-529f-5c57-8121-af8a507326f0-0-jupyter-smash" - }, - "values": [ - [ - 1686907200, - "2.623185233" - ], - [ - 1686907260, - "5.775293023000001" - ], - [ - 1686907320, - "5.818879645000001" - ], - [ - 1686907380, - "5.818879645000001" - ], - [ - 1686907440, - "5.818879645000001" - ], - [ - 1686907500, - "5.818879645000001" - ], - [ - 1686907560, - "5.818879645000001" - ] - ] - }, - { - "metric": { - "container_label_com_docker_compose_oneoff": "False", - "container_label_com_docker_compose_project_working_dir": "/tmp/tmp6y2a68v3", - "container_label_com_docker_compose_version": "1.29.1", - "container_label_io_simcore_runtime_product_name": "osparc", - "container_label_simcore_service_settings": "[{\"name\": \"ports\", \"type\": \"int\", \"value\": 8888}, {\"name\": \"env\", \"type\": \"string\", \"value\": [\"DISPLAY=:0\"]}, {\"name\": \"env\", \"type\": \"string\", \"value\": [\"SYM_SERVER_HOSTNAME=sym-server_%service_uuid%\"]}, {\"name\": \"mount\", \"type\": \"object\", \"value\": [{\"ReadOnly\": true, \"Source\": \"/tmp/.X11-unix\", \"Target\": \"/tmp/.X11-unix\", \"Type\": \"bind\"}]}, {\"name\": \"constraints\", \"type\": \"string\", \"value\": [\"node.platform.os == linux\"]}, {\"name\": \"Resources\", \"type\": \"Resources\", \"value\": {\"Limits\": {\"NanoCPUs\": 4000000000, \"MemoryBytes\": 17179869184}, \"Reservations\": {\"NanoCPUs\": 100000000, \"MemoryBytes\": 536870912, \"GenericResources\": [{\"DiscreteResourceSpec\": {\"Kind\": \"VRAM\", \"Value\": 1}}]}}}]", - "container_label_io_simcore_runtime_simcore_user_agent": "puppeteer", - "container_label_io_simcore_runtime_project_id": "df604058-0c26-11ee-994f-02420a0b0fc8", - "container_label_io_simcore_runtime_user_id": "43819", - "container_label_io_simcore_runtime_node_id": "14387f03-4a37-5187-b8e0-0e491389ade4", - "container_label_io_simcore_runtime_cpu_limit": "3.5", - "container_label_io_simcore_runtime_memory_limit": "17179869184", - "id": "/docker/7f7d260357ee8c80f69b148bc090068df4bc1c9aafad909dc1557934d0366967", - "image": "registry.osparc.io/simcore/services/dynamic/jupyter-smash:3.0.7", - "instance": "gpu1", - "job": "cadvisor", - "name": "dy-sidecar-88ebaebf-c50e-5b33-a3ce-fe7ed2ad9668-0-jupyter-smash" - }, - "values": [ - [ - 1686906660, - "2.4900833509999996" - ], - [ - 1686906720, - "10.969049619000002" - ], - [ - 1686906780, - "17.436269327999998" - ], - [ - 1686906840, - "17.436269327999998" - ], - [ - 1686906900, - "17.436269327999998" - ], - [ - 1686906960, - "17.436269327999998" - ], - [ - 1686907020, - "17.436269327999998" - ] - ] - }, - { - "metric": { - "container_label_com_docker_compose_oneoff": "False", - "container_label_com_docker_compose_project_working_dir": "/tmp/tmp_3seh6kp", - "container_label_com_docker_compose_version": "1.29.1", - "container_label_io_simcore_runtime_product_name": "osparc", - "container_label_simcore_service_settings": "[{\"name\": \"ports\", \"type\": \"int\", \"value\": 8888}, {\"name\": \"env\", \"type\": \"string\", \"value\": [\"DISPLAY=:0\"]}, {\"name\": \"env\", \"type\": \"string\", \"value\": [\"SYM_SERVER_HOSTNAME=sym-server_%service_uuid%\"]}, {\"name\": \"mount\", \"type\": \"object\", \"value\": [{\"ReadOnly\": true, \"Source\": \"/tmp/.X11-unix\", \"Target\": \"/tmp/.X11-unix\", \"Type\": \"bind\"}]}, {\"name\": \"constraints\", \"type\": \"string\", \"value\": [\"node.platform.os == linux\"]}, {\"name\": \"Resources\", \"type\": \"Resources\", \"value\": {\"Limits\": {\"NanoCPUs\": 4000000000, \"MemoryBytes\": 17179869184}, \"Reservations\": {\"NanoCPUs\": 100000000, \"MemoryBytes\": 536870912, \"GenericResources\": [{\"DiscreteResourceSpec\": {\"Kind\": \"VRAM\", \"Value\": 1}}]}}}]", - "container_label_io_simcore_runtime_simcore_user_agent": "puppeteer", - "container_label_io_simcore_runtime_project_id": "df604058-0c26-11ee-994f-02420a0b0fc8", - "container_label_io_simcore_runtime_user_id": "43819", - "container_label_io_simcore_runtime_node_id": "14387f03-4a37-5187-b8e0-0e491389ade4", - "container_label_io_simcore_runtime_cpu_limit": "3.5", - "container_label_io_simcore_runtime_memory_limit": "17179869184", - "id": "/docker/58e1138d51eb5eafd737024d0df0b01ef88f2087e5a3922565c59130d57ac7a3", - "image": "registry.osparc.io/simcore/services/dynamic/jupyter-smash:3.0.7", - "instance": "gpu1", - "job": "cadvisor", - "name": "dy-sidecar-2b231c38-0ebc-5cc0-9030-1ffe573f54e9-0-jupyter-smash" - }, - "values": [ - [ - 1686907440, - "5.157543565" - ], - [ - 1686907500, - "17.386926716" - ], - [ - 1686907560, - "17.386926716" - ] - ] - }, - { - "metric": { - "container_label_com_docker_compose_oneoff": "False", - "container_label_com_docker_compose_project_working_dir": "/tmp/tmp_3seh6kp", - "container_label_com_docker_compose_version": "1.29.1", - "container_label_io_simcore_runtime_product_name": "osparc", - "container_label_simcore_service_settings": "[{\"name\": \"ports\", \"type\": \"int\", \"value\": 8888}, {\"name\": \"env\", \"type\": \"string\", \"value\": [\"DISPLAY=:0\"]}, {\"name\": \"env\", \"type\": \"string\", \"value\": [\"SYM_SERVER_HOSTNAME=sym-server_%service_uuid%\"]}, {\"name\": \"mount\", \"type\": \"object\", \"value\": [{\"ReadOnly\": true, \"Source\": \"/tmp/.X11-unix\", \"Target\": \"/tmp/.X11-unix\", \"Type\": \"bind\"}]}, {\"name\": \"constraints\", \"type\": \"string\", \"value\": [\"node.platform.os == linux\"]}, {\"name\": \"Resources\", \"type\": \"Resources\", \"value\": {\"Limits\": {\"NanoCPUs\": 4000000000, \"MemoryBytes\": 17179869184}, \"Reservations\": {\"NanoCPUs\": 100000000, \"MemoryBytes\": 536870912, \"GenericResources\": [{\"DiscreteResourceSpec\": {\"Kind\": \"VRAM\", \"Value\": 1}}]}}}]", - "container_label_io_simcore_runtime_simcore_user_agent": "puppeteer", - "container_label_io_simcore_runtime_project_id": "df604058-0c26-11ee-994f-02420a0b0fc8", - "container_label_io_simcore_runtime_user_id": "43819", - "container_label_io_simcore_runtime_node_id": "14387f03-4a37-5187-b8e0-0e491389ade4", - "container_label_io_simcore_runtime_cpu_limit": "3.5", - "container_label_io_simcore_runtime_memory_limit": "17179869184", - "id": "/docker/58e1138d51eb5eafd737024d0df0b01ef88f2087e5a3922565c59130d57ac7a3", - "image": "registry.osparc.io/simcore/services/dynamic/jupyter-smash:3.0.7", - "instance": "gpu1", - "job": "cadvisor", - "name": "dy-sidecar-2b231c38-0ebc-5cc0-9030-1ffe573f54e9-0-jupyter-smash" - }, - "values": [ - [ - 1686907440, - "5.157543565" - ], - [ - 1686907500, - "17.386926716" - ], - [ - 1686908560, - "20.846512345" - ] - ] - } -] diff --git a/services/resource-usage-tracker/tests/unit/with_dbs/test_api_resource_tracker_service_runs__export.py b/services/resource-usage-tracker/tests/unit/with_dbs/test_api_resource_tracker_service_runs__export.py index c53c1accb90..37ea1fa8ac4 100644 --- a/services/resource-usage-tracker/tests/unit/with_dbs/test_api_resource_tracker_service_runs__export.py +++ b/services/resource-usage-tracker/tests/unit/with_dbs/test_api_resource_tracker_service_runs__export.py @@ -26,7 +26,7 @@ @pytest.fixture async def mocked_export(mocker: MockerFixture): mock_export = mocker.patch( - "simcore_service_resource_usage_tracker.services.resource_tracker_service_runs.ResourceTrackerRepository.export_service_runs_table_to_s3", + "simcore_service_resource_usage_tracker.services.service_runs.ResourceTrackerRepository.export_service_runs_table_to_s3", autospec=True, ) @@ -36,7 +36,7 @@ async def mocked_export(mocker: MockerFixture): @pytest.fixture async def mocked_presigned_link(mocker: MockerFixture): mock_presigned_link = mocker.patch( - "simcore_service_resource_usage_tracker.services.resource_tracker_service_runs.SimcoreS3API.create_single_presigned_download_link", + "simcore_service_resource_usage_tracker.services.service_runs.SimcoreS3API.create_single_presigned_download_link", return_value=parse_obj_as( AnyUrl, "https://www.testing.com/", diff --git a/services/resource-usage-tracker/tests/unit/with_dbs/test_api_resource_tracker_service_runs__list_billable.py b/services/resource-usage-tracker/tests/unit/with_dbs/test_api_resource_tracker_service_runs__list_billable.py index c9bd9e7a0c6..a9027414d5d 100644 --- a/services/resource-usage-tracker/tests/unit/with_dbs/test_api_resource_tracker_service_runs__list_billable.py +++ b/services/resource-usage-tracker/tests/unit/with_dbs/test_api_resource_tracker_service_runs__list_billable.py @@ -13,10 +13,8 @@ ) from models_library.rest_ordering import OrderBy, OrderDirection from servicelib.rabbitmq import RabbitMQRPCClient +from servicelib.rabbitmq._errors import RPCServerError from servicelib.rabbitmq.rpc_interfaces.resource_usage_tracker import service_runs -from servicelib.rabbitmq.rpc_interfaces.resource_usage_tracker.errors import ( - CustomResourceUsageTrackerError, -) from simcore_postgres_database.models.resource_tracker_credit_transactions import ( resource_tracker_credit_transactions, ) @@ -188,10 +186,11 @@ async def test_rpc_list_service_runs_raising_custom_error( resource_tracker_setup_db: dict, rpc_client: RabbitMQRPCClient, ): - with pytest.raises(CustomResourceUsageTrackerError): + with pytest.raises(RPCServerError) as e: await service_runs.get_service_run_page( rpc_client, user_id=_USER_ID, product_name="osparc", access_all_wallet_usage=True, ) + assert e diff --git a/services/resource-usage-tracker/tests/unit/with_dbs/test_background_task.py b/services/resource-usage-tracker/tests/unit/with_dbs/test_background_task_periodic_heartbeat_check.py similarity index 95% rename from services/resource-usage-tracker/tests/unit/with_dbs/test_background_task.py rename to services/resource-usage-tracker/tests/unit/with_dbs/test_background_task_periodic_heartbeat_check.py index 2b719326bc9..ce2f3f8a6db 100644 --- a/services/resource-usage-tracker/tests/unit/with_dbs/test_background_task.py +++ b/services/resource-usage-tracker/tests/unit/with_dbs/test_background_task_periodic_heartbeat_check.py @@ -16,18 +16,16 @@ resource_tracker_service_runs, ) from simcore_service_resource_usage_tracker.core.settings import ApplicationSettings -from simcore_service_resource_usage_tracker.models.resource_tracker_credit_transactions import ( +from simcore_service_resource_usage_tracker.models.credit_transactions import ( CreditTransactionDB, ) -from simcore_service_resource_usage_tracker.models.resource_tracker_service_runs import ( - ServiceRunDB, +from simcore_service_resource_usage_tracker.models.service_runs import ServiceRunDB +from simcore_service_resource_usage_tracker.services.background_task_periodic_heartbeat_check import ( + periodic_check_of_running_services_task, ) -from simcore_service_resource_usage_tracker.modules.db.repositories.resource_tracker import ( +from simcore_service_resource_usage_tracker.services.modules.db.repositories.resource_tracker import ( ResourceTrackerRepository, ) -from simcore_service_resource_usage_tracker.resource_tracker_background_task import ( - periodic_check_of_running_services_task, -) pytest_simcore_core_services_selection = ["postgres", "rabbit"] pytest_simcore_ops_services_selection = [ diff --git a/services/resource-usage-tracker/tests/unit/with_dbs/test_process_rabbitmq_message.py b/services/resource-usage-tracker/tests/unit/with_dbs/test_process_rabbitmq_message.py index dec714a582b..da321f593f3 100644 --- a/services/resource-usage-tracker/tests/unit/with_dbs/test_process_rabbitmq_message.py +++ b/services/resource-usage-tracker/tests/unit/with_dbs/test_process_rabbitmq_message.py @@ -8,10 +8,10 @@ SimcorePlatformStatus, ) from servicelib.rabbitmq import RabbitMQClient -from simcore_service_resource_usage_tracker.modules.db.repositories.resource_tracker import ( +from simcore_service_resource_usage_tracker.services.modules.db.repositories.resource_tracker import ( ResourceTrackerRepository, ) -from simcore_service_resource_usage_tracker.resource_tracker_process_messages import ( +from simcore_service_resource_usage_tracker.services.process_message_running_service import ( _process_heartbeat_event, _process_start_event, _process_stop_event, diff --git a/services/resource-usage-tracker/tests/unit/with_dbs/test_process_rabbitmq_message_with_billing.py b/services/resource-usage-tracker/tests/unit/with_dbs/test_process_rabbitmq_message_with_billing.py index 4b6c1a0dfac..4537d1fb6d2 100644 --- a/services/resource-usage-tracker/tests/unit/with_dbs/test_process_rabbitmq_message_with_billing.py +++ b/services/resource-usage-tracker/tests/unit/with_dbs/test_process_rabbitmq_message_with_billing.py @@ -31,10 +31,10 @@ resource_tracker_pricing_units, ) from simcore_postgres_database.models.services import services_meta_data -from simcore_service_resource_usage_tracker.modules.db.repositories.resource_tracker import ( +from simcore_service_resource_usage_tracker.services.modules.db.repositories.resource_tracker import ( ResourceTrackerRepository, ) -from simcore_service_resource_usage_tracker.resource_tracker_process_messages import ( +from simcore_service_resource_usage_tracker.services.process_message_running_service import ( _process_heartbeat_event, _process_start_event, _process_stop_event, diff --git a/services/resource-usage-tracker/tests/unit/with_dbs/test_process_rabbitmq_message_with_billing_cost_0.py b/services/resource-usage-tracker/tests/unit/with_dbs/test_process_rabbitmq_message_with_billing_cost_0.py index c1d62af5b23..a3e69edac99 100644 --- a/services/resource-usage-tracker/tests/unit/with_dbs/test_process_rabbitmq_message_with_billing_cost_0.py +++ b/services/resource-usage-tracker/tests/unit/with_dbs/test_process_rabbitmq_message_with_billing_cost_0.py @@ -31,10 +31,10 @@ resource_tracker_pricing_units, ) from simcore_postgres_database.models.services import services_meta_data -from simcore_service_resource_usage_tracker.modules.db.repositories.resource_tracker import ( +from simcore_service_resource_usage_tracker.services.modules.db.repositories.resource_tracker import ( ResourceTrackerRepository, ) -from simcore_service_resource_usage_tracker.resource_tracker_process_messages import ( +from simcore_service_resource_usage_tracker.services.process_message_running_service import ( _process_heartbeat_event, _process_start_event, _process_stop_event, diff --git a/services/web/server/src/simcore_service_webserver/resource_usage/_pricing_plans_admin_handlers.py b/services/web/server/src/simcore_service_webserver/resource_usage/_pricing_plans_admin_handlers.py index b71317b1aab..d8b4749a37a 100644 --- a/services/web/server/src/simcore_service_webserver/resource_usage/_pricing_plans_admin_handlers.py +++ b/services/web/server/src/simcore_service_webserver/resource_usage/_pricing_plans_admin_handlers.py @@ -26,9 +26,7 @@ parse_request_path_parameters_as, ) from servicelib.aiohttp.typing_extension import Handler -from servicelib.rabbitmq.rpc_interfaces.resource_usage_tracker.errors import ( - CustomResourceUsageTrackerError, -) +from servicelib.rabbitmq._errors import RPCServerError from servicelib.request_keys import RQT_USERID_KEY from .._constants import RQ_PRODUCT_KEY @@ -49,8 +47,10 @@ async def wrapper(request: web.Request) -> web.StreamResponse: try: return await handler(request) - except CustomResourceUsageTrackerError as exc: - raise CustomResourceUsageTrackerError from exc + except RPCServerError as exc: + # NOTE: This will be improved; we will add a mapping between + # RPC errors and user-friendly frontend errors to pass to the frontend. + raise RPCServerError from exc return wrapper