From e6f3767eb475502b4965931cecbcf12a7233d280 Mon Sep 17 00:00:00 2001 From: Martin Fenner Date: Thu, 21 Nov 2019 07:17:02 +0100 Subject: [PATCH] remove benchmark logging. datacite/datacite#881 --- app/controllers/clients_controller.rb | 34 ++-------- app/controllers/dois_controller.rb | 91 +++++++------------------- app/controllers/events_controller.rb | 24 +++---- app/controllers/prefixes_controller.rb | 18 +---- 4 files changed, 39 insertions(+), 128 deletions(-) diff --git a/app/controllers/clients_controller.rb b/app/controllers/clients_controller.rb index 35e37d98f..246e7f929 100644 --- a/app/controllers/clients_controller.rb +++ b/app/controllers/clients_controller.rb @@ -1,5 +1,3 @@ -require 'benchmark' - class ClientsController < ApplicationController include Countable @@ -160,36 +158,12 @@ def totals logger = Logger.new(STDOUT) page = { size: 0, number: 1} - response = nil - bmt = Benchmark.ms { - state = current_user.present? && current_user.is_admin_or_staff? && params[:state].present? ? params[:state] : "registered,findable" - response = Doi.query(nil, provider_id: params[:provider_id], state: state, page: page, totals_agg: true) - } - if bmt > 10000 - logger.warn "[Benchmark Warning] clients totals " + bmt.to_s + " ms" - else - logger.info "[Benchmark] clients totals " + bmt.to_s + " ms" - end + state = current_user.present? && current_user.is_admin_or_staff? && params[:state].present? ? params[:state] : "registered,findable" + response = Doi.query(nil, provider_id: params[:provider_id], state: state, page: page, totals_agg: true) total = response.results.total - registrant = nil - bmc = Benchmark.ms { - registrant = total > 0 ? clients_totals(response.response.aggregations.clients_totals.buckets) : nil - } - if bmc > 10000 - logger.warn "[Benchmark Warning] clients clients_totals " + bmc.to_s + " ms" - else - logger.info "[Benchmark] clients clients_totals " + bmc.to_s + " ms" - end - - bmr = Benchmark.ms { - render json: registrant, status: :ok - } - if bmr > 10000 - logger.warn "[Benchmark Warning] clients render " + bmr.to_s + " ms" - else - logger.info "[Benchmark] clients render " + bmr.to_s + " ms" - end + registrant = total > 0 ? clients_totals(response.response.aggregations.clients_totals.buckets) : nil + render json: registrant, status: :ok end protected diff --git a/app/controllers/dois_controller.rb b/app/controllers/dois_controller.rb index ad1925445..91da1cd2d 100644 --- a/app/controllers/dois_controller.rb +++ b/app/controllers/dois_controller.rb @@ -1,6 +1,5 @@ require 'uri' require 'base64' -require 'benchmark' class DoisController < ApplicationController include ActionController::MimeResponds @@ -45,9 +44,7 @@ def index params[:state] = "findable" if current_user.nil? || current_user.role_id == "user" if params[:id].present? - logger.info "[Benchmark] find_by_id " + Benchmark.ms { - response = Doi.find_by_id(params[:id]) - }.to_s + " ms" + response = Doi.find_by_id(params[:id]) elsif params[:ids].present? response = Doi.find_by_id(params[:ids], page: page, sort: sort) else @@ -84,12 +81,6 @@ def index end begin - if response.took > 1000 - logger.warn "[Benchmark Warning] Elasticsearch request " + response.took.to_s + " ms" - else - logger.info "[Benchmark] Elasticsearch request " + response.took.to_s + " ms" - end - # If we're using sample groups we need to unpack the results from the aggregation bucket hits. if sample_group_field.present? sample_dois = [] @@ -113,50 +104,24 @@ def index total_pages = page[:size] > 0 ? (total_for_pages / page[:size]).ceil : 0 end - # we need to define those variables before the block - states = nil - resource_types = nil - created = nil - registered = nil - providers = nil - clients = nil - affiliations = nil - prefixes = nil - schema_versions = nil - sources = nil - link_checks_status = nil - links_with_schema_org = nil - link_checks_schema_org_id = nil - link_checks_dc_identifier = nil - link_checks_citation_doi = nil - links_checked = nil - subjects = nil - certificates = nil - bma = Benchmark.ms { - states = total > 0 ? facet_by_key(response.response.aggregations.states.buckets) : nil - resource_types = total > 0 ? facet_by_resource_type(response.response.aggregations.resource_types.buckets) : nil - created = total > 0 ? facet_by_year(response.response.aggregations.created.buckets) : nil - registered = total > 0 ? facet_by_year(response.response.aggregations.registered.buckets) : nil - providers = total > 0 ? facet_by_provider(response.response.aggregations.providers.buckets) : nil - clients = total > 0 ? facet_by_client(response.response.aggregations.clients.buckets) : nil - affiliations = total > 0 ? facet_by_affiliation(response.response.aggregations.affiliations.buckets) : nil - prefixes = total > 0 ? facet_by_key(response.response.aggregations.prefixes.buckets) : nil - schema_versions = total > 0 ? facet_by_schema(response.response.aggregations.schema_versions.buckets) : nil - sources = total > 0 ? facet_by_key(response.response.aggregations.sources.buckets) : nil - link_checks_status = total > 0 ? facet_by_cumulative_year(response.response.aggregations.link_checks_status.buckets) : nil - links_with_schema_org = total > 0 ? facet_by_cumulative_year(response.response.aggregations.link_checks_has_schema_org.buckets) : nil - link_checks_schema_org_id = total > 0 ? response.response.aggregations.link_checks_schema_org_id.value : nil - link_checks_dc_identifier = total > 0 ? response.response.aggregations.link_checks_dc_identifier.value : nil - link_checks_citation_doi = total > 0 ? response.response.aggregations.link_checks_citation_doi.value : nil - links_checked = total > 0 ? response.response.aggregations.links_checked.value : nil - subjects = total > 0 ? facet_by_key(response.response.aggregations.subjects.buckets) : nil - certificates = total > 0 ? facet_by_key(response.response.aggregations.certificates.buckets) : nil - } - if bma > 1000 - logger.warn "[Benchmark Warning] aggregations " + bma.to_s + " ms" - else - logger.info "[Benchmark] aggregations " + bma.to_s + " ms" - end + states = total > 0 ? facet_by_key(response.response.aggregations.states.buckets) : nil + resource_types = total > 0 ? facet_by_resource_type(response.response.aggregations.resource_types.buckets) : nil + created = total > 0 ? facet_by_year(response.response.aggregations.created.buckets) : nil + registered = total > 0 ? facet_by_year(response.response.aggregations.registered.buckets) : nil + providers = total > 0 ? facet_by_provider(response.response.aggregations.providers.buckets) : nil + clients = total > 0 ? facet_by_client(response.response.aggregations.clients.buckets) : nil + affiliations = total > 0 ? facet_by_affiliation(response.response.aggregations.affiliations.buckets) : nil + prefixes = total > 0 ? facet_by_key(response.response.aggregations.prefixes.buckets) : nil + schema_versions = total > 0 ? facet_by_schema(response.response.aggregations.schema_versions.buckets) : nil + sources = total > 0 ? facet_by_key(response.response.aggregations.sources.buckets) : nil + link_checks_status = total > 0 ? facet_by_cumulative_year(response.response.aggregations.link_checks_status.buckets) : nil + links_with_schema_org = total > 0 ? facet_by_cumulative_year(response.response.aggregations.link_checks_has_schema_org.buckets) : nil + link_checks_schema_org_id = total > 0 ? response.response.aggregations.link_checks_schema_org_id.value : nil + link_checks_dc_identifier = total > 0 ? response.response.aggregations.link_checks_dc_identifier.value : nil + link_checks_citation_doi = total > 0 ? response.response.aggregations.link_checks_citation_doi.value : nil + links_checked = total > 0 ? response.response.aggregations.links_checked.value : nil + subjects = total > 0 ? facet_by_key(response.response.aggregations.subjects.buckets) : nil + certificates = total > 0 ? facet_by_key(response.response.aggregations.certificates.buckets) : nil respond_to do |format| format.json do @@ -207,20 +172,12 @@ def index is_collection: options[:is_collection] } - bmr = Benchmark.ms { - # sparse fieldsets - fields = fields_from_params(params) - if fields - render json: DoiSerializer.new(results, options.merge(fields: fields)).serialized_json, status: :ok - else - render json: DoiSerializer.new(results, options).serialized_json, status: :ok - end - } - - if bmr > 3000 - logger.warn "[Benchmark Warning] render " + bmr.to_s + " ms" + # sparse fieldsets + fields = fields_from_params(params) + if fields + render json: DoiSerializer.new(results, options.merge(fields: fields)).serialized_json, status: :ok else - logger.info "[Benchmark] render " + bmr.to_s + " ms" + render json: DoiSerializer.new(results, options).serialized_json, status: :ok end end diff --git a/app/controllers/events_controller.rb b/app/controllers/events_controller.rb index ce40b5e7a..0b9dc1f40 100644 --- a/app/controllers/events_controller.rb +++ b/app/controllers/events_controller.rb @@ -1,5 +1,3 @@ -require 'benchmark' - class EventsController < ApplicationController include Identifiable @@ -191,21 +189,15 @@ def index options[:is_collection] = true - bmr = Benchmark.ms { - events_serialized = EventSerializer.new(results, options).serializable_hash - if @include.include?(:dois) - options[:include] =[] - doi_names = (results.map { |event| event.doi}).uniq().join(",") - events_serialized[:included] = DoiSerializer.new((Doi.find_by_id(doi_names).results), {is_collection: true}).serializable_hash.dig(:data) - end - render json: events_serialized, status: :ok - } - - if bmr > 3000 - logger.warn "[Benchmark Warning] Events render.} " + bmr.to_s + " ms" - else - logger.info "[Benchmark] Events render.} " + bmr.to_s + " ms" + events_serialized = EventSerializer.new(results, options).serializable_hash + + if @include.include?(:dois) + options[:include] = [] + doi_names = (results.map { |event| event.doi}).uniq().join(",") + events_serialized[:included] = DoiSerializer.new((Doi.find_by_id(doi_names).results), {is_collection: true}).serializable_hash.dig(:data) end + + render json: events_serialized, status: :ok end def destroy diff --git a/app/controllers/prefixes_controller.rb b/app/controllers/prefixes_controller.rb index aa6a96e2e..9b1e2eaaf 100644 --- a/app/controllers/prefixes_controller.rb +++ b/app/controllers/prefixes_controller.rb @@ -1,5 +1,3 @@ -require 'benchmark' - class PrefixesController < ApplicationController before_action :set_prefix, only: [:show, :update, :destroy] before_action :authenticate_user! @@ -138,22 +136,12 @@ def update end def totals - logger = Logger.new(STDOUT) - page = { size: 0, number: 1} - response = nil - logger.info "[Benchmark] prefixes totals " + Benchmark.ms { - response = Doi.query(nil, client_id: params[:client_id], state: "findable,registered", page: page, totals_agg: true) - }.to_s + " ms" + response = Doi.query(nil, client_id: params[:client_id], state: "findable,registered", page: page, totals_agg: true) total = response.results.total - registrant = nil - logger.info "[Benchmark] prefixes prefixes_totals " + Benchmark.ms { - registrant = total > 0 ? prefixes_totals(response.response.aggregations.prefixes_totals.buckets) : nil - }.to_s + " ms" - logger.info "[Benchmark] clients render " + Benchmark.ms { - render json: registrant, status: :ok - }.to_s + " ms" + registrant = total > 0 ? prefixes_totals(response.response.aggregations.prefixes_totals.buckets) : nil + render json: registrant, status: :ok end def destroy