2020-07-05 23:09:07 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
module Projects
|
|
|
|
class MetricsDashboardController < Projects::ApplicationController
|
|
|
|
# Metrics dashboard code is in the process of being decoupled from environments
|
|
|
|
# and is getting moved to this controller. Some code may be duplicated from
|
|
|
|
# app/controllers/projects/environments_controller.rb
|
|
|
|
# See https://gitlab.com/gitlab-org/gitlab/-/issues/226002 for more details.
|
|
|
|
|
2020-08-28 08:10:37 -04:00
|
|
|
include Gitlab::Utils::StrongMemoize
|
|
|
|
|
2020-07-05 23:09:07 -04:00
|
|
|
before_action :authorize_metrics_dashboard!
|
|
|
|
before_action do
|
|
|
|
push_frontend_feature_flag(:prometheus_computed_alerts)
|
2020-07-17 11:09:13 -04:00
|
|
|
push_frontend_feature_flag(:disable_metric_dashboard_refresh_rate)
|
2020-07-05 23:09:07 -04:00
|
|
|
end
|
|
|
|
|
2020-10-08 14:08:32 -04:00
|
|
|
feature_category :metrics
|
|
|
|
|
2020-07-05 23:09:07 -04:00
|
|
|
def show
|
|
|
|
if environment
|
|
|
|
render 'projects/environments/metrics'
|
2020-08-28 08:10:37 -04:00
|
|
|
elsif default_environment
|
2020-08-31 11:10:41 -04:00
|
|
|
redirect_to project_metrics_dashboard_path(
|
|
|
|
project,
|
2020-09-07 14:08:32 -04:00
|
|
|
# Reverse merge the query parameters so that a query parameter named dashboard_path doesn't
|
|
|
|
# override the dashboard_path path parameter.
|
|
|
|
**permitted_params.to_h.symbolize_keys
|
|
|
|
.merge(environment: default_environment.id)
|
|
|
|
.reverse_merge(request.query_parameters.symbolize_keys)
|
2020-08-31 11:10:41 -04:00
|
|
|
)
|
2020-07-05 23:09:07 -04:00
|
|
|
else
|
2020-08-12 23:10:13 -04:00
|
|
|
render 'projects/environments/empty_metrics'
|
2020-07-05 23:09:07 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2020-08-31 11:10:41 -04:00
|
|
|
def permitted_params
|
|
|
|
@permitted_params ||= params.permit(:dashboard_path, :environment, :page)
|
|
|
|
end
|
|
|
|
|
2020-07-05 23:09:07 -04:00
|
|
|
def environment
|
2020-08-28 08:10:37 -04:00
|
|
|
strong_memoize(:environment) do
|
2020-08-31 11:10:41 -04:00
|
|
|
env = permitted_params[:environment]
|
|
|
|
project.environments.find(env) if env
|
2020-08-28 08:10:37 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def default_environment
|
|
|
|
strong_memoize(:default_environment) do
|
|
|
|
project.default_environment
|
|
|
|
end
|
2020-07-05 23:09:07 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|