fluent-plugin-throttle 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6b2e1a36b7725f3104af98d1fb78418cda39bbd485a4c934652a9e01a179bb23
4
- data.tar.gz: 55a63790bcf7b60f27fdf6a886791feb57a7f8245c7607a1c182890ea95122e6
3
+ metadata.gz: 42672474afdd0860dfd06b5dfa7547c1e3b6365f1a995bd288b5928d54afdcaa
4
+ data.tar.gz: 78cb604160da44a19eee7473e56590af7d7076042b143bc3138b8198b35c8f97
5
5
  SHA512:
6
- metadata.gz: 0ed4d59ec171b432ceb4d0f7bfd95842dbba2deef99d8fa81c12aa6531b3a72a87668f26df08a75189d203c5b9e31192d6cc02b3c60f70fbb7865a311ea35bc2
7
- data.tar.gz: f6fddde539b046be640c99327276e3f965c605f87a1949e25e29e2339d109b29cc7f874608bdd164bc6a1c7a6b4d34f7f0441e83432f4a6a41ee77e7270b1a95
6
+ metadata.gz: 6fe4f1c8d5c250ab8e4945086460227040ed87357ad8565ba484710a405d7f1a14461c1db2bd16f921945916e69e035c2d92c01b5fe91e57eacb9644a4d05349
7
+ data.tar.gz: 10d3b4572029fc79cbfb09cf223e82d2af69f3c1239165a6690d97a1ee512a27f27b05e945db195ca4c8f924b2e0aa2688f4e670364145f789f9f8aeefebf3dc
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- fluent-plugin-throttle (0.0.3)
4
+ fluent-plugin-throttle (0.0.5)
5
5
  fluentd (~> 1.1)
6
6
 
7
7
  GEM
@@ -15,19 +15,18 @@ GEM
15
15
  thor (>= 0.14.0)
16
16
  byebug (10.0.2)
17
17
  coderay (1.1.2)
18
- cool.io (1.5.3)
18
+ concurrent-ruby (1.1.6)
19
+ cool.io (1.6.0)
19
20
  crack (0.4.3)
20
21
  safe_yaml (~> 1.0.0)
21
- dig_rb (1.0.1)
22
- fluentd (1.2.3)
22
+ fluentd (1.11.1)
23
23
  cool.io (>= 1.4.5, < 2.0.0)
24
- dig_rb (~> 1.0.0)
25
24
  http_parser.rb (>= 0.5.1, < 0.7.0)
26
- msgpack (>= 0.7.0, < 2.0.0)
25
+ msgpack (>= 1.3.1, < 2.0.0)
27
26
  serverengine (>= 2.0.4, < 3.0.0)
28
27
  sigdump (~> 0.2.2)
29
28
  strptime (>= 0.2.2, < 1.0.0)
30
- tzinfo (~> 1.0)
29
+ tzinfo (>= 1.0, < 3.0)
31
30
  tzinfo-data (~> 1.0)
32
31
  yajl-ruby (~> 1.0)
33
32
  hashdiff (0.3.7)
@@ -39,7 +38,7 @@ GEM
39
38
  minitest (5.11.3)
40
39
  mocha (1.6.0)
41
40
  metaclass (~> 0.0.1)
42
- msgpack (1.2.4)
41
+ msgpack (1.3.3)
43
42
  power_assert (1.1.3)
44
43
  pry (0.11.3)
45
44
  coderay (~> 1.1.0)
@@ -50,18 +49,17 @@ GEM
50
49
  public_suffix (3.0.2)
51
50
  rake (12.3.1)
52
51
  safe_yaml (1.0.4)
53
- serverengine (2.0.7)
52
+ serverengine (2.2.1)
54
53
  sigdump (~> 0.2.2)
55
54
  sigdump (0.2.4)
56
55
  single_cov (1.1.0)
57
- strptime (0.2.3)
56
+ strptime (0.2.4)
58
57
  test-unit (3.2.8)
59
58
  power_assert
60
59
  thor (0.20.0)
61
- thread_safe (0.3.6)
62
- tzinfo (1.2.5)
63
- thread_safe (~> 0.1)
64
- tzinfo-data (1.2018.5)
60
+ tzinfo (2.0.2)
61
+ concurrent-ruby (~> 1.0)
62
+ tzinfo-data (1.2020.1)
65
63
  tzinfo (>= 1.0.0)
66
64
  webmock (3.4.2)
67
65
  addressable (>= 2.3.6)
@@ -86,4 +84,4 @@ DEPENDENCIES
86
84
  webmock (~> 3.3)
87
85
 
88
86
  BUNDLED WITH
89
- 1.16.2
87
+ 1.17.2
data/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  [![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://github.com/rubrikinc/fluent-plugin-throttle/blob/master/LICENSE)
4
4
 
5
- A sentry pluging to throttle logs. Logs are grouped by a configurable key. When
5
+ A sentry plugin to throttle logs. Logs are grouped by a configurable key. When
6
6
  a group exceeds a configuration rate, logs are dropped for this group.
7
7
 
8
8
  ## Installation
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = "fluent-plugin-throttle"
7
- spec.version = "0.0.4"
7
+ spec.version = "0.0.5"
8
8
  spec.authors = ["François-Xavier Bourlet"]
9
9
  spec.email = ["fx.bourlet@rubrik.com"]
10
10
  spec.summary = %q{Fluentd filter for throttling logs based on a configurable key.}
@@ -51,6 +51,8 @@ module Fluent::Plugin
51
51
  raise "group_bucket_period_s must be > 0" \
52
52
  unless @group_bucket_period_s > 0
53
53
 
54
+ @group_gc_timeout_s = 2 * @group_bucket_period_s
55
+
54
56
  raise "group_bucket_limit must be > 0" \
55
57
  unless @group_bucket_limit > 0
56
58
 
@@ -83,17 +85,26 @@ module Fluent::Plugin
83
85
  now = Time.now
84
86
  rate_limit_exceeded = @group_drop_logs ? nil : record # return nil on rate_limit_exceeded to drop the record
85
87
  group = extract_group(record)
86
- counter = (@counters[group] ||= Group.new(0, now, 0, 0, now, nil))
87
- counter.rate_count += 1
88
+
89
+ # Ruby hashes are ordered by insertion.
90
+ # Deleting and inserting moves the item to the end of the hash (most recently used)
91
+ counter = @counters[group] = @counters.delete(group) || Group.new(0, now, 0, 0, now, nil)
88
92
 
93
+ counter.rate_count += 1
89
94
  since_last_rate_reset = now - counter.rate_last_reset
90
95
  if since_last_rate_reset >= 1
91
- # compute and store rate/s at most every seconds.
96
+ # compute and store rate/s at most every second
92
97
  counter.aprox_rate = (counter.rate_count / since_last_rate_reset).round()
93
98
  counter.rate_count = 0
94
99
  counter.rate_last_reset = now
95
100
  end
96
101
 
102
+ # try to evict the least recently used group
103
+ lru_group, lru_counter = @counters.first
104
+ if !lru_group.nil? && now - lru_counter.rate_last_reset > @group_gc_timeout_s
105
+ @counters.delete(lru_group)
106
+ end
107
+
97
108
  if (now.to_i / @group_bucket_period_s) \
98
109
  > (counter.bucket_last_reset.to_i / @group_bucket_period_s)
99
110
  # next time period reached.
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-throttle
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - François-Xavier Bourlet
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-01-28 00:00:00.000000000 Z
11
+ date: 2020-06-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler