Class: ScoutApm::SlowRequestPolicy

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

Constant Summary collapse

CAPTURE_TYPES =
[
  CAPTURE_DETAIL  = "capture_detail",
  CAPTURE_NONE    = "capture_none",
]
POINT_MULTIPLIER_SPEED =

Adjust speed points. See the function

0.25
POINT_MULTIPLIER_AGE =

For each minute we haven’t seen an endpoint

0.25
POINT_MULTIPLIER_PERCENTILE =

Outliers are worth up to “1000ms” of weight

1.0
POINT_MULTIPLIER_PERCENT_TIME =

Points for an endpoint’s who’s throughput * response time is a large % of overall time spent processing requests

2.5

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(context) ⇒ SlowRequestPolicy

Returns a new instance of SlowRequestPolicy.



34
35
36
37
38
39
# File 'lib/scout_apm/slow_request_policy.rb', line 34

def initialize(context)
  @context = context

  zero_time = Time.now
  @last_seen = Hash.new { |h, k| h[k] = zero_time }
end

Instance Attribute Details

#contextObject (readonly)

The AgentContext we’re running in



32
33
34
# File 'lib/scout_apm/slow_request_policy.rb', line 32

def context
  @context
end

#last_seenObject (readonly)

A hash of Endpoint Name to the last time we stored a slow transaction for it.

Defaults to a start time that is pretty close to application boot time. So the “age” of an endpoint we’ve never seen is the time the application has been running.



29
30
31
# File 'lib/scout_apm/slow_request_policy.rb', line 29

def last_seen
  @last_seen
end

Instance Method Details

#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.



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/scout_apm/slow_request_policy.rb', line 53

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

  total_time = request.root_layer.total_call_time

  # How long has it been since we've seen this?
  age = Time.now - last_seen[unique_name]

  # What approximate percentile was this request?
  percentile = context.request_histograms.approximate_quantile_of_value(unique_name, total_time)

  percent_of_total_time = context.transaction_time_consumed.percent_of_total(unique_name)

  return speed_points(total_time) + percentile_points(percentile) + age_points(age) + percent_time_points(percent_of_total_time)
end

#stored!(request) ⇒ Object



41
42
43
# File 'lib/scout_apm/slow_request_policy.rb', line 41

def stored!(request)
  last_seen[request.unique_name] = Time.now
end