logstash-codec-avro 3.3.1-java → 3.4.1-java

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: 772c2d05da7c85d818be97b57d65587730bc7204624199b670ba1f40de35b8a6
4
- data.tar.gz: 124b77e35ebc93783576228831ee427081bc9b052535abe8f20108cf962293f4
3
+ metadata.gz: 58f5ee3b7dd49fc9d5ea8a85c8b91cd042e67027a6b80440b48f3c943f149397
4
+ data.tar.gz: f0321dffe64cc44165dd5ccfc95fb4d8b7cbcff561aa8f1a048f7c79f53881ba
5
5
  SHA512:
6
- metadata.gz: 42b7e3f92cca071b122851cd18c79735c109570ba42cd4ce82ab87bd19bd887297006d9822d7fecbc5b54e1034ba33b33ab4f98b1c0f1cbb76df4e5f6e3ce36f
7
- data.tar.gz: 79771d37cc0b6dde478dff2a1f09f026ce644967aaeaf7a8e6ddaf77318d995f17301da3c681391dacd1f8bce9a5ae5e43d6ac5e14b006a93845cc87ae386300
6
+ metadata.gz: 9af8121f74ead4621f3979b638125c209e6790248d81681fdeb060f886d0f84e79cbb560c6c009d1cc21c5e94120e484830dd26186d93a5726c08e2187ab744f
7
+ data.tar.gz: 13e6a4db21017088f70f062d054625547b728a633788fdd5478f13a81746e9f9f23840cc73140fa8b82617f827c9a746b586b5fca669db300a08ef0209b4b06d
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ ## 3.4.1
2
+ - Fixes `(Errno::ENOENT) No such file or directory` error [#43](https://github.com/logstash-plugins/logstash-codec-avro/pull/43)
3
+
4
+ ## 3.4.0
5
+ - Add `encoding` option to select the encoding of Avro payload, could be `binary` or `base64` [#39](https://github.com/logstash-plugins/logstash-codec-avro/pull/39)
6
+
1
7
  ## 3.3.1
2
8
  - Pin avro gem to 1.10.x, as 1.11+ requires ruby 2.6+ [#37](https://github.com/logstash-plugins/logstash-codec-avro/pull/37)
3
9
 
data/docs/index.asciidoc CHANGED
@@ -82,6 +82,7 @@ output {
82
82
  |=======================================================================
83
83
  |Setting |Input type|Required
84
84
  | <<plugins-{type}s-{plugin}-ecs_compatibility>> | <<string,string>>|No
85
+ | <<plugins-{type}s-{plugin}-encoding>> | <<string,string>>, one of `["binary", "base64"]`|No
85
86
  | <<plugins-{type}s-{plugin}-schema_uri>> |<<string,string>>|Yes
86
87
  | <<plugins-{type}s-{plugin}-tag_on_failure>> |<<boolean,boolean>>|No
87
88
  | <<plugins-{type}s-{plugin}-target>> |<<string,string>>|No
@@ -99,6 +100,17 @@ output {
99
100
 
100
101
  Controls this plugin's compatibility with the {ecs-ref}[Elastic Common Schema (ECS)].
101
102
 
103
+ [id="plugins-{type}s-{plugin}-encoding"]
104
+ ===== `encoding`
105
+
106
+ * Value can be any of: `binary`, `base64`
107
+ * Default value is `base64`
108
+
109
+ Set encoding for Avro's payload.
110
+ Use `base64` (default) to indicate that this codec sends or expects to receive base64-encoded bytes.
111
+
112
+ Set this option to `binary` to indicate that this codec sends or expects to receive binary Avro data.
113
+
102
114
 
103
115
  [id="plugins-{type}s-{plugin}-schema_uri"]
104
116
  ===== `schema_uri`
@@ -59,6 +59,14 @@ class LogStash::Codecs::Avro < LogStash::Codecs::Base
59
59
 
60
60
  include LogStash::PluginMixins::EventSupport::EventFactoryAdapter
61
61
 
62
+ BINARY_ENCODING = "binary".freeze
63
+ BASE64_ENCODING = "base64".freeze
64
+
65
+ # Set encoding for Avro's payload.
66
+ # Use `base64` (default) encoding to convert the raw binary bytes to a `base64` encoded string.
67
+ # Set this option to `binary` to use the plain binary bytes.
68
+ config :encoding, :validate => [BINARY_ENCODING, BASE64_ENCODING], :default => BASE64_ENCODING
69
+
62
70
  # schema path to fetch the schema from.
63
71
  # This can be a 'http' or 'file' scheme URI
64
72
  # example:
@@ -77,7 +85,7 @@ class LogStash::Codecs::Avro < LogStash::Codecs::Base
77
85
  config :target, :validate => :field_reference
78
86
 
79
87
  def open_and_read(uri_string)
80
- open(uri_string).read
88
+ URI.open(uri_string, &:read)
81
89
  end
82
90
 
83
91
  public
@@ -92,7 +100,11 @@ class LogStash::Codecs::Avro < LogStash::Codecs::Base
92
100
 
93
101
  public
94
102
  def decode(data)
95
- datum = StringIO.new(Base64.strict_decode64(data)) rescue StringIO.new(data)
103
+ if encoding == BASE64_ENCODING
104
+ datum = StringIO.new(Base64.strict_decode64(data)) rescue StringIO.new(data)
105
+ else
106
+ datum = StringIO.new(data)
107
+ end
96
108
  decoder = Avro::IO::BinaryDecoder.new(datum)
97
109
  datum_reader = Avro::IO::DatumReader.new(@schema)
98
110
  event = targeted_event_factory.new_event(datum_reader.read(decoder))
@@ -113,6 +125,10 @@ class LogStash::Codecs::Avro < LogStash::Codecs::Base
113
125
  buffer = StringIO.new
114
126
  encoder = Avro::IO::BinaryEncoder.new(buffer)
115
127
  dw.write(event.to_hash, encoder)
116
- @on_event.call(event, Base64.strict_encode64(buffer.string))
128
+ if encoding == BASE64_ENCODING
129
+ @on_event.call(event, Base64.strict_encode64(buffer.string))
130
+ else
131
+ @on_event.call(event, buffer.string)
132
+ end
117
133
  end
118
134
  end
@@ -1,14 +1,14 @@
1
1
  Gem::Specification.new do |s|
2
2
 
3
3
  s.name = 'logstash-codec-avro'
4
- s.version = '3.3.1'
4
+ s.version = '3.4.1'
5
5
  s.platform = 'java'
6
6
  s.licenses = ['Apache-2.0']
7
7
  s.summary = "Reads serialized Avro records as Logstash events"
8
8
  s.description = "This gem is a Logstash plugin required to be installed on top of the Logstash core pipeline using $LS_HOME/bin/logstash-plugin install gemname. This gem is not a stand-alone program"
9
9
  s.authors = ["Elastic"]
10
10
  s.email = 'info@elastic.co'
11
- s.homepage = "http://www.elastic.co/guide/en/logstash/current/index.html"
11
+ s.homepage = "https://www.elastic.co/logstash"
12
12
  s.require_paths = ["lib"]
13
13
 
14
14
  # Files
@@ -55,6 +55,35 @@ describe LogStash::Codecs::Avro, :ecs_compatibility_support, :aggregate_failures
55
55
  end
56
56
  end
57
57
 
58
+ context "with binary encoding" do
59
+ let (:avro_config) { super().merge('encoding' => 'binary') }
60
+
61
+ it "should return an LogStash::Event from raw and base64 encoded avro data" do
62
+ schema = Avro::Schema.parse(avro_config['schema_uri'])
63
+ dw = Avro::IO::DatumWriter.new(schema)
64
+ buffer = StringIO.new
65
+ encoder = Avro::IO::BinaryEncoder.new(buffer)
66
+ dw.write(test_event.to_hash, encoder)
67
+
68
+ subject.decode(buffer.string) do |event|
69
+ expect(event).to be_a_kind_of(LogStash::Event)
70
+ expect(event.get("foo")).to eq(test_event.get("foo"))
71
+ expect(event.get("bar")).to eq(test_event.get("bar"))
72
+ expect(event.get('[event][original]')).to eq(buffer.string) if ecs_compatibility != :disabled
73
+ end
74
+ end
75
+
76
+ it "should raise an error if base64 encoded data is provided" do
77
+ schema = Avro::Schema.parse(avro_config['schema_uri'])
78
+ dw = Avro::IO::DatumWriter.new(schema)
79
+ buffer = StringIO.new
80
+ encoder = Avro::IO::BinaryEncoder.new(buffer)
81
+ dw.write(test_event.to_hash, encoder)
82
+
83
+ expect {subject.decode(Base64.strict_encode64(buffer.string))}.to raise_error
84
+ end
85
+ end
86
+
58
87
  context "#decode with tag_on_failure" do
59
88
  let (:avro_config) {{ 'schema_uri' => '
60
89
  {"type": "record", "name": "Test",
@@ -111,6 +140,28 @@ describe LogStash::Codecs::Avro, :ecs_compatibility_support, :aggregate_failures
111
140
  insist {got_event}
112
141
  end
113
142
 
143
+ context "with binary encoding" do
144
+ let (:avro_config) { super().merge('encoding' => 'binary') }
145
+
146
+ it "should return avro data from a LogStash::Event not base64 encoded" do
147
+ got_event = false
148
+ subject.on_event do |event, data|
149
+ schema = Avro::Schema.parse(avro_config['schema_uri'])
150
+ datum = StringIO.new(data)
151
+ decoder = Avro::IO::BinaryDecoder.new(datum)
152
+ datum_reader = Avro::IO::DatumReader.new(schema)
153
+ record = datum_reader.read(decoder)
154
+
155
+ expect(event).to be_a_kind_of(LogStash::Event)
156
+ expect(event.get("foo")).to eq(test_event.get("foo"))
157
+ expect(event.get("bar")).to eq(test_event.get("bar"))
158
+ got_event = true
159
+ end
160
+ subject.encode(test_event)
161
+ expect(got_event).to be true
162
+ end
163
+ end
164
+
114
165
  context "binary data" do
115
166
 
116
167
  let (:avro_config) {{ 'schema_uri' => '{"namespace": "com.systems.test.data",
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.3.1
4
+ version: 3.4.1
5
5
  platform: java
6
6
  authors:
7
7
  - Elastic
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-12-07 00:00:00.000000000 Z
11
+ date: 2023-10-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  requirement: !ruby/object:Gem::Requirement
@@ -133,7 +133,7 @@ files:
133
133
  - lib/logstash/codecs/avro.rb
134
134
  - logstash-codec-avro.gemspec
135
135
  - spec/codecs/avro_spec.rb
136
- homepage: http://www.elastic.co/guide/en/logstash/current/index.html
136
+ homepage: https://www.elastic.co/logstash
137
137
  licenses:
138
138
  - Apache-2.0
139
139
  metadata:
@@ -154,7 +154,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
154
154
  - !ruby/object:Gem::Version
155
155
  version: '0'
156
156
  requirements: []
157
- rubygems_version: 3.1.6
157
+ rubygems_version: 3.2.33
158
158
  signing_key:
159
159
  specification_version: 4
160
160
  summary: Reads serialized Avro records as Logstash events