vmpooler/bin/vmpooler
Gene Liverman 8f3039e321
Add distributed tracing (#399)
This change utilizes OpenTelemetry's automatic instrumentation to add
distributed tracing capabilities to VMPooler. This is a non-breaking
change as traces are processed in noop mode by default.
2020-09-17 15:35:21 -04:00

70 lines
2 KiB
Ruby
Executable file

#!/usr/bin/env ruby
# frozen_string_literal: true
require 'vmpooler'
require 'vmpooler/version'
config = Vmpooler.config
logger_file = config[:config]['logfile']
prefix = config[:config]['prefix']
redis_host = config[:redis]['server']
redis_port = config[:redis]['port']
redis_password = config[:redis]['password']
redis_connection_pool_size = config[:redis]['connection_pool_size']
redis_connection_pool_timeout = config[:redis]['connection_pool_timeout']
redis_reconnect_attempts = config[:redis]['reconnect_attempts']
tracing_enabled = config[:tracing]['enabled']
tracing_jaeger_host = config[:tracing]['jaeger_host']
logger = Vmpooler::Logger.new logger_file
metrics = Vmpooler::Metrics.init(logger, config)
version = Vmpooler::VERSION
startup_args = ARGV
Vmpooler.configure_tracing(startup_args, prefix, tracing_enabled, tracing_jaeger_host, version)
torun_threads = []
if ARGV.count == 0
torun = %i[api manager]
else
torun = []
torun << :api if ARGV.include?('api')
torun << :manager if ARGV.include?('manager')
exit(2) if torun.empty?
end
if torun.include?(:api)
api = Thread.new do
redis = Vmpooler.new_redis(redis_host, redis_port, redis_password)
Vmpooler::API.execute(torun, config, redis, metrics, logger)
end
torun_threads << api
elsif metrics.respond_to?(:setup_prometheus_metrics)
# Run the cut down API - Prometheus Metrics only.
prometheus_only_api = Thread.new do
Vmpooler::API.execute(torun, config, nil, metrics, logger)
end
torun_threads << prometheus_only_api
end
if torun.include?(:manager)
manager = Thread.new do
Vmpooler::PoolManager.new(
config,
logger,
Vmpooler.redis_connection_pool(redis_host, redis_port, redis_password, redis_connection_pool_size, redis_connection_pool_timeout, metrics, redis_reconnect_attempts),
metrics
).execute!
end
torun_threads << manager
end
if ENV['VMPOOLER_DEBUG']
trap('INT') do
puts 'Shutting down.'
torun_threads.each(&:exit)
end
end
torun_threads.each(&:join)