Class: StatsD::Instrument::Expectation
- Inherits:
-
Object
- Object
- StatsD::Instrument::Expectation
- Defined in:
- lib/statsd/instrument/expectation.rb
Defined Under Namespace
Modules: RubyBackports
Instance Attribute Summary collapse
-
#name ⇒ Object
Returns the value of attribute name.
-
#sample_rate ⇒ Object
Returns the value of attribute sample_rate.
-
#tags ⇒ Object
Returns the value of attribute tags.
-
#times ⇒ Object
Returns the value of attribute times.
-
#type ⇒ Object
Returns the value of attribute type.
-
#value ⇒ Object
Returns the value of attribute value.
Class Method Summary collapse
- .distribution(name, value = nil, **options) ⇒ Object
- .gauge(name, value = nil, **options) ⇒ Object
- .histogram(name, value = nil, **options) ⇒ Object
- .increment(name, value = nil, **options) ⇒ Object
- .measure(name, value = nil, **options) ⇒ Object
- .set(name, value = nil, **options) ⇒ Object
Instance Method Summary collapse
-
#initialize(client: StatsD.singleton_client, type:, name:, value: nil, sample_rate: nil, tags: nil, no_prefix: false, times: 1) ⇒ Expectation
constructor
A new instance of Expectation.
- #inspect ⇒ Object
- #matches(actual_metric) ⇒ Object
- #normalized_value_for_type(type, value) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(client: StatsD.singleton_client, type:, name:, value: nil, sample_rate: nil, tags: nil, no_prefix: false, times: 1) ⇒ Expectation
Returns a new instance of Expectation.
35 36 37 38 39 40 41 42 43 44 |
# File 'lib/statsd/instrument/expectation.rb', line 35 def initialize(client: StatsD.singleton_client, type:, name:, value: nil, sample_rate: nil, tags: nil, no_prefix: false, times: 1) @type = type @name = no_prefix || !client.prefix ? name : "#{client.prefix}.#{name}" @value = normalized_value_for_type(type, value) if value @sample_rate = sample_rate = () @times = times end |
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
33 34 35 |
# File 'lib/statsd/instrument/expectation.rb', line 33 def name @name end |
#sample_rate ⇒ Object
Returns the value of attribute sample_rate.
33 34 35 |
# File 'lib/statsd/instrument/expectation.rb', line 33 def sample_rate @sample_rate end |
#tags ⇒ Object
Returns the value of attribute tags.
33 34 35 |
# File 'lib/statsd/instrument/expectation.rb', line 33 def end |
#times ⇒ Object
Returns the value of attribute times.
33 34 35 |
# File 'lib/statsd/instrument/expectation.rb', line 33 def times @times end |
#type ⇒ Object
Returns the value of attribute type.
33 34 35 |
# File 'lib/statsd/instrument/expectation.rb', line 33 def type @type end |
#value ⇒ Object
Returns the value of attribute value.
33 34 35 |
# File 'lib/statsd/instrument/expectation.rb', line 33 def value @value end |
Class Method Details
.distribution(name, value = nil, **options) ⇒ Object
24 25 26 |
# File 'lib/statsd/instrument/expectation.rb', line 24 def distribution(name, value = nil, **) new(type: :d, name: name, value: value, **) end |
.gauge(name, value = nil, **options) ⇒ Object
16 17 18 |
# File 'lib/statsd/instrument/expectation.rb', line 16 def gauge(name, value = nil, **) new(type: :g, name: name, value: value, **) end |
.histogram(name, value = nil, **options) ⇒ Object
28 29 30 |
# File 'lib/statsd/instrument/expectation.rb', line 28 def histogram(name, value = nil, **) new(type: :h, name: name, value: value, **) end |
.increment(name, value = nil, **options) ⇒ Object
8 9 10 |
# File 'lib/statsd/instrument/expectation.rb', line 8 def increment(name, value = nil, **) new(type: :c, name: name, value: value, **) end |
.measure(name, value = nil, **options) ⇒ Object
12 13 14 |
# File 'lib/statsd/instrument/expectation.rb', line 12 def measure(name, value = nil, **) new(type: :ms, name: name, value: value, **) end |
.set(name, value = nil, **options) ⇒ Object
20 21 22 |
# File 'lib/statsd/instrument/expectation.rb', line 20 def set(name, value = nil, **) new(type: :s, name: name, value: value, **) end |
Instance Method Details
#inspect ⇒ Object
75 76 77 |
# File 'lib/statsd/instrument/expectation.rb', line 75 def inspect "#<StatsD::Instrument::Expectation:\"#{self}\">" end |
#matches(actual_metric) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/statsd/instrument/expectation.rb', line 55 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 = Set.new() = Set.new(actual_metric.) return .subset?() end true end |
#normalized_value_for_type(type, value) ⇒ Object
46 47 48 49 50 51 52 53 |
# File 'lib/statsd/instrument/expectation.rb', line 46 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 ⇒ Object
67 68 69 70 71 72 73 |
# File 'lib/statsd/instrument/expectation.rb', line 67 def to_s str = +"#{name}:#{value || "<anything>"}|#{type}" str << "|@#{sample_rate}" if sample_rate str << "|#" << .join(",") if str << " (expected #{times} times)" if times > 1 str end |