Class: StatsD::Instrument::Expectation
- Inherits:
-
Object
- Object
- StatsD::Instrument::Expectation
- Defined in:
- lib/statsd/instrument/expectation.rb
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: nil, 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: nil, type:, name:, value: nil, sample_rate: nil, tags: nil, no_prefix: false, times: 1) ⇒ Expectation
Returns a new instance of Expectation.
37 38 39 40 41 42 43 44 45 |
# File 'lib/statsd/instrument/expectation.rb', line 37 def initialize(client: nil, type:, name:, value: nil, sample_rate: nil, tags: nil, no_prefix: false, times: 1) @type = type @name = no_prefix ? name : StatsD::Instrument::Helpers.prefix_metric(name, client: client) @value = normalized_value_for_type(type, value) if value @sample_rate = sample_rate @tags = () @times = times end |
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
35 36 37 |
# File 'lib/statsd/instrument/expectation.rb', line 35 def name @name end |
#sample_rate ⇒ Object
Returns the value of attribute sample_rate.
35 36 37 |
# File 'lib/statsd/instrument/expectation.rb', line 35 def sample_rate @sample_rate end |
#tags ⇒ Object
Returns the value of attribute tags.
35 36 37 |
# File 'lib/statsd/instrument/expectation.rb', line 35 def @tags end |
#times ⇒ Object
Returns the value of attribute times.
35 36 37 |
# File 'lib/statsd/instrument/expectation.rb', line 35 def times @times end |
#type ⇒ Object
Returns the value of attribute type.
35 36 37 |
# File 'lib/statsd/instrument/expectation.rb', line 35 def type @type end |
#value ⇒ Object
Returns the value of attribute value.
35 36 37 |
# File 'lib/statsd/instrument/expectation.rb', line 35 def value @value end |
Class Method Details
.distribution(name, value = nil, **options) ⇒ Object
26 27 28 |
# File 'lib/statsd/instrument/expectation.rb', line 26 def distribution(name, value = nil, **) new(type: :d, name: name, value: value, **) end |
.gauge(name, value = nil, **options) ⇒ Object
18 19 20 |
# File 'lib/statsd/instrument/expectation.rb', line 18 def gauge(name, value = nil, **) new(type: :g, name: name, value: value, **) end |
.histogram(name, value = nil, **options) ⇒ Object
30 31 32 |
# File 'lib/statsd/instrument/expectation.rb', line 30 def histogram(name, value = nil, **) new(type: :h, name: name, value: value, **) end |
.increment(name, value = nil, **options) ⇒ Object
10 11 12 |
# File 'lib/statsd/instrument/expectation.rb', line 10 def increment(name, value = nil, **) new(type: :c, name: name, value: value, **) end |
.measure(name, value = nil, **options) ⇒ Object
14 15 16 |
# File 'lib/statsd/instrument/expectation.rb', line 14 def measure(name, value = nil, **) new(type: :ms, name: name, value: value, **) end |
.set(name, value = nil, **options) ⇒ Object
22 23 24 |
# File 'lib/statsd/instrument/expectation.rb', line 22 def set(name, value = nil, **) new(type: :s, name: name, value: value, **) end |
Instance Method Details
#inspect ⇒ Object
76 77 78 |
# File 'lib/statsd/instrument/expectation.rb', line 76 def inspect "#<StatsD::Instrument::Expectation:\"#{self}\">" end |
#matches(actual_metric) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 |
# 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 = Set.new() = Set.new(actual_metric.) return .subset?() end true end |
#normalized_value_for_type(type, value) ⇒ Object
47 48 49 50 51 52 53 54 |
# 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 ⇒ Object
68 69 70 71 72 73 74 |
# File 'lib/statsd/instrument/expectation.rb', line 68 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 |