fluent-plugin-gcloud-pubsub-custom 0.1.0
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 +11 -0
- data/.travis.yml +30 -0
- data/Gemfile +3 -0
- data/Gemfile.v0.12 +5 -0
- data/LICENSE +22 -0
- data/README.md +143 -0
- data/Rakefile +12 -0
- data/fluent-plugin-gcloud-pubsub-custom.gemspec +26 -0
- data/lib/fluent/plugin/gcloud_pubsub/client.rb +40 -0
- data/lib/fluent/plugin/in_gcloud_pubsub.rb +98 -0
- data/lib/fluent/plugin/out_gcloud_pubsub.rb +72 -0
- data/test/plugin/test_in_gcloud_pubsub.rb +54 -0
- data/test/plugin/test_out_gcloud_pubsub.rb +134 -0
- data/test/test_helper.rb +31 -0
- metadata +150 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: d0d5b921e5457be93cc2d3c8876bd11aae90e41b
|
4
|
+
data.tar.gz: f74e1e5ab85e31ee5090cc84ac6926136ad8eb8f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 553e885ee97a831dffa3441e999865ff039e41e30803e2e0ec29ed7db71ffc178481a38c2dceaa86f965a2f1a484f539c2b671e8c74f842ec27cc7ef2c628bc1
|
7
|
+
data.tar.gz: 39066e1bbca376d1c128dc2f6fa30de54d20fa7ee3b7b1eb795df6054d7f4f041877cd26e47a3043a03df411aecbdd90eee028e24a73491150f79d514675c497
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
language: ruby
|
2
|
+
|
3
|
+
rvm:
|
4
|
+
- 2.0
|
5
|
+
- 2.1
|
6
|
+
- 2.2.5
|
7
|
+
- 2.3.1
|
8
|
+
- ruby-head
|
9
|
+
- rbx
|
10
|
+
|
11
|
+
gemfile:
|
12
|
+
- Gemfile
|
13
|
+
- Gemfile.v0.12
|
14
|
+
|
15
|
+
branches:
|
16
|
+
only:
|
17
|
+
- master
|
18
|
+
|
19
|
+
before_install: gem update bundler
|
20
|
+
script: bundle exec rake test
|
21
|
+
|
22
|
+
sudo: false
|
23
|
+
|
24
|
+
matrix:
|
25
|
+
allow_failures:
|
26
|
+
- rvm: ruby-head
|
27
|
+
- rvm: rbx
|
28
|
+
exclude:
|
29
|
+
- rvm: 2.0
|
30
|
+
gemfile: Gemfile
|
data/Gemfile
ADDED
data/Gemfile.v0.12
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 mdoi
|
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,143 @@
|
|
1
|
+
# fluent-plugin-gcloud-pubsub-custom
|
2
|
+
|
3
|
+
[](https://travis-ci.org/mia-0032/fluent-plugin-gcloud-pubsub-custom)
|
4
|
+
[](http://badge.fury.io/rb/fluent-plugin-gcloud-pubsub-custom)
|
5
|
+
|
6
|
+
This plugin is forked from https://github.com/mdoi/fluent-plugin-gcloud-pubsub
|
7
|
+
|
8
|
+
## Overview
|
9
|
+
|
10
|
+
[Cloud Pub/Sub](https://cloud.google.com/pubsub/) Input/Output(BufferedOutput) plugin for [Fluentd](http://www.fluentd.org/) with [gcloud](https://googlecloudplatform.github.io/gcloud-ruby/) gem
|
11
|
+
|
12
|
+
- [Publish](https://googlecloudplatform.github.io/gcloud-ruby/docs/v0.12.2/Gcloud/Pubsub/Topic.html#publish-instance_method) messages to Cloud Pub/Sub
|
13
|
+
- [Pull](https://googlecloudplatform.github.io/gcloud-ruby/docs/v0.12.2/Gcloud/Pubsub/Subscription.html#pull-instance_method) messages from Cloud Pub/Sub
|
14
|
+
|
15
|
+
## Preparation
|
16
|
+
|
17
|
+
- Create a project on Google Developer Console
|
18
|
+
- Add a topic of Cloud Pub/Sub to the project
|
19
|
+
- Add a pull style subscription to the topic
|
20
|
+
- Download your credential (json) or [set scope on GCE instance](https://cloud.google.com/compute/docs/api/how-tos/authorization)
|
21
|
+
|
22
|
+
## Installation
|
23
|
+
|
24
|
+
Install by gem:
|
25
|
+
|
26
|
+
```shell
|
27
|
+
$ gem install fluent-plugin-gcloud-pubsub-custom
|
28
|
+
```
|
29
|
+
|
30
|
+
## Configuration
|
31
|
+
|
32
|
+
### Publish messages
|
33
|
+
|
34
|
+
Use `gcloud_pubsub` output plugin.
|
35
|
+
|
36
|
+
```
|
37
|
+
<match example.publish>
|
38
|
+
@type gcloud_pubsub
|
39
|
+
project <YOUR PROJECT>
|
40
|
+
key <YOUR KEY>
|
41
|
+
topic <YOUR TOPIC>
|
42
|
+
autocreate_topic false
|
43
|
+
max_messages 1000
|
44
|
+
max_total_size 10000000
|
45
|
+
buffer_type file
|
46
|
+
buffer_path /path/to/your/buffer
|
47
|
+
flush_interval 1s
|
48
|
+
try_flush_interval 0.1
|
49
|
+
format json
|
50
|
+
</match>
|
51
|
+
```
|
52
|
+
|
53
|
+
- `project` (optional)
|
54
|
+
- Set your GCP project
|
55
|
+
- Running fluentd on GCP, you don't have to specify.
|
56
|
+
- You can also use environment variable such as `GCLOUD_PROJECT`.
|
57
|
+
- `key` (optional)
|
58
|
+
- Set your credential file path.
|
59
|
+
- Running fluentd on GCP, you can use scope instead of specifying this.
|
60
|
+
- You can also use environment variable such as `GCLOUD_KEYFILE`.
|
61
|
+
- `topic` (required)
|
62
|
+
- Set topic name to publish.
|
63
|
+
- `autocreate_topic` (optional, default: `false`)
|
64
|
+
- If set to `true`, specified topic will be created when it doesn't exist.
|
65
|
+
- `max_messages` (optional, default: `1000`)
|
66
|
+
- Publishing messages count per request to Cloud Pub/Sub.
|
67
|
+
- See https://cloud.google.com/pubsub/quotas#other_limits
|
68
|
+
- `max_total_size` (optional, default: `10000000` = `10MB`)
|
69
|
+
- Publishing messages bytesize per request to Cloud Pub/Sub.
|
70
|
+
- See https://cloud.google.com/pubsub/quotas#other_limits
|
71
|
+
- `buffer_type`, `buffer_path`, `flush_interval`, `try_flush_interval`
|
72
|
+
- These are fluentd buffer configuration. See http://docs.fluentd.org/articles/buffer-plugin-overview
|
73
|
+
- `format` (optional, default: `json`)
|
74
|
+
- Set output format. See http://docs.fluentd.org/articles/out_file#format
|
75
|
+
|
76
|
+
### Pull messages
|
77
|
+
|
78
|
+
Use `gcloud_pubsub` input plugin.
|
79
|
+
|
80
|
+
```
|
81
|
+
<source>
|
82
|
+
@type gcloud_pubsub
|
83
|
+
tag example.pull
|
84
|
+
project <YOUR PROJECT>
|
85
|
+
key <YOUR KEY>
|
86
|
+
topic <YOUR TOPIC>
|
87
|
+
subscription <YOUR SUBSCRIPTION>
|
88
|
+
max_messages 1000
|
89
|
+
return_immediately true
|
90
|
+
pull_interval 2
|
91
|
+
format json
|
92
|
+
</source>
|
93
|
+
```
|
94
|
+
|
95
|
+
- `tag` (required)
|
96
|
+
- Set tag of messages.
|
97
|
+
- `project` (optional)
|
98
|
+
- Set your GCP project
|
99
|
+
- Running fluentd on GCP, you don't have to specify.
|
100
|
+
- You can also use environment variable such as `GCLOUD_PROJECT`.
|
101
|
+
- `key` (optional)
|
102
|
+
- Set your credential file path.
|
103
|
+
- Running fluentd on GCP, you can use scope instead of specifying this.
|
104
|
+
- You can also use environment variable such as `GCLOUD_KEYFILE`.
|
105
|
+
- `topic` (optional)
|
106
|
+
- Set topic name to pull.
|
107
|
+
- `subscription` (required)
|
108
|
+
- Set subscription name to pull.
|
109
|
+
- `max_messages` (optional, default: `100`)
|
110
|
+
- See maxMessages on https://cloud.google.com/pubsub/subscriber#receiving-pull-messages
|
111
|
+
- `return_immediately` (optional, default: `true`)
|
112
|
+
- See returnImmediately on https://cloud.google.com/pubsub/subscriber#receiving-pull-messages
|
113
|
+
- If `return_immediately` is `true`, this plugin ignore `pull_interval`.
|
114
|
+
- `pull_interval` (optional, default: `5`)
|
115
|
+
- Pulling messages by intervals of specified seconds.
|
116
|
+
- `format` (optional, default: `json`)
|
117
|
+
- Set input format. See format section in http://docs.fluentd.org/articles/in_tail
|
118
|
+
|
119
|
+
## ChangeLog
|
120
|
+
|
121
|
+
- Release 0.1.0 - 2016/08/22
|
122
|
+
- Use formatter / parser plugin and add format configuration
|
123
|
+
- Bump up gcloud-ruby to 0.12
|
124
|
+
- Remove dependency on lightening buffer
|
125
|
+
- Fix error caused by Pub/Sub quotas
|
126
|
+
|
127
|
+
## Contributing
|
128
|
+
|
129
|
+
1. Fork it
|
130
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
131
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
132
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
133
|
+
5. Create a new Pull Request
|
134
|
+
|
135
|
+
## TODO
|
136
|
+
|
137
|
+
- Add `tag` attribute in output plugin and use `tag` attribute as tag in input plugin.
|
138
|
+
- Send ack after other output plugin committed (if possible).
|
139
|
+
|
140
|
+
## Authors
|
141
|
+
|
142
|
+
- [@mdoi](https://github.com/mdoi) : First author
|
143
|
+
- [@mia-0032](https://github.com/mia-0032) : This version author
|
data/Rakefile
ADDED
@@ -0,0 +1,12 @@
|
|
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' << 'test'
|
8
|
+
test.test_files = FileList['test/plugin/test_*.rb']
|
9
|
+
test.verbose = true
|
10
|
+
end
|
11
|
+
|
12
|
+
task :default => [:build]
|
@@ -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-gcloud-pubsub-custom"
|
6
|
+
gem.description = "Google Cloud Pub/Sub input/output plugin for Fluentd event collector"
|
7
|
+
gem.license = "MIT"
|
8
|
+
gem.homepage = "https://github.com/mia-0032/fluent-plugin-gcloud-pubsub-custom"
|
9
|
+
gem.summary = gem.description
|
10
|
+
gem.version = "0.1.0"
|
11
|
+
gem.authors = ["Yoshihiro MIYAI"]
|
12
|
+
gem.email = "msparrow17@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.10.58", "< 2"]
|
20
|
+
gem.add_runtime_dependency "gcloud", "~> 0.12"
|
21
|
+
|
22
|
+
gem.add_development_dependency "bundler"
|
23
|
+
gem.add_development_dependency "rake"
|
24
|
+
gem.add_development_dependency "test-unit"
|
25
|
+
gem.add_development_dependency "test-unit-rr"
|
26
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'gcloud'
|
2
|
+
|
3
|
+
module Fluent
|
4
|
+
module GcloudPubSub
|
5
|
+
class Error < StandardError; end
|
6
|
+
|
7
|
+
class Publisher
|
8
|
+
def initialize(project, key, topic, autocreate_topic)
|
9
|
+
pubsub = (Gcloud.new project, key).pubsub
|
10
|
+
|
11
|
+
@client = pubsub.topic topic, autocreate: autocreate_topic
|
12
|
+
raise Fluent::GcloudPubSub::Error.new "topic:#{topic} does not exist." if @client.nil?
|
13
|
+
end
|
14
|
+
|
15
|
+
def publish(messages)
|
16
|
+
@client.publish do |batch|
|
17
|
+
messages.each do |m|
|
18
|
+
batch.publish m
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
class Subscriber
|
25
|
+
def initialize(project, key, topic, subscription)
|
26
|
+
pubsub = (Gcloud.new project, key).pubsub
|
27
|
+
@client = pubsub.subscription subscription
|
28
|
+
raise Fluent::GcloudPubSub::Error.new "subscription:#{subscription} does not exist." if @client.nil?
|
29
|
+
end
|
30
|
+
|
31
|
+
def pull(immediate, max)
|
32
|
+
@client.pull immediate: immediate, max: max
|
33
|
+
end
|
34
|
+
|
35
|
+
def acknowledge(messages)
|
36
|
+
@client.acknowledge messages
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,98 @@
|
|
1
|
+
require 'fluent/input'
|
2
|
+
require 'fluent/parser'
|
3
|
+
|
4
|
+
require 'fluent/plugin/gcloud_pubsub/client'
|
5
|
+
|
6
|
+
module Fluent
|
7
|
+
class GcloudPubSubInput < Input
|
8
|
+
Fluent::Plugin.register_input('gcloud_pubsub', self)
|
9
|
+
|
10
|
+
config_param :tag, :string
|
11
|
+
config_param :project, :string, :default => nil
|
12
|
+
config_param :key, :string, :default => nil
|
13
|
+
config_param :topic, :string, :default => nil
|
14
|
+
config_param :subscription, :string
|
15
|
+
config_param :pull_interval, :integer, :default => 5
|
16
|
+
config_param :max_messages, :integer, :default => 100
|
17
|
+
config_param :return_immediately, :bool, :default => true
|
18
|
+
config_param :format, :string, :default => 'json'
|
19
|
+
|
20
|
+
unless method_defined?(:log)
|
21
|
+
define_method("log") { $log }
|
22
|
+
end
|
23
|
+
|
24
|
+
unless method_defined?(:router)
|
25
|
+
define_method("router") { Fluent::Engine }
|
26
|
+
end
|
27
|
+
|
28
|
+
def configure(conf)
|
29
|
+
super
|
30
|
+
@parser = Plugin.new_parser(@format)
|
31
|
+
@parser.configure(conf)
|
32
|
+
end
|
33
|
+
|
34
|
+
def start
|
35
|
+
super
|
36
|
+
@subscriber = Fluent::GcloudPubSub::Subscriber.new @project, @key, @topic, @subscription
|
37
|
+
log.debug "connected subscription:#{@subscription} in project #{@project}"
|
38
|
+
@stop_subscribing = false
|
39
|
+
@subscribe_thread = Thread.new(&method(:subscribe))
|
40
|
+
end
|
41
|
+
|
42
|
+
def shutdown
|
43
|
+
super
|
44
|
+
@stop_subscribing = true
|
45
|
+
@subscribe_thread.join
|
46
|
+
end
|
47
|
+
|
48
|
+
private
|
49
|
+
|
50
|
+
def subscribe
|
51
|
+
until @stop_subscribing
|
52
|
+
messages = @subscriber.pull @return_immediately, @max_messages
|
53
|
+
|
54
|
+
if messages.length > 0
|
55
|
+
es = parse_messages(messages)
|
56
|
+
unless es.empty?
|
57
|
+
begin
|
58
|
+
router.emit_stream(@tag, es)
|
59
|
+
rescue
|
60
|
+
# ignore errors. Engine shows logs and backtraces.
|
61
|
+
end
|
62
|
+
@subscriber.acknowledge messages
|
63
|
+
log.debug "#{messages.length} message(s) processed"
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
if @return_immediately
|
68
|
+
sleep @pull_interval
|
69
|
+
end
|
70
|
+
end
|
71
|
+
rescue
|
72
|
+
log.error "unexpected error", :error=>$!.to_s
|
73
|
+
log.error_backtrace
|
74
|
+
end
|
75
|
+
|
76
|
+
def parse_messages(messages)
|
77
|
+
es = MultiEventStream.new
|
78
|
+
messages.each do |m|
|
79
|
+
convert_line_to_event(m.message.data, es)
|
80
|
+
end
|
81
|
+
es
|
82
|
+
end
|
83
|
+
|
84
|
+
def convert_line_to_event(line, es)
|
85
|
+
line.chomp! # remove \n
|
86
|
+
@parser.parse(line) { |time, record|
|
87
|
+
if time && record
|
88
|
+
es.add(time, record)
|
89
|
+
else
|
90
|
+
log.warn "pattern not match: #{line.inspect}"
|
91
|
+
end
|
92
|
+
}
|
93
|
+
rescue => e
|
94
|
+
log.warn line.dump, :error => e.to_s
|
95
|
+
log.debug_backtrace(e.backtrace)
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
require 'fluent/output'
|
2
|
+
|
3
|
+
require 'fluent/plugin/gcloud_pubsub/client'
|
4
|
+
|
5
|
+
module Fluent
|
6
|
+
class GcloudPubSubOutput < BufferedOutput
|
7
|
+
Fluent::Plugin.register_output('gcloud_pubsub', self)
|
8
|
+
|
9
|
+
config_param :project, :string, :default => nil
|
10
|
+
config_param :key, :string, :default => nil
|
11
|
+
config_param :topic, :string
|
12
|
+
config_param :autocreate_topic, :bool, :default => false
|
13
|
+
config_param :max_messages, :integer, :default => 1000
|
14
|
+
config_param :max_total_size, :integer, :default => 10000000 # 10MB
|
15
|
+
config_param :format, :string, :default => 'json'
|
16
|
+
|
17
|
+
unless method_defined?(:log)
|
18
|
+
define_method("log") { $log }
|
19
|
+
end
|
20
|
+
|
21
|
+
unless method_defined?(:router)
|
22
|
+
define_method("router") { Fluent::Engine }
|
23
|
+
end
|
24
|
+
|
25
|
+
def configure(conf)
|
26
|
+
super
|
27
|
+
@formatter = Plugin.new_formatter(@format)
|
28
|
+
@formatter.configure(conf)
|
29
|
+
end
|
30
|
+
|
31
|
+
def start
|
32
|
+
super
|
33
|
+
@publisher = Fluent::GcloudPubSub::Publisher.new @project, @key, @topic, @autocreate_topic
|
34
|
+
log.debug "connected topic:#{@topic} in project #{@project}"
|
35
|
+
end
|
36
|
+
|
37
|
+
def format(tag, time, record)
|
38
|
+
[tag, time, record].to_msgpack
|
39
|
+
end
|
40
|
+
|
41
|
+
def write(chunk)
|
42
|
+
messages = []
|
43
|
+
size = 0
|
44
|
+
|
45
|
+
chunk.msgpack_each do |tag, time, record|
|
46
|
+
msg = @formatter.format(tag, time, record)
|
47
|
+
if messages.length + 1 > @max_messages || size + msg.bytesize > @max_total_size
|
48
|
+
publish messages
|
49
|
+
messages = []
|
50
|
+
size = 0
|
51
|
+
end
|
52
|
+
messages << msg
|
53
|
+
size += msg.bytesize
|
54
|
+
end
|
55
|
+
|
56
|
+
if messages.length > 0
|
57
|
+
publish messages
|
58
|
+
end
|
59
|
+
rescue => e
|
60
|
+
log.error "unexpected error", :error=>$!.to_s
|
61
|
+
log.error_backtrace
|
62
|
+
raise e
|
63
|
+
end
|
64
|
+
|
65
|
+
private
|
66
|
+
|
67
|
+
def publish(messages)
|
68
|
+
log.debug "send message topic:#{@topic} length:#{messages.length.to_s}"
|
69
|
+
@publisher.publish messages
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require_relative "../test_helper"
|
2
|
+
|
3
|
+
class GcloudPubSubInputTest < Test::Unit::TestCase
|
4
|
+
CONFIG = %[
|
5
|
+
tag test
|
6
|
+
project project-test
|
7
|
+
subscription subscription-test
|
8
|
+
key key-test
|
9
|
+
format json
|
10
|
+
]
|
11
|
+
|
12
|
+
def create_driver(conf=CONFIG)
|
13
|
+
Fluent::Test::InputTestDriver.new(Fluent::GcloudPubSubInput).configure(conf)
|
14
|
+
end
|
15
|
+
|
16
|
+
setup do
|
17
|
+
Fluent::Test.setup
|
18
|
+
end
|
19
|
+
|
20
|
+
sub_test_case 'configure' do
|
21
|
+
test 'all params are configured' do
|
22
|
+
d = create_driver(%[
|
23
|
+
tag test
|
24
|
+
project project-test
|
25
|
+
topic topic-test
|
26
|
+
subscription subscription-test
|
27
|
+
key key-test
|
28
|
+
max_messages 1000
|
29
|
+
return_immediately true
|
30
|
+
pull_interval 2
|
31
|
+
format ltsv
|
32
|
+
])
|
33
|
+
|
34
|
+
assert_equal('test', d.instance.tag)
|
35
|
+
assert_equal('project-test', d.instance.project)
|
36
|
+
assert_equal('topic-test', d.instance.topic)
|
37
|
+
assert_equal('subscription-test', d.instance.subscription)
|
38
|
+
assert_equal('key-test', d.instance.key)
|
39
|
+
assert_equal(2, d.instance.pull_interval)
|
40
|
+
assert_equal(1000, d.instance.max_messages)
|
41
|
+
assert_equal(true, d.instance.return_immediately)
|
42
|
+
assert_equal('ltsv', d.instance.format)
|
43
|
+
end
|
44
|
+
|
45
|
+
test 'default values are configured' do
|
46
|
+
d = create_driver
|
47
|
+
assert_equal(nil, d.instance.topic)
|
48
|
+
assert_equal(5, d.instance.pull_interval)
|
49
|
+
assert_equal(100, d.instance.max_messages)
|
50
|
+
assert_equal(true, d.instance.return_immediately)
|
51
|
+
assert_equal('json', d.instance.format)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,134 @@
|
|
1
|
+
require_relative "../test_helper"
|
2
|
+
|
3
|
+
class GcloudPubSubOutputTest < Test::Unit::TestCase
|
4
|
+
CONFIG = %[
|
5
|
+
project project-test
|
6
|
+
topic topic-test
|
7
|
+
key key-test
|
8
|
+
]
|
9
|
+
|
10
|
+
ReRaisedError = Class.new(RuntimeError)
|
11
|
+
|
12
|
+
def create_driver(conf = CONFIG)
|
13
|
+
Fluent::Test::BufferedOutputTestDriver.new(Fluent::GcloudPubSubOutput).configure(conf)
|
14
|
+
end
|
15
|
+
|
16
|
+
setup do
|
17
|
+
Fluent::Test.setup
|
18
|
+
end
|
19
|
+
|
20
|
+
sub_test_case 'configure' do
|
21
|
+
test 'default values are configured' do
|
22
|
+
d = create_driver(%[
|
23
|
+
project project-test
|
24
|
+
topic topic-test
|
25
|
+
key key-test
|
26
|
+
])
|
27
|
+
|
28
|
+
assert_equal('project-test', d.instance.project)
|
29
|
+
assert_equal('topic-test', d.instance.topic)
|
30
|
+
assert_equal('key-test', d.instance.key)
|
31
|
+
assert_equal(false, d.instance.autocreate_topic)
|
32
|
+
assert_equal(1000, d.instance.max_messages)
|
33
|
+
assert_equal(10000000, d.instance.max_total_size)
|
34
|
+
end
|
35
|
+
|
36
|
+
test '"topic" must be specified' do
|
37
|
+
assert_raises Fluent::ConfigError do
|
38
|
+
create_driver(%[
|
39
|
+
project project-test
|
40
|
+
key key-test
|
41
|
+
])
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
test '"autocreate_topic" can be specified' do
|
46
|
+
d = create_driver(%[
|
47
|
+
project project-test
|
48
|
+
topic topic-test
|
49
|
+
key key-test
|
50
|
+
autocreate_topic true
|
51
|
+
])
|
52
|
+
|
53
|
+
assert_equal(true, d.instance.autocreate_topic)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
sub_test_case 'topic' do
|
58
|
+
setup do
|
59
|
+
@publisher = mock!
|
60
|
+
@pubsub_mock = mock!
|
61
|
+
@gcloud_mock = mock!.pubsub { @pubsub_mock }
|
62
|
+
stub(Gcloud).new { @gcloud_mock }
|
63
|
+
end
|
64
|
+
|
65
|
+
test '"autocreate_topic" is enabled' do
|
66
|
+
d = create_driver(%[
|
67
|
+
project project-test
|
68
|
+
topic topic-test
|
69
|
+
key key-test
|
70
|
+
autocreate_topic true
|
71
|
+
])
|
72
|
+
|
73
|
+
@pubsub_mock.topic("topic-test", autocreate: true).once { @publisher }
|
74
|
+
d.run
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
sub_test_case 'publish' do
|
79
|
+
setup do
|
80
|
+
@publisher = mock!
|
81
|
+
@pubsub_mock = mock!.topic(anything, anything) { @publisher }
|
82
|
+
@gcloud_mock = mock!.pubsub { @pubsub_mock }
|
83
|
+
stub(Gcloud).new { @gcloud_mock }
|
84
|
+
end
|
85
|
+
|
86
|
+
setup do
|
87
|
+
@time = Time.parse('2016-07-09 11:12:13 UTC').to_i
|
88
|
+
end
|
89
|
+
|
90
|
+
test 'messages are divided into "max_messages"' do
|
91
|
+
d = create_driver
|
92
|
+
@publisher.publish.times(2)
|
93
|
+
# max_messages is default 1000
|
94
|
+
1001.times do |i|
|
95
|
+
d.emit({"a" => i}, @time)
|
96
|
+
end
|
97
|
+
d.run
|
98
|
+
end
|
99
|
+
|
100
|
+
test 'messages are divided into "max_total_size"' do
|
101
|
+
d = create_driver(%[
|
102
|
+
project project-test
|
103
|
+
topic topic-test
|
104
|
+
key key-test
|
105
|
+
max_messages 100000
|
106
|
+
max_total_size 1000
|
107
|
+
])
|
108
|
+
|
109
|
+
@publisher.publish.times(2)
|
110
|
+
# 400 * 4 / max_total_size = twice
|
111
|
+
4.times do
|
112
|
+
d.emit({"a" => "a" * 400}, @time)
|
113
|
+
end
|
114
|
+
d.run
|
115
|
+
end
|
116
|
+
|
117
|
+
test 'accept "ASCII-8BIT" encoded multibyte strings' do
|
118
|
+
# on fluentd v0.14, all strings treated as "ASCII-8BIT" except specified encoding.
|
119
|
+
d = create_driver
|
120
|
+
@publisher.publish.once
|
121
|
+
d.emit({"a" => "あああ".force_encoding("ASCII-8BIT")}, @time)
|
122
|
+
d.run
|
123
|
+
end
|
124
|
+
|
125
|
+
test 'reraise errors' do
|
126
|
+
d = create_driver
|
127
|
+
@publisher.publish.once { raise ReRaisedError }
|
128
|
+
assert_raises ReRaisedError do
|
129
|
+
d.emit([{'a' => 1, 'b' => 2}])
|
130
|
+
d.run
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
begin
|
4
|
+
Bundler.setup(:default, :development)
|
5
|
+
rescue Bundler::BundlerError => e
|
6
|
+
$stderr.puts e.message
|
7
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
+
exit e.status_code
|
9
|
+
end
|
10
|
+
require 'test/unit'
|
11
|
+
require "test/unit/rr"
|
12
|
+
|
13
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
14
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
15
|
+
|
16
|
+
require 'fluent/test'
|
17
|
+
unless ENV.has_key?('VERBOSE')
|
18
|
+
nulllogger = Object.new
|
19
|
+
nulllogger.instance_eval {|obj|
|
20
|
+
def method_missing(method, *args)
|
21
|
+
# pass
|
22
|
+
end
|
23
|
+
}
|
24
|
+
$log = nulllogger
|
25
|
+
end
|
26
|
+
|
27
|
+
require 'fluent/plugin/in_gcloud_pubsub'
|
28
|
+
require 'fluent/plugin/out_gcloud_pubsub'
|
29
|
+
|
30
|
+
class Test::Unit::TestCase
|
31
|
+
end
|
metadata
ADDED
@@ -0,0 +1,150 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: fluent-plugin-gcloud-pubsub-custom
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Yoshihiro MIYAI
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-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.10.58
|
20
|
+
- - "<"
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '2'
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 0.10.58
|
30
|
+
- - "<"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '2'
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: gcloud
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - "~>"
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0.12'
|
40
|
+
type: :runtime
|
41
|
+
prerelease: false
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - "~>"
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0.12'
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: bundler
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '0'
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: rake
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '0'
|
68
|
+
type: :development
|
69
|
+
prerelease: false
|
70
|
+
version_requirements: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0'
|
75
|
+
- !ruby/object:Gem::Dependency
|
76
|
+
name: test-unit
|
77
|
+
requirement: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - ">="
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '0'
|
82
|
+
type: :development
|
83
|
+
prerelease: false
|
84
|
+
version_requirements: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
89
|
+
- !ruby/object:Gem::Dependency
|
90
|
+
name: test-unit-rr
|
91
|
+
requirement: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - ">="
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '0'
|
96
|
+
type: :development
|
97
|
+
prerelease: false
|
98
|
+
version_requirements: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - ">="
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '0'
|
103
|
+
description: Google Cloud Pub/Sub input/output plugin for Fluentd event collector
|
104
|
+
email: msparrow17@gmail.com
|
105
|
+
executables: []
|
106
|
+
extensions: []
|
107
|
+
extra_rdoc_files: []
|
108
|
+
files:
|
109
|
+
- ".gitignore"
|
110
|
+
- ".travis.yml"
|
111
|
+
- Gemfile
|
112
|
+
- Gemfile.v0.12
|
113
|
+
- LICENSE
|
114
|
+
- README.md
|
115
|
+
- Rakefile
|
116
|
+
- fluent-plugin-gcloud-pubsub-custom.gemspec
|
117
|
+
- lib/fluent/plugin/gcloud_pubsub/client.rb
|
118
|
+
- lib/fluent/plugin/in_gcloud_pubsub.rb
|
119
|
+
- lib/fluent/plugin/out_gcloud_pubsub.rb
|
120
|
+
- test/plugin/test_in_gcloud_pubsub.rb
|
121
|
+
- test/plugin/test_out_gcloud_pubsub.rb
|
122
|
+
- test/test_helper.rb
|
123
|
+
homepage: https://github.com/mia-0032/fluent-plugin-gcloud-pubsub-custom
|
124
|
+
licenses:
|
125
|
+
- MIT
|
126
|
+
metadata: {}
|
127
|
+
post_install_message:
|
128
|
+
rdoc_options: []
|
129
|
+
require_paths:
|
130
|
+
- lib
|
131
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
132
|
+
requirements:
|
133
|
+
- - ">="
|
134
|
+
- !ruby/object:Gem::Version
|
135
|
+
version: '0'
|
136
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
137
|
+
requirements:
|
138
|
+
- - ">="
|
139
|
+
- !ruby/object:Gem::Version
|
140
|
+
version: '0'
|
141
|
+
requirements: []
|
142
|
+
rubyforge_project:
|
143
|
+
rubygems_version: 2.5.1
|
144
|
+
signing_key:
|
145
|
+
specification_version: 4
|
146
|
+
summary: Google Cloud Pub/Sub input/output plugin for Fluentd event collector
|
147
|
+
test_files:
|
148
|
+
- test/plugin/test_in_gcloud_pubsub.rb
|
149
|
+
- test/plugin/test_out_gcloud_pubsub.rb
|
150
|
+
- test/test_helper.rb
|