logjam_agent 0.33.0 → 0.33.3

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: eb075dc1c42d045d800df979adde0ba2a4861de680c5154e42fb04552d2d4019
4
+ data.tar.gz: 6f0bf552907f852f0d6e16dcbf05f66b7d0ec5488c36e206046ae4edd5319db3
5
5
  SHA512:
6
- metadata.gz: d5fbde19a0225c1859940ab1add7a690ef67109f861154e7a9d80bbc33834ae18fc415d1ab90ca891d7c245c20761c96ab92d07e99ca011ac5866a740ba37376
7
- data.tar.gz: ff9c7d40001b7902f5fbccb8db57b32d57f23760e74225412be354d046967c97c7e0eafec4bc31b7cd2c961920d31fbc2645671091081e441100001ce82c1d40
6
+ metadata.gz: 30597a450700826424e80d43bdd1e210b0a11e27ba1576bdfe3498fa71d3bd122d30e36b8ba5038a1e2544e30e0a7b63b2ef2e3214df7719276fbdd311d8693f
7
+ data.tar.gz: 271462e2feac5b3ef4eaa29197b64b7d627b6f2561b699f3f0f24ec90a567ef3925d888486e40820f69b410528215f5f790d5f6a0248a2e4a66ec22dd323e7ca
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.3"
3
3
  end
@@ -45,7 +45,8 @@ module LogjamAgent
45
45
  begin
46
46
  require 'ffi-rzmq'
47
47
  context = ZMQ::Context.new(1)
48
- at_exit { context.terminate }
48
+ pid = Process.pid
49
+ at_exit { context.terminate if Process.pid == pid }
49
50
  context
50
51
  end
51
52
  end
@@ -59,7 +60,8 @@ module LogjamAgent
59
60
 
60
61
  def ensure_ping_at_exit
61
62
  return if @ping_ensured
62
- at_exit { ping; reset }
63
+ pid = Process.pid
64
+ at_exit { (ping; reset) if Process.pid == pid }
63
65
  @ping_ensured = true
64
66
  end
65
67
 
@@ -99,7 +101,8 @@ module LogjamAgent
99
101
  if LogjamAgent.ensure_ping_at_exit
100
102
  ensure_ping_at_exit
101
103
  else
102
- at_exit { reset }
104
+ pid = Process.pid
105
+ at_exit { reset if Process.pid == pid}
103
106
  end
104
107
  @socket.setsockopt(ZMQ::LINGER, @config[:linger])
105
108
  @socket.setsockopt(ZMQ::SNDHWM, @config[:snd_hwm])
@@ -141,7 +144,7 @@ module LogjamAgent
141
144
  reset_without_locking
142
145
  return nil
143
146
  end
144
- if answer_parts.first != "" || !VALID_RESPONSE_CODES.include?(answer_parts.second.to_s.to_i)
147
+ if answer_parts.first != app_env || !VALID_RESPONSE_CODES.include?(answer_parts.second.to_s.to_i)
145
148
  log_warning "unexpected answer from logjam broker: #{answer_parts.inspect}"
146
149
  end
147
150
  answer_parts.second
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.3
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-07-29 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.15
279
279
  signing_key:
280
280
  specification_version: 4
281
281
  summary: Logjam client library to be used with logjam