fluent-plugin-mysql-binlog 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in fluent-plugin-mysql-binlog.gemspec
4
+ gemspec
@@ -0,0 +1,13 @@
1
+ Copyright (c) 2013 IZUMIYA Hiroyuki
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.
@@ -0,0 +1,46 @@
1
+ fluent-plugin-mysql-binlog
2
+ ===========================
3
+
4
+ MySQL Binlog input plugin for Fluentd event collector.
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ gem 'fluent-plugin-mysql-binlog'
11
+
12
+ And then execute:
13
+
14
+ $ bundle
15
+
16
+ Or install it yourself as:
17
+
18
+ $ gem install fluent-plugin-mysql-binlog
19
+
20
+ ## Configuration
21
+
22
+ ### Config Sample
23
+ `````
24
+ <source>
25
+ type mysql_binlog
26
+ host localhost # Optional (default: localhost)
27
+ port 3306 # Optional (default: 3306)
28
+ username msandbox # Optional (default: root)
29
+ password msadnbox # Optional (default nopassword)
30
+ tag input.mysql # Required
31
+ position_file position.log # Optional (default: position.log)
32
+ retry_wait 3 # Optional (default: 3)
33
+ retry_limit 100 # Optional (default: 100)
34
+ log_level debug # Optional (default: info)
35
+ listen_event row_event # Optional (default: Fluent::MysqlBinlogInput::BinlogUtil::EVENT_TYPES.join(','))
36
+ </source>
37
+ `````
38
+
39
+
40
+ ## Contributing
41
+
42
+ 1. Fork it
43
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
44
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
45
+ 4. Push to the branch (`git push origin my-new-feature`)
46
+ 5. Create new Pull Request
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ require 'rake/testtask'
4
+ Rake::TestTask.new(:test) do |test|
5
+ test.libs << 'lib' << 'test'
6
+ test.pattern = 'test/**/test_*.rb'
7
+ test.verbose = true
8
+ end
9
+
10
+ task :default => :test
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "fluent-plugin-mysql-binlog"
7
+ spec.version = "0.0.2"
8
+ spec.authors = ["IZUMIYA Hiroyuki"]
9
+ spec.email = ["izumiya@gmail.com"]
10
+ spec.description = %q{MySQL Binlog input plugin for Fluentd event collector.}
11
+ spec.summary = %q{MySQL Binlog input plugin for Fluentd event collector.}
12
+ spec.homepage = "https://github.com/izumiya/fluent-plugin-mysql-binlog"
13
+
14
+ spec.files = `git ls-files`.split($/)
15
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
16
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
17
+ spec.require_paths = ["lib"]
18
+
19
+ spec.add_runtime_dependency "fluentd"
20
+ spec.add_runtime_dependency "kodama"
21
+ spec.add_runtime_dependency "activesupport"
22
+ spec.add_development_dependency "bundler", "~> 1.3"
23
+ spec.add_development_dependency "rake"
24
+ end
@@ -0,0 +1,102 @@
1
+ module Fluent
2
+
3
+ class MysqlBinlogInput < Input
4
+ Plugin.register_input('mysql_binlog', self)
5
+
6
+ def initialize
7
+ super
8
+ require 'kodama'
9
+ end
10
+
11
+ config_param :tag, :string
12
+ config_param :host, :string, :default => 'localhost'
13
+ config_param :port, :integer, :default => 3306
14
+ config_param :username, :string, :default => 'root'
15
+ config_param :password, :string, :default => nil
16
+ config_param :position_file, :string, :default => 'position.log'
17
+ config_param :retry_wait, :integer, :default => 3
18
+ config_param :retry_limit, :integer, :default => 100
19
+ config_param :log_level, :string, :default => 'info'
20
+ config_param :listen_event, :string, :default => nil
21
+
22
+ def configure(conf)
23
+ super
24
+ @listen_event ||= BinlogUtil::EVENT_TYPES.join(',')
25
+ @listen_events = @listen_event.split(',').map {|i| i.strip }
26
+ end
27
+
28
+ def start
29
+ $log.debug "listening mysql replication on #{mysql_url}"
30
+ @thread = Thread.new(&method(:run))
31
+ end
32
+
33
+ def shutdown
34
+ Thread.kill(@thread)
35
+ end
36
+
37
+ def run
38
+ Kodama::Client.start(mysql_url) do |c|
39
+ c.binlog_position_file = @position_file
40
+ c.connection_retry_limit = @retry_limit
41
+ c.connection_retry_wait = @retry_wait
42
+ c.log_level = @log_level.to_sym
43
+ c.gracefully_stop_on :QUIT, :INT
44
+ @listen_events.each do |event_type|
45
+ $log.trace { "registered binlog event listener '#{event_type}'" }
46
+ c.send("on_#{event_type}", &method(:event_listener))
47
+ end
48
+ end
49
+ end
50
+
51
+ def event_listener(event)
52
+ Engine.emit(@tag, Engine.now, BinlogUtil.to_hash(event))
53
+ end
54
+
55
+ def mysql_url
56
+ {
57
+ host: @host,
58
+ port: @port,
59
+ username: @username,
60
+ password: @password,
61
+ }
62
+ end
63
+
64
+ class BinlogUtil
65
+ require 'active_support'
66
+
67
+ EVENT_TYPES = %w(query_event rotate_event int_var_event user_var_event format_event xid table_map_event row_event incident_event unimplemented_event)
68
+
69
+ TYPE_ATTRIBUTES = {
70
+ base: %w(marker timestamp type_code server_id event_length next_position flags event_type),
71
+ format_event: %w(binlog_version created_ts log_header_len),
72
+ incident_event: %w(incident_type message),
73
+ int_var_event: %w(var_type value),
74
+ query_event: %w(thread_id exec_time error_code variables db_name query),
75
+ rotate_event: %w(binlog_file binlog_pos),
76
+ row_event: %w(table_id db_name table_name columns columns_len null_bits_len raw_columns_before_image raw_used_columns raw_row rows),
77
+ table_map_event: %w(table_id db_name table_name raw_columns columns metadata null_bits),
78
+ unimplemented_event: nil,
79
+ user_var_event: %w(name is_null var_type charset value),
80
+ xid: %w(xid_id),
81
+ }
82
+
83
+ class << self
84
+ def to_hash(event)
85
+ Hash[
86
+ attributes_for(event).map do |attr|
87
+ [attr, event.send(attr.to_sym)] rescue nil
88
+ end
89
+ ]
90
+ end
91
+
92
+ def attributes_for(event)
93
+ event_type = ActiveSupport::Inflector.underscore(
94
+ ActiveSupport::Inflector.demodulize(event.class)
95
+ ).gsub(/^on_/, '')
96
+ TYPE_ATTRIBUTES[:base] + (TYPE_ATTRIBUTES[event_type.to_sym] || [])
97
+ end
98
+ end
99
+ end
100
+
101
+ end
102
+ end
@@ -0,0 +1,28 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'test/unit'
11
+
12
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
13
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
14
+ require 'fluent/test'
15
+ unless ENV.has_key?('VERBOSE')
16
+ nulllogger = Object.new
17
+ nulllogger.instance_eval {|obj|
18
+ def method_missing(method, *args)
19
+ # pass
20
+ end
21
+ }
22
+ $log = nulllogger
23
+ end
24
+
25
+ require 'fluent/plugin/in_mysql_binlog'
26
+
27
+ class Test::Unit::TestCase
28
+ end
@@ -0,0 +1,49 @@
1
+ require 'helper'
2
+
3
+ module Dummy
4
+ class IntVarEvent
5
+ def var_type ; :var_type end
6
+ def value ; :value end
7
+ end
8
+ end
9
+
10
+ class MysqlBinlogInputTest < Test::Unit::TestCase
11
+ def setup
12
+ Fluent::Test.setup
13
+ end
14
+
15
+ CONFIG = %[
16
+ host localhost
17
+ port 3306
18
+ tag input.mysql
19
+ position_file position.log
20
+ listen_event row_event
21
+ ]
22
+
23
+ def create_driver(conf=CONFIG, tag='test')
24
+ Fluent::Test::OutputTestDriver.new(Fluent::MysqlBinlogInput, tag).configure(conf)
25
+ end
26
+
27
+ def test_configure
28
+ assert_raise(Fluent::ConfigError) {
29
+ d = create_driver('')
30
+ }
31
+ d = create_driver %[
32
+ host localhost
33
+ port 3306
34
+ tag input.mysql
35
+ position_file position.log
36
+ listen_event row_event
37
+ ]
38
+ assert_equal 'localhost', d.instance.host
39
+ assert_equal 3306, d.instance.port
40
+ assert_equal 'input.mysql', d.instance.tag
41
+ assert_equal 'row_event', d.instance.listen_event
42
+ end
43
+
44
+ def test_binlog_util
45
+ assert_not_nil Fluent::MysqlBinlogInput::BinlogUtil.to_hash(Dummy::IntVarEvent.new)
46
+ assert_not_nil Fluent::MysqlBinlogInput::BinlogUtil.attributes_for(:base)
47
+
48
+ end
49
+ end
metadata ADDED
@@ -0,0 +1,142 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fluent-plugin-mysql-binlog
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - IZUMIYA Hiroyuki
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-08-07 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: fluentd
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: kodama
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: activesupport
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: bundler
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ~>
68
+ - !ruby/object:Gem::Version
69
+ version: '1.3'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ version: '1.3'
78
+ - !ruby/object:Gem::Dependency
79
+ name: rake
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ description: MySQL Binlog input plugin for Fluentd event collector.
95
+ email:
96
+ - izumiya@gmail.com
97
+ executables: []
98
+ extensions: []
99
+ extra_rdoc_files: []
100
+ files:
101
+ - .gitignore
102
+ - Gemfile
103
+ - LICENSE.txt
104
+ - README.md
105
+ - Rakefile
106
+ - fluent-plugin-mysql-binlog.gemspec
107
+ - lib/fluent/plugin/in_mysql_binlog.rb
108
+ - test/helper.rb
109
+ - test/plugin/test_in_mysql_binlog.rb
110
+ homepage: https://github.com/izumiya/fluent-plugin-mysql-binlog
111
+ licenses: []
112
+ post_install_message:
113
+ rdoc_options: []
114
+ require_paths:
115
+ - lib
116
+ required_ruby_version: !ruby/object:Gem::Requirement
117
+ none: false
118
+ requirements:
119
+ - - ! '>='
120
+ - !ruby/object:Gem::Version
121
+ version: '0'
122
+ segments:
123
+ - 0
124
+ hash: -1109768793546365793
125
+ required_rubygems_version: !ruby/object:Gem::Requirement
126
+ none: false
127
+ requirements:
128
+ - - ! '>='
129
+ - !ruby/object:Gem::Version
130
+ version: '0'
131
+ segments:
132
+ - 0
133
+ hash: -1109768793546365793
134
+ requirements: []
135
+ rubyforge_project:
136
+ rubygems_version: 1.8.23
137
+ signing_key:
138
+ specification_version: 3
139
+ summary: MySQL Binlog input plugin for Fluentd event collector.
140
+ test_files:
141
+ - test/helper.rb
142
+ - test/plugin/test_in_mysql_binlog.rb