fluent-plugin-rds-slowlog-patched-encoding 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c2ac7cb942fdacb8789452243427f26db03972c2
4
+ data.tar.gz: 7283d0359b7d3b923f8f613105ffa26d356f96e6
5
+ SHA512:
6
+ metadata.gz: 3d8e4f7595435046a837ee30c862c733d1a3e7a156a490fc6a9e1ace339e68e2751a841c789cd05918f88c9e260d04174d578a86ad887b2e741e1677f3c55ae5
7
+ data.tar.gz: 3cfa0434f6370aaeb53743e60b6878ed6ae2fc695d448412d8b060bee6f92261ed7ff987be2df3aa8376f62e174fe0eb65f6f943673fbe60933bd222cfb02486
@@ -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
@@ -0,0 +1,11 @@
1
+ language: ruby
2
+
3
+ rvm:
4
+ - 1.9.2
5
+ - 1.9.3
6
+ - 2.0.0
7
+ - 2.1
8
+ - 2.2
9
+
10
+ script: bundle exec rake test
11
+ before_install: gem update bundler
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in fluent-plugin-rds-slowlog.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 kenjiskywalker
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,98 @@
1
+ # fluent-plugin-rds-slowlog [![Build Status](https://travis-ci.org/kenjiskywalker/fluent-plugin-rds-slowlog.png)](https://travis-ci.org/kenjiskywalker/fluent-plugin-rds-slowlog/)
2
+
3
+
4
+ ## RDS Setting
5
+
6
+ [Working with MySQL Database Log Files / aws documentation](http://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_LogAccess.Concepts.MySQL.html)
7
+
8
+ - Set the `slow_query_log` parameter to `1`
9
+ - setting `min_examined_row_limit`
10
+ - setting `long_query_time`
11
+
12
+ ## Overview
13
+ ***AWS RDS slow_log*** input plugin.
14
+
15
+ 1. **"CALL mysql.rds_rotate_slow_log"**
16
+ 2. **"SELECT * FROM slow_log_backup"**
17
+ 3. **"INSERT INTO yourdb.slow_log_custom_backup SELECT * FROM slow_log_backup"** (if you want to take a backup)
18
+
19
+ every 10 seconds from AWS RDS.
20
+
21
+ ## Configuration
22
+
23
+ ```config
24
+ <source>
25
+ type rds_slowlog
26
+ tag rds-slowlog
27
+ host [RDS Hostname]
28
+ username [RDS Username]
29
+ password [RDS Password]
30
+ backup_table [Your Backup Tablename]
31
+ </source>
32
+ ```
33
+
34
+ ### Example: GET RDS slow_log
35
+
36
+ ```config
37
+ <source>
38
+ type rds_slowlog
39
+ tag rds-slowlog
40
+ host [RDS Hostname]
41
+ username [RDS Username]
42
+ password [RDS Password]
43
+ interval 10
44
+ backup_table [Your Backup Tablename]
45
+ </source>
46
+
47
+ <match rds-slowlog>
48
+ type copy
49
+ <store>
50
+ type file
51
+ path /var/log/slow_log
52
+ </store>
53
+ </match>
54
+ ```
55
+
56
+ #### output data format
57
+
58
+ ```
59
+ 2013-03-08T16:04:43+09:00 rds-slowlog {"start_time":"2013-03-08 07:04:38","user_host":"rds_db[rds_db] @ [192.0.2.10]","query_time":"00:00:00","lock_time":"00:00:00","rows_sent":"3000","rows_examined":"3000","db":"rds_db","last_insert_id":"0","insert_id":"0","server_id":"100000000","sql_text":"select foo from bar"}
60
+ 2013-03-08T16:04:43+09:00 rds-slowlog {"start_time":"2013-03-08 07:04:38","user_host":"rds_db[rds_db] @ [192.0.2.10]","query_time":"00:00:00","lock_time":"00:00:00","rows_sent":"3000","rows_examined":"3000","db":"rds_db","last_insert_id":"0","insert_id":"0","server_id":"100000000","sql_text":"Quit"}
61
+ ```
62
+
63
+ #### if not connect
64
+
65
+ - td-agent.log
66
+
67
+ ```
68
+ 2013-06-29 00:32:55 +0900 [error]: fluent-plugin-rds-slowlog: cannot connect RDS
69
+ ```
70
+
71
+ ### Example: Encode output string
72
+
73
+ Specify the encoding of output string. The default is ASCII-8BIT.
74
+
75
+ ```config
76
+ <source>
77
+ ...
78
+ encoding UTF-8
79
+ </source>
80
+ ```
81
+
82
+ - If specify only encoding, the plugin changes string to encoding. This use ruby's [String#force_encoding](https://docs.ruby-lang.org/en/trunk/String.html#method-i-force_encoding)
83
+
84
+ ```config
85
+ <source>
86
+ ...
87
+ encoding CP932
88
+ from_encoding UTF-8
89
+ </source>
90
+ ```
91
+
92
+ - If specify encoding and from_encoding, the plugin tries to encode string from from_encoding to encoding. This uses ruby's [String#encode](https://docs.ruby-lang.org/en/trunk/String.html#method-i-encode)
93
+
94
+ You can get supported encoding list by typing following command:
95
+
96
+ ```
97
+ $ ruby -e 'p Encoding.name_list.sort'
98
+ ```
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
3
+
4
+ require "rake/testtask"
5
+ Rake::TestTask.new(:test) do |test|
6
+ test.libs << 'lib' << 'test'
7
+ test.pattern = 'test/**/test_*.rb'
8
+ test.verbose = true
9
+ end
10
+
11
+ task :default => :test
@@ -0,0 +1,39 @@
1
+ # -*- encoding: 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 |gem|
6
+ gem.name = "fluent-plugin-rds-slowlog-patched-encoding"
7
+ gem.version = "0.0.8"
8
+ gem.authors = ["kenjiskywalker", "winebarrel"]
9
+ gem.email = ["git@kenjiskywalker.org", "sgwr_dts@yahoo.co.jp"]
10
+ gem.description = "Amazon RDS slow_log input plugin for Fluent event collector"
11
+ gem.homepage = "https://github.com/kenjiskywalker/fluent-plugin-rds-slowlog"
12
+ gem.summary = gem.description
13
+ gem.files = `git ls-files`.split($/)
14
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
15
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
16
+ gem.require_paths = ["lib"]
17
+
18
+ if RUBY_VERSION > '2.0.0'
19
+ gem.add_dependency "fluentd"
20
+ elsif RUBY_VERSION > '1.9.2'
21
+ gem.add_dependency "fluentd", "~> 0.12.29"
22
+ else
23
+ gem.add_dependency "fluentd", "<= 0.10.55"
24
+ end
25
+
26
+ if RUBY_VERSION <= '2.0.0'
27
+ gem.add_dependency "json", "< 2"
28
+ end
29
+
30
+ if RUBY_VERSION <= '1.9.2'
31
+ gem.add_development_dependency "rake", "<= 11"
32
+ else
33
+ gem.add_development_dependency "rake", ">= 10.0.4"
34
+ end
35
+
36
+ gem.add_dependency "mysql2", "~> 0.3.11"
37
+ gem.add_development_dependency "test-unit", "~> 3.1.3"
38
+ gem.add_development_dependency "timecop"
39
+ end
@@ -0,0 +1,149 @@
1
+ require 'fluent/input'
2
+
3
+ class Fluent::Rds_SlowlogInput < Fluent::Input
4
+ Fluent::Plugin.register_input("rds_slowlog", self)
5
+
6
+ # To support log_level option implemented by Fluentd v0.10.43
7
+ unless method_defined?(:log)
8
+ define_method("log") { $log }
9
+ end
10
+
11
+ # Define `router` method of v0.12 to support v0.10 or earlier
12
+ unless method_defined?(:router)
13
+ define_method("router") { Fluent::Engine }
14
+ end
15
+
16
+ config_param :tag, :string
17
+ config_param :host, :string, :default => nil
18
+ config_param :port, :integer, :default => 3306
19
+ config_param :username, :string, :default => nil
20
+ config_param :password, :string, :default => nil, :secret => true
21
+ config_param :interval, :integer, :default => 10
22
+ config_param :backup_table, :string, :default => nil
23
+ # The encoding after conversion of the input.
24
+ config_param :encoding, :string, default: nil
25
+ # The encoding of the input.
26
+ config_param :from_encoding, :string, default: nil
27
+
28
+ def initialize
29
+ super
30
+ require 'mysql2'
31
+ end
32
+
33
+ def configure_encoding
34
+ unless @encoding
35
+ if @from_encoding
36
+ raise Fluent::ConfigError, "fluent-plugin-rds-slowlog: 'from_encoding' parameter must be specified with 'encoding' parameter."
37
+ end
38
+ end
39
+
40
+ @encoding = parse_encoding_param(@encoding) if @encoding
41
+ @from_encoding = parse_encoding_param(@from_encoding) if @from_encoding
42
+ end
43
+
44
+ def parse_encoding_param(encoding_name)
45
+ begin
46
+ Encoding.find(encoding_name) if encoding_name
47
+ rescue ArgumentError => e
48
+ raise Fluent::ConfigError, e.message
49
+ end
50
+ end
51
+
52
+ def configure(conf)
53
+ super
54
+ configure_encoding
55
+
56
+ begin
57
+ @client = create_mysql_client
58
+ rescue
59
+ log.error "fluent-plugin-rds-slowlog: cannot connect RDS"
60
+ end
61
+ end
62
+
63
+ def start
64
+ super
65
+ if @backup_table
66
+ @client.query("CREATE TABLE IF NOT EXISTS #{@backup_table} LIKE slow_log")
67
+ end
68
+
69
+ @loop = Coolio::Loop.new
70
+ timer = TimerWatcher.new(@interval, true, log, &method(:output))
71
+ @loop.attach(timer)
72
+ @watcher = Thread.new(&method(:watch))
73
+ end
74
+
75
+ def shutdown
76
+ super
77
+ @watcher.terminate
78
+ @watcher.join
79
+ end
80
+
81
+ private
82
+ def watch
83
+ @loop.run
84
+ rescue => e
85
+ log.error(e.message)
86
+ log.error_backtrace(e.backtrace)
87
+ end
88
+
89
+ def output
90
+ @client.query('CALL mysql.rds_rotate_slow_log')
91
+
92
+ slow_log_data = []
93
+ slow_log_data = @client.query('SELECT * FROM slow_log_backup', :cast => false)
94
+
95
+ slow_log_data.each do |row|
96
+ row.each_key {|key| transcode(row[key]) if row[key].is_a?(String)}
97
+ router.emit(tag, Fluent::Engine.now, row)
98
+ end
99
+
100
+ if @backup_table
101
+ @client.query("INSERT INTO #{@backup_table} SELECT * FROM slow_log_backup")
102
+ end
103
+ rescue Mysql2::Error => e
104
+ @log.error(e.message)
105
+ @log.error_backtrace(e.backtrace)
106
+
107
+ unless @client.ping
108
+ @log.info('fluent-plugin-rds-slowlog: try to reconnect to RDS')
109
+ @client = create_mysql_client
110
+ end
111
+ end
112
+
113
+ def create_mysql_client
114
+ Mysql2::Client.new({
115
+ :host => @host,
116
+ :port => @port,
117
+ :username => @username,
118
+ :password => @password,
119
+ :database => 'mysql'
120
+ })
121
+ end
122
+
123
+ def transcode(value)
124
+ if @encoding
125
+ if @from_encoding
126
+ value.encode!(@encoding, @from_encoding)
127
+ else
128
+ value.force_encoding(@encoding)
129
+ end
130
+ else
131
+ value.force_encoding(Encoding::ASCII_8BIT)
132
+ end
133
+ end
134
+
135
+ class TimerWatcher < Coolio::TimerWatcher
136
+ def initialize(interval, repeat, log, &callback)
137
+ @callback = callback
138
+ @log = log
139
+ super(interval, repeat)
140
+ end
141
+
142
+ def on_timer
143
+ @callback.call
144
+ rescue => e
145
+ @log.error(e.message)
146
+ @log.error_backtrace(e.backtrace)
147
+ end
148
+ end
149
+ end
@@ -0,0 +1,32 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+
4
+ begin
5
+ Bundler.setup(:default, :development)
6
+ rescue Bundler::BundlerError => e
7
+ $stderr.puts e.message
8
+ $stderr.puts "Run `bundle install` to install missing gems"
9
+ exit e.status_code
10
+ end
11
+ require "test/unit"
12
+ require "mysql2"
13
+ require "timecop"
14
+
15
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), "..", "lib"))
16
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
17
+ require "fluent/test"
18
+ unless ENV.has_key?("VERBOSE")
19
+ nulllogger = Object.new
20
+ nulllogger.instance_eval {|obj|
21
+ def method_missing(method, *args)
22
+ #pass
23
+ end
24
+ }
25
+ $log = nulllogger
26
+ end
27
+
28
+ require "fluent/plugin/in_rds_slowlog"
29
+
30
+ class Test::Unit::TestCase
31
+ end
32
+
@@ -0,0 +1,210 @@
1
+ # encoding: utf-8
2
+ require 'helper'
3
+
4
+ class Rds_SlowlogInputTest < Test::Unit::TestCase
5
+ class << self
6
+ def startup
7
+ setup_database
8
+ Timecop.freeze(Time.parse('2015/05/24 18:30 UTC'))
9
+ end
10
+
11
+ def shutdown
12
+ cleanup_database
13
+ end
14
+
15
+ def setup_database
16
+ client = mysql2_client
17
+ client.query("GRANT ALL ON *.* TO test_rds_user@localhost IDENTIFIED BY 'test_rds_password'")
18
+
19
+ client.query <<-EOS
20
+ CREATE PROCEDURE `mysql`.`rds_rotate_slow_log`()
21
+ BEGIN
22
+ DECLARE sql_logging BOOLEAN;
23
+ select @@sql_log_bin into sql_logging;
24
+ set @@sql_log_bin=off;
25
+ CREATE TABLE IF NOT EXISTS mysql.slow_log2 LIKE mysql.slow_log;
26
+
27
+ #{insert_slow_log_sql}
28
+
29
+ DROP TABLE IF EXISTS mysql.slow_log_backup;
30
+ RENAME TABLE mysql.slow_log TO mysql.slow_log_backup, mysql.slow_log2 TO mysql.slow_log;
31
+ set @@sql_log_bin=sql_logging;
32
+ END
33
+ EOS
34
+ end
35
+
36
+ def cleanup_database
37
+ client = mysql2_client
38
+ client.query("DROP USER test_rds_user@localhost")
39
+ client.query("DROP PROCEDURE `mysql`.`rds_rotate_slow_log`")
40
+ client.query("DROP TABLE `mysql`.`slow_log_custom_backup`")
41
+ end
42
+
43
+ def insert_slow_log_sql
44
+ if has_thread_id?
45
+ <<-EOS
46
+ INSERT INTO `mysql`.`slow_log2` (
47
+ `start_time`, `user_host`, `query_time`, `lock_time`, `rows_sent`, `rows_examined`, `db`, `last_insert_id`, `insert_id`, `server_id`, `sql_text`, `thread_id`)
48
+ VALUES
49
+ ('2015-09-29 15:43:44', 'root@localhost', '00:00:00', '00:00:00', 0, 0, 'employees', 0, 0, 1, 'SELECT 1', 0)
50
+ ,('2015-09-29 15:43:45', 'root@localhost', '00:00:00', '00:00:00', 0, 0, 'employees', 0, 0, 1, 'SELECT 2', 0)
51
+ ,('2015-09-29 15:43:45', 'root@localhost', '00:00:00', '00:00:00', 0, 0, 'employees', 0, 0, 1, 'SELECT 3 -- テスト', 0)
52
+ ;
53
+ EOS
54
+ else
55
+ <<-EOS
56
+ INSERT INTO `mysql`.`slow_log2` (
57
+ `start_time`, `user_host`, `query_time`, `lock_time`, `rows_sent`, `rows_examined`, `db`, `last_insert_id`, `insert_id`, `server_id`, `sql_text`)
58
+ VALUES
59
+ ('2015-09-29 15:43:44', 'root@localhost', '00:00:00', '00:00:00', 0, 0, 'employees', 0, 0, 1, 'SELECT 1')
60
+ ,('2015-09-29 15:43:45', 'root@localhost', '00:00:00', '00:00:00', 0, 0, 'employees', 0, 0, 1, 'SELECT 2')
61
+ ,('2015-09-29 15:43:45', 'root@localhost', '00:00:00', '00:00:00', 0, 0, 'employees', 0, 0, 1, 'SELECT 3 -- テスト')
62
+ ;
63
+ EOS
64
+ end
65
+ end
66
+
67
+ def has_thread_id?
68
+ client = mysql2_client
69
+ fields = client.query("SHOW FULL FIELDS FROM `mysql`.`slow_log`").map {|r| r['Field'] }
70
+ fields.include?('thread_id')
71
+ end
72
+
73
+ def mysql2_client
74
+ Mysql2::Client.new(:username => 'root')
75
+ end
76
+ end
77
+
78
+ def rotate_slow_log
79
+ client = self.class.mysql2_client
80
+ client.query("CALL `mysql`.`rds_rotate_slow_log`")
81
+ end
82
+
83
+ def setup
84
+ Fluent::Test.setup
85
+ rotate_slow_log
86
+ end
87
+
88
+ CONFIG = %[
89
+ tag rds-slowlog
90
+ host localhost
91
+ username test_rds_user
92
+ password test_rds_password
93
+ interval 0
94
+ backup_table mysql.slow_log_custom_backup
95
+ ]
96
+
97
+ CONFIG_WITH_ENCODING = %[
98
+ tag rds-slowlog
99
+ host localhost
100
+ username test_rds_user
101
+ password test_rds_password
102
+ interval 0
103
+ backup_table mysql.slow_log_custom_backup
104
+ encoding UTF-8
105
+ ]
106
+
107
+ CONFIG_WITH_ENCODING_AND_FROMENCODING = %[
108
+ tag rds-slowlog
109
+ host localhost
110
+ username test_rds_user
111
+ password test_rds_password
112
+ interval 0
113
+ backup_table mysql.slow_log_custom_backup
114
+ encoding CP932
115
+ from_encoding UTF-8
116
+ ]
117
+
118
+ def create_driver(conf = CONFIG)
119
+ Fluent::Test::InputTestDriver.new(Fluent::Rds_SlowlogInput).configure(conf)
120
+ end
121
+
122
+ def test_configure
123
+ d = create_driver
124
+ assert_equal 'rds-slowlog', d.instance.tag
125
+ assert_equal 'localhost', d.instance.host
126
+ assert_equal 'test_rds_user', d.instance.username
127
+ assert_equal 'test_rds_password', d.instance.password
128
+ assert_equal 0, d.instance.interval
129
+ assert_equal 'mysql.slow_log_custom_backup', d.instance.backup_table
130
+ assert_equal nil, d.instance.encoding
131
+ assert_equal nil, d.instance.from_encoding
132
+ end
133
+
134
+ def test_output
135
+ d = create_driver
136
+ d.run
137
+ records = d.emits
138
+
139
+ unless self.class.has_thread_id?
140
+ records.each {|r| r[2]["thread_id"] = "0" }
141
+ end
142
+
143
+ records.each {|r| assert_equal Encoding::ASCII_8BIT, r[2]['sql_text'].encoding }
144
+
145
+ assert_equal [
146
+ ["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"}],
147
+ ["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"}],
148
+ ["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 3 -- #{"テスト".force_encoding(Encoding::ASCII_8BIT)}", "thread_id"=>"0"}],
149
+ ], records
150
+ end
151
+
152
+ def test_backup
153
+ d = create_driver
154
+ d.run
155
+
156
+ records = []
157
+ client = self.class.mysql2_client
158
+ slow_logs = client.query('SELECT * FROM `mysql`.`slow_log_custom_backup`', :cast => false)
159
+ slow_logs.each do |row|
160
+ row.each_key {|key| row[key].force_encoding(Encoding::ASCII_8BIT) if row[key].is_a?(String)}
161
+ records.push(row)
162
+ end
163
+
164
+ unless self.class.has_thread_id?
165
+ records.each {|r| r["thread_id"] = "0" }
166
+ end
167
+
168
+ assert_equal [
169
+ {"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"},
170
+ {"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"},
171
+ {"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 3 -- #{"テスト".force_encoding(Encoding::ASCII_8BIT)}", "thread_id"=>"0"},
172
+ ], records
173
+ end
174
+
175
+ def test_transcode_with_encoding
176
+ d = create_driver(CONFIG_WITH_ENCODING)
177
+ d.run
178
+ records = d.emits
179
+
180
+ unless self.class.has_thread_id?
181
+ records.each {|r| r[2]["thread_id"] = "0" }
182
+ end
183
+
184
+ records.each {|r| assert_equal Encoding::UTF_8, r[2]['sql_text'].encoding }
185
+
186
+ assert_equal [
187
+ ["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"}],
188
+ ["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"}],
189
+ ["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 3 -- #{"テスト".force_encoding(Encoding::UTF_8)}", "thread_id"=>"0"}],
190
+ ], records
191
+ end
192
+
193
+ def test_transcode_with_encoding_fromencoding
194
+ d = create_driver(CONFIG_WITH_ENCODING_AND_FROMENCODING)
195
+ d.run
196
+ records = d.emits
197
+
198
+ unless self.class.has_thread_id?
199
+ records.each {|r| r[2]["thread_id"] = "0" }
200
+ end
201
+
202
+ records.each {|r| assert_equal Encoding::CP932, r[2]['sql_text'].encoding }
203
+
204
+ assert_equal [
205
+ ["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"}],
206
+ ["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"}],
207
+ ["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 3 -- #{"テスト".encode(Encoding::CP932, Encoding::UTF_8)}", "thread_id"=>"0"}],
208
+ ], records
209
+ end
210
+ end
metadata ADDED
@@ -0,0 +1,127 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fluent-plugin-rds-slowlog-patched-encoding
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.8
5
+ platform: ruby
6
+ authors:
7
+ - kenjiskywalker
8
+ - winebarrel
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2017-05-17 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: fluentd
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ">="
19
+ - !ruby/object:Gem::Version
20
+ version: '0'
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ version: '0'
28
+ - !ruby/object:Gem::Dependency
29
+ name: rake
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: 10.0.4
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: 10.0.4
42
+ - !ruby/object:Gem::Dependency
43
+ name: mysql2
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - "~>"
47
+ - !ruby/object:Gem::Version
48
+ version: 0.3.11
49
+ type: :runtime
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - "~>"
54
+ - !ruby/object:Gem::Version
55
+ version: 0.3.11
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'
84
+ description: Amazon RDS slow_log input plugin for Fluent event collector
85
+ email:
86
+ - git@kenjiskywalker.org
87
+ - sgwr_dts@yahoo.co.jp
88
+ executables: []
89
+ extensions: []
90
+ extra_rdoc_files: []
91
+ files:
92
+ - ".gitignore"
93
+ - ".travis.yml"
94
+ - Gemfile
95
+ - LICENSE.txt
96
+ - README.md
97
+ - Rakefile
98
+ - fluent-plugin-rds-slowlog.gemspec
99
+ - lib/fluent/plugin/in_rds_slowlog.rb
100
+ - test/helper.rb
101
+ - test/plugin/test_in_rds_slowlog.rb
102
+ homepage: https://github.com/kenjiskywalker/fluent-plugin-rds-slowlog
103
+ licenses: []
104
+ metadata: {}
105
+ post_install_message:
106
+ rdoc_options: []
107
+ require_paths:
108
+ - lib
109
+ required_ruby_version: !ruby/object:Gem::Requirement
110
+ requirements:
111
+ - - ">="
112
+ - !ruby/object:Gem::Version
113
+ version: '0'
114
+ required_rubygems_version: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ requirements: []
120
+ rubyforge_project:
121
+ rubygems_version: 2.4.5
122
+ signing_key:
123
+ specification_version: 4
124
+ summary: Amazon RDS slow_log input plugin for Fluent event collector
125
+ test_files:
126
+ - test/helper.rb
127
+ - test/plugin/test_in_rds_slowlog.rb