logstash-filter-throttle 4.0.0 → 4.0.1
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/CHANGELOG.md +15 -9
- data/lib/logstash/filters/throttle.rb +27 -16
- data/logstash-filter-throttle.gemspec +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fad6d0a8d7a465d2f90cfc4ccb065804890444fe
|
4
|
+
data.tar.gz: 201cd6b667a0d2034116ef37a154aa8f3bd32dd1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 089baf8ba028077104a6bcde68d87eee9298825cb7bc7414ac0291eff7aa8a9e80533be00330dc15efb66acacc80dd6a6bc182aa26f998cc1d7f7b3d2a79f248
|
7
|
+
data.tar.gz: 4fe4d68746fe2119a753876dfe7e927abd13b4c8ca5dd46f291d4c8593dbc3c99f79a768aee67d1ef3830a733d49b836996b6103117e7314060c12682a2564ad
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,6 @@
|
|
1
|
+
## 4.0.1
|
2
|
+
- fix racing condition that causes logstash to crash under heavy load conditions
|
3
|
+
|
1
4
|
## 4.0.0
|
2
5
|
- Full reimplementation of the plugin. The plugin is now thread-safe and properly tracks past events.
|
3
6
|
- Updated tests and added runtime dependencies
|
@@ -6,15 +9,18 @@
|
|
6
9
|
- Relax constraint on logstash-core-plugin-api to >= 1.60 <= 2.99
|
7
10
|
|
8
11
|
## 3.0.1
|
9
|
-
|
12
|
+
- internal: Republish all the gems under jruby.
|
13
|
+
|
10
14
|
## 3.0.0
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
15
|
+
- internal,deps: Update the plugin to the version 2.0 of the plugin api, this change is required for Logstash 5.0 compatibility. See https://github.com/elastic/logstash/issues/5141
|
16
|
+
|
17
|
+
## 2.0.4
|
18
|
+
- internal,deps: Depend on logstash-core-plugin-api instead of logstash-core, removing the need to mass update plugins on major releases of logstash
|
19
|
+
|
20
|
+
## 2.0.3
|
21
|
+
- internal,deps: New dependency requirements for logstash-core for the 5.0 release
|
22
|
+
|
16
23
|
## 2.0.0
|
17
|
-
- Plugins were updated to follow the new shutdown semantic, this mainly allows Logstash to instruct input plugins to terminate gracefully,
|
24
|
+
- internal: Plugins were updated to follow the new shutdown semantic, this mainly allows Logstash to instruct input plugins to terminate gracefully,
|
18
25
|
instead of using Thread.raise on the plugins' threads. Ref: https://github.com/elastic/logstash/pull/3895
|
19
|
-
- Dependency on logstash-core update to 2.0
|
20
|
-
|
26
|
+
- internal,deps: Dependency on logstash-core update to 2.0
|
@@ -221,27 +221,38 @@ class LogStash::Filters::Throttle < LogStash::Filters::Base
|
|
221
221
|
# filters the event
|
222
222
|
public
|
223
223
|
def filter(event)
|
224
|
-
key = event.sprintf(@key)
|
225
|
-
period = event.sprintf(@period).to_i
|
226
|
-
period = 60 if period == 0
|
227
|
-
epoch = event.timestamp.to_i
|
228
|
-
|
229
|
-
|
230
|
-
|
224
|
+
key = event.sprintf(@key) # substitute field
|
225
|
+
period = event.sprintf(@period).to_i # substitute period
|
226
|
+
period = 60 if period == 0 # fallback if unparsable
|
227
|
+
epoch = event.timestamp.to_i # event epoch time
|
228
|
+
|
229
|
+
while true
|
230
|
+
# initialise timeslot cache (if required)
|
231
|
+
@key_cache.compute_if_absent(key) { ThreadSafe::TimeslotCache.new(epoch) }
|
232
|
+
timeslot_cache = @key_cache[key] # try to get timeslot cache
|
233
|
+
break unless timeslot_cache.nil? # retry until succesful
|
234
|
+
|
235
|
+
@logger.warn? and @logger.warn(
|
236
|
+
"filters/#{self.class.name}: timeslot cache disappeared, increase max_counters to prevent this.")
|
231
237
|
end
|
232
238
|
|
233
|
-
timeslot_cache =
|
234
|
-
timeslot_cache.latest = epoch # update to latest epoch
|
239
|
+
timeslot_cache.latest = epoch # update to latest epoch
|
235
240
|
|
236
241
|
# find target timeslot
|
237
242
|
timeslot_key = epoch - (epoch - timeslot_cache.created) % period
|
238
243
|
|
239
|
-
|
240
|
-
|
244
|
+
while true
|
245
|
+
# initialise timeslot and counter (if required)
|
246
|
+
timeslot_cache.compute_if_absent(timeslot_key) { Atomic.new(0) }
|
247
|
+
timeslot = timeslot_cache[timeslot_key] # try to get timeslot
|
248
|
+
break unless timeslot.nil? # retry until succesful
|
241
249
|
|
242
|
-
|
243
|
-
|
244
|
-
|
250
|
+
@logger.warn? and @logger.warn(
|
251
|
+
"filters/#{self.class.name}: timeslot disappeared, increase max_age to prevent this.")
|
252
|
+
end
|
253
|
+
|
254
|
+
timeslot.update { |v| v + 1 } # increment counter
|
255
|
+
count = timeslot.value # get latest counter value
|
245
256
|
|
246
257
|
@logger.debug? and @logger.debug(
|
247
258
|
"filters/#{self.class.name}: counter incremented",
|
@@ -267,13 +278,13 @@ class LogStash::Filters::Throttle < LogStash::Filters::Base
|
|
267
278
|
|
268
279
|
public
|
269
280
|
def flush(options = {})
|
270
|
-
max_latest = 0
|
281
|
+
max_latest = 0 # get maximum epoch
|
271
282
|
@key_cache.each_value { |tc| max_latest = tc.latest if tc.latest > max_latest }
|
272
283
|
|
273
284
|
total_counters = 0
|
274
285
|
@key_cache.each_pair do |key,timeslot_cache|
|
275
286
|
if timeslot_cache.latest < max_latest - @max_age
|
276
|
-
@key_cache.delete(key)
|
287
|
+
@key_cache.delete(key) # delete expired timeslot cache
|
277
288
|
else
|
278
289
|
total_counters += timeslot_cache.size # get total number of counters
|
279
290
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
|
3
3
|
s.name = 'logstash-filter-throttle'
|
4
|
-
s.version = '4.0.
|
4
|
+
s.version = '4.0.1'
|
5
5
|
s.licenses = ['Apache License (2.0)']
|
6
6
|
s.summary = "The throttle filter is for throttling the number of events received."
|
7
7
|
s.description = "This gem is a Logstash plugin required to be installed on top of the Logstash core pipeline using $LS_HOME/bin/logstash-plugin install gemname. This gem is not a stand-alone program"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: logstash-filter-throttle
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.0.
|
4
|
+
version: 4.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Elastic
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-09-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
requirement: !ruby/object:Gem::Requirement
|