api_hammer 0.18.2 → 0.19.0

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: d08b690f386355cb74fcf2f6dea70a70db2a84baa95087b77a3ef3b7e13b146f
4
- data.tar.gz: a483f9f0b8ca038f76623a1014bbdcf4a37d266293f26976bf439ecba1ae17e2
3
+ metadata.gz: 43a33c5f9ae38cb2f9bdc1fa75f16c9bbb58abc228ae400d1321f90872dc09e6
4
+ data.tar.gz: c69e131b3dc28183e32f1cc5a601f38bdb7cd82a8493e0b854818e66c8f9215d
5
5
  SHA512:
6
- metadata.gz: 2b3a55ad37ca4ca755c8de88c09a1c713b654d3cde3e51fa63d37e04c236582f02da336b4882dd9f18cc3e5ff078464c9cc569e1a18933c03e7eb0fd2d8c3d0b
7
- data.tar.gz: 3f4c29c95bba19accd4a74ce940d9fdc967e27634bc2c60587806387502e727b908c6ce03218d78687a86348a5058a0e2ebd58b2b39430726c8747b1cc8f7302
6
+ metadata.gz: a581e28995ffdeee7f712d9bc743b77db7deca57748267cfbc17e2fb0bf481542facf6a5d511379ed5d8c9291ccb57f4539021eb1e0951834872da6754cdd1bb
7
+ data.tar.gz: a1fada15803bcb03ba0745c1c46bdd062845b9c511d792d48795a67271ccac78203106a9e9e955e4aad29fad9ba950b5430db51e2c2f472431e9864358a0bfc1
@@ -1,7 +1,7 @@
1
1
  rvm:
2
- - 2.0.0
3
- - 2.2.5
4
- - 2.3.1
2
+ - 2.2.10
3
+ - 2.3.8
4
+ - 2.6.1
5
5
  gemfile:
6
6
  - gemfiles/Gemfile_rack_1
7
7
  - gemfiles/Gemfile_rack_2
@@ -1,3 +1,9 @@
1
+ # v0.19.0
2
+ - drop support for ruby < 2.2
3
+ - count time monotonically
4
+ - bugfix getting current logger tags
5
+ - prepare for ur
6
+
1
7
  # v0.18.2
2
8
  - bugfix utf8 http body handling
3
9
  - report to Rollbar on 4xx if Rollbar available and DEBUG_4XX indicates so
@@ -29,6 +29,7 @@ module ApiHammer
29
29
 
30
30
  def call(request_env)
31
31
  began_at = Time.now
32
+ began_ns = Process.clock_gettime(Process::CLOCK_MONOTONIC, :nanosecond)
32
33
 
33
34
  log_tags = Thread.current[:activesupport_tagged_logging_tags]
34
35
  saved_log_tags = log_tags.dup if log_tags && log_tags.any?
@@ -36,7 +37,7 @@ module ApiHammer
36
37
  request_body = request_env[:body].dup if request_env[:body]
37
38
 
38
39
  @app.call(request_env).on_complete do |response_env|
39
- now = Time.now
40
+ now_ns = Process.clock_gettime(Process::CLOCK_MONOTONIC, :nanosecond)
40
41
  status = response_env[:status]
41
42
 
42
43
  if log_bodies(status)
@@ -59,6 +60,7 @@ module ApiHammer
59
60
 
60
61
  data = {
61
62
  'request_role' => 'client',
63
+ 'bound' => 'outbound',
62
64
  'request' => {
63
65
  'method' => request_env[:method],
64
66
  'uri' => request_env[:url].normalize.to_s,
@@ -72,15 +74,15 @@ module ApiHammer
72
74
  }.reject{|k,v| v.nil? },
73
75
  'processing' => {
74
76
  'began_at' => began_at.utc.to_f,
75
- 'duration' => now - began_at,
77
+ 'duration' => (now_ns - began_ns) * 1e-9,
76
78
  'activesupport_tagged_logging_tags' => log_tags,
77
79
  }.reject{|k,v| v.nil? },
78
80
  }
79
81
 
80
82
  json_data = JSON.generate(data)
81
83
  dolog = proc do
82
- now_s = now.strftime('%Y-%m-%d %H:%M:%S %Z')
83
- @logger.info "#{bold(intense_magenta('>'))} #{status_s(status)} : #{bold(intense_magenta(request_env[:method].to_s.upcase))} #{intense_magenta(request_env[:url].normalize.to_s)} @ #{intense_magenta(now_s)}"
84
+ began_s = began_at.strftime('%Y-%m-%d %H:%M:%S %Z')
85
+ @logger.info "#{bold(intense_magenta('>'))} #{status_s(status)} : #{bold(intense_magenta(request_env[:method].to_s.upcase))} #{intense_magenta(request_env[:url].normalize.to_s)} @ #{intense_magenta(began_s)}"
84
86
  @logger.info json_data
85
87
  end
86
88
 
@@ -55,14 +55,16 @@ module ApiHammer
55
55
 
56
56
  def call(env)
57
57
  began_at = Time.now
58
+ began_ns = Process.clock_gettime(Process::CLOCK_MONOTONIC, :nanosecond)
58
59
 
59
60
  # this is closed after the app is called, so read it before
60
61
  env["rack.input"].rewind
61
62
  request_body = env["rack.input"].read
62
63
  env["rack.input"].rewind
63
64
 
64
- log_tags = Thread.current[:activesupport_tagged_logging_tags]
65
- log_tags = log_tags.dup if log_tags && log_tags.any?
65
+ if @logger && @logger.formatter.respond_to?(:current_tags)
66
+ log_tags = @logger.formatter.current_tags.dup
67
+ end
66
68
 
67
69
  request = Rack::Request.new(env)
68
70
  request_uri = Addressable::URI.new(
@@ -76,13 +78,13 @@ module ApiHammer
76
78
  status, response_headers, response_body = @app.call(env)
77
79
  response_headers = ::Rack::Utils::HeaderHash.new(response_headers)
78
80
  body_proxy = ::Rack::BodyProxy.new(response_body) do
79
- log(env, request_uri, request_body, status, response_headers, response_body, began_at, log_tags)
81
+ log(env, request_uri, request_body, status, response_headers, response_body, began_at, began_ns, log_tags)
80
82
  end
81
83
  [status, response_headers, body_proxy]
82
84
  end
83
85
 
84
- def log(env, request_uri, request_body, status, response_headers, response_body, began_at, log_tags)
85
- now = Time.now
86
+ def log(env, request_uri, request_body, status, response_headers, response_body, began_at, began_ns, log_tags)
87
+ now_ns = Process.clock_gettime(Process::CLOCK_MONOTONIC, :nanosecond)
86
88
 
87
89
  request = Rack::Request.new(env)
88
90
  response = Rack::Response.new('', status, response_headers)
@@ -102,6 +104,7 @@ module ApiHammer
102
104
 
103
105
  data = {
104
106
  'request_role' => 'server',
107
+ 'bound' => 'inbound',
105
108
  'request' => {
106
109
  'method' => request.request_method,
107
110
  'uri' => request_uri.normalize.to_s,
@@ -121,7 +124,7 @@ module ApiHammer
121
124
  }.reject { |k,v| v.nil? },
122
125
  'processing' => {
123
126
  'began_at' => began_at.utc.to_f,
124
- 'duration' => now - began_at,
127
+ 'duration' => (now_ns - began_ns) * 1e-9,
125
128
  'activesupport_tagged_logging_tags' => log_tags,
126
129
  }.merge(env['request_logger.info'] || {}).merge(Thread.current['request_logger.info'] || {}).reject { |k,v| v.nil? },
127
130
  }
@@ -156,8 +159,8 @@ module ApiHammer
156
159
  Thread.current['request_logger.info'] = nil
157
160
  json_data = JSON.dump(data)
158
161
  dolog = proc do
159
- now_s = now.strftime('%Y-%m-%d %H:%M:%S %Z')
160
- @logger.info "#{bold(intense_cyan('<'))} #{status_s(status)} : #{bold(intense_cyan(request.request_method))} #{intense_cyan(request_uri.normalize)} @ #{intense_cyan(now_s)}"
162
+ began_s = began_at.strftime('%Y-%m-%d %H:%M:%S %Z')
163
+ @logger.info "#{bold(intense_cyan('<'))} #{status_s(status)} : #{bold(intense_cyan(request.request_method))} #{intense_cyan(request_uri.normalize)} @ #{intense_cyan(began_s)}"
161
164
  @logger.info json_data
162
165
  end
163
166
  # do the logging with tags that applied to the request if appropriate
@@ -1,3 +1,3 @@
1
1
  module ApiHammer
2
- VERSION = "0.18.2"
2
+ VERSION = "0.19.0"
3
3
  end
@@ -24,8 +24,8 @@ class LogStash::Filters::ApiHammerRequest < LogStash::Filters::Base
24
24
  parsed_message = JSON.parse(event[@source])
25
25
  if @consume
26
26
  # replace the source with a brief human-readable message
27
- role = parsed_message['request_role']
28
- dir = role == 'server' ? '<' : role == 'client' ? '>' : '*'
27
+ bound = parsed_message['bound']
28
+ dir = role == 'inbound' ? '<' : role == 'outbound' ? '>' : '*'
29
29
  status = parsed_message['response'] && parsed_message['response']['status']
30
30
  request_method = parsed_message['request'] && parsed_message['request']['method']
31
31
  request_uri = parsed_message['request'] && parsed_message['request']['uri']
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: api_hammer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.18.2
4
+ version: 0.19.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ethan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-09-20 00:00:00.000000000 Z
11
+ date: 2019-02-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack
@@ -305,7 +305,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
305
305
  version: '0'
306
306
  requirements: []
307
307
  rubyforge_project:
308
- rubygems_version: 2.7.7
308
+ rubygems_version: 2.7.8
309
309
  signing_key:
310
310
  specification_version: 4
311
311
  summary: an API tool