fluent-plugin-cloud-pubsub 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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f2e73ecd93f477db47b6b65460ae859d9866d488
4
+ data.tar.gz: 153f860d1f0f481a3b140042c831ad8a8976ecf8
5
+ SHA512:
6
+ metadata.gz: bb3779c706f2cbaebb60eca80c9ed251aafe2bd3da4322a84f8148731351023ed963fd9420813976586b542666e73f1343ed8ccb9e75fcad194a293fe9633223
7
+ data.tar.gz: 615977a94d7de3a796ecf8697f09d3bfd4b5f6c6d9a87ef37e2a94ebcccbfa5598bdb5b323205c9eb76297a7cecb20cc627ce4d324e98032a15c96442742da18
data/.gitignore ADDED
@@ -0,0 +1,35 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /test/tmp/
9
+ /test/version_tmp/
10
+ /tmp/
11
+
12
+ ## Specific to RubyMotion:
13
+ .dat*
14
+ .repl_history
15
+ build/
16
+
17
+ ## Documentation cache and generated files:
18
+ /.yardoc/
19
+ /_yardoc/
20
+ /doc/
21
+ /rdoc/
22
+
23
+ ## Environment normalisation:
24
+ /.bundle/
25
+ /vendor/bundle
26
+ /lib/bundler/man/
27
+
28
+ # for a library or gem, you might want to ignore these files since the code is
29
+ # intended to run in multiple environments; otherwise, check them in:
30
+ Gemfile.lock
31
+ # .ruby-version
32
+ # .ruby-gemset
33
+
34
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
35
+ .rvmrc
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Keiji Yoshida
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.
22
+
data/README.md ADDED
@@ -0,0 +1,2 @@
1
+ # fluent-plugin-cloud-pubsub
2
+ fluent-plugin-cloud-pubsub
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rake/testtask'
3
+
4
+ Rake::TestTask.new(:test) do |test|
5
+ test.libs << 'lib' << 'test'
6
+ test.pattern = 'test/**/test_*.rb'
7
+ test.verbose = true
8
+ end
9
+
10
+ task :default => :test
@@ -0,0 +1,26 @@
1
+ # encoding: utf-8
2
+ $:.push File.expand_path('../lib', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.name = "fluent-plugin-cloud-pubsub"
6
+ gem.description = "Fluentd plugin for sending data to Cloud Pub/Sub"
7
+ gem.license = "MIT"
8
+ gem.homepage = "https://github.com/yosssi/fluent-plugin-cloud-pubsub"
9
+ gem.summary = gem.description
10
+ gem.version = "0.0.1"
11
+ gem.authors = ["Keiji Yoshida"]
12
+ gem.email = "yoshida.keiji.84@gmail.com"
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.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
17
+ gem.require_paths = ['lib']
18
+
19
+ gem.add_runtime_dependency "fluentd", "~> 0.12.0"
20
+ gem.add_runtime_dependency "gcloud", "~> 0.3.0"
21
+ gem.add_runtime_dependency "yajl-ruby", "~> 1.0"
22
+
23
+ gem.add_development_dependency "bundler"
24
+ gem.add_development_dependency "rake"
25
+ gem.add_development_dependency "test-unit"
26
+ end
@@ -0,0 +1,74 @@
1
+ require 'gcloud'
2
+
3
+ module Fluent
4
+ class CloudPubSubOutput < BufferedOutput
5
+ MAX_REQ_SIZE = 10 * 1024 * 1024 # 10 MB
6
+ MAX_MSGS_PER_REQ = 1000
7
+
8
+ Plugin.register_output('cloud_pubsub', self)
9
+
10
+ config_param :project, :string, :default => nil
11
+ config_param :topic, :string, :default => nil
12
+ config_param :key, :string, :default => nil
13
+ config_param :max_req_size, :integer, :default => MAX_REQ_SIZE
14
+ config_param :max_msgs_per_req, :integer, :default => MAX_MSGS_PER_REQ
15
+
16
+ unless method_defined?(:log)
17
+ define_method("log") { $log }
18
+ end
19
+
20
+ unless method_defined?(:router)
21
+ define_method("router") { Fluent::Engine }
22
+ end
23
+
24
+ def configure(conf)
25
+ super
26
+
27
+ raise Fluent::ConfigError, "'project' must be specified." unless @project
28
+ raise Fluent::ConfigError, "'topic' must be specified." unless @topic
29
+ raise Fluent::ConfigError, "'key' must be specified." unless @key
30
+ end
31
+
32
+ def start
33
+ super
34
+
35
+ pubsub = (Gcloud.new @project, @key).pubsub
36
+ @client = pubsub.topic @topic
37
+ end
38
+
39
+ def format(tag, time, record)
40
+ [tag, time, record].to_msgpack
41
+ end
42
+
43
+ def write(chunk)
44
+ msgs = []
45
+ msgs_size = 0
46
+
47
+ chunk.msgpack_each do |tag, time, record|
48
+ size = Yajl.dump(record).bytesize
49
+ if msgs.length > 0 && (msgs_size + size > max_req_size || msgs.length + 1 > max_msgs_per_req)
50
+ publish(msgs)
51
+ msgs = []
52
+ msgs_size = 0
53
+ end
54
+ msgs << record.to_json
55
+ msgs_size += size
56
+ end
57
+
58
+ if msgs.length > 0
59
+ publish(msgs)
60
+ end
61
+ rescue
62
+ log.error "unexpected error", :error=>$!.to_s
63
+ log.error_backtrace
64
+ end
65
+ end
66
+
67
+ def publish(msgs)
68
+ @client.publish do |batch|
69
+ msgs.each do |m|
70
+ batch.publish m
71
+ end
72
+ end
73
+ end
74
+ end
metadata ADDED
@@ -0,0 +1,134 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fluent-plugin-cloud-pubsub
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Keiji Yoshida
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-10-09 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.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.12.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: gcloud
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: 0.3.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.3.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: yajl-ruby
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '1.0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '1.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: '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
+ - !ruby/object:Gem::Dependency
70
+ name: rake
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'
83
+ - !ruby/object:Gem::Dependency
84
+ name: test-unit
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: Fluentd plugin for sending data to Cloud Pub/Sub
98
+ email: yoshida.keiji.84@gmail.com
99
+ executables: []
100
+ extensions: []
101
+ extra_rdoc_files: []
102
+ files:
103
+ - .gitignore
104
+ - Gemfile
105
+ - LICENSE
106
+ - README.md
107
+ - Rakefile
108
+ - fluent-plugin-gcloud-pubsub.gemspec
109
+ - lib/fluent/plugin/out_cloud_pubsub.rb
110
+ homepage: https://github.com/yosssi/fluent-plugin-cloud-pubsub
111
+ licenses:
112
+ - MIT
113
+ metadata: {}
114
+ post_install_message:
115
+ rdoc_options: []
116
+ require_paths:
117
+ - lib
118
+ required_ruby_version: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - '>='
121
+ - !ruby/object:Gem::Version
122
+ version: '0'
123
+ required_rubygems_version: !ruby/object:Gem::Requirement
124
+ requirements:
125
+ - - '>='
126
+ - !ruby/object:Gem::Version
127
+ version: '0'
128
+ requirements: []
129
+ rubyforge_project:
130
+ rubygems_version: 2.0.14
131
+ signing_key:
132
+ specification_version: 4
133
+ summary: Fluentd plugin for sending data to Cloud Pub/Sub
134
+ test_files: []