Sha256: 8d14f0e08afda64b6000074b73ccc690ed9ac222e85c36f9a622613ebccb63b2

Contents?: true

Size: 1.09 KB

Versions: 4

Compression:

Stored size: 1.09 KB

Contents

# typed: strict

module PackStats
  class GaugeMetric < T::Struct
    extend T::Sig

    const :name, String
    const :count, Integer
    const :tags, T::Array[Tag]

    sig { params(metric_name: String, count: Integer, tags: T::Array[Tag]).returns(GaugeMetric) }
    def self.for(metric_name, count, tags)
      name = "modularization.#{metric_name}"
      # https://docs.datadoghq.com/metrics/custom_metrics/#naming-custom-metrics
      # Metric names must not exceed 200 characters. Fewer than 100 is preferred from a UI perspective
      if name.length > 200
        raise StandardError.new("Metrics names must not exceed 200 characters: #{name}") # rubocop:disable Style/RaiseArgs
      end

      new(
        name: name,
        count: count,
        tags: tags
      )
    end

    sig { returns(String) }
    def to_s
      "#{name} with count #{count}, with tags #{tags.map(&:to_s).join(', ')}"
    end

    sig { params(other: GaugeMetric).returns(T::Boolean) }
    def ==(other)
      other.name == self.name &&
        other.count == self.count &&
        other.tags == self.tags
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
pack_stats-0.0.4 lib/pack_stats/gauge_metric.rb
pack_stats-0.0.3 lib/pack_stats/gauge_metric.rb
pack_stats-0.0.2 lib/pack_stats/gauge_metric.rb
pack_stats-0.0.1 lib/pack_stats/gauge_metric.rb