Skip to content

Commit 7fb7291

Browse files
authored
Fix #960: add endpoint to view queue content (#961)
* Fix #960: add endpoint to view queue content * Fix text, but not root cause * Fix root cause * Rewrite dl queue fixture with @grahamalama suggestion * Reduce amount of data in response
1 parent e06ad77 commit 7fb7291

File tree

4 files changed

+71
-4
lines changed

4 files changed

+71
-4
lines changed

jbi/router.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,31 @@ async def bugzilla_webhook(
7575
return await execute_or_queue(webhook_request, queue, actions)
7676

7777

78+
@router.get(
79+
"/dl_queue/",
80+
dependencies=[Depends(api_key_auth)],
81+
)
82+
async def inspect_dl_queue(queue: Annotated[DeadLetterQueue, Depends(get_dl_queue)]):
83+
"""API for viewing queue content"""
84+
bugs = await queue.retrieve()
85+
results = []
86+
for items in bugs.values():
87+
async for item in items:
88+
results.append(
89+
item.model_dump(
90+
include={
91+
"identifier": True,
92+
"error": True,
93+
"payload": {
94+
"bug": {"id", "whiteboard", "product", "component"},
95+
"event": {"action", "time"},
96+
},
97+
}
98+
)
99+
)
100+
return results
101+
102+
78103
@router.get(
79104
"/whiteboard_tags/",
80105
dependencies=[Depends(api_key_auth)],

tests/conftest.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
from jbi import Operation, bugzilla, jira
1616
from jbi.environment import Settings
1717
from jbi.models import ActionContext
18-
from jbi.queue import DeadLetterQueue
18+
from jbi.queue import DeadLetterQueue, get_dl_queue
1919

2020

2121
class FilteredLogCaptureFixture(pytest.LogCaptureFixture):
@@ -76,8 +76,10 @@ def mocked_statsd():
7676

7777

7878
@pytest.fixture
79-
def app():
80-
return jbi.app.app
79+
def app(dl_queue):
80+
app = jbi.app.app
81+
app.dependency_overrides[get_dl_queue] = lambda: dl_queue
82+
return app
8183

8284

8385
@pytest.fixture
@@ -116,6 +118,11 @@ def mock_queue():
116118
return mock.MagicMock(spec=DeadLetterQueue)
117119

118120

121+
@pytest.fixture
122+
def dl_queue(tmp_path):
123+
return DeadLetterQueue("file://" + str(tmp_path))
124+
125+
119126
@pytest.fixture(autouse=True)
120127
def mocked_bugzilla(request):
121128
if "no_mocked_bugzilla" in request.keywords:

tests/unit/test_environment.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def test_sentry_dsn_no_url_string_raises():
2727

2828

2929
def dl_queue_dsn_allowed_schema(dsn):
30-
Settings(dl_queue_dsn="file://tmp")
30+
Settings(dl_queue_dsn="file://tmp/queue")
3131

3232

3333
@pytest.mark.parametrize("dsn", ["http://www.example.com", "foobar"])

tests/unit/test_router.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ def test_read_root(anon_client):
2323
"endpoint",
2424
[
2525
"/whiteboard_tags",
26+
"/dl_queue/",
2627
"/jira_projects/",
2728
"/powered_by_jbi/",
2829
"/bugzilla_webhooks/",
@@ -74,6 +75,40 @@ def test_whiteboard_tags_filtered(authenticated_client):
7475
assert sorted(infos.keys()) == ["devtest"]
7576

7677

78+
@pytest.mark.asyncio
79+
async def test_dl_queue_endpoint(
80+
dl_queue, authenticated_client, webhook_request_factory
81+
):
82+
item = webhook_request_factory(event__time=datetime(1982, 5, 8, 9, 10))
83+
exc = Exception("boom")
84+
await dl_queue.track_failed(item, exc)
85+
86+
resp = authenticated_client.get("/dl_queue/")
87+
results = resp.json()
88+
89+
[infos] = results
90+
assert infos == {
91+
"error": {
92+
"description": "boom",
93+
"details": "Exception: boom\n",
94+
"type": "Exception",
95+
},
96+
"identifier": "1982-05-08 09:10:00+00:00-654321-create-error",
97+
"payload": {
98+
"bug": {
99+
"component": "General",
100+
"id": 654321,
101+
"product": "JBI",
102+
"whiteboard": "[devtest]",
103+
},
104+
"event": {
105+
"action": "create",
106+
"time": "1982-05-08T09:10:00+00:00",
107+
},
108+
},
109+
}
110+
111+
77112
def test_powered_by_jbi(exclude_middleware, authenticated_client):
78113
resp = authenticated_client.get("/powered_by_jbi/")
79114
html = resp.text

0 commit comments

Comments
 (0)