Skip to content

Commit

Permalink
add probes
Browse files Browse the repository at this point in the history
  • Loading branch information
nilsmechtel committed Dec 10, 2024
1 parent bb22306 commit 06393fc
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 4 deletions.
38 changes: 37 additions & 1 deletion bioimageio_colab/register_sam_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,22 @@ def clear_cache(embedding_cache: TTLCache, context: dict = None) -> bool:
def hello(context: dict = None) -> str:
return "Welcome to the Interactive Segmentation service!"

def ping(context: dict = None) -> str:
return "pong"

def check_readiness():
# Check if the service is ready
return {"status": "ok"}

async def check_liveness(colab_client, sid):
# Check if the service is alive
service = await colab_client.get_service(sid)
alive = await service.ping() == "pong"
if alive:
return {"status": "ok"}
else:
return {"success": "false", "detail": "Service is not alive"}


async def register_service(args: dict) -> None:
"""
Expand Down Expand Up @@ -243,6 +259,7 @@ async def register_service(args: dict) -> None:
},
# Exposed functions:
"hello": hello,
"ping": ping,
# **Run segmentation**
# Params:
# - model name
Expand All @@ -269,7 +286,26 @@ async def register_service(args: dict) -> None:
sid = service_info["id"]
logger.info(f"Registered service with ID: {sid}")
logger.info(
f"Test the service here: {args.server_url}/{args.workspace_name}/services/{args.service_id}/hello"
f"Test the service here: {args.server_url}/{args.workspace_name}/services/{sid.split('/')[1]}/hello"
)

# Register a probe for the service
probe_info = await colab_client.register_service({
"name": "Probes service",
"id": "probes",
"config": {
"visibility": "public"
},
"readiness": check_readiness,
"liveness": partial(check_liveness, colab_client, sid)
})
pid = probe_info["id"]
logger.info(f"Registered probe with ID: {pid}")
logger.info(
f"Test the readiness probe here: {args.server_url}/{args.workspace_name}/services/{pid.split('/')[1]}/readiness"
)
logger.info(
f"Test the liveness probe here: {args.server_url}/{args.workspace_name}/services/{pid.split('/')[1]}/liveness"
)


Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ requires = ["setuptools", "wheel"]

[project]
name = "bioimageio-colab"
version = "0.1.4"
version = "0.1.5"
readme = "README.md"
description = "Collaborative image annotation and model training with human in the loop."
dependencies = [
Expand Down
4 changes: 2 additions & 2 deletions test/test_model_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@


def test_service_available():
service_url = f"{SERVER_URL}/{WORKSPACE_NAME}/services/{SERVICE_ID}/hello"
service_url = f"{SERVER_URL}/{WORKSPACE_NAME}/services/{SERVICE_ID}/ping"
response = requests.get(service_url)
assert response.status_code == 200
assert response.json() == "Welcome to the Interactive Segmentation service!"
assert response.json() == "pong"

def test_get_service():
client = connect_to_server({"server_url": SERVER_URL, "method_timeout": 5})
Expand Down

0 comments on commit 06393fc

Please sign in to comment.