Commit 990a82f9 authored by Allison Browne's avatar Allison Browne Committed by Peter Leitzen

Add new start_time display value

Add start_time to the alert presenter
parent b8b06f53
......@@ -45,8 +45,8 @@ module Projects
project_issues_url(project, label_name: INCIDENT_LABEL_NAME)
end
def starts_at
super&.rfc3339
def start_time
starts_at&.strftime('%d %B %Y, %-l:%M%p (%Z)')
end
def issue_summary_markdown
......@@ -73,7 +73,7 @@ module Projects
def metadata_list
metadata = []
metadata << list_item('Start time', starts_at) if starts_at
metadata << list_item('Start time', start_time) if start_time
metadata << list_item('full_query', backtick(full_query)) if full_query
metadata << list_item(service.label.humanize, service.value) if service
metadata << list_item(monitoring_tool.label.humanize, monitoring_tool.value) if monitoring_tool
......@@ -149,7 +149,7 @@ module Projects
end
def embed_time
starts_at ? Time.rfc3339(starts_at) : Time.current
starts_at || Time.current
end
def alert_embed_window_params(time)
......
---
title: Add timezone display to alert based issue start time
merge_request: 32702
author:
type: added
......@@ -173,7 +173,10 @@ module Gitlab
value = payload&.dig(field)
return unless value
Time.rfc3339(value)
# value is a rfc3339 timestamp
# Timestamps from Prometheus and Alertmanager are UTC RFC3339 timestamps like: '2018-03-12T09:06:00Z' (Z represents 0 offset or UTC)
# .utc sets the datetime zone to `UTC`
Time.rfc3339(value).utc
rescue ArgumentError
end
......
......@@ -24,18 +24,25 @@ describe Projects::Prometheus::AlertPresenter do
it { is_expected.to eq(project.full_path) }
end
describe '#starts_at' do
subject { presenter.starts_at }
describe '#start_time' do
subject { presenter.start_time }
let(:starts_at) { '2020-10-31T14:02:04Z' }
before do
payload['startsAt'] = starts_at
end
context 'with valid datetime' do
let(:datetime) { Time.now }
let(:starts_at) { datetime.rfc3339 }
context 'with valid utc datetime' do
it { is_expected.to eq('31 October 2020, 2:02PM (UTC)') }
it { is_expected.to eq(datetime.rfc3339) }
context 'with admin time zone not UTC' do
before do
allow(Time).to receive(:zone).and_return(ActiveSupport::TimeZone.new('Perth'))
end
it { is_expected.to eq('31 October 2020, 2:02PM (UTC)') }
end
end
context 'with invalid datetime' do
......@@ -56,7 +63,7 @@ describe Projects::Prometheus::AlertPresenter do
<<~MARKDOWN.chomp
#### Summary
**Start time:** #{presenter.starts_at}
**Start time:** #{presenter.start_time}
MARKDOWN
)
......@@ -73,7 +80,7 @@ describe Projects::Prometheus::AlertPresenter do
<<~MARKDOWN.chomp
#### Summary
**Start time:** #{presenter.starts_at}
**Start time:** #{presenter.start_time}
#### Alert Details
......@@ -94,7 +101,7 @@ describe Projects::Prometheus::AlertPresenter do
<<~MARKDOWN.chomp
#### Summary
**Start time:** #{presenter.starts_at}#{markdown_line_break}
**Start time:** #{presenter.start_time}#{markdown_line_break}
**full_query:** `query`
MARKDOWN
......@@ -122,7 +129,7 @@ describe Projects::Prometheus::AlertPresenter do
<<~MARKDOWN.chomp
#### Summary
**Start time:** #{presenter.starts_at}#{markdown_line_break}
**Start time:** #{presenter.start_time}#{markdown_line_break}
**Service:** service_name#{markdown_line_break}
**Monitoring tool:** monitoring_tool_name#{markdown_line_break}
**Hosts:** http://localhost:3000 http://localhost:3001
......@@ -144,7 +151,7 @@ describe Projects::Prometheus::AlertPresenter do
<<~MARKDOWN.chomp
#### Summary
**Start time:** #{presenter.starts_at}#{markdown_line_break}
**Start time:** #{presenter.start_time}#{markdown_line_break}
**Hosts:** http://localhost:3000
MARKDOWN
......@@ -161,7 +168,7 @@ describe Projects::Prometheus::AlertPresenter do
<<~MARKDOWN.chomp
#### Summary
**Start time:** #{presenter.starts_at}#{markdown_line_break}
**Start time:** #{presenter.start_time}#{markdown_line_break}
**full_query:** `avg(metric) > 1.0`
[](#{url})
......@@ -253,7 +260,7 @@ describe Projects::Prometheus::AlertPresenter do
<<~MARKDOWN.chomp
#### Summary
**Start time:** #{presenter.starts_at}#{markdown_line_break}
**Start time:** #{presenter.start_time}#{markdown_line_break}
**full_query:** `avg(metric) > 1.0`
MARKDOWN
......@@ -280,7 +287,7 @@ describe Projects::Prometheus::AlertPresenter do
<<~MARKDOWN.chomp
#### Summary
**Start time:** #{presenter.starts_at}
**Start time:** #{presenter.start_time}
MARKDOWN
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment