logstash-filter-delta 1.0.1 → 1.1.0
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/delta.rb +17 -8
- data/logstash-filter-delta.gemspec +1 -1
- data/spec/filters/delta_spec.rb +22 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1f5e44d2824a950b7d381a2769b3b4d71be155ca
|
4
|
+
data.tar.gz: 8ee30261a9d8bdbb3765dc2a10a62fd7fb3182fc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1a3a5bd6139c7bcd1984abab12940762edfe319be5149c83ab2e291c856d0bce68ad1cb9ce2f70d3b6cb151ebd90917929b79575da5679f7d560ee3f74391064
|
7
|
+
data.tar.gz: b11c7cdb422e50d24566b6f06137fdce5b5f63267d9dc6269fd31acb9c4e1a8bbee24a864b69b320dba1e580ee71bd605bc4cb2e9e85ff9fbbab2ae55a3cc989
|
data/CHANGELOG.md
CHANGED
@@ -33,8 +33,20 @@ class LogStash::Filters::Delta < LogStash::Filters::Base
|
|
33
33
|
end
|
34
34
|
|
35
35
|
private
|
36
|
-
def
|
37
|
-
|
36
|
+
def cast_string_to_numeric(value)
|
37
|
+
begin
|
38
|
+
return Integer(value)
|
39
|
+
rescue ArgumentError
|
40
|
+
return Float(value)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
private
|
45
|
+
def ensure_numeric(value)
|
46
|
+
if (value.is_a? Float or value.is_a? Integer)
|
47
|
+
return value
|
48
|
+
end
|
49
|
+
return cast_string_to_numeric(value)
|
38
50
|
end
|
39
51
|
|
40
52
|
public
|
@@ -54,15 +66,12 @@ class LogStash::Filters::Delta < LogStash::Filters::Base
|
|
54
66
|
return filter_failed(event, @tag_on_failure)
|
55
67
|
end
|
56
68
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
if !is_numeric(to) or !is_numeric(from)
|
69
|
+
begin
|
70
|
+
delta = ensure_numeric(event.get(to)) - ensure_numeric(event.get(from))
|
71
|
+
rescue ArgumentError
|
61
72
|
return filter_failed(event, @tag_on_failure)
|
62
73
|
end
|
63
74
|
|
64
|
-
delta = to - from
|
65
|
-
|
66
75
|
if @min and delta < @min
|
67
76
|
return filter_failed(event, @tag_on_min_failure)
|
68
77
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'logstash-filter-delta'
|
3
|
-
s.version = '1.0
|
3
|
+
s.version = '1.1.0'
|
4
4
|
s.licenses = ['Apache License (2.0)']
|
5
5
|
s.summary = "This filter helps you to calculate integer or float delta."
|
6
6
|
s.description = "This gem is a Logstash plugin required to be installed on top of the Logstash core pipeline using `logstash-plugin install logstash-filter-delta`. This gem is not a stand-alone program"
|
data/spec/filters/delta_spec.rb
CHANGED
@@ -29,6 +29,28 @@ describe LogStash::Filters::Delta do
|
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
32
|
+
describe "Test string casting" do
|
33
|
+
sample("start" => "100", "end" => "250.5") do
|
34
|
+
expect(subject.get("output")).to eq(150.5)
|
35
|
+
expect(subject.get("tags")).to eq(nil)
|
36
|
+
end
|
37
|
+
|
38
|
+
sample("start" => "100.3", "end" => "250.5") do
|
39
|
+
expect(subject.get("output")).to eq(150.2)
|
40
|
+
expect(subject.get("tags")).to eq(nil)
|
41
|
+
end
|
42
|
+
|
43
|
+
sample("start" => "100", "end" => "250") do
|
44
|
+
expect(subject.get("output")).to eq(150)
|
45
|
+
expect(subject.get("tags")).to eq(nil)
|
46
|
+
end
|
47
|
+
|
48
|
+
sample("start" => "abc", "end" => "250") do
|
49
|
+
expect(subject.get("output")).to eq(nil)
|
50
|
+
expect(subject.get("tags")).to eq(["_deltafailure"])
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
32
54
|
describe "Write delta to field" do
|
33
55
|
sample("start" => 100, "end" => 250) do
|
34
56
|
expect(subject.get("output")).to eq(150)
|