Skip to content

Commit 35f60bf

Browse files
committed
Adding callback for Log Detective
Signed-off-by: Jiri Podivin <[email protected]>
1 parent d4e04b3 commit 35f60bf

File tree

3 files changed

+69
-0
lines changed

3 files changed

+69
-0
lines changed

packit_service_fedmsg/callbacks.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,12 @@ def _openscanhub_task_started(
226226
)
227227

228228

229+
def _logdetective_analysis_result(topic: str, event: dict, packit_user: str):
230+
return CallbackResult(
231+
msg=f"[LogDetective] analysis for {event.get('target_build')} is available.",
232+
)
233+
234+
229235
# [WARNING]
230236
# Configuration of the topics to listen to needs to be changed in
231237
# a respective fedora.toml.j2 (https://github.com/packit/deployment/tree/main/secrets)
@@ -247,4 +253,5 @@ def _openscanhub_task_started(
247253
"org.release-monitoring.prod.anitya.project.version.update.v2": _anitya_version_update,
248254
"org.fedoraproject.prod.openscanhub.task.started": _openscanhub_task_started,
249255
"org.fedoraproject.prod.openscanhub.task.finished": _openscanhub_task_finished,
256+
"org.fedoraproject.prod.logdetective.analysis": _logdetective_analysis_result,
250257
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
{
2+
"body": {
3+
"log_detective_response": {
4+
"explanation": {
5+
"text": "The RPM build failed due to a test setup failure and a specific test case \"XXXX\" failing.\nThe overall result of the build process was also reported as FAIL.\nTo resolve this, investigate the test setup environment and the failing test case to identify the root cause.",
6+
"logprobs": null
7+
},
8+
"response_certainty": 0.0,
9+
"snippets": [
10+
{
11+
"explanation": {
12+
"text": "The snippet indicates uncertainty about an event that occured during the build.",
13+
"relevance": 95
14+
},
15+
"text": "What happened?",
16+
"line_number": 0
17+
},
18+
{
19+
"explanation": {
20+
"text": "The log snippet indicates a generic failure during an RPM build process. The message 'Failure!' suggests that a command or script executed during the build returned a non-zero exit code, halting the process.",
21+
"relevance": 95
22+
},
23+
"text": "Failure!",
24+
"line_number": 0
25+
}
26+
]
27+
},
28+
"target_build": "9999",
29+
"build_system": "koji",
30+
"result": "complete"
31+
},
32+
"headers": {
33+
"fedora_messaging_schema": "base.message",
34+
"fedora_messaging_severity": 20,
35+
"priority": 0,
36+
"sent-at": "2025-11-29T00:00:00+00:00"
37+
},
38+
"id": "197dc06b-3ae6-435a-93dc-baad4e39cda2",
39+
"priority": 0,
40+
"queue": null,
41+
"topic": "org.fedoraproject.prod.logdetective.analysis"
42+
}

tests/test_log_detective_tasks.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Copyright Contributors to the Packit project.
2+
# SPDX-License-Identifier: MIT
3+
4+
import json
5+
6+
from celery import Celery
7+
from fedora_messaging import message
8+
from flexmock import flexmock
9+
10+
from packit_service_fedmsg.consumer import Consumerino
11+
from tests.spellbook import DATA_DIR
12+
13+
14+
def test_tasks_event():
15+
flexmock(Celery).should_receive("send_task").and_return(flexmock(id="a")).once()
16+
with open(DATA_DIR / "logdetective_analysis_result.json") as outfile:
17+
json_msg = json.load(outfile)
18+
msg = message.loads(json.dumps(json_msg))
19+
c = Consumerino()
20+
c(msg[0])

0 commit comments

Comments
 (0)