Class: Vmpooler::API
- Inherits:
-
Sinatra::Base
- Object
- Sinatra::Base
- Vmpooler::API
- Defined in:
- lib/vmpooler/api.rb,
lib/vmpooler/api/v1.rb,
lib/vmpooler/api/helpers.rb,
lib/vmpooler/api/reroute.rb,
lib/vmpooler/api/dashboard.rb,
lib/vmpooler/api/request_logger.rb
Defined Under Namespace
Modules: Helpers Classes: Dashboard, RequestLogger, Reroute, V1
Class Method Summary collapse
Class Method Details
.execute(torun, config, redis, metrics, logger) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/vmpooler/api.rb', line 12 def self.execute(torun, config, redis, metrics, logger) self.settings.set :config, config self.settings.set :redis, redis unless redis.nil? self.settings.set :metrics, metrics self.settings.set :checkoutlock, Mutex.new # Deflating in all situations # https://www.schneems.com/2017/11/08/80-smaller-rails-footprint-with-rack-deflate/ use Rack::Deflater # not_found clause placed here to fix rspec test issue. not_found do content_type :json result = { ok: false } JSON.pretty_generate(result) end if metrics.respond_to?(:setup_prometheus_metrics) # Prometheus metrics are only setup if actually specified # in the config file. metrics.setup_prometheus_metrics(torun) # Using customised collector that filters out hostnames on API paths require 'vmpooler/metrics/promstats/collector_middleware' require 'prometheus/middleware/exporter' use Vmpooler::Metrics::Promstats::CollectorMiddleware, metrics_prefix: "#{metrics.prometheus_prefix}_http" use Prometheus::Middleware::Exporter, path: metrics.prometheus_endpoint end if torun.include? :api # Enable API request logging only if required use Vmpooler::API::RequestLogger, logger: logger if config[:config]['request_logger'] use Vmpooler::Dashboard use Vmpooler::API::Dashboard use Vmpooler::API::Reroute use Vmpooler::API::V1 end # Get thee started O WebServer self.run! end |