Module: Promenade

Defined in:
lib/promenade.rb,
lib/promenade/setup.rb,
lib/promenade/engine.rb,
lib/promenade/railtie.rb,
lib/promenade/version.rb,
lib/promenade/prometheus.rb,
lib/promenade/yjit/stats.rb,
lib/promenade/configuration.rb,
lib/promenade/pitchfork/stats.rb,
lib/promenade/raindrops/stats.rb,
lib/promenade/yjit/middleware.rb,
lib/promenade/kafka/subscriber.rb,
lib/promenade/karafka/subscriber.rb,
lib/promenade/pitchfork/mem_stats.rb,
lib/promenade/pitchfork/middleware.rb,
lib/promenade/raindrops/middleware.rb,
lib/promenade/waterdrop/subscriber.rb,
lib/promenade/kafka/fetcher_subscriber.rb,
lib/promenade/karafka/error_subscriber.rb,
lib/promenade/kafka/consumer_subscriber.rb,
lib/promenade/kafka/producer_subscriber.rb,
lib/promenade/waterdrop/error_subscriber.rb,
lib/promenade/client/rack/middleware_base.rb,
lib/promenade/client/rack/request_labeler.rb,
lib/promenade/kafka/connection_subscriber.rb,
lib/promenade/karafka/consumer_subscriber.rb,
lib/promenade/client/rack/singleton_caller.rb,
lib/promenade/waterdrop/message_subscriber.rb,
lib/promenade/client/rack/exception_handler.rb,
lib/promenade/karafka/statistics_subscriber.rb,
lib/promenade/pitchfork/worker_pid_provider.rb,
lib/promenade/client/rack/queue_time_duration.rb,
lib/promenade/kafka/async_producer_subscriber.rb,
lib/promenade/waterdrop/statistics_subscriber.rb,
lib/promenade/client/rack/http_request_duration_collector.rb,
lib/promenade/client/rack/http_request_queue_time_collector.rb,
lib/promenade/client/rack/request_controller_action_labeler.rb

Defined Under Namespace

Modules: Client, Kafka, Karafka, Pitchfork, Prometheus, Raindrops, Waterdrop, YJIT Classes: Configuration, Engine, Railtie

Constant Summary collapse

VERSION =
"0.12.4".freeze

Class Method Summary collapse

Class Method Details

.configurationObject



18
19
20
# File 'lib/promenade.rb', line 18

def configuration
  @_configuration ||= Configuration.new
end

.configure {|configuration| ... } ⇒ Object

Yields:



22
23
24
# File 'lib/promenade.rb', line 22

def configure
  yield(configuration)
end

.metric(name) ⇒ Object



14
15
16
# File 'lib/promenade.rb', line 14

def metric(name)
  Promenade::Prometheus.metric(name)
end

.multiprocess_files_dirObject



18
19
20
# File 'lib/promenade/setup.rb', line 18

def multiprocess_files_dir
  ENV.fetch("PROMETHEUS_MULTIPROC_DIR", root_dir.join("tmp", "promenade"))
end

.pid_provider_methodObject



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/promenade/setup.rb', line 38

def pid_provider_method
  # This workaround enables us to utilize the same PID provider for both Unicorn, Pitchfork and Puma.
  # We cannot employ the same method directly because Unicorn and Pitchfork are not loaded simultaneously.
  # Instead, we define a method that dynamically loads the appropriate PID provider based on the active server.
  # As a fallback, we use the process ID.

  if defined?(::Unicorn)
    require "prometheus/client/support/unicorn"
    ::Prometheus::Client::Support::Unicorn.method(:worker_pid_provider)
  elsif defined?(::Pitchfork)
    require "promenade/pitchfork/worker_pid_provider"
    Pitchfork::WorkerPidProvider.method(:fetch)
  elsif defined?(::Puma)
    require "prometheus/client/support/puma"
    ::Prometheus::Client::Support::Puma.method(:worker_pid_provider)
  else
    -> { "process_id_#{Process.pid}" }
  end
end

.rails_defined?Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/promenade/setup.rb', line 14

def rails_defined?
  defined?(Rails)
end

.root_dirObject



6
7
8
9
10
11
12
# File 'lib/promenade/setup.rb', line 6

def root_dir
  if rails_defined?
    Rails.root
  else
    Pathname.new(ENV.fetch("RAILS_ROOT", Dir.pwd))
  end
end

.setupObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/promenade/setup.rb', line 22

def setup
  unless File.directory? multiprocess_files_dir
    FileUtils.mkdir_p multiprocess_files_dir
  end

  ENV["prometheus_multiproc_dir"] = multiprocess_files_dir.to_s

  require "prometheus/client"

  ::Prometheus::Client.configure do |config|
    config.multiprocess_files_dir = multiprocess_files_dir

    config.pid_provider = pid_provider_method
  end
end