fluent-plugin-record-reformer 0.2.2 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/fluent-plugin-record-reformer.gemspec +1 -1
- data/lib/fluent/plugin/out_record_reformer.rb +31 -55
- data/spec/out_record_reformer_spec.rb +4 -4
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 01c153cf57bbdddaf7164d074b5f3e4f47402682
|
4
|
+
data.tar.gz: bcd0d98e566429e1e04a1823a354f05934997ce1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c161aa72e64c8414deccef1ce8d2dfa22755ce52af9c17de5468490eea0972ddaa6ac0c57ae2bb5d433a9a7cb7e0f7897bccb297c1435d663add76ff61f01e6f
|
7
|
+
data.tar.gz: 58e92e2efc93924898c7070adacc4112745dfc3f8d7f5d862cc6f11d633405004642e3c3db215191c6505c19d13fee07d5635aa15587960159c501afcbb437a6
|
data/CHANGELOG.md
CHANGED
@@ -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.
|
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,
|
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,
|
76
|
-
@placeholder_expander.prepare_placeholders(
|
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(
|
110
|
-
placeholders = {
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
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
|
-
|
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.
|
167
|
-
|
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.
|
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.
|
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.
|
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.
|
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.
|
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-
|
11
|
+
date: 2014-01-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: fluentd
|