diff --git a/bentoml/_internal/utils/analytics/schemas.py b/bentoml/_internal/utils/analytics/schemas.py index d923a9a20b..a34e814975 100644 --- a/bentoml/_internal/utils/analytics/schemas.py +++ b/bentoml/_internal/utils/analytics/schemas.py @@ -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) diff --git a/bentoml/_internal/utils/analytics/usage_stats.py b/bentoml/_internal/utils/analytics/usage_stats.py index 8fef693f68..d9e28fab8a 100644 --- a/bentoml/_internal/utils/analytics/usage_stats.py +++ b/bentoml/_internal/utils/analytics/usage_stats.py @@ -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]: @@ -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), diff --git a/bentoml/start.py b/bentoml/start.py index 30a12ad28e..fc327c48d1 100644 --- a/bentoml/start.py +++ b/bentoml/start.py @@ -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__) @@ -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( @@ -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", @@ -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) @inject @@ -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, @@ -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)