logjam_agent 0.33.0 → 0.33.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -1
- data/lib/logjam_agent/rack/logger.rb +23 -17
- data/lib/logjam_agent/version.rb +1 -1
- data/test/sinatra_test.rb +1 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 29e2045e24e8a76d6cd8d13c4521562f237849880f39eec65c6be243b275cd06
|
4
|
+
data.tar.gz: 264a22f43eafaca127977d689ede51a657c4aa9403f5339528c56647f0a502c7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4fb90fd911820483409d59f8b0d8f272fe06b55460127899edbfc77da57cf064b32c633dee61bd1bf113acbf205487689bfdc43d623c6d8faaea4bbff9523bd5
|
7
|
+
data.tar.gz: 86470089e012dbf3462725708e65e0deb3a5d8d9cb1268452fb051948d80f55ce6c2361ffde3064aff41f8c9049a5d3452cfad4cbb8c7e87e455142289aed8f2
|
data/README.md
CHANGED
@@ -10,7 +10,8 @@ Has experimental support for Sinatra.
|
|
10
10
|
Currently only one mechanism is available for data transport:
|
11
11
|
ZeroMQ. Support for AMQP has been dropped.
|
12
12
|
|
13
|
-
|
13
|
+
|
14
|
+
![Build](https://github.com/skaes/logjam_agent/actions/workflows/run-tests.yml/badge.svg)
|
14
15
|
|
15
16
|
|
16
17
|
## Usage
|
@@ -32,23 +32,16 @@ module LogjamAgent
|
|
32
32
|
|
33
33
|
def call_app(request, env)
|
34
34
|
start_time = Time.now
|
35
|
-
|
36
|
-
if
|
37
|
-
|
38
|
-
|
39
|
-
http_start_time = Time.at($1.to_f / 1_000_000.0)
|
40
|
-
elsif start_time_header =~ /\Ats=(\d+)(?:\.(\d+))?\z/
|
41
|
-
# HTTP_X_STARTTIME is seconds since the epoch (UTC) with a milliseconds resolution
|
42
|
-
http_start_time = Time.at($1.to_f + $2.to_f / 1000)
|
43
|
-
end
|
44
|
-
|
45
|
-
if http_start_time && (wait_time_ms = (start_time - http_start_time) * 1000) > 0
|
35
|
+
wait_time_ms = 0.0
|
36
|
+
if http_start_time = extract_http_start_time(env)
|
37
|
+
wait_time_ms = (start_time - http_start_time) * 1000
|
38
|
+
if wait_time_ms > 0
|
46
39
|
start_time = http_start_time
|
40
|
+
else
|
41
|
+
wait_time_ms = 0.0
|
47
42
|
end
|
48
|
-
else
|
49
|
-
wait_time_ms = 0.0
|
50
43
|
end
|
51
|
-
before_dispatch(request, env, start_time)
|
44
|
+
before_dispatch(request, env, start_time, wait_time_ms)
|
52
45
|
result = @app.call(env)
|
53
46
|
rescue ActionDispatch::RemoteIp::IpSpoofAttackError
|
54
47
|
result = [403, {}, ['Forbidden']]
|
@@ -57,6 +50,20 @@ module LogjamAgent
|
|
57
50
|
after_dispatch(env, result, run_time_ms, wait_time_ms)
|
58
51
|
end
|
59
52
|
|
53
|
+
def extract_http_start_time(env)
|
54
|
+
start_time_header = env['HTTP_X_STARTTIME']
|
55
|
+
if start_time_header
|
56
|
+
if start_time_header =~ /\At=(\d+)\z/
|
57
|
+
# HTTP_X_STARTTIME is microseconds since the epoch (UTC)
|
58
|
+
return Time.at($1.to_f / 1_000_000.0)
|
59
|
+
elsif start_time_header =~ /\Ats=(\d+)(?:\.(\d+))?\z/
|
60
|
+
# HTTP_X_STARTTIME is seconds since the epoch (UTC) with a milliseconds resolution
|
61
|
+
return Time.at($1.to_f + $2.to_f / 1000)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
return nil
|
65
|
+
end
|
66
|
+
|
60
67
|
def compute_tags(request)
|
61
68
|
@taggers.collect do |tag|
|
62
69
|
case tag
|
@@ -78,7 +85,7 @@ module LogjamAgent
|
|
78
85
|
false
|
79
86
|
end
|
80
87
|
|
81
|
-
def before_dispatch(request, env, start_time)
|
88
|
+
def before_dispatch(request, env, start_time, wait_time_ms)
|
82
89
|
logger.formatter.reset_attributes if logger.formatter.respond_to?(:reset_attributes)
|
83
90
|
TimeBandits.reset
|
84
91
|
Thread.current.thread_variable_set(:time_bandits_completed_info, nil)
|
@@ -90,6 +97,7 @@ module LogjamAgent
|
|
90
97
|
|
91
98
|
logjam_request.start_time = start_time
|
92
99
|
logjam_fields = logjam_request.fields
|
100
|
+
logjam_fields[:wait_time] = wait_time_ms if wait_time_ms > 0.0
|
93
101
|
spoofed = nil
|
94
102
|
ip = nil
|
95
103
|
begin
|
@@ -125,7 +133,6 @@ module LogjamAgent
|
|
125
133
|
|
126
134
|
if wait_time_ms < 0
|
127
135
|
warn LogjamAgent::NegativeWaitTime.new("#{wait_time_ms} ms")
|
128
|
-
wait_time_ms = 0.0
|
129
136
|
end
|
130
137
|
|
131
138
|
message = "Completed #{status} #{::Rack::Utils::HTTP_STATUS_CODES[status]} in %.1fms" % run_time_ms
|
@@ -135,7 +142,6 @@ module LogjamAgent
|
|
135
142
|
ActiveSupport::LogSubscriber.flush_all!
|
136
143
|
request_info = { :total_time => run_time_ms, :code => status }
|
137
144
|
request_info[:view_time] = view_time if view_time
|
138
|
-
request_info[:wait_time] = wait_time_ms if wait_time_ms > 0
|
139
145
|
logjam_request.fields.merge!(request_info)
|
140
146
|
|
141
147
|
env["time_bandits.metrics"] = TimeBandits.metrics
|
data/lib/logjam_agent/version.rb
CHANGED
data/test/sinatra_test.rb
CHANGED
@@ -37,6 +37,7 @@ module LogjamAgent
|
|
37
37
|
assert_kind_of String, payload["started_at"]
|
38
38
|
assert_kind_of Integer, payload["started_ms"]
|
39
39
|
assert_kind_of String, payload["ip"]
|
40
|
+
assert_nil payload["wait_time"]
|
40
41
|
# assert_kind_of Float, payload["view_time"]
|
41
42
|
lines = payload["lines"]
|
42
43
|
assert_match(/Started GET.*password=\[FILTERED\]/, lines[0][2])
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: logjam_agent
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.33.
|
4
|
+
version: 0.33.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stefan Kaes
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-03-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -275,7 +275,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
275
275
|
- !ruby/object:Gem::Version
|
276
276
|
version: '0'
|
277
277
|
requirements: []
|
278
|
-
rubygems_version: 3.
|
278
|
+
rubygems_version: 3.3.4
|
279
279
|
signing_key:
|
280
280
|
specification_version: 4
|
281
281
|
summary: Logjam client library to be used with logjam
|