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

Changes to embed tags in decode_event function. #14

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
28 changes: 16 additions & 12 deletions lib/logstash/codecs/fluent.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ def encode(event)

private

def merge_values(source, target)
source.merge!(target){|key, old_val, new_val| [new_val, old_val]}
end

def decode_event(data, &block)
tag = data[0]
entries = data[1]
Expand All @@ -70,31 +74,31 @@ def decode_event(data, &block)
entries_decoder.feed_each(entries) do |entry|
epochtime = entry[0]
map = entry[1]
event = LogStash::Event.new(map.merge(
LogStash::Event::TIMESTAMP => LogStash::Timestamp.at(epochtime),
"tags" => [ tag ]
))
event = LogStash::Event.new(merge_values(map, {
LogStash::Event::TIMESTAMP => LogStash::Timestamp.at(epochtime),
"tags" => tag
}))
yield event
end
when Array
# Forward
entries.each do |entry|
epochtime = entry[0]
map = entry[1]
event = LogStash::Event.new(map.merge(
LogStash::Event::TIMESTAMP => LogStash::Timestamp.at(epochtime),
"tags" => [ tag ]
))
event = LogStash::Event.new(merge_values(map, {
LogStash::Event::TIMESTAMP => LogStash::Timestamp.at(epochtime),
"tags" => tag
}))
yield event
end
when Fixnum
# Message
epochtime = entries
map = data[2]
event = LogStash::Event.new(map.merge(
LogStash::Event::TIMESTAMP => LogStash::Timestamp.at(epochtime),
"tags" => [ tag ]
))
event = LogStash::Event.new(merge_values(map, {
LogStash::Event::TIMESTAMP => LogStash::Timestamp.at(epochtime),
"tags" => tag
}))
yield event
else
raise(LogStash::Error, "Unknown event type")
Expand Down
2 changes: 2 additions & 0 deletions spec/codecs/fluent_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
it "should decode without errors" do
subject.decode(message) do |event|
expect(event.get("name")).to eq("foo")
expect(event.get("tags")).to eq(tag)
end
end

Expand All @@ -63,6 +64,7 @@

subject.decode(message) do |event|
expect(event.get("name")).to eq("foo")
expect(event.get("tags")).to eq(tag)
count += 1
end

Expand Down