Class: Gitlab::Metrics::Dashboard::Finder

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab/metrics/dashboard/finder.rb

Constant Summary collapse

PREDEFINED_DASHBOARD_EXCLUSION_LIST =

Dashboards that should not be part of the list of all dashboards displayed on the metrics dashboard page.

[
  # This dashboard is only useful in the self monitoring project.
  ::Metrics::Dashboard::SelfMonitoringDashboardService,

  # This dashboard is displayed on the K8s cluster settings health page.
  ::Metrics::Dashboard::ClusterDashboardService
].freeze

Class Method Summary collapse

Class Method Details

.find(project, user, options = {}) ⇒ Hash

Returns a formatted dashboard packed with DB info.

Parameters:

  • project (Project)
  • user (User)
  • environment (Environment)
  • options (Hash<Symbol,Any>) (defaults to: {})
  • options (defaults to: {})
    • embedded [Boolean] Determines whether the

    dashboard is to be rendered as part of an issue or location other than the primary metrics dashboard UI. Returns only the Memory/CPU charts of the system dash.

  • options (defaults to: {})
    • dashboard_path [String] Path at which the

    dashboard can be found. Nil values will default to the system dashboard.

  • options (defaults to: {})
    • group [String, Group] Title of the group

    to which a panel might belong. Used by embedded dashboards. If cluster dashboard, refers to the Group corresponding to the cluster.

  • options (defaults to: {})
    • title [String] Title of the panel.

    Used by embedded dashboards.

  • options (defaults to: {})
    • y_label [String] Y-Axis label of

    a panel. Used by embedded dashboards.

  • options (defaults to: {})
    • cluster [Cluster]. Used by

    embedded and un-embedded dashboards.

  • options (defaults to: {})
    • cluster_type [Symbol] The level of

    cluster, one of [:admin, :project, :group]. Used by embedded and un-embedded dashboards.

  • options (defaults to: {})
    • grafana_url [String] URL pointing

    to a grafana dashboard panel

  • options (defaults to: {})
    • prometheus_alert_id [Integer] ID of

    a PrometheusAlert. For dashboard embeds.

Returns:

  • (Hash)

52
53
54
55
56
# File 'lib/gitlab/metrics/dashboard/finder.rb', line 52

def find(project, user, options = {})
  service_for(options)
    .new(project, user, options)
    .get_dashboard
end

.find_all_paths(project) ⇒ Array<Hash>

Summary of all known dashboards.

Returns:

  • (Array<Hash>)

    ex) [{ path: String, display_name: String, default: Boolean }]


71
72
73
74
75
76
77
# File 'lib/gitlab/metrics/dashboard/finder.rb', line 71

def find_all_paths(project)
  dashboards = user_facing_dashboard_services(project).flat_map do |service|
    service.all_dashboard_paths(project)
  end

  Gitlab::Utils.stable_sort_by(dashboards) { |dashboard| dashboard[:display_name].downcase }
end

.find_raw(project, dashboard_path: nil) ⇒ Hash

Returns a dashboard without any supplemental info. Returns only full, yml-defined dashboards.

Returns:

  • (Hash)

61
62
63
64
65
# File 'lib/gitlab/metrics/dashboard/finder.rb', line 61

def find_raw(project, dashboard_path: nil)
  service_for(dashboard_path: dashboard_path)
    .new(project, nil, dashboard_path: dashboard_path)
    .raw_dashboard
end