fluent-plugin-gcloud-pubsub-custom 0.3.4 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/README.md +3 -0
- data/fluent-plugin-gcloud-pubsub-custom.gemspec +1 -1
- data/lib/fluent/plugin/in_gcloud_pubsub.rb +27 -6
- data/test/plugin/test_in_gcloud_pubsub.rb +43 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a8daf09e1eeb0af707c9fc9fda10284540c73555
|
4
|
+
data.tar.gz: c61879a204d49e5c1e11a630e5274916d3b8e507
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3de06b045e2f552038d2102c35cc127af05ee67d97138c428c5159f34db5f6f2d552215f8f3f882bab8c1c462f242bc7de21c723ee82e0f9a0e202af6802f0f9
|
7
|
+
data.tar.gz: 17502d7a5df5570848fcfb40de28522618825b5f31dc51674c2ded054827a0082a18b36e373ec375398a2c3ca3797dc11559755fc213996bc58fb054096c23c6
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -105,6 +105,9 @@ Use `gcloud_pubsub` input plugin.
|
|
105
105
|
|
106
106
|
- `tag` (required)
|
107
107
|
- Set tag of messages.
|
108
|
+
- If `tag_key` is specified, `tag` is used as tag when record don't have specified key.
|
109
|
+
- `tag_key` (optional)
|
110
|
+
- Set key to be used as tag.
|
108
111
|
- `project` (optional)
|
109
112
|
- Set your GCP project
|
110
113
|
- Running fluentd on GCP, you don't have to specify.
|
@@ -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 = "0.
|
10
|
+
gem.version = "0.4.0"
|
11
11
|
gem.authors = ["Yoshihiro MIYAI"]
|
12
12
|
gem.email = "msparrow17@gmail.com"
|
13
13
|
gem.has_rdoc = false
|
@@ -22,6 +22,8 @@ module Fluent
|
|
22
22
|
|
23
23
|
desc 'Set tag of messages.'
|
24
24
|
config_param :tag, :string
|
25
|
+
desc 'Set key to be used as tag.'
|
26
|
+
config_param :tag_key, :string, default: nil
|
25
27
|
desc 'Set your GCP project.'
|
26
28
|
config_param :project, :string, default: nil
|
27
29
|
desc 'Set your credential file path.'
|
@@ -108,6 +110,12 @@ module Fluent
|
|
108
110
|
@rpc_thread = nil
|
109
111
|
@stop_pull = false
|
110
112
|
|
113
|
+
@extract_tag = if @tag_key.nil?
|
114
|
+
method(:static_tag)
|
115
|
+
else
|
116
|
+
method(:dynamic_tag)
|
117
|
+
end
|
118
|
+
|
111
119
|
@parser = Plugin.new_parser(@format)
|
112
120
|
@parser.configure(conf)
|
113
121
|
end
|
@@ -153,6 +161,14 @@ module Fluent
|
|
153
161
|
|
154
162
|
private
|
155
163
|
|
164
|
+
def static_tag(record)
|
165
|
+
@tag
|
166
|
+
end
|
167
|
+
|
168
|
+
def dynamic_tag(record)
|
169
|
+
record.delete(@tag_key) || @tag
|
170
|
+
end
|
171
|
+
|
156
172
|
def start_rpc
|
157
173
|
log.info "listening http rpc server on http://#{@rpc_bind}:#{@rpc_port}/"
|
158
174
|
@rpc_srv = WEBrick::HTTPServer.new(
|
@@ -201,12 +217,15 @@ module Fluent
|
|
201
217
|
end
|
202
218
|
|
203
219
|
def process(messages)
|
204
|
-
|
220
|
+
event_streams = Hash.new do |hsh, key|
|
221
|
+
hsh[key] = MultiEventStream.new
|
222
|
+
end
|
223
|
+
|
205
224
|
messages.each do |m|
|
206
225
|
line = m.message.data.chomp
|
207
226
|
@parser.parse(line) do |time, record|
|
208
227
|
if time && record
|
209
|
-
|
228
|
+
event_streams[@extract_tag.call(record)].add(time, record)
|
210
229
|
else
|
211
230
|
case @parse_error_action
|
212
231
|
when :exception
|
@@ -218,10 +237,12 @@ module Fluent
|
|
218
237
|
end
|
219
238
|
end
|
220
239
|
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
240
|
+
event_streams.each do |tag, es|
|
241
|
+
# There are some output plugins not to supposed to be called with multi-threading.
|
242
|
+
# Maybe remove in the future.
|
243
|
+
@emit_guard.synchronize do
|
244
|
+
router.emit_stream(tag, es)
|
245
|
+
end
|
225
246
|
end
|
226
247
|
end
|
227
248
|
end
|
@@ -99,6 +99,23 @@ class GcloudPubSubInputTest < Test::Unit::TestCase
|
|
99
99
|
end
|
100
100
|
end
|
101
101
|
|
102
|
+
class DummyMsgDataWithTagKey
|
103
|
+
def initialize(tag)
|
104
|
+
@tag = tag
|
105
|
+
end
|
106
|
+
def data
|
107
|
+
return '{"foo": "bar", "test_tag_key": "' + @tag + '"}'
|
108
|
+
end
|
109
|
+
end
|
110
|
+
class DummyMessageWithTagKey
|
111
|
+
def initialize(tag)
|
112
|
+
@tag = tag
|
113
|
+
end
|
114
|
+
def message
|
115
|
+
DummyMsgDataWithTagKey.new @tag
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
102
119
|
setup do
|
103
120
|
@subscriber = mock!
|
104
121
|
@topic_mock = mock!.subscription('subscription-test') { @subscriber }
|
@@ -154,6 +171,32 @@ class GcloudPubSubInputTest < Test::Unit::TestCase
|
|
154
171
|
end
|
155
172
|
end
|
156
173
|
|
174
|
+
test 'with tag_key' do
|
175
|
+
messages = [
|
176
|
+
DummyMessageWithTagKey.new('tag1'),
|
177
|
+
DummyMessageWithTagKey.new('tag2'),
|
178
|
+
DummyMessage.new
|
179
|
+
]
|
180
|
+
@subscriber.pull(immediate: true, max: 100).once { messages }
|
181
|
+
@subscriber.acknowledge(messages).once
|
182
|
+
|
183
|
+
d = create_driver("#{CONFIG}\ntag_key test_tag_key")
|
184
|
+
d.run {
|
185
|
+
# d.run sleeps 0.5 sec
|
186
|
+
}
|
187
|
+
emits = d.emits
|
188
|
+
|
189
|
+
assert_equal(3, emits.length)
|
190
|
+
# test tag
|
191
|
+
assert_equal("tag1", emits[0][0])
|
192
|
+
assert_equal("tag2", emits[1][0])
|
193
|
+
assert_equal("test", emits[2][0])
|
194
|
+
# test record
|
195
|
+
emits.each do |tag, time, record|
|
196
|
+
assert_equal({"foo" => "bar"}, record)
|
197
|
+
end
|
198
|
+
end
|
199
|
+
|
157
200
|
test 'invalid messages with parse_error_action exception ' do
|
158
201
|
messages = Array.new(1, DummyInvalidMessage.new)
|
159
202
|
@subscriber.pull(immediate: true, max: 100).once { messages }
|
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: 0.
|
4
|
+
version: 0.4.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: 2017-01-
|
11
|
+
date: 2017-01-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: fluentd
|