Class: ScoutApm::SlowRequestPolicy
- Inherits:
-
Object
- Object
- ScoutApm::SlowRequestPolicy
- 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
Instance Attribute Summary collapse
-
#context ⇒ Object
readonly
The AgentContext we’re running in.
-
#last_seen ⇒ Object
readonly
A hash of Endpoint Name to the last time we stored a slow transaction for it.
Instance Method Summary collapse
-
#initialize(context) ⇒ SlowRequestPolicy
constructor
A new instance of SlowRequestPolicy.
-
#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.
- #stored!(request) ⇒ Object
Constructor Details
#initialize(context) ⇒ SlowRequestPolicy
Returns a new instance of SlowRequestPolicy.
30 31 32 33 34 35 |
# File 'lib/scout_apm/slow_request_policy.rb', line 30 def initialize(context) @context = context zero_time = Time.now @last_seen = Hash.new { |h, k| h[k] = zero_time } end |
Instance Attribute Details
#context ⇒ Object (readonly)
The AgentContext we’re running in
28 29 30 |
# File 'lib/scout_apm/slow_request_policy.rb', line 28 def context @context end |
#last_seen ⇒ Object (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.
25 26 27 |
# File 'lib/scout_apm/slow_request_policy.rb', line 25 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.
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/scout_apm/slow_request_policy.rb', line 49 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) return speed_points(total_time) + percentile_points(percentile) + age_points(age) end |
#stored!(request) ⇒ Object
37 38 39 |
# File 'lib/scout_apm/slow_request_policy.rb', line 37 def stored!(request) last_seen[request.unique_name] = Time.now end |