fluent-plugin-rewrite 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +43 -0
- data/fluent-plugin-rewrite.gemspec +1 -1
- data/lib/fluent/plugin/out_rewrite.rb +10 -3
- data/test/plugin/test_out_rewrite.rb +25 -0
- metadata +2 -2
data/README.md
CHANGED
@@ -145,6 +145,49 @@ This time, the messabe above will be re-emmited as the message below:
|
|
145
145
|
apache.log.others { "path" : "/foo/bar" }
|
146
146
|
```
|
147
147
|
|
148
|
+
### rule: last
|
149
|
+
|
150
|
+
If you set `last` option to true, rewriting chain stops applying rule where the pattern matches first.
|
151
|
+
|
152
|
+
```
|
153
|
+
<rule>
|
154
|
+
key path
|
155
|
+
pattern ^/foo$
|
156
|
+
replace /bar
|
157
|
+
last true
|
158
|
+
</rule>
|
159
|
+
<rule>
|
160
|
+
key path
|
161
|
+
pattern ^/bar$
|
162
|
+
replace /baz
|
163
|
+
</rule>
|
164
|
+
```
|
165
|
+
|
166
|
+
This rules will be applied like below:
|
167
|
+
|
168
|
+
```
|
169
|
+
{ "path" => "/foo" }
|
170
|
+
```
|
171
|
+
|
172
|
+
will be replaced with
|
173
|
+
|
174
|
+
```
|
175
|
+
{ "path" => "/bar" }
|
176
|
+
```
|
177
|
+
|
178
|
+
and the chain stops here. Therefore, the second rule is never
|
179
|
+
applied.
|
180
|
+
|
181
|
+
```
|
182
|
+
{ "path" => "/bar" }
|
183
|
+
```
|
184
|
+
|
185
|
+
will be replaced by the second rule as usual.
|
186
|
+
|
187
|
+
```
|
188
|
+
{ "path" => "/baz" }
|
189
|
+
```
|
190
|
+
|
148
191
|
## Installation
|
149
192
|
|
150
193
|
Add this line to your application's Gemfile:
|
@@ -66,7 +66,9 @@ module Fluent
|
|
66
66
|
end
|
67
67
|
|
68
68
|
rules.each do |rule|
|
69
|
-
tag, record = apply_rule(rule, tag, record)
|
69
|
+
tag, record, last = apply_rule(rule, tag, record)
|
70
|
+
|
71
|
+
break if last
|
70
72
|
return if !tag && !record
|
71
73
|
end
|
72
74
|
|
@@ -77,6 +79,7 @@ module Fluent
|
|
77
79
|
tag = rule["append_to_tag"] ? tag.dup : tag
|
78
80
|
key = rule["key"]
|
79
81
|
pattern = rule["pattern"]
|
82
|
+
last = nil
|
80
83
|
|
81
84
|
return [tag, record] if !key || !record.has_key?(key)
|
82
85
|
return [tag, record] unless pattern
|
@@ -85,20 +88,24 @@ module Fluent
|
|
85
88
|
return if rule["ignore"]
|
86
89
|
|
87
90
|
if rule["replace"]
|
88
|
-
replace = rule["replace"]
|
91
|
+
replace = rule["replace"]
|
89
92
|
record[key] = record[key].gsub(rule["regex"], replace)
|
90
93
|
end
|
91
94
|
|
92
95
|
if rule["append_to_tag"]
|
93
96
|
matched.captures.each { |m| tag << ".#{m}" }
|
94
97
|
end
|
98
|
+
|
99
|
+
if rule["last"]
|
100
|
+
last = true
|
101
|
+
end
|
95
102
|
else
|
96
103
|
if rule["append_to_tag"] && rule["fallback"]
|
97
104
|
tag << ".#{rule["fallback"]}"
|
98
105
|
end
|
99
106
|
end
|
100
107
|
|
101
|
-
[tag, record]
|
108
|
+
[tag, record, last]
|
102
109
|
end
|
103
110
|
end
|
104
111
|
end
|
@@ -142,6 +142,31 @@ class RewriteOutputTest < Test::Unit::TestCase
|
|
142
142
|
)
|
143
143
|
end
|
144
144
|
|
145
|
+
def test_last
|
146
|
+
d = create_driver(%[
|
147
|
+
<rule>
|
148
|
+
key path
|
149
|
+
pattern ^/foo$
|
150
|
+
replace /bar
|
151
|
+
last true
|
152
|
+
</rule>
|
153
|
+
<rule>
|
154
|
+
key path
|
155
|
+
pattern ^/bar$
|
156
|
+
replace /baz
|
157
|
+
</rule>
|
158
|
+
])
|
159
|
+
|
160
|
+
assert_equal(
|
161
|
+
[ "test", { "path" => "/bar" } ],
|
162
|
+
d.instance.rewrite("test", { "path" => "/foo" })
|
163
|
+
)
|
164
|
+
assert_equal(
|
165
|
+
[ "test", { "path" => "/baz" } ],
|
166
|
+
d.instance.rewrite("test", { "path" => "/bar" })
|
167
|
+
)
|
168
|
+
end
|
169
|
+
|
145
170
|
def test_rewrite_rules
|
146
171
|
d = create_driver(%[
|
147
172
|
<rule>
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fluent-plugin-rewrite
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-07-01 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|