Skip to content

Commit 35d6b64

Browse files
Adding callback for Log Detective (#119)
Adding callback for Log Detective TODO: Write new tests or update the old ones to cover new functionality. Update doc-strings where appropriate. Callback for messages produced by https://github.com/fedora-copr/logdetective-packit/ I do not expect the infrastructure on the side of packit-service to be available for some time yet. However, merging this will have effectively no effect until requests from packit start coming in, and responses from Log Detective start coming back. Schema for the message shouldn't change. Although, if necessary, we may yet release it as a package. RELEASE NOTES BEGIN Messages from Log Detective, under the org.fedoraproject.prod.logdetective.analysis topic are now processed by a callback. RELEASE NOTES END Reviewed-by: Marek Blaha <[email protected]> Reviewed-by: Jiří Podivín
2 parents d4e04b3 + 906c418 commit 35d6b64

File tree

3 files changed

+73
-0
lines changed

3 files changed

+73
-0
lines changed

packit_service_fedmsg/callbacks.py

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

228228

229+
def _logdetective_analysis_result(
230+
topic: str,
231+
event: dict,
232+
packit_user: str,
233+
) -> CallbackResult:
234+
return CallbackResult(
235+
msg=f"[LogDetective] analysis for {event.get('target_build')} is available.",
236+
)
237+
238+
229239
# [WARNING]
230240
# Configuration of the topics to listen to needs to be changed in
231241
# a respective fedora.toml.j2 (https://github.com/packit/deployment/tree/main/secrets)
@@ -247,4 +257,5 @@ def _openscanhub_task_started(
247257
"org.release-monitoring.prod.anitya.project.version.update.v2": _anitya_version_update,
248258
"org.fedoraproject.prod.openscanhub.task.started": _openscanhub_task_started,
249259
"org.fedoraproject.prod.openscanhub.task.finished": _openscanhub_task_finished,
260+
"org.fedoraproject.prod.logdetective.analysis": _logdetective_analysis_result,
250261
}
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)