-
Notifications
You must be signed in to change notification settings - Fork 59
Add information about Log Detective runs into API #3075
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
centosinfra-prod-github-app
merged 3 commits into
packit:main
from
jpodivin:log_dective_api
Mar 26, 2026
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,7 +13,11 @@ | |
| optional_timestamp, | ||
| ) | ||
| from packit_service.service.api.parsers import indices, pagination_arguments | ||
| from packit_service.service.api.utils import get_project_info_from_build, response_maker | ||
| from packit_service.service.api.utils import ( | ||
| get_log_detective_runs, | ||
| get_project_info_from_build, | ||
| response_maker, | ||
| ) | ||
|
|
||
| logger = getLogger("packit_service") | ||
|
|
||
|
|
@@ -99,6 +103,7 @@ def get(self, id): | |
| "run_ids": sorted(run.id for run in build.group_of_targets.runs), | ||
| "build_submission_stdout": build.build_submission_stdout, | ||
| "error_message": build.data.get("error") if build.data else None, | ||
| "log_detective_runs": get_log_detective_runs(build=build), | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same as above |
||
| } | ||
|
|
||
| build_dict.update(get_project_info_from_build(build)) | ||
|
|
||
|
jpodivin marked this conversation as resolved.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,119 @@ | ||
| # Copyright Contributors to the Packit project. | ||
| # SPDX-License-Identifier: MIT | ||
|
|
||
| import logging | ||
| from http import HTTPStatus | ||
|
|
||
| from flask_restx import Namespace, Resource | ||
|
|
||
| from packit_service.models import ( | ||
| LogDetectiveRunGroupModel, | ||
| LogDetectiveRunModel, | ||
| optional_timestamp, | ||
| ) | ||
| from packit_service.service.api.parsers import indices, pagination_arguments | ||
| from packit_service.service.api.utils import get_project_info_from_build, response_maker | ||
|
|
||
| logger = logging.getLogger("packit_service") | ||
|
jpodivin marked this conversation as resolved.
|
||
|
|
||
| ns = Namespace("log-detective", description="Log Detective") | ||
|
|
||
|
|
||
| @ns.route("/<int:id>") | ||
| @ns.param("id", "Packit id of the Log Detective run") | ||
| class LogDetectiveResult(Resource): | ||
| @ns.response(HTTPStatus.OK.value, "OK, Log Detective run details follow") | ||
| @ns.response(HTTPStatus.NOT_FOUND.value, "No info about Log Detective run stored in DB") | ||
| def get(self, id): | ||
| """A specific Log Detective run details.""" | ||
| log_detective_run_model = LogDetectiveRunModel.get_by_id(int(id)) | ||
|
|
||
| if not log_detective_run_model: | ||
| return response_maker( | ||
| {"error": "No info about Log Detective run stored in DB"}, | ||
| status=HTTPStatus.NOT_FOUND, | ||
| ) | ||
| run_ids = [] | ||
| if log_detective_run_model.group_of_targets.runs: | ||
| run_ids = sorted(run.id for run in log_detective_run_model.group_of_targets.runs) | ||
|
|
||
| log_detective_result_dict = { | ||
| "packit_id": log_detective_run_model.id, | ||
| "analysis_id": log_detective_run_model.analysis_id, | ||
| "status": log_detective_run_model.status.value, | ||
|
jpodivin marked this conversation as resolved.
|
||
| "chroot": log_detective_run_model.target, | ||
| "commit_sha": log_detective_run_model.commit_sha, | ||
| "log_detective_response": log_detective_run_model.log_detective_response, | ||
| "target_build": log_detective_run_model.target_build, | ||
| "run_ids": run_ids, | ||
| "submitted_time": optional_timestamp(log_detective_run_model.submitted_time), | ||
| } | ||
|
|
||
| log_detective_result_dict.update(get_project_info_from_build(log_detective_run_model)) | ||
| return response_maker(log_detective_result_dict) | ||
|
|
||
|
|
||
| @ns.route("/groups/<int:id>") | ||
| @ns.param("id", "Packit id of the Log Detective run group") | ||
| class LogDetectiveGroup(Resource): | ||
| @ns.response(HTTPStatus.OK, "OK, Log Detective run group details follow") | ||
| @ns.response( | ||
| HTTPStatus.NOT_FOUND.value, | ||
| "No info about Log Detective run group stored in DB", | ||
| ) | ||
| def get(self, id): | ||
| """A specific Log Detective run group details.""" | ||
| group_model = LogDetectiveRunGroupModel.get_by_id(int(id)) | ||
|
jpodivin marked this conversation as resolved.
|
||
|
|
||
| if not group_model: | ||
| return response_maker( | ||
| {"error": "No info about group stored in DB"}, | ||
| status=HTTPStatus.NOT_FOUND, | ||
| ) | ||
| run_ids = [] | ||
| if group_model.runs: | ||
| run_ids = sorted(run.id for run in group_model.runs) | ||
| group_dict = { | ||
| "packit_id": group_model.id, | ||
| "submitted_time": optional_timestamp(group_model.submitted_time), | ||
| "run_ids": run_ids, | ||
| "log_detective_target_ids": sorted(ld_run.id for ld_run in group_model.grouped_targets), | ||
| } | ||
|
|
||
| group_dict.update(get_project_info_from_build(group_model)) | ||
| return response_maker(group_dict) | ||
|
|
||
|
|
||
| @ns.route("") | ||
| class LogDetectiveResultList(Resource): | ||
| @ns.expect(pagination_arguments) | ||
| @ns.response(HTTPStatus.PARTIAL_CONTENT, "Log Detective result list follows") | ||
| def get(self): | ||
| """List all Log Detective results.""" | ||
|
|
||
| first, last = indices() | ||
| result = [] | ||
|
|
||
| for log_detective_run_model in LogDetectiveRunModel.get_range(first, last): | ||
| run_ids = [] | ||
| if log_detective_run_model.group_of_targets.runs: | ||
| run_ids = sorted(run.id for run in log_detective_run_model.group_of_targets.runs) | ||
| log_detective_result_dict = { | ||
| "packit_id": log_detective_run_model.id, | ||
| "analysis_id": log_detective_run_model.analysis_id, | ||
| "status": log_detective_run_model.status.value, | ||
| "chroot": log_detective_run_model.target, | ||
| "commit_sha": log_detective_run_model.commit_sha, | ||
| "log_detective_response": log_detective_run_model.log_detective_response, | ||
| "target_build": log_detective_run_model.target_build, | ||
| "run_ids": run_ids, | ||
| "submitted_time": optional_timestamp(log_detective_run_model.submitted_time), | ||
| } | ||
| result.append(log_detective_result_dict) | ||
|
|
||
| resp = response_maker( | ||
| result, | ||
| status=HTTPStatus.PARTIAL_CONTENT, | ||
| ) | ||
| resp.headers["Content-Range"] = f"log-detective-results {first + 1}-{last}/*" | ||
| return resp | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.