diff --git a/python-sdk/indexify/cli.py b/python-sdk/indexify/cli.py index 2e085c88d..8f70e12ca 100644 --- a/python-sdk/indexify/cli.py +++ b/python-sdk/indexify/cli.py @@ -6,9 +6,11 @@ import sys import threading import time +from importlib.metadata import version from typing import Annotated, List, Optional import nanoid +import structlog import typer from rich.console import Console from rich.panel import Panel @@ -32,6 +34,7 @@ } ) +logging = structlog.get_logger(module=__name__) console = Console(theme=custom_theme) app = typer.Typer(pretty_exceptions_enable=False, no_args_is_help=True) @@ -158,6 +161,9 @@ def build_default_image(): @app.command(help="Joins the extractors to the coordinator server") def executor( server_addr: str = "localhost:8900", + dev: Annotated[ + bool, typer.Option("--dev", "-d", help="Run the executor in development mode") + ] = False, workers: Annotated[ int, typer.Option(help="number of worker processes for extraction") ] = 1, @@ -174,19 +180,26 @@ def executor( "1", help="Requested Image Version for this executor" ), ): + # configure structured logging + if not dev: + processors = [ + structlog.processors.dict_tracebacks, + structlog.processors.JSONRenderer(), + ] + structlog.configure(processors=processors) + id = nanoid.generate() - console.print( - Panel( - f"Number of workers: {workers}\n" - f"Config path: {config_path}\n" - f"Server address: {server_addr}\n" - f"Executor ID: {id}\n" - f"Executor cache: {executor_cache}\n" - f"Name Alias: {name_alias}" - f"Image Version: {image_version}\n", - title="Agent Configuration", - border_style="info", - ) + executor_version = version("indexify") + logging.info( + "executor started", + workers=workers, + server_addr=server_addr, + config_path=config_path, + executor_id=id, + executor_version=executor_version, + executor_cache=executor_cache, + name_alias=name_alias, + image_version=image_version, ) from pathlib import Path @@ -208,8 +221,8 @@ def executor( try: asyncio.get_event_loop().run_until_complete(agent.run()) - except asyncio.CancelledError as ex: - console.print(Text(f"Exiting gracefully: {ex}", style="bold yellow")) + except asyncio.CancelledError: + logging.info("graceful shutdown") def _create_image(image: Image, python_sdk_path): diff --git a/python-sdk/indexify/executor/agent.py b/python-sdk/indexify/executor/agent.py index a99ddb69e..a4134ae5f 100644 --- a/python-sdk/indexify/executor/agent.py +++ b/python-sdk/indexify/executor/agent.py @@ -299,7 +299,12 @@ async def run(self): image_version=image_version, labels=runtime_probe.labels, ).model_dump() - logging.info("registering_executor", executor_id=self._executor_id, url=url) + logging.info( + "registering_executor", + executor_id=self._executor_id, + url=url, + executor_version=executor_version, + ) try: async with get_httpx_client(self._config_path, True) as client: async with aconnect_sse( diff --git a/python-sdk/poetry.lock b/python-sdk/poetry.lock index 2bfa2f462..f147dc577 100644 --- a/python-sdk/poetry.lock +++ b/python-sdk/poetry.lock @@ -1,4 +1,4 @@ -# This file is automatically @generated by Poetry 1.8.4 and should not be changed by hand. +# This file is automatically @generated by Poetry 1.8.3 and should not be changed by hand. [[package]] name = "annotated-types" @@ -13,24 +13,24 @@ files = [ [[package]] name = "anyio" -version = "4.6.2.post1" +version = "4.7.0" description = "High level compatibility layer for multiple asynchronous event loop implementations" optional = false python-versions = ">=3.9" files = [ - {file = "anyio-4.6.2.post1-py3-none-any.whl", hash = "sha256:6d170c36fba3bdd840c73d3868c1e777e33676a69c3a72cf0a0d5d6d8009b61d"}, - {file = "anyio-4.6.2.post1.tar.gz", hash = "sha256:4c8bc31ccdb51c7f7bd251f51c609e038d63e34219b44aa86e47576389880b4c"}, + {file = "anyio-4.7.0-py3-none-any.whl", hash = "sha256:ea60c3723ab42ba6fff7e8ccb0488c898ec538ff4df1f1d5e642c3601d07e352"}, + {file = "anyio-4.7.0.tar.gz", hash = "sha256:2f834749c602966b7d456a7567cafcb309f96482b5081d14ac93ccd457f9dd48"}, ] [package.dependencies] exceptiongroup = {version = ">=1.0.2", markers = "python_version < \"3.11\""} idna = ">=2.8" sniffio = ">=1.1" -typing-extensions = {version = ">=4.1", markers = "python_version < \"3.11\""} +typing_extensions = {version = ">=4.5", markers = "python_version < \"3.13\""} [package.extras] -doc = ["Sphinx (>=7.4,<8.0)", "packaging", "sphinx-autodoc-typehints (>=1.2.0)", "sphinx-rtd-theme"] -test = ["anyio[trio]", "coverage[toml] (>=7)", "exceptiongroup (>=1.2.0)", "hypothesis (>=4.0)", "psutil (>=5.9)", "pytest (>=7.0)", "pytest-mock (>=3.6.1)", "trustme", "truststore (>=0.9.1)", "uvloop (>=0.21.0b1)"] +doc = ["Sphinx (>=7.4,<8.0)", "packaging", "sphinx-autodoc-typehints (>=1.2.0)", "sphinx_rtd_theme"] +test = ["anyio[trio]", "coverage[toml] (>=7)", "exceptiongroup (>=1.2.0)", "hypothesis (>=4.0)", "psutil (>=5.9)", "pytest (>=7.0)", "pytest-mock (>=3.6.1)", "trustme", "truststore (>=0.9.1)", "uvloop (>=0.21)"] trio = ["trio (>=0.26.1)"] [[package]] @@ -1127,4 +1127,4 @@ files = [ [metadata] lock-version = "2.0" python-versions = "^3.9" -content-hash = "31628f9c231567383a7d91a62d61aa2aa51477010443d7e7343a5191539969f7" +content-hash = "21ca7f3c56f09eeb50f4ef3090349a0baaa5bbc839df8f8ceb06ef6dc7f593c0"