Class: Atatus::Metrics::Set Private

Inherits:
Object
  • Object
show all
Includes:
Logging
Defined in:
lib/atatus/metrics/set.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Direct Known Subclasses

CpuMemSet, JVMSet, SpanScopedSet, VMSet

Constant Summary collapse

DISTINCT_LABEL_LIMIT =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

1000

Constants included from Logging

Logging::LEVELS, Logging::PREFIX

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Logging

#debug, #error, #fatal, #info, #warn

Constructor Details

#initialize(config) ⇒ Set

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Set.



31
32
33
34
35
36
# File 'lib/atatus/metrics/set.rb', line 31

def initialize(config)
  @config = config
  @metrics = {}
  @disabled = false
  @lock = Mutex.new
end

Instance Attribute Details

#metricsObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



38
39
40
# File 'lib/atatus/metrics/set.rb', line 38

def metrics
  @metrics
end

Instance Method Details

#collectObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/atatus/metrics/set.rb', line 88

def collect
  return if disabled?

  @lock.synchronize do
    metrics.each_with_object({}) do |(key, metric), sets|
      next unless (value = metric.collect)

      # metrics have a key of name and flat array of key-value pairs
      #   eg [name, key, value, key, value]
      # they can be sent in the same metricset but not if they have
      # differing tags. So, we split the resulting sets by tags first.
      name, *tags = key
      sets[tags] ||= Metricset.new

      # then we set the `samples` value for the metricset
      set = sets[tags]
      set.samples[name] = value

      # and finally we copy the tags from the Metric to the Metricset
      set.merge_tags! metric.tags
    end.values
  end
end

#counter(key, tags: nil, **args) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



48
49
50
# File 'lib/atatus/metrics/set.rb', line 48

def counter(key, tags: nil, **args)
  metric(Counter, key, tags: tags, **args)
end

#disable!Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



40
41
42
# File 'lib/atatus/metrics/set.rb', line 40

def disable!
  @disabled = true
end

#disabled?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


44
45
46
# File 'lib/atatus/metrics/set.rb', line 44

def disabled?
  @disabled
end

#gauge(key, tags: nil, **args) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



52
53
54
# File 'lib/atatus/metrics/set.rb', line 52

def gauge(key, tags: nil, **args)
  metric(Gauge, key, tags: tags, **args)
end

#metric(kls, key, tags: nil, **args) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/atatus/metrics/set.rb', line 60

def metric(kls, key, tags: nil, **args)
  if @config.disable_metrics.any? { |p| p.match? key }
    return NOOP
  end

  key = key_with_tags(key, tags)
  return metrics[key] if metrics[key]

  @lock.synchronize do
    return metrics[key] if metrics[key]

    metrics[key] =
      if metrics.length < DISTINCT_LABEL_LIMIT
        kls.new(key, tags: tags, **args)
      else
        unless @label_limit_logged
          warn(
            'The limit of %d metricsets has been reached, no new ' \
             'metricsets will be created.', DISTINCT_LABEL_LIMIT
          )
          @label_limit_logged = true
        end

        NOOP
      end
  end
end

#timer(key, tags: nil, **args) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



56
57
58
# File 'lib/atatus/metrics/set.rb', line 56

def timer(key, tags: nil, **args)
  metric(Timer, key, tags: tags, **args)
end