logstash-filter-throttle-prop 0.1.0

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 1de866a8a0676952e1ae664db261ae6a2ae830fe
4
+ data.tar.gz: 760ed358226f05c5b7ae5e2d96513dabfc12992c
5
+ SHA512:
6
+ metadata.gz: 961256d37c2b2b6e9deb5c330bdc1a4861ac6cb3d6efb64593de7e835a5fb4f63022a1499ea89ed0e4d0bf8a74ab69f11ca757dbb1eea5ef2f47d1a67f5d2f53
7
+ data.tar.gz: 6d9e0dc7cb4a113084f1049ee64c2563a455bf02503c53a849e870b5918a41190ad43d0f80d4a86e8d1d252c015a674293ba54876f1e209748f13f5e60839fae
@@ -0,0 +1,2 @@
1
+ ## 0.1.0
2
+ - Plugin created with the logstash plugin generator
@@ -0,0 +1,10 @@
1
+ The following is a list of people who have contributed ideas, code, bug
2
+ reports, or in general have helped logstash along its way.
3
+
4
+ Contributors:
5
+ * your_username - your_username@example.com
6
+
7
+ Note: If you've sent us patches, bug reports, or otherwise contributed to
8
+ Logstash, and you aren't on the list above and want to be, please let us know
9
+ and we'll make sure you're here. Contributions from folks like you are what make
10
+ open source awesome.
@@ -0,0 +1,2 @@
1
+ # logstash-filter-throttle-prop
2
+ Example filter plugin. This should help bootstrap your effort to write your own filter plugin!
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
3
+
data/LICENSE ADDED
@@ -0,0 +1,11 @@
1
+ Licensed under the Apache License, Version 2.0 (the "License");
2
+ you may not use this file except in compliance with the License.
3
+ You may obtain a copy of the License at
4
+
5
+ http://www.apache.org/licenses/LICENSE-2.0
6
+
7
+ Unless required by applicable law or agreed to in writing, software
8
+ distributed under the License is distributed on an "AS IS" BASIS,
9
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10
+ See the License for the specific language governing permissions and
11
+ limitations under the License.
@@ -0,0 +1,69 @@
1
+ # Logstash Filter Throttle Prop
2
+
3
+ This is a plugin for [Logstash](https://github.com/elastic/logstash).
4
+
5
+ It is fully free and fully open source. The license is Apache 2.0, meaning you are pretty much free to use it however you want in whatever way.
6
+
7
+ The throttle-prop-filter is to throttle events per a dynamic property. The filter is configured with a key, a value and a limit. The key is used to group the values. If the values with a different content are inserted more than limit, it will be filtered.
8
+
9
+
10
+ ## How to install
11
+
12
+ ```sh
13
+ bin/logstash-plugin install logstash-filter-throttle-prop
14
+ ```
15
+
16
+ ## Hou to use
17
+
18
+ For example, if you wanted to throttle events per a property "type",
19
+ and you didn't want to have more than two differents types,
20
+ you would use the configuration:
21
+
22
+ ```ruby
23
+ filter {
24
+ throttle_prop {
25
+ key => "fixed_key"
26
+ value => "%{type}"
27
+ limit => 2
28
+ add_tag => [ "throttled" ]
29
+ }
30
+ }
31
+ ```
32
+
33
+ ##### Which would result in:
34
+ - event 1 { type => 'a' } - not throttled
35
+ - event 2 { type => 'a' } - not throttled
36
+ - event 3 { type => 'b' } - not throttled
37
+ - event 4 { type => 'b' } - not throttled
38
+ - event 5 { type => 'c' } - throttled (successful filter)
39
+ - event 6 { type => 'c' } - throttled (successful filter)
40
+ - event 7 { type => 'a' } - not throttled
41
+ - event 8 { type => 'b' } - not throttled
42
+ - event 9 { type => 'c' } - throttled (successful filter)
43
+ - event 10 { type => 'd' } - throttled (successful filter)
44
+
45
+ ## Developing
46
+
47
+ ### 1. Plugin Developement and Testing
48
+
49
+ #### Code
50
+ - To get started, you'll need JRuby with the Bundler gem installed.
51
+
52
+ - Install dependencies
53
+ ```sh
54
+ bundle install
55
+ ```
56
+
57
+ #### Test
58
+
59
+ - Update your dependencies
60
+
61
+ ```sh
62
+ bundle install
63
+ ```
64
+
65
+ - Run tests
66
+
67
+ ```sh
68
+ bundle exec rspec
69
+ ```
@@ -0,0 +1,68 @@
1
+ # encoding: utf-8
2
+ require "logstash/filters/base"
3
+ require "logstash/namespace"
4
+
5
+ # The throttle-prop-filter is to throttle events per a dynamic property.
6
+ # The filter is configured with a key, a value and a limit.
7
+ # The key is used to group the values.
8
+ # If the values with a different content are be inserted more
9
+ # than limit, it will be filtered
10
+ #
11
+ #
12
+ # For example, if you wanted to throttle events per a property "type",
13
+ # and you didn't want to have more than two differents types,
14
+ # you would use the configuration:
15
+ #
16
+ # [source, ruby]
17
+ # key => "fixed_key"
18
+ # value => "%{type}"
19
+ # limit => 2
20
+ #
21
+ # Which would result in:
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)
33
+
34
+ class LogStash::Filters::ThrottleProp < LogStash::Filters::Base
35
+
36
+ config_name "throttle_prop"
37
+
38
+ config :key, :validate => :string, :required => true
39
+
40
+ config :value, :validate => :string, :required => true
41
+
42
+ config :limit, :validate => :number, :required => true
43
+
44
+ public
45
+ def register
46
+ @keys = Hash.new
47
+ end # def register
48
+
49
+ public
50
+ def filter(event)
51
+ key = event.sprintf(@key)
52
+ value = event.sprintf(@value)
53
+ limit = event.sprintf(@limit).to_i
54
+
55
+ if @keys.has_key? @key
56
+ unless @keys[@key].include? value
57
+ if @keys[@key].length + 1 > limit
58
+ filter_matched(event)
59
+ else
60
+ @keys[@key].push(value)
61
+ end
62
+ end
63
+ else
64
+ @keys[@key] = [value]
65
+ end
66
+
67
+ end # def filter
68
+ end # class LogStash::Filters::ThrottleProp
@@ -0,0 +1,23 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = 'logstash-filter-throttle-prop'
3
+ s.version = '0.1.0'
4
+ s.licenses = ['Apache License (2.0)']
5
+ s.description = 'A logstash filter plugin to throttle events per properties'
6
+ s.summary = s.description
7
+ s.homepage = 'https://github.com/JeanPinzon/logstash-filter-throttle-prop'
8
+ s.authors = ['jeanpinzon']
9
+ s.email = 'jean.pinzon1@gmail.com'
10
+ s.require_paths = ['lib']
11
+
12
+ # Files
13
+ s.files = Dir['lib/**/*','spec/**/*','vendor/**/*','*.gemspec','*.md','CONTRIBUTORS','Gemfile','LICENSE','NOTICE.TXT']
14
+ # Tests
15
+ s.test_files = s.files.grep(%r{^(test|spec|features)/})
16
+
17
+ # Special flag to let us know this is actually a logstash plugin
18
+ s.metadata = { "logstash_plugin" => "true", "logstash_group" => "filter" }
19
+
20
+ # Gem dependencies
21
+ s.add_runtime_dependency "logstash-core-plugin-api", "~> 2.0"
22
+ s.add_development_dependency 'logstash-devutils'
23
+ end
@@ -0,0 +1,94 @@
1
+ # encoding: utf-8
2
+ require_relative '../spec_helper'
3
+ require "logstash/filters/throttle_prop"
4
+
5
+ describe LogStash::Filters::ThrottleProp do
6
+
7
+ let(:config) do <<-CONFIG
8
+ filter {
9
+ throttle_prop {
10
+ key => "test"
11
+ value => "%{property}"
12
+ limit => 2
13
+ add_tag => [ "throttled" ]
14
+ }
15
+ }
16
+ CONFIG
17
+ end
18
+
19
+ describe "Throttling per property" do
20
+ events = [{
21
+ "property" => "a"
22
+ }, {
23
+ "property" => "b"
24
+ }, {
25
+ "property" => "c"
26
+ }]
27
+
28
+ 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[2].get("tags")).to eq([ "throttled" ])
33
+ end
34
+ end
35
+
36
+ describe "Don't throttling equal properties" do
37
+ events = [{
38
+ "property" => "a"
39
+ }, {
40
+ "property" => "a"
41
+ }, {
42
+ "property" => "a"
43
+ }]
44
+
45
+ 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')
49
+ expect(subject[2].get("tags")).to eq(nil)
50
+ end
51
+ end
52
+
53
+ describe "Don't throttling equal properties and throttling differents" do
54
+ events = [{
55
+ "property" => "a"
56
+ }, {
57
+ "property" => "a"
58
+ }, {
59
+ "property" => "b"
60
+ }, {
61
+ "property" => "b"
62
+ }, {
63
+ "property" => "c"
64
+ }, {
65
+ "property" => "c"
66
+ }, {
67
+ "property" => "a"
68
+ }, {
69
+ "property" => "b"
70
+ }, {
71
+ "property" => "c"
72
+ }, {
73
+ "property" => "d"
74
+ }]
75
+
76
+ 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')
83
+ expect(subject[4].get("tags")).to eq([ "throttled" ])
84
+ 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')
88
+ expect(subject[8].get("tags")).to eq([ "throttled" ])
89
+ expect(subject[9].get("property")).to eq('d')
90
+ expect(subject[9].get("tags")).to eq([ "throttled" ])
91
+ end
92
+ end
93
+
94
+ end
@@ -0,0 +1,2 @@
1
+ # encoding: utf-8
2
+ require "logstash/devutils/rspec/spec_helper"
metadata ADDED
@@ -0,0 +1,85 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: logstash-filter-throttle-prop
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - jeanpinzon
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-05-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - "~>"
17
+ - !ruby/object:Gem::Version
18
+ version: '2.0'
19
+ name: logstash-core-plugin-api
20
+ prerelease: false
21
+ type: :runtime
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ - !ruby/object:Gem::Dependency
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ name: logstash-devutils
34
+ prerelease: false
35
+ type: :development
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: A logstash filter plugin to throttle events per properties
42
+ email: jean.pinzon1@gmail.com
43
+ executables: []
44
+ extensions: []
45
+ extra_rdoc_files: []
46
+ files:
47
+ - CHANGELOG.md
48
+ - CONTRIBUTORS
49
+ - DEVELOPER.md
50
+ - Gemfile
51
+ - LICENSE
52
+ - README.md
53
+ - lib/logstash/filters/throttle_prop.rb
54
+ - logstash-filter-throttle-prop.gemspec
55
+ - spec/filters/throttle_prop_spec.rb
56
+ - spec/spec_helper.rb
57
+ homepage: https://github.com/JeanPinzon/logstash-filter-throttle-prop
58
+ licenses:
59
+ - Apache License (2.0)
60
+ metadata:
61
+ logstash_plugin: 'true'
62
+ logstash_group: filter
63
+ post_install_message:
64
+ rdoc_options: []
65
+ require_paths:
66
+ - lib
67
+ required_ruby_version: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ version: '0'
72
+ required_rubygems_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ requirements: []
78
+ rubyforge_project:
79
+ rubygems_version: 2.6.8
80
+ signing_key:
81
+ specification_version: 4
82
+ summary: A logstash filter plugin to throttle events per properties
83
+ test_files:
84
+ - spec/filters/throttle_prop_spec.rb
85
+ - spec/spec_helper.rb