logstash-codec-protobuf 1.0.5 → 1.2.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +20 -1
  3. data/Gemfile +1 -1
  4. data/LICENSE +2 -3
  5. data/README.md +147 -40
  6. data/docs/index.asciidoc +173 -41
  7. data/lib/logstash/codecs/protobuf.rb +598 -238
  8. data/logstash-codec-protobuf.gemspec +3 -3
  9. data/spec/codecs/{protobuf_spec.rb → pb2_spec.rb} +81 -54
  10. data/spec/codecs/pb3_decode_spec.rb +445 -0
  11. data/spec/codecs/pb3_encode_spec.rb +243 -0
  12. data/spec/helpers/pb2/event.pb.rb +19 -0
  13. data/spec/helpers/pb2/event.proto +12 -0
  14. data/spec/helpers/pb2/header/header.pb.rb +16 -0
  15. data/spec/helpers/pb2/header/header.proto +8 -0
  16. data/spec/helpers/pb3/FantasyHorse_pb.rb +44 -0
  17. data/spec/helpers/pb3/ProbeResult_pb.rb +26 -0
  18. data/spec/helpers/pb3/dnsmessage_pb.rb +82 -0
  19. data/spec/helpers/pb3/events.proto3 +10 -0
  20. data/spec/helpers/pb3/events_pb.rb +17 -0
  21. data/spec/helpers/pb3/header/header.proto3 +7 -0
  22. data/spec/helpers/pb3/header/header_pb.rb +12 -0
  23. data/spec/helpers/pb3/integertest_pb.rb +20 -0
  24. data/spec/helpers/pb3/messageA.proto3 +12 -0
  25. data/spec/helpers/pb3/messageA_pb.rb +16 -0
  26. data/spec/helpers/pb3/messageB.proto3 +12 -0
  27. data/spec/helpers/pb3/messageB_pb.rb +16 -0
  28. data/spec/helpers/pb3/rum2_pb.rb +87 -0
  29. data/spec/helpers/pb3/rum3_pb.rb +87 -0
  30. data/spec/helpers/pb3/rum_pb.rb +87 -0
  31. metadata +62 -34
  32. data/lib/net/jpountz/lz4/lz4/1.3.0/lz4-1.3.0.jar +0 -0
  33. data/lib/org/apache/kafka/kafka-clients/0.11.0.0/kafka-clients-0.11.0.0.jar +0 -0
  34. data/lib/org/apache/logging/log4j/log4j-api/2.8.2/log4j-api-2.8.2.jar +0 -0
  35. data/lib/org/apache/logging/log4j/log4j-slf4j-impl/2.8.2/log4j-slf4j-impl-2.8.2.jar +0 -0
  36. data/lib/org/slf4j/slf4j-api/1.7.24/slf4j-api-1.7.24.jar +0 -0
  37. data/lib/org/slf4j/slf4j-api/1.7.25/slf4j-api-1.7.25.jar +0 -0
  38. data/lib/org/xerial/snappy/snappy-java/1.1.2.6/snappy-java-1.1.2.6.jar +0 -0
  39. data/spec/codecs/protobuf3_spec.rb +0 -147
  40. data/vendor/jar-dependencies/runtime-jars/kafka-clients-0.11.0.0.jar +0 -0
  41. data/vendor/jar-dependencies/runtime-jars/log4j-api-2.8.2.jar +0 -0
  42. data/vendor/jar-dependencies/runtime-jars/log4j-slf4j-impl-2.8.2.jar +0 -0
  43. data/vendor/jar-dependencies/runtime-jars/lz4-1.3.0.jar +0 -0
  44. data/vendor/jar-dependencies/runtime-jars/slf4j-api-1.7.24.jar +0 -0
  45. data/vendor/jar-dependencies/runtime-jars/slf4j-api-1.7.25.jar +0 -0
  46. data/vendor/jar-dependencies/runtime-jars/snappy-java-1.1.2.6.jar +0 -0
@@ -1,147 +0,0 @@
1
- # encoding: utf-8
2
- require "logstash/devutils/rspec/spec_helper"
3
- require "logstash/codecs/protobuf"
4
- require "logstash/event"
5
- require "insist"
6
-
7
-
8
- require 'google/protobuf' # for protobuf3
9
-
10
-
11
- describe LogStash::Codecs::Protobuf do
12
-
13
-
14
- context "#decodePB3" do
15
-
16
-
17
- #### Test case 1: Decode simple protobuf ####################################################################################################################
18
- let(:plugin_unicorn) { LogStash::Codecs::Protobuf.new("class_name" => "Unicorn", "include_path" => ['spec/helpers/pb3/unicorn_pb.rb'], "protobuf_version_3" => true) }
19
- before do
20
- plugin_unicorn.register
21
- end
22
-
23
- it "should return an event from protobuf encoded data" do
24
-
25
- unicorn_class = Google::Protobuf::DescriptorPool.generated_pool.lookup("Unicorn").msgclass
26
- data = {:name => 'Pinkie', :age => 18, :is_pegasus => false, :favourite_numbers => [4711,23], :fur_colour => Colour::PINK,
27
- :favourite_colours => [Colour::GREEN, Colour::BLUE]
28
- }
29
-
30
- unicorn_object = unicorn_class.new(data)
31
- bin = unicorn_class.encode(unicorn_object)
32
- plugin_unicorn.decode(bin) do |event|
33
- expect(event.get("name") ).to eq(data[:name] )
34
- expect(event.get("age") ).to eq(data[:age])
35
- expect(event.get("fur_colour") ).to eq("PINK")
36
- expect(event.get("favourite_numbers") ).to eq(data[:favourite_numbers])
37
- expect(event.get("favourite_colours") ).to eq(["GREEN","BLUE"])
38
- expect(event.get("is_pegasus") ).to eq(data[:is_pegasus] )
39
- end
40
- end # it
41
-
42
-
43
-
44
-
45
-
46
- #### Test case 2: decode nested protobuf ####################################################################################################################
47
- let(:plugin_unicorn) { LogStash::Codecs::Protobuf.new("class_name" => "Unicorn", "include_path" => ['spec/helpers/pb3/unicorn_pb.rb'], "protobuf_version_3" => true) }
48
- before do
49
- plugin_unicorn.register
50
- end
51
-
52
- it "should return an event from protobuf encoded data with nested classes" do
53
-
54
-
55
- unicorn_class = Google::Protobuf::DescriptorPool.generated_pool.lookup("Unicorn").msgclass
56
-
57
- father = unicorn_class.new({:name=> "Sparkle", :age => 50, :fur_colour => 3 })
58
- data = {:name => 'Glitter', :fur_colour => Colour::GLITTER, :father => father}
59
-
60
- unicorn_object = unicorn_class.new(data)
61
- bin = unicorn_class.encode(unicorn_object)
62
- plugin_unicorn.decode(bin) do |event|
63
- expect(event.get("name") ).to eq(data[:name] )
64
- expect(event.get("fur_colour") ).to eq("GLITTER" )
65
- expect(event.get("father")["name"] ).to eq(data[:father][:name] )
66
- expect(event.get("father")["age"] ).to eq(data[:father][:age] )
67
- expect(event.get("father")["fur_colour"] ).to eq("SILVER")
68
-
69
- end
70
- end # it
71
-
72
-
73
- end # context #decodePB3
74
-
75
-
76
- context "#encodePB3-a" do
77
-
78
- #### Test case 3: encode simple protobuf ####################################################################################################################
79
-
80
- definitions_file = 'spec/helpers/pb3/unicorn_pb.rb'
81
- require definitions_file
82
-
83
- subject do
84
- next LogStash::Codecs::Protobuf.new("class_name" => "Unicorn", "include_path" => [definitions_file], "protobuf_version_3" => true)
85
- end
86
-
87
- event3 = LogStash::Event.new("name" => "Pinkie", "age" => 18, "is_pegasus" => false, "favourite_numbers" => [1,2,3], "fur_colour" => Colour::PINK, "favourite_colours" => [1,5] )
88
-
89
- it "should return protobuf encoded data for testcase 3" do
90
-
91
- subject.on_event do |event, data|
92
- insist { data.is_a? String }
93
-
94
- pb_builder = Google::Protobuf::DescriptorPool.generated_pool.lookup("Unicorn").msgclass
95
- decoded_data = pb_builder.decode(data)
96
- expect(decoded_data.name ).to eq(event.get("name") )
97
- expect(decoded_data.age ).to eq(event.get("age") )
98
- expect(decoded_data.is_pegasus ).to eq(event.get("is_pegasus") )
99
- expect(decoded_data.fur_colour ).to eq(:PINK)
100
- expect(decoded_data.favourite_numbers ).to eq(event.get("favourite_numbers") )
101
- expect(decoded_data.favourite_colours ).to eq([:BLUE,:WHITE] )
102
- end # subject.on_event
103
- subject.encode(event3)
104
- end # it
105
-
106
- end # context
107
-
108
- context "#encodePB3-b" do
109
-
110
- #### Test case 4: encode nested protobuf ####################################################################################################################
111
-
112
- definitions_file = 'spec/helpers/pb3/unicorn_pb.rb'
113
- require definitions_file
114
-
115
- subject do
116
- next LogStash::Codecs::Protobuf.new("class_name" => "Unicorn", "include_path" => [definitions_file], "protobuf_version_3" => true)
117
- end
118
-
119
- event4 = LogStash::Event.new("name" => "Horst", "age" => 23, "is_pegasus" => true, "mother" => \
120
- {"name" => "Mom", "age" => 47}, "father" => {"name"=> "Daddy", "age"=> 50, "fur_colour" => 3 } # 3 == SILVER
121
- )
122
-
123
- it "should return protobuf encoded data for testcase 4" do
124
-
125
- subject.on_event do |event, data|
126
- insist { data.is_a? String }
127
-
128
- pb_builder = Google::Protobuf::DescriptorPool.generated_pool.lookup("Unicorn").msgclass
129
- decoded_data = pb_builder.decode(data)
130
-
131
- expect(decoded_data.name ).to eq(event.get("name") )
132
- expect(decoded_data.age ).to eq(event.get("age") )
133
- expect(decoded_data.is_pegasus ).to eq(event.get("is_pegasus") )
134
- expect(decoded_data.mother.name ).to eq(event.get("mother")["name"] )
135
- expect(decoded_data.mother.age ).to eq(event.get("mother")["age"] )
136
- expect(decoded_data.father.name ).to eq(event.get("father")["name"] )
137
- expect(decoded_data.father.age ).to eq(event.get("father")["age"] )
138
- expect(decoded_data.father.fur_colour ).to eq(:SILVER)
139
-
140
-
141
- end # subject4.on_event
142
- subject.encode(event4)
143
- end # it
144
-
145
- end # context #encodePB3
146
-
147
- end # describe