Class: QaServer::ScenarioRunHistory

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/qa_server/scenario_run_history.rb

Constant Summary collapse

GOOD_MARKER =
''
BAD_MARKER =
'X'
UNKNOWN_MARKER =
'?'

Class Method Summary collapse

Class Method Details

.historical_summary(force: false) ⇒ Object

Get a summary level of historical data

Examples:

auth_name, failing, passing
{ 'agrovoc' => { "good" => 0, "bad" => 24 },
  'geonames_ld4l_cache' => { "good" => 2, "bad" => 22 } }


141
142
143
144
145
# File 'app/models/qa_server/scenario_run_history.rb', line 141

def historical_summary(force: false)
  Rails.cache.fetch("QaServer::ScenarioRunHistory/#{__method__}", expires_in: QaServer::MonitorCacheService.cache_expiry, race_condition_ttl: 1.minute, force: force) do
    runs_per_authority_for_time_period
  end
end

.run_failures(run_id:, force: false) ⇒ Object

Get set of failures for a run, if any.

Examples:

[ { status: :bad,
    authority_name: "geonames_ld4l_cache",
    subauthority_name: "area",
    service: "ld4l_cache",
    action: "search",
    url: "/qa/search/linked_data/geonames_ld4l_cache/area?q=France&maxRecords=4",
    err_message: "Unable to connect to authority",
    scenario_type: :connection
    run_time: 11.2 },
  { status: :unknown,
    authority_name: "oclcfast_ld4l_cache",
    subauthority_name: "Person",
    service: "ld4l_cache",
    action: "search",
    url: "/qa/search/linked_data/oclcfast_ld4l_cache/person?q=mark twain&maxRecords=4",
    err_message: "Not enough search results returned",
    scenario_type: :connection
    run_time: 0.123 } ]

Parameters:

  • run_id (Integer)

    the run on which to gather statistics

  • force (Boolean) (defaults to: false)

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



128
129
130
131
132
133
134
# File 'app/models/qa_server/scenario_run_history.rb', line 128

def run_failures(run_id:, force: false)
  return [] unless run_id
  Rails.cache.fetch("QaServer::ScenarioRunHistory/#{__method__}", expires_in: QaServer::MonitorCacheService.cache_expiry, race_condition_ttl: 1.minute, force: force) do
    QaServer.config.monitor_logger.info("(QaServer::ScenarioRunHistory##{__method__}) - finding failures in latest run - cache expired or refresh requested (force: #{force})")
    QaServer::ScenarioRunHistory.where(scenario_run_registry_id: run_id).where.not(status: :good).to_a
  end
end

.run_results(run_id:, authority_name: nil, status: nil, url: nil) ⇒ Object

Deprecated.

Not used anywhere. Being removed.

Get set of all scenario results for a run.

Examples:

[ { status: :bad,
    authority_name: "geonames_ld4l_cache",
    subauthority_name: "area",
    service: "ld4l_cache",
    action: "search",
    url: "/qa/search/linked_data/geonames_ld4l_cache/area?q=France&maxRecords=4",
    err_message: "Unable to connect to authority",
    scenario_type: :connection
    run_time: 11.2 },
  { status: :good,
    authority_name: "oclcfast_ld4l_cache",
    subauthority_name: "Organization",
    service: "ld4l_cache",
    action: "search",
    url: "/qa/search/linked_data/oclcfast_ld4l_cache/organization?q=mark twain&maxRecords=4",
    err_message: "",
    scenario_type: :connection
    run_time: 0.131 },
  { status: :unknown,
    authority_name: "oclcfast_ld4l_cache",
    subauthority_name: "Person",
    service: "ld4l_cache",
    action: "search",
    url: "/qa/search/linked_data/oclcfast_ld4l_cache/person?q=mark twain&maxRecords=4",
    err_message: "Not enough search results returned",
    scenario_type: :connection
    run_time: 0.123 } ]

Parameters:

  • run_id (Integer)

    the run on which to gather statistics

  • authority_name (String) (defaults to: nil)

    limit results to those for the authority with this name

  • status (Array<Symbol> | Symbol) (defaults to: nil)

    :good, :bad, :unknown, or any of these in an array to select multiple status

  • url (String) (defaults to: nil)

    limit results to a specific scenario URL



94
95
96
97
98
99
100
101
102
# File 'app/models/qa_server/scenario_run_history.rb', line 94

def run_results(run_id:, authority_name: nil, status: nil, url: nil)
  return [] unless run_id
  where = {}
  where[:scenario_run_registry_id] = run_id
  where[:authority_name] = authority_name if authority_name.present?
  where[:status] = status if status.present?
  where[:url] = url if url.present?
  QaServer::ScenarioRunHistory.where(where).to_a
end

.run_summary(scenario_run:, force: false) ⇒ Object

Get a summary of passing/failing tests for a run.

Examples:

ScenarioRunSummary includes methods for accessing

* run_id: 14,
* run_dt_stamp:
* authority_count: 22,
* failing_authority_count: 1
* passing_scenario_count: 156,
* failing_scenario_count: 3,
* total_scenario_count: 159,

Parameters:

  • scenario_run (QaServer::ScenarioRunRegistry)

    the run on which to gather statistics

  • force (Boolean) (defaults to: false)

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



46
47
48
49
50
51
52
53
54
55
56
57
# File 'app/models/qa_server/scenario_run_history.rb', line 46

def run_summary(scenario_run:, force: false)
  Rails.cache.fetch("QaServer::ScenarioRunHistory/#{__method__}", expires_in: QaServer::MonitorCacheService.cache_expiry, race_condition_ttl: 1.minute, force: force) do
    QaServer.config.monitor_logger.info("(QaServer::ScenarioRunHistory##{__method__}) - creating summary of latest run - cache expired or refresh requested (force: #{force})")
    status = status_counts_in_run(run_id: scenario_run.id)
    summary_class.new(run_id: scenario_run.id,
                      run_dt_stamp: scenario_run.dt_stamp,
                      authority_count: authorities_in_run(run_id: scenario_run.id).count,
                      failing_authority_count: authorities_with_failures_in_run(run_id: scenario_run.id).count,
                      passing_scenario_count: status['good'],
                      failing_scenario_count: status['bad'] + status['unknown'])
  end
end

.save_result(run_id:, scenario_result:) ⇒ Object

Save a scenario result

Parameters:

  • run_id (Integer)

    the run on which to gather statistics

  • result (Hash)

    the scenario result to be saved



22
23
24
25
26
27
28
29
30
31
32
# File 'app/models/qa_server/scenario_run_history.rb', line 22

def save_result(run_id:, scenario_result:)
  QaServer::ScenarioRunHistory.create(scenario_run_registry_id: run_id,
                                      status: scenario_result[:status],
                                      authority_name: scenario_result[:authority_name],
                                      subauthority_name: scenario_result[:subauthority_name],
                                      service: scenario_result[:service],
                                      action: scenario_result[:action],
                                      url: scenario_result[:url],
                                      err_message: scenario_result[:err_message],
                                      run_time: scenario_result[:run_time])
end