Class: StatsD::Instrument::MetricExpectation
- Inherits:
-
Object
- Object
- StatsD::Instrument::MetricExpectation
- Defined in:
- lib/statsd/instrument/metric_expectation.rb
Constant Summary collapse
- TYPES =
{ c: 'increment', ms: 'measure', g: 'gauge', h: 'histogram', d: 'distribution', kv: 'key/value', s: 'set', }
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.
Instance Method Summary collapse
- #default_value ⇒ Object
-
#initialize(options = {}) ⇒ MetricExpectation
constructor
A new instance of MetricExpectation.
- #inspect ⇒ Object
- #matches(actual_metric) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ MetricExpectation
Returns a new instance of MetricExpectation.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/statsd/instrument/metric_expectation.rb', line 8 def initialize( = {}) if [:type] @type = [:type] else raise ArgumentError, "Metric :type is required." end if [:name] @name = [:name] else raise ArgumentError, "Metric :name is required." end if [:times] @times = [:times] else raise ArgumentError, "Metric :times is required." end @name = StatsD.prefix ? "#{StatsD.prefix}.#{@name}" : @name unless [:no_prefix] @tags = StatsD::Instrument::Metric.([:tags]) @sample_rate = [:sample_rate] @value = [:value] @ignore_tags = StatsD::Instrument::Metric.([:ignore_tags]) end |
Instance Attribute Details
#ignore_tags ⇒ Object (readonly)
Returns the value of attribute ignore_tags.
6 7 8 |
# File 'lib/statsd/instrument/metric_expectation.rb', line 6 def @ignore_tags end |
#name ⇒ Object
Returns the value of attribute name.
5 6 7 |
# File 'lib/statsd/instrument/metric_expectation.rb', line 5 def name @name end |
#sample_rate ⇒ Object
Returns the value of attribute sample_rate.
5 6 7 |
# File 'lib/statsd/instrument/metric_expectation.rb', line 5 def sample_rate @sample_rate end |
#tags ⇒ Object
Returns the value of attribute tags.
5 6 7 |
# File 'lib/statsd/instrument/metric_expectation.rb', line 5 def @tags end |
#times ⇒ Object
Returns the value of attribute times.
5 6 7 |
# File 'lib/statsd/instrument/metric_expectation.rb', line 5 def times @times end |
#type ⇒ Object
Returns the value of attribute type.
5 6 7 |
# File 'lib/statsd/instrument/metric_expectation.rb', line 5 def type @type end |
#value ⇒ Object
Returns the value of attribute value.
5 6 7 |
# File 'lib/statsd/instrument/metric_expectation.rb', line 5 def value @value end |
Instance Method Details
#default_value ⇒ Object
57 58 59 |
# File 'lib/statsd/instrument/metric_expectation.rb', line 57 def default_value 1 if type == :c end |
#inspect ⇒ Object
79 80 81 |
# File 'lib/statsd/instrument/metric_expectation.rb', line 79 def inspect "#<StatsD::Instrument::MetricExpectation #{self}>" end |
#matches(actual_metric) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/statsd/instrument/metric_expectation.rb', line 34 def matches(actual_metric) return false if sample_rate && sample_rate != actual_metric.sample_rate return false if value && value != 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 |
#to_s ⇒ Object
71 72 73 74 75 76 77 |
# File 'lib/statsd/instrument/metric_expectation.rb', line 71 def to_s str = +"#{TYPES[type]} #{name}:#{value}" str << " @#{sample_rate}" if sample_rate != 1.0 str << " " << .map { |t| "##{t}" }.join(' ') if str << " times:#{times}" if times > 1 str end |