debian-mirror-gitlab/app/controllers/projects/grafana_api_controller.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

47 lines
1,015 B
Ruby
Raw Normal View History

2019-12-21 20:55:43 +05:30
# frozen_string_literal: true
class Projects::GrafanaApiController < Projects::ApplicationController
include RenderServiceResults
2019-12-26 22:10:19 +05:30
include MetricsDashboard
2019-12-21 20:55:43 +05:30
2023-01-10 11:22:00 +05:30
before_action :authorize_read_grafana!, only: :proxy
2021-01-03 14:25:43 +05:30
feature_category :metrics
2022-07-23 23:45:48 +05:30
urgency :low
2021-01-03 14:25:43 +05:30
2019-12-21 20:55:43 +05:30
def proxy
2023-07-09 08:55:56 +05:30
return not_found if Feature.enabled?(:remove_monitor_metrics)
2019-12-21 20:55:43 +05:30
result = ::Grafana::ProxyService.new(
project,
params[:datasource_id],
params[:proxy_path],
2020-04-22 19:07:51 +05:30
prometheus_params
2019-12-21 20:55:43 +05:30
).execute
return continue_polling_response if result.nil?
return error_response(result) if result[:status] == :error
success_response(result)
end
private
2019-12-26 22:10:19 +05:30
def metrics_dashboard_params
params.permit(:embedded, :grafana_url)
end
2019-12-21 20:55:43 +05:30
def query_params
2020-04-22 19:07:51 +05:30
params.permit(:query, :start_time, :end_time, :step)
end
def prometheus_params
query_params.to_h
.except(:start_time, :end_time)
.merge(
start: query_params[:start_time],
end: query_params[:end_time]
)
2019-12-21 20:55:43 +05:30
end
end