2019-10-10 08:06:19 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class Projects::GrafanaApiController < Projects::ApplicationController
|
|
|
|
include RenderServiceResults
|
2019-10-31 11:06:41 -04:00
|
|
|
include MetricsDashboard
|
|
|
|
|
2020-10-08 14:08:32 -04:00
|
|
|
feature_category :metrics
|
2022-05-20 11:09:10 -04:00
|
|
|
urgency :low
|
2020-10-08 14:08:32 -04:00
|
|
|
|
2019-10-10 08:06:19 -04:00
|
|
|
def proxy
|
|
|
|
result = ::Grafana::ProxyService.new(
|
|
|
|
project,
|
|
|
|
params[:datasource_id],
|
|
|
|
params[:proxy_path],
|
2020-04-03 05:09:31 -04:00
|
|
|
prometheus_params
|
2019-10-10 08:06:19 -04:00
|
|
|
).execute
|
|
|
|
|
|
|
|
return continue_polling_response if result.nil?
|
|
|
|
return error_response(result) if result[:status] == :error
|
|
|
|
|
|
|
|
success_response(result)
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2019-10-31 11:06:41 -04:00
|
|
|
def metrics_dashboard_params
|
|
|
|
params.permit(:embedded, :grafana_url)
|
|
|
|
end
|
|
|
|
|
2019-10-10 08:06:19 -04:00
|
|
|
def query_params
|
2020-04-03 05:09:31 -04:00
|
|
|
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-10-10 08:06:19 -04:00
|
|
|
end
|
|
|
|
end
|