fluentd 1.13.1-x64-mingw32 → 1.14.1-x64-mingw32
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.
- checksums.yaml +4 -4
- data/.github/ISSUE_TEMPLATE/bug_report.yaml +69 -0
- data/.github/ISSUE_TEMPLATE/feature_request.yaml +38 -0
- data/.github/workflows/windows-test.yaml +3 -3
- data/CHANGELOG.md +136 -0
- data/README.md +2 -2
- data/example/v0_12_filter.conf +2 -2
- data/fluentd.gemspec +1 -1
- data/lib/fluent/command/fluentd.rb +8 -0
- data/lib/fluent/command/plugin_generator.rb +15 -5
- data/lib/fluent/compat/output.rb +9 -6
- data/lib/fluent/config/parser.rb +1 -1
- data/lib/fluent/config/types.rb +15 -0
- data/lib/fluent/config/v1_parser.rb +4 -3
- data/lib/fluent/config.rb +1 -1
- data/lib/fluent/env.rb +2 -1
- data/lib/fluent/event_router.rb +28 -1
- data/lib/fluent/oj_options.rb +62 -0
- data/lib/fluent/plugin/bare_output.rb +49 -8
- data/lib/fluent/plugin/buffer.rb +84 -22
- data/lib/fluent/plugin/file_wrapper.rb +22 -0
- data/lib/fluent/plugin/filter.rb +35 -1
- data/lib/fluent/plugin/formatter.rb +1 -0
- data/lib/fluent/plugin/formatter_json.rb +9 -7
- data/lib/fluent/plugin/in_http.rb +21 -2
- data/lib/fluent/plugin/in_monitor_agent.rb +4 -2
- data/lib/fluent/plugin/in_syslog.rb +13 -1
- data/lib/fluent/plugin/in_tail/position_file.rb +20 -18
- data/lib/fluent/plugin/in_tail.rb +77 -6
- data/lib/fluent/plugin/input.rb +39 -1
- data/lib/fluent/plugin/metrics.rb +119 -0
- data/lib/fluent/plugin/metrics_local.rb +96 -0
- data/lib/fluent/plugin/multi_output.rb +43 -6
- data/lib/fluent/plugin/out_copy.rb +1 -1
- data/lib/fluent/plugin/out_forward.rb +15 -7
- data/lib/fluent/plugin/output.rb +77 -36
- data/lib/fluent/plugin/parser_json.rb +2 -3
- data/lib/fluent/plugin.rb +10 -1
- data/lib/fluent/plugin_helper/event_emitter.rb +8 -1
- data/lib/fluent/plugin_helper/metrics.rb +129 -0
- data/lib/fluent/plugin_helper/server.rb +4 -2
- data/lib/fluent/plugin_helper.rb +1 -0
- data/lib/fluent/root_agent.rb +6 -0
- data/lib/fluent/supervisor.rb +2 -0
- data/lib/fluent/system_config.rb +9 -1
- data/lib/fluent/test/driver/storage.rb +30 -0
- data/lib/fluent/version.rb +1 -1
- data/templates/new_gem/lib/fluent/plugin/storage.rb.erb +40 -0
- data/templates/new_gem/test/plugin/test_storage.rb.erb +18 -0
- data/test/command/test_plugin_generator.rb +2 -1
- data/test/config/test_system_config.rb +6 -0
- data/test/config/test_types.rb +7 -0
- data/test/plugin/in_tail/test_io_handler.rb +12 -4
- data/test/plugin/in_tail/test_position_file.rb +48 -8
- data/test/plugin/test_bare_output.rb +13 -0
- data/test/plugin/test_buffer.rb +8 -2
- data/test/plugin/test_file_wrapper.rb +11 -0
- data/test/plugin/test_filter.rb +11 -0
- data/test/plugin/test_in_http.rb +40 -0
- data/test/plugin/test_in_monitor_agent.rb +214 -8
- data/test/plugin/test_in_syslog.rb +35 -0
- data/test/plugin/test_in_tail.rb +157 -29
- data/test/plugin/test_input.rb +11 -0
- data/test/plugin/test_metrics.rb +294 -0
- data/test/plugin/test_metrics_local.rb +96 -0
- data/test/plugin/test_multi_output.rb +25 -1
- data/test/plugin/test_output.rb +16 -0
- data/test/plugin_helper/test_event_emitter.rb +29 -0
- data/test/plugin_helper/test_metrics.rb +137 -0
- data/test/test_event_time.rb +2 -2
- data/test/test_oj_options.rb +55 -0
- data/test/test_plugin_classes.rb +102 -0
- data/test/test_root_agent.rb +30 -1
- metadata +21 -6
- data/.github/ISSUE_TEMPLATE/bug_report.md +0 -40
- data/.github/ISSUE_TEMPLATE/feature_request.md +0 -23
@@ -0,0 +1,294 @@
|
|
1
|
+
require_relative '../helper'
|
2
|
+
require 'fluent/plugin/metrics'
|
3
|
+
require 'fluent/plugin/base'
|
4
|
+
require 'fluent/system_config'
|
5
|
+
|
6
|
+
class BareMetrics < Fluent::Plugin::Metrics
|
7
|
+
Fluent::Plugin.register_metrics('bare', self)
|
8
|
+
|
9
|
+
private
|
10
|
+
|
11
|
+
# Just override for tests.
|
12
|
+
def has_methods_for_counter?
|
13
|
+
false
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
class BasicCounterMetrics < Fluent::Plugin::Metrics
|
18
|
+
Fluent::Plugin.register_metrics('example', self)
|
19
|
+
|
20
|
+
attr_reader :data
|
21
|
+
|
22
|
+
def initialize
|
23
|
+
super
|
24
|
+
@data = 0
|
25
|
+
end
|
26
|
+
def get
|
27
|
+
@data
|
28
|
+
end
|
29
|
+
def inc
|
30
|
+
@data +=1
|
31
|
+
end
|
32
|
+
def add(value)
|
33
|
+
@data += value
|
34
|
+
end
|
35
|
+
def set(value)
|
36
|
+
@data = value
|
37
|
+
end
|
38
|
+
def close
|
39
|
+
@data = 0
|
40
|
+
super
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
class AliasedCounterMetrics < Fluent::Plugin::Metrics
|
45
|
+
Fluent::Plugin.register_metrics('example', self)
|
46
|
+
|
47
|
+
attr_reader :data
|
48
|
+
|
49
|
+
def initialize
|
50
|
+
super
|
51
|
+
@data = 0
|
52
|
+
end
|
53
|
+
def configure(conf)
|
54
|
+
super
|
55
|
+
class << self
|
56
|
+
alias_method :set, :set_counter
|
57
|
+
end
|
58
|
+
end
|
59
|
+
def get
|
60
|
+
@data
|
61
|
+
end
|
62
|
+
def inc
|
63
|
+
@data +=1
|
64
|
+
end
|
65
|
+
def add(value)
|
66
|
+
@data += value
|
67
|
+
end
|
68
|
+
def set_counter(value)
|
69
|
+
@data = value
|
70
|
+
end
|
71
|
+
def close
|
72
|
+
@data = 0
|
73
|
+
super
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
class BasicGaugeMetrics < Fluent::Plugin::Metrics
|
78
|
+
Fluent::Plugin.register_metrics('example', self)
|
79
|
+
|
80
|
+
attr_reader :data
|
81
|
+
|
82
|
+
def initialize
|
83
|
+
super
|
84
|
+
@data = 0
|
85
|
+
end
|
86
|
+
def get
|
87
|
+
@data
|
88
|
+
end
|
89
|
+
def inc
|
90
|
+
@data +=1
|
91
|
+
end
|
92
|
+
def dec
|
93
|
+
@data -=1
|
94
|
+
end
|
95
|
+
def add(value)
|
96
|
+
@data += value
|
97
|
+
end
|
98
|
+
def sub(value)
|
99
|
+
@data -= value
|
100
|
+
end
|
101
|
+
def set(value)
|
102
|
+
@data = value
|
103
|
+
end
|
104
|
+
def close
|
105
|
+
@data = 0
|
106
|
+
super
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
class AliasedGaugeMetrics < Fluent::Plugin::Metrics
|
111
|
+
Fluent::Plugin.register_metrics('example', self)
|
112
|
+
|
113
|
+
attr_reader :data
|
114
|
+
|
115
|
+
def initialize
|
116
|
+
super
|
117
|
+
@data = 0
|
118
|
+
end
|
119
|
+
def configure(conf)
|
120
|
+
super
|
121
|
+
class << self
|
122
|
+
alias_method :dec, :dec_gauge
|
123
|
+
alias_method :set, :set_gauge
|
124
|
+
alias_method :sub, :sub_gauge
|
125
|
+
end
|
126
|
+
end
|
127
|
+
def get
|
128
|
+
@data
|
129
|
+
end
|
130
|
+
def inc
|
131
|
+
@data +=1
|
132
|
+
end
|
133
|
+
def dec_gauge
|
134
|
+
@data -=1
|
135
|
+
end
|
136
|
+
def add(value)
|
137
|
+
@data += value
|
138
|
+
end
|
139
|
+
def sub_gauge(value)
|
140
|
+
@data -= value
|
141
|
+
end
|
142
|
+
def set_gauge(value)
|
143
|
+
@data = value
|
144
|
+
end
|
145
|
+
def close
|
146
|
+
@data = 0
|
147
|
+
super
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
class StorageTest < Test::Unit::TestCase
|
152
|
+
sub_test_case 'BareMetrics' do
|
153
|
+
setup do
|
154
|
+
@m = BareMetrics.new
|
155
|
+
@m.configure(config_element())
|
156
|
+
end
|
157
|
+
|
158
|
+
test 'is configured with plugin information and system config' do
|
159
|
+
m = BareMetrics.new
|
160
|
+
m.configure(config_element('metrics', '', {}))
|
161
|
+
|
162
|
+
assert_false m.use_gauge_metric
|
163
|
+
assert_false m.has_methods_for_counter
|
164
|
+
assert_false m.has_methods_for_gauge
|
165
|
+
end
|
166
|
+
|
167
|
+
test 'all bare operations are not defined yet' do
|
168
|
+
assert_raise NotImplementedError do
|
169
|
+
@m.get
|
170
|
+
end
|
171
|
+
assert_raise NotImplementedError do
|
172
|
+
@m.inc
|
173
|
+
end
|
174
|
+
assert_raise NotImplementedError do
|
175
|
+
@m.dec
|
176
|
+
end
|
177
|
+
assert_raise NotImplementedError do
|
178
|
+
@m.add(10)
|
179
|
+
end
|
180
|
+
assert_raise NotImplementedError do
|
181
|
+
@m.sub(11)
|
182
|
+
end
|
183
|
+
assert_raise NotImplementedError do
|
184
|
+
@m.set(123)
|
185
|
+
end
|
186
|
+
end
|
187
|
+
end
|
188
|
+
|
189
|
+
sub_test_case 'BasicCounterMetric' do
|
190
|
+
setup do
|
191
|
+
@m = BasicCounterMetrics.new
|
192
|
+
@m.configure(config_element('metrics', '', {'@id' => '1'}))
|
193
|
+
end
|
194
|
+
|
195
|
+
test 'all basic counter operations work well' do
|
196
|
+
assert_true @m.has_methods_for_counter
|
197
|
+
assert_false @m.has_methods_for_gauge
|
198
|
+
|
199
|
+
assert_equal 0, @m.get
|
200
|
+
assert_equal 1, @m.inc
|
201
|
+
|
202
|
+
@m.add(20)
|
203
|
+
assert_equal 21, @m.get
|
204
|
+
assert_raise NotImplementedError do
|
205
|
+
@m.dec
|
206
|
+
end
|
207
|
+
|
208
|
+
@m.set(100)
|
209
|
+
assert_equal 100, @m.get
|
210
|
+
assert_raise NotImplementedError do
|
211
|
+
@m.sub(11)
|
212
|
+
end
|
213
|
+
end
|
214
|
+
end
|
215
|
+
|
216
|
+
sub_test_case 'AliasedCounterMetric' do
|
217
|
+
setup do
|
218
|
+
@m = AliasedCounterMetrics.new
|
219
|
+
@m.configure(config_element('metrics', '', {}))
|
220
|
+
end
|
221
|
+
|
222
|
+
test 'all aliased counter operations work well' do
|
223
|
+
assert_true @m.has_methods_for_counter
|
224
|
+
assert_false @m.has_methods_for_gauge
|
225
|
+
|
226
|
+
assert_equal 0, @m.get
|
227
|
+
assert_equal 1, @m.inc
|
228
|
+
|
229
|
+
@m.add(20)
|
230
|
+
assert_equal 21, @m.get
|
231
|
+
assert_raise NotImplementedError do
|
232
|
+
@m.dec
|
233
|
+
end
|
234
|
+
|
235
|
+
@m.set(100)
|
236
|
+
assert_equal 100, @m.get
|
237
|
+
assert_raise NotImplementedError do
|
238
|
+
@m.sub(11)
|
239
|
+
end
|
240
|
+
end
|
241
|
+
end
|
242
|
+
|
243
|
+
sub_test_case 'BasicGaugeMetric' do
|
244
|
+
setup do
|
245
|
+
@m = BasicGaugeMetrics.new
|
246
|
+
@m.use_gauge_metric = true
|
247
|
+
@m.configure(config_element('metrics', '', {}))
|
248
|
+
end
|
249
|
+
|
250
|
+
test 'all basic gauge operations work well' do
|
251
|
+
assert_false @m.has_methods_for_counter
|
252
|
+
assert_true @m.has_methods_for_gauge
|
253
|
+
|
254
|
+
assert_equal 0, @m.get
|
255
|
+
assert_equal 1, @m.inc
|
256
|
+
|
257
|
+
@m.add(20)
|
258
|
+
assert_equal 21, @m.get
|
259
|
+
@m.dec
|
260
|
+
assert_equal 20, @m.get
|
261
|
+
|
262
|
+
@m.set(100)
|
263
|
+
assert_equal 100, @m.get
|
264
|
+
@m.sub(11)
|
265
|
+
assert_equal 89, @m.get
|
266
|
+
end
|
267
|
+
end
|
268
|
+
|
269
|
+
sub_test_case 'AliasedGaugeMetric' do
|
270
|
+
setup do
|
271
|
+
@m = AliasedGaugeMetrics.new
|
272
|
+
@m.use_gauge_metric = true
|
273
|
+
@m.configure(config_element('metrics', '', {}))
|
274
|
+
end
|
275
|
+
|
276
|
+
test 'all aliased gauge operations work well' do
|
277
|
+
assert_false @m.has_methods_for_counter
|
278
|
+
assert_true @m.has_methods_for_gauge
|
279
|
+
|
280
|
+
assert_equal 0, @m.get
|
281
|
+
assert_equal 1, @m.inc
|
282
|
+
|
283
|
+
@m.add(20)
|
284
|
+
assert_equal 21, @m.get
|
285
|
+
@m.dec
|
286
|
+
assert_equal 20, @m.get
|
287
|
+
|
288
|
+
@m.set(100)
|
289
|
+
assert_equal 100, @m.get
|
290
|
+
@m.sub(11)
|
291
|
+
assert_equal 89, @m.get
|
292
|
+
end
|
293
|
+
end
|
294
|
+
end
|
@@ -0,0 +1,96 @@
|
|
1
|
+
require_relative '../helper'
|
2
|
+
require 'fluent/plugin/metrics_local'
|
3
|
+
require 'fluent/system_config'
|
4
|
+
|
5
|
+
class LocalMetricsTest < ::Test::Unit::TestCase
|
6
|
+
sub_test_case 'configure' do
|
7
|
+
test "configured for counter mode" do
|
8
|
+
m = Fluent::Plugin::LocalMetrics.new
|
9
|
+
m.configure(config_element('metrics', '', {"labels" => {test: "test-unit", language: "Ruby"}}))
|
10
|
+
|
11
|
+
assert_false m.use_gauge_metric
|
12
|
+
assert_equal({agent: "Fluentd", hostname: "#{Socket.gethostname}"}, m.default_labels)
|
13
|
+
assert_equal({test: "test-unit", language: "Ruby"}, m.labels)
|
14
|
+
assert_true m.has_methods_for_counter
|
15
|
+
assert_false m.has_methods_for_gauge
|
16
|
+
end
|
17
|
+
|
18
|
+
test "configured for gauge mode" do
|
19
|
+
m = Fluent::Plugin::LocalMetrics.new
|
20
|
+
m.use_gauge_metric = true
|
21
|
+
m.configure(config_element('metrics', '', {"labels" => {test: "test-unit", language: "Ruby"}}))
|
22
|
+
|
23
|
+
assert_true m.use_gauge_metric
|
24
|
+
assert_equal({agent: "Fluentd", hostname: "#{Socket.gethostname}"}, m.default_labels)
|
25
|
+
assert_equal({test: "test-unit", language: "Ruby"}, m.labels)
|
26
|
+
assert_false m.has_methods_for_counter
|
27
|
+
assert_true m.has_methods_for_gauge
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
sub_test_case 'LocalMetric' do
|
32
|
+
sub_test_case "counter" do
|
33
|
+
setup do
|
34
|
+
@m = Fluent::Plugin::LocalMetrics.new
|
35
|
+
@m.configure(config_element('metrics', '', {}))
|
36
|
+
end
|
37
|
+
|
38
|
+
test '#configure' do
|
39
|
+
assert_true @m.has_methods_for_counter
|
40
|
+
assert_false @m.has_methods_for_gauge
|
41
|
+
end
|
42
|
+
|
43
|
+
test 'all local counter operations work well' do
|
44
|
+
assert_equal 0, @m.get
|
45
|
+
assert_equal 1, @m.inc
|
46
|
+
|
47
|
+
@m.add(20)
|
48
|
+
assert_equal 21, @m.get
|
49
|
+
assert_raise NotImplementedError do
|
50
|
+
@m.dec
|
51
|
+
end
|
52
|
+
|
53
|
+
@m.set(100)
|
54
|
+
assert_equal 100, @m.get
|
55
|
+
|
56
|
+
@m.set(10)
|
57
|
+
assert_equal 100, @m.get # On counter, value should be overwritten bigger than stored one.
|
58
|
+
assert_raise NotImplementedError do
|
59
|
+
@m.sub(11)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
sub_test_case "gauge" do
|
65
|
+
setup do
|
66
|
+
@m = Fluent::Plugin::LocalMetrics.new
|
67
|
+
@m.use_gauge_metric = true
|
68
|
+
@m.configure(config_element('metrics', '', {}))
|
69
|
+
end
|
70
|
+
|
71
|
+
test '#configure' do
|
72
|
+
assert_false @m.has_methods_for_counter
|
73
|
+
assert_true @m.has_methods_for_gauge
|
74
|
+
end
|
75
|
+
|
76
|
+
test 'all local gauge operations work well' do
|
77
|
+
assert_equal 0, @m.get
|
78
|
+
assert_equal 1, @m.inc
|
79
|
+
|
80
|
+
@m.add(20)
|
81
|
+
assert_equal 21, @m.get
|
82
|
+
@m.dec
|
83
|
+
assert_equal 20, @m.get
|
84
|
+
|
85
|
+
@m.set(100)
|
86
|
+
assert_equal 100, @m.get
|
87
|
+
|
88
|
+
@m.sub(11)
|
89
|
+
assert_equal 89, @m.get
|
90
|
+
|
91
|
+
@m.set(10)
|
92
|
+
assert_equal 10, @m.get # On gauge, value always should be overwritten.
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
@@ -146,8 +146,11 @@ class MultiOutputTest < Test::Unit::TestCase
|
|
146
146
|
@i.configure(conf)
|
147
147
|
assert_equal 4, @i.outputs.size
|
148
148
|
|
149
|
+
log_size_for_multi_output_itself = 4
|
150
|
+
log_size_for_metrics_plugin_helper = 4
|
151
|
+
expected_warn_log_size = log_size_for_multi_output_itself + log_size_for_metrics_plugin_helper
|
149
152
|
logs = @i.log.out.logs
|
150
|
-
assert{ logs.select{|log| log.include?('[warn]') && log.include?("'type' is deprecated parameter name. use '@type' instead.") }.size ==
|
153
|
+
assert{ logs.select{|log| log.include?('[warn]') && log.include?("'type' is deprecated parameter name. use '@type' instead.") }.size == expected_warn_log_size }
|
151
154
|
end
|
152
155
|
|
153
156
|
test '#emit_events calls #process always' do
|
@@ -176,5 +179,26 @@ class MultiOutputTest < Test::Unit::TestCase
|
|
176
179
|
|
177
180
|
assert_equal 2, @i.events.size
|
178
181
|
end
|
182
|
+
|
183
|
+
test 'can use metrics plugins and fallback methods' do
|
184
|
+
conf = config_element('ROOT', '', { '@type' => 'dummy_test_multi_output' },
|
185
|
+
[
|
186
|
+
config_element('store', '', { 'type' => 'dummy_test_multi_output_1' }),
|
187
|
+
config_element('store', '', { 'type' => 'dummy_test_multi_output_2' }),
|
188
|
+
config_element('store', '', { 'type' => 'dummy_test_multi_output_3' }),
|
189
|
+
config_element('store', '', { 'type' => 'dummy_test_multi_output_4' }),
|
190
|
+
]
|
191
|
+
)
|
192
|
+
@i.configure(conf)
|
193
|
+
|
194
|
+
%w[num_errors_metrics emit_count_metrics emit_size_metrics emit_records_metrics].each do |metric_name|
|
195
|
+
assert_true @i.instance_variable_get(:"@#{metric_name}").is_a?(Fluent::Plugin::Metrics)
|
196
|
+
end
|
197
|
+
|
198
|
+
assert_equal 0, @i.num_errors
|
199
|
+
assert_equal 0, @i.emit_count
|
200
|
+
assert_equal 0, @i.emit_size
|
201
|
+
assert_equal 0, @i.emit_records
|
202
|
+
end
|
179
203
|
end
|
180
204
|
end
|
data/test/plugin/test_output.rb
CHANGED
@@ -223,6 +223,22 @@ class OutputTest < Test::Unit::TestCase
|
|
223
223
|
assert @i.terminated?
|
224
224
|
end
|
225
225
|
|
226
|
+
test 'can use metrics plugins and fallback methods' do
|
227
|
+
@i.configure(config_element())
|
228
|
+
|
229
|
+
%w[num_errors_metrics emit_count_metrics emit_size_metrics emit_records_metrics
|
230
|
+
write_count_metrics rollback_count_metrics flush_time_count_metrics slow_flush_count_metrics].each do |metric_name|
|
231
|
+
assert_true @i.instance_variable_get(:"@#{metric_name}").is_a?(Fluent::Plugin::Metrics)
|
232
|
+
end
|
233
|
+
|
234
|
+
assert_equal 0, @i.num_errors
|
235
|
+
assert_equal 0, @i.emit_count
|
236
|
+
assert_equal 0, @i.emit_size
|
237
|
+
assert_equal 0, @i.emit_records
|
238
|
+
assert_equal 0, @i.write_count
|
239
|
+
assert_equal 0, @i.rollback_count
|
240
|
+
end
|
241
|
+
|
226
242
|
data(:new_api => :chunk,
|
227
243
|
:old_api => :metadata)
|
228
244
|
test '#extract_placeholders does nothing if chunk key is not specified' do |api|
|
@@ -1,6 +1,7 @@
|
|
1
1
|
require_relative '../helper'
|
2
2
|
require 'fluent/plugin_helper/event_emitter'
|
3
3
|
require 'fluent/plugin/base'
|
4
|
+
require 'flexmock/test_unit'
|
4
5
|
|
5
6
|
class EventEmitterTest < Test::Unit::TestCase
|
6
7
|
setup do
|
@@ -48,4 +49,32 @@ class EventEmitterTest < Test::Unit::TestCase
|
|
48
49
|
|
49
50
|
d1.terminate
|
50
51
|
end
|
52
|
+
|
53
|
+
test 'should not have event_emitter_router' do
|
54
|
+
d0 = Dummy0.new
|
55
|
+
assert !d0.respond_to?(:event_emitter_router)
|
56
|
+
end
|
57
|
+
|
58
|
+
test 'should have event_emitter_router' do
|
59
|
+
d = Dummy.new
|
60
|
+
assert d.respond_to?(:event_emitter_router)
|
61
|
+
end
|
62
|
+
|
63
|
+
test 'get router' do
|
64
|
+
router_mock = flexmock('mytest')
|
65
|
+
label_mock = flexmock('mylabel')
|
66
|
+
label_mock.should_receive(:event_router).twice.and_return(router_mock)
|
67
|
+
Fluent::Engine.root_agent.labels['@mytest'] = label_mock
|
68
|
+
|
69
|
+
d = Dummy.new
|
70
|
+
d.configure(config_element('ROOT', '', {'@label' => '@mytest'}))
|
71
|
+
router = d.event_emitter_router("@mytest")
|
72
|
+
assert_equal router_mock, router
|
73
|
+
end
|
74
|
+
|
75
|
+
test 'get root router' do
|
76
|
+
d = Dummy.new
|
77
|
+
router = d.event_emitter_router("@ROOT")
|
78
|
+
assert_equal Fluent::Engine.root_agent.event_router, router
|
79
|
+
end
|
51
80
|
end
|
@@ -0,0 +1,137 @@
|
|
1
|
+
require_relative '../helper'
|
2
|
+
require 'fluent/plugin_helper/metrics'
|
3
|
+
require 'fluent/plugin/base'
|
4
|
+
|
5
|
+
class MetricsTest < Test::Unit::TestCase
|
6
|
+
class Dummy < Fluent::Plugin::TestBase
|
7
|
+
helpers :metrics
|
8
|
+
def configure(conf)
|
9
|
+
super
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
setup do
|
14
|
+
@d = nil
|
15
|
+
end
|
16
|
+
|
17
|
+
teardown do
|
18
|
+
if @d
|
19
|
+
@d.stop unless @d.stopped?
|
20
|
+
@d.shutdown unless @d.shutdown?
|
21
|
+
@d.close unless @d.closed?
|
22
|
+
@d.terminate unless @d.terminated?
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
test 'can be initialized without any metrics at first' do
|
27
|
+
d = Dummy.new
|
28
|
+
assert_equal 0, d._metrics.size
|
29
|
+
end
|
30
|
+
|
31
|
+
test 'can be configured' do
|
32
|
+
d1 = Dummy.new
|
33
|
+
assert_nothing_raised do
|
34
|
+
d1.configure(config_element())
|
35
|
+
end
|
36
|
+
assert d1.plugin_id
|
37
|
+
assert d1.log
|
38
|
+
end
|
39
|
+
|
40
|
+
test 'creates metrics instances' do
|
41
|
+
d = Dummy.new
|
42
|
+
i = d.metrics_create(namespace: "fluentd_test", subsystem: "unit-test", name: "metrics1", help_text: "metrics testing")
|
43
|
+
d.configure(config_element())
|
44
|
+
assert do
|
45
|
+
d.instance_variable_get(:@plugin_type_or_id).include?("dummy.object")
|
46
|
+
end
|
47
|
+
assert{ i.is_a?(Fluent::Plugin::LocalMetrics) }
|
48
|
+
assert_true i.has_methods_for_counter
|
49
|
+
assert_false i.has_methods_for_gauge
|
50
|
+
|
51
|
+
d = Dummy.new
|
52
|
+
i = d.metrics_create(namespace: "fluentd_test", subsystem: "unit-test", name: "metrics2", help_text: "metrics testing", prefer_gauge: true)
|
53
|
+
d.configure(config_element())
|
54
|
+
assert do
|
55
|
+
d.instance_variable_get(:@plugin_type_or_id).include?("dummy.object")
|
56
|
+
end
|
57
|
+
assert{ i.is_a?(Fluent::Plugin::LocalMetrics) }
|
58
|
+
assert_false i.has_methods_for_counter
|
59
|
+
assert_true i.has_methods_for_gauge
|
60
|
+
end
|
61
|
+
|
62
|
+
test 'calls lifecycle methods for all plugin instances via owner plugin' do
|
63
|
+
@d = d = Dummy.new
|
64
|
+
i1 = d.metrics_create(namespace: "fluentd_test", subsystem: "unit-test", name: "metrics1", help_text: "metrics testing")
|
65
|
+
i2 = d.metrics_create(namespace: "fluentd_test", subsystem: "unit-test", name: "metrics2", help_text: "metrics testing", prefer_gauge: true)
|
66
|
+
i3 = d.metrics_create(namespace: "fluentd_test", subsystem: "unit-test", name: "metrics3", help_text: "metrics testing")
|
67
|
+
d.configure(config_element())
|
68
|
+
assert do
|
69
|
+
d.instance_variable_get(:@plugin_type_or_id).include?("dummy.object")
|
70
|
+
end
|
71
|
+
d.start
|
72
|
+
|
73
|
+
assert i1.started?
|
74
|
+
assert i2.started?
|
75
|
+
assert i3.started?
|
76
|
+
|
77
|
+
assert !i1.stopped?
|
78
|
+
assert !i2.stopped?
|
79
|
+
assert !i3.stopped?
|
80
|
+
|
81
|
+
d.stop
|
82
|
+
|
83
|
+
assert i1.stopped?
|
84
|
+
assert i2.stopped?
|
85
|
+
assert i3.stopped?
|
86
|
+
|
87
|
+
assert !i1.before_shutdown?
|
88
|
+
assert !i2.before_shutdown?
|
89
|
+
assert !i3.before_shutdown?
|
90
|
+
|
91
|
+
d.before_shutdown
|
92
|
+
|
93
|
+
assert i1.before_shutdown?
|
94
|
+
assert i2.before_shutdown?
|
95
|
+
assert i3.before_shutdown?
|
96
|
+
|
97
|
+
assert !i1.shutdown?
|
98
|
+
assert !i2.shutdown?
|
99
|
+
assert !i3.shutdown?
|
100
|
+
|
101
|
+
d.shutdown
|
102
|
+
|
103
|
+
assert i1.shutdown?
|
104
|
+
assert i2.shutdown?
|
105
|
+
assert i3.shutdown?
|
106
|
+
|
107
|
+
assert !i1.after_shutdown?
|
108
|
+
assert !i2.after_shutdown?
|
109
|
+
assert !i3.after_shutdown?
|
110
|
+
|
111
|
+
d.after_shutdown
|
112
|
+
|
113
|
+
assert i1.after_shutdown?
|
114
|
+
assert i2.after_shutdown?
|
115
|
+
assert i3.after_shutdown?
|
116
|
+
|
117
|
+
assert !i1.closed?
|
118
|
+
assert !i2.closed?
|
119
|
+
assert !i3.closed?
|
120
|
+
|
121
|
+
d.close
|
122
|
+
|
123
|
+
assert i1.closed?
|
124
|
+
assert i2.closed?
|
125
|
+
assert i3.closed?
|
126
|
+
|
127
|
+
assert !i1.terminated?
|
128
|
+
assert !i2.terminated?
|
129
|
+
assert !i3.terminated?
|
130
|
+
|
131
|
+
d.terminate
|
132
|
+
|
133
|
+
assert i1.terminated?
|
134
|
+
assert i2.terminated?
|
135
|
+
assert i3.terminated?
|
136
|
+
end
|
137
|
+
end
|
data/test/test_event_time.rb
CHANGED
@@ -64,8 +64,8 @@ class EventTimeTest < Test::Unit::TestCase
|
|
64
64
|
|
65
65
|
test 'Oj.dump' do
|
66
66
|
time = Fluent::EventTime.new(100)
|
67
|
-
require 'fluent/
|
68
|
-
|
67
|
+
require 'fluent/oj_options'
|
68
|
+
Fluent::OjOptions.load_env
|
69
69
|
assert_equal('{"time":100}', Oj.dump({'time' => time}))
|
70
70
|
assert_equal('["tag",100,{"key":"value"}]', Oj.dump(["tag", time, {"key" => "value"}], mode: :compat))
|
71
71
|
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require_relative 'helper'
|
2
|
+
require 'fluent/test'
|
3
|
+
require 'fluent/oj_options'
|
4
|
+
|
5
|
+
class OjOptionsTest < ::Test::Unit::TestCase
|
6
|
+
begin
|
7
|
+
require 'oj'
|
8
|
+
@@oj_is_avaibale = true
|
9
|
+
rescue LoadError
|
10
|
+
@@oj_is_avaibale = false
|
11
|
+
end
|
12
|
+
|
13
|
+
setup do
|
14
|
+
@orig_env = {}
|
15
|
+
ENV.each do |key, value|
|
16
|
+
@orig_env[key] = value if key.start_with?("FLUENT_OJ_OPTION_")
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
teardown do
|
21
|
+
ENV.delete_if { |key| key.start_with?("FLUENT_OJ_OPTION_") }
|
22
|
+
@orig_env.each { |key, value| ENV[key] = value }
|
23
|
+
end
|
24
|
+
|
25
|
+
test "available?" do
|
26
|
+
assert_equal(@@oj_is_avaibale, Fluent::OjOptions.available?)
|
27
|
+
end
|
28
|
+
|
29
|
+
sub_test_case "set by environment variable" do
|
30
|
+
test "when no env vars set, returns default options" do
|
31
|
+
ENV.delete_if { |key| key.start_with?("FLUENT_OJ_OPTION_") }
|
32
|
+
defaults = Fluent::OjOptions::DEFAULTS
|
33
|
+
assert_equal(defaults, Fluent::OjOptions.load_env)
|
34
|
+
assert_equal(defaults, Oj.default_options.slice(*defaults.keys)) if @@oj_is_avaibale
|
35
|
+
end
|
36
|
+
|
37
|
+
test "valid env var passed with valid value, default is overridden" do
|
38
|
+
ENV["FLUENT_OJ_OPTION_BIGDECIMAL_LOAD"] = ":bigdecimal"
|
39
|
+
assert_equal(:bigdecimal, Fluent::OjOptions.load_env[:bigdecimal_load])
|
40
|
+
assert_equal(:bigdecimal, Oj.default_options[:bigdecimal_load]) if @@oj_is_avaibale
|
41
|
+
end
|
42
|
+
|
43
|
+
test "valid env var passed with invalid value, default is not overriden" do
|
44
|
+
ENV["FLUENT_OJ_OPTION_BIGDECIMAL_LOAD"] = ":conor"
|
45
|
+
assert_equal(:float, Fluent::OjOptions.load_env[:bigdecimal_load])
|
46
|
+
assert_equal(:float, Oj.default_options[:bigdecimal_load]) if @@oj_is_avaibale
|
47
|
+
end
|
48
|
+
|
49
|
+
test "invalid env var passed, nothing done with it" do
|
50
|
+
ENV["FLUENT_OJ_OPTION_CONOR"] = ":conor"
|
51
|
+
assert_equal(nil, Fluent::OjOptions.load_env[:conor])
|
52
|
+
assert_equal(nil, Oj.default_options[:conor]) if @@oj_is_avaibale
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|