fluent-plugin-record-reformer 0.2.2 → 0.2.3

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: f79ddbaecca21d91a17132b991c9f031b5a19b01
4
- data.tar.gz: e6f3777a3a2fdc0fe14887c3d745dfd38e39c60a
3
+ metadata.gz: 01c153cf57bbdddaf7164d074b5f3e4f47402682
4
+ data.tar.gz: bcd0d98e566429e1e04a1823a354f05934997ce1
5
5
  SHA512:
6
- metadata.gz: 5193f5ee853ff6af02e119759bc8ec6a6c018f1a69bad34511757f62bd95918c2c3dc766eb3bc485ad47e65829a88e44da16e63a5238150314b9dca4f137e678
7
- data.tar.gz: dc3313b3754851512e110247fd0c184c9130e9c2137f5c6adc39c62c173e9c6f2a3379b55b29dd2bf453c88e036722817a19455e72389e05e25f00e02da77585
6
+ metadata.gz: c161aa72e64c8414deccef1ce8d2dfa22755ce52af9c17de5468490eea0972ddaa6ac0c57ae2bb5d433a9a7cb7e0f7897bccb297c1435d663add76ff61f01e6f
7
+ data.tar.gz: 58e92e2efc93924898c7070adacc4112745dfc3f8d7f5d862cc6f11d633405004642e3c3db215191c6505c19d13fee07d5635aa15587960159c501afcbb437a6
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ ## 0.2.3 (2014/01/25)
2
+
3
+ Changes:
4
+
5
+ * Change ${time} placeholder from integer to string when `enable_ruby false`
6
+
1
7
  ## 0.2.2 (2014/01/20)
2
8
 
3
9
  Enhancement:
@@ -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.2.2"
6
+ gem.version = "0.2.3"
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"
@@ -47,13 +47,6 @@ module Fluent
47
47
  PlaceholderExpander.new
48
48
  end
49
49
 
50
- @time_proc = # hmm, want to remove ${time} placeholder ...
51
- if @enable_ruby
52
- Proc.new {|time| Time.at(time) }
53
- else
54
- Proc.new {|time| time }
55
- end
56
-
57
50
  @hostname = Socket.gethostname
58
51
  end
59
52
 
@@ -61,8 +54,16 @@ module Fluent
61
54
  tag_parts = tag.split('.')
62
55
  tag_prefix = tag_prefix(tag_parts)
63
56
  tag_suffix = tag_suffix(tag_parts)
57
+ placeholders = {
58
+ 'tag' => tag,
59
+ 'tags' => tag_parts,
60
+ 'tag_parts' => tag_parts,
61
+ 'tag_prefix' => tag_prefix,
62
+ 'tag_suffix' => tag_suffix,
63
+ 'hostname' => @hostname,
64
+ }
64
65
  es.each { |time, record|
65
- new_tag, new_record = reform(@output_tag, record, tag, tag_parts, tag_prefix, tag_suffix, @time_proc.call(time))
66
+ new_tag, new_record = reform(@output_tag, time, record, placeholders)
66
67
  Engine.emit(new_tag, time, new_record)
67
68
  }
68
69
  chain.next
@@ -72,8 +73,8 @@ module Fluent
72
73
 
73
74
  private
74
75
 
75
- def reform(output_tag, record, tag, tag_parts, tag_prefix, tag_suffix, time)
76
- @placeholder_expander.prepare_placeholders(record, tag, tag_parts, tag_prefix, tag_suffix, @hostname, time)
76
+ def reform(output_tag, time, record, opts)
77
+ @placeholder_expander.prepare_placeholders(time, record, opts)
77
78
  new_tag = @placeholder_expander.expand(output_tag)
78
79
 
79
80
  new_record = @renew_record ? {} : record.dup
@@ -103,40 +104,23 @@ module Fluent
103
104
  end
104
105
 
105
106
  class PlaceholderExpander
106
- # referenced https://github.com/fluent/fluent-plugin-rewrite-tag-filter, thanks!
107
107
  attr_reader :placeholders
108
108
 
109
- def prepare_placeholders(record, tag, tag_parts, tag_prefix, tag_suffix, hostname, time)
110
- placeholders = {
111
- '${time}' => time,
112
- '${tag}' => tag,
113
- '${hostname}' => hostname,
114
- }
115
-
116
- size = tag_parts.size
117
-
118
- tag_parts.each_with_index { |t, idx|
119
- placeholders.store("${tag_parts[#{idx}]}", t)
120
- placeholders.store("${tag_parts[#{idx-size}]}", t) # support tag_parts[-1]
121
-
122
- # tags is just for old version compatibility
123
- placeholders.store("${tags[#{idx}]}", t)
124
- placeholders.store("${tags[#{idx-size}]}", t) # support tags[-1]
125
- }
126
-
127
- tag_prefix.each_with_index { |t, idx|
128
- placeholders.store("${tag_prefix[#{idx}]}", t)
129
- placeholders.store("${tag_prefix[#{idx-size}]}", t) # support tag_prefix[-1]
130
- }
131
-
132
- tag_suffix.each_with_index { |t, idx|
133
- placeholders.store("${tag_suffix[#{idx}]}", t)
134
- placeholders.store("${tag_suffix[#{idx-size}]}", t) # support tag_suffix[-1]
135
- }
136
-
137
- record.each { |k, v|
138
- placeholders.store("${#{k}}", v)
139
- }
109
+ def prepare_placeholders(time, record, opts)
110
+ placeholders = { '${time}' => Time.at(time).to_s }
111
+ record.each {|key, val| placeholders.store("${#{key}}", val) }
112
+
113
+ opts.each do |key, val|
114
+ if val.kind_of?(Array)
115
+ size = val.size
116
+ val.each_with_index { |t, idx|
117
+ placeholders.store("${#{key}[#{idx}]}", t)
118
+ placeholders.store("${#{key}[#{idx-size}]}", t) # support [-1]
119
+ }
120
+ else # string, interger, float, and others?
121
+ placeholders["${#{key}}"] = val
122
+ end
123
+ end
140
124
 
141
125
  @placeholders = placeholders
142
126
  end
@@ -154,21 +138,13 @@ module Fluent
154
138
 
155
139
  # Get placeholders as a struct
156
140
  #
157
- # @param [Hash] record the record, one of information
158
- # @param [String] tag the tag
159
- # @param [Array] tag_parts the tag parts (tag splitted by .)
160
- # @param [Array] tag_prefix the tag prefix parts
161
- # @param [Array] tag_suffix the tag suffix parts
162
- # @param [String] hostname the hostname
163
141
  # @param [Time] time the time
164
- def prepare_placeholders(record, tag, tag_parts, tag_prefix, tag_suffix, hostname, time)
142
+ # @param [Hash] record the record
143
+ # @param [Hash] opts others
144
+ def prepare_placeholders(time, record, opts)
165
145
  struct = UndefOpenStruct.new(record)
166
- struct.tag = tag
167
- struct.tags = struct.tag_parts = tag_parts # tags is for old version compatibility
168
- struct.tag_prefix = tag_prefix
169
- struct.tag_suffix = tag_suffix
170
- struct.time = time
171
- struct.hostname = hostname
146
+ struct.time = Time.at(time)
147
+ opts.each {|key, val| struct.__send__("#{key}=", val) }
172
148
  @placeholders = struct
173
149
  end
174
150
 
@@ -163,14 +163,14 @@ describe Fluent::RecordReformerOutput do
163
163
  'foo' => 'bar',
164
164
  'hostname' => hostname,
165
165
  'tag' => tag,
166
- 'time' => time.to_i.to_s, # hmm, want to remove ${time} placeholder
166
+ 'time' => time.to_s,
167
167
  'message' => "#{hostname} #{tag_parts.last} 1",
168
168
  })
169
169
  Fluent::Engine.should_receive(:emit).with("reformed.#{tag}", time.to_i, {
170
170
  'foo' => 'bar',
171
171
  'hostname' => hostname,
172
172
  'tag' => tag,
173
- 'time' => time.to_i.to_s, # hmm, want to remove ${time} placeholder
173
+ 'time' => time.to_s,
174
174
  'message' => "#{hostname} #{tag_parts.last} 2",
175
175
  })
176
176
  end
@@ -197,14 +197,14 @@ describe Fluent::RecordReformerOutput do
197
197
  'message' => "prefix.test prefix.test.tag tag.suffix test.tag.suffix 1",
198
198
  'hostname' => hostname,
199
199
  'tag' => tag,
200
- 'time' => time.to_i.to_s, # hmm, want to remove ${time} placeholder
200
+ 'time' => time.to_s,
201
201
  })
202
202
  Fluent::Engine.should_receive(:emit).with("tag.suffix", time.to_i, {
203
203
  'foo' => 'bar',
204
204
  'message' => "prefix.test prefix.test.tag tag.suffix test.tag.suffix 2",
205
205
  'hostname' => hostname,
206
206
  'tag' => tag,
207
- 'time' => time.to_i.to_s, # hmm, want to remove ${time} placeholder
207
+ 'time' => time.to_s,
208
208
  })
209
209
  end
210
210
  it { emit }
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.2.2
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Naotoshi Seo
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-01-20 00:00:00.000000000 Z
11
+ date: 2014-01-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: fluentd