Skip to content

Commit

Permalink
Set default RuleSampler rate_limit of 100 (#898)
Browse files Browse the repository at this point in the history
* Set default RuleSampler rate_limit of 100

* use constant for default rate limit
  • Loading branch information
brettlangdon authored Jan 2, 2020
1 parent bead229 commit 53bf0e4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
6 changes: 4 additions & 2 deletions lib/ddtrace/sampling/rule_sampler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,16 @@ class RuleSampler

attr_reader :rules, :rate_limiter, :default_sampler

DEFAULT_RATE_LIMIT = 100

# @param rules [Array<Rule>] ordered list of rules to be applied to a span
# @param rate_limit [Float] number of traces per second, defaults to no rate limit
# @param rate_limit [Float] number of traces per second, defaults to +100+
# @param rate_limiter [RateLimiter] limiter applied after rule matching
# @param default_sample_rate [Float] fallback sample rate when no rules apply to a span,
# between +[0,1]+, defaults to +1+
# @param default_sampler [Sample] fallback strategy when no rules apply to a span
def initialize(rules = [],
rate_limit: nil,
rate_limit: DEFAULT_RATE_LIMIT,
rate_limiter: nil,
default_sample_rate: nil,
default_sampler: nil)
Expand Down
8 changes: 7 additions & 1 deletion spec/ddtrace/sampling/rule_sampler_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
context '#initialize' do
subject(:rule_sampler) { described_class.new(rules) }

it { expect(subject.rate_limiter).to be_a(Datadog::Sampling::UnlimitedLimiter) }
it { expect(subject.rate_limiter).to be_a(Datadog::Sampling::TokenBucket) }
it { expect(subject.default_sampler).to be_a(Datadog::AllSampler) }

context 'with rate_limit' do
Expand All @@ -32,6 +32,12 @@
it { expect(subject.rate_limiter).to be_a(Datadog::Sampling::TokenBucket) }
end

context 'with nil rate_limit' do
subject(:rule_sampler) { described_class.new(rules, rate_limit: nil) }

it { expect(subject.rate_limiter).to be_a(Datadog::Sampling::UnlimitedLimiter) }
end

context 'with default_sample_rate' do
subject(:rule_sampler) { described_class.new(rules, default_sample_rate: 1.0) }

Expand Down

0 comments on commit 53bf0e4

Please sign in to comment.