2018-12-05 23:21:45 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-03-27 19:54:05 +05:30
|
|
|
module Projects
|
|
|
|
module Prometheus
|
|
|
|
class MetricsController < Projects::ApplicationController
|
|
|
|
before_action :authorize_admin_project!
|
|
|
|
before_action :require_prometheus_metrics!
|
|
|
|
|
|
|
|
def active_common
|
|
|
|
respond_to do |format|
|
|
|
|
format.json do
|
|
|
|
matched_metrics = prometheus_adapter.query(:matched_metrics) || {}
|
|
|
|
|
|
|
|
if matched_metrics.any?
|
|
|
|
render json: matched_metrics
|
|
|
|
else
|
|
|
|
head :no_content
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def prometheus_adapter
|
2020-03-13 15:44:24 +05:30
|
|
|
@prometheus_adapter ||= ::Gitlab::Prometheus::Adapter.new(project, project.deployment_platform&.cluster).prometheus_adapter
|
2018-03-27 19:54:05 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def require_prometheus_metrics!
|
2018-10-15 14:42:47 +05:30
|
|
|
render_404 unless prometheus_adapter&.can_query?
|
2018-03-27 19:54:05 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2019-12-04 20:38:33 +05:30
|
|
|
|
|
|
|
Projects::Prometheus::MetricsController.prepend_if_ee('EE::Projects::Prometheus::MetricsController')
|