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 +4 -4
- data/.gitignore +1 -0
- data/CHANGELOG.md +6 -0
- data/Gemfile +0 -1
- data/README.md +5 -3
- data/fluent-plugin-record-reformer.gemspec +1 -1
- data/lib/fluent/plugin/out_record_reformer.rb +12 -12
- data/spec/out_record_reformer_spec.rb +40 -20
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6cb811fb3f7274893d0f871c070fa298b0f9c138
|
4
|
+
data.tar.gz: 504bb732f1e60a2bc98f80b44a78294de6770627
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 29c43c2e9b76b18de8c5744219814a1a9ca4babfa1f332c88d84c7b1db2e89fe38a57e4f78fc6c8a320cacb4ab88542174a05728f997a913857bc0603511d0b5
|
7
|
+
data.tar.gz: b6a984d357f3a1f74221284a3982265001a01338c6c3667b60d1ad1d7455270553e46345351172510c7d4d6775409daf59dda35fbd686b4bbcee80b22c903455
|
data/.gitignore
CHANGED
data/CHANGELOG.md
CHANGED
data/Gemfile
CHANGED
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} ${
|
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
|
-
* ${
|
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.
|
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
|
-
|
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,
|
37
|
-
Engine.emit(output_tag, time, replace_record(record, tag,
|
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,
|
47
|
+
def replace_record(record, tag, tag_parts, time)
|
48
48
|
@map.each_pair { |k, v|
|
49
|
-
record[k] = expand_placeholder(v, record, tag,
|
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
|
57
|
-
# @param [Hash] record
|
58
|
-
# @param [String] tag
|
59
|
-
# @param [Array]
|
60
|
-
# @param [Time] time
|
61
|
-
def expand_placeholder(str, record, tag,
|
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} ${
|
13
|
+
message ${hostname} ${tag_parts.last} ${message}
|
14
14
|
]
|
15
15
|
let(:tag) { 'test.tag' }
|
16
|
-
let(:
|
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
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
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.
|
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-
|
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.
|
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
|