Commit 23d1a1f9 by Joel Barciauskas Committed by GitHub

Merge pull request #242 from edx/jbarciauskas/remove-newrelic-dep

Wrap newrelic calls in a rescue block
parents 1acbf22f 346c65ee
...@@ -20,7 +20,6 @@ def get_thread_ids(context, group_ids, local_params, search_text) ...@@ -20,7 +20,6 @@ def get_thread_ids(context, group_ids, local_params, search_text)
) )
end end
self.class.trace_execution_scoped(['Custom/get_search_threads/es_search']) do
body = { body = {
size: CommentService.config['max_deep_search_comment_count'].to_i, size: CommentService.config['max_deep_search_comment_count'].to_i,
sort: [ sort: [
...@@ -55,7 +54,6 @@ def get_thread_ids(context, group_ids, local_params, search_text) ...@@ -55,7 +54,6 @@ def get_thread_ids(context, group_ids, local_params, search_text)
end end
end end
thread_ids thread_ids
end
end end
def get_suggested_text(search_text) def get_suggested_text(search_text)
......
...@@ -54,13 +54,11 @@ get "#{APIPREFIX}/users/:user_id/active_threads" do |user_id| ...@@ -54,13 +54,11 @@ get "#{APIPREFIX}/users/:user_id/active_threads" do |user_id|
collection = presenter.to_hash collection = presenter.to_hash
json_output = nil json_output = nil
self.class.trace_execution_scoped(['Custom/get_user_active_threads/json_serialize']) do
json_output = { json_output = {
collection: collection, collection: collection,
num_pages: num_pages, num_pages: num_pages,
page: page, page: page,
}.to_json }.to_json
end
json_output json_output
end end
......
require 'new_relic/agent/method_tracer'
helpers do helpers do
def commentable def commentable
...@@ -151,7 +150,6 @@ helpers do ...@@ -151,7 +150,6 @@ helpers do
end end
if filter_flagged if filter_flagged
self.class.trace_execution_scoped(['Custom/handle_threads_query/find_flagged']) do
# TODO replace with aggregate query? # TODO replace with aggregate query?
comment_ids = Comment.where(:course_id => course_id). comment_ids = Comment.where(:course_id => course_id).
where(:abuse_flaggers.ne => [], :abuse_flaggers.exists => true). where(:abuse_flaggers.ne => [], :abuse_flaggers.exists => true).
...@@ -162,17 +160,14 @@ helpers do ...@@ -162,17 +160,14 @@ helpers do
comment_threads = comment_threads.in({"_id" => (comment_ids + thread_ids).uniq}) comment_threads = comment_threads.in({"_id" => (comment_ids + thread_ids).uniq})
end end
end
if filter_unanswered if filter_unanswered
self.class.trace_execution_scoped(['Custom/handle_threads_query/find_unanswered']) do
endorsed_thread_ids = Comment.where(:course_id => course_id). endorsed_thread_ids = Comment.where(:course_id => course_id).
where(:parent_id.exists => false, :endorsed => true). where(:parent_id.exists => false, :endorsed => true).
collect{|c| c.comment_thread_id}.uniq collect{|c| c.comment_thread_id}.uniq
comment_threads = comment_threads.where({"thread_type" => :question}).nin({"_id" => endorsed_thread_ids}) comment_threads = comment_threads.where({"thread_type" => :question}).nin({"_id" => endorsed_thread_ids})
end end
end
sort_criteria = get_sort_criteria(sort_key) sort_criteria = get_sort_criteria(sort_key)
if not sort_criteria if not sort_criteria
...@@ -375,6 +370,8 @@ helpers do ...@@ -375,6 +370,8 @@ helpers do
end end
end end
begin
require 'new_relic/agent/method_tracer'
include ::NewRelic::Agent::MethodTracer include ::NewRelic::Agent::MethodTracer
add_method_tracer :user add_method_tracer :user
add_method_tracer :thread add_method_tracer :thread
...@@ -382,4 +379,7 @@ helpers do ...@@ -382,4 +379,7 @@ helpers do
add_method_tracer :flag_as_abuse add_method_tracer :flag_as_abuse
add_method_tracer :un_flag_as_abuse add_method_tracer :un_flag_as_abuse
add_method_tracer :handle_threads_query add_method_tracer :handle_threads_query
rescue LoadError
logger.warn "NewRelic agent library not installed"
end
end end
require 'new_relic/agent/method_tracer'
require_relative 'concerns/searchable' require_relative 'concerns/searchable'
require_relative 'content' require_relative 'content'
require_relative 'constants' require_relative 'constants'
...@@ -166,6 +165,11 @@ class Comment < Content ...@@ -166,6 +165,11 @@ class Comment < Content
end end
end end
begin
require 'new_relic/agent/method_tracer'
include ::NewRelic::Agent::MethodTracer include ::NewRelic::Agent::MethodTracer
add_method_tracer :to_hash add_method_tracer :to_hash
rescue LoadError
logger.warn "NewRelic agent library not installed"
end
end end
require 'new_relic/agent/method_tracer'
require_relative 'concerns/searchable' require_relative 'concerns/searchable'
require_relative 'content' require_relative 'content'
require_relative 'constants' require_relative 'constants'
...@@ -158,6 +157,11 @@ class CommentThread < Content ...@@ -158,6 +157,11 @@ class CommentThread < Content
subscriptions.delete_all subscriptions.delete_all
end end
begin
require 'new_relic/agent/method_tracer'
include ::NewRelic::Agent::MethodTracer include ::NewRelic::Agent::MethodTracer
add_method_tracer :to_hash add_method_tracer :to_hash
rescue LoadError
logger.warn "NewRelic agent library not installed"
end
end end
require 'new_relic/agent/method_tracer'
require_relative 'constants' require_relative 'constants'
class User class User
...@@ -51,7 +50,6 @@ class User ...@@ -51,7 +50,6 @@ class User
end end
if params[:course_id] if params[:course_id]
self.class.trace_execution_scoped(['Custom/User.to_hash/count_comments_and_threads']) do
if not params[:group_ids].empty? if not params[:group_ids].empty?
# Get threads in either the specified group(s) or posted to all groups (nil). # Get threads in either the specified group(s) or posted to all groups (nil).
specified_groups_or_global = params[:group_ids] << nil specified_groups_or_global = params[:group_ids] << nil
...@@ -106,7 +104,6 @@ class User ...@@ -106,7 +104,6 @@ class User
end end
hash = hash.merge!("threads_count" => threads_count, "comments_count" => comments_count) hash = hash.merge!("threads_count" => threads_count, "comments_count" => comments_count)
end end
end
hash hash
end end
...@@ -142,6 +139,8 @@ class User ...@@ -142,6 +139,8 @@ class User
read_state.save read_state.save
end end
begin
require 'new_relic/agent/method_tracer'
include ::NewRelic::Agent::MethodTracer include ::NewRelic::Agent::MethodTracer
add_method_tracer :to_hash add_method_tracer :to_hash
add_method_tracer :subscribed_thread_ids add_method_tracer :subscribed_thread_ids
...@@ -149,6 +148,9 @@ class User ...@@ -149,6 +148,9 @@ class User
add_method_tracer :downvoted_ids add_method_tracer :downvoted_ids
add_method_tracer :subscribe add_method_tracer :subscribe
add_method_tracer :mark_as_read add_method_tracer :mark_as_read
rescue LoadError
logger.warn "NewRelic agent library not installed"
end
end end
......
require_relative 'thread_utils' require_relative 'thread_utils'
require 'new_relic/agent/method_tracer'
class ThreadPresenter class ThreadPresenter
...@@ -120,8 +119,13 @@ class ThreadPresenter ...@@ -120,8 +119,13 @@ class ThreadPresenter
top_level top_level
end end
begin
require 'new_relic/agent/method_tracer'
include ::NewRelic::Agent::MethodTracer include ::NewRelic::Agent::MethodTracer
add_method_tracer :to_hash add_method_tracer :to_hash
add_method_tracer :merge_response_content add_method_tracer :merge_response_content
rescue LoadError
logger.warn "NewRelic agent library not installed"
end
end end
require 'new_relic/agent/method_tracer'
module ThreadUtils module ThreadUtils
def self.get_endorsed(threads) def self.get_endorsed(threads)
...@@ -42,9 +40,14 @@ module ThreadUtils ...@@ -42,9 +40,14 @@ module ThreadUtils
end end
class << self class << self
begin
require 'new_relic/agent/method_tracer'
include ::NewRelic::Agent::MethodTracer include ::NewRelic::Agent::MethodTracer
add_method_tracer :get_read_states add_method_tracer :get_read_states
add_method_tracer :get_endorsed add_method_tracer :get_endorsed
rescue LoadError
logger.warn "NewRelic agent library not installed"
end
end end
end end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment