-
Notifications
You must be signed in to change notification settings - Fork 375
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace AppSec rate limiter with core rate limiter
This allows us to be more precise in throttling outgoing AppSec traces and removes additional custom logic of rate limiting.
- Loading branch information
Showing
3 changed files
with
65 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
require 'datadog/appsec/spec_helper' | ||
require 'datadog/appsec/rate_limiter' | ||
|
||
RSpec.describe Datadog::AppSec::RateLimiter do | ||
before { described_class.reset!(:traces) } | ||
|
||
describe '#limit' do | ||
context 'in different threads' do | ||
before do | ||
allow(described_class).to receive(:trace_rate_limit).and_return(rate_limit) | ||
end | ||
|
||
let(:rate_limit) { 50 } | ||
let(:spy_1) { spy('thread-1 workload') } | ||
let(:spy_2) { spy('thread-2 workload') } | ||
|
||
it 'creates separate rate limiter per thread' do | ||
thread_1 = Thread.new do | ||
Array.new(rate_limit * 2) do | ||
described_class.limit(:traces) { spy_1.call } | ||
end | ||
end | ||
|
||
thread_2 = Thread.new do | ||
Array.new(rate_limit * 2) do | ||
described_class.limit(:traces) { spy_2.call } | ||
end | ||
end | ||
|
||
thread_1.join | ||
thread_2.join | ||
|
||
expect(spy_1).to have_received(:call).exactly(rate_limit) | ||
expect(spy_2).to have_received(:call).exactly(rate_limit) | ||
end | ||
end | ||
end | ||
end |