class StatsD::Instrument::Expectation
@private
Attributes
name[RW]
sample_rate[RW]
times[RW]
type[RW]
value[RW]
Public Class Methods
distribution(name, value = nil, **options)
click to toggle source
# File lib/statsd/instrument/expectation.rb, line 24 def distribution(name, value = nil, **options) new(type: :d, name: name, value: value, **options) end
gauge(name, value = nil, **options)
click to toggle source
# File lib/statsd/instrument/expectation.rb, line 16 def gauge(name, value = nil, **options) new(type: :g, name: name, value: value, **options) end
histogram(name, value = nil, **options)
click to toggle source
# File lib/statsd/instrument/expectation.rb, line 28 def histogram(name, value = nil, **options) new(type: :h, name: name, value: value, **options) end
increment(name, value = nil, **options)
click to toggle source
# File lib/statsd/instrument/expectation.rb, line 8 def increment(name, value = nil, **options) new(type: :c, name: name, value: value, **options) end
measure(name, value = nil, **options)
click to toggle source
# File lib/statsd/instrument/expectation.rb, line 12 def measure(name, value = nil, **options) new(type: :ms, name: name, value: value, **options) end
new(client: nil, type:, name:, value: nil, sample_rate: nil, tags: nil, no_prefix: false, times: 1)
click to toggle source
# File lib/statsd/instrument/expectation.rb, line 35 def initialize(client: nil, type:, name:, value: nil, sample_rate: nil, tags: nil, no_prefix: false, times: 1) client ||= StatsD.singleton_client @type = type @name = no_prefix || !client.prefix ? name : "#{client.prefix}.#{name}" @value = normalized_value_for_type(type, value) if value @sample_rate = sample_rate @tags = normalize_tags(tags) @times = times end
set(name, value = nil, **options)
click to toggle source
# File lib/statsd/instrument/expectation.rb, line 20 def set(name, value = nil, **options) new(type: :s, name: name, value: value, **options) end
Public Instance Methods
inspect()
click to toggle source
# File lib/statsd/instrument/expectation.rb, line 76 def inspect "#<StatsD::Instrument::Expectation:\"#{self}\">" end
matches(actual_metric)
click to toggle source
# File lib/statsd/instrument/expectation.rb, line 56 def matches(actual_metric) return false if sample_rate && sample_rate != actual_metric.sample_rate return false if value && value != normalized_value_for_type(actual_metric.type, actual_metric.value) if tags expected_tags = Set.new(tags) actual_tags = Set.new(actual_metric.tags) return expected_tags.subset?(actual_tags) end true end
normalized_value_for_type(type, value)
click to toggle source
# File lib/statsd/instrument/expectation.rb, line 47 def normalized_value_for_type(type, value) case type when :c then Integer(value) when :g, :h, :d, :kv, :ms then Float(value) when :s then String(value) else value end end
to_s()
click to toggle source
# File lib/statsd/instrument/expectation.rb, line 68 def to_s str = +"#{name}:#{value || "<anything>"}|#{type}" str << "|@#{sample_rate}" if sample_rate str << "|#" << tags.join(",") if tags str << " (expected #{times} times)" if times > 1 str end