logstash-codec-avro_schema_registry 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.md +3 -0
- data/CONTRIBUTORS +12 -0
- data/DEVELOPER.md +45 -0
- data/Gemfile +2 -0
- data/LICENSE +13 -0
- data/NOTICE.TXT +5 -0
- data/README.md +89 -0
- data/lib/logstash/codecs/avro_schema_registry.rb +92 -0
- data/logstash-codec-avro_schema_registry.gemspec +30 -0
- data/spec/codecs/avro_schema_registry_spec.rb +52 -0
- metadata +118 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: d00edc13002f8c653b857c22b82f24705b1e252e
|
4
|
+
data.tar.gz: 707db9b1981757925f28040e511c5214330728f8
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4b15236ceaaea864dadaa68fd69e880ca410fbe3db12263d410613c7398ee8d1fbedca01ee54532da200e255beddd63d2eb63086e4537df0909cace036bdd643
|
7
|
+
data.tar.gz: b061bbb87c516b24d9d20a9748330d268735ca66425c4ec1ef2d755df3b921778241c7d429ab98a1c97e261b26bbdd6b6ca4fcb16e158839a54cdcabd6ea721c
|
data/CHANGELOG.md
ADDED
data/CONTRIBUTORS
ADDED
@@ -0,0 +1,12 @@
|
|
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
|
+
* Ryan Anguiano (ryananguiano)
|
8
|
+
|
9
|
+
Note: If you've sent us patches, bug reports, or otherwise contributed to
|
10
|
+
Logstash, and you aren't on the list above and want to be, please let us know
|
11
|
+
and we'll make sure you're here. Contributions from folks like you are what make
|
12
|
+
open source awesome.
|
data/DEVELOPER.md
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
Logstash Avro Schema Registry Codec
|
2
|
+
===================
|
3
|
+
|
4
|
+
How to Install
|
5
|
+
--------------
|
6
|
+
|
7
|
+
```
|
8
|
+
bin/plugin install logstash-avro_schema_registry-codec
|
9
|
+
```
|
10
|
+
|
11
|
+
How to Use
|
12
|
+
----------
|
13
|
+
You can use this codec to decode avro messages
|
14
|
+
in a Kafka topic input. Each message must be prefixed
|
15
|
+
with a 5-byte struct containing a magic byte and
|
16
|
+
the schema id.
|
17
|
+
|
18
|
+
You must pass the endpoint of the schema registry server.
|
19
|
+
|
20
|
+
Along with the logstash config for reading in messages of this
|
21
|
+
type using the avro codec with the logstash-input-kafka plugin.
|
22
|
+
|
23
|
+
### logstash.conf
|
24
|
+
|
25
|
+
```
|
26
|
+
input {
|
27
|
+
kafka {
|
28
|
+
topic_id => 'test_topic'
|
29
|
+
codec => avro_schema_registry {
|
30
|
+
endpoint => 'http://schemas.example.com'
|
31
|
+
}
|
32
|
+
}
|
33
|
+
}
|
34
|
+
|
35
|
+
output {
|
36
|
+
stdout {
|
37
|
+
codec => rubydebug
|
38
|
+
}
|
39
|
+
}
|
40
|
+
```
|
41
|
+
|
42
|
+
### Running the setup
|
43
|
+
```
|
44
|
+
bin/logstash -f logstash.conf
|
45
|
+
```
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
Copyright (c) 2012–2015 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
data/README.md
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
# Logstash Plugin
|
2
|
+
|
3
|
+
[![Build
|
4
|
+
Status](http://build-eu-00.elastic.co/view/LS%20Plugins/view/LS%20Codecs/job/logstash-plugin-codec-avro-unit/badge/icon)](http://build-eu-00.elastic.co/view/LS%20Plugins/view/LS%20Codecs/job/logstash-plugin-codec-avro-unit/)
|
5
|
+
|
6
|
+
This is a plugin for [Logstash](https://github.com/elastic/logstash).
|
7
|
+
|
8
|
+
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.
|
9
|
+
|
10
|
+
## Documentation
|
11
|
+
|
12
|
+
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/).
|
13
|
+
|
14
|
+
- For formatting code or config example, you can use the asciidoc `[source,ruby]` directive
|
15
|
+
- For more asciidoc formatting tips, see the excellent reference here https://github.com/elastic/docs#asciidoc-guide
|
16
|
+
|
17
|
+
## Need Help?
|
18
|
+
|
19
|
+
Need help? Try #logstash on freenode IRC or the https://discuss.elastic.co/c/logstash discussion forum.
|
20
|
+
|
21
|
+
## Developing
|
22
|
+
|
23
|
+
### 1. Plugin Developement and Testing
|
24
|
+
|
25
|
+
#### Code
|
26
|
+
- To get started, you'll need JRuby with the Bundler gem installed.
|
27
|
+
|
28
|
+
- 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).
|
29
|
+
|
30
|
+
- Install dependencies
|
31
|
+
```sh
|
32
|
+
bundle install
|
33
|
+
```
|
34
|
+
|
35
|
+
#### Test
|
36
|
+
|
37
|
+
- Update your dependencies
|
38
|
+
|
39
|
+
```sh
|
40
|
+
bundle install
|
41
|
+
```
|
42
|
+
|
43
|
+
- Run tests
|
44
|
+
|
45
|
+
```sh
|
46
|
+
bundle exec rspec
|
47
|
+
```
|
48
|
+
|
49
|
+
### 2. Running your unpublished Plugin in Logstash
|
50
|
+
|
51
|
+
#### 2.1 Run in a local Logstash clone
|
52
|
+
|
53
|
+
- Edit Logstash `Gemfile` and add the local plugin path, for example:
|
54
|
+
```ruby
|
55
|
+
gem "logstash-filter-awesome", :path => "/your/local/logstash-filter-awesome"
|
56
|
+
```
|
57
|
+
- Install plugin
|
58
|
+
```sh
|
59
|
+
bin/plugin install --no-verify
|
60
|
+
```
|
61
|
+
- Run Logstash with your plugin
|
62
|
+
```sh
|
63
|
+
bin/logstash -e 'filter {awesome {}}'
|
64
|
+
```
|
65
|
+
At this point any modifications to the plugin code will be applied to this local Logstash setup. After modifying the plugin, simply rerun Logstash.
|
66
|
+
|
67
|
+
#### 2.2 Run in an installed Logstash
|
68
|
+
|
69
|
+
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:
|
70
|
+
|
71
|
+
- Build your plugin gem
|
72
|
+
```sh
|
73
|
+
gem build logstash-filter-awesome.gemspec
|
74
|
+
```
|
75
|
+
- Install the plugin from the Logstash home
|
76
|
+
```sh
|
77
|
+
bin/plugin install /your/local/plugin/logstash-filter-awesome.gem
|
78
|
+
```
|
79
|
+
- Start Logstash and proceed to test the plugin
|
80
|
+
|
81
|
+
## Contributing
|
82
|
+
|
83
|
+
All contributions are welcome: ideas, patches, documentation, bug reports, complaints, and even something you drew up on a napkin.
|
84
|
+
|
85
|
+
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.
|
86
|
+
|
87
|
+
It is more important to the community that you are able to contribute.
|
88
|
+
|
89
|
+
For more information about contributing, see the [CONTRIBUTING](https://github.com/elastic/logstash/blob/master/CONTRIBUTING.md) file.
|
@@ -0,0 +1,92 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require "avro"
|
3
|
+
require "schema_registry"
|
4
|
+
require "schema_registry/client"
|
5
|
+
require "logstash/codecs/base"
|
6
|
+
require "logstash/event"
|
7
|
+
require "logstash/timestamp"
|
8
|
+
require "logstash/util"
|
9
|
+
|
10
|
+
MAGIC_BYTE = 0
|
11
|
+
|
12
|
+
# Read serialized Avro records as Logstash events
|
13
|
+
#
|
14
|
+
# This plugin is used to serialize Logstash events as
|
15
|
+
# Avro datums, as well as deserializing Avro datums into
|
16
|
+
# Logstash events.
|
17
|
+
#
|
18
|
+
# ==== Encoding
|
19
|
+
#
|
20
|
+
# This codec currently does not encode. This might be added later.
|
21
|
+
#
|
22
|
+
#
|
23
|
+
# ==== Decoding
|
24
|
+
#
|
25
|
+
# This codec is for deserializing individual Avro records. It looks up
|
26
|
+
# the associated avro schema from a Confluent schema registry.
|
27
|
+
# (https://github.com/confluentinc/schema-registry)
|
28
|
+
#
|
29
|
+
#
|
30
|
+
# ==== Usage
|
31
|
+
# Example usage with Kafka input.
|
32
|
+
#
|
33
|
+
# [source,ruby]
|
34
|
+
# ----------------------------------
|
35
|
+
# input {
|
36
|
+
# kafka {
|
37
|
+
# codec => avro_schema_registry {
|
38
|
+
# endpoint => "http://schemas.example.com"
|
39
|
+
# }
|
40
|
+
# }
|
41
|
+
# }
|
42
|
+
# filter {
|
43
|
+
# ...
|
44
|
+
# }
|
45
|
+
# output {
|
46
|
+
# ...
|
47
|
+
# }
|
48
|
+
# ----------------------------------
|
49
|
+
class LogStash::Codecs::AvroSchemaRegistry < LogStash::Codecs::Base
|
50
|
+
config_name "avro_schema_registry"
|
51
|
+
|
52
|
+
# schema registry endpoint and credentials
|
53
|
+
config :endpoint, :validate => :string, :required => true
|
54
|
+
config :username, :validate => :string, :default => nil
|
55
|
+
config :password, :validate => :string, :default => nil
|
56
|
+
|
57
|
+
public
|
58
|
+
def register
|
59
|
+
@client = SchemaRegistry::Client.new(endpoint, username, password)
|
60
|
+
@schemas = Hash.new
|
61
|
+
end
|
62
|
+
|
63
|
+
def get_schema(schema_id)
|
64
|
+
if !@schemas.has_key?(schema_id)
|
65
|
+
@schemas[schema_id] = Avro::Schema.parse(@client.schema(schema_id))
|
66
|
+
end
|
67
|
+
@schemas[schema_id]
|
68
|
+
end
|
69
|
+
|
70
|
+
public
|
71
|
+
def decode(data)
|
72
|
+
if data.length < 5
|
73
|
+
@logger.error('message is too small to decode')
|
74
|
+
else
|
75
|
+
datum = StringIO.new(data)
|
76
|
+
magic_byte, schema_id = datum.read(5).unpack("cI>")
|
77
|
+
if magic_byte != MAGIC_BYTE
|
78
|
+
@logger.error('message does not start with magic byte')
|
79
|
+
else
|
80
|
+
schema = get_schema(schema_id)
|
81
|
+
decoder = Avro::IO::BinaryDecoder.new(datum)
|
82
|
+
datum_reader = Avro::IO::DatumReader.new(schema)
|
83
|
+
yield LogStash::Event.new(datum_reader.read(decoder))
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
public
|
89
|
+
def encode(event)
|
90
|
+
@logger.error('Encode has not been implemented for this codec')
|
91
|
+
end
|
92
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
|
3
|
+
s.name = 'logstash-codec-avro_schema_registry'
|
4
|
+
s.version = '0.9.0'
|
5
|
+
s.licenses = ['Apache License (2.0)']
|
6
|
+
s.summary = "Encode and decode avro formatted data from a Confluent schema registry"
|
7
|
+
s.description = "Encode and decode avro formatted data from a Confluent schema registry"
|
8
|
+
s.authors = ["RevPoint Media"]
|
9
|
+
s.email = 'tech@revpointmedia.com'
|
10
|
+
s.homepage = "https://github.com/revpoint/logstash-codec-avro_schema_registry"
|
11
|
+
s.require_paths = ["lib"]
|
12
|
+
|
13
|
+
# Files
|
14
|
+
s.files = Dir['lib/**/*','spec/**/*','vendor/**/*','*.gemspec','*.md','CONTRIBUTORS','Gemfile','LICENSE','NOTICE.TXT']
|
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-core", ">= 2.0.0.beta2", "< 3.0.0"
|
24
|
+
|
25
|
+
s.add_runtime_dependency "avro" #(Apache 2.0 license)
|
26
|
+
|
27
|
+
s.add_runtime_dependency "schema_registry" #(MIT license)
|
28
|
+
|
29
|
+
s.add_development_dependency 'logstash-devutils'
|
30
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require "logstash/devutils/rspec/spec_helper"
|
3
|
+
require 'avro'
|
4
|
+
require 'logstash/codecs/avro_schema_registry'
|
5
|
+
require 'logstash/event'
|
6
|
+
|
7
|
+
describe LogStash::Codecs::AvroSchemaRegistry do
|
8
|
+
let (:avro_config) {{'endpoint' => 'http://registry.example.com'}}
|
9
|
+
let (:test_event) { LogStash::Event.new({"foo" => "hello", "bar" => 10}) }
|
10
|
+
|
11
|
+
subject do
|
12
|
+
# allow_any_instance_of(LogStash::Codecs::AvroSchemaRegistry).to \
|
13
|
+
# receive(:open_and_read).and_return(avro_config['schema_uri'])
|
14
|
+
next LogStash::Codecs::AvroSchemaRegistry.new(avro_config)
|
15
|
+
end
|
16
|
+
|
17
|
+
context "#decode" do
|
18
|
+
# it "should return an LogStash::Event from avro data" do
|
19
|
+
# schema = Avro::Schema.parse(avro_config['schema_uri'])
|
20
|
+
# dw = Avro::IO::DatumWriter.new(schema)
|
21
|
+
# buffer = StringIO.new
|
22
|
+
# encoder = Avro::IO::BinaryEncoder.new(buffer)
|
23
|
+
# dw.write(test_event.to_hash, encoder)
|
24
|
+
#
|
25
|
+
# subject.decode(buffer.string) do |event|
|
26
|
+
# insist { event.is_a? LogStash::Event }
|
27
|
+
# insist { event["foo"] } == test_event["foo"]
|
28
|
+
# insist { event["bar"] } == test_event["bar"]
|
29
|
+
# end
|
30
|
+
# end
|
31
|
+
end
|
32
|
+
|
33
|
+
context "#encode" do
|
34
|
+
# it "should return avro data from a LogStash::Event" do
|
35
|
+
# got_event = false
|
36
|
+
# subject.on_event do |event, data|
|
37
|
+
# schema = Avro::Schema.parse(avro_config['schema_uri'])
|
38
|
+
# datum = StringIO.new(data)
|
39
|
+
# decoder = Avro::IO::BinaryDecoder.new(datum)
|
40
|
+
# datum_reader = Avro::IO::DatumReader.new(schema)
|
41
|
+
# record = datum_reader.read(decoder)
|
42
|
+
#
|
43
|
+
# insist { record["foo"] } == test_event["foo"]
|
44
|
+
# insist { record["bar"] } == test_event["bar"]
|
45
|
+
# insist { event.is_a? LogStash::Event }
|
46
|
+
# got_event = true
|
47
|
+
# end
|
48
|
+
# subject.encode(test_event)
|
49
|
+
# insist { got_event }
|
50
|
+
# end
|
51
|
+
end
|
52
|
+
end
|
metadata
ADDED
@@ -0,0 +1,118 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: logstash-codec-avro_schema_registry
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.9.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- RevPoint Media
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-12-08 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: logstash-core
|
15
|
+
version_requirements: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 2.0.0.beta2
|
20
|
+
- - <
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 3.0.0
|
23
|
+
requirement: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - '>='
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: 2.0.0.beta2
|
28
|
+
- - <
|
29
|
+
- !ruby/object:Gem::Version
|
30
|
+
version: 3.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: schema_registry
|
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: :runtime
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: logstash-devutils
|
63
|
+
version_requirements: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - '>='
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '0'
|
68
|
+
requirement: !ruby/object:Gem::Requirement
|
69
|
+
requirements:
|
70
|
+
- - '>='
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: '0'
|
73
|
+
prerelease: false
|
74
|
+
type: :development
|
75
|
+
description: Encode and decode avro formatted data from a Confluent schema registry
|
76
|
+
email: tech@revpointmedia.com
|
77
|
+
executables: []
|
78
|
+
extensions: []
|
79
|
+
extra_rdoc_files: []
|
80
|
+
files:
|
81
|
+
- CHANGELOG.md
|
82
|
+
- CONTRIBUTORS
|
83
|
+
- DEVELOPER.md
|
84
|
+
- Gemfile
|
85
|
+
- LICENSE
|
86
|
+
- NOTICE.TXT
|
87
|
+
- README.md
|
88
|
+
- lib/logstash/codecs/avro_schema_registry.rb
|
89
|
+
- logstash-codec-avro_schema_registry.gemspec
|
90
|
+
- spec/codecs/avro_schema_registry_spec.rb
|
91
|
+
homepage: https://github.com/revpoint/logstash-codec-avro_schema_registry
|
92
|
+
licenses:
|
93
|
+
- Apache License (2.0)
|
94
|
+
metadata:
|
95
|
+
logstash_plugin: 'true'
|
96
|
+
logstash_group: codec
|
97
|
+
post_install_message:
|
98
|
+
rdoc_options: []
|
99
|
+
require_paths:
|
100
|
+
- lib
|
101
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
102
|
+
requirements:
|
103
|
+
- - '>='
|
104
|
+
- !ruby/object:Gem::Version
|
105
|
+
version: '0'
|
106
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - '>='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
requirements: []
|
112
|
+
rubyforge_project:
|
113
|
+
rubygems_version: 2.4.5
|
114
|
+
signing_key:
|
115
|
+
specification_version: 4
|
116
|
+
summary: Encode and decode avro formatted data from a Confluent schema registry
|
117
|
+
test_files:
|
118
|
+
- spec/codecs/avro_schema_registry_spec.rb
|