fluent-plugin-gcloud-pubsub-custom 1.4.0 → 1.5.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 +4 -4
- data/.github/workflows/test.yml +25 -0
- data/CHANGELOG.md +6 -0
- data/README.md +8 -1
- data/Rakefile +1 -0
- data/fluent-plugin-gcloud-pubsub-custom.gemspec +2 -2
- data/lib/fluent/plugin/gcloud_pubsub/client.rb +2 -2
- data/lib/fluent/plugin/in_gcloud_pubsub.rb +19 -1
- data/lib/fluent/plugin/out_gcloud_pubsub.rb +21 -2
- data/test/{test_helper.rb → helper.rb} +6 -14
- data/test/plugin/test_in_gcloud_pubsub.rb +34 -1
- data/test/plugin/test_out_gcloud_pubsub.rb +34 -1
- metadata +7 -7
- data/.travis.yml +0 -24
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 374946914ce3cfc2d8118fc8f0b4f98d9b3b9a588f2a44b05f540cf39f79b416
|
4
|
+
data.tar.gz: b593cb71d7b4305d3bb230829a7a7653038dbd33f180ba0f1d1903429203dddf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a926442360078e78350dae24fef50412bbd9fbca6bbfd5a0ede662c47c9e2b5eef815ad5da6b23e5ffe76014b22138f530768add2dbdb39d0dface069f1315f9
|
7
|
+
data.tar.gz: 7aa23e9902f6720b8e755031bcba63a49c69fb43d1f6600fb69d681197dbe8b25fcdbbaba48bac844ab331254c01307da5ea4c999f7cb13ca49ff65682e53ef7
|
@@ -0,0 +1,25 @@
|
|
1
|
+
name: Test
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
branches: [ master ]
|
6
|
+
pull_request:
|
7
|
+
branches: [ master ]
|
8
|
+
|
9
|
+
jobs:
|
10
|
+
test:
|
11
|
+
runs-on: ubuntu-latest
|
12
|
+
strategy:
|
13
|
+
fail-fast: false
|
14
|
+
matrix:
|
15
|
+
ruby-version: ['2.4', '2.5', '2.6', '2.7']
|
16
|
+
|
17
|
+
steps:
|
18
|
+
- uses: actions/checkout@v2
|
19
|
+
- name: Set up Ruby
|
20
|
+
uses: ruby/setup-ruby@v1
|
21
|
+
with:
|
22
|
+
ruby-version: ${{ matrix.ruby-version }}
|
23
|
+
bundler-cache: true
|
24
|
+
- name: Run tests
|
25
|
+
run: bundle exec rake test
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# fluent-plugin-gcloud-pubsub-custom
|
2
2
|
|
3
|
-
|
3
|
+

|
4
4
|
[](http://badge.fury.io/rb/fluent-plugin-gcloud-pubsub-custom)
|
5
5
|
|
6
6
|
This plugin is forked from https://github.com/mdoi/fluent-plugin-gcloud-pubsub
|
@@ -60,6 +60,7 @@ Use `gcloud_pubsub` output plugin.
|
|
60
60
|
max_messages 1000
|
61
61
|
max_total_size 9800000
|
62
62
|
max_message_size 4000000
|
63
|
+
endpoint <Endpoint URL>
|
63
64
|
<buffer>
|
64
65
|
@type memory
|
65
66
|
flush_interval 1s
|
@@ -95,6 +96,10 @@ Use `gcloud_pubsub` output plugin.
|
|
95
96
|
- Messages exceeding `max_message_size` are not published because Pub/Sub clients cannot receive it.
|
96
97
|
- `attribute_keys` (optional, default: `[]`)
|
97
98
|
- Publishing the set fields as attributes.
|
99
|
+
- `endpoint`(optional)
|
100
|
+
- Set Pub/Sub service endpoint. For more information, see [Service Endpoints](https://cloud.google.com/pubsub/docs/reference/service_apis_overview#service_endpoints)
|
101
|
+
- `compression` (optional, default: `nil`)
|
102
|
+
- If set to `gzip`, messages will be compressed with gzip.
|
98
103
|
|
99
104
|
### Pull messages
|
100
105
|
|
@@ -160,6 +165,8 @@ Use `gcloud_pubsub` input plugin.
|
|
160
165
|
- Bind IP address for HTTP RPC.
|
161
166
|
- `rpc_port` (optional, default: `24680`)
|
162
167
|
- Port for HTTP RPC.
|
168
|
+
- `decompression` (optional, default: `nil`)
|
169
|
+
- If set to `gzip`, messages will be decompressed with gzip.
|
163
170
|
|
164
171
|
## Contributing
|
165
172
|
|
data/Rakefile
CHANGED
@@ -7,7 +7,7 @@ Gem::Specification.new do |gem|
|
|
7
7
|
gem.license = "MIT"
|
8
8
|
gem.homepage = "https://github.com/mia-0032/fluent-plugin-gcloud-pubsub-custom"
|
9
9
|
gem.summary = gem.description
|
10
|
-
gem.version = "1.
|
10
|
+
gem.version = "1.5.0"
|
11
11
|
gem.authors = ["Yoshihiro MIYAI"]
|
12
12
|
gem.email = "msparrow17@gmail.com"
|
13
13
|
gem.files = `git ls-files`.split("\n")
|
@@ -16,7 +16,7 @@ Gem::Specification.new do |gem|
|
|
16
16
|
gem.require_paths = ['lib']
|
17
17
|
|
18
18
|
gem.add_runtime_dependency "fluentd", [">= 0.14.15", "< 2"]
|
19
|
-
gem.add_runtime_dependency "google-cloud-pubsub", "~>
|
19
|
+
gem.add_runtime_dependency "google-cloud-pubsub", "~> 2.3.1"
|
20
20
|
|
21
21
|
gem.add_development_dependency "bundler"
|
22
22
|
gem.add_development_dependency "rake"
|
@@ -24,8 +24,8 @@ module Fluent
|
|
24
24
|
end
|
25
25
|
|
26
26
|
class Publisher
|
27
|
-
def initialize(project, key, autocreate_topic, dest_project)
|
28
|
-
@pubsub = Google::Cloud::Pubsub.new project_id: project, credentials: key
|
27
|
+
def initialize(project, key, autocreate_topic, dest_project, endpoint)
|
28
|
+
@pubsub = Google::Cloud::Pubsub.new project_id: project, credentials: key, endpoint: endpoint
|
29
29
|
@autocreate_topic = autocreate_topic
|
30
30
|
@dest_project = dest_project
|
31
31
|
@topics = {}
|
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'json'
|
2
2
|
require 'webrick'
|
3
3
|
|
4
|
+
require 'fluent/plugin/compressable'
|
4
5
|
require 'fluent/plugin/input'
|
5
6
|
require 'fluent/plugin/parser'
|
6
7
|
|
@@ -8,6 +9,8 @@ require 'fluent/plugin/gcloud_pubsub/client'
|
|
8
9
|
|
9
10
|
module Fluent::Plugin
|
10
11
|
class GcloudPubSubInput < Input
|
12
|
+
include Fluent::Plugin::Compressable
|
13
|
+
|
11
14
|
Fluent::Plugin.register_input('gcloud_pubsub', self)
|
12
15
|
|
13
16
|
helpers :compat_parameters, :parser, :thread
|
@@ -48,6 +51,8 @@ module Fluent::Plugin
|
|
48
51
|
config_param :rpc_bind, :string, default: '0.0.0.0'
|
49
52
|
desc 'Port for HTTP RPC.'
|
50
53
|
config_param :rpc_port, :integer, default: 24680
|
54
|
+
desc 'Decompress messages'
|
55
|
+
config_param :decompression, :string, default: nil
|
51
56
|
|
52
57
|
config_section :parse do
|
53
58
|
config_set_default :@type, DEFAULT_PARSER_TYPE
|
@@ -114,6 +119,11 @@ module Fluent::Plugin
|
|
114
119
|
end
|
115
120
|
|
116
121
|
@parser = parser_create
|
122
|
+
@decompress = if @decompression == 'gzip'
|
123
|
+
method(:gzip_decompress)
|
124
|
+
else
|
125
|
+
method(:no_decompress)
|
126
|
+
end
|
117
127
|
end
|
118
128
|
|
119
129
|
def start
|
@@ -168,6 +178,14 @@ module Fluent::Plugin
|
|
168
178
|
record.delete(@tag_key) || @tag
|
169
179
|
end
|
170
180
|
|
181
|
+
def gzip_decompress(message)
|
182
|
+
decompress message
|
183
|
+
end
|
184
|
+
|
185
|
+
def no_decompress(message)
|
186
|
+
message
|
187
|
+
end
|
188
|
+
|
171
189
|
def start_rpc
|
172
190
|
log.info "listening http rpc server on http://#{@rpc_bind}:#{@rpc_port}/"
|
173
191
|
@rpc_srv = WEBrick::HTTPServer.new(
|
@@ -221,7 +239,7 @@ module Fluent::Plugin
|
|
221
239
|
end
|
222
240
|
|
223
241
|
messages.each do |m|
|
224
|
-
line = m.message.data.chomp
|
242
|
+
line = @decompress.call(m.message.data).chomp
|
225
243
|
attributes = m.attributes
|
226
244
|
@parser.parse(line) do |time, record|
|
227
245
|
if time && record
|
@@ -1,9 +1,11 @@
|
|
1
|
+
require 'fluent/plugin/compressable'
|
1
2
|
require 'fluent/plugin/output'
|
2
3
|
require 'fluent/plugin/gcloud_pubsub/client'
|
3
4
|
require 'fluent/plugin_helper/inject'
|
4
5
|
|
5
6
|
module Fluent::Plugin
|
6
7
|
class GcloudPubSubOutput < Output
|
8
|
+
include Fluent::Plugin::Compressable
|
7
9
|
include Fluent::PluginHelper::Inject
|
8
10
|
|
9
11
|
Fluent::Plugin.register_output('gcloud_pubsub', self)
|
@@ -31,6 +33,10 @@ module Fluent::Plugin
|
|
31
33
|
config_param :max_message_size, :integer, :default => 4000000 # 4MB
|
32
34
|
desc 'Publishing the set field as an attribute'
|
33
35
|
config_param :attribute_keys, :array, :default => []
|
36
|
+
desc 'Set service endpoint'
|
37
|
+
config_param :endpoint, :string, :default => nil
|
38
|
+
desc 'Compress messages'
|
39
|
+
config_param :compression, :string, :default => nil
|
34
40
|
|
35
41
|
config_section :buffer do
|
36
42
|
config_set_default :@type, DEFAULT_BUFFER_TYPE
|
@@ -45,11 +51,16 @@ module Fluent::Plugin
|
|
45
51
|
super
|
46
52
|
placeholder_validate!(:topic, @topic)
|
47
53
|
@formatter = formatter_create
|
54
|
+
@compress = if @compression == 'gzip'
|
55
|
+
method(:gzip_compress)
|
56
|
+
else
|
57
|
+
method(:no_compress)
|
58
|
+
end
|
48
59
|
end
|
49
60
|
|
50
61
|
def start
|
51
62
|
super
|
52
|
-
@publisher = Fluent::GcloudPubSub::Publisher.new @project, @key, @autocreate_topic, @dest_project
|
63
|
+
@publisher = Fluent::GcloudPubSub::Publisher.new @project, @key, @autocreate_topic, @dest_project, @endpoint
|
53
64
|
end
|
54
65
|
|
55
66
|
def format(tag, time, record)
|
@@ -58,7 +69,7 @@ module Fluent::Plugin
|
|
58
69
|
@attribute_keys.each do |key|
|
59
70
|
attributes[key] = record.delete(key)
|
60
71
|
end
|
61
|
-
[@formatter.format(tag, time, record), attributes].to_msgpack
|
72
|
+
[@compress.call(@formatter.format(tag, time, record)), attributes].to_msgpack
|
62
73
|
end
|
63
74
|
|
64
75
|
def formatted_to_msgpack_binary?
|
@@ -108,5 +119,13 @@ module Fluent::Plugin
|
|
108
119
|
log.debug "send message topic:#{topic} length:#{messages.length} size:#{messages.map(&:bytesize).inject(:+)}"
|
109
120
|
@publisher.publish(topic, messages)
|
110
121
|
end
|
122
|
+
|
123
|
+
def gzip_compress(message)
|
124
|
+
compress message
|
125
|
+
end
|
126
|
+
|
127
|
+
def no_compress(message)
|
128
|
+
message
|
129
|
+
end
|
111
130
|
end
|
112
131
|
end
|
@@ -10,22 +10,14 @@ end
|
|
10
10
|
require 'test/unit'
|
11
11
|
require "test/unit/rr"
|
12
12
|
|
13
|
-
$LOAD_PATH.unshift(File.
|
14
|
-
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
13
|
+
$LOAD_PATH.unshift(File.expand_path("../../", __FILE__))
|
15
14
|
|
16
|
-
require
|
17
|
-
|
18
|
-
|
19
|
-
nulllogger.instance_eval {|obj|
|
20
|
-
def method_missing(method, *args)
|
21
|
-
# pass
|
22
|
-
end
|
23
|
-
}
|
24
|
-
$log = nulllogger
|
25
|
-
end
|
15
|
+
require "fluent/test"
|
16
|
+
require "fluent/test/driver/output"
|
17
|
+
require "fluent/test/helpers"
|
26
18
|
|
27
19
|
require 'fluent/plugin/in_gcloud_pubsub'
|
28
20
|
require 'fluent/plugin/out_gcloud_pubsub'
|
29
21
|
|
30
|
-
|
31
|
-
|
22
|
+
Test::Unit::TestCase.include(Fluent::Test::Helpers)
|
23
|
+
Test::Unit::TestCase.extend(Fluent::Test::Helpers)
|
@@ -1,7 +1,8 @@
|
|
1
1
|
require 'net/http'
|
2
2
|
require 'json'
|
3
3
|
|
4
|
-
require_relative "../
|
4
|
+
require_relative "../helper"
|
5
|
+
require 'fluent/plugin/compressable'
|
5
6
|
require "fluent/test/driver/input"
|
6
7
|
|
7
8
|
class GcloudPubSubInputTest < Test::Unit::TestCase
|
@@ -164,6 +165,22 @@ class GcloudPubSubInputTest < Test::Unit::TestCase
|
|
164
165
|
end
|
165
166
|
end
|
166
167
|
|
168
|
+
class DummyMsgDataGzipped
|
169
|
+
include Fluent::Plugin::Compressable
|
170
|
+
|
171
|
+
def data
|
172
|
+
compress '{"foo": "bar"}'
|
173
|
+
end
|
174
|
+
end
|
175
|
+
class DummyMessageGzipped
|
176
|
+
def message
|
177
|
+
DummyMsgDataGzipped.new
|
178
|
+
end
|
179
|
+
def attributes
|
180
|
+
{"attr_1" => "a", "attr_2" => "b"}
|
181
|
+
end
|
182
|
+
end
|
183
|
+
|
167
184
|
setup do
|
168
185
|
@subscriber = mock!
|
169
186
|
@topic_mock = mock!.subscription('subscription-test') { @subscriber }
|
@@ -263,6 +280,22 @@ class GcloudPubSubInputTest < Test::Unit::TestCase
|
|
263
280
|
end
|
264
281
|
end
|
265
282
|
|
283
|
+
test 'with gzip decompression' do
|
284
|
+
messages = Array.new(1, DummyMessageGzipped.new)
|
285
|
+
@subscriber.pull(immediate: true, max: 100).at_least(1) { messages }
|
286
|
+
@subscriber.acknowledge(messages).at_least(1)
|
287
|
+
|
288
|
+
d = create_driver("#{CONFIG}\ndecompression gzip")
|
289
|
+
d.run(expect_emits: 1, timeout: 3)
|
290
|
+
emits = d.events
|
291
|
+
|
292
|
+
assert_equal(1, emits.length)
|
293
|
+
emits.each do |tag, time, record|
|
294
|
+
assert_equal("test", tag)
|
295
|
+
assert_equal({"foo" => "bar"}, record)
|
296
|
+
end
|
297
|
+
end
|
298
|
+
|
266
299
|
test 'invalid messages with parse_error_action warning' do
|
267
300
|
messages = Array.new(1, DummyInvalidMessage.new)
|
268
301
|
@subscriber.pull(immediate: true, max: 100).at_least(1) { messages }
|
@@ -1,10 +1,12 @@
|
|
1
1
|
# coding: utf-8
|
2
|
-
require_relative "../
|
2
|
+
require_relative "../helper"
|
3
|
+
require 'fluent/plugin/compressable'
|
3
4
|
require "fluent/test/driver/output"
|
4
5
|
require "fluent/test/helpers"
|
5
6
|
|
6
7
|
class GcloudPubSubOutputTest < Test::Unit::TestCase
|
7
8
|
include Fluent::Test::Helpers
|
9
|
+
include Fluent::Plugin::Compressable
|
8
10
|
|
9
11
|
CONFIG = %[
|
10
12
|
project project-test
|
@@ -80,6 +82,13 @@ class GcloudPubSubOutputTest < Test::Unit::TestCase
|
|
80
82
|
@publisher = mock!
|
81
83
|
@pubsub_mock = mock!
|
82
84
|
stub(Google::Cloud::Pubsub).new { @pubsub_mock }
|
85
|
+
|
86
|
+
@old_report_on_exception = Thread.report_on_exception
|
87
|
+
Thread.report_on_exception = false
|
88
|
+
end
|
89
|
+
|
90
|
+
teardown do
|
91
|
+
Thread.report_on_exception = @old_report_on_exception
|
83
92
|
end
|
84
93
|
|
85
94
|
test '"autocreate_topic" is enabled' do
|
@@ -173,6 +182,13 @@ class GcloudPubSubOutputTest < Test::Unit::TestCase
|
|
173
182
|
@publisher = mock!
|
174
183
|
@pubsub_mock = mock!.topic(anything) { @publisher }
|
175
184
|
stub(Google::Cloud::Pubsub).new { @pubsub_mock }
|
185
|
+
|
186
|
+
@old_report_on_exception = Thread.report_on_exception
|
187
|
+
Thread.report_on_exception = false
|
188
|
+
end
|
189
|
+
|
190
|
+
teardown do
|
191
|
+
Thread.report_on_exception = @old_report_on_exception
|
176
192
|
end
|
177
193
|
|
178
194
|
test 'messages are divided into "max_messages"' do
|
@@ -248,5 +264,22 @@ class GcloudPubSubOutputTest < Test::Unit::TestCase
|
|
248
264
|
end
|
249
265
|
assert_equal({"tag" => 'test', "foo" => "bar"}, JSON.parse(MessagePack.unpack(d.formatted.first)[0]))
|
250
266
|
end
|
267
|
+
|
268
|
+
test 'with gzip compression' do
|
269
|
+
d = create_driver(%[
|
270
|
+
project project-test
|
271
|
+
topic topic-test
|
272
|
+
key key-test
|
273
|
+
compression gzip
|
274
|
+
])
|
275
|
+
test_msg = {"a" => "abc"}
|
276
|
+
|
277
|
+
@publisher.publish.once
|
278
|
+
d.run(default_tag: "test") do
|
279
|
+
d.feed(test_msg)
|
280
|
+
end
|
281
|
+
|
282
|
+
assert_equal(test_msg, JSON.parse(decompress(MessagePack.unpack(d.formatted.first)[0])))
|
283
|
+
end
|
251
284
|
end
|
252
285
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fluent-plugin-gcloud-pubsub-custom
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yoshihiro MIYAI
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-01-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: fluentd
|
@@ -36,14 +36,14 @@ dependencies:
|
|
36
36
|
requirements:
|
37
37
|
- - "~>"
|
38
38
|
- !ruby/object:Gem::Version
|
39
|
-
version:
|
39
|
+
version: 2.3.1
|
40
40
|
type: :runtime
|
41
41
|
prerelease: false
|
42
42
|
version_requirements: !ruby/object:Gem::Requirement
|
43
43
|
requirements:
|
44
44
|
- - "~>"
|
45
45
|
- !ruby/object:Gem::Version
|
46
|
-
version:
|
46
|
+
version: 2.3.1
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: bundler
|
49
49
|
requirement: !ruby/object:Gem::Requirement
|
@@ -106,8 +106,8 @@ executables: []
|
|
106
106
|
extensions: []
|
107
107
|
extra_rdoc_files: []
|
108
108
|
files:
|
109
|
+
- ".github/workflows/test.yml"
|
109
110
|
- ".gitignore"
|
110
|
-
- ".travis.yml"
|
111
111
|
- CHANGELOG.md
|
112
112
|
- Gemfile
|
113
113
|
- LICENSE
|
@@ -117,9 +117,9 @@ files:
|
|
117
117
|
- lib/fluent/plugin/gcloud_pubsub/client.rb
|
118
118
|
- lib/fluent/plugin/in_gcloud_pubsub.rb
|
119
119
|
- lib/fluent/plugin/out_gcloud_pubsub.rb
|
120
|
+
- test/helper.rb
|
120
121
|
- test/plugin/test_in_gcloud_pubsub.rb
|
121
122
|
- test/plugin/test_out_gcloud_pubsub.rb
|
122
|
-
- test/test_helper.rb
|
123
123
|
homepage: https://github.com/mia-0032/fluent-plugin-gcloud-pubsub-custom
|
124
124
|
licenses:
|
125
125
|
- MIT
|
@@ -144,6 +144,6 @@ signing_key:
|
|
144
144
|
specification_version: 4
|
145
145
|
summary: Google Cloud Pub/Sub input/output plugin for Fluentd event collector
|
146
146
|
test_files:
|
147
|
+
- test/helper.rb
|
147
148
|
- test/plugin/test_in_gcloud_pubsub.rb
|
148
149
|
- test/plugin/test_out_gcloud_pubsub.rb
|
149
|
-
- test/test_helper.rb
|
data/.travis.yml
DELETED
@@ -1,24 +0,0 @@
|
|
1
|
-
language: ruby
|
2
|
-
|
3
|
-
rvm:
|
4
|
-
- 2.4
|
5
|
-
- 2.5
|
6
|
-
- 2.6
|
7
|
-
- 2.7
|
8
|
-
- ruby-head
|
9
|
-
|
10
|
-
gemfile:
|
11
|
-
- Gemfile
|
12
|
-
|
13
|
-
branches:
|
14
|
-
only:
|
15
|
-
- master
|
16
|
-
|
17
|
-
before_install: gem update bundler
|
18
|
-
script: bundle exec rake test
|
19
|
-
|
20
|
-
sudo: false
|
21
|
-
|
22
|
-
matrix:
|
23
|
-
allow_failures:
|
24
|
-
- rvm: ruby-head
|