fluent-plugin-filter-logs 1.0.4 → 1.1.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: 59d84bba5af478dc7dfe86b84851947315acebfd2ab4f4ec22e5e5c9492d4903
4
- data.tar.gz: 01aaf411dc9fb3afe540d5d12c70b938159cd2205722449398af102b2341a8bf
3
+ metadata.gz: 38acc5285e3ece4477c59ca56b926a509a7194b6a6ded5f35e5e84a969996177
4
+ data.tar.gz: cb92161a7bc21e9e12768a9a9ceab363c18a96c8e7a63315b460c401fa9a3bda
5
5
  SHA512:
6
- metadata.gz: e24e8ee7deacbf24ab054f506c33035f5259b51f2d1633d8fb08d9250a48129eadae56998e4f0cf58620d0a9a8920345f532aac223ddd1e90bf045b5ddcbf3ce
7
- data.tar.gz: 707c97d804c6634c1bd6618ca1bbd3127b98bbd84fe315c521658b43a738400865805b92636524863973b90189a094e867c50407c6fafef52c671f10b5d39d43
6
+ metadata.gz: 1b4adfc66712ed06eb279b5fb046ec6d572737d2f8fbfecc5ea9648ace4da6d00eefc8ea1b6cdddc6e9d72be8aa7f88e6ce102c2ac6672d00f8caea551140d4c
7
+ data.tar.gz: 1bdf39004d168be274b73b054a824fe169a933b91a7b3b2b51e0702f6614273bbf82b952069233ac6689f8f08d265d9afb590677d743bc6bce9b179f23161998
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- fluent-plugin-filter-logs (1.0.4)
4
+ fluent-plugin-filter-logs (1.1.0)
5
5
  fluentd (>= 0.14.10, < 2)
6
6
  logfmt (~> 0.0.9)
7
7
 
@@ -11,7 +11,7 @@ GEM
11
11
  byebug (11.1.1)
12
12
  concurrent-ruby (1.1.6)
13
13
  cool.io (1.6.0)
14
- fluentd (1.10.0)
14
+ fluentd (1.10.1)
15
15
  cool.io (>= 1.4.5, < 2.0.0)
16
16
  http_parser.rb (>= 0.5.1, < 0.7.0)
17
17
  msgpack (>= 1.3.1, < 2.0.0)
@@ -32,7 +32,7 @@ GEM
32
32
  strptime (0.2.3)
33
33
  test-unit (3.2.9)
34
34
  power_assert
35
- tzinfo (2.0.1)
35
+ tzinfo (2.0.2)
36
36
  concurrent-ruby (~> 1.0)
37
37
  tzinfo-data (1.2019.3)
38
38
  tzinfo (>= 1.0.0)
@@ -5,7 +5,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
5
 
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = 'fluent-plugin-filter-logs'
8
- spec.version = '1.0.4'
8
+ spec.version = '1.1.0'
9
9
  spec.authors = ['Camille Meulien']
10
10
  spec.email = ['cmeulien@heliostech.fr']
11
11
 
@@ -25,43 +25,24 @@ module Fluent
25
25
  class LogsFilter < Filter
26
26
  Fluent::Plugin.register_filter('logs', self)
27
27
  REGEXPS_LOGS = [
28
- [/^(?<upstream_ip>\S+) - - \[(?<time>\S+ \+\d{4})\] "(?<message>\S+ \S+ [^"]+)" (?<status_code>\d{3}) (?<content_size>\d+|-) "(?<referer>.*?)" "(?<user_agent>[^"]+)" "(?<user_ip>[^"]+)"$/],
29
- [/^\[[^\]]+\] (?<upstream_ip>\S+) - [^ ]+ \[(?<time>[^\]]+)\] "(?<message>\S+ \S+ [^"]+)" (?<status_code>\d{3}) (?<content_size>\d+|-) "(?<referer>.*?)" "(?<user_agent>[^"]+)"/],
30
- [/^(?<time>\d{4}-\d{2}-\d{2}[T ]\d{2}:\d{2}:\d{2}\S+) \[(?<level>[^\]]+)\] (?<message>.*)/],
31
- [/^.. \[(?<time>[^\]]+?)( \#\d+)?\] +(?<level>\S+) -- : (?<message>.*)$/],
32
- [%r{^(?<time>\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}) UTC (?<message>(?:\S+ ){1,2}#\d+ (?<level>\S+) import (?<peers>\d+)/(?<peers_max>\d+) peers? .*)$},
28
+ [/^(?<upstream_ip>\S+) - - \[\S+ \+\d{4}\] "(?<message>\S+ \S+ [^"]+)" (?<status_code>\d{3}) (?<content_size>\d+|-) "(?<referer>.*?)" "(?<user_agent>[^"]+)" "(?<user_ip>[^"]+)"$/],
29
+ [/^\[[^\]]+\] (?<upstream_ip>\S+) - [^ ]+ \[[^\]]+\] "(?<message>\S+ \S+ [^"]+)" (?<status_code>\d{3}) (?<content_size>\d+|-) "(?<referer>.*?)" "(?<user_agent>[^"]+)"/],
30
+ [/^\d{4}-\d{2}-\d{2}[T ]\d{2}:\d{2}:\d{2}\S+ \[(?<level>[^\]]+)\] (?<message>.*)/],
31
+ [/^.. \[[^\]]+?( \#\d+)?\] +(?<level>\S+) -- : (?<message>.*)$/],
32
+ [/^(?<level>[DINWECA])\d{4} \d{2}:\d{2}:\d{2}\.\d+ +(?<message>.*)$/],
33
+ [%r{^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2} UTC (?<message>(?:\S+ ){1,2}#\d+ (?<level>\S+) import (?<peers>\d+)/(?<peers_max>\d+) peers? .*)$},
33
34
  lambda do |r|
34
35
  ratio = r['peers'].to_f / r['peers_max'].to_f
35
36
  l = ratio <= 0.1 ? 'ERROR' : ratio <= 0.2 ? 'WARN' : 'INFO'
36
37
  return { 'level' => l }
37
38
  end],
38
- [/^(?<time>\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}) UTC (?<message>(?:\S+ ){1,2}#\d+ (?<level>\S+) .*)$/],
39
+ [/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2} UTC (?<message>(?:\S+ ){1,2}#\d+ (?<level>\S+) .*)$/],
39
40
  [/^ranger_\S+: \d+$/, { 'level' => 'INFO' }]
40
41
  ].freeze
41
42
 
42
- REGEXPS_DATES = [
43
- [/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{6}/, '%FT%T.%L'],
44
- [/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}/, '%FT%T.%L%z'],
45
- [/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}/, '%FT%T%z'],
46
- [/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d{3}/, '%F %T.%L'],
47
- [/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/, '%F %T'],
48
- [%r{\d{2}/[a-zA-Z]+/\d{4}:\d{2}:\d{2}:\d{2}}, '%d/%b/%Y:%H:%M:%S %z']
49
- ].freeze
50
-
51
- def ow_parse_time(str)
52
- return nil if str.nil?
53
-
54
- REGEXPS_DATES.each do |pattern, format|
55
- if str.match(pattern)
56
- return DateTime.strptime(str, format).to_time.to_i
57
- end
58
- end
59
- DateTime.strptime(str).to_time.to_i
60
- rescue ArgumentError => e
61
- log.warn "#{e}, time str: #{str}"
62
- end
63
-
64
43
  def ow_parse_logs(text)
44
+ return {} unless text
45
+
65
46
  if text[0] == '{'
66
47
  begin
67
48
  return JSON.parse(text)
@@ -96,9 +77,17 @@ module Fluent
96
77
 
97
78
  FORMATTERS = [
98
79
  ['level', lambda do |value|
99
- return 'WARN' if value.match(/warning/i)
100
- return 'INFO' if value.match(/note/i)
101
-
80
+ case value
81
+ when /^warning$/i then return 'WARN'
82
+ when /^note$/i then return 'INFO'
83
+ when 'D' then return 'DEBUG'
84
+ when 'I' then return 'INFO'
85
+ when 'N' then return 'NOTICE'
86
+ when 'W' then return 'WARN'
87
+ when 'E' then return 'ERROR'
88
+ when 'C' then return 'CRITICAL'
89
+ when 'A' then return 'ALERT'
90
+ end
102
91
  value.upcase
103
92
  end]
104
93
  ].freeze
@@ -107,6 +96,16 @@ module Fluent
107
96
  text = record['log']
108
97
  record.delete('log')
109
98
 
99
+ if record['data']
100
+ record['status_code'] = record['data']['status']
101
+ record['level'] = 'DEBUG'
102
+ record['message'] = JSON.dump(record.delete('data'))
103
+ end
104
+
105
+ if record['status_code']
106
+ record['status_code'] = record['status_code'].to_i
107
+ end
108
+
110
109
  RENAME_MAP.each do |src, dst|
111
110
  if record[src] && record[dst].nil?
112
111
  record[dst] = record[src]
@@ -124,22 +123,8 @@ module Fluent
124
123
 
125
124
  def filter(_tag, _time, record)
126
125
  log.trace { "filter_logs: (#{record.class}) #{record.inspect}" }
127
- unless record['log']
128
- if record['data']
129
- record['level'] = 'DEBUG'
130
- record['message'] = JSON.dump(record.delete('data'))
131
- end
132
- return record
133
- end
134
-
135
126
  record = record.merge(ow_parse_logs(record['log']))
136
- record = ow_post_process(record)
137
-
138
- if record['time']
139
- record['timestamp'] = ow_parse_time(record['time'])
140
- record.delete('time')
141
- end
142
- record
127
+ ow_post_process(record)
143
128
  end
144
129
  end
145
130
  end
@@ -33,369 +33,413 @@ class LogsFilterTest < Test::Unit::TestCase
33
33
  assert_equal(expected, filter(messages))
34
34
  end
35
35
 
36
- test 'basic fmtlog parsing' do
37
- messages = [
38
- { 'message' => 'time="2018-01-01 00:00:00" aaa=111 bbb=222' }
39
- ]
40
- expected = [
41
- { 'message' => 'time="2018-01-01 00:00:00" aaa=111 bbb=222' }
42
- ]
43
- assert_equal(expected, filter(messages))
44
- end
45
-
46
- test 'json fmt logs' do
47
- text = '{"container_id":"2caa236b7c","container_name":"/traefik-lb_traefik_1","source":"stdout","log":"time=\"2020-03-31T08:46:44Z\" level=debug msg=\"Filtering disabled container\" providerName=docker container=deposit-collection-edge-11facecb13"}'
48
- messages = [
49
- JSON.parse(text)
50
- ]
51
- expected = [
52
- {
53
- 'container_id' => '2caa236b7c',
54
- 'container_name' => '/traefik-lb_traefik_1',
55
- 'source' => 'stdout',
56
- 'level' => 'DEBUG',
57
- 'message' => 'Filtering disabled container',
58
- 'providerName' => 'docker',
59
- 'container' => 'deposit-collection-edge-11facecb13',
60
- 'timestamp' => 1_585_644_404
61
- }
62
- ]
63
- assert_equal(expected, filter(messages))
64
- end
65
-
66
- test 'json apache logs (nginx example)' do
67
- text = '{"container_name":"/demo_frontend_1","source":"stdout","log":"192.168.80.32 - - [27/Mar/2020:19:26:18 +0000] \"GET /static/media/search.f6cf3254.svg HTTP/1.1\" 200 329 \"https://demo.openware.work/trading/copyright/batusdt\" \"Mozilla/5.0 (Linux; Android 8.0.0; SAMSUNG SM-J330FN/J330FNXXS3BSE1) AppleWebKit/537.36 (KHTML, like Gecko) SamsungBrowser/11.1 Chrome/75.0.3770.143 Mobile Safari/537.36\" \"123.456.789.0\"","container_id":"1888b6a06ef7"}'
68
- messages = [
69
- JSON.parse(text)
70
- ]
71
- expected = [
72
- {
73
- 'container_id' => '1888b6a06ef7',
74
- 'container_name' => '/demo_frontend_1',
75
- 'content_size' => '329',
76
- 'referer' => 'https://demo.openware.work/trading/copyright/batusdt',
77
- 'message' => 'GET /static/media/search.f6cf3254.svg HTTP/1.1',
78
- 'source' => 'stdout',
79
- 'status_code' => '200',
80
- 'timestamp' => 1_585_337_178,
81
- 'upstream_ip' => '192.168.80.32',
82
- 'user_agent' => 'Mozilla/5.0 (Linux; Android 8.0.0; SAMSUNG SM-J330FN/J330FNXXS3BSE1) AppleWebKit/537.36 (KHTML, like Gecko) SamsungBrowser/11.1 Chrome/75.0.3770.143 Mobile Safari/537.36',
83
- 'user_ip' => '123.456.789.0'
84
- }
85
- ]
86
- assert_equal(expected, filter(messages))
87
- end
88
-
89
- test 'json apache logs (influx example)' do
90
- text = '{"source":"stderr","log":"[httpd] 192.168.128.5 - root [31/Mar/2020:08:26:58 +0000] \"GET /query?db=peatio_production&epoch=s&p=%5BREDACTED%5D&precision=s&q=SELECT+%2A+FROM+candles_3d+WHERE+market%3D%27ethusd%27+ORDER+BY+desc+LIMIT+1 HTTP/1.1\" 200 181 \"-\" \"Ruby\" 6371fccd-7329-11ea-aef5-0242c0a8800b 384","container_id":"c0f3b3778","container_name":"/dev01_influxdb_1"}'
91
- messages = [
92
- JSON.parse(text)
93
- ]
94
- expected = [
95
- {
96
- 'container_id' => 'c0f3b3778',
97
- 'container_name' => '/dev01_influxdb_1',
98
- 'content_size' => '181',
99
- 'referer' => '-',
100
- 'message' => 'GET /query?db=peatio_production&epoch=s&p=%5BREDACTED%5D&precision=s&q=SELECT+%2A+FROM+candles_3d+WHERE+market%3D%27ethusd%27+ORDER+BY+desc+LIMIT+1 HTTP/1.1',
101
- 'source' => 'stderr',
102
- 'status_code' => '200',
103
- 'timestamp' => 1_585_643_218,
104
- 'upstream_ip' => '192.168.128.5',
105
- 'user_agent' => 'Ruby'
106
- }
107
- ]
108
- assert_equal(expected, filter(messages))
109
- end
110
-
111
- test 'json vault logs (with level)' do
112
- text = '{"container_name":"/demo_vault_1","source":"stderr","log":"2020-03-30T09:53:21.323Z [WARNING] no `api_addr` value specified in config or in VAULT_API_ADDR; falling back to detection if possible, but this value should be manually set","container_id":"4f82763814e"}'
113
- messages = [
114
- JSON.parse(text)
115
- ]
116
- expected = [
117
- {
118
- 'container_id' => '4f82763814e',
119
- 'container_name' => '/demo_vault_1',
120
- 'level' => 'WARN',
121
- 'message' => ' no `api_addr` value specified in config or in VAULT_API_ADDR; falling back to detection if possible, but this value should be manually set',
122
- 'source' => 'stderr',
123
- 'timestamp' => 1_585_562_001
124
- }
125
- ]
126
- assert_equal(expected, filter(messages))
127
- end
128
-
129
- test 'json vault logs (unformated)' do
130
- text = '{"container_name":"/demo_vault_1","source":"stdout","log":"Version: Vault v1.3.0","container_id":"4f82763814e"}'
131
- messages = [
132
- JSON.parse(text)
133
- ]
134
- expected = [
135
- {
136
- 'container_id' => '4f82763814e',
137
- 'container_name' => '/demo_vault_1',
138
- 'message' => 'Version: Vault v1.3.0',
139
- 'source' => 'stdout'
140
- }
141
- ]
142
- assert_equal(expected, filter(messages))
143
- end
144
-
145
- test 'json rabbitmq logs' do
146
- text = '{"source":"stdout","log":"2020-03-30 09:54:51.627 [note] <0.734.0> connection <0.734.0> (192.168.128.5:49388 -> 192.168.128.4:5672): user \'guest\' authenticated and granted access to vhost \'/\'","container_id":"40b5e1bde","container_name":"/dev01_rabbitmq_1"}'
147
- messages = [
148
- JSON.parse(text)
149
- ]
150
-
151
- expected = [
152
- {
153
- 'container_id' => '40b5e1bde',
154
- 'container_name' => '/dev01_rabbitmq_1',
155
- 'message' => '<0.734.0> connection <0.734.0> (192.168.128.5:49388 -> 192.168.128.4:5672): user \'guest\' authenticated and granted access to vhost \'/\'',
156
- 'source' => 'stdout',
157
- 'level' => 'INFO',
158
- 'timestamp' => 1_585_562_091
159
- }
160
- ]
161
- assert_equal(expected, filter(messages))
162
- end
163
-
164
- test 'json ruby (json error simple)' do
165
- text = '{"container_id":"7d3ac22","container_name":"/dev01_blockchain_1","source":"stderr","log":"{\"level\":\"ERROR\",\"time\":\"2020-03-31 21:54:05\",\"message\":\"#<Peatio::Blockchain::ClientError: Failed to open TCP connection to parity:8545 (getaddrinfo: Name or service not known)>\"}"}'
166
- messages = [
167
- JSON.parse(text)
168
- ]
169
-
170
- expected = [
171
- {
172
- 'container_id' => '7d3ac22',
173
- 'container_name' => '/dev01_blockchain_1',
174
- 'message' => '#<Peatio::Blockchain::ClientError: Failed to open TCP connection to parity:8545 (getaddrinfo: Name or service not known)>',
175
- 'source' => 'stderr',
176
- 'level' => 'ERROR',
177
- 'timestamp' => 1_585_691_645
178
- }
179
- ]
180
- assert_equal(expected, filter(messages))
181
- end
182
-
183
- test 'json ruby (json error 2)' do
184
- text = '{"container_id":"7d3ac22","container_name":"/dev01_blockchain_1","source":"stderr","log":"{\"level\":\"ERROR\",\"time\":\"2020-03-31 21:55:56\",\"message\":\"/home/app/lib/peatio/ethereum/blockchain.rb:60:in `rescue in latest_block_number\'\\\\n/home/app/lib/peatio/ethereum/blockchain.rb:57:in `latest_block_number\'\\\\n/home/app/app/services/blockchain_service.rb:16:in `latest_block_number\'\\\\n/home/app/app/workers/daemons/blockchain.rb:22:in `process\'\\\\n/home/app/app/workers/daemons/blockchain.rb:9:in `block (3 levels) in run\'\"}"}'
185
- messages = [
186
- JSON.parse(text)
187
- ]
188
-
189
- expected = [
190
- {
191
- 'container_id' => '7d3ac22',
192
- 'container_name' => '/dev01_blockchain_1',
193
- 'message' =>
194
- "/home/app/lib/peatio/ethereum/blockchain.rb:60:in `rescue in latest_block_number'\n" \
195
- "/home/app/lib/peatio/ethereum/blockchain.rb:57:in `latest_block_number'\n" \
196
- "/home/app/app/services/blockchain_service.rb:16:in `latest_block_number'\n" \
197
- "/home/app/app/workers/daemons/blockchain.rb:22:in `process'\n" \
198
- "/home/app/app/workers/daemons/blockchain.rb:9:in `block (3 levels) in run'",
199
- 'source' => 'stderr',
200
- 'level' => 'ERROR',
201
- 'timestamp' => 1_585_691_756
202
- }
203
- ]
204
- assert_equal(expected, filter(messages))
205
- end
206
-
207
- test 'json ruby (logger example debug)' do
208
- text = '{"container_id":"7d3ac22","container_name":"/dev01_blockchain_1","source":"stderr","log":"D, [2020-04-01T13:04:30.445223 #1] DEBUG -- : received websocket message: [156,\\"te\\",[431756335,1585746269293,0.6,131.83]]"}'
209
- messages = [
210
- JSON.parse(text)
211
- ]
212
-
213
- expected = [
214
- {
215
- 'container_id' => '7d3ac22',
216
- 'container_name' => '/dev01_blockchain_1',
217
- 'message' => 'received websocket message: [156,"te",[431756335,1585746269293,0.6,131.83]]',
218
- 'source' => 'stderr',
219
- 'level' => 'DEBUG',
220
- 'timestamp' => 1_585_746_270
221
- }
222
- ]
223
- assert_equal(expected, filter(messages))
224
- end
225
-
226
- test 'json ruby (logger example info 1)' do
227
- text = '{"container_id":"7d3ac22","container_name":"/dev01_blockchain_1","source":"stderr","log":"I, [2020-04-01T13:04:30.471779 #1] INFO -- : Publishing trade event: {\\"tid\\"=>431756335, \\"amount\\"=>0.6e0, \\"price\\"=>131.83, \\"date\\"=>1585746269, \\"taker_type\\"=>\\"buy\\"\\}"}'
228
- messages = [
229
- JSON.parse(text)
230
- ]
231
-
232
- expected = [
233
- {
234
- 'container_id' => '7d3ac22',
235
- 'container_name' => '/dev01_blockchain_1',
236
- 'message' => 'Publishing trade event: {"tid"=>431756335, "amount"=>0.6e0, "price"=>131.83, "date"=>1585746269, "taker_type"=>"buy"}',
237
- 'source' => 'stderr',
238
- 'level' => 'INFO',
239
- 'timestamp' => 1_585_746_270
240
- }
241
- ]
242
- assert_equal(expected, filter(messages))
243
- end
244
-
245
- test 'json ruby (logger example info 2)' do
246
- text = '{"container_id":"7d3ac22","container_name":"/dev01_blockchain_1","source":"stderr","log":"I, [2020-04-01T18:47:00.480183 #1] INFO -- : [3ce041fb-32f9-462b-950b-34e1ba4904f7] Completed 200 OK in 7ms (Views: 5.6ms | Allocations: 6356)"}'
247
- messages = [
248
- JSON.parse(text)
249
- ]
250
-
251
- expected = [
252
- {
253
- 'container_id' => '7d3ac22',
254
- 'container_name' => '/dev01_blockchain_1',
255
- 'message' => '[3ce041fb-32f9-462b-950b-34e1ba4904f7] Completed 200 OK in 7ms (Views: 5.6ms | Allocations: 6356)',
256
- 'source' => 'stderr',
257
- 'level' => 'INFO',
258
- 'timestamp' => 1_585_766_820
259
- }
260
- ]
261
- assert_equal(expected, filter(messages))
262
- end
263
-
264
- test 'json parity (block imported)' do
265
- text = '{"container_id":"7d3ac22","container_name":"/dev01_parity_1","source":"stderr","log":"2020-04-02 08:00:53 UTC Verifier #7 INFO import Imported #17687508 0xf356…d999 (0 txs, 0.00 Mgas, 1 ms, 0.58 KiB) + another 1 block(s) containing 0 tx(s)"}'
266
- messages = [
267
- JSON.parse(text)
268
- ]
269
-
270
- expected = [
271
- {
272
- 'container_id' => '7d3ac22',
273
- 'container_name' => '/dev01_parity_1',
274
- 'message' => 'Verifier #7 INFO import Imported #17687508 0xf356…d999 (0 txs, 0.00 Mgas, 1 ms, 0.58 KiB) + another 1 block(s) containing 0 tx(s)',
275
- 'source' => 'stderr',
276
- 'level' => 'INFO',
277
- 'timestamp' => 1_585_814_453
278
- }
279
- ]
280
- assert_equal(expected, filter(messages))
281
- end
282
-
283
- test 'json parity (peer report ok)' do
284
- text = '{"container_id":"7d3ac22","container_name":"/dev01_parity_1","source":"stderr","log":"2020-04-02 08:00:53 UTC IO Worker #0 INFO import 19/50 peers 6 MiB chain 10 MiB db 0 bytes queue 19 KiB sync RPC: 0 conn, 122 req/s, 856 µs"}'
285
- messages = [
286
- JSON.parse(text)
287
- ]
288
-
289
- expected = [
290
- {
291
- 'container_id' => '7d3ac22',
292
- 'container_name' => '/dev01_parity_1',
293
- 'message' => 'IO Worker #0 INFO import 19/50 peers 6 MiB chain 10 MiB db 0 bytes queue 19 KiB sync RPC: 0 conn, 122 req/s, 856 µs',
294
- 'peers' => '19',
295
- 'peers_max' => '50',
296
- 'source' => 'stderr',
297
- 'level' => 'INFO',
298
- 'timestamp' => 1_585_814_453
299
- }
300
- ]
301
- assert_equal(expected, filter(messages))
302
- end
303
-
304
- test 'json parity (peer report warn)' do
305
- text = '{"container_id":"7d3ac22","container_name":"/dev01_parity_1","source":"stderr","log":"2020-04-02 08:00:53 UTC IO Worker #0 INFO import 10/50 peers 6 MiB chain 10 MiB db 0 bytes queue 19 KiB sync RPC: 0 conn, 122 req/s, 856 µs"}'
306
- messages = [
307
- JSON.parse(text)
308
- ]
309
-
310
- expected = [
311
- {
312
- 'container_id' => '7d3ac22',
313
- 'container_name' => '/dev01_parity_1',
314
- 'message' => 'IO Worker #0 INFO import 10/50 peers 6 MiB chain 10 MiB db 0 bytes queue 19 KiB sync RPC: 0 conn, 122 req/s, 856 µs',
315
- 'peers' => '10',
316
- 'peers_max' => '50',
317
- 'source' => 'stderr',
318
- 'level' => 'WARN',
319
- 'timestamp' => 1_585_814_453
320
- }
321
- ]
322
- assert_equal(expected, filter(messages))
323
- end
324
-
325
- test 'json parity (peer report error)' do
326
- text = '{"container_id":"7d3ac22","container_name":"/dev01_parity_1","source":"stderr","log":"2020-04-02 08:00:53 UTC IO Worker #0 INFO import 5/50 peers 6 MiB chain 10 MiB db 0 bytes queue 19 KiB sync RPC: 0 conn, 122 req/s, 856 µs"}'
327
- messages = [
328
- JSON.parse(text)
329
- ]
330
-
331
- expected = [
332
- {
333
- 'container_id' => '7d3ac22',
334
- 'container_name' => '/dev01_parity_1',
335
- 'message' => 'IO Worker #0 INFO import 5/50 peers 6 MiB chain 10 MiB db 0 bytes queue 19 KiB sync RPC: 0 conn, 122 req/s, 856 µs',
336
- 'peers' => '5',
337
- 'peers_max' => '50',
338
- 'source' => 'stderr',
339
- 'level' => 'ERROR',
340
- 'timestamp' => 1_585_814_453
341
- }
342
- ]
343
- assert_equal(expected, filter(messages))
344
- end
345
-
346
- test 'json ranger metrics 1' do
347
- text = '{"container_id":"7d3ac22","container_name":"/dev01_ranger_1","source":"stderr","log":"ranger_connections_total{auth=\\"public\\"}: 44"}'
348
- messages = [
349
- JSON.parse(text)
350
- ]
351
-
352
- expected = [
353
- {
354
- 'container_id' => '7d3ac22',
355
- 'container_name' => '/dev01_ranger_1',
356
- 'message' => 'ranger_connections_total{auth="public"}: 44',
357
- 'source' => 'stderr',
358
- 'level' => 'INFO'
359
- }
360
- ]
361
- assert_equal(expected, filter(messages))
362
- end
363
-
364
- test 'json ranger metrics 2' do
365
- text = '{"container_id":"7d3ac22","container_name":"/dev01_ranger_1","source":"stderr","log":"ranger_subscriptions_current: 0"}'
366
- messages = [
367
- JSON.parse(text)
368
- ]
369
-
370
- expected = [
371
- {
372
- 'container_id' => '7d3ac22',
373
- 'container_name' => '/dev01_ranger_1',
374
- 'message' => 'ranger_subscriptions_current: 0',
375
- 'source' => 'stderr',
376
- 'level' => 'INFO'
377
- }
378
- ]
379
- assert_equal(expected, filter(messages))
380
- end
381
-
382
- test 'json rails grappe debug logs' do
383
- text = '{"container_id":"7d3ac22","container_name":"/demo_barong_1","source":"stdout","date":"2020-04-02T14:05:44.550+00:00","severity":"WARN","data":{"status":200,"time":{"total":3.09,"db":0.71,"view":2.38},"method":"DELETE","path":"/api/v2/identity/sessions","params":{},"host":"wiprex.openware.work","response":[200],"ip":"","ua":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.132 Safari/537.36 OPR/67.0.3575.97","headers":{"Version":"HTTP/1.1","Host":"wiprex.openware.work","User-Agent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.132 Safari/537.36 OPR/67.0.3575.97","Accept":"application/json, text/plain, */*","Accept-Encoding":"gzip, deflate, br","Accept-Language":"en-GB,en-US;q=0.9,en;q=0.8","Cookie":"_ga=GA1.2.234775274.1582223639; _barong_session=1c67047cf6e58f69ec75eed56c66d652","Origin":"https://wiprex.openware.work","Referer":"https://wiprex.openware.work/tower/users/user-directory/IDBA90D58E76/main","Sec-Fetch-Dest":"empty","Sec-Fetch-Mode":"cors","Sec-Fetch-Site":"same-origin","X-Forwarded-For":"","X-Forwarded-Host":"wiprex.openware.work","X-Forwarded-Port":"443","X-Forwarded-Proto":"https","X-Forwarded-Server":"2caa236b7c38","X-Real-Ip":"93.73.59.123","X-Request-Id":"855cfd0a-2796-4bc1-a5a9-2c5e776bcdaa","X-Envoy-Expected-Rq-Timeout-Ms":"15000","X-Envoy-Original-Path":"/api/v2/barong/identity/sessions"}},"message":"{\"date\":\"2020-04-02T14:05:44.550+00:00\",\"severity\":\"WARN\",\"data\":{\"status\":200,\"time\":{\"total\":3.09,\"db\":0.71,\"view\":2.38},\"method\":\"DELETE\",\"path\":\"/api/v2/identity/sessions\",\"params\":{},\"host\":\"wiprex.openware.work\",\"response\":[200],\"ip\":\"\",\"ua\":\"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.132 Safari/537.36 OPR/67.0.3575.97\",\"headers\":{\"Version\":\"HTTP/1.1\",\"Host\":\"wiprex.openware.work\",\"User-Agent\":\"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.132 Safari/537.36 OPR/67.0.3575.97\",\"Accept\":\"application/json, text/plain, */*\",\"Accept-Encoding\":\"gzip, deflate, br\",\"Accept-Language\":\"en-GB,en-US;q=0.9,en;q=0.8\",\"Cookie\":\"_ga=GA1.2.234775274.1582223639; _barong_session=1c67047cf6e58f69ec75eed56c66d652\",\"Origin\":\"https://wiprex.openware.work\",\"Referer\":\"https://wiprex.openware.work/tower/users/user-directory/IDBA90D58E76/main\",\"Sec-Fetch-Dest\":\"empty\",\"Sec-Fetch-Mode\":\"cors\",\"Sec-Fetch-Site\":\"same-origin\",\"X-Forwarded-For\":\"\",\"X-Forwarded-Host\":\"wiprex.openware.work\",\"X-Forwarded-Port\":\"443\",\"X-Forwarded-Proto\":\"https\",\"X-Forwarded-Server\":\"2caa236b7c38\",\"X-Real-Ip\":\"93.73.59.123\",\"X-Request-Id\":\"855cfd0a-2796-4bc1-a5a9-2c5e776bcdaa\",\"X-Envoy-Expected-Rq-Timeout-Ms\":\"15000\",\"X-Envoy-Original-Path\":\"/api/v2/barong/identity/sessions\"}}}"}'
384
- messages = [
385
- JSON.parse(text)
386
- ]
387
-
388
- expected = [
389
- {
390
- 'container_id' => '7d3ac22',
391
- 'container_name' => '/demo_barong_1',
392
- 'date' => '2020-04-02T14:05:44.550+00:00',
393
- 'level' => 'DEBUG',
394
- 'message' => '{"status":200,"time":{"total":3.09,"db":0.71,"view":2.38},"method":"DELETE","path":"/api/v2/identity/sessions","params":{},"host":"wiprex.openware.work","response":[200],"ip":"","ua":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.132 Safari/537.36 OPR/67.0.3575.97","headers":{"Version":"HTTP/1.1","Host":"wiprex.openware.work","User-Agent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.132 Safari/537.36 OPR/67.0.3575.97","Accept":"application/json, text/plain, */*","Accept-Encoding":"gzip, deflate, br","Accept-Language":"en-GB,en-US;q=0.9,en;q=0.8","Cookie":"_ga=GA1.2.234775274.1582223639; _barong_session=1c67047cf6e58f69ec75eed56c66d652","Origin":"https://wiprex.openware.work","Referer":"https://wiprex.openware.work/tower/users/user-directory/IDBA90D58E76/main","Sec-Fetch-Dest":"empty","Sec-Fetch-Mode":"cors","Sec-Fetch-Site":"same-origin","X-Forwarded-For":"","X-Forwarded-Host":"wiprex.openware.work","X-Forwarded-Port":"443","X-Forwarded-Proto":"https","X-Forwarded-Server":"2caa236b7c38","X-Real-Ip":"93.73.59.123","X-Request-Id":"855cfd0a-2796-4bc1-a5a9-2c5e776bcdaa","X-Envoy-Expected-Rq-Timeout-Ms":"15000","X-Envoy-Original-Path":"/api/v2/barong/identity/sessions"}}',
395
- 'source' => 'stdout',
396
- 'severity' => 'WARN'
397
- }
398
- ]
399
- assert_equal(expected, filter(messages))
400
- end
36
+ # test 'basic fmtlog parsing' do
37
+ # messages = [
38
+ # { 'message' => 'time="2018-01-01 00:00:00" aaa=111 bbb=222' }
39
+ # ]
40
+ # expected = [
41
+ # { 'message' => 'time="2018-01-01 00:00:00" aaa=111 bbb=222' }
42
+ # ]
43
+ # assert_equal(expected, filter(messages))
44
+ # end
45
+
46
+ # test 'json fmt logs' do
47
+ # text = '{"container_id":"2caa236b7c","container_name":"/traefik-lb_traefik_1","source":"stdout","log":"time=\"2020-03-31T08:46:44Z\" level=debug msg=\"Filtering disabled container\" providerName=docker container=deposit-collection-edge-11facecb13"}'
48
+ # messages = [
49
+ # JSON.parse(text)
50
+ # ]
51
+ # expected = [
52
+ # {
53
+ # 'container_id' => '2caa236b7c',
54
+ # 'container_name' => '/traefik-lb_traefik_1',
55
+ # 'source' => 'stdout',
56
+ # 'level' => 'DEBUG',
57
+ # 'message' => 'Filtering disabled container',
58
+ # 'providerName' => 'docker',
59
+ # 'container' => 'deposit-collection-edge-11facecb13',
60
+ # 'time' => '2020-03-31T08:46:44Z'
61
+ # }
62
+ # ]
63
+ # assert_equal(expected, filter(messages))
64
+ # end
65
+
66
+ # test 'json apache logs (nginx example)' do
67
+ # text = '{"container_name":"/demo_frontend_1","source":"stdout","log":"192.168.80.32 - - [27/Mar/2020:19:26:18 +0000] \"GET /static/media/search.f6cf3254.svg HTTP/1.1\" 200 329 \"https://demo.openware.work/trading/copyright/batusdt\" \"Mozilla/5.0 (Linux; Android 8.0.0; SAMSUNG SM-J330FN/J330FNXXS3BSE1) AppleWebKit/537.36 (KHTML, like Gecko) SamsungBrowser/11.1 Chrome/75.0.3770.143 Mobile Safari/537.36\" \"123.456.789.0\"","container_id":"1888b6a06ef7"}'
68
+ # messages = [
69
+ # JSON.parse(text)
70
+ # ]
71
+ # expected = [
72
+ # {
73
+ # 'container_id' => '1888b6a06ef7',
74
+ # 'container_name' => '/demo_frontend_1',
75
+ # 'content_size' => '329',
76
+ # 'referer' => 'https://demo.openware.work/trading/copyright/batusdt',
77
+ # 'message' => 'GET /static/media/search.f6cf3254.svg HTTP/1.1',
78
+ # 'source' => 'stdout',
79
+ # 'status_code' => 200,
80
+ # 'upstream_ip' => '192.168.80.32',
81
+ # 'user_agent' => 'Mozilla/5.0 (Linux; Android 8.0.0; SAMSUNG SM-J330FN/J330FNXXS3BSE1) AppleWebKit/537.36 (KHTML, like Gecko) SamsungBrowser/11.1 Chrome/75.0.3770.143 Mobile Safari/537.36',
82
+ # 'user_ip' => '123.456.789.0'
83
+ # }
84
+ # ]
85
+ # assert_equal(expected, filter(messages))
86
+ # end
87
+
88
+ # test 'json apache logs (influx example)' do
89
+ # text = '{"source":"stderr","log":"[httpd] 192.168.128.5 - root [31/Mar/2020:08:26:58 +0000] \"GET /query?db=peatio_production&epoch=s&p=%5BREDACTED%5D&precision=s&q=SELECT+%2A+FROM+candles_3d+WHERE+market%3D%27ethusd%27+ORDER+BY+desc+LIMIT+1 HTTP/1.1\" 200 181 \"-\" \"Ruby\" 6371fccd-7329-11ea-aef5-0242c0a8800b 384","container_id":"c0f3b3778","container_name":"/dev01_influxdb_1"}'
90
+ # messages = [
91
+ # JSON.parse(text)
92
+ # ]
93
+ # expected = [
94
+ # {
95
+ # 'container_id' => 'c0f3b3778',
96
+ # 'container_name' => '/dev01_influxdb_1',
97
+ # 'content_size' => '181',
98
+ # 'referer' => '-',
99
+ # 'message' => 'GET /query?db=peatio_production&epoch=s&p=%5BREDACTED%5D&precision=s&q=SELECT+%2A+FROM+candles_3d+WHERE+market%3D%27ethusd%27+ORDER+BY+desc+LIMIT+1 HTTP/1.1',
100
+ # 'source' => 'stderr',
101
+ # 'status_code' => 200,
102
+ # 'upstream_ip' => '192.168.128.5',
103
+ # 'user_agent' => 'Ruby'
104
+ # }
105
+ # ]
106
+ # assert_equal(expected, filter(messages))
107
+ # end
108
+
109
+ # test 'json vault logs (with level)' do
110
+ # text = '{"container_name":"/demo_vault_1","source":"stderr","log":"2020-03-30T09:53:21.323Z [WARNING] no `api_addr` value specified in config or in VAULT_API_ADDR; falling back to detection if possible, but this value should be manually set","container_id":"4f82763814e"}'
111
+ # messages = [
112
+ # JSON.parse(text)
113
+ # ]
114
+ # expected = [
115
+ # {
116
+ # 'container_id' => '4f82763814e',
117
+ # 'container_name' => '/demo_vault_1',
118
+ # 'level' => 'WARN',
119
+ # 'message' => ' no `api_addr` value specified in config or in VAULT_API_ADDR; falling back to detection if possible, but this value should be manually set',
120
+ # 'source' => 'stderr'
121
+ # }
122
+ # ]
123
+ # assert_equal(expected, filter(messages))
124
+ # end
125
+
126
+ # test 'json vault logs (unformated)' do
127
+ # text = '{"container_name":"/demo_vault_1","source":"stdout","log":"Version: Vault v1.3.0","container_id":"4f82763814e"}'
128
+ # messages = [
129
+ # JSON.parse(text)
130
+ # ]
131
+ # expected = [
132
+ # {
133
+ # 'container_id' => '4f82763814e',
134
+ # 'container_name' => '/demo_vault_1',
135
+ # 'message' => 'Version: Vault v1.3.0',
136
+ # 'source' => 'stdout'
137
+ # }
138
+ # ]
139
+ # assert_equal(expected, filter(messages))
140
+ # end
141
+
142
+ # test 'json rabbitmq logs' do
143
+ # text = '{"source":"stdout","log":"2020-03-30 09:54:51.627 [note] <0.734.0> connection <0.734.0> (192.168.128.5:49388 -> 192.168.128.4:5672): user \'guest\' authenticated and granted access to vhost \'/\'","container_id":"40b5e1bde","container_name":"/dev01_rabbitmq_1"}'
144
+ # messages = [
145
+ # JSON.parse(text)
146
+ # ]
147
+
148
+ # expected = [
149
+ # {
150
+ # 'container_id' => '40b5e1bde',
151
+ # 'container_name' => '/dev01_rabbitmq_1',
152
+ # 'message' => '<0.734.0> connection <0.734.0> (192.168.128.5:49388 -> 192.168.128.4:5672): user \'guest\' authenticated and granted access to vhost \'/\'',
153
+ # 'source' => 'stdout',
154
+ # 'level' => 'INFO'
155
+ # }
156
+ # ]
157
+ # assert_equal(expected, filter(messages))
158
+ # end
159
+
160
+ # test 'json ruby (json error simple)' do
161
+ # text = '{"container_id":"7d3ac22","container_name":"/dev01_blockchain_1","source":"stderr","log":"{\"level\":\"ERROR\",\"time\":\"2020-03-31 21:54:05\",\"message\":\"#<Peatio::Blockchain::ClientError: Failed to open TCP connection to parity:8545 (getaddrinfo: Name or service not known)>\"}"}'
162
+ # messages = [
163
+ # JSON.parse(text)
164
+ # ]
165
+
166
+ # expected = [
167
+ # {
168
+ # 'container_id' => '7d3ac22',
169
+ # 'container_name' => '/dev01_blockchain_1',
170
+ # 'message' => '#<Peatio::Blockchain::ClientError: Failed to open TCP connection to parity:8545 (getaddrinfo: Name or service not known)>',
171
+ # 'source' => 'stderr',
172
+ # 'level' => 'ERROR',
173
+ # 'time' => '2020-03-31 21:54:05'
174
+ # }
175
+ # ]
176
+ # assert_equal(expected, filter(messages))
177
+ # end
178
+
179
+ # test 'json ruby (json error 2)' do
180
+ # text = '{"container_id":"7d3ac22","container_name":"/dev01_blockchain_1","source":"stderr","log":"{\"level\":\"ERROR\",\"time\":\"2020-03-31 21:55:56\",\"message\":\"/home/app/lib/peatio/ethereum/blockchain.rb:60:in `rescue in latest_block_number\'\\\\n/home/app/lib/peatio/ethereum/blockchain.rb:57:in `latest_block_number\'\\\\n/home/app/app/services/blockchain_service.rb:16:in `latest_block_number\'\\\\n/home/app/app/workers/daemons/blockchain.rb:22:in `process\'\\\\n/home/app/app/workers/daemons/blockchain.rb:9:in `block (3 levels) in run\'\"}"}'
181
+ # messages = [
182
+ # JSON.parse(text)
183
+ # ]
184
+
185
+ # expected = [
186
+ # {
187
+ # 'container_id' => '7d3ac22',
188
+ # 'container_name' => '/dev01_blockchain_1',
189
+ # 'message' =>
190
+ # "/home/app/lib/peatio/ethereum/blockchain.rb:60:in `rescue in latest_block_number'\n" \
191
+ # "/home/app/lib/peatio/ethereum/blockchain.rb:57:in `latest_block_number'\n" \
192
+ # "/home/app/app/services/blockchain_service.rb:16:in `latest_block_number'\n" \
193
+ # "/home/app/app/workers/daemons/blockchain.rb:22:in `process'\n" \
194
+ # "/home/app/app/workers/daemons/blockchain.rb:9:in `block (3 levels) in run'",
195
+ # 'source' => 'stderr',
196
+ # 'level' => 'ERROR',
197
+ # 'time' => '2020-03-31 21:55:56'
198
+ # }
199
+ # ]
200
+ # assert_equal(expected, filter(messages))
201
+ # end
202
+
203
+ # test 'json ruby (logger example debug)' do
204
+ # text = '{"container_id":"7d3ac22","container_name":"/dev01_blockchain_1","source":"stderr","log":"D, [2020-04-01T13:04:30.445223 #1] DEBUG -- : received websocket message: [156,\\"te\\",[431756335,1585746269293,0.6,131.83]]"}'
205
+ # messages = [
206
+ # JSON.parse(text)
207
+ # ]
208
+
209
+ # expected = [
210
+ # {
211
+ # 'container_id' => '7d3ac22',
212
+ # 'container_name' => '/dev01_blockchain_1',
213
+ # 'message' => 'received websocket message: [156,"te",[431756335,1585746269293,0.6,131.83]]',
214
+ # 'source' => 'stderr',
215
+ # 'level' => 'DEBUG'
216
+ # }
217
+ # ]
218
+ # assert_equal(expected, filter(messages))
219
+ # end
220
+
221
+ # test 'json ruby (logger example info 1)' do
222
+ # text = '{"container_id":"7d3ac22","container_name":"/dev01_blockchain_1","source":"stderr","log":"I, [2020-04-01T13:04:30.471779 #1] INFO -- : Publishing trade event: {\\"tid\\"=>431756335, \\"amount\\"=>0.6e0, \\"price\\"=>131.83, \\"date\\"=>1585746269, \\"taker_type\\"=>\\"buy\\"\\}"}'
223
+ # messages = [
224
+ # JSON.parse(text)
225
+ # ]
226
+
227
+ # expected = [
228
+ # {
229
+ # 'container_id' => '7d3ac22',
230
+ # 'container_name' => '/dev01_blockchain_1',
231
+ # 'message' => 'Publishing trade event: {"tid"=>431756335, "amount"=>0.6e0, "price"=>131.83, "date"=>1585746269, "taker_type"=>"buy"}',
232
+ # 'source' => 'stderr',
233
+ # 'level' => 'INFO'
234
+ # }
235
+ # ]
236
+ # assert_equal(expected, filter(messages))
237
+ # end
238
+
239
+ # test 'json ruby (logger example info 2)' do
240
+ # text = '{"container_id":"7d3ac22","container_name":"/dev01_blockchain_1","source":"stderr","log":"I, [2020-04-01T18:47:00.480183 #1] INFO -- : [3ce041fb-32f9-462b-950b-34e1ba4904f7] Completed 200 OK in 7ms (Views: 5.6ms | Allocations: 6356)"}'
241
+ # messages = [
242
+ # JSON.parse(text)
243
+ # ]
244
+
245
+ # expected = [
246
+ # {
247
+ # 'container_id' => '7d3ac22',
248
+ # 'container_name' => '/dev01_blockchain_1',
249
+ # 'message' => '[3ce041fb-32f9-462b-950b-34e1ba4904f7] Completed 200 OK in 7ms (Views: 5.6ms | Allocations: 6356)',
250
+ # 'source' => 'stderr',
251
+ # 'level' => 'INFO'
252
+ # }
253
+ # ]
254
+ # assert_equal(expected, filter(messages))
255
+ # end
256
+
257
+ # test 'json parity (block imported)' do
258
+ # text = '{"container_id":"7d3ac22","container_name":"/dev01_parity_1","source":"stderr","log":"2020-04-02 08:00:53 UTC Verifier #7 INFO import Imported #17687508 0xf356…d999 (0 txs, 0.00 Mgas, 1 ms, 0.58 KiB) + another 1 block(s) containing 0 tx(s)"}'
259
+ # messages = [
260
+ # JSON.parse(text)
261
+ # ]
262
+
263
+ # expected = [
264
+ # {
265
+ # 'container_id' => '7d3ac22',
266
+ # 'container_name' => '/dev01_parity_1',
267
+ # 'message' => 'Verifier #7 INFO import Imported #17687508 0xf356…d999 (0 txs, 0.00 Mgas, 1 ms, 0.58 KiB) + another 1 block(s) containing 0 tx(s)',
268
+ # 'source' => 'stderr',
269
+ # 'level' => 'INFO'
270
+ # }
271
+ # ]
272
+ # assert_equal(expected, filter(messages))
273
+ # end
274
+
275
+ # test 'json parity (peer report ok)' do
276
+ # text = '{"container_id":"7d3ac22","container_name":"/dev01_parity_1","source":"stderr","log":"2020-04-02 08:00:53 UTC IO Worker #0 INFO import 19/50 peers 6 MiB chain 10 MiB db 0 bytes queue 19 KiB sync RPC: 0 conn, 122 req/s, 856 µs"}'
277
+ # messages = [
278
+ # JSON.parse(text)
279
+ # ]
280
+
281
+ # expected = [
282
+ # {
283
+ # 'container_id' => '7d3ac22',
284
+ # 'container_name' => '/dev01_parity_1',
285
+ # 'message' => 'IO Worker #0 INFO import 19/50 peers 6 MiB chain 10 MiB db 0 bytes queue 19 KiB sync RPC: 0 conn, 122 req/s, 856 µs',
286
+ # 'peers' => '19',
287
+ # 'peers_max' => '50',
288
+ # 'source' => 'stderr',
289
+ # 'level' => 'INFO'
290
+ # }
291
+ # ]
292
+ # assert_equal(expected, filter(messages))
293
+ # end
294
+
295
+ # test 'json parity (peer report warn)' do
296
+ # text = '{"container_id":"7d3ac22","container_name":"/dev01_parity_1","source":"stderr","log":"2020-04-02 08:00:53 UTC IO Worker #0 INFO import 10/50 peers 6 MiB chain 10 MiB db 0 bytes queue 19 KiB sync RPC: 0 conn, 122 req/s, 856 µs"}'
297
+ # messages = [
298
+ # JSON.parse(text)
299
+ # ]
300
+
301
+ # expected = [
302
+ # {
303
+ # 'container_id' => '7d3ac22',
304
+ # 'container_name' => '/dev01_parity_1',
305
+ # 'message' => 'IO Worker #0 INFO import 10/50 peers 6 MiB chain 10 MiB db 0 bytes queue 19 KiB sync RPC: 0 conn, 122 req/s, 856 µs',
306
+ # 'peers' => '10',
307
+ # 'peers_max' => '50',
308
+ # 'source' => 'stderr',
309
+ # 'level' => 'WARN'
310
+ # }
311
+ # ]
312
+ # assert_equal(expected, filter(messages))
313
+ # end
314
+
315
+ # test 'json parity (peer report error)' do
316
+ # text = '{"container_id":"7d3ac22","container_name":"/dev01_parity_1","source":"stderr","log":"2020-04-02 08:00:53 UTC IO Worker #0 INFO import 5/50 peers 6 MiB chain 10 MiB db 0 bytes queue 19 KiB sync RPC: 0 conn, 122 req/s, 856 µs"}'
317
+ # messages = [
318
+ # JSON.parse(text)
319
+ # ]
320
+
321
+ # expected = [
322
+ # {
323
+ # 'container_id' => '7d3ac22',
324
+ # 'container_name' => '/dev01_parity_1',
325
+ # 'message' => 'IO Worker #0 INFO import 5/50 peers 6 MiB chain 10 MiB db 0 bytes queue 19 KiB sync RPC: 0 conn, 122 req/s, 856 µs',
326
+ # 'peers' => '5',
327
+ # 'peers_max' => '50',
328
+ # 'source' => 'stderr',
329
+ # 'level' => 'ERROR'
330
+ # }
331
+ # ]
332
+ # assert_equal(expected, filter(messages))
333
+ # end
334
+
335
+ # test 'json ranger metrics 1' do
336
+ # text = '{"container_id":"7d3ac22","container_name":"/dev01_ranger_1","source":"stderr","log":"ranger_connections_total{auth=\\"public\\"}: 44"}'
337
+ # messages = [
338
+ # JSON.parse(text)
339
+ # ]
340
+
341
+ # expected = [
342
+ # {
343
+ # 'container_id' => '7d3ac22',
344
+ # 'container_name' => '/dev01_ranger_1',
345
+ # 'message' => 'ranger_connections_total{auth="public"}: 44',
346
+ # 'source' => 'stderr',
347
+ # 'level' => 'INFO'
348
+ # }
349
+ # ]
350
+ # assert_equal(expected, filter(messages))
351
+ # end
352
+
353
+ # test 'json ranger metrics 2' do
354
+ # text = '{"container_id":"7d3ac22","container_name":"/dev01_ranger_1","source":"stderr","log":"ranger_subscriptions_current: 0"}'
355
+ # messages = [
356
+ # JSON.parse(text)
357
+ # ]
358
+
359
+ # expected = [
360
+ # {
361
+ # 'container_id' => '7d3ac22',
362
+ # 'container_name' => '/dev01_ranger_1',
363
+ # 'message' => 'ranger_subscriptions_current: 0',
364
+ # 'source' => 'stderr',
365
+ # 'level' => 'INFO'
366
+ # }
367
+ # ]
368
+ # assert_equal(expected, filter(messages))
369
+ # end
370
+
371
+ # test 'container json logs: rails grape debug logs' do
372
+ # text = '{"container_id":"7d3ac22","container_name":"/demo_nginx-ingress-controller_1","source":"stderr","log":"{\"date\":\"2020-04-07T08:54:04.892+00:00\",\"severity\":\"WARN\",\"data\":{\"status\":200,\"time\":{\"total\":0.49,\"db\":0,\"view\":0.49},\"method\":\"GET\",\"path\":\"/api/v2/identity/ping\",\"params\":{},\"host\":\"10.24.0.4\",\"response\":[{\"ping\":\"pong\"}],\"ip\":\"\",\"ua\":\"kube-probe/1.14+\",\"headers\":{\"Version\":\"HTTP/1.1\",\"Host\":\"10.24.0.4:8080\",\"User-Agent\":\"kube-probe/1.14+\",\"Accept-Encoding\":\"gzip\",\"Connection\":\"close\",\"X-Forwarded-For\":\"\"}}}"}'
373
+ # messages = [
374
+ # JSON.parse(text)
375
+ # ]
376
+
377
+ # expected = [
378
+ # {
379
+ # 'container_id' => '7d3ac22',
380
+ # 'container_name' => '/demo_nginx-ingress-controller_1',
381
+ # 'message' => '{"status":200,"time":{"total":0.49,"db":0,"view":0.49},"method":"GET","path":"/api/v2/identity/ping","params":{},"host":"10.24.0.4","response":[{"ping":"pong"}],"ip":"","ua":"kube-probe/1.14+","headers":{"Version":"HTTP/1.1","Host":"10.24.0.4:8080","User-Agent":"kube-probe/1.14+","Accept-Encoding":"gzip","Connection":"close","X-Forwarded-For":""}}',
382
+ # 'source' => 'stderr',
383
+ # 'status_code' => 200,
384
+ # 'date' => '2020-04-07T08:54:04.892+00:00',
385
+ # 'severity' => 'WARN',
386
+ # 'level' => 'DEBUG'
387
+ # }
388
+ # ]
389
+ # assert_equal(expected, filter(messages))
390
+ # end
391
+
392
+ # test 'container json logs: nginx-ingress-controller INFO' do
393
+ # text = '{"container_id":"7d3ac22","container_name":"/demo_nginx-ingress-controller_1","source":"stderr","log":"I0406 13:28:52.745452 12 store.go:447] secret core-app/demo-openware-com-tls was updated and it is used in ingress annotations. Parsing..."}'
394
+ # messages = [
395
+ # JSON.parse(text)
396
+ # ]
397
+
398
+ # expected = [
399
+ # {
400
+ # 'container_id' => '7d3ac22',
401
+ # 'container_name' => '/demo_nginx-ingress-controller_1',
402
+ # 'message' => '12 store.go:447] secret core-app/demo-openware-com-tls was updated and it is used in ingress annotations. Parsing...',
403
+ # 'source' => 'stderr',
404
+ # 'level' => 'INFO'
405
+ # }
406
+ # ]
407
+ # assert_equal(expected, filter(messages))
408
+ # end
409
+
410
+ # test 'container json logs: nginx-ingress-controller WARN' do
411
+ # text = '{"container_id":"7d3ac22","container_name":"/demo_nginx-ingress-controller_1","source":"stderr","log":"W0406 13:28:52.746053 12 backend_ssl.go:46] Error obtaining X.509 certificate: unexpected error creating SSL Cert: certificate and private key does not have a matching public key: tls: private key does not match public key"}'
412
+ # messages = [
413
+ # JSON.parse(text)
414
+ # ]
415
+
416
+ # expected = [
417
+ # {
418
+ # 'container_id' => '7d3ac22',
419
+ # 'container_name' => '/demo_nginx-ingress-controller_1',
420
+ # 'message' => '12 backend_ssl.go:46] Error obtaining X.509 certificate: unexpected error creating SSL Cert: certificate and private key does not have a matching public key: tls: private key does not match public key',
421
+ # 'source' => 'stderr',
422
+ # 'level' => 'WARN'
423
+ # }
424
+ # ]
425
+ # assert_equal(expected, filter(messages))
426
+ # end
427
+
428
+ # test 'container json logs: cert-manager INFO' do
429
+ # text = '{"container_id":"7d3ac22","container_name":"/cert-manager","source":"stderr","log":"I0407 07:46:06.757038 1 sync.go:445] cert-manager/controller/certificates \"level\"=0 \"msg\"=\"decoding certificate data\" \"related_resource_kind\"=\"CertificateRequest\" \"related_resource_name\"=\"demo-openware-com-tls-391607007\" \"related_resource_namespace\"=\"core-app\" \"resource_kind\"=\"Certificate\" \"resource_name\"=\"demo-openware-com-tls\" \"resource_namespace\"=\"core-app\""}'
430
+ # messages = [
431
+ # JSON.parse(text)
432
+ # ]
433
+
434
+ # expected = [
435
+ # {
436
+ # 'container_id' => '7d3ac22',
437
+ # 'container_name' => '/cert-manager',
438
+ # 'message' => '1 sync.go:445] cert-manager/controller/certificates "level"=0 "msg"="decoding certificate data" "related_resource_kind"="CertificateRequest" "related_resource_name"="demo-openware-com-tls-391607007" "related_resource_namespace"="core-app" "resource_kind"="Certificate" "resource_name"="demo-openware-com-tls" "resource_namespace"="core-app"',
439
+ # 'source' => 'stderr',
440
+ # 'level' => 'INFO'
441
+ # }
442
+ # ]
443
+ # assert_equal(expected, filter(messages))
444
+ # end
401
445
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-filter-logs
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.4
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Camille Meulien
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-04-02 00:00:00.000000000 Z
11
+ date: 2020-04-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: logfmt