Add healthcheck endpoint, spec testing

This commit is contained in:
Belen Bustamante 2020-08-25 10:45:50 -07:00 committed by suckatrash
parent 4d06c01d21
commit 08132f75bd
No known key found for this signature in database
GPG key ID: 3857A763831B0756
4 changed files with 76 additions and 2 deletions

View file

@ -3,7 +3,7 @@
module Vmpooler
class API < Sinatra::Base
# Load API components
%w[helpers dashboard reroute v1 request_logger].each do |lib|
%w[helpers dashboard reroute v1 request_logger healthcheck].each do |lib|
require "vmpooler/api/#{lib}"
end
# Load dashboard components
@ -40,6 +40,10 @@ module Vmpooler
require 'prometheus/middleware/exporter'
use Vmpooler::Metrics::Promstats::CollectorMiddleware, metrics_prefix: "#{metrics.prometheus_prefix}_http"
use Prometheus::Middleware::Exporter, path: metrics.prometheus_endpoint
# Note that a user may want to use this check without prometheus
# However, prometheus setup includes the web server which is required for this check
# At this time prometheus is a requirement of using the health check on manager
use Vmpooler::API::Healthcheck
end
if torun.include? :api

View file

@ -0,0 +1,14 @@
# frozen_string_literal: true
module Vmpooler
class API
class Healthcheck < Sinatra::Base
get '/healthcheck/?' do
content_type :json
status 200
JSON.pretty_generate({ 'ok' => true })
end
end
end
end