fluent-plugin-filter_linefeeder 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/fluent-plugin-filter_linefeeder.gemspec +1 -1
- data/lib/fluent/plugin/filter_linetrimer.rb +33 -0
- data/test/test_filter_linetrimer.rb +48 -0
- metadata +4 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 49230790cad9dc3fa4539a4061c9622cb2eaaf52
|
4
|
+
data.tar.gz: c4f87c213aaed77b1cec61da9d49ca63519537bb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bcdf2bb366b66ac6a53c28c64fd3e612cbed5214721eaf3f539c21c12a71bb857b054bcbf7190ed5ae1c1388119723d3718e2c8cb82b7f524d0dcc78a0094be2
|
7
|
+
data.tar.gz: 4a0d52a98a928c086498af53a2563b32ab43d1c5cbcb211284423d77de8e3d9bfe27090a0deebfd0cb5d361df520055472e5114b77a99795b8cc795925983d75
|
data/CHANGELOG.md
CHANGED
@@ -3,7 +3,7 @@ $:.push File.expand_path("../lib", __FILE__)
|
|
3
3
|
|
4
4
|
Gem::Specification.new do |s|
|
5
5
|
s.name = "fluent-plugin-filter_linefeeder"
|
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-filter_linefeeder"
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module Fluent
|
2
|
+
class LinetrimerFilter < Filter
|
3
|
+
Fluent::Plugin.register_filter('linetrimer', self)
|
4
|
+
|
5
|
+
config_param :key, :string
|
6
|
+
config_param :num, :integer
|
7
|
+
|
8
|
+
def initialize
|
9
|
+
require 'string/scrub' if RUBY_VERSION.to_f < 2.1
|
10
|
+
super
|
11
|
+
end
|
12
|
+
|
13
|
+
def configure(conf)
|
14
|
+
super
|
15
|
+
end
|
16
|
+
|
17
|
+
def filter(tag, time, record)
|
18
|
+
return record unless record[key]
|
19
|
+
record[key] = trim(record[key], num)
|
20
|
+
record
|
21
|
+
end
|
22
|
+
|
23
|
+
def trim(string, num)
|
24
|
+
begin
|
25
|
+
string.split("\n")[0...num].join("\n")
|
26
|
+
rescue ArgumentError => e
|
27
|
+
raise e unless e.message.index("invalid byte sequence in") == 0
|
28
|
+
string.scrub!('?')
|
29
|
+
retry
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require_relative 'helper'
|
2
|
+
require 'fluent/plugin/filter_linetrimer'
|
3
|
+
|
4
|
+
class LinetrimerFilterTest < Test::Unit::TestCase
|
5
|
+
include Fluent
|
6
|
+
|
7
|
+
setup do
|
8
|
+
Fluent::Test.setup
|
9
|
+
@time = Fluent::Engine.now
|
10
|
+
end
|
11
|
+
|
12
|
+
def create_driver(conf = '')
|
13
|
+
Test::FilterTestDriver.new(LinetrimerFilter).configure(conf, true)
|
14
|
+
end
|
15
|
+
|
16
|
+
def filter(d, msg)
|
17
|
+
d.run { d.filter(msg, @time) }
|
18
|
+
d.filtered_as_array.first[2]
|
19
|
+
end
|
20
|
+
|
21
|
+
sub_test_case 'configure' do
|
22
|
+
def test_keys
|
23
|
+
assert_raise Fluent::ConfigError do
|
24
|
+
create_driver('')
|
25
|
+
end
|
26
|
+
|
27
|
+
d = create_driver(%[key a\nnum 10])
|
28
|
+
assert_equal "a", d.instance.key
|
29
|
+
assert_equal 10, d.instance.num
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
sub_test_case 'filter' do
|
34
|
+
def test_trim
|
35
|
+
d = create_driver(%[key message\nnum 2])
|
36
|
+
msg = { 'message' => "foo\nbar\nbaz" }
|
37
|
+
filtered = filter(d, msg)
|
38
|
+
assert_equal "foo\nbar", filtered['message']
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_scrub
|
42
|
+
d = create_driver(%[key message\nnum 2])
|
43
|
+
msg = { 'message' => "\xff".force_encoding('UTF-8') }
|
44
|
+
filtered = filter(d, msg)
|
45
|
+
assert_equal "?", filtered['message']
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fluent-plugin-filter_linefeeder
|
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
|
@@ -97,8 +97,10 @@ files:
|
|
97
97
|
- example.conf
|
98
98
|
- fluent-plugin-filter_linefeeder.gemspec
|
99
99
|
- lib/fluent/plugin/filter_linefeeder.rb
|
100
|
+
- lib/fluent/plugin/filter_linetrimer.rb
|
100
101
|
- test/helper.rb
|
101
102
|
- test/test_filter_linefeeder.rb
|
103
|
+
- test/test_filter_linetrimer.rb
|
102
104
|
homepage: https://github.com/sonots/fluent-plugin-filter_linefeeder
|
103
105
|
licenses:
|
104
106
|
- MIT
|
@@ -126,3 +128,4 @@ summary: A Fluentd filter plugin to convert ' ' to " " (line feed)
|
|
126
128
|
test_files:
|
127
129
|
- test/helper.rb
|
128
130
|
- test/test_filter_linefeeder.rb
|
131
|
+
- test/test_filter_linetrimer.rb
|