fluent-plugin-grep 0.1.1 → 0.2.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e0613931c1a98ce10f1cbbdc97a712b158b38e13
4
- data.tar.gz: 4fc868cced83edb4fe14cb0960894178c2162eca
3
+ metadata.gz: 96e41f9ac8b3207023da172df7e94f0890dda86d
4
+ data.tar.gz: 5e0d3601c87d4a5cba48dd0395947287e36285e9
5
5
  SHA512:
6
- metadata.gz: 15fc714a1b73e0628de80e8b4059db41ef990c7a0db68d0334ee00ab849c9dee3902d4ac356f6ed872ffc97cb0d9755b8c2a618fb50281d571c4512cb69ab40d
7
- data.tar.gz: 5d926b83217838e8aa06894618b4871992573c763ee33b3e9f1cddd21984522900eb8b4cf42757fa65c7161fee174ae5dde70c507588e9f2b8552283dfb9daa6
6
+ metadata.gz: ec7018222ac042c04f005e9e3d294c2e32d810cd6296ddf7139b67685008546cdfcd7599e83c11a41c5cc9774f7eb7f1871a49725eccb847a5017038952a7685
7
+ data.tar.gz: 52f35e4778260dfffaf3ccc6b4d8ca09d37b5597e3a140a93c9201a175ed6b634f17ee6510bbaf4ee6951064c020ecbc81d0673c4934779601e9ddfe252b6e90
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ ## 0.2.0 (2013/11/30)
2
+
3
+ Features:
4
+
5
+ - Add `remove_tag_prefix` option
6
+
1
7
  ## 0.1.1 (2013/11/02)
2
8
 
3
9
  Changes:
data/README.md CHANGED
@@ -46,6 +46,10 @@ then output bocomes as belows (like, | grep WARN | grep -v favicon.ico):
46
46
 
47
47
  Add tag prefix for output message
48
48
 
49
+ - remove_tag_prefix
50
+
51
+ Remove tag prefix for output message
52
+
49
53
  - replace_invalid_sequence
50
54
 
51
55
  Replace invalid byte sequence in UTF-8 with '?' character if `true`
@@ -3,8 +3,8 @@ $:.push File.expand_path("../lib", __FILE__)
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "fluent-plugin-grep"
6
- s.version = "0.1.1"
7
- s.authors = ["Naotoshi SEO"]
6
+ s.version = "0.2.0"
7
+ s.authors = ["Naotoshi Seo"]
8
8
  s.email = ["sonots@gmail.com"]
9
9
  s.homepage = "https://github.com/sonots/fluent-plugin-grep"
10
10
  s.summary = "fluentd plugin to grep messages"
@@ -6,6 +6,7 @@ class Fluent::GrepOutput < Fluent::Output
6
6
  config_param :exclude, :string, :default => nil
7
7
  config_param :tag, :string, :default => nil
8
8
  config_param :add_tag_prefix, :string, :default => 'greped'
9
+ config_param :remove_tag_prefix, :string, :default => nil
9
10
  config_param :replace_invalid_sequence, :bool, :default => false
10
11
 
11
12
  def configure(conf)
@@ -14,10 +15,25 @@ class Fluent::GrepOutput < Fluent::Output
14
15
  @input_key = @input_key.to_s
15
16
  @regexp = Regexp.compile(@regexp) if @regexp
16
17
  @exclude = Regexp.compile(@exclude) if @exclude
18
+ @tag_prefix = "#{@add_tag_prefix}."
19
+ @tag_prefix_match = "#{@remove_tag_prefix}." if @remove_tag_prefix
20
+
21
+ @tag_proc =
22
+ if @tag
23
+ Proc.new {|tag| @tag }
24
+ elsif @tag_prefix and @tag_prefix_match
25
+ Proc.new {|tag| "#{@tag_prefix}#{lstrip(tag, @tag_prefix_match)}" }
26
+ elsif @tag_prefix_match
27
+ Proc.new {|tag| lstrip(tag, @tag_prefix_match) }
28
+ elsif @tag_prefix
29
+ Proc.new {|tag| "#{@tag_prefix}#{tag}" }
30
+ else
31
+ Proc.new {|tag| tag }
32
+ end
17
33
  end
18
34
 
19
35
  def emit(tag, es, chain)
20
- emit_tag = @tag ? @tag : "#{@add_tag_prefix}.#{tag}"
36
+ emit_tag = @tag_proc.call(tag)
21
37
 
22
38
  es.each do |time,record|
23
39
  value = record[@input_key]
@@ -33,17 +49,18 @@ class Fluent::GrepOutput < Fluent::Output
33
49
 
34
50
  private
35
51
 
52
+ def lstrip(string, substring)
53
+ string.index(substring) == 0 ? string[substring.size..-1] : string
54
+ end
55
+
36
56
  def match(string)
37
57
  begin
38
58
  return false if @regexp and !@regexp.match(string)
39
59
  return false if @exclude and @exclude.match(string)
40
60
  rescue ArgumentError => e
41
- unless e.message.index("invalid byte sequence in") == 0
42
- raise
43
- end
61
+ raise e unless e.message.index("invalid byte sequence in") == 0
44
62
  string = replace_invalid_byte(string)
45
- return false if @regexp and !@regexp.match(string)
46
- return false if @exclude and @exclude.match(string)
63
+ retry
47
64
  end
48
65
  return true
49
66
  end
@@ -0,0 +1,31 @@
1
+ # encoding: UTF-8
2
+ require_relative 'spec_helper'
3
+
4
+ # setup
5
+ Fluent::Test.setup
6
+ config = %[
7
+ input_key message
8
+ grep INFO
9
+ exlude something
10
+ remove_tag_prefix foo
11
+ add_tag_prefix bar
12
+ ]
13
+ time = Time.now.to_i
14
+ tag = 'foo.bar'
15
+ driver = Fluent::Test::OutputTestDriver.new(Fluent::GrepOutput, tag).configure(config)
16
+
17
+ # bench
18
+ require 'benchmark'
19
+ message = "2013/01/13T07:02:11.124202 INFO GET /ping"
20
+ n = 100000
21
+ Benchmark.bm(7) do |x|
22
+ x.report { driver.run { n.times { driver.emit({'message' => message}, time) } } }
23
+ end
24
+
25
+ # BEFORE TAG_PROC
26
+ # user system total real
27
+ # 2.560000 0.030000 2.590000 ( 3.169847)
28
+ # AFTER TAG_PROC
29
+ # user system total real
30
+ # 2.480000 0.040000 2.520000 ( 3.085798)
31
+
@@ -115,6 +115,21 @@ describe Fluent::GrepOutput do
115
115
  it { emit }
116
116
  end
117
117
 
118
+ context 'remove_tag_prefix' do
119
+ let(:config) do
120
+ CONFIG + %[
121
+ regexp ping
122
+ add_tag_prefix foo
123
+ remove_tag_prefix syslog
124
+ ]
125
+ end
126
+ before do
127
+ Fluent::Engine.stub(:now).and_return(time)
128
+ Fluent::Engine.should_receive(:emit).with("foo.host1", time, {'foo'=>'bar', 'message'=>"2013/01/13T07:02:11.124202 INFO GET /ping"})
129
+ end
130
+ it { emit }
131
+ end
132
+
118
133
  context 'replace_invalid_sequence' do
119
134
  let(:config) do
120
135
  CONFIG + %[
@@ -130,7 +145,7 @@ describe Fluent::GrepOutput do
130
145
  before do
131
146
  Fluent::Engine.stub(:now).and_return(time)
132
147
  end
133
- it { expect { emit }.not_to raise_error(ArgumentError) }
148
+ it { expect { emit }.not_to raise_error }
134
149
  end
135
150
  end
136
151
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-grep
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
- - Naotoshi SEO
7
+ - Naotoshi Seo
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-11-02 00:00:00.000000000 Z
11
+ date: 2013-11-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: fluentd
@@ -99,6 +99,7 @@ files:
99
99
  - Rakefile
100
100
  - fluent-plugin-grep.gemspec
101
101
  - lib/fluent/plugin/out_grep.rb
102
+ - spec/out_grep_bench.rb
102
103
  - spec/out_grep_spec.rb
103
104
  - spec/spec_helper.rb
104
105
  homepage: https://github.com/sonots/fluent-plugin-grep
@@ -126,5 +127,6 @@ signing_key:
126
127
  specification_version: 4
127
128
  summary: fluentd plugin to grep messages
128
129
  test_files:
130
+ - spec/out_grep_bench.rb
129
131
  - spec/out_grep_spec.rb
130
132
  - spec/spec_helper.rb