logstash-filter-throttle-prop 0.1.2 → 0.1.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 45eb9268eec8e9bbd40160f0d72ef041bc3d9235
4
- data.tar.gz: 7416e52a7ab4204abbd5820f5d07d6f3938551dd
3
+ metadata.gz: 29356acbb0d2242d095bd5bbacce2145b7bd817e
4
+ data.tar.gz: 373bcaeda86e835f4c02ae0dfe04838b6596bdf3
5
5
  SHA512:
6
- metadata.gz: 480a1a875de4876c32ff91265e2f7a8266eb278c96e91a3b89bc10d4731962cd123644ed12255b2391beaa7d4069ee7876cca2893cd4302aed64698f043ab6dd
7
- data.tar.gz: ca7d3c51eef613020c117fbfa2cb936ae19b3eed8b3057e3ad6b0f75f47532a7785dbfacb1da34ad75ce58bfa5196ea3156f4cae65a6e6c169c31acdef24bd87
6
+ metadata.gz: db1c34dfa73e8c858404348ba8b0ef3b9e839ddeae6e6ff1700227bdcfc92ec9be9138a1fb8e305bd51a02ce8d75d4d47eb7ba3adbbc672bbc41b3cd3e7e44bf
7
+ data.tar.gz: 2e32b8288633c6098edf41fa6d99d8bc6870d3217017945acc8bc7c5b67fdf1ef00633e0f30366229d94b6194b5fd1bfc0489ce3b85c0b7b660c22968ac25b32
@@ -2,7 +2,7 @@ The following is a list of people who have contributed ideas, code, bug
2
2
  reports, or in general have helped logstash along its way.
3
3
 
4
4
  Contributors:
5
- * your_username - your_username@example.com
5
+ * jeanpinzon - jean.pinzon1@gmail.com
6
6
 
7
7
  Note: If you've sent us patches, bug reports, or otherwise contributed to
8
8
  Logstash, and you aren't on the list above and want to be, please let us know
@@ -14,22 +14,23 @@ require "logstash/namespace"
14
14
  # you would use the configuration:
15
15
  #
16
16
  # [source, ruby]
17
- # key => "fixed_key"
17
+ # key => "%{property_key}"
18
18
  # value => "%{type}"
19
19
  # limit => 2
20
20
  #
21
21
  # Which would result in:
22
22
  # ==========================
23
- # event 1 { type => 'a' } - not throttled
24
- # event 2 { type => 'a' } - not throttled
25
- # event 3 { type => 'b' } - not throttled
26
- # event 4 { type => 'b' } - not throttled
27
- # event 5 { type => 'c' } - throttled (successful filter)
28
- # event 6 { type => 'c' } - throttled (successful filter)
29
- # event 7 { type => 'a' } - not throttled
30
- # event 8 { type => 'b' } - not throttled
31
- # event 9 { type => 'c' } - throttled (successful filter)
32
- # event 10 { type => 'd' } - throttled (successful filter)
23
+ # event 1 { property_key => 'some_key', type => 'a' } - not throttled
24
+ # event 2 { property_key => 'some_key', type => 'a' } - not throttled
25
+ # event 3 { property_key => 'some_key', type => 'b' } - not throttled
26
+ # event 4 { property_key => 'some_key', type => 'b' } - not throttled
27
+ # event 5 { property_key => 'some_key', type => 'c' } - throttled (successful filter)
28
+ # event 6 { property_key => 'some_key', type => 'c' } - throttled (successful filter)
29
+ # event 7 { property_key => 'some_key', type => 'a' } - not throttled
30
+ # event 8 { property_key => 'some_key', type => 'b' } - not throttled
31
+ # event 9 { property_key => 'some_key', type => 'c' } - throttled (successful filter)
32
+ # event 10 { property_key => 'some_key', type => 'd' } - throttled (successful filter)
33
+ # event 11 { property_key => 'other_key', type => 'd' } - not throttled
33
34
 
34
35
  class LogStash::Filters::ThrottleProp < LogStash::Filters::Base
35
36
 
@@ -48,20 +49,20 @@ class LogStash::Filters::ThrottleProp < LogStash::Filters::Base
48
49
 
49
50
  public
50
51
  def filter(event)
51
- key = event.sprintf(@key)
52
- value = event.sprintf(@value)
53
- limit = event.sprintf(@limit).to_i
52
+ event_key = event.sprintf(@key)
53
+ event_value = event.sprintf(@value)
54
+ event_limit = event.sprintf(@limit).to_i
54
55
 
55
- if @keys.has_key? @key
56
- unless @keys[@key].include? value
57
- if @keys[@key].length + 1 > limit
56
+ if @keys.has_key? event_key
57
+ unless @keys[event_key].include? event_value
58
+ if @keys[event_key].length + 1 > event_limit
58
59
  filter_matched(event)
59
60
  else
60
- @keys[@key].push(value)
61
+ @keys[event_key].push(event_value)
61
62
  end
62
63
  end
63
64
  else
64
- @keys[@key] = [value]
65
+ @keys[event_key] = [event_value]
65
66
  end
66
67
 
67
68
  end # def filter
@@ -1,9 +1,9 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'logstash-filter-throttle-prop'
3
- s.version = '0.1.2'
3
+ s.version = '0.1.3'
4
4
  s.licenses = ['Apache License (2.0)']
5
5
  s.description = 'A logstash filter plugin to throttle events per properties'
6
- s.summary = 'Filter to throttle events per properties'
6
+ s.summary = s.description
7
7
  s.homepage = 'https://github.com/JeanPinzon/logstash-filter-throttle-prop'
8
8
  s.authors = ['jeanpinzon']
9
9
  s.email = 'jean.pinzon1@gmail.com'
@@ -7,8 +7,8 @@ describe LogStash::Filters::ThrottleProp do
7
7
  let(:config) do <<-CONFIG
8
8
  filter {
9
9
  throttle_prop {
10
- key => "test"
11
- value => "%{property}"
10
+ key => "%{property_key}"
11
+ value => "%{property_value}"
12
12
  limit => 2
13
13
  add_tag => [ "throttled" ]
14
14
  }
@@ -18,76 +18,113 @@ describe LogStash::Filters::ThrottleProp do
18
18
 
19
19
  describe "Throttling per property" do
20
20
  events = [{
21
- "property" => "a"
21
+ "property_key" => "some_key",
22
+ "property_value" => "a"
22
23
  }, {
23
- "property" => "b"
24
+ "property_key" => "some_key",
25
+ "property_value" => "b"
24
26
  }, {
25
- "property" => "c"
27
+ "property_key" => "some_key",
28
+ "property_value" => "c"
26
29
  }]
27
30
 
28
31
  sample events do
29
- expect(subject[0].get("property")).to eq('a')
30
- expect(subject[1].get("property")).to eq('b')
31
- expect(subject[2].get("property")).to eq('c')
32
+ expect(subject[0].get("property_value")).to eq('a')
33
+ expect(subject[1].get("property_value")).to eq('b')
34
+ expect(subject[2].get("property_value")).to eq('c')
32
35
  expect(subject[2].get("tags")).to eq([ "throttled" ])
33
36
  end
34
37
  end
35
38
 
36
39
  describe "Don't throttling equal properties" do
37
40
  events = [{
38
- "property" => "a"
41
+ "property_key" => "some_key",
42
+ "property_value" => "a"
39
43
  }, {
40
- "property" => "a"
44
+ "property_key" => "some_key",
45
+ "property_value" => "a"
41
46
  }, {
42
- "property" => "a"
47
+ "property_key" => "some_key",
48
+ "property_value" => "a"
43
49
  }]
44
50
 
45
51
  sample events do
46
- expect(subject[0].get("property")).to eq('a')
47
- expect(subject[1].get("property")).to eq('a')
48
- expect(subject[2].get("property")).to eq('a')
52
+ expect(subject[0].get("property_value")).to eq('a')
53
+ expect(subject[1].get("property_value")).to eq('a')
54
+ expect(subject[2].get("property_value")).to eq('a')
49
55
  expect(subject[2].get("tags")).to eq(nil)
50
56
  end
51
57
  end
52
58
 
53
59
  describe "Don't throttling equal properties and throttling differents" do
54
60
  events = [{
55
- "property" => "a"
61
+ "property_key" => "some_key",
62
+ "property_value" => "a"
56
63
  }, {
57
- "property" => "a"
64
+ "property_key" => "some_key",
65
+ "property_value" => "a"
58
66
  }, {
59
- "property" => "b"
67
+ "property_key" => "some_key",
68
+ "property_value" => "b"
60
69
  }, {
61
- "property" => "b"
70
+ "property_key" => "some_key",
71
+ "property_value" => "b"
62
72
  }, {
63
- "property" => "c"
73
+ "property_key" => "some_key",
74
+ "property_value" => "c"
64
75
  }, {
65
- "property" => "c"
76
+ "property_key" => "some_key",
77
+ "property_value" => "c"
66
78
  }, {
67
- "property" => "a"
79
+ "property_key" => "some_key",
80
+ "property_value" => "a"
68
81
  }, {
69
- "property" => "b"
82
+ "property_key" => "some_key",
83
+ "property_value" => "b"
70
84
  }, {
71
- "property" => "c"
85
+ "property_key" => "some_key",
86
+ "property_value" => "c"
72
87
  }, {
73
- "property" => "d"
88
+ "property_key" => "some_key",
89
+ "property_value" => "d"
90
+ }, {
91
+ "property_key" => "other_key",
92
+ "property_value" => "d"
74
93
  }]
75
94
 
76
95
  sample events do
77
- expect(subject[0].get("property")).to eq('a')
78
- expect(subject[1].get("property")).to eq('a')
79
- expect(subject[2].get("property")).to eq('b')
80
- expect(subject[3].get("property")).to eq('b')
81
- expect(subject[4].get("property")).to eq('c')
82
- expect(subject[5].get("property")).to eq('c')
96
+ expect(subject[0].get("property_value")).to eq('a')
97
+ expect(subject[0].get("tags")).to eq(nil)
98
+
99
+ expect(subject[1].get("property_value")).to eq('a')
100
+ expect(subject[1].get("tags")).to eq(nil)
101
+
102
+ expect(subject[2].get("property_value")).to eq('b')
103
+ expect(subject[2].get("tags")).to eq(nil)
104
+
105
+ expect(subject[3].get("property_value")).to eq('b')
106
+ expect(subject[3].get("tags")).to eq(nil)
107
+
108
+ expect(subject[4].get("property_value")).to eq('c')
83
109
  expect(subject[4].get("tags")).to eq([ "throttled" ])
110
+
111
+ expect(subject[5].get("property_value")).to eq('c')
84
112
  expect(subject[5].get("tags")).to eq([ "throttled" ])
85
- expect(subject[6].get("property")).to eq('a')
86
- expect(subject[7].get("property")).to eq('b')
87
- expect(subject[8].get("property")).to eq('c')
113
+
114
+ expect(subject[6].get("property_value")).to eq('a')
115
+ expect(subject[6].get("tags")).to eq(nil)
116
+
117
+ expect(subject[7].get("property_value")).to eq('b')
118
+ expect(subject[7].get("tags")).to eq(nil)
119
+
120
+ expect(subject[8].get("property_value")).to eq('c')
88
121
  expect(subject[8].get("tags")).to eq([ "throttled" ])
89
- expect(subject[9].get("property")).to eq('d')
122
+
123
+ expect(subject[9].get("property_value")).to eq('d')
90
124
  expect(subject[9].get("tags")).to eq([ "throttled" ])
125
+
126
+ expect(subject[10].get("property_value")).to eq('d')
127
+ expect(subject[10].get("tags")).to eq(nil)
91
128
  end
92
129
  end
93
130
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logstash-filter-throttle-prop
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - jeanpinzon
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-05-11 00:00:00.000000000 Z
11
+ date: 2017-05-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  requirement: !ruby/object:Gem::Requirement
@@ -79,7 +79,7 @@ rubyforge_project:
79
79
  rubygems_version: 2.6.8
80
80
  signing_key:
81
81
  specification_version: 4
82
- summary: Filter to throttle events per properties
82
+ summary: A logstash filter plugin to throttle events per properties
83
83
  test_files:
84
84
  - spec/filters/throttle_prop_spec.rb
85
85
  - spec/spec_helper.rb