Skip to content

Commit

Permalink
Improvements for storing downstream Koji builds (#2249)
Browse files Browse the repository at this point in the history
See the commits.

Related to packit/dashboard#354

---

RELEASE NOTES BEGIN

RELEASE NOTES END
  • Loading branch information
lbarcziova authored Nov 10, 2023
2 parents 1ff9b2b + 748e62c commit 3084367
Show file tree
Hide file tree
Showing 13 changed files with 82 additions and 15 deletions.
30 changes: 24 additions & 6 deletions packit_service/worker/events/koji.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,18 @@

class AbstractKojiEvent(AbstractResultEvent):
def __init__(
self, task_id: int, rpm_build_task_ids: Optional[Dict[str, int]] = None
self,
task_id: int,
rpm_build_task_ids: Optional[Dict[str, int]] = None,
start_time: Optional[Union[int, float, str]] = None,
completion_time: Optional[Union[int, float, str]] = None,
):
super().__init__()
self.task_id = task_id
# dictionary with archs and IDs, e.g. {"x86_64": 123}
self.rpm_build_task_ids = rpm_build_task_ids
self.start_time: Optional[Union[int, float, str]] = start_time
self.completion_time: Optional[Union[int, float, str]] = completion_time

# Lazy properties
self._target: Optional[str] = None
Expand Down Expand Up @@ -122,8 +128,15 @@ def __init__(
web_url: Optional[str] = None,
old_state: Optional[KojiBuildState] = None,
rpm_build_task_ids: Optional[Dict[str, int]] = None,
start_time: Optional[Union[int, float, str]] = None,
completion_time: Optional[Union[int, float, str]] = None,
):
super().__init__(task_id=task_id, rpm_build_task_ids=rpm_build_task_ids)
super().__init__(
task_id=task_id,
rpm_build_task_ids=rpm_build_task_ids,
start_time=start_time,
completion_time=completion_time,
)
self.build_id = build_id
self.state = state
self.old_state = old_state
Expand Down Expand Up @@ -183,6 +196,8 @@ def from_event_dict(cls, event: dict):
epoch=event.get("epoch"),
version=event.get("version"),
release=event.get("release"),
start_time=event.get("start_time"),
completion_time=event.get("completion_time"),
)


Expand All @@ -200,11 +215,14 @@ def __init__(
start_time: Optional[Union[int, float, str]] = None,
completion_time: Optional[Union[int, float, str]] = None,
):
super().__init__(task_id=task_id, rpm_build_task_ids=rpm_build_task_ids)
super().__init__(
task_id=task_id,
rpm_build_task_ids=rpm_build_task_ids,
start_time=start_time,
completion_time=completion_time,
)
self.state = state
self.old_state = old_state
self.start_time: Optional[Union[int, float, str]] = start_time
self.completion_time: Optional[Union[int, float, str]] = completion_time

# Lazy properties
self._pr_id: Optional[int] = None
Expand Down Expand Up @@ -257,7 +275,7 @@ def identifier(self) -> str:
@classmethod
def from_event_dict(cls, event: dict):
return KojiTaskEvent(
task_id=event.get("build_id"),
task_id=event.get("task_id"),
state=KojiTaskState(event.get("state")) if event.get("state") else None,
old_state=(
KojiTaskState(event.get("old_state"))
Expand Down
11 changes: 6 additions & 5 deletions packit_service/worker/handlers/distgit.py
Original file line number Diff line number Diff line change
Expand Up @@ -840,12 +840,13 @@ def get_handler_specific_task_accepted_message(
user = "packit-stg"
user_id = 5279

dashboard_url = service_config.dashboard_url

return (
f"You can check the recent Koji build activity of `{user}` in [the Koji interface]"
f"(https://koji.fedoraproject.org/koji/userinfo?userID={user_id}) (we "
f"have also planned adding support for viewing the builds in "
f"[Packit dashboard]({service_config.dashboard_url}), "
f"see [this issue](https://github.com/packit/dashboard/issues/187))."
"You can check the recent runs of downstream Koji jobs "
f"in [Packit dashboard]({dashboard_url}/jobs/downstream-koji-builds). "
f"You can also check the recent Koji build activity of `{user}` in [the Koji interface]"
f"(https://koji.fedoraproject.org/koji/userinfo?userID={user_id})."
)


Expand Down
12 changes: 12 additions & 0 deletions packit_service/worker/handlers/koji.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,18 @@ def run(self):
)
logger.debug(msg)

self.build.set_build_start_time(
datetime.fromisoformat(self.koji_build_event.start_time)
if self.koji_build_event.start_time
else None
)

self.build.set_build_finished_time(
datetime.fromisoformat(self.koji_build_event.completion_time)
if self.koji_build_event.completion_time
else None
)

new_commit_status = {
KojiBuildState.building: BaseCommitStatus.running,
KojiBuildState.complete: BaseCommitStatus.success,
Expand Down
5 changes: 5 additions & 0 deletions packit_service/worker/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -1349,6 +1349,9 @@ def parse_koji_build_event(event) -> Optional[KojiBuildEvent]:
else None
)

start_time = event.get("creation_time")
completion_time = event.get("completion_time")

version = event.get("version")
epoch = event.get("epoch")

Expand Down Expand Up @@ -1391,6 +1394,8 @@ def parse_koji_build_event(event) -> Optional[KojiBuildEvent]:
koji_web_url=ServiceConfig.get_service_config().koji_web_url,
),
old_state=old_state,
start_time=start_time,
completion_time=completion_time,
)

@staticmethod
Expand Down
2 changes: 2 additions & 0 deletions tests/data/fedmsg/koji_build_completed_epel8.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
{
"body": {
"completion_time": "2023-11-08T10:01:04.706963+00:00",
"creation_time": "2023-11-08T09:54:48.493165+00:00",
"attribute": "state",
"build_id": 1874072,
"epoch": null,
Expand Down
2 changes: 2 additions & 0 deletions tests/data/fedmsg/koji_build_completed_f36.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
{
"body": {
"completion_time": "2023-11-08T10:01:04.706963+00:00",
"creation_time": "2023-11-08T09:54:48.493165+00:00",
"attribute": "state",
"build_id": 1874070,
"epoch": null,
Expand Down
2 changes: 2 additions & 0 deletions tests/data/fedmsg/koji_build_completed_rawhide.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
{
"body": {
"completion_time": "2023-11-08T10:01:04.706963+00:00",
"creation_time": "2023-11-08T09:54:48.493165+00:00",
"attribute": "state",
"build_id": 1874074,
"epoch": null,
Expand Down
2 changes: 2 additions & 0 deletions tests/data/fedmsg/koji_build_start_epel8.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
{
"body": {
"completion_time": null,
"creation_time": "2023-11-08T09:54:48.493165+00:00",
"attribute": "state",
"build_id": 1874072,
"epoch": null,
Expand Down
2 changes: 2 additions & 0 deletions tests/data/fedmsg/koji_build_start_f36.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
{
"body": {
"completion_time": null,
"creation_time": "2023-11-08T09:54:48.493165+00:00",
"attribute": "state",
"build_id": 1874070,
"epoch": null,
Expand Down
2 changes: 2 additions & 0 deletions tests/data/fedmsg/koji_build_start_rawhide.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
{
"body": {
"completion_time": null,
"creation_time": "2023-11-08T09:54:48.493165+00:00",
"attribute": "state",
"build_id": 1874074,
"epoch": null,
Expand Down
2 changes: 2 additions & 0 deletions tests/integration/test_koji_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ def test_downstream_koji_build_report_known_build(koji_build_fixture, request):
id=1, job_config_trigger_type=JobConfigTriggerType.commit
),
set_status=lambda x: None,
set_build_start_time=lambda x: None,
set_build_finished_time=lambda x: None,
)
.should_receive("set_build_logs_urls")
.with_args({})
Expand Down
8 changes: 4 additions & 4 deletions tests/integration/test_pr_comment.py
Original file line number Diff line number Diff line change
Expand Up @@ -2392,11 +2392,11 @@ def test_koji_build_retrigger_via_dist_git_pr_comment(pagure_pr_comment_added):
flexmock(target_branch="the_distgit_branch")
.should_receive("comment")
.with_args(
"The task was accepted. You can check the recent Koji build activity of "
"The task was accepted. You can check the recent runs of downstream Koji jobs "
"in [Packit dashboard](/jobs/downstream-koji-builds). "
"You can also check the recent Koji build activity of "
"`packit` in [the Koji interface]"
"(https://koji.fedoraproject.org/koji/userinfo?userID=4641) (we have also "
"planned adding support for viewing the builds in [Packit dashboard](), "
"see [this issue](https://github.com/packit/dashboard/issues/187))."
"(https://koji.fedoraproject.org/koji/userinfo?userID=4641)."
)
.mock()
)
Expand Down
17 changes: 17 additions & 0 deletions tests/unit/test_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -1134,6 +1134,9 @@ def test_parse_koji_build_event_start_rawhide(
event_object.project_url == "https://src.fedoraproject.org/rpms/python-ogr"
)

assert event_object.start_time is not None
assert event_object.completion_time is None

assert isinstance(event_object.project, PagureProject)
assert event_object.project.full_repo_name == "rpms/python-ogr"

Expand Down Expand Up @@ -1172,6 +1175,9 @@ def test_parse_koji_build_event_start_f36(self, koji_build_start_f36, mock_confi
event_object.project_url == "https://src.fedoraproject.org/rpms/python-ogr"
)

assert event_object.start_time is not None
assert event_object.completion_time is None

assert isinstance(event_object.project, PagureProject)
assert event_object.project.full_repo_name == "rpms/python-ogr"

Expand Down Expand Up @@ -1211,6 +1217,9 @@ def test_parse_koji_build_event_start_epel8(
event_object.project_url == "https://src.fedoraproject.org/rpms/python-ogr"
)

assert event_object.start_time is not None
assert event_object.completion_time is None

assert isinstance(event_object.project, PagureProject)
assert event_object.project.full_repo_name == "rpms/python-ogr"

Expand Down Expand Up @@ -1288,6 +1297,8 @@ def test_parse_koji_build_event_completed_rawhide(
assert (
event_object.project_url == "https://src.fedoraproject.org/rpms/python-ogr"
)
assert event_object.start_time is not None
assert event_object.completion_time is not None

assert isinstance(event_object.project, PagureProject)
assert event_object.project.full_repo_name == "rpms/python-ogr"
Expand Down Expand Up @@ -1329,6 +1340,9 @@ def test_parse_koji_build_event_completed_f36(
event_object.project_url == "https://src.fedoraproject.org/rpms/python-ogr"
)

assert event_object.start_time is not None
assert event_object.completion_time is not None

assert isinstance(event_object.project, PagureProject)
assert event_object.project.full_repo_name == "rpms/python-ogr"

Expand Down Expand Up @@ -1369,6 +1383,9 @@ def test_parse_koji_build_event_completed_epel8(
event_object.project_url == "https://src.fedoraproject.org/rpms/python-ogr"
)

assert event_object.start_time is not None
assert event_object.completion_time is not None

assert isinstance(event_object.project, PagureProject)
assert event_object.project.full_repo_name == "rpms/python-ogr"

Expand Down

0 comments on commit 3084367

Please sign in to comment.