From a7e71d030ac176e610cb78815745e5acf650d5a1 Mon Sep 17 00:00:00 2001 From: Jiew Peng Date: Thu, 1 Sep 2022 02:18:07 +0000 Subject: [PATCH 01/11] implement logging configuration --- bentoml/_internal/configuration/containers.py | 15 +++++++++++++++ .../configuration/default_configuration.yaml | 7 +++++++ bentoml/_internal/log.py | 17 +++++++++++------ 3 files changed, 33 insertions(+), 6 deletions(-) diff --git a/bentoml/_internal/configuration/containers.py b/bentoml/_internal/configuration/containers.py index 4d7b35bf90a..c48f04cf997 100644 --- a/bentoml/_internal/configuration/containers.py +++ b/bentoml/_internal/configuration/containers.py @@ -178,6 +178,14 @@ def _is_ip_address(addr: str) -> bool: }, }, }, + "logging": { + "formatting": { + "format": str, + "datefmt": str, + "trace_id_format": str, + "span_id_format": str, + } + }, } ) @@ -535,5 +543,12 @@ def duration_buckets( ) return DEFAULT_BUCKET + @providers.SingletonFactory + @staticmethod + def logging_formats( + cfg: dict[str, t.Any] = Provide[config.logging.formatting], + ) -> dict[str, str]: + return cfg + BentoMLContainer = _BentoMLContainerClass() diff --git a/bentoml/_internal/configuration/default_configuration.yaml b/bentoml/_internal/configuration/default_configuration.yaml index 95224193d7f..5ba2bc9fb3a 100644 --- a/bentoml/_internal/configuration/default_configuration.yaml +++ b/bentoml/_internal/configuration/default_configuration.yaml @@ -51,3 +51,10 @@ tracing: otlp: protocol: Null url: Null + +logging: + formatting: + format: "%(asctime)s %(levelname_bracketed)s %(component)s %(message)s%(trace_msg)s" + datefmt: "%Y-%m-%dT%H:%M:%S%z" + trace_id_format: 032x + span_id_format: 016x diff --git a/bentoml/_internal/log.py b/bentoml/_internal/log.py index 6829dd7e473..f3451ca7965 100644 --- a/bentoml/_internal/log.py +++ b/bentoml/_internal/log.py @@ -9,6 +9,7 @@ from .context import component_context from .configuration import get_debug_mode from .configuration import get_quiet_mode +from .configuration.containers import BentoMLContainer default_factory = logging.getLogRecordFactory() @@ -45,10 +46,11 @@ def filter(self, record: logging.LogRecord) -> bool: "root": {"level": logging.WARNING}, } -TRACED_LOG_FORMAT = ( - "%(asctime)s %(levelname_bracketed)s %(component)s %(message)s%(trace_msg)s" -) -DATE_FORMAT = "%Y-%m-%dT%H:%M:%S%z" +LOGGING_FORMATS = BentoMLContainer.logging_formats.get() +TRACED_LOG_FORMAT = LOGGING_FORMATS["format"] +DATE_FORMAT = LOGGING_FORMATS["datefmt"] +TRACE_ID_FORMAT = LOGGING_FORMATS["trace_id_format"] +SPAN_ID_FORMAT = LOGGING_FORMATS["span_id_format"] SERVER_LOGGING_CONFIG: dict[str, t.Any] = { "version": 1, @@ -111,10 +113,13 @@ def trace_record_factory(*args: t.Any, **kwargs: t.Any): record = default_factory(*args, **kwargs) record.levelname_bracketed = f"[{record.levelname}]" # type: ignore (adding fields to record) record.component = f"[{_component_name()}]" # type: ignore (adding fields to record) - if trace_context.trace_id == 0: + trace_id = trace_context.trace_id + if trace_id in (0, None): record.trace_msg = "" # type: ignore (adding fields to record) else: - record.trace_msg = f" (trace={trace_context.trace_id},span={trace_context.span_id},sampled={trace_context.sampled})" # type: ignore (adding fields to record) + trace_id = format(trace_id, TRACE_ID_FORMAT) + span_id = format(trace_context.span_id, SPAN_ID_FORMAT) + record.trace_msg = f" (trace={trace_id},span={span_id},sampled={trace_context.sampled})" # type: ignore (adding fields to record) record.request_id = trace_context.request_id # type: ignore (adding fields to record) return record From a98f9e558a302a01011ed850016ab0ead5f221e8 Mon Sep 17 00:00:00 2001 From: Jiew Peng Date: Thu, 1 Sep 2022 02:18:22 +0000 Subject: [PATCH 02/11] add docs --- docs/source/guides/logging.rst | 47 +++++++++++++++++++++++----------- 1 file changed, 32 insertions(+), 15 deletions(-) diff --git a/docs/source/guides/logging.rst b/docs/source/guides/logging.rst index de89a36e9d8..01149cba78d 100644 --- a/docs/source/guides/logging.rst +++ b/docs/source/guides/logging.rst @@ -59,22 +59,22 @@ logs are logged under the ``"bentoml"`` namespace. Web Service Request Logging """"""""""""""""""""""""""" -For web requests, logging can be enabled and disabled using the `logging.access` parameter at the -top level of the ``bentoml_configuration.yml``. +For web requests, logging can be enabled and disabled using the `logging.access` parameter in both the `api_server` and `runner` +sections of the ``bentoml_configuration.yml``. .. code-block:: yaml logging: access: - enabled: False - # whether to log the size of the request body - request_content_length: True - # whether to log the content type of the request - request_content_type: True - # whether to log the content length of the response - response_content_length: True - # whether to log the content type of the response - response_content_type: True + enabled: False + # whether to log the size of the request body + request_content_length: True + # whether to log the content type of the request + request_content_type: True + # whether to log the content length of the response + response_content_length: True + # whether to log the content type of the response + response_content_type: True Model Runner Request Logging @@ -88,15 +88,32 @@ your ``bentoml_configuration.yml``: .. code-block:: yaml runners: - logging: - access: - enabled: True - ... + logging: + access: + enabled: True + ... The available configuration options are identical to the webserver request logging options above. These logs are disabled by default in order to prevent double logging of requests. +Logging Formatting +"""""""""""""""""" + +You may configure the logging formatting options at the top level of your ``bentoml_configuration.yml``. +The default configuration is shown below, where the opentelemetry trace_id and span_id are logged in +hexadecimal format, consistent with opentelemetry logging instrumentation. + +.. code-block:: yaml + + logging: + formatting: + format: "%(asctime)s %(levelname_bracketed)s %(component)s %(message)s%(trace_msg)s" + datefmt: "%Y-%m-%dT%H:%M:%S%z" + trace_id_format: 032x + span_id_format: 016x + + Library Logging --------------- From d7028e2613bfdf58537a926bb94bff1eb76285e1 Mon Sep 17 00:00:00 2001 From: Jinsung Lee Date: Thu, 1 Sep 2022 02:09:18 +0900 Subject: [PATCH 03/11] docs: fix wrong name for example neural net (#2959) --- docs/source/frameworks/pytorch.rst | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/docs/source/frameworks/pytorch.rst b/docs/source/frameworks/pytorch.rst index bfaf2cce86f..d7ec91c642a 100644 --- a/docs/source/frameworks/pytorch.rst +++ b/docs/source/frameworks/pytorch.rst @@ -21,7 +21,8 @@ For common PyTorch models with single input: .. code-block:: python :caption: `train.py` - + + import bentoml import torch import torch.nn as nn import torch.nn.functional as F @@ -74,7 +75,7 @@ For common PyTorch models with single input: import torch.optim as optim criterion = nn.CrossEntropyLoss() - optimizer = optim.SGD(net.parameters(), lr=0.001, momentum=0.9) + optimizer = optim.SGD(model.parameters(), lr=0.001, momentum=0.9) for epoch in range(2): # a small epoch just for demostration purpose for i, data in enumerate(trainloader, 0): @@ -85,7 +86,7 @@ For common PyTorch models with single input: optimizer.zero_grad() # forward + backward + optimize - outputs = net(inputs) + outputs = model(inputs) loss = criterion(outputs, labels) loss.backward() optimizer.step() From 2eec1fd109d8d84de6990493c6f339981b630554 Mon Sep 17 00:00:00 2001 From: Aaron Pham <29749331+aarnphm@users.noreply.github.com> Date: Wed, 31 Aug 2022 15:37:37 -0700 Subject: [PATCH 04/11] docs: fix bentoml containerize command help message (#2957) Co-authored-by: Sauyon Lee <2347889+sauyon@users.noreply.github.com> --- bentoml/bentos.py | 13 +++++++++---- bentoml_cli/containerize.py | 20 ++++++++++---------- 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/bentoml/bentos.py b/bentoml/bentos.py index 2835f1b27fd..da441bcde65 100644 --- a/bentoml/bentos.py +++ b/bentoml/bentos.py @@ -380,7 +380,7 @@ def build_bentofile( @inject def containerize( tag: Tag | str, - docker_image_tag: str | t.List[str] | None = None, + docker_image_tag: t.List[str] | None = None, *, add_host: dict[str, str] | None = None, allow: t.List[str] | None = None, @@ -418,7 +418,7 @@ def containerize( bento = _bento_store.get(tag) if not docker_image_tag: - docker_image_tag = str(bento.tag) + docker_image_tag = [str(bento.tag)] dockerfile_path = os.path.join("env", "docker", "Dockerfile") @@ -465,9 +465,14 @@ def containerize( ) return False else: - logger.info(f'Successfully built docker image "{docker_image_tag}"') logger.info( - f'To run your newly built Bento container, use: "docker run -it --rm -p 3000:3000 {docker_image_tag}"' + 'Successfully built docker image for "%s" with tags "%s"', + str(bento.tag), + ",".join(docker_image_tag), + ) + logger.info( + 'To run your newly built Bento container, use one of the above tags, and pass it to "docker run". i.e: "docker run -it --rm -p 3000:3000 %s"', + docker_image_tag[0], ) return True diff --git a/bentoml_cli/containerize.py b/bentoml_cli/containerize.py index 1a7df808985..e6964ca23ec 100644 --- a/bentoml_cli/containerize.py +++ b/bentoml_cli/containerize.py @@ -196,29 +196,29 @@ def containerize( # type: ignore BENTO is the target BentoService to be containerized, referenced by its name and version in format of name:version. For example: "iris_classifier:v1.2.0" - `bentoml containerize` command also supports the use of the `latest` tag + 'bentoml containerize' command also supports the use of the 'latest' tag which will automatically use the last built version of your Bento. You can provide a tag for the image built by Bento using the - `--tag` flag. Additionally, you can provide a `--push` flag, + '--docker-image-tag' flag. Additionally, you can provide a '--push' flag, which will push the built image to the Docker repository specified by the image tag. You can also prefixing the tag with a hostname for the repository you wish to push to. - e.g. `bentoml containerize IrisClassifier:latest --push --tag - repo-address.com:username/iris` would build a Docker image called - `username/iris:latest` and push that to docker repository at repo-address.com. + e.g. 'bentoml containerize IrisClassifier:latest --push --tag + repo-address.com:username/iris' would build a Docker image called + 'username/iris:latest' and push that to docker repository at repo-address.com. - By default, the `containerize` command will use the current credentials + By default, the 'containerize' command will use the current credentials provided by Docker daemon. - `bentoml containerize` also uses Docker Buildx as backend, in place for normal `docker build`. + 'bentoml containerize' also uses Docker Buildx as backend, in place for normal 'docker build'. By doing so, BentoML will leverage Docker Buildx features such as multi-node builds for cross-platform images, Full BuildKit capabilities with all of the - familiar UI from `docker build`. + familiar UI from 'docker build'. - We also pass all given args for `docker buildx` through `bentoml containerize` with ease. + We also pass all given args for 'docker buildx' through 'bentoml containerize' with ease. """ from bentoml._internal.utils import buildx @@ -268,7 +268,7 @@ def containerize( # type: ignore if platform and len(platform) > 1: if not push: logger.warning( - "Multiple `--platform` arguments were found. Make sure to also use `--push` to push images to a repository or generated images will not be saved. For more information, see https://docs.docker.com/engine/reference/commandline/buildx_build/#load." + "Multiple '--platform' arguments were found. Make sure to also use '--push' to push images to a repository or generated images will not be saved. For more information, see https://docs.docker.com/engine/reference/commandline/buildx_build/#load." ) if push: load = False From 16c8e2062968dbbaa1951ddeafeef707943c00aa Mon Sep 17 00:00:00 2001 From: Benjamin Tan Wei Hao Date: Sat, 3 Sep 2022 08:07:41 +0800 Subject: [PATCH 05/11] chore(cli): remove unused `--no-trunc` (#2965) --- bentoml_cli/bentos.py | 7 +------ bentoml_cli/models.py | 7 +------ 2 files changed, 2 insertions(+), 12 deletions(-) diff --git a/bentoml_cli/bentos.py b/bentoml_cli/bentos.py index f00b32bfb7b..551652b33a6 100644 --- a/bentoml_cli/bentos.py +++ b/bentoml_cli/bentos.py @@ -92,12 +92,7 @@ def get(bento_tag: str, output: str) -> None: # type: ignore (not accessed) type=click.Choice(["json", "yaml", "table"]), default="table", ) - @click.option( - "--no-trunc", - is_flag=False, - help="Don't truncate the output", - ) - def list_bentos(bento_name: str, output: str, no_trunc: bool) -> None: # type: ignore (not accessed) + def list_bentos(bento_name: str, output: str) -> None: # type: ignore (not accessed) """List Bentos in local store \b diff --git a/bentoml_cli/models.py b/bentoml_cli/models.py index c8e2b8aa97c..adde121ee49 100644 --- a/bentoml_cli/models.py +++ b/bentoml_cli/models.py @@ -92,12 +92,7 @@ def get(model_tag: str, output: str) -> None: # type: ignore (not accessed) type=click.Choice(["json", "yaml", "table"]), default="table", ) - @click.option( - "--no-trunc", - is_flag=False, - help="Don't truncate the output", - ) - def list_models(model_name: str, output: str, no_trunc: bool) -> None: # type: ignore (not accessed) + def list_models(model_name: str, output: str) -> None: # type: ignore (not accessed) """List Models in local store \b From 24d1f7fb174b18dfdab0f8c77ad4f70eeb354455 Mon Sep 17 00:00:00 2001 From: Jiew Peng Date: Sat, 3 Sep 2022 08:20:20 +0000 Subject: [PATCH 06/11] remove options to configure logging format and datefmt --- bentoml/_internal/configuration/containers.py | 2 -- bentoml/_internal/configuration/default_configuration.yaml | 2 -- bentoml/_internal/log.py | 7 +++++-- docs/source/guides/logging.rst | 2 -- 4 files changed, 5 insertions(+), 8 deletions(-) diff --git a/bentoml/_internal/configuration/containers.py b/bentoml/_internal/configuration/containers.py index c48f04cf997..be0be9c770f 100644 --- a/bentoml/_internal/configuration/containers.py +++ b/bentoml/_internal/configuration/containers.py @@ -180,8 +180,6 @@ def _is_ip_address(addr: str) -> bool: }, "logging": { "formatting": { - "format": str, - "datefmt": str, "trace_id_format": str, "span_id_format": str, } diff --git a/bentoml/_internal/configuration/default_configuration.yaml b/bentoml/_internal/configuration/default_configuration.yaml index 5ba2bc9fb3a..8daa523629c 100644 --- a/bentoml/_internal/configuration/default_configuration.yaml +++ b/bentoml/_internal/configuration/default_configuration.yaml @@ -54,7 +54,5 @@ tracing: logging: formatting: - format: "%(asctime)s %(levelname_bracketed)s %(component)s %(message)s%(trace_msg)s" - datefmt: "%Y-%m-%dT%H:%M:%S%z" trace_id_format: 032x span_id_format: 016x diff --git a/bentoml/_internal/log.py b/bentoml/_internal/log.py index f3451ca7965..02691631750 100644 --- a/bentoml/_internal/log.py +++ b/bentoml/_internal/log.py @@ -46,9 +46,12 @@ def filter(self, record: logging.LogRecord) -> bool: "root": {"level": logging.WARNING}, } +TRACED_LOG_FORMAT = ( + "%(asctime)s %(levelname_bracketed)s %(component)s %(message)s%(trace_msg)s" +) +DATE_FORMAT = "%Y-%m-%dT%H:%M:%S%z" + LOGGING_FORMATS = BentoMLContainer.logging_formats.get() -TRACED_LOG_FORMAT = LOGGING_FORMATS["format"] -DATE_FORMAT = LOGGING_FORMATS["datefmt"] TRACE_ID_FORMAT = LOGGING_FORMATS["trace_id_format"] SPAN_ID_FORMAT = LOGGING_FORMATS["span_id_format"] diff --git a/docs/source/guides/logging.rst b/docs/source/guides/logging.rst index 01149cba78d..50cec2c6128 100644 --- a/docs/source/guides/logging.rst +++ b/docs/source/guides/logging.rst @@ -108,8 +108,6 @@ hexadecimal format, consistent with opentelemetry logging instrumentation. logging: formatting: - format: "%(asctime)s %(levelname_bracketed)s %(component)s %(message)s%(trace_msg)s" - datefmt: "%Y-%m-%dT%H:%M:%S%z" trace_id_format: 032x span_id_format: 016x From 66f9c743d12dd18010e2beb7c5d6f3a91bf07969 Mon Sep 17 00:00:00 2001 From: Jiew Peng Date: Tue, 6 Sep 2022 13:41:16 +0000 Subject: [PATCH 07/11] use eager imports --- bentoml/_internal/log.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/bentoml/_internal/log.py b/bentoml/_internal/log.py index 02691631750..429c0b6260e 100644 --- a/bentoml/_internal/log.py +++ b/bentoml/_internal/log.py @@ -9,7 +9,6 @@ from .context import component_context from .configuration import get_debug_mode from .configuration import get_quiet_mode -from .configuration.containers import BentoMLContainer default_factory = logging.getLogRecordFactory() @@ -51,9 +50,6 @@ def filter(self, record: logging.LogRecord) -> bool: ) DATE_FORMAT = "%Y-%m-%dT%H:%M:%S%z" -LOGGING_FORMATS = BentoMLContainer.logging_formats.get() -TRACE_ID_FORMAT = LOGGING_FORMATS["trace_id_format"] -SPAN_ID_FORMAT = LOGGING_FORMATS["span_id_format"] SERVER_LOGGING_CONFIG: dict[str, t.Any] = { "version": 1, @@ -120,8 +116,14 @@ def trace_record_factory(*args: t.Any, **kwargs: t.Any): if trace_id in (0, None): record.trace_msg = "" # type: ignore (adding fields to record) else: - trace_id = format(trace_id, TRACE_ID_FORMAT) - span_id = format(trace_context.span_id, SPAN_ID_FORMAT) + from .configuration.containers import BentoMLContainer + + logging_formats = BentoMLContainer.logging_formats.get() + trace_id_format = logging_formats["trace_id_format"] + span_id_format = logging_formats["span_id_format"] + + trace_id = format(trace_id, trace_id_format) + span_id = format(trace_context.span_id, span_id_format) record.trace_msg = f" (trace={trace_id},span={span_id},sampled={trace_context.sampled})" # type: ignore (adding fields to record) record.request_id = trace_context.request_id # type: ignore (adding fields to record) From 6e7d2a31a56d2c1f10e888a68ab0739e107c9169 Mon Sep 17 00:00:00 2001 From: Jiew Peng Date: Wed, 7 Sep 2022 12:58:36 +0000 Subject: [PATCH 08/11] standardise naming --- bentoml/_internal/configuration/containers.py | 2 +- bentoml/_internal/log.py | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/bentoml/_internal/configuration/containers.py b/bentoml/_internal/configuration/containers.py index be0be9c770f..47bf2631d53 100644 --- a/bentoml/_internal/configuration/containers.py +++ b/bentoml/_internal/configuration/containers.py @@ -543,7 +543,7 @@ def duration_buckets( @providers.SingletonFactory @staticmethod - def logging_formats( + def logging_formatting( cfg: dict[str, t.Any] = Provide[config.logging.formatting], ) -> dict[str, str]: return cfg diff --git a/bentoml/_internal/log.py b/bentoml/_internal/log.py index 429c0b6260e..9feddc31760 100644 --- a/bentoml/_internal/log.py +++ b/bentoml/_internal/log.py @@ -118,9 +118,9 @@ def trace_record_factory(*args: t.Any, **kwargs: t.Any): else: from .configuration.containers import BentoMLContainer - logging_formats = BentoMLContainer.logging_formats.get() - trace_id_format = logging_formats["trace_id_format"] - span_id_format = logging_formats["span_id_format"] + logging_formatting = BentoMLContainer.logging_formatting.get() + trace_id_format = logging_formatting["trace_id_format"] + span_id_format = logging_formatting["span_id_format"] trace_id = format(trace_id, trace_id_format) span_id = format(trace_context.span_id, span_id_format) From f0ec88141fe7959037bf3fdbd269862ed94dfcaa Mon Sep 17 00:00:00 2001 From: Huib Keemink Date: Thu, 8 Sep 2022 09:51:54 +0200 Subject: [PATCH 09/11] docs: update wrong paths for disabling logs (#2974) YAML fields for disabling access logs on docs is not correct before. This PR address this. --- docs/source/guides/logging.rst | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/docs/source/guides/logging.rst b/docs/source/guides/logging.rst index 50cec2c6128..44cd694341e 100644 --- a/docs/source/guides/logging.rst +++ b/docs/source/guides/logging.rst @@ -64,17 +64,18 @@ sections of the ``bentoml_configuration.yml``. .. code-block:: yaml - logging: - access: - enabled: False - # whether to log the size of the request body - request_content_length: True - # whether to log the content type of the request - request_content_type: True - # whether to log the content length of the response - response_content_length: True - # whether to log the content type of the response - response_content_type: True + api_server: + logging: + access: + enabled: False + # whether to log the size of the request body + request_content_length: True + # whether to log the content type of the request + request_content_type: True + # whether to log the content length of the response + response_content_length: True + # whether to log the content type of the response + response_content_type: True Model Runner Request Logging From 098daa29f49bd072020fbaba680faddfff5a2af4 Mon Sep 17 00:00:00 2001 From: Sean Sheng Date: Sun, 11 Sep 2022 20:41:49 -0700 Subject: [PATCH 10/11] feat: track serve update for start subcommands (#2976) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## What does this PR address? Fixes #(issue) ## Before submitting: - [ ] Does the Pull Request follow [Conventional Commits specification](https://www.conventionalcommits.org/en/v1.0.0/#summary) naming? Here are [GitHub's guide](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/creating-a-pull-request) on how to create a pull request. - [ ] Does the code follow BentoML's code style, both `make format` and `make lint` script have passed ([instructions](https://github.com/bentoml/BentoML/blob/main/DEVELOPMENT.md#style-check-auto-formatting-type-checking))? - [ ] Did you read through [contribution guidelines](https://github.com/bentoml/BentoML/blob/main/CONTRIBUTING.md#ways-to-contribute) and follow [development guidelines](https://github.com/bentoml/BentoML/blob/main/DEVELOPMENT.md#start-developing)? - [ ] Did your changes require updates to the documentation? Have you updated those accordingly? Here are [documentation guidelines](https://github.com/bentoml/BentoML/tree/main/docs) and [tips on writting docs](https://github.com/bentoml/BentoML/tree/main/docs#writing-documentation). - [ ] Did you write tests to cover your changes? ## Who can help review? Feel free to tag members/contributors who can help review your PR. --- bentoml/_internal/utils/analytics/schemas.py | 1 + .../_internal/utils/analytics/usage_stats.py | 2 + bentoml/start.py | 54 ++++++++++--------- 3 files changed, 33 insertions(+), 24 deletions(-) diff --git a/bentoml/_internal/utils/analytics/schemas.py b/bentoml/_internal/utils/analytics/schemas.py index d923a9a20b4..a34e814975a 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 8fef693f685..d9e28fab8ad 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 30a12ad28e5..fc327c48d1e 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) From 7e40042d5c78211b69daa6d84b6a5497463a340b Mon Sep 17 00:00:00 2001 From: Jiew Peng Date: Thu, 1 Sep 2022 02:18:22 +0000 Subject: [PATCH 11/11] add docs --- docs/source/guides/logging.rst | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/docs/source/guides/logging.rst b/docs/source/guides/logging.rst index 44cd694341e..2eccd9d8f47 100644 --- a/docs/source/guides/logging.rst +++ b/docs/source/guides/logging.rst @@ -109,6 +109,11 @@ hexadecimal format, consistent with opentelemetry logging instrumentation. logging: formatting: +<<<<<<< HEAD +======= + format: "%(asctime)s %(levelname_bracketed)s %(component)s %(message)s%(trace_msg)s" + datefmt: "%Y-%m-%dT%H:%M:%S%z" +>>>>>>> 57805c3c (add docs) trace_id_format: 032x span_id_format: 016x