Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve empty short_message identification #6

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions lib/fluent/gelf_util.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,15 @@ def make_gelfentry(tag,time,record, conf = {})
end
end

if !gelfentry.key?('short_message') or gelfentry['short_message'].to_s.empty? then
if !gelfentry.key?('short_message') or gelfentry['short_message'].to_s.strip.empty? then
# allow other non-empty fields to masquerade as the short_message if it is unset
if gelfentry.key?('_message') and !gelfentry['_message'].to_s.empty? then
if gelfentry.key?('_message') and !gelfentry['_message'].to_s.strip.empty? then
gelfentry['short_message'] = gelfentry.delete('_message')
elsif gelfentry.key?('_msg') and !gelfentry['_msg'].to_s.empty? then
elsif gelfentry.key?('_msg') and !gelfentry['_msg'].to_s.strip.empty? then
gelfentry['short_message'] = gelfentry.delete('_msg')
elsif gelfentry.key?('_log') and !gelfentry['_log'].to_s.empty? then
elsif gelfentry.key?('_log') and !gelfentry['_log'].to_s.strip.empty? then
gelfentry['short_message'] = gelfentry.delete('_log')
elsif gelfentry.key?('_record') and !gelfentry['_record'].to_s.empty? then
elsif gelfentry.key?('_record') and !gelfentry['_record'].to_s.strip.empty? then
gelfentry['short_message'] = gelfentry.delete('_record')
else
# we must have a short_message, so provide placeholder
Expand Down
68 changes: 66 additions & 2 deletions test/plugin/test_out_gelf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,79 @@ def test_configure
def test_format
d = create_driver
time = Time.now
d.emit({"message" => "gelf"}, time.to_i)
d.emit({'message' => 'gelf'}, time.to_i)
d.expect_format({'_tag' => 'test', 'timestamp' => time.to_i, 'short_message' => 'gelf'}.to_msgpack)
d.run
end

def test_format_msg
d = create_driver
time = Time.now
d.emit({'_msg' => 'mymessage'}, time.to_i)
d.expect_format({'_tag' => 'test', 'timestamp' => time.to_i, 'short_message' => 'mymessage'}.to_msgpack)
d.run
end

def test_format_log
d = create_driver
time = Time.now
d.emit({'_log' => 'mylog'}, time.to_i)
d.expect_format({'_tag' => 'test', 'timestamp' => time.to_i, 'short_message' => 'mylog'}.to_msgpack)
d.run
end

def test_format_record
d = create_driver
time = Time.now
d.emit({'_record' => 'myrecord'}, time.to_i)
d.expect_format({'_tag' => 'test', 'timestamp' => time.to_i, 'short_message' => 'myrecord'}.to_msgpack)
d.run
end

def test_empty_short_message
d = create_driver
time = Time.now
d.emit({'short_message' => "\n\r \n"}, time.to_i)
d.expect_format({'_tag' => 'test', 'timestamp' => time.to_i, 'short_message' => '(no message)'}.to_msgpack)
d.run
end

def test_empty_message
d = create_driver
time = Time.now
d.emit({'_message' => "\n\r \n"}, time.to_i)
d.expect_format({'_tag' => 'test', 'timestamp' => time.to_i, '_message' => "\n\r \n", 'short_message' => '(no message)'}.to_msgpack)
d.run
end

def test_empty_msg
d = create_driver
time = Time.now
d.emit({'_msg' => "\n\r \n"}, time.to_i)
d.expect_format({'_tag' => 'test', 'timestamp' => time.to_i, '_msg' => "\n\r \n", 'short_message' => '(no message)'}.to_msgpack)
d.run
end

def test_empty_log
d = create_driver
time = Time.now
d.emit({'_log' => "\n\r \n"}, time.to_i)
d.expect_format({'_tag' => 'test', 'timestamp' => time.to_i, '_log' => "\n\r \n", 'short_message' => '(no message)'}.to_msgpack)
d.run
end

def test_empty_record
d = create_driver
time = Time.now
d.emit({'_record' => "\n\r \n"}, time.to_i)
d.expect_format({'_tag' => 'test', 'timestamp' => time.to_i, '_record' => "\n\r \n", 'short_message' => '(no message)'}.to_msgpack)
d.run
end

def test_write
d = create_driver
time = Time.now
d.emit({"message" => "gelf"}, time.to_i)
d.emit({'message' => 'gelf'}, time.to_i)
d.run
end
end