2019-04-02 06:26:09 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class Projects::Environments::PrometheusApiController < Projects::ApplicationController
|
2019-10-10 12:06:19 +00:00
|
|
|
include RenderServiceResults
|
|
|
|
|
2019-04-02 06:26:09 +00:00
|
|
|
before_action :authorize_read_prometheus!
|
|
|
|
before_action :environment
|
|
|
|
|
|
|
|
def proxy
|
2019-12-09 03:07:57 +00:00
|
|
|
variable_substitution_result =
|
|
|
|
variable_substitution_service.new(environment, permit_params).execute
|
|
|
|
|
|
|
|
if variable_substitution_result[:status] == :error
|
|
|
|
return error_response(variable_substitution_result)
|
|
|
|
end
|
|
|
|
|
|
|
|
prometheus_result = Prometheus::ProxyService.new(
|
2019-04-02 06:26:09 +00:00
|
|
|
environment,
|
2019-04-15 15:31:59 +00:00
|
|
|
proxy_method,
|
|
|
|
proxy_path,
|
2019-12-09 03:07:57 +00:00
|
|
|
variable_substitution_result[:params]
|
2019-04-02 06:26:09 +00:00
|
|
|
).execute
|
|
|
|
|
2019-12-09 03:07:57 +00:00
|
|
|
return continue_polling_response if prometheus_result.nil?
|
|
|
|
return error_response(prometheus_result) if prometheus_result[:status] == :error
|
2019-10-10 12:06:19 +00:00
|
|
|
|
2019-12-09 03:07:57 +00:00
|
|
|
success_response(prometheus_result)
|
2019-04-02 06:26:09 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2019-12-09 03:07:57 +00:00
|
|
|
def variable_substitution_service
|
|
|
|
Prometheus::ProxyVariableSubstitutionService
|
|
|
|
end
|
|
|
|
|
|
|
|
def permit_params
|
|
|
|
params.permit!
|
2019-04-15 15:31:59 +00:00
|
|
|
end
|
|
|
|
|
2019-04-02 06:26:09 +00:00
|
|
|
def environment
|
|
|
|
@environment ||= project.environments.find(params[:id])
|
|
|
|
end
|
2019-04-15 15:31:59 +00:00
|
|
|
|
|
|
|
def proxy_method
|
|
|
|
request.method
|
|
|
|
end
|
|
|
|
|
|
|
|
def proxy_path
|
|
|
|
params[:proxy_path]
|
|
|
|
end
|
2019-04-02 06:26:09 +00:00
|
|
|
end
|