fluent-plugin-conditional_filter 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cab6711bb735bb3f4cdba2f091567ce6d432645d
4
- data.tar.gz: 85e70261a231649cc302071c8a49459df4712432
3
+ metadata.gz: da5d5a07de7eecf356626bd2cf0bdd88c300f39e
4
+ data.tar.gz: 8ad55890d05c1e1ecc37264d2003c9d139968318
5
5
  SHA512:
6
- metadata.gz: ad91077d850402e1d1a5c373920d92218459b7607a999a382d521e5bfa259b7f8c9c696def3f849daa415b413d6b16483eab9deb8da95a3339b90f8bb8e9f5cd
7
- data.tar.gz: d29859f4d660c79ed199c5cecc071a5123e692057c2646250020ed827a4bf32d5a1efaaead58b44fa3429071de5be25bf883086242fbf47f1f7e8e386ed9501f
6
+ metadata.gz: 4002c8649cb44d8a05f1219483c9998cff8d3158e489c58769f7b31b2e8f698dd292ec30c81ba8e610e3f14282762bb5cc298d17a72dfddba1ddb6313457dda0
7
+ data.tar.gz: 785a93b79ba285fd2c948c2d0456cf83ddd8cb8c38f3d1080c4d927605399ed353dfc764cbbbd1e8f975ab56f54eaf77bf99181639779ff1757dbc9e3c983451
data/README.md CHANGED
@@ -1,10 +1,10 @@
1
- # Fluent::Plugin::ConditionalFilter [![BuildStatus](https://secure.travis-ci.org/kentaro/fluent-plugin-conditional_filter)](http://travis-ci.org/kentaro/fluent-plugin-conditional_filter)
1
+ # Fluent::Plugin::ConditionalFilter [![BuildStatus](https://secure.travis-ci.org/kentaro/fluent-plugin-conditional_filter.png)](http://travis-ci.org/kentaro/fluent-plugin-conditional_filter)
2
2
 
3
3
  ## Component
4
4
 
5
5
  ### ConditionalFilterOutput
6
6
 
7
- fluent-plugin-conditional_filter provides a simple filter that filters out key/value pairs that don't match a condition.
7
+ fluent-plugin-conditional_filter provides a simple filter that filters out key/value pairs that don't satisfy a given condition.
8
8
 
9
9
  ## Usage
10
10
 
@@ -12,9 +12,10 @@ fluent-plugin-conditional_filter provides a simple filter that filters out key/v
12
12
 
13
13
  ```
14
14
  <match test.**>
15
- key_pattern @example.com$
16
- condition 10
17
- filter numeric_upward
15
+ add_tag_prefix filtered.
16
+ key_pattern @example\.com$
17
+ condition 10
18
+ filter numeric_upward
18
19
  </match>
19
20
  ```
20
21
 
@@ -24,7 +25,7 @@ fluent-plugin-conditional_filter provides a simple filter that filters out key/v
24
25
 
25
26
  Key pattern to check.
26
27
 
27
- #### `condition` (optional: default = 'http')
28
+ #### `condition` (required)
28
29
 
29
30
  Condition for the filter below.
30
31
 
@@ -36,6 +37,20 @@ Set filtering strategy.
36
37
 
37
38
  You can also use the params above inherited from [Fluent::HandleTagNameMixin](https://github.com/fluent/fluentd/blob/master/lib/fluent/mixin.rb).
38
39
 
40
+ ### Filters
41
+
42
+ #### numeric_upward
43
+
44
+ Filter out such key/value pairs whose value aren't greater than or equal to the given value as float value.
45
+
46
+ #### numeric_downward
47
+
48
+ Filter out such key/value pairs whose value aren't smaller than or equal to the given value as float value
49
+
50
+ #### string_match
51
+
52
+ Filter out such key/value pairs whose value don't match the given value as string.
53
+
39
54
  ## Installation
40
55
 
41
56
  Add this line to your application's Gemfile:
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = 'fluent-plugin-conditional_filter'
7
- spec.version = '0.0.1'
7
+ spec.version = '0.0.2'
8
8
  spec.authors = ['Kentaro Kuribayashi']
9
9
  spec.email = ['kentarok@gmail.com']
10
10
  spec.description = %q{A fluent plugin that provides conditional filters}
@@ -17,7 +17,7 @@ class Fluent::ConditionalFilterOutput < Fluent::Output
17
17
  )
18
18
  end
19
19
 
20
- @key_pattern_regexp = /#{key_pattern}/
20
+ @key_pattern_regexp = Regexp.new(key_pattern)
21
21
  end
22
22
 
23
23
  def emit(tag, es, chain)
@@ -40,7 +40,17 @@ class Fluent::ConditionalFilterOutput < Fluent::Output
40
40
  when 'numeric_upward'
41
41
  filter_record = record.select do |key, value|
42
42
  key.match(@key_pattern_regexp) &&
43
- record[key].to_f >= condition.to_f
43
+ record[key].to_f >= condition.to_f
44
+ end
45
+ when 'numeric_downward'
46
+ filter_record = record.select do |key, value|
47
+ key.match(@key_pattern_regexp) &&
48
+ record[key].to_f <= condition.to_f
49
+ end
50
+ when 'string_match'
51
+ filter_record = record.select do |key, value|
52
+ key.match(@key_pattern_regexp) &&
53
+ record[key].match(Regexp.new(condition))
44
54
  end
45
55
  else
46
56
  raise ArgumentError.new("[out_conditional_filter] no such filter: #{filter}")
@@ -6,7 +6,7 @@ describe Fluent::ConditionalFilterOutput do
6
6
  context "success" do
7
7
  let(:conf) {
8
8
  %[
9
- key_pattern @example.com$
9
+ key_pattern @example\.com$
10
10
  condition 10
11
11
  filter numeric_upward
12
12
  ]
@@ -19,7 +19,7 @@ describe Fluent::ConditionalFilterOutput do
19
19
 
20
20
  it {
21
21
  expect(subject).to be_an_instance_of described_class
22
- expect(subject.key_pattern).to be == '@example.com$'
22
+ expect(subject.key_pattern).to be == "@example\.com$"
23
23
  expect(subject.instance_variable_get(:@key_pattern_regexp)).to be == /@example.com$/
24
24
  }
25
25
  end
@@ -123,6 +123,108 @@ describe Fluent::ConditionalFilterOutput do
123
123
  }
124
124
  end
125
125
  end
126
+
127
+ context('numeric_downward') do
128
+ let(:conf) {
129
+ %[
130
+ key_pattern @example.com$
131
+ condition 10
132
+ filter numeric_downward
133
+ ]
134
+ }
135
+
136
+ let(:driver) { Fluent::Test::OutputTestDriver.new(described_class, 'test').configure(conf) }
137
+ subject {
138
+ driver.instance
139
+ }
140
+
141
+ context('with 0 matched key/value pair') do
142
+ before {
143
+ driver.run {
144
+ driver.emit('foo@example.com' => 18, 'bar@example.com' => 26, 'baz@baz.com' => 15)
145
+ }
146
+ }
147
+
148
+ it {
149
+ expect(driver.emits[0]).to be_nil
150
+ }
151
+ end
152
+
153
+ context('with 1 matched key/value pair') do
154
+ before {
155
+ driver.run {
156
+ driver.emit('foo@example.com' => 11, 'bar@example.com' => 6, 'baz@baz.com' => 5)
157
+ }
158
+ }
159
+
160
+ it {
161
+ expect(driver.emits[0][2].keys.length).to be == 1
162
+ }
163
+ end
164
+
165
+ context('with 2 matched key/value pairs') do
166
+ before {
167
+ driver.run {
168
+ driver.emit('foo@example.com' => 10, 'bar@example.com' => 5, 'baz@baz.com' => 5)
169
+ }
170
+ }
171
+
172
+ it {
173
+ expect(driver.emits[0][2].keys.length).to be == 2
174
+ }
175
+ end
176
+ end
177
+
178
+ context('string_match') do
179
+ let(:conf) {
180
+ %[
181
+ key_pattern @example.com$
182
+ condition (staff|user)
183
+ filter string_match
184
+ ]
185
+ }
186
+
187
+ let(:driver) { Fluent::Test::OutputTestDriver.new(described_class, 'test').configure(conf) }
188
+ subject {
189
+ driver.instance
190
+ }
191
+
192
+ context('with 0 matched key/value pair') do
193
+ before {
194
+ driver.run {
195
+ driver.emit('foo@example.com' => 'guest', 'bar@example.com' => 'guest', 'baz@baz.com' => 'staff')
196
+ }
197
+ }
198
+
199
+ it {
200
+ expect(driver.emits[0]).to be_nil
201
+ }
202
+ end
203
+
204
+ context('with 1 matched key/value pair') do
205
+ before {
206
+ driver.run {
207
+ driver.emit('foo@example.com' => 'staff', 'bar@example.com' => 'guest', 'baz@baz.com' => 'user')
208
+ }
209
+ }
210
+
211
+ it {
212
+ expect(driver.emits[0][2].keys.length).to be == 1
213
+ }
214
+ end
215
+
216
+ context('with 2 matched key/value pairs') do
217
+ before {
218
+ driver.run {
219
+ driver.emit('foo@example.com' => 'staff', 'bar@example.com' => 'user', 'baz@baz.com' => 'staff')
220
+ }
221
+ }
222
+
223
+ it {
224
+ expect(driver.emits[0][2].keys.length).to be == 2
225
+ }
226
+ end
227
+ end
126
228
  end
127
229
  end
128
230
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-conditional_filter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kentaro Kuribayashi