Class: ScoutApm::SlowRequestPolicy

Inherits:
Object
  • Object
show all
Defined in:
lib/scout_apm/slow_request_policy.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(context) ⇒ SlowRequestPolicy

Returns a new instance of SlowRequestPolicy.



10
11
12
13
# File 'lib/scout_apm/slow_request_policy.rb', line 10

def initialize(context)
  @context = context
  @policies = []
end

Instance Attribute Details

#contextObject (readonly)

The AgentContext we’re running in



7
8
9
# File 'lib/scout_apm/slow_request_policy.rb', line 7

def context
  @context
end

#policiesObject (readonly)

Returns the value of attribute policies.



8
9
10
# File 'lib/scout_apm/slow_request_policy.rb', line 8

def policies
  @policies
end

Instance Method Details

#add(policy) ⇒ Object

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



23
24
25
26
27
28
29
# 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_policiesObject



15
16
17
18
19
20
# 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) ⇒ Object

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.



39
40
41
42
43
44
45
46
# 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) ⇒ Object



48
49
50
# File 'lib/scout_apm/slow_request_policy.rb', line 48

def stored!(request)
  policies.each{ |p| p.stored!(request) }
end