fluent-plugin-avro_deluxe 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/formatter_avro.rb +79 -0
- metadata +43 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: a0e4f8b9b1274e6614a9b34371662de4b32f6aae
|
4
|
+
data.tar.gz: 0d19cb5cfd89d1f1a102bb8e238bd7bc42d08a4f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4f648bf32dec3de55670c3cdc50995adedb630618a12c25dc2ef541db3a51f9d66462a204a0d5fe4d5933d10fb37f8f22c0ded5c85ddfcba5f023afeb5d3627a
|
7
|
+
data.tar.gz: 0c6f5d903bc9a862b99e00835af656c8bb714485b537ca2c471dfb585d85a6f06d6d7917fc366b68c391a223060257e8486f48c9dba5d1123074a50d9154bc40
|
@@ -0,0 +1,79 @@
|
|
1
|
+
require 'avro'
|
2
|
+
require 'schema_registry'
|
3
|
+
# https://github.com/revpoint/logstash-codec-avro_schema_registry/blob/master/lib/logstash/codecs/avro_schema_registry.rb
|
4
|
+
module Fluent
|
5
|
+
module TextFormatter
|
6
|
+
class AvroFormatter < Formatter
|
7
|
+
Fluent::Plugin.register_formatter('avro', self)
|
8
|
+
|
9
|
+
config_param :schema_file, :string, :default => nil
|
10
|
+
config_param :schema_json, :string, :default => nil
|
11
|
+
config_param :schema_url, :string, :default => nil
|
12
|
+
config_param :schema_subject, :string, :default => nil
|
13
|
+
config_param :schema_version, :string, :default => nil
|
14
|
+
# this stuff is needed if you're using a schema registry
|
15
|
+
# config_param :schema_version, :string, :default => nil
|
16
|
+
config_param :schema_id, :string, :default => nil
|
17
|
+
def configure(conf)
|
18
|
+
super
|
19
|
+
if !@schema_file.nil? then
|
20
|
+
raise Fluent::ConfigError "schema_file specified but schema_json already set" if !@schema_json.nil?
|
21
|
+
@schema_json = File.read(@schema_file)
|
22
|
+
end
|
23
|
+
if !@schema_url.nil? then
|
24
|
+
raise Fluent::ConfigError "schema_url specified but schema_json already set" if !@schema_json.nil?
|
25
|
+
client = SchemaRegistry::Client.new(
|
26
|
+
@schema_url,
|
27
|
+
'',
|
28
|
+
'',
|
29
|
+
SchemaRegistry::Client.connection_options(
|
30
|
+
client_certificate: '/etc/td-agent/ssl/avro_client.crt',
|
31
|
+
client_key: '/etc/td-agent/ssl/avro_client.key',
|
32
|
+
ca_certificate: "/etc/td-agent/ssl/avro_ca.pem",
|
33
|
+
verify_mode: :verify_peer
|
34
|
+
)
|
35
|
+
)
|
36
|
+
subject = client.subject(@schema_subject)
|
37
|
+
schema = subject.version(@schema_version)
|
38
|
+
@schema_json = schema.schema
|
39
|
+
@schema_id = schema.id
|
40
|
+
# puts "id:#{@schema_id} #{@schema_json}"
|
41
|
+
# body = Net::HTTP.get(URI.parse(@schema_url))
|
42
|
+
# data = JSON.parse(body)
|
43
|
+
# @schema_version = data['version']
|
44
|
+
# @schema_id = data['id']
|
45
|
+
# @schema_json = JSON.parse(data['schema']).to_json
|
46
|
+
end
|
47
|
+
puts "formatter_avro initializing with schema id #{@schema_id} json: #{@schema_json}"
|
48
|
+
@schema = Avro::Schema.parse(@schema_json)
|
49
|
+
end
|
50
|
+
|
51
|
+
def format(tag, time, record)
|
52
|
+
# <hack offender="rolabrie@cisco.com" technical_debt>
|
53
|
+
# We needed tags to be an array to satisfy the avro schema
|
54
|
+
# fluentd 0.12 doesn't support array type for record object attribs
|
55
|
+
# so instead of writing a whole new formatter plugin to handle this
|
56
|
+
# we're just clobbering it here -- therefore tags must be set
|
57
|
+
# which we are doing inside 990_transform.conf
|
58
|
+
|
59
|
+
record['tags'] = (record['tags'] || '').split(',')
|
60
|
+
# </hack>
|
61
|
+
|
62
|
+
# uncomment this when troubleshooting
|
63
|
+
# puts "formatter_avro handling type:#{record['type']} kafka_topic:#{record['kafka_topic']} payload:\n#{record['payload']}"
|
64
|
+
magic_byte = 0
|
65
|
+
dw = Avro::IO::DatumWriter.new(@schema)
|
66
|
+
buffer = StringIO.new
|
67
|
+
if @schema_url
|
68
|
+
# this only matters if using a schema registry
|
69
|
+
buffer.write(magic_byte.chr)
|
70
|
+
buffer.write([@schema_id].pack("I>"))
|
71
|
+
end
|
72
|
+
encoder = Avro::IO::BinaryEncoder.new(buffer)
|
73
|
+
eh = record.to_hash
|
74
|
+
dw.write(eh, encoder)
|
75
|
+
buffer.string
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
metadata
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: fluent-plugin-avro_deluxe
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Robert Labrie
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-10-25 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Fluentd avro formnatter - Do not use this unsupported module
|
14
|
+
email: rolabrie@cisco.com
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- lib/formatter_avro.rb
|
20
|
+
homepage:
|
21
|
+
licenses: []
|
22
|
+
metadata: {}
|
23
|
+
post_install_message:
|
24
|
+
rdoc_options: []
|
25
|
+
require_paths:
|
26
|
+
- lib
|
27
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
28
|
+
requirements:
|
29
|
+
- - ">="
|
30
|
+
- !ruby/object:Gem::Version
|
31
|
+
version: '0'
|
32
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
33
|
+
requirements:
|
34
|
+
- - ">="
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: '0'
|
37
|
+
requirements: []
|
38
|
+
rubyforge_project:
|
39
|
+
rubygems_version: 2.5.1
|
40
|
+
signing_key:
|
41
|
+
specification_version: 3
|
42
|
+
summary: Do not use this unsupported module
|
43
|
+
test_files: []
|