Module: StatsD::Instrument::Helpers

Included in:
Assertions, Matchers::Matcher
Defined in:
lib/statsd/instrument/helpers.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.add_tag(tags, key, value) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/statsd/instrument/helpers.rb', line 15

def add_tag(tags, key, value)
  tags = tags.dup || {}

  if tags.is_a?(String)
    tags = tags.empty? ? "#{key}:#{value}" : "#{tags},#{key}:#{value}"
  elsif tags.is_a?(Array)
    tags << "#{key}:#{value}"
  elsif tags.is_a?(Hash)
    tags[key] = value
  else
    raise ArgumentError, "add_tag only supports string, array or hash, #{tags.class} provided"
  end

  tags
end

.prefix_metric(metric_name, client: nil) ⇒ Object



31
32
33
34
# File 'lib/statsd/instrument/helpers.rb', line 31

def prefix_metric(metric_name, client: nil)
  client ||= StatsD.singleton_client
  client&.prefix ? "#{client.prefix}.#{metric_name}" : metric_name
end

.prefixed_metric?(metric_name, client: nil) ⇒ Boolean

Returns:

  • (Boolean)


36
37
38
39
40
41
# File 'lib/statsd/instrument/helpers.rb', line 36

def prefixed_metric?(metric_name, client: nil)
  client ||= StatsD.singleton_client
  return false unless client&.prefix

  metric_name =~ /\A#{Regexp.escape(client.prefix)}\./
end

Instance Method Details

#capture_statsd_datagrams(client: nil, &block) ⇒ Object Also known as: capture_statsd_calls



6
7
8
9
# File 'lib/statsd/instrument/helpers.rb', line 6

def capture_statsd_datagrams(client: nil, &block)
  client ||= StatsD.singleton_client
  client.capture(&block)
end