fluent-plugin-time-sampling 0.1.2 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +5 -7
- data/fluent-plugin-time-sampling.gemspec +3 -3
- data/lib/fluent/plugin/filter_time_sampling.rb +11 -13
- data/test/helper.rb +6 -5
- data/test/plugin/test_filter_time_sampling.rb +7 -9
- metadata +9 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9b13c685c3a37cd72a52a6b94c76869644d5aaf0
|
4
|
+
data.tar.gz: 4a750fedf415443a7cc3c69432fed6c3ef1ac9dc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 051c2327dc905e8e6ec3e147bbb3e3c8f5c81f23537df7fbf5943e742d06d16575a1b20702c7f6b2aec0799939ff70fc4c1d3f6791be54cd4d694d10fd931163
|
7
|
+
data.tar.gz: 96bca62ee538425e816eccc5319376475088a014ca18e02468883700e074697cec579b2504d26ff215ffbf9c6851661be89d912a9628fa7a4f0f96ebdffff965
|
data/README.md
CHANGED
@@ -25,17 +25,15 @@ Example:
|
|
25
25
|
|
26
26
|
Assume following input in 10 seconds:
|
27
27
|
```
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
test.tag { "hostname": "host2", "sample_key1": "baz", "sample_key2": "ddd" }
|
28
|
+
sample.tag { "hostname": "host1", "sample_key1": "foo", "sample_key2": "aaa" }
|
29
|
+
sample.tag { "hostname": "host1", "sample_key1": "foo", "sample_key2": "bbb" }
|
30
|
+
sample.tag { "hostname": "host2", "sample_key1": "bar", "sample_key2": "ccc" }
|
32
31
|
```
|
33
32
|
|
34
33
|
then output is below:
|
35
34
|
```
|
36
|
-
|
37
|
-
|
38
|
-
test.tag { "hostname": "host2", "sample_key2": "ddd" }
|
35
|
+
sample.tag { "hostname": "host1", "sample_key2": "aaa" }
|
36
|
+
sample.tag { "hostname": "host2", "sample_key2": "ccc" }
|
39
37
|
```
|
40
38
|
|
41
39
|
## Configuration
|
@@ -4,10 +4,10 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
|
5
5
|
Gem::Specification.new do |gem|
|
6
6
|
gem.name = "fluent-plugin-time-sampling"
|
7
|
-
gem.version = "0.
|
7
|
+
gem.version = "1.0.2"
|
8
8
|
gem.authors = ["Yuki Kuwabara"]
|
9
9
|
gem.email = ["eramuk@gmail.com"]
|
10
|
-
gem.summary = "
|
10
|
+
gem.summary = "filtering record at prescribed intervals"
|
11
11
|
gem.description = gem.summary
|
12
12
|
gem.homepage = "https://github.com/eramuk/fluent-plugin-time-sampling"
|
13
13
|
gem.licenses = ["MIT"]
|
@@ -17,7 +17,7 @@ Gem::Specification.new do |gem|
|
|
17
17
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
18
|
gem.require_paths = ["lib"]
|
19
19
|
|
20
|
-
gem.add_runtime_dependency "fluentd", "
|
20
|
+
gem.add_runtime_dependency "fluentd", ">= 0.14.0"
|
21
21
|
|
22
22
|
gem.add_development_dependency "rake"
|
23
23
|
gem.add_development_dependency "test-unit"
|
@@ -1,12 +1,9 @@
|
|
1
|
-
require "fluent/
|
2
|
-
require "fluent/time"
|
3
|
-
require "fluent/timezone"
|
4
|
-
require "fluent/config/error"
|
1
|
+
require "fluent/plugin/filter"
|
5
2
|
require "date"
|
6
3
|
|
7
|
-
module Fluent
|
4
|
+
module Fluent::Plugin
|
8
5
|
class TimeSamplingFilter < Filter
|
9
|
-
Plugin.register_filter('time_sampling', self)
|
6
|
+
Fluent::Plugin.register_filter('time_sampling', self)
|
10
7
|
|
11
8
|
config_param :unit, :array, value_type: :string
|
12
9
|
config_param :keep_keys, :array, value_type: :string, default: []
|
@@ -15,9 +12,10 @@ module Fluent
|
|
15
12
|
def configure(conf)
|
16
13
|
super
|
17
14
|
@cache = {}
|
18
|
-
@
|
19
|
-
@cache_clear_interval = @interval * 2
|
15
|
+
@cache_period = @interval * 2
|
20
16
|
@interval = -1 if @interval.zero?
|
17
|
+
@old_cache_clear_interval = 300
|
18
|
+
@old_cache_clear_time = Time.now
|
21
19
|
end
|
22
20
|
|
23
21
|
def start
|
@@ -48,9 +46,9 @@ module Fluent
|
|
48
46
|
record.dup : record.select { |k, v| @keep_keys.include?(k) }
|
49
47
|
end
|
50
48
|
|
51
|
-
if Time.now > @
|
52
|
-
|
53
|
-
@
|
49
|
+
if Time.now > @old_cache_clear_time + @old_cache_clear_interval
|
50
|
+
clear_old_cache
|
51
|
+
@old_cache_clear_time = Time.now
|
54
52
|
end
|
55
53
|
|
56
54
|
new_record ||= nil
|
@@ -69,9 +67,9 @@ module Fluent
|
|
69
67
|
end
|
70
68
|
end
|
71
69
|
|
72
|
-
def
|
70
|
+
def clear_old_cache
|
73
71
|
@cache.each_key do |key|
|
74
|
-
expired = Time.now > @cache[key][:time]
|
72
|
+
expired = Time.now > @cache[key][:time] + @cache_period
|
75
73
|
@cache.delete(key) if expired
|
76
74
|
end
|
77
75
|
end
|
data/test/helper.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require "rubygems"
|
2
|
+
require "bundler"
|
3
3
|
begin
|
4
4
|
Bundler.setup(:default, :development)
|
5
5
|
rescue Bundler::BundlerError => e
|
@@ -7,11 +7,11 @@ rescue Bundler::BundlerError => e
|
|
7
7
|
$stderr.puts "Run `bundle install` to install missing gems"
|
8
8
|
exit e.status_code
|
9
9
|
end
|
10
|
-
require
|
10
|
+
require "test/unit"
|
11
11
|
|
12
12
|
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
13
13
|
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
14
|
-
require
|
14
|
+
require "fluent/test"
|
15
15
|
unless ENV.has_key?('VERBOSE')
|
16
16
|
nulllogger = Object.new
|
17
17
|
nulllogger.instance_eval {|obj|
|
@@ -22,7 +22,8 @@ unless ENV.has_key?('VERBOSE')
|
|
22
22
|
$log = nulllogger
|
23
23
|
end
|
24
24
|
|
25
|
-
require
|
25
|
+
require "fluent/test/driver/filter"
|
26
|
+
require "fluent/plugin/filter_time_sampling"
|
26
27
|
|
27
28
|
class Test::Unit::TestCase
|
28
29
|
end
|
@@ -10,8 +10,8 @@ class TimeSamplingFilterTest < Test::Unit::TestCase
|
|
10
10
|
keep_keys sample_key2
|
11
11
|
}
|
12
12
|
|
13
|
-
def create_driver(conf = CONFIG, tag = "test")
|
14
|
-
Fluent::Test::
|
13
|
+
def create_driver(conf = CONFIG, tag = "tag.test")
|
14
|
+
Fluent::Test::Driver::Filter.new(Fluent::Plugin::TimeSamplingFilter).configure(conf)
|
15
15
|
end
|
16
16
|
|
17
17
|
def test_filter
|
@@ -21,13 +21,11 @@ class TimeSamplingFilterTest < Test::Unit::TestCase
|
|
21
21
|
{"sample_key1" => "bar", "sample_key2" => "ccc"},
|
22
22
|
]
|
23
23
|
d = create_driver
|
24
|
-
d.run
|
25
|
-
sample_records.each do |
|
26
|
-
d.
|
24
|
+
d.run(default_tag: "test") do
|
25
|
+
sample_records.each do |record|
|
26
|
+
d.feed(record)
|
27
27
|
end
|
28
|
-
|
29
|
-
|
30
|
-
p filtered.map {|m| m[2] }
|
28
|
+
end
|
29
|
+
p d.filtered
|
31
30
|
end
|
32
|
-
|
33
31
|
end
|
metadata
CHANGED
@@ -1,29 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fluent-plugin-time-sampling
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yuki Kuwabara
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-08-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: fluentd
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 0.
|
19
|
+
version: 0.14.0
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 0.
|
26
|
+
version: 0.14.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -52,7 +52,7 @@ dependencies:
|
|
52
52
|
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
|
-
description:
|
55
|
+
description: filtering record at prescribed intervals
|
56
56
|
email:
|
57
57
|
- eramuk@gmail.com
|
58
58
|
executables: []
|
@@ -87,10 +87,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
87
87
|
version: '0'
|
88
88
|
requirements: []
|
89
89
|
rubyforge_project:
|
90
|
-
rubygems_version: 2.
|
90
|
+
rubygems_version: 2.6.14
|
91
91
|
signing_key:
|
92
92
|
specification_version: 4
|
93
|
-
summary:
|
93
|
+
summary: filtering record at prescribed intervals
|
94
94
|
test_files:
|
95
95
|
- test/helper.rb
|
96
96
|
- test/plugin/test_filter_time_sampling.rb
|