Class: QaServer::PerformanceGraphDataService

Inherits:
Object
  • Object
show all
Extended by:
PerformanceHistoryDataKeys
Defined in:
app/services/qa_server/performance_graph_data_service.rb

Constant Summary

Constants included from PerformanceHistoryDataKeys

QaServer::PerformanceHistoryDataKeys::ALL_ACTIONS, QaServer::PerformanceHistoryDataKeys::ALL_AUTH, QaServer::PerformanceHistoryDataKeys::AVG_ACTN, QaServer::PerformanceHistoryDataKeys::AVG_FULL, QaServer::PerformanceHistoryDataKeys::AVG_GRPH, QaServer::PerformanceHistoryDataKeys::AVG_LOAD, QaServer::PerformanceHistoryDataKeys::AVG_NORM, QaServer::PerformanceHistoryDataKeys::AVG_RETR, QaServer::PerformanceHistoryDataKeys::BY_DAY, QaServer::PerformanceHistoryDataKeys::BY_HOUR, QaServer::PerformanceHistoryDataKeys::BY_MONTH, QaServer::PerformanceHistoryDataKeys::FETCH, QaServer::PerformanceHistoryDataKeys::FOR_DATATABLE, QaServer::PerformanceHistoryDataKeys::FOR_DAY, QaServer::PerformanceHistoryDataKeys::FOR_MONTH, QaServer::PerformanceHistoryDataKeys::FOR_YEAR, QaServer::PerformanceHistoryDataKeys::HIGH_ACTN, QaServer::PerformanceHistoryDataKeys::HIGH_FULL, QaServer::PerformanceHistoryDataKeys::HIGH_GRPH, QaServer::PerformanceHistoryDataKeys::HIGH_LOAD, QaServer::PerformanceHistoryDataKeys::HIGH_NORM, QaServer::PerformanceHistoryDataKeys::HIGH_RETR, QaServer::PerformanceHistoryDataKeys::LOW_ACTN, QaServer::PerformanceHistoryDataKeys::LOW_FULL, QaServer::PerformanceHistoryDataKeys::LOW_GRPH, QaServer::PerformanceHistoryDataKeys::LOW_LOAD, QaServer::PerformanceHistoryDataKeys::LOW_NORM, QaServer::PerformanceHistoryDataKeys::LOW_RETR, QaServer::PerformanceHistoryDataKeys::SEARCH, QaServer::PerformanceHistoryDataKeys::STATS

Class Method Summary collapse

Class Method Details

.average_last_12_months(authority_name: nil, action: nil, force: false) ⇒ Object

Get daily average for the past 12 months.

Examples:

{ 0: { month: '09-2019', stats: { load_avg_ms: 12.3, normalization_avg_ms: 4.2, full_request_avg_ms: 16.5, etc. }},
  1: { month: '10-2019', stats: { load_avg_ms: 12.3, normalization_avg_ms: 4.2, full_request_avg_ms: 16.5, etc. }},
  2: { month: '11-2019', stats: { load_avg_ms: 12.3, normalization_avg_ms: 4.2, full_request_avg_ms: 16.5, etc. }},
  ...,
  11: { month: '08-2019', stats: { load_avg_ms: 12.3, normalization_avg_ms: 4.2, full_request_avg_ms: 16.5, etc. }}
}

Parameters:

  • authority_name (String) (defaults to: nil)

    limit statistics to records for the given authority (default: all authorities)

  • action (Symbol) (defaults to: nil)

    one of :search, :fetch, :all_actions

  • force (Boolean) (defaults to: false)

    if true, forces cache to regenerate; otherwise, returns value from cache unless expired



65
66
67
68
69
70
71
# File 'app/services/qa_server/performance_graph_data_service.rb', line 65

def average_last_12_months(authority_name: nil, action: nil, force: false)
  Rails.cache.fetch("#{self.class}/#{__method__}/#{authority_name || ALL_AUTH}/#{action}/#{FOR_YEAR}",
                    expires_in: QaServer.cache_expiry, race_condition_ttl: 1.hour, force: force) do
    Rails.logger.info("#{self.class}##{__method__} - calculating performance stats for last 12 months - cache expired or refresh requested (#{force})")
    calculate_last_12_months(authority_name, action)
  end
end

.average_last_24_hours(authority_name: nil, action: nil, force: false) ⇒ Object

Get hourly average for the past 24 hours.

Examples:

{ 0: { hour: '1400', stats: { load_avg_ms: 12.3, normalization_avg_ms: 4.2, full_request_avg_ms: 16.5, etc. }},
  1: { hour: '1500', stats: { load_avg_ms: 12.3, normalization_avg_ms: 4.2, full_request_avg_ms: 16.5, etc. }},
  2: { hour: '1600', stats: { load_avg_ms: 12.3, normalization_avg_ms: 4.2, full_request_avg_ms: 16.5, etc. }},
  ...,
  23: { hour: 'NOW', stats: { load_avg_ms: 12.3, normalization_avg_ms: 4.2, full_request_avg_ms: 16.5, etc. }}
}

Parameters:

  • authority_name (String) (defaults to: nil)

    limit statistics to records for the given authority (default: all authorities)

  • action (Symbol) (defaults to: nil)

    one of :search, :fetch, :all_actions

  • force (Boolean) (defaults to: false)

    if true, forces cache to regenerate; otherwise, returns value from cache unless expired



24
25
26
27
28
29
30
31
# File 'app/services/qa_server/performance_graph_data_service.rb', line 24

def average_last_24_hours(authority_name: nil, action: nil, force: false)
  Rails.cache.fetch("#{self.class}/#{__method__}/#{authority_name || ALL_AUTH}/#{action}/#{FOR_DAY}",
                    expires_in: QaServer.current_time.end_of_hour - QaServer.current_time,
                    race_condition_ttl: 1.hour, force: force) do
    Rails.logger.info("#{self.class}##{__method__} - calculating performance stats for last 24 hours - cache expired or refresh requested (#{force})")
    calculate_last_24_hours(authority_name, action)
  end
end

.average_last_30_days(authority_name: nil, action: nil, force: false) ⇒ Object

Get daily average for the past 30 days.

Examples:

{ 0: { day: '07-15-2019', stats: { load_avg_ms: 12.3, normalization_avg_ms: 4.2, full_request_avg_ms: 16.5, etc. }},
  1: { day: '07-16-2019', stats: { load_avg_ms: 12.3, normalization_avg_ms: 4.2, full_request_avg_ms: 16.5, etc. }},
  2: { day: '07-17-2019', stats: { load_avg_ms: 12.3, normalization_avg_ms: 4.2, full_request_avg_ms: 16.5, etc. }},
  ...,
  29: { day: 'TODAY', stats: { load_avg_ms: 12.3, normalization_avg_ms: 4.2, full_request_avg_ms: 16.5, etc. }}
}

Parameters:

  • authority_name (String) (defaults to: nil)

    limit statistics to records for the given authority (default: all authorities)

  • action (Symbol) (defaults to: nil)

    one of :search, :fetch, :all_actions

  • force (Boolean) (defaults to: false)

    if true, forces cache to regenerate; otherwise, returns value from cache unless expired



45
46
47
48
49
50
51
# File 'app/services/qa_server/performance_graph_data_service.rb', line 45

def average_last_30_days(authority_name: nil, action: nil, force: false)
  Rails.cache.fetch("#{self.class}/#{__method__}/#{authority_name || ALL_AUTH}/#{action}/#{FOR_MONTH}",
                    expires_in: QaServer.cache_expiry, race_condition_ttl: 1.hour, force: force) do
    Rails.logger.info("#{self.class}##{__method__} - calculating performance stats for last 30 days - cache expired or refresh requested (#{force})")
    calculate_last_30_days(authority_name, action)
  end
end