fluent-plugin-bigobject 0.0.3
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 +7 -0
- data/.gitignore +9 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +59 -0
- data/Rakefile +1 -0
- data/fluent-plugin-bigobject.gemspec +21 -0
- data/lib/fluent/plugin/out_bigobject.rb +199 -0
- metadata +107 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 0f32d55fb8208a02537e14888097a8ee2e6db740
|
4
|
+
data.tar.gz: d4b41b61f8886371fb10b5fb12b32a2df0ed9508
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 8562552cdf32bf6b3bfd166c1812bab657b2915763560bb7d054b7651d7dd437496f802480e2b6391956ef998d9d4a4fbefcdc50260d47ec0975eeee66e424d7
|
7
|
+
data.tar.gz: 5c5d5413c9847d2c5016b7b00cf417e106e5a10cc61a6726ebaf0172ba1dc9e3504e20fb23c3a7345202e1a69a0d238ca10d94e1fa2e12a5dd8facc73b133087
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 MacroData
|
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.
|
data/README.md
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
# fluent-plugin-bigobject
|
2
|
+
|
3
|
+
Fluentd output plugin for inserting data to BigObject
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'fluent-plugin-bigobject'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install fluent-plugin-bigobject
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
Configure BigObject URL and the table/column to be mapped in BigObject
|
24
|
+
|
25
|
+
```apache
|
26
|
+
<match bo.insert.*>
|
27
|
+
type bigobject
|
28
|
+
|
29
|
+
log_level info
|
30
|
+
|
31
|
+
# specify the bigobject_url to connect to
|
32
|
+
bigobject_url http://192.168.59.103:9090/cmd
|
33
|
+
|
34
|
+
remove_tag_prefix bo.insert.
|
35
|
+
flush_interval 5s
|
36
|
+
|
37
|
+
<table>
|
38
|
+
table Customer
|
39
|
+
column_mapping id,name,language,state,company,gender,age
|
40
|
+
pattern customer
|
41
|
+
#bo_workspace
|
42
|
+
#bo_opts
|
43
|
+
</table>
|
44
|
+
|
45
|
+
<table>
|
46
|
+
table search_test3
|
47
|
+
# map to different column name in BigObject
|
48
|
+
column_mapping 'ID:id3, TEXT:text3'
|
49
|
+
pattern test3
|
50
|
+
</table>
|
51
|
+
|
52
|
+
</match>
|
53
|
+
```
|
54
|
+
|
55
|
+
|
56
|
+
## License
|
57
|
+
|
58
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
59
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
Gem::Specification.new do |gem|
|
3
|
+
gem.name = "fluent-plugin-bigobject"
|
4
|
+
gem.version = "0.0.3"
|
5
|
+
gem.authors = ["Andrea Sung"]
|
6
|
+
gem.email = ["andrea@bigobject.io"]
|
7
|
+
gem.description = %q{Fluentd output plugin to insert BIGOBJECT }
|
8
|
+
gem.summary = %q{Fluentd output plugin to insert BIGOBJECT}
|
9
|
+
gem.homepage = "https://github.com/andreasung/fluent-plugin-bigobject"
|
10
|
+
gem.license = "MIT"
|
11
|
+
|
12
|
+
gem.files = `git ls-files`.split($\)
|
13
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
14
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
|
17
|
+
gem.add_runtime_dependency "fluentd"
|
18
|
+
gem.add_runtime_dependency "rest-client"
|
19
|
+
gem.add_runtime_dependency "json"
|
20
|
+
gem.add_development_dependency "rake"
|
21
|
+
end
|
@@ -0,0 +1,199 @@
|
|
1
|
+
class Fluent::BigObjectOutput < Fluent::BufferedOutput
|
2
|
+
Fluent::Plugin.register_output('bigobject', self)
|
3
|
+
|
4
|
+
include Fluent::SetTimeKeyMixin
|
5
|
+
include Fluent::SetTagKeyMixin
|
6
|
+
|
7
|
+
config_param :bigobject_url, :string
|
8
|
+
config_param :remove_tag_prefix, :string, :default => nil
|
9
|
+
config_param :send_unknown_chunks, :string, :default=>true
|
10
|
+
|
11
|
+
attr_accessor :tables
|
12
|
+
|
13
|
+
unless method_defined?(:log)
|
14
|
+
define_method(:log) { $log }
|
15
|
+
end
|
16
|
+
|
17
|
+
class TableElement
|
18
|
+
include Fluent::Configurable
|
19
|
+
|
20
|
+
config_param :table, :string
|
21
|
+
config_param :column_mapping, :string
|
22
|
+
config_param :pattern, :string, :default=>nil
|
23
|
+
config_param :bo_workspace, :string, :default=>nil
|
24
|
+
config_param :bo_opts, :string, :default=>nil
|
25
|
+
|
26
|
+
attr_reader :mpattern
|
27
|
+
|
28
|
+
def initialize(log)
|
29
|
+
super()
|
30
|
+
@log = log
|
31
|
+
end
|
32
|
+
|
33
|
+
def configure(conf)
|
34
|
+
super
|
35
|
+
@mpattern = Fluent::MatchPattern.create(pattern)
|
36
|
+
@mapping = parse_column_mapping(@column_mapping)
|
37
|
+
@log.info("column mapping for #{table} - #{@mapping}")
|
38
|
+
@format_proc = Proc.new { |record|
|
39
|
+
new_record = {}
|
40
|
+
@mapping.each { |k, c|
|
41
|
+
new_record[c] = record[k]
|
42
|
+
}
|
43
|
+
new_record
|
44
|
+
}
|
45
|
+
end
|
46
|
+
|
47
|
+
def send(bourl, chunk)
|
48
|
+
stmts = Array.new
|
49
|
+
i=0
|
50
|
+
columns = nil
|
51
|
+
chunk.msgpack_each { |tag, time, data|
|
52
|
+
keys = Array.new
|
53
|
+
values = Array.new
|
54
|
+
data = @format_proc.call(data)
|
55
|
+
data.keys.sort.each do |key|
|
56
|
+
keys << key
|
57
|
+
values << data[key]
|
58
|
+
end
|
59
|
+
if columns.to_s.empty?
|
60
|
+
columns = "(#{keys.join(",")})"
|
61
|
+
end
|
62
|
+
#single quote each column data
|
63
|
+
stmts.push("('#{values.join("','")}')")
|
64
|
+
i+=1
|
65
|
+
}
|
66
|
+
|
67
|
+
sendStmt = "INSERT INTO #{@table} #{columns} VALUES" + stmts.join(",")
|
68
|
+
# @log.debug("sendStmt=", sendStmt)
|
69
|
+
@log.info("bigobject start insert #{i} rows")
|
70
|
+
resp = sendBO(bourl, sendStmt)
|
71
|
+
parsed = JSON.parse(resp)
|
72
|
+
err = parsed['Err']
|
73
|
+
# puts "Content=#{parsed['Content']}, Err=#{err}"
|
74
|
+
if (err.to_s!='')
|
75
|
+
@log.error("[BigObject] #{err}")
|
76
|
+
end
|
77
|
+
@log.info("bigobject end insert #{i} rows")
|
78
|
+
|
79
|
+
end
|
80
|
+
|
81
|
+
def to_s
|
82
|
+
"table:#{table}, column_mapping:#{column_mapping}, pattern:#{pattern}"
|
83
|
+
end
|
84
|
+
|
85
|
+
private
|
86
|
+
def parse_column_mapping(column_mapping_conf)
|
87
|
+
mapping = {}
|
88
|
+
column_mapping_conf.split(',').each { |column_map|
|
89
|
+
key, column = column_map.strip.split(':', 2)
|
90
|
+
column = key if column.nil?
|
91
|
+
mapping[key] = column
|
92
|
+
}
|
93
|
+
mapping
|
94
|
+
end
|
95
|
+
|
96
|
+
def formatRequest(stmt)
|
97
|
+
params = Hash.new
|
98
|
+
params['Stmt'] = stmt
|
99
|
+
|
100
|
+
if @bo_workspace.to_s!=''
|
101
|
+
params['Workspace'] = @bo_workspace
|
102
|
+
end
|
103
|
+
if @bo_opts.to_s!=''
|
104
|
+
params['Opts'] = @bo_opts
|
105
|
+
end
|
106
|
+
return params
|
107
|
+
end
|
108
|
+
|
109
|
+
def sendBO(bourl, sendStmt)
|
110
|
+
params = formatRequest(sendStmt)
|
111
|
+
@log.debug("\nbourl=#{bourl} params=#{params.to_json}")
|
112
|
+
|
113
|
+
begin
|
114
|
+
resp = RestClient.post bourl, params.to_json, :content_type =>:json, :accept =>:json
|
115
|
+
@log.debug("resp= #{resp.body}")
|
116
|
+
rescue Exception => e
|
117
|
+
@log.error(e.message)
|
118
|
+
raise "Failed to sendBO: #{e.message}"
|
119
|
+
end
|
120
|
+
return resp
|
121
|
+
end
|
122
|
+
|
123
|
+
end #end class
|
124
|
+
|
125
|
+
def initialize
|
126
|
+
super
|
127
|
+
require 'rest-client'
|
128
|
+
require 'json'
|
129
|
+
log.info("bigobject initialize")
|
130
|
+
end
|
131
|
+
|
132
|
+
def configure(conf)
|
133
|
+
super
|
134
|
+
|
135
|
+
if remove_tag_prefix = conf['remove_tag_prefix']
|
136
|
+
@remove_tag_prefix = Regexp.new('^' + Regexp.escape(remove_tag_prefix))
|
137
|
+
end
|
138
|
+
|
139
|
+
@tables = []
|
140
|
+
@default_table = nil
|
141
|
+
conf.elements.select { |e|
|
142
|
+
e.name == 'table'
|
143
|
+
}.each { |e|
|
144
|
+
te = TableElement.new(log)
|
145
|
+
te.configure(e)
|
146
|
+
# puts "conf.elements #{e}"
|
147
|
+
@tables << te
|
148
|
+
}
|
149
|
+
|
150
|
+
# @tables.each {|t| puts t.to_s}
|
151
|
+
end
|
152
|
+
|
153
|
+
def start
|
154
|
+
super
|
155
|
+
log.info("bigobject start")
|
156
|
+
end
|
157
|
+
|
158
|
+
def shutdown
|
159
|
+
super
|
160
|
+
log.info("bigobject shutdown")
|
161
|
+
end
|
162
|
+
|
163
|
+
|
164
|
+
# This method is called when an event reaches to Fluentd.
|
165
|
+
def format(tag, time, record)
|
166
|
+
# puts "tag=#{tag}, time=#{time}, record=#{record}"
|
167
|
+
[tag, time, record].to_msgpack
|
168
|
+
end
|
169
|
+
|
170
|
+
# This method is called every flush interval. Write the buffer chunk
|
171
|
+
# to files or databases here.
|
172
|
+
# 'chunk' is a buffer chunk that includes multiple formatted events.
|
173
|
+
def write(chunk)
|
174
|
+
unknownChunks = []
|
175
|
+
@tables.each { |table|
|
176
|
+
# puts "write table #{table}"
|
177
|
+
# puts "chunk.key= #{chunk.key}"
|
178
|
+
if table.mpattern.match(chunk.key)
|
179
|
+
log.info("add known chunk #{chunk.key}")
|
180
|
+
return table.send(@bigobject_url, chunk)
|
181
|
+
end
|
182
|
+
}
|
183
|
+
|
184
|
+
log.warn("unknown chunk #{chunk.key}")
|
185
|
+
|
186
|
+
end
|
187
|
+
|
188
|
+
def format_tag(tag)
|
189
|
+
if @remove_tag_prefix
|
190
|
+
tag.gsub(@remove_tag_prefix, '')
|
191
|
+
else
|
192
|
+
tag
|
193
|
+
end
|
194
|
+
end
|
195
|
+
|
196
|
+
def emit(tag, es, chain)
|
197
|
+
super(tag, es, chain, format_tag(tag))
|
198
|
+
end
|
199
|
+
end
|
metadata
ADDED
@@ -0,0 +1,107 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: fluent-plugin-bigobject
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.3
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Andrea Sung
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-09-10 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'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rest-client
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
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: json
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
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: rake
|
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: 'Fluentd output plugin to insert BIGOBJECT '
|
70
|
+
email:
|
71
|
+
- andrea@bigobject.io
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- Gemfile
|
78
|
+
- LICENSE.txt
|
79
|
+
- README.md
|
80
|
+
- Rakefile
|
81
|
+
- fluent-plugin-bigobject.gemspec
|
82
|
+
- lib/fluent/plugin/out_bigobject.rb
|
83
|
+
homepage: https://github.com/andreasung/fluent-plugin-bigobject
|
84
|
+
licenses:
|
85
|
+
- MIT
|
86
|
+
metadata: {}
|
87
|
+
post_install_message:
|
88
|
+
rdoc_options: []
|
89
|
+
require_paths:
|
90
|
+
- lib
|
91
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - ">="
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '0'
|
96
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
97
|
+
requirements:
|
98
|
+
- - ">="
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
version: '0'
|
101
|
+
requirements: []
|
102
|
+
rubyforge_project:
|
103
|
+
rubygems_version: 2.2.2
|
104
|
+
signing_key:
|
105
|
+
specification_version: 4
|
106
|
+
summary: Fluentd output plugin to insert BIGOBJECT
|
107
|
+
test_files: []
|