fluent-mixin-rewrite-tag-name 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
5
+ vendor/*
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ language: ruby
2
+
3
+ rvm:
4
+ - 2.1.0
5
+ - 2.0.0
6
+ - 1.9.3
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in fluent-mixin-rewrite-tag-name.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,14 @@
1
+ Copyright (c) 2014- Kentaro Yoshida
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+
7
+ http://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ Unless required by applicable law or agreed to in writing, software
10
+ distributed under the License is distributed on an "AS IS" BASIS,
11
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ See the License for the specific language governing permissions and
13
+ limitations under the License.
14
+
data/README.md ADDED
@@ -0,0 +1,23 @@
1
+ ## Fluent::Mixin::RewriteTagName [![Build Status](https://travis-ci.org/y-ken/fluent-mixin-rewrite-tag-name.png?branch=master)](https://travis-ci.org/y-ken/fluent-mixin-rewrite-tag-name)
2
+
3
+ ## Overview
4
+
5
+ Fluentd mixin plugin to rewrite tag like [rewrite-tag-filter](https://github.com/fluent/fluent-plugin-rewrite-tag-filter) for your any plugins.
6
+
7
+ ## Usage
8
+
9
+ TODO
10
+
11
+ ## TODO
12
+
13
+ * merge into [fluentd/lib/fluent/mixin.rb](https://github.com/fluent/fluentd/blob/master/lib/fluent/mixin.rb) as RewriteTagNameMixin module.
14
+
15
+ Pull requests are very welcome!!
16
+
17
+ ## Copyright
18
+
19
+ Copyright © 2014- Kentaro Yoshida ([@yoshi_ken](https://twitter.com/yoshi_ken))
20
+
21
+ ## License
22
+
23
+ Apache License, Version 2.0
data/Rakefile ADDED
@@ -0,0 +1,9 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+ Rake::TestTask.new(:test) do |test|
4
+ test.libs << 'lib' << 'test'
5
+ test.pattern = 'test/**/test_*.rb'
6
+ test.verbose = true
7
+ end
8
+
9
+ task :default => :test
@@ -0,0 +1,22 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "fluent-mixin-rewrite-tag-name"
7
+ spec.version = "0.0.1"
8
+ spec.authors = ["Kentaro Yoshida"]
9
+ spec.email = ["y.ken.studio@gmail.com"]
10
+ spec.summary = %q{Fluentd mixin plugin to rewrite tag like rewrite-tag-filter for your any plugins.}
11
+ spec.homepage = "https://github.com/y-ken/fluent-mixin-rewrite-tag-name"
12
+ spec.license = "Apache License, Version 2.0"
13
+
14
+ spec.files = `git ls-files`.split($/)
15
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
16
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
17
+ spec.require_paths = ["lib"]
18
+
19
+ spec.add_development_dependency "bundler"
20
+ spec.add_development_dependency "rake"
21
+ spec.add_runtime_dependency "fluentd"
22
+ end
@@ -0,0 +1,27 @@
1
+ module Fluent
2
+ module Mixin
3
+ module RewriteTagName
4
+ include RecordFilterMixin
5
+ attr_accessor :tag
6
+
7
+ def filter_record(tag, time, record)
8
+ super
9
+ if @tag
10
+ rewrite_tag!(tag)
11
+ end
12
+ end
13
+
14
+ def rewrite_tag!(tag)
15
+ placeholder = {
16
+ '${tag}' => tag,
17
+ '__TAG__' => tag
18
+ }
19
+ emit_tag = @tag.gsub(/(\${[a-z_]+(\[[0-9]+\])?}|__[A-Z_]+__)/) do
20
+ $log.warn "RewriteTagNameMixin: unknown placeholder found. :placeholder=>#{$1} :tag=>#{tag} :rewritetag=>#{rewritetag}" unless placeholder.include?($1)
21
+ placeholder[$1]
22
+ end
23
+ tag.gsub!(tag, emit_tag)
24
+ end
25
+ end
26
+ end
27
+ end
data/test/helper.rb ADDED
@@ -0,0 +1,30 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'test/unit'
11
+
12
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
13
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
14
+
15
+ require 'fluent/test'
16
+ unless ENV.has_key?('VERBOSE')
17
+ nulllogger = Object.new
18
+ nulllogger.instance_eval {|obj|
19
+ def method_missing(method, *args)
20
+ # pass
21
+ end
22
+ }
23
+ $log = nulllogger
24
+ end
25
+
26
+ require 'fluent/mixin/rewrite_tag_name'
27
+ require_relative 'plugin'
28
+
29
+ class Test::Unit::TestCase
30
+ end
@@ -0,0 +1,54 @@
1
+ require 'helper'
2
+
3
+ class RewriteTagNameMixinTest < Test::Unit::TestCase
4
+ def setup
5
+ Fluent::Test.setup
6
+ end
7
+
8
+ CONFIG = %[
9
+ tag rewrited.${tag}
10
+ ]
11
+
12
+ def create_driver(conf=CONFIG,tag='test')
13
+ Fluent::Test::OutputTestDriver.new(Fluent::RewriteTagNameMixinOutput, tag).configure(conf)
14
+ end
15
+
16
+ def test_configure
17
+ assert_raise(Fluent::ConfigError) {
18
+ d = create_driver('')
19
+ }
20
+ assert_raise(Fluent::ConfigError) {
21
+ d = create_driver('unknown_keys')
22
+ }
23
+ d = create_driver(CONFIG)
24
+ puts d.instance.inspect
25
+ assert_equal 'rewrited.${tag}', d.instance.config['tag']
26
+ end
27
+
28
+ def test_emit
29
+ d1 = create_driver(CONFIG, 'input.access')
30
+ d1.run do
31
+ d1.emit({'message' => 'foo'})
32
+ end
33
+ emits = d1.emits
34
+ assert_equal 1, emits.length
35
+ p emits[0]
36
+ assert_equal 'rewrited.input.access', emits[0][0] # tag
37
+ assert_equal 'foo', emits[0][2]['message']
38
+ end
39
+
40
+ def test_emit_with_HandleTagNameMixin
41
+ d1 = create_driver(%[
42
+ tag rewrited.${tag}
43
+ remove_tag_prefix input.
44
+ ], 'input.access')
45
+ d1.run do
46
+ d1.emit({'message' => 'foo'})
47
+ end
48
+ emits = d1.emits
49
+ assert_equal 1, emits.length
50
+ p emits[0]
51
+ assert_equal 'rewrited.access', emits[0][0] # tag
52
+ assert_equal 'foo', emits[0][2]['message']
53
+ end
54
+ end
data/test/plugin.rb ADDED
@@ -0,0 +1,26 @@
1
+ class Fluent::RewriteTagNameMixinOutput < Fluent::Output
2
+ Fluent::Plugin.register_output('rewrite_tag_name_mixin', self)
3
+
4
+ config_param :tag, :string, :default => nil
5
+
6
+ include Fluent::HandleTagNameMixin
7
+ include Fluent::Mixin::RewriteTagName
8
+
9
+ def configure(conf)
10
+ super
11
+
12
+ if @tag.nil?
13
+ raise Fluent::ConfigError, "'tag' parameter is required."
14
+ end
15
+
16
+ end
17
+
18
+ def emit(tag, es, chain)
19
+ es.each do |time, record|
20
+ emit_tag = tag.dup
21
+ filter_record(emit_tag, time, record)
22
+ Fluent::Engine.emit(emit_tag, time, record)
23
+ end
24
+ chain.next
25
+ end
26
+ end
metadata ADDED
@@ -0,0 +1,109 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fluent-mixin-rewrite-tag-name
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Kentaro Yoshida
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2014-01-20 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: fluentd
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ description:
63
+ email:
64
+ - y.ken.studio@gmail.com
65
+ executables: []
66
+ extensions: []
67
+ extra_rdoc_files: []
68
+ files:
69
+ - .gitignore
70
+ - .travis.yml
71
+ - Gemfile
72
+ - LICENSE
73
+ - README.md
74
+ - Rakefile
75
+ - fluent-mixin-rewrite-tag-name.gemspec
76
+ - lib/fluent/mixin/rewrite_tag_name.rb
77
+ - test/helper.rb
78
+ - test/mixin/test_rewrite_tag_name.rb
79
+ - test/plugin.rb
80
+ homepage: https://github.com/y-ken/fluent-mixin-rewrite-tag-name
81
+ licenses:
82
+ - Apache License, Version 2.0
83
+ post_install_message:
84
+ rdoc_options: []
85
+ require_paths:
86
+ - lib
87
+ required_ruby_version: !ruby/object:Gem::Requirement
88
+ none: false
89
+ requirements:
90
+ - - ! '>='
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ required_rubygems_version: !ruby/object:Gem::Requirement
94
+ none: false
95
+ requirements:
96
+ - - ! '>='
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ requirements: []
100
+ rubyforge_project:
101
+ rubygems_version: 1.8.23
102
+ signing_key:
103
+ specification_version: 3
104
+ summary: Fluentd mixin plugin to rewrite tag like rewrite-tag-filter for your any
105
+ plugins.
106
+ test_files:
107
+ - test/helper.rb
108
+ - test/mixin/test_rewrite_tag_name.rb
109
+ - test/plugin.rb