fluent-plugin-rds-slowlog 0.0.5 → 0.0.6

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 8f911129eaa88bdb7e6637df787ccfb7b5c42a9d
4
+ data.tar.gz: 3889a1524f662e638f104adce831750700481b64
5
+ SHA512:
6
+ metadata.gz: ffc66003262cb3c9c7492835064f7e4fa8e7e0e25575eb3d596a96aa54349cf61f75441aee4bc3179a59c419fab4da509b8ebcaf191d86e435edc8bca233972c
7
+ data.tar.gz: d5c3bd047eb583eae7073a038b123d99943dc4057b760cf432558a38a4fc881acdaa4ae3484b5d795ef91705c078eacb65500761bb563f145d987ff2660d4aa0
data/.travis.yml CHANGED
@@ -4,5 +4,7 @@ rvm:
4
4
  - 1.9.2
5
5
  - 1.9.3
6
6
  - 2.0.0
7
+ - 2.1
8
+ - 2.2
7
9
 
8
10
  script: bundle exec rake test
data/README.md CHANGED
@@ -10,10 +10,10 @@
10
10
  - setting `long_query_time`
11
11
 
12
12
  ## Overview
13
- ***AWS RDS slow_log*** input plugin.
13
+ ***AWS RDS slow_log*** input plugin.
14
14
 
15
- 1. **"SELECT * FROM slow_log"**
16
- 2. **"CALL mysql.rds_rotate_slow_log"**
15
+ 1. **"CALL mysql.rds_rotate_slow_log"**
16
+ 2. **"SELECT * FROM slow_log_backup"**
17
17
 
18
18
  every 10 seconds from AWS RDS.
19
19
 
@@ -38,6 +38,7 @@ every 10 seconds from AWS RDS.
38
38
  host [RDS Hostname]
39
39
  username [RDS Username]
40
40
  password [RDS Password]
41
+ interval 10
41
42
  </source>
42
43
 
43
44
  <match rds-slowlog>
@@ -4,9 +4,9 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |gem|
6
6
  gem.name = "fluent-plugin-rds-slowlog"
7
- gem.version = "0.0.5"
8
- gem.authors = ["kenjiskywalker"]
9
- gem.email = ["git@kenjiskywalker.org"]
7
+ gem.version = "0.0.6"
8
+ gem.authors = ["kenjiskywalker", "winebarrel"]
9
+ gem.email = ["git@kenjiskywalker.org", "sgwr_dts@yahoo.co.jp"]
10
10
  gem.description = "Amazon RDS slow_log input plugin for Fluent event collector"
11
11
  gem.homepage = "https://github.com/kenjiskywalker/fluent-plugin-rds-slowlog"
12
12
  gem.summary = gem.description
@@ -14,7 +14,15 @@ Gem::Specification.new do |gem|
14
14
  gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
15
15
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
16
16
  gem.require_paths = ["lib"]
17
- gem.add_dependency "fluentd", "~> 0.10.30"
17
+
18
+ if RUBY_VERSION >= '1.9.3'
19
+ gem.add_dependency "fluentd"
20
+ else
21
+ gem.add_dependency "fluentd", "<= 0.10.55"
22
+ end
23
+
18
24
  gem.add_dependency "mysql2", "~> 0.3.11"
19
25
  gem.add_development_dependency "rake", ">= 10.0.4"
26
+ gem.add_development_dependency "test-unit", "~> 3.1.3"
27
+ gem.add_development_dependency "timecop"
20
28
  end
@@ -6,11 +6,17 @@ class Fluent::Rds_SlowlogInput < Fluent::Input
6
6
  define_method("log") { $log }
7
7
  end
8
8
 
9
+ # Define `router` method of v0.12 to support v0.10 or earlier
10
+ unless method_defined?(:router)
11
+ define_method("router") { Fluent::Engine }
12
+ end
13
+
9
14
  config_param :tag, :string
10
15
  config_param :host, :string, :default => nil
11
16
  config_param :port, :integer, :default => 3306
12
17
  config_param :username, :string, :default => nil
13
- config_param :password, :string, :default => nil
18
+ config_param :password, :string, :default => nil, :secret => true
19
+ config_param :interval, :integer, :default => 10
14
20
 
15
21
  def initialize
16
22
  super
@@ -34,6 +40,9 @@ class Fluent::Rds_SlowlogInput < Fluent::Input
34
40
 
35
41
  def start
36
42
  super
43
+ @loop = Coolio::Loop.new
44
+ timer = TimerWatcher.new(@interval, true, log, &method(:output))
45
+ @loop.attach(timer)
37
46
  @watcher = Thread.new(&method(:watch))
38
47
  end
39
48
 
@@ -45,21 +54,36 @@ class Fluent::Rds_SlowlogInput < Fluent::Input
45
54
 
46
55
  private
47
56
  def watch
48
- while true
49
- sleep 10
50
- output
51
- end
57
+ @loop.run
58
+ rescue => e
59
+ log.error(e.message)
60
+ log.error_backtrace(e.backtrace)
52
61
  end
53
62
 
54
63
  def output
64
+ @client.query('CALL mysql.rds_rotate_slow_log')
65
+
55
66
  slow_log_data = []
56
- slow_log_data = @client.query('SELECT * FROM slow_log', :cast => false)
67
+ slow_log_data = @client.query('SELECT * FROM slow_log_backup', :cast => false)
57
68
 
58
69
  slow_log_data.each do |row|
59
70
  row.each_key {|key| row[key].force_encoding(Encoding::ASCII_8BIT) if row[key].is_a?(String)}
60
- Fluent::Engine.emit(tag, Fluent::Engine.now, row)
71
+ router.emit(tag, Fluent::Engine.now, row)
61
72
  end
73
+ end
62
74
 
63
- @client.query('CALL mysql.rds_rotate_slow_log')
75
+ class TimerWatcher < Coolio::TimerWatcher
76
+ def initialize(interval, repeat, log, &callback)
77
+ @callback = callback
78
+ @log = log
79
+ super(interval, repeat)
80
+ end
81
+
82
+ def on_timer
83
+ @callback.call
84
+ rescue => e
85
+ @log.error(e.message)
86
+ @log.error_backtrace(e.backtrace)
87
+ end
64
88
  end
65
89
  end
data/test/helper.rb CHANGED
@@ -9,6 +9,8 @@ rescue Bundler::BundlerError => e
9
9
  exit e.status_code
10
10
  end
11
11
  require "test/unit"
12
+ require "mysql2"
13
+ require "timecop"
12
14
 
13
15
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), "..", "lib"))
14
16
  $LOAD_PATH.unshift(File.dirname(__FILE__))
@@ -1,8 +1,84 @@
1
1
  require 'helper'
2
2
 
3
3
  class Rds_SlowlogInputTest < Test::Unit::TestCase
4
+ class << self
5
+ def startup
6
+ setup_database
7
+ Timecop.freeze(Time.parse('2015/05/24 18:30 UTC'))
8
+ end
9
+
10
+ def shutdown
11
+ cleanup_database
12
+ end
13
+
14
+ def setup_database
15
+ client = mysql2_client
16
+ client.query("GRANT ALL ON *.* TO test_rds_user@localhost IDENTIFIED BY 'test_rds_password'")
17
+
18
+ client.query <<-EOS
19
+ CREATE PROCEDURE `mysql`.`rds_rotate_slow_log`()
20
+ BEGIN
21
+ DECLARE sql_logging BOOLEAN;
22
+ select @@sql_log_bin into sql_logging;
23
+ set @@sql_log_bin=off;
24
+ CREATE TABLE IF NOT EXISTS mysql.slow_log2 LIKE mysql.slow_log;
25
+
26
+ #{insert_slow_log_sql}
27
+
28
+ DROP TABLE IF EXISTS mysql.slow_log_backup;
29
+ RENAME TABLE mysql.slow_log TO mysql.slow_log_backup, mysql.slow_log2 TO mysql.slow_log;
30
+ set @@sql_log_bin=sql_logging;
31
+ END
32
+ EOS
33
+ end
34
+
35
+ def cleanup_database
36
+ client = mysql2_client
37
+ client.query("DROP USER test_rds_user@localhost")
38
+ client.query("DROP PROCEDURE `mysql`.`rds_rotate_slow_log`")
39
+ end
40
+
41
+ def insert_slow_log_sql
42
+ if has_thread_id?
43
+ <<-EOS
44
+ INSERT INTO `mysql`.`slow_log2` (
45
+ `start_time`, `user_host`, `query_time`, `lock_time`, `rows_sent`, `rows_examined`, `db`, `last_insert_id`, `insert_id`, `server_id`, `sql_text`, `thread_id`)
46
+ VALUES
47
+ ('2015-09-29 15:43:44', 'root@localhost', '00:00:00', '00:00:00', 0, 0, 'employees', 0, 0, 1, 'SELECT 1', 0)
48
+ ,('2015-09-29 15:43:45', 'root@localhost', '00:00:00', '00:00:00', 0, 0, 'employees', 0, 0, 1, 'SELECT 2', 0)
49
+ ;
50
+ EOS
51
+ else
52
+ <<-EOS
53
+ INSERT INTO `mysql`.`slow_log2` (
54
+ `start_time`, `user_host`, `query_time`, `lock_time`, `rows_sent`, `rows_examined`, `db`, `last_insert_id`, `insert_id`, `server_id`, `sql_text`)
55
+ VALUES
56
+ ('2015-09-29 15:43:44', 'root@localhost', '00:00:00', '00:00:00', 0, 0, 'employees', 0, 0, 1, 'SELECT 1')
57
+ ,('2015-09-29 15:43:45', 'root@localhost', '00:00:00', '00:00:00', 0, 0, 'employees', 0, 0, 1, 'SELECT 2')
58
+ ;
59
+ EOS
60
+ end
61
+ end
62
+
63
+ def has_thread_id?
64
+ client = mysql2_client
65
+ fields = client.query("SHOW FULL FIELDS FROM `mysql`.`slow_log`").map {|r| r['Field'] }
66
+ fields.include?('thread_id')
67
+ end
68
+
69
+ def mysql2_client
70
+ Mysql2::Client.new(:username => 'root')
71
+ end
72
+ end
73
+
74
+ def rotate_slow_log
75
+ client = self.class.mysql2_client
76
+ client.query("CALL `mysql`.`rds_rotate_slow_log`")
77
+ end
78
+
4
79
  def setup
5
80
  Fluent::Test.setup
81
+ rotate_slow_log
6
82
  end
7
83
 
8
84
  CONFIG = %[
@@ -10,6 +86,7 @@ class Rds_SlowlogInputTest < Test::Unit::TestCase
10
86
  host localhost
11
87
  username test_rds_user
12
88
  password test_rds_password
89
+ interval 0
13
90
  ]
14
91
 
15
92
  def create_driver(conf = CONFIG)
@@ -22,6 +99,21 @@ class Rds_SlowlogInputTest < Test::Unit::TestCase
22
99
  assert_equal 'localhost', d.instance.host
23
100
  assert_equal 'test_rds_user', d.instance.username
24
101
  assert_equal 'test_rds_password', d.instance.password
102
+ assert_equal 0, d.instance.interval
25
103
  end
26
104
 
105
+ def test_output
106
+ d = create_driver
107
+ d.run
108
+ records = d.emits
109
+
110
+ unless self.class.has_thread_id?
111
+ records.each {|r| r[2]["thread_id"] = "0" }
112
+ end
113
+
114
+ assert_equal [
115
+ ["rds-slowlog", 1432492200, {"start_time"=>"2015-09-29 15:43:44", "user_host"=>"root@localhost", "query_time"=>"00:00:00", "lock_time"=>"00:00:00", "rows_sent"=>"0", "rows_examined"=>"0", "db"=>"employees", "last_insert_id"=>"0", "insert_id"=>"0", "server_id"=>"1", "sql_text"=>"SELECT 1", "thread_id"=>"0"}],
116
+ ["rds-slowlog", 1432492200, {"start_time"=>"2015-09-29 15:43:45", "user_host"=>"root@localhost", "query_time"=>"00:00:00", "lock_time"=>"00:00:00", "rows_sent"=>"0", "rows_examined"=>"0", "db"=>"employees", "last_insert_id"=>"0", "insert_id"=>"0", "server_id"=>"1", "sql_text"=>"SELECT 2", "thread_id"=>"0"}],
117
+ ], records
118
+ end
27
119
  end
metadata CHANGED
@@ -1,73 +1,96 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-rds-slowlog
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
5
- prerelease:
4
+ version: 0.0.6
6
5
  platform: ruby
7
6
  authors:
8
7
  - kenjiskywalker
8
+ - winebarrel
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-02-05 00:00:00.000000000 Z
12
+ date: 2015-10-13 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: fluentd
16
16
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
17
  requirements:
19
- - - ~>
18
+ - - ">="
20
19
  - !ruby/object:Gem::Version
21
- version: 0.10.30
20
+ version: '0'
22
21
  type: :runtime
23
22
  prerelease: false
24
23
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
24
  requirements:
27
- - - ~>
25
+ - - ">="
28
26
  - !ruby/object:Gem::Version
29
- version: 0.10.30
27
+ version: '0'
30
28
  - !ruby/object:Gem::Dependency
31
29
  name: mysql2
32
30
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
31
  requirements:
35
- - - ~>
32
+ - - "~>"
36
33
  - !ruby/object:Gem::Version
37
34
  version: 0.3.11
38
35
  type: :runtime
39
36
  prerelease: false
40
37
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
38
  requirements:
43
- - - ~>
39
+ - - "~>"
44
40
  - !ruby/object:Gem::Version
45
41
  version: 0.3.11
46
42
  - !ruby/object:Gem::Dependency
47
43
  name: rake
48
44
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
45
  requirements:
51
- - - ! '>='
46
+ - - ">="
52
47
  - !ruby/object:Gem::Version
53
48
  version: 10.0.4
54
49
  type: :development
55
50
  prerelease: false
56
51
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
52
  requirements:
59
- - - ! '>='
53
+ - - ">="
60
54
  - !ruby/object:Gem::Version
61
55
  version: 10.0.4
56
+ - !ruby/object:Gem::Dependency
57
+ name: test-unit
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - "~>"
61
+ - !ruby/object:Gem::Version
62
+ version: 3.1.3
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - "~>"
68
+ - !ruby/object:Gem::Version
69
+ version: 3.1.3
70
+ - !ruby/object:Gem::Dependency
71
+ name: timecop
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
62
84
  description: Amazon RDS slow_log input plugin for Fluent event collector
63
85
  email:
64
86
  - git@kenjiskywalker.org
87
+ - sgwr_dts@yahoo.co.jp
65
88
  executables: []
66
89
  extensions: []
67
90
  extra_rdoc_files: []
68
91
  files:
69
- - .gitignore
70
- - .travis.yml
92
+ - ".gitignore"
93
+ - ".travis.yml"
71
94
  - Gemfile
72
95
  - LICENSE.txt
73
96
  - README.md
@@ -78,27 +101,26 @@ files:
78
101
  - test/plugin/test_in_rds_slowlog.rb
79
102
  homepage: https://github.com/kenjiskywalker/fluent-plugin-rds-slowlog
80
103
  licenses: []
104
+ metadata: {}
81
105
  post_install_message:
82
106
  rdoc_options: []
83
107
  require_paths:
84
108
  - lib
85
109
  required_ruby_version: !ruby/object:Gem::Requirement
86
- none: false
87
110
  requirements:
88
- - - ! '>='
111
+ - - ">="
89
112
  - !ruby/object:Gem::Version
90
113
  version: '0'
91
114
  required_rubygems_version: !ruby/object:Gem::Requirement
92
- none: false
93
115
  requirements:
94
- - - ! '>='
116
+ - - ">="
95
117
  - !ruby/object:Gem::Version
96
118
  version: '0'
97
119
  requirements: []
98
120
  rubyforge_project:
99
- rubygems_version: 1.8.23
121
+ rubygems_version: 2.4.5
100
122
  signing_key:
101
- specification_version: 3
123
+ specification_version: 4
102
124
  summary: Amazon RDS slow_log input plugin for Fluent event collector
103
125
  test_files:
104
126
  - test/helper.rb