2018-12-05 23:21:45 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
module EnvironmentsHelper
|
2020-03-13 15:44:24 +05:30
|
|
|
include ActionView::Helpers::AssetUrlHelper
|
2019-12-04 20:38:33 +05:30
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
def environments_list_data
|
|
|
|
{
|
2017-09-10 17:25:29 +05:30
|
|
|
endpoint: project_environments_path(@project, format: :json)
|
2017-08-17 22:00:37 +05:30
|
|
|
}
|
|
|
|
end
|
2018-11-18 11:00:15 +05:30
|
|
|
|
2019-03-02 22:35:43 +05:30
|
|
|
def environments_folder_list_view_data
|
|
|
|
{
|
|
|
|
"endpoint" => folder_project_environments_path(@project, @folder, format: :json),
|
|
|
|
"folder-name" => @folder,
|
|
|
|
"can-read-environment" => can?(current_user, :read_environment, @project).to_s
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2020-04-22 19:07:51 +05:30
|
|
|
def custom_metrics_available?(project)
|
|
|
|
can?(current_user, :admin_project, project)
|
|
|
|
end
|
|
|
|
|
2018-11-18 11:00:15 +05:30
|
|
|
def metrics_data(project, environment)
|
2020-05-24 23:13:21 +05:30
|
|
|
metrics_data = {}
|
|
|
|
metrics_data.merge!(project_metrics_data(project)) if project
|
2020-07-28 23:09:34 +05:30
|
|
|
metrics_data.merge!(environment_metrics_data(environment, project)) if environment
|
2020-05-24 23:13:21 +05:30
|
|
|
metrics_data.merge!(project_and_environment_metrics_data(project, environment)) if project && environment
|
|
|
|
metrics_data.merge!(static_metrics_data)
|
|
|
|
|
|
|
|
metrics_data
|
2018-11-18 11:00:15 +05:30
|
|
|
end
|
2020-04-08 14:13:33 +05:30
|
|
|
|
|
|
|
def environment_logs_data(project, environment)
|
|
|
|
{
|
|
|
|
"environment-name": environment.name,
|
|
|
|
"environments-path": project_environments_path(project, format: :json),
|
|
|
|
"environment-id": environment.id,
|
2020-07-28 23:09:34 +05:30
|
|
|
"cluster-applications-documentation-path" => help_page_path('user/clusters/applications.md', anchor: 'elastic-stack'),
|
|
|
|
"clusters-path": project_clusters_path(project, format: :json)
|
2020-04-08 14:13:33 +05:30
|
|
|
}
|
|
|
|
end
|
2020-04-22 19:07:51 +05:30
|
|
|
|
|
|
|
def can_destroy_environment?(environment)
|
|
|
|
can?(current_user, :destroy_environment, environment)
|
|
|
|
end
|
2020-05-24 23:13:21 +05:30
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def project_metrics_data(project)
|
|
|
|
return {} unless project
|
|
|
|
|
|
|
|
{
|
|
|
|
'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)}",
|
2020-06-23 00:09:42 +05:30
|
|
|
'prometheus-alerts-available' => "#{can?(current_user, :read_prometheus_alerts, project)}",
|
|
|
|
'dashboard-timezone' => project.metrics_setting_dashboard_timezone.to_s.upcase
|
2020-05-24 23:13:21 +05:30
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
def environment_metrics_data(environment, project = nil)
|
2020-05-24 23:13:21 +05:30
|
|
|
return {} unless environment
|
|
|
|
|
|
|
|
{
|
2020-07-28 23:09:34 +05:30
|
|
|
'metrics-dashboard-base-path' => metrics_dashboard_base_path(environment, project),
|
2020-06-23 00:09:42 +05:30
|
|
|
'current-environment-name' => environment.name,
|
|
|
|
'has-metrics' => "#{environment.has_metrics?}",
|
|
|
|
'prometheus-status' => "#{environment.prometheus_status}",
|
|
|
|
'environment-state' => "#{environment.state}"
|
2020-05-24 23:13:21 +05:30
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
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-24 23:13:21 +05:30
|
|
|
def project_and_environment_metrics_data(project, environment)
|
|
|
|
return {} unless project && environment
|
|
|
|
|
|
|
|
{
|
|
|
|
'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-28 23:09:34 +05:30
|
|
|
'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
|
2020-05-24 23:13:21 +05:30
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
def static_metrics_data
|
|
|
|
{
|
|
|
|
'documentation-path' => help_page_path('administration/monitoring/prometheus/index.md'),
|
2020-07-28 23:09:34 +05:30
|
|
|
'add-dashboard-documentation-path' => help_page_path('user/project/integrations/prometheus.md', anchor: 'adding-a-new-dashboard-to-your-project'),
|
2020-05-24 23:13:21 +05:30
|
|
|
'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'),
|
2020-06-23 00:09:42 +05:30
|
|
|
'empty-unable-to-connect-svg-path' => image_path('illustrations/monitoring/unable_to_connect.svg'),
|
|
|
|
'custom-dashboard-base-path' => Metrics::Dashboard::CustomDashboardService::DASHBOARD_ROOT
|
2020-05-24 23:13:21 +05:30
|
|
|
}
|
|
|
|
end
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
2020-05-24 23:13:21 +05:30
|
|
|
|
|
|
|
EnvironmentsHelper.prepend_if_ee('::EE::EnvironmentsHelper')
|