rv-logstasher 1.4.0 → 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ae42bed976297c0bd68a70f5c8c1c2b6f7bdb24f
|
4
|
+
data.tar.gz: 11b24849c5ec9abf497e5585afb754ed9e262c51
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b8d12f21f733c625f27fc2de6ec78ccf07aa29ea4d2475b6249ce09c217fdb42b495074e8c60aa0ecbb86c72179d006bc6f6292c44e09a3852218baa97cf7aa6
|
7
|
+
data.tar.gz: 999f1d3d9137d865310ab239a13639a608bd5c33160c0b09bdb98253bd6d87d143de5d2dd8f8fddb40a5eab88e81a9d0aa3d5396fdf2d10eb623ab76f86d766e
|
data/lib/logstasher.rb
CHANGED
@@ -34,12 +34,29 @@ module LogStasher
|
|
34
34
|
private
|
35
35
|
|
36
36
|
def format_hash(data)
|
37
|
-
|
38
|
-
|
39
|
-
|
37
|
+
formatted_data = filter_parameters(data)
|
38
|
+
|
39
|
+
# logstash overrides the path attribute
|
40
|
+
formatted_data.merge!(request_path: formatted_data[:path]) if formatted_data[:path]
|
41
|
+
|
42
|
+
if formatted_data[:exception]
|
43
|
+
format_exception(formatted_data.delete(:exception)).merge(formatted_data)
|
40
44
|
else
|
41
|
-
|
45
|
+
formatted_data
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def filter_parameters(data)
|
50
|
+
return data unless data[:params]
|
51
|
+
|
52
|
+
# We override fields, don't want to risk mutating params object!
|
53
|
+
filtered_data = data.dup
|
54
|
+
|
55
|
+
LogStasher.filter_parameters.each do |param|
|
56
|
+
filtered_data[:params][param] = '[FILTERED]' unless filtered_data[:params][param].nil?
|
42
57
|
end
|
58
|
+
|
59
|
+
filtered_data
|
43
60
|
end
|
44
61
|
|
45
62
|
def format_exception(exception)
|
@@ -93,9 +93,6 @@ module LogStasher
|
|
93
93
|
def extract_parameters(payload)
|
94
94
|
if LogStasher.include_parameters?
|
95
95
|
external_params = payload[:params].except(*INTERNAL_PARAMS)
|
96
|
-
LogStasher.filter_parameters.each do |param|
|
97
|
-
external_params[param] = '[FILTERED]' unless external_params[param].nil?
|
98
|
-
end
|
99
96
|
|
100
97
|
if LogStasher.serialize_parameters?
|
101
98
|
{ :params => JSON.generate(external_params) }
|
data/lib/logstasher/version.rb
CHANGED
@@ -25,25 +25,32 @@ describe LogStasher::LogFormatter do
|
|
25
25
|
]
|
26
26
|
end
|
27
27
|
|
28
|
-
|
28
|
+
let(:instance) { described_class.new('base-tag', '/my/root/releases/12345') }
|
29
29
|
|
30
30
|
describe '#release' do
|
31
|
+
subject(:release) { instance.release }
|
32
|
+
|
31
33
|
it 'returns indetifier of release from the root dir' do
|
32
|
-
expect(
|
34
|
+
expect(release).to eq('12345')
|
33
35
|
end
|
34
36
|
end
|
35
37
|
|
36
38
|
describe '#format' do
|
39
|
+
subject(:format) { instance.format(data) }
|
40
|
+
|
37
41
|
context 'with string as an argument' do
|
42
|
+
let(:data) { 'foo' }
|
43
|
+
|
38
44
|
it 'returns hash with message key' do
|
39
|
-
expect(
|
45
|
+
expect(format).to eq({ message: 'foo' })
|
40
46
|
end
|
41
47
|
end
|
42
48
|
|
43
49
|
context 'with exception as an argument' do
|
50
|
+
let(:data) { exception }
|
44
51
|
|
45
52
|
it 'returns hash describing the exception' do
|
46
|
-
expect(
|
53
|
+
expect(format).to match({
|
47
54
|
tags: 'exception',
|
48
55
|
error_class: 'TestError',
|
49
56
|
error_message: exception_message,
|
@@ -60,9 +67,11 @@ describe LogStasher::LogFormatter do
|
|
60
67
|
end
|
61
68
|
|
62
69
|
context 'with hash as an argument' do
|
70
|
+
let(:data) { { foo: 'bar', path: '/my/path' } }
|
71
|
+
|
63
72
|
it 'returns hash as it is with path attribute copied to request_path' do
|
64
73
|
# logstash overrides the path attribute
|
65
|
-
expect(
|
74
|
+
expect(format).to match({
|
66
75
|
foo: 'bar',
|
67
76
|
path: '/my/path',
|
68
77
|
request_path: '/my/path',
|
@@ -71,8 +80,10 @@ describe LogStasher::LogFormatter do
|
|
71
80
|
end
|
72
81
|
|
73
82
|
context 'with hash containing exception key as an argument' do
|
83
|
+
let(:data) { { exception: exception, tags: 'custom_tag', foo: 'bar' } }
|
84
|
+
|
74
85
|
it 'returns hash describing the exception merged with items from origina hash' do
|
75
|
-
expect(
|
86
|
+
expect(format).to match({
|
76
87
|
tags: 'custom_tag',
|
77
88
|
error_class: 'TestError',
|
78
89
|
error_message: exception_message,
|
@@ -88,18 +99,58 @@ describe LogStasher::LogFormatter do
|
|
88
99
|
})
|
89
100
|
end
|
90
101
|
end
|
102
|
+
|
103
|
+
context 'when the hash contains filtered parameters' do
|
104
|
+
describe 'defaults' do
|
105
|
+
let(:data) do
|
106
|
+
{
|
107
|
+
params: {
|
108
|
+
'password' => '1337passWORD',
|
109
|
+
'password_confirmation' => '1337passWORD'
|
110
|
+
}
|
111
|
+
}
|
112
|
+
end
|
113
|
+
|
114
|
+
it 'filters out password and password_confirmation' do
|
115
|
+
expect(format).to match(
|
116
|
+
params: {
|
117
|
+
'password' => '[FILTERED]',
|
118
|
+
'password_confirmation' => '[FILTERED]'
|
119
|
+
}
|
120
|
+
)
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
context 'with specified filtering' do
|
125
|
+
let(:data) { {params: {'foo' => 'bar', 'blah' => 'something'}} }
|
126
|
+
before(:each) do
|
127
|
+
allow(::LogStasher).to receive(:filter_parameters).and_return(['foo'])
|
128
|
+
end
|
129
|
+
|
130
|
+
it 'filters out the specified fields only' do
|
131
|
+
expect(format).to match(params: {'foo' => '[FILTERED]', 'blah' => 'something'})
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
91
135
|
end
|
92
136
|
|
93
137
|
describe '#call' do
|
138
|
+
let(:args) do
|
139
|
+
[
|
140
|
+
:error,
|
141
|
+
Time.new(2016, 01, 02, 03, 04, 05),
|
142
|
+
progname,
|
143
|
+
exception_message
|
144
|
+
]
|
145
|
+
end
|
146
|
+
|
147
|
+
subject(:call) { instance.call(*args) }
|
148
|
+
|
94
149
|
context 'when progname is nil' do
|
95
150
|
let(:progname) { nil }
|
96
151
|
|
97
152
|
it 'returns hash with message key' do
|
98
|
-
result = JSON.parse(
|
99
|
-
:error,
|
100
|
-
Time.new(2016, 01, 02, 03, 04, 05),
|
101
|
-
progname,
|
102
|
-
exception_message)).deep_symbolize_keys!
|
153
|
+
result = JSON.parse(call).deep_symbolize_keys!
|
103
154
|
|
104
155
|
expect(result).to include({
|
105
156
|
message: exception_message,
|
@@ -115,15 +166,10 @@ describe LogStasher::LogFormatter do
|
|
115
166
|
let(:progname) { exception }
|
116
167
|
|
117
168
|
it 'returns hash describing the exception' do
|
118
|
-
result = JSON.parse(
|
119
|
-
:error,
|
120
|
-
Time.new(2016, 01, 02, 03, 04, 05),
|
121
|
-
progname,
|
122
|
-
exception_message)).deep_symbolize_keys!
|
169
|
+
result = JSON.parse(call).deep_symbolize_keys!
|
123
170
|
|
124
171
|
expect(result).to include({
|
125
172
|
message: exception_message,
|
126
|
-
tags: 'exception',
|
127
173
|
error_class: 'TestError',
|
128
174
|
error_message: exception_message,
|
129
175
|
error_source: '/foo/broken.rb',
|
@@ -35,12 +35,11 @@ describe LogStasher::LogSubscriber do
|
|
35
35
|
describe '#process_action' do
|
36
36
|
let(:timestamp) { ::Time.new.utc.iso8601(3) }
|
37
37
|
let(:duration) { 12.4 }
|
38
|
-
let(:params) { {'foo' => 'bar'} }
|
39
38
|
let(:json_params) { JSON.dump(payload[:params]) }
|
40
39
|
let(:payload) {{
|
41
40
|
:controller => 'users',
|
42
41
|
:action => 'show',
|
43
|
-
:params =>
|
42
|
+
:params => { 'foo' => 'bar' },
|
44
43
|
:format => 'text/plain',
|
45
44
|
:method => 'method',
|
46
45
|
:path => '/users/1',
|
@@ -106,32 +105,6 @@ describe LogStasher::LogSubscriber do
|
|
106
105
|
subject.process_action(event)
|
107
106
|
end
|
108
107
|
|
109
|
-
it 'can be configured to filter out certain parameters' do
|
110
|
-
allow(::LogStasher).to receive(:filter_parameters).and_return(['foo'])
|
111
|
-
|
112
|
-
expect(logger).to receive(:<<) do |json|
|
113
|
-
expect(JSON.parse(json)['params']).to eq('{"foo":"[FILTERED]"}')
|
114
|
-
end
|
115
|
-
|
116
|
-
subject.process_action(event)
|
117
|
-
end
|
118
|
-
|
119
|
-
context 'with passwords in parameters' do
|
120
|
-
let(:params) do
|
121
|
-
{'password' => '1337passWORD', 'password_confirmation' => '1337passWORD'}
|
122
|
-
end
|
123
|
-
|
124
|
-
it 'filters them out by default' do
|
125
|
-
expect(logger).to receive(:<<) do |json|
|
126
|
-
expect(JSON.parse(json)['params']).to eq(
|
127
|
-
'{"password":"[FILTERED]","password_confirmation":"[FILTERED]"}'
|
128
|
-
)
|
129
|
-
end
|
130
|
-
|
131
|
-
subject.process_action(event)
|
132
|
-
end
|
133
|
-
end
|
134
|
-
|
135
108
|
it 'includes redirect location in the log' do
|
136
109
|
redirect_event = double(:payload => {:location => 'new/location'})
|
137
110
|
subject.redirect_to(redirect_event)
|