fluent-plugin-record-reformer 0.1.0 → 0.1.1

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: 7f559864ef660d47eddb8014db068e4bde4ada84
4
- data.tar.gz: d386239a2519be28502c088d5943ac6fa40a8271
3
+ metadata.gz: 6cb811fb3f7274893d0f871c070fa298b0f9c138
4
+ data.tar.gz: 504bb732f1e60a2bc98f80b44a78294de6770627
5
5
  SHA512:
6
- metadata.gz: f4803fe2a264683ad621602819a4e646afcd94b3a22a7263344a3278df4bd8240dd41bee86b566437c831afbf7b864f69ef8beeaf62295d6967c4e01c9bf7a57
7
- data.tar.gz: 96de88d6872141f4804c168baa526767be7cb49ab2ea14389bad1d5255bee9508b872c7c906f5e17e74023bc95303d48eaea0ea518729e3f8daf4642cf17b3b2
6
+ metadata.gz: 29c43c2e9b76b18de8c5744219814a1a9ca4babfa1f332c88d84c7b1db2e89fe38a57e4f78fc6c8a320cacb4ab88542174a05728f997a913857bc0603511d0b5
7
+ data.tar.gz: b6a984d357f3a1f74221284a3982265001a01338c6c3667b60d1ad1d7455270553e46345351172510c7d4d6775409daf59dda35fbd686b4bbcee80b22c903455
data/.gitignore CHANGED
@@ -11,3 +11,4 @@ tmp/*
11
11
  coverage
12
12
  .yardoc
13
13
  pkg/
14
+ .ruby-version
@@ -1,3 +1,9 @@
1
+ ## 0.1.1 (2013/11/21)
2
+
3
+ Changes:
4
+
5
+ * change the name of `tags` placeholder to `tag_parts`. `tags` is still available for old version compatibility, though
6
+
1
7
  ## 0.1.0 (2013/09/09)
2
8
 
3
9
  Enhancement:
data/Gemfile CHANGED
@@ -1,4 +1,3 @@
1
1
  source "http://rubygems.org"
2
2
 
3
- gem 'simplecov', git: 'https://github.com/colszowka/simplecov.git'
4
3
  gemspec
data/README.md CHANGED
@@ -21,7 +21,7 @@ Example:
21
21
  hostname ${hostname}
22
22
  tag ${tag}
23
23
  time ${time.strftime('%Y-%m-%dT%H:%M:%S%z')}
24
- message ${hostname} ${tags.last} ${message}
24
+ message ${hostname} ${tag_parts.last} ${message}
25
25
  </match>
26
26
 
27
27
  Assume following input is coming:
@@ -55,13 +55,15 @@ shall be available. In addition, following placeholders are reserved:
55
55
 
56
56
  * ${hostname} hostname
57
57
  * ${tag} input tag
58
- * ${tags} input tag splitted by '.'
58
+ * ${tags} input tag splitted by '.' (obsolete. use tag_parts)
59
+ * ${tag_parts} input tag splitted by '.'
59
60
  * ${time} time of the event
60
61
 
61
62
  It is also possible to write a ruby code in placeholders, so you may write some codes as
62
63
 
63
64
  * ${time.strftime('%Y-%m-%dT%H:%M:%S%z')}
64
- * ${tags.last}
65
+ * ${tag_parts[0]}
66
+ * ${tag_parts.last}
65
67
 
66
68
  ## Notice
67
69
 
@@ -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-record-reformer"
6
- gem.version = "0.1.0"
6
+ gem.version = "0.1.1"
7
7
  gem.authors = ["Naotoshi Seo"]
8
8
  gem.email = "sonots@gmail.com"
9
9
  gem.homepage = "https://github.com/sonots/fluent-plugin-record-reformer"
@@ -30,11 +30,11 @@ module Fluent
30
30
  end
31
31
 
32
32
  def emit(tag, es, chain)
33
- tags = tag.split('.')
33
+ tag_parts = tag.split('.')
34
34
  es.each { |time, record|
35
35
  t_time = Time.at(time)
36
- output_tag = expand_placeholder(@output_tag, record, tag, tags, t_time)
37
- Engine.emit(output_tag, time, replace_record(record, tag, tags, t_time))
36
+ output_tag = expand_placeholder(@output_tag, record, tag, tag_parts, t_time)
37
+ Engine.emit(output_tag, time, replace_record(record, tag, tag_parts, t_time))
38
38
  }
39
39
  chain.next
40
40
  rescue => e
@@ -44,24 +44,24 @@ module Fluent
44
44
 
45
45
  private
46
46
 
47
- def replace_record(record, tag, tags, time)
47
+ def replace_record(record, tag, tag_parts, time)
48
48
  @map.each_pair { |k, v|
49
- record[k] = expand_placeholder(v, record, tag, tags, time)
49
+ record[k] = expand_placeholder(v, record, tag, tag_parts, time)
50
50
  }
51
51
  record
52
52
  end
53
53
 
54
54
  # Replace placeholders in a string
55
55
  #
56
- # @param [String] str the string to be replaced
57
- # @param [Hash] record the record, one of information
58
- # @param [String] tag one of information
59
- # @param [Array] tags one of information
60
- # @param [Time] time one of information
61
- def expand_placeholder(str, record, tag, tags, time)
56
+ # @param [String] str the string to be replaced
57
+ # @param [Hash] record the record, one of information
58
+ # @param [String] tag the tag
59
+ # @param [Array] tag_parts the tag parts (tag splitted by .)
60
+ # @param [Time] time the time
61
+ def expand_placeholder(str, record, tag, tag_parts, time)
62
62
  struct = UndefOpenStruct.new(record)
63
63
  struct.tag = tag
64
- struct.tags = tags
64
+ struct.tags = struct.tag_parts = tag_parts # tags is for old version compatibility
65
65
  struct.time = time
66
66
  struct.hostname = @hostname
67
67
  str = str.gsub(/\$\{([^}]+)\}/, '#{\1}') # ${..} => #{..}
@@ -10,10 +10,10 @@ describe Fluent::RecordReformerOutput do
10
10
  hostname ${hostname}
11
11
  tag ${tag}
12
12
  time ${time.strftime('%S')}
13
- message ${hostname} ${tags.last} ${message}
13
+ message ${hostname} ${tag_parts.last} ${message}
14
14
  ]
15
15
  let(:tag) { 'test.tag' }
16
- let(:tags) { tag.split('.') }
16
+ let(:tag_parts) { tag.split('.') }
17
17
  let(:hostname) { Socket.gethostname.chomp }
18
18
  let(:driver) { Fluent::Test::OutputTestDriver.new(Fluent::RecordReformerOutput, tag).configure(config) }
19
19
 
@@ -36,24 +36,44 @@ describe Fluent::RecordReformerOutput do
36
36
  end
37
37
  end
38
38
 
39
- let(:config) { CONFIG }
40
- before do
41
- Fluent::Engine.stub(:now).and_return(time)
42
- Fluent::Engine.should_receive(:emit).with("reformed.#{tag}", time.to_i, {
43
- 'foo' => 'bar',
44
- 'hostname' => hostname,
45
- 'tag' => tag,
46
- 'time' => time.strftime('%S'),
47
- 'message' => "#{hostname} #{tags.last} 1",
48
- })
49
- Fluent::Engine.should_receive(:emit).with("reformed.#{tag}", time.to_i, {
50
- 'foo' => 'bar',
51
- 'hostname' => hostname,
52
- 'tag' => tag,
53
- 'time' => time.strftime('%S'),
54
- 'message' => "#{hostname} #{tags.last} 2",
55
- })
39
+ context 'typical usage' do
40
+ let(:config) { CONFIG }
41
+ before do
42
+ Fluent::Engine.stub(:now).and_return(time)
43
+ Fluent::Engine.should_receive(:emit).with("reformed.#{tag}", time.to_i, {
44
+ 'foo' => 'bar',
45
+ 'hostname' => hostname,
46
+ 'tag' => tag,
47
+ 'time' => time.strftime('%S'),
48
+ 'message' => "#{hostname} #{tag_parts.last} 1",
49
+ })
50
+ Fluent::Engine.should_receive(:emit).with("reformed.#{tag}", time.to_i, {
51
+ 'foo' => 'bar',
52
+ 'hostname' => hostname,
53
+ 'tag' => tag,
54
+ 'time' => time.strftime('%S'),
55
+ 'message' => "#{hostname} #{tag_parts.last} 2",
56
+ })
57
+ end
58
+ it { emit }
59
+ end
60
+
61
+ context 'support old ${tags} placeholder' do
62
+ let(:config) { %[
63
+ type reformed
64
+ output_tag reformed.${tag}
65
+
66
+ message ${tags[1]}
67
+ ]}
68
+
69
+ before do
70
+ Fluent::Engine.stub(:now).and_return(time)
71
+ Fluent::Engine.should_receive(:emit).twice.with("reformed.#{tag}", time.to_i, {
72
+ 'foo' => 'bar',
73
+ 'message' => "#{tag_parts[1]}",
74
+ })
75
+ end
76
+ it { emit }
56
77
  end
57
- it { emit }
58
78
  end
59
79
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-record-reformer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Naotoshi Seo
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-09-09 00:00:00.000000000 Z
11
+ date: 2013-12-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: fluentd
@@ -104,7 +104,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
104
104
  version: '0'
105
105
  requirements: []
106
106
  rubyforge_project:
107
- rubygems_version: 2.0.2
107
+ rubygems_version: 2.0.3
108
108
  signing_key:
109
109
  specification_version: 4
110
110
  summary: Output filter plugin for reforming each event record