logstash-codec-avro 3.1.0-java → 3.2.0-java

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 800d769a22f692329606bfe7b30fef7b22894038
4
- data.tar.gz: 62f39efb3bcaf5074dd81d1b657f08a6ec857664
3
+ metadata.gz: 118c841f2c7a535679e7259b93799339c12997ea
4
+ data.tar.gz: 1f293ccd56c2b30fd09e776d728c077edbeb69f2
5
5
  SHA512:
6
- metadata.gz: 2a17a7e2514b3f8b97f019ff6bf0f5a8b6b68b19c41e6c5f95b324a79eb3ff72374276d37fde76f2a3f5c58384cf5466de73bd4c0d570f228a00c3d6d96ebbaa
7
- data.tar.gz: 07cef39e0789d1638f9f55f5edf1e290358f445ce878642cd00bea65d54638baadf54c743f9e7721028d9dfbb0b03baf8e7180b1ac07f4c452255e6edca38607
6
+ metadata.gz: ce35c4b91b1b97d55d9a5142ca4d0796b9663cf50dd41f927f077989cbc676cee37891b3f352731bf78e040940471d6e6c3cae62cc3360d531f9ad7d1df4b30b
7
+ data.tar.gz: 1afb54a0aac2920568ca0f048edb4c451b5151333d36eb754b79954f85b38829004da91280a6f711ad05271413fca780e41a82b58332f0915183ddad9412d340
data/CHANGELOG.md CHANGED
@@ -1,3 +1,6 @@
1
+ ## 3.2.0
2
+ - Fixed an issue with the encoding that prevented certain fields from being serialized in a way compatible with the Kafka plugins
3
+
1
4
  ## 3.1.0
2
5
  - Introduce `tag_on_failure` option to tag events with `_avroparsefailure` instead of throwing an exception when decoding
3
6
 
@@ -0,0 +1,103 @@
1
+ :plugin: avro
2
+ :type: codec
3
+
4
+ ///////////////////////////////////////////
5
+ START - GENERATED VARIABLES, DO NOT EDIT!
6
+ ///////////////////////////////////////////
7
+ :version: %VERSION%
8
+ :release_date: %RELEASE_DATE%
9
+ :changelog_url: %CHANGELOG_URL%
10
+ :include_path: ../../../logstash/docs/include
11
+ ///////////////////////////////////////////
12
+ END - GENERATED VARIABLES, DO NOT EDIT!
13
+ ///////////////////////////////////////////
14
+
15
+ [id="plugins-{type}-{plugin}"]
16
+
17
+ === Avro
18
+
19
+ include::{include_path}/plugin_header.asciidoc[]
20
+
21
+ ==== Description
22
+
23
+ Read serialized Avro records as Logstash events
24
+
25
+ This plugin is used to serialize Logstash events as
26
+ Avro datums, as well as deserializing Avro datums into
27
+ Logstash events.
28
+
29
+ ==== Encoding
30
+
31
+ This codec is for serializing individual Logstash events
32
+ as Avro datums that are Avro binary blobs. It does not encode
33
+ Logstash events into an Avro file.
34
+
35
+
36
+ ==== Decoding
37
+
38
+ This codec is for deserializing individual Avro records. It is not for reading
39
+ Avro files. Avro files have a unique format that must be handled upon input.
40
+
41
+
42
+ ==== Usage
43
+ Example usage with Kafka input.
44
+
45
+ [source,ruby]
46
+ ----------------------------------
47
+ input {
48
+ kafka {
49
+ codec => avro {
50
+ schema_uri => "/tmp/schema.avsc"
51
+ }
52
+ }
53
+ }
54
+ filter {
55
+ ...
56
+ }
57
+ output {
58
+ ...
59
+ }
60
+ ----------------------------------
61
+
62
+ [id="plugins-{type}s-{plugin}-options"]
63
+ ==== Avro Codec Configuration Options
64
+
65
+ This plugin supports the following configuration options plus the <<plugins-{type}s-common-options>> described later.
66
+
67
+ [cols="<,<,<",options="header",]
68
+ |=======================================================================
69
+ |Setting |Input type|Required
70
+ | <<plugins-{type}s-{plugin}-schema_uri>> |<<string,string>>|Yes
71
+ | <<plugins-{type}s-{plugin}-tag_on_failure>> |<<boolean,boolean>>|No
72
+ |=======================================================================
73
+
74
+ Also see <<plugins-{type}s-common-options>> for a list of options supported by all
75
+ codec plugins.
76
+
77
+ &nbsp;
78
+
79
+ [id="plugins-{type}s-{plugin}-schema_uri"]
80
+ ===== `schema_uri`
81
+
82
+ * This is a required setting.
83
+ * Value type is <<string,string>>
84
+ * There is no default value for this setting.
85
+
86
+ schema path to fetch the schema from.
87
+ This can be a 'http' or 'file' scheme URI
88
+ example:
89
+
90
+ * http - `http://example.com/schema.avsc`
91
+ * file - `/path/to/schema.avsc`
92
+
93
+ [id="plugins-{type}s-{plugin}-tag_on_failure"]
94
+ ===== `tag_on_failure`
95
+
96
+ * Value type is <<boolean,boolean>>
97
+ * Default value is `false`
98
+
99
+ tag events with `_avroparsefailure` when decode fails
100
+
101
+
102
+
103
+ include::{include_path}/{type}.asciidoc[]
@@ -1,6 +1,7 @@
1
1
  # encoding: utf-8
2
2
  require "open-uri"
3
3
  require "avro"
4
+ require "base64"
4
5
  require "logstash/codecs/base"
5
6
  require "logstash/event"
6
7
  require "logstash/timestamp"
@@ -70,7 +71,7 @@ class LogStash::Codecs::Avro < LogStash::Codecs::Base
70
71
 
71
72
  public
72
73
  def decode(data)
73
- datum = StringIO.new(data)
74
+ datum = StringIO.new(Base64.strict_decode64(data)) rescue StringIO.new(data)
74
75
  decoder = Avro::IO::BinaryDecoder.new(datum)
75
76
  datum_reader = Avro::IO::DatumReader.new(@schema)
76
77
  yield LogStash::Event.new(datum_reader.read(decoder))
@@ -89,6 +90,6 @@ class LogStash::Codecs::Avro < LogStash::Codecs::Base
89
90
  buffer = StringIO.new
90
91
  encoder = Avro::IO::BinaryEncoder.new(buffer)
91
92
  dw.write(event.to_hash, encoder)
92
- @on_event.call(event, buffer.string)
93
+ @on_event.call(event, Base64.strict_encode64(buffer.string))
93
94
  end
94
95
  end
@@ -1,7 +1,7 @@
1
1
  Gem::Specification.new do |s|
2
2
 
3
3
  s.name = 'logstash-codec-avro'
4
- s.version = '3.1.0'
4
+ s.version = '3.2.0'
5
5
  s.platform = 'java'
6
6
  s.licenses = ['Apache-2.0']
7
7
  s.summary = "Encode and decode avro formatted data"
@@ -12,7 +12,7 @@ Gem::Specification.new do |s|
12
12
  s.require_paths = ["lib"]
13
13
 
14
14
  # Files
15
- s.files = Dir['lib/**/*','spec/**/*','vendor/**/*','*.gemspec','*.md','CONTRIBUTORS','Gemfile','LICENSE','NOTICE.TXT']
15
+ s.files = Dir["lib/**/*","spec/**/*","*.gemspec","*.md","CONTRIBUTORS","Gemfile","LICENSE","NOTICE.TXT", "vendor/jar-dependencies/**/*.jar", "vendor/jar-dependencies/**/*.rb", "VERSION", "docs/**/*"]
16
16
 
17
17
  # Tests
18
18
  s.test_files = s.files.grep(%r{^(test|spec|features)/})
@@ -1,70 +1,114 @@
1
1
  # encoding: utf-8
2
- require "logstash/devutils/rspec/spec_helper"
2
+ require 'logstash/devutils/rspec/spec_helper'
3
3
  require 'avro'
4
+ require 'base64'
4
5
  require 'logstash/codecs/avro'
5
6
  require 'logstash/event'
6
7
 
7
8
  describe LogStash::Codecs::Avro do
8
- let (:avro_config) {{'schema_uri' => '
9
+
10
+ context "non binary data" do
11
+ let (:avro_config) {{ 'schema_uri' => '
9
12
  {"type": "record", "name": "Test",
10
13
  "fields": [{"name": "foo", "type": ["null", "string"]},
11
- {"name": "bar", "type": "int"}]}'}}
12
- let (:test_event) { LogStash::Event.new({"foo" => "hello", "bar" => 10}) }
14
+ {"name": "bar", "type": "int"}]}' }}
15
+ let (:test_event) {LogStash::Event.new({ "foo" => "hello", "bar" => 10 })}
13
16
 
14
- subject do
15
- allow_any_instance_of(LogStash::Codecs::Avro).to \
17
+ subject do
18
+ allow_any_instance_of(LogStash::Codecs::Avro).to \
16
19
  receive(:open_and_read).and_return(avro_config['schema_uri'])
17
- next LogStash::Codecs::Avro.new(avro_config)
18
- end
20
+ next LogStash::Codecs::Avro.new(avro_config)
21
+ end
19
22
 
20
- context "#decode" do
21
- it "should return an LogStash::Event from avro data" do
22
- schema = Avro::Schema.parse(avro_config['schema_uri'])
23
- dw = Avro::IO::DatumWriter.new(schema)
24
- buffer = StringIO.new
25
- encoder = Avro::IO::BinaryEncoder.new(buffer)
26
- dw.write(test_event.to_hash, encoder)
23
+ context "#decode" do
24
+ it "should return an LogStash::Event from raw and base64 encoded avro data" do
25
+ schema = Avro::Schema.parse(avro_config['schema_uri'])
26
+ dw = Avro::IO::DatumWriter.new(schema)
27
+ buffer = StringIO.new
28
+ encoder = Avro::IO::BinaryEncoder.new(buffer)
29
+ dw.write(test_event.to_hash, encoder)
27
30
 
28
- subject.decode(buffer.string) do |event|
29
- insist { event.is_a? LogStash::Event }
30
- insist { event.get("foo") } == test_event.get("foo")
31
- insist { event.get("bar") } == test_event.get("bar")
31
+ subject.decode(Base64.strict_encode64(buffer.string)) do |event|
32
+ insist {event.is_a? LogStash::Event}
33
+ insist {event.get("foo")} == test_event.get("foo")
34
+ insist {event.get("bar")} == test_event.get("bar")
35
+ end
36
+ subject.decode(buffer.string) do |event|
37
+ insist {event.is_a? LogStash::Event}
38
+ insist {event.get("foo")} == test_event.get("foo")
39
+ insist {event.get("bar")} == test_event.get("bar")
40
+ end
32
41
  end
33
- end
34
42
 
35
- it "should throw exception if decoding fails" do
36
- expect { subject.decode("not avro") { |_| } }.to raise_error NoMethodError
43
+ it "should throw exception if decoding fails" do
44
+ expect {subject.decode("not avro") {|_| }}.to raise_error NoMethodError
45
+ end
37
46
  end
38
- end
39
47
 
40
- context "#decode with tag_on_failure" do
41
- let (:avro_config) { super.merge("tag_on_failure" => true) }
48
+ context "#decode with tag_on_failure" do
49
+ let (:avro_config) {super.merge("tag_on_failure" => true)}
42
50
 
43
- it "should tag event on failure" do
44
- subject.decode("not avro") do |event|
45
- insist { event.is_a? LogStash::Event }
46
- insist { event.get("tags") } == ["_avroparsefailure"]
51
+ it "should tag event on failure" do
52
+ subject.decode("not avro") do |event|
53
+ insist {event.is_a? LogStash::Event}
54
+ insist {event.get("tags")} == ["_avroparsefailure"]
55
+ end
47
56
  end
48
57
  end
49
- end
50
58
 
51
- context "#encode" do
52
- it "should return avro data from a LogStash::Event" do
53
- got_event = false
54
- subject.on_event do |event, data|
55
- schema = Avro::Schema.parse(avro_config['schema_uri'])
56
- datum = StringIO.new(data)
57
- decoder = Avro::IO::BinaryDecoder.new(datum)
58
- datum_reader = Avro::IO::DatumReader.new(schema)
59
- record = datum_reader.read(decoder)
59
+ context "#encode" do
60
+ it "should return avro data from a LogStash::Event" do
61
+ got_event = false
62
+ subject.on_event do |event, data|
63
+ schema = Avro::Schema.parse(avro_config['schema_uri'])
64
+ datum = StringIO.new(Base64.strict_decode64(data))
65
+ decoder = Avro::IO::BinaryDecoder.new(datum)
66
+ datum_reader = Avro::IO::DatumReader.new(schema)
67
+ record = datum_reader.read(decoder)
68
+
69
+ insist {record["foo"]} == test_event.get("foo")
70
+ insist {record["bar"]} == test_event.get("bar")
71
+ insist {event.is_a? LogStash::Event}
72
+ got_event = true
73
+ end
74
+ subject.encode(test_event)
75
+ insist {got_event}
76
+ end
77
+
78
+ context "binary data" do
79
+
80
+ let (:avro_config) {{ 'schema_uri' => '{"namespace": "com.systems.test.data",
81
+ "type": "record",
82
+ "name": "TestRecord",
83
+ "fields": [
84
+ {"name": "name", "type": ["string", "null"]},
85
+ {"name": "longitude", "type": ["double", "null"]},
86
+ {"name": "latitude", "type": ["double", "null"]}
87
+ ]
88
+ }' }}
89
+ let (:test_event) {LogStash::Event.new({ "name" => "foo", "longitude" => 21.01234.to_f, "latitude" => 111.0123.to_f })}
90
+
91
+ subject do
92
+ allow_any_instance_of(LogStash::Codecs::Avro).to \
93
+ receive(:open_and_read).and_return(avro_config['schema_uri'])
94
+ next LogStash::Codecs::Avro.new(avro_config)
95
+ end
96
+
97
+ it "should correctly encode binary data" do
98
+ schema = Avro::Schema.parse(avro_config['schema_uri'])
99
+ dw = Avro::IO::DatumWriter.new(schema)
100
+ buffer = StringIO.new
101
+ encoder = Avro::IO::BinaryEncoder.new(buffer)
102
+ dw.write(test_event.to_hash, encoder)
60
103
 
61
- insist { record["foo"] } == test_event.get("foo")
62
- insist { record["bar"] } == test_event.get("bar")
63
- insist { event.is_a? LogStash::Event }
64
- got_event = true
104
+ subject.decode(Base64.strict_encode64(buffer.string)) do |event|
105
+ insist {event.is_a? LogStash::Event}
106
+ insist {event.get("name")} == test_event.get("name")
107
+ insist {event.get("longitude")} == test_event.get("longitude")
108
+ insist {event.get("latitude")} == test_event.get("latitude")
109
+ end
110
+ end
65
111
  end
66
- subject.encode(test_event)
67
- insist { got_event }
68
112
  end
69
113
  end
70
114
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logstash-codec-avro
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.0
4
+ version: 3.2.0
5
5
  platform: java
6
6
  authors:
7
7
  - Elastic
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-02-24 00:00:00.000000000 Z
11
+ date: 2017-05-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  requirement: !ruby/object:Gem::Requirement
@@ -71,6 +71,7 @@ files:
71
71
  - LICENSE
72
72
  - NOTICE.TXT
73
73
  - README.md
74
+ - docs/index.asciidoc
74
75
  - lib/logstash/codecs/avro.rb
75
76
  - logstash-codec-avro.gemspec
76
77
  - spec/codecs/avro_spec.rb