Class: Projects::Prometheus::AlertPresenter

Inherits:
Gitlab::View::Presenter::Delegated show all
Defined in:
app/presenters/projects/prometheus/alert_presenter.rb

Constant Summary collapse

GENERIC_ALERT_SUMMARY_ANNOTATIONS =
%w(monitoring_tool service hosts).freeze
MARKDOWN_LINE_BREAK =
"  \n".freeze
INCIDENT_LABEL_NAME =
::IncidentManagement::CreateIncidentLabelService::LABEL_PROPERTIES[:title].freeze
METRIC_TIME_WINDOW =
30.minutes

Instance Attribute Summary

Attributes included from Gitlab::View::Presenter::Base

#subject

Instance Method Summary collapse

Methods inherited from Gitlab::View::Presenter::Delegated

#initialize

Methods included from Gitlab::View::Presenter::Base

#can?, #declarative_policy_delegate, #is_a?, #present, #url_builder, #web_path, #web_url

Methods included from Gitlab::Allowable

#can?

Methods included from Gitlab::Routing

add_helpers, includes_helpers, redirect_legacy_paths, url_helpers

Constructor Details

This class inherits a constructor from Gitlab::View::Presenter::Delegated

Instance Method Details

#details_listObject


58
59
60
61
62
63
64
# File 'app/presenters/projects/prometheus/alert_presenter.rb', line 58

def details_list
  strong_memoize(:details_list) do
    details
      .map { |label, value| list_item(label, value) }
      .join(MARKDOWN_LINE_BREAK)
  end
end

#details_urlObject


76
77
78
79
80
81
82
83
# File 'app/presenters/projects/prometheus/alert_presenter.rb', line 76

def details_url
  return unless am_alert

  ::Gitlab::Routing.url_helpers.details_project_alert_management_url(
    project,
    am_alert.iid
  )
end

#environment_nameObject


23
24
25
# File 'app/presenters/projects/prometheus/alert_presenter.rb', line 23

def environment_name
  environment&.name
end

#full_titleObject


11
12
13
# File 'app/presenters/projects/prometheus/alert_presenter.rb', line 11

def full_title
  [environment_name, alert_title].compact.join(': ')
end

43
44
45
# File 'app/presenters/projects/prometheus/alert_presenter.rb', line 43

def incident_issues_link
  project_issues_url(project, label_name: INCIDENT_LABEL_NAME)
end

#issue_summary_markdownObject


51
52
53
54
55
56
# File 'app/presenters/projects/prometheus/alert_presenter.rb', line 51

def issue_summary_markdown
  <<~MARKDOWN.chomp
    #{}
    #{alert_details}#{metric_embed_for_alert}
  MARKDOWN
end

#metric_embed_for_alertObject


66
67
68
# File 'app/presenters/projects/prometheus/alert_presenter.rb', line 66

def metric_embed_for_alert
  "\n[](#{metrics_dashboard_url})" if metrics_dashboard_url
end

#metric_queryObject


19
20
21
# File 'app/presenters/projects/prometheus/alert_presenter.rb', line 19

def metric_query
  gitlab_alert&.full_query
end

#metrics_dashboard_urlObject


70
71
72
73
74
# File 'app/presenters/projects/prometheus/alert_presenter.rb', line 70

def metrics_dashboard_url
  strong_memoize(:metrics_dashboard_url) do
    embed_url_for_gitlab_alert || embed_url_for_self_managed_alert
  end
end

27
28
29
30
31
32
33
# File 'app/presenters/projects/prometheus/alert_presenter.rb', line 27

def performance_dashboard_link
  if environment
    metrics_project_environment_url(project, environment)
  else
    metrics_project_environments_url(project)
  end
end

#project_full_pathObject


15
16
17
# File 'app/presenters/projects/prometheus/alert_presenter.rb', line 15

def project_full_path
  project.full_path
end

#show_incident_issues_link?Boolean

Returns:

  • (Boolean)

39
40
41
# File 'app/presenters/projects/prometheus/alert_presenter.rb', line 39

def show_incident_issues_link?
  project.incident_management_setting&.create_issue?
end

#show_performance_dashboard_link?Boolean

Returns:

  • (Boolean)

35
36
37
# File 'app/presenters/projects/prometheus/alert_presenter.rb', line 35

def show_performance_dashboard_link?
  gitlab_alert.present?
end

#start_timeObject


47
48
49
# File 'app/presenters/projects/prometheus/alert_presenter.rb', line 47

def start_time
  starts_at&.strftime('%d %B %Y, %-l:%M%p (%Z)')
end