-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #448 from LD4P/analytics/historical
Add chart showing simulated graph (in table) of the last 30 days of up-down connection data
- Loading branch information
Showing
14 changed files
with
409 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
app/presenters/qa_server/monitor_status/history_up_down_presenter.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
# frozen_string_literal: true | ||
# This presenter class provides historical testing data needed by the view that monitors status of authorities. | ||
module QaServer::MonitorStatus | ||
class HistoryUpDownPresenter | ||
attr_reader :historical_up_down_data | ||
|
||
# @param parent [QaServer::MonitorStatusPresenter] parent presenter | ||
# @param historical_up_down_data [Hash<Array>] recent connection status of queries (typically last 30 days) | ||
# @example historical_up_down_data | ||
# { 'AGROVOC' = [ | ||
# :FULLY_UP, # 0 - today | ||
# :MOSTLY_UP, # 1 - yesterday | ||
# :MOSTLY_UP, # 2 - two days ago | ||
# :FULLY_UP, # 3 - three days ago | ||
# :DOWN, # 4 - four days ago | ||
# ... # etc. | ||
# ], | ||
# 'CERL' = [ ... ] | ||
# } | ||
def initialize(parent:, historical_up_down_data:) | ||
@parent = parent | ||
@historical_up_down_data = historical_up_down_data | ||
end | ||
|
||
# Return the last date of data represented in the history graph and data table | ||
# @return [ActiveSupport::TimeWithZone] date time stamp | ||
def up_down_start | ||
QaServer::TimeService.pretty_date(up_down_end_dt - 29.days) | ||
end | ||
|
||
def up_down_end | ||
QaServer::TimeService.pretty_date(up_down_end_dt) | ||
end | ||
|
||
def up_down_end_dt | ||
@parent.last_updated_dt | ||
end | ||
|
||
# @param status [Symbol] :fully_up, :mostly_up, :timeouts, :barely_up, :down | ||
# @param day [Integer] retrieve the status for this day | ||
# @return [String] name of the css class for the status | ||
def historical_up_down_status_class(status, day) # rubocop:disable Metrics/CyclomaticComplexity | ||
case status[day] | ||
when :no_date then 'connection-no-date' | ||
when :fully_up then 'connection-fully-up' | ||
when :mostly_up then 'connection-mostly-up' | ||
when :timeouts then 'connection-timeouts' | ||
when :barely_up then 'connection-barely-up' | ||
when :down then 'connection-down' | ||
end | ||
end | ||
|
||
# @return [Boolean] true if historical datatable should be visible; otherwise false | ||
def display_historical_up_down? | ||
QaServer.config.display_historical_datatable? && @historical_up_down_data.present? | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
# frozen_string_literal: true | ||
# This class determines the state (e.g. fully_up, mostly_up, barely_up, down)of an authority during the last 30 days. | ||
module QaServer | ||
class HistoryUpDownService | ||
NO_DATA = :no_data | ||
FULLY_UP = :fully_up | ||
MOSTLY_UP = :mostly_up | ||
EXCESSIVE_TIMEOUTS = :timeouts | ||
BARELY_UP = :barely_up | ||
DOWN = :down | ||
|
||
MOSTLY_UP_THRESHOLD = QaServer.config.up_down_data_mostly_up_threshold | ||
TIMEOUT_THRESHOLD = QaServer.config.up_down_data_timeouts_max_threshold | ||
|
||
class_attribute :authority_lister, :scenario_history_class, :time_service | ||
self.authority_lister = QaServer::AuthorityListerService | ||
self.scenario_history_class = QaServer::ScenarioRunHistory | ||
self.time_service = QaServer::TimeService | ||
|
||
def last_30_days | ||
data = {} | ||
authorities_list.each { |authority| data[authority] = last_30_days_for(authority.to_s) } | ||
data | ||
end | ||
|
||
private | ||
|
||
# @returns [Hash <Array<Hash>>] data for an authority for each of the last 30 days | ||
# @example | ||
# { 'AGROVOC' = [ | ||
# :FULLY_UP, # 0 - today | ||
# :MOSTLY_UP, # 1 - yesterday | ||
# :MOSTLY_UP, # 2 - two days ago | ||
# :FULLY_UP, # 3 - three days ago | ||
# :DOWN, # 4 - four days ago | ||
# ... # etc. | ||
# ] | ||
# } | ||
def last_30_days_for(authority) | ||
auth_data = [] | ||
0.upto(29) { |offset| auth_data[offset] = day_status(authority, offset) } | ||
auth_data | ||
end | ||
|
||
# @returns [Symbol] status for a given day for an authority | ||
def day_status(authority, offset) | ||
day = offset_day(offset) | ||
good_count = count_good(authority, day) | ||
unknown_count = count_unknown(authority, day) | ||
bad_count = count_bad(authority, day) | ||
timeout_count = count_timeouts(authority, day) | ||
status_determination(good_count, unknown_count, bad_count, timeout_count) | ||
end | ||
|
||
def status_determination(good_count, unknown_count, bad_count, timeout_count) # rubocop:disable Metrics/CyclomaticComplexity | ||
total_count = good_count + unknown_count + bad_count | ||
return NO_DATA if total_count.zero? | ||
return FULLY_UP if good_count == total_count | ||
return DOWN if bad_count == total_count | ||
return BARELY_UP if unknown_count == total_count | ||
return EXCESSIVE_TIMEOUTS if (timeout_count.to_f / total_count) > TIMEOUT_THRESHOLD | ||
return MOSTLY_UP if (bad_count.to_f / total_count) < (1 - MOSTLY_UP_THRESHOLD) | ||
BARELY_UP | ||
end | ||
|
||
def authorities_list | ||
@authorities_list ||= authority_lister.authorities_list | ||
end | ||
|
||
def offset_day(offset) | ||
@today ||= time_service.current_time | ||
time_service.pretty_query_date(@today - offset.days) | ||
end | ||
|
||
def count_good(authority, day) | ||
scenario_history_class.where(authority_name: authority) | ||
.where(date: day) | ||
.where(status: :good) | ||
.count(:id) | ||
end | ||
|
||
def count_unknown(authority, day) | ||
scenario_history_class.where(authority_name: authority) | ||
.where(date: day) | ||
.where(status: :unknown) | ||
.count(:id) | ||
end | ||
|
||
def count_bad(authority, day) | ||
scenario_history_class.where(authority_name: authority) | ||
.where(date: day) | ||
.where(status: :bad) | ||
.count(:id) | ||
end | ||
|
||
def count_timeouts(authority, day) | ||
scenario_history_class.where(authority_name: authority) | ||
.where(date: day) | ||
.where('err_message LIKE ?', "%timeout%") | ||
.count(:id) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
app/views/qa_server/monitor_status/_test_up_down_connection_history.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<% if @presenter.history? && @presenter.display_history_details?%> | ||
<div id="availability-history" class="status-section"> | ||
<h3><%= t('qa_server.monitor_status.history.title') %></h3> | ||
<% if @presenter.display_historical_graph? %> | ||
<p class="status-update-dtstamp"><%= t('qa_server.monitor_status.history.range', from: @presenter.history_start, to: @presenter.history_end) %></p> | ||
<%= image_tag(@presenter.historical_graph, alt: 'History Graph Unavailable') %> | ||
<% end %> | ||
|
||
<% if @presenter.display_historical_up_down? %> | ||
<p class="status-update-dtstamp"><%= t('qa_server.monitor_status.history.range', from: @presenter.up_down_start, to: @presenter.up_down_end) %></p> | ||
<table class="up-down-history"> | ||
<tr> | ||
<th class="up-down-history"><%= t('qa_server.monitor_status.history.authority') %></th> | ||
<% 0.upto(29) do %> | ||
<th class='up-down-history'></th> | ||
<% end %> | ||
<td class='up-down-history'>Most Recent</td> | ||
</tr> | ||
<% @presenter.historical_up_down_data.each do |authority_name, status| %> | ||
<tr> | ||
<td class="connection-up-down"><%= authority_name %></td> | ||
<% 29.downto(0) do |day| %> | ||
<td class="connection-up-down <%= @presenter.historical_up_down_status_class(status, day) %>"></td> | ||
<% end %> | ||
</tr> | ||
<% end %> | ||
</table> | ||
<% end %> | ||
</div> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.