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
data/lib/fluent/plugin.rb CHANGED
@@ -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,13 +13,13 @@
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 PluginClass
20
- # This class is refactored using Fluent::Registry at v0.14
21
-
22
19
  def initialize
23
20
  @input = {}
24
21
  @output = {}
22
+ @filter = {}
25
23
  @buffer = {}
26
24
  end
27
25
 
@@ -33,16 +31,12 @@ module Fluent
33
31
  register_impl('output', @output, type, klass)
34
32
  end
35
33
 
36
- def register_buffer(type, klass)
37
- register_impl('buffer', @buffer, type, klass)
38
- end
39
-
40
- def register_parser(type, klass)
41
- TextParser.register_template(type, klass)
34
+ def register_filter(type, klass)
35
+ register_impl('filter', @filter, type, klass)
42
36
  end
43
37
 
44
- def register_formatter(type, klass)
45
- TextFormatter.register_template(type, klass)
38
+ def register_buffer(type, klass)
39
+ register_impl('buffer', @buffer, type, klass)
46
40
  end
47
41
 
48
42
  def new_input(type)
@@ -53,16 +47,12 @@ module Fluent
53
47
  new_impl('output', @output, type)
54
48
  end
55
49
 
56
- def new_buffer(type)
57
- new_impl('buffer', @buffer, type)
50
+ def new_filter(type)
51
+ new_impl('filter', @filter, type)
58
52
  end
59
53
 
60
- def new_parser(type)
61
- TextParser.lookup(type)
62
- end
63
-
64
- def new_formatter(type)
65
- TextFormatter.lookup(type)
54
+ def new_buffer(type)
55
+ new_impl('buffer', @buffer, type)
66
56
  end
67
57
 
68
58
  def load_plugins
@@ -108,6 +98,8 @@ module Fluent
108
98
  path = "fluent/plugin/in_#{type}"
109
99
  when 'output'
110
100
  path = "fluent/plugin/out_#{type}"
101
+ when 'filter'
102
+ path = "fluent/plugin/filter_#{type}"
111
103
  when 'buffer'
112
104
  path = "fluent/plugin/buf_#{type}"
113
105
  else
@@ -126,33 +118,16 @@ module Fluent
126
118
  end
127
119
 
128
120
  # search gems
129
- if defined?(::Gem::Specification) && ::Gem::Specification.respond_to?(:find_all)
130
- specs = Gem::Specification.find_all {|spec|
131
- spec.contains_requirable_file? path
132
- }
133
-
134
- # prefer newer version
135
- specs = specs.sort_by {|spec| spec.version }
136
- if spec = specs.last
137
- spec.require_paths.each {|lib|
138
- file = "#{spec.full_gem_path}/#{lib}/#{path}"
139
- require file
140
- }
141
- end
142
-
143
- # backward compatibility for rubygems < 1.8
144
- elsif defined?(::Gem) && ::Gem.respond_to?(:searcher)
145
- #files = Gem.find_files(path).sort
146
- specs = Gem.searcher.find_all(path)
121
+ specs = Gem::Specification.find_all { |spec|
122
+ spec.contains_requirable_file? path
123
+ }
147
124
 
148
- # prefer newer version
149
- specs = specs.sort_by {|spec| spec.version }
150
- specs.reverse_each {|spec|
151
- files = Gem.searcher.matching_files(spec, path)
152
- unless files.empty?
153
- require files.first
154
- break
155
- end
125
+ # prefer newer version
126
+ specs = specs.sort_by { |spec| spec.version }
127
+ if spec = specs.last
128
+ spec.require_paths.each { |lib|
129
+ file = "#{spec.full_gem_path}/#{lib}/#{path}"
130
+ require file
156
131
  }
157
132
  end
158
133
  end
@@ -160,4 +135,3 @@ module Fluent
160
135
 
161
136
  Plugin = PluginClass.new
162
137
  end
163
-
@@ -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 FileBufferChunk < BufferChunk
20
19
  def initialize(key, path, unique_id, mode="a+", symlink_path = nil)
@@ -84,7 +83,6 @@ module Fluent
84
83
  end
85
84
 
86
85
  config_param :buffer_path, :string
87
- config_param :flush_at_shutdown, :bool, :default => false
88
86
 
89
87
  attr_accessor :symlink_path
90
88
 
@@ -92,9 +90,9 @@ module Fluent
92
90
  super
93
91
 
94
92
  if @@buffer_paths.has_key?(@buffer_path)
95
- raise ConfigError, "Other '#{@@buffer_paths[@buffer_path]}' plugin already use same buffer_path: type = #{conf['@type'] || conf['type']}, buffer_path = #{@buffer_path}"
93
+ raise ConfigError, "Other '#{@@buffer_paths[@buffer_path]}' plugin already use same buffer_path: type = #{conf['type']}, buffer_path = #{@buffer_path}"
96
94
  else
97
- @@buffer_paths[@buffer_path] = conf['@type'] || conf['type']
95
+ @@buffer_paths[@buffer_path] = conf['type']
98
96
  end
99
97
 
100
98
  if pos = @buffer_path.index('*')
@@ -105,10 +103,15 @@ module Fluent
105
103
  @buffer_path_suffix = ".log"
106
104
  end
107
105
 
106
+ if flush_at_shutdown = conf['flush_at_shutdown']
107
+ @flush_at_shutdown = true
108
+ else
109
+ @flush_at_shutdown = false
110
+ end
108
111
  end
109
112
 
110
113
  def start
111
- FileUtils.mkdir_p File.dirname(@buffer_path_prefix + "path"), :mode => DEFAULT_DIR_PERMISSION
114
+ FileUtils.mkdir_p File.dirname(@buffer_path_prefix+"path")
112
115
  super
113
116
  end
114
117
 
@@ -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 MemoryBufferChunk < BufferChunk
20
19
  def initialize(key, data='')
@@ -0,0 +1,75 @@
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 ZFileBufferChunk < FileBufferChunk
19
+ def initialize(path)
20
+ super(path)
21
+ @z = Zlib::Deflate.new
22
+ end
23
+
24
+ def <<(data)
25
+ zdata = @z.deflate(data, Z_NO_FLUSH)
26
+ unless zdata.empty?
27
+ super(zdata)
28
+ end
29
+ end
30
+
31
+ def close_write
32
+ zdata = @z.flush
33
+ unless zdata.empty?
34
+ @file.write(zdata)
35
+ @size += zdata.bytesize
36
+ end
37
+ super
38
+ end
39
+
40
+ def close
41
+ @z.close
42
+ super
43
+ end
44
+
45
+ def purge
46
+ @z.close
47
+ super
48
+ end
49
+
50
+ #def open(&block)
51
+ #end
52
+ end
53
+
54
+ class ZFileBuffer < FileBuffer
55
+ #Plugin.register_buffer('zfile', self)
56
+
57
+ def initialize
58
+ require 'zlib'
59
+ super
60
+ end
61
+
62
+ def resume_queue
63
+ queue = resume_queue_paths.map {|path|
64
+ ZFileBufferChunk.new(path)
65
+ }
66
+ top = new_chunk
67
+ return queue, top
68
+ end
69
+
70
+ def new_chunk
71
+ path = new_chunk_path
72
+ ZFileBufferChunk.new(path)
73
+ end
74
+ end
75
+ end
@@ -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
  module ExecUtil
3
19
  SUPPORTED_FORMAT = {
@@ -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 DebugAgentInput < Input
20
19
  Plugin.register_input('debug_agent', 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
  class ExecInput < Input
20
19
  Plugin.register_input('exec', self)
@@ -22,7 +21,6 @@ module Fluent
22
21
  def initialize
23
22
  super
24
23
  require 'fluent/plugin/exec_util'
25
- require 'fluent/timezone'
26
24
  end
27
25
 
28
26
  SUPPORTED_FORMAT = {
@@ -55,11 +53,6 @@ module Fluent
55
53
  @localtime = false
56
54
  end
57
55
 
58
- if conf['timezone']
59
- @timezone = conf['timezone']
60
- Fluent::Timezone.validate!(@timezone)
61
- end
62
-
63
56
  if !@tag && !@tag_key
64
57
  raise ConfigError, "'tag' or 'tag_key' option is required on exec input"
65
58
  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,9 +13,8 @@
15
13
  # See the License for the specific language governing permissions and
16
14
  # limitations under the License.
17
15
  #
18
- module Fluent
19
-
20
16
 
17
+ module Fluent
21
18
  class ForwardInput < Input
22
19
  Plugin.register_input('forward', self)
23
20
 
@@ -54,19 +51,12 @@ module Fluent
54
51
  @loop.attach(@hbr)
55
52
 
56
53
  @thread = Thread.new(&method(:run))
57
- @cached_unpacker = $use_msgpack_5 ? nil : MessagePack::Unpacker.new
58
54
  end
59
55
 
60
56
  def shutdown
61
57
  @loop.watchers.each {|w| w.detach }
62
58
  @loop.stop
63
59
  @usock.close
64
- unless support_blocking_timeout?
65
- listen_address = (@bind == '0.0.0.0' ? '127.0.0.1' : @bind)
66
- # This line is for connecting listen socket to stop the event loop.
67
- # We should use more better approach, e.g. using pipe, fixing cool.io with timeout, etc.
68
- TCPSocket.open(listen_address, @port) {|sock| } # FIXME @thread.join blocks without this line
69
- end
70
60
  @thread.join
71
61
  @lsock.close
72
62
  end
@@ -89,11 +79,7 @@ module Fluent
89
79
  #end
90
80
 
91
81
  def run
92
- if support_blocking_timeout?
93
- @loop.run(@blocking_timeout)
94
- else
95
- @loop.run
96
- end
82
+ @loop.run(@blocking_timeout)
97
83
  rescue => e
98
84
  log.error "unexpected error", :error => e, :error_class => e.class
99
85
  log.error_backtrace
@@ -101,10 +87,6 @@ module Fluent
101
87
 
102
88
  protected
103
89
 
104
- def support_blocking_timeout?
105
- @loop.method(:run).arity.nonzero?
106
- end
107
-
108
90
  # message Entry {
109
91
  # 1: long time
110
92
  # 2: object record
@@ -144,7 +126,7 @@ module Fluent
144
126
 
145
127
  if entries.class == String
146
128
  # PackedForward
147
- es = MessagePackEventStream.new(entries, @cached_unpacker)
129
+ es = MessagePackEventStream.new(entries)
148
130
  router.emit_stream(tag, es)
149
131
 
150
132
  elsif entries.class == Array
@@ -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 GCStatInput < Input
20
19
  Plugin.register_input('gc_stat', 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
  class HttpInput < Input
20
19
  Plugin.register_input('http', self)
@@ -29,18 +28,14 @@ module Fluent
29
28
  super
30
29
  end
31
30
 
32
- EMPTY_GIF_IMAGE = "GIF89a\u0001\u0000\u0001\u0000\x80\xFF\u0000\xFF\xFF\xFF\u0000\u0000\u0000,\u0000\u0000\u0000\u0000\u0001\u0000\u0001\u0000\u0000\u0002\u0002D\u0001\u0000;".force_encoding("UTF-8")
33
-
34
31
  config_param :port, :integer, :default => 9880
35
32
  config_param :bind, :string, :default => '0.0.0.0'
36
33
  config_param :body_size_limit, :size, :default => 32*1024*1024 # TODO default
37
34
  config_param :keepalive_timeout, :time, :default => 10 # TODO default
38
35
  config_param :backlog, :integer, :default => nil
39
36
  config_param :add_http_headers, :bool, :default => false
40
- config_param :add_remote_addr, :bool, :default => false
41
37
  config_param :format, :string, :default => 'default'
42
- config_param :cors_allow_origins, :array, :default => nil
43
- config_param :respond_with_empty_img, :bool, :default => false
38
+ config_param :blocking_timeout, :time, :default => 0.5
44
39
 
45
40
  def configure(conf)
46
41
  super
@@ -48,8 +43,9 @@ module Fluent
48
43
  m = if @format == 'default'
49
44
  method(:parse_params_default)
50
45
  else
51
- @parser = Plugin.new_parser(@format)
52
- @parser.configure(conf)
46
+ parser = TextParser.new
47
+ parser.configure(conf)
48
+ @parser = parser
53
49
  method(:parse_params_with_parser)
54
50
  end
55
51
  (class << self; self; end).module_eval do
@@ -89,9 +85,7 @@ module Fluent
89
85
  super
90
86
  @km = KeepaliveManager.new(@keepalive_timeout)
91
87
  #@lsock = Coolio::TCPServer.new(@bind, @port, Handler, @km, method(:on_request), @body_size_limit)
92
- @lsock = Coolio::TCPServer.new(lsock, nil, Handler, @km, method(:on_request),
93
- @body_size_limit, @format, log,
94
- @cors_allow_origins)
88
+ @lsock = Coolio::TCPServer.new(lsock, nil, Handler, @km, method(:on_request), @body_size_limit, @format, log)
95
89
  @lsock.listen(@backlog) unless @backlog.nil?
96
90
 
97
91
  @loop = Coolio::Loop.new
@@ -110,20 +104,12 @@ module Fluent
110
104
  end
111
105
 
112
106
  def run
113
- if support_blocking_timeout?
114
- @loop.run(0.5)
115
- else
116
- @loop.run
117
- end
107
+ @loop.run(@blocking_timeout)
118
108
  rescue
119
109
  log.error "unexpected error", :error=>$!.to_s
120
110
  log.error_backtrace
121
111
  end
122
112
 
123
- def support_blocking_timeout?
124
- @loop.method(:run).arity.nonzero?
125
- end
126
-
127
113
  def on_request(path_info, params)
128
114
  begin
129
115
  path = path_info[1..-1] # remove /
@@ -132,11 +118,7 @@ module Fluent
132
118
 
133
119
  # Skip nil record
134
120
  if record.nil?
135
- if @respond_with_empty_img
136
- return ["200 OK", {'Content-type'=>'image/gif; charset=utf-8'}, EMPTY_GIF_IMAGE]
137
- else
138
- return ["200 OK", {'Content-type'=>'text/plain'}, ""]
139
- end
121
+ return ["200 OK", {'Content-type'=>'text/plain'}, ""]
140
122
  end
141
123
 
142
124
  if @add_http_headers
@@ -147,10 +129,6 @@ module Fluent
147
129
  }
148
130
  end
149
131
 
150
- if @add_remote_addr
151
- record['REMOTE_ADDR'] = params['REMOTE_ADDR']
152
- end
153
-
154
132
  time = if param_time = params['time']
155
133
  param_time = param_time.to_i
156
134
  param_time.zero? ? Engine.now : param_time
@@ -164,10 +142,10 @@ module Fluent
164
142
  # TODO server error
165
143
  begin
166
144
  # Support batched requests
167
- if record.is_a?(Array)
145
+ if record.is_a?(Array)
168
146
  mes = MultiEventStream.new
169
147
  record.each do |single_record|
170
- single_time = single_record.delete("time") || time
148
+ single_time = single_record.delete("time") || time
171
149
  mes.add(single_time, single_record)
172
150
  end
173
151
  router.emit_stream(tag, mes)
@@ -178,11 +156,7 @@ module Fluent
178
156
  return ["500 Internal Server Error", {'Content-type'=>'text/plain'}, "500 Internal Server Error\n#{$!}\n"]
179
157
  end
180
158
 
181
- if @respond_with_empty_img
182
- return ["200 OK", {'Content-type'=>'image/gif; charset=utf-8'}, EMPTY_GIF_IMAGE]
183
- else
184
- return ["200 OK", {'Content-type'=>'text/plain'}, ""]
185
- end
159
+ return ["200 OK", {'Content-type'=>'text/plain'}, ""]
186
160
  end
187
161
 
188
162
  private
@@ -202,25 +176,25 @@ module Fluent
202
176
 
203
177
  def parse_params_with_parser(params)
204
178
  if content = params[EVENT_RECORD_PARAMETER]
205
- @parser.parse(content) { |time, record|
206
- raise "Received event is not #{@format}: #{content}" if record.nil?
207
- return time, record
208
- }
179
+ time, record = @parser.parse(content)
180
+ raise "Received event is not #{@format}: #{content}" if record.nil?
181
+ return time, record
209
182
  else
210
183
  raise "'#{EVENT_RECORD_PARAMETER}' parameter is required"
211
184
  end
212
185
  end
213
186
 
214
187
  class Handler < Coolio::Socket
215
- def initialize(io, km, callback, body_size_limit, format, log, cors_allow_origins)
188
+ def initialize(io, km, callback, body_size_limit, format, log)
216
189
  super(io)
217
190
  @km = km
218
191
  @callback = callback
219
192
  @body_size_limit = body_size_limit
193
+ @content_type = ""
220
194
  @next_close = false
221
195
  @format = format
222
196
  @log = log
223
- @cors_allow_origins = cors_allow_origins
197
+
224
198
  @idle = 0
225
199
  @km.add(self)
226
200
 
@@ -255,14 +229,12 @@ module Fluent
255
229
  def on_headers_complete(headers)
256
230
  expect = nil
257
231
  size = nil
258
-
259
232
  if @parser.http_version == [1, 1]
260
233
  @keep_alive = true
261
234
  else
262
235
  @keep_alive = false
263
236
  end
264
237
  @env = {}
265
- @content_type = ""
266
238
  headers.each_pair {|k,v|
267
239
  @env["HTTP_#{k.gsub('-','_').upcase}"] = v
268
240
  case k
@@ -278,8 +250,6 @@ module Fluent
278
250
  elsif v =~ /Keep-alive/i
279
251
  @keep_alive = true
280
252
  end
281
- when /Origin/i
282
- @origin = v
283
253
  end
284
254
  }
285
255
  if expect
@@ -308,17 +278,6 @@ module Fluent
308
278
  def on_message_complete
309
279
  return if closing?
310
280
 
311
- # CORS check
312
- # ==========
313
- # For every incoming request, we check if we have some CORS
314
- # restrictions and white listed origins through @cors_allow_origins.
315
- unless @cors_allow_origins.nil?
316
- unless @cors_allow_origins.include?(@origin)
317
- send_response_and_close("403 Forbidden", {'Connection' => 'close'}, "")
318
- return
319
- end
320
- end
321
-
322
281
  @env['REMOTE_ADDR'] = @remote_addr if @remote_addr
323
282
 
324
283
  uri = URI.parse(@parser.request_url)
@@ -388,3 +347,4 @@ module Fluent
388
347
  end
389
348
  end
390
349
  end
350
+