Sha256: abe5271f27fd961d6dd4eb5bfc147e5c51f2ab959420c6abdc39b3e251c65ab7

Contents?: true

Size: 1.37 KB

Versions: 33

Compression:

Stored size: 1.37 KB

Contents

# This file is distributed under New Relic's license terms.
# See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details.
# frozen_string_literal: true

# this struct uniquely defines a metric, optionally inside
# the call scope of another metric
class NewRelic::MetricSpec
  attr_reader :name, :scope

  # the maximum length of a metric name or metric scope
  MAX_LENGTH = 255
  LENGTH_RANGE = (0...MAX_LENGTH)
  EMPTY_SCOPE = ''.freeze

  def initialize(metric_name = '', metric_scope = nil)
    if metric_name.to_s.length > MAX_LENGTH
      @name = metric_name.to_s[LENGTH_RANGE]
    else
      @name = metric_name.to_s
    end

    if metric_scope
      if metric_scope.to_s.length > MAX_LENGTH
        @scope = metric_scope.to_s[LENGTH_RANGE]
      else
        @scope = metric_scope.to_s
      end
    else
      @scope = EMPTY_SCOPE
    end
  end

  def ==(o)
    self.eql?(o)
  end

  def eql?(o)
    @name == o.name && @scope == o.scope
  end

  def hash
    [@name, @scope].hash
  end

  def to_s
    return name if scope.empty?

    "#{name}:#{scope}"
  end

  def inspect
    "#<NewRelic::MetricSpec '#{name}':'#{scope}'>"
  end

  def to_json(*a)
    {'name' => name,
     'scope' => scope}.to_json(*a)
  end

  def <=>(o)
    namecmp = self.name <=> o.name
    return namecmp if namecmp != 0

    return (self.scope || '') <=> (o.scope || '')
  end
end

Version data entries

33 entries across 33 versions & 1 rubygems

Version Path
newrelic_rpm-9.17.0 lib/new_relic/metric_spec.rb
newrelic_rpm-9.16.1 lib/new_relic/metric_spec.rb
newrelic_rpm-9.16.0 lib/new_relic/metric_spec.rb
newrelic_rpm-9.15.0 lib/new_relic/metric_spec.rb
newrelic_rpm-9.14.0 lib/new_relic/metric_spec.rb
newrelic_rpm-9.13.0 lib/new_relic/metric_spec.rb
newrelic_rpm-9.12.0 lib/new_relic/metric_spec.rb
newrelic_rpm-9.11.0 lib/new_relic/metric_spec.rb
newrelic_rpm-9.10.2 lib/new_relic/metric_spec.rb
newrelic_rpm-9.10.1 lib/new_relic/metric_spec.rb
newrelic_rpm-9.10.0 lib/new_relic/metric_spec.rb
newrelic_rpm-9.9.0 lib/new_relic/metric_spec.rb
newrelic_rpm-9.8.0 lib/new_relic/metric_spec.rb
newrelic_rpm-9.7.1 lib/new_relic/metric_spec.rb
newrelic_rpm-9.7.0 lib/new_relic/metric_spec.rb
newrelic_rpm-9.6.0 lib/new_relic/metric_spec.rb
newrelic_rpm-9.5.0 lib/new_relic/metric_spec.rb
newrelic_rpm-9.4.2 lib/new_relic/metric_spec.rb
newrelic_rpm-9.4.1 lib/new_relic/metric_spec.rb
newrelic_rpm-9.4.0 lib/new_relic/metric_spec.rb