fluent-plugin-mysql-replicator 0.6.2 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7e0d8447f15a51520238bda787d9f00e1ffc2b17
4
- data.tar.gz: acd39ee14e5eca137189069f652b91baa23847e4
3
+ metadata.gz: e43736658fa9d53723c3f1a2089c46108016bc68
4
+ data.tar.gz: 187e611b52bfb740337041716f68cddfa879b433
5
5
  SHA512:
6
- metadata.gz: 2c8d1b8c80419b6b7b88540181b7a5d2c8b4cb8b5d7dca7489cfe9e163fdfa225cbc27ace78c31ffa7b198a54447ca1802a68c907d1a201ffd2e94b9c47123e1
7
- data.tar.gz: 1465dbf6119e9a07ca3e177d2825868fa34fe0f4382c1c676f004a38493dcb1fba4c97e52f4b6991273b49dda9f2e8210cd7ebc2ff84138c02d44c363b4ee10e
6
+ metadata.gz: c89083833cf2cf8e2ae7dadd472227744806700ba59803474b2f3d7a0451a3d1bb996014039a5ef75f2e4d3817403fd6fc13efac45ba03b0597f30b25bb75a8b
7
+ data.tar.gz: f127d31178d16bba47b133a537fb1f8f1c2df1813444b05898f712d97914bd8861f5381fa4a1c4ef6a2f7392980c908364ae6a6a7673aad5a825074a1addda61
data/README.md CHANGED
@@ -10,8 +10,8 @@ It's comming support replicate to another RDB/noSQL.
10
10
 
11
11
  | fluent-plugin-mysql-replicator | fluentd | ruby |
12
12
  |--------------------|------------|--------|
13
- | 0.6.2 | v0.14.x | >= 2.1 |
14
- | 0.6.2 | v0.12.x | >= 1.9 |
13
+ | >= 0.6.1 | >= v0.14.x | >= 2.1 |
14
+ | <= 0.6.1 | >= v0.12.x | >= 1.9 |
15
15
 
16
16
  ## Dependency
17
17
 
@@ -31,10 +31,10 @@ install with gem or fluent-gem command as:
31
31
 
32
32
  `````
33
33
  # for system installed fluentd
34
- $ gem install fluent-plugin-mysql-replicator -v 0.6.2
34
+ $ gem install fluent-plugin-mysql-replicator -v 0.6.1
35
35
 
36
36
  # for td-agent2
37
- $ sudo td-agent-gem install fluent-plugin-mysql-replicator -v 0.6.2
37
+ $ sudo td-agent-gem install fluent-plugin-mysql-replicator -v 0.6.1
38
38
  `````
39
39
 
40
40
  ## Included plugins
@@ -1,7 +1,7 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
  Gem::Specification.new do |s|
3
3
  s.name = "fluent-plugin-mysql-replicator"
4
- s.version = "0.6.2"
4
+ s.version = "1.0.0"
5
5
  s.authors = ["Kentaro Yoshida"]
6
6
  s.email = ["y.ken.studio@gmail.com"]
7
7
  s.homepage = "https://github.com/y-ken/fluent-plugin-mysql-replicator"
@@ -19,7 +19,7 @@ Gem::Specification.new do |s|
19
19
  s.add_development_dependency "webmock", "~> 1.24.0"
20
20
  s.add_development_dependency "test-unit", ">= 3.1.0"
21
21
 
22
- s.add_runtime_dependency "fluentd", [">= 0.10.58", "< 2"]
22
+ s.add_runtime_dependency "fluentd", [">= 0.14.15", "< 2"]
23
23
  s.add_runtime_dependency "mysql2"
24
24
  s.add_runtime_dependency "rsolr"
25
25
  end
@@ -1,14 +1,12 @@
1
- require 'fluent/input'
1
+ require 'mysql2'
2
+ require 'digest/sha1'
3
+ require 'fluent/plugin/input'
2
4
 
3
- module Fluent
4
- class MysqlReplicatorInput < Fluent::Input
5
- Plugin.register_input('mysql_replicator', self)
5
+ module Fluent::Plugin
6
+ class MysqlReplicatorInput < Fluent::Plugin::Input
7
+ Fluent::Plugin.register_input('mysql_replicator', self)
6
8
 
7
- def initialize
8
- require 'mysql2'
9
- require 'digest/sha1'
10
- super
11
- end
9
+ helpers :thread
12
10
 
13
11
  config_param :host, :string, :default => 'localhost'
14
12
  config_param :port, :integer, :default => 3306
@@ -25,7 +23,7 @@ module Fluent
25
23
 
26
24
  def configure(conf)
27
25
  super
28
- @interval = Config.time_value(@interval)
26
+ @interval = Fluent::Config.time_value(@interval)
29
27
 
30
28
  if @tag.nil?
31
29
  raise Fluent::ConfigError, "mysql_replicator: missing 'tag' parameter. Please add following line into config like 'tag replicator.mydatabase.mytable.${event}.${primary_key}'"
@@ -35,11 +33,12 @@ module Fluent
35
33
  end
36
34
 
37
35
  def start
38
- @thread = Thread.new(&method(:run))
36
+ super
37
+ thread_create(:in_mysql_replicator_runner, &method(:run))
39
38
  end
40
39
 
41
40
  def shutdown
42
- Thread.kill(@thread)
41
+ super
43
42
  end
44
43
 
45
44
  def run
@@ -107,7 +106,7 @@ module Fluent
107
106
  end
108
107
  if deleted_ids.count > 0
109
108
  hash_delete_by_list(table_hash, deleted_ids)
110
- deleted_ids.each do |id|
109
+ deleted_ids.each do |id|
111
110
  tag = format_tag(@tag, {:event => :delete})
112
111
  emit_record(tag, {@primary_key => id})
113
112
  end
@@ -1,8 +1,8 @@
1
1
  require 'fluent/input'
2
2
 
3
- module Fluent
3
+ module Fluent::Plugin
4
4
  class MysqlReplicatorMultiInput < Fluent::Input
5
- Plugin.register_input('mysql_replicator_multi', self)
5
+ Fluent::Plugin.register_input('mysql_replicator_multi', self)
6
6
 
7
7
  def initialize
8
8
  require 'mysql2'
@@ -28,18 +28,19 @@ module Fluent
28
28
  end
29
29
 
30
30
  def start
31
+ super
31
32
  begin
32
33
  @threads = []
33
34
  @mutex = Mutex.new
34
35
  @manager_db = get_manager_connection
35
36
  @manager_db.query("SET SESSION wait_timeout=1800;")
36
- @threads << Thread.new {
37
+ @threads << thread_create(:in_mysql_replicator_flusher) {
37
38
  @hash_table_bulk_insert = []
38
39
  @hash_table_bulk_insert_last_time = Time.now
39
40
  hash_table_flusher
40
41
  }
41
- get_settings.each do |config|
42
- @threads << Thread.new {
42
+ get_settings.each_with_index do |config, idx|
43
+ @threads << thread_create(:"in_mysql_replicator_pollers_#{idx}") {
43
44
  poll(config)
44
45
  }
45
46
  end
@@ -51,9 +52,7 @@ module Fluent
51
52
  end
52
53
 
53
54
  def shutdown
54
- @threads.each do |thread|
55
- Thread.kill(thread)
56
- end
55
+ super
57
56
  end
58
57
 
59
58
  def get_settings
@@ -106,9 +105,6 @@ module Fluent
106
105
  rows_count += 1
107
106
  end
108
107
  db.close
109
- unless config['prepared_query'].nil?
110
- nest_db.close
111
- end
112
108
  elapsed_time = sprintf("%0.02f", Time.now - start_time)
113
109
  @mutex.synchronize {
114
110
  log.info "mysql_replicator_multi: execution finished. :setting_name=>#{config['name']} :rows_count=>#{rows_count} :elapsed_time=>#{elapsed_time} sec"
@@ -1,9 +1,14 @@
1
1
  require 'net/http'
2
2
  require 'date'
3
+ require 'fluent/plugin/output'
3
4
 
4
- class Fluent::MysqlReplicatorElasticsearchOutput < Fluent::BufferedOutput
5
+ class Fluent::Plugin::MysqlReplicatorElasticsearchOutput < Fluent::Plugin::Output
5
6
  Fluent::Plugin.register_output('mysql_replicator_elasticsearch', self)
6
7
 
8
+ DEFAULT_BUFFER_TYPE = "memory"
9
+
10
+ helpers :compat_parameters
11
+
7
12
  config_param :host, :string, :default => 'localhost'
8
13
  config_param :port, :integer, :default => 9200
9
14
  config_param :tag_format, :string, :default => nil
@@ -11,6 +16,10 @@ class Fluent::MysqlReplicatorElasticsearchOutput < Fluent::BufferedOutput
11
16
  config_param :username, :string, :default => nil
12
17
  config_param :password, :string, :default => nil, :secret => true
13
18
 
19
+ config_section :buffer do
20
+ config_set_default :@type, DEFAULT_BUFFER_TYPE
21
+ end
22
+
14
23
  DEFAULT_TAG_FORMAT = /(?<index_name>[^\.]+)\.(?<type_name>[^\.]+)\.(?<event>[^\.]+)\.(?<primary_key>[^\.]+)$/
15
24
 
16
25
  def initialize
@@ -39,6 +48,14 @@ class Fluent::MysqlReplicatorElasticsearchOutput < Fluent::BufferedOutput
39
48
  super
40
49
  end
41
50
 
51
+ def multi_workers_ready?
52
+ true
53
+ end
54
+
55
+ def formatted_to_msgpack_binary?
56
+ true
57
+ end
58
+
42
59
  def write(chunk)
43
60
  bulk_message = []
44
61
 
@@ -1,13 +1,22 @@
1
1
  require 'rsolr'
2
2
  require 'uri'
3
+ require 'fluent/plugin/output'
3
4
 
4
- class Fluent::MysqlReplicatorSolrOutput < Fluent::BufferedOutput
5
+ class Fluent::Plugin::MysqlReplicatorSolrOutput < Fluent::Plugin::Output
5
6
  Fluent::Plugin.register_output('mysql_replicator_solr', self)
6
7
 
8
+ DEFAULT_BUFFER_TYPE = "memory"
9
+
10
+ helpers :compat_parameters
11
+
7
12
  config_param :host, :string, :default => 'localhost'
8
13
  config_param :port, :integer, :default => 8983
9
14
  config_param :tag_format, :string, :default => nil
10
15
 
16
+ config_section :buffer do
17
+ config_set_default :@type, DEFAULT_BUFFER_TYPE
18
+ end
19
+
11
20
  DEFAULT_TAG_FORMAT = /(?<core_name>[^\.]+)\.(?<event>[^\.]+)\.(?<primary_key>[^\.]+)$/
12
21
 
13
22
  def initialize
@@ -36,6 +45,14 @@ class Fluent::MysqlReplicatorSolrOutput < Fluent::BufferedOutput
36
45
  super
37
46
  end
38
47
 
48
+ def multi_workers_ready?
49
+ true
50
+ end
51
+
52
+ def formatted_to_msgpack_binary?
53
+ true
54
+ end
55
+
39
56
  def write(chunk)
40
57
  solr_connection = {}
41
58
 
@@ -1,4 +1,5 @@
1
1
  require 'helper'
2
+ require 'fluent/test/driver/input'
2
3
 
3
4
  class MysqlReplicatorInputTest < Test::Unit::TestCase
4
5
  def setup
@@ -14,8 +15,8 @@ class MysqlReplicatorInputTest < Test::Unit::TestCase
14
15
  record_hostname yes
15
16
  ]
16
17
 
17
- def create_driver(conf=CONFIG,tag='test')
18
- Fluent::Test::OutputTestDriver.new(Fluent::MysqlReplicatorInput, tag).configure(conf)
18
+ def create_driver(conf=CONFIG)
19
+ Fluent::Test::Driver::Input.new(Fluent::Plugin::MysqlReplicatorInput).configure(conf)
19
20
  end
20
21
 
21
22
  def test_configure
@@ -1,4 +1,5 @@
1
1
  require 'helper'
2
+ require 'fluent/test/driver/input'
2
3
 
3
4
  class MysqlReplicatorMultiInputTest < Test::Unit::TestCase
4
5
  def setup
@@ -13,8 +14,8 @@ class MysqlReplicatorMultiInputTest < Test::Unit::TestCase
13
14
  tag replicator.${name}.${event}.${primary_key}
14
15
  ]
15
16
 
16
- def create_driver(conf=CONFIG,tag='test')
17
- Fluent::Test::OutputTestDriver.new(Fluent::MysqlReplicatorMultiInput, tag).configure(conf)
17
+ def create_driver(conf=CONFIG)
18
+ Fluent::Test::Driver::Input.new(Fluent::Plugin::MysqlReplicatorMultiInput).configure(conf)
18
19
  end
19
20
 
20
21
  def test_configure
@@ -1,4 +1,5 @@
1
1
  require 'helper'
2
+ require 'fluent/test/driver/output'
2
3
  require 'webmock/test_unit'
3
4
 
4
5
  WebMock.disable_net_connect!
@@ -9,10 +10,11 @@ class MysqlReplicatorElasticsearchOutput < Test::Unit::TestCase
9
10
  def setup
10
11
  Fluent::Test.setup
11
12
  @driver = nil
13
+ @tag = 'myindex.mytype.insert.id'
12
14
  end
13
15
 
14
- def driver(tag='myindex.mytype.insert.id', conf='')
15
- @driver ||= Fluent::Test::BufferedOutputTestDriver.new(Fluent::MysqlReplicatorElasticsearchOutput, tag).configure(conf)
16
+ def driver(conf='')
17
+ @driver ||= Fluent::Test::Driver::Output.new(Fluent::Plugin::MysqlReplicatorElasticsearchOutput).configure(conf)
16
18
  end
17
19
 
18
20
  def sample_record
@@ -32,56 +34,63 @@ class MysqlReplicatorElasticsearchOutput < Test::Unit::TestCase
32
34
 
33
35
  def test_wrties_with_proper_content_type
34
36
  stub_elastic
35
- driver.emit(sample_record)
36
- driver.run
37
+ driver.run(default_tag: @tag) do
38
+ driver.feed(sample_record)
39
+ end
37
40
  assert_equal("application/json; charset=utf-8", @content_type)
38
41
  end
39
42
 
40
43
  def test_writes_to_speficied_index
41
44
  driver.configure("index_name myindex\n")
42
45
  stub_elastic
43
- driver.emit(sample_record)
44
- driver.run
46
+ driver.run(default_tag: @tag) do
47
+ driver.feed(sample_record)
48
+ end
45
49
  assert_equal('myindex', index_cmds.first['index']['_index'])
46
50
  end
47
51
 
48
52
  def test_writes_to_speficied_type
49
53
  driver.configure("type_name mytype\n")
50
54
  stub_elastic
51
- driver.emit(sample_record)
52
- driver.run
55
+ driver.run(default_tag: @tag) do
56
+ driver.feed(sample_record)
57
+ end
53
58
  assert_equal('mytype', index_cmds.first['index']['_type'])
54
59
  end
55
60
 
56
61
  def test_writes_to_speficied_host
57
62
  driver.configure("host 192.168.33.50\n")
58
63
  elastic_request = stub_elastic("http://192.168.33.50:9200/_bulk")
59
- driver.emit(sample_record)
60
- driver.run
64
+ driver.run(default_tag: @tag) do
65
+ driver.feed(sample_record)
66
+ end
61
67
  assert_requested(elastic_request)
62
68
  end
63
69
 
64
70
  def test_writes_to_speficied_port
65
71
  driver.configure("port 9201\n")
66
72
  elastic_request = stub_elastic("http://localhost:9201/_bulk")
67
- driver.emit(sample_record)
68
- driver.run
73
+ driver.run(default_tag: @tag) do
74
+ driver.feed(sample_record)
75
+ end
69
76
  assert_requested(elastic_request)
70
77
  end
71
78
 
72
79
  def test_makes_bulk_request
73
80
  stub_elastic
74
- driver.emit(sample_record)
75
- driver.emit(sample_record.merge('age' => 27))
76
- driver.run
81
+ driver.run(default_tag: @tag) do
82
+ driver.feed(sample_record)
83
+ driver.feed(sample_record.merge('age' => 27))
84
+ end
77
85
  assert_equal(4, index_cmds.count)
78
86
  end
79
87
 
80
88
  def test_all_records_are_preserved_in_bulk
81
89
  stub_elastic
82
- driver.emit(sample_record)
83
- driver.emit(sample_record.merge('age' => 27))
84
- driver.run
90
+ driver.run(default_tag: @tag) do
91
+ driver.feed(sample_record)
92
+ driver.feed(sample_record.merge('age' => 27))
93
+ end
85
94
  assert_equal(26, index_cmds[1]['age'])
86
95
  assert_equal(27, index_cmds[3]['age'])
87
96
  end
@@ -89,47 +98,53 @@ class MysqlReplicatorElasticsearchOutput < Test::Unit::TestCase
89
98
 
90
99
  def test_doesnt_add_logstash_timestamp_by_default
91
100
  stub_elastic
92
- driver.emit(sample_record)
93
- driver.run
101
+ driver.run(default_tag: @tag) do
102
+ driver.feed(sample_record)
103
+ end
94
104
  assert_nil(index_cmds[1]['@timestamp'])
95
105
  end
96
106
 
97
107
 
98
108
  def test_doesnt_add_tag_key_by_default
99
109
  stub_elastic
100
- driver.emit(sample_record)
101
- driver.run
110
+ driver.run(default_tag: @tag) do
111
+ driver.feed(sample_record)
112
+ end
102
113
  assert_nil(index_cmds[1]['tag'])
103
114
  end
104
115
 
105
116
  def test_doesnt_add_id_key_if_missing_when_configured
106
117
  driver.configure("id_key another_request_id\n")
107
118
  stub_elastic
108
- driver.emit(sample_record)
109
- driver.run
119
+ driver.run(default_tag: @tag) do
120
+ driver.feed(sample_record)
121
+ end
110
122
  assert(!index_cmds[0]['index'].has_key?('_id'))
111
123
  end
112
124
 
113
125
  def test_adds_id_key_when_not_configured
114
126
  stub_elastic
115
- driver.emit(sample_record)
116
- driver.run
127
+ driver.run(default_tag: @tag) do
128
+ driver.feed(sample_record)
129
+ end
117
130
  assert(!index_cmds[0]['index'].has_key?('_id'))
118
131
  end
119
132
 
120
133
  def test_request_error
121
134
  stub_elastic_unavailable
122
- driver.emit(sample_record)
123
135
  assert_raise(Net::HTTPFatalError) {
124
- driver.run
136
+ driver.run(default_tag: @tag) do
137
+ driver.feed(sample_record)
138
+ end
125
139
  }
126
140
  end
127
141
 
128
142
  def test_writes_to_https_host
129
143
  driver.configure("ssl true\n")
130
144
  elastic_request = stub_elastic("https://localhost:9200/_bulk")
131
- driver.emit(sample_record)
132
- driver.run
145
+ driver.run(default_tag: @tag) do
146
+ driver.feed(sample_record)
147
+ end
133
148
  assert_requested(elastic_request)
134
149
  end
135
150
 
@@ -139,8 +154,9 @@ class MysqlReplicatorElasticsearchOutput < Test::Unit::TestCase
139
154
  password bar\n
140
155
  ])
141
156
  elastic_request = stub_elastic("http://foo:bar@localhost:9200/_bulk")
142
- driver.emit(sample_record)
143
- driver.run
157
+ driver.run(default_tag: @tag) do
158
+ driver.feed(sample_record)
159
+ end
144
160
  assert_requested(elastic_request)
145
161
  end
146
162
 
@@ -150,9 +166,10 @@ class MysqlReplicatorElasticsearchOutput < Test::Unit::TestCase
150
166
  password bar\n
151
167
  ])
152
168
  elastic_request = stub_elastic("http://foo:bar@localhost:9200/_bulk")
153
- driver.emit(sample_record)
154
169
  assert_raise(WebMock::NetConnectNotAllowedError) {
155
- driver.run
170
+ driver.run(default_tag: @tag) do
171
+ driver.feed(sample_record)
172
+ end
156
173
  }
157
174
  end
158
175
  end
@@ -1,4 +1,5 @@
1
1
  require 'helper'
2
+ require 'fluent/test/driver/output'
2
3
 
3
4
  class MysqlReplicatorSolrOutput < Test::Unit::TestCase
4
5
 
@@ -12,8 +13,8 @@ class MysqlReplicatorSolrOutput < Test::Unit::TestCase
12
13
  tag_format (?<core_name>[^\.]+)\.(?<event>[^\.]+)\.(?<primary_key>[^\.]+)$
13
14
  ]
14
15
 
15
- def create_driver(conf=CONFIG,tag='test')
16
- Fluent::Test::OutputTestDriver.new(Fluent::MysqlReplicatorSolrOutput, tag).configure(conf)
16
+ def create_driver(conf=CONFIG)
17
+ Fluent::Test::Driver::Output.new(Fluent::Plugin::MysqlReplicatorSolrOutput).configure(conf)
17
18
  end
18
19
 
19
20
  def test_configure
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-mysql-replicator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.2
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kentaro Yoshida
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-11-19 00:00:00.000000000 Z
11
+ date: 2019-11-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -58,7 +58,7 @@ dependencies:
58
58
  requirements:
59
59
  - - ">="
60
60
  - !ruby/object:Gem::Version
61
- version: 0.10.58
61
+ version: 0.14.15
62
62
  - - "<"
63
63
  - !ruby/object:Gem::Version
64
64
  version: '2'
@@ -68,7 +68,7 @@ dependencies:
68
68
  requirements:
69
69
  - - ">="
70
70
  - !ruby/object:Gem::Version
71
- version: 0.10.58
71
+ version: 0.14.15
72
72
  - - "<"
73
73
  - !ruby/object:Gem::Version
74
74
  version: '2'