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 +4 -4
- data/.travis.yml +3 -3
- data/CHANGELOG.md +6 -0
- data/lib/api_hammer/faraday/request_logger.rb +6 -4
- data/lib/api_hammer/request_logger.rb +11 -8
- data/lib/api_hammer/version.rb +1 -1
- data/lib/logstash/filters/api_hammer_request.rb +2 -2
- 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: 43a33c5f9ae38cb2f9bdc1fa75f16c9bbb58abc228ae400d1321f90872dc09e6
|
4
|
+
data.tar.gz: c69e131b3dc28183e32f1cc5a601f38bdb7cd82a8493e0b854818e66c8f9215d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a581e28995ffdeee7f712d9bc743b77db7deca57748267cfbc17e2fb0bf481542facf6a5d511379ed5d8c9291ccb57f4539021eb1e0951834872da6754cdd1bb
|
7
|
+
data.tar.gz: a1fada15803bcb03ba0745c1c46bdd062845b9c511d792d48795a67271ccac78203106a9e9e955e4aad29fad9ba950b5430db51e2c2f472431e9864358a0bfc1
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -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
|
-
|
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' =>
|
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
|
-
|
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(
|
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
|
-
|
65
|
-
|
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
|
-
|
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' =>
|
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
|
-
|
160
|
-
@logger.info "#{bold(intense_cyan('<'))} #{status_s(status)} : #{bold(intense_cyan(request.request_method))} #{intense_cyan(request_uri.normalize)} @ #{intense_cyan(
|
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
|
data/lib/api_hammer/version.rb
CHANGED
@@ -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
|
-
|
28
|
-
dir = role == '
|
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.
|
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:
|
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.
|
308
|
+
rubygems_version: 2.7.8
|
309
309
|
signing_key:
|
310
310
|
specification_version: 4
|
311
311
|
summary: an API tool
|