Class: ScoutApm::SlowJobPolicy

Inherits:
Object
  • Object
show all
Defined in:
lib/scout_apm/slow_job_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

Instance Method Summary collapse

Constructor Details

#initializeSlowJobPolicy

Returns a new instance of SlowJobPolicy.



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

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

Instance Attribute Details

#last_seenObject (readonly)

A hash of Job Names to the last time we stored a slow trace 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_job_policy.rb', line 25

def last_seen
  @last_seen
end

Instance Method Details

#score(request) ⇒ Object

Determine if this job 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.



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/scout_apm/slow_job_policy.rb', line 45

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 = ScoutApm::Agent.instance.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



33
34
35
# File 'lib/scout_apm/slow_job_policy.rb', line 33

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