fluent-plugin-dedup 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +1 -0
- data/README.md +6 -0
- data/fluent-plugin-dedup.gemspec +2 -1
- data/lib/fluent/plugin/out_dedup.rb +6 -3
- data/test/fluent/plugin/test_out_dedup.rb +35 -0
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a92bdeb92dfea752942d7e900ccfc3f3533b8413
|
4
|
+
data.tar.gz: bbf4d1075267b6aea71581d81575a49d6f8a7a21
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: eb8019884f0c506f9bb7a2d10ef5ac1a91db01537c59aa863c219a5eccb65ddf7c80596bef349433c8e9278f3aeab42b139444e10d4d9447f78accd4a8048fa2
|
7
|
+
data.tar.gz: 13074c5f076328e3a3993655db17c8083140c98640825da49e6721362f20084bfead1389920071de924ebf910b39dfa702069c85bdfb39fd1029456ff020e62e
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -21,6 +21,8 @@ It's useful when the output of a command executed by `in_exec` only returns the
|
|
21
21
|
type dedup
|
22
22
|
key unique_id # required
|
23
23
|
file /tmp/dedup_state.json # optional. If set, saves the state to the file.
|
24
|
+
cache_per_tag 10 # optional. If set, recent logs up to this number is cached.
|
25
|
+
cache_ttl 600 # optional. If set, cache entries is expired in this TTL.
|
24
26
|
</match>
|
25
27
|
|
26
28
|
<match dedup.some.thing>
|
@@ -31,6 +33,10 @@ All logs that are processed by this plugin will have tag prefix `dedup`.
|
|
31
33
|
|
32
34
|
If the optional `file` parameter is set, it dumps the state during shutdown and loads on start, so that it can still dedup after reload.
|
33
35
|
|
36
|
+
If the optional `cache_per_tag` is set, it caches N recently appeared logs (only caches `unique_id` in this example) and compared to new logs.
|
37
|
+
|
38
|
+
If the optional `cache_ttl` is set, it evicts cache entries in a specific amount of time.
|
39
|
+
|
34
40
|
## Testing
|
35
41
|
|
36
42
|
bundle install
|
data/fluent-plugin-dedup.gemspec
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
Gem::Specification.new do |spec|
|
3
3
|
spec.name = "fluent-plugin-dedup"
|
4
|
-
spec.version = "0.
|
4
|
+
spec.version = "0.3.0"
|
5
5
|
spec.authors = ["edvakf"]
|
6
6
|
spec.email = ["taka.atsushi@gmail.com"]
|
7
7
|
spec.summary = %q{fluentd plugin for removing duplicate logs}
|
@@ -17,6 +17,7 @@ Gem::Specification.new do |spec|
|
|
17
17
|
spec.add_development_dependency "bundler", "~> 1.6"
|
18
18
|
spec.add_development_dependency "rake"
|
19
19
|
spec.add_development_dependency "test-unit", "~> 3.0"
|
20
|
+
spec.add_development_dependency "timecop"
|
20
21
|
|
21
22
|
spec.add_runtime_dependency "fluentd"
|
22
23
|
spec.add_runtime_dependency "lru_redux"
|
@@ -7,6 +7,7 @@ class Fluent::DedupOutput < Fluent::Output
|
|
7
7
|
config_param :key, :string, :default => nil
|
8
8
|
config_param :file, :string, :default => nil
|
9
9
|
config_param :cache_per_tag, :size, :default => 1
|
10
|
+
config_param :cache_ttl, :integer, :default => 0
|
10
11
|
|
11
12
|
# Define `log` method for v0.10.42 or earlier
|
12
13
|
unless method_defined?(:log)
|
@@ -18,8 +19,6 @@ class Fluent::DedupOutput < Fluent::Output
|
|
18
19
|
unless conf.include?('key')
|
19
20
|
raise Fluent::ConfigError, "config parameter `key` is required"
|
20
21
|
end
|
21
|
-
@key = conf['key']
|
22
|
-
@file = conf['file']
|
23
22
|
@states = {}
|
24
23
|
end
|
25
24
|
|
@@ -84,6 +83,10 @@ class Fluent::DedupOutput < Fluent::Output
|
|
84
83
|
end
|
85
84
|
|
86
85
|
def new_lru
|
87
|
-
|
86
|
+
if 0 < @cache_ttl
|
87
|
+
LruRedux::TTL::ThreadSafeCache.new(@cache_per_tag, @cache_ttl)
|
88
|
+
else
|
89
|
+
LruRedux::ThreadSafeCache.new(@cache_per_tag)
|
90
|
+
end
|
88
91
|
end
|
89
92
|
end
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'helper'
|
2
|
+
require 'timecop'
|
2
3
|
|
3
4
|
class DedupOutputTest < Test::Unit::TestCase
|
4
5
|
def setup
|
@@ -110,4 +111,38 @@ class DedupOutputTest < Test::Unit::TestCase
|
|
110
111
|
assert_equal '2', d.emits[1][2]['unique_id']
|
111
112
|
end
|
112
113
|
end
|
114
|
+
|
115
|
+
sub_test_case '`cache_ttl` parameter is present' do
|
116
|
+
setup do
|
117
|
+
Timecop.freeze(Time.now)
|
118
|
+
end
|
119
|
+
|
120
|
+
teardown do
|
121
|
+
Timecop.return
|
122
|
+
end
|
123
|
+
|
124
|
+
test "a record identical to most recent N records is suppressed with TTL option" do
|
125
|
+
config = %[
|
126
|
+
key unique_id
|
127
|
+
cache_per_tag 2
|
128
|
+
cache_ttl 60
|
129
|
+
]
|
130
|
+
|
131
|
+
d = create_driver(config)
|
132
|
+
d.run do
|
133
|
+
d.emit({'unique_id' => '1'}, Time.now)
|
134
|
+
d.emit({'unique_id' => '1'}, Time.now) # dup
|
135
|
+
Timecop.freeze(Time.now + 59)
|
136
|
+
d.emit({'unique_id' => '1'}, Time.now) # dup
|
137
|
+
Timecop.freeze(Time.now + 1) # expires cache
|
138
|
+
d.emit({'unique_id' => '1'}, Time.now)
|
139
|
+
Timecop.freeze(Time.now + 1)
|
140
|
+
d.emit({'unique_id' => '1'}, Time.now) # dup
|
141
|
+
end
|
142
|
+
|
143
|
+
assert_equal 2, d.emits.length
|
144
|
+
assert_equal '1', d.emits[0][2]['unique_id']
|
145
|
+
assert_equal '1', d.emits[1][2]['unique_id']
|
146
|
+
end
|
147
|
+
end
|
113
148
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fluent-plugin-dedup
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- edvakf
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-11-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -52,6 +52,20 @@ dependencies:
|
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: timecop
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
55
69
|
- !ruby/object:Gem::Dependency
|
56
70
|
name: fluentd
|
57
71
|
requirement: !ruby/object:Gem::Requirement
|