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 ...@@ -45,8 +45,8 @@ module Projects
project_issues_url(project, label_name: INCIDENT_LABEL_NAME) project_issues_url(project, label_name: INCIDENT_LABEL_NAME)
end end
def starts_at def start_time
super&.rfc3339 starts_at&.strftime('%d %B %Y, %-l:%M%p (%Z)')
end end
def issue_summary_markdown def issue_summary_markdown
...@@ -73,7 +73,7 @@ module Projects ...@@ -73,7 +73,7 @@ module Projects
def metadata_list def metadata_list
metadata = [] 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('full_query', backtick(full_query)) if full_query
metadata << list_item(service.label.humanize, service.value) if service metadata << list_item(service.label.humanize, service.value) if service
metadata << list_item(monitoring_tool.label.humanize, monitoring_tool.value) if monitoring_tool metadata << list_item(monitoring_tool.label.humanize, monitoring_tool.value) if monitoring_tool
...@@ -149,7 +149,7 @@ module Projects ...@@ -149,7 +149,7 @@ module Projects
end end
def embed_time def embed_time
starts_at ? Time.rfc3339(starts_at) : Time.current starts_at || Time.current
end end
def alert_embed_window_params(time) 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 ...@@ -173,7 +173,10 @@ module Gitlab
value = payload&.dig(field) value = payload&.dig(field)
return unless value 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 rescue ArgumentError
end end
......
...@@ -24,18 +24,25 @@ describe Projects::Prometheus::AlertPresenter do ...@@ -24,18 +24,25 @@ describe Projects::Prometheus::AlertPresenter do
it { is_expected.to eq(project.full_path) } it { is_expected.to eq(project.full_path) }
end end
describe '#starts_at' do describe '#start_time' do
subject { presenter.starts_at } subject { presenter.start_time }
let(:starts_at) { '2020-10-31T14:02:04Z' }
before do before do
payload['startsAt'] = starts_at payload['startsAt'] = starts_at
end end
context 'with valid datetime' do context 'with valid utc datetime' do
let(:datetime) { Time.now } it { is_expected.to eq('31 October 2020, 2:02PM (UTC)') }
let(:starts_at) { datetime.rfc3339 }
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 end
context 'with invalid datetime' do context 'with invalid datetime' do
...@@ -56,7 +63,7 @@ describe Projects::Prometheus::AlertPresenter do ...@@ -56,7 +63,7 @@ describe Projects::Prometheus::AlertPresenter do
<<~MARKDOWN.chomp <<~MARKDOWN.chomp
#### Summary #### Summary
**Start time:** #{presenter.starts_at} **Start time:** #{presenter.start_time}
MARKDOWN MARKDOWN
) )
...@@ -73,7 +80,7 @@ describe Projects::Prometheus::AlertPresenter do ...@@ -73,7 +80,7 @@ describe Projects::Prometheus::AlertPresenter do
<<~MARKDOWN.chomp <<~MARKDOWN.chomp
#### Summary #### Summary
**Start time:** #{presenter.starts_at} **Start time:** #{presenter.start_time}
#### Alert Details #### Alert Details
...@@ -94,7 +101,7 @@ describe Projects::Prometheus::AlertPresenter do ...@@ -94,7 +101,7 @@ describe Projects::Prometheus::AlertPresenter do
<<~MARKDOWN.chomp <<~MARKDOWN.chomp
#### Summary #### Summary
**Start time:** #{presenter.starts_at}#{markdown_line_break} **Start time:** #{presenter.start_time}#{markdown_line_break}
**full_query:** `query` **full_query:** `query`
MARKDOWN MARKDOWN
...@@ -122,7 +129,7 @@ describe Projects::Prometheus::AlertPresenter do ...@@ -122,7 +129,7 @@ describe Projects::Prometheus::AlertPresenter do
<<~MARKDOWN.chomp <<~MARKDOWN.chomp
#### Summary #### Summary
**Start time:** #{presenter.starts_at}#{markdown_line_break} **Start time:** #{presenter.start_time}#{markdown_line_break}
**Service:** service_name#{markdown_line_break} **Service:** service_name#{markdown_line_break}
**Monitoring tool:** monitoring_tool_name#{markdown_line_break} **Monitoring tool:** monitoring_tool_name#{markdown_line_break}
**Hosts:** http://localhost:3000 http://localhost:3001 **Hosts:** http://localhost:3000 http://localhost:3001
...@@ -144,7 +151,7 @@ describe Projects::Prometheus::AlertPresenter do ...@@ -144,7 +151,7 @@ describe Projects::Prometheus::AlertPresenter do
<<~MARKDOWN.chomp <<~MARKDOWN.chomp
#### Summary #### Summary
**Start time:** #{presenter.starts_at}#{markdown_line_break} **Start time:** #{presenter.start_time}#{markdown_line_break}
**Hosts:** http://localhost:3000 **Hosts:** http://localhost:3000
MARKDOWN MARKDOWN
...@@ -161,7 +168,7 @@ describe Projects::Prometheus::AlertPresenter do ...@@ -161,7 +168,7 @@ describe Projects::Prometheus::AlertPresenter do
<<~MARKDOWN.chomp <<~MARKDOWN.chomp
#### Summary #### Summary
**Start time:** #{presenter.starts_at}#{markdown_line_break} **Start time:** #{presenter.start_time}#{markdown_line_break}
**full_query:** `avg(metric) > 1.0` **full_query:** `avg(metric) > 1.0`
[](#{url}) [](#{url})
...@@ -253,7 +260,7 @@ describe Projects::Prometheus::AlertPresenter do ...@@ -253,7 +260,7 @@ describe Projects::Prometheus::AlertPresenter do
<<~MARKDOWN.chomp <<~MARKDOWN.chomp
#### Summary #### Summary
**Start time:** #{presenter.starts_at}#{markdown_line_break} **Start time:** #{presenter.start_time}#{markdown_line_break}
**full_query:** `avg(metric) > 1.0` **full_query:** `avg(metric) > 1.0`
MARKDOWN MARKDOWN
...@@ -280,7 +287,7 @@ describe Projects::Prometheus::AlertPresenter do ...@@ -280,7 +287,7 @@ describe Projects::Prometheus::AlertPresenter do
<<~MARKDOWN.chomp <<~MARKDOWN.chomp
#### Summary #### Summary
**Start time:** #{presenter.starts_at} **Start time:** #{presenter.start_time}
MARKDOWN MARKDOWN
end 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