class ScoutApm::SlowRequestPolicy

Attributes

context[R]

The AgentContext we're running in

policies[R]

Public Class Methods

new(context) click to toggle source
# File lib/scout_apm/slow_request_policy.rb, line 10
def initialize(context)
  @context = context
  @policies = []
end

Public Instance Methods

add(policy) click to toggle source

policy is an object that behaves like a policy (responds to .call(req) for the score, and .store!(req))

# 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
add_default_policies() click to toggle source
# File lib/scout_apm/slow_request_policy.rb, line 15
def add_default_policies
  add(SlowPolicy::SpeedPolicy.new(context))
  add(SlowPolicy::PercentilePolicy.new(context))
  add(SlowPolicy::AgePolicy.new(context))
  add(SlowPolicy::PercentilePolicy.new(context))
end
score(request) click to toggle source

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.

# 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
stored!(request) click to toggle source
# File lib/scout_apm/slow_request_policy.rb, line 48
def stored!(request)
  policies.each{ |p| p.stored!(request) }
end