2018-08-18 07:19:57 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-10-14 08:15:29 -04:00
|
|
|
module EnvironmentsHelper
|
2020-02-14 13:08:45 -05:00
|
|
|
include ActionView::Helpers::AssetUrlHelper
|
2019-09-13 09:26:31 -04:00
|
|
|
|
2016-11-15 05:12:59 -05:00
|
|
|
def environments_list_data
|
2016-10-14 08:15:29 -04:00
|
|
|
{
|
2017-06-29 13:06:35 -04:00
|
|
|
endpoint: project_environments_path(@project, format: :json)
|
2016-10-14 08:15:29 -04:00
|
|
|
}
|
|
|
|
end
|
2018-06-25 05:57:29 -04:00
|
|
|
|
2019-01-11 11:14:49 -05:00
|
|
|
def environments_folder_list_view_data
|
|
|
|
{
|
|
|
|
"endpoint" => folder_project_environments_path(@project, @folder, format: :json),
|
2020-08-21 08:10:22 -04:00
|
|
|
"folder_name" => @folder,
|
|
|
|
"can_read_environment" => can?(current_user, :read_environment, @project).to_s
|
2019-01-11 11:14:49 -05:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2020-04-07 08:09:34 -04:00
|
|
|
def custom_metrics_available?(project)
|
|
|
|
can?(current_user, :admin_project, project)
|
|
|
|
end
|
|
|
|
|
2018-06-25 05:57:29 -04:00
|
|
|
def metrics_data(project, environment)
|
2020-05-15 17:08:21 -04:00
|
|
|
metrics_data = {}
|
|
|
|
metrics_data.merge!(project_metrics_data(project)) if project
|
2020-07-15 05:09:34 -04:00
|
|
|
metrics_data.merge!(environment_metrics_data(environment, project)) if environment
|
2020-05-15 17:08:21 -04:00
|
|
|
metrics_data.merge!(project_and_environment_metrics_data(project, environment)) if project && environment
|
|
|
|
metrics_data.merge!(static_metrics_data)
|
|
|
|
|
|
|
|
metrics_data
|
2018-06-25 05:57:29 -04:00
|
|
|
end
|
2020-03-11 11:09:37 -04:00
|
|
|
|
|
|
|
def environment_logs_data(project, environment)
|
|
|
|
{
|
2020-08-21 08:10:22 -04:00
|
|
|
"environment_name": environment.name,
|
2021-05-13 11:10:20 -04:00
|
|
|
"environments_path": api_v4_projects_environments_path(id: project.id),
|
2020-08-21 08:10:22 -04:00
|
|
|
"environment_id": environment.id,
|
2021-06-08 17:10:05 -04:00
|
|
|
"cluster_applications_documentation_path" => help_page_path('user/clusters/integrations.md', anchor: 'elastic-stack-cluster-integration'),
|
2020-08-21 08:10:22 -04:00
|
|
|
"clusters_path": project_clusters_path(project, format: :json)
|
2020-03-11 11:09:37 -04:00
|
|
|
}
|
|
|
|
end
|
2020-03-25 05:08:11 -04:00
|
|
|
|
|
|
|
def can_destroy_environment?(environment)
|
|
|
|
can?(current_user, :destroy_environment, environment)
|
|
|
|
end
|
2020-05-15 17:08:21 -04:00
|
|
|
|
2021-07-23 05:08:49 -04:00
|
|
|
def environment_data(environment)
|
|
|
|
Gitlab::Json.generate({
|
|
|
|
id: environment.id,
|
|
|
|
name: environment.name,
|
|
|
|
external_url: environment.external_url
|
|
|
|
})
|
|
|
|
end
|
|
|
|
|
2020-05-15 17:08:21 -04:00
|
|
|
private
|
|
|
|
|
|
|
|
def project_metrics_data(project)
|
|
|
|
return {} unless project
|
|
|
|
|
|
|
|
{
|
2021-12-30 13:13:34 -05:00
|
|
|
'settings_path' => edit_project_integration_path(project, 'prometheus'),
|
2020-08-21 08:10:22 -04:00
|
|
|
'clusters_path' => project_clusters_path(project),
|
|
|
|
'dashboards_endpoint' => project_performance_monitoring_dashboards_path(project, format: :json),
|
|
|
|
'default_branch' => project.default_branch,
|
|
|
|
'project_path' => project_path(project),
|
|
|
|
'tags_path' => project_tags_path(project),
|
|
|
|
'external_dashboard_url' => project.metrics_setting_external_dashboard_url,
|
|
|
|
'custom_metrics_path' => project_prometheus_metrics_path(project),
|
|
|
|
'validate_query_path' => validate_query_project_prometheus_metrics_path(project),
|
|
|
|
'custom_metrics_available' => "#{custom_metrics_available?(project)}",
|
2021-10-21 14:10:11 -04:00
|
|
|
'dashboard_timezone' => project.metrics_setting_dashboard_timezone.to_s.upcase
|
2020-05-15 17:08:21 -04:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2020-07-15 05:09:34 -04:00
|
|
|
def environment_metrics_data(environment, project = nil)
|
2020-05-15 17:08:21 -04:00
|
|
|
return {} unless environment
|
|
|
|
|
|
|
|
{
|
2020-08-21 08:10:22 -04:00
|
|
|
'metrics_dashboard_base_path' => metrics_dashboard_base_path(environment, project),
|
|
|
|
'current_environment_name' => environment.name,
|
|
|
|
'has_metrics' => "#{environment.has_metrics?}",
|
|
|
|
'environment_state' => "#{environment.state}"
|
2020-05-15 17:08:21 -04:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2020-07-15 05:09:34 -04:00
|
|
|
def metrics_dashboard_base_path(environment, project)
|
|
|
|
# This is needed to support our transition from environment scoped metric paths to project scoped.
|
|
|
|
if project
|
|
|
|
path = project_metrics_dashboard_path(project)
|
|
|
|
|
|
|
|
return path if request.path.include?(path)
|
|
|
|
end
|
|
|
|
|
2022-04-08 05:08:18 -04:00
|
|
|
project_metrics_dashboard_path(project, environment: environment)
|
2020-07-15 05:09:34 -04:00
|
|
|
end
|
|
|
|
|
2020-05-15 17:08:21 -04:00
|
|
|
def project_and_environment_metrics_data(project, environment)
|
|
|
|
return {} unless project && environment
|
|
|
|
|
|
|
|
{
|
2020-08-21 08:10:22 -04:00
|
|
|
'metrics_endpoint' => additional_metrics_project_environment_path(project, environment, format: :json),
|
|
|
|
'dashboard_endpoint' => metrics_dashboard_project_environment_path(project, environment, format: :json),
|
|
|
|
'deployments_endpoint' => project_environment_deployments_path(project, environment, format: :json),
|
|
|
|
'alerts_endpoint' => project_prometheus_alerts_path(project, environment_id: environment.id, format: :json),
|
|
|
|
'operations_settings_path' => project_settings_operations_path(project),
|
|
|
|
'can_access_operations_settings' => can?(current_user, :admin_operations, project).to_s,
|
|
|
|
'panel_preview_endpoint' => project_metrics_dashboards_builder_path(project, format: :json)
|
2020-05-15 17:08:21 -04:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
def static_metrics_data
|
|
|
|
{
|
2020-08-21 08:10:22 -04:00
|
|
|
'documentation_path' => help_page_path('administration/monitoring/prometheus/index.md'),
|
|
|
|
'add_dashboard_documentation_path' => help_page_path('operations/metrics/dashboards/index.md', anchor: 'add-a-new-dashboard-to-your-project'),
|
|
|
|
'empty_getting_started_svg_path' => image_path('illustrations/monitoring/getting_started.svg'),
|
|
|
|
'empty_loading_svg_path' => image_path('illustrations/monitoring/loading.svg'),
|
|
|
|
'empty_no_data_svg_path' => image_path('illustrations/monitoring/no_data.svg'),
|
|
|
|
'empty_no_data_small_svg_path' => image_path('illustrations/chart-empty-state-small.svg'),
|
|
|
|
'empty_unable_to_connect_svg_path' => image_path('illustrations/monitoring/unable_to_connect.svg'),
|
|
|
|
'custom_dashboard_base_path' => Gitlab::Metrics::Dashboard::RepoDashboardFinder::DASHBOARD_ROOT
|
2020-05-15 17:08:21 -04:00
|
|
|
}
|
|
|
|
end
|
2016-10-20 07:09:35 -04:00
|
|
|
end
|
2020-04-22 20:09:41 -04:00
|
|
|
|
2021-05-11 17:10:21 -04:00
|
|
|
EnvironmentsHelper.prepend_mod_with('EnvironmentsHelper')
|