From b5539f2b5296acabda63ec7f41a4cbf44786e6c8 Mon Sep 17 00:00:00 2001 From: Julian Cardonnet Date: Wed, 14 Aug 2024 12:26:08 -0300 Subject: [PATCH 01/13] Implement validation check for Organization, Name and Admin Email fields in Settings --- .../src/syft/service/settings/settings.py | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/packages/syft/src/syft/service/settings/settings.py b/packages/syft/src/syft/service/settings/settings.py index 950c4c711dc..a35cbe76372 100644 --- a/packages/syft/src/syft/service/settings/settings.py +++ b/packages/syft/src/syft/service/settings/settings.py @@ -4,6 +4,8 @@ from typing import Any # third party +from email_validator import EmailNotValidError +from email_validator import validate_email from pydantic import field_validator from pydantic import model_validator from typing_extensions import Self @@ -30,6 +32,9 @@ logger = logging.getLogger(__name__) +MIN_ORG_NAME_LENGTH = 1 +MIN_SERVER_NAME_LENGTH = 1 + @serializable() class PwdTokenResetConfig(SyftObject): @@ -265,6 +270,30 @@ class ServerSettings(SyftObject): pwd_token_config: PwdTokenResetConfig = PwdTokenResetConfig() allow_guest_sessions: bool = True + @field_validator("admin_email") + def admin_email_format(cls, v: str) -> str: + try: + validate_email(v) + except EmailNotValidError as e: + raise ValueError(f"Invalid email format: {e}") + return v + + @field_validator("organization") + def organization_length(cls, v: str) -> str: + if len(v) < MIN_ORG_NAME_LENGTH: + raise ValueError( + f"'organization' must be at least {MIN_ORG_NAME_LENGTH} characters long" + ) + return v + + @field_validator("name") + def name_length(cls, v: str) -> str: + if len(v) < MIN_SERVER_NAME_LENGTH: + raise ValueError( + f'"name" must be at least {MIN_SERVER_NAME_LENGTH} characters long' + ) + return v + def _repr_html_(self) -> Any: # .api.services.notifications.settings() is how the server itself would dispatch notifications. # .api.services.notifications.user_settings() sets if a specific user wants or not to receive notifications. From 44719391f057cdf10837bc9c2867d7f7234b0545 Mon Sep 17 00:00:00 2001 From: Julian Cardonnet Date: Wed, 14 Aug 2024 12:34:18 -0300 Subject: [PATCH 02/13] Validate Settings on Update. Fix inconsistencies on services return types. Refactor Settings Service. --- .../syft/service/settings/settings_service.py | 102 ++++++++---------- 1 file changed, 47 insertions(+), 55 deletions(-) diff --git a/packages/syft/src/syft/service/settings/settings_service.py b/packages/syft/src/syft/service/settings/settings_service.py index b54abacd078..59b24edecfe 100644 --- a/packages/syft/src/syft/service/settings/settings_service.py +++ b/packages/syft/src/syft/service/settings/settings_service.py @@ -2,9 +2,7 @@ from string import Template # third party -from result import Err -from result import Ok -from result import Result +from pydantic import ValidationError # relative from ...abstract_server import ServerSideType @@ -44,7 +42,7 @@ def __init__(self, store: DocumentStore) -> None: self.stash = SettingsStash(store=store) @service_method(path="settings.get", name="get") - def get(self, context: UnauthedServiceContext) -> Result[Ok, Err]: + def get(self, context: UnauthedServiceContext) -> ServerSettings | SyftError: """Get Settings""" result = self.stash.get_all(context.server.signing_key.verify_key) @@ -54,14 +52,14 @@ def get(self, context: UnauthedServiceContext) -> Result[Ok, Err]: if len(settings) == 0: return SyftError(message="No settings found") result = settings[0] - return Ok(result) + return result else: return SyftError(message=result.err()) @service_method(path="settings.set", name="set") def set( self, context: AuthedServiceContext, settings: ServerSettings - ) -> Result[Ok, Err]: + ) -> ServerSettings | SyftError: """Set a new the Server Settings""" result = self.stash.set(context.credentials, settings) if result.is_ok(): @@ -77,21 +75,7 @@ def set( ) def update( self, context: AuthedServiceContext, settings: ServerSettingsUpdate - ) -> Result[SyftSuccess, SyftError]: - res = self._update(context, settings) - if res.is_ok(): - return SyftSuccess( - message=( - "Settings updated successfully. " - + "You must call .refresh() to sync your client with the changes." - ) - ) - else: - return SyftError(message=res.err()) - - def _update( - self, context: AuthedServiceContext, settings: ServerSettingsUpdate - ) -> Result[Ok, Err]: + ) -> SyftSuccess | SyftError: """ Update the Server Settings using the provided values. @@ -111,42 +95,50 @@ def _update( association_request_auto_approval: Optional[bool] Returns: - Result[SyftSuccess, SyftError]: A result indicating the success or failure of the update operation. + SyftSuccess | SyftError: A result indicating the success or failure of the update operation. Example: >>> server_client.update(name='foo', organization='bar', description='baz', signup_enabled=True) SyftSuccess: Settings updated successfully. """ + result = self.stash.get_all(context.credentials) - if result.is_ok(): - current_settings = result.ok() - if len(current_settings) > 0: - new_settings = current_settings[0].model_copy( - update=settings.to_dict(exclude_empty=True) - ) - notifier_service = context.server.get_service("notifierservice") + if result.is_err(): + return SyftError(message=result.err()) - # If notifications_enabled is present in the update, we need to update the notifier settings - if settings.notifications_enabled is True: - if not notifier_service.settings(context): - return SyftError( - message="Create notification settings using enable_notifications from user_service" - ) - notifier_service = context.server.get_service("notifierservice") - result = notifier_service.set_notifier_active_to_true(context) - elif settings.notifications_enabled is False: - if not notifier_service.settings(context): - return SyftError( - message="Create notification settings using enable_notifications from user_service" - ) - notifier_service = context.server.get_service("notifierservice") - result = notifier_service.set_notifier_active_to_false(context) - update_result = self.stash.update(context.credentials, new_settings) - return update_result - else: - return Err(value="No settings found") + current_settings = result.ok() + if len(current_settings) == 0: + return SyftError(message="No settings found") + try: + new_settings = current_settings[0].model_copy( + update=settings.to_dict(exclude_empty=True) + ) + ServerSettings.model_validate(new_settings.to_dict()) + except ValidationError as e: + return SyftError(message=str(e)) + + notifier_service = context.server.get_service("notifierservice") + if not notifier_service.settings(context): + return SyftError( + message="Create notification settings using enable_notifications from user_service" + ) + # If notifications_enabled is present in the update, we need to update the notifier settings + if settings.notifications_enabled is True: + result = notifier_service.set_notifier_active_to_true(context) + elif settings.notifications_enabled is False: + result = notifier_service.set_notifier_active_to_false(context) + + update_result = self.stash.update(context.credentials, new_settings) + + if update_result.is_ok(): + return SyftSuccess( + message=( + "Settings updated successfully. " + + "You must call .refresh() to sync your client with the changes." + ) + ) else: - return result + return SyftError(message=update_result.err()) @service_method( path="settings.set_server_side_type_dangerous", @@ -155,7 +147,7 @@ def _update( ) def set_server_side_type_dangerous( self, context: AuthedServiceContext, server_side_type: str - ) -> Result[SyftSuccess, SyftError]: + ) -> SyftSuccess | SyftError: side_type_options = [e.value for e in ServerSideType] if server_side_type not in side_type_options: return SyftError( @@ -231,7 +223,7 @@ def allow_guest_signup( flags.CAN_REGISTER = enable settings = ServerSettingsUpdate(signup_enabled=enable) - result = self._update(context=context, settings=settings) + result = self.update(context=context, settings=settings) if isinstance(result, SyftError): return SyftError(message=f"Failed to update settings: {result.err()}") @@ -252,9 +244,9 @@ def enable_eager_execution( """Enable/Disable eager execution.""" settings = ServerSettingsUpdate(eager_execution_enabled=enable) - result = self._update(context=context, settings=settings) + result = self.update(context=context, settings=settings) - if result.is_err(): + if isinstance(result, SyftError): return SyftError(message=f"Failed to update settings: {result.err()}") message = "enabled" if enable else "disabled" @@ -275,7 +267,7 @@ def allow_association_request_auto_approval( self, context: AuthedServiceContext, enable: bool ) -> SyftSuccess | SyftError: new_settings = ServerSettingsUpdate(association_request_auto_approval=enable) - result = self._update(context, settings=new_settings) + result = self.update(context, settings=new_settings) if isinstance(result, SyftError): return result @@ -329,7 +321,7 @@ def welcome_customize( welcome_msg = HTMLObject(text=html) new_settings = ServerSettingsUpdate(welcome_markdown=welcome_msg) - result = self._update(context=context, settings=new_settings) + result = self.update(context=context, settings=new_settings) if isinstance(result, SyftError): return result From f103ece7430c4b3b81058c76300d6f922245287d Mon Sep 17 00:00:00 2001 From: Julian Cardonnet Date: Wed, 14 Aug 2024 19:22:53 -0300 Subject: [PATCH 03/13] Simplify email validation. Fix settings tests. --- packages/syft/src/syft/service/settings/settings.py | 13 ++----------- .../tests/syft/settings/settings_service_test.py | 6 +++--- 2 files changed, 5 insertions(+), 14 deletions(-) diff --git a/packages/syft/src/syft/service/settings/settings.py b/packages/syft/src/syft/service/settings/settings.py index a35cbe76372..ae05fbdd70c 100644 --- a/packages/syft/src/syft/service/settings/settings.py +++ b/packages/syft/src/syft/service/settings/settings.py @@ -4,8 +4,7 @@ from typing import Any # third party -from email_validator import EmailNotValidError -from email_validator import validate_email +from pydantic import EmailStr from pydantic import field_validator from pydantic import model_validator from typing_extensions import Self @@ -257,7 +256,7 @@ class ServerSettings(SyftObject): description: str = "This is the default description for a Datasite Server." server_type: ServerType = ServerType.DATASITE signup_enabled: bool - admin_email: str + admin_email: EmailStr server_side_type: ServerSideType = ServerSideType.HIGH_SIDE show_warnings: bool association_request_auto_approval: bool @@ -270,14 +269,6 @@ class ServerSettings(SyftObject): pwd_token_config: PwdTokenResetConfig = PwdTokenResetConfig() allow_guest_sessions: bool = True - @field_validator("admin_email") - def admin_email_format(cls, v: str) -> str: - try: - validate_email(v) - except EmailNotValidError as e: - raise ValueError(f"Invalid email format: {e}") - return v - @field_validator("organization") def organization_length(cls, v: str) -> str: if len(v) < MIN_ORG_NAME_LENGTH: diff --git a/packages/syft/tests/syft/settings/settings_service_test.py b/packages/syft/tests/syft/settings/settings_service_test.py index 03af399bc8f..e140bf028a9 100644 --- a/packages/syft/tests/syft/settings/settings_service_test.py +++ b/packages/syft/tests/syft/settings/settings_service_test.py @@ -85,8 +85,8 @@ def test_settingsservice_set_success( response = settings_service.set(authed_context, settings) assert response.is_ok() is True - assert isinstance(response.ok(), ServerSettings) - assert response.ok() == settings + assert isinstance(response, ServerSettings) + assert response == settings def test_settingsservice_set_fail( @@ -117,7 +117,7 @@ def add_mock_settings( result = settings_stash.partition.set(root_verify_key, settings) assert result.is_ok() - created_settings = result.ok() + created_settings = result assert created_settings is not None return created_settings From c5201d007efd1eda259d8ddd51241188f64b2ac5 Mon Sep 17 00:00:00 2001 From: Julian Cardonnet Date: Wed, 14 Aug 2024 20:05:42 -0300 Subject: [PATCH 04/13] Fix test --- packages/syft/tests/syft/settings/settings_service_test.py | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/syft/tests/syft/settings/settings_service_test.py b/packages/syft/tests/syft/settings/settings_service_test.py index e140bf028a9..1d827081006 100644 --- a/packages/syft/tests/syft/settings/settings_service_test.py +++ b/packages/syft/tests/syft/settings/settings_service_test.py @@ -84,7 +84,6 @@ def test_settingsservice_set_success( ) -> None: response = settings_service.set(authed_context, settings) - assert response.is_ok() is True assert isinstance(response, ServerSettings) assert response == settings From 7e2a560003a7f834db78ea3cbeea4fb6e9047215 Mon Sep 17 00:00:00 2001 From: Julian Cardonnet Date: Wed, 14 Aug 2024 21:17:00 -0300 Subject: [PATCH 05/13] unbox result object Fix test cases --- packages/syft/src/syft/service/settings/settings_service.py | 2 +- packages/syft/tests/syft/settings/settings_service_test.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/syft/src/syft/service/settings/settings_service.py b/packages/syft/src/syft/service/settings/settings_service.py index 59b24edecfe..8351930aeb8 100644 --- a/packages/syft/src/syft/service/settings/settings_service.py +++ b/packages/syft/src/syft/service/settings/settings_service.py @@ -63,7 +63,7 @@ def set( """Set a new the Server Settings""" result = self.stash.set(context.credentials, settings) if result.is_ok(): - return result + return result.ok() else: return SyftError(message=result.err()) diff --git a/packages/syft/tests/syft/settings/settings_service_test.py b/packages/syft/tests/syft/settings/settings_service_test.py index 1d827081006..cadefc9edce 100644 --- a/packages/syft/tests/syft/settings/settings_service_test.py +++ b/packages/syft/tests/syft/settings/settings_service_test.py @@ -45,7 +45,7 @@ def mock_stash_get_all(credentials) -> Ok: response = settings_service.get(context=authed_context) - assert isinstance(response.ok(), ServerSettings) + assert isinstance(response, ServerSettings) assert response == expected_output @@ -116,7 +116,7 @@ def add_mock_settings( result = settings_stash.partition.set(root_verify_key, settings) assert result.is_ok() - created_settings = result + created_settings = result.ok() assert created_settings is not None return created_settings From caa4a8cead1e94ebb4ec6ce2d04dba25dea06e5d Mon Sep 17 00:00:00 2001 From: Julian Cardonnet Date: Wed, 14 Aug 2024 21:27:09 -0300 Subject: [PATCH 06/13] Fix test --- packages/syft/tests/syft/settings/settings_service_test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/syft/tests/syft/settings/settings_service_test.py b/packages/syft/tests/syft/settings/settings_service_test.py index cadefc9edce..e6339cbcc8e 100644 --- a/packages/syft/tests/syft/settings/settings_service_test.py +++ b/packages/syft/tests/syft/settings/settings_service_test.py @@ -36,7 +36,7 @@ def test_settingsservice_get_success( authed_context: AuthedServiceContext, ) -> None: mock_stash_get_all_output = [settings, settings] - expected_output = Ok(mock_stash_get_all_output[0]) + expected_output = mock_stash_get_all_output[0] def mock_stash_get_all(credentials) -> Ok: return Ok(mock_stash_get_all_output) From cbb7fd9bea83501136b2052c467f872201a0568c Mon Sep 17 00:00:00 2001 From: IonesioJunior Date: Mon, 2 Sep 2024 10:04:29 -0300 Subject: [PATCH 07/13] Fix linting --- packages/syft/src/syft/service/settings/settings_service.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/syft/src/syft/service/settings/settings_service.py b/packages/syft/src/syft/service/settings/settings_service.py index ef5498beb65..ca307ef2567 100644 --- a/packages/syft/src/syft/service/settings/settings_service.py +++ b/packages/syft/src/syft/service/settings/settings_service.py @@ -2,6 +2,7 @@ from string import Template from typing import Any from typing import cast + # third party from pydantic import ValidationError @@ -58,7 +59,6 @@ def __init__(self, store: DocumentStore) -> None: @service_method(path="settings.get", name="get") def get(self, context: UnauthedServiceContext) -> ServerSettings: - """Get Settings""" all_settings = self.stash.get_all( context.server.signing_key.verify_key From acf8448256108f385bacae81a2530b0e703f5df5 Mon Sep 17 00:00:00 2001 From: eelcovdw Date: Mon, 2 Sep 2024 15:14:53 +0200 Subject: [PATCH 08/13] add env var for num_jobs+num_users --- ...tart-and-configure-server-and-admins.ipynb | 9 ++- .../bigquery/01-setup-datasite.ipynb | 9 ++- .../bigquery/011-users-emails-passwords.ipynb | 70 +++++++++++++------ .../scenarios/bigquery/02-configure-api.ipynb | 2 +- .../scenarios/bigquery/021-create-jobs.ipynb | 16 +++-- .../bigquery/04-do-review-requests.ipynb | 2 +- notebooks/scenarios/bigquery/job_helpers.py | 8 +-- tox.ini | 4 ++ 8 files changed, 84 insertions(+), 36 deletions(-) diff --git a/notebooks/scenarios/bigquery/00-start-and-configure-server-and-admins.ipynb b/notebooks/scenarios/bigquery/00-start-and-configure-server-and-admins.ipynb index 213c4c6d405..8235576b5f5 100644 --- a/notebooks/scenarios/bigquery/00-start-and-configure-server-and-admins.ipynb +++ b/notebooks/scenarios/bigquery/00-start-and-configure-server-and-admins.ipynb @@ -212,6 +212,13 @@ "source": [ "server.land()" ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": { @@ -230,7 +237,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.12.2" + "version": "3.10.13" } }, "nbformat": 4, diff --git a/notebooks/scenarios/bigquery/01-setup-datasite.ipynb b/notebooks/scenarios/bigquery/01-setup-datasite.ipynb index 51e4efb58c7..0f2d42fe391 100644 --- a/notebooks/scenarios/bigquery/01-setup-datasite.ipynb +++ b/notebooks/scenarios/bigquery/01-setup-datasite.ipynb @@ -476,6 +476,13 @@ "source": [ "server.land()" ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": { @@ -494,7 +501,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.12.2" + "version": "3.10.13" } }, "nbformat": 4, diff --git a/notebooks/scenarios/bigquery/011-users-emails-passwords.ipynb b/notebooks/scenarios/bigquery/011-users-emails-passwords.ipynb index 45e6e10d847..c585aa55a07 100644 --- a/notebooks/scenarios/bigquery/011-users-emails-passwords.ipynb +++ b/notebooks/scenarios/bigquery/011-users-emails-passwords.ipynb @@ -129,14 +129,32 @@ "# high_client.api.services.settings.disable_notifications()" ] }, + { + "cell_type": "markdown", + "id": "9", + "metadata": {}, + "source": [ + "# Register users" + ] + }, { "cell_type": "code", "execution_count": null, - "id": "9", + "id": "10", + "metadata": {}, + "outputs": [], + "source": [ + "num_users = int(os.environ.get(\"NUM_TEST_USERS\", 5))\n", + "print(f\"registering {num_users} users\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "11", "metadata": {}, "outputs": [], "source": [ - "num_users = 5\n", "users = []\n", "email_disable_index = 0\n", "reset_password_index = 1\n", @@ -155,7 +173,7 @@ { "cell_type": "code", "execution_count": null, - "id": "10", + "id": "12", "metadata": {}, "outputs": [], "source": [ @@ -165,7 +183,7 @@ { "cell_type": "code", "execution_count": null, - "id": "11", + "id": "13", "metadata": {}, "outputs": [], "source": [ @@ -178,7 +196,7 @@ { "cell_type": "code", "execution_count": null, - "id": "12", + "id": "14", "metadata": {}, "outputs": [], "source": [ @@ -197,7 +215,7 @@ { "cell_type": "code", "execution_count": null, - "id": "13", + "id": "15", "metadata": {}, "outputs": [], "source": [ @@ -222,7 +240,7 @@ { "cell_type": "code", "execution_count": null, - "id": "14", + "id": "16", "metadata": {}, "outputs": [], "source": [ @@ -232,7 +250,7 @@ { "cell_type": "code", "execution_count": null, - "id": "15", + "id": "17", "metadata": {}, "outputs": [], "source": [ @@ -243,7 +261,7 @@ { "cell_type": "code", "execution_count": null, - "id": "16", + "id": "18", "metadata": {}, "outputs": [], "source": [ @@ -257,7 +275,7 @@ { "cell_type": "code", "execution_count": null, - "id": "17", + "id": "19", "metadata": {}, "outputs": [], "source": [ @@ -269,7 +287,7 @@ { "cell_type": "code", "execution_count": null, - "id": "18", + "id": "20", "metadata": {}, "outputs": [], "source": [ @@ -279,7 +297,7 @@ { "cell_type": "code", "execution_count": null, - "id": "19", + "id": "21", "metadata": {}, "outputs": [], "source": [ @@ -290,7 +308,7 @@ { "cell_type": "code", "execution_count": null, - "id": "20", + "id": "22", "metadata": {}, "outputs": [], "source": [ @@ -301,7 +319,7 @@ { "cell_type": "code", "execution_count": null, - "id": "21", + "id": "23", "metadata": {}, "outputs": [], "source": [ @@ -312,7 +330,7 @@ { "cell_type": "code", "execution_count": null, - "id": "22", + "id": "24", "metadata": {}, "outputs": [], "source": [ @@ -323,7 +341,7 @@ { "cell_type": "code", "execution_count": null, - "id": "23", + "id": "25", "metadata": {}, "outputs": [], "source": [ @@ -336,7 +354,7 @@ { "cell_type": "code", "execution_count": null, - "id": "24", + "id": "26", "metadata": {}, "outputs": [], "source": [ @@ -346,7 +364,7 @@ { "cell_type": "code", "execution_count": null, - "id": "25", + "id": "27", "metadata": {}, "outputs": [], "source": [ @@ -357,7 +375,7 @@ { "cell_type": "code", "execution_count": null, - "id": "26", + "id": "28", "metadata": {}, "outputs": [], "source": [ @@ -367,7 +385,7 @@ { "cell_type": "code", "execution_count": null, - "id": "27", + "id": "29", "metadata": {}, "outputs": [], "source": [ @@ -377,12 +395,20 @@ { "cell_type": "code", "execution_count": null, - "id": "28", + "id": "30", "metadata": {}, "outputs": [], "source": [ "server.land()" ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "31", + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": { @@ -401,7 +427,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.12.2" + "version": "3.10.13" } }, "nbformat": 4, diff --git a/notebooks/scenarios/bigquery/02-configure-api.ipynb b/notebooks/scenarios/bigquery/02-configure-api.ipynb index a1e805bc37e..bcec4a3905e 100644 --- a/notebooks/scenarios/bigquery/02-configure-api.ipynb +++ b/notebooks/scenarios/bigquery/02-configure-api.ipynb @@ -535,7 +535,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.12.2" + "version": "3.10.13" } }, "nbformat": 4, diff --git a/notebooks/scenarios/bigquery/021-create-jobs.ipynb b/notebooks/scenarios/bigquery/021-create-jobs.ipynb index 9d718e8c24e..3b6f56d57a3 100644 --- a/notebooks/scenarios/bigquery/021-create-jobs.ipynb +++ b/notebooks/scenarios/bigquery/021-create-jobs.ipynb @@ -169,10 +169,9 @@ "metadata": {}, "outputs": [], "source": [ - "# maybe we should assign one of each first, and then randomly generate the rest\n", - "n_per_user = 2\n", + "num_jobs = int(os.environ.get(\"NUM_TEST_JOBS\", 10))\n", "\n", - "jobs = create_jobs(users, n_per_user=n_per_user)" + "jobs = create_jobs(users, n=num_jobs)" ] }, { @@ -182,7 +181,12 @@ "metadata": {}, "outputs": [], "source": [ - "jobs" + "# stdlib\n", + "from collections import Counter\n", + "\n", + "counts = Counter([j.job_type for j in jobs])\n", + "for k, v in counts.most_common():\n", + " print(f\"number of {k}: {v}\")" ] }, { @@ -220,7 +224,7 @@ "metadata": {}, "outputs": [], "source": [ - "assert len(jobs) == len(users) * n_per_user\n", + "assert len(jobs) == num_jobs\n", "assert all(isinstance(j, TestJob) for j in jobs)\n", "assert all(job.client is not None for job in jobs)" ] @@ -428,7 +432,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.12.2" + "version": "3.10.13" } }, "nbformat": 4, diff --git a/notebooks/scenarios/bigquery/04-do-review-requests.ipynb b/notebooks/scenarios/bigquery/04-do-review-requests.ipynb index 9af349607d1..011c4bf3e25 100644 --- a/notebooks/scenarios/bigquery/04-do-review-requests.ipynb +++ b/notebooks/scenarios/bigquery/04-do-review-requests.ipynb @@ -253,7 +253,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.12.2" + "version": "3.10.13" } }, "nbformat": 4, diff --git a/notebooks/scenarios/bigquery/job_helpers.py b/notebooks/scenarios/bigquery/job_helpers.py index 00afe5b9c50..15ad35480e9 100644 --- a/notebooks/scenarios/bigquery/job_helpers.py +++ b/notebooks/scenarios/bigquery/job_helpers.py @@ -247,15 +247,15 @@ def create_job_many_columns(user: TestUser) -> TestJob: return job -def create_job(user: TestUser) -> TestJob: +def create_random_job(user: TestUser) -> TestJob: job_func = random.choice(create_job_functions) return job_func(user) -def create_jobs(users: list[TestUser], n_per_user: int = 10) -> list[TestJob]: +def create_jobs(users: list[TestUser], n: int = 10) -> list[TestJob]: jobs = [] num_users = len(users) - total_jobs = n_per_user * num_users + total_jobs = n user_index = 0 each_count = 0 # keep making jobs until we have enough @@ -266,7 +266,7 @@ def create_jobs(users: list[TestUser], n_per_user: int = 10) -> list[TestJob]: each_count += 1 else: # otherwise lets get a random one - job_func = create_job + job_func = create_random_job # use the current index of user jobs.append(job_func(users[user_index])) diff --git a/tox.ini b/tox.ini index 3716fc9de44..4a394a44fe4 100644 --- a/tox.ini +++ b/tox.ini @@ -355,6 +355,8 @@ setenv = TEST_query_limit_size={env:test_query_limit_size:500000} SERVER_URL = {env:SERVER_URL:http://localhost} SERVER_PORT = {env:SERVER_PORT:8080} + NUM_TEST_USERS = {env:NUM_TEST_USERS:5} + NUM_TEST_JOBS = {env:NUM_TEST_JOBS:10} commands = python --version bash -c "echo Running with ORCHESTRA_DEPLOYMENT_TYPE=$ORCHESTRA_DEPLOYMENT_TYPE DEV_MODE=$DEV_MODE TEST_NOTEBOOK_PATHS=$TEST_NOTEBOOK_PATHS; date" @@ -422,6 +424,8 @@ setenv = TEST_EXTERNAL_REGISTRY = {env:TEST_EXTERNAL_REGISTRY:k3d-registry.localhost:5800} TEST_QUERY_LIMIT_SIZE={env:TEST_QUERY_LIMIT_SIZE:500000} TRACING={env:TRACING:False} + NUM_TEST_USERS = {env:NUM_TEST_USERS:5} + NUM_TEST_JOBS = {env:NUM_TEST_JOBS:10} commands = bash -c "python --version || true" bash -c "echo Running with GITHUB_CI=$GITHUB_CI; date" From 707257a0f4e899ef0be7266d3c9d2a97b1969f39 Mon Sep 17 00:00:00 2001 From: IonesioJunior Date: Mon, 2 Sep 2024 10:35:15 -0300 Subject: [PATCH 09/13] ADD new protocol version --- packages/syft/src/syft/protocol/protocol_version.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/syft/src/syft/protocol/protocol_version.json b/packages/syft/src/syft/protocol/protocol_version.json index d12435881c9..bc025daa762 100644 --- a/packages/syft/src/syft/protocol/protocol_version.json +++ b/packages/syft/src/syft/protocol/protocol_version.json @@ -339,7 +339,7 @@ }, "4": { "version": 4, - "hash": "cf6c1cb55d569af9823d8541ca038806bd350450a919345244ed4f432a099f34", + "hash": "b8067777967a0e06733433e179e549caaf501419d62f7e8474ee33b839e3890d", "action": "add" } }, From 682ed37cd4755b888dcbe8084838f1e05bc5f4f8 Mon Sep 17 00:00:00 2001 From: eelcovdw Date: Mon, 2 Sep 2024 15:40:23 +0200 Subject: [PATCH 10/13] add num_test_workers --- notebooks/scenarios/bigquery/01-setup-datasite.ipynb | 6 ++++-- tox.ini | 1 + 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/notebooks/scenarios/bigquery/01-setup-datasite.ipynb b/notebooks/scenarios/bigquery/01-setup-datasite.ipynb index 0f2d42fe391..6835be3053c 100644 --- a/notebooks/scenarios/bigquery/01-setup-datasite.ipynb +++ b/notebooks/scenarios/bigquery/01-setup-datasite.ipynb @@ -402,7 +402,9 @@ "source": [ "worker_pool_name = \"bigquery-pool\"\n", "custom_pool_pod_annotations = {\"bigquery-custom-pool\": \"Pod annotation for bigquery\"}\n", - "custom_pool_pod_labels = {\"bigquery-custom-pool\": \"Pod_label_for_bigquery\"}" + "custom_pool_pod_labels = {\"bigquery-custom-pool\": \"Pod_label_for_bigquery\"}\n", + "\n", + "num_workers = int(os.environ.get(\"NUM_TEST_WORKERS\", 1))" ] }, { @@ -414,7 +416,7 @@ "result = high_client.api.services.worker_pool.launch(\n", " pool_name=worker_pool_name,\n", " image_uid=worker_image.id,\n", - " num_workers=1,\n", + " num_workers=num_workers,\n", " pod_annotations=custom_pool_pod_annotations,\n", " pod_labels=custom_pool_pod_labels,\n", ")\n", diff --git a/tox.ini b/tox.ini index 4a394a44fe4..1f955d8a1af 100644 --- a/tox.ini +++ b/tox.ini @@ -426,6 +426,7 @@ setenv = TRACING={env:TRACING:False} NUM_TEST_USERS = {env:NUM_TEST_USERS:5} NUM_TEST_JOBS = {env:NUM_TEST_JOBS:10} + NUM_TEST_WORKERS = {env:NUM_TEST_WORKERS:4} commands = bash -c "python --version || true" bash -c "echo Running with GITHUB_CI=$GITHUB_CI; date" From 39fcc2e4fd86704546bf85606fb6ca2646d660be Mon Sep 17 00:00:00 2001 From: eelcovdw Date: Mon, 2 Sep 2024 15:47:31 +0200 Subject: [PATCH 11/13] fix scaling num_workers --- notebooks/scenarios/bigquery/01-setup-datasite.ipynb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/notebooks/scenarios/bigquery/01-setup-datasite.ipynb b/notebooks/scenarios/bigquery/01-setup-datasite.ipynb index 6835be3053c..c734b07298e 100644 --- a/notebooks/scenarios/bigquery/01-setup-datasite.ipynb +++ b/notebooks/scenarios/bigquery/01-setup-datasite.ipynb @@ -416,7 +416,7 @@ "result = high_client.api.services.worker_pool.launch(\n", " pool_name=worker_pool_name,\n", " image_uid=worker_image.id,\n", - " num_workers=num_workers,\n", + " num_workers=1,\n", " pod_annotations=custom_pool_pod_annotations,\n", " pod_labels=custom_pool_pod_labels,\n", ")\n", @@ -430,7 +430,9 @@ "outputs": [], "source": [ "if environment == \"remote\":\n", - " result = high_client.worker_pools.scale(number=2, pool_name=worker_pool_name)\n", + " result = high_client.worker_pools.scale(\n", + " number=num_workers, pool_name=worker_pool_name\n", + " )\n", " print(result)" ] }, From 0a7df9edec83db47327b516cb334d907ae827f14 Mon Sep 17 00:00:00 2001 From: eelcovdw Date: Mon, 2 Sep 2024 16:26:31 +0200 Subject: [PATCH 12/13] rename total_jobs --- notebooks/scenarios/bigquery/021-create-jobs.ipynb | 2 +- notebooks/scenarios/bigquery/job_helpers.py | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/notebooks/scenarios/bigquery/021-create-jobs.ipynb b/notebooks/scenarios/bigquery/021-create-jobs.ipynb index 3b6f56d57a3..c889100e86b 100644 --- a/notebooks/scenarios/bigquery/021-create-jobs.ipynb +++ b/notebooks/scenarios/bigquery/021-create-jobs.ipynb @@ -171,7 +171,7 @@ "source": [ "num_jobs = int(os.environ.get(\"NUM_TEST_JOBS\", 10))\n", "\n", - "jobs = create_jobs(users, n=num_jobs)" + "jobs = create_jobs(users, total_jobs=num_jobs)" ] }, { diff --git a/notebooks/scenarios/bigquery/job_helpers.py b/notebooks/scenarios/bigquery/job_helpers.py index 15ad35480e9..3d83a4f05a6 100644 --- a/notebooks/scenarios/bigquery/job_helpers.py +++ b/notebooks/scenarios/bigquery/job_helpers.py @@ -252,10 +252,9 @@ def create_random_job(user: TestUser) -> TestJob: return job_func(user) -def create_jobs(users: list[TestUser], n: int = 10) -> list[TestJob]: +def create_jobs(users: list[TestUser], total_jobs: int = 10) -> list[TestJob]: jobs = [] num_users = len(users) - total_jobs = n user_index = 0 each_count = 0 # keep making jobs until we have enough From 01c1e23b3bb58b794713aca8e0d671b6fa77c91d Mon Sep 17 00:00:00 2001 From: eelcovdw Date: Mon, 2 Sep 2024 16:26:55 +0200 Subject: [PATCH 13/13] default CI settings --- tox.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tox.ini b/tox.ini index 1f955d8a1af..67d86b19ff7 100644 --- a/tox.ini +++ b/tox.ini @@ -426,7 +426,7 @@ setenv = TRACING={env:TRACING:False} NUM_TEST_USERS = {env:NUM_TEST_USERS:5} NUM_TEST_JOBS = {env:NUM_TEST_JOBS:10} - NUM_TEST_WORKERS = {env:NUM_TEST_WORKERS:4} + NUM_TEST_WORKERS = {env:NUM_TEST_WORKERS:2} commands = bash -c "python --version || true" bash -c "echo Running with GITHUB_CI=$GITHUB_CI; date"