fluent-plugin-heroku-postgres 0.0.1 → 0.0.3

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: a1fc6e06906c84a2db95ebd2e83abf10ef08b741
4
- data.tar.gz: b692260d42c77b31576f243a09b6dec79a76b6b1
3
+ metadata.gz: 8ecf7d3ef69df838b352ea889c49c71b25a94a96
4
+ data.tar.gz: e0741e2ccc67340a3dadb2749aa533de42af8457
5
5
  SHA512:
6
- metadata.gz: bf64e8dd32d67b48c8feca4d57d0199aefb1498b1884b74a796d0fb6a54e18b4ab7f779b80860281231f6501bf7397d3e471dd655ef7cfcf1d00c6136eeae70f
7
- data.tar.gz: 85b61854e18cb6ccb9d1559026adc5323cfecf669b8fe0c96bebfc9503e82d618afd377e60d3ab58f6231fb8c70ad2c9587ebd5d624f85ed5cd4437afae5d377
6
+ metadata.gz: 5b9fc5a2003b82543053a609bd575c99e43c127641bcbe18028af7b226e858c6b4bc89e8f3626853ab4652b70827ebaad20a5079cc5a233a7a48b96f09de023d
7
+ data.tar.gz: 763addc1eb379dc106a55ab6780e5ff43386e9bbc2cd93f9fafb99a6507bd24acc5af423c13bf1037c57b1a0c2b8c5f2305ced564ed0995587f02f6274f05329
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
- # Fluent::Plugin::Heroku::Postgres
1
+ # Fluentd Plugin for Heroku Postgres
2
2
 
3
- TODO: Write a gem description
3
+ td-agent on Heroku.
4
4
 
5
5
  ## Installation
6
6
 
@@ -12,13 +12,32 @@ And then execute:
12
12
 
13
13
  $ bundle
14
14
 
15
- Or install it yourself as:
15
+ ## Usage
16
16
 
17
- $ gem install fluent-plugin-heroku-postgres
17
+ * example
18
18
 
19
- ## Usage
19
+ ### td-agent-conf.rb
20
+
21
+ ※ Not 'td-agent.conf'
22
+
23
+ ```ruby
24
+ # td-agent-conf.rb
25
+
26
+ match('postgres.**') {
27
+ type :heroku_postgres
28
+
29
+ heroku_postgres_url "#{::ENV['DATABASE_URL']}"
30
+ key_names 'name'
31
+ sql "INSERT INTO vendors (name) VALUES ($1)"
32
+ }
33
+ ```
34
+
35
+ ### Procfile
36
+
37
+ ```
38
+ web: bundle exec fluentd -c td-agent-conf.rb -i "source { type :http; port $PORT }" -vv
39
+ ```
20
40
 
21
- TODO: Write usage instructions here
22
41
 
23
42
  ## Contributing
24
43
 
@@ -1,11 +1,10 @@
1
1
  # coding: utf-8
2
2
  lib = File.expand_path('../lib', __FILE__)
3
3
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'fluent/plugin/heroku/postgres/version'
5
4
 
6
5
  Gem::Specification.new do |spec|
7
6
  spec.name = "fluent-plugin-heroku-postgres"
8
- spec.version = Fluent::Plugin::Heroku::Postgres::VERSION
7
+ spec.version = '0.0.3'
9
8
  spec.authors = ["Naohiro Sakuma"]
10
9
  spec.email = ["nao.bear@gmail.com"]
11
10
  spec.summary = %q{fluent plugin to insert on Heroku Postgre.}
@@ -18,6 +17,10 @@ Gem::Specification.new do |spec|
18
17
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
18
  spec.require_paths = ["lib"]
20
19
 
20
+ spec.add_dependency 'fluentd', "~> 0.10"
21
+ spec.add_dependency 'pg', "~> 0.17"
22
+
21
23
  spec.add_development_dependency "bundler", "~> 1.6"
22
24
  spec.add_development_dependency "rake", '~> 0'
25
+ spec.add_development_dependency "pry", '~> 0'
23
26
  end
@@ -0,0 +1,85 @@
1
+ class Fluent::HerokuPostgresOutput < Fluent::BufferedOutput
2
+ Fluent::Plugin.register_output('heroku_postgres', self)
3
+
4
+ include Fluent::SetTimeKeyMixin
5
+ include Fluent::SetTagKeyMixin
6
+
7
+ attr_accessor :host, :port, :database, :username, :password
8
+
9
+ config_param :heroku_postgres_url, :string
10
+
11
+ config_param :key_names, :string, :default => nil # nil allowed for json format
12
+ config_param :sql, :string, :default => nil
13
+ config_param :table, :string, :default => nil
14
+ config_param :columns, :string, :default => nil
15
+
16
+ config_param :format, :string, :default => "raw" # or json
17
+
18
+ attr_accessor :handler
19
+
20
+ def initialize
21
+ super
22
+ require 'pg'
23
+ end
24
+
25
+ # We don't currently support mysql's analogous json format
26
+ def configure(conf)
27
+ super
28
+
29
+ parse_heroku_postgres_url!
30
+
31
+ if @format == 'json'
32
+ @format_proc = Proc.new{|tag, time, record| record.to_json}
33
+ else
34
+ @key_names = @key_names.split(',')
35
+ @format_proc = Proc.new{|tag, time, record| @key_names.map{|k| record[k]}}
36
+ end
37
+
38
+ if @columns.nil? and @sql.nil?
39
+ raise Fluent::ConfigError, "columns or sql MUST be specified, but missing"
40
+ end
41
+ if @columns and @sql
42
+ raise Fluent::ConfigError, "both of columns and sql are specified, but specify one of them"
43
+ end
44
+ end
45
+
46
+ def start
47
+ super
48
+ end
49
+
50
+ def shutdown
51
+ super
52
+ end
53
+
54
+ def format(tag, time, record)
55
+ [tag, time, @format_proc.call(tag, time, record)].to_msgpack
56
+ end
57
+
58
+ def client
59
+ PG::Connection.new({
60
+ :host => @host, :port => @port,
61
+ :user => @username, :password => @password,
62
+ :dbname => @database
63
+ })
64
+ end
65
+
66
+ def write(chunk)
67
+ handler = self.client
68
+ handler.prepare("write", @sql)
69
+ chunk.msgpack_each { |tag, time, data|
70
+ handler.exec_prepared("write", data)
71
+ }
72
+ handler.close
73
+ end
74
+
75
+ private
76
+
77
+ def parse_heroku_postgres_url!
78
+ parsed_url = URI.parse(@heroku_postgres_url)
79
+ @host = parsed_url.host
80
+ @port = parsed_url.port
81
+ @database = parsed_url.path.sub(/\//, '')
82
+ @username = parsed_url.user
83
+ @password = parsed_url.password
84
+ end
85
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-heroku-postgres
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Naohiro Sakuma
@@ -10,6 +10,34 @@ bindir: bin
10
10
  cert_chain: []
11
11
  date: 2014-05-13 00:00:00.000000000 Z
12
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.10'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.10'
27
+ - !ruby/object:Gem::Dependency
28
+ name: pg
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.17'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.17'
13
41
  - !ruby/object:Gem::Dependency
14
42
  name: bundler
15
43
  requirement: !ruby/object:Gem::Requirement
@@ -38,6 +66,20 @@ dependencies:
38
66
  - - "~>"
39
67
  - !ruby/object:Gem::Version
40
68
  version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
41
83
  description: This gem is fluent plugin to insert on Heroku Postgre.
42
84
  email:
43
85
  - nao.bear@gmail.com
@@ -51,8 +93,7 @@ files:
51
93
  - README.md
52
94
  - Rakefile
53
95
  - fluent-plugin-heroku-postgres.gemspec
54
- - lib/fluent/plugin/heroku/postgres.rb
55
- - lib/fluent/plugin/heroku/postgres/version.rb
96
+ - lib/fluent/plugin/out_heroku_postgres.rb
56
97
  homepage: https://github.com/n-sakuma/fluent-plugin-heroku-postgres
57
98
  licenses:
58
99
  - MIT
@@ -1,11 +0,0 @@
1
- require "fluent/plugin/heroku/postgres/version"
2
-
3
- module Fluent
4
- module Plugin
5
- module Heroku
6
- module Postgres
7
- # Your code goes here...
8
- end
9
- end
10
- end
11
- end
@@ -1,9 +0,0 @@
1
- module Fluent
2
- module Plugin
3
- module Heroku
4
- module Postgres
5
- VERSION = "0.0.1"
6
- end
7
- end
8
- end
9
- end