Class: StatsD::Instrument::Expectation
- Inherits:
-
Object
- Object
- StatsD::Instrument::Expectation
- Defined in:
- lib/statsd/instrument/expectation.rb
Instance Attribute Summary collapse
-
#ignore_tags ⇒ Object
readonly
Returns the value of attribute ignore_tags.
-
#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, **options) ⇒ Object
- .gauge(name, **options) ⇒ Object
- .histogram(name, **options) ⇒ Object
- .increment(name, **options) ⇒ Object
- .key_value(name, **options) ⇒ Object
- .measure(name, **options) ⇒ Object
- .set(name, **options) ⇒ Object
Instance Method Summary collapse
-
#initialize(type:, name:, value: nil, sample_rate: nil, tags: nil, ignore_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(type:, name:, value: nil, sample_rate: nil, tags: nil, ignore_tags: nil, no_prefix: false, times: 1) ⇒ Expectation
Returns a new instance of Expectation.
38 39 40 41 42 43 44 45 46 |
# File 'lib/statsd/instrument/expectation.rb', line 38 def initialize(type:, name:, value: nil, sample_rate: nil, tags: nil, ignore_tags: nil, no_prefix: false, times: 1) @type = type @name = StatsD.prefix ? "#{StatsD.prefix}.#{name}" : name unless no_prefix @value = normalized_value_for_type(type, value) if value @sample_rate = sample_rate @tags = StatsD::Instrument::Metric.() @ignore_tags = StatsD::Instrument::Metric.() @times = times end |
Instance Attribute Details
#ignore_tags ⇒ Object (readonly)
Returns the value of attribute ignore_tags.
36 37 38 |
# File 'lib/statsd/instrument/expectation.rb', line 36 def @ignore_tags end |
#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, **options) ⇒ Object
26 27 28 |
# File 'lib/statsd/instrument/expectation.rb', line 26 def distribution(name, **) new(type: :d, name: name, **) end |
.gauge(name, **options) ⇒ Object
14 15 16 |
# File 'lib/statsd/instrument/expectation.rb', line 14 def gauge(name, **) new(type: :g, name: name, **) end |
.histogram(name, **options) ⇒ Object
30 31 32 |
# File 'lib/statsd/instrument/expectation.rb', line 30 def histogram(name, **) new(type: :h, name: name, **) end |
.increment(name, **options) ⇒ Object
6 7 8 |
# File 'lib/statsd/instrument/expectation.rb', line 6 def increment(name, **) new(type: :c, name: name, **) end |
.key_value(name, **options) ⇒ Object
22 23 24 |
# File 'lib/statsd/instrument/expectation.rb', line 22 def key_value(name, **) new(type: :kv, name: name, **) end |
.measure(name, **options) ⇒ Object
10 11 12 |
# File 'lib/statsd/instrument/expectation.rb', line 10 def measure(name, **) new(type: :ms, name: name, **) end |
.set(name, **options) ⇒ Object
18 19 20 |
# File 'lib/statsd/instrument/expectation.rb', line 18 def set(name, **) new(type: :s, name: name, **) end |
Instance Method Details
#inspect ⇒ Object
87 88 89 |
# File 'lib/statsd/instrument/expectation.rb', line 87 def inspect "#<StatsD::Instrument::Expectation:\"#{self}\">" end |
#matches(actual_metric) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/statsd/instrument/expectation.rb', line 57 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.) if = Set.new() - -= if .is_a?(Array) .delete_if { |key| .include?(key.split(":").first) } end end return .subset?() end true end |
#normalized_value_for_type(type, value) ⇒ Object
48 49 50 51 52 53 54 55 |
# File 'lib/statsd/instrument/expectation.rb', line 48 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
79 80 81 82 83 84 85 |
# File 'lib/statsd/instrument/expectation.rb', line 79 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 |