fluent-plugin-azuretables 0.0.1

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: 717265673ec738d28e0944107c0c914db730d802
4
+ data.tar.gz: 8744a23d087250c75451f7ad64b71332fa1cf18e
5
+ SHA512:
6
+ metadata.gz: 637d2208fcb7116c36bec17e81391f8aa9e1d9976d62746ce5f19f9479efcb94227c0c04ad38cef98c2269be582d2b3bd2a130df1885e9f851fe8b7f30483add
7
+ data.tar.gz: 503e67abc865fea869c37cc8af53e20fb0952a5ef96149eb5346645ab6db712febdf32f477e3b0895930bc121982c7237c7d02c429aa483ca5b5817acce04832
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.0
4
+ before_install: gem install bundler -v 1.10.6
@@ -0,0 +1,8 @@
1
+ # ChangeLog
2
+
3
+ - - -
4
+ ### Version 0.1.0
5
+ ###### 08 Sep 2015 ######
6
+ * Very first commit.
7
+
8
+ - - -
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in fluent-plugin-azuretables.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) <2015> <Anh Phong (dev.hibiki@gmail.com)>
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,39 @@
1
+ # Azure Tables output plugin for [Fluentd](http://www.fluentd.org/)
2
+
3
+ ## Installation
4
+
5
+ ```ruby
6
+ fluent-gem install fluent-plugin-azuretables
7
+ ```
8
+
9
+ ## Usage
10
+
11
+ ### Configuration
12
+ ```
13
+ <match azuretables.**>
14
+ type azuretables
15
+ account_name AZURE_STORAGE_ACCOUNT
16
+ access_key AZURE_STORAGE_ACCESS_KEY
17
+ table YOUR_TABLE_NAME
18
+ detach_process 6
19
+ create_table_if_not_exists false
20
+ partition_keys test-partition-key-01,test-partition-key-02
21
+ row_keys rk1 test-row-key-01,test-row-key-02
22
+ key_delimiter __
23
+ </match>
24
+ ```
25
+
26
+ * type (required) - azuretables
27
+ * account_name (required) - AZURE_STORAGE_ACCOUNT (from your Azure portal).
28
+ * access_key (required) - AZURE_STORAGE_ACCESS_KEY (from your Azure portal).
29
+ * table (required) - table name where you want to store event records.
30
+ * detach_process (optional) - number of processes. You can launch multiprocessing if you need high throughput.
31
+ * create_table_if_not_exists (optional) - Set __true__ if you want create table if it doesn't exist. Default: __false__.
32
+ * partition_keys (optional) - A string with comma delimiter.List of properties which are used to create a composite __PartitionKey__.
33
+ * row_keys (optional) - A string with comma delimiter.List of properties which are used to create a composite __RowKey__.
34
+ * key_delimiter (optional) - A string becomes delimiter of partition key and row key in table. Default: "__" (underscores x2)
35
+
36
+ ## TODO
37
+
38
+ ## Contributing
39
+ Bug reports and pull requests are welcome on GitHub at [https://github.com/heocoi/fluent-plugin-azuretables](https://github.com/heocoi/fluent-plugin-azuretables).
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,26 @@
1
+ # coding: 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 |spec|
6
+ spec.name = "fluent-plugin-azuretables"
7
+ spec.version = "0.0.1"
8
+ spec.authors = ["Anh Phong"]
9
+ spec.email = ["dev.hibiki@gmail.com"]
10
+ spec.summary = %q{Fluent plugin to add event record into Azure Tables Storage.}
11
+ spec.description = %q{Fluent plugin to add event record into Azure Tables Storage.}
12
+ spec.homepage = "https://github.com/heocoi/fluent-plugin-azuretables"
13
+ spec.licenses = ["MIT"]
14
+ spec.has_rdoc = false
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_dependency "fluentd", '~> 0'
21
+ spec.add_dependency "azure", '~> 0'
22
+ spec.add_dependency "msgpack", '~> 0'
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.10"
25
+ spec.add_development_dependency "rake", "~> 10.0"
26
+ end
@@ -0,0 +1,143 @@
1
+ # coding: utf-8
2
+ require 'azure'
3
+ require 'msgpack'
4
+
5
+ module Fluent
6
+ class AzuretablesOutput < BufferedOutput
7
+ Plugin.register_output('azuretables', self)
8
+
9
+ include DetachMultiProcessMixin
10
+
11
+ ENTITY_SIZE_LIMIT = 1024*1024 # 1MB
12
+ BATCHWRITE_ENTITY_LIMIT = 100
13
+ BATCHWRITE_SIZE_LIMIT = 4*1024*1024 # 4MB
14
+
15
+ # config_param defines a parameter
16
+ config_param :account_name, :string # your azure storage account
17
+ config_param :access_key, :string # your azure storage access key
18
+ config_param :table, :string # azure storage table name
19
+ config_param :create_table_if_not_exists, :bool, :default => false
20
+ config_param :key_delimiter, :string, :default => '__'
21
+ config_param :partition_keys, :string, :default => nil
22
+ config_param :row_keys, :string, :default => nil
23
+
24
+ # This method is called before starting.
25
+ # 'conf' is a Hash that includes configuration parameters.
26
+ # If the configuration is invalid, raise Fluent::ConfigError.
27
+ def configure(conf)
28
+ super
29
+ unless @partition_keys.nil?
30
+ @partition_key_array = @partition_keys.split(',')
31
+ end
32
+
33
+ unless @row_keys.nil?
34
+ @row_key_array = @row_keys.split(',')
35
+ end
36
+ end
37
+
38
+ # connect azure table storage service
39
+ def start
40
+ super
41
+ unless @account_name.nil? || @access_key.nil?
42
+ Azure.config.storage_account_name = @account_name
43
+ Azure.config.storage_access_key = @access_key
44
+ end
45
+
46
+ detach_multi_process do
47
+ super
48
+
49
+ begin
50
+ @azure_table_service = Azure::Table::TableService.new
51
+ # create table if not exits
52
+ @azure_table_service.create_table(@table) if !table_exists?(@table) && @create_table_if_not_exists
53
+ rescue Exception => e
54
+ log.error e
55
+ exit!
56
+ end
57
+ end
58
+ end
59
+
60
+ def table_exists?(table_name)
61
+ begin
62
+ @azure_table_service.get_table(table_name)
63
+ true
64
+ rescue Azure::Core::Http::HTTPError => e
65
+ false
66
+ rescue Exception => e
67
+ log.fatal "UnknownError: '#{e}'"
68
+ exit!
69
+ end
70
+ end
71
+
72
+ # This method is called when shutting down.
73
+ def shutdown
74
+ super
75
+ end
76
+
77
+ # create entity from event record
78
+ def format(tag, time, record)
79
+ partition_keys = []
80
+ row_keys = []
81
+ record.each_pair do |name, val|
82
+ if @partition_key_array.include?(name)
83
+ partition_keys << val
84
+ record.delete(name)
85
+ elsif @row_key_array.include?(name)
86
+ row_keys << val
87
+ record.delete(name)
88
+ end
89
+ end
90
+
91
+ entity = Hash.new
92
+ entity['partition_key'] = partition_keys.join(@key_delimiter)
93
+ entity['row_key'] = row_keys.join(@key_delimiter)
94
+ entity['entity_values'] = record
95
+ entity.to_msgpack
96
+ end
97
+
98
+ def format_key(record, keys, key_delimiter)
99
+ ret = []
100
+ record.each_pair do |name, val|
101
+ ret << val if keys.include?(name)
102
+ end
103
+ ret.join(key_delimiter)
104
+ end
105
+
106
+ def write(chunk)
107
+ batch_size = 0
108
+ group_entities = Hash.new
109
+ chunk.msgpack_each do |entity|
110
+ partition_key = entity['partition_key']
111
+ group_entities[partition_key] = [] unless group_entities.has_key?(partition_key)
112
+ group_entities[partition_key] << entity
113
+ batch_size += entity.to_json.length
114
+ if group_entities[partition_key].size >= BATCHWRITE_ENTITY_LIMIT || batch_size >= BATCHWRITE_SIZE_LIMIT
115
+ insert_entities(partition_key, group_entities[partition_key])
116
+ group_entities[partition_key] = []
117
+ batch_size = 0
118
+ end
119
+ end
120
+ unless group_entities.empty?
121
+ group_entities.each_pair do |partition_key, entities|
122
+ insert_entities(partition_key, entities)
123
+ end
124
+ end
125
+ end
126
+
127
+ def insert_entities(partition_key, entities)
128
+ begin
129
+ batch = Azure::Table::Batch.new(@table, partition_key) do
130
+ entities.each do |entity|
131
+ insert entity['row_key'], entity['entity_values']
132
+ end
133
+ end
134
+ return @azure_table_service.execute_batch(batch)
135
+ rescue Exception => e
136
+ log.fatal "UnknownError: '#{e}'"
137
+ log.debug partition_key
138
+ log.debug entities.inspect
139
+ end
140
+ end
141
+
142
+ end # class
143
+ end # module
metadata ADDED
@@ -0,0 +1,123 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fluent-plugin-azuretables
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Anh Phong
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-09-15 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: azure
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: msgpack
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: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.10'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.10'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '10.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '10.0'
83
+ description: Fluent plugin to add event record into Azure Tables Storage.
84
+ email:
85
+ - dev.hibiki@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".travis.yml"
92
+ - CHANGELOG.md
93
+ - Gemfile
94
+ - LICENSE
95
+ - README.md
96
+ - Rakefile
97
+ - fluent-plugin-azuretables.gemspec
98
+ - lib/fluent/plugin/out_azuretables.rb
99
+ homepage: https://github.com/heocoi/fluent-plugin-azuretables
100
+ licenses:
101
+ - MIT
102
+ metadata: {}
103
+ post_install_message:
104
+ rdoc_options: []
105
+ require_paths:
106
+ - lib
107
+ required_ruby_version: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ required_rubygems_version: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ requirements: []
118
+ rubyforge_project:
119
+ rubygems_version: 2.2.0.rc.1
120
+ signing_key:
121
+ specification_version: 4
122
+ summary: Fluent plugin to add event record into Azure Tables Storage.
123
+ test_files: []