class OneApm::MetricSpec

Constants

OA_EMPTY_SCOPE
OA_LENGTH_RANGE
OA_MAX_LENGTH

the maximum length of a metric name or metric scope

Attributes

name[R]
scope[R]

Public Class Methods

new(metric_name='', metric_scope=nil) click to toggle source
# 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

Public Instance Methods

<=>(o) click to toggle source
# 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) click to toggle source
# File lib/one_apm/metrics/metric_spec.rb, line 30
def ==(o)
  self.eql?(o)
end
eql?(o) click to toggle source
# File lib/one_apm/metrics/metric_spec.rb, line 34
def eql? o
  @name == o.name && @scope == o.scope
end
hash() click to toggle source
# File lib/one_apm/metrics/metric_spec.rb, line 38
def hash
  @name.hash ^ @scope.hash
end
inspect() click to toggle source
# File lib/one_apm/metrics/metric_spec.rb, line 64
def inspect
  "#<OneApm::MetricSpec '#{name}':'#{scope}'>"
end
sub(pattern, replacement, apply_to_scope = true) click to toggle source

return a new metric spec if the given regex matches the name or scope.

# 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) click to toggle source
# File lib/one_apm/metrics/metric_spec.rb, line 68
def to_json(*a)
  {'name' => name,
  'scope' => scope}.to_json(*a)
end
to_s() click to toggle source
# File lib/one_apm/metrics/metric_spec.rb, line 59
def to_s
  return name if scope.empty?
  "#{name}:#{scope}"
end