class ScoutApm::SlowRequestPolicy
Attributes
The AgentContext
we’re running in
Public Class Methods
Source
# File lib/scout_apm/slow_request_policy.rb, line 10 def initialize(context) @context = context @policies = [] end
Public Instance Methods
Source
# File lib/scout_apm/slow_request_policy.rb, line 23 def add(policy) unless policy.respond_to?(:call) && policy.respond_to?(:stored!) raise "SlowRequestPolicy must implement policy api call(req) and stored!(req)" end @policies << policy end
policy is an object that behaves like a policy (responds to .call(req) for the score, and .store!(req))
Source
# File lib/scout_apm/slow_request_policy.rb, line 15 def add_default_policies add(SlowPolicy::SpeedPolicy.new(context)) add(SlowPolicy::PercentPolicy.new(context)) add(SlowPolicy::AgePolicy.new(context)) add(SlowPolicy::PercentilePolicy.new(context)) end
Source
# File lib/scout_apm/slow_request_policy.rb, line 39 def score(request) unique_name = request.unique_name if unique_name == :unknown return -1 # A negative score, should never be good enough to store. end policies.map{ |p| p.call(request) }.sum end
Determine if this request trace should be fully analyzed by scoring it across several metrics, and then determining if that’s good enough to make it into this minute’s payload.
Due to the combining nature of the agent & layaway file, there’s no guarantee that a high scoring local champion will still be a winner when they go up to “regionals” and are compared against the other processes running on a node.
Source
# File lib/scout_apm/slow_request_policy.rb, line 48 def stored!(request) policies.each{ |p| p.stored!(request) } end