Skip to content

Add app version to queue items #1064

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions jbi/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@

settings = get_settings()
version_info = get_version(APP_DIR)
VERSION = version_info["version"]

logging.config.dictConfig(CONFIG)

Expand All @@ -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,
)


Expand Down Expand Up @@ -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,
)
Expand Down
9 changes: 7 additions & 2 deletions jbi/queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -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<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)"
)
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions jbi/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
Expand Down
1 change: 1 addition & 0 deletions tests/fixtures/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,3 +191,4 @@ class Meta:

payload = factory.SubFactory(WebhookRequestFactory)
error = factory.SubFactory(PythonExceptionFactory)
version = "42.0.1"
2 changes: 2 additions & 0 deletions tests/unit/test_router.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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": {
Expand Down
Loading