logstash-codec-protobuf 1.2.8-jruby → 1.2.9-jruby

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4282811dfc02dd7f91bf6c7c5f1e959e238bb26adb561ae53032279437af0f8e
4
- data.tar.gz: c6941995f4e7be2e4704dc672b38b200cec6cb63d13c8cc94b2ce142f965e1a7
3
+ metadata.gz: a2ec4c6cbd85449002193bfca0cdb35072fd24cf8c8986f8fea39300ca318e34
4
+ data.tar.gz: 2b9b98884f6b0534a50d4d917e86983c5aabf471da660e59c6f4e10ea3f5b030
5
5
  SHA512:
6
- metadata.gz: a1e2fe6f267983100d21eb6933835a039271c0df5fe2a27ac64324b770f9c38b8f8778c435552df20447887b3be84fc560d94139fecf5aee8054284c98debbcd
7
- data.tar.gz: 2627426ef1cd58df02d673d7070fcc599f18d19a43982a3932bed2c54f4f4d46c3a587950d37e8c8ef6d8f6be61614d3fb01eea11b3e54bc3baf424b59da1b77
6
+ metadata.gz: 2e56c03f7d5ef66c3583099ad2a23fe3cfeb2c61bab35af05eb9d8a48eaf845d2587bec39d9fbd90436b79e15d60df4b5d0495d0690eea37d651d6098e8943fb
7
+ data.tar.gz: 0e91ef1eca2eb5ce88a0f3fbef75824251bb121cc0f4396decc6e3def7a6877ea4bb8f48858a5ef58398117ec61c96797153d262e01d7d111285ea2ae0cef1aa
data/CHANGELOG.md CHANGED
@@ -1,3 +1,6 @@
1
+ ## 1.2.9
2
+ - Fix decoding of structs
3
+
1
4
  ## 1.2.8
2
5
  - Update protobuf library to 3.22.2
3
6
 
@@ -2,6 +2,7 @@
2
2
  require 'logstash/codecs/base'
3
3
  require 'logstash/util/charset'
4
4
  require 'google/protobuf' # for protobuf3
5
+ require 'google/protobuf/struct_pb'
5
6
  require 'protocol_buffers' # https://github.com/codekitchen/ruby-protocol-buffers, for protobuf2
6
7
 
7
8
  # Monkey-patch the `Google::Protobuf::DescriptorPool` with a mutex for exclusive
@@ -226,11 +227,14 @@ class LogStash::Codecs::Protobuf < LogStash::Codecs::Base
226
227
  end
227
228
  yield e if block_given?
228
229
  rescue => ex
229
- @logger.warn("Couldn't decode protobuf: #{ex.inspect}.")
230
+ @logger.warn("Couldn't decode protobuf: #{ex.inspect}")
230
231
  if stop_on_error
231
232
  raise ex
232
233
  else # keep original message so that the user can debug it.
233
- yield LogStash::Event.new("message" => data, "tags" => ["_protobufdecodefailure"])
234
+ yield LogStash::Event.new(
235
+ "message" => data, "tags" => ["_protobufdecodefailure"],
236
+ "decoder_exception" => "#{ex.inspect}"
237
+ )
234
238
  end
235
239
  end # def decode
236
240
 
@@ -250,9 +254,17 @@ class LogStash::Codecs::Protobuf < LogStash::Codecs::Base
250
254
  private
251
255
  def pb3_deep_to_hash(input)
252
256
  case input
257
+ when Google::Protobuf::Struct
258
+ result = JSON.parse input.to_json({
259
+ :preserve_proto_fieldnames => true,
260
+ :emit_defaults => true
261
+ })
253
262
  when Google::Protobuf::MessageExts # it's a protobuf class
254
263
  result = Hash.new
264
+ # when we've called to_h here it is already a nested hash, for the
265
+ # structs we bubble down the original value instead.
255
266
  input.to_h.each {|key, value|
267
+ value = input[key] if input[key].is_a? Google::Protobuf::Struct
256
268
  result[key] = pb3_deep_to_hash(value) # the key is required for the class lookup of enums.
257
269
  }
258
270
  when ::Array
@@ -1,7 +1,7 @@
1
1
  Gem::Specification.new do |s|
2
2
 
3
3
  s.name = 'logstash-codec-protobuf'
4
- s.version = '1.2.8'
4
+ s.version = '1.2.9'
5
5
  s.licenses = ['Apache License (2.0)']
6
6
  s.summary = "Reads protobuf messages and converts to Logstash Events"
7
7
  s.description = "This gem is a logstash plugin required to be installed on top of the Logstash core pipeline using $LS_HOME/bin/plugin install gemname. This gem is not a stand-alone program"
@@ -76,7 +76,7 @@ describe LogStash::Codecs::Protobuf do
76
76
  context "#pb3decoder_test1" do
77
77
 
78
78
 
79
- #### Test case 1: Decode simple protobuf ####################################################################################################################
79
+ #### Test case 1: Decode simple protobuf ##############################################
80
80
  let(:plugin_unicorn) { LogStash::Codecs::Protobuf.new(
81
81
  "class_name" => "Unicorn", "include_path" => [pb_include_path + '/pb3/unicorn_pb.rb'], "protobuf_version" => 3)
82
82
  }
@@ -84,8 +84,8 @@ describe LogStash::Codecs::Protobuf do
84
84
  it "should return an event from protobuf data" do
85
85
 
86
86
  unicorn_class = Google::Protobuf::DescriptorPool.generated_pool.lookup("Unicorn").msgclass
87
- data = {:name => 'Pinkie', :age => 18, :is_pegasus => false, :favourite_numbers => [4711,23], :fur_colour => Colour::PINK,
88
- :favourite_colours => [Colour::GREEN, Colour::BLUE]
87
+ data = {:name => 'Pinkie', :age => 18, :is_pegasus => false, :favourite_numbers => [4711,23],
88
+ :fur_colour => Colour::PINK, :favourite_colours => [Colour::GREEN, Colour::BLUE]
89
89
  }
90
90
 
91
91
  unicorn_object = unicorn_class.new(data)
@@ -103,8 +103,9 @@ describe LogStash::Codecs::Protobuf do
103
103
 
104
104
  context "#pb3decoder_test2" do
105
105
 
106
- #### Test case 2: decode nested protobuf ####################################################################################################################
107
- let(:plugin_unicorn) { LogStash::Codecs::Protobuf.new("class_name" => "Unicorn", "include_path" => [pb_include_path + '/pb3/unicorn_pb.rb'], "protobuf_version" => 3) }
106
+ #### Test case 2: decode nested protobuf ##############################################
107
+ let(:plugin_unicorn) { LogStash::Codecs::Protobuf.new("class_name" => "Unicorn",
108
+ "include_path" => [pb_include_path + '/pb3/unicorn_pb.rb'], "protobuf_version" => 3) }
108
109
 
109
110
  it "should return an event from protobuf data with nested classes" do
110
111
  father = unicorn_class.new({:name=> "Sparkle", :age => 50, :fur_colour => 3 })
@@ -126,8 +127,9 @@ describe LogStash::Codecs::Protobuf do
126
127
 
127
128
  context "#pb3decoder_test3" do
128
129
 
129
- #### Test case 3: decode ProbeResult ####################################################################################################################
130
- let(:plugin_3) { LogStash::Codecs::Protobuf.new("class_name" => "ProbeResult", "include_path" => [pb_include_path + '/pb3/ProbeResult_pb.rb'], "protobuf_version" => 3) }
130
+ #### Test case 3: decode ProbeResult ##############################################
131
+ let(:plugin_3) { LogStash::Codecs::Protobuf.new("class_name" => "ProbeResult",
132
+ "include_path" => [pb_include_path + '/pb3/ProbeResult_pb.rb'], "protobuf_version" => 3) }
131
133
 
132
134
  before do
133
135
  plugin_3.register
@@ -158,8 +160,9 @@ describe LogStash::Codecs::Protobuf do
158
160
 
159
161
  context "#pb3decoder_test4" do
160
162
 
161
- #### Test case 4: decode PBDNSMessage ####################################################################################################################
162
- let(:plugin_4) { LogStash::Codecs::Protobuf.new("class_name" => "PBDNSMessage", "include_path" => [pb_include_path + '/pb3/dnsmessage_pb.rb'], "protobuf_version" => 3) }
163
+ #### Test case 4: decode PBDNSMessage ##############################################
164
+ let(:plugin_4) { LogStash::Codecs::Protobuf.new("class_name" => "PBDNSMessage",
165
+ "include_path" => [pb_include_path + '/pb3/dnsmessage_pb.rb'], "protobuf_version" => 3) }
163
166
 
164
167
  before do
165
168
  plugin_4.register
@@ -167,7 +170,6 @@ describe LogStash::Codecs::Protobuf do
167
170
 
168
171
  it "should return an event from protobuf data with nested classes" do
169
172
 
170
-
171
173
  pbdns_message_class = Google::Protobuf::DescriptorPool.generated_pool.lookup("PBDNSMessage").msgclass
172
174
  dns_question_class = Google::Protobuf::DescriptorPool.generated_pool.lookup("PBDNSMessage.DNSQuestion").msgclass
173
175
  dns_response_class = Google::Protobuf::DescriptorPool.generated_pool.lookup("PBDNSMessage.DNSResponse").msgclass
@@ -239,7 +241,7 @@ describe LogStash::Codecs::Protobuf do
239
241
 
240
242
  context "#pb3decoder_test5" do
241
243
 
242
- #### Test case 5: decode test case for github issue 17 ####################################################################################################################
244
+ #### Test case 5: decode test case for github issue 17 ##############################################
243
245
  let(:plugin_5) { LogStash::Codecs::Protobuf.new("class_name" => "com.foo.bar.IntegerTestMessage", "include_path" => [pb_include_path + '/pb3/integertest_pb.rb'], "protobuf_version" => 3) }
244
246
 
245
247
  before do
@@ -308,7 +310,7 @@ describe LogStash::Codecs::Protobuf do
308
310
 
309
311
  context "#pb3decoder_test7" do
310
312
 
311
- #### Test case 6: decode test case for github issue 17 ####################################################################################################################
313
+ #### Test case 6: decode test case for github issue 17 ##############################################
312
314
  let(:plugin_7) { LogStash::Codecs::Protobuf.new("class_name" => "RepeatedEvents", "include_path" => [pb_include_path + '/pb3/events_pb.rb'], "protobuf_version" => 3) }
313
315
  before do
314
316
  plugin_7.register
@@ -338,7 +340,7 @@ describe LogStash::Codecs::Protobuf do
338
340
 
339
341
  context "#pb3decoder_test8a" do
340
342
 
341
- ########################################################################################################################
343
+ ##################################################
342
344
  let(:plugin_8a) { LogStash::Codecs::Protobuf.new("class_name" => "FantasyHorse", "class_file" => 'pb3/FantasyHorse_pb.rb',
343
345
  "protobuf_root_directory" => pb_include_path, "protobuf_version" => 3, "pb3_set_oneof_metainfo" => true) }
344
346
  before do
@@ -376,7 +378,7 @@ describe LogStash::Codecs::Protobuf do
376
378
 
377
379
  context "#pb3decoder_test8b" do
378
380
 
379
- ########################################################################################################################
381
+ ##################################################
380
382
  let(:plugin_8b) { LogStash::Codecs::Protobuf.new("class_name" => "FantasyHorse", "class_file" => 'pb3/FantasyHorse_pb.rb',
381
383
  "protobuf_root_directory" => pb_include_path, "protobuf_version" => 3, "pb3_set_oneof_metainfo" => false) }
382
384
  before do
@@ -410,7 +412,7 @@ describe LogStash::Codecs::Protobuf do
410
412
 
411
413
  context "#pb3decoder_test8c" do # same test as 8a just with different one_of options selected
412
414
 
413
- ########################################################################################################################
415
+ ##################################################
414
416
  let(:plugin_8c) { LogStash::Codecs::Protobuf.new("class_name" => "FantasyHorse", "class_file" => 'pb3/FantasyHorse_pb.rb',
415
417
  "protobuf_root_directory" => pb_include_path, "protobuf_version" => 3, "pb3_set_oneof_metainfo" => true) }
416
418
  before do
@@ -442,4 +444,33 @@ describe LogStash::Codecs::Protobuf do
442
444
 
443
445
  end # context pb3decoder_test8c
444
446
 
447
+ context "#pb3decoder_test9" do
448
+
449
+ ##################################################
450
+ let(:plugin_9) { LogStash::Codecs::Protobuf.new("class_name" => "messages.SendJsonRequest", "class_file" => 'pb3/struct_test_pb.rb',
451
+ "protobuf_root_directory" => pb_include_path, "protobuf_version" => 3, "pb3_set_oneof_metainfo" => false) }
452
+ # TODO: pb3_set_oneof_metainfo => true is broken when running with a struct field
453
+ before do
454
+ plugin_9.register
455
+ end
456
+
457
+ require pb_include_path + '/pb3/struct_test_pb.rb'
458
+
459
+ it "should decode a message with an embedded struct" do
460
+ # nested struct field
461
+ details = Google::Protobuf::Struct.new(
462
+ fields: {"field_a" => {:string_value => "value_a"}},
463
+ )
464
+ data = {:UserID=>"123-456", :Details => details}
465
+ pb_obj = Messages::SendJsonRequest.new(data)
466
+ bin = Messages::SendJsonRequest.encode(pb_obj)
467
+
468
+ plugin_9.decode(bin) do |event|
469
+ expect(event.get("UserID") ).to eq(data[:UserID])
470
+ expect(event.get("Details") ).to eq({"field_a"=>"value_a"})
471
+ end
472
+
473
+ end # it
474
+ end # context pb3decoder_test9
475
+
445
476
  end # describe
@@ -0,0 +1,21 @@
1
+ # Generated by the protocol buffer compiler. DO NOT EDIT!
2
+
3
+ begin; require 'google/protobuf'; rescue LoadError; end
4
+
5
+ begin; require 'google/protobuf/struct_pb'; rescue LoadError; end
6
+ Google::Protobuf::DescriptorPool.generated_pool.build do
7
+ add_file("RequestStruct.proto", :syntax => :proto3) do
8
+ add_message "messages.SendJsonRequest" do
9
+ optional :UserID, :string, 1
10
+ optional :Details, :message, 2, "google.protobuf.Struct"
11
+ end
12
+ add_message "messages.SendJsonResponse" do
13
+ optional :Response, :string, 1
14
+ end
15
+ end
16
+ end
17
+
18
+ module Messages
19
+ SendJsonRequest = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("messages.SendJsonRequest").msgclass
20
+ SendJsonResponse = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("messages.SendJsonResponse").msgclass
21
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logstash-codec-protobuf
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.8
4
+ version: 1.2.9
5
5
  platform: jruby
6
6
  authors:
7
7
  - Inga Feick
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-03-28 00:00:00.000000000 Z
11
+ date: 2023-04-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  requirement: !ruby/object:Gem::Requirement
@@ -118,6 +118,7 @@ files:
118
118
  - spec/helpers/pb3/rum2_pb.rb
119
119
  - spec/helpers/pb3/rum3_pb.rb
120
120
  - spec/helpers/pb3/rum_pb.rb
121
+ - spec/helpers/pb3/struct_test_pb.rb
121
122
  - spec/helpers/pb3/unicorn.proto3
122
123
  - spec/helpers/pb3/unicorn_pb.rb
123
124
  homepage:
@@ -141,7 +142,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
141
142
  - !ruby/object:Gem::Version
142
143
  version: '0'
143
144
  requirements: []
144
- rubygems_version: 3.2.29
145
+ rubygems_version: 3.4.11
145
146
  signing_key:
146
147
  specification_version: 4
147
148
  summary: Reads protobuf messages and converts to Logstash Events
@@ -173,5 +174,6 @@ test_files:
173
174
  - spec/helpers/pb3/rum2_pb.rb
174
175
  - spec/helpers/pb3/rum3_pb.rb
175
176
  - spec/helpers/pb3/rum_pb.rb
177
+ - spec/helpers/pb3/struct_test_pb.rb
176
178
  - spec/helpers/pb3/unicorn.proto3
177
179
  - spec/helpers/pb3/unicorn_pb.rb