Skip to content
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

consumer: fix fetching of workflow engine logs when scheduling fails #544

Merged
merged 1 commit into from
Nov 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
Changes
=======

Version 0.9.2 (UNRELEASED)
--------------------------

- Fixes job status consumer exception while attempting to fetch workflow engine logs for workflows could not have been successfully scheduled.

Version 0.9.1 (2023-09-27)
--------------------------

Expand Down
59 changes: 26 additions & 33 deletions reana_workflow_controller/consumer.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,20 +153,20 @@
try:
workflow_engine_logs = _get_workflow_engine_pod_logs(workflow)
workflow.logs += workflow_engine_logs + "\n"
except REANAWorkflowControllerError as exception:
logging.error(
f"Could not fetch workflow engine pod logs for workflow {workflow.id_}."
f" Error: {exception}"
except ApiException as e:
logging.exception(

Check warning on line 157 in reana_workflow_controller/consumer.py

View check run for this annotation

Codecov / codecov/patch

reana_workflow_controller/consumer.py#L157

Added line #L157 was not covered by tests
f"Could not fetch workflow engine pod logs for workflow {workflow.id_}. "
f"Error: {e}"
)
workflow.logs += "Workflow engine logs could not be retrieved.\n"

if RunStatus.should_cleanup_job(status):
try:
_delete_workflow_job(workflow)
except REANAWorkflowControllerError as exception:
except ApiException as e:

Check warning on line 166 in reana_workflow_controller/consumer.py

View check run for this annotation

Codecov / codecov/patch

reana_workflow_controller/consumer.py#L166

Added line #L166 was not covered by tests
logging.error(
f"Could not clean up workflow job for workflow {workflow.id_}."
f" Error: {exception}"
f"Could not clean up workflow job for workflow {workflow.id_}. "
f"Error: {e}"
)


Expand Down Expand Up @@ -284,32 +284,25 @@

def _delete_workflow_job(workflow: Workflow) -> None:
job_name = build_unique_component_name("run-batch", workflow.id_)
try:
current_k8s_batchv1_api_client.delete_namespaced_job(
name=job_name,
namespace=REANA_RUNTIME_KUBERNETES_NAMESPACE,
propagation_policy="Background",
)
except ApiException as e:
raise REANAWorkflowControllerError(
f"Workflow engine pod could not be deleted. Error: {e}"
)
current_k8s_batchv1_api_client.delete_namespaced_job(

Check warning on line 287 in reana_workflow_controller/consumer.py

View check run for this annotation

Codecov / codecov/patch

reana_workflow_controller/consumer.py#L287

Added line #L287 was not covered by tests
name=job_name,
namespace=REANA_RUNTIME_KUBERNETES_NAMESPACE,
propagation_policy="Background",
)


def _get_workflow_engine_pod_logs(workflow: Workflow) -> str:
try:
pods = current_k8s_corev1_api_client.list_namespaced_pod(
namespace=REANA_RUNTIME_KUBERNETES_NAMESPACE,
label_selector=f"reana-run-batch-workflow-uuid={str(workflow.id_)}",
)
for pod in pods.items:
if str(workflow.id_) in pod.metadata.name:
return current_k8s_corev1_api_client.read_namespaced_pod_log(
namespace=pod.metadata.namespace,
name=pod.metadata.name,
container="workflow-engine",
)
except ApiException as e:
raise REANAWorkflowControllerError(
f"Workflow engine pod logs could not be fetched. Error: {e}"
)
pods = current_k8s_corev1_api_client.list_namespaced_pod(
namespace=REANA_RUNTIME_KUBERNETES_NAMESPACE,
label_selector=f"reana-run-batch-workflow-uuid={str(workflow.id_)}",
)
for pod in pods.items:
if str(workflow.id_) in pod.metadata.name:
return current_k8s_corev1_api_client.read_namespaced_pod_log(

Check warning on line 301 in reana_workflow_controller/consumer.py

View check run for this annotation

Codecov / codecov/patch

reana_workflow_controller/consumer.py#L300-L301

Added lines #L300 - L301 were not covered by tests
namespace=pod.metadata.namespace,
name=pod.metadata.name,
container="workflow-engine",
)
# There might not be any pod returned by `list_namespaced_pod`, for example
# when a workflow fails to be scheduled
return ""

Check warning on line 308 in reana_workflow_controller/consumer.py

View check run for this annotation

Codecov / codecov/patch

reana_workflow_controller/consumer.py#L308

Added line #L308 was not covered by tests