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

[7.17](backport #42966) fix(libbeat): mitigate race condition in ratelimit processor #43117

Open
wants to merge 1 commit into
base: 7.17
Choose a base branch
from

Conversation

mergify[bot]
Copy link
Contributor

@mergify mergify bot commented Mar 7, 2025

Proposed commit message

This PR fixes race conditions on the ratelimit processor. The race conditions can only manifest with configurations that have a global ratelimit processor and multiple inputs. Fixed by adding a mutex to the bucket struct.

During benchmarking, I also noticed an unnecessary allocation occurring in the hot path. Removing this allocation resulted in a 25% performance improvement. While locks have an inherent cost, in this scenario, the performance gain offsets that cost.

Checklist

  • My code follows the style guidelines of this project
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have made corresponding change to the default configuration files
  • I have added tests that prove my fix is effective or that my feature works
  • I have added an entry in CHANGELOG.next.asciidoc or CHANGELOG-developer.next.asciidoc.

How to test this PR locally

Run filebeat with a global ratelimit processor under the race detector:

$ cd x-pack/filebeat; go build -race .
$ GORACE="halt_on_error=1" ./filebeat -c ratelimit.yml -d '*' -v -e
filebeat:
  inputs:
    - type: benchmark
      enabled: true
      message: "bench1"
      eps: 100
    - type: benchmark
      enabled: true
      message: "bench2"
      eps: 100
    - type: benchmark
      enabled: true
      message: "bench3"
      eps: 100
    - type: benchmark
      enabled: true
      message: "bench4"
      eps: 100
processors:
- rate_limit:
   limit: "1/s"
output.console:
  pretty: true
logging:
  level: debug
  selectors:
    - "*"
path.home: /tmp/filebeat

This is an automatic backport of pull request #42966 done by [Mergify](https://mergify.com).

* fix(libbeat): mitigate race condition in ratelimit processor

* use right changelog file

* remove allocation on the hot path

* use past tense in changelog entry

* add test for allocs

(cherry picked from commit acce29c)

# Conflicts:
#	libbeat/processors/ratelimit/token_bucket.go
@mergify mergify bot requested a review from a team as a code owner March 7, 2025 15:45
@mergify mergify bot added backport conflicts There is a conflict in the backported pull request labels Mar 7, 2025
@mergify mergify bot requested review from faec and khushijain21 and removed request for a team March 7, 2025 15:45
Copy link
Contributor Author

mergify bot commented Mar 7, 2025

Cherry-pick of acce29c has failed:

On branch mergify/bp/7.17/pr-42966
Your branch is up to date with 'origin/7.17'.

You are currently cherry-picking commit acce29cf2.
  (fix conflicts and run "git cherry-pick --continue")
  (use "git cherry-pick --skip" to skip this patch)
  (use "git cherry-pick --abort" to cancel the cherry-pick operation)

Changes to be committed:
	modified:   CHANGELOG.next.asciidoc
	modified:   libbeat/processors/ratelimit/rate_limit_test.go

Unmerged paths:
  (use "git add <file>..." to mark resolution)
	both modified:   libbeat/processors/ratelimit/token_bucket.go

To fix up this pull request, you can check it out locally. See documentation: https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/reviewing-changes-in-pull-requests/checking-out-pull-requests-locally

@botelastic botelastic bot added the needs_team Indicates that the issue/PR needs a Team:* label label Mar 7, 2025
@botelastic
Copy link

botelastic bot commented Mar 7, 2025

This pull request doesn't have a Team:<team> label.

@@ -15,6 +15,47 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha2...master[Check the HEAD d

*Filebeat*

- Convert netflow input to API v2 and disable event normalisation {pull}37901[37901]
Copy link
Contributor

Choose a reason for hiding this comment

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

broken changelog merge should be fixed (along with the explicit broken merges below)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport conflicts There is a conflict in the backported pull request needs_team Indicates that the issue/PR needs a Team:* label
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants