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-07-01 17:08:51 -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-07-01 17:08:51 -04:00
|
|
|
"environment-name": environment.name,
|
|
|
|
"environments-path": project_environments_path(project, format: :json),
|
|
|
|
"environment-id": environment.id,
|
2020-07-14 11:09:05 -04:00
|
|
|
"cluster-applications-documentation-path" => help_page_path('user/clusters/applications.md', anchor: 'elastic-stack'),
|
|
|
|
"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
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def project_metrics_data(project)
|
|
|
|
return {} unless project
|
|
|
|
|
|
|
|
{
|
2020-07-01 17:08:51 -04:00
|
|
|
'settings-path' => edit_project_service_path(project, 'prometheus'),
|
|
|
|
'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)}",
|
|
|
|
'prometheus-alerts-available' => "#{can?(current_user, :read_prometheus_alerts, project)}",
|
|
|
|
'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-07-15 05:09:34 -04:00
|
|
|
'metrics-dashboard-base-path' => metrics_dashboard_base_path(environment, project),
|
2020-07-01 17:08:51 -04:00
|
|
|
'current-environment-name' => environment.name,
|
|
|
|
'has-metrics' => "#{environment.has_metrics?}",
|
|
|
|
'prometheus-status' => "#{environment.prometheus_status}",
|
|
|
|
'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
|
|
|
|
|
|
|
|
environment_metrics_path(environment)
|
|
|
|
end
|
|
|
|
|
2020-05-15 17:08:21 -04:00
|
|
|
def project_and_environment_metrics_data(project, environment)
|
|
|
|
return {} unless project && environment
|
|
|
|
|
|
|
|
{
|
2020-07-01 17:08:51 -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),
|
2020-07-09 05:09:27 -04:00
|
|
|
'alerts-endpoint' => project_prometheus_alerts_path(project, environment_id: environment.id, format: :json),
|
|
|
|
'operations-settings-path' => project_settings_operations_path(project),
|
2020-08-04 14:09:49 -04:00
|
|
|
'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-07-01 17:08:51 -04:00
|
|
|
'documentation-path' => help_page_path('administration/monitoring/prometheus/index.md'),
|
2020-07-29 20:09:53 -04:00
|
|
|
'add-dashboard-documentation-path' => help_page_path('operations/metrics/dashboards/index.md', anchor: 'add-a-new-dashboard-to-your-project'),
|
2020-07-01 17:08:51 -04:00
|
|
|
'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'),
|
2020-07-30 20:09:37 -04:00
|
|
|
'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
|
|
|
|
|
|
|
EnvironmentsHelper.prepend_if_ee('::EE::EnvironmentsHelper')
|