fluent-plugin-multi-format-parser 1.0.0 → 1.1.0
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 +5 -5
- data/.bundle/config +2 -0
- data/README.md +39 -2
- data/Rakefile +1 -2
- data/VERSION +1 -1
- data/fluent-plugin-multi-format-parser.gemspec +2 -1
- data/lib/fluent/plugin/parser_multi_format.rb +8 -3
- data/test/test_parser_multi_format.rb +61 -0
- metadata +24 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 6c766b375521ddc5cc16503d3851d73ce3e7c995cd5f78dc3667dbe62966ff0b
|
4
|
+
data.tar.gz: 18f41d24351b487385d4433835cf0d8f81a648c86e3b99094e0127d08394a209
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cfbc21ac9ec34e10cbde396e3d34b4358121cc2430db5fd91f1b60576499531476862f23ed6858373841405cf742ee04bcd800d8218b5a85f9a0c77724361bd8
|
7
|
+
data.tar.gz: 14f2c6ecc7b3aed398f040d636797147ccd1c096e0573f8c3392d857972376905be0b1e46e67600d35e4c787f53c65ca7395495ce55da53fd6b2c0b7bb66fd71
|
data/.bundle/config
ADDED
data/README.md
CHANGED
@@ -44,7 +44,7 @@ Use multiple `<pattern>`s to specify multiple parser formats.
|
|
44
44
|
Available format patterns and parameters are depends on Fluentd parsers.
|
45
45
|
See [parser plugin document](http://docs.fluentd.org/v1.0/articles/parser-plugin-overview) for more details.
|
46
46
|
|
47
|
-
### For v1.0
|
47
|
+
### For v1.0
|
48
48
|
|
49
49
|
Put `<pattern>`s inside `<parse>`.
|
50
50
|
|
@@ -86,6 +86,43 @@ Use `format` instead of `<parse></parse>`.
|
|
86
86
|
</pattern>
|
87
87
|
</filter>
|
88
88
|
|
89
|
+
### Adding format identity field
|
90
|
+
|
91
|
+
Sometimes it may be useful to know which pattern was used. Since pareser usage
|
92
|
+
may not support retagging, there is an option to add a format name field and/or
|
93
|
+
index field.
|
94
|
+
|
95
|
+
Example:
|
96
|
+
|
97
|
+
|
98
|
+
<filter app.**>
|
99
|
+
@type parser
|
100
|
+
key_name message
|
101
|
+
<parse>
|
102
|
+
@type multi_format
|
103
|
+
|
104
|
+
# if set, add this key to record with value being pattern format name
|
105
|
+
# (format_name key)
|
106
|
+
format_key 'format'
|
107
|
+
|
108
|
+
<pattern>
|
109
|
+
format json
|
110
|
+
# set format name for this pattern. If unset, uses format name
|
111
|
+
# followed by index (in this case would be 'json#0')
|
112
|
+
format_name 'json'
|
113
|
+
</pattern>
|
114
|
+
<pattern>
|
115
|
+
format regexp
|
116
|
+
format_name 'MyRefex'
|
117
|
+
expression /...your regexp pattern.../
|
118
|
+
</pattern>
|
119
|
+
<pattern>
|
120
|
+
format none
|
121
|
+
format_name 'unparsed'
|
122
|
+
</pattern>
|
123
|
+
</parse>
|
124
|
+
</filter>
|
125
|
+
|
89
126
|
### NOTE
|
90
127
|
|
91
128
|
This plugin doesn't work with `multiline` parsers because parser itself doesn't store previous lines.
|
@@ -100,6 +137,6 @@ This plugin doesn't work with `multiline` parsers because parser itself doesn't
|
|
100
137
|
<td>Copyright</td><td>Copyright (c) 2014- Masahiro Nakagawa</td>
|
101
138
|
</tr>
|
102
139
|
<tr>
|
103
|
-
<td>License</td><td>
|
140
|
+
<td>License</td><td>Apache License (2.0)</td>
|
104
141
|
</tr>
|
105
142
|
</table>
|
data/Rakefile
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.
|
1
|
+
1.1.0
|
@@ -9,7 +9,7 @@ Gem::Specification.new do |gem|
|
|
9
9
|
gem.version = File.read("VERSION").strip
|
10
10
|
gem.authors = ["Masahiro Nakagawa"]
|
11
11
|
gem.email = "repeatedly@gmail.com"
|
12
|
-
gem.has_rdoc = false
|
12
|
+
#gem.has_rdoc = false
|
13
13
|
#gem.platform = Gem::Platform::RUBY
|
14
14
|
gem.license = 'Apache License (2.0)'
|
15
15
|
gem.files = `git ls-files`.split("\n")
|
@@ -19,4 +19,5 @@ Gem::Specification.new do |gem|
|
|
19
19
|
|
20
20
|
gem.add_dependency "fluentd", [">= 0.14.0", "< 2"]
|
21
21
|
gem.add_development_dependency "rake", ">= 0.9.2"
|
22
|
+
gem.add_development_dependency("test-unit", ["~> 3.3"])
|
22
23
|
end
|
@@ -4,20 +4,22 @@ module Fluent
|
|
4
4
|
module Plugin
|
5
5
|
class MultiFormatParser < Parser
|
6
6
|
Plugin.register_parser('multi_format', self)
|
7
|
+
config_param :format_key, :string, default: nil
|
7
8
|
|
8
9
|
def initialize
|
9
10
|
super
|
10
11
|
|
11
12
|
@parsers = []
|
13
|
+
@parser_format_names = []
|
12
14
|
end
|
13
15
|
|
14
16
|
def configure(conf)
|
15
17
|
super
|
16
18
|
|
17
|
-
conf.elements.
|
19
|
+
conf.elements.each_with_index { |e, i|
|
18
20
|
next unless ['pattern', 'format'].include?(e.name)
|
19
21
|
next if e['format'].nil? && (e['@type'] == 'multi_format')
|
20
|
-
|
22
|
+
@parser_format_names << e.delete('format_name') || ""+e['format']+"#"+i.to_s
|
21
23
|
parser = Plugin.new_parser(e['format'])
|
22
24
|
parser.configure(e)
|
23
25
|
@parsers << parser
|
@@ -25,10 +27,13 @@ module Fluent
|
|
25
27
|
end
|
26
28
|
|
27
29
|
def parse(text)
|
28
|
-
@parsers.
|
30
|
+
@parsers.each_with_index { |parser, i|
|
29
31
|
begin
|
30
32
|
parser.parse(text) { |time, record|
|
31
33
|
if time && record
|
34
|
+
if @format_key
|
35
|
+
record[@format_key] = @parser_format_names[i]
|
36
|
+
end
|
32
37
|
yield time, record
|
33
38
|
return
|
34
39
|
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require 'fluent/config'
|
2
|
+
require 'fluent/test'
|
3
|
+
require 'fluent/test/driver/parser'
|
4
|
+
require 'fluent/plugin/parser'
|
5
|
+
require 'fluent/plugin/parser_multi_format'
|
6
|
+
require 'test/unit'
|
7
|
+
|
8
|
+
class MultiFormatParserTest < ::Test::Unit::TestCase
|
9
|
+
def setup
|
10
|
+
Fluent::Test.setup
|
11
|
+
end
|
12
|
+
|
13
|
+
def create_driver(conf)
|
14
|
+
conf = Fluent::Config.parse(conf, "(test)", "(test_dir)", true)
|
15
|
+
Fluent::Test::Driver::Parser.new(Fluent::Plugin::MultiFormatParser.new).configure(conf)
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_configure
|
19
|
+
conf = %[
|
20
|
+
@type multi_format
|
21
|
+
<pattern>
|
22
|
+
format apache
|
23
|
+
</pattern>
|
24
|
+
<pattern>
|
25
|
+
format json
|
26
|
+
time_key timestamp
|
27
|
+
</pattern>
|
28
|
+
<pattern>
|
29
|
+
format none
|
30
|
+
</pattern>
|
31
|
+
]
|
32
|
+
d = create_driver(conf)
|
33
|
+
parsers = d.instance.instance_variable_get(:@parsers)
|
34
|
+
assert_instance_of(Fluent::Plugin::ApacheParser, parsers[0])
|
35
|
+
assert_instance_of(Fluent::Plugin::JSONParser, parsers[1])
|
36
|
+
assert_instance_of(Fluent::Plugin::NoneParser, parsers[2])
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_parse
|
40
|
+
conf = %[
|
41
|
+
@type multi_format
|
42
|
+
<pattern>
|
43
|
+
format apache
|
44
|
+
</pattern>
|
45
|
+
<pattern>
|
46
|
+
format json
|
47
|
+
time_key timestamp
|
48
|
+
</pattern>
|
49
|
+
<pattern>
|
50
|
+
format none
|
51
|
+
</pattern>
|
52
|
+
]
|
53
|
+
d = create_driver(conf)
|
54
|
+
d.instance.parse('{"k":"v"}') { |t, r|
|
55
|
+
assert_equal({"k" => "v"}, r)
|
56
|
+
}
|
57
|
+
d.instance.parse('hello') { |t, r|
|
58
|
+
assert_equal({"message" => "hello"}, r)
|
59
|
+
}
|
60
|
+
end
|
61
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fluent-plugin-multi-format-parser
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Masahiro Nakagawa
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-11-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: fluentd
|
@@ -44,12 +44,27 @@ dependencies:
|
|
44
44
|
- - ">="
|
45
45
|
- !ruby/object:Gem::Version
|
46
46
|
version: 0.9.2
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: test-unit
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - "~>"
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '3.3'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - "~>"
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '3.3'
|
47
61
|
description: Multi format parser plugin for Fluentd
|
48
62
|
email: repeatedly@gmail.com
|
49
63
|
executables: []
|
50
64
|
extensions: []
|
51
65
|
extra_rdoc_files: []
|
52
66
|
files:
|
67
|
+
- ".bundle/config"
|
53
68
|
- ".travis.yml"
|
54
69
|
- Gemfile
|
55
70
|
- README.md
|
@@ -57,11 +72,12 @@ files:
|
|
57
72
|
- VERSION
|
58
73
|
- fluent-plugin-multi-format-parser.gemspec
|
59
74
|
- lib/fluent/plugin/parser_multi_format.rb
|
75
|
+
- test/test_parser_multi_format.rb
|
60
76
|
homepage: https://github.com/repeatedly/fluent-plugin-multi-format-parser
|
61
77
|
licenses:
|
62
78
|
- Apache License (2.0)
|
63
79
|
metadata: {}
|
64
|
-
post_install_message:
|
80
|
+
post_install_message:
|
65
81
|
rdoc_options: []
|
66
82
|
require_paths:
|
67
83
|
- lib
|
@@ -76,9 +92,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
76
92
|
- !ruby/object:Gem::Version
|
77
93
|
version: '0'
|
78
94
|
requirements: []
|
79
|
-
|
80
|
-
|
81
|
-
signing_key:
|
95
|
+
rubygems_version: 3.4.1
|
96
|
+
signing_key:
|
82
97
|
specification_version: 4
|
83
98
|
summary: Multi format parser plugin for Fluentd
|
84
|
-
test_files:
|
99
|
+
test_files:
|
100
|
+
- test/test_parser_multi_format.rb
|