Skip to content

Commit 520df14

Browse files
author
Cryptophobia
committed
fix: reconcile upstream with v1 API PR
- fixing missing code to make v1 API commit work with upstream changes - fixing functions for new parameter `force_line_breaks` - fixing rubocop errors and exanded lineLength to 100 chars - all tests pass on ruby 2.7.4 Signed-off-by: Cryptophobia <[email protected]>
1 parent 886343f commit 520df14

File tree

5 files changed

+29
-22
lines changed

5 files changed

+29
-22
lines changed

.rubocop.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ Metrics/AbcSize:
1414
Metrics/ClassLength:
1515
Max: 1300
1616

17+
# Offense count: 2
18+
# Configuration parameters: CountComments.
19+
Metrics/LineLength:
20+
Max: 100
21+
1722
# Offense count: 1
1823
# Configuration parameters: CountComments.
1924
Metrics/ModuleLength:

README.rdoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ The plugin supports the following parameters:
7070
forwarded. If not set, incomplete exceptions stacks
7171
are not flushed.
7272

73-
[force_line_breaks] Force line breaks between each lines when comibining exception stacks.
73+
[force_line_breaks] Force line breaks between each lines when combining exception stacks.
7474
This is useful if your exception is formatted
7575
as a single line. i.e., logs retrieved from the docker's
7676
logging driver don't have any line break.

fluent-plugin-detect-exceptions.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ eos
2020
gem.test_files = gem.files.grep(/^(test)/)
2121
gem.require_paths = ['lib']
2222

23-
gem.add_runtime_dependency 'fluentd', '>= 1.0', "< 2"
23+
gem.add_runtime_dependency 'fluentd', '>= 1.0', '< 2'
2424

2525
gem.add_development_dependency 'rake'
2626
gem.add_development_dependency 'rubocop', '= 0.42.0'

lib/fluent/plugin/out_detect_exceptions.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ class DetectExceptionsOutput < Fluent::Plugin::Output
2626

2727
helpers :compat_parameters, :thread, :event_emitter
2828

29+
desc 'The prefix to be removed from the input tag when outputting a record.'
30+
config_param :remove_tag_prefix, :string
2931
desc 'The field which contains the raw message text in the input JSON data.'
3032
config_param :message, :string, default: ''
3133
desc 'The interval of flushing the buffer for multiline format.'

test/plugin/test_out_detect_exceptions.rb

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ def feed_lines_without_line_breaks(driver, t, *messages, stream: nil)
8282
messages.each do |m|
8383
m.each_line do |line|
8484
line.delete!("\n")
85-
driver.emit(log_entry(line, count, stream), t + count)
85+
driver.feed(t + count, log_entry(line, count, stream))
8686
count += 1
8787
end
8888
end
@@ -125,10 +125,10 @@ def test_exception_detection
125125
d = create_driver
126126
t = Time.now.to_i
127127
messages = [ARBITRARY_TEXT, JAVA_EXC, ARBITRARY_TEXT]
128-
d.run(default_tag: DEFAULT_TAG) do
128+
d.run(default_tag: DEFAULT_TAG_STRIPPED) do
129129
feed_lines(d, t, *messages)
130130
end
131-
assert_equal(make_logs("test.tag", t, *messages), d.events)
131+
assert_equal(make_logs('test.tag', t, *messages), d.events)
132132
end
133133

134134
def test_ignore_nested_exceptions
@@ -183,7 +183,7 @@ def test_ignore_nested_exceptions
183183

184184
d.instance.router = router_mock
185185

186-
d.run(default_tag: DEFAULT_TAG) do
186+
d.run(default_tag: DEFAULT_TAG_STRIPPED) do
187187
feed_lines(d, t, json_line_with_exception + json_line_without_exception)
188188
end
189189
end
@@ -195,11 +195,11 @@ def test_single_language_config
195195
languages java)
196196
d = create_driver(cfg)
197197
t = Time.now.to_i
198-
d.run(default_tag: DEFAULT_TAG) do
198+
d.run(default_tag: DEFAULT_TAG_STRIPPED) do
199199
feed_lines(d, t, ARBITRARY_TEXT, JAVA_EXC, PYTHON_EXC)
200200
end
201201
expected = ARBITRARY_TEXT.lines + [JAVA_EXC] + PYTHON_EXC.lines
202-
assert_equal(make_logs(DEFAULT_TAG, t, *expected), d.events)
202+
assert_equal(make_logs(DEFAULT_TAG_STRIPPED, t, *expected), d.events)
203203
end
204204

205205
def test_multi_language_config
@@ -208,11 +208,11 @@ def test_multi_language_config
208208
languages python, java)
209209
d = create_driver(cfg)
210210
t = Time.now.to_i
211-
d.run(default_tag: DEFAULT_TAG) do
211+
d.run(default_tag: DEFAULT_TAG_STRIPPED) do
212212
feed_lines(d, t, ARBITRARY_TEXT, JAVA_EXC, PYTHON_EXC)
213213
end
214214
expected = ARBITRARY_TEXT.lines + [JAVA_EXC] + [PYTHON_EXC]
215-
assert_equal(make_logs(DEFAULT_TAG, t, *expected), d.events)
215+
assert_equal(make_logs(DEFAULT_TAG_STRIPPED, t, *expected), d.events)
216216
end
217217

218218
def test_split_exception_after_timeout
@@ -229,8 +229,8 @@ def test_split_exception_after_timeout
229229
t2 = Time.now.to_i
230230
feed_lines(d, t2, " at x\n at y\n")
231231
end
232-
assert_equal(make_logs(DEFAULT_TAG, t1, JAVA_EXC) +
233-
make_logs(DEFAULT_TAG, t2, " at x\n", " at y\n"),
232+
assert_equal(make_logs(DEFAULT_TAG_STRIPPED, t1, JAVA_EXC) +
233+
make_logs(DEFAULT_TAG_STRIPPED, t2, " at x\n", " at y\n"),
234234
d.events)
235235
end
236236

@@ -246,7 +246,7 @@ def test_do_not_split_exception_after_pause
246246
feed_lines(d, t2, " at x\n at y\n")
247247
d.instance.before_shutdown
248248
end
249-
assert_equal(make_logs("test.tag", t1, JAVA_EXC + " at x\n at y\n"), d.events)
249+
assert_equal(make_logs('test.tag', t1, JAVA_EXC + " at x\n at y\n"), d.events)
250250
end
251251

252252
def test_remove_tag_prefix_is_required
@@ -277,11 +277,11 @@ def test_force_line_breaks_false
277277
force_line_breaks true)
278278
d = create_driver(cfg)
279279
t = Time.now.to_i
280-
d.run do
280+
d.run(default_tag: DEFAULT_TAG) do
281281
feed_lines(d, t, JAVA_EXC)
282282
end
283283
expected = JAVA_EXC
284-
assert_equal(make_logs(t, *expected), d.events)
284+
assert_equal(make_logs(DEFAULT_TAG_STRIPPED, t, *expected), d.events)
285285
end
286286

287287
def test_force_line_breaks_true
@@ -290,7 +290,7 @@ def test_force_line_breaks_true
290290
force_line_breaks true)
291291
d = create_driver(cfg)
292292
t = Time.now.to_i
293-
d.run do
293+
d.run(default_tag: DEFAULT_TAG) do
294294
feed_lines_without_line_breaks(d, t, JAVA_EXC)
295295
end
296296
# Expected: the first two lines of the exception are buffered and combined.
@@ -300,7 +300,7 @@ def test_force_line_breaks_true
300300
# are buffered and combined. So are the first two lines of the second
301301
# exception. Then the rest is logged line-by-line.
302302
expected = JAVA_EXC.chomp
303-
assert_equal(make_logs(t, *expected), d.events)
303+
assert_equal(make_logs(DEFAULT_TAG_STRIPPED, t, *expected), d.events)
304304
end
305305

306306
def test_flush_after_max_lines
@@ -321,7 +321,7 @@ def test_flush_after_max_lines
321321
expected = [PYTHON_EXC.lines[0..1].join] + PYTHON_EXC.lines[2..-1] + \
322322
[JAVA_EXC.lines[0..1].join] + [JAVA_EXC.lines[2..3].join] + \
323323
JAVA_EXC.lines[4..-1]
324-
assert_equal(make_logs(DEFAULT_TAG, t, *expected), d.events)
324+
assert_equal(make_logs(DEFAULT_TAG_STRIPPED, t, *expected), d.events)
325325
end
326326

327327
def test_separate_streams
@@ -342,10 +342,10 @@ def test_separate_streams
342342
# because they belong to different streams.
343343
# Note that the Java exception is only detected when 'something else'
344344
# is processed.
345-
expected = make_logs(DEFAULT_TAG, t, JAVA_EXC, stream: 'java') +
346-
make_logs(DEFAULT_TAG, t, PYTHON_EXC, stream: 'python') +
347-
make_logs(DEFAULT_TAG, t, JAVA_EXC, stream: 'java') +
348-
make_logs(DEFAULT_TAG, t, 'something else', stream: 'java')
345+
expected = make_logs(DEFAULT_TAG_STRIPPED, t, JAVA_EXC, stream: 'java') +
346+
make_logs(DEFAULT_TAG_STRIPPED, t, PYTHON_EXC, stream: 'python') +
347+
make_logs(DEFAULT_TAG_STRIPPED, t, JAVA_EXC, stream: 'java') +
348+
make_logs(DEFAULT_TAG_STRIPPED, t, 'something else', stream: 'java')
349349
assert_equal(expected, d.events)
350350
end
351351
end

0 commit comments

Comments
 (0)