2019-05-01 06:16:03 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module MetricsDashboardHelpers
|
2020-08-04 20:09:52 -04:00
|
|
|
# @param dashboards [Hash<string, string>] - Should contain a hash where
|
|
|
|
# each key is the path to a dashboard in the repository and each value is
|
|
|
|
# the dashboard content.
|
|
|
|
# Ex: { '.gitlab/dashboards/dashboard1.yml' => fixture_file('lib/gitlab/metrics/dashboard/sample_dashboard.yml') }
|
|
|
|
def project_with_dashboards(dashboards, project_params = {})
|
|
|
|
create(:project, :custom_repo, **project_params, files: dashboards)
|
2019-05-01 06:16:03 -04:00
|
|
|
end
|
|
|
|
|
2020-08-04 20:09:52 -04:00
|
|
|
def project_with_dashboard(dashboard_path, dashboard_yml = nil, project_params = {})
|
2020-06-30 08:08:57 -04:00
|
|
|
dashboard_yml ||= fixture_file('lib/gitlab/metrics/dashboard/sample_dashboard.yml')
|
|
|
|
|
2020-08-04 20:09:52 -04:00
|
|
|
project_with_dashboards({ dashboard_path => dashboard_yml }, project_params)
|
|
|
|
end
|
|
|
|
|
|
|
|
def project_with_dashboard_namespace(dashboard_path, dashboard_yml = nil, project_params = {})
|
|
|
|
project_with_dashboard(dashboard_path, dashboard_yml, project_params.reverse_merge(path: 'monitor-project'))
|
2020-06-30 08:08:57 -04:00
|
|
|
end
|
|
|
|
|
2019-05-01 06:16:03 -04:00
|
|
|
def delete_project_dashboard(project, user, dashboard_path)
|
|
|
|
project.repository.delete_file(
|
|
|
|
user,
|
|
|
|
dashboard_path,
|
|
|
|
branch_name: 'master',
|
|
|
|
message: 'Delete dashboard'
|
|
|
|
)
|
|
|
|
|
|
|
|
project.repository.refresh_method_caches([:metrics_dashboard])
|
|
|
|
end
|
|
|
|
|
2020-06-18 11:08:45 -04:00
|
|
|
def load_sample_dashboard
|
2020-06-26 20:09:17 -04:00
|
|
|
load_dashboard_yaml(fixture_file('lib/gitlab/metrics/dashboard/sample_dashboard.yml'))
|
|
|
|
end
|
|
|
|
|
|
|
|
def load_dashboard_yaml(data)
|
|
|
|
::Gitlab::Config::Loader::Yaml.new(data).load_raw!
|
2020-06-18 11:08:45 -04:00
|
|
|
end
|
|
|
|
|
2019-08-07 12:17:35 -04:00
|
|
|
def system_dashboard_path
|
2019-11-27 07:06:30 -05:00
|
|
|
Metrics::Dashboard::SystemDashboardService::DASHBOARD_PATH
|
2019-08-07 12:17:35 -04:00
|
|
|
end
|
|
|
|
|
2019-12-17 07:08:11 -05:00
|
|
|
def pod_dashboard_path
|
|
|
|
Metrics::Dashboard::PodDashboardService::DASHBOARD_PATH
|
|
|
|
end
|
|
|
|
|
2019-08-07 12:17:35 -04:00
|
|
|
def business_metric_title
|
2020-08-24 17:10:17 -04:00
|
|
|
Enums::PrometheusMetric.group_details[:business][:group_title]
|
2019-08-07 12:17:35 -04:00
|
|
|
end
|
2020-02-13 10:08:52 -05:00
|
|
|
|
|
|
|
def self_monitoring_dashboard_path
|
|
|
|
Metrics::Dashboard::SelfMonitoringDashboardService::DASHBOARD_PATH
|
|
|
|
end
|
2019-05-01 06:16:03 -04:00
|
|
|
end
|