fluent-plugin-route 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,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in fluent-plugin-route.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 TAGOMORI Satoshi
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,29 @@
1
+ # Fluent::Plugin::Route
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'fluent-plugin-route'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install fluent-plugin-route
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
@@ -0,0 +1,15 @@
1
+ # -*- encoding: utf-8 -*-
2
+ Gem::Specification.new do |gem|
3
+ gem.name = "fluent-plugin-route"
4
+ gem.version = "0.1.0"
5
+ gem.authors = ["TAGOMORI Satoshi", "FURUHASHI Sadayuki"]
6
+ gem.email = ["tagomoris@gmail.com", "frsyuki@gmail.com"]
7
+ gem.summary = %q{Fluentd plugin to route messages in fluentd processes}
8
+ gem.description = %q{This is copy of out_route.rb originally written by frsyuki}
9
+ gem.homepage = "https://github.com/tagomoris/fluent-plugin-route"
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.require_paths = ["lib"]
15
+ end
@@ -0,0 +1,9 @@
1
+ require "fluent-plugin-route/version"
2
+
3
+ module Fluent
4
+ module Plugin
5
+ module Route
6
+ # Your code goes here...
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,154 @@
1
+ #
2
+ # Fluent
3
+ #
4
+ # Copyright (C) 2011 FURUHASHI Sadayuki
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+ module Fluent
19
+
20
+
21
+ class RouteOutput < MultiOutput
22
+ Plugin.register_output('route', self)
23
+
24
+ class Route
25
+ include Configurable
26
+
27
+ config_param :remove_tag_prefix, :string, :default => nil
28
+ config_param :add_tag_prefix, :string, :default => nil
29
+ # TODO tag_transform regexp
30
+ attr_accessor :copy
31
+
32
+ def initialize(pattern)
33
+ super()
34
+ if !pattern || pattern.empty?
35
+ pattern = '**'
36
+ end
37
+ @pattern = MatchPattern.create(pattern)
38
+ @tag_cache = {}
39
+ end
40
+
41
+ def match?(tag)
42
+ @pattern.match(tag)
43
+ end
44
+
45
+ def configure(conf)
46
+ super
47
+ if conf['copy']
48
+ @copy = true
49
+ end
50
+ if @remove_tag_prefix
51
+ @prefix_match = /^#{Regexp.escape(@remove_tag_prefix)}\.?/
52
+ else
53
+ @prefix_match = //
54
+ end
55
+ if @add_tag_prefix
56
+ @tag_prefix = "#{@add_tag_prefix}."
57
+ else
58
+ @tag_prefix = ""
59
+ end
60
+ end
61
+
62
+ def copy?
63
+ @copy
64
+ end
65
+
66
+ def emit(tag, es)
67
+ ntag = @tag_cache[tag]
68
+ unless ntag
69
+ ntag = tag.sub(@prefix_match, @tag_prefix)
70
+ if @tag_cache.size < 1024 # TODO size limit
71
+ @tag_cache[tag] = ntag
72
+ end
73
+ end
74
+ Engine.emit_stream(ntag, es)
75
+ end
76
+ end
77
+
78
+ def initialize
79
+ super
80
+ @routes = []
81
+ @tag_cache = {}
82
+ @match_cache = {}
83
+ end
84
+
85
+ config_param :remove_tag_prefix, :string, :default => nil
86
+ config_param :add_tag_prefix, :string, :default => nil
87
+ # TODO tag_transform regexp
88
+
89
+ attr_reader :routes
90
+
91
+ def configure(conf)
92
+ super
93
+
94
+ if @remove_tag_prefix
95
+ @prefix_match = /^#{Regexp.escape(@remove_tag_prefix)}\.?/
96
+ else
97
+ @prefix_match = //
98
+ end
99
+ if @add_tag_prefix
100
+ @tag_prefix = "#{@add_tag_prefix}."
101
+ else
102
+ @tag_prefix = ""
103
+ end
104
+
105
+ conf.elements.select {|e|
106
+ e.name == 'route'
107
+ }.each {|e|
108
+ route = Route.new(e.arg)
109
+ route.configure(e)
110
+ @routes << route
111
+ }
112
+ end
113
+
114
+ def emit(tag, es, chain)
115
+ ntag, targets = @match_cache[tag]
116
+ unless targets
117
+ ntag = tag.sub(@prefix_match, @tag_prefix)
118
+ targets = []
119
+ @routes.each {|r|
120
+ if r.match?(ntag)
121
+ targets << r
122
+ break unless r.copy?
123
+ end
124
+ }
125
+ if @match_cache.size < 1024 # TODO size limit
126
+ @match_cache[tag] = [ntag, targets]
127
+ end
128
+ end
129
+
130
+ case targets.size
131
+ when 0
132
+ return
133
+ when 1
134
+ targets.first.emit(ntag, es)
135
+ chain.next
136
+ else
137
+ unless es.repeatable?
138
+ m = MultiEventStream.new
139
+ es.each {|time,record|
140
+ m.add(time, record)
141
+ }
142
+ es = m
143
+ end
144
+ targets.each {|t|
145
+ t.emit(ntag, es)
146
+ }
147
+ chain.next
148
+ end
149
+ end
150
+ end
151
+
152
+
153
+ end
154
+
metadata ADDED
@@ -0,0 +1,55 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fluent-plugin-route
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - TAGOMORI Satoshi
9
+ - FURUHASHI Sadayuki
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2013-03-07 00:00:00.000000000 Z
14
+ dependencies: []
15
+ description: This is copy of out_route.rb originally written by frsyuki
16
+ email:
17
+ - tagomoris@gmail.com
18
+ - frsyuki@gmail.com
19
+ executables: []
20
+ extensions: []
21
+ extra_rdoc_files: []
22
+ files:
23
+ - .gitignore
24
+ - Gemfile
25
+ - LICENSE
26
+ - README.md
27
+ - Rakefile
28
+ - fluent-plugin-route.gemspec
29
+ - lib/fluent-plugin-route.rb
30
+ - lib/fluent/plugin/out_route.rb
31
+ homepage: https://github.com/tagomoris/fluent-plugin-route
32
+ licenses: []
33
+ post_install_message:
34
+ rdoc_options: []
35
+ require_paths:
36
+ - lib
37
+ required_ruby_version: !ruby/object:Gem::Requirement
38
+ none: false
39
+ requirements:
40
+ - - ! '>='
41
+ - !ruby/object:Gem::Version
42
+ version: '0'
43
+ required_rubygems_version: !ruby/object:Gem::Requirement
44
+ none: false
45
+ requirements:
46
+ - - ! '>='
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ requirements: []
50
+ rubyforge_project:
51
+ rubygems_version: 1.8.21
52
+ signing_key:
53
+ specification_version: 3
54
+ summary: Fluentd plugin to route messages in fluentd processes
55
+ test_files: []