-
Notifications
You must be signed in to change notification settings - Fork 28
/
1795.patch
61 lines (54 loc) · 1.8 KB
/
1795.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
From 2fae9033755a082b282d9f2e070e0e026154d88a Mon Sep 17 00:00:00 2001
From: Joao Duarte <[email protected]>
Date: Sat, 27 Sep 2014 23:59:50 +0200
Subject: [PATCH] Fix add_tag behaviour in dns filter
The filter should only modify the event's fields and tags if and only if
all resolves/reverses succeed. So we clone the event, modify the new
copy and return it if all operations succeed. Otherwise the original
event is not modified.
For performance reasons we could reverse the clone logic: clone the
event, modify the original event and, it case of failure, return the
backup.
Note: this changes the dns filter behaviour towards add_tag
---
lib/logstash/filters/dns.rb | 12 ++++++---
spec/filters/dns_spec.rb | 60 ++++++++++++++++++++++++++++++++++++++++++++-
2 files changed, 68 insertions(+), 4 deletions(-)
diff --git a/lib/logstash/filters/dns.rb b/lib/logstash/filters/dns.rb
index 46bb075..f23b819 100644
--- a/lib/logstash/filters/dns.rb
+++ b/lib/logstash/filters/dns.rb
@@ -70,11 +70,14 @@ def register
def filter(event)
return unless filter?(event)
+ new_event = event.clone
+
if @resolve
begin
status = Timeout::timeout(@timeout) {
- resolve(event)
+ resolve(new_event)
}
+ return if status.nil?
rescue Timeout::Error
@logger.debug("DNS: resolve action timed out")
return
@@ -84,15 +87,18 @@ def filter(event)
if @reverse
begin
status = Timeout::timeout(@timeout) {
- reverse(event)
+ reverse(new_event)
}
+ return if status.nil?
rescue Timeout::Error
@logger.debug("DNS: reverse action timed out")
return
end
end
- filter_matched(event)
+ filter_matched(new_event)
+ yield new_event
+ event.cancel
end
private