-
Notifications
You must be signed in to change notification settings - Fork 11
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
add ECS support and target option #20
Merged
kaisecheng
merged 4 commits into
logstash-plugins:master
from
kaisecheng:add_ecs_support
Jul 26, 2021
Merged
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -2,57 +2,67 @@ | |||||
require "logstash/codecs/es_bulk" | ||||||
require "logstash/event" | ||||||
require "insist" | ||||||
require 'logstash/plugin_mixins/ecs_compatibility_support/spec_helper' | ||||||
|
||||||
describe LogStash::Codecs::ESBulk do | ||||||
subject do | ||||||
next LogStash::Codecs::ESBulk.new | ||||||
end | ||||||
describe LogStash::Codecs::ESBulk, :ecs_compatibility_support do | ||||||
ecs_compatibility_matrix(:disabled, :v1, :v8 => :v1) do |ecs_select| | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we want to test with setting the field to
Suggested change
|
||||||
before(:each) do | ||||||
allow_any_instance_of(described_class).to receive(:ecs_compatibility).and_return(ecs_compatibility) | ||||||
end | ||||||
|
||||||
context "#decode" do | ||||||
it "should return 4 events from json data" do | ||||||
data = <<-HERE | ||||||
subject do | ||||||
next LogStash::Codecs::ESBulk.new | ||||||
end | ||||||
|
||||||
context "#decode" do | ||||||
it "should return 4 events from json data" do | ||||||
data = <<-HERE | ||||||
{ "index" : { "_index" : "test", "_type" : "type1", "_id" : "1" } } | ||||||
{ "field1" : "value1" } | ||||||
{ "delete" : { "_index" : "test", "_type" : "type1", "_id" : "2" } } | ||||||
{ "create" : { "_index" : "test", "_type" : "type1", "_id" : "3" } } | ||||||
{ "field1" : "value3" } | ||||||
{ "update" : {"_id" : "1", "_type" : "type1", "_index" : "index1"} } | ||||||
{ "doc" : {"field2" : "value2"} } | ||||||
HERE | ||||||
|
||||||
count = 0 | ||||||
subject.decode(data) do |event| | ||||||
case count | ||||||
when 0 | ||||||
insist { event.get("[@metadata][_id]") } == "1" | ||||||
insist { event.get("[@metadata][action]") } == "index" | ||||||
insist { event.get("field1") } == "value1" | ||||||
when 1 | ||||||
insist { event.get("[@metadata][_id]") } == "2" | ||||||
insist { event.get("[@metadata][action]") } == "delete" | ||||||
when 2 | ||||||
insist { event.get("[@metadata][_id]") } == "3" | ||||||
insist { event.get("[@metadata][action]") } == "create" | ||||||
insist { event.get("field1") } == "value3" | ||||||
when 3 | ||||||
insist { event.get("[@metadata][_id]") } == "1" | ||||||
insist { event.get("[@metadata][action]") } == "update" | ||||||
insist { event.get("[doc][field2]") } == "value2" | ||||||
HERE | ||||||
|
||||||
metadata_field = ecs_select[disabled: '[@metadata]', v1: '[@metadata][codec][es_bulk]'] | ||||||
|
||||||
count = 0 | ||||||
subject.decode(data) do |event| | ||||||
case count | ||||||
when 0 | ||||||
insist { event.get("#{metadata_field}[_id]") } == "1" | ||||||
insist { event.get("#{metadata_field}[action]") } == "index" | ||||||
insist { event.get("field1") } == "value1" | ||||||
when 1 | ||||||
insist { event.get("#{metadata_field}[_id]") } == "2" | ||||||
insist { event.get("#{metadata_field}[action]") } == "delete" | ||||||
when 2 | ||||||
insist { event.get("#{metadata_field}[_id]") } == "3" | ||||||
insist { event.get("#{metadata_field}[action]") } == "create" | ||||||
insist { event.get("field1") } == "value3" | ||||||
when 3 | ||||||
insist { event.get("#{metadata_field}[_id]") } == "1" | ||||||
insist { event.get("#{metadata_field}[action]") } == "update" | ||||||
insist { event.get("[doc][field2]") } == "value2" | ||||||
end | ||||||
count += 1 | ||||||
end | ||||||
count += 1 | ||||||
insist { count } == 4 | ||||||
end | ||||||
insist { count } == 4 | ||||||
end | ||||||
end | ||||||
|
||||||
context "fail to process non-bulk event then continue" do | ||||||
it "continues after a fail" do | ||||||
decoded = false | ||||||
subject.decode("something that isn't a bulk event\n") do |event| | ||||||
decoded = true | ||||||
context "fail to process non-bulk event then continue" do | ||||||
it "continues after a fail" do | ||||||
decoded = false | ||||||
subject.decode("something that isn't a bulk event\n") do |event| | ||||||
decoded = true | ||||||
end | ||||||
insist { decoded } == false | ||||||
end | ||||||
insist { decoded } == false | ||||||
end | ||||||
|
||||||
end | ||||||
|
||||||
end |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would it make sense to
event.set('[event][original]', bulk.get("message").dup.freeze)
in ECS mode?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are four options here. Considering the following input
Store the whole input as
event.original
.The input generates four events. Each event saves the complete raw data.
It could generate too much extra bandwidth
Store { "field1" : "value1" } as
event.original
.This is the line when target_event_factory is called. Metadata is not included. The information is not complete.
This is the result of
event.set('[event][original]', bulk.get("message").dup.freeze)
The information is not particularly interesting because the same stuff transforms into an event.
tailor-make a new line to concatenate metadata { "index" : { "_index" : "test", "_type" : "type1", "_id" : "1" } } and data { "field1" : "value1" }
This will be a full event that requires concatenating the decoded string
do not store
event.original
I am opened to save it in
event.original
if you think it is usefulThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh right, it's tricky with the multi-line and the managed state ... was undecided on this making sense.
Reading your comments I am leaning towards 4. do not store
event.original
for now and ship as is...