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
 
| 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            # frozen_string_literal: true
         
     | 
| 
       2 
     | 
    
         
            -
            # Provide access to the  
     | 
| 
      
 2 
     | 
    
         
            +
            # Provide access to the scenario_run_history database table which tracks scenario runs over time.
         
     | 
| 
       3 
3 
     | 
    
         
             
            module QaServer
         
     | 
| 
       4 
     | 
    
         
            -
              class ScenarioRunHistory < ActiveRecord::Base 
     | 
| 
      
 4 
     | 
    
         
            +
              class ScenarioRunHistory < ActiveRecord::Base
         
     | 
| 
       5 
5 
     | 
    
         
             
                self.table_name = 'scenario_run_history'
         
     | 
| 
       6 
6 
     | 
    
         
             
                belongs_to :scenario_run_registry
         
     | 
| 
       7 
7 
     | 
    
         
             
                enum scenario_type: [:connection, :accuracy, :performance], _suffix: :type
         
     | 
| 
         @@ -15,195 +15,180 @@ module QaServer 
     | 
|
| 
       15 
15 
     | 
    
         | 
| 
       16 
16 
     | 
    
         
             
                self.summary_class = QaServer::ScenarioRunSummary
         
     | 
| 
       17 
17 
     | 
    
         | 
| 
       18 
     | 
    
         
            -
                 
     | 
| 
       19 
     | 
    
         
            -
             
     | 
| 
       20 
     | 
    
         
            -
             
     | 
| 
       21 
     | 
    
         
            -
             
     | 
| 
       22 
     | 
    
         
            -
                   
     | 
| 
       23 
     | 
    
         
            -
             
     | 
| 
       24 
     | 
    
         
            -
             
     | 
| 
       25 
     | 
    
         
            -
             
     | 
| 
       26 
     | 
    
         
            -
             
     | 
| 
       27 
     | 
    
         
            -
             
     | 
| 
       28 
     | 
    
         
            -
             
     | 
| 
       29 
     | 
    
         
            -
             
     | 
| 
       30 
     | 
    
         
            -
             
     | 
| 
       31 
     | 
    
         
            -
             
     | 
| 
      
 18 
     | 
    
         
            +
                class << self
         
     | 
| 
      
 19 
     | 
    
         
            +
                  # Save a scenario result
         
     | 
| 
      
 20 
     | 
    
         
            +
                  # @param run_id [Integer] the run on which to gather statistics
         
     | 
| 
      
 21 
     | 
    
         
            +
                  # @param result [Hash] the scenario result to be saved
         
     | 
| 
      
 22 
     | 
    
         
            +
                  def save_result(run_id:, scenario_result:)
         
     | 
| 
      
 23 
     | 
    
         
            +
                    QaServer::ScenarioRunHistory.create(scenario_run_registry_id: run_id,
         
     | 
| 
      
 24 
     | 
    
         
            +
                                                        status: scenario_result[:status],
         
     | 
| 
      
 25 
     | 
    
         
            +
                                                        authority_name: scenario_result[:authority_name],
         
     | 
| 
      
 26 
     | 
    
         
            +
                                                        subauthority_name: scenario_result[:subauthority_name],
         
     | 
| 
      
 27 
     | 
    
         
            +
                                                        service: scenario_result[:service],
         
     | 
| 
      
 28 
     | 
    
         
            +
                                                        action: scenario_result[:action],
         
     | 
| 
      
 29 
     | 
    
         
            +
                                                        url: scenario_result[:url],
         
     | 
| 
      
 30 
     | 
    
         
            +
                                                        err_message: scenario_result[:err_message],
         
     | 
| 
      
 31 
     | 
    
         
            +
                                                        run_time: scenario_result[:run_time])
         
     | 
| 
      
 32 
     | 
    
         
            +
                  end
         
     | 
| 
       32 
33 
     | 
    
         | 
| 
       33 
     | 
    
         
            -
             
     | 
| 
       34 
     | 
    
         
            -
             
     | 
| 
       35 
     | 
    
         
            -
             
     | 
| 
       36 
     | 
    
         
            -
             
     | 
| 
       37 
     | 
    
         
            -
             
     | 
| 
       38 
     | 
    
         
            -
             
     | 
| 
       39 
     | 
    
         
            -
             
     | 
| 
       40 
     | 
    
         
            -
             
     | 
| 
       41 
     | 
    
         
            -
             
     | 
| 
       42 
     | 
    
         
            -
             
     | 
| 
       43 
     | 
    
         
            -
             
     | 
| 
       44 
     | 
    
         
            -
             
     | 
| 
       45 
     | 
    
         
            -
             
     | 
| 
       46 
     | 
    
         
            -
             
     | 
| 
       47 
     | 
    
         
            -
             
     | 
| 
       48 
     | 
    
         
            -
             
     | 
| 
       49 
     | 
    
         
            -
             
     | 
| 
       50 
     | 
    
         
            -
             
     | 
| 
       51 
     | 
    
         
            -
             
     | 
| 
       52 
     | 
    
         
            -
             
     | 
| 
       53 
     | 
    
         
            -
             
     | 
| 
       54 
     | 
    
         
            -
             
     | 
| 
      
 34 
     | 
    
         
            +
                  # Get a summary of passing/failing tests for a run.
         
     | 
| 
      
 35 
     | 
    
         
            +
                  # @param scenario_run [QaServer::ScenarioRunRegistry] the run on which to gather statistics
         
     | 
| 
      
 36 
     | 
    
         
            +
                  # @param force [Boolean] if true, forces cache to regenerate; otherwise, returns value from cache unless expired
         
     | 
| 
      
 37 
     | 
    
         
            +
                  # @returns [QaServer::ScenarioRunSummary] statistics on the requested run
         
     | 
| 
      
 38 
     | 
    
         
            +
                  # @example ScenarioRunSummary includes methods for accessing
         
     | 
| 
      
 39 
     | 
    
         
            +
                  #   * run_id: 14,
         
     | 
| 
      
 40 
     | 
    
         
            +
                  #   * run_dt_stamp:
         
     | 
| 
      
 41 
     | 
    
         
            +
                  #   * authority_count: 22,
         
     | 
| 
      
 42 
     | 
    
         
            +
                  #   * failing_authority_count: 1
         
     | 
| 
      
 43 
     | 
    
         
            +
                  #   * passing_scenario_count: 156,
         
     | 
| 
      
 44 
     | 
    
         
            +
                  #   * failing_scenario_count: 3,
         
     | 
| 
      
 45 
     | 
    
         
            +
                  #   * total_scenario_count: 159,
         
     | 
| 
      
 46 
     | 
    
         
            +
                  def run_summary(scenario_run:, force: false)
         
     | 
| 
      
 47 
     | 
    
         
            +
                    Rails.cache.fetch("QaServer::ScenarioRunHistory/#{__method__}", expires_in: QaServer::MonitorCacheService.cache_expiry, race_condition_ttl: 1.minute, force: force) do
         
     | 
| 
      
 48 
     | 
    
         
            +
                      QaServer.config.monitor_logger.info("(QaServer::ScenarioRunHistory##{__method__}) - creating summary of latest run - cache expired or refresh requested (force: #{force})")
         
     | 
| 
      
 49 
     | 
    
         
            +
                      status = status_counts_in_run(run_id: scenario_run.id)
         
     | 
| 
      
 50 
     | 
    
         
            +
                      summary_class.new(run_id: scenario_run.id,
         
     | 
| 
      
 51 
     | 
    
         
            +
                                        run_dt_stamp: scenario_run.dt_stamp,
         
     | 
| 
      
 52 
     | 
    
         
            +
                                        authority_count: authorities_in_run(run_id: scenario_run.id).count,
         
     | 
| 
      
 53 
     | 
    
         
            +
                                        failing_authority_count: authorities_with_failures_in_run(run_id: scenario_run.id).count,
         
     | 
| 
      
 54 
     | 
    
         
            +
                                        passing_scenario_count: status['good'],
         
     | 
| 
      
 55 
     | 
    
         
            +
                                        failing_scenario_count: status['bad'] + status['unknown'])
         
     | 
| 
      
 56 
     | 
    
         
            +
                    end
         
     | 
| 
       55 
57 
     | 
    
         
             
                  end
         
     | 
| 
       56 
     | 
    
         
            -
                end
         
     | 
| 
       57 
58 
     | 
    
         | 
| 
       58 
     | 
    
         
            -
             
     | 
| 
       59 
     | 
    
         
            -
             
     | 
| 
       60 
     | 
    
         
            -
             
     | 
| 
       61 
     | 
    
         
            -
             
     | 
| 
       62 
     | 
    
         
            -
             
     | 
| 
       63 
     | 
    
         
            -
             
     | 
| 
       64 
     | 
    
         
            -
             
     | 
| 
       65 
     | 
    
         
            -
             
     | 
| 
       66 
     | 
    
         
            -
             
     | 
| 
       67 
     | 
    
         
            -
             
     | 
| 
       68 
     | 
    
         
            -
             
     | 
| 
       69 
     | 
    
         
            -
             
     | 
| 
       70 
     | 
    
         
            -
             
     | 
| 
       71 
     | 
    
         
            -
             
     | 
| 
       72 
     | 
    
         
            -
             
     | 
| 
       73 
     | 
    
         
            -
             
     | 
| 
       74 
     | 
    
         
            -
             
     | 
| 
       75 
     | 
    
         
            -
             
     | 
| 
       76 
     | 
    
         
            -
             
     | 
| 
       77 
     | 
    
         
            -
             
     | 
| 
       78 
     | 
    
         
            -
             
     | 
| 
       79 
     | 
    
         
            -
             
     | 
| 
       80 
     | 
    
         
            -
             
     | 
| 
       81 
     | 
    
         
            -
             
     | 
| 
       82 
     | 
    
         
            -
             
     | 
| 
       83 
     | 
    
         
            -
             
     | 
| 
       84 
     | 
    
         
            -
             
     | 
| 
       85 
     | 
    
         
            -
             
     | 
| 
       86 
     | 
    
         
            -
             
     | 
| 
       87 
     | 
    
         
            -
             
     | 
| 
       88 
     | 
    
         
            -
             
     | 
| 
       89 
     | 
    
         
            -
             
     | 
| 
       90 
     | 
    
         
            -
             
     | 
| 
       91 
     | 
    
         
            -
             
     | 
| 
       92 
     | 
    
         
            -
             
     | 
| 
       93 
     | 
    
         
            -
             
     | 
| 
       94 
     | 
    
         
            -
             
     | 
| 
       95 
     | 
    
         
            -
             
     | 
| 
       96 
     | 
    
         
            -
             
     | 
| 
       97 
     | 
    
         
            -
             
     | 
| 
       98 
     | 
    
         
            -
             
     | 
| 
       99 
     | 
    
         
            -
             
     | 
| 
       100 
     | 
    
         
            -
             
     | 
| 
       101 
     | 
    
         
            -
             
     | 
| 
       102 
     | 
    
         
            -
             
     | 
| 
      
 59 
     | 
    
         
            +
                  # Get set of all scenario results for a run.
         
     | 
| 
      
 60 
     | 
    
         
            +
                  # @param run_id [Integer] the run on which to gather statistics
         
     | 
| 
      
 61 
     | 
    
         
            +
                  # @param authority_name [String] limit results to those for the authority with this name
         
     | 
| 
      
 62 
     | 
    
         
            +
                  # @param status [Array<Symbol> | Symbol] :good, :bad, :unknown, or any of these in an array to select multiple status
         
     | 
| 
      
 63 
     | 
    
         
            +
                  # @param url [String] limit results to a specific scenario URL
         
     | 
| 
      
 64 
     | 
    
         
            +
                  # @returns [Array<ScenarioRunHistory>] scenario details for all scenarios in the run
         
     | 
| 
      
 65 
     | 
    
         
            +
                  # @example
         
     | 
| 
      
 66 
     | 
    
         
            +
                  #   [ { status: :bad,
         
     | 
| 
      
 67 
     | 
    
         
            +
                  #       authority_name: "geonames_ld4l_cache",
         
     | 
| 
      
 68 
     | 
    
         
            +
                  #       subauthority_name: "area",
         
     | 
| 
      
 69 
     | 
    
         
            +
                  #       service: "ld4l_cache",
         
     | 
| 
      
 70 
     | 
    
         
            +
                  #       action: "search",
         
     | 
| 
      
 71 
     | 
    
         
            +
                  #       url: "/qa/search/linked_data/geonames_ld4l_cache/area?q=France&maxRecords=4",
         
     | 
| 
      
 72 
     | 
    
         
            +
                  #       err_message: "Unable to connect to authority",
         
     | 
| 
      
 73 
     | 
    
         
            +
                  #       scenario_type: :connection
         
     | 
| 
      
 74 
     | 
    
         
            +
                  #       run_time: 11.2 },
         
     | 
| 
      
 75 
     | 
    
         
            +
                  #     { status: :good,
         
     | 
| 
      
 76 
     | 
    
         
            +
                  #       authority_name: "oclcfast_ld4l_cache",
         
     | 
| 
      
 77 
     | 
    
         
            +
                  #       subauthority_name: "Organization",
         
     | 
| 
      
 78 
     | 
    
         
            +
                  #       service: "ld4l_cache",
         
     | 
| 
      
 79 
     | 
    
         
            +
                  #       action: "search",
         
     | 
| 
      
 80 
     | 
    
         
            +
                  #       url: "/qa/search/linked_data/oclcfast_ld4l_cache/organization?q=mark twain&maxRecords=4",
         
     | 
| 
      
 81 
     | 
    
         
            +
                  #       err_message: "",
         
     | 
| 
      
 82 
     | 
    
         
            +
                  #       scenario_type: :connection
         
     | 
| 
      
 83 
     | 
    
         
            +
                  #       run_time: 0.131 },
         
     | 
| 
      
 84 
     | 
    
         
            +
                  #     { status: :unknown,
         
     | 
| 
      
 85 
     | 
    
         
            +
                  #       authority_name: "oclcfast_ld4l_cache",
         
     | 
| 
      
 86 
     | 
    
         
            +
                  #       subauthority_name: "Person",
         
     | 
| 
      
 87 
     | 
    
         
            +
                  #       service: "ld4l_cache",
         
     | 
| 
      
 88 
     | 
    
         
            +
                  #       action: "search",
         
     | 
| 
      
 89 
     | 
    
         
            +
                  #       url: "/qa/search/linked_data/oclcfast_ld4l_cache/person?q=mark twain&maxRecords=4",
         
     | 
| 
      
 90 
     | 
    
         
            +
                  #       err_message: "Not enough search results returned",
         
     | 
| 
      
 91 
     | 
    
         
            +
                  #       scenario_type: :connection
         
     | 
| 
      
 92 
     | 
    
         
            +
                  #       run_time: 0.123 } ]
         
     | 
| 
      
 93 
     | 
    
         
            +
                  # @deprecated Not used anywhere. Being removed.
         
     | 
| 
      
 94 
     | 
    
         
            +
                  def run_results(run_id:, authority_name: nil, status: nil, url: nil)
         
     | 
| 
      
 95 
     | 
    
         
            +
                    return [] unless run_id
         
     | 
| 
      
 96 
     | 
    
         
            +
                    where = {}
         
     | 
| 
      
 97 
     | 
    
         
            +
                    where[:scenario_run_registry_id] = run_id
         
     | 
| 
      
 98 
     | 
    
         
            +
                    where[:authority_name] = authority_name if authority_name.present?
         
     | 
| 
      
 99 
     | 
    
         
            +
                    where[:status] = status if status.present?
         
     | 
| 
      
 100 
     | 
    
         
            +
                    where[:url] = url if url.present?
         
     | 
| 
      
 101 
     | 
    
         
            +
                    QaServer::ScenarioRunHistory.where(where).to_a
         
     | 
| 
      
 102 
     | 
    
         
            +
                  end
         
     | 
| 
      
 103 
     | 
    
         
            +
                  deprecation_deprecate run_results: "Not used anywhere. Being removed."
         
     | 
| 
       103 
104 
     | 
    
         | 
| 
       104 
     | 
    
         
            -
             
     | 
| 
       105 
     | 
    
         
            -
             
     | 
| 
       106 
     | 
    
         
            -
             
     | 
| 
       107 
     | 
    
         
            -
             
     | 
| 
       108 
     | 
    
         
            -
             
     | 
| 
       109 
     | 
    
         
            -
             
     | 
| 
       110 
     | 
    
         
            -
             
     | 
| 
       111 
     | 
    
         
            -
             
     | 
| 
       112 
     | 
    
         
            -
             
     | 
| 
       113 
     | 
    
         
            -
             
     | 
| 
       114 
     | 
    
         
            -
             
     | 
| 
       115 
     | 
    
         
            -
             
     | 
| 
       116 
     | 
    
         
            -
             
     | 
| 
       117 
     | 
    
         
            -
             
     | 
| 
       118 
     | 
    
         
            -
             
     | 
| 
       119 
     | 
    
         
            -
             
     | 
| 
       120 
     | 
    
         
            -
             
     | 
| 
       121 
     | 
    
         
            -
             
     | 
| 
       122 
     | 
    
         
            -
             
     | 
| 
       123 
     | 
    
         
            -
             
     | 
| 
       124 
     | 
    
         
            -
             
     | 
| 
       125 
     | 
    
         
            -
             
     | 
| 
       126 
     | 
    
         
            -
             
     | 
| 
       127 
     | 
    
         
            -
             
     | 
| 
       128 
     | 
    
         
            -
             
     | 
| 
       129 
     | 
    
         
            -
             
     | 
| 
       130 
     | 
    
         
            -
             
     | 
| 
       131 
     | 
    
         
            -
             
     | 
| 
      
 105 
     | 
    
         
            +
                  # Get set of failures for a run, if any.
         
     | 
| 
      
 106 
     | 
    
         
            +
                  # @param run_id [Integer] the run on which to gather statistics
         
     | 
| 
      
 107 
     | 
    
         
            +
                  # @param force [Boolean] if true, forces cache to regenerate; otherwise, returns value from cache unless expired
         
     | 
| 
      
 108 
     | 
    
         
            +
                  # @returns [Array<Hash>] scenario details for any failing scenarios in the run
         
     | 
| 
      
 109 
     | 
    
         
            +
                  # @example
         
     | 
| 
      
 110 
     | 
    
         
            +
                  #   [ { status: :bad,
         
     | 
| 
      
 111 
     | 
    
         
            +
                  #       authority_name: "geonames_ld4l_cache",
         
     | 
| 
      
 112 
     | 
    
         
            +
                  #       subauthority_name: "area",
         
     | 
| 
      
 113 
     | 
    
         
            +
                  #       service: "ld4l_cache",
         
     | 
| 
      
 114 
     | 
    
         
            +
                  #       action: "search",
         
     | 
| 
      
 115 
     | 
    
         
            +
                  #       url: "/qa/search/linked_data/geonames_ld4l_cache/area?q=France&maxRecords=4",
         
     | 
| 
      
 116 
     | 
    
         
            +
                  #       err_message: "Unable to connect to authority",
         
     | 
| 
      
 117 
     | 
    
         
            +
                  #       scenario_type: :connection
         
     | 
| 
      
 118 
     | 
    
         
            +
                  #       run_time: 11.2 },
         
     | 
| 
      
 119 
     | 
    
         
            +
                  #     { status: :unknown,
         
     | 
| 
      
 120 
     | 
    
         
            +
                  #       authority_name: "oclcfast_ld4l_cache",
         
     | 
| 
      
 121 
     | 
    
         
            +
                  #       subauthority_name: "Person",
         
     | 
| 
      
 122 
     | 
    
         
            +
                  #       service: "ld4l_cache",
         
     | 
| 
      
 123 
     | 
    
         
            +
                  #       action: "search",
         
     | 
| 
      
 124 
     | 
    
         
            +
                  #       url: "/qa/search/linked_data/oclcfast_ld4l_cache/person?q=mark twain&maxRecords=4",
         
     | 
| 
      
 125 
     | 
    
         
            +
                  #       err_message: "Not enough search results returned",
         
     | 
| 
      
 126 
     | 
    
         
            +
                  #       scenario_type: :connection
         
     | 
| 
      
 127 
     | 
    
         
            +
                  #       run_time: 0.123 } ]
         
     | 
| 
      
 128 
     | 
    
         
            +
                  def run_failures(run_id:, force: false)
         
     | 
| 
      
 129 
     | 
    
         
            +
                    return [] unless run_id
         
     | 
| 
      
 130 
     | 
    
         
            +
                    Rails.cache.fetch("QaServer::ScenarioRunHistory/#{__method__}", expires_in: QaServer::MonitorCacheService.cache_expiry, race_condition_ttl: 1.minute, force: force) do
         
     | 
| 
      
 131 
     | 
    
         
            +
                      QaServer.config.monitor_logger.info("(QaServer::ScenarioRunHistory##{__method__}) - finding failures in latest run - cache expired or refresh requested (force: #{force})")
         
     | 
| 
      
 132 
     | 
    
         
            +
                      QaServer::ScenarioRunHistory.where(scenario_run_registry_id: run_id).where.not(status: :good).to_a
         
     | 
| 
      
 133 
     | 
    
         
            +
                    end
         
     | 
| 
       132 
134 
     | 
    
         
             
                  end
         
     | 
| 
       133 
     | 
    
         
            -
                end
         
     | 
| 
       134 
135 
     | 
    
         | 
| 
       135 
     | 
    
         
            -
             
     | 
| 
       136 
     | 
    
         
            -
             
     | 
| 
       137 
     | 
    
         
            -
             
     | 
| 
       138 
     | 
    
         
            -
             
     | 
| 
       139 
     | 
    
         
            -
             
     | 
| 
       140 
     | 
    
         
            -
             
     | 
| 
       141 
     | 
    
         
            -
             
     | 
| 
       142 
     | 
    
         
            -
             
     | 
| 
       143 
     | 
    
         
            -
                    runs = all_runs_per_authority
         
     | 
| 
       144 
     | 
    
         
            -
                    failures = failing_runs_per_authority
         
     | 
| 
       145 
     | 
    
         
            -
                    return [] unless runs.present?
         
     | 
| 
       146 
     | 
    
         
            -
                    data = []
         
     | 
| 
       147 
     | 
    
         
            -
                    runs.each do |auth_name, run_count|
         
     | 
| 
       148 
     | 
    
         
            -
                      data << pass_fail_stats_for_authority(failures, auth_name, run_count)
         
     | 
| 
      
 136 
     | 
    
         
            +
                  # Get a summary level of historical data
         
     | 
| 
      
 137 
     | 
    
         
            +
                  # @returns [Array<Array>] summary of passing/failing tests for each authority
         
     | 
| 
      
 138 
     | 
    
         
            +
                  # @example [auth_name, failing, passing]
         
     | 
| 
      
 139 
     | 
    
         
            +
                  #   { 'agrovoc' => { "good" => 0, "bad" => 24 },
         
     | 
| 
      
 140 
     | 
    
         
            +
                  #     'geonames_ld4l_cache' => { "good" => 2, "bad" => 22 } }
         
     | 
| 
      
 141 
     | 
    
         
            +
                  def historical_summary(force: false)
         
     | 
| 
      
 142 
     | 
    
         
            +
                    Rails.cache.fetch("QaServer::ScenarioRunHistory/#{__method__}", expires_in: QaServer::MonitorCacheService.cache_expiry, race_condition_ttl: 1.minute, force: force) do
         
     | 
| 
      
 143 
     | 
    
         
            +
                      runs_per_authority_for_time_period
         
     | 
| 
       149 
144 
     | 
    
         
             
                    end
         
     | 
| 
       150 
     | 
    
         
            -
                    data
         
     | 
| 
       151 
145 
     | 
    
         
             
                  end
         
     | 
| 
       152 
     | 
    
         
            -
                end
         
     | 
| 
       153 
146 
     | 
    
         | 
| 
       154 
     | 
    
         
            -
             
     | 
| 
       155 
     | 
    
         
            -
                  auth_data = []
         
     | 
| 
       156 
     | 
    
         
            -
                  auth_data[0] = auth_name
         
     | 
| 
       157 
     | 
    
         
            -
                  failure_count = failures.key?(auth_name) ? failures[auth_name] : 0
         
     | 
| 
       158 
     | 
    
         
            -
                  auth_data[1] = failure_count
         
     | 
| 
       159 
     | 
    
         
            -
                  auth_data[2] = run_count - failure_count # passing
         
     | 
| 
       160 
     | 
    
         
            -
                  auth_data
         
     | 
| 
       161 
     | 
    
         
            -
                end
         
     | 
| 
       162 
     | 
    
         
            -
                private_class_method :pass_fail_stats_for_authority
         
     | 
| 
      
 147 
     | 
    
         
            +
                  private
         
     | 
| 
       163 
148 
     | 
    
         | 
| 
       164 
     | 
    
         
            -
             
     | 
| 
       165 
     | 
    
         
            -
             
     | 
| 
       166 
     | 
    
         
            -
             
     | 
| 
       167 
     | 
    
         
            -
                private_class_method :authorities_in_run
         
     | 
| 
      
 149 
     | 
    
         
            +
                    def authorities_in_run(run_id:)
         
     | 
| 
      
 150 
     | 
    
         
            +
                      QaServer::ScenarioRunHistory.where(scenario_run_registry_id: run_id).pluck(:authority_name).uniq
         
     | 
| 
      
 151 
     | 
    
         
            +
                    end
         
     | 
| 
       168 
152 
     | 
    
         | 
| 
       169 
     | 
    
         
            -
             
     | 
| 
       170 
     | 
    
         
            -
             
     | 
| 
       171 
     | 
    
         
            -
             
     | 
| 
       172 
     | 
    
         
            -
                private_class_method :authorities_with_failures_in_run
         
     | 
| 
      
 153 
     | 
    
         
            +
                    def authorities_with_failures_in_run(run_id:)
         
     | 
| 
      
 154 
     | 
    
         
            +
                      QaServer::ScenarioRunHistory.where(scenario_run_registry_id: run_id).where.not(status: 'good').pluck('authority_name').uniq
         
     | 
| 
      
 155 
     | 
    
         
            +
                    end
         
     | 
| 
       173 
156 
     | 
    
         | 
| 
       174 
     | 
    
         
            -
             
     | 
| 
       175 
     | 
    
         
            -
             
     | 
| 
       176 
     | 
    
         
            -
             
     | 
| 
       177 
     | 
    
         
            -
             
     | 
| 
       178 
     | 
    
         
            -
             
     | 
| 
       179 
     | 
    
         
            -
             
     | 
| 
       180 
     | 
    
         
            -
             
     | 
| 
       181 
     | 
    
         
            -
             
     | 
| 
       182 
     | 
    
         
            -
             
     | 
| 
       183 
     | 
    
         
            -
                private_class_method :status_counts_in_run
         
     | 
| 
      
 157 
     | 
    
         
            +
                    # @return [Hash] status counts across all authorities (used for current test summary)
         
     | 
| 
      
 158 
     | 
    
         
            +
                    # @example { "good" => 23, "bad" => 3, "unknown" => 0 }
         
     | 
| 
      
 159 
     | 
    
         
            +
                    def status_counts_in_run(run_id:)
         
     | 
| 
      
 160 
     | 
    
         
            +
                      status = QaServer::ScenarioRunHistory.group('status').where(scenario_run_registry_id: run_id).count
         
     | 
| 
      
 161 
     | 
    
         
            +
                      status["good"] = 0 unless status.key? "good"
         
     | 
| 
      
 162 
     | 
    
         
            +
                      status["bad"] = 0 unless status.key? "bad"
         
     | 
| 
      
 163 
     | 
    
         
            +
                      status["unknown"] = 0 unless status.key? "unknown"
         
     | 
| 
      
 164 
     | 
    
         
            +
                      status
         
     | 
| 
      
 165 
     | 
    
         
            +
                    end
         
     | 
| 
       184 
166 
     | 
    
         | 
| 
       185 
     | 
    
         
            -
             
     | 
| 
       186 
     | 
    
         
            -
             
     | 
| 
       187 
     | 
    
         
            -
             
     | 
| 
       188 
     | 
    
         
            -
             
     | 
| 
       189 
     | 
    
         
            -
             
     | 
| 
       190 
     | 
    
         
            -
             
     | 
| 
      
 167 
     | 
    
         
            +
                    def runs_per_authority_for_time_period
         
     | 
| 
      
 168 
     | 
    
         
            +
                      status = QaServer::ScenarioRunHistory.joins(:scenario_run_registry).where(time_period_where).group('authority_name', 'status').count
         
     | 
| 
      
 169 
     | 
    
         
            +
                      status.each_with_object({}) do |(k, v), hash|
         
     | 
| 
      
 170 
     | 
    
         
            +
                        h = hash[k[0]] || { "good" => 0, "bad" => 0 } # initialize for an authority if it doesn't already exist
         
     | 
| 
      
 171 
     | 
    
         
            +
                        h[k[1]] = v
         
     | 
| 
      
 172 
     | 
    
         
            +
                        hash[k[0]] = h
         
     | 
| 
      
 173 
     | 
    
         
            +
                      end
         
     | 
| 
      
 174 
     | 
    
         
            +
                    end
         
     | 
| 
       191 
175 
     | 
    
         | 
| 
       192 
     | 
    
         
            -
             
     | 
| 
       193 
     | 
    
         
            -
             
     | 
| 
       194 
     | 
    
         
            -
             
     | 
| 
       195 
     | 
    
         
            -
                end
         
     | 
| 
       196 
     | 
    
         
            -
                private_class_method :failing_runs_per_authority
         
     | 
| 
      
 176 
     | 
    
         
            +
                    def expected_time_period
         
     | 
| 
      
 177 
     | 
    
         
            +
                      QaServer.config.historical_datatable_default_time_period
         
     | 
| 
      
 178 
     | 
    
         
            +
                    end
         
     | 
| 
       197 
179 
     | 
    
         | 
| 
       198 
     | 
    
         
            -
             
     | 
| 
       199 
     | 
    
         
            -
             
     | 
| 
       200 
     | 
    
         
            -
             
     | 
| 
       201 
     | 
    
         
            -
             
     | 
| 
       202 
     | 
    
         
            -
             
     | 
| 
       203 
     | 
    
         
            -
             
     | 
| 
       204 
     | 
    
         
            -
             
     | 
| 
       205 
     | 
    
         
            -
             
     | 
| 
      
 180 
     | 
    
         
            +
                    def time_period_where
         
     | 
| 
      
 181 
     | 
    
         
            +
                      case expected_time_period
         
     | 
| 
      
 182 
     | 
    
         
            +
                      when :day
         
     | 
| 
      
 183 
     | 
    
         
            +
                        QaServer::TimePeriodService.where_clause_for_last_24_hours(dt_table: :scenario_run_registry)
         
     | 
| 
      
 184 
     | 
    
         
            +
                      when :month
         
     | 
| 
      
 185 
     | 
    
         
            +
                        QaServer::TimePeriodService.where_clause_for_last_30_days(dt_table: :scenario_run_registry)
         
     | 
| 
      
 186 
     | 
    
         
            +
                      when :year
         
     | 
| 
      
 187 
     | 
    
         
            +
                        QaServer::TimePeriodService.where_clause_for_last_12_months(dt_table: :scenario_run_registry)
         
     | 
| 
      
 188 
     | 
    
         
            +
                      else
         
     | 
| 
      
 189 
     | 
    
         
            +
                        all_records
         
     | 
| 
      
 190 
     | 
    
         
            +
                      end
         
     | 
| 
      
 191 
     | 
    
         
            +
                    end
         
     | 
| 
       206 
192 
     | 
    
         
             
                end
         
     | 
| 
       207 
     | 
    
         
            -
                private_class_method :runs_per_authority
         
     | 
| 
       208 
193 
     | 
    
         
             
              end
         
     | 
| 
       209 
194 
     | 
    
         
             
            end
         
     | 
| 
         @@ -23,17 +23,17 @@ module QaServer 
     | 
|
| 
       23 
23 
     | 
    
         
             
                end
         
     | 
| 
       24 
24 
     | 
    
         
             
                deprecation_deprecate latest_run_id: "Not used anywhere. Being removed."
         
     | 
| 
       25 
25 
     | 
    
         | 
| 
       26 
     | 
    
         
            -
                # @return [ 
     | 
| 
      
 26 
     | 
    
         
            +
                # @return [ActiveSupport::TimeWithZone] datetime stamp of first registered run
         
     | 
| 
       27 
27 
     | 
    
         
             
                def self.first_run_dt
         
     | 
| 
       28 
     | 
    
         
            -
                  Rails.cache.fetch("#{self.class}/#{__method__}", expires_in: QaServer.cache_expiry, race_condition_ttl:  
     | 
| 
       29 
     | 
    
         
            -
                    QaServer::ScenarioRunRegistry.first.dt_stamp 
     | 
| 
      
 28 
     | 
    
         
            +
                  Rails.cache.fetch("#{self.class}/#{__method__}", expires_in: QaServer::MonitorCacheService.cache_expiry, race_condition_ttl: 30.seconds) do
         
     | 
| 
      
 29 
     | 
    
         
            +
                    QaServer::ScenarioRunRegistry.first.dt_stamp
         
     | 
| 
       30 
30 
     | 
    
         
             
                  end
         
     | 
| 
       31 
31 
     | 
    
         
             
                end
         
     | 
| 
       32 
32 
     | 
    
         | 
| 
       33 
33 
     | 
    
         
             
                # Register and save latest test run results
         
     | 
| 
       34 
34 
     | 
    
         
             
                # @param scenarios_results [Array<Hash>] results of latest test run
         
     | 
| 
       35 
35 
     | 
    
         
             
                def self.save_run(scenarios_results:)
         
     | 
| 
       36 
     | 
    
         
            -
                  run = QaServer::ScenarioRunRegistry.create(dt_stamp: QaServer.current_time)
         
     | 
| 
      
 36 
     | 
    
         
            +
                  run = QaServer::ScenarioRunRegistry.create(dt_stamp: QaServer::TimeService.current_time)
         
     | 
| 
       37 
37 
     | 
    
         
             
                  scenarios_results.each { |result| QaServer::ScenarioRunHistory.save_result(run_id: run.id, scenario_result: result) }
         
     | 
| 
       38 
38 
     | 
    
         
             
                end
         
     | 
| 
       39 
39 
     | 
    
         
             
              end
         
     | 
| 
         @@ -21,7 +21,7 @@ module PrependedLinkedData::FindTerm 
     | 
|
| 
       21 
21 
     | 
    
         | 
| 
       22 
22 
     | 
    
         
             
                def setup_find(request_header: {}, language: nil, replacements: {}, subauth: nil, format: nil, performance_data: false) # rubocop:disable Metrics/ParameterLists
         
     | 
| 
       23 
23 
     | 
    
         
             
                  QaServer.log_agent_info(request_header[:request])
         
     | 
| 
       24 
     | 
    
         
            -
                  @start_time_s = QaServer.current_time_s
         
     | 
| 
      
 24 
     | 
    
         
            +
                  @start_time_s = QaServer::TimeService.current_time_s
         
     | 
| 
       25 
25 
     | 
    
         
             
                  request_header = build_request_header(language: language, replacements: replacements, subauth: subauth, format: format, performance_data: performance_data) if request_header.empty?
         
     | 
| 
       26 
26 
     | 
    
         
             
                  @saved_performance_data = performance_data || request_header[:performance_data]
         
     | 
| 
       27 
27 
     | 
    
         
             
                  request_header[:performance_data] = true
         
     | 
| 
         @@ -30,7 +30,7 @@ module PrependedLinkedData::FindTerm 
     | 
|
| 
       30 
30 
     | 
    
         | 
| 
       31 
31 
     | 
    
         
             
                def update_performance_history_record(full_results)
         
     | 
| 
       32 
32 
     | 
    
         
             
                  return QaServer.config.performance_cache.destroy(@phid) unless full_results.is_a?(Hash) && full_results.key?(:performance)
         
     | 
| 
       33 
     | 
    
         
            -
                  updates = { action_time_ms: (QaServer.current_time_s - @start_time_s) * 1000,
         
     | 
| 
      
 33 
     | 
    
         
            +
                  updates = { action_time_ms: (QaServer::TimeService.current_time_s - @start_time_s) * 1000,
         
     | 
| 
       34 
34 
     | 
    
         
             
                              size_bytes: full_results[:performance][:fetched_bytes],
         
     | 
| 
       35 
35 
     | 
    
         
             
                              retrieve_plus_graph_load_time_ms: full_results[:performance][:fetch_time_s] * 1000,
         
     | 
| 
       36 
36 
     | 
    
         
             
                              normalization_time_ms: full_results[:performance][:normalization_time_s] * 1000 }
         
     | 
| 
         @@ -42,12 +42,12 @@ module PrependedLinkedData::FindTerm 
     | 
|
| 
       42 
42 
     | 
    
         
             
                def load_graph(url:)
         
     | 
| 
       43 
43 
     | 
    
         
             
                  return super if QaServer.config.suppress_performance_gathering
         
     | 
| 
       44 
44 
     | 
    
         | 
| 
       45 
     | 
    
         
            -
                  access_start_dt = QaServer.current_time
         
     | 
| 
      
 45 
     | 
    
         
            +
                  access_start_dt = QaServer::TimeService.current_time
         
     | 
| 
       46 
46 
     | 
    
         | 
| 
       47 
47 
     | 
    
         
             
                  url += "&phid=#{@phid}"
         
     | 
| 
       48 
48 
     | 
    
         
             
                  @full_graph = graph_service.load_graph(url: url)
         
     | 
| 
       49 
49 
     | 
    
         | 
| 
       50 
     | 
    
         
            -
                  access_end_dt = QaServer.current_time
         
     | 
| 
      
 50 
     | 
    
         
            +
                  access_end_dt = QaServer::TimeService.current_time
         
     | 
| 
       51 
51 
     | 
    
         
             
                  @access_time_s = access_end_dt - access_start_dt
         
     | 
| 
       52 
52 
     | 
    
         
             
                  @fetched_size = full_graph.triples.to_s.size if performance_data?
         
     | 
| 
       53 
53 
     | 
    
         
             
                  Rails.logger.info("Time to receive data from authority: #{access_time_s}s")
         
     | 
| 
         @@ -21,7 +21,7 @@ module PrependedLinkedData::SearchQuery 
     | 
|
| 
       21 
21 
     | 
    
         | 
| 
       22 
22 
     | 
    
         
             
                def setup_search(request_header: {}, language: nil, replacements: {}, subauth: nil, context: false, performance_data: false) # rubocop:disable Metrics/ParameterLists
         
     | 
| 
       23 
23 
     | 
    
         
             
                  QaServer.log_agent_info(request_header[:request])
         
     | 
| 
       24 
     | 
    
         
            -
                  @start_time_s = QaServer.current_time_s
         
     | 
| 
      
 24 
     | 
    
         
            +
                  @start_time_s = QaServer::TimeService.current_time_s
         
     | 
| 
       25 
25 
     | 
    
         
             
                  request_header = build_request_header(language: language, replacements: replacements, subauth: subauth, context: context, performance_data: performance_data) if request_header.empty?
         
     | 
| 
       26 
26 
     | 
    
         
             
                  @saved_performance_data = performance_data || request_header[:performance_data]
         
     | 
| 
       27 
27 
     | 
    
         
             
                  request_header[:performance_data] = true
         
     | 
| 
         @@ -30,7 +30,7 @@ module PrependedLinkedData::SearchQuery 
     | 
|
| 
       30 
30 
     | 
    
         | 
| 
       31 
31 
     | 
    
         
             
                def update_performance_history_record(full_results)
         
     | 
| 
       32 
32 
     | 
    
         
             
                  return QaServer.config.performance_cache.destroy(@phid) unless full_results.is_a?(Hash) && full_results.key?(:performance)
         
     | 
| 
       33 
     | 
    
         
            -
                  updates = { action_time_ms: (QaServer.current_time_s - @start_time_s) * 1000,
         
     | 
| 
      
 33 
     | 
    
         
            +
                  updates = { action_time_ms: (QaServer::TimeService.current_time_s - @start_time_s) * 1000,
         
     | 
| 
       34 
34 
     | 
    
         
             
                              size_bytes: full_results[:performance][:fetched_bytes],
         
     | 
| 
       35 
35 
     | 
    
         
             
                              retrieve_plus_graph_load_time_ms: full_results[:performance][:fetch_time_s] * 1000,
         
     | 
| 
       36 
36 
     | 
    
         
             
                              normalization_time_ms: full_results[:performance][:normalization_time_s] * 1000 }
         
     | 
| 
         @@ -42,12 +42,12 @@ module PrependedLinkedData::SearchQuery 
     | 
|
| 
       42 
42 
     | 
    
         
             
                def load_graph(url:)
         
     | 
| 
       43 
43 
     | 
    
         
             
                  return super if QaServer.config.suppress_performance_gathering
         
     | 
| 
       44 
44 
     | 
    
         | 
| 
       45 
     | 
    
         
            -
                  access_start_dt = QaServer.current_time
         
     | 
| 
      
 45 
     | 
    
         
            +
                  access_start_dt = QaServer::TimeService.current_time
         
     | 
| 
       46 
46 
     | 
    
         | 
| 
       47 
47 
     | 
    
         
             
                  url += "&phid=#{@phid}"
         
     | 
| 
       48 
48 
     | 
    
         
             
                  @full_graph = graph_service.load_graph(url: url)
         
     | 
| 
       49 
49 
     | 
    
         | 
| 
       50 
     | 
    
         
            -
                  access_end_dt = QaServer.current_time
         
     | 
| 
      
 50 
     | 
    
         
            +
                  access_end_dt = QaServer::TimeService.current_time
         
     | 
| 
       51 
51 
     | 
    
         
             
                  @access_time_s = access_end_dt - access_start_dt
         
     | 
| 
       52 
52 
     | 
    
         
             
                  @fetched_size = full_graph.triples.to_s.size if performance_data?
         
     | 
| 
       53 
53 
     | 
    
         
             
                  Rails.logger.info("Time to receive data from authority: #{access_time_s}s")
         
     |