Module: RailsPodKit::Exporter

Defined in:
lib/rails_pod_kit/exporter.rb

Overview

The in-process WEBrick /metrics server, shared by every non-Puma entry point: the Sidekiq worker, the Rails-free global exporter and the SolidQueue exporter. Under Puma the exporter comes from the :yabeda_prometheus plugin instead (see RailsPodKit::Puma), so this is never used there.

Class Method Summary collapse

Class Method Details

.reset!Object

Test/reset hook — drops the "already started" latch.



38
39
40
# File 'lib/rails_pod_kit/exporter.rb', line 38

def reset!
  @started = false
end

.start!Object

Starts the background exporter and returns whether it did. Idempotent: the latch keeps a re-entrant boot from double-binding the port.



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/rails_pod_kit/exporter.rb', line 15

def start!
  return false unless RailsPodKit.enabled?
  return false if @started

  require 'yabeda/prometheus/mmap'

  # `start_metrics_server!` reads the bind port from the env, so publish the
  # configured one first.
  ENV['PROMETHEUS_EXPORTER_PORT'] ||= RailsPodKit.config.port.to_s
  # Drop the exporter's per-scrape access log (Rack::CommonLogger, which the
  # mmap exporter mounts unless this is exactly 'false'). See
  # Config#silence_exporter_access_log.
  ENV['PROMETHEUS_EXPORTER_LOG_REQUESTS'] = 'false' if RailsPodKit.config.silence_exporter_access_log

  Yabeda::Prometheus::Exporter.start_metrics_server!
  @started = true
end

.started?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/rails_pod_kit/exporter.rb', line 33

def started?
  !!@started
end