Class: OneApm::MetricSpec
- Inherits:
-
Object
- Object
- OneApm::MetricSpec
- Defined in:
- lib/one_apm/metrics/metric_spec.rb
Constant Summary collapse
- OA_MAX_LENGTH =
the maximum length of a metric name or metric scope
255
- OA_LENGTH_RANGE =
(0...OA_MAX_LENGTH)
- OA_EMPTY_SCOPE =
''.freeze
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#scope ⇒ Object
readonly
Returns the value of attribute scope.
Instance Method Summary collapse
- #<=>(o) ⇒ Object
- #==(o) ⇒ Object
- #eql?(o) ⇒ Boolean
- #hash ⇒ Object
-
#initialize(metric_name = '', metric_scope = nil) ⇒ MetricSpec
constructor
A new instance of MetricSpec.
- #inspect ⇒ Object
-
#sub(pattern, replacement, apply_to_scope = true) ⇒ Object
return a new metric spec if the given regex matches the name or scope.
- #to_json(*a) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(metric_name = '', metric_scope = nil) ⇒ MetricSpec
Returns a new instance of MetricSpec.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/one_apm/metrics/metric_spec.rb', line 12 def initialize(metric_name='', metric_scope=nil) if metric_name.to_s.length > OA_MAX_LENGTH @name = metric_name.to_s[OA_LENGTH_RANGE] else @name = metric_name.to_s end if metric_scope if metric_scope.to_s.length > OA_MAX_LENGTH @scope = metric_scope.to_s[OA_LENGTH_RANGE] else @scope = metric_scope.to_s end else @scope = OA_EMPTY_SCOPE end end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
5 6 7 |
# File 'lib/one_apm/metrics/metric_spec.rb', line 5 def name @name end |
#scope ⇒ Object (readonly)
Returns the value of attribute scope.
5 6 7 |
# File 'lib/one_apm/metrics/metric_spec.rb', line 5 def scope @scope end |
Instance Method Details
#<=>(o) ⇒ Object
73 74 75 76 77 |
# File 'lib/one_apm/metrics/metric_spec.rb', line 73 def <=>(o) namecmp = self.name <=> o.name return namecmp if namecmp != 0 return (self.scope || '') <=> (o.scope || '') end |
#==(o) ⇒ Object
30 31 32 |
# File 'lib/one_apm/metrics/metric_spec.rb', line 30 def ==(o) self.eql?(o) end |
#eql?(o) ⇒ Boolean
34 35 36 |
# File 'lib/one_apm/metrics/metric_spec.rb', line 34 def eql? o @name == o.name && @scope == o.scope end |
#hash ⇒ Object
38 39 40 |
# File 'lib/one_apm/metrics/metric_spec.rb', line 38 def hash @name.hash ^ @scope.hash end |
#inspect ⇒ Object
64 65 66 |
# File 'lib/one_apm/metrics/metric_spec.rb', line 64 def inspect "#<OneApm::MetricSpec '#{name}':'#{scope}'>" end |
#sub(pattern, replacement, apply_to_scope = true) ⇒ Object
return a new metric spec if the given regex matches the name or scope.
44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/one_apm/metrics/metric_spec.rb', line 44 def sub(pattern, replacement, apply_to_scope = true) OneApm::Manager.logger.warn("The sub method on metric specs is deprecated") rescue nil return nil if name !~ pattern && (!apply_to_scope || scope.nil? || scope !~ pattern) new_name = name.sub(pattern, replacement)[OA_LENGTH_RANGE] if apply_to_scope new_scope = (scope && scope.sub(pattern, replacement)[OA_LENGTH_RANGE]) else new_scope = scope end self.class.new new_name, new_scope end |
#to_json(*a) ⇒ Object
68 69 70 71 |
# File 'lib/one_apm/metrics/metric_spec.rb', line 68 def to_json(*a) {'name' => name, 'scope' => scope}.to_json(*a) end |
#to_s ⇒ Object
59 60 61 62 |
# File 'lib/one_apm/metrics/metric_spec.rb', line 59 def to_s return name if scope.empty? "#{name}:#{scope}" end |