From dd16b80360b40ff204c76abe7018e136686c2cd9 Mon Sep 17 00:00:00 2001 From: Inoki Date: Fri, 15 Sep 2023 23:03:35 +0200 Subject: [PATCH] [GSK-1698] Remove legacy ML worker info and properties (#1390) * Remove TCP port exposing in ngrok Format `cli_server.py` by git pre-commit * Remove legacy worker related properties * Cleanup legacy ML worker port description in doc * Remove 40051 port in backend and ngrok configs * Try to remove all legacy ML worker related info * Clean up legacy port in legacy Docker compose file --------- Co-authored-by: Andrey Avtomonov --- .../giskard/config/ApplicationProperties.java | 5 -- .../giskard/web/dto/config/AppConfigDTO.java | 2 - .../dto/config/MLWorkerConnectionInfoDTO.java | 5 -- .../rest/controllers/SettingsController.java | 4 - .../src/main/resources/config/application.yml | 4 - .../src/test/resources/config/application.yml | 2 - docker-compose.dev.yml | 2 - docker-compose.yml | 4 - python-client/docs/cli/ngrok/index.rst | 2 - .../docs/guides/installation_app/index.rst | 4 +- .../installation_app/install_aws/index.md | 2 +- .../installation_app/install_gcp/index.md | 4 +- python-client/giskard/commands/cli_server.py | 82 ++++--------------- python-client/giskard/settings.py | 3 - python-client/tests/utils.py | 14 +--- scripts/ngrok.yml | 5 +- 16 files changed, 24 insertions(+), 120 deletions(-) diff --git a/backend/src/main/java/ai/giskard/config/ApplicationProperties.java b/backend/src/main/java/ai/giskard/config/ApplicationProperties.java index caf114135a..ceb0241612 100644 --- a/backend/src/main/java/ai/giskard/config/ApplicationProperties.java +++ b/backend/src/main/java/ai/giskard/config/ApplicationProperties.java @@ -16,11 +16,6 @@ @Getter @ConfigurationProperties(prefix = "giskard", ignoreUnknownFields = false) public class ApplicationProperties { - private String mlWorkerHost; - private int mlWorkerPort; - private int externalMlWorkerEntrypointPort; - private String externalMlWorkerEntrypointHost; - private boolean externalMlWorkerEnabled; private int apiTokenValidityInDays; private int invitationTokenValidityInDays; private int maxInboundMLWorkerMessageMB = 1024; diff --git a/backend/src/main/java/ai/giskard/web/dto/config/AppConfigDTO.java b/backend/src/main/java/ai/giskard/web/dto/config/AppConfigDTO.java index b9529ec39f..9874e8d5ad 100644 --- a/backend/src/main/java/ai/giskard/web/dto/config/AppConfigDTO.java +++ b/backend/src/main/java/ai/giskard/web/dto/config/AppConfigDTO.java @@ -42,8 +42,6 @@ public static class AppInfoDTO { private String buildCommitId; private Instant buildCommitTime; private GeneralSettings generalSettings; - private int externalMlWorkerEntrypointPort; - private String externalMlWorkerEntrypointHost; private String hfSpaceId; @JsonProperty(value = "isRunningOnHfSpaces") private boolean isRunningOnHfSpaces; diff --git a/backend/src/main/java/ai/giskard/web/dto/config/MLWorkerConnectionInfoDTO.java b/backend/src/main/java/ai/giskard/web/dto/config/MLWorkerConnectionInfoDTO.java index 010ae34b65..b2c4c7d4a2 100644 --- a/backend/src/main/java/ai/giskard/web/dto/config/MLWorkerConnectionInfoDTO.java +++ b/backend/src/main/java/ai/giskard/web/dto/config/MLWorkerConnectionInfoDTO.java @@ -8,11 +8,6 @@ @NoArgsConstructor @AllArgsConstructor public class MLWorkerConnectionInfoDTO { - private int externalMlWorkerEntrypointPort; - private String externalMlWorkerEntrypointHost; - - private String encryptionKey; - private String keyId; private String instanceId; private String serverVersion; private String user; diff --git a/backend/src/main/java/ai/giskard/web/rest/controllers/SettingsController.java b/backend/src/main/java/ai/giskard/web/rest/controllers/SettingsController.java index 1841f20762..bfd5fc2258 100644 --- a/backend/src/main/java/ai/giskard/web/rest/controllers/SettingsController.java +++ b/backend/src/main/java/ai/giskard/web/rest/controllers/SettingsController.java @@ -96,8 +96,6 @@ public AppConfigDTO getApplicationSettings(@AuthenticationPrincipal final UserDe .buildCommitTime(buildCommitTime) .planCode(currentLicense.getPlanCode()) .planName(currentLicense.getPlanName()) - .externalMlWorkerEntrypointPort(applicationProperties.getExternalMlWorkerEntrypointPort()) - .externalMlWorkerEntrypointHost(applicationProperties.getExternalMlWorkerEntrypointHost()) .hfSpaceId(GeneralSettingsService.hfSpaceId) .isRunningOnHfSpaces(GeneralSettingsService.isRunningInHFSpaces) .roles(roles) @@ -111,8 +109,6 @@ public MLWorkerConnectionInfoDTO getMLWorkerConnectionInfo() { String currentUser = SecurityUtils.getCurrentAuthenticatedUserLogin(); return MLWorkerConnectionInfoDTO.builder() - .externalMlWorkerEntrypointHost(applicationProperties.getExternalMlWorkerEntrypointHost()) - .externalMlWorkerEntrypointPort(applicationProperties.getExternalMlWorkerEntrypointPort()) .instanceId(settingsService.getSettings().getInstanceId()) .serverVersion(buildVersion) .user(currentUser) diff --git a/backend/src/main/resources/config/application.yml b/backend/src/main/resources/config/application.yml index 9c2cf42644..9021256bcb 100644 --- a/backend/src/main/resources/config/application.yml +++ b/backend/src/main/resources/config/application.yml @@ -162,10 +162,6 @@ info: display-ribbon-on-profiles: 'dev' giskard: - ml-worker-host: localhost - ml-worker-port: 50051 - external-ml-worker-entrypoint-port: 40051 - external-ml-worker-enabled: true api-token-validity-in-days: 90 invitation-token-validity-in-days: 3 borderLineThreshold: 0.1 diff --git a/backend/src/test/resources/config/application.yml b/backend/src/test/resources/config/application.yml index 74b666a2b0..98d81c2fef 100644 --- a/backend/src/test/resources/config/application.yml +++ b/backend/src/test/resources/config/application.yml @@ -80,8 +80,6 @@ server: giskard: api-token-validity-in-days: 90 invitation-token-validity-in-days: 3 - ml-worker-host: localhost - ml-worker-port: 50051 home: ${user.home}/giskard-home auth: true email-from: giskard@localhost diff --git a/docker-compose.dev.yml b/docker-compose.dev.yml index 1177a37ffc..df335f5fba 100644 --- a/docker-compose.dev.yml +++ b/docker-compose.dev.yml @@ -6,8 +6,6 @@ services: - "5432:5432" ml-worker: - ports: - - "50051:50051" backend: ports: diff --git a/docker-compose.yml b/docker-compose.yml index f0a88303d4..1c068ac562 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -34,8 +34,6 @@ services: - db env_file: - .env - ports: - - "${GISKARD_EXTERNAL_ML_WORKER_PORT-40051}:40051" environment: - _JAVA_OPTIONS=-Xmx4048m -Xms512m - SPRING_PROFILES_ACTIVE=prod @@ -45,8 +43,6 @@ services: - SPRING_DATASOURCE_PASSWORD=y1QYbF2BtFUC - SPRING_DATASOURCE_URL=jdbc:postgresql://db:5432/app - SPRING_LIQUIBASE_URL=jdbc:postgresql://db:5432/app - - GISKARD_ML_WORKER_HOST=${GISKARD_ML_WORKER_HOST-ml-worker} - - GISKARD_ML_WORKER_PORT=50051 - SPRING_MAIL_HOST - SPRING_MAIL_PORT - SPRING_MAIL_USERNAME diff --git a/python-client/docs/cli/ngrok/index.rst b/python-client/docs/cli/ngrok/index.rst index 496e615f89..a6b91ed79e 100644 --- a/python-client/docs/cli/ngrok/index.rst +++ b/python-client/docs/cli/ngrok/index.rst @@ -33,7 +33,5 @@ Now you can run :code:`giskard server expose --token ` which shou # To run your model with the Giskard Server, execute these three lines on Google Colab: - %env GSK_EXTERNAL_ML_WORKER_HOST= - %env GSK_EXTERNAL_ML_WORKER_PORT= %env GSK_API_KEY=... !giskard worker start -d -u diff --git a/python-client/docs/guides/installation_app/index.rst b/python-client/docs/guides/installation_app/index.rst index e76672839a..2087994a80 100644 --- a/python-client/docs/guides/installation_app/index.rst +++ b/python-client/docs/guides/installation_app/index.rst @@ -62,7 +62,7 @@ You can either install and run the server **locally** or on an **external server Installing Giskard in the cloud is preferable if you want to use the **collaborative** features of Giskard: collect feedback on your model from your team, share your Quality Assurance results, save and provide all your custom tests to your team, etc. - Since Giskard uses 2 TCP ports: ``19000`` and ``40051``, **make sure that these two ports are open** on the cloud instances where Giskard is installed. For step-by-step installation steps in the cloud, please go to the `AWS `_, `GCP `_, and `Azure `_ installation pages. + Since Giskard uses a TCP ports: ``19000``, **make sure that the port is open** on the cloud instances where Giskard is installed. For step-by-step installation steps in the cloud, please go to the `AWS `_, `GCP `_, and `Azure `_ installation pages. .. toctree:: :maxdepth: 1 @@ -123,8 +123,6 @@ Giskard executes your model using an worker that runs directly the model in your .. code-block:: sh - %env GSK_EXTERNAL_ML_WORKER_HOST=4.tcp.ngrok.io - %env GSK_EXTERNAL_ML_WORKER_PORT=10853 %env GSK_API_KEY=YOUR_API_KEY !giskard worker start -d -k YOUR_TOKEN -u https://e840-93-23-184-184.ngrok-free.app diff --git a/python-client/docs/guides/installation_app/install_aws/index.md b/python-client/docs/guides/installation_app/install_aws/index.md index e0a6b7c259..7152623985 100644 --- a/python-client/docs/guides/installation_app/install_aws/index.md +++ b/python-client/docs/guides/installation_app/install_aws/index.md @@ -10,7 +10,7 @@ * **Application and OS image**: Select the default Ubuntu server 22.04 LTS 64-bit (x86) * **Instance type**: We recommend you to choose at least a `t2.large` instance type (2vCPU, 8GB memory) * **Key pair**: Choose your usual key pair. If you don't have one, go to the [Amazon document](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/create-key-pairs.html) to create the right one -* **Network settings**: You need to **open the ports `19000` and `40051` (TCP connection)** to access the Giskard frontend (port `19000`) and upload your model (port `40051`). To do so, click on `Edit` and add the following security groups: +* **Network settings**: You need to **open the port `19000` to access the Giskard frontend and upload your model. To do so, click on `Edit` and add the following security groups: ![](<../../../assets/image_(1)_(1)_(2).png>) diff --git a/python-client/docs/guides/installation_app/install_gcp/index.md b/python-client/docs/guides/installation_app/install_gcp/index.md index 527c51af43..3e4e3a9844 100644 --- a/python-client/docs/guides/installation_app/install_gcp/index.md +++ b/python-client/docs/guides/installation_app/install_gcp/index.md @@ -10,11 +10,10 @@ Installing Giskard in GCP enables you to inspect & test models that you created 2. Choose `Allow full access to all Cloud APIs` 3. In the firewall section, allow **HTTP** and **HTTPS** traffic 3. Connect to your VM in SSH by opening a browser window -4. Create a firewall rule to open ports `19000` and `40051` port of the Giskard instance. Here is the command line that you can execute in the terminal opened by your SSH connection: +4. Create a firewall rule to open the `19000` port of the Giskard instance. Here is the command line that you can execute in the terminal opened by your SSH connection: ```bash gcloud compute firewall-rules create giskard-main --allow tcp:19000 -gcloud compute firewall-rules create giskard-worker --allow tcp:40051 ``` :::{warning} @@ -32,7 +31,6 @@ Creating the firewall rules can also be done **through UI** in the `VPC Network` * In `source IPv4 ranges,` select `0.0.0.0/0` * In `Protocols and ports`, select `Specified protocols and ports` * Then select `TCP`, and type `19000` -* `Repeat the same steps to open port 40051` ::: ### 2. Install Giskard in the GCP VM diff --git a/python-client/giskard/commands/cli_server.py b/python-client/giskard/commands/cli_server.py index 59ffb2c918..72b45a5b62 100644 --- a/python-client/giskard/commands/cli_server.py +++ b/python-client/giskard/commands/cli_server.py @@ -3,7 +3,6 @@ import time from pathlib import Path from typing import Optional -from urllib.parse import urlparse import click import docker @@ -41,9 +40,7 @@ def create_docker_client() -> DockerClient: exit(1) -@click.group( - "server", help="Giskard UI management", context_settings={"show_default": True} -) +@click.group("server", help="Giskard UI management", context_settings={"show_default": True}) def server() -> None: """ Giskard UI management @@ -88,9 +85,7 @@ def get_container(version=None, quit_if_not_exists=True) -> Optional[Container]: return create_docker_client().containers.get(name) except NotFound: if quit_if_not_exists: - logger.error( - f"Container {name} could not be found. Run `giskard server start` to create the container" - ) + logger.error(f"Container {name} could not be found. Run `giskard server start` to create the container") raise click.Abort() else: return None @@ -128,7 +123,6 @@ def _start(attached=False, version=None): settings = _get_settings() or {} port = settings.get("port", 19000) - ml_worker_port = settings.get("ml_worker_port", 40051) version = get_version(version) @@ -143,7 +137,7 @@ def _start(attached=False, version=None): get_image_name(version), detach=not attached, name=get_container_name(version), - ports={7860: port, 40051: ml_worker_port}, + ports={7860: port}, volumes={home_volume.name: {"bind": "/home/giskard/datadir", "mode": "rw"}}, ) container.start() @@ -151,9 +145,7 @@ def _start(attached=False, version=None): up = _wait_backend_ready(port) if up: - logger.info( - f"Giskard Server {version} started. You can access it at http://localhost:{port}" - ) + logger.info(f"Giskard Server {version} started. You can access it at http://localhost:{port}") else: logger.warning( "Giskard backend takes unusually long time to start, " @@ -190,17 +182,13 @@ def _fetch_latest_tag() -> str: """ Returns: the latest tag from the Docker Hub API. Format: vX.Y.Z """ - response = requests.get( - "https://hub.docker.com/v2/namespaces/giskardai/repositories/giskard/tags?page_size=10" - ) + response = requests.get("https://hub.docker.com/v2/namespaces/giskardai/repositories/giskard/tags?page_size=10") response.raise_for_status() json_response = response.json() latest_tag = "latest" latest = next(i for i in json_response["results"] if i["name"] == latest_tag) latest_version_image = next( - i - for i in json_response["results"] - if ((i["name"] != latest_tag) and (i["digest"] == latest["digest"])) + i for i in json_response["results"] if ((i["name"] != latest_tag) and (i["digest"] == latest["digest"])) ) tag = latest_version_image["name"] @@ -236,9 +224,7 @@ def _expose(token): container = get_container() if container: if container.status != "running": - print( - "Error: Giskard server is not running. Please start it using `giskard server start`" - ) + print("Error: Giskard server is not running. Please start it using `giskard server start`") raise click.Abort() else: raise click.Abort() @@ -249,20 +235,10 @@ def _expose(token): if token: ngrok.set_auth_token(token) - http_tunnel = ngrok.connect( - 19000, "http", pyngrok_config=None if token else PyngrokConfig(region="us") - ) - tcp_tunnel = ngrok.connect( - 40051, "tcp", pyngrok_config=None if token else PyngrokConfig(region="eu") - ) - - # Only split the last ':' in case the URL contains a port - tcp_addr = urlparse(tcp_tunnel.public_url) + http_tunnel = ngrok.connect(19000, "http", pyngrok_config=None if token else PyngrokConfig(region="us")) print("Giskard Server is now exposed to the internet.") - print( - "You can now upload objects to the Giskard Server using the following client: \n" - ) + print("You can now upload objects to the Giskard Server using the following client: \n") print( f"""token=... @@ -270,8 +246,6 @@ def _expose(token): # To run your model with the Giskard Server, execute these three lines on Google Colab: -%env GSK_EXTERNAL_ML_WORKER_HOST={tcp_addr.hostname} -%env GSK_EXTERNAL_ML_WORKER_PORT={tcp_addr.port} %env GSK_API_KEY=... !giskard worker start -d -u {http_tunnel.public_url}""" ) @@ -294,9 +268,7 @@ def _expose(token): default=False, help="Starts the server and attaches to it, displaying logs in console.", ) -@click.option( - "--version", "version", required=False, help="Version of Giskard server to start" -) +@click.option("--version", "version", required=False, help="Version of Giskard server to start") @common_options def start(attached, version): """\b @@ -373,12 +345,8 @@ def restart(service, hard): logger.info(f"Container {container.name} restarted") else: if service: - logger.info( - f"Restarting service {service} in {container.name} container" - ) - command = ( - f"supervisorctl -c /opt/giskard/supervisord.conf restart {service}" - ) + logger.info(f"Restarting service {service} in {container.name} container") + command = f"supervisorctl -c /opt/giskard/supervisord.conf restart {service}" else: logger.info(f"Restarting all services in {container.name} container") command = "supervisorctl -c /opt/giskard/supervisord.conf restart all" @@ -455,15 +423,11 @@ def diagnose(local_dir): analytics.track("giskard-server:diagnose") out_dir = Path(local_dir) assert out_dir.is_dir(), "'output' should be an existing directory" - bits, _ = get_container().get_archive( - "/home/giskard/datadir/run", encode_stream=True - ) + bits, _ = get_container().get_archive("/home/giskard/datadir/run", encode_stream=True) from datetime import datetime now = datetime.now().strftime("%Y%m%d_%H%M%S_%f") - out_file = ( - out_dir / f"giskard-diagnose-{get_version().replace('.', '_')}-{now}.tar.gz" - ) + out_file = out_dir / f"giskard-diagnose-{get_version().replace('.', '_')}-{now}.tar.gz" with open(out_file, "wb") as f: for chunk in bits: f.write(chunk) @@ -514,9 +478,7 @@ def status(): analytics.track("giskard-server:status") app_settings = _get_settings() if not app_settings: - logger.info( - "Giskard Server is not installed. Install using `giskard server start`" - ) + logger.info("Giskard Server is not installed. Install using `giskard server start`") return else: version = app_settings["version"] @@ -532,21 +494,13 @@ def status(): if container: if container.status == "running": logger.info(f"Container {container.name} status:") - print( - get_container() - .exec_run("supervisorctl -c /opt/giskard/supervisord.conf") - .output.decode() - ) + print(get_container().exec_run("supervisorctl -c /opt/giskard/supervisord.conf").output.decode()) else: - logger.info( - f"Container {container.name} isn't running ({container.status})" - ) + logger.info(f"Container {container.name} isn't running ({container.status})") @server.command("clean") -@click.option( - "--data", "delete_data", is_flag=True, help="Delete user data (giskard-home volume)" -) +@click.option("--data", "delete_data", is_flag=True, help="Delete user data (giskard-home volume)") @common_options def clean(delete_data): """\b diff --git a/python-client/giskard/settings.py b/python-client/giskard/settings.py index afaa34e17f..3da390e572 100644 --- a/python-client/giskard/settings.py +++ b/python-client/giskard/settings.py @@ -18,13 +18,10 @@ def expand_env_var(env_var: Optional[str]) -> Optional[str]: class Settings(BaseSettings): home: str = "~/giskard-home" - port: int = 50051 ws_port: int = 9000 ws_path: str = "/ml-worker" host: str = "localhost" max_workers: int = 10 - max_send_message_length_mb: int = 1024 - max_receive_message_length_mb: int = 1024 loglevel = "INFO" cache_dir: str = "cache" disable_analytics = False diff --git a/python-client/tests/utils.py b/python-client/tests/utils.py index afaf360d08..de436539c9 100644 --- a/python-client/tests/utils.py +++ b/python-client/tests/utils.py @@ -63,12 +63,7 @@ def __enter__(self): self.mocked_requests.register_uri( requests_mock.GET, self.ml_worker_connect_url_pattern, - json={ - "externalMlWorkerEntrypointPort": 40051, - "externalMlWorkerEntrypointHost": None, - "encryptionKey": "7J2oBM4si/GciQScXjjs6w==", - "keyId": "fh1sjr7h", - }, + json={}, ) url = "http://giskard-host:12345" @@ -95,12 +90,7 @@ def verify_model_upload(my_model, my_data): m.register_uri( requests_mock.GET, ml_worker_connect_url_pattern, - json={ - "externalMlWorkerEntrypointPort": 40051, - "externalMlWorkerEntrypointHost": None, - "encryptionKey": "7J2oBM4si/GciQScXjjs6w==", - "keyId": "fh1sjr7h", - }, + json={}, ) url = "http://giskard-host:12345" diff --git a/scripts/ngrok.yml b/scripts/ngrok.yml index ed6bab7569..a170b45d1f 100644 --- a/scripts/ngrok.yml +++ b/scripts/ngrok.yml @@ -10,7 +10,4 @@ authtoken: YOUR_AUTHTOKEN_HERE tunnels: backend: proto: http - addr: 19000 - mlworker: - proto: tcp - addr: 40051 \ No newline at end of file + addr: 19000 \ No newline at end of file