fluentd 0.14.1 → 0.14.2

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of fluentd might be problematic. Click here for more details.

Files changed (129) hide show
  1. checksums.yaml +4 -4
  2. data/ChangeLog +110 -1
  3. data/Rakefile +5 -1
  4. data/appveyor.yml +7 -1
  5. data/example/in_forward.conf +4 -0
  6. data/lib/fluent/compat/exec_util.rb +129 -0
  7. data/lib/fluent/compat/file_util.rb +54 -0
  8. data/lib/fluent/compat/filter.rb +21 -3
  9. data/lib/fluent/compat/formatter.rb +4 -2
  10. data/lib/fluent/compat/formatter_utils.rb +85 -0
  11. data/lib/fluent/compat/handle_tag_and_time_mixin.rb +60 -0
  12. data/lib/fluent/compat/input.rb +1 -3
  13. data/lib/fluent/compat/output.rb +95 -39
  14. data/lib/fluent/compat/parser.rb +17 -0
  15. data/lib/fluent/compat/parser_utils.rb +40 -0
  16. data/lib/fluent/compat/socket_util.rb +165 -0
  17. data/lib/fluent/compat/string_util.rb +34 -0
  18. data/lib/fluent/{test/driver/owner.rb → compat/structured_format_mixin.rb} +5 -11
  19. data/lib/fluent/config/element.rb +2 -2
  20. data/lib/fluent/configurable.rb +2 -1
  21. data/lib/fluent/event.rb +61 -7
  22. data/lib/fluent/event_router.rb +1 -1
  23. data/lib/fluent/plugin.rb +7 -7
  24. data/lib/fluent/plugin/buf_file.rb +5 -2
  25. data/lib/fluent/plugin/buffer.rb +194 -64
  26. data/lib/fluent/plugin/buffer/chunk.rb +28 -3
  27. data/lib/fluent/plugin/buffer/file_chunk.rb +5 -21
  28. data/lib/fluent/plugin/buffer/memory_chunk.rb +1 -11
  29. data/lib/fluent/plugin/exec_util.rb +2 -112
  30. data/lib/fluent/plugin/file_util.rb +3 -38
  31. data/lib/fluent/plugin/file_wrapper.rb +1 -1
  32. data/lib/fluent/plugin/filter_grep.rb +3 -7
  33. data/lib/fluent/plugin/filter_record_transformer.rb +5 -5
  34. data/lib/fluent/plugin/filter_stdout.rb +18 -11
  35. data/lib/fluent/plugin/formatter.rb +0 -48
  36. data/lib/fluent/plugin/formatter_csv.rb +7 -8
  37. data/lib/fluent/plugin/formatter_hash.rb +1 -4
  38. data/lib/fluent/plugin/formatter_json.rb +1 -4
  39. data/lib/fluent/plugin/formatter_ltsv.rb +5 -6
  40. data/lib/fluent/plugin/formatter_msgpack.rb +1 -4
  41. data/lib/fluent/plugin/formatter_out_file.rb +36 -3
  42. data/lib/fluent/plugin/formatter_stdout.rb +36 -1
  43. data/lib/fluent/plugin/in_dummy.rb +9 -2
  44. data/lib/fluent/plugin/in_exec.rb +20 -57
  45. data/lib/fluent/plugin/in_forward.rb +4 -3
  46. data/lib/fluent/plugin/in_object_space.rb +8 -44
  47. data/lib/fluent/plugin/in_syslog.rb +13 -24
  48. data/lib/fluent/plugin/in_tail.rb +3 -0
  49. data/lib/fluent/plugin/out_buffered_stdout.rb +14 -4
  50. data/lib/fluent/plugin/out_exec.rb +7 -5
  51. data/lib/fluent/plugin/out_exec_filter.rb +10 -10
  52. data/lib/fluent/plugin/out_file.rb +1 -3
  53. data/lib/fluent/plugin/out_forward.rb +38 -57
  54. data/lib/fluent/plugin/out_stdout.rb +14 -5
  55. data/lib/fluent/plugin/out_stream.rb +3 -0
  56. data/lib/fluent/plugin/output.rb +31 -14
  57. data/lib/fluent/plugin/parser.rb +0 -69
  58. data/lib/fluent/plugin/parser_apache.rb +10 -6
  59. data/lib/fluent/plugin/parser_apache_error.rb +8 -3
  60. data/lib/fluent/plugin/parser_csv.rb +3 -1
  61. data/lib/fluent/plugin/parser_json.rb +1 -1
  62. data/lib/fluent/plugin/parser_multiline.rb +5 -3
  63. data/lib/fluent/plugin/parser_nginx.rb +10 -6
  64. data/lib/fluent/plugin/parser_regexp.rb +73 -0
  65. data/lib/fluent/plugin/socket_util.rb +2 -148
  66. data/lib/fluent/plugin/storage_local.rb +1 -1
  67. data/lib/fluent/plugin/string_util.rb +3 -18
  68. data/lib/fluent/plugin_helper.rb +1 -0
  69. data/lib/fluent/plugin_helper/compat_parameters.rb +166 -41
  70. data/lib/fluent/plugin_helper/formatter.rb +30 -19
  71. data/lib/fluent/plugin_helper/inject.rb +25 -12
  72. data/lib/fluent/plugin_helper/parser.rb +22 -13
  73. data/lib/fluent/plugin_helper/storage.rb +22 -13
  74. data/lib/fluent/registry.rb +19 -6
  75. data/lib/fluent/supervisor.rb +27 -1
  76. data/lib/fluent/test/driver/base.rb +16 -92
  77. data/lib/fluent/test/driver/base_owned.rb +17 -53
  78. data/lib/fluent/test/driver/base_owner.rb +125 -0
  79. data/lib/fluent/test/driver/filter.rb +24 -2
  80. data/lib/fluent/test/driver/input.rb +2 -2
  81. data/lib/fluent/test/driver/multi_output.rb +2 -2
  82. data/lib/fluent/test/driver/output.rb +3 -5
  83. data/lib/fluent/test/helpers.rb +25 -0
  84. data/lib/fluent/test/input_test.rb +4 -4
  85. data/lib/fluent/test/output_test.rb +3 -3
  86. data/lib/fluent/version.rb +1 -1
  87. data/test/config/test_element.rb +135 -6
  88. data/test/plugin/test_buf_file.rb +71 -3
  89. data/test/plugin/test_buffer.rb +305 -86
  90. data/test/plugin/test_buffer_chunk.rb +60 -2
  91. data/test/plugin/test_buffer_file_chunk.rb +4 -3
  92. data/test/plugin/test_filter_grep.rb +25 -21
  93. data/test/plugin/test_filter_record_transformer.rb +75 -67
  94. data/test/plugin/test_filter_stdout.rb +171 -74
  95. data/test/plugin/test_formatter_csv.rb +94 -0
  96. data/test/plugin/test_formatter_json.rb +30 -0
  97. data/test/plugin/test_formatter_ltsv.rb +52 -0
  98. data/test/plugin/test_formatter_msgpack.rb +28 -0
  99. data/test/plugin/test_formatter_out_file.rb +95 -0
  100. data/test/plugin/test_formatter_single_value.rb +38 -0
  101. data/test/plugin/test_in_dummy.rb +95 -0
  102. data/test/plugin/test_in_exec.rb +27 -31
  103. data/test/plugin/test_in_forward.rb +24 -0
  104. data/test/plugin/test_in_gc_stat.rb +5 -5
  105. data/test/plugin/test_in_object_space.rb +4 -4
  106. data/test/plugin/test_in_syslog.rb +60 -35
  107. data/test/plugin/test_out_buffered_stdout.rb +17 -3
  108. data/test/plugin/test_out_forward.rb +93 -5
  109. data/test/plugin/test_out_stdout.rb +14 -3
  110. data/test/plugin/test_output_as_buffered_retries.rb +20 -0
  111. data/test/plugin/test_output_as_buffered_secondary.rb +16 -0
  112. data/test/plugin/test_output_as_standard.rb +22 -22
  113. data/test/plugin/test_parser_apache.rb +13 -9
  114. data/test/plugin/test_parser_apache_error.rb +11 -6
  115. data/test/plugin/test_parser_csv.rb +35 -25
  116. data/test/plugin/test_parser_nginx.rb +11 -5
  117. data/test/plugin/test_parser_regexp.rb +235 -68
  118. data/test/plugin/test_parser_tsv.rb +54 -58
  119. data/test/plugin_helper/test_compat_parameters.rb +111 -46
  120. data/test/plugin_helper/test_formatter.rb +40 -0
  121. data/test/plugin_helper/test_inject.rb +101 -2
  122. data/test/plugin_helper/test_parser.rb +40 -0
  123. data/test/plugin_helper/test_storage.rb +43 -0
  124. data/test/test_event.rb +93 -0
  125. data/test/test_event_router.rb +13 -4
  126. data/test/test_event_time.rb +0 -3
  127. data/test/test_formatter.rb +7 -164
  128. data/test/test_plugin_classes.rb +28 -1
  129. metadata +24 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3eae91c70d2df47e3cd6aeb7b1e80d44fd8ee41b
4
- data.tar.gz: 926661743f2177e7d116c1c7238d802b57fee63d
3
+ metadata.gz: 7907d31d5c45acece1bda509c0f893ce21196121
4
+ data.tar.gz: 37e214f67d98969b7cf77448600983411317b37b
5
5
  SHA512:
6
- metadata.gz: 3584a4e41dc1188a43c0f5b75ea8505662bae178bdc796dd3a2cc8d28395000c18cb9b13c55cc34c113bf5d704c571634ba0ea1709325cc255e88da2a0150e74
7
- data.tar.gz: 2f3836aea63fbaa48d761f2bce898f2925e130228c0c1b40e7115f2ccb0ce424aa7cd6200c0381b279f4358f3eef2e3d90e0f50ee0114441aaecc15250f1e2bd
6
+ metadata.gz: 37c4a7f40cc99f86f68b8418eff89443c7a9e45303ee2e873964992798df1639a35a67f8ea749e473408206d39770e51a7517442ba3db72432d7278dcc18c207
7
+ data.tar.gz: 38919ba08777c7b324026843e90b14a29acc14f4f8a8a069cc7acbeaa655a46a3eb03adf8ff115f52f76eb1e1a2bba4ce57b2c182719772d59ca3b13caad2bd7
data/ChangeLog CHANGED
@@ -1,5 +1,114 @@
1
1
  # v0.14
2
2
 
3
+ ## Release 0.14.1 - 2016/06/30
4
+
5
+ ### New features / Enhancement
6
+
7
+ * Fix to split large event stream into some/many chunks in buffers
8
+ https://github.com/fluent/fluentd/pull/1062
9
+ * Add parser and filter support in compat_parameters plugin helper
10
+ https://github.com/fluent/fluentd/pull/1079
11
+ * Add a RPC call to flush buffers and stop workers
12
+ https://github.com/fluent/fluentd/pull/1134
13
+ * Update forward protocol to pass the number of events in a payload
14
+ https://github.com/fluent/fluentd/pull/1137
15
+ * Improve performance of some built-in formatter plugins
16
+ https://github.com/fluent/fluentd/pull/1082
17
+ https://github.com/fluent/fluentd/pull/1086
18
+ * Migrate some built-in plugins and plugin util modules into v0.14 API
19
+ https://github.com/fluent/fluentd/pull/1058
20
+ https://github.com/fluent/fluentd/pull/1061
21
+ https://github.com/fluent/fluentd/pull/1076
22
+ https://github.com/fluent/fluentd/pull/1078
23
+ https://github.com/fluent/fluentd/pull/1081
24
+ https://github.com/fluent/fluentd/pull/1083
25
+ https://github.com/fluent/fluentd/pull/1091
26
+ * Register RegExpParser as a parser plugin explicitly
27
+ https://github.com/fluent/fluentd/pull/1094
28
+ * Add delimiter option to CSV parser
29
+ https://github.com/fluent/fluentd/pull/1108
30
+ * Add an option to receive longer udp syslog messages
31
+ https://github.com/fluent/fluentd/pull/1127
32
+ * Add a option to suspend internal status in dummy plugin
33
+ https://github.com/fluent/fluentd/pull/900
34
+ * Add a feature to capture filtered records in test driver for Filter plugins
35
+ https://github.com/fluent/fluentd/pull/1077
36
+ * Add some utility methods to plugin test drivers
37
+ https://github.com/fluent/fluentd/pull/1114
38
+
39
+ ### Bug fixes
40
+
41
+ * Fix bug to read non buffer-chunk files as buffer chunks when Fluentd resumed
42
+ https://github.com/fluent/fluentd/pull/1124
43
+ * Fix bug not to load Filter plugins which are specified in configurations
44
+ https://github.com/fluent/fluentd/pull/1118
45
+ * Fix bug to ignore `-p` option to specify directories of plugins
46
+ https://github.com/fluent/fluentd/pull/1133
47
+ * Fix bug to overwrite base class configuration section definitions by subclasses
48
+ https://github.com/fluent/fluentd/pull/1119
49
+ * Fix to stop Fluentd worker process by Ctrl-C when --no-supervisor specified
50
+ https://github.com/fluent/fluentd/pull/1089
51
+ * Fix regression about RPC call to reload configuration
52
+ https://github.com/fluent/fluentd/pull/1093
53
+ * Specify to ensure Oj JSON parser to use strict mode
54
+ https://github.com/fluent/fluentd/pull/1147
55
+ * Fix unexisting path handling in Windows environment
56
+ https://github.com/fluent/fluentd/pull/1104
57
+
58
+ ## Release 0.14.1 - 2016/06/30
59
+
60
+ ### New features / Enhancement
61
+
62
+ * Add plugin helpers for parsers and formatters
63
+ https://github.com/fluent/fluentd/pull/1023
64
+ * Extract some mixins into compat modules
65
+ https://github.com/fluent/fluentd/pull/1044
66
+ https://github.com/fluent/fluentd/pull/1052
67
+ * Add utility methods for tests and test drivers
68
+ https://github.com/fluent/fluentd/pull/1047
69
+ * Migrate some built-in plugins to v0.14 APIs
70
+ https://github.com/fluent/fluentd/pull/1049
71
+ https://github.com/fluent/fluentd/pull/1057
72
+ https://github.com/fluent/fluentd/pull/1060
73
+ https://github.com/fluent/fluentd/pull/1064
74
+ * Add support of X-Forwarded-For header in in_http plugin
75
+ https://github.com/fluent/fluentd/pull/1051
76
+ * Warn not to create too many staged chunks at configure
77
+ https://github.com/fluent/fluentd/pull/1054
78
+ * Add a plugin helper to inject tag/time/hostname
79
+ https://github.com/fluent/fluentd/pull/1063
80
+
81
+ ### Bug fixes
82
+
83
+ * Fix in_monitor_agent for v0.14 plugins
84
+ https://github.com/fluent/fluentd/pull/1003
85
+ * Fix to call #format_stream of plugins themselves when RecordFilter mixin included
86
+ https://github.com/fluent/fluentd/pull/1005
87
+ * Fix shutdown sequence to wait force flush
88
+ https://github.com/fluent/fluentd/pull/1009
89
+ * Fix a deadlock bug in shutdown
90
+ https://github.com/fluent/fluentd/pull/1010
91
+ * Fix to require DetachProcessMixin in default for compat plugins
92
+ https://github.com/fluent/fluentd/pull/1014
93
+ * Fix to overwrite configure_proxy name only for root sections for debugging
94
+ https://github.com/fluent/fluentd/pull/1015
95
+ * Rename file for in_unix plugin
96
+ https://github.com/fluent/fluentd/pull/1017
97
+ * Fix a bug not to create pid file when daemonized
98
+ https://github.com/fluent/fluentd/pull/1021
99
+ * Fix wrong DEFAULT_PLUGIN_PATH
100
+ https://github.com/fluent/fluentd/pull/1028
101
+ * Fix a bug not to use primary plugin type for secondary in default
102
+ https://github.com/fluent/fluentd/pull/1032
103
+ * Add --run-worker option to distinguish to run as worker without supervisor
104
+ https://github.com/fluent/fluentd/pull/1033
105
+ * Fix regression of fluent-debug command
106
+ https://github.com/fluent/fluentd/pull/1046
107
+ * Update windows-pr dependency to 1.2.5
108
+ https://github.com/fluent/fluentd/pull/1065
109
+ * Fix supervisor to pass RUBYOPT to worker processes
110
+ https://github.com/fluent/fluentd/pull/1066
111
+
3
112
  ## Release 0.14.0 - 2016/05/25
4
113
 
5
114
  ### New features / Enhancement
@@ -81,7 +190,7 @@ This list includes changes of 0.14.0.pre.1 and release candidates.
81
190
 
82
191
  * Fix dependencies between files
83
192
  https://github.com/fluent/fluentd/pull/799
84
- https://github.com/fluent/fluentd/pull/808
193
+ https://github.com/fluent/fluentd/pull/808
85
194
  https://github.com/fluent/fluentd/pull/823
86
195
  https://github.com/fluent/fluentd/pull/824
87
196
  https://github.com/fluent/fluentd/pull/825
data/Rakefile CHANGED
@@ -13,7 +13,11 @@ Rake::TestTask.new(:base_test) do |t|
13
13
  # $ bundle exec rake base_test TEST=test/test_specified_path.rb
14
14
  # $ bundle exec rake base_test TEST=test/test_*.rb
15
15
  t.libs << "test"
16
- t.test_files = Dir["test/**/test_*.rb"].sort
16
+ t.test_files = if ENV["WIN_RAPID"]
17
+ ["test/test_event.rb", "test/test_supervisor.rb", "test/plugin_helper/test_event_loop.rb"]
18
+ else
19
+ Dir["test/**/test_*.rb"].sort
20
+ end
17
21
  t.verbose = true
18
22
  t.warning = true
19
23
  t.ruby_opts = ["-Eascii-8bit:ascii-8bit"]
@@ -11,7 +11,7 @@ install:
11
11
  - bundle install
12
12
  build: off
13
13
  test_script:
14
- - bundle exec rake test TESTOPTS=-v
14
+ - bundle exec rake test
15
15
 
16
16
  branches:
17
17
  only:
@@ -22,14 +22,20 @@ branches:
22
22
 
23
23
  environment:
24
24
  matrix:
25
+ - ruby_version: "23-x64"
26
+ devkit: C:\Ruby23-x64\DevKit
27
+ - ruby_version: "23"
28
+ devkit: C:\Ruby23\DevKit
25
29
  - ruby_version: "22-x64"
26
30
  devkit: C:\Ruby23-x64\DevKit
27
31
  - ruby_version: "22"
28
32
  devkit: C:\Ruby23\DevKit
33
+ WIN_RAPID: true
29
34
  - ruby_version: "21-x64"
30
35
  devkit: C:\Ruby23-x64\DevKit
31
36
  - ruby_version: "21"
32
37
  devkit: C:\Ruby23\DevKit
38
+ WIN_RAPID: true
33
39
  matrix:
34
40
  allow_failures:
35
41
  - ruby_version: "21"
@@ -1,3 +1,7 @@
1
+ <system>
2
+ rpc_endpoint 0.0.0.0:24444
3
+ </system>
4
+
1
5
  <source>
2
6
  @type forward
3
7
  </source>
@@ -0,0 +1,129 @@
1
+ #
2
+ # Fluentd
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
17
+ require 'msgpack'
18
+ require 'yajl'
19
+
20
+ require 'fluent/engine'
21
+ require 'fluent/plugin'
22
+ require 'fluent/parser'
23
+
24
+ module Fluent
25
+ module Compat
26
+ module ExecUtil
27
+ SUPPORTED_FORMAT = {
28
+ 'tsv' => :tsv,
29
+ 'json' => :json,
30
+ 'msgpack' => :msgpack,
31
+ }
32
+
33
+ class Parser
34
+ def initialize(on_message)
35
+ @on_message = on_message
36
+ end
37
+ end
38
+
39
+ class TextParserWrapperParser < Parser
40
+ def initialize(conf, on_message)
41
+ @parser = Plugin.new_parser(conf['format'])
42
+ @parser.configure(conf)
43
+ super(on_message)
44
+ end
45
+
46
+ def call(io)
47
+ io.each_line(&method(:each_line))
48
+ end
49
+
50
+ def each_line(line)
51
+ line.chomp!
52
+ @parser.parse(line) { |time, record|
53
+ @on_message.call(record, time)
54
+ }
55
+ end
56
+ end
57
+
58
+ class TSVParser < Parser
59
+ def initialize(keys, on_message)
60
+ @keys = keys
61
+ super(on_message)
62
+ end
63
+
64
+ def call(io)
65
+ io.each_line(&method(:each_line))
66
+ end
67
+
68
+ def each_line(line)
69
+ line.chomp!
70
+ vals = line.split("\t")
71
+
72
+ record = Hash[@keys.zip(vals)]
73
+
74
+ @on_message.call(record)
75
+ end
76
+ end
77
+
78
+ class JSONParser < Parser
79
+ def call(io)
80
+ y = Yajl::Parser.new
81
+ y.on_parse_complete = @on_message
82
+ y.parse(io)
83
+ end
84
+ end
85
+
86
+ class MessagePackParser < Parser
87
+ def call(io)
88
+ @u = Fluent::Engine.msgpack_factory.unpacker(io)
89
+ begin
90
+ @u.each(&@on_message)
91
+ rescue EOFError
92
+ end
93
+ end
94
+ end
95
+
96
+ class Formatter
97
+ end
98
+
99
+ class TSVFormatter < Formatter
100
+ def initialize(in_keys)
101
+ @in_keys = in_keys
102
+ super()
103
+ end
104
+
105
+ def call(record, out)
106
+ last = @in_keys.length-1
107
+ for i in 0..last
108
+ key = @in_keys[i]
109
+ out << record[key].to_s
110
+ out << "\t" if i != last
111
+ end
112
+ out << "\n"
113
+ end
114
+ end
115
+
116
+ class JSONFormatter < Formatter
117
+ def call(record, out)
118
+ out << Yajl.dump(record) << "\n"
119
+ end
120
+ end
121
+
122
+ class MessagePackFormatter < Formatter
123
+ def call(record, out)
124
+ record.to_msgpack(out)
125
+ end
126
+ end
127
+ end
128
+ end
129
+ end
@@ -0,0 +1,54 @@
1
+ #
2
+ # Fluentd
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
17
+ module Fluent
18
+ module Compat
19
+ module FileUtil
20
+ # Check file is writable if file exists
21
+ # Check directory is writable if file does not exist
22
+ #
23
+ # @param [String] path File path
24
+ # @return [Boolean] file is writable or not
25
+ def writable?(path)
26
+ return false if File.directory?(path)
27
+ return File.writable?(path) if File.exist?(path)
28
+
29
+ dirname = File.dirname(path)
30
+ return false if !File.directory?(dirname)
31
+ File.writable?(dirname)
32
+ end
33
+ module_function :writable?
34
+
35
+ # Check file is writable in conjunction wtih mkdir_p(dirname(path))
36
+ #
37
+ # @param [String] path File path
38
+ # @return [Boolean] file writable or not
39
+ def writable_p?(path)
40
+ return false if File.directory?(path)
41
+ return File.writable?(path) if File.exist?(path)
42
+
43
+ dirname = File.dirname(path)
44
+ until File.exist?(dirname)
45
+ dirname = File.dirname(dirname)
46
+ end
47
+
48
+ return false if !File.directory?(dirname)
49
+ File.writable?(dirname)
50
+ end
51
+ module_function :writable_p?
52
+ end
53
+ end
54
+ end
@@ -17,25 +17,43 @@
17
17
  require 'fluent/plugin'
18
18
  require 'fluent/plugin/filter'
19
19
  require 'fluent/compat/call_super_mixin'
20
+ require 'fluent/compat/formatter_utils'
21
+ require 'fluent/compat/parser_utils'
20
22
 
21
23
  module Fluent
22
24
  module Compat
23
25
  class Filter < Fluent::Plugin::Filter
24
26
  # TODO: warn when deprecated
25
27
 
28
+ helpers :inject
29
+
26
30
  def initialize
27
31
  super
28
32
  unless self.class.ancestors.include?(Fluent::Compat::CallSuperMixin)
29
- self.class.module_eval do
30
- prepend Fluent::Compat::CallSuperMixin
31
- end
33
+ self.class.prepend Fluent::Compat::CallSuperMixin
32
34
  end
33
35
  end
34
36
 
37
+ def configure(conf)
38
+ ParserUtils.convert_parser_conf(conf)
39
+ FormatterUtils.convert_formatter_conf(conf)
40
+
41
+ super
42
+ end
43
+
35
44
  # These definitions are to get instance methods of superclass of 3rd party plugins
36
45
  # to make it sure to call super
37
46
  def start
38
47
  super
48
+
49
+ if instance_variable_defined?(:@formatter) && @inject_config
50
+ unless @formatter.class.ancestors.include?(Fluent::Compat::HandleTagAndTimeMixin)
51
+ if @formatter.respond_to?(:owner) && !@formatter.owner
52
+ @formatter.owner = self
53
+ @formatter.singleton_class.prepend FormatterUtils::InjectMixin
54
+ end
55
+ end
56
+ end
39
57
  end
40
58
 
41
59
  def before_shutdown
@@ -16,6 +16,8 @@
16
16
 
17
17
  require 'fluent/plugin'
18
18
  require 'fluent/plugin/formatter'
19
+ require 'fluent/compat/handle_tag_and_time_mixin'
20
+ require 'fluent/compat/structured_format_mixin'
19
21
 
20
22
  require 'fluent/plugin/formatter_out_file'
21
23
  require 'fluent/plugin/formatter_stdout'
@@ -66,8 +68,8 @@ module Fluent
66
68
  formatter
67
69
  end
68
70
 
69
- HandleTagAndTimeMixin = Fluent::Plugin::Formatter::HandleTagAndTimeMixin
70
- StructuredFormatMixin = Fluent::Plugin::Formatter::StructuredFormatMixin
71
+ HandleTagAndTimeMixin = Fluent::Compat::HandleTagAndTimeMixin
72
+ StructuredFormatMixin = Fluent::Compat::StructuredFormatMixin
71
73
 
72
74
  class ProcWrappedFormatter < Fluent::Plugin::ProcWrappedFormatter
73
75
  # TODO: warn when deprecated
@@ -0,0 +1,85 @@
1
+ #
2
+ # Fluentd
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
17
+ require 'fluent/plugin_helper/compat_parameters'
18
+
19
+ module Fluent
20
+ module Compat
21
+ module FormatterUtils
22
+ INJECT_PARAMS = Fluent::PluginHelper::CompatParameters::INJECT_PARAMS
23
+ FORMATTER_PARAMS = Fluent::PluginHelper::CompatParameters::FORMATTER_PARAMS
24
+
25
+ module InjectMixin
26
+ def format(tag, time, record)
27
+ r = owner.inject_values_to_record(tag, time, record)
28
+ super(tag, time, r)
29
+ end
30
+ end
31
+
32
+ def self.convert_formatter_conf(conf)
33
+ return if conf.elements(name: 'inject').first || conf.elements(name: 'format').first
34
+
35
+ inject_params = {}
36
+ INJECT_PARAMS.each do |older, newer|
37
+ next unless newer
38
+ if conf.has_key?(older)
39
+ inject_params[newer] = conf[older]
40
+ end
41
+ end
42
+
43
+ if conf.has_key?('include_time_key') && Fluent::Config.bool_value(conf['include_time_key'])
44
+ inject_params['time_key'] ||= 'time'
45
+ inject_params['time_type'] ||= 'string'
46
+ end
47
+ if conf.has_key?('time_as_epoch') && Fluent::Config.bool_value(conf['time_as_epoch'])
48
+ inject_params['time_type'] = 'unixtime'
49
+ end
50
+ if conf.has_key?('localtime') || conf.has_key?('utc')
51
+ if conf.has_key?('localtime') && conf.has_key?('utc')
52
+ raise Fluent::ConfigError, "both of utc and localtime are specified, use only one of them"
53
+ elsif conf.has_key?('localtime')
54
+ inject_params['localtime'] = Fluent::Config.bool_value(conf['localtime'])
55
+ elsif conf.has_key?('utc')
56
+ inject_params['localtime'] = !(Fluent::Config.bool_value(conf['utc']))
57
+ # Specifying "localtime false" means using UTC in TimeFormatter
58
+ # And specifying "utc" is different from specifying "timezone +0000"(it's not always UTC).
59
+ # There are difference between "Z" and "+0000" in timezone formatting.
60
+ # TODO: add kwargs to TimeFormatter to specify "using localtime", "using UTC" or "using specified timezone" in more explicit way
61
+ end
62
+ end
63
+
64
+ if conf.has_key?('include_tag_key') && Fluent::Config.bool_value(conf['include_tag_key'])
65
+ inject_params['tag_key'] ||= 'tag'
66
+ end
67
+
68
+ unless inject_params.empty?
69
+ conf.elements << Fluent::Config::Element.new('inject', '', inject_params, [])
70
+ end
71
+
72
+ formatter_params = {}
73
+ FORMATTER_PARAMS.each do |older, newer|
74
+ next unless newer
75
+ if conf.has_key?(older)
76
+ formatter_params[newer] = conf[older]
77
+ end
78
+ end
79
+ unless formatter_params.empty?
80
+ conf.elements << Fluent::Config::Element.new('format', '', formatter_params, [])
81
+ end
82
+ end
83
+ end
84
+ end
85
+ end