fluent-plugin-sql_fingerprint 0.0.1

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,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 16f9a74d5b145d2aa1812144e2f5e08ca042d57c
4
+ data.tar.gz: 4f9c6215e10c779cde913f49fc78219868713f83
5
+ SHA512:
6
+ metadata.gz: a4c8972f57f543c605da2647d425d28cdda42620281c4009c635e3c4fadbf680d430999dd51e8aa99737086a89f9b64c7d36f496e0af040df6e0e77120b0728f
7
+ data.tar.gz: a28ba79972e74b5ce66add8842683c99541e60ecb08578e0560f802e3359948d74a8cd8345b1b0061dd6f35dc2e26a1c1a59af8cf424dd12692ce94208bb6e39
@@ -0,0 +1,14 @@
1
+ /*.gem
2
+ ~*
3
+ #*
4
+ *~
5
+ .bundle
6
+ Gemfile.lock
7
+ .rbenv-version
8
+ vendor
9
+ doc/*
10
+ tmp/*
11
+ coverage
12
+ .yardoc
13
+ .ruby-version
14
+ pkg/*
@@ -0,0 +1,8 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - 2.0.0
5
+ - 2.1.*
6
+ - 2.2.*
7
+ gemfile:
8
+ - Gemfile
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in fluent-plugin-sql-fingerprint.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Takahiro Kikumoto
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,64 @@
1
+ # fluent-plugin-sql_fingerprint
2
+
3
+ [![Build Status](https://travis-ci.org/kikumoto/fluent-plugin-sql_fingerprint.svg?branch=master)](https://travis-ci.org/kikumoto/fluent-plugin-sql_fingerprint)
4
+
5
+ A Fluent filter plugin to convert sql to sql's fingerprint.
6
+
7
+ ## Requirements
8
+
9
+ Fluentd >= v0.12
10
+
11
+ ## Install
12
+
13
+ ```shell
14
+ gem install fluent-plugin-sql_fingerprint
15
+ ```
16
+
17
+ ## Configuration Example
18
+
19
+ ```conf
20
+ <filter tag.dummy.*>
21
+ type sql_fingerprint
22
+ fingerprint_tool_path /usr/bin/pt-fingerprint
23
+ </filter>
24
+ ```
25
+
26
+ ### sample
27
+
28
+ record before filter
29
+
30
+ ```
31
+ {
32
+ "sql": "SELECT * FROM demo WHERE record = 'AAA';"
33
+ }
34
+ ```
35
+
36
+ record after filter
37
+
38
+ ```
39
+ {
40
+ "sql": "SELECT * FROM demo WHERE record = 'AAA';",
41
+ "fingerprint": "select * from demo where record = ?"
42
+ }
43
+ ```
44
+
45
+
46
+ ## Parameters
47
+
48
+ * fingerprint_tool_path (required)
49
+
50
+ Tool path which generates fingerpint.
51
+ It must input from standard input and output to standard output.
52
+ Ex. pt-fingerprint (see https://www.percona.com/doc/percona-toolkit/2.2/index.html)
53
+
54
+ * target_key
55
+
56
+ The key which was passed to standard input of fingerprint_tool. Default is `sql`.
57
+
58
+ * added_key
59
+
60
+ The key which was added to new record that holds fingerprint generated by fingerpinrt_tool. Default is `fingerprint`.
61
+
62
+ ## Copyright
63
+
64
+ Copyright (c) 2015 Takahiro Kikumoto. See [LICENSE](LICENSE) for details.
@@ -0,0 +1,17 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ require 'rake/testtask'
4
+ desc 'Run test_unit based test'
5
+ Rake::TestTask.new(:test) do |t|
6
+ t.libs << "test"
7
+ t.test_files = Dir["test/**/test_*.rb"].sort
8
+ t.verbose = true
9
+ #t.warning = true
10
+ end
11
+ task :default => :test
12
+
13
+ desc 'Open an irb session preloaded with the gem library'
14
+ task :console do
15
+ sh 'irb -rubygems -I lib'
16
+ end
17
+ task :c => :console
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ # $:.push File.expand_path("../lib", __FILE__)
3
+
4
+ Gem::Specification.new do |spec|
5
+ spec.name = "fluent-plugin-sql_fingerprint"
6
+ spec.version = "0.0.1"
7
+ spec.authors = ["Takahiro Kikumoto"]
8
+ spec.email = ["kikumoto.takahiro@hamee.co.jp"]
9
+
10
+ spec.summary = "A Fluent filter plugin to convert sql to sql's fingerprint"
11
+ spec.description = spec.summary
12
+ spec.homepage = "https://github.com/kikumoto/fluent-plugin-sql_fingerprint"
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files`.split("\n")
16
+ spec.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
17
+ spec.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_runtime_dependency "fluentd", ">= 0.12"
21
+ spec.add_development_dependency "bundler"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "test-unit"
24
+ end
@@ -0,0 +1,51 @@
1
+ module Fluent
2
+ class SqlFingerprintFilter < Filter
3
+ Plugin.register_filter('sql_fingerprint', self)
4
+
5
+ def initialize
6
+ super
7
+ require "open3"
8
+ end
9
+
10
+ config_param :fingerprint_tool_path, :string
11
+ config_param :target_key, :string, :default => 'sql'
12
+ config_param :added_key, :string, :default => 'fingerprint'
13
+
14
+ def configure(conf)
15
+ super
16
+ end
17
+
18
+ def start
19
+ super
20
+ end
21
+
22
+ def shutdown
23
+ super
24
+ end
25
+
26
+ def filter(tag, time, record)
27
+ sql = hash_get(record, @target_key)
28
+ if !sql.nil? && !sql.empty?
29
+ record[@added_key] = fingerprint(sql)
30
+ end
31
+ record
32
+ end
33
+
34
+ def fingerprint(sql)
35
+ unless sql.empty?
36
+ o, s = Open3.capture2(@fingerprint_tool_path, :stdin_data => sql)
37
+ if s.success?
38
+ o.chomp!
39
+ sql = o unless o.empty?
40
+ end
41
+ end
42
+ sql
43
+ end
44
+
45
+ def hash_get(hash, key)
46
+ return hash[key.to_sym] if hash.key?(key.to_sym)
47
+ return hash[key] if hash.key?(key)
48
+ nil
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,8 @@
1
+ require 'test/unit'
2
+ require 'fluent/log'
3
+ require 'fluent/test'
4
+
5
+ unless defined?(Test::Unit::AssertionFailedError)
6
+ class Test::Unit::AssertionFailedError < StandardError
7
+ end
8
+ end
@@ -0,0 +1,44 @@
1
+ require_relative 'helper'
2
+ require 'fluent/plugin/filter_sql_fingerprint'
3
+
4
+ class SqlFingerprintFilterTest < Test::Unit::TestCase
5
+ include Fluent
6
+
7
+ setup do
8
+ Test.setup
9
+ @time = Fluent::Engine.now
10
+ end
11
+
12
+ def create_driver(conf = '')
13
+ Test::FilterTestDriver.new(SqlFingerprintFilter).configure(conf, true)
14
+ end
15
+
16
+ def filter(d, msg)
17
+ d.run { d.filter(msg, @time) }
18
+ d.filtered
19
+ end
20
+
21
+ sub_test_case 'configure' do
22
+ def test_finggerprint_tool_path
23
+ assert_raise Fluent::ConfigError do
24
+ create_driver('')
25
+ end
26
+
27
+ d = create_driver(%[fingerprint_tool_path a_tool])
28
+ assert_equal "a_tool", d.instance.fingerprint_tool_path
29
+ end
30
+ end
31
+
32
+ sub_test_case 'filter' do
33
+ def test_sql_fingerprint
34
+ sql = "SELECT * FROM hogeho"
35
+ d = create_driver(%[fingerprint_tool_path cat])
36
+ msg = { 'sql' => sql }
37
+ es = filter(d, msg)
38
+ es.each do |t, r|
39
+ assert_equal(sql, r['sql'])
40
+ assert_equal(sql, r['fingerprint'])
41
+ end
42
+ end
43
+ end
44
+ end
metadata ADDED
@@ -0,0 +1,112 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fluent-plugin-sql_fingerprint
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Takahiro Kikumoto
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-11-27 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: fluentd
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0.12'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0.12'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: test-unit
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: A Fluent filter plugin to convert sql to sql's fingerprint
70
+ email:
71
+ - kikumoto.takahiro@hamee.co.jp
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".travis.yml"
78
+ - Gemfile
79
+ - LICENSE
80
+ - README.md
81
+ - Rakefile
82
+ - fluent-plugin-sql_fingerprint.gemspec
83
+ - lib/fluent/plugin/filter_sql_fingerprint.rb
84
+ - test/helper.rb
85
+ - test/test_sql_fingerprint.rb
86
+ homepage: https://github.com/kikumoto/fluent-plugin-sql_fingerprint
87
+ licenses:
88
+ - MIT
89
+ metadata: {}
90
+ post_install_message:
91
+ rdoc_options: []
92
+ require_paths:
93
+ - lib
94
+ required_ruby_version: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ required_rubygems_version: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ requirements: []
105
+ rubyforge_project:
106
+ rubygems_version: 2.4.5
107
+ signing_key:
108
+ specification_version: 4
109
+ summary: A Fluent filter plugin to convert sql to sql's fingerprint
110
+ test_files:
111
+ - test/helper.rb
112
+ - test/test_sql_fingerprint.rb