diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-05-08 12:09:39 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-05-08 12:09:39 +0300 |
commit | 5bdbc604c8a08f827c3833e2c28ec0c299bb41fc (patch) | |
tree | 1fbf5e5dc3bff54d371baa15775371ebc8525f62 /app/presenters/projects | |
parent | 79ddf163588de2d9a7f1cc27262dc1a14503f619 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/presenters/projects')
-rw-r--r-- | app/presenters/projects/prometheus/alert_presenter.rb | 61 |
1 files changed, 58 insertions, 3 deletions
diff --git a/app/presenters/projects/prometheus/alert_presenter.rb b/app/presenters/projects/prometheus/alert_presenter.rb index c03925c0871..2114e06a8c5 100644 --- a/app/presenters/projects/prometheus/alert_presenter.rb +++ b/app/presenters/projects/prometheus/alert_presenter.rb @@ -7,6 +7,7 @@ module Projects GENERIC_ALERT_SUMMARY_ANNOTATIONS = %w(monitoring_tool service hosts).freeze MARKDOWN_LINE_BREAK = " \n".freeze INCIDENT_LABEL_NAME = IncidentManagement::CreateIssueService::INCIDENT_LABEL[:title].freeze + METRIC_TIME_WINDOW = 30.minutes def full_title [environment_name, alert_title].compact.join(': ') @@ -119,9 +120,63 @@ module Projects Array(hosts.value).join(' ') end - def metric_embed_for_alert; end + def metric_embed_for_alert + url = embed_url_for_gitlab_alert || embed_url_for_self_managed_alert + + "\n[](#{url})" if url + end + + def embed_url_for_gitlab_alert + return unless gitlab_alert + + metrics_dashboard_project_prometheus_alert_url( + project, + gitlab_alert.prometheus_metric_id, + environment_id: environment.id, + **alert_embed_window_params(embed_time) + ) + end + + def embed_url_for_self_managed_alert + return unless environment && full_query && title + + metrics_dashboard_project_environment_url( + project, + environment, + embed_json: dashboard_for_self_managed_alert.to_json, + **alert_embed_window_params(embed_time) + ) + end + + def embed_time + starts_at ? Time.rfc3339(starts_at) : Time.current + end + + def alert_embed_window_params(time) + { + start: format_embed_timestamp(time - METRIC_TIME_WINDOW), + end: format_embed_timestamp(time + METRIC_TIME_WINDOW) + } + end + + def format_embed_timestamp(time) + time.utc.strftime('%FT%TZ') + end + + def dashboard_for_self_managed_alert + { + panel_groups: [{ + panels: [{ + type: 'line-graph', + title: title, + y_label: y_label, + metrics: [{ + query_range: full_query + }] + }] + }] + } + end end end end - -Projects::Prometheus::AlertPresenter.prepend_if_ee('EE::Projects::Prometheus::AlertPresenter') |