mirror of
https://github.com/puppetlabs/vmpooler.git
synced 2026-01-26 10:08:40 -05:00
(POOLER-181) Separate Dashboard from api
Allow the dashboard to run separately from the API, so that the dashboard can be scaled appropriately. Note - this implementation actually co-runs the api in the dashboard instance to re-use the api code for the dashboard endpoints and other v1 endpoints collecting the operating information.
This commit is contained in:
parent
6d01079f4a
commit
1073629c13
3 changed files with 16 additions and 10 deletions
|
|
@ -16,20 +16,21 @@ metrics = Vmpooler::Metrics.init(logger, config)
|
||||||
|
|
||||||
torun_threads = []
|
torun_threads = []
|
||||||
if ARGV.count == 0
|
if ARGV.count == 0
|
||||||
torun = %i[api manager]
|
torun = %i[api manager dashboard]
|
||||||
else
|
else
|
||||||
torun = []
|
torun = []
|
||||||
torun << :api if ARGV.include? 'api'
|
torun << :api if ARGV.include? 'api'
|
||||||
torun << :manager if ARGV.include? 'manager'
|
torun << :manager if ARGV.include? 'manager'
|
||||||
|
torun << :dashboard if ARGV.include? 'dashboard'
|
||||||
exit(2) if torun.empty?
|
exit(2) if torun.empty?
|
||||||
end
|
end
|
||||||
|
|
||||||
if torun.include? :api
|
if (torun & %i[api dashboard]).any?
|
||||||
api = Thread.new do
|
api_or_dashboard = Thread.new do
|
||||||
redis = Vmpooler.new_redis(redis_host, redis_port, redis_password)
|
redis = Vmpooler.new_redis(redis_host, redis_port, redis_password)
|
||||||
Vmpooler::API.execute(torun, config, redis, metrics, logger)
|
Vmpooler::API.execute(torun, config, redis, metrics, logger)
|
||||||
end
|
end
|
||||||
torun_threads << api
|
torun_threads << api_or_dashboard
|
||||||
elsif metrics.respond_to?(:setup_prometheus_metrics)
|
elsif metrics.respond_to?(:setup_prometheus_metrics)
|
||||||
# Run the cut down API - Prometheus Metrics only.
|
# Run the cut down API - Prometheus Metrics only.
|
||||||
prometheus_only_api = Thread.new do
|
prometheus_only_api = Thread.new do
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
module Vmpooler
|
module Vmpooler
|
||||||
class API < Sinatra::Base
|
class API < Sinatra::Base
|
||||||
# Load API components
|
# Load API components
|
||||||
%w[helpers dashboard reroute v1 request_logger].each do |lib|
|
%w[helpers reroute v1 request_logger dashboard].each do |lib|
|
||||||
require "vmpooler/api/#{lib}"
|
require "vmpooler/api/#{lib}"
|
||||||
end
|
end
|
||||||
# Load dashboard components
|
# Load dashboard components
|
||||||
|
|
@ -42,12 +42,17 @@ module Vmpooler
|
||||||
use Prometheus::Middleware::Exporter, path: metrics.endpoint
|
use Prometheus::Middleware::Exporter, path: metrics.endpoint
|
||||||
end
|
end
|
||||||
|
|
||||||
if torun.include? :api
|
# Determine which parts of the API to actually run.
|
||||||
|
# The Dashboard also runs the API parts for its own "self-referencing" purposes, i.e. to re-use those parts
|
||||||
|
# that allow it to pull the information from redis.
|
||||||
|
if (torun & %i[api dashboard]).any?
|
||||||
# Enable API request logging only if required
|
# Enable API request logging only if required
|
||||||
use Vmpooler::API::RequestLogger, logger: logger if config[:config]['request_logger']
|
use Vmpooler::API::RequestLogger, logger: logger if config[:config]['request_logger'] && (torun.include? :api)
|
||||||
|
|
||||||
use Vmpooler::Dashboard
|
if torun.include? :dashboard
|
||||||
use Vmpooler::API::Dashboard
|
use Vmpooler::Dashboard
|
||||||
|
use Vmpooler::API::Dashboard
|
||||||
|
end
|
||||||
use Vmpooler::API::Reroute
|
use Vmpooler::API::Reroute
|
||||||
use Vmpooler::API::V1
|
use Vmpooler::API::V1
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,7 @@ describe Vmpooler::API do
|
||||||
|
|
||||||
before(:each) do
|
before(:each) do
|
||||||
expect(app).to receive(:run!)
|
expect(app).to receive(:run!)
|
||||||
app.execute([:api], config, redis, nil, nil)
|
app.execute([:dashboard], config, redis, nil, nil)
|
||||||
app.settings.set :config, auth: false
|
app.settings.set :config, auth: false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue