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

Updated fix to Do not strip leading underscore from fields conflicting with GELF fields #72

Open
wants to merge 2 commits into
base: main
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## next
- Fix: avoid GELF internal fields when removing leading underscores

## 3.3.2
- Fix: avoid panic when handling very-large exponent-notation `_@timestamp` values [#71](https://github.com/logstash-plugins/logstash-input-gelf/pull/71)

Expand Down
5 changes: 4 additions & 1 deletion lib/logstash/inputs/gelf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,10 @@ def remap_gelf(event)
def strip_leading_underscore(event)
# Map all '_foo' fields to simply 'foo'
event.to_hash.keys.each do |key|
move_field(event, key, key.slice(1..-1)) if key.start_with?('_')
next unless key.start_with?('_')
destination_field = key.slice(1..-1)
next if %w[version host short_message full_message timestamp level facility line file].include? destination_field # GELF inner fields
move_field(event, key, key.slice(1..-1))
end
end

Expand Down
34 changes: 34 additions & 0 deletions spec/inputs/gelf_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -238,4 +238,38 @@ def client_bootstrap(gelfclient, queue)
end
end
end

describe "when handling complex messages" do
let(:host) { "127.0.0.1" }
let(:port) { 12211 }
let(:chunksize) { 1420 }
let(:gelfclient) { GELF::Notifier.new(host, port, chunksize) }

let(:config) { { "port" => port, "host" => host } }
let(:queue) { Queue.new }

subject(:gelf_input) { described_class.new(config) }

before(:each) do
subject.register
@runner = Thread.new { subject.run(queue) }

client_bootstrap(gelfclient, queue)
end

after(:each) do
subject.do_stop
@runner.kill
@runner.join
end

it "should not overwrite inner gelf fields" do
message = "level field conflicting with internal GELF level field"
gelfclient.notify!("short_message" => message, "_level" => "foo")
e = queue.pop
expect(e.get("message")).to eq(message)
expect(e.get("level")).to eq(1) # default
expect(e.get("_level")).to eq("foo")
end
end
end