logstash-codec-avro 3.0.0-java

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 82c13044b81979f3dcc59afc6e0b12c84bc399a8
4
+ data.tar.gz: a63d24090bac54031cd9b4190ffb6eae7c3d951d
5
+ SHA512:
6
+ metadata.gz: 6f48ad5d631470cad389df4f431c841ba6ddf7f54692b19db13257ee2fe76d6e903875f31dc6d11b127b1571f06d2f2a14011396d9245b10c3b17f8820886851
7
+ data.tar.gz: fb08fb0bd4c7996840871e4d9b4592d7dc42e2fb65c229a768b67fe87a99e3ac39c041f58bcecc0fb682c8e72161421cf24725fda99e3492bd619c4f995128eb
data/CHANGELOG.md ADDED
@@ -0,0 +1,14 @@
1
+ ## 3.0.0
2
+ - breaking: Update to new Event API
3
+
4
+ ## 2.0.4
5
+ - Depend on logstash-core-plugin-api instead of logstash-core, removing the need to mass update plugins on major releases of logstash
6
+
7
+ ## 2.0.3
8
+ - New dependency requirements for logstash-core for the 5.0 release
9
+
10
+ ## 2.0.0
11
+ - Plugins were updated to follow the new shutdown semantic, this mainly allows Logstash to instruct input plugins to terminate gracefully,
12
+ instead of using Thread.raise on the plugins' threads. Ref: https://github.com/elastic/logstash/pull/3895
13
+ - Dependency on logstash-core update to 2.0
14
+
data/CONTRIBUTORS ADDED
@@ -0,0 +1,11 @@
1
+ The following is a list of people who have contributed ideas, code, bug
2
+ reports, or in general have helped logstash along its way.
3
+
4
+ Contributors:
5
+ * Pier-Hugues Pellerin (ph)
6
+ * Tal Levy (talevy)
7
+
8
+ Note: If you've sent us patches, bug reports, or otherwise contributed to
9
+ Logstash, and you aren't on the list above and want to be, please let us know
10
+ and we'll make sure you're here. Contributions from folks like you are what make
11
+ open source awesome.
data/DEVELOPER.md ADDED
@@ -0,0 +1,66 @@
1
+ Logstash Avro Codec
2
+ ===================
3
+
4
+ How to Install
5
+ --------------
6
+
7
+ ```
8
+ bin/plugin install logstash-avro-codec
9
+ ```
10
+
11
+ How to Use
12
+ ----------
13
+ You can use this codec to decode avro messages
14
+ in a Kafka topic input.
15
+
16
+ Here is an example schema for tweets.
17
+
18
+ ### tweet.avsc
19
+ ```
20
+ {
21
+ "type" : "record",
22
+ "name" : "twitter_schema",
23
+ "namespace" : "com.miguno.avro",
24
+ "fields" : [ {
25
+ "name" : "username",
26
+ "type" : "string",
27
+ "doc" : "Name of the user account on Twitter.com"
28
+ }, {
29
+ "name" : "tweet",
30
+ "type" : "string",
31
+ "doc" : "The content of the user's Twitter message"
32
+ }, {
33
+ "name" : "timestamp",
34
+ "type" : "long",
35
+ "doc" : "Unix epoch time in seconds"
36
+ } ],
37
+ "doc:" : "A basic schema for storing Twitter messages"
38
+ }
39
+ ```
40
+
41
+ Along with the logstash config for reading in messages of this
42
+ type using the avro codec with the logstash-input-kafka plugin.
43
+
44
+ ### logstash.conf
45
+
46
+ ```
47
+ input {
48
+ kafka {
49
+ topic_id => 'test_topic'
50
+ codec => avro {
51
+ schema_uri => 'tweet.avsc'
52
+ }
53
+ }
54
+ }
55
+
56
+ output {
57
+ stdout {
58
+ codec => rubydebug
59
+ }
60
+ }
61
+ ```
62
+
63
+ ### Running the setup
64
+ ```
65
+ bin/logstash -f logstash.conf
66
+ ```
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,13 @@
1
+ Copyright (c) 2012–2016 Elasticsearch <http://www.elastic.co>
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+
7
+ http://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ Unless required by applicable law or agreed to in writing, software
10
+ distributed under the License is distributed on an "AS IS" BASIS,
11
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ See the License for the specific language governing permissions and
13
+ limitations under the License.
data/NOTICE.TXT ADDED
@@ -0,0 +1,5 @@
1
+ Elasticsearch
2
+ Copyright 2012-2015 Elasticsearch
3
+
4
+ This product includes software developed by The Apache Software
5
+ Foundation (http://www.apache.org/).
data/README.md ADDED
@@ -0,0 +1,98 @@
1
+ # Logstash Plugin
2
+
3
+ [![Travis Build Status](https://travis-ci.org/logstash-plugins/logstash-codec-avro.svg)](https://travis-ci.org/logstash-plugins/logstash-codec-avro)
4
+
5
+ This is a plugin for [Logstash](https://github.com/elastic/logstash).
6
+
7
+ It is fully free and fully open source. The license is Apache 2.0, meaning you are pretty much free to use it however you want in whatever way.
8
+
9
+ ## Documentation
10
+
11
+ Logstash provides infrastructure to automatically generate documentation for this plugin. We use the asciidoc format to write documentation so any comments in the source code will be first converted into asciidoc and then into html. All plugin documentation are placed under one [central location](http://www.elastic.co/guide/en/logstash/current/).
12
+
13
+ - For formatting code or config example, you can use the asciidoc `[source,ruby]` directive
14
+ - For more asciidoc formatting tips, see the excellent reference here https://github.com/elastic/docs#asciidoc-guide
15
+
16
+ ## Need Help?
17
+
18
+ Need help? Try #logstash on freenode IRC or the https://discuss.elastic.co/c/logstash discussion forum.
19
+
20
+ ## Developing
21
+
22
+ ### 1. Plugin Developement and Testing
23
+
24
+ #### Code
25
+ - To get started, you'll need JRuby with the Bundler gem installed.
26
+
27
+ - Create a new plugin or clone and existing from the GitHub [logstash-plugins](https://github.com/logstash-plugins) organization. We also provide [example plugins](https://github.com/logstash-plugins?query=example).
28
+
29
+ - Install dependencies
30
+ ```sh
31
+ bundle install
32
+ ```
33
+
34
+ #### Test
35
+
36
+ - Update your dependencies
37
+
38
+ ```sh
39
+ bundle install
40
+ ```
41
+
42
+ - Run tests
43
+
44
+ ```sh
45
+ bundle exec rspec
46
+ ```
47
+
48
+ ### 2. Running your unpublished Plugin in Logstash
49
+
50
+ #### 2.1 Run in a local Logstash clone
51
+
52
+ - Edit Logstash `Gemfile` and add the local plugin path, for example:
53
+ ```ruby
54
+ gem "logstash-filter-awesome", :path => "/your/local/logstash-filter-awesome"
55
+ ```
56
+ - Install plugin
57
+ ```sh
58
+ # Logstash 2.3 and higher
59
+ bin/logstash-plugin install --no-verify
60
+
61
+ # Prior to Logstash 2.3
62
+ bin/plugin install --no-verify
63
+
64
+ ```
65
+ - Run Logstash with your plugin
66
+ ```sh
67
+ bin/logstash -e 'filter {awesome {}}'
68
+ ```
69
+ At this point any modifications to the plugin code will be applied to this local Logstash setup. After modifying the plugin, simply rerun Logstash.
70
+
71
+ #### 2.2 Run in an installed Logstash
72
+
73
+ You can use the same **2.1** method to run your plugin in an installed Logstash by editing its `Gemfile` and pointing the `:path` to your local plugin development directory or you can build the gem and install it using:
74
+
75
+ - Build your plugin gem
76
+ ```sh
77
+ gem build logstash-filter-awesome.gemspec
78
+ ```
79
+ - Install the plugin from the Logstash home
80
+ ```sh
81
+ # Logstash 2.3 and higher
82
+ bin/logstash-plugin install --no-verify
83
+
84
+ # Prior to Logstash 2.3
85
+ bin/plugin install --no-verify
86
+
87
+ ```
88
+ - Start Logstash and proceed to test the plugin
89
+
90
+ ## Contributing
91
+
92
+ All contributions are welcome: ideas, patches, documentation, bug reports, complaints, and even something you drew up on a napkin.
93
+
94
+ Programming is not a required skill. Whatever you've seen about open source and maintainers or community members saying "send patches or die" - you will not see that here.
95
+
96
+ It is more important to the community that you are able to contribute.
97
+
98
+ For more information about contributing, see the [CONTRIBUTING](https://github.com/elastic/logstash/blob/master/CONTRIBUTING.md) file.
@@ -0,0 +1,84 @@
1
+ # encoding: utf-8
2
+ require "open-uri"
3
+ require "avro"
4
+ require "logstash/codecs/base"
5
+ require "logstash/event"
6
+ require "logstash/timestamp"
7
+ require "logstash/util"
8
+
9
+ # Read serialized Avro records as Logstash events
10
+ #
11
+ # This plugin is used to serialize Logstash events as
12
+ # Avro datums, as well as deserializing Avro datums into
13
+ # Logstash events.
14
+ #
15
+ # ==== Encoding
16
+ #
17
+ # This codec is for serializing individual Logstash events
18
+ # as Avro datums that are Avro binary blobs. It does not encode
19
+ # Logstash events into an Avro file.
20
+ #
21
+ #
22
+ # ==== Decoding
23
+ #
24
+ # This codec is for deserializing individual Avro records. It is not for reading
25
+ # Avro files. Avro files have a unique format that must be handled upon input.
26
+ #
27
+ #
28
+ # ==== Usage
29
+ # Example usage with Kafka input.
30
+ #
31
+ # [source,ruby]
32
+ # ----------------------------------
33
+ # input {
34
+ # kafka {
35
+ # codec => avro {
36
+ # schema_uri => "/tmp/schema.avsc"
37
+ # }
38
+ # }
39
+ # }
40
+ # filter {
41
+ # ...
42
+ # }
43
+ # output {
44
+ # ...
45
+ # }
46
+ # ----------------------------------
47
+ class LogStash::Codecs::Avro < LogStash::Codecs::Base
48
+ config_name "avro"
49
+
50
+
51
+ # schema path to fetch the schema from.
52
+ # This can be a 'http' or 'file' scheme URI
53
+ # example:
54
+ #
55
+ # * http - `http://example.com/schema.avsc`
56
+ # * file - `/path/to/schema.avsc`
57
+ config :schema_uri, :validate => :string, :required => true
58
+
59
+ def open_and_read(uri_string)
60
+ open(uri_string).read
61
+ end
62
+
63
+ public
64
+ def register
65
+ @schema = Avro::Schema.parse(open_and_read(schema_uri))
66
+ end
67
+
68
+ public
69
+ def decode(data)
70
+ datum = StringIO.new(data)
71
+ decoder = Avro::IO::BinaryDecoder.new(datum)
72
+ datum_reader = Avro::IO::DatumReader.new(@schema)
73
+ yield LogStash::Event.new(datum_reader.read(decoder))
74
+ end
75
+
76
+ public
77
+ def encode(event)
78
+ dw = Avro::IO::DatumWriter.new(@schema)
79
+ buffer = StringIO.new
80
+ encoder = Avro::IO::BinaryEncoder.new(buffer)
81
+ dw.write(event.to_hash, encoder)
82
+ @on_event.call(event, buffer.string)
83
+ end
84
+ end
@@ -0,0 +1,30 @@
1
+ Gem::Specification.new do |s|
2
+
3
+ s.name = 'logstash-codec-avro'
4
+ s.version = '3.0.0'
5
+ s.platform = 'java'
6
+ s.licenses = ['Apache-2.0']
7
+ s.summary = "Encode and decode avro formatted data"
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
+ s.authors = ["Elastic"]
10
+ s.email = 'info@elastic.co'
11
+ s.homepage = "http://www.elastic.co/guide/en/logstash/current/index.html"
12
+ s.require_paths = ["lib"]
13
+
14
+ # Files
15
+ s.files = Dir['lib/**/*','spec/**/*','vendor/**/*','*.gemspec','*.md','CONTRIBUTORS','Gemfile','LICENSE','NOTICE.TXT']
16
+
17
+ # Tests
18
+ s.test_files = s.files.grep(%r{^(test|spec|features)/})
19
+
20
+ # Special flag to let us know this is actually a logstash plugin
21
+ s.metadata = { "logstash_plugin" => "true", "logstash_group" => "codec" }
22
+
23
+ # Gem dependencies
24
+ s.add_runtime_dependency "logstash-core-plugin-api", ">= 1.60", "<= 2.99"
25
+
26
+ s.add_runtime_dependency "avro" #(Apache 2.0 license)
27
+
28
+ s.add_development_dependency 'logstash-devutils'
29
+ end
30
+
@@ -0,0 +1,55 @@
1
+ # encoding: utf-8
2
+ require "logstash/devutils/rspec/spec_helper"
3
+ require 'avro'
4
+ require 'logstash/codecs/avro'
5
+ require 'logstash/event'
6
+
7
+ describe LogStash::Codecs::Avro do
8
+ let (:avro_config) {{'schema_uri' => '
9
+ {"type": "record", "name": "Test",
10
+ "fields": [{"name": "foo", "type": ["null", "string"]},
11
+ {"name": "bar", "type": "int"}]}'}}
12
+ let (:test_event) { LogStash::Event.new({"foo" => "hello", "bar" => 10}) }
13
+
14
+ subject do
15
+ allow_any_instance_of(LogStash::Codecs::Avro).to \
16
+ receive(:open_and_read).and_return(avro_config['schema_uri'])
17
+ next LogStash::Codecs::Avro.new(avro_config)
18
+ end
19
+
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)
27
+
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")
32
+ end
33
+ end
34
+ end
35
+
36
+ context "#encode" do
37
+ it "should return avro data from a LogStash::Event" do
38
+ got_event = false
39
+ subject.on_event do |event, data|
40
+ schema = Avro::Schema.parse(avro_config['schema_uri'])
41
+ datum = StringIO.new(data)
42
+ decoder = Avro::IO::BinaryDecoder.new(datum)
43
+ datum_reader = Avro::IO::DatumReader.new(schema)
44
+ record = datum_reader.read(decoder)
45
+
46
+ insist { record["foo"] } == test_event.get("foo")
47
+ insist { record["bar"] } == test_event.get("bar")
48
+ insist { event.is_a? LogStash::Event }
49
+ got_event = true
50
+ end
51
+ subject.encode(test_event)
52
+ insist { got_event }
53
+ end
54
+ end
55
+ end
metadata ADDED
@@ -0,0 +1,104 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: logstash-codec-avro
3
+ version: !ruby/object:Gem::Version
4
+ version: 3.0.0
5
+ platform: java
6
+ authors:
7
+ - Elastic
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-09-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - ">="
17
+ - !ruby/object:Gem::Version
18
+ version: '1.60'
19
+ - - "<="
20
+ - !ruby/object:Gem::Version
21
+ version: '2.99'
22
+ name: logstash-core-plugin-api
23
+ prerelease: false
24
+ type: :runtime
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: '1.60'
30
+ - - "<="
31
+ - !ruby/object:Gem::Version
32
+ version: '2.99'
33
+ - !ruby/object:Gem::Dependency
34
+ requirement: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - ">="
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ name: avro
40
+ prerelease: false
41
+ type: :runtime
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ - !ruby/object:Gem::Dependency
48
+ requirement: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: '0'
53
+ name: logstash-devutils
54
+ prerelease: false
55
+ type: :development
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ 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
62
+ email: info@elastic.co
63
+ executables: []
64
+ extensions: []
65
+ extra_rdoc_files: []
66
+ files:
67
+ - CHANGELOG.md
68
+ - CONTRIBUTORS
69
+ - DEVELOPER.md
70
+ - Gemfile
71
+ - LICENSE
72
+ - NOTICE.TXT
73
+ - README.md
74
+ - lib/logstash/codecs/avro.rb
75
+ - logstash-codec-avro.gemspec
76
+ - spec/codecs/avro_spec.rb
77
+ homepage: http://www.elastic.co/guide/en/logstash/current/index.html
78
+ licenses:
79
+ - Apache-2.0
80
+ metadata:
81
+ logstash_plugin: 'true'
82
+ logstash_group: codec
83
+ post_install_message:
84
+ rdoc_options: []
85
+ require_paths:
86
+ - lib
87
+ required_ruby_version: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ required_rubygems_version: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ requirements: []
98
+ rubyforge_project:
99
+ rubygems_version: 2.4.8
100
+ signing_key:
101
+ specification_version: 4
102
+ summary: Encode and decode avro formatted data
103
+ test_files:
104
+ - spec/codecs/avro_spec.rb