fluentd 0.12.40 → 0.14.0

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 (252) hide show
  1. checksums.yaml +4 -4
  2. data/.github/ISSUE_TEMPLATE.md +6 -0
  3. data/.gitignore +2 -0
  4. data/.travis.yml +33 -21
  5. data/CONTRIBUTING.md +1 -0
  6. data/ChangeLog +810 -237
  7. data/README.md +0 -25
  8. data/Rakefile +2 -1
  9. data/Vagrantfile +17 -0
  10. data/appveyor.yml +35 -0
  11. data/example/filter_stdout.conf +5 -5
  12. data/example/in_forward.conf +2 -2
  13. data/example/in_http.conf +2 -2
  14. data/example/in_out_forward.conf +17 -0
  15. data/example/in_syslog.conf +2 -2
  16. data/example/in_tail.conf +2 -2
  17. data/example/in_tcp.conf +2 -2
  18. data/example/in_udp.conf +2 -2
  19. data/example/out_copy.conf +4 -4
  20. data/example/out_file.conf +2 -2
  21. data/example/out_forward.conf +2 -2
  22. data/example/out_forward_buf_file.conf +23 -0
  23. data/example/v0_12_filter.conf +8 -8
  24. data/fluent.conf +29 -0
  25. data/fluentd.gemspec +18 -11
  26. data/lib/fluent/agent.rb +60 -58
  27. data/lib/fluent/command/cat.rb +1 -1
  28. data/lib/fluent/command/debug.rb +7 -5
  29. data/lib/fluent/command/fluentd.rb +97 -2
  30. data/lib/fluent/compat/call_super_mixin.rb +67 -0
  31. data/lib/fluent/compat/filter.rb +50 -0
  32. data/lib/fluent/compat/formatter.rb +109 -0
  33. data/lib/fluent/compat/input.rb +50 -0
  34. data/lib/fluent/compat/output.rb +617 -0
  35. data/lib/fluent/compat/output_chain.rb +60 -0
  36. data/lib/fluent/compat/parser.rb +163 -0
  37. data/lib/fluent/compat/propagate_default.rb +62 -0
  38. data/lib/fluent/config.rb +23 -20
  39. data/lib/fluent/config/configure_proxy.rb +119 -70
  40. data/lib/fluent/config/dsl.rb +5 -18
  41. data/lib/fluent/config/element.rb +72 -8
  42. data/lib/fluent/config/error.rb +0 -3
  43. data/lib/fluent/config/literal_parser.rb +0 -2
  44. data/lib/fluent/config/parser.rb +4 -4
  45. data/lib/fluent/config/section.rb +39 -28
  46. data/lib/fluent/config/types.rb +2 -13
  47. data/lib/fluent/config/v1_parser.rb +1 -3
  48. data/lib/fluent/configurable.rb +48 -16
  49. data/lib/fluent/daemon.rb +15 -0
  50. data/lib/fluent/engine.rb +26 -52
  51. data/lib/fluent/env.rb +6 -4
  52. data/lib/fluent/event.rb +58 -11
  53. data/lib/fluent/event_router.rb +5 -5
  54. data/lib/fluent/filter.rb +2 -50
  55. data/lib/fluent/formatter.rb +4 -293
  56. data/lib/fluent/input.rb +2 -32
  57. data/lib/fluent/label.rb +2 -2
  58. data/lib/fluent/load.rb +3 -2
  59. data/lib/fluent/log.rb +107 -38
  60. data/lib/fluent/match.rb +0 -36
  61. data/lib/fluent/mixin.rb +117 -7
  62. data/lib/fluent/msgpack_factory.rb +62 -0
  63. data/lib/fluent/output.rb +7 -612
  64. data/lib/fluent/output_chain.rb +23 -0
  65. data/lib/fluent/parser.rb +4 -800
  66. data/lib/fluent/plugin.rb +100 -121
  67. data/lib/fluent/plugin/bare_output.rb +63 -0
  68. data/lib/fluent/plugin/base.rb +121 -0
  69. data/lib/fluent/plugin/buf_file.rb +101 -182
  70. data/lib/fluent/plugin/buf_memory.rb +9 -92
  71. data/lib/fluent/plugin/buffer.rb +473 -0
  72. data/lib/fluent/plugin/buffer/chunk.rb +135 -0
  73. data/lib/fluent/plugin/buffer/file_chunk.rb +339 -0
  74. data/lib/fluent/plugin/buffer/memory_chunk.rb +100 -0
  75. data/lib/fluent/plugin/exec_util.rb +80 -75
  76. data/lib/fluent/plugin/file_util.rb +33 -28
  77. data/lib/fluent/plugin/file_wrapper.rb +120 -0
  78. data/lib/fluent/plugin/filter.rb +51 -0
  79. data/lib/fluent/plugin/filter_grep.rb +13 -40
  80. data/lib/fluent/plugin/filter_record_transformer.rb +22 -18
  81. data/lib/fluent/plugin/formatter.rb +93 -0
  82. data/lib/fluent/plugin/formatter_csv.rb +48 -0
  83. data/lib/fluent/plugin/formatter_hash.rb +32 -0
  84. data/lib/fluent/plugin/formatter_json.rb +47 -0
  85. data/lib/fluent/plugin/formatter_ltsv.rb +42 -0
  86. data/lib/fluent/plugin/formatter_msgpack.rb +32 -0
  87. data/lib/fluent/plugin/formatter_out_file.rb +45 -0
  88. data/lib/fluent/plugin/formatter_single_value.rb +34 -0
  89. data/lib/fluent/plugin/formatter_stdout.rb +39 -0
  90. data/lib/fluent/plugin/in_debug_agent.rb +4 -0
  91. data/lib/fluent/plugin/in_dummy.rb +22 -18
  92. data/lib/fluent/plugin/in_exec.rb +18 -8
  93. data/lib/fluent/plugin/in_forward.rb +36 -79
  94. data/lib/fluent/plugin/in_gc_stat.rb +4 -0
  95. data/lib/fluent/plugin/in_http.rb +21 -18
  96. data/lib/fluent/plugin/in_monitor_agent.rb +15 -48
  97. data/lib/fluent/plugin/in_object_space.rb +6 -1
  98. data/lib/fluent/plugin/in_stream.rb +7 -3
  99. data/lib/fluent/plugin/in_syslog.rb +46 -95
  100. data/lib/fluent/plugin/in_tail.rb +51 -595
  101. data/lib/fluent/plugin/in_tcp.rb +8 -1
  102. data/lib/fluent/plugin/in_udp.rb +8 -14
  103. data/lib/fluent/plugin/input.rb +33 -0
  104. data/lib/fluent/plugin/multi_output.rb +95 -0
  105. data/lib/fluent/plugin/out_buffered_null.rb +59 -0
  106. data/lib/fluent/plugin/out_copy.rb +11 -7
  107. data/lib/fluent/plugin/out_exec.rb +15 -11
  108. data/lib/fluent/plugin/out_exec_filter.rb +18 -10
  109. data/lib/fluent/plugin/out_file.rb +34 -5
  110. data/lib/fluent/plugin/out_forward.rb +19 -9
  111. data/lib/fluent/plugin/out_null.rb +0 -14
  112. data/lib/fluent/plugin/out_roundrobin.rb +11 -7
  113. data/lib/fluent/plugin/out_stdout.rb +5 -7
  114. data/lib/fluent/plugin/out_stream.rb +3 -1
  115. data/lib/fluent/plugin/output.rb +979 -0
  116. data/lib/fluent/plugin/owned_by_mixin.rb +42 -0
  117. data/lib/fluent/plugin/parser.rb +244 -0
  118. data/lib/fluent/plugin/parser_apache.rb +24 -0
  119. data/lib/fluent/plugin/parser_apache2.rb +84 -0
  120. data/lib/fluent/plugin/parser_apache_error.rb +21 -0
  121. data/lib/fluent/plugin/parser_csv.rb +31 -0
  122. data/lib/fluent/plugin/parser_json.rb +79 -0
  123. data/lib/fluent/plugin/parser_ltsv.rb +50 -0
  124. data/lib/fluent/plugin/parser_multiline.rb +102 -0
  125. data/lib/fluent/plugin/parser_nginx.rb +24 -0
  126. data/lib/fluent/plugin/parser_none.rb +36 -0
  127. data/lib/fluent/plugin/parser_syslog.rb +82 -0
  128. data/lib/fluent/plugin/parser_tsv.rb +37 -0
  129. data/lib/fluent/plugin/socket_util.rb +120 -114
  130. data/lib/fluent/plugin/storage.rb +84 -0
  131. data/lib/fluent/plugin/storage_local.rb +116 -0
  132. data/lib/fluent/plugin/string_util.rb +16 -13
  133. data/lib/fluent/plugin_helper.rb +39 -0
  134. data/lib/fluent/plugin_helper/child_process.rb +298 -0
  135. data/lib/fluent/plugin_helper/compat_parameters.rb +99 -0
  136. data/lib/fluent/plugin_helper/event_emitter.rb +80 -0
  137. data/lib/fluent/plugin_helper/event_loop.rb +118 -0
  138. data/lib/fluent/plugin_helper/retry_state.rb +177 -0
  139. data/lib/fluent/plugin_helper/storage.rb +308 -0
  140. data/lib/fluent/plugin_helper/thread.rb +147 -0
  141. data/lib/fluent/plugin_helper/timer.rb +85 -0
  142. data/lib/fluent/plugin_id.rb +63 -0
  143. data/lib/fluent/process.rb +21 -30
  144. data/lib/fluent/registry.rb +21 -9
  145. data/lib/fluent/root_agent.rb +115 -40
  146. data/lib/fluent/supervisor.rb +330 -320
  147. data/lib/fluent/system_config.rb +42 -18
  148. data/lib/fluent/test.rb +6 -1
  149. data/lib/fluent/test/base.rb +23 -3
  150. data/lib/fluent/test/driver/base.rb +247 -0
  151. data/lib/fluent/test/driver/event_feeder.rb +98 -0
  152. data/lib/fluent/test/driver/filter.rb +35 -0
  153. data/lib/fluent/test/driver/input.rb +31 -0
  154. data/lib/fluent/test/driver/output.rb +78 -0
  155. data/lib/fluent/test/driver/test_event_router.rb +45 -0
  156. data/lib/fluent/test/filter_test.rb +0 -1
  157. data/lib/fluent/test/formatter_test.rb +2 -1
  158. data/lib/fluent/test/input_test.rb +23 -17
  159. data/lib/fluent/test/output_test.rb +28 -39
  160. data/lib/fluent/test/parser_test.rb +1 -1
  161. data/lib/fluent/time.rb +104 -1
  162. data/lib/fluent/{status.rb → unique_id.rb} +15 -24
  163. data/lib/fluent/version.rb +1 -1
  164. data/lib/fluent/winsvc.rb +72 -0
  165. data/test/compat/test_calls_super.rb +164 -0
  166. data/test/config/test_config_parser.rb +83 -0
  167. data/test/config/test_configurable.rb +547 -274
  168. data/test/config/test_configure_proxy.rb +146 -29
  169. data/test/config/test_dsl.rb +3 -181
  170. data/test/config/test_element.rb +274 -0
  171. data/test/config/test_literal_parser.rb +1 -1
  172. data/test/config/test_section.rb +79 -7
  173. data/test/config/test_system_config.rb +21 -0
  174. data/test/config/test_types.rb +3 -26
  175. data/test/helper.rb +78 -8
  176. data/test/plugin/test_bare_output.rb +118 -0
  177. data/test/plugin/test_base.rb +75 -0
  178. data/test/plugin/test_buf_file.rb +420 -521
  179. data/test/plugin/test_buf_memory.rb +32 -194
  180. data/test/plugin/test_buffer.rb +981 -0
  181. data/test/plugin/test_buffer_chunk.rb +110 -0
  182. data/test/plugin/test_buffer_file_chunk.rb +770 -0
  183. data/test/plugin/test_buffer_memory_chunk.rb +265 -0
  184. data/test/plugin/test_filter.rb +255 -0
  185. data/test/plugin/test_filter_grep.rb +2 -73
  186. data/test/plugin/test_filter_record_transformer.rb +24 -68
  187. data/test/plugin/test_filter_stdout.rb +6 -6
  188. data/test/plugin/test_in_debug_agent.rb +2 -0
  189. data/test/plugin/test_in_dummy.rb +11 -17
  190. data/test/plugin/test_in_exec.rb +6 -25
  191. data/test/plugin/test_in_forward.rb +112 -151
  192. data/test/plugin/test_in_gc_stat.rb +2 -0
  193. data/test/plugin/test_in_http.rb +106 -157
  194. data/test/plugin/test_in_object_space.rb +21 -5
  195. data/test/plugin/test_in_stream.rb +14 -13
  196. data/test/plugin/test_in_syslog.rb +30 -275
  197. data/test/plugin/test_in_tail.rb +95 -234
  198. data/test/plugin/test_in_tcp.rb +14 -0
  199. data/test/plugin/test_in_udp.rb +21 -13
  200. data/test/plugin/test_input.rb +122 -0
  201. data/test/plugin/test_multi_output.rb +180 -0
  202. data/test/plugin/test_out_buffered_null.rb +79 -0
  203. data/test/plugin/test_out_copy.rb +15 -2
  204. data/test/plugin/test_out_exec.rb +75 -25
  205. data/test/plugin/test_out_exec_filter.rb +74 -8
  206. data/test/plugin/test_out_file.rb +61 -7
  207. data/test/plugin/test_out_forward.rb +92 -15
  208. data/test/plugin/test_out_roundrobin.rb +1 -0
  209. data/test/plugin/test_out_stdout.rb +22 -13
  210. data/test/plugin/test_out_stream.rb +18 -0
  211. data/test/plugin/test_output.rb +515 -0
  212. data/test/plugin/test_output_as_buffered.rb +1540 -0
  213. data/test/plugin/test_output_as_buffered_overflow.rb +247 -0
  214. data/test/plugin/test_output_as_buffered_retries.rb +808 -0
  215. data/test/plugin/test_output_as_buffered_secondary.rb +776 -0
  216. data/test/plugin/test_output_as_standard.rb +362 -0
  217. data/test/plugin/test_owned_by.rb +35 -0
  218. data/test/plugin/test_storage.rb +167 -0
  219. data/test/plugin/test_storage_local.rb +8 -0
  220. data/test/plugin_helper/test_child_process.rb +599 -0
  221. data/test/plugin_helper/test_compat_parameters.rb +175 -0
  222. data/test/plugin_helper/test_event_emitter.rb +51 -0
  223. data/test/plugin_helper/test_event_loop.rb +52 -0
  224. data/test/plugin_helper/test_retry_state.rb +399 -0
  225. data/test/plugin_helper/test_storage.rb +411 -0
  226. data/test/plugin_helper/test_thread.rb +164 -0
  227. data/test/plugin_helper/test_timer.rb +100 -0
  228. data/test/scripts/exec_script.rb +0 -6
  229. data/test/scripts/fluent/plugin/out_test.rb +3 -0
  230. data/test/test_config.rb +13 -4
  231. data/test/test_event.rb +24 -13
  232. data/test/test_event_router.rb +8 -7
  233. data/test/test_event_time.rb +187 -0
  234. data/test/test_formatter.rb +13 -51
  235. data/test/test_input.rb +1 -1
  236. data/test/test_log.rb +239 -16
  237. data/test/test_mixin.rb +1 -1
  238. data/test/test_output.rb +53 -66
  239. data/test/test_parser.rb +105 -323
  240. data/test/test_plugin_helper.rb +81 -0
  241. data/test/test_root_agent.rb +4 -52
  242. data/test/test_supervisor.rb +272 -0
  243. data/test/test_unique_id.rb +47 -0
  244. metadata +180 -54
  245. data/lib/fluent/buffer.rb +0 -365
  246. data/lib/fluent/plugin/filter_parser.rb +0 -107
  247. data/lib/fluent/plugin/in_status.rb +0 -76
  248. data/lib/fluent/test/helpers.rb +0 -86
  249. data/test/plugin/data/log/foo/bar2 +0 -0
  250. data/test/plugin/test_filter_parser.rb +0 -744
  251. data/test/plugin/test_in_status.rb +0 -38
  252. data/test/test_buffer.rb +0 -624
@@ -3,15 +3,21 @@ require 'fluent/config/configure_proxy'
3
3
 
4
4
  module Fluent::Config
5
5
  class TestConfigureProxy < ::Test::Unit::TestCase
6
+ setup do
7
+ @type_lookup = ->(type) { Fluent::Configurable.lookup_type(type) }
8
+ end
9
+
6
10
  sub_test_case 'to generate a instance' do
7
11
  sub_test_case '#initialize' do
8
12
  test 'has default values' do
9
- proxy = Fluent::Config::ConfigureProxy.new('section')
13
+ proxy = Fluent::Config::ConfigureProxy.new('section', type_lookup: @type_lookup)
10
14
  assert_equal(:section, proxy.name)
11
15
 
12
- proxy = Fluent::Config::ConfigureProxy.new(:section)
16
+ proxy = Fluent::Config::ConfigureProxy.new(:section, type_lookup: @type_lookup)
13
17
  assert_equal(:section, proxy.name)
14
- assert_equal(:section, proxy.param_name)
18
+ assert_nil(proxy.param_name)
19
+ assert_equal(:section, proxy.variable_name)
20
+ assert_nil(proxy.init)
15
21
  assert_nil(proxy.required)
16
22
  assert_false(proxy.required?)
17
23
  assert_nil(proxy.multi)
@@ -19,85 +25,196 @@ module Fluent::Config
19
25
  end
20
26
 
21
27
  test 'can specify param_name/required/multi with optional arguments' do
22
- proxy = Fluent::Config::ConfigureProxy.new(:section, param_name: 'sections', required: false, multi: true)
28
+ proxy = Fluent::Config::ConfigureProxy.new(:section, param_name: 'sections', init: true, required: false, multi: true, type_lookup: @type_lookup)
23
29
  assert_equal(:section, proxy.name)
24
30
  assert_equal(:sections, proxy.param_name)
31
+ assert_equal(:sections, proxy.variable_name)
25
32
  assert_false(proxy.required)
26
33
  assert_false(proxy.required?)
27
34
  assert_true(proxy.multi)
28
35
  assert_true(proxy.multi?)
29
36
 
30
- proxy = Fluent::Config::ConfigureProxy.new(:section, param_name: :sections, required: true, multi: false)
37
+ proxy = Fluent::Config::ConfigureProxy.new(:section, param_name: :sections, init: false, required: true, multi: false, type_lookup: @type_lookup)
31
38
  assert_equal(:section, proxy.name)
32
39
  assert_equal(:sections, proxy.param_name)
40
+ assert_equal(:sections, proxy.variable_name)
33
41
  assert_true(proxy.required)
34
42
  assert_true(proxy.required?)
35
43
  assert_false(proxy.multi)
36
44
  assert_false(proxy.multi?)
37
45
  end
46
+ test 'raise error if both of init and required are true' do
47
+ assert_raise "init and required are exclusive" do
48
+ Fluent::Config::ConfigureProxy.new(:section, init: true, required: true, type_lookup: @type_lookup)
49
+ end
50
+ end
38
51
  end
39
52
 
40
53
  sub_test_case '#merge' do
41
54
  test 'generate a new instance which values are overwritten by the argument object' do
42
- proxy = p1 = Fluent::Config::ConfigureProxy.new(:section)
55
+ proxy = p1 = Fluent::Config::ConfigureProxy.new(:section, type_lookup: @type_lookup)
43
56
  assert_equal(:section, proxy.name)
44
- assert_equal(:section, proxy.param_name)
57
+ assert_nil(proxy.param_name)
58
+ assert_equal(:section, proxy.variable_name)
59
+ assert_nil(proxy.init)
45
60
  assert_nil(proxy.required)
46
61
  assert_false(proxy.required?)
47
62
  assert_nil(proxy.multi)
48
63
  assert_true(proxy.multi?)
64
+ assert_nil(proxy.configured_in_section)
49
65
 
50
- p2 = Fluent::Config::ConfigureProxy.new(:section, param_name: :sections, required: true, multi: false)
66
+ p2 = Fluent::Config::ConfigureProxy.new(:section, init: false, required: true, multi: false, type_lookup: @type_lookup)
51
67
  proxy = p1.merge(p2)
52
68
  assert_equal(:section, proxy.name)
53
- assert_equal(:sections, proxy.param_name)
69
+ assert_nil(proxy.param_name)
70
+ assert_equal(:section, proxy.variable_name)
71
+ assert_false(proxy.init)
72
+ assert_false(proxy.init?)
54
73
  assert_true(proxy.required)
55
74
  assert_true(proxy.required?)
56
75
  assert_false(proxy.multi)
57
76
  assert_false(proxy.multi?)
77
+ assert_nil(proxy.configured_in_section)
58
78
  end
59
79
 
60
80
  test 'does not overwrite with argument object without any specifications of required/multi' do
61
- p1 = Fluent::Config::ConfigureProxy.new(:section1)
62
- p2 = Fluent::Config::ConfigureProxy.new(:section2, param_name: :sections, required: true, multi: false)
63
- p3 = Fluent::Config::ConfigureProxy.new(:section3)
81
+ p1 = Fluent::Config::ConfigureProxy.new(:section1, param_name: :sections, type_lookup: @type_lookup)
82
+ p1.configured_in_section = :subsection
83
+ p2 = Fluent::Config::ConfigureProxy.new(:section2, init: false, required: true, multi: false, type_lookup: @type_lookup)
84
+ p3 = Fluent::Config::ConfigureProxy.new(:section3, type_lookup: @type_lookup)
64
85
  proxy = p1.merge(p2).merge(p3)
65
- assert_equal(:section3, proxy.name)
66
- assert_equal(:section3, proxy.param_name)
86
+ assert_equal(:section1, proxy.name)
87
+ assert_equal(:sections, proxy.param_name)
88
+ assert_equal(:sections, proxy.variable_name)
89
+ assert_false(proxy.init)
90
+ assert_false(proxy.init?)
67
91
  assert_true(proxy.required)
68
92
  assert_true(proxy.required?)
69
93
  assert_false(proxy.multi)
70
94
  assert_false(proxy.multi?)
95
+ assert_equal :subsection, proxy.configured_in_section
96
+ end
97
+ end
98
+
99
+ sub_test_case '#overwrite_defaults' do
100
+ test 'overwrites only defaults with others defaults' do
101
+ type_lookup = ->(type) { Fluent::Configurable.lookup_type(type) }
102
+ p1 = Fluent::Config::ConfigureProxy.new(:mychild, type_lookup: type_lookup)
103
+ p1.configured_in_section = :child
104
+ p1.config_param(:k1a, :string)
105
+ p1.config_param(:k1b, :string)
106
+ p1.config_param(:k2a, :integer, default: 0)
107
+ p1.config_param(:k2b, :integer, default: 0)
108
+ p1.config_section(:sub1) do
109
+ config_param :k3, :time, default: 30
110
+ end
111
+
112
+ p0 = Fluent::Config::ConfigureProxy.new(:myparent, type_lookup: type_lookup)
113
+ p0.config_section(:child) do
114
+ config_set_default :k1a, "v1a"
115
+ config_param :k1b, :string, default: "v1b"
116
+ config_set_default :k2a, 21
117
+ config_param :k2b, :integer, default: 22
118
+ config_section :sub1 do
119
+ config_set_default :k3, 60
120
+ end
121
+ end
122
+
123
+ p1.overwrite_defaults(p0.sections[:child])
124
+
125
+ assert_equal "v1a", p1.defaults[:k1a]
126
+ assert_equal "v1b", p1.defaults[:k1b]
127
+ assert_equal 21, p1.defaults[:k2a]
128
+ assert_equal 22, p1.defaults[:k2b]
129
+ assert_equal 60, p1.sections[:sub1].defaults[:k3]
130
+ end
131
+ end
132
+
133
+ sub_test_case '#configured_in' do
134
+ test 'sets a section name which have configuration parameters of target plugin in owners configuration' do
135
+ proxy = Fluent::Config::ConfigureProxy.new(:section, type_lookup: @type_lookup)
136
+ proxy.configured_in(:mysection)
137
+ assert_equal :mysection, proxy.configured_in_section
138
+ end
139
+
140
+ test 'do not permit to be called twice' do
141
+ proxy = Fluent::Config::ConfigureProxy.new(:section, type_lookup: @type_lookup)
142
+ proxy.configured_in(:mysection)
143
+ assert_raise(ArgumentError) { proxy.configured_in(:myothersection) }
71
144
  end
72
145
  end
73
146
 
74
147
  sub_test_case '#config_param / #config_set_default / #config_argument' do
148
+ setup do
149
+ @proxy = Fluent::Config::ConfigureProxy.new(:section, type_lookup: @type_lookup)
150
+ end
151
+
75
152
  test 'does not permit config_set_default for param w/ :default option' do
76
- proxy = Fluent::Config::ConfigureProxy.new(:section)
77
- proxy.config_param(:name, :string, default: "name1")
78
- assert_raise(ArgumentError) { proxy.config_set_default(:name, "name2") }
153
+ @proxy.config_param(:name, :string, default: "name1")
154
+ assert_raise(ArgumentError) { @proxy.config_set_default(:name, "name2") }
79
155
  end
80
156
 
81
157
  test 'does not permit default value specification twice' do
82
- proxy = Fluent::Config::ConfigureProxy.new(:section)
83
- proxy.config_param(:name, :string)
84
- proxy.config_set_default(:name, "name1")
85
- assert_raise(ArgumentError) { proxy.config_set_default(:name, "name2") }
158
+ @proxy.config_param(:name, :string)
159
+ @proxy.config_set_default(:name, "name1")
160
+ assert_raise(ArgumentError) { @proxy.config_set_default(:name, "name2") }
86
161
  end
87
162
 
88
163
  test 'does not permit default value specification twice, even on config_argument' do
89
- proxy = Fluent::Config::ConfigureProxy.new(:section)
90
- proxy.config_param(:name, :string)
91
- proxy.config_set_default(:name, "name1")
164
+ @proxy.config_param(:name, :string)
165
+ @proxy.config_set_default(:name, "name1")
166
+
167
+ @proxy.config_argument(:name)
168
+ assert_raise(ArgumentError) { @proxy.config_argument(:name, default: "name2") }
169
+ end
170
+ end
171
+
172
+ sub_test_case '#config_param without default values cause error if section is configured as init:true' do
173
+ setup do
174
+ @proxy = Fluent::Config::ConfigureProxy.new(:section, type_lookup: @type_lookup)
175
+ end
92
176
 
93
- proxy.config_argument(:name)
94
- assert_raise(ArgumentError) { proxy.config_argument(:name, default: "name2") }
177
+ test 'with simple config_param with default value' do
178
+ assert_nothing_raised do
179
+ @proxy.config_section :subsection, init: true do
180
+ config_param :param1, :integer, default: 1
181
+ end
182
+ end
183
+ end
184
+ test 'with simple config_param without default value' do
185
+ assert_raise ArgumentError do
186
+ @proxy.config_section :subsection, init: true do
187
+ config_param :param1, :integer
188
+ end
189
+ end
190
+ end
191
+ test 'with config_param with config_set_default' do
192
+ assert_nothing_raised do
193
+ @proxy.config_section :subsection, init: true do
194
+ config_param :param1, :integer
195
+ config_set_default :param1, 1
196
+ end
197
+ end
198
+ end
199
+ test 'with config_argument' do
200
+ assert_raise ArgumentError do
201
+ @proxy.config_section :subsection, init: true do
202
+ config_argument :param0, :string
203
+ end
204
+ end
205
+ end
206
+ test 'with config_argument with default value' do
207
+ assert_nothing_raised do
208
+ @proxy.config_section :subsection, init: true do
209
+ config_argument :param0, :string, default: ''
210
+ end
211
+ end
95
212
  end
96
213
  end
97
214
 
98
215
  sub_test_case '#config_set_desc' do
99
216
  setup do
100
- @proxy = Fluent::Config::ConfigureProxy.new(:section)
217
+ @proxy = Fluent::Config::ConfigureProxy.new(:section, type_lookup: @type_lookup)
101
218
  end
102
219
 
103
220
  test 'does not permit description specification twice w/ :desc option' do
@@ -114,7 +231,7 @@ module Fluent::Config
114
231
 
115
232
  sub_test_case '#desc' do
116
233
  setup do
117
- @proxy = Fluent::Config::ConfigureProxy.new(:section)
234
+ @proxy = Fluent::Config::ConfigureProxy.new(:section, type_lookup: @type_lookup)
118
235
  end
119
236
 
120
237
  test 'permit to specify description twice' do
@@ -134,7 +251,7 @@ module Fluent::Config
134
251
 
135
252
  sub_test_case '#dump' do
136
253
  setup do
137
- @proxy = Fluent::Config::ConfigureProxy.new(:section)
254
+ @proxy = Fluent::Config::ConfigureProxy.new(:section, type_lookup: @type_lookup)
138
255
  end
139
256
 
140
257
  test 'empty proxy' do
@@ -2,66 +2,6 @@ require_relative '../helper'
2
2
  require 'fluent/config/element'
3
3
  require "fluent/config/dsl"
4
4
 
5
- TMP_DIR = File.dirname(__FILE__) + "/tmp/config_dsl#{ENV['TEST_ENV_NUMBER']}"
6
- def write_config(path, data)
7
- FileUtils.mkdir_p(File.dirname(path))
8
- File.open(path, "w") {|f| f.write data }
9
- end
10
-
11
- def prepare_config1
12
- write_config "#{TMP_DIR}/config_test_1.conf", %[
13
- k1 root_config
14
- include dir/config_test_2.conf #
15
- @include #{TMP_DIR}/config_test_4.conf
16
- include file://#{TMP_DIR}/config_test_5.conf
17
- @include config.d/*.conf
18
- ]
19
- write_config "#{TMP_DIR}/dir/config_test_2.conf", %[
20
- k2 relative_path_include
21
- @include ../config_test_3.conf
22
- ]
23
- write_config "#{TMP_DIR}/config_test_3.conf", %[
24
- k3 relative_include_in_included_file
25
- ]
26
- write_config "#{TMP_DIR}/config_test_4.conf", %[
27
- k4 absolute_path_include
28
- ]
29
- write_config "#{TMP_DIR}/config_test_5.conf", %[
30
- k5 uri_include
31
- ]
32
- write_config "#{TMP_DIR}/config.d/config_test_6.conf", %[
33
- k6 wildcard_include_1
34
- <elem1 name>
35
- include normal_parameter
36
- </elem1>
37
- ]
38
- write_config "#{TMP_DIR}/config.d/config_test_7.conf", %[
39
- k7 wildcard_include_2
40
- ]
41
- write_config "#{TMP_DIR}/config.d/config_test_8.conf", %[
42
- <elem2 name>
43
- @include ../dir/config_test_9.conf
44
- </elem2>
45
- ]
46
- write_config "#{TMP_DIR}/dir/config_test_9.conf", %[
47
- k9 embeded
48
- <elem3 name>
49
- nested nested_value
50
- include hoge
51
- </elem3>
52
- ]
53
- write_config "#{TMP_DIR}/config.d/00_config_test_8.conf", %[
54
- k8 wildcard_include_3
55
- <elem4 name>
56
- include normal_parameter
57
- </elem4>
58
- ]
59
- end
60
-
61
- def prepare_config2
62
- write_config "#{TMP_DIR}/config_test_1.rb", DSL_CONFIG_EXAMPLE
63
- end
64
-
65
5
  DSL_CONFIG_EXAMPLE = %q[
66
6
  worker {
67
7
  hostname = "myhostname"
@@ -117,14 +57,6 @@ source {
117
57
  }
118
58
  ]
119
59
 
120
- DSL_CONFIG_EXAMPLE_FOR_INCLUDE_CONF = %q[
121
- include "#{TMP_DIR}/config_test_1.conf"
122
- ]
123
-
124
- DSL_CONFIG_EXAMPLE_FOR_INCLUDE_RB = %q[
125
- include "#{TMP_DIR}/config_test_1.rb"
126
- ]
127
-
128
60
  DSL_CONFIG_RETURNS_NON_ELEMENT = %q[
129
61
  worker {
130
62
  }
@@ -142,9 +74,6 @@ match('aa','bb'){
142
74
  DSL_CONFIG_WRONG_SYNTAX3 = %q[
143
75
  match('aa','bb')
144
76
  ]
145
- DSL_CONFIG_WRONG_SYNTAX4 = %q[
146
- include
147
- ]
148
77
 
149
78
  module Fluent::Config
150
79
  class TestDSLParser < ::Test::Unit::TestCase
@@ -229,116 +158,10 @@ module Fluent::Config
229
158
  end
230
159
  end
231
160
 
232
- sub_test_case 'with include conf' do
233
- def setup
234
- prepare_config1
235
- @root = Fluent::Config::DSL::Parser.parse(DSL_CONFIG_EXAMPLE_FOR_INCLUDE_CONF, 'dsl_config_for_include.conf')
236
- end
237
- test 'include config' do
238
- assert_equal('root_config', @root['k1'])
239
- assert_equal('relative_path_include', @root['k2'])
240
- assert_equal('relative_include_in_included_file', @root['k3'])
241
- assert_equal('absolute_path_include', @root['k4'])
242
- assert_equal('uri_include', @root['k5'])
243
- assert_equal('wildcard_include_1', @root['k6'])
244
- assert_equal('wildcard_include_2', @root['k7'])
245
- assert_equal('wildcard_include_3', @root['k8'])
246
- assert_equal([
247
- 'k1',
248
- 'k2',
249
- 'k3',
250
- 'k4',
251
- 'k5',
252
- 'k8', # Because of the file name this comes first.
253
- 'k6',
254
- 'k7',
255
- ], @root.keys)
256
-
257
- elem1 = @root.elements.find { |e| e.name == 'elem1' }
258
- assert(elem1)
259
- assert_equal('name', elem1.arg)
260
- assert_equal('normal_parameter', elem1['include'])
261
-
262
- elem2 = @root.elements.find { |e| e.name == 'elem2' }
263
- assert(elem2)
264
- assert_equal('name', elem2.arg)
265
- assert_equal('embeded', elem2['k9'])
266
- assert_not_include(elem2, 'include')
267
-
268
- elem3 = elem2.elements.find { |e| e.name == 'elem3' }
269
- assert(elem3)
270
- assert_equal('nested_value', elem3['nested'])
271
- assert_equal('hoge', elem3['include'])
272
- end
273
-
274
- # TODO: Add uri based include spec
275
- end
276
-
277
- sub_test_case 'with include rb' do
278
- def setup
279
- prepare_config2
280
- @root = Fluent::Config::DSL::Parser.parse(DSL_CONFIG_EXAMPLE_FOR_INCLUDE_RB, 'dsl_config_for_include.rb')
281
- end
282
- sub_test_case '.parse' do
283
- test 'makes root element' do
284
- assert_equal('ROOT', @root.name)
285
- assert_predicate(@root.arg, :empty?)
286
- assert_equal(0, @root.keys.size)
287
- end
288
-
289
- test 'makes worker element for worker tag' do
290
- assert_equal(1, @root.elements.size)
291
-
292
- worker = @root.elements.first
293
- assert_equal('worker', worker.name)
294
- assert_predicate(worker.arg, :empty?)
295
- assert_equal(0, worker.keys.size)
296
- assert_equal(10, worker.elements.size)
297
- end
298
-
299
- test 'makes subsections for blocks, with variable substitution' do
300
- ele4 = @root.elements.first.elements[4]
301
-
302
- assert_equal('source', ele4.name)
303
- assert_predicate(ele4.arg, :empty?)
304
- assert_equal(2, ele4.keys.size)
305
- assert_equal('tail', ele4['type'])
306
- assert_equal("/var/log/httpd/access.part4.log", ele4['path'])
307
- end
308
-
309
- test 'makes user-defined sections with blocks' do
310
- filter0 = @root.elements.first.elements[4].elements.first
311
-
312
- assert_equal('filter', filter0.name)
313
- assert_equal('bar.**', filter0.arg)
314
- assert_equal('hoge', filter0['type'])
315
- assert_equal('moge', filter0['val1'])
316
- assert_equal(JSON.dump(['foo', 'bar', 'baz']), filter0['val2'])
317
- assert_equal('10', filter0['val3'])
318
- assert_equal('hoge', filter0['id'])
319
-
320
- assert_equal(2, filter0.elements.size)
321
- assert_equal('subsection', filter0.elements[0].name)
322
- assert_equal('bar', filter0.elements[0]['foo'])
323
- assert_equal('subsection', filter0.elements[1].name)
324
- assert_equal('baz', filter0.elements[1]['foo'])
325
- end
326
-
327
- test 'makes values with user-assigned variable substitutions' do
328
- match0 = @root.elements.first.elements[4].elements.last
329
-
330
- assert_equal('match', match0.name)
331
- assert_equal('{foo,bar}.**', match0.arg)
332
- assert_equal('file', match0['type'])
333
- assert_equal('/var/log/httpd/access.myhostname.4.log', match0['path'])
334
- end
335
- end
336
- end
337
-
338
161
  sub_test_case 'with configuration that returns non element on top' do
339
162
  sub_test_case '.parse' do
340
163
  test 'does not crash' do
341
- root = Fluent::Config::DSL::Parser.parse(DSL_CONFIG_RETURNS_NON_ELEMENT, 'dsl_config_returns_non_element.rb')
164
+ Fluent::Config::DSL::Parser.parse(DSL_CONFIG_RETURNS_NON_ELEMENT, 'dsl_config_returns_non_element.rb')
342
165
  end
343
166
  end
344
167
  end
@@ -347,9 +170,8 @@ module Fluent::Config
347
170
  sub_test_case '.parse' do
348
171
  test 'raises ArgumentError correctly' do
349
172
  assert_raise(ArgumentError) { Fluent::Config::DSL::Parser.parse(DSL_CONFIG_WRONG_SYNTAX1, 'dsl_config_wrong_syntax1') }
350
- assert_raise(ArgumentError) { Fluent::Config::DSL::Parser.parse(DSL_CONFIG_WRONG_SYNTAX2, 'dsl_config_wrong_syntax2') }
351
- assert_raise(ArgumentError) { Fluent::Config::DSL::Parser.parse(DSL_CONFIG_WRONG_SYNTAX3, 'dsl_config_wrong_syntax3') }
352
- assert_raise(ArgumentError) { Fluent::Config::DSL::Parser.parse(DSL_CONFIG_WRONG_SYNTAX4, 'dsl_config_wrong_syntax4') }
173
+ assert_raise(ArgumentError) { Fluent::Config::DSL::Parser.parse(DSL_CONFIG_WRONG_SYNTAX2, 'dsl_config_wrong_syntax1') }
174
+ assert_raise(ArgumentError) { Fluent::Config::DSL::Parser.parse(DSL_CONFIG_WRONG_SYNTAX3, 'dsl_config_wrong_syntax1') }
353
175
  end
354
176
  end
355
177
  end