Skip to content

Commit

Permalink
Merge pull request #311 from LD4P/refactor/env_max_cache
Browse files Browse the repository at this point in the history
make performance cache size settable by environment variable
  • Loading branch information
elrayle authored Feb 20, 2020
2 parents 00fdd5f + 65711c3 commit 9cd8857
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 7 deletions.
6 changes: 5 additions & 1 deletion app/controllers/qa_server/check_status_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,12 @@ def authority_name
end

def log_header
QaServer.config.performance_cache_logger.debug("------------------------------------- check status ---------------------------------")
QaServer.config.performance_cache_logger.debug("---------------------- check status (max_cache_size = #{max_cache_size}) ----------------------")
QaServer.config.performance_cache_logger.debug("(#{self.class}##{__method__}) check status page request (authority_name # #{authority_name})")
end

def max_cache_size
ActiveSupport::NumberHelper.number_to_human_size(QaServer.config.max_performance_cache_size)
end
end
end
29 changes: 23 additions & 6 deletions lib/qa_server/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def preferred_time_zone_name
end

# Set preferred hour to expire caches related to slow running calculations (e.g. monitoring tests, performance data)
# @param [Integer] count of hours after midnight (0-23 with 0=midnight)
# @param offset [Integer] count of hours after midnight (0-23 with 0=midnight)
# @raise [ArgumentError] if offset is not between 0 and 23
# @example
# For preferred_time_zone_name of 'Eastern Time (US & Canada)', use 3 for slow down at midnight PT/3am ET
Expand All @@ -27,7 +27,7 @@ def hour_offset_to_expire_cache
end

# Set preferred hour to run monitoring tests (deprecated)
# @param [Integer] count of hours from midnight (0-23 with 0=midnight)
# @param offset [Integer] count of hours from midnight (0-23 with 0=midnight)
# @example
# For preferred_time_zone_name of 'Eastern Time (US & Canada)', use 3 for slow down at midnight PT/3am ET
# For preferred_time_zone_name of 'Pacific Time (US & Canada)', use 0 for slow down at midnight PT/3am ET
Expand Down Expand Up @@ -60,7 +60,7 @@ def display_historical_datatable?
end

# Historical datatable default time period.
# @param [Symbol] time period for calculating historical pass/fail (i.e., one of :month, :year, or :all)
# @param time_period [Symbol] time period for calculating historical pass/fail (i.e., one of :month, :year, or :all)
# @raise [ArgumentError] if time_period is not one of :month, :year, or :all
def historical_datatable_default_time_period=(time_period)
raise ArgumentError, 'time_period must be one of :day, :month, or :year' unless [:month, :year, :all].include? time_period
Expand Down Expand Up @@ -112,7 +112,7 @@ def performance_normalization_color
end

# Performance graph default time period for all graphs. All authorities will show the graph for this time period on page load.
# @param [Symbol] time period for default display of performance graphs (i.e., one of :day, :month, or :year)
# @param time_period [Symbol] time period for default display of performance graphs (i.e., one of :day, :month, or :year)
# @raise [ArgumentError] if time_period is not one of :day, :month, or :year
def performance_graph_default_time_period=(time_period)
raise ArgumentError, 'time_period must be one of :day, :month, or :year' unless [:day, :month, :year].include? time_period
Expand All @@ -134,7 +134,7 @@ def display_performance_datatable?
end

# Performance datatable default time period for calculating stats.
# @param [Symbol] time period for calculating performance stats (i.e., one of :day, :month, :year, or :all)
# @param time_period [Symbol] time period for calculating performance stats (i.e., one of :day, :month, :year, or :all)
# @raise [ArgumentError] if time_period is not one of :day, :month, :year, or :all
def performance_datatable_default_time_period=(time_period)
raise ArgumentError, 'time_period must be one of :day, :month, :year, or :all' unless [:day, :month, :year, :all].include? time_period
Expand Down Expand Up @@ -205,7 +205,7 @@ def suppress_logging_performance_datails
# @param [Integer] maximum size of performance cache before flushing
attr_writer :max_performance_cache_size
def max_performance_cache_size
@max_performance_cache_size ||= 32.megabytes
@max_performance_cache_size ||= convert_size_to_bytes(ENV['MAX_PERFORMANCE_CACHE_SIZE']) || 32.megabytes
end

# For internal use only
Expand Down Expand Up @@ -242,5 +242,22 @@ def disable_monitor_status_logging
def monitor_logger
@monitor_logger ||= Logger.new(ENV['MONITOR_LOG_PATH'] || File.join("log", "monitor.log"))
end

private

def convert_size_to_bytes(size)
md = size.match(/^(?<num>\d+)\s?(?<unit>\w+)?$/)
md[:num].to_i *
case md[:unit].upcase
when 'KB'
1024
when 'MB'
1024**2
when 'GB'
1024**3
else
1
end
end
end
end

0 comments on commit 9cd8857

Please sign in to comment.