Class: PackStats::GaugeMetric

Inherits:
T::Struct
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/pack_stats/gauge_metric.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.for(metric_name, count, tags) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/pack_stats/gauge_metric.rb', line 12

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

  all_tags = [*tags, max_enforcements_tag]
  new(
    name: name,
    count: count,
    tags: all_tags
  )
end

.max_enforcements_tagObject



47
48
49
# File 'lib/pack_stats/gauge_metric.rb', line 47

def self.max_enforcements_tag
  @max_enforcements_tag || Tag.new(key: 'max_enforcements', value: 'false')
end

.set_max_enforcements_tag(tag_value) ⇒ Object



41
42
43
44
# File 'lib/pack_stats/gauge_metric.rb', line 41

def self.set_max_enforcements_tag(tag_value)
  @max_enforcements_tag = T.let(@max_enforcements_tag, T.nilable(Tag))
  @max_enforcements_tag = Tag.new(key: 'max_enforcements', value: tag_value ? 'true' : 'false')
end

Instance Method Details

#==(other) ⇒ Object



34
35
36
37
38
# File 'lib/pack_stats/gauge_metric.rb', line 34

def ==(other)
  other.name == self.name &&
    other.count == self.count &&
    other.tags == self.tags
end

#to_sObject



29
30
31
# File 'lib/pack_stats/gauge_metric.rb', line 29

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