Class: Datadog::DI::CorrelationSampler::TraceBudget Private
- Inherits:
-
Object
- Object
- Datadog::DI::CorrelationSampler::TraceBudget
- Defined in:
- lib/datadog/di/correlation_sampler/trace_budget.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Per-trace emission counters: an all counter shared by every probe,
and a per-probe counter that starts at per_probe_budget for each
distinct probe.
Instance Attribute Summary collapse
-
#all_remaining ⇒ Integer
readonly
private
Remaining all-probe counter.
-
#per_probe ⇒ Hash[String, Integer]
readonly
private
Remaining per-probe counters, keyed by probe id.
-
#per_probe_budget ⇒ Integer
readonly
private
Per-probe counter start value this budget was constructed with.
Class Method Summary collapse
-
.validate_budgets!(per_probe_budget:, all_budget:) ⇒ void
private
Validates the budget arguments, raising ArgumentError when either is negative or non-Integer.
Instance Method Summary collapse
-
#admit(probe_id) ⇒ Boolean
private
Consumes one per-probe and one all token for
probe_id. -
#initialize(per_probe_budget:, all_budget:) ⇒ void
constructor
private
Initializes the all-probe counter to
all_budgetwith each probe's counter starting atper_probe_budget.
Constructor Details
#initialize(per_probe_budget:, all_budget:) ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Initializes the all-probe counter to all_budget with each probe's
counter starting at per_probe_budget.
36 37 38 39 40 41 42 |
# File 'lib/datadog/di/correlation_sampler/trace_budget.rb', line 36 def initialize(per_probe_budget:, all_budget:) TraceBudget.validate_budgets!(per_probe_budget: per_probe_budget, all_budget: all_budget) @all_remaining = all_budget @per_probe_budget = per_probe_budget @per_probe = {} end |
Instance Attribute Details
#all_remaining ⇒ Integer (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Remaining all-probe counter.
47 48 49 |
# File 'lib/datadog/di/correlation_sampler/trace_budget.rb', line 47 def all_remaining @all_remaining end |
#per_probe ⇒ Hash[String, Integer] (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Remaining per-probe counters, keyed by probe id.
57 58 59 |
# File 'lib/datadog/di/correlation_sampler/trace_budget.rb', line 57 def per_probe @per_probe end |
#per_probe_budget ⇒ Integer (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Per-probe counter start value this budget was constructed with.
52 53 54 |
# File 'lib/datadog/di/correlation_sampler/trace_budget.rb', line 52 def per_probe_budget @per_probe_budget end |
Class Method Details
.validate_budgets!(per_probe_budget:, all_budget:) ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Validates the budget arguments, raising ArgumentError when either is negative or non-Integer.
18 19 20 21 22 23 24 25 26 |
# File 'lib/datadog/di/correlation_sampler/trace_budget.rb', line 18 def self.validate_budgets!(per_probe_budget:, all_budget:) unless per_probe_budget.is_a?(Integer) && per_probe_budget >= 0 raise ArgumentError, "per_probe_budget must be a non-negative Integer: #{per_probe_budget}" end unless all_budget.is_a?(Integer) && all_budget >= 0 raise ArgumentError, "all_budget must be a non-negative Integer: #{all_budget}" end nil end |
Instance Method Details
#admit(probe_id) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Consumes one per-probe and one all token for probe_id.
64 65 66 67 68 69 70 71 |
# File 'lib/datadog/di/correlation_sampler/trace_budget.rb', line 64 def admit(probe_id) remaining = per_probe.fetch(probe_id, per_probe_budget) return false if remaining <= 0 || all_remaining <= 0 per_probe[probe_id] = remaining - 1 @all_remaining = all_remaining - 1 true end |