Class: Puma::Plugin::TelemetryToo::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/puma/plugin/telemetry_too/config.rb

Overview

Configuration object for plugin

Constant Summary collapse

DEFAULT_PUMA_TELEMETRY =
[
  # Total booted workers.
  'workers.booted',

  # Total number of workers configured.
  'workers.total',

  # Current number of threads spawned.
  'workers.spawned_threads',

  # Maximum number of threads that can run .
  'workers.max_threads',

  # Number of requests performed so far.
  'workers.requests_count',

  # Number of requests waiting to be processed.
  'queue.backlog',

  # Maximum number of requests held in Puma's Reactor which is used for
  # asyncronously buffering request bodies. This stat is reset on every
  # call, so it's the maximum value observed since the last call
  'queue.backlog_max',

  # Maximum number of requests that have been fully buffered by the
  # Reactor and placed in a ready queue, but have not yet been picked
  # up by a server thread. This stat is reset on every call, so it's
  # the maximum value observed since the last stat call.
  'queue.reactor_max',

  # Free capacity that could be utilized, i.e. if backlog
  # is growing, and we still have capacity available, it
  # could mean that load balancing is not performing well.
  'queue.capacity'
].freeze
TARGETS =
{
  dogstatsd: TelemetryToo::Targets::DatadogStatsdTarget,
  io: TelemetryToo::Targets::IOTarget,
  open_telemetry: TelemetryToo::Targets::OpenTelemetryTarget,
  log: TelemetryToo::Targets::LogTarget
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfig

Returns a new instance of Config.



92
93
94
95
96
97
98
99
100
# File 'lib/puma/plugin/telemetry_too/config.rb', line 92

def initialize
  @enabled = false
  @initial_delay = 5
  @frequency = 5
  @targets = []
  @puma_telemetry = DEFAULT_PUMA_TELEMETRY
  @socket_telemetry = false
  @socket_parser = :unpack
end

Instance Attribute Details

#enabledObject

Whenever telemetry should run with puma

  • default: false


53
54
55
# File 'lib/puma/plugin/telemetry_too/config.rb', line 53

def enabled
  @enabled
end

#frequencyObject

Seconds between publishing telemetry

  • default: 5


61
62
63
# File 'lib/puma/plugin/telemetry_too/config.rb', line 61

def frequency
  @frequency
end

#initial_delayObject

Number of seconds to delay first telemetry

  • default: 5


57
58
59
# File 'lib/puma/plugin/telemetry_too/config.rb', line 57

def initial_delay
  @initial_delay
end

#puma_telemetryObject

Which metrics to publish from puma stats. You can select a subset from default ones that interest you the most.

  • default: DEFAULT_PUMA_TELEMETRY


72
73
74
# File 'lib/puma/plugin/telemetry_too/config.rb', line 72

def puma_telemetry
  @puma_telemetry
end

#socket_parserObject

Symbol representing method to parse the Socket::Option, or the whole implementation as a lambda. Available options:

  • :inspect, based on the Socket::Option#inspect method, it's the safest and slowest way to extract the info. inspect output might not be available, i.e. on AWS Fargate
  • :unpack, parse binary data given by Socket::Option. Fastest way (12x compared to inspect) but depends on kernel headers and fields ordering within the struct. It should almost always match though. DEFAULT
  • proc/lambda, Socket::Option will be given as an argument, it should return the value of unacked field as an integer.


90
91
92
# File 'lib/puma/plugin/telemetry_too/config.rb', line 90

def socket_parser
  @socket_parser
end

#socket_telemetryObject

Whenever to publish socket telemetry.

  • default: false


76
77
78
# File 'lib/puma/plugin/telemetry_too/config.rb', line 76

def socket_telemetry
  @socket_telemetry
end

#targetsObject

List of targets which are meant to publish telemetry. Target should implement #call method accepting a single argument - so it can be even a simple proc.

  • default: []


67
68
69
# File 'lib/puma/plugin/telemetry_too/config.rb', line 67

def targets
  @targets
end

Instance Method Details

#add_target(name_or_target, **args) ⇒ Object



121
122
123
124
125
126
127
128
129
# File 'lib/puma/plugin/telemetry_too/config.rb', line 121

def add_target(name_or_target, **args)
  return @targets.push(name_or_target) unless name_or_target.is_a?(Symbol)

  target = TARGETS.fetch(name_or_target) do
    raise TelemetryToo::Error, "Unknown Target: #{name_or_target.inspect}, #{args.inspect}"
  end

  @targets.push(target.new(**args))
end

#enabled?Boolean

Returns:

  • (Boolean)


102
103
104
# File 'lib/puma/plugin/telemetry_too/config.rb', line 102

def enabled?
  !!@enabled
end

#socket_telemetry!Object



106
107
108
109
110
111
112
113
114
115
# File 'lib/puma/plugin/telemetry_too/config.rb', line 106

def socket_telemetry!
  # These structs are platform specific, and not available on macOS,
  # for example. If they're undefined, then we cannot capture socket
  # telemetry. We'll warn in that case.
  if defined?(Socket::SOL_TCP) && defined?(Socket::TCP_INFO)
    @socket_telemetry = true
  else
    warn("Cannot capture socket telemetry on this platform (#{RUBY_PLATFORM}); socket_telemetry is disabled.")
  end
end

#socket_telemetry?Boolean

Returns:

  • (Boolean)


117
118
119
# File 'lib/puma/plugin/telemetry_too/config.rb', line 117

def socket_telemetry?
  @socket_telemetry
end