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

chore: http client healthcheck #3636

Merged
merged 8 commits into from
Mar 8, 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
9 changes: 9 additions & 0 deletions src/bentoml/_internal/client/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import time
import socket
import typing as t
import asyncio
import logging
import urllib.error
import urllib.request
Expand Down Expand Up @@ -77,6 +78,14 @@ def wait_until_server_ready(
logger.error(err)
raise

async def async_health(self) -> t.Any:
async with aiohttp.ClientSession(self.server_url) as sess:
async with sess.get("/readyz") as resp:
return resp

def health(self) -> t.Any:
return asyncio.run(self.async_health())

@classmethod
def from_url(cls, server_url: str, **kwargs: t.Any) -> HTTPClient:
server_url = server_url if "://" in server_url else "http://" + server_url
Expand Down
24 changes: 24 additions & 0 deletions tests/e2e/bento_server_http/tests/test_client.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import pytest

import bentoml
from bentoml.client import HTTPClient


@pytest.fixture(scope="session")
def http_client(host: str) -> HTTPClient:
service = bentoml.load(bento_identifier="service:svc")

return HTTPClient(service, f"http://{host}")


@pytest.mark.asyncio
async def test_async_health(http_client: HTTPClient) -> None:
resp = await http_client.async_health()
denyszhak marked this conversation as resolved.
Show resolved Hide resolved

assert resp.status == 200


def test_health(http_client: HTTPClient) -> None:
resp = http_client.health()

assert resp.status == 200