-
Notifications
You must be signed in to change notification settings - Fork 16.4k
Add customizable log prefix and formatter to KubernetesPodOperator #53598
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
Conversation
db9524f to
3d0d615
Compare
jason810496
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR! LGTM overall but the unit still needs fix.
kubernetes-tests/tests/kubernetes_tests/test_kubernetes_pod_operator.py
Outdated
Show resolved
Hide resolved
3d0d615 to
af7174e
Compare
jason810496
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the update, only a small nit and this PR is good to be merged.
After #53475 has merged, we don't need pytest.mark.asyncio any more.
It would be nice to remove the mark and rebase again, thanks!
kubernetes-tests/tests/kubernetes_tests/test_kubernetes_pod_operator.py
Outdated
Show resolved
Hide resolved
4d639e0 to
0ce8fd1
Compare
kubernetes-tests/tests/kubernetes_tests/test_kubernetes_pod_operator.py
Outdated
Show resolved
Hide resolved
0ce8fd1 to
7eee299
Compare
17ebc2e to
4ea3f09
Compare
|
@HsiuChuanHsu I think this is ready to merge |
|
@NilsJPWerner Yes, this PR is nearly complete, but I don't have the right to merge the code. Still wait for approval to merge. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! Thanks for the fix!
providers/cncf/kubernetes/src/airflow/providers/cncf/kubernetes/operators/pod.py
Outdated
Show resolved
Hide resolved
providers/cncf/kubernetes/src/airflow/providers/cncf/kubernetes/operators/pod.py
Show resolved
Hide resolved
providers/cncf/kubernetes/src/airflow/providers/cncf/kubernetes/utils/pod_manager.py
Outdated
Show resolved
Hide resolved
providers/cncf/kubernetes/src/airflow/providers/cncf/kubernetes/utils/pod_manager.py
Outdated
Show resolved
Hide resolved
- Introduce parameter to toggle container name prefix in logs - Add parameter for custom log message formatting - Update PodManager to support log_prefix and log_formatter in log fetching
- Add test_log_prefix_enabled to verify default log_prefix=True behavior - Add test_log_prefix_disabled to confirm log_prefix=False removes container prefix - Add test_custom_log_formatter to validate custom log_formatter functionality
…ter options Consolidated log prefix and formatter tests into a single parameterized test_log_output_configurations, covering: log_prefix=True: Includes container name prefix ([base]). log_prefix=False: Excludes container name prefix. Custom log formatter: Applies user-defined formatting (e.g., CUSTOM[base]: message)
Co-authored-by: LIU ZHE YOU <68415893+jason810496@users.noreply.github.com>
- Replace caplog with targeted mocking of PodManager logger
…g in KubernetesPodOperator - Rename log_prefix to container_name_log_prefix_enabled parameter to control container name prefix in logs - Extract duplicate log formatting logic into _log_message private method in PodManager - Update docstrings with detailed parameter descriptions
16ee837 to
4277d18
Compare
|
Thanks for the review!! 🤩 |
…pache#53598) * Add custom log formatting and prefix control to KubernetesPodOperator - Introduce parameter to toggle container name prefix in logs - Add parameter for custom log message formatting - Update PodManager to support log_prefix and log_formatter in log fetching * Add tests for log prefix and custom formatter in KubernetesPodOperator - Add test_log_prefix_enabled to verify default log_prefix=True behavior - Add test_log_prefix_disabled to confirm log_prefix=False removes container prefix - Add test_custom_log_formatter to validate custom log_formatter functionality * Enhance KubernetesPodOperator logging with flexible prefix and formatter options Consolidated log prefix and formatter tests into a single parameterized test_log_output_configurations, covering: log_prefix=True: Includes container name prefix ([base]). log_prefix=False: Excludes container name prefix. Custom log formatter: Applies user-defined formatting (e.g., CUSTOM[base]: message) * Remove @pytest.mark.asyncio Co-authored-by: LIU ZHE YOU <68415893+jason810496@users.noreply.github.com> * Modify test_log_output_configurations to improve log message capturing: - Replace caplog with targeted mocking of PodManager logger * Add custom log formatting support to KubernetesPodOperator tests * feat(kubernetes): Add log formatting options and refactor log handling in KubernetesPodOperator - Rename log_prefix to container_name_log_prefix_enabled parameter to control container name prefix in logs - Extract duplicate log formatting logic into _log_message private method in PodManager - Update docstrings with detailed parameter descriptions --------- Co-authored-by: LIU ZHE YOU <68415893+jason810496@users.noreply.github.com>
…pache#53598) * Add custom log formatting and prefix control to KubernetesPodOperator - Introduce parameter to toggle container name prefix in logs - Add parameter for custom log message formatting - Update PodManager to support log_prefix and log_formatter in log fetching * Add tests for log prefix and custom formatter in KubernetesPodOperator - Add test_log_prefix_enabled to verify default log_prefix=True behavior - Add test_log_prefix_disabled to confirm log_prefix=False removes container prefix - Add test_custom_log_formatter to validate custom log_formatter functionality * Enhance KubernetesPodOperator logging with flexible prefix and formatter options Consolidated log prefix and formatter tests into a single parameterized test_log_output_configurations, covering: log_prefix=True: Includes container name prefix ([base]). log_prefix=False: Excludes container name prefix. Custom log formatter: Applies user-defined formatting (e.g., CUSTOM[base]: message) * Remove @pytest.mark.asyncio Co-authored-by: LIU ZHE YOU <68415893+jason810496@users.noreply.github.com> * Modify test_log_output_configurations to improve log message capturing: - Replace caplog with targeted mocking of PodManager logger * Add custom log formatting support to KubernetesPodOperator tests * feat(kubernetes): Add log formatting options and refactor log handling in KubernetesPodOperator - Rename log_prefix to container_name_log_prefix_enabled parameter to control container name prefix in logs - Extract duplicate log formatting logic into _log_message private method in PodManager - Update docstrings with detailed parameter descriptions --------- Co-authored-by: LIU ZHE YOU <68415893+jason810496@users.noreply.github.com>
Description
Addresses the issue where KubernetesPodOperator (KPO) logs always include a container name prefix, which can consume unnecessary horizontal space and feel redundant. This PR introduces two new optional parameters to
KubernetesPodOperator:log_prefix: A boolean to enable/disable the container name prefix in logs (default: True).log_formatter: A callable to fully customize log output format, overriding log_prefix if provided.This allows users to either disable the prefix or define a custom log format, improving log readability and flexibility.
Changes
log_prefix: bool = Trueandlog_formatter: Callable[[str, str], str] | None = NonetoKubernetesPodOperatorconstructor.PodManagermethods (fetch_container_logs,fetch_requested_init_container_logs,fetch_requested_container_logs) to accept and use these new parameters.PodManager.fetch_container_logsto:log_formatterif provided.log_prefixto include/exclude container name prefix whenlog_formatteris not set.log_prefix=True.log_prefix=False(no container name prefix).log_formatter.Related Issue
#53054
^ Add meaningful description above
Read the Pull Request Guidelines for more information.
In case of fundamental code changes, an Airflow Improvement Proposal (AIP) is needed.
In case of a new dependency, check compliance with the ASF 3rd Party License Policy.
In case of backwards incompatible changes please leave a note in a newsfragment file, named
{pr_number}.significant.rstor{issue_number}.significant.rst, in airflow-core/newsfragments.