Add customizable log prefix and formatter to KubernetesPodOperator#53598
Merged
jason810496 merged 7 commits intoapache:mainfrom Aug 24, 2025
Merged
Add customizable log prefix and formatter to KubernetesPodOperator#53598jason810496 merged 7 commits intoapache:mainfrom
jason810496 merged 7 commits intoapache:mainfrom
Conversation
db9524f to
3d0d615
Compare
jason810496
reviewed
Jul 21, 2025
Member
jason810496
left a comment
There was a problem hiding this comment.
Thanks for the PR! LGTM overall but the unit still needs fix.
3d0d615 to
af7174e
Compare
jason810496
approved these changes
Jul 27, 2025
Member
jason810496
left a comment
There was a problem hiding this comment.
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!
4d639e0 to
0ce8fd1
Compare
jason810496
reviewed
Jul 28, 2025
0ce8fd1 to
7eee299
Compare
17ebc2e to
4ea3f09
Compare
jason810496
approved these changes
Jul 30, 2025
Contributor
|
@HsiuChuanHsu I think this is ready to merge |
Contributor
Author
|
@NilsJPWerner Yes, this PR is nearly complete, but I don't have the right to merge the code. Still wait for approval to merge. |
jason810496
reviewed
Aug 17, 2025
- 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
Contributor
Author
|
Thanks for the review!! 🤩 |
mangal-vairalkar
pushed a commit
to mangal-vairalkar/airflow
that referenced
this pull request
Aug 30, 2025
…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>
nothingmin
pushed a commit
to nothingmin/airflow
that referenced
this pull request
Sep 2, 2025
…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>
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
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.