logstash-codec-avro 0.1.0

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: bb0bcc66f0b7e43cae0ac6936ddda5f7cf65dc44
4
+ data.tar.gz: 095ac47a666d8b0db08757e07132021db22f83e4
5
+ SHA512:
6
+ metadata.gz: 69e7e6ca8fcbe43db61ff6ed8246507e0df04e253cb1aaebb0549256bc017c634a12032337a6b9cf1dc539b353b05c6afd8e1dc3f71ad17c001888d5aa8f466b
7
+ data.tar.gz: 6f738e2a34e9de2acdf2a67f9d7b982bd8859c2bf5bf1f77d431d227d7901c4fff0960b5b1d1e7a13d8300a4d006c49c3ea70f44cd962192c4702329db21a096
data/.gitignore ADDED
@@ -0,0 +1,3 @@
1
+ *.gem
2
+ Gemfile.lock
3
+ .bundle
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
3
+ gem "logstash", :github => "elasticsearch/logstash", :branch => "1.5"
data/LICENSE ADDED
@@ -0,0 +1,13 @@
1
+ Copyright (c) 2012-2014 Elasticsearch <http://www.elasticsearch.org>
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/README.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_file => '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/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ @files=[]
2
+
3
+ task :default do
4
+ system("rake -T")
5
+ end
6
+
7
+ require "logstash/devutils/rake"
@@ -0,0 +1,46 @@
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
+ class LogStash::Codecs::Avro < LogStash::Codecs::Base
10
+ config_name "avro"
11
+
12
+ milestone 1
13
+
14
+ # schema path to fetch the schema from
15
+ # This can be a 'http' or 'file' scheme URI
16
+ # example:
17
+ # http - "http://example.com/schema.avsc"
18
+ # file - "/path/to/schema.avsc"
19
+ config :schema_uri, :validate => :string, :required => true
20
+
21
+ def open_and_read(uri_string)
22
+ open(uri_string).read
23
+ end
24
+
25
+ public
26
+ def register
27
+ @schema = Avro::Schema.parse(open_and_read(schema_uri))
28
+ end
29
+
30
+ public
31
+ def decode(data)
32
+ datum = StringIO.new(data)
33
+ decoder = Avro::IO::BinaryDecoder.new(datum)
34
+ datum_reader = Avro::IO::DatumReader.new(@schema)
35
+ yield LogStash::Event.new(datum_reader.read(decoder))
36
+ end
37
+
38
+ public
39
+ def encode(event)
40
+ dw = Avro::IO::DatumWriter.new(@schema)
41
+ buffer = StringIO.new
42
+ encoder = Avro::IO::BinaryEncoder.new(buffer)
43
+ dw.write(event.to_hash, encoder)
44
+ @on_event.call(buffer.string)
45
+ end
46
+ end
@@ -0,0 +1,29 @@
1
+ Gem::Specification.new do |s|
2
+
3
+ s.name = 'logstash-codec-avro'
4
+ s.version = '0.1.0'
5
+ s.licenses = ['Apache License (2.0)']
6
+ s.summary = "Encode and decode avro formatted data"
7
+ s.description = "Encode and decode avro formatted data"
8
+ s.authors = ["Elasticsearch"]
9
+ s.email = 'info@elasticsearch.com'
10
+ s.homepage = "http://www.elasticsearch.org/guide/en/logstash/current/index.html"
11
+ s.require_paths = ["lib"]
12
+
13
+ # Files
14
+ s.files = `git ls-files`.split($\)
15
+
16
+ # Tests
17
+ s.test_files = s.files.grep(%r{^(test|spec|features)/})
18
+
19
+ # Special flag to let us know this is actually a logstash plugin
20
+ s.metadata = { "logstash_plugin" => "true", "logstash_group" => "codec" }
21
+
22
+ # Gem dependencies
23
+ s.add_runtime_dependency 'logstash', '>= 1.4.0', '< 2.0.0'
24
+
25
+ s.add_runtime_dependency "avro" #(Apache 2.0 license)
26
+
27
+ s.add_development_dependency 'logstash-devutils'
28
+ end
29
+
@@ -0,0 +1,54 @@
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["foo"] } == test_event["foo"]
31
+ insist { event["bar"] } == test_event["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 |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["foo"]
47
+ insist { record["bar"] } == test_event["bar"]
48
+ got_event = true
49
+ end
50
+ subject.encode(test_event)
51
+ insist { got_event }
52
+ end
53
+ end
54
+ end
metadata ADDED
@@ -0,0 +1,102 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: logstash-codec-avro
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Elasticsearch
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-12-11 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: logstash
15
+ version_requirements: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: 1.4.0
20
+ - - <
21
+ - !ruby/object:Gem::Version
22
+ version: 2.0.0
23
+ requirement: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - '>='
26
+ - !ruby/object:Gem::Version
27
+ version: 1.4.0
28
+ - - <
29
+ - !ruby/object:Gem::Version
30
+ version: 2.0.0
31
+ prerelease: false
32
+ type: :runtime
33
+ - !ruby/object:Gem::Dependency
34
+ name: avro
35
+ version_requirements: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - '>='
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ requirement: !ruby/object:Gem::Requirement
41
+ requirements:
42
+ - - '>='
43
+ - !ruby/object:Gem::Version
44
+ version: '0'
45
+ prerelease: false
46
+ type: :runtime
47
+ - !ruby/object:Gem::Dependency
48
+ name: logstash-devutils
49
+ version_requirements: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ requirement: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - '>='
57
+ - !ruby/object:Gem::Version
58
+ version: '0'
59
+ prerelease: false
60
+ type: :development
61
+ description: Encode and decode avro formatted data
62
+ email: info@elasticsearch.com
63
+ executables: []
64
+ extensions: []
65
+ extra_rdoc_files: []
66
+ files:
67
+ - .gitignore
68
+ - Gemfile
69
+ - LICENSE
70
+ - README.md
71
+ - Rakefile
72
+ - lib/logstash/codecs/avro.rb
73
+ - logstash-codec-avro.gemspec
74
+ - spec/codecs/avro_spec.rb
75
+ homepage: http://www.elasticsearch.org/guide/en/logstash/current/index.html
76
+ licenses:
77
+ - Apache License (2.0)
78
+ metadata:
79
+ logstash_plugin: 'true'
80
+ logstash_group: codec
81
+ post_install_message:
82
+ rdoc_options: []
83
+ require_paths:
84
+ - lib
85
+ required_ruby_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ required_rubygems_version: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - '>='
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ requirements: []
96
+ rubyforge_project:
97
+ rubygems_version: 2.1.9
98
+ signing_key:
99
+ specification_version: 4
100
+ summary: Encode and decode avro formatted data
101
+ test_files:
102
+ - spec/codecs/avro_spec.rb