Skip to content

Commit f5f514a

Browse files
leplatremdavehunt
authored andcommitted
Add app version to queue items (mozilla#1064)
1 parent d81cff5 commit f5f514a

File tree

5 files changed

+14
-4
lines changed

5 files changed

+14
-4
lines changed

jbi/app.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333

3434
settings = get_settings()
3535
version_info = get_version(APP_DIR)
36+
VERSION: str = version_info["version"]
3637

3738
logging.config.dictConfig(CONFIG)
3839

@@ -52,7 +53,7 @@ def traces_sampler(sampling_context: dict[str, Any]) -> float:
5253
sentry_sdk.init(
5354
dsn=str(settings.sentry_dsn) if settings.sentry_dsn else None,
5455
traces_sampler=traces_sampler,
55-
release=version_info["version"],
56+
release=VERSION,
5657
)
5758

5859

@@ -100,7 +101,7 @@ async def lifespan(app: FastAPI) -> AsyncGenerator[None, None]:
100101
app = FastAPI(
101102
title="Jira Bugzilla Integration (JBI)",
102103
description="Platform providing synchronization of Bugzilla bugs to Jira issues.",
103-
version=version_info["version"],
104+
version=VERSION,
104105
debug=settings.app_debug,
105106
lifespan=lifespan,
106107
)

jbi/queue.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,11 @@
3737
import dockerflow.checks
3838
from pydantic import BaseModel, FileUrl, ValidationError, computed_field
3939

40-
from jbi import bugzilla
40+
from jbi import app, bugzilla
4141
from jbi.environment import get_settings
4242

4343
logger = logging.getLogger(__name__)
4444

45-
4645
ITEM_ID_PATTERN = re.compile(
4746
r"(?P<timestamp>\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\+\d{2}:\d{2})-(?P<bug_id>\d+)-(?P<action>\w*)-(?P<status>error|postponed)"
4847
)
@@ -90,6 +89,12 @@ class QueueItem(BaseModel, frozen=True):
9089
error: Optional[PythonException] = None
9190
rid: Optional[str] = None
9291

92+
@computed_field # type: ignore
93+
@property
94+
def version(self) -> str:
95+
# Prevents circular imports.
96+
return app.VERSION
97+
9398
@property
9499
def timestamp(self) -> datetime:
95100
return self.payload.event.time

jbi/router.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ async def inspect_dl_queue(queue: Annotated[DeadLetterQueue, Depends(get_dl_queu
8787
"identifier": True,
8888
"rid": True,
8989
"error": True,
90+
"version": True,
9091
"payload": {
9192
"bug": {"id", "whiteboard", "product", "component"},
9293
"event": {"action", "time"},

tests/fixtures/factories.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,3 +191,4 @@ class Meta:
191191

192192
payload = factory.SubFactory(WebhookRequestFactory)
193193
error = factory.SubFactory(PythonExceptionFactory)
194+
version = "42.0.1"

tests/unit/test_router.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import pytest
88
from fastapi.testclient import TestClient
99

10+
from jbi import app
1011
from jbi.environment import get_settings
1112
from jbi.queue import get_dl_queue
1213

@@ -93,6 +94,7 @@ async def test_dl_queue_endpoint(
9394
"details": "Exception: boom\n",
9495
"type": "Exception",
9596
},
97+
"version": app.VERSION,
9698
"identifier": "1982-05-08 09:10:00+00:00-654321-create-error",
9799
"rid": "rid",
98100
"payload": {

0 commit comments

Comments
 (0)