From 1e9beff866ad0075ecabfaee32495582e74adcbe Mon Sep 17 00:00:00 2001 From: RavensClaw Date: Tue, 12 Dec 2017 15:32:52 +0530 Subject: [PATCH 1/9] Added support for adding multiple tag items. Currently the code will override the tag with the tag in the conf file. So this change will add tag to existing tag as an array --- lib/logstash/codecs/fluent.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/logstash/codecs/fluent.rb b/lib/logstash/codecs/fluent.rb index 92175f3..dfaaf8d 100644 --- a/lib/logstash/codecs/fluent.rb +++ b/lib/logstash/codecs/fluent.rb @@ -72,7 +72,7 @@ def decode_event(data, &block) map = entry[1] event = LogStash::Event.new(map.merge( LogStash::Event::TIMESTAMP => LogStash::Timestamp.at(epochtime), - "tags" => [ tag ] + "tags" => map.has_key?("tags") ? map["tags"] + [ tag ] : [ tag ] )) yield event end @@ -83,7 +83,7 @@ def decode_event(data, &block) map = entry[1] event = LogStash::Event.new(map.merge( LogStash::Event::TIMESTAMP => LogStash::Timestamp.at(epochtime), - "tags" => [ tag ] + "tags" => map.has_key?("tags") ? map["tags"] + [ tag ] : [ tag ] )) yield event end @@ -93,7 +93,7 @@ def decode_event(data, &block) map = data[2] event = LogStash::Event.new(map.merge( LogStash::Event::TIMESTAMP => LogStash::Timestamp.at(epochtime), - "tags" => [ tag ] + "tags" => map.has_key?("tags") ? map["tags"] + [ tag ] : [ tag ] )) yield event else From 08d3feae8996c18150283b7b00b9461f8e9c0bff Mon Sep 17 00:00:00 2001 From: RavensClaw Date: Wed, 3 Jan 2018 17:28:49 +0530 Subject: [PATCH 2/9] Update fluent_spec.rb --- spec/codecs/fluent_spec.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/spec/codecs/fluent_spec.rb b/spec/codecs/fluent_spec.rb index c85cd1f..aae635b 100644 --- a/spec/codecs/fluent_spec.rb +++ b/spec/codecs/fluent_spec.rb @@ -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 @@ -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 From 485c6e746c125e474c1a0849b04043414c1df29e Mon Sep 17 00:00:00 2001 From: RavensClaw Date: Wed, 3 Jan 2018 18:59:53 +0530 Subject: [PATCH 3/9] Update fluent_spec.rb --- spec/codecs/fluent_spec.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/spec/codecs/fluent_spec.rb b/spec/codecs/fluent_spec.rb index aae635b..4e1f4ce 100644 --- a/spec/codecs/fluent_spec.rb +++ b/spec/codecs/fluent_spec.rb @@ -28,7 +28,7 @@ describe "event decoding" do - let(:tag) { "mytag" } + let(:tag) { "mytag","anothertag" } let(:epochtime) { event.timestamp.to_i } let(:data) { LogStash::Util.normalize(event.to_hash) } let(:message) do @@ -38,7 +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") + expect(event.get("tags")).to eq(event.get("tag")) end end @@ -64,7 +64,7 @@ subject.decode(message) do |event| expect(event.get("name")).to eq("foo") - expect(event.get("tags")).to eq("tag") + expect(event.get("tags")).to eq(event.get("tag")) count += 1 end From 72b0ea871ece873d40cf523f9509112299354563 Mon Sep 17 00:00:00 2001 From: RavensClaw Date: Wed, 3 Jan 2018 19:00:43 +0530 Subject: [PATCH 4/9] Update fluent_spec.rb --- spec/codecs/fluent_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/codecs/fluent_spec.rb b/spec/codecs/fluent_spec.rb index 4e1f4ce..5c585e1 100644 --- a/spec/codecs/fluent_spec.rb +++ b/spec/codecs/fluent_spec.rb @@ -75,7 +75,7 @@ describe "event decoding (broken package)" do - let(:tag) { "mytag" } + let(:tag) { "mytag","anothertag" } let(:epochtime) { event.timestamp.to_s } let(:data) { LogStash::Util.normalize(event.to_hash) } let(:message) do From c24d1d3edb166e68e548f310f4755c82d43e9510 Mon Sep 17 00:00:00 2001 From: RavensClaw Date: Wed, 3 Jan 2018 19:07:22 +0530 Subject: [PATCH 5/9] Update fluent_spec.rb --- spec/codecs/fluent_spec.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/spec/codecs/fluent_spec.rb b/spec/codecs/fluent_spec.rb index 5c585e1..cc0e6e8 100644 --- a/spec/codecs/fluent_spec.rb +++ b/spec/codecs/fluent_spec.rb @@ -28,7 +28,7 @@ describe "event decoding" do - let(:tag) { "mytag","anothertag" } + let(:tag) { ["mytag","anothertag"] } let(:epochtime) { event.timestamp.to_i } let(:data) { LogStash::Util.normalize(event.to_hash) } let(:message) do @@ -46,7 +46,7 @@ describe "event decoding (buckets of events)" do - let(:tag) { "mytag" } + let(:tag) { ["mytag","anothertag"] } let(:epochtime) { event.timestamp.to_i } let(:data) { LogStash::Util.normalize(event.to_hash) } let(:message) do @@ -75,7 +75,7 @@ describe "event decoding (broken package)" do - let(:tag) { "mytag","anothertag" } + let(:tag) { ["mytag","anothertag"] } let(:epochtime) { event.timestamp.to_s } let(:data) { LogStash::Util.normalize(event.to_hash) } let(:message) do From 9c63df5444c5d74e040e41ebf7428f1880f208ca Mon Sep 17 00:00:00 2001 From: RavensClaw Date: Wed, 3 Jan 2018 19:21:14 +0530 Subject: [PATCH 6/9] Update fluent_spec.rb --- spec/codecs/fluent_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/codecs/fluent_spec.rb b/spec/codecs/fluent_spec.rb index cc0e6e8..bab1d9a 100644 --- a/spec/codecs/fluent_spec.rb +++ b/spec/codecs/fluent_spec.rb @@ -38,7 +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(event.get("tag")) + expect(event.get("tags")).to match_array(event.get("tag")) end end @@ -64,7 +64,7 @@ subject.decode(message) do |event| expect(event.get("name")).to eq("foo") - expect(event.get("tags")).to eq(event.get("tag")) + expect(event.get("tags")).to match_array(event.get("tag")) count += 1 end From 9de8b8192466daecf1b9e857eed986d0573834d5 Mon Sep 17 00:00:00 2001 From: RavensClaw Date: Wed, 3 Jan 2018 19:31:45 +0530 Subject: [PATCH 7/9] Update fluent_spec.rb --- spec/codecs/fluent_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/codecs/fluent_spec.rb b/spec/codecs/fluent_spec.rb index bab1d9a..6b60f19 100644 --- a/spec/codecs/fluent_spec.rb +++ b/spec/codecs/fluent_spec.rb @@ -38,7 +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 match_array(event.get("tag")) + expect(event.get("tags")).to match_array(["mytag","anothertag"]) end end @@ -64,7 +64,7 @@ subject.decode(message) do |event| expect(event.get("name")).to eq("foo") - expect(event.get("tags")).to match_array(event.get("tag")) + expect(event.get("tags")).to match_array(["mytag","anothertag"]) count += 1 end From c48410ced0d48444be45c4c8e53e12fafbad6512 Mon Sep 17 00:00:00 2001 From: RavensClaw Date: Wed, 3 Jan 2018 19:47:59 +0530 Subject: [PATCH 8/9] Update fluent_spec.rb From f3f117dd4f10dcd966e417bb29c36003989384d2 Mon Sep 17 00:00:00 2001 From: RavensClaw Date: Wed, 3 Jan 2018 21:51:11 +0530 Subject: [PATCH 9/9] Update fluent_spec.rb --- spec/codecs/fluent_spec.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/spec/codecs/fluent_spec.rb b/spec/codecs/fluent_spec.rb index 6b60f19..49d5b83 100644 --- a/spec/codecs/fluent_spec.rb +++ b/spec/codecs/fluent_spec.rb @@ -28,7 +28,7 @@ describe "event decoding" do - let(:tag) { ["mytag","anothertag"] } + let(:tag) { "mytag" } let(:epochtime) { event.timestamp.to_i } let(:data) { LogStash::Util.normalize(event.to_hash) } let(:message) do @@ -38,7 +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 match_array(["mytag","anothertag"]) + expect(event.get("tags")).to eq("mytag") end end @@ -46,7 +46,7 @@ describe "event decoding (buckets of events)" do - let(:tag) { ["mytag","anothertag"] } + let(:tag) { "mytag" } let(:epochtime) { event.timestamp.to_i } let(:data) { LogStash::Util.normalize(event.to_hash) } let(:message) do @@ -64,7 +64,7 @@ subject.decode(message) do |event| expect(event.get("name")).to eq("foo") - expect(event.get("tags")).to match_array(["mytag","anothertag"]) + expect(event.get("tags")).to eq("mytag") count += 1 end @@ -75,7 +75,7 @@ describe "event decoding (broken package)" do - let(:tag) { ["mytag","anothertag"] } + let(:tag) { "mytag" } let(:epochtime) { event.timestamp.to_s } let(:data) { LogStash::Util.normalize(event.to_hash) } let(:message) do