fluent-plugin-azure-queue 0.0.1.pre

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: b6a171e37ab51926fea05fb9a3af2b1732c2dc06
4
+ data.tar.gz: 20de54cb2df97d3a1f2f25d2e66a30a6b8ea79e6
5
+ SHA512:
6
+ metadata.gz: ef3d713e38a5cee209a69930dfba747ac37239d1ae443e7473de000391b558bd9eecae4f29b6e111e3d891bb1fe91b17b0dbe458dbf9a2905e16e27939966bd5
7
+ data.tar.gz: aef6bd13e15495361dcc8414d3b17d8abf92c13ca87b98bd6e76c057d0f2e7be0d68fe2b8a750ccbcad6b1818a88fef959369f2f0069397b3128e90d94651ef6
data/.gitignore ADDED
@@ -0,0 +1,50 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /spec/examples.txt
9
+ /test/tmp/
10
+ /test/version_tmp/
11
+ /tmp/
12
+
13
+ # Used by dotenv library to load environment variables.
14
+ # .env
15
+
16
+ ## Specific to RubyMotion:
17
+ .dat*
18
+ .repl_history
19
+ build/
20
+ *.bridgesupport
21
+ build-iPhoneOS/
22
+ build-iPhoneSimulator/
23
+
24
+ ## Specific to RubyMotion (use of CocoaPods):
25
+ #
26
+ # We recommend against adding the Pods directory to your .gitignore. However
27
+ # you should judge for yourself, the pros and cons are mentioned at:
28
+ # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
29
+ #
30
+ # vendor/Pods/
31
+
32
+ ## Documentation cache and generated files:
33
+ /.yardoc/
34
+ /_yardoc/
35
+ /doc/
36
+ /rdoc/
37
+
38
+ ## Environment normalization:
39
+ /.bundle/
40
+ /vendor/bundle
41
+ /lib/bundler/man/
42
+
43
+ # for a library or gem, you might want to ignore these files since the code is
44
+ # intended to run in multiple environments; otherwise, check them in:
45
+ # Gemfile.lock
46
+ # .ruby-version
47
+ # .ruby-gemset
48
+
49
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
50
+ .rvmrc
data/.travis.yml ADDED
@@ -0,0 +1,19 @@
1
+ language: ruby
2
+
3
+ rvm:
4
+ - 2.1
5
+ - 2.2.6
6
+ - 2.3.3
7
+ - 2.4.0
8
+
9
+ branches:
10
+ only:
11
+ - master
12
+
13
+ gemfile:
14
+ - Gemfile
15
+
16
+ before_install: gem update bundler
17
+ script: bundle exec rake test
18
+
19
+ sudo: false
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "http://rubygems.org"
2
+
3
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,65 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ fluent-plugin-azure-queue (0.0.1.pre.pre)
5
+ azure-storage (>= 0.12.3.preview, < 0.13)
6
+ fluentd (>= 0.12.2, < 0.14)
7
+ nokogiri
8
+
9
+ GEM
10
+ remote: http://rubygems.org/
11
+ specs:
12
+ azure-core (0.1.10)
13
+ faraday (~> 0.9)
14
+ faraday_middleware (~> 0.10)
15
+ azure-storage (0.12.3.preview)
16
+ azure-core (~> 0.1)
17
+ faraday (~> 0.9)
18
+ faraday_middleware (~> 0.10)
19
+ cool.io (1.5.1)
20
+ faraday (0.13.1)
21
+ multipart-post (>= 1.2, < 3)
22
+ faraday_middleware (0.12.2)
23
+ faraday (>= 0.7.4, < 1.0)
24
+ flexmock (2.3.5)
25
+ fluentd (0.12.39)
26
+ cool.io (>= 1.2.2, < 2.0.0)
27
+ http_parser.rb (>= 0.5.1, < 0.7.0)
28
+ json (>= 1.4.3)
29
+ msgpack (>= 0.5.11, < 2)
30
+ sigdump (~> 0.2.2)
31
+ string-scrub (>= 0.0.3, <= 0.0.5)
32
+ tzinfo (>= 1.0.0)
33
+ tzinfo-data (>= 1.0.0)
34
+ yajl-ruby (~> 1.0)
35
+ http_parser.rb (0.6.0)
36
+ json (2.1.0)
37
+ mini_portile2 (2.1.0)
38
+ msgpack (1.1.0)
39
+ multipart-post (2.0.0)
40
+ nokogiri (1.7.2)
41
+ mini_portile2 (~> 2.1.0)
42
+ power_assert (1.0.2)
43
+ rake (12.0.0)
44
+ sigdump (0.2.4)
45
+ string-scrub (0.0.5)
46
+ test-unit (3.2.5)
47
+ power_assert
48
+ thread_safe (0.3.6)
49
+ tzinfo (1.2.3)
50
+ thread_safe (~> 0.1)
51
+ tzinfo-data (1.2017.2)
52
+ tzinfo (>= 1.0.0)
53
+ yajl-ruby (1.3.0)
54
+
55
+ PLATFORMS
56
+ ruby
57
+
58
+ DEPENDENCIES
59
+ flexmock (>= 1.3.3)
60
+ fluent-plugin-azure-queue!
61
+ rake (>= 0.9.2)
62
+ test-unit (>= 3.0.8)
63
+
64
+ BUNDLED WITH
65
+ 1.15.3
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2017 Scott Bonebrake
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 all
13
+ 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 THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,51 @@
1
+ # A [Fluentd](http://github.com/fluent/fluentd) plugin to read from azure queues
2
+
3
+ ## Dependencies
4
+
5
+ fluentd v.12
6
+
7
+ ## Input: Configuration
8
+
9
+ <source>
10
+ @type azure_queue
11
+
12
+ tag queue_input
13
+ storage_account_name my_storage_account
14
+ storage_access_key my_storage_access_key
15
+ queue_name my_storage_queue
16
+ fetch_interval 5
17
+ batch_size 10
18
+ lease_time 30
19
+ </source>
20
+
21
+ **tag (required)**
22
+
23
+ The tag for the input
24
+
25
+ **storage_account_name (required)**
26
+
27
+ The storage account name
28
+
29
+ **storage_access_key (required)**
30
+
31
+ The storage account access key
32
+
33
+ **queue_name (required)**
34
+
35
+ The storage queue name
36
+
37
+ **message_key**
38
+
39
+ The the record key to put the message data into. Default 'message'
40
+
41
+ **fetch_interval**
42
+
43
+ How long to wait between getting messages from the queue. Default 5
44
+
45
+ **batch_size**
46
+
47
+ The maximum number of messages to pull from the queue at once. Default 10. Max 32
48
+
49
+ **lease_time**
50
+
51
+ The time to lease the messages for. Default 30
data/Rakefile ADDED
@@ -0,0 +1,13 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
3
+
4
+ require 'rake/testtask'
5
+
6
+ Rake::TestTask.new(:test) do |test|
7
+ test.libs << 'lib'
8
+ test.test_files = FileList['test/test_*.rb']
9
+ test.verbose = false
10
+ test.warning = false
11
+ end
12
+
13
+ task :default => [:build]
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1.pre
@@ -0,0 +1,24 @@
1
+ # encoding: utf-8
2
+ $:.push File.expand_path('../lib', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.name = "fluent-plugin-azure-queue"
6
+ gem.description = "Fluent input plugin for azure queue input"
7
+ gem.license = "MIT"
8
+ gem.homepage = "https://github.com/sbonebrake/fluent-plugin-azure-queue"
9
+ gem.summary = gem.description
10
+ gem.version = File.read("VERSION").strip
11
+ gem.authors = ["Scott Bonebrake"]
12
+ gem.email = "N/A"
13
+ gem.has_rdoc = false
14
+ gem.files = `git ls-files`.split("\n")
15
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
16
+ gem.require_paths = ['lib']
17
+
18
+ gem.add_dependency "fluentd", [">= 0.12.2", "< 0.14"]
19
+ gem.add_dependency "azure-storage", [">= 0.12.3.preview", "< 0.13"]
20
+ gem.add_dependency "nokogiri"
21
+ gem.add_development_dependency "rake", ">= 0.9.2"
22
+ gem.add_development_dependency "test-unit", ">= 3.0.8"
23
+ gem.add_development_dependency "flexmock", ">= 1.3.3"
24
+ end
@@ -0,0 +1,90 @@
1
+ require 'fluent/input'
2
+ require 'azure/storage'
3
+ require 'base64'
4
+
5
+ module Fluent
6
+ class AzureQueueInput < Input
7
+ Fluent::Plugin.register_input('azure_queue', self)
8
+
9
+ desc 'Tag of the output events.'
10
+ config_param :tag, :string
11
+ desc 'The azure storage account name'
12
+ config_param :storage_account_name, :string
13
+ desc 'The azure storage account access key'
14
+ config_param :storage_access_key, :string
15
+ desc 'The azure storage account queue name'
16
+ config_param :queue_name, :string
17
+ desc 'The the record key to put the message data into'
18
+ config_param :message_key, :string, default: 'message'
19
+ desc 'The time in seconds to sleep between fetching messages'
20
+ config_param :fetch_interval, :integer, default: 5
21
+ desc 'The number of messages to fetch during each request'
22
+ config_param :batch_size, :integer, default: 10
23
+ desc 'The the lease time on the messages in seconds'
24
+ config_param :lease_time, :integer, default: 30
25
+
26
+ def configure(conf)
27
+ super
28
+ end
29
+
30
+ def start
31
+ super
32
+ if @batch_size > 32 || @batch_size < 1
33
+ raise Fluent::ConfigError, "fluent-plugin-azure-queue: 'batch_size' parameter must be between 1 and 32: #{@batch_size}"
34
+ end
35
+ @queue_client = Azure::Storage::Client.create(
36
+ :storage_account_name => @storage_account_name,
37
+ :storage_access_key => @storage_access_key).queue_client
38
+ log.debug("Succeeded to creating azure queue client")
39
+ @running = true
40
+
41
+ @thread = Thread.new(&method(:run))
42
+ end
43
+
44
+ def shutdown
45
+ log.debug("Begin azure queue shutdown")
46
+ @running = false
47
+ @thread.join
48
+ log.debug("Finish azure queue shutdown")
49
+ super
50
+ end
51
+
52
+ private
53
+
54
+ def run
55
+ log.debug("Begin running azure queue")
56
+ @next_fetch_time = Time.now
57
+ while @running
58
+ deleted = false
59
+ begin
60
+ if Time.now > @next_fetch_time
61
+ @next_fetch_time += @fetch_interval
62
+ log.trace("Fetching #{@batch_size} messages from azure queue", queue_name: @queue_name)
63
+ messages = @queue_client.list_messages(@queue_name, @lease_time, { number_of_messages: @batch_size })
64
+ log.trace("Recieved #{messages.count} messages from azure queue", queue_name: @queue_name)
65
+ messages.each do |message|
66
+ deleted = false
67
+ message_content = Base64.decode64(message.message_text)
68
+ router.emit(@tag, Fluent::Engine.now, { @message_key => message_content })
69
+ log.trace("Emitted azure queue message", queue_name: @queue_name, id: message.id, content: message_content)
70
+ @queue_client.delete_message(@queue_name, message.id, message.pop_receipt)
71
+ log.trace("Deleted azure queue message", queue_name: @queue_name, id: message.id)
72
+ deleted = true
73
+ end
74
+ else
75
+ sleep 0.05
76
+ end
77
+ rescue => e
78
+ if deleted
79
+ log.warn(error: e)
80
+ log.warn_backtrace(e.backtrace)
81
+ else
82
+ log.warn("Message emmitted but not deleted from azure queue", queue_name: @queue_name, error: e)
83
+ log.warn_backtrace(e.backtrace)
84
+ end
85
+ end
86
+ end
87
+
88
+ end
89
+ end
90
+ end
@@ -0,0 +1,73 @@
1
+ require 'fluent/test'
2
+ require 'fluent/plugin/in_azure_queue'
3
+ require 'flexmock/test_unit'
4
+
5
+ class AzureQueueInputTest < Test::Unit::TestCase
6
+ def setup
7
+ Fluent::Test.setup
8
+ @time = Time.parse("2017-08-17 18:03:27 UTC")
9
+ Fluent::Engine.now = @time
10
+ if Fluent.const_defined?(:EventTime)
11
+ stub(Fluent::EventTime).now { @time }
12
+ end
13
+ end
14
+
15
+ CONFIG = %[
16
+ tag test_tag
17
+ storage_account_name test_storage_account_name
18
+ storage_access_key test_storage_access_key
19
+ queue_name test_queue_name
20
+ ]
21
+
22
+ def create_driver(conf = CONFIG)
23
+ d = Fluent::Test::InputTestDriver.new(Fluent::AzureQueueInput)
24
+ d.configure(conf)
25
+ d
26
+ end
27
+
28
+ def test_configure
29
+ d = create_driver
30
+ assert_equal 'test_tag', d.instance.tag
31
+ assert_equal 'test_storage_account_name', d.instance.storage_account_name
32
+ assert_equal 'test_storage_access_key', d.instance.storage_access_key
33
+ assert_equal 'test_queue_name', d.instance.queue_name
34
+ end
35
+
36
+ Struct.new("QueueMessage", :id, :pop_receipt, :message_text)
37
+
38
+ def setup_mocks(driver, messages)
39
+ queue_client = flexmock("queue_client")
40
+ queue_client.should_receive(:list_messages).with(
41
+ driver.instance.queue_name,
42
+ driver.instance.lease_time,
43
+ { number_of_messages: driver.instance.batch_size}).and_return(messages).once
44
+ client = flexmock("client", :queue_client => queue_client)
45
+ flexmock(Azure::Storage::Client, :create => client)
46
+ queue_client
47
+ end
48
+
49
+ def test_two_messages
50
+ d = create_driver
51
+ messages = [ Struct::QueueMessage.new(1, 99, Base64.encode64("test line")),
52
+ Struct::QueueMessage.new(2, 100, Base64.encode64("test line2"))]
53
+ queue_client = setup_mocks(d, messages)
54
+ queue_client.should_receive(:delete_message).with(d.instance.queue_name, messages[0].id,messages[0].pop_receipt).once
55
+ queue_client.should_receive(:delete_message).with(d.instance.queue_name, messages[1].id,messages[1].pop_receipt).once
56
+ d.run do
57
+ sleep 1
58
+ end
59
+ assert_equal(2, d.emits.size)
60
+ d.expect_emit(d.instance.tag, @time, { "message" => "test line" })
61
+ d.expect_emit(d.instance.tag, @time, { "message" => "test line2" })
62
+ end
63
+
64
+ def test_no_messages
65
+ d = create_driver
66
+ messages = []
67
+ queue_client = setup_mocks(d, messages)
68
+ d.run do
69
+ sleep 1
70
+ end
71
+ assert_equal(0, d.emits.size)
72
+ end
73
+ end
metadata ADDED
@@ -0,0 +1,151 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fluent-plugin-azure-queue
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1.pre
5
+ platform: ruby
6
+ authors:
7
+ - Scott Bonebrake
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-08-22 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.12.2
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '0.14'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: 0.12.2
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '0.14'
33
+ - !ruby/object:Gem::Dependency
34
+ name: azure-storage
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: 0.12.3.preview
40
+ - - "<"
41
+ - !ruby/object:Gem::Version
42
+ version: '0.13'
43
+ type: :runtime
44
+ prerelease: false
45
+ version_requirements: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: 0.12.3.preview
50
+ - - "<"
51
+ - !ruby/object:Gem::Version
52
+ version: '0.13'
53
+ - !ruby/object:Gem::Dependency
54
+ name: nokogiri
55
+ requirement: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: '0'
60
+ type: :runtime
61
+ prerelease: false
62
+ version_requirements: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ - !ruby/object:Gem::Dependency
68
+ name: rake
69
+ requirement: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: 0.9.2
74
+ type: :development
75
+ prerelease: false
76
+ version_requirements: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ version: 0.9.2
81
+ - !ruby/object:Gem::Dependency
82
+ name: test-unit
83
+ requirement: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: 3.0.8
88
+ type: :development
89
+ prerelease: false
90
+ version_requirements: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ version: 3.0.8
95
+ - !ruby/object:Gem::Dependency
96
+ name: flexmock
97
+ requirement: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - ">="
100
+ - !ruby/object:Gem::Version
101
+ version: 1.3.3
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - ">="
107
+ - !ruby/object:Gem::Version
108
+ version: 1.3.3
109
+ description: Fluent input plugin for azure queue input
110
+ email: N/A
111
+ executables: []
112
+ extensions: []
113
+ extra_rdoc_files: []
114
+ files:
115
+ - ".gitignore"
116
+ - ".travis.yml"
117
+ - Gemfile
118
+ - Gemfile.lock
119
+ - LICENSE
120
+ - README.md
121
+ - Rakefile
122
+ - VERSION
123
+ - fluent-plugin-azure-queue.gemspec
124
+ - lib/fluent/plugin/in_azure_queue.rb
125
+ - test/test_in_azure_queue.rb
126
+ homepage: https://github.com/sbonebrake/fluent-plugin-azure-queue
127
+ licenses:
128
+ - MIT
129
+ metadata: {}
130
+ post_install_message:
131
+ rdoc_options: []
132
+ require_paths:
133
+ - lib
134
+ required_ruby_version: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ required_rubygems_version: !ruby/object:Gem::Requirement
140
+ requirements:
141
+ - - ">"
142
+ - !ruby/object:Gem::Version
143
+ version: 1.3.1
144
+ requirements: []
145
+ rubyforge_project:
146
+ rubygems_version: 2.6.12
147
+ signing_key:
148
+ specification_version: 4
149
+ summary: Fluent input plugin for azure queue input
150
+ test_files:
151
+ - test/test_in_azure_queue.rb