qa_server 5.5.1 → 6.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +12 -0
- data/README.md +53 -0
- data/app/controllers/{qa_server/authority_validation_controller.rb → concerns/qa_server/authority_validation_behavior.rb} +13 -11
- data/app/controllers/qa_server/authority_list_controller.rb +5 -1
- data/app/controllers/qa_server/check_status_controller.rb +5 -1
- data/app/controllers/qa_server/monitor_status_controller.rb +40 -28
- data/app/jobs/qa_server/monitor_tests_job.rb +50 -0
- data/app/models/qa_server/performance_cache.rb +11 -3
- data/app/models/qa_server/performance_history.rb +24 -106
- data/app/models/qa_server/scenario_run_history.rb +161 -176
- data/app/models/qa_server/scenario_run_registry.rb +4 -4
- data/app/prepends/prepended_linked_data/find_term.rb +4 -4
- data/app/prepends/prepended_linked_data/search_query.rb +4 -4
- data/app/prepends/prepended_rdf/rdf_graph.rb +4 -4
- data/app/presenters/concerns/qa_server/monitor_status/performance_datatable_behavior.rb +23 -1
- data/app/presenters/qa_server/check_status_presenter.rb +4 -4
- data/app/presenters/qa_server/monitor_status/current_status_presenter.rb +17 -5
- data/app/presenters/qa_server/monitor_status/history_presenter.rb +40 -19
- data/app/presenters/qa_server/monitor_status/performance_presenter.rb +3 -1
- data/app/presenters/qa_server/monitor_status_presenter.rb +9 -9
- data/app/services/qa_server/monitor_cache_service.rb +22 -0
- data/app/services/qa_server/performance_calculator_service.rb +18 -7
- data/app/services/qa_server/performance_datatable_service.rb +82 -0
- data/app/services/qa_server/performance_graph_data_service.rb +140 -82
- data/app/services/qa_server/performance_graphing_service.rb +15 -12
- data/app/services/qa_server/time_period_service.rb +93 -0
- data/app/services/qa_server/time_service.rb +29 -0
- data/app/validators/qa_server/scenario_validator.rb +3 -3
- data/app/validators/qa_server/search_scenario_validator.rb +3 -3
- data/app/views/qa_server/monitor_status/_performance.html.erb +2 -1
- data/app/views/qa_server/monitor_status/_test_history.html.erb +1 -2
- data/app/views/qa_server/monitor_status/_test_summary.html.erb +2 -2
- data/config/locales/qa_server.en.yml +3 -4
- data/lib/generators/qa_server/templates/config/initializers/qa_server.rb +4 -0
- data/lib/qa_server.rb +0 -23
- data/lib/qa_server/configuration.rb +20 -0
- data/lib/qa_server/version.rb +1 -1
- data/spec/lib/qa_server_spec.rb +0 -51
- data/spec/services/qa_server/monitor_cache_service_spec.rb +20 -0
- data/spec/services/qa_server/time_period_service_spec.rb +246 -0
- data/spec/services/qa_server/time_service_spec.rb +50 -0
- metadata +14 -3
@@ -12,6 +12,7 @@ module QaServer
|
|
12
12
|
# @param performance_data [Hash] hash of all performance data for all authorities
|
13
13
|
# @see QaServer:PerformanceHistory
|
14
14
|
def create_performance_graphs(performance_data:)
|
15
|
+
QaServer.config.monitor_logger.info("(QaServer::PerformanceGraphingService##{__method__}) - generating graphs")
|
15
16
|
performance_data.each_key do |auth_name|
|
16
17
|
create_graphs_for_authority(performance_data, auth_name.to_sym, :search)
|
17
18
|
create_graphs_for_authority(performance_data, auth_name.to_sym, :fetch)
|
@@ -35,33 +36,35 @@ module QaServer
|
|
35
36
|
end
|
36
37
|
|
37
38
|
def create_performance_for_day_graph(performance_data, authority_name, action)
|
38
|
-
|
39
|
-
return
|
40
|
-
gruff_data = rework_performance_data_for_gruff(
|
39
|
+
data = authority_performance_data(performance_data, authority_name, action, FOR_DAY)
|
40
|
+
return if data.empty?
|
41
|
+
gruff_data = rework_performance_data_for_gruff(data, BY_HOUR)
|
41
42
|
create_gruff_graph(gruff_data,
|
42
43
|
performance_for_day_graph_full_path(authority_name, action),
|
43
44
|
I18n.t('qa_server.monitor_status.performance.x_axis_hour'))
|
44
45
|
end
|
45
46
|
|
46
47
|
def create_performance_for_month_graph(performance_data, authority_name, action)
|
47
|
-
|
48
|
-
|
48
|
+
data = authority_performance_data(performance_data, authority_name, action, FOR_MONTH)
|
49
|
+
return if data.empty?
|
50
|
+
gruff_data = rework_performance_data_for_gruff(data, BY_DAY)
|
49
51
|
create_gruff_graph(gruff_data,
|
50
52
|
performance_for_month_graph_full_path(authority_name, action),
|
51
53
|
I18n.t('qa_server.monitor_status.performance.x_axis_day'))
|
52
54
|
end
|
53
55
|
|
54
56
|
def create_performance_for_year_graph(performance_data, authority_name, action)
|
55
|
-
|
56
|
-
|
57
|
+
data = authority_performance_data(performance_data, authority_name, action, FOR_YEAR)
|
58
|
+
return if data.empty?
|
59
|
+
gruff_data = rework_performance_data_for_gruff(data, BY_MONTH)
|
57
60
|
create_gruff_graph(gruff_data,
|
58
61
|
performance_for_year_graph_full_path(authority_name, action),
|
59
62
|
I18n.t('qa_server.monitor_status.performance.x_axis_month'))
|
60
63
|
end
|
61
64
|
|
62
|
-
def authority_performance_data(data, authority_name)
|
65
|
+
def authority_performance_data(data, authority_name, action, time_period)
|
63
66
|
auth_name = authority_name.nil? ? ALL_AUTH : authority_name
|
64
|
-
data[auth_name]
|
67
|
+
data[auth_name][action].key?(time_period) ? data[auth_name][action][time_period] : {}
|
65
68
|
end
|
66
69
|
|
67
70
|
def performance_for_day_graph_full_path(authority_name, action)
|
@@ -92,7 +95,7 @@ module QaServer
|
|
92
95
|
graph_load_data << graph_load_time(data)
|
93
96
|
normalization_data << data[STATS][AVG_NORM]
|
94
97
|
end
|
95
|
-
[labels,
|
98
|
+
[labels, retrieve_data, graph_load_data, normalization_data]
|
96
99
|
end
|
97
100
|
|
98
101
|
def graph_load_time(data)
|
@@ -122,9 +125,9 @@ module QaServer
|
|
122
125
|
g = Gruff::StackedBar.new
|
123
126
|
performance_graph_theme(g, x_axis_label)
|
124
127
|
g.labels = performance_data[0]
|
125
|
-
g.data(I18n.t('qa_server.monitor_status.performance.
|
128
|
+
g.data(I18n.t('qa_server.monitor_status.performance.retrieve_time_ms'), performance_data[1])
|
126
129
|
g.data(I18n.t('qa_server.monitor_status.performance.graph_load_time_ms'), performance_data[2])
|
127
|
-
g.data(I18n.t('qa_server.monitor_status.performance.
|
130
|
+
g.data(I18n.t('qa_server.monitor_status.performance.normalization_time_ms'), performance_data[3])
|
128
131
|
g.write performance_graph_full_path
|
129
132
|
end
|
130
133
|
end
|
@@ -0,0 +1,93 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
# Create where clauses for time periods and authorities.
|
3
|
+
module QaServer
|
4
|
+
class TimePeriodService
|
5
|
+
class << self
|
6
|
+
# Construct a hash to pass to ActiveRecord where method limiting to last 24 hours and optionally an authority.
|
7
|
+
# @param auth_name [String] authority name if limiting to an authority; otherwise, nil
|
8
|
+
# @param auth_table [Symbol] name of the table holding the authority name; or nil if in same table
|
9
|
+
# @param dt_table [Symbol] name of the table holding the date-time stamp; or nil if in same table
|
10
|
+
# @return [Hash] a where clause for the last 24 hours for an authority
|
11
|
+
# @example returned where for join
|
12
|
+
# { scenario_run_registry: { dt_stamp: start_hour..end_hour },
|
13
|
+
# scenario_run_history: { authority: 'LOC_DIRECT' } }
|
14
|
+
# @example returned where for join with no authority
|
15
|
+
# { scenario_run_registry: { dt_stamp: start_hour..end_hour } }
|
16
|
+
# @example returned where for same table
|
17
|
+
# { dt_stamp: start_hour..end_hour, authority: 'LOC_DIRECT' }
|
18
|
+
# @example returned where when no authority
|
19
|
+
# { dt_stamp: start_hour..end_hour }
|
20
|
+
def where_clause_for_last_24_hours(auth_name: nil, auth_table: nil, dt_table: nil)
|
21
|
+
validate_params(auth_name, auth_table, dt_table)
|
22
|
+
where_clause = where_for_dt_stamp(dt_table, 1.day)
|
23
|
+
where_with_authority(where_clause, auth_name, auth_table)
|
24
|
+
end
|
25
|
+
|
26
|
+
# Construct a hash to pass to ActiveRecord where method limiting to last 30 days and optionally an authority.
|
27
|
+
# @param auth_name [String] authority name if limiting to an authority; otherwise, nil
|
28
|
+
# @param auth_table [Symbol] name of the table holding the authority name; or nil if in same table
|
29
|
+
# @param dt_table [Symbol] name of the table holding the date-time stamp; or nil if in same table
|
30
|
+
# @return [Hash] a where clause for the last 30 days for an authority
|
31
|
+
# @example returned where for join
|
32
|
+
# { scenario_run_registry: { dt_stamp: start_day..end_day },
|
33
|
+
# scenario_run_history: { authority: 'LOC_DIRECT' } }
|
34
|
+
# @example returned where for join with no authority
|
35
|
+
# { scenario_run_registry: { dt_stamp: start_day..end_day } }
|
36
|
+
# @example returned where for same table
|
37
|
+
# { dt_stamp: start_day..end_day, authority: 'LOC_DIRECT' }
|
38
|
+
# @example returned where when no authority
|
39
|
+
# { dt_stamp: start_day..end_day }
|
40
|
+
def where_clause_for_last_30_days(auth_name: nil, auth_table: nil, dt_table: nil)
|
41
|
+
validate_params(auth_name, auth_table, dt_table)
|
42
|
+
where_clause = where_for_dt_stamp(dt_table, 1.month)
|
43
|
+
where_with_authority(where_clause, auth_name, auth_table)
|
44
|
+
end
|
45
|
+
|
46
|
+
# Construct a hash to pass to ActiveRecord where method limiting to last 12 months and optionally an authority.
|
47
|
+
# @param auth_name [String] authority name if limiting to an authority; otherwise, nil
|
48
|
+
# @param auth_table [Symbol] name of the table holding the authority name; or nil if in same table
|
49
|
+
# @param dt_table [Symbol] name of the table holding the date-time stamp; or nil if in same table
|
50
|
+
# @return [Hash] a where clause for the last 12 months for an authority
|
51
|
+
# @example returned where for join
|
52
|
+
# { scenario_run_registry: { dt_stamp: start_month..end_month },
|
53
|
+
# scenario_run_history: { authority: 'LOC_DIRECT' } }
|
54
|
+
# @example returned where for join with no authority
|
55
|
+
# { scenario_run_registry: { dt_stamp: start_month..end_month } }
|
56
|
+
# @example returned where for same table
|
57
|
+
# { dt_stamp: start_month..end_month, authority: 'LOC_DIRECT' }
|
58
|
+
# @example returned where when no authority
|
59
|
+
# { dt_stamp: start_month..end_month }
|
60
|
+
def where_clause_for_last_12_months(auth_name: nil, auth_table: nil, dt_table: nil)
|
61
|
+
validate_params(auth_name, auth_table, dt_table)
|
62
|
+
where_clause = where_for_dt_stamp(dt_table, 1.year)
|
63
|
+
where_with_authority(where_clause, auth_name, auth_table)
|
64
|
+
end
|
65
|
+
|
66
|
+
private
|
67
|
+
|
68
|
+
def where_for_dt_stamp(dt_table, time_period)
|
69
|
+
end_range = QaServer::TimeService.current_time
|
70
|
+
start_range = end_range - time_period
|
71
|
+
where_clause = { dt_stamp: start_range..end_range }
|
72
|
+
where_clause = { dt_table => where_clause } unless dt_table.nil?
|
73
|
+
where_clause
|
74
|
+
end
|
75
|
+
|
76
|
+
def where_with_authority(where_clause, auth_name, auth_table)
|
77
|
+
return where_clause if auth_name.nil?
|
78
|
+
if auth_table.nil?
|
79
|
+
where_clause[:authority] = auth_name
|
80
|
+
else
|
81
|
+
where_clause[auth_table] = { authority: auth_name }
|
82
|
+
end
|
83
|
+
where_clause
|
84
|
+
end
|
85
|
+
|
86
|
+
def validate_params(auth_name, auth_table, dt_table)
|
87
|
+
raise ArgumentError, "Do not specify auth_table when auth_name is not specified" if auth_table.present? && auth_name.nil?
|
88
|
+
return if auth_name.nil?
|
89
|
+
raise ArgumentError, "Either both table names need to be specified or neither" if auth_table.present? ^ dt_table.present?
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
# Create where clauses for time periods and authorities.
|
3
|
+
module QaServer
|
4
|
+
class TimeService
|
5
|
+
class << self
|
6
|
+
# @return [ActiveSupport::TimeWithZone] current DateTime in the configured preferred_time_zone_name
|
7
|
+
def current_time
|
8
|
+
Time.now.in_time_zone(QaServer.config.preferred_time_zone_name)
|
9
|
+
end
|
10
|
+
|
11
|
+
# @return [Float] current DateTime in seconds
|
12
|
+
def current_time_s
|
13
|
+
current_time.to_f
|
14
|
+
end
|
15
|
+
|
16
|
+
# @param dt [ActiveSupport::TimeWithZone] date time stamp
|
17
|
+
# @return [String] string version of date formatted with date and time (e.g. "02/01/2020 - 02:35 PM ET")
|
18
|
+
def pretty_time(dt)
|
19
|
+
dt.in_time_zone(QaServer.config.preferred_time_zone_name).strftime("%m/%d/%Y - %I:%M %p")
|
20
|
+
end
|
21
|
+
|
22
|
+
# @param dt [ActiveSupport::TimeWithZone] date time stamp
|
23
|
+
# @return [String] string version of date formatted with just date (e.g. "02/01/2020")
|
24
|
+
def pretty_date(dt)
|
25
|
+
dt.in_time_zone(QaServer.config.preferred_time_zone_name).strftime("%m/%d/%Y")
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -59,15 +59,15 @@ module QaServer
|
|
59
59
|
# Runs the test in the block passed by the specific scenario type.
|
60
60
|
# @return [Symbol] :good (PASS) or :unknown (UNKNOWN) based on whether enough results were returned
|
61
61
|
def test_connection(min_expected_size: MIN_EXPECTED_SIZE, scenario_type_name:)
|
62
|
-
dt_start = QaServer.current_time
|
62
|
+
dt_start = QaServer::TimeService.current_time
|
63
63
|
results = yield if block_given?
|
64
|
-
dt_end = QaServer.current_time
|
64
|
+
dt_end = QaServer::TimeService.current_time
|
65
65
|
actual_size = results.to_s.length
|
66
66
|
status = actual_size > min_expected_size ? PASS : UNKNOWN
|
67
67
|
errmsg = status == PASS ? '' : "#{scenario_type_name.capitalize} scenario unknown status; cause: Results actual size (#{actual_size} < expected size (#{min_expected_size})"
|
68
68
|
log(status: status, error_message: errmsg, normalization_run_time: (dt_end - dt_start)) # TODO: need to get run times from results
|
69
69
|
rescue Exception => e
|
70
|
-
dt_end = QaServer.current_time
|
70
|
+
dt_end = QaServer::TimeService.current_time
|
71
71
|
log(status: FAIL, error_message: "Exception executing #{scenario_type_name} scenario; cause: #{e.message}", request_run_time: (dt_end - dt_start))
|
72
72
|
end
|
73
73
|
|
@@ -40,9 +40,9 @@ module QaServer
|
|
40
40
|
|
41
41
|
# Runs the accuracy test and log results
|
42
42
|
def test_accuracy(subject_uri:, expected_by_position:)
|
43
|
-
dt_start = QaServer.current_time
|
43
|
+
dt_start = QaServer::TimeService.current_time
|
44
44
|
results = yield if block_given?
|
45
|
-
dt_end = QaServer.current_time
|
45
|
+
dt_end = QaServer::TimeService.current_time
|
46
46
|
if results.blank?
|
47
47
|
log(status: UNKNOWN, errmsg: "Search position scenario failed; cause: no results found", expected: expected_by_position, target: subject_uri, request_run_time: (dt_end - dt_start))
|
48
48
|
return
|
@@ -50,7 +50,7 @@ module QaServer
|
|
50
50
|
|
51
51
|
check_position(results, subject_uri, expected_by_position, total_run_time: (dt_end - dt_start)) # TODO: need to get run times from results
|
52
52
|
rescue Exception => e
|
53
|
-
dt_end = QaServer.current_time
|
53
|
+
dt_end = QaServer::TimeService.current_time
|
54
54
|
log(status: FAIL, errmsg: "Exception executing search position scenario; cause: #{e.message}",
|
55
55
|
expected: expected_by_position, target: subject_uri, request_run_time: (dt_end - dt_start))
|
56
56
|
end
|
@@ -83,7 +83,8 @@
|
|
83
83
|
|
84
84
|
<% if @presenter.display_performance_datatable? && !@presenter.performance_data.nil? %>
|
85
85
|
<div id="performance-datatable-section">
|
86
|
-
<h4><%=
|
86
|
+
<h4><%= t('qa_server.monitor_status.performance.datatable_desc') %></h4>
|
87
|
+
<p class="status-update-dtstamp"><%= t('qa_server.monitor_status.performance.datarange', from: @presenter.performance_data_start, to: @presenter.performance_data_end) %></p>
|
87
88
|
<table class="status">
|
88
89
|
<tr>
|
89
90
|
<th></th>
|
@@ -1,8 +1,7 @@
|
|
1
1
|
<% if @presenter.history? && @presenter.display_history_details?%>
|
2
2
|
<div id="availability-history" class="status-section">
|
3
3
|
<h3><%= t('qa_server.monitor_status.history.title') %></h3>
|
4
|
-
<p class="status-update-dtstamp"><%= t('qa_server.monitor_status.history.
|
5
|
-
<%#= column_chart @presenter.historical_summary, stacked: true, colors: ["green", "red"], xtitle: 'Authority', ytitle: 'Pass-Fail', legend: 'bottom' %>
|
4
|
+
<p class="status-update-dtstamp"><%= t('qa_server.monitor_status.history.range', from: @presenter.history_start, to: @presenter.history_end) %></p>
|
6
5
|
<% if @presenter.display_historical_graph? %>
|
7
6
|
<%= image_tag(@presenter.historical_graph, alt: 'History Graph Unavailable') %>
|
8
7
|
<% end %>
|
@@ -19,7 +19,7 @@
|
|
19
19
|
</table>
|
20
20
|
<p class="status-update-dtstamp"><%= t('qa_server.monitor_status.summary.last_updated', date: @presenter.last_updated) %></p>
|
21
21
|
|
22
|
-
<% if @presenter.failures? & !@
|
22
|
+
<% if @presenter.failures? & !@presenter.failures.nil? %>
|
23
23
|
<div id="failures" class="status-section">
|
24
24
|
<h4><%= t('qa_server.monitor_status.failures.title') %></h4>
|
25
25
|
|
@@ -33,7 +33,7 @@
|
|
33
33
|
<th><%= t('qa_server.monitor_status.failures.errmsg') %></th>
|
34
34
|
</tr>
|
35
35
|
<% current_authority = nil %>
|
36
|
-
<% @
|
36
|
+
<% @presenter.failures.each do |status| %>
|
37
37
|
<% unless status[:authority_name] == current_authority %>
|
38
38
|
<% current_authority = status[:authority_name] %>
|
39
39
|
<tr>
|
@@ -69,6 +69,7 @@ en:
|
|
69
69
|
history:
|
70
70
|
title: Authority Connection History
|
71
71
|
since: 'Since %{date} ET'
|
72
|
+
range: 'From %{from} to %{to}'
|
72
73
|
authority: Authority
|
73
74
|
days_failing: Days Failing
|
74
75
|
days_passing: Days Passing
|
@@ -95,10 +96,8 @@ en:
|
|
95
96
|
y_axis_ms: Milliseconds (ms)
|
96
97
|
now: NOW
|
97
98
|
today: TODAY
|
98
|
-
|
99
|
-
|
100
|
-
datatable_year_desc: 'Performance tabulated data for one year'
|
101
|
-
datatable_all_desc: 'Performance tabulated data for all recorded data'
|
99
|
+
datatable_desc: 'Performance tabulated data'
|
100
|
+
datarange: 'From %{from} to %{to}'
|
102
101
|
authority: Authority
|
103
102
|
average_times: Average (ms)
|
104
103
|
fastest_times: 10th percentile (ms)
|
@@ -20,6 +20,10 @@ QaServer.config do |config|
|
|
20
20
|
# @param [Boolean] display history datatable when true
|
21
21
|
# config.display_historical_datatable = true
|
22
22
|
|
23
|
+
# Historical datatable default time period.
|
24
|
+
# @param [Symbol] time period for calculating historical pass/fail (i.e., one of :month, :year, or :all)
|
25
|
+
# config.historical_datatable_default_time_period = :year
|
26
|
+
|
23
27
|
# Displays a graph of performance test data when true
|
24
28
|
# @param [Boolean] display performance graph when true
|
25
29
|
# config.display_performance_graph = false
|
data/lib/qa_server.rb
CHANGED
@@ -27,29 +27,6 @@ module QaServer
|
|
27
27
|
@config
|
28
28
|
end
|
29
29
|
|
30
|
-
# @return [ActiveSupport::TimeWithZone] current DateTime in the configured preferred_time_zone_name
|
31
|
-
def self.current_time
|
32
|
-
Time.now.in_time_zone(QaServer.config.preferred_time_zone_name)
|
33
|
-
end
|
34
|
-
|
35
|
-
# @return [Float] current DateTime in seconds
|
36
|
-
def self.current_time_s
|
37
|
-
current_time.to_f
|
38
|
-
end
|
39
|
-
|
40
|
-
# @return [ActiveSupport::TimeWithZone] DateTime at which cache should expire
|
41
|
-
def self.monitoring_expires_at
|
42
|
-
offset = QaServer.config.hour_offset_to_expire_cache
|
43
|
-
offset_time = current_time
|
44
|
-
offset_time = offset_time.tomorrow unless (offset_time + 5.minutes).hour < offset
|
45
|
-
offset_time.beginning_of_day + offset.hours - 5.minutes
|
46
|
-
end
|
47
|
-
|
48
|
-
# @return [Float] number of seconds until cache should expire
|
49
|
-
def self.cache_expiry
|
50
|
-
monitoring_expires_at - current_time
|
51
|
-
end
|
52
|
-
|
53
30
|
def self.log_agent_info(request)
|
54
31
|
return if !Qa.config.respond_to?(:suppress_ip_data_from_log) || Qa.config.suppress_ip_data_from_log
|
55
32
|
user_agent = request.respond_to?(:user_agent) && !request.user_agent.nil? ? ::UserAgent.parse(request.user_agent) : nil
|
@@ -59,6 +59,20 @@ module QaServer
|
|
59
59
|
@display_historical_datatable = true
|
60
60
|
end
|
61
61
|
|
62
|
+
# Historical datatable default time period.
|
63
|
+
# @param [Symbol] time period for calculating historical pass/fail (i.e., one of :month, :year, or :all)
|
64
|
+
# @raise [ArgumentError] if time_period is not one of :month, :year, or :all
|
65
|
+
def historical_datatable_default_time_period=(time_period)
|
66
|
+
raise ArgumentError, 'time_period must be one of :day, :month, or :year' unless [:month, :year, :all].include? time_period
|
67
|
+
@historical_datatable_default_time_period = time_period
|
68
|
+
end
|
69
|
+
|
70
|
+
# Historical datatable default time period.
|
71
|
+
# @return [Symbol] time period for calculating historical pass/fail (i.e., one of :month, :year, or :all)
|
72
|
+
def historical_datatable_default_time_period
|
73
|
+
@historical_datatable_default_time_period ||= :year
|
74
|
+
end
|
75
|
+
|
62
76
|
# Displays a graph of performance test data when true
|
63
77
|
# @param [Boolean] display performance graph when true
|
64
78
|
attr_writer :display_performance_graph
|
@@ -187,9 +201,15 @@ module QaServer
|
|
187
201
|
@suppress_logging_performance_datails ||= false
|
188
202
|
end
|
189
203
|
|
204
|
+
# For internal use only
|
190
205
|
# TODO: consider refactor performance caching to use Rails cache
|
191
206
|
def performance_cache
|
192
207
|
@performance_cache ||= QaServer::PerformanceCache.new
|
193
208
|
end
|
209
|
+
|
210
|
+
# For internal use only
|
211
|
+
def monitor_logger
|
212
|
+
@monitor_logger ||= Logger.new(ENV['MONITOR_LOG_PATH'] || File.join("log", "monitor.log"))
|
213
|
+
end
|
194
214
|
end
|
195
215
|
end
|
data/lib/qa_server/version.rb
CHANGED
data/spec/lib/qa_server_spec.rb
CHANGED
@@ -3,57 +3,6 @@ require 'spec_helper'
|
|
3
3
|
|
4
4
|
RSpec.describe QaServer do
|
5
5
|
# rubocop:disable RSpec/MessageChain
|
6
|
-
let(:timezone_name) { 'Eastern Time (US & Canada)' }
|
7
|
-
before { allow(described_class).to receive_message_chain(:config, :preferred_time_zone_name).and_return(timezone_name) }
|
8
|
-
|
9
|
-
describe '.current_time' do
|
10
|
-
before do
|
11
|
-
allow(Time).to receive(:now).and_return(DateTime.parse('2019-12-11 05:00:00 -0500').in_time_zone(timezone_name))
|
12
|
-
end
|
13
|
-
|
14
|
-
it 'returns the time in the preferred time zone' do
|
15
|
-
puts 'Running QaServer.current_time spec'
|
16
|
-
expect(described_class.current_time.zone).to eq 'EST'
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
describe '.monitoring_expires_at' do
|
21
|
-
before do
|
22
|
-
allow(described_class).to receive_message_chain(:config, :hour_offset_to_expire_cache).and_return(3)
|
23
|
-
end
|
24
|
-
|
25
|
-
context 'when current hour is before offset time' do
|
26
|
-
before do
|
27
|
-
allow(described_class).to receive(:current_time).and_return(DateTime.parse('2019-12-11 02:54:00 -0500').in_time_zone(timezone_name))
|
28
|
-
end
|
29
|
-
|
30
|
-
it 'returns expiration on current date at offset time' do
|
31
|
-
expect(described_class.monitoring_expires_at).to eq DateTime.parse('2019-12-11 02:55:00 -0500').in_time_zone(timezone_name)
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
context 'when current hour is after offset time' do
|
36
|
-
before do
|
37
|
-
allow(described_class).to receive(:current_time).and_return(DateTime.parse('2019-12-11 02:56:00 -0500').in_time_zone(timezone_name))
|
38
|
-
end
|
39
|
-
|
40
|
-
it 'returns expiration on previous date at offset time' do
|
41
|
-
expect(described_class.monitoring_expires_at).to eq DateTime.parse('2019-12-12 02:55:00 -0500').in_time_zone(timezone_name)
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
describe '.cache_expiry' do
|
47
|
-
before do
|
48
|
-
allow(described_class).to receive_message_chain(:config, :hour_offset_to_expire_cache).and_return(3)
|
49
|
-
allow(Time).to receive(:now).and_return(DateTime.parse('2019-12-11 02:54:59 -0500').in_time_zone(timezone_name))
|
50
|
-
end
|
51
|
-
|
52
|
-
it 'returns seconds until offset time (simulates 1 second before offset time)' do
|
53
|
-
expect(described_class.cache_expiry).to eq 1.second
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
6
|
# rubocop:disable RSpec/MessageSpies
|
58
7
|
describe '.log_agent_info' do
|
59
8
|
let(:request) { double }
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
RSpec.describe QaServer::MonitorCacheService do
|
5
|
+
# rubocop:disable RSpec/MessageChain
|
6
|
+
let(:timezone_name) { 'Eastern Time (US & Canada)' }
|
7
|
+
before { allow(described_class).to receive_message_chain(:config, :preferred_time_zone_name).and_return(timezone_name) }
|
8
|
+
|
9
|
+
describe '.cache_expiry' do
|
10
|
+
before do
|
11
|
+
allow(described_class).to receive_message_chain(:config, :hour_offset_to_expire_cache).and_return(3)
|
12
|
+
allow(Time).to receive(:now).and_return(DateTime.parse('2019-12-11 02:54:59 -0500').in_time_zone(timezone_name))
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'returns seconds until offset time (simulates 1 second before offset time)' do
|
16
|
+
expect(described_class.cache_expiry).to eq 1.second
|
17
|
+
end
|
18
|
+
end
|
19
|
+
# rubocop:enable RSpec/MessageChain
|
20
|
+
end
|