Class: Bigcommerce::Prometheus::Servers::Thin::RackApp

Inherits:
Object
  • Object
show all
Defined in:
lib/bigcommerce/prometheus/servers/thin/rack_app.rb

Overview

Handles metrics requests as a Rack App on the Thin server

Instance Method Summary collapse

Constructor Details

#initialize(collector: nil, timeout: nil, logger: nil) ⇒ RackApp

Returns a new instance of RackApp.



28
29
30
31
32
33
# File 'lib/bigcommerce/prometheus/servers/thin/rack_app.rb', line 28

def initialize(collector: nil, timeout: nil, logger: nil)
  @timeout = timeout || ::Bigcommerce::Prometheus.server_timeout
  @collector = collector || ::PrometheusExporter::Server::Collector.new
  @logger = logger || ::Bigcommerce::Prometheus.logger
  @server_metrics = ::Bigcommerce::Prometheus::Servers::Thin::ServerMetrics.new(logger: @logger)
end

Instance Method Details

#add_type_collector(collector) ⇒ Object

Add a type collector to this server

Parameters:

  • collector (PrometheusExporter::Server::TypeCollector)


50
51
52
# File 'lib/bigcommerce/prometheus/servers/thin/rack_app.rb', line 50

def add_type_collector(collector)
  @collector.register_collector(collector)
end

#call(env) ⇒ Object



35
36
37
38
39
40
41
42
43
# File 'lib/bigcommerce/prometheus/servers/thin/rack_app.rb', line 35

def call(env)
  request = ::Rack::Request.new(env)
  response = ::Rack::Response.new
  controller = route(request)
  handle(controller: controller, request: request, response: response)
rescue StandardError => e
  @logger.error "Error: #{e.message}"
  handle(controller: ::Bigcommerce::Prometheus::Servers::Thin::Controllers::ErrorController, request: request, response: response)
end