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

[8.x](backport #42966) fix(libbeat): mitigate race condition in ratelimit processor #43116

Open
wants to merge 1 commit into
base: 8.x
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)
@mergify mergify bot requested a review from a team as a code owner March 7, 2025 15:45
@mergify mergify bot added the backport label Mar 7, 2025
@mergify mergify bot requested review from rdner and mauri870 and removed request for a team March 7, 2025 15:45
@botelastic botelastic bot added the needs_team Indicates that the issue/PR needs a Team:* label label Mar 7, 2025
@github-actions github-actions bot added Team:Elastic-Agent-Data-Plane Label for the Agent Data Plane team bugfix labels Mar 7, 2025
@botelastic botelastic bot removed the needs_team Indicates that the issue/PR needs a Team:* label label Mar 7, 2025
@elasticmachine
Copy link
Collaborator

Pinging @elastic/elastic-agent-data-plane (Team:Elastic-Agent-Data-Plane)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport bugfix 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.

2 participants