logstash-filter-grok 4.0.0 → 4.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +3 -0
- data/lib/logstash/filters/grok/timeout_enforcer.rb +22 -55
- data/logstash-filter-grok.gemspec +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4a821dcb7736046a21e53c4cbb4d23e9e807175c0641e4f6855674bca39e00cb
|
4
|
+
data.tar.gz: e1b8780ab43c0701dc8a4c6db7335da834fd6fb057957dbca8d61bb190c8585b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ce2e26791c303cd15c504e136252cf01ced839481a2afd01536a76253b12f87f0d48826b522315f6b19dd0cdeefbb23ea9d7718e5dedfb3096539e077fd8f1d0
|
7
|
+
data.tar.gz: 386308027f66ec688f55712d83acca7f692f6b9fad3c0cbe0a4bc865e1beaa2c5d4c32757a572f388a73bede0788e11740ce989b84516da26e651095ed70cef1
|
data/CHANGELOG.md
CHANGED
@@ -1,44 +1,37 @@
|
|
1
1
|
class LogStash::Filters::Grok::TimeoutEnforcer
|
2
|
-
attr_reader :running
|
3
|
-
|
4
2
|
def initialize(logger, timeout_nanos)
|
5
3
|
@logger = logger
|
6
|
-
@running = false
|
4
|
+
@running = java.util.concurrent.atomic.AtomicBoolean.new(false)
|
7
5
|
@timeout_nanos = timeout_nanos
|
8
6
|
|
9
7
|
# Stores running matches with their start time, this is used to cancel long running matches
|
10
8
|
# Is a map of Thread => start_time
|
11
9
|
@threads_to_start_time = java.util.concurrent.ConcurrentHashMap.new
|
12
|
-
|
10
|
+
end
|
11
|
+
|
12
|
+
def running
|
13
|
+
@running.get()
|
13
14
|
end
|
14
15
|
|
15
16
|
def grok_till_timeout(grok, field, value)
|
16
17
|
begin
|
17
18
|
thread = java.lang.Thread.currentThread()
|
18
|
-
|
19
|
+
@threads_to_start_time.put(thread, java.lang.System.nanoTime)
|
19
20
|
grok.execute(value)
|
20
|
-
rescue InterruptedRegexpError => e
|
21
|
+
rescue InterruptedRegexpError, java.lang.InterruptedException => e
|
21
22
|
raise ::LogStash::Filters::Grok::TimeoutException.new(grok, field, value)
|
22
23
|
ensure
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
# It may appear that this should go in #stop_thread_groking but that would actually
|
28
|
-
# break functionality! If this were moved there we would clear the interrupt
|
29
|
-
# immediately after setting it in #cancel_timed_out, hence this MUST be here
|
30
|
-
java.lang.Thread.interrupted
|
31
|
-
ensure
|
32
|
-
@cancel_mutex.unlock
|
33
|
-
end
|
34
|
-
end
|
24
|
+
# If the regexp finished, but interrupt was called after, we'll want to
|
25
|
+
# clear the interrupted status anyway
|
26
|
+
@threads_to_start_time.remove(thread)
|
27
|
+
thread.interrupted
|
35
28
|
end
|
36
29
|
end
|
37
30
|
|
38
31
|
def start!
|
39
|
-
@running
|
32
|
+
@running.set(true)
|
40
33
|
@timer_thread = Thread.new do
|
41
|
-
while @running
|
34
|
+
while @running.get()
|
42
35
|
begin
|
43
36
|
cancel_timed_out!
|
44
37
|
rescue Exception => e
|
@@ -54,49 +47,23 @@ class LogStash::Filters::Grok::TimeoutEnforcer
|
|
54
47
|
end
|
55
48
|
|
56
49
|
def stop!
|
57
|
-
@running
|
50
|
+
@running.set(false)
|
58
51
|
# Check for the thread mostly for a fast start/shutdown scenario
|
59
52
|
@timer_thread.join if @timer_thread
|
60
53
|
end
|
61
54
|
|
62
55
|
private
|
63
56
|
|
64
|
-
# These methods are private in large part because if they aren't called
|
65
|
-
# in specific sequence and used together in specific ways the interrupt
|
66
|
-
# behavior will be incorrect. Do NOT use or modify these methods unless
|
67
|
-
# you know what you are doing!
|
68
|
-
|
69
|
-
def start_thread_groking(thread)
|
70
|
-
# Clear any interrupts from any previous invocations that were not caught by Joni
|
71
|
-
java.lang.Thread.interrupted
|
72
|
-
@threads_to_start_time.put(thread, java.lang.System.nanoTime)
|
73
|
-
end
|
74
|
-
|
75
|
-
# Returns falsy in case there was no Grok execution in progress for the thread
|
76
|
-
def stop_thread_groking(thread)
|
77
|
-
@threads_to_start_time.remove(thread)
|
78
|
-
end
|
79
|
-
|
80
57
|
def cancel_timed_out!
|
81
58
|
now = java.lang.System.nanoTime # save ourselves some nanotime calls
|
82
|
-
@threads_to_start_time.
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
# output, pulling new input events and starting a new Grok execution in worker thread
|
91
|
-
# in between the above `if start_time < now && now - start_time > @timeout_nanos` and
|
92
|
-
# the call to `stop_thread_groking`.
|
93
|
-
if stop_thread_groking(thread)
|
94
|
-
@cancel_mutex.lock
|
95
|
-
begin
|
96
|
-
thread.interrupt()
|
97
|
-
ensure
|
98
|
-
@cancel_mutex.unlock
|
99
|
-
end
|
59
|
+
@threads_to_start_time.forEach do |thread, start_time|
|
60
|
+
# Use compute to lock this value
|
61
|
+
@threads_to_start_time.computeIfPresent(thread) do |thread, start_time|
|
62
|
+
if start_time < now && now - start_time > @timeout_nanos
|
63
|
+
thread.interrupt
|
64
|
+
nil # Delete the key
|
65
|
+
else
|
66
|
+
start_time # preserve the key
|
100
67
|
end
|
101
68
|
end
|
102
69
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
|
3
3
|
s.name = 'logstash-filter-grok'
|
4
|
-
s.version = '4.0.
|
4
|
+
s.version = '4.0.1'
|
5
5
|
s.licenses = ['Apache License (2.0)']
|
6
6
|
s.summary = "Parses unstructured event data into fields"
|
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-grok
|
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: 2017-
|
11
|
+
date: 2017-12-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
requirement: !ruby/object:Gem::Requirement
|