remnant 0.4.6 → 0.4.7

Sign up to get free protection for your applications and to get access to all the features.
data/lib/remnant/base.rb CHANGED
@@ -28,6 +28,9 @@ class Remnant
28
28
 
29
29
  extra_remnant_key = Remnant::Discover.results.delete(:extra_remnant_key)
30
30
 
31
+ # process special queue times
32
+ ::Remnant::Queue.process!
33
+
31
34
  if ::Rails.env.development? || ::Rails.env.test?
32
35
  # always log in development mode
33
36
  Rails.logger.info "#{color(false, true)}--------------Remnants Discovered--------------#{color(true)}"
@@ -0,0 +1,81 @@
1
+ #
2
+ # majority of this code comes from NewRelic RPM
3
+ #
4
+ class Remnant
5
+ class Queue
6
+ FRONTEND_START_HEADER = 'HTTP_X_FRONTEND_START'.freeze
7
+ LOAD_BALANCED_START_HEADER = 'HTTP_X_LOAD_BALANCER_START'.freeze
8
+
9
+ START_HEADERS = {
10
+ 'lb' => [
11
+ LOAD_BALANCED_START_HEADER
12
+ ],
13
+ 'fe' => [
14
+ FRONTEND_START_HEADER
15
+ ]
16
+ }.freeze
17
+
18
+ # any timestamps before this are thrown out and the parser
19
+ # will try again with a larger unit (2000/1/1 UTC)
20
+ EARLIEST_ACCEPTABLE_TIME = 946684800
21
+
22
+
23
+ class << self
24
+ def process!
25
+ lb_queue_start = ::Remnant::Discover.results.delete('lb_queue_start')
26
+ fe_queue_start = ::Remnant::Discover.results.delete('fe_queue_start')
27
+ app_queue_start = ::Remnant::Discover.results.delete('app_queue_start')
28
+
29
+ if lb_queue_start && fe_queue_start
30
+ ::Remnant::Discover.results['queue_lb'] = (fe_queue_start - lb_queue_start) # ms
31
+ end
32
+
33
+ if fe_queue_start && app_queue_start
34
+ ::Remnant::Discover.results['queue_fe'] = (app_queue_start - fe_queue_start) # ms
35
+ end
36
+ end
37
+
38
+ def parse_frontend_timestamp(headers, role, unit = :second, now = Time.now.to_f)
39
+ now = now.to_f if now.is_a?(Time)
40
+ earliest = nil
41
+
42
+ (START_HEADERS[role] || []).map do |header|
43
+ if headers[header]
44
+ parsed = parse_timestamp(timestamp_string_from_header_value(headers[header]), unit)
45
+
46
+ if parsed && (!earliest || parsed < earliest)
47
+ earliest = parsed
48
+ end
49
+ end
50
+ end
51
+
52
+ if earliest && earliest > now
53
+ earliest = now
54
+ end
55
+
56
+ earliest
57
+ end
58
+
59
+ def timestamp_string_from_header_value(value)
60
+ case value
61
+ when /^\s*([\d+\.]+)\s*$/ then $1
62
+ # following regexp intentionally unanchored to handle
63
+ # (ie ignore) leading server names
64
+ when /t=([\d+\.]+)/ then $1
65
+ end
66
+ end
67
+
68
+ # bring everything into a millisecond precision
69
+ def parse_timestamp(string, unit = :second)
70
+ case unit
71
+ when :second
72
+ string.to_f * 1_000.0
73
+ when :millisecond
74
+ string.to_f
75
+ when :microsecond
76
+ string.to_f / 1_000
77
+ end
78
+ end
79
+ end
80
+ end
81
+ end
data/lib/remnant/rails.rb CHANGED
@@ -116,6 +116,10 @@ class Remnant
116
116
  # hook into perform_action for the extra remnant key
117
117
  ::ActionController::Base.class_eval do
118
118
  def perform_action_with_remnant_key(*args, &block) #:nodoc:
119
+ ::Remnant::Discover.results['lb_queue_start'] = ::Remnant::Queue.parse_frontend_timestamp(request.headers, 'lb')
120
+ ::Remnant::Discover.results['fe_queue_start'] = ::Remnant::Queue.parse_frontend_timestamp(request.headers, 'fe')
121
+ ::Remnant::Discover.results['app_queue_start'] = request.env['process.request_start'] || Time.now.to_f
122
+
119
123
  perform_action_without_remnant_key(*args, &block)
120
124
  end
121
125
  alias_method_chain :perform_action, :remnant_key
@@ -1,3 +1,3 @@
1
1
  class Remnant
2
- VERSION = "0.4.6"
2
+ VERSION = "0.4.7"
3
3
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: remnant
3
3
  version: !ruby/object:Gem::Version
4
- hash: 3
4
+ hash: 1
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 4
9
- - 6
10
- version: 0.4.6
9
+ - 7
10
+ version: 0.4.7
11
11
  platform: ruby
12
12
  authors:
13
13
  - John 'asceth' Long
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2015-03-10 00:00:00 -04:00
18
+ date: 2015-03-23 00:00:00 -04:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -153,6 +153,7 @@ files:
153
153
  - lib/remnant/gc/base.rb
154
154
  - lib/remnant/gc/mri.rb
155
155
  - lib/remnant/gc/ree.rb
156
+ - lib/remnant/queue.rb
156
157
  - lib/remnant/rails.rb
157
158
  - lib/remnant/railtie.rb
158
159
  - lib/remnant/template.rb