diff --git a/jbi/app.py b/jbi/app.py index 0d903d49..8e777236 100644 --- a/jbi/app.py +++ b/jbi/app.py @@ -33,6 +33,7 @@ settings = get_settings() version_info = get_version(APP_DIR) +VERSION: str = version_info["version"] logging.config.dictConfig(CONFIG) @@ -52,7 +53,7 @@ def traces_sampler(sampling_context: dict[str, Any]) -> float: sentry_sdk.init( dsn=str(settings.sentry_dsn) if settings.sentry_dsn else None, traces_sampler=traces_sampler, - release=version_info["version"], + release=VERSION, ) @@ -100,7 +101,7 @@ async def lifespan(app: FastAPI) -> AsyncGenerator[None, None]: app = FastAPI( title="Jira Bugzilla Integration (JBI)", description="Platform providing synchronization of Bugzilla bugs to Jira issues.", - version=version_info["version"], + version=VERSION, debug=settings.app_debug, lifespan=lifespan, ) diff --git a/jbi/queue.py b/jbi/queue.py index 7d2aa6a9..35049108 100644 --- a/jbi/queue.py +++ b/jbi/queue.py @@ -37,12 +37,11 @@ import dockerflow.checks from pydantic import BaseModel, FileUrl, ValidationError, computed_field -from jbi import bugzilla +from jbi import app, bugzilla from jbi.environment import get_settings logger = logging.getLogger(__name__) - ITEM_ID_PATTERN = re.compile( r"(?P\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\+\d{2}:\d{2})-(?P\d+)-(?P\w*)-(?Perror|postponed)" ) @@ -90,6 +89,12 @@ class QueueItem(BaseModel, frozen=True): error: Optional[PythonException] = None rid: Optional[str] = None + @computed_field # type: ignore + @property + def version(self) -> str: + # Prevents circular imports. + return app.VERSION + @property def timestamp(self) -> datetime: return self.payload.event.time diff --git a/jbi/router.py b/jbi/router.py index 63102802..1f55f0ea 100644 --- a/jbi/router.py +++ b/jbi/router.py @@ -87,6 +87,7 @@ async def inspect_dl_queue(queue: Annotated[DeadLetterQueue, Depends(get_dl_queu "identifier": True, "rid": True, "error": True, + "version": True, "payload": { "bug": {"id", "whiteboard", "product", "component"}, "event": {"action", "time"}, diff --git a/tests/fixtures/factories.py b/tests/fixtures/factories.py index 3909d45e..e7db1e47 100644 --- a/tests/fixtures/factories.py +++ b/tests/fixtures/factories.py @@ -191,3 +191,4 @@ class Meta: payload = factory.SubFactory(WebhookRequestFactory) error = factory.SubFactory(PythonExceptionFactory) + version = "42.0.1" diff --git a/tests/unit/test_router.py b/tests/unit/test_router.py index 0b0af2e8..7347e5f4 100644 --- a/tests/unit/test_router.py +++ b/tests/unit/test_router.py @@ -7,6 +7,7 @@ import pytest from fastapi.testclient import TestClient +from jbi import app from jbi.environment import get_settings from jbi.queue import get_dl_queue @@ -93,6 +94,7 @@ async def test_dl_queue_endpoint( "details": "Exception: boom\n", "type": "Exception", }, + "version": app.VERSION, "identifier": "1982-05-08 09:10:00+00:00-654321-create-error", "rid": "rid", "payload": {