fluentd 1.13.3 → 1.14.2

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

Potentially problematic release.


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

Files changed (63) hide show
  1. checksums.yaml +4 -4
  2. data/.drone.yml +6 -6
  3. data/.github/ISSUE_TEMPLATE/bug_report.yaml +1 -0
  4. data/.github/workflows/windows-test.yaml +3 -3
  5. data/CHANGELOG.md +96 -0
  6. data/fluentd.gemspec +1 -1
  7. data/lib/fluent/command/cat.rb +13 -3
  8. data/lib/fluent/command/fluentd.rb +8 -0
  9. data/lib/fluent/compat/output.rb +9 -6
  10. data/lib/fluent/config/parser.rb +1 -1
  11. data/lib/fluent/config/v1_parser.rb +1 -1
  12. data/lib/fluent/event_router.rb +28 -1
  13. data/lib/fluent/plugin/bare_output.rb +49 -8
  14. data/lib/fluent/plugin/buf_file.rb +2 -2
  15. data/lib/fluent/plugin/buffer.rb +84 -22
  16. data/lib/fluent/plugin/filter.rb +35 -1
  17. data/lib/fluent/plugin/in_http.rb +21 -2
  18. data/lib/fluent/plugin/in_monitor_agent.rb +4 -2
  19. data/lib/fluent/plugin/in_syslog.rb +13 -1
  20. data/lib/fluent/plugin/in_tail/position_file.rb +1 -1
  21. data/lib/fluent/plugin/in_tail.rb +37 -5
  22. data/lib/fluent/plugin/input.rb +39 -1
  23. data/lib/fluent/plugin/metrics.rb +119 -0
  24. data/lib/fluent/plugin/metrics_local.rb +96 -0
  25. data/lib/fluent/plugin/multi_output.rb +43 -6
  26. data/lib/fluent/plugin/out_copy.rb +1 -1
  27. data/lib/fluent/plugin/out_forward.rb +15 -7
  28. data/lib/fluent/plugin/output.rb +80 -38
  29. data/lib/fluent/plugin/parser_apache2.rb +1 -1
  30. data/lib/fluent/plugin/storage_local.rb +3 -5
  31. data/lib/fluent/plugin.rb +10 -1
  32. data/lib/fluent/plugin_helper/event_emitter.rb +8 -1
  33. data/lib/fluent/plugin_helper/metrics.rb +129 -0
  34. data/lib/fluent/plugin_helper/server.rb +4 -2
  35. data/lib/fluent/plugin_helper.rb +1 -0
  36. data/lib/fluent/plugin_id.rb +2 -1
  37. data/lib/fluent/root_agent.rb +6 -0
  38. data/lib/fluent/supervisor.rb +4 -2
  39. data/lib/fluent/system_config.rb +9 -1
  40. data/lib/fluent/time.rb +21 -20
  41. data/lib/fluent/version.rb +1 -1
  42. data/test/command/test_cat.rb +31 -2
  43. data/test/config/test_system_config.rb +6 -0
  44. data/test/plugin/in_tail/test_io_handler.rb +12 -4
  45. data/test/plugin/in_tail/test_position_file.rb +26 -4
  46. data/test/plugin/test_bare_output.rb +13 -0
  47. data/test/plugin/test_buffer.rb +8 -2
  48. data/test/plugin/test_filter.rb +11 -0
  49. data/test/plugin/test_in_http.rb +40 -0
  50. data/test/plugin/test_in_monitor_agent.rb +214 -8
  51. data/test/plugin/test_in_syslog.rb +35 -0
  52. data/test/plugin/test_in_tail.rb +28 -29
  53. data/test/plugin/test_input.rb +11 -0
  54. data/test/plugin/test_metrics.rb +294 -0
  55. data/test/plugin/test_metrics_local.rb +96 -0
  56. data/test/plugin/test_multi_output.rb +25 -1
  57. data/test/plugin/test_output.rb +16 -0
  58. data/test/plugin_helper/test_event_emitter.rb +29 -0
  59. data/test/plugin_helper/test_metrics.rb +137 -0
  60. data/test/test_plugin_classes.rb +102 -0
  61. data/test/test_root_agent.rb +30 -1
  62. data/test/test_time_parser.rb +22 -0
  63. metadata +13 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1603571f755a962fde001cbb33fd24ad8929633bdeb38832e61f45da2c0dfba5
4
- data.tar.gz: 5c2d45299617e9e4424758c76eb53d78889387cedc28d1d8bac549402094b6af
3
+ metadata.gz: 9607315f05f94d8852e40219924b394e3744614f12b4109ea2c2c862a9c40e04
4
+ data.tar.gz: 12b6b47e9e1f7e43e112b6db097024dde27d692434550ea9807501010b2f51fc
5
5
  SHA512:
6
- metadata.gz: 8dd4cc4947766345b5455fbae8043610d1c3d33e0e2ea9ea348a866722c099545301236d507d754e31b063017bb7daefdc8aef0e2a8078b67df83eb3c2489b2c
7
- data.tar.gz: f0d126ed7704b519c2b7db5693de9685db7fd3ed1844f770a08e1e3351f3daf0f66e4b88c9435b3e456f40e38480c9af7652241f029a36b7a13184364a595251
6
+ metadata.gz: 0110ef8bb482a0b7d4193cb96712f8011dee152637ccf8140077861074db25d2efeaf784902475ca1b65acbca34997edfbf074bd3abcdb2364fa840055503d4f
7
+ data.tar.gz: 760b7f1254b51a072dcc6b44069b6857f365da60e61b210c985b1271858b828600e4eaa7ca8257b76ea8a9d3108953ddf6d80da37fe84e23d2f6ef0e17571b4f
data/.drone.yml CHANGED
@@ -1,13 +1,13 @@
1
1
  kind: pipeline
2
- name: fluentd-test-arm64-2-6-3
2
+ name: fluentd-test-arm64-3-0
3
3
 
4
4
  platform:
5
5
  os: linux
6
6
  arch: arm64
7
7
 
8
8
  steps:
9
- - name: fluentd-test-arm64-2-6-3
10
- image: arm64v8/ruby:2.6.3
9
+ - name: fluentd-test-arm64-3-0
10
+ image: arm64v8/ruby:3.0
11
11
  commands:
12
12
  - apt update
13
13
  - apt -y install libgmp3-dev
@@ -17,15 +17,15 @@ steps:
17
17
  - bundle exec rake test
18
18
  ---
19
19
  kind: pipeline
20
- name: fluentd-test-arm64-latest
20
+ name: fluentd-test-arm64-2-7
21
21
 
22
22
  platform:
23
23
  os: linux
24
24
  arch: arm64
25
25
 
26
26
  steps:
27
- - name: fluentd-test-arm64-latest
28
- image: arm64v8/ruby:latest
27
+ - name: fluentd-test-arm64-2-7
28
+ image: arm64v8/ruby:2.7
29
29
  commands:
30
30
  - apt update
31
31
  - apt -y install libgmp3-dev
@@ -50,6 +50,7 @@ body:
50
50
  label: Your Configuration
51
51
  description: |
52
52
  Write your configuration here. Minimum reproducible fluentd.conf is recommended.
53
+ render: apache
53
54
  validations:
54
55
  required: true
55
56
  - type: textarea
@@ -18,7 +18,7 @@ jobs:
18
18
  - windows-latest
19
19
  experimental: [false]
20
20
  include:
21
- - ruby-version: '3.0.1'
21
+ - ruby-version: '3.0.2'
22
22
  os: windows-latest
23
23
  experimental: true
24
24
  # On Ruby 3.0, we need to use fiddle 1.0.8 or later to retrieve correct
@@ -28,7 +28,7 @@ jobs:
28
28
  # * https://github.com/ruby/fiddle/issues/72
29
29
  # * https://bugs.ruby-lang.org/issues/17813
30
30
  # * https://github.com/oneclick/rubyinstaller2/blob/8225034c22152d8195bc0aabc42a956c79d6c712/lib/ruby_installer/build/dll_directory.rb
31
- ruby-lib-opt: RUBYLIB=%RUNNER_TOOL_CACHE%/Ruby/3.0.1/x64/lib/ruby/gems/3.0.0/gems/fiddle-1.0.8/lib
31
+ ruby-lib-opt: RUBYLIB=%RUNNER_TOOL_CACHE%/Ruby/3.0.2/x64/lib/ruby/gems/3.0.0/gems/fiddle-1.0.8/lib
32
32
 
33
33
  name: Unit testing with Ruby ${{ matrix.ruby-version }} on ${{ matrix.os }}
34
34
  steps:
@@ -38,7 +38,7 @@ jobs:
38
38
  with:
39
39
  ruby-version: ${{ matrix.ruby-version }}
40
40
  - name: Add Fiddle 1.0.8
41
- if: ${{ matrix.ruby-version == '3.0.1' }}
41
+ if: ${{ matrix.ruby-version == '3.0.2' }}
42
42
  run: gem install fiddle --version 1.0.8
43
43
  - name: Install dependencies
44
44
  run: ridk exec bundle install
data/CHANGELOG.md CHANGED
@@ -1,3 +1,99 @@
1
+ # v1.14.2
2
+
3
+ ## Release v1.14.2 - 2021/10/29
4
+
5
+ IMPORTANT: This release contain the fix for CVE-2021-41186 -
6
+ ReDoS vulnerability in `parser_apache2`.
7
+ This vulnerability is affected from Fluentd v0.14.14 to v1.14.1.
8
+ We recommend to upgrade Fluentd to v1.14.2 or use patched version of
9
+ `parser_apache2` plugin.
10
+
11
+ ### Enhancement
12
+
13
+ * fluent-cat: Add `--event-time` option to send specified event time for testing.
14
+
15
+ ### Bug fix
16
+
17
+ * Fixed to generate correct epoch timestamp even after switching Daylight Saving Time
18
+ https://github.com/fluent/fluentd/pull/3524
19
+ * Fixed ReDoS vulnerability in parser_apache2.
20
+ This vulnerability is caused by a certain pattern of a broken apache log.
21
+
22
+ # v1.14.1
23
+
24
+ ## Release v1.14.1 - 2021/09/29
25
+
26
+ ### Enhancement
27
+
28
+ * in_tail: Added file related metrics.
29
+ These metrics should be collected same as fluent-bit's in_tail.
30
+ https://github.com/fluent/fluentd/pull/3504
31
+ * out_forward: Changed to use metrics mechanism for node statistics
32
+ https://github.com/fluent/fluentd/pull/3506
33
+
34
+ ### Bug fix
35
+
36
+ * in_tail: Fixed a crash bug that it raise undefined method of eof? error.
37
+ This error may happen only when `read_bytes_limit_per_second` was specified.
38
+ https://github.com/fluent/fluentd/pull/3500
39
+ * out_forward: Fixed a bug that node statistics information is not included correctly.
40
+ https://github.com/fluent/fluentd/pull/3503
41
+ https://github.com/fluent/fluentd/pull/3507
42
+ * Fixed a error when using `@include` directive
43
+ It was occurred when http/https scheme URI is used in `@include` directive with Ruby 3.
44
+ https://github.com/fluent/fluentd/pull/3517
45
+ * out_copy: Fixed to suppress a wrong warning for `ignore_if_prev_success`
46
+ It didn't work even if a user set it.
47
+ https://github.com/fluent/fluentd/pull/3515
48
+ * Fixed not to output nanoseconds field of next retry time in warning log
49
+ Then, inappropriate labels in log are also fixed. (retry_time -> retry_times,
50
+ next_retry_seconds -> next_retry_time)
51
+ https://github.com/fluent/fluentd/pull/3518
52
+
53
+ # v1.14.0
54
+
55
+ ## Release v1.14.0 - 2021/08/30
56
+
57
+ ### Enhancement
58
+
59
+ * Added `enable_input_metrics`, `enable_size_metrics` system
60
+ configuration parameter
61
+ This feature might need to pay higher CPU cost, so input event metrics
62
+ features are disabled by default. These features are also enabled by
63
+ `--enable-input-metrics`,`--enable-size-metrics` command line
64
+ option.
65
+ https://github.com/fluent/fluentd/pull/3440
66
+ * Added reserved word `@ROOT` for getting root router.
67
+ This is incompatible change. Do not use `@ROOT` for label name.
68
+ https://github.com/fluent/fluentd/pull/3358
69
+ * in_syslog: Added `send_keepalive_packet` option
70
+ https://github.com/fluent/fluentd/pull/3474
71
+ * in_http: Added `cors_allow_credentials` option.
72
+ This option tells browsers whether to expose the response to
73
+ frontend when the credentials mode is "include".
74
+ https://github.com/fluent/fluentd/pull/3481
75
+ https://github.com/fluent/fluentd/pull/3491
76
+
77
+ ### Bug fix
78
+
79
+ * in_tail: Fixed a bug that deleted paths are not removed
80
+ from pos file by file compaction at start up
81
+ https://github.com/fluent/fluentd/pull/3467
82
+ * in_tail: Revived a warning message of retrying unaccessible file
83
+ https://github.com/fluent/fluentd/pull/3478
84
+ * TLSServer: Fixed a crash bug on logging peer host name errors
85
+ https://github.com/fluent/fluentd/pull/3483
86
+
87
+ ### Misc
88
+
89
+ * Added metrics plugin mechanism
90
+ The implementations is changed to use metrics plugin.
91
+ In the future, 3rd party plugin will be able to handle these metrics.
92
+ https://github.com/fluent/fluentd/pull/3471
93
+ https://github.com/fluent/fluentd/pull/3473
94
+ https://github.com/fluent/fluentd/pull/3479
95
+ https://github.com/fluent/fluentd/pull/3484
96
+
1
97
  # v1.13.3
2
98
 
3
99
  ## Release v1.13.3 - 2021/07/27
data/fluentd.gemspec CHANGED
@@ -27,7 +27,7 @@ Gem::Specification.new do |gem|
27
27
  gem.add_runtime_dependency("sigdump", ["~> 0.2.2"])
28
28
  gem.add_runtime_dependency("tzinfo", [">= 1.0", "< 3.0"])
29
29
  gem.add_runtime_dependency("tzinfo-data", ["~> 1.0"])
30
- gem.add_runtime_dependency("strptime", [">= 0.2.2", "< 1.0.0"])
30
+ gem.add_runtime_dependency("strptime", [">= 0.2.4", "< 1.0.0"])
31
31
  gem.add_runtime_dependency("webrick", [">= 1.4.2", "< 1.8.0"])
32
32
 
33
33
  # build gem for a certain platform. see also Rakefile
@@ -35,6 +35,7 @@ format = 'json'
35
35
  message_key = 'message'
36
36
  time_as_integer = false
37
37
  retry_limit = 5
38
+ event_time = nil
38
39
 
39
40
  op.on('-p', '--port PORT', "fluent tcp port (default: #{port})", Integer) {|i|
40
41
  port = i
@@ -80,6 +81,10 @@ op.on('--retry-limit N', "Specify the number of retry limit (default: #{retry_li
80
81
  retry_limit = n
81
82
  }
82
83
 
84
+ op.on('--event-time TIME_STRING', "Specify the time expression string (default: nil)") {|v|
85
+ event_time = v
86
+ }
87
+
83
88
  singleton_class.module_eval do
84
89
  define_method(:usage) do |msg|
85
90
  puts op.to_s
@@ -134,7 +139,7 @@ class Writer
134
139
  end
135
140
  end
136
141
 
137
- def initialize(tag, connector, time_as_integer: false, retry_limit: 5)
142
+ def initialize(tag, connector, time_as_integer: false, retry_limit: 5, event_time: nil)
138
143
  @tag = tag
139
144
  @connector = connector
140
145
  @socket = false
@@ -148,6 +153,7 @@ class Writer
148
153
  @retry_wait = 1
149
154
  @retry_limit = retry_limit
150
155
  @time_as_integer = time_as_integer
156
+ @event_time = event_time
151
157
 
152
158
  super()
153
159
  end
@@ -166,7 +172,11 @@ class Writer
166
172
  end
167
173
  end
168
174
 
169
- time = Fluent::EventTime.now
175
+ time = if @event_time
176
+ Fluent::EventTime.parse(@event_time)
177
+ else
178
+ Fluent::EventTime.now
179
+ end
170
180
  time = time.to_i if @time_as_integer
171
181
  entry = if secondary_record?(record)
172
182
  # Even though secondary contains Fluent::EventTime in record,
@@ -309,7 +319,7 @@ else
309
319
  }
310
320
  end
311
321
 
312
- w = Writer.new(tag, connector, time_as_integer: time_as_integer, retry_limit: retry_limit)
322
+ w = Writer.new(tag, connector, time_as_integer: time_as_integer, retry_limit: retry_limit, event_time: event_time)
313
323
  w.start
314
324
 
315
325
  case format
@@ -134,6 +134,14 @@ op.on('--strict-config-value', "Parse config values strictly", TrueClass) {|b|
134
134
  opts[:strict_config_value] = b
135
135
  }
136
136
 
137
+ op.on('--enable-input-metrics', "Enable input plugin metrics on fluentd", TrueClass) {|b|
138
+ opts[:enable_input_metrics] = b
139
+ }
140
+
141
+ op.on('--enable-size-metrics', "Enable plugin record size metrics on fluentd", TrueClass) {|b|
142
+ opts[:enable_size_metrics] = b
143
+ }
144
+
137
145
  op.on('-v', '--verbose', "increase verbose level (-v: debug, -vv: trace)", TrueClass) {|b|
138
146
  if b
139
147
  opts[:log_level] = [opts[:log_level] - 1, Fluent::Log::LEVEL_TRACE].max
@@ -310,7 +310,7 @@ module Fluent
310
310
  # original implementation of v0.12 BufferedOutput
311
311
  def emit(tag, es, chain, key="")
312
312
  # this method will not be used except for the case that plugin calls super
313
- @emit_count += 1
313
+ @emit_count_metrics.inc
314
314
  data = format_stream(tag, es)
315
315
  if @buffer.emit(key, data, chain)
316
316
  submit_flush
@@ -337,14 +337,14 @@ module Fluent
337
337
  # because v0.12 BufferedOutput may overrides #format_stream, but original #handle_stream_simple method doesn't consider about it
338
338
  def handle_stream_simple(tag, es, enqueue: false)
339
339
  if @overrides_emit
340
- current_emit_count = @emit_count
340
+ current_emit_count = @emit_count_metrics.get
341
341
  size = es.size
342
342
  key = data = nil
343
343
  begin
344
344
  emit(tag, es, NULL_OUTPUT_CHAIN)
345
345
  key, data = self.last_emit_via_buffer
346
346
  ensure
347
- @emit_count = current_emit_count
347
+ @emit_count_metrics.set(current_emit_count)
348
348
  self.last_emit_via_buffer = nil
349
349
  end
350
350
  # on-the-fly key assignment can be done, and it's not configurable if Plugin#emit does it dynamically
@@ -352,7 +352,8 @@ module Fluent
352
352
  write_guard do
353
353
  @buffer.write({meta => data}, format: ->(_data){ _data }, size: ->(){ size }, enqueue: enqueue)
354
354
  end
355
- @counter_mutex.synchronize{ @emit_records += size }
355
+ @emit_records_metrics.add(es.size)
356
+ @emit_size_metrics.add(es.to_msgpack_stream.bytesize) if @enable_size_metrics
356
357
  return [meta]
357
358
  end
358
359
 
@@ -363,7 +364,8 @@ module Fluent
363
364
  write_guard do
364
365
  @buffer.write({meta => bulk}, format: ->(_data){ _data }, size: ->(){ size }, enqueue: enqueue)
365
366
  end
366
- @counter_mutex.synchronize{ @emit_records += size }
367
+ @emit_records_metrics.add(es.size)
368
+ @emit_size_metrics.add(es.to_msgpack_stream.bytesize) if @enable_size_metrics
367
369
  return [meta]
368
370
  end
369
371
 
@@ -373,7 +375,8 @@ module Fluent
373
375
  write_guard do
374
376
  @buffer.write({meta => data}, enqueue: enqueue)
375
377
  end
376
- @counter_mutex.synchronize{ @emit_records += size }
378
+ @emit_records_metrics.add(es.size)
379
+ @emit_size_metrics.add(es.to_msgpack_stream.bytesize) if @enable_size_metrics
377
380
  [meta]
378
381
  end
379
382
 
@@ -93,7 +93,7 @@ module Fluent
93
93
  basepath = '/'
94
94
  fname = path
95
95
  require 'open-uri'
96
- open(uri) {|f|
96
+ URI.open(uri) {|f|
97
97
  Parser.new(basepath, f.each_line, fname).parse!(allow_include, nil, attrs, elems)
98
98
  }
99
99
  end
@@ -172,7 +172,7 @@ module Fluent
172
172
  require 'open-uri'
173
173
  basepath = '/'
174
174
  fname = path
175
- data = open(uri) { |f| f.read }
175
+ data = URI.open(uri) { |f| f.read }
176
176
  data.force_encoding('UTF-8')
177
177
  ss = StringScanner.new(data)
178
178
  V1Parser.new(ss, basepath, fname, @eval_context).parse_element(true, nil, attrs, elems)
@@ -47,6 +47,8 @@ module Fluent
47
47
  @match_cache = MatchCache.new
48
48
  @default_collector = default_collector
49
49
  @emit_error_handler = emit_error_handler
50
+ @metric_callbacks = {}
51
+ @caller_plugin_id = nil
50
52
  end
51
53
 
52
54
  attr_accessor :default_collector
@@ -83,6 +85,22 @@ module Fluent
83
85
  @match_rules << Rule.new(pattern, collector)
84
86
  end
85
87
 
88
+ def add_metric_callbacks(caller_plugin_id, callback)
89
+ @metric_callbacks[caller_plugin_id] = callback
90
+ end
91
+
92
+ def caller_plugin_id=(caller_plugin_id)
93
+ @caller_plugin_id = caller_plugin_id
94
+ end
95
+
96
+ def find_callback
97
+ if @caller_plugin_id
98
+ @metric_callbacks[@caller_plugin_id]
99
+ else
100
+ nil
101
+ end
102
+ end
103
+
86
104
  def emit(tag, time, record)
87
105
  unless record.nil?
88
106
  emit_stream(tag, OneEventStream.new(time, record))
@@ -95,6 +113,9 @@ module Fluent
95
113
 
96
114
  def emit_stream(tag, es)
97
115
  match(tag).emit_events(tag, es)
116
+ if callback = find_callback
117
+ callback.call(es)
118
+ end
98
119
  rescue => e
99
120
  @emit_error_handler.handle_emits_error(tag, es, e)
100
121
  end
@@ -175,7 +196,11 @@ module Fluent
175
196
  if optimizable?
176
197
  optimized_filter_stream(tag, es)
177
198
  else
178
- @filters.reduce(es) { |acc, filter| filter.filter_stream(tag, acc) }
199
+ @filters.reduce(es) { |acc, filter|
200
+ filtered_es = filter.filter_stream(tag, acc)
201
+ filter.measure_metrics(filtered_es)
202
+ filtered_es
203
+ }
179
204
  end
180
205
  end
181
206
 
@@ -193,6 +218,7 @@ module Fluent
193
218
  begin
194
219
  filtered_time, filtered_record = filter.filter_with_time(tag, filtered_time, filtered_record)
195
220
  throw :break_loop unless filtered_record && filtered_time
221
+ filter.measure_metrics(OneEventStream.new(time, record))
196
222
  rescue => e
197
223
  filter.router.emit_error_event(tag, filtered_time, filtered_record, e)
198
224
  end
@@ -200,6 +226,7 @@ module Fluent
200
226
  begin
201
227
  filtered_record = filter.filter(tag, filtered_time, filtered_record)
202
228
  throw :break_loop unless filtered_record
229
+ filter.measure_metrics(OneEventStream.new(time, record))
203
230
  rescue => e
204
231
  filter.router.emit_error_event(tag, filtered_time, filtered_record, e)
205
232
  end
@@ -23,37 +23,78 @@ require 'fluent/plugin_helper'
23
23
  module Fluent
24
24
  module Plugin
25
25
  class BareOutput < Base
26
+ include PluginHelper::Mixin # for metrics
27
+
26
28
  # DO NOT USE THIS plugin for normal output plugin. Use Output instead.
27
29
  # This output plugin base class is only for meta-output plugins
28
30
  # which cannot be implemented on MultiOutput.
29
31
  # E.g,: forest, config-expander
30
32
 
33
+ helpers_internal :metrics
34
+
31
35
  include PluginId
32
36
  include PluginLoggerMixin
33
37
  include PluginHelper::Mixin
34
38
 
35
- attr_reader :num_errors, :emit_count, :emit_records
36
-
37
39
  def process(tag, es)
38
40
  raise NotImplementedError, "BUG: output plugins MUST implement this method"
39
41
  end
40
42
 
43
+ def num_errors
44
+ @num_errors_metrics.get
45
+ end
46
+
47
+ def emit_count
48
+ @emit_count_metrics.get
49
+ end
50
+
51
+ def emit_size
52
+ @emit_size_metrics.get
53
+ end
54
+
55
+ def emit_records
56
+ @emit_records_metrics.get
57
+ end
58
+
41
59
  def initialize
42
60
  super
43
61
  @counter_mutex = Mutex.new
44
62
  # TODO: well organized counters
45
- @num_errors = 0
46
- @emit_count = 0
47
- @emit_records = 0
63
+ @num_errors_metrics = nil
64
+ @emit_count_metrics = nil
65
+ @emit_records_metrics = nil
66
+ @emit_size_metrics = nil
67
+ end
68
+
69
+ def configure(conf)
70
+ super
71
+
72
+ @num_errors_metrics = metrics_create(namespace: "fluentd", subsystem: "bare_output", name: "num_errors", help_text: "Number of count num errors")
73
+ @emit_count_metrics = metrics_create(namespace: "fluentd", subsystem: "bare_output", name: "emit_records", help_text: "Number of count emits")
74
+ @emit_records_metrics = metrics_create(namespace: "fluentd", subsystem: "bare_output", name: "emit_records", help_text: "Number of emit records")
75
+ @emit_size_metrics = metrics_create(namespace: "fluentd", subsystem: "bare_output", name: "emit_size", help_text: "Total size of emit events")
76
+ @enable_size_metrics = !!system_config.enable_size_metrics
77
+ end
78
+
79
+ def statistics
80
+ stats = {
81
+ 'num_errors' => @num_errors_metrics.get,
82
+ 'emit_records' => @emit_records_metrics.get,
83
+ 'emit_count' => @emit_count_metrics.get,
84
+ 'emit_size' => @emit_size_metrics.get,
85
+ }
86
+
87
+ { 'bare_output' => stats }
48
88
  end
49
89
 
50
90
  def emit_sync(tag, es)
51
- @counter_mutex.synchronize{ @emit_count += 1 }
91
+ @emit_count_metrics.inc
52
92
  begin
53
93
  process(tag, es)
54
- @counter_mutex.synchronize{ @emit_records += es.size }
94
+ @emit_records_metrics.add(es.size)
95
+ @emit_size_metrics.add(es.to_msgpack_stream.bytesize) if @enable_size_metrics
55
96
  rescue
56
- @counter_mutex.synchronize{ @num_errors += 1 }
97
+ @num_errors_metrics.inc
57
98
  raise
58
99
  end
59
100
  end
@@ -39,8 +39,8 @@ module Fluent
39
39
  config_set_default :chunk_limit_size, DEFAULT_CHUNK_LIMIT_SIZE
40
40
  config_set_default :total_limit_size, DEFAULT_TOTAL_LIMIT_SIZE
41
41
 
42
- config_param :file_permission, :string, default: nil # '0644'
43
- config_param :dir_permission, :string, default: nil # '0755'
42
+ config_param :file_permission, :string, default: nil # '0644' (Fluent::DEFAULT_FILE_PERMISSION)
43
+ config_param :dir_permission, :string, default: nil # '0755' (Fluent::DEFAULT_DIR_PERMISSION)
44
44
 
45
45
  def initialize
46
46
  super