Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[GSK-1698] Remove legacy ML worker info and properties #1390

Merged
merged 12 commits into from
Sep 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
4 changes: 0 additions & 4 deletions backend/src/main/resources/config/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions backend/src/test/resources/config/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 0 additions & 2 deletions docker-compose.dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ services:
- "5432:5432"

ml-worker:
ports:
- "50051:50051"

backend:
ports:
Expand Down
4 changes: 0 additions & 4 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 0 additions & 2 deletions python-client/docs/cli/ngrok/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,5 @@ Now you can run :code:`giskard server expose --token <ngrok_API_key>` which shou

# To run your model with the Giskard Server, execute these three lines on Google Colab:

%env GSK_EXTERNAL_ML_WORKER_HOST=<host>
%env GSK_EXTERNAL_ML_WORKER_PORT=<port>
%env GSK_API_KEY=...
!giskard worker start -d -u <ngrok_external_server_link>
4 changes: 1 addition & 3 deletions python-client/docs/guides/installation_app/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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 <install_aws/index/index.md>`_, `GCP <install_gcp/index.md>`_, and `Azure <install_azure/index.md>`_ 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 <install_aws/index/index.md>`_, `GCP <install_gcp/index.md>`_, and `Azure <install_azure/index.md>`_ installation pages.

.. toctree::
:maxdepth: 1
Expand Down Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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>)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand All @@ -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
Expand Down
82 changes: 18 additions & 64 deletions python-client/giskard/commands/cli_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import time
from pathlib import Path
from typing import Optional
from urllib.parse import urlparse

import click
import docker
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand All @@ -143,17 +137,15 @@ 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()

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, "
Expand Down Expand Up @@ -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"]
Expand Down Expand Up @@ -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()
Expand All @@ -249,29 +235,17 @@ 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=...
client = giskard.GiskardClient(\"{http_tunnel.public_url}\", 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}"""
)
Expand All @@ -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
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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"]
Expand All @@ -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
Expand Down
3 changes: 0 additions & 3 deletions python-client/giskard/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 2 additions & 12 deletions python-client/tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand Down
Loading