fluent-plugin-tagged_copy 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -0
- data/README.md +8 -0
- data/fluent-plugin-tagged_copy.gemspec +2 -1
- data/lib/fluent/plugin/out_tagged_copy.rb +23 -17
- data/test/plugin/out_tagged_copy.rb +74 -0
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 38965e064c26bb7bca4fffb45b46757f7afcad8e
|
4
|
+
data.tar.gz: 86ec877a8d1468b8d54c7a29b3db1069b8f57eaf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dba9888630a6da2be2c48b18d1e186c137c681a555e4d0802a2de7eab7994a2d89dd55023c5cda8b70dc3e71e837e6e69f135c865631d68555eb2cb0c64df7cf
|
7
|
+
data.tar.gz: 4ced69264a506126ebb0bc8e697bfcf65818af4fca159fd8c66e8ff010b0d2ae792c1cc3e1669635be08fa47727a883c499ad3c5d24e4be473c35b5a2e868c2a
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -44,6 +44,14 @@ But, you can specify `filter` directive with following options
|
|
44
44
|
|
45
45
|
Remove tag prefix for output message
|
46
46
|
|
47
|
+
* add_tag_suffix
|
48
|
+
|
49
|
+
Add tag suffix for output message
|
50
|
+
|
51
|
+
* remove_tag_suffix
|
52
|
+
|
53
|
+
Remove tag suffix for output message
|
54
|
+
|
47
55
|
## Contributing
|
48
56
|
|
49
57
|
1. Fork it
|
@@ -3,12 +3,13 @@ $:.push File.expand_path("../lib", __FILE__)
|
|
3
3
|
|
4
4
|
Gem::Specification.new do |s|
|
5
5
|
s.name = "fluent-plugin-tagged_copy"
|
6
|
-
s.version = "0.0.
|
6
|
+
s.version = "0.0.2"
|
7
7
|
s.authors = ["Naotoshi Seo"]
|
8
8
|
s.email = ["sonots@gmail.com"]
|
9
9
|
s.homepage = "https://github.com/sonots/fluent-plugin-tagged_copy"
|
10
10
|
s.summary = "Fluentd out_copy extension to do tagging before copy"
|
11
11
|
s.description = s.summary
|
12
|
+
s.licenses = ["MIT"]
|
12
13
|
|
13
14
|
s.rubyforge_project = "fluent-plugin-tagged_copy"
|
14
15
|
|
@@ -21,8 +21,13 @@ module Fluent
|
|
21
21
|
log.debug "adding store type=#{type.dump}"
|
22
22
|
|
23
23
|
f = e.elements.select {|i| i.name == 'filter'}.first || {}
|
24
|
-
|
25
|
-
|
24
|
+
@tag_procs << tag_proc(
|
25
|
+
f['tag'],
|
26
|
+
f['add_tag_prefix'],
|
27
|
+
f['remove_tag_prefix'],
|
28
|
+
f['add_tag_suffix'],
|
29
|
+
f['remove_tag_suffix']
|
30
|
+
)
|
26
31
|
|
27
32
|
output = Plugin.new_output(type)
|
28
33
|
output.configure(e)
|
@@ -49,25 +54,26 @@ module Fluent
|
|
49
54
|
|
50
55
|
private
|
51
56
|
|
52
|
-
def
|
53
|
-
|
54
|
-
|
55
|
-
if
|
56
|
-
|
57
|
-
|
58
|
-
|
57
|
+
def tag_proc(tag, add_tag_prefix, remove_tag_prefix, add_tag_suffix, remove_tag_suffix)
|
58
|
+
rstrip = Proc.new {|str, substr| str.chomp(substr) }
|
59
|
+
lstrip = Proc.new {|str, substr| str.start_with?(substr) ? str[substr.size..-1] : str }
|
60
|
+
tag_prefix = "#{rstrip.call(add_tag_prefix, '.')}." if add_tag_prefix
|
61
|
+
tag_suffix = ".#{lstrip.call(add_tag_suffix, '.')}" if add_tag_suffix
|
62
|
+
tag_prefix_match = "#{rstrip.call(remove_tag_prefix, '.')}." if remove_tag_prefix
|
63
|
+
tag_suffix_match = ".#{lstrip.call(remove_tag_suffix, '.')}" if remove_tag_suffix
|
64
|
+
tag_fixed = tag if tag
|
65
|
+
if tag_fixed
|
66
|
+
Proc.new {|tag| tag_fixed }
|
67
|
+
elsif tag_prefix_match and tag_suffix_match
|
68
|
+
Proc.new {|tag| "#{tag_prefix}#{rstrip.call(lstrip.call(tag, tag_prefix_match), tag_suffix_match)}#{tag_suffix}" }
|
59
69
|
elsif tag_prefix_match
|
60
|
-
Proc.new {|
|
61
|
-
elsif
|
62
|
-
Proc.new {|
|
70
|
+
Proc.new {|tag| "#{tag_prefix}#{lstrip.call(tag, tag_prefix_match)}#{tag_suffix}" }
|
71
|
+
elsif tag_suffix_match
|
72
|
+
Proc.new {|tag| "#{tag_prefix}#{rstrip.call(tag, tag_suffix_match)}#{tag_suffix}" }
|
63
73
|
else
|
64
|
-
Proc.new {|
|
74
|
+
Proc.new {|tag| "#{tag_prefix}#{tag}#{tag_suffix}" }
|
65
75
|
end
|
66
76
|
end
|
67
|
-
|
68
|
-
def lstrip(string, substring)
|
69
|
-
string.index(substring) == 0 ? string[substring.size..-1] : string
|
70
|
-
end
|
71
77
|
end
|
72
78
|
|
73
79
|
class TaggedOutputChain
|
@@ -278,4 +278,78 @@ class TaggedCopyOutputTest < Test::Unit::TestCase
|
|
278
278
|
['test', time, {"a"=>2}],
|
279
279
|
], second.emits
|
280
280
|
end
|
281
|
+
|
282
|
+
def test_add_tag_suffix_emit
|
283
|
+
config = %[
|
284
|
+
<store>
|
285
|
+
<filter>
|
286
|
+
add_tag_suffix first
|
287
|
+
</filter>
|
288
|
+
type test
|
289
|
+
name c0
|
290
|
+
</store>
|
291
|
+
<store>
|
292
|
+
<filter>
|
293
|
+
add_tag_suffix second
|
294
|
+
</filter>
|
295
|
+
type test
|
296
|
+
name c0
|
297
|
+
</store>
|
298
|
+
]
|
299
|
+
d = create_driver(config)
|
300
|
+
|
301
|
+
time = Time.parse("2011-01-02 13:14:15 UTC").to_i
|
302
|
+
d.emit({"a"=>1}, time)
|
303
|
+
d.emit({"a"=>2}, time)
|
304
|
+
|
305
|
+
first = d.instance.outputs.first
|
306
|
+
assert_equal [
|
307
|
+
['test.first', time, {"a"=>1}],
|
308
|
+
['test.first', time, {"a"=>2}],
|
309
|
+
], first.emits
|
310
|
+
|
311
|
+
second = d.instance.outputs[1]
|
312
|
+
assert_equal [
|
313
|
+
['test.second', time, {"a"=>1}],
|
314
|
+
['test.second', time, {"a"=>2}],
|
315
|
+
], second.emits
|
316
|
+
end
|
317
|
+
|
318
|
+
def test_remove_tag_suffix_emit
|
319
|
+
config = %[
|
320
|
+
<store>
|
321
|
+
<filter>
|
322
|
+
remove_tag_suffix first
|
323
|
+
</filter>
|
324
|
+
type test
|
325
|
+
name c0
|
326
|
+
</store>
|
327
|
+
<store>
|
328
|
+
<filter>
|
329
|
+
remove_tag_suffix second
|
330
|
+
</filter>
|
331
|
+
type test
|
332
|
+
name c0
|
333
|
+
</store>
|
334
|
+
]
|
335
|
+
d = create_driver(config)
|
336
|
+
|
337
|
+
time = Time.parse("2011-01-02 13:14:15 UTC").to_i
|
338
|
+
d.tag = 'test.first'
|
339
|
+
d.emit({"a"=>1}, time)
|
340
|
+
d.tag = 'test.second'
|
341
|
+
d.emit({"a"=>2}, time)
|
342
|
+
|
343
|
+
first = d.instance.outputs.first
|
344
|
+
assert_equal [
|
345
|
+
['test', time, {"a"=>1}],
|
346
|
+
['test.second', time, {"a"=>2}],
|
347
|
+
], first.emits
|
348
|
+
|
349
|
+
second = d.instance.outputs[1]
|
350
|
+
assert_equal [
|
351
|
+
['test.first', time, {"a"=>1}],
|
352
|
+
['test', time, {"a"=>2}],
|
353
|
+
], second.emits
|
354
|
+
end
|
281
355
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fluent-plugin-tagged_copy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Naotoshi Seo
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-04-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: fluentd
|
@@ -85,7 +85,8 @@ files:
|
|
85
85
|
- test/helper.rb
|
86
86
|
- test/plugin/out_tagged_copy.rb
|
87
87
|
homepage: https://github.com/sonots/fluent-plugin-tagged_copy
|
88
|
-
licenses:
|
88
|
+
licenses:
|
89
|
+
- MIT
|
89
90
|
metadata: {}
|
90
91
|
post_install_message:
|
91
92
|
rdoc_options: []
|