fluent-plugin-rename-key 0.1.2 → 0.1.3

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: 60e3765941b5e976e67523ec08d3339a331b3834
4
- data.tar.gz: b28f691513dde3dd285b69067caf667a31e46beb
3
+ metadata.gz: 127c0dc647c54e676bf479369cb0d83fb6a4c154
4
+ data.tar.gz: ef08017890d3968f6e704b8dde5b823a28c34a00
5
5
  SHA512:
6
- metadata.gz: fa4c5cf24eca410e42877a6d62f1f1f48fcc45ee32b49264d4c46de9cd73c540e3596eabe4b55e51e40924a36742f09167f40526cd6a5f732990b822f32c0e79
7
- data.tar.gz: a3e1c48fd89a1351a5145cc55ba1b24eca6ff507992c9fcb6c397ae73aad9e4fe5de60c65d4f2f686cca9d3b5254903f516b2839faa0c4cb646919266ac26392
6
+ metadata.gz: c0ad6f76423d9a9b9deacfa231bcd574ddde7d4be5a684f7201e3abdd86baa53968e3a9cebd4a540d504eca11acb2bca5ce15287d6be9d50428152ceb2e98a2d
7
+ data.tar.gz: b9acaecddc19f2cb21095cdd12e1f7ec6fcd77072f2586e95c3910adc31b62cd7c1b0c30a897bb476cd24e8263e18edb48255652a944433aa511fa50f0749ead
data/.gitignore CHANGED
@@ -10,3 +10,4 @@ tmtags
10
10
  .\#*
11
11
  *.swp
12
12
  tmp/*
13
+ coverage/*
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ language: ruby
2
+
3
+ rvm:
4
+ - 2.0.0
5
+ - 1.9.3
6
+ - rbx-19mode
7
+
data/README.md CHANGED
@@ -1,10 +1,15 @@
1
1
  # fluent-plugin-rename-key
2
2
 
3
+ ## Status
4
+ [![Gem Version](https://badge.fury.io/rb/fluent-plugin-rename-key.png)](http://badge.fury.io/rb/fluent-plugin-rename-key)
5
+ [![Build Status](https://travis-ci.org/shunwen/fluent-plugin-rename-key.png?branch=master)](https://travis-ci.org/shunwen/fluent-plugin-rename-key)
6
+ [![Coverage Status](https://coveralls.io/repos/shunwen/fluent-plugin-rename-key/badge.png?branch=master)](https://coveralls.io/r/shunwen/fluent-plugin-rename-key?branch=master)
7
+
3
8
  ## Overview
4
9
 
5
10
  Fluentd Output filter plugin. It goes through each record, rename keys matching the given regular expressions, and re-emit the event with a new tag. This plugin resembles the implementation of [fluent-plugin-rewrite-tag-filter](https://github.com/y-ken/fluent-plugin-rewrite-tag-filter).
6
11
 
7
- This plugin is created to resolve the invalid record problem while converting to BSON document before inserting to MongoDB, see [restrictions on Field Names](http://docs.mongodb.org/manual/reference/limits/#Restrictions on Field Names) and [MongoDB Document Types](http://docs.mongodb.org/meta-driver/latest/legacy/bson/#mongodb-document-types).
12
+ This plugin is created to resolve the invalid record problem while converting to BSON document before inserting to MongoDB, see [Restrictions on Field Names](http://docs.mongodb.org/manual/reference/limits/#Restrictions on Field Names) and [MongoDB Document Types](http://docs.mongodb.org/meta-driver/latest/legacy/bson/#mongodb-document-types).
8
13
 
9
14
  ## Installation
10
15
 
@@ -14,6 +19,9 @@ install with gem or fluent-gem command as:
14
19
  # for fluentd
15
20
  $ gem install fluent-plugin-rename-key
16
21
 
22
+ # for td-agent OSX (Homebrew)
23
+ $ /usr/local/Cellar/td-agent/1.1.17/bin/fluent-gem install fluent-plugin-rename-key
24
+
17
25
  # for td-agent
18
26
  $ sudo /usr/lib64/fluent/ruby/bin/fluent-gem install fluent-plugin-rename-key
19
27
  ```
@@ -23,6 +31,9 @@ $ sudo /usr/lib64/fluent/ruby/bin/fluent-gem install fluent-plugin-rename-key
23
31
  ### Syntax
24
32
 
25
33
  ```
34
+ # <num> is a integer, used to sort and apply the rules
35
+ # <key_regexp> is the regular expression used to match the keys, whitespace is not allowed, use "\s" instead
36
+ # <new_key> is the string with MatchData placeholder for creating the new key name, whitespace is allowed
26
37
  rename_rule<num> <key_regexp> <new_key>
27
38
 
28
39
  # Optional: remove tag prefix
@@ -42,8 +53,8 @@ Take this record as example: `'$url' => 'www.google.com', 'level2' => {'$1' => '
42
53
  To successfully save it into MongoDB, we can use the following config to replace the keys starting with dollar sign.
43
54
 
44
55
  ```
45
- # At rename_rule1, it matches the key starting the `$`, say `$url`,
46
- # and puts the following characters into match group 1.
56
+ # At rename_rule1, it matches the key starting the `$`, say `$url`,
57
+ # and puts the following characters into match group 1.
47
58
  # Then uses the content in match group 1, `url`, to generate the new key name `x$url`.
48
59
 
49
60
  <match input.test>
@@ -51,17 +62,17 @@ To successfully save it into MongoDB, we can use the following config to replace
51
62
  remove_tag_prefix input.test
52
63
  append_tag renamed
53
64
  rename_rule1 ^\$(.+) x$${md[1]}
54
- rename_rule2 ^l(eve)l(\d+) ${md[1]}_${md[2]}
65
+ rename_rule2 ^l(.{3})l(\d+) ${md[1]}_${md[2]}
55
66
  </match>
56
67
  ```
57
68
 
58
- The resulting record will be `'x$url' => 'www.google.com', 'eve_2' => {'x$1' => 'option1'}`
69
+ The resulting record becomes `'x$url' => 'www.google.com', 'eve_2' => {'x$1' => 'option1'}`
59
70
 
60
71
  ### MatchData placeholder
61
72
 
62
73
  This plugin uses Ruby's `String#match` to match the key to be replaced, and it is possible to refer to the contents of the resulting `MatchData` to create the new key name. `${md[0]}` refers to the matched string and `${md[1]}` refers to match group 1, and so on.
63
74
 
64
- **Note** Range expression ```${md[0..2]}``` is not supported.
75
+ **Note:** Range expression ```${md[0..2]}``` is not supported.
65
76
 
66
77
  ## TODO
67
78
 
data/Rakefile ADDED
@@ -0,0 +1,9 @@
1
+ task :default => [:spec]
2
+ begin
3
+ require 'rspec/core/rake_task'
4
+ RSpec::Core::RakeTask.new(:spec) do |spec|
5
+ spec.pattern = 'spec/**/*_spec.rb'
6
+ spec.rspec_opts = ['-cfs']
7
+ end
8
+ rescue LoadError => e
9
+ end
@@ -3,7 +3,7 @@ $:.push File.expand_path('../lib', __FILE__)
3
3
 
4
4
  Gem::Specification.new do |gem|
5
5
  gem.name = "fluent-plugin-rename-key"
6
- gem.version = "0.1.2"
6
+ gem.version = "0.1.3"
7
7
  gem.license = "Apache 2.0"
8
8
  gem.authors = ["Shunwen Hsiao"]
9
9
  gem.email = "hsiaoshunwen@gmail.com"
@@ -19,5 +19,7 @@ Gem::Specification.new do |gem|
19
19
  gem.add_dependency "fluentd", "~> 0.10.9"
20
20
  gem.add_development_dependency "rspec"
21
21
  gem.add_development_dependency "bundler"
22
+ gem.add_development_dependency "rake"
23
+ gem.add_development_dependency 'coveralls'
22
24
 
23
25
  end
@@ -63,7 +63,14 @@ class Fluent::RenameKeyOutput < Fluent::Output
63
63
  break
64
64
  end
65
65
 
66
- value = rename_key value if value.is_a? Hash and @deep_rename
66
+ if @deep_rename
67
+ if value.is_a? Hash
68
+ value = rename_key value
69
+ elsif value.is_a? Array
70
+ value = value.map { |v| v.is_a?(Hash) ? rename_key(v) : v }
71
+ end
72
+ end
73
+
67
74
  new_record[key] = value
68
75
  end
69
76
 
@@ -100,6 +100,16 @@ describe Fluent::RenameKeyOutput do
100
100
  expect(result['level2']).to have_key '$1'
101
101
  end
102
102
 
103
+ it "replace key of hashes in an array" do
104
+ d = create_driver 'rename_rule1 ^\$(.+)\s(\w+) x$${md[2]} ${md[1]}'
105
+ d.run do
106
+ d.emit 'array' => [{'$url jump' => 'www.google.com'}, {'$url run' => 'www.google.com'}], 'level2' => {'$1' => 'options1'}
107
+ end
108
+ result = d.emits[0][2]
109
+ expect(result['array'][0]).to have_key 'x$jump url'
110
+ expect(result['array'][1]).to have_key 'x$run url'
111
+ end
112
+
103
113
  it "replaces key name using match data" do
104
114
  d = create_driver 'rename_rule1 ^\$(.+)\s(\w+) x$${md[2]} ${md[1]}'
105
115
  d.run do
data/spec/spec_helper.rb CHANGED
@@ -11,6 +11,10 @@ $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..', 'lib')
11
11
  $LOAD_PATH.unshift File.dirname(__FILE__)
12
12
 
13
13
  require 'rspec'
14
+ require 'coveralls'
15
+ Coveralls.wear!
16
+
17
+ ARGV = []
14
18
  require 'fluent/test'
15
19
 
16
20
  unless ENV.has_key?('VERBOSE')
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-rename-key
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shunwen Hsiao
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-11-14 00:00:00.000000000 Z
11
+ date: 2013-11-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: fluentd
@@ -52,6 +52,34 @@ dependencies:
52
52
  - - '>='
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: coveralls
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
55
83
  description:
56
84
  email: hsiaoshunwen@gmail.com
57
85
  executables: []
@@ -59,10 +87,12 @@ extensions: []
59
87
  extra_rdoc_files: []
60
88
  files:
61
89
  - .gitignore
90
+ - .travis.yml
62
91
  - Gemfile
63
92
  - Guardfile
64
93
  - LICENSE.txt
65
94
  - README.md
95
+ - Rakefile
66
96
  - fluent-plugin-rename-key.gemspec
67
97
  - lib/fluent/plugin/out_rename_key.rb
68
98
  - spec/plugin/out_rename_key_spec.rb