Skip to content
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

logp: add rate limited logger #256

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

mauri870
Copy link
Member

What does this PR do?

This commit adds support for rate limiting to logp.Logger. This is useful
when you have a lot of log messages and you want to avoid flooding the
destination.

The logger was augmented with the following methods:
Throttled will only log once every period.
Sampled will only log the nth message.
Limited will only log the first n messages.

The implementation is based on x/time/rate.Sometimes.

For all these limiters any message that is not logged will be dropped.

These also synergize with one another, for example:

log.Sampled(10).
    Throttled(time.Second).
    Info("")`

will log one message every second, and only one out of ten messages.

Likewise,

log.Limited(10).
    Throttled(time.Second).
    Info("")

will log the first ten messages, and then one message every second.

Why is it important?

Checklist

  • My code follows the style guidelines of this project
  • I have commented my code, particularly in hard-to-understand areas
  • I have added tests that prove my fix is effective or that my feature works

Author's Checklist

  • [ ]

Related issues

This commit adds support for rate limiting to logp.Logger. This is useful
when you have a lot of log messages and you want to avoid flooding the
destination.

The logger was augmented with the following methods:
    `Throttled` will only log once every period.
    `Sampled` will only log the nth message.
    `Limited` will only log the first n messages.

The implementation is based on x/time/rate.Sometimes.

For all these limiters any message that is not logged will be dropped.

These also synergize with one another, for example:

    log.Sampled(10).
        Throttled(time.Second).
        Info("")`

will log one message every second, and only one out of ten messages.

Likewise,

    log.Limited(10).
        Throttled(time.Second).
        Info("")

will log the first ten messages, and then one message every second.
@mauri870 mauri870 added the enhancement New feature or request label Nov 29, 2024
@mauri870 mauri870 self-assigned this Nov 29, 2024
@mauri870 mauri870 marked this pull request as ready for review November 29, 2024 16:10
@mauri870 mauri870 requested a review from a team as a code owner November 29, 2024 16:10
@mauri870 mauri870 requested review from faec and VihasMakwana and removed request for a team November 29, 2024 16:10
@pierrehilbert pierrehilbert added the Team:Elastic-Agent-Data-Plane Label for the Agent Data Plane team label Nov 29, 2024
@mauri870 mauri870 marked this pull request as draft December 4, 2024 11:08
@elasticmachine
Copy link
Collaborator

💚 Build Succeeded

History

cc @mauri870

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request Team:Elastic-Agent-Data-Plane Label for the Agent Data Plane team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants