logstash-codec-protobuf 0.1.0 → 0.1.1

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
  SHA1:
3
- metadata.gz: ae5fff64bbdc72cfc6f1dbbeecd0857481bd1a93
4
- data.tar.gz: 5ff0987575c066dd83443a3a4fe1eefc9149f9ea
3
+ metadata.gz: 92231ace59a2a8218764c99dab51abb5636db440
4
+ data.tar.gz: d8129bf3a5bf757f42bb3c2e95ae8d74455531b2
5
5
  SHA512:
6
- metadata.gz: 8875e1c022bc8a7155469838c312a0076a296c99d506bb37f18cbe4ea77b080e034b46a76ec6e0084f07f60e5aad88feafe3157b72408c3213746d1a39dac79c
7
- data.tar.gz: e3eb525c75ed899a003767855ed03201dcab2338f1fd33d8a6328045be4b8dad776acd422375155ddc7455ef6a3ab8cb710bc3211b1c483def8126bb25545040
6
+ metadata.gz: 6a7379eeb8a33c4dd722a01e55bd67f5daeb37ba7ad323ebd41707b359f27a585ca5dcaaf720ecb74d6746c50230fda17249ef849ff3f01489714dbd9c286769
7
+ data.tar.gz: d2175a9b628f60128295e9e4871d895ba8cb65d33202af0a3c66ac63c0aa4540a173b3b7c508f28de8db3d950f4b72604e308d5138530a79393144244c5188a1
data/CHANGELOG.md CHANGED
@@ -1,4 +0,0 @@
1
- * 1.1.0
2
- - Handle scalar types (string/number) and be more defensive about crashable errors
3
- * 1.0.1
4
- - Handle JSON arrays at source root by emitting multiple events
data/CONTRIBUTORS CHANGED
@@ -2,14 +2,9 @@ The following is a list of people who have contributed ideas, code, bug
2
2
  reports, or in general have helped logstash along its way.
3
3
 
4
4
  Contributors:
5
- * Colin Surprenant (colinsurprenant)
6
- * Jordan Sissel (jordansissel)
7
- * João Duarte (jsvd)
8
- * Kurt Hurtado (kurtado)
9
- * Nick Ethier (nickethier)
10
- * Pier-Hugues Pellerin (ph)
11
- * Richard Pijnenburg (electrical)
12
- * Tal Levy (talevy)
5
+ * Inga Feick (ingafeick)
6
+ * Nicolai Schulten (krakenfuss)
7
+
13
8
 
14
9
  Note: If you've sent us patches, bug reports, or otherwise contributed to
15
10
  Logstash, and you aren't on the list above and want to be, please let us know
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2012–2015 Elasticsearch <http://www.elastic.co>
1
+ Copyright (c) 2012–2015 Trivago (http://www.trivago.com/)
2
2
 
3
3
  Licensed under the Apache License, Version 2.0 (the "License");
4
4
  you may not use this file except in compliance with the License.
data/NOTICE.TXT CHANGED
@@ -1,5 +1,4 @@
1
- Elasticsearch
2
- Copyright 2012-2015 Elasticsearch
1
+ Copyright Trivago http://www.trivago.com/
3
2
 
4
3
  This product includes software developed by The Apache Software
5
4
  Foundation (http://www.apache.org/).
data/README.md CHANGED
@@ -2,15 +2,15 @@
2
2
 
3
3
  This is a codec plugin for [Logstash](https://github.com/elastic/logstash) to parse protobuf messages.
4
4
 
5
- # Prerequisites
5
+ # Prerequisites and Installation
6
6
 
7
7
  * prepare your ruby versions of the protobuf definitions, for example using the ruby-protoc compiler from https://github.com/codekitchen/ruby-protocol-buffers
8
- * download the logstash-codec-protobuf-$VERSION.gem to your computer.
8
+ * download the [gem file](https://rubygems.org/gems/logstash-codec-protobuf) to your computer.
9
9
  * Install the plugin. From within your logstash directory, do
10
10
  bin/plugin install /path/to/logstash-codec-protobuf-$VERSION.gem
11
11
  * use the codec in your logstash config file. See details below.
12
12
 
13
- # Usage
13
+ ## Usage
14
14
 
15
15
  Use this as a codec in any logstash input. Just provide the name of the class that your incoming objects will be encoded in, and specify the path to the compiled definition.
16
16
  Here's an example for a kafka input:
@@ -46,20 +46,20 @@ Set the class name to the parent class:
46
46
 
47
47
  class_name => "Foods::Dairy::Cheese"
48
48
 
49
- # Configuration
49
+ ## Configuration
50
50
 
51
51
  include_path (required): an array of strings with filenames or directory names where logstash can find your protobuf definitions. Please provide absolute paths. For directories it will only try to import files ending on .rb
52
52
 
53
53
  class_name (required): the name of the protobuf class that is to be decoded.
54
54
 
55
55
 
56
- # Troubleshooting
56
+ ## Troubleshooting
57
57
 
58
- ## "uninitialized constant SOME_CLASS_NAME"
58
+ ### "uninitialized constant SOME_CLASS_NAME"
59
59
 
60
60
  If you include more than one definition class, consider the order of inclusion. This is especially relevant if you include whole directories. A definition might refer to another definition that is not loaded yet. In this case, please specify the files in the include_path variable in reverse order of reference. See 'Example with referenced definitions' above.
61
61
 
62
62
 
63
- # Roapmap
63
+ # #Roadmap
64
64
 
65
65
  Currently the plugin supports the decode functionality only. Maybe we'll add the encoding part also.
@@ -1,10 +1,10 @@
1
1
  # encoding: utf-8
2
- require "logstash/codecs/base"
3
- require "logstash/util/charset"
2
+ require 'logstash/codecs/base'
3
+ require 'logstash/util/charset'
4
4
  require 'protocol_buffers' # https://github.com/codekitchen/ruby-protocol-buffers
5
5
 
6
6
  class LogStash::Codecs::Protobuf < LogStash::Codecs::Base
7
- config_name "protobuf"
7
+ config_name 'protobuf'
8
8
 
9
9
  # Required: list of strings containing directories or files with protobuf definitions
10
10
  config :include_path, :validate => :array, :required => true
@@ -12,100 +12,72 @@ class LogStash::Codecs::Protobuf < LogStash::Codecs::Base
12
12
  # Name of the class to decode
13
13
  config :class_name, :validate => :string, :required => true
14
14
 
15
- # remove 'set_fields' field
16
- config :remove_set_fields, :validate => :boolean, :default => true # TODO add documentation
17
-
18
15
 
19
- public
20
16
  def register
21
- @include_path.each{|path| require_pb_path(path) }
22
- @obj = create_object_from_name(@class_name)
23
-
17
+ include_path.each { |path| require_pb_path(path) }
18
+ @obj = create_object_from_name(class_name)
19
+ @logger.debug("Protobuf files successfully loaded.")
24
20
  end
25
21
 
22
+ def decode(data)
23
+ decoded = @obj.parse(data.to_s)
24
+ results = extract_vars(decoded)
25
+ yield LogStash::Event.new(results) if block_given?
26
+ end # def decode
27
+
28
+ def encode(event)
29
+ raise 'Encodeør function not implemented yet for protobuf codec. Sorry!'
30
+ # @on_event.call(event, event.to_s)
31
+ # TODO integrate
32
+ end # def encode
33
+
34
+
26
35
 
27
36
  private
28
37
  def create_object_from_name(name)
29
38
  begin
30
- c = name.split("::").inject(Object) { |n,c| n.const_get c }
31
- return c
32
- end
39
+ @logger.debug("Creating instance of " + name)
40
+ return name.split('::').inject(Object) { |n,c| n.const_get c }
41
+ end
33
42
  end
34
43
 
35
- private
36
- def debug(message)
37
- begin
38
- if @debug
39
- @logger.debug(message)
40
- end
41
- end
42
- end
43
44
 
44
- private
45
45
  def require_pb_path(dir_or_file)
46
- f = dir_or_file.end_with? (".rb")
46
+ f = dir_or_file.end_with? ('.rb')
47
47
  begin
48
48
  if f
49
+ @logger.debug("Including protobuf file: " + dir_or_file)
49
50
  require dir_or_file
50
51
  else
51
- Dir[ dir_or_file + "/*.rb"].each { |file|
52
+ Dir[ dir_or_file + '/*.rb'].each { |file|
53
+ @logger.debug("Including protobuf path: " + dir_or_file + "/" + file)
52
54
  require file
53
55
  }
54
56
  end
55
57
  end
56
58
  end
57
59
 
58
- private
59
- def extract_variables(decoded_object)
60
- begin
61
- result_hash = {}
62
- if decoded_object.nil?
63
- return result_hash
64
- end
65
- decoded_object.instance_variables.map do |ivar|
66
- varname = ivar.to_s
67
- key = varname.gsub("@","")
68
- value = decoded_object.instance_variable_get("#{ivar}")
69
- recurse = value.is_a? (::ProtocolBuffers::Message) # object is not a primitive scalar
70
- is_iterable |= value.is_a? Enumerable # value.respond_to? :each # object is an array
71
- if recurse
72
- result_hash[key] = extract_variables(value)
73
- elsif is_iterable
74
- tmp = []
75
- value.each do | nested |
76
- tmp.push(nested)
77
- end
78
- result_hash[key] = tmp
60
+
61
+ def extract_vars(decoded_object)
62
+ return {} if decoded_object.nil?
63
+ results = {}
64
+ decoded_object.instance_variables.each do |key|
65
+ formatted_key = key.to_s.gsub('@', '')
66
+ next if (formatted_key == :set_fields || formatted_key == "set_fields")
67
+ instance_var = decoded_object.instance_variable_get(key)
68
+
69
+ results[formatted_key] =
70
+ if instance_var.is_a?(::ProtocolBuffers::Message)
71
+ extract_vars(instance_var)
72
+ elsif instance_var.is_a?(::Hash)
73
+ instance_var.inject([]) { |h, (k, v)| h[k.to_s] = extract_vars(v); h }
74
+ elsif instance_var.is_a?(Enumerable) # is a list
75
+ instance_var.inject([]) { |h, v| h.push(extract_vars(v)); h }
79
76
  else
80
- result_hash[key] = value
77
+ instance_var
81
78
  end
82
- end
83
- if remove_set_fields
84
- return result_hash.except("set_fields") # todo try to do this before the object is handed to this method
85
- else
86
- return result_hash
87
- end
88
- end
79
+ end
80
+ results
89
81
  end
90
82
 
91
-
92
-
93
-
94
-
95
- public
96
- def decode(data)
97
- decoded = @obj.parse(data.to_s)
98
- results = extract_variables(decoded)
99
- event = LogStash::Event.new(results)
100
- yield event
101
-
102
- end # def decode
103
-
104
- public
105
- def encode(event)
106
- raise "Encoder function not implemented yet for protobuf codec. Sorry!"
107
- # @on_event.call(event, event.to_s)
108
- # TODO integrate
109
- end # def encode
110
-
111
83
  end # class LogStash::Codecs::Protobuf
@@ -1,11 +1,12 @@
1
1
  Gem::Specification.new do |s|
2
2
 
3
3
  s.name = 'logstash-codec-protobuf'
4
- s.version = '0.1.0'
4
+ s.version = '0.1.1'
5
5
  s.licenses = ['Apache License (2.0)']
6
6
  s.summary = "This codec may be used to decode (via inputs) and encode (via outputs) protobuf messages"
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"
8
- s.authors = ["trivago"]
8
+ s.authors = ["Inga Feick"]
9
+ s.email = 'inga.feick@trivago.com'
9
10
  s.require_paths = ["lib"]
10
11
 
11
12
  # Files
@@ -17,14 +17,12 @@ describe LogStash::Codecs::Protobuf do
17
17
 
18
18
  data = {:colour => 'rainbow', :horn_length => 18, :last_seen => 1420081471}
19
19
  unicorn = Animal::Unicorn.new(data)
20
-
20
+
21
21
  plugin.decode(unicorn.serialize_to_string) do |event|
22
- insist { event.is_a? LogStash::Event }
23
- insist { event["colour"] } == data[:colour]
24
- insist { event["horn_length"] } == data[:horn_length]
25
- insist { event["last_seen"] } == data[:last_seen]
22
+
23
+ expect(event["colour"] ).to eq(data[:colour] )
24
+ expect(event["horn_length"] ).to eq(data[:horn_length] )
26
25
  end
27
26
  end
28
27
  end
29
-
30
28
  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: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
- - trivago
7
+ - Inga Feick
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-01-05 00:00:00.000000000 Z
11
+ date: 2016-02-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: logstash-core
@@ -59,7 +59,7 @@ dependencies:
59
59
  prerelease: false
60
60
  type: :development
61
61
  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
62
- email:
62
+ email: inga.feick@trivago.com
63
63
  executables: []
64
64
  extensions: []
65
65
  extra_rdoc_files: []