traxor 0.1.9 → 0.1.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/traxor/rack/middleware/pre.rb +24 -3
- data/lib/traxor/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: de2e0c72345192d52a355f1d1092b59cd2652cf3d2e3611238a525362f700ae2
|
4
|
+
data.tar.gz: 733a91fe1e2813188b79fc6bab6853a8cc1397d35c1a4d0ef9acbc64930a7fc2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8c1818372a18ed552085161498b68e0477bb96e0f959eea5a8a89a56c7e293d6962f5c909964c4d337973f35e62046b173d138f09905fd9ed9385a7cafab6226
|
7
|
+
data.tar.gz: 6f247f75df7d0eee65ef8681df0415abf8ec3b7006247c7b1faf23375e6b7659def46662e6a8f1faf57c08e6b0e2fa492845341b5662d026d7e610ae7e44f586
|
data/Gemfile.lock
CHANGED
@@ -2,6 +2,12 @@ module Traxor
|
|
2
2
|
module Rack
|
3
3
|
module Middleware
|
4
4
|
class Pre
|
5
|
+
# any timestamps before this are thrown out and the parser
|
6
|
+
# will try again with a larger unit (2000/1/1 UTC)
|
7
|
+
EARLIEST_ACCEPTABLE_TIME = Time.at(946684800)
|
8
|
+
|
9
|
+
DIVISORS = [1_000_000, 1_000, 1]
|
10
|
+
|
5
11
|
def initialize(app)
|
6
12
|
@app = app
|
7
13
|
end
|
@@ -9,9 +15,9 @@ module Traxor
|
|
9
15
|
def call(env)
|
10
16
|
env['traxor.rack.middleware.pre_middleware_start'] = Time.now.to_f
|
11
17
|
queue_duration = nil
|
12
|
-
|
13
|
-
if
|
14
|
-
queue_duration = (env['traxor.rack.middleware.pre_middleware_start'].to_f
|
18
|
+
request_start = env['HTTP_X_REQUEST_START']
|
19
|
+
if request_start
|
20
|
+
queue_duration = (env['traxor.rack.middleware.pre_middleware_start'].to_f - parse_request_queue(request_start).to_f) * 1_000
|
15
21
|
end
|
16
22
|
status, headers, body = @app.call(env)
|
17
23
|
env['traxor.rack.middleware.post_middleware_end'] = Time.now.to_f
|
@@ -52,6 +58,21 @@ module Traxor
|
|
52
58
|
|
53
59
|
[status, headers, body]
|
54
60
|
end
|
61
|
+
|
62
|
+
def parse_request_queue(string)
|
63
|
+
DIVISORS.each do |divisor|
|
64
|
+
begin
|
65
|
+
t = Time.at(string.to_f / divisor)
|
66
|
+
return t if t > EARLIEST_ACCEPTABLE_TIME
|
67
|
+
rescue RangeError
|
68
|
+
# On Ruby versions built with a 32-bit time_t, attempting to
|
69
|
+
# instantiate a Time object in the far future raises a RangeError,
|
70
|
+
# in which case we know we've chosen the wrong divisor.
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
nil
|
75
|
+
end
|
55
76
|
end
|
56
77
|
end
|
57
78
|
end
|
data/lib/traxor/version.rb
CHANGED