fluent-plugin-azure-table 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
+ SHA256:
3
+ metadata.gz: 0a844a14fe06c8bb2c7161da361728ae2b6732ba26fa4b291d76bb660a9bae5c
4
+ data.tar.gz: 79ea422e41baf90fe70bd634d9bac827e3087e50af8f1a344252d956897127eb
5
+ SHA512:
6
+ metadata.gz: 98cfc0330eca4264d88c3766ca544bab93a99ad6b715891f49705b93b6ff92da7f9f92c21ccede9614714592dddaffc3dd3f94a5292ef1a482dbeea80d06171b
7
+ data.tar.gz: 707c41d69552d8c34647ce4162bb2688095432af01e72b437468f4bfbf8e1d0b79ae48fc4e30cd6d2d07f792344393c9cf3766f8aa1cb7dd3403e2a9e3688c42
@@ -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,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-azure-storage-tables.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,45 @@
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
+ add_time_to_partition_key true
23
+ add_time_row_key true
24
+ add_uuid_to_row_key true
25
+ key_delimiter __
26
+ </match>
27
+ ```
28
+
29
+ * type (required) - azuretables
30
+ * account_name (required) - AZURE_STORAGE_ACCOUNT (from your Azure portal).
31
+ * access_key (required) - AZURE_STORAGE_ACCESS_KEY (from your Azure portal).
32
+ * table (required) - table name where you want to store event records.
33
+ * detach_process (optional) - number of processes. You can launch multiprocessing if you need high throughput.
34
+ * create_table_if_not_exists (optional) - Set __true__ if you want create table if it doesn't exist. Default: __false__.
35
+ * partition_keys (optional) - A string with comma delimiter.List of properties which are used to create a composite __PartitionKey__.
36
+ * row_keys (optional) - A string with comma delimiter.List of properties which are used to create a composite __RowKey__.
37
+ * key_delimiter (optional) - A string becomes delimiter of partition key and row key in table. Default: "__" (underscores x2)
38
+ * add_uuid_to_row_key (optional) - Adds uuid to row key to try to make partition_key and row_key unique across , in case of same partition_key is used across servers. Default: __true__.
39
+ * add_time_to_partition_key (optional) - Adds current time to partition_key. Default: __true__
40
+ * add_time_to_row_key (optional) - Adds current time to row_key. Default: __true__
41
+
42
+ ## TODO
43
+
44
+ ## Contributing
45
+ Bug reports and pull requests are welcome on GitHub at [https://github.com/VikramNisarga/fluent-plugin-azuretables](https://github.com/VikramNisarga/fluent-plugin-azuretables).
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,24 @@
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-azure-table"
7
+ spec.version = "0.0.1"
8
+ spec.authors = ["Vikram"]
9
+ spec.email = ["vikramnisarga1@gmail.com"]
10
+ spec.summary = "Fluentd plugin for Azure Tables Storage."
11
+ spec.description = "Fluentd plugin to add event record into Azure Tables Storage"
12
+ spec.homepage = "https://github.com/VikramNisarga/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.14.10'
21
+ spec.add_dependency "azure-storage-table", '~> 2.0'
22
+ spec.add_development_dependency "bundler", "~> 2.1"
23
+ spec.add_development_dependency "rake", "~> 12.0"
24
+ end
@@ -0,0 +1,150 @@
1
+ # coding: utf-8
2
+ require 'azure/storage/table'
3
+ require 'time'
4
+ require 'msgpack'
5
+
6
+ module Fluent
7
+ class AzuretablesOutput < BufferedOutput
8
+ Plugin.register_output('azuretables', self)
9
+
10
+ include DetachMultiProcessMixin
11
+
12
+ ENTITY_SIZE_LIMIT = 1024 * 1024 # 1MB
13
+ BATCHWRITE_ENTITY_LIMIT = 100
14
+ BATCHWRITE_SIZE_LIMIT = 4 * 1024 * 1024 # 4MB
15
+
16
+ # config_param defines a parameter
17
+ config_param :account_name, :string # your azure storage account
18
+ config_param :access_key, :string, :secret => true # your azure storage access key
19
+ config_param :table, :string # azure storage table name
20
+ config_param :create_table_if_not_exists, :bool, :default => false
21
+ config_param :key_delimiter, :string, :default => '__'
22
+ config_param :partition_keys, :string, :default => nil
23
+ config_param :row_keys, :string, :default => nil
24
+ config_param :add_uuid_to_row_key, :bool, :default => true
25
+ config_param :add_time_to_partition_key, :bool, :default => true
26
+ config_param :add_time_row_key, :bool, :default => true
27
+
28
+ # This method is called before starting.
29
+ # 'conf' is a Hash that includes configuration parameters.
30
+ # If the configuration is invalid, raise Fluent::ConfigError
31
+ def configure(conf)
32
+ super
33
+ unless @partition_keys.nil?
34
+ @partition_key_array = @partition_keys.split(',')
35
+ end
36
+
37
+ unless @row_keys.nil?
38
+ @row_key_array = @row_keys.split(',')
39
+ end
40
+
41
+ end
42
+
43
+ # connect azure table storage service
44
+ def start
45
+ super
46
+ unless @account_name.nil? || @access_key.nil?
47
+ @table_client = Azure::Storage::Table::TableService.create(storage_account_name: @account_name,storage_access_key:@access_key)
48
+ end
49
+
50
+ begin
51
+ @table_client.create_table(@table) if @create_table_if_not_exists && !table_exists?(@table)
52
+ rescue Exception => e
53
+ log.error e
54
+ exit!
55
+ end
56
+ end
57
+
58
+ def table_exists?(table_name)
59
+ begin
60
+ @table_client.get_table(table_name)
61
+ true
62
+ rescue Azure::Core::Http::HTTPError => e
63
+ false
64
+ rescue Exception => e
65
+ log.fatal "UnknownError: '#{e}'"
66
+ exit!
67
+ end
68
+ end
69
+
70
+ # This method is called when shutting down.
71
+ def shutdown
72
+ super
73
+ end
74
+
75
+ #create entity from event record
76
+ def format(tag, time, record)
77
+ partition_keys = []
78
+ row_keys = []
79
+ record.each_pair do |name, val|
80
+ if @partition_key_array && @partition_key_array.include?(name)
81
+ partition_keys << val
82
+ record.delete(name)
83
+ elsif @row_key_array && @row_key_array.include?(name)
84
+ row_keys << val
85
+ record.delete(name)
86
+ end
87
+ end
88
+ if @add_time_to_partition_key
89
+ partition_keys << Time.now.strftime("%Y%m%d")
90
+ end
91
+ if @add_time_to_partition_key
92
+ row_keys << Time.now.getutc.to_i
93
+ end
94
+ if @add_uuid_to_row_key
95
+ row_keys << SecureRandom.uuid
96
+ end
97
+
98
+ entity = Hash.new
99
+ entity['partition_key'] = partition_keys.join(@key_delimiter)
100
+ entity['row_key'] = row_keys.join(@key_delimiter)
101
+ entity['entity_values'] = record
102
+ entity.to_msgpack
103
+ end
104
+
105
+ def format_key(record, keys, key_delimiter)
106
+ ret = []
107
+ record.each_pair do |name, val|
108
+ ret << val if keys.include?(name)
109
+ end
110
+ ret.join(key_delimiter)
111
+ end
112
+
113
+ def write(chunk)
114
+ batch_size = 0
115
+ group_entities = Hash.new
116
+ chunk.msgpack_each do |entity|
117
+ partition_key = entity['partition_key']
118
+ group_entities[partition_key] = [] unless group_entities.has_key?(partition_key)
119
+ group_entities[partition_key] << entity
120
+ batch_size += entity.to_json.length
121
+ if group_entities[partition_key].size >= BATCHWRITE_ENTITY_LIMIT || batch_size >= BATCHWRITE_SIZE_LIMIT
122
+ insert_entities(partition_key, group_entities[partition_key])
123
+ group_entities[partition_key] = []
124
+ batch_size = 0
125
+ end
126
+ end
127
+ unless group_entities.empty?
128
+ group_entities.each_pair do |partition_key, entities|
129
+ insert_entities(partition_key, entities)
130
+ end
131
+ end
132
+ end
133
+
134
+ def insert_entities(partition_key, entities)
135
+ begin
136
+ batch = Azure::Storage::Table::Batch.new(@table, partition_key) do
137
+ entities.each do |entity|
138
+ insert entity['row_key'], entity['entity_values']
139
+ end
140
+ end
141
+ return @table_client.execute_batch(batch)
142
+ rescue Exception => e
143
+ log.fatal "UnknownError: '#{e}'"
144
+ log.debug partition_key
145
+ log.debug entities.inspect
146
+ end
147
+ end
148
+
149
+ end # class
150
+ end # module
metadata ADDED
@@ -0,0 +1,108 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fluent-plugin-azure-table
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Vikram
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-03-26 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.14.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.14.10
27
+ - !ruby/object:Gem::Dependency
28
+ name: azure-storage-table
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '2.1'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '2.1'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '12.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '12.0'
69
+ description: Fluentd plugin to add event record into Azure Tables Storage
70
+ email:
71
+ - vikramnisarga1@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - CHANGELOG.md
78
+ - Gemfile
79
+ - LICENSE
80
+ - README.md
81
+ - Rakefile
82
+ - fluent-plugin-azure-table.gemspec
83
+ - lib/fluent/plugin/out_azuretables.rb
84
+ homepage: https://github.com/VikramNisarga/fluent-plugin-azuretables
85
+ licenses:
86
+ - MIT
87
+ metadata: {}
88
+ post_install_message:
89
+ rdoc_options: []
90
+ require_paths:
91
+ - lib
92
+ required_ruby_version: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ required_rubygems_version: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - ">="
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ requirements: []
103
+ rubyforge_project:
104
+ rubygems_version: 2.7.6.2
105
+ signing_key:
106
+ specification_version: 4
107
+ summary: Fluentd plugin for Azure Tables Storage.
108
+ test_files: []