fluentd 0.10.62 → 0.12.0.pre.1

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 (140) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -2
  3. data/.travis.yml +0 -4
  4. data/ChangeLog +0 -72
  5. data/Gemfile +0 -6
  6. data/Rakefile +12 -3
  7. data/example/in_http.conf +14 -0
  8. data/example/in_syslog.conf +15 -0
  9. data/example/in_tail.conf +14 -0
  10. data/example/in_tcp.conf +13 -0
  11. data/example/in_udp.conf +13 -0
  12. data/example/out_copy.conf +20 -0
  13. data/example/out_file.conf +13 -0
  14. data/example/out_forward.conf +30 -0
  15. data/fluent.conf +2 -12
  16. data/fluentd.gemspec +8 -11
  17. data/lib/fluent/agent.rb +180 -0
  18. data/lib/fluent/buffer.rb +6 -12
  19. data/lib/fluent/command/cat.rb +1 -3
  20. data/lib/fluent/command/debug.rb +1 -3
  21. data/lib/fluent/command/fluentd.rb +0 -10
  22. data/lib/fluent/config.rb +9 -3
  23. data/lib/fluent/config/basic_parser.rb +1 -6
  24. data/lib/fluent/config/configure_proxy.rb +25 -61
  25. data/lib/fluent/config/dsl.rb +16 -0
  26. data/lib/fluent/config/element.rb +21 -2
  27. data/lib/fluent/config/error.rb +16 -0
  28. data/lib/fluent/config/literal_parser.rb +9 -27
  29. data/lib/fluent/config/parser.rb +16 -0
  30. data/lib/fluent/config/section.rb +16 -2
  31. data/lib/fluent/config/types.rb +16 -1
  32. data/lib/fluent/config/v1_parser.rb +4 -12
  33. data/lib/fluent/configurable.rb +16 -0
  34. data/lib/fluent/engine.rb +43 -163
  35. data/lib/fluent/env.rb +16 -1
  36. data/lib/fluent/event.rb +20 -48
  37. data/lib/fluent/event_router.rb +187 -0
  38. data/lib/fluent/filter.rb +32 -0
  39. data/lib/fluent/formatter.rb +29 -101
  40. data/lib/fluent/input.rb +6 -4
  41. data/lib/fluent/label.rb +18 -0
  42. data/lib/fluent/load.rb +1 -3
  43. data/lib/fluent/log.rb +1 -3
  44. data/lib/fluent/match.rb +12 -19
  45. data/lib/fluent/mixin.rb +9 -25
  46. data/lib/fluent/output.rb +27 -45
  47. data/lib/fluent/parser.rb +93 -99
  48. data/lib/fluent/plugin.rb +22 -48
  49. data/lib/fluent/plugin/buf_file.rb +10 -7
  50. data/lib/fluent/plugin/buf_memory.rb +2 -3
  51. data/lib/fluent/plugin/buf_zfile.rb +75 -0
  52. data/lib/fluent/plugin/exec_util.rb +16 -0
  53. data/lib/fluent/plugin/in_debug_agent.rb +2 -3
  54. data/lib/fluent/plugin/in_exec.rb +2 -9
  55. data/lib/fluent/plugin/in_forward.rb +4 -22
  56. data/lib/fluent/plugin/in_gc_stat.rb +2 -3
  57. data/lib/fluent/plugin/in_http.rb +19 -59
  58. data/lib/fluent/plugin/in_monitor_agent.rb +21 -47
  59. data/lib/fluent/plugin/in_object_space.rb +2 -3
  60. data/lib/fluent/plugin/in_status.rb +2 -3
  61. data/lib/fluent/plugin/in_stream.rb +6 -16
  62. data/lib/fluent/plugin/in_syslog.rb +8 -17
  63. data/lib/fluent/plugin/in_tail.rb +17 -24
  64. data/lib/fluent/plugin/in_tcp.rb +16 -0
  65. data/lib/fluent/plugin/in_udp.rb +16 -0
  66. data/lib/fluent/plugin/out_copy.rb +3 -4
  67. data/lib/fluent/plugin/out_exec.rb +2 -4
  68. data/lib/fluent/plugin/out_exec_filter.rb +2 -13
  69. data/lib/fluent/plugin/out_file.rb +5 -6
  70. data/lib/fluent/plugin/out_forward.rb +4 -5
  71. data/lib/fluent/plugin/out_null.rb +2 -3
  72. data/lib/fluent/plugin/out_relabel.rb +26 -0
  73. data/lib/fluent/plugin/out_roundrobin.rb +3 -4
  74. data/lib/fluent/plugin/out_stdout.rb +2 -3
  75. data/lib/fluent/plugin/out_stream.rb +2 -3
  76. data/{test/scripts → lib}/fluent/plugin/out_test.rb +2 -3
  77. data/lib/fluent/plugin/socket_util.rb +19 -10
  78. data/lib/fluent/process.rb +4 -6
  79. data/lib/fluent/registry.rb +16 -0
  80. data/lib/fluent/root_agent.rb +212 -0
  81. data/lib/fluent/status.rb +2 -3
  82. data/lib/fluent/supervisor.rb +33 -54
  83. data/lib/fluent/test.rb +16 -0
  84. data/lib/fluent/test/base.rb +3 -17
  85. data/lib/fluent/test/input_test.rb +52 -7
  86. data/lib/fluent/test/output_test.rb +4 -20
  87. data/lib/fluent/version.rb +17 -1
  88. data/spec/config/config_parser_spec.rb +314 -0
  89. data/spec/config/configurable_spec.rb +524 -0
  90. data/spec/config/configure_proxy_spec.rb +96 -0
  91. data/spec/config/dsl_spec.rb +239 -0
  92. data/spec/config/helper.rb +49 -0
  93. data/spec/config/literal_parser_spec.rb +222 -0
  94. data/spec/config/section_spec.rb +97 -0
  95. data/spec/config/system_config_spec.rb +49 -0
  96. data/test/helper.rb +0 -25
  97. data/test/plugin/test_in_exec.rb +1 -1
  98. data/test/plugin/test_in_forward.rb +2 -1
  99. data/test/plugin/test_in_gc_stat.rb +1 -1
  100. data/test/plugin/test_in_http.rb +3 -78
  101. data/test/plugin/test_in_object_space.rb +1 -1
  102. data/test/plugin/test_in_status.rb +1 -1
  103. data/test/plugin/test_in_stream.rb +2 -1
  104. data/test/plugin/test_in_syslog.rb +2 -1
  105. data/test/plugin/test_in_tail.rb +6 -11
  106. data/test/plugin/test_in_tcp.rb +2 -1
  107. data/test/plugin/test_in_udp.rb +2 -1
  108. data/test/plugin/test_out_copy.rb +1 -12
  109. data/test/plugin/test_out_exec.rb +1 -1
  110. data/test/plugin/test_out_exec_filter.rb +1 -1
  111. data/test/plugin/test_out_file.rb +7 -96
  112. data/test/plugin/test_out_forward.rb +2 -1
  113. data/test/plugin/test_out_roundrobin.rb +1 -12
  114. data/test/plugin/test_out_stdout.rb +1 -1
  115. data/test/plugin/test_out_stream.rb +2 -1
  116. data/test/scripts/fluent/plugin/formatter_known.rb +1 -4
  117. data/test/scripts/fluent/plugin/parser_known.rb +1 -2
  118. data/test/test_config.rb +1 -1
  119. data/test/test_configdsl.rb +2 -1
  120. data/test/test_formatter.rb +3 -395
  121. data/test/test_match.rb +2 -1
  122. data/test/test_mixin.rb +3 -75
  123. data/test/test_output.rb +1 -112
  124. data/test/test_parser.rb +85 -152
  125. metadata +58 -167
  126. data/example/v1_literal_example.conf +0 -36
  127. data/lib/fluent/plugin/in_dummy.rb +0 -103
  128. data/lib/fluent/timezone.rb +0 -131
  129. data/test/config/assertions.rb +0 -42
  130. data/test/config/test_config_parser.rb +0 -389
  131. data/test/config/test_configurable.rb +0 -652
  132. data/test/config/test_configure_proxy.rb +0 -99
  133. data/test/config/test_dsl.rb +0 -237
  134. data/test/config/test_literal_parser.rb +0 -295
  135. data/test/config/test_section.rb +0 -112
  136. data/test/config/test_system_config.rb +0 -99
  137. data/test/config/test_types.rb +0 -63
  138. data/test/plugin/test_in_dummy.rb +0 -95
  139. data/test/test_event.rb +0 -168
  140. data/test/test_input.rb +0 -21
@@ -1,3 +1,19 @@
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
+
1
17
  require 'fluent/plugin/socket_util'
2
18
 
3
19
  module Fluent
@@ -1,7 +1,5 @@
1
1
  #
2
- # Fluent
3
- #
4
- # Copyright (C) 2011 FURUHASHI Sadayuki
2
+ # Fluentd
5
3
  #
6
4
  # Licensed under the Apache License, Version 2.0 (the "License");
7
5
  # you may not use this file except in compliance with the License.
@@ -15,6 +13,7 @@
15
13
  # See the License for the specific language governing permissions and
16
14
  # limitations under the License.
17
15
  #
16
+
18
17
  module Fluent
19
18
  class CopyOutput < MultiOutput
20
19
  Plugin.register_output('copy', self)
@@ -33,7 +32,7 @@ module Fluent
33
32
  conf.elements.select {|e|
34
33
  e.name == 'store'
35
34
  }.each {|e|
36
- type = e['@type'] || e['type']
35
+ type = e['type']
37
36
  unless type
38
37
  raise ConfigError, "Missing 'type' parameter on <store> directive"
39
38
  end
@@ -1,7 +1,5 @@
1
1
  #
2
- # Fluent
3
- #
4
- # Copyright (C) 2011 FURUHASHI Sadayuki
2
+ # Fluentd
5
3
  #
6
4
  # Licensed under the Apache License, Version 2.0 (the "License");
7
5
  # you may not use this file except in compliance with the License.
@@ -58,7 +56,7 @@ module Fluent
58
56
 
59
57
  if @time_key
60
58
  if @time_format
61
- tf = TimeFormatter.new(@time_format, @localtime, @timezone)
59
+ tf = TimeFormatter.new(@time_format, @localtime)
62
60
  @time_format_proc = tf.method(:format)
63
61
  else
64
62
  @time_format_proc = Proc.new { |time| time.to_s }
@@ -1,7 +1,5 @@
1
1
  #
2
- # Fluent
3
- #
4
- # Copyright (C) 2011 FURUHASHI Sadayuki
2
+ # Fluentd
5
3
  #
6
4
  # Licensed under the Apache License, Version 2.0 (the "License");
7
5
  # you may not use this file except in compliance with the License.
@@ -24,7 +22,6 @@ module Fluent
24
22
 
25
23
  def initialize
26
24
  super
27
- require 'fluent/timezone'
28
25
  end
29
26
 
30
27
  config_param :command, :string
@@ -62,7 +59,6 @@ module Fluent
62
59
  config_param :time_format, :string, :default => nil
63
60
 
64
61
  config_param :localtime, :bool, :default => true
65
- config_param :timezone, :string, :default => nil
66
62
  config_param :num_children, :integer, :default => 1
67
63
 
68
64
  # nil, 'none' or 0: no respawn, 'inf' or -1: infinite times, positive integer: try to respawn specified times only
@@ -100,18 +96,13 @@ module Fluent
100
96
  @localtime = false
101
97
  end
102
98
 
103
- if conf['timezone']
104
- @timezone = conf['timezone']
105
- Fluent::Timezone.validate!(@timezone)
106
- end
107
-
108
99
  if !@tag && !@out_tag_key
109
100
  raise ConfigError, "'tag' or 'out_tag_key' option is required on exec_filter output"
110
101
  end
111
102
 
112
103
  if @in_time_key
113
104
  if f = @in_time_format
114
- tf = TimeFormatter.new(f, @localtime, @timezone)
105
+ tf = TimeFormatter.new(f, @localtime)
115
106
  @time_format_proc = tf.method(:format)
116
107
  else
117
108
  @time_format_proc = Proc.new {|time| time.to_s }
@@ -354,7 +345,6 @@ module Fluent
354
345
  end
355
346
 
356
347
  router.emit(tag, time, record)
357
-
358
348
  rescue
359
349
  if @suppress_error_log_interval == 0 || Time.now.to_i > @next_log_time
360
350
  log.error "exec_filter failed to emit", :error=>$!.to_s, :error_class=>$!.class.to_s, :record=>Yajl.dump(record)
@@ -364,4 +354,3 @@ module Fluent
364
354
  end
365
355
  end
366
356
  end
367
-
@@ -1,7 +1,5 @@
1
1
  #
2
- # Fluent
3
- #
4
- # Copyright (C) 2011 FURUHASHI Sadayuki
2
+ # Fluentd
5
3
  #
6
4
  # Licensed under the Apache License, Version 2.0 (the "License");
7
5
  # you may not use this file except in compliance with the License.
@@ -15,6 +13,7 @@
15
13
  # See the License for the specific language governing permissions and
16
14
  # limitations under the License.
17
15
  #
16
+
18
17
  module Fluent
19
18
  class FileOutput < TimeSlicedOutput
20
19
  Plugin.register_output('file', self)
@@ -62,8 +61,8 @@ module Fluent
62
61
 
63
62
  super
64
63
 
65
- @formatter = Plugin.new_formatter(@format)
66
- @formatter.configure(conf)
64
+ conf['format'] = @format
65
+ @formatter = TextFormatter.create(conf)
67
66
 
68
67
  @buffer.symlink_path = @symlink_path if @symlink_path
69
68
  end
@@ -74,7 +73,7 @@ module Fluent
74
73
 
75
74
  def write(chunk)
76
75
  path = generate_path(chunk)
77
- FileUtils.mkdir_p File.dirname(path), :mode => DEFAULT_DIR_PERMISSION
76
+ FileUtils.mkdir_p File.dirname(path)
78
77
 
79
78
  case @compress
80
79
  when nil
@@ -1,7 +1,5 @@
1
1
  #
2
- # Fluent
3
- #
4
- # Copyright (C) 2011 FURUHASHI Sadayuki
2
+ # Fluentd
5
3
  #
6
4
  # Licensed under the Apache License, Version 2.0 (the "License");
7
5
  # you may not use this file except in compliance with the License.
@@ -15,6 +13,7 @@
15
13
  # See the License for the specific language governing permissions and
16
14
  # limitations under the License.
17
15
  #
16
+
18
17
  module Fluent
19
18
  class ForwardOutput < ObjectBufferedOutput
20
19
  Plugin.register_output('forward', self)
@@ -87,7 +86,7 @@ module Fluent
87
86
  node_conf = NodeConfig.new(name, host, port, weight, standby, failure,
88
87
  @phi_threshold, recover_sample_size, @expire_dns_cache, @phi_failure_detector)
89
88
  @nodes << Node.new(log, node_conf)
90
- log.info "adding forwarding server '#{name}'", :host=>host, :port=>port, :weight=>weight, :plugin_id=>plugin_id
89
+ log.info "adding forwarding server '#{name}'", :host=>host, :port=>port, :weight=>weight
91
90
  }
92
91
  end
93
92
 
@@ -288,7 +287,7 @@ module Fluent
288
287
  else
289
288
  @usock.send "\0", 0, Socket.pack_sockaddr_in(n.port, n.resolved_host)
290
289
  end
291
- rescue Errno::EAGAIN, Errno::EWOULDBLOCK, Errno::EINTR, Errno::ECONNREFUSED
290
+ rescue Errno::EAGAIN, Errno::EWOULDBLOCK, Errno::EINTR
292
291
  # TODO log
293
292
  log.debug "failed to send heartbeat packet to #{n.host}:#{n.port}", :error=>$!.to_s
294
293
  end
@@ -1,7 +1,5 @@
1
1
  #
2
- # Fluent
3
- #
4
- # Copyright (C) 2011 FURUHASHI Sadayuki
2
+ # Fluentd
5
3
  #
6
4
  # Licensed under the Apache License, Version 2.0 (the "License");
7
5
  # you may not use this file except in compliance with the License.
@@ -15,6 +13,7 @@
15
13
  # See the License for the specific language governing permissions and
16
14
  # limitations under the License.
17
15
  #
16
+
18
17
  module Fluent
19
18
  class NullOutput < Output
20
19
  Plugin.register_output('null', self)
@@ -0,0 +1,26 @@
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
+ class RelabelOutput < Output
19
+ Plugin.register_output('relabel', self)
20
+
21
+ def emit(tag, es, chain)
22
+ router.emit_stream(tag, es)
23
+ chain.next
24
+ end
25
+ end
26
+ end
@@ -1,7 +1,5 @@
1
1
  #
2
- # Fluent
3
- #
4
- # Copyright (C) 2011 FURUHASHI Sadayuki
2
+ # Fluentd
5
3
  #
6
4
  # Licensed under the Apache License, Version 2.0 (the "License");
7
5
  # you may not use this file except in compliance with the License.
@@ -15,6 +13,7 @@
15
13
  # See the License for the specific language governing permissions and
16
14
  # limitations under the License.
17
15
  #
16
+
18
17
  module Fluent
19
18
  class RoundRobinOutput < MultiOutput
20
19
  Plugin.register_output('roundrobin', self)
@@ -35,7 +34,7 @@ module Fluent
35
34
  conf.elements.select {|e|
36
35
  e.name == 'store'
37
36
  }.each {|e|
38
- type = e['@type'] || e['type']
37
+ type = e['type']
39
38
  unless type
40
39
  raise ConfigError, "Missing 'type' parameter on <store> directive"
41
40
  end
@@ -1,7 +1,5 @@
1
1
  #
2
- # Fluent
3
- #
4
- # Copyright (C) 2011 FURUHASHI Sadayuki
2
+ # Fluentd
5
3
  #
6
4
  # Licensed under the Apache License, Version 2.0 (the "License");
7
5
  # you may not use this file except in compliance with the License.
@@ -15,6 +13,7 @@
15
13
  # See the License for the specific language governing permissions and
16
14
  # limitations under the License.
17
15
  #
16
+
18
17
  module Fluent
19
18
  class StdoutOutput < Output
20
19
  Plugin.register_output('stdout', self)
@@ -1,7 +1,5 @@
1
1
  #
2
- # Fluent
3
- #
4
- # Copyright (C) 2011 FURUHASHI Sadayuki
2
+ # Fluentd
5
3
  #
6
4
  # Licensed under the Apache License, Version 2.0 (the "License");
7
5
  # you may not use this file except in compliance with the License.
@@ -15,6 +13,7 @@
15
13
  # See the License for the specific language governing permissions and
16
14
  # limitations under the License.
17
15
  #
16
+
18
17
  module Fluent
19
18
  # obsolete
20
19
  class StreamOutput < BufferedOutput
@@ -1,7 +1,5 @@
1
1
  #
2
- # Fluent
3
- #
4
- # Copyright (C) 2011 FURUHASHI Sadayuki
2
+ # Fluentd
5
3
  #
6
4
  # Licensed under the Apache License, Version 2.0 (the "License");
7
5
  # you may not use this file except in compliance with the License.
@@ -15,6 +13,7 @@
15
13
  # See the License for the specific language governing permissions and
16
14
  # limitations under the License.
17
15
  #
16
+
18
17
  module Fluent
19
18
  class TestOutput < Output
20
19
  Plugin.register_output('test', self)
@@ -1,3 +1,19 @@
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
+
1
17
  require 'cool.io'
2
18
 
3
19
  module Fluent
@@ -83,11 +99,12 @@ module Fluent
83
99
  config_param :port, :integer, :default => 5150
84
100
  config_param :bind, :string, :default => '0.0.0.0'
85
101
  config_param :source_host_key, :string, :default => nil
102
+ config_param :blocking_timeout, :time, :default => 0.5
86
103
 
87
104
  def configure(conf)
88
105
  super
89
106
 
90
- @parser = Plugin.new_parser(@format)
107
+ @parser = TextParser.new
91
108
  @parser.configure(conf)
92
109
  end
93
110
 
@@ -106,11 +123,7 @@ module Fluent
106
123
  end
107
124
 
108
125
  def run
109
- if support_blocking_timeout?
110
- @loop.run(0.5)
111
- else
112
- @loop.run
113
- end
126
+ @loop.run(@blocking_timeout)
114
127
  rescue => e
115
128
  log.error "unexpected error", :error => e, :error_class => e.class
116
129
  log.error_backtrace
@@ -118,10 +131,6 @@ module Fluent
118
131
 
119
132
  private
120
133
 
121
- def support_blocking_timeout?
122
- @loop.method(:run).arity.nonzero?
123
- end
124
-
125
134
  def on_message(msg, addr)
126
135
  @parser.parse(msg) { |time, record|
127
136
  unless time && record
@@ -1,7 +1,5 @@
1
1
  #
2
- # Fluent
3
- #
4
- # Copyright (C) 2011 FURUHASHI Sadayuki
2
+ # Fluentd
5
3
  #
6
4
  # Licensed under the Apache License, Version 2.0 (the "License");
7
5
  # you may not use this file except in compliance with the License.
@@ -15,6 +13,7 @@
15
13
  # See the License for the specific language governing permissions and
16
14
  # limitations under the License.
17
15
  #
16
+
18
17
  module Fluent
19
18
  class DetachProcessManager
20
19
  require 'singleton'
@@ -178,7 +177,6 @@ module Fluent
178
177
 
179
178
  def read_event_stream(r, &block)
180
179
  u = MessagePack::Unpacker.new(r)
181
- cached_unpacker = $use_msgpack_5 ? nil : MessagePack::Unpacker.new
182
180
  begin
183
181
  #buf = ''
184
182
  #map = {}
@@ -193,14 +191,14 @@ module Fluent
193
191
  # }
194
192
  # unless map.empty?
195
193
  # map.each_pair {|tag,ms|
196
- # es = MessagePackEventStream.new(ms, cached_unpacker)
194
+ # es = MessagePackEventStream.new(ms)
197
195
  # block.call(tag, es)
198
196
  # }
199
197
  # map.clear
200
198
  # end
201
199
  #end
202
200
  u.each {|tag,ms|
203
- es = MessagePackEventStream.new(ms, cached_unpacker)
201
+ es = MessagePackEventStream.new(ms)
204
202
  block.call(tag, es)
205
203
  }
206
204
  rescue EOFError
@@ -1,3 +1,19 @@
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
+
1
17
  module Fluent
2
18
  require 'fluent/config/error'
3
19
 
@@ -0,0 +1,212 @@
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
+ module Fluent
17
+
18
+ require 'delegate'
19
+
20
+ require 'fluent/agent'
21
+ require 'fluent/label'
22
+
23
+ #
24
+ # Fluentd forms a tree structure to manage plugins:
25
+ #
26
+ # RootAgent
27
+ # |
28
+ # +------------+-------------+
29
+ # | | |
30
+ # <label> <source> <match>
31
+ # |
32
+ # +----+----+
33
+ # | |
34
+ # <filter> <match>
35
+ #
36
+ # Relation:
37
+ # * RootAgent has many <label>, <source> and <match>
38
+ # * <label> has many <match> and <filter>
39
+ #
40
+ # Next step: `fluentd/agent.rb`
41
+ # Next step: 'fluentd/label.rb'
42
+ #
43
+ class RootAgent < Agent
44
+ ERROR_LABEL = "@ERROR".freeze
45
+
46
+ def initialize(opts = {})
47
+ super
48
+
49
+ @labels = {}
50
+ @inputs = []
51
+ @started_inputs = []
52
+ @suppress_emit_error_log_interval = 0
53
+ @next_emit_error_log_time = nil
54
+
55
+ suppress_interval(opts[:suppress_interval]) if opts[:suppress_interval]
56
+ @without_source = opts[:without_source] if opts[:without_source]
57
+ end
58
+
59
+ attr_reader :inputs
60
+ attr_reader :labels
61
+
62
+ def configure(conf)
63
+ super
64
+
65
+ error_label_config = nil
66
+
67
+ # initialize <label> elements
68
+ label_configs = {}
69
+ conf.elements.select { |e| e.name == 'label' }.each { |e|
70
+ name = e.arg
71
+ raise ConfigError, "Missing symbol argument on <label> directive" if name.empty?
72
+
73
+ if name == ERROR_LABEL
74
+ error_label_config = e
75
+ else
76
+ add_label(name, e)
77
+ label_configs[name] = e
78
+ end
79
+ }
80
+ # Call 'configure' here to avoid 'label not found'
81
+ label_configs.each { |name, e| @labels[name].configure(e) }
82
+
83
+ # initialize <source> elements
84
+ if @without_source
85
+ log.info "'--without-source' is applied. Ignore <source> sections"
86
+ else
87
+ conf.elements.select { |e| e.name == 'source' }.each { |e|
88
+ type = e['type']
89
+ raise ConfigError, "Missing 'type' parameter on <source> directive" unless type
90
+ add_source(type, e)
91
+ }
92
+ end
93
+
94
+ setup_error_label(error_label_config) if error_label_config
95
+ end
96
+
97
+ def setup_error_label(e)
98
+ # initialize built-in ERROR label
99
+ error_label = add_label(ERROR_LABEL, e)
100
+ error_label.configure(e)
101
+ error_label.root_agent = RootAgentProxyWithoutErrorCollector.new(self)
102
+ @error_collector = error_label.event_router
103
+ end
104
+
105
+ def start
106
+ super
107
+
108
+ @labels.each { |n, l|
109
+ l.start
110
+ }
111
+
112
+ @inputs.each { |i|
113
+ i.start
114
+ @started_inputs << i
115
+ }
116
+ end
117
+
118
+ def shutdown
119
+ # Shutdown Input plugin first to prevent emitting to terminated Output plugin
120
+ @started_inputs.map { |i|
121
+ Thread.new do
122
+ begin
123
+ i.shutdown
124
+ rescue => e
125
+ log.warn "unexpected error while shutting down input plugin", :plugin => i.class, :plugin_id => i.plugin_id, :error_class => e.class, :error => e
126
+ log.warn_backtrace
127
+ end
128
+ end
129
+ }.each { |t| t.join }
130
+
131
+ @labels.each { |n, l|
132
+ l.shutdown
133
+ }
134
+
135
+ super
136
+ end
137
+
138
+ def suppress_interval(interval_time)
139
+ @suppress_emit_error_log_interval = interval_time
140
+ @next_emit_error_log_time = Time.now.to_i
141
+ end
142
+
143
+ def add_source(type, conf)
144
+ log.info "adding source", type: type
145
+
146
+ input = Plugin.new_input(type)
147
+ # <source> emits events to the top-level event router (RootAgent#event_router).
148
+ # Input#configure overwrites event_router to a label's event_router if it has `@label` parameter.
149
+ # See also 'fluentd/plugin/input.rb'
150
+ input.router = @event_router
151
+ input.configure(conf)
152
+ @inputs << input
153
+
154
+ input
155
+ end
156
+
157
+ def add_label(name, e)
158
+ label = Label.new(name)
159
+ label.root_agent = self
160
+ @labels[name] = label
161
+ end
162
+
163
+ def find_label(label_name)
164
+ if label = @labels[label_name]
165
+ label
166
+ else
167
+ raise ArgumentError, "#{label_name} label not found"
168
+ end
169
+ end
170
+
171
+ def handle_emits_error(tag, es, e)
172
+ if @error_collector
173
+ @error_collector.emit_stream(tag, es)
174
+ else
175
+ now = Engine.now
176
+ if @suppress_emit_error_log_interval.zero? || now > @next_emit_error_log_time
177
+ log.warn "emit transaction failed ", :error_class => e.class, :error => e
178
+ log.warn_backtrace
179
+ # log.debug "current next_emit_error_log_time: #{Time.at(@next_emit_error_log_time)}"
180
+ @next_emit_error_log_time = now + @suppress_emit_error_log_interval
181
+ # log.debug "next emit failure log suppressed"
182
+ # log.debug "next logged time is #{Time.at(@next_emit_error_log_time)}"
183
+ end
184
+ raise e
185
+ end
186
+ end
187
+
188
+ # <label @ERROR> element use RootAgent wrapped by # this RootAgentProxyWithoutErrorCollector.
189
+ # So that those elements don't send cause infinite loop.
190
+ class RootAgentProxyWithoutErrorCollector < SimpleDelegator
191
+ def initialize(root_agent)
192
+ super
193
+
194
+ @suppress_emit_error_log_interval = 0
195
+ @next_emit_error_log_time = nil
196
+
197
+ interval_time = root_agent.instance_variable_get(:@suppress_emit_error_log_interval)
198
+ suppress_interval(interval_time) unless interval_time.zero?
199
+ end
200
+
201
+ def handle_emits_error(tag, es, e)
202
+ now = Engine.now
203
+ if @suppress_emit_error_log_interval.zero? || now > @next_emit_error_log_time
204
+ log.warn "emit transaction failed ", :error_class => e.class, :error => e
205
+ log.warn_backtrace
206
+ @next_emit_error_log_time = now + @suppress_emit_error_log_interval
207
+ end
208
+ raise e
209
+ end
210
+ end
211
+ end
212
+ end