From 7972b3c0e9602a738052443d5af05d5a06e9390f Mon Sep 17 00:00:00 2001 From: "E. Lynette Rayle" Date: Fri, 16 Apr 2021 19:36:17 -0400 Subject: [PATCH 1/3] add table showing up-down data for last 30 days --- .../qa_server/_monitor-status.scss | 45 ++++++++ .../concerns/qa_server/cache_keys.rb | 1 + .../qa_server/scenario_history_cache.rb | 20 +++- .../qa_server/monitor_status_controller.rb | 8 ++ .../history_up_down_presenter.rb | 44 ++++++++ .../qa_server/monitor_status_presenter.rb | 6 +- .../qa_server/history_up_down_service.rb | 103 ++++++++++++++++++ app/services/qa_server/time_service.rb | 6 + .../_test_up_down_connection_history.html.erb | 29 +++++ .../qa_server/monitor_status/index.html.erb | 3 +- .../qa_server/history_up_down_service_spec.rb | 86 +++++++++++++++ 11 files changed, 348 insertions(+), 3 deletions(-) create mode 100644 app/presenters/qa_server/monitor_status/history_up_down_presenter.rb create mode 100644 app/services/qa_server/history_up_down_service.rb create mode 100644 app/views/qa_server/monitor_status/_test_up_down_connection_history.html.erb create mode 100644 spec/services/qa_server/history_up_down_service_spec.rb diff --git a/app/assets/stylesheets/qa_server/_monitor-status.scss b/app/assets/stylesheets/qa_server/_monitor-status.scss index 54913fe..8cc6993 100644 --- a/app/assets/stylesheets/qa_server/_monitor-status.scss +++ b/app/assets/stylesheets/qa_server/_monitor-status.scss @@ -53,3 +53,48 @@ div#performance-by-the-day { div#performance-by-the-month { display: none; } + +table.up-down-history { + border: none; +} + +td.up-down-history { + font-size: .8em; + font-style: italic; + border: none; +} +th.up-down-history { + width: 20px; + border: none; +} + +td.connection-up-down { + border-right: 8px white solid; + border-left: 8px white solid; + border-top: none; + border-bottom: 3px white solid; +} + +td.connection-no-data { + background-color: white; +} + +td.connection-fully-up { + background-color: #19AE19; +} + +td.connection-mostly-up { + background-color: #19AEA7; +} + +td.connection-timeouts { + background-color: #EDF908; +} + +td.connection-barely-up { + background-color: #AE7619; +} + +td.connection-down { + background-color: #CE0303; +} diff --git a/app/cache_processors/concerns/qa_server/cache_keys.rb b/app/cache_processors/concerns/qa_server/cache_keys.rb index 3bb73b9..7dae50d 100644 --- a/app/cache_processors/concerns/qa_server/cache_keys.rb +++ b/app/cache_processors/concerns/qa_server/cache_keys.rb @@ -5,6 +5,7 @@ module CacheKeys SCENARIO_RUN_SUMMARY_DATA_CACHE_KEY = "QaServer--CacheKeys--scenario_run_summary_data" SCENARIO_RUN_FAILURE_DATA_CACHE_KEY = "QaServer--CacheKeys--scenario_run_failure_data" SCENARIO_RUN_HISTORY_DATA_CACHE_KEY = "QaServer--CacheKeys--scenario_run_history_data" + SCENARIO_RUN_HISTORY_UP_DOWN_DATA_CACHE_KEY = "QaServer--CacheKeys--history_up_down_data" PERFORMANCE_DATATABLE_DATA_CACHE_KEY = "QaServer--Cache--performance_datatable_data" end diff --git a/app/cache_processors/qa_server/scenario_history_cache.rb b/app/cache_processors/qa_server/scenario_history_cache.rb index ad55881..314286d 100644 --- a/app/cache_processors/qa_server/scenario_history_cache.rb +++ b/app/cache_processors/qa_server/scenario_history_cache.rb @@ -2,8 +2,9 @@ # Maintain a cache of data for Authority Connection History table displayed on Monitor Status page module QaServer class ScenarioHistoryCache - class_attribute :scenario_history_class + class_attribute :scenario_history_class, :scenario_up_down_class self.scenario_history_class = QaServer::ScenarioRunHistory + self.scenario_up_down_class = QaServer::HistoryUpDownService class << self include QaServer::CacheKeys @@ -21,12 +22,29 @@ def historical_summary(force: false) end end + # Get a status for each of the last 30 days for queries that succeeded or failed. + # @param force [Boolean] if true, run the tests even if the cache hasn't expired; otherwise, use cache if not expired + # @returns [Hash] status for the last 30 days for each authority + # @example { auth_name => [:fully_up, :fully_up, :down, :mostly_up, ... ], ... } + # { 'agrovoc' => [ :fully_up, :fully_up, :down, :mostly_up, ...], + # 'geonames_ld4l_cache' => [ :fully_up, :mostly_up, :down, :fully_up, :timeouts, ...] } + def historical_up_down_data(force: false) + Rails.cache.fetch(cache_key_for_historical_up_down_data, expires_in: next_expiry, race_condition_ttl: 30.seconds, force: force) do + QaServer.config.monitor_logger.debug("(QaServer::ScenarioHistoryCache) - CALCULATING UP-DOWN STATUS HISTORY of scenario runs (force: #{force})") + scenario_up_down_class.new.last_30_days + end + end + private def cache_key_for_historical_data SCENARIO_RUN_HISTORY_DATA_CACHE_KEY end + def cache_key_for_historical_up_down_data + SCENARIO_RUN_HISTORY_UP_DOWN_DATA_CACHE_KEY + end + def next_expiry QaServer::CacheExpiryService.cache_expiry end diff --git a/app/controllers/qa_server/monitor_status_controller.rb b/app/controllers/qa_server/monitor_status_controller.rb index 6d2fc23..2e8e062 100644 --- a/app/controllers/qa_server/monitor_status_controller.rb +++ b/app/controllers/qa_server/monitor_status_controller.rb @@ -19,6 +19,7 @@ def index @presenter = presenter_class.new(current_summary: latest_summary, current_failure_data: latest_failures, historical_summary_data: historical_data, + historical_up_down_data: historical_up_down_data, performance_data: performance_table_data) QaServer.config.monitor_logger.debug("~~~~~~~~ DONE rendering monitor status") render 'index', status: :internal_server_error if latest_summary&.failing_authority_count&.positive? @@ -59,6 +60,13 @@ def historical_data @historical_data ||= QaServer::ScenarioHistoryCache.historical_summary(force: refresh_history?) end + # Get a summary level of historical data + # @returns [Array] summary of passing/failing tests for each authority + # @see QaServer::ScenarioRunHistory#historical_summary for structure of output + def historical_up_down_data + @historical_up_down_data ||= QaServer::ScenarioHistoryCache.historical_up_down_data(force: refresh_history?) + end + def update_historical_graph return unless QaServer.config.display_historical_graph? QaServer::ScenarioHistoryGraphCache.generate_graph(data: historical_data, force: refresh_history?) diff --git a/app/presenters/qa_server/monitor_status/history_up_down_presenter.rb b/app/presenters/qa_server/monitor_status/history_up_down_presenter.rb new file mode 100644 index 0000000..82ca462 --- /dev/null +++ b/app/presenters/qa_server/monitor_status/history_up_down_presenter.rb @@ -0,0 +1,44 @@ +# 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] 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 + + # @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 diff --git a/app/presenters/qa_server/monitor_status_presenter.rb b/app/presenters/qa_server/monitor_status_presenter.rb index c3fcc1b..0af12a5 100644 --- a/app/presenters/qa_server/monitor_status_presenter.rb +++ b/app/presenters/qa_server/monitor_status_presenter.rb @@ -7,10 +7,12 @@ class MonitorStatusPresenter # @param current_summary [ScenarioRunSummary] summary status of the latest run of test scenarios # @param current_data [Array] current set of failures for the latest test run, if any # @param historical_summary_data [Array] summary of past failuring runs per authority to drive chart + # @param historical_up_down_data [Hash] status of queries for the last 30 days # @param performance_data [Hash] performance datatable data - def initialize(current_summary:, current_failure_data:, historical_summary_data:, performance_data:) + def initialize(current_summary:, current_failure_data:, historical_summary_data:, historical_up_down_data:, performance_data:) @current_status_presenter = QaServer::MonitorStatus::CurrentStatusPresenter.new(parent: self, current_summary: current_summary, current_failure_data: current_failure_data) @history_presenter = QaServer::MonitorStatus::HistoryPresenter.new(parent: self, historical_summary_data: historical_summary_data) + @history_up_down_presenter = QaServer::MonitorStatus::HistoryUpDownPresenter.new(parent: self, historical_up_down_data: historical_up_down_data) @performance_presenter = QaServer::MonitorStatus::PerformancePresenter.new(parent: self, performance_data: performance_data) end @@ -23,6 +25,8 @@ def initialize(current_summary:, current_failure_data:, historical_summary_data: :percent_authority_failing, :percent_authority_failing_str, :failure_style_class, :passing_style_class, :display_history_details?, :display_historical_graph?, :display_historical_datatable?, :history_start, :history_end + def_delegators :@history_up_down_presenter, :historical_up_down_data, :display_historical_up_down?, :historical_up_down_status_class + def_delegators :@performance_presenter, :performance_data, :performance_data?, :display_performance?, :display_performance_graph?, :display_performance_datatable?, :performance_data_authority_name, :performance_for_day_graph, :performance_for_month_graph, :performance_for_year_graph, :datatable_search_stats, :datatable_fetch_stats, :datatable_all_actions_stats, diff --git a/app/services/qa_server/history_up_down_service.rb b/app/services/qa_server/history_up_down_service.rb new file mode 100644 index 0000000..db86d11 --- /dev/null +++ b/app/services/qa_server/history_up_down_service.rb @@ -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 = 0.95 + TIMEOUT_THRESHOLD = 0.5 + + 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 >] 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 diff --git a/app/services/qa_server/time_service.rb b/app/services/qa_server/time_service.rb index d788239..0fedef0 100644 --- a/app/services/qa_server/time_service.rb +++ b/app/services/qa_server/time_service.rb @@ -24,6 +24,12 @@ def pretty_time(dt) def pretty_date(dt) dt.in_time_zone(QaServer.config.preferred_time_zone_name).strftime("%m/%d/%Y") end + + # @param dt [ActiveSupport::TimeWithZone] date time stamp + # @return [String] string version of date formatted with just date (e.g. "2020-02-01") + def pretty_query_date(dt) + dt.in_time_zone(QaServer.config.preferred_time_zone_name).strftime("%Y-%m-%d") + end end end end diff --git a/app/views/qa_server/monitor_status/_test_up_down_connection_history.html.erb b/app/views/qa_server/monitor_status/_test_up_down_connection_history.html.erb new file mode 100644 index 0000000..399610e --- /dev/null +++ b/app/views/qa_server/monitor_status/_test_up_down_connection_history.html.erb @@ -0,0 +1,29 @@ + <% if @presenter.history? && @presenter.display_history_details?%> +
+

<%= t('qa_server.monitor_status.history.title') %>

+

<%= t('qa_server.monitor_status.history.range', from: @presenter.history_start, to: @presenter.history_end) %>

+ <% if @presenter.display_historical_graph? %> + <%= image_tag(@presenter.historical_graph, alt: 'History Graph Unavailable') %> + <% end %> + + <% if @presenter.display_historical_up_down? %> + + + + <% 0.upto(29) do %> + + <% end %> + + + <% @presenter.historical_up_down_data.each do |authority_name, status| %> + + + <% 29.downto(0) do |day| %> + + <% end %> + + <% end %> +
<%= t('qa_server.monitor_status.history.authority') %>Most Recent
<%= authority_name %>
+ <% end %> +
+ <% end %> diff --git a/app/views/qa_server/monitor_status/index.html.erb b/app/views/qa_server/monitor_status/index.html.erb index 921381d..6827af5 100644 --- a/app/views/qa_server/monitor_status/index.html.erb +++ b/app/views/qa_server/monitor_status/index.html.erb @@ -5,7 +5,8 @@

<%= t('qa_server.monitor_status.title') %>

<%= render 'test_summary' %> - <%= render 'test_history' %> + <%= render 'test_up_down_connection_history' %> + <% # = render 'test_history' %> <%= render 'performance' %> diff --git a/spec/services/qa_server/history_up_down_service_spec.rb b/spec/services/qa_server/history_up_down_service_spec.rb new file mode 100644 index 0000000..56b6a9b --- /dev/null +++ b/spec/services/qa_server/history_up_down_service_spec.rb @@ -0,0 +1,86 @@ +# frozen_string_literal: true +require 'spec_helper' + +RSpec.describe QaServer::HistoryUpDownService do + let(:service) { described_class.new } + + context 'when total_count is 0' do + let(:good_count) { 0 } + let(:unknown_count) { 0 } + let(:bad_count) { 0 } + let(:timeout_count) { 0 } + it 'returns :no_data' do + status = service.send(:status_determination, good_count, unknown_count, bad_count, timeout_count) + expect(status).to eq :no_data + end + end + + context 'when all queries failed' do + let(:good_count) { 0 } + let(:unknown_count) { 0 } + let(:bad_count) { 5 } + let(:timeout_count) { 0 } + it 'returns :down' do + status = service.send(:status_determination, good_count, unknown_count, bad_count, timeout_count) + expect(status).to eq :down + end + end + + context 'when all queries passed' do + let(:good_count) { 5 } + let(:unknown_count) { 0 } + let(:bad_count) { 0 } + let(:timeout_count) { 0 } + it 'returns :fully_up' do + status = service.send(:status_determination, good_count, unknown_count, bad_count, timeout_count) + expect(status).to eq :fully_up + end + end + + context 'when all queries are unknown' do + let(:good_count) { 0 } + let(:unknown_count) { 5 } + let(:bad_count) { 0 } + let(:timeout_count) { 0 } + it 'returns :barely_up' do + status = service.send(:status_determination, good_count, unknown_count, bad_count, timeout_count) + expect(status).to eq :barely_up + end + end + + context 'when too many queries timed out' do + let(:threshold) { 0.5 } + let(:good_count) { 100 - bad_count } + let(:unknown_count) { 0 } + let(:bad_count) { timeout_count + 2 } + let(:timeout_count) { threshold * 100 + 1 } + it 'returns :good' do + status = service.send(:status_determination, good_count, unknown_count, bad_count, timeout_count) + expect(status).to eq :timeouts + end + end + + context 'when almost all queries pass' do + let(:threshold) { 0.95 } + let(:good_count) { threshold * 100 + 1 } + let(:unknown_count) { 0 } + let(:bad_count) { 100 - good_count } + let(:timeout_count) { 0 } + it 'returns :good' do + status = service.send(:status_determination, good_count, unknown_count, bad_count, timeout_count) + expect(status).to eq :mostly_up + end + end + + context 'when too many queries fail' do + let(:threshold) { 0.95 } + let(:good_count) { threshold * 100 - 1 } + let(:unknown_count) { 0 } + let(:bad_count) { 100 - good_count } + let(:timeout_count) { 0 } + it 'returns :good' do + status = service.send(:status_determination, good_count, unknown_count, bad_count, timeout_count) + expect(status).to eq :barely_up + end + end +end From 705b5934018f861e8323da2b6a0661cfa184974c Mon Sep 17 00:00:00 2001 From: "E. Lynette Rayle" Date: Fri, 16 Apr 2021 20:21:38 -0400 Subject: [PATCH 2/3] force date range for up-down history to last 30 days --- .../monitor_status/history_up_down_presenter.rb | 16 +++++++++++++++- .../qa_server/monitor_status_presenter.rb | 5 +++-- .../_test_up_down_connection_history.html.erb | 3 ++- 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/app/presenters/qa_server/monitor_status/history_up_down_presenter.rb b/app/presenters/qa_server/monitor_status/history_up_down_presenter.rb index 82ca462..fcec2c9 100644 --- a/app/presenters/qa_server/monitor_status/history_up_down_presenter.rb +++ b/app/presenters/qa_server/monitor_status/history_up_down_presenter.rb @@ -21,7 +21,21 @@ 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 diff --git a/app/presenters/qa_server/monitor_status_presenter.rb b/app/presenters/qa_server/monitor_status_presenter.rb index 0af12a5..34b12aa 100644 --- a/app/presenters/qa_server/monitor_status_presenter.rb +++ b/app/presenters/qa_server/monitor_status_presenter.rb @@ -5,7 +5,7 @@ class MonitorStatusPresenter extend Forwardable # @param current_summary [ScenarioRunSummary] summary status of the latest run of test scenarios - # @param current_data [Array] current set of failures for the latest test run, if any + # @param current_failure_data [Array] current set of failures for the latest test run, if any # @param historical_summary_data [Array] summary of past failuring runs per authority to drive chart # @param historical_up_down_data [Hash] status of queries for the last 30 days # @param performance_data [Hash] performance datatable data @@ -25,7 +25,8 @@ def initialize(current_summary:, current_failure_data:, historical_summary_data: :percent_authority_failing, :percent_authority_failing_str, :failure_style_class, :passing_style_class, :display_history_details?, :display_historical_graph?, :display_historical_datatable?, :history_start, :history_end - def_delegators :@history_up_down_presenter, :historical_up_down_data, :display_historical_up_down?, :historical_up_down_status_class + def_delegators :@history_up_down_presenter, :historical_up_down_data, :display_historical_up_down?, :historical_up_down_status_class, + :up_down_start, :up_down_end def_delegators :@performance_presenter, :performance_data, :performance_data?, :display_performance?, :display_performance_graph?, :display_performance_datatable?, :performance_data_authority_name, :performance_for_day_graph, :performance_for_month_graph, diff --git a/app/views/qa_server/monitor_status/_test_up_down_connection_history.html.erb b/app/views/qa_server/monitor_status/_test_up_down_connection_history.html.erb index 399610e..6173465 100644 --- a/app/views/qa_server/monitor_status/_test_up_down_connection_history.html.erb +++ b/app/views/qa_server/monitor_status/_test_up_down_connection_history.html.erb @@ -1,12 +1,13 @@ <% if @presenter.history? && @presenter.display_history_details?%>

<%= t('qa_server.monitor_status.history.title') %>

-

<%= t('qa_server.monitor_status.history.range', from: @presenter.history_start, to: @presenter.history_end) %>

<% if @presenter.display_historical_graph? %> +

<%= t('qa_server.monitor_status.history.range', from: @presenter.history_start, to: @presenter.history_end) %>

<%= image_tag(@presenter.historical_graph, alt: 'History Graph Unavailable') %> <% end %> <% if @presenter.display_historical_up_down? %> +

<%= t('qa_server.monitor_status.history.range', from: @presenter.up_down_start, to: @presenter.up_down_end) %>

From a3656696e18afb38d21245c366bca5172480d0a3 Mon Sep 17 00:00:00 2001 From: "E. Lynette Rayle" Date: Fri, 16 Apr 2021 20:00:13 -0400 Subject: [PATCH 3/3] make up-down threshold configurable --- .../qa_server/history_up_down_service.rb | 4 ++-- .../config/initializers/qa_server.rb | 8 +++++++ lib/qa_server/configuration.rb | 14 ++++++++++++ spec/lib/configuration_spec.rb | 22 +++++++++++++++++++ 4 files changed, 46 insertions(+), 2 deletions(-) diff --git a/app/services/qa_server/history_up_down_service.rb b/app/services/qa_server/history_up_down_service.rb index db86d11..c55098e 100644 --- a/app/services/qa_server/history_up_down_service.rb +++ b/app/services/qa_server/history_up_down_service.rb @@ -9,8 +9,8 @@ class HistoryUpDownService BARELY_UP = :barely_up DOWN = :down - MOSTLY_UP_THRESHOLD = 0.95 - TIMEOUT_THRESHOLD = 0.5 + 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 diff --git a/lib/generators/qa_server/templates/config/initializers/qa_server.rb b/lib/generators/qa_server/templates/config/initializers/qa_server.rb index 08f8f8d..827bb00 100644 --- a/lib/generators/qa_server/templates/config/initializers/qa_server.rb +++ b/lib/generators/qa_server/templates/config/initializers/qa_server.rb @@ -24,6 +24,14 @@ # @param [Symbol] time period for calculating historical pass/fail (i.e., one of :month, :year, or :all) # config.historical_datatable_default_time_period = :year + # Threshold for percentage of queries that timed out after which it gets marked in the Authority Connection up-down History + # @param [Float] percentage of queries that are ok to timeout + # config.up_down_data_timeouts_max_threshold = 0.3 + + # Threshold for percentage of queries that are passing, below which are marked in the Authority Connection up-down History as barely_up + # @param [Float] required percentage of queries passing to be considered mostly-up when there are some failures + # config.up_down_data_mostly_up_threshold = 0.95 + # Displays a graph of performance test data when true # @param [Boolean] display performance graph when true # config.display_performance_graph = false diff --git a/lib/qa_server/configuration.rb b/lib/qa_server/configuration.rb index 3464695..8a7e52e 100644 --- a/lib/qa_server/configuration.rb +++ b/lib/qa_server/configuration.rb @@ -73,6 +73,20 @@ def historical_datatable_default_time_period @historical_datatable_default_time_period ||= :year end + # Threshold for percentage of queries that timed out after which it gets marked in the Authority Connection up-down History + # @param [Float] percentage of queries that are ok to timeout + attr_writer :up_down_data_timeouts_max_threshold + def up_down_data_timeouts_max_threshold + @up_down_data_timeouts_max_threshold ||= 0.3 + end + + # Threshold for percentage of queries that are passing, below which are marked in the Authority Connection up-down History as barely_up + # @param [Float] required percentage of queries passing to be considered mostly-up when there are some failures + attr_writer :up_down_data_mostly_up_threshold + def up_down_data_mostly_up_threshold + @up_down_data_mostly_up_threshold ||= 0.95 + end + # Displays a graph of performance test data when true # @param [Boolean] display performance graph when true attr_writer :display_performance_graph diff --git a/spec/lib/configuration_spec.rb b/spec/lib/configuration_spec.rb index bae1785..a03de16 100644 --- a/spec/lib/configuration_spec.rb +++ b/spec/lib/configuration_spec.rb @@ -86,6 +86,28 @@ end end + describe '#up_down_data_timeouts_max_threshold' do + it 'return default as 0.3 (e.g. 30%)' do + expect(config.up_down_data_timeouts_max_threshold).to eq 0.3 + end + + it 'returns set value' do + config.up_down_data_timeouts_max_threshold = 0.25 + expect(config.up_down_data_timeouts_max_threshold).to eq 0.25 + end + end + + describe '#up_down_data_mostly_up_threshold' do + it 'return default as 0.95 (e.g. 95%)' do + expect(config.up_down_data_mostly_up_threshold).to eq 0.95 + end + + it 'returns set value' do + config.up_down_data_mostly_up_threshold = 0.98 + expect(config.up_down_data_mostly_up_threshold).to eq 0.98 + end + end + describe '#display_performance_graph?' do it 'return default as false' do expect(config.display_performance_graph?).to eq false
<%= t('qa_server.monitor_status.history.authority') %>