prometheus_api_controller.rb 1.14 KB
Newer Older
1
2
3
# frozen_string_literal: true

class Projects::Environments::PrometheusApiController < Projects::ApplicationController
4
5
  include RenderServiceResults

6
7
8
9
  before_action :authorize_read_prometheus!
  before_action :environment

  def proxy
10
11
12
13
14
15
16
17
    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(
18
      environment,
19
20
      proxy_method,
      proxy_path,
21
      variable_substitution_result[:params]
22
23
    ).execute

24
25
    return continue_polling_response if prometheus_result.nil?
    return error_response(prometheus_result) if prometheus_result[:status] == :error
26

27
    success_response(prometheus_result)
28
29
30
31
  end

  private

32
33
34
35
36
37
  def variable_substitution_service
    Prometheus::ProxyVariableSubstitutionService
  end

  def permit_params
    params.permit!
38
39
  end

40
41
42
  def environment
    @environment ||= project.environments.find(params[:id])
  end
43
44
45
46
47
48
49
50

  def proxy_method
    request.method
  end

  def proxy_path
    params[:proxy_path]
  end
51
end