Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
tagomoris committed Apr 14, 2012
0 parents commit 65e33a4
Show file tree
Hide file tree
Showing 9 changed files with 222 additions and 0 deletions.
17 changes: 17 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
*.gem
*.rbc
.bundle
.config
.yardoc
Gemfile.lock
InstalledFiles
_yardoc
coverage
doc/
lib/bundler/man
pkg
rdoc
spec/reports
test/tmp
test/version_tmp
tmp
4 changes: 4 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
source 'https://rubygems.org'

# Specify your gem's dependencies in fluent-plugin-mysql.gemspec
gemspec
22 changes: 22 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
Copyright (c) 2012 TAGOMORI Satoshi

MIT License

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 changes: 29 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Fluent::Plugin::Mysql

TODO: Write a gem description

## Installation

Add this line to your application's Gemfile:

gem 'fluent-plugin-mysql'

And then execute:

$ bundle

Or install it yourself as:

$ gem install fluent-plugin-mysql

## Usage

TODO: Write usage instructions here

## Contributing

1. Fork it
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am 'Added some feature'`)
4. Push to the branch (`git push origin my-new-feature`)
5. Create new Pull Request
11 changes: 11 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env rake
require "bundler/gem_tasks"

require 'rake/testtask'
Rake::TestTask.new(:test) do |test|
test.libs << 'lib' << 'test'
test.pattern = 'test/**/test_*.rb'
test.verbose = true
end

task :default => :test
20 changes: 20 additions & 0 deletions fluent-plugin-mysql.gemspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# -*- encoding: utf-8 -*-
Gem::Specification.new do |gem|
gem.name = "fluent-plugin-mysql"
gem.version = "0.1.0"
gem.authors = ["TAGOMORI Satoshi"]
gem.email = ["tagomoris@gmail.com"]
gem.description = %q{fluent plugin to insert mysql as json(single column) or insert statement}
gem.summary = %q{fluent plugin to insert mysql}
gem.homepage = "https://github.com/tagomoris/fluent-plugin-mysql"

gem.files = `git ls-files`.split($\)
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
gem.require_paths = ["lib"]

gem.add_development_dependency "fluentd"
gem.add_development_dependency "mysql2"
gem.add_runtime_dependency "fluentd"
gem.add_runtime_dependency "mysql2"
end
35 changes: 35 additions & 0 deletions lib/fluent/plugin/out_mysql.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
class Fluent::MysqlOutput < Fluent::BufferedOutput
Fluent::Plugin.register_output('mysql', self)

def initialize
super
require 'mysql2'
end

def configure(conf)
super
# @path = conf['path']
end

def start
super
# init
end

def shutdown
super
# destroy
end

def format(tag, time, record)
[tag, time, record].to_msgpack
end

def write(chunk)
records = []
chunk.msgpack_each { |record|
# records << record
}
# write records
end
end
28 changes: 28 additions & 0 deletions test/helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
require 'rubygems'
require 'bundler'
begin
Bundler.setup(:default, :development)
rescue Bundler::BundlerError => e
$stderr.puts e.message
$stderr.puts "Run `bundle install` to install missing gems"
exit e.status_code
end
require 'test/unit'

$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
$LOAD_PATH.unshift(File.dirname(__FILE__))
require 'fluent/test'
unless ENV.has_key?('VERBOSE')
nulllogger = Object.new
nulllogger.instance_eval {|obj|
def method_missing(method, *args)
# pass
end
}
$log = nulllogger
end

require 'fluent/plugin/out_mysql'

class Test::Unit::TestCase
end
56 changes: 56 additions & 0 deletions test/plugin/test_out_mysql.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
require 'helper'

class MysqlOutputTest < Test::Unit::TestCase
def setup
Fluent::Test.setup
end

CONFIG = %[
]
# CONFIG = %[
# path #{TMP_DIR}/out_file_test
# compress gz
# utc
# ]

def create_driver(conf = CONFIG, tag='test')
Fluent::Test::BufferedOutputTestDriver.new(Fluent::MysqlOutput, tag).configure(conf)
end

def test_configure
#### set configurations
# d = create_driver %[
# path test_path
# compress gz
# ]
#### check configurations
# assert_equal 'test_path', d.instance.path
# assert_equal :gz, d.instance.compress
end

def test_format
d = create_driver

# time = Time.parse("2011-01-02 13:14:15 UTC").to_i
# d.emit({"a"=>1}, time)
# d.emit({"a"=>2}, time)

# d.expect_format %[2011-01-02T13:14:15Z\ttest\t{"a":1}\n]
# d.expect_format %[2011-01-02T13:14:15Z\ttest\t{"a":2}\n]

# d.run
end

def test_write
d = create_driver

# time = Time.parse("2011-01-02 13:14:15 UTC").to_i
# d.emit({"a"=>1}, time)
# d.emit({"a"=>2}, time)

# ### FileOutput#write returns path
# path = d.run
# expect_path = "#{TMP_DIR}/out_file_test._0.log.gz"
# assert_equal expect_path, path
end
end

0 comments on commit 65e33a4

Please sign in to comment.