Skip to content

Add logger helper functions from detectron2 (licensed as Apache 2.0) - #36432

Merged
tvalentyn merged 6 commits into
apache:masterfrom
tvalentyn:log_less
Oct 10, 2025
Merged

Add logger helper functions from detectron2 (licensed as Apache 2.0)#36432
tvalentyn merged 6 commits into
apache:masterfrom
tvalentyn:log_less

Conversation

@tvalentyn

@tvalentyn tvalentyn commented Oct 8, 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():

abesil/abseil-py has handy helper functions that can reduce the logging footprint, and these inspirations were adapted in some other opensource projects. The adaptation in detectron2 is sufficiently decoupled from absl and should be easy to integrate with our codebase.


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.

@github-actions github-actions Bot added the python label Oct 8, 2025
@tvalentyn
tvalentyn marked this pull request as ready for review October 10, 2025 17:51
@tvalentyn

Copy link
Copy Markdown
Contributor Author

R: @claudevdm

@github-actions

Copy link
Copy Markdown
Contributor

Stopping reviewer notifications for this pull request: review requested by someone other than the bot, ceding control. If you'd like to restart, comment assign set of reviewers

return "unknown", ("unknown", 0, "unknown")


_LOG_COUNTER = Counter()

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be protected by a lock?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same with access to _LOG_TIMER

@tvalentyn tvalentyn Oct 10, 2025

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's not necessary for the kind of modifications we have here (they won't cause a crash like one where you modify a dictionary while iterating it in another thread), and overheads of synchronization would likely outweigh the benefits. Indeed, there can be a race where log_every_n_seconds might emit a log twice but that should be fine.

@tvalentyn
tvalentyn merged commit 227a632 into apache:master Oct 10, 2025
110 of 118 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants