fluent-plugin-filter_empty_keys 0.0.2 → 0.0.3
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 +44 -0
- data/fluent-plugin-filter_empty_keys.gemspec +1 -1
- data/lib/fluent/plugin/filter_empty_keys.rb +26 -1
- data/test/test_filter_empty_keys.rb +13 -8
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8f90d886f79fd03b913bba8151528489e376380c
|
4
|
+
data.tar.gz: b9e146a6345f7d985ef0003edf71a758cf396d05
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d1979232f4de1292104871165ca37889d5b3f6778c2a16da501da6615c5f1015f3fe614414be61aff48045ed2993acaa61bef5b889166700a5c901c1e4468f5e
|
7
|
+
data.tar.gz: f693eb2bba9f3faa8d6418dd6470ff8a749eb83f4f7cd809c752ee82bf615893ec4819ca543c2367c5b372271b51d808741df0ece6d10d42d1aad1d31f116072
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -14,6 +14,50 @@ Use RubyGems:
|
|
14
14
|
gem install fluent-plugin-filter_empty_keys
|
15
15
|
```
|
16
16
|
|
17
|
+
## Configuration Examples
|
18
|
+
|
19
|
+
```
|
20
|
+
<source>
|
21
|
+
type dummy
|
22
|
+
tag dummy
|
23
|
+
dummy {"field1":"","field2":"2","field3":"2013-02-12 22:04:14 UTC","field4":"","field5":"a,b,c"}
|
24
|
+
</source>
|
25
|
+
|
26
|
+
<filter **>
|
27
|
+
type empty_keys
|
28
|
+
</filter>
|
29
|
+
|
30
|
+
<match **>
|
31
|
+
type stdout
|
32
|
+
</match>
|
33
|
+
```
|
34
|
+
|
35
|
+
You should see casted records:
|
36
|
+
```
|
37
|
+
dummy {"field2":"2","field3":"2013-02-12 22:04:14 UTC","field5":"a,b,c"}
|
38
|
+
```
|
39
|
+
|
40
|
+
```
|
41
|
+
<source>
|
42
|
+
type dummy
|
43
|
+
tag dummy
|
44
|
+
dummy {"field0":0,"field1":"","field2":"Undefined","field3":"2013-02-12 22:04:14 UTC","field4":"","field5":"a,b,c"}
|
45
|
+
</source>
|
46
|
+
|
47
|
+
<filter **>
|
48
|
+
type empty_keys
|
49
|
+
empty_keys field0:0,field2:Undefined
|
50
|
+
</filter>
|
51
|
+
|
52
|
+
<match **>
|
53
|
+
type stdout
|
54
|
+
</match>
|
55
|
+
```
|
56
|
+
|
57
|
+
You should see casted records:
|
58
|
+
```
|
59
|
+
dummy {"field3":"2013-02-12 22:04:14 UTC","field5":"a,b,c"}
|
60
|
+
```
|
17
61
|
|
18
62
|
## ChangeLog
|
19
63
|
|
@@ -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_empty_keys"
|
6
|
-
s.version = "0.0.
|
6
|
+
s.version = "0.0.3"
|
7
7
|
s.authors = ["Al-waleed Shihadeh"]
|
8
8
|
s.email = ["wshihadh@gmail.com"]
|
9
9
|
s.homepage = "https://github.com/wshihadeh/fluent-plugin-filter_empty_keys.git"
|
@@ -5,8 +5,33 @@ module Fluent
|
|
5
5
|
class EmptyKeysFilter < Filter
|
6
6
|
Fluent::Plugin.register_filter('empty_keys', self)
|
7
7
|
|
8
|
+
config_param :empty_keys, :string, default: nil
|
9
|
+
config_param :keys_delimiter, :string, default: ','
|
10
|
+
config_param :values_delimiter, :string, default: ':'
|
11
|
+
|
12
|
+
def configure(conf)
|
13
|
+
super
|
14
|
+
|
15
|
+
@keys_empty_values = nil
|
16
|
+
@keys_empty_values = parse_empty_values_parameter unless @empty_keys.nil?
|
17
|
+
end
|
18
|
+
|
8
19
|
def filter(tag, time, record)
|
9
|
-
record.reject{ |k,v| (v.nil? || v.to_s.empty?) }
|
20
|
+
record.reject{ |k,v| (v.nil? || v.to_s.empty? || (!@keys_empty_values.nil? && v.to_s.eql?(@keys_empty_values[k]))) }
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def parse_empty_values_parameter
|
26
|
+
keys_empty_values = {}
|
27
|
+
|
28
|
+
@empty_keys.split(@keys_delimiter).each do |pattern_name|
|
29
|
+
key, empty_value, format = pattern_name.split(@values_delimiter, 3)
|
30
|
+
raise ConfigError, "EmptyValue is needed" if empty_value.nil?
|
31
|
+
keys_empty_values[key] = empty_value
|
32
|
+
end
|
33
|
+
|
34
|
+
keys_empty_values
|
10
35
|
end
|
11
36
|
end
|
12
37
|
end
|
@@ -23,14 +23,18 @@ class TypecastFilterTest < Test::Unit::TestCase
|
|
23
23
|
end
|
24
24
|
|
25
25
|
test 'test_empty_keys' do
|
26
|
-
d = create_driver
|
26
|
+
d = create_driver(%[
|
27
|
+
empty_keys Undefined:Undefined,Remove:1
|
28
|
+
])
|
27
29
|
msg = {
|
28
|
-
'integer'
|
29
|
-
'nil'
|
30
|
-
'time'
|
31
|
-
'bool'
|
32
|
-
'array'
|
33
|
-
'empty'
|
30
|
+
'integer' => 1,
|
31
|
+
'nil' => nil,
|
32
|
+
'time' => '2013-02-12 22:01:15 UTC',
|
33
|
+
'bool' => 'true',
|
34
|
+
'array' => 'a,b,c',
|
35
|
+
'empty' => '',
|
36
|
+
'Undefined' => 'Undefined',
|
37
|
+
'Remove' => 1,
|
34
38
|
}
|
35
39
|
filtered = filter(d, [msg]).first[2]
|
36
40
|
assert_equal 4, filtered.count
|
@@ -40,6 +44,7 @@ class TypecastFilterTest < Test::Unit::TestCase
|
|
40
44
|
assert_equal true, filtered.key?("bool")
|
41
45
|
assert_equal true, filtered.key?("array")
|
42
46
|
assert_equal false, filtered.key?("empty")
|
43
|
-
|
47
|
+
assert_equal false, filtered.key?("Undefined")
|
48
|
+
assert_equal false, filtered.key?("Remove")
|
44
49
|
end
|
45
50
|
end
|