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

feat: track serve update for start subcommands #2976

Merged
merged 2 commits into from Sep 12, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions bentoml/_internal/utils/analytics/schemas.py
Expand Up @@ -199,6 +199,7 @@ class ServeInitEvent(EventMeta):
class ServeUpdateEvent(EventMeta):
serve_id: str
production: bool
component: str
triggered_at: datetime
duration_in_seconds: int
metrics: t.List[t.Any] = attr.field(factory=list)
Expand Down
2 changes: 2 additions & 0 deletions bentoml/_internal/utils/analytics/usage_stats.py
Expand Up @@ -196,6 +196,7 @@ def get_metrics_report(
def track_serve(
svc: Service,
production: bool,
component: str = "standalone",
metrics_client: PrometheusClient = Provide[BentoMLContainer.metrics_client],
serve_info: ServeInfo = Provide[BentoMLContainer.serve_info],
) -> t.Generator[None, None, None]:
Expand All @@ -220,6 +221,7 @@ def loop() -> t.NoReturn: # type: ignore
event_properties = ServeUpdateEvent(
serve_id=serve_info.serve_id,
production=production,
component=component,
triggered_at=now,
duration_in_seconds=int((now - last_tracked_timestamp).total_seconds()),
metrics=get_metrics_report(metrics_client),
Expand Down
54 changes: 30 additions & 24 deletions bentoml/start.py
Expand Up @@ -19,6 +19,7 @@
from ._internal.utils import reserve_free_port
from ._internal.resource import CpuResource
from ._internal.utils.circus import create_standalone_arbiter
from ._internal.utils.analytics import track_serve
from ._internal.configuration.containers import BentoMLContainer

logger = logging.getLogger(__name__)
Expand All @@ -27,6 +28,9 @@
SCRIPT_API_SERVER = "bentoml_cli.worker.http_api_server"
SCRIPT_DEV_API_SERVER = "bentoml_cli.worker.http_dev_api_server"

API_SERVER = "api_server"
RUNNER = "runner"


@inject
def ensure_prometheus_dir(
Expand Down Expand Up @@ -114,7 +118,7 @@ def start_runner_server(

watchers.append(
Watcher(
name=f"runner_{runner.name}",
name=f"{RUNNER}_{runner.name}",
cmd=sys.executable,
args=[
"-m",
Expand Down Expand Up @@ -149,18 +153,19 @@ def start_runner_server(
sockets=list(circus_socket_map.values()),
)

try:
arbiter.start(
cb=lambda _: logger.info( # type: ignore
'Starting RunnerServer from "%s"\n running on http://%s:%s (Press CTRL+C to quit)',
bento_identifier,
host,
port,
),
)
finally:
if uds_path is not None:
shutil.rmtree(uds_path)
with track_serve(svc, production=True, component=RUNNER):
try:
arbiter.start(
cb=lambda _: logger.info( # type: ignore
'Starting RunnerServer from "%s"\n running on http://%s:%s (Press CTRL+C to quit)',
bento_identifier,
host,
port,
),
)
finally:
if uds_path is not None:
shutil.rmtree(uds_path)
aarnphm marked this conversation as resolved.
Show resolved Hide resolved


@inject
Expand Down Expand Up @@ -248,7 +253,7 @@ def start_http_server(

watchers.append(
Watcher(
name="api_server",
name=API_SERVER,
cmd=sys.executable,
args=args,
copy_env=True,
Expand All @@ -264,13 +269,14 @@ def start_http_server(
sockets=list(circus_socket_map.values()),
)

try:
arbiter.start(
cb=lambda _: logger.info( # type: ignore
f'Starting bare Bento API server from "{bento_identifier}" '
f"running on http://{host}:{port} (Press CTRL+C to quit)"
),
)
finally:
if uds_path is not None:
shutil.rmtree(uds_path)
with track_serve(svc, production=True, component=API_SERVER):
try:
arbiter.start(
cb=lambda _: logger.info( # type: ignore
f'Starting bare Bento API server from "{bento_identifier}" '
f"running on http://{host}:{port} (Press CTRL+C to quit)"
),
)
finally:
if uds_path is not None:
shutil.rmtree(uds_path)
aarnphm marked this conversation as resolved.
Show resolved Hide resolved