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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: dbd400c4a9aedda3d5659a550bd2da21e9a29696cd1e5c77c14cb1f15d8e7e50
4
- data.tar.gz: d71e179fd331b16c0b2117a31a15e45278477b8f4709ffaf93d91c2a859d9a44
3
+ metadata.gz: 29e2045e24e8a76d6cd8d13c4521562f237849880f39eec65c6be243b275cd06
4
+ data.tar.gz: 264a22f43eafaca127977d689ede51a657c4aa9403f5339528c56647f0a502c7
5
5
  SHA512:
6
- metadata.gz: d5fbde19a0225c1859940ab1add7a690ef67109f861154e7a9d80bbc33834ae18fc415d1ab90ca891d7c245c20761c96ab92d07e99ca011ac5866a740ba37376
7
- data.tar.gz: ff9c7d40001b7902f5fbccb8db57b32d57f23760e74225412be354d046967c97c7e0eafec4bc31b7cd2c961920d31fbc2645671091081e441100001ce82c1d40
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
- [![Travis](https://travis-ci.org/skaes/logjam_agent.svg?branch=master)](https://travis-ci.org/github/skaes/logjam_agent)
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
- start_time_header = env['HTTP_X_STARTTIME']
36
- if start_time_header
37
- if start_time_header =~ /\At=(\d+)\z/
38
- # HTTP_X_STARTTIME is microseconds since the epoch (UTC)
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
@@ -1,3 +1,3 @@
1
1
  module LogjamAgent
2
- VERSION = "0.33.0"
2
+ VERSION = "0.33.1"
3
3
  end
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.0
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: 2021-08-07 00:00:00.000000000 Z
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.2.24
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