Skip to content

Commit

Permalink
Make Kubernetes job description fit on one log line (#18377)
Browse files Browse the repository at this point in the history
Currently, when the Kubernetes executor creates a pod it prints a dictionary description of the pod across many lines (can easily be 20+ lines). This is fine if you're reading the log in a stream in a text file, but throws off log search tools like Kibana. A better practice would be to print the whole pod description on a single line. It is quite easy to prettify a dictionary if one wants to see it back in a more human-friendly form with the newlines.

This update simply forces the log from this command into a single line.
  • Loading branch information
collinmcnulty committed Sep 21, 2021
1 parent 44f601e commit 7808be7
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 1 addition & 1 deletion airflow/executors/kubernetes_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ def run_next(self, next_job: KubernetesJobType) -> None:
and store relevant info in the current_jobs map so we can track the job's
status
"""
self.log.info('Kubernetes job is %s', str(next_job))
self.log.info('Kubernetes job is %s', str(next_job).replace("\n", " "))
key, command, kube_executor_config, pod_template_file = next_job
dag_id, task_id, run_id, try_number = key

Expand Down
4 changes: 3 additions & 1 deletion airflow/providers/cncf/kubernetes/utils/pod_launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,9 @@ def run_pod_async(self, pod: V1Pod, **kwargs):
)
self.log.debug('Pod Creation Response: %s', resp)
except Exception as e:
self.log.exception('Exception when attempting to create Namespaced Pod: %s', json_pod)
self.log.exception(
'Exception when attempting to create Namespaced Pod: %s', str(json_pod).replace("\n", " ")
)
raise e
return resp

Expand Down

0 comments on commit 7808be7

Please sign in to comment.