Skip to content

Introduce a helper to reduce logs in frequently invoked codepaths. - #34977

Closed
tvalentyn wants to merge 7 commits into
apache:masterfrom
tvalentyn:less_logs
Closed

Introduce a helper to reduce logs in frequently invoked codepaths.#34977
tvalentyn wants to merge 7 commits into
apache:masterfrom
tvalentyn:less_logs

Conversation

@tvalentyn

@tvalentyn tvalentyn commented May 16, 2025

Copy link
Copy Markdown
Contributor

We have several places in Python SDK where a certain log entry is emitted multiple times, when a single warning would be sufficient. This is causing excessive noise, particularly visible during job submission, when INFO logs are enabled.

We also have codepaths where we may want to log a particular message, but not more often than once per x minutes. Every time that happens, we add the same logic counting time, for example:

if self._large_flush_last_observed_timestamp + 600 < time.time():

I suggest to introduce a helper that can streamline this functionality at the cost storing identifiers of a log entry in memory, such as a position in the codebase where the log is emitted, or some identifier to dedup or group similar messages.

For example, a caller can use an ID to print a GCS bucket configuration note only once per bucket, using bucket name as an ID.


Thank you for your contribution! Follow this checklist to help us incorporate your contribution quickly and easily:

  • Mention the appropriate issue in your description (for example: addresses #123), if applicable. This will automatically add a link to the pull request in the issue. If you would like the issue to automatically close on merging the pull request, comment fixes #<ISSUE NUMBER> instead.
  • Update CHANGES.md with noteworthy changes.
  • If this contribution is large, please file an Apache Individual Contributor License Agreement.

See the Contributor Guide for more tips on how to make review process smoother.

To check the build health, please visit https://github.com/apache/beam/blob/master/.test-infra/BUILD_STATUS.md

GitHub Actions Tests Status (on master branch)

Build python source distribution and wheels
Python tests
Java tests
Go tests

See CI.md for more information about GitHub Actions CI or the workflows README to see a list of phrases to trigger workflows.

@codecov

codecov Bot commented May 16, 2025

Copy link
Copy Markdown

Codecov Report

Attention: Patch coverage is 96.87500% with 1 line in your changes missing coverage. Please review.

Project coverage is 54.51%. Comparing base (5f9cd73) to head (3fbe327).
Report is 3 commits behind head on master.

Files with missing lines Patch % Lines
...dks/python/apache_beam/options/pipeline_options.py 90.90% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff            @@
##             master   #34977   +/-   ##
=========================================
  Coverage     54.50%   54.51%           
  Complexity     1479     1479           
=========================================
  Files          1012     1013    +1     
  Lines        160667   160691   +24     
  Branches       1079     1079           
=========================================
+ Hits          87577    87603   +26     
+ Misses        70990    70988    -2     
  Partials       2100     2100           
Flag Coverage Δ
python 81.00% <96.87%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@Abacn

Abacn commented May 16, 2025

Copy link
Copy Markdown
Contributor

+1 this is a useful helper. Always wondering there is a Python implementation of absl's LOG_EVERY_N_SEC

@github-actions

Copy link
Copy Markdown
Contributor

Assigning reviewers:

R: @claudevdm for label python.

Note: If you would like to opt out of this review, comment assign to next reviewer.

Available commands:

  • stop reviewer notifications - opt out of the automated review tooling
  • remind me after tests pass - tag the comment author after tests pass
  • waiting on author - shift the attention set back to the author (any comment or push by the author will return the attention set to the reviewers)

The PR bot will only process comments in the main thread (not review comments).

@tvalentyn
tvalentyn force-pushed the less_logs branch 2 times, most recently from f6384e1 to 995e489 Compare May 17, 2025 01:06
@tvalentyn

Copy link
Copy Markdown
Contributor Author

Always wondering there is a Python implementation of absl's LOG_EVERY_N_SEC

Looks like there is:
https://github.com/abseil/abseil-py/blob/369ce9badbda914b7d3b975b7272e1194b419213/absl/logging/__init__.py#L494

Looks interesting, i wonder if we can use absl.logging instead without causing some unintentional consequences. It already has all these helpers.

@tvalentyn
tvalentyn marked this pull request as draft May 17, 2025 03:16
@tvalentyn

tvalentyn commented May 19, 2025

Copy link
Copy Markdown
Contributor Author

Looks interesting, i wonder if we can use absl.logging instead without causing some unintentional consequences. It already has all these helpers.

Took a look. I think the main issue is we adopted hierarchical logging with named loggers to allow for per-file logging levels. Absl uses a different method of per-file logging that would require code and documentation changes to adopt, so seems like not a drop-in replacement.

absl-py apis look better, I'll try to TAL if we can have something similar.

@tvalentyn

Copy link
Copy Markdown
Contributor Author

Found an implementation accomplishes what i'd like to have, will need to polish the change a bit.

@github-actions

Copy link
Copy Markdown
Contributor

Reminder, please take a look at this pr: @claudevdm

@tvalentyn

Copy link
Copy Markdown
Contributor Author

waiting on author

@github-actions

Copy link
Copy Markdown
Contributor

Assigning new set of reviewers because Pr has gone too long without review. If you would like to opt out of this review, comment assign to next reviewer:

R: @jrmccluskey for label python.

Available commands:

  • stop reviewer notifications - opt out of the automated review tooling
  • remind me after tests pass - tag the comment author after tests pass
  • waiting on author - shift the attention set back to the author (any comment or push by the author will return the attention set to the reviewers)

@github-actions

Copy link
Copy Markdown
Contributor

This pull request has been marked as stale due to 60 days of inactivity. It will be closed in 1 week if no further activity occurs. If you think that’s incorrect or this pull request requires a review, please simply write any comment. If closed, you can revive the PR at any time and @mention a reviewer or discuss it on the dev@beam.apache.org list. Thank you for your contributions.

@github-actions github-actions Bot added the stale label Jul 29, 2025
@github-actions

github-actions Bot commented Aug 5, 2025

Copy link
Copy Markdown
Contributor

This pull request has been closed due to lack of activity. If you think that is incorrect, or the pull request requires review, you can revive the PR at any time.

@github-actions github-actions Bot closed this Aug 5, 2025
@tvalentyn

tvalentyn commented Oct 10, 2025

Copy link
Copy Markdown
Contributor Author

followup: #36432 and #36585

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants