fluentd 1.13.2 → 1.14.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 (55) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/windows-test.yaml +3 -3
  3. data/CHANGELOG.md +99 -0
  4. data/example/v0_12_filter.conf +2 -2
  5. data/lib/fluent/command/fluentd.rb +8 -0
  6. data/lib/fluent/compat/output.rb +9 -6
  7. data/lib/fluent/config/parser.rb +1 -1
  8. data/lib/fluent/config/v1_parser.rb +1 -1
  9. data/lib/fluent/event_router.rb +28 -1
  10. data/lib/fluent/plugin/bare_output.rb +49 -8
  11. data/lib/fluent/plugin/buffer.rb +84 -22
  12. data/lib/fluent/plugin/file_wrapper.rb +22 -0
  13. data/lib/fluent/plugin/filter.rb +35 -1
  14. data/lib/fluent/plugin/in_http.rb +21 -2
  15. data/lib/fluent/plugin/in_monitor_agent.rb +4 -2
  16. data/lib/fluent/plugin/in_syslog.rb +13 -1
  17. data/lib/fluent/plugin/in_tail/position_file.rb +20 -18
  18. data/lib/fluent/plugin/in_tail.rb +46 -6
  19. data/lib/fluent/plugin/input.rb +39 -1
  20. data/lib/fluent/plugin/metrics.rb +119 -0
  21. data/lib/fluent/plugin/metrics_local.rb +96 -0
  22. data/lib/fluent/plugin/multi_output.rb +43 -6
  23. data/lib/fluent/plugin/out_copy.rb +1 -1
  24. data/lib/fluent/plugin/out_forward.rb +15 -7
  25. data/lib/fluent/plugin/output.rb +77 -36
  26. data/lib/fluent/plugin.rb +10 -1
  27. data/lib/fluent/plugin_helper/event_emitter.rb +8 -1
  28. data/lib/fluent/plugin_helper/metrics.rb +129 -0
  29. data/lib/fluent/plugin_helper/server.rb +4 -2
  30. data/lib/fluent/plugin_helper.rb +1 -0
  31. data/lib/fluent/root_agent.rb +6 -0
  32. data/lib/fluent/supervisor.rb +2 -0
  33. data/lib/fluent/system_config.rb +9 -1
  34. data/lib/fluent/version.rb +1 -1
  35. data/test/config/test_system_config.rb +6 -0
  36. data/test/plugin/in_tail/test_io_handler.rb +12 -4
  37. data/test/plugin/in_tail/test_position_file.rb +48 -8
  38. data/test/plugin/test_bare_output.rb +13 -0
  39. data/test/plugin/test_buffer.rb +8 -2
  40. data/test/plugin/test_file_wrapper.rb +11 -0
  41. data/test/plugin/test_filter.rb +11 -0
  42. data/test/plugin/test_in_http.rb +40 -0
  43. data/test/plugin/test_in_monitor_agent.rb +214 -8
  44. data/test/plugin/test_in_syslog.rb +35 -0
  45. data/test/plugin/test_in_tail.rb +72 -29
  46. data/test/plugin/test_input.rb +11 -0
  47. data/test/plugin/test_metrics.rb +294 -0
  48. data/test/plugin/test_metrics_local.rb +96 -0
  49. data/test/plugin/test_multi_output.rb +25 -1
  50. data/test/plugin/test_output.rb +16 -0
  51. data/test/plugin_helper/test_event_emitter.rb +29 -0
  52. data/test/plugin_helper/test_metrics.rb +137 -0
  53. data/test/test_plugin_classes.rb +102 -0
  54. data/test/test_root_agent.rb +30 -1
  55. metadata +11 -2
@@ -0,0 +1,129 @@
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
+ require 'forwardable'
18
+
19
+ require 'fluent/plugin'
20
+ require 'fluent/plugin/metrics'
21
+ require 'fluent/plugin_helper/timer'
22
+ require 'fluent/config/element'
23
+ require 'fluent/configurable'
24
+ require 'fluent/system_config'
25
+
26
+ module Fluent
27
+ module PluginHelper
28
+ module Metrics
29
+ include Fluent::SystemConfig::Mixin
30
+
31
+ attr_reader :_metrics # For tests.
32
+
33
+ def initialize
34
+ super
35
+ @_metrics_started = false
36
+ @_metrics = {} # usage => metrics_state
37
+ end
38
+
39
+ def configure(conf)
40
+ super
41
+
42
+ @plugin_type_or_id = if self.plugin_id_configured?
43
+ self.plugin_id
44
+ else
45
+ if type = (conf["@type"] || conf["type"])
46
+ "#{type}.#{self.plugin_id}"
47
+ else
48
+ "#{self.class.to_s.split("::").last.downcase}.#{self.plugin_id}"
49
+ end
50
+ end
51
+ end
52
+
53
+ def metrics_create(namespace: "fluentd", subsystem: "metrics", name:, help_text:, labels: {}, prefer_gauge: false)
54
+ metrics = if system_config.metrics
55
+ Fluent::Plugin.new_metrics(system_config.metrics[:@type], parent: self)
56
+ else
57
+ Fluent::Plugin.new_metrics(Fluent::Plugin::Metrics::DEFAULT_TYPE, parent: self)
58
+ end
59
+ config = if system_config.metrics
60
+ system_config.metrics.corresponding_config_element
61
+ else
62
+ Fluent::Config::Element.new('metrics', '', {'@type' => Fluent::Plugin::Metrics::DEFAULT_TYPE}, [])
63
+ end
64
+ metrics.use_gauge_metric = prefer_gauge
65
+ metrics.configure(config)
66
+ # For multi workers environment, cmetrics should be distinguish with static labels.
67
+ if Fluent::Engine.system_config.workers > 1
68
+ labels.merge!(worker_id: fluentd_worker_id.to_s)
69
+ end
70
+ labels.merge!(plugin: @plugin_type_or_id)
71
+ metrics.create(namespace: namespace, subsystem: subsystem, name: name, help_text: help_text, labels: labels)
72
+
73
+ @_metrics["#{@plugin_type_or_id}_#{namespace}_#{subsystem}_#{name}"] = metrics
74
+
75
+ metrics
76
+ end
77
+
78
+ def metrics_operate(method_name, &block)
79
+ @_metrics.each_pair do |key, m|
80
+ begin
81
+ block.call(s) if block_given?
82
+ m.__send__(method_name)
83
+ rescue => e
84
+ log.error "unexpected error while #{method_name}", key: key, metrics: m, error: e
85
+ end
86
+ end
87
+ end
88
+
89
+ def start
90
+ super
91
+
92
+ metrics_operate(:start)
93
+ @_metrics_started = true
94
+ end
95
+
96
+ def stop
97
+ super
98
+ # timer stops automatically in super
99
+ metrics_operate(:stop)
100
+ end
101
+
102
+ def before_shutdown
103
+ metrics_operate(:before_shutdown)
104
+ super
105
+ end
106
+
107
+ def shutdown
108
+ metrics_operate(:shutdown)
109
+ super
110
+ end
111
+
112
+ def after_shutdown
113
+ metrics_operate(:after_shutdown)
114
+ super
115
+ end
116
+
117
+ def close
118
+ metrics_operate(:close)
119
+ super
120
+ end
121
+
122
+ def terminate
123
+ metrics_operate(:terminate)
124
+ @_metrics = {}
125
+ super
126
+ end
127
+ end
128
+ end
129
+ end
@@ -709,13 +709,15 @@ module Fluent
709
709
  return true
710
710
  end
711
711
  rescue Errno::EPIPE, Errno::ECONNRESET, Errno::ETIMEDOUT, Errno::ECONNREFUSED, Errno::EHOSTUNREACH => e
712
+ peeraddr = (@_handler_socket.peeraddr rescue PEERADDR_FAILED)
712
713
  @log.trace "unexpected error before accepting TLS connection",
713
- host: @_handler_socket.peeraddr[3], port: @_handler_socket.peeraddr[1], error: e
714
+ addr: peeraddr[3], host: peeraddr[2], port: peeraddr[1], error: e
714
715
  close rescue nil
715
716
  rescue OpenSSL::SSL::SSLError => e
717
+ peeraddr = (@_handler_socket.peeraddr rescue PEERADDR_FAILED)
716
718
  # Use same log level as on_readable
717
719
  @log.warn "unexpected error before accepting TLS connection by OpenSSL",
718
- host: @_handler_socket.peeraddr[3], port: @_handler_socket.peeraddr[1], error: e
720
+ addr: peeraddr[3], host: peeraddr[2], port: peeraddr[1], error: e
719
721
  close rescue nil
720
722
  end
721
723
 
@@ -32,6 +32,7 @@ require 'fluent/plugin_helper/retry_state'
32
32
  require 'fluent/plugin_helper/record_accessor'
33
33
  require 'fluent/plugin_helper/compat_parameters'
34
34
  require 'fluent/plugin_helper/service_discovery'
35
+ require 'fluent/plugin_helper/metrics'
35
36
 
36
37
  module Fluent
37
38
  module PluginHelper
@@ -55,9 +55,11 @@ module Fluent
55
55
  @suppress_emit_error_log_interval = 0
56
56
  @next_emit_error_log_time = nil
57
57
  @without_source = false
58
+ @enable_input_metrics = false
58
59
 
59
60
  suppress_interval(system_config.emit_error_log_interval) unless system_config.emit_error_log_interval.nil?
60
61
  @without_source = system_config.without_source unless system_config.without_source.nil?
62
+ @enable_input_metrics = !!system_config.enable_input_metrics
61
63
  end
62
64
 
63
65
  attr_reader :inputs
@@ -131,6 +133,7 @@ module Fluent
131
133
  end
132
134
  name = e.arg
133
135
  raise ConfigError, "Missing symbol argument on <label> directive" if name.empty?
136
+ raise ConfigError, "@ROOT for <label> is not permitted, reserved for getting root router" if name == '@ROOT'
134
137
 
135
138
  if name == ERROR_LABEL
136
139
  error_label_config = e
@@ -315,6 +318,9 @@ module Fluent
315
318
  # See also 'fluentd/plugin/input.rb'
316
319
  input.context_router = @event_router
317
320
  input.configure(conf)
321
+ if @enable_input_metrics
322
+ @event_router.add_metric_callbacks(input.plugin_id, Proc.new {|es| input.metric_callback(es) })
323
+ end
318
324
  @inputs << input
319
325
 
320
326
  input
@@ -570,6 +570,8 @@ module Fluent
570
570
  suppress_repeated_stacktrace: true,
571
571
  ignore_repeated_log_interval: nil,
572
572
  without_source: nil,
573
+ enable_input_metrics: nil,
574
+ enable_size_metrics: nil,
573
575
  use_v1_config: true,
574
576
  strict_config_value: nil,
575
577
  supervise: true,
@@ -27,7 +27,8 @@ module Fluent
27
27
  :log_event_verbose, :ignore_repeated_log_interval, :ignore_same_log_interval,
28
28
  :without_source, :rpc_endpoint, :enable_get_dump, :process_name,
29
29
  :file_permission, :dir_permission, :counter_server, :counter_client,
30
- :strict_config_value, :enable_msgpack_time_support, :disable_shared_socket
30
+ :strict_config_value, :enable_msgpack_time_support, :disable_shared_socket,
31
+ :metrics, :enable_input_metrics, :enable_size_metrics
31
32
  ]
32
33
 
33
34
  config_param :workers, :integer, default: 1
@@ -46,6 +47,8 @@ module Fluent
46
47
  config_param :strict_config_value, :bool, default: nil
47
48
  config_param :enable_msgpack_time_support, :bool, default: nil
48
49
  config_param :disable_shared_socket, :bool, default: nil
50
+ config_param :enable_input_metrics, :bool, default: nil
51
+ config_param :enable_size_metrics, :bool, default: nil
49
52
  config_param :file_permission, default: nil do |v|
50
53
  v.to_i(8)
51
54
  end
@@ -93,6 +96,11 @@ module Fluent
93
96
  config_param :timeout, :time, default: nil
94
97
  end
95
98
 
99
+ config_section :metrics, multi: false do
100
+ config_param :@type, :string, default: "local"
101
+ config_param :labels, :hash, default: {}
102
+ end
103
+
96
104
  def self.create(conf, strict_config_value=false)
97
105
  systems = conf.elements(name: 'system')
98
106
  return SystemConfig.new if systems.empty?
@@ -16,6 +16,6 @@
16
16
 
17
17
  module Fluent
18
18
 
19
- VERSION = '1.13.2'
19
+ VERSION = '1.14.1'
20
20
 
21
21
  end
@@ -28,6 +28,8 @@ module Fluent::Config
28
28
  log_event_label: nil,
29
29
  log_event_verbose: nil,
30
30
  without_source: nil,
31
+ enable_input_metrics: nil,
32
+ enable_size_metrics: nil,
31
33
  emit_error_log_interval: nil,
32
34
  file_permission: nil,
33
35
  dir_permission: nil,
@@ -77,6 +79,8 @@ module Fluent::Config
77
79
  assert_nil(sc.emit_error_log_interval)
78
80
  assert_nil(sc.suppress_config_dump)
79
81
  assert_nil(sc.without_source)
82
+ assert_nil(sc.enable_input_metrics)
83
+ assert_nil(sc.enable_size_metrics)
80
84
  assert_nil(sc.enable_msgpack_time_support)
81
85
  assert_equal(:text, sc.log.format)
82
86
  assert_equal('%Y-%m-%d %H:%M:%S %z', sc.log.time_format)
@@ -93,6 +97,8 @@ module Fluent::Config
93
97
  'without_source' => ['without_source', true],
94
98
  'strict_config_value' => ['strict_config_value', true],
95
99
  'enable_msgpack_time_support' => ['enable_msgpack_time_support', true],
100
+ 'enable_input_metrics' => ['enable_input_metrics', true],
101
+ 'enable_size_metrics' => ['enable_size_metrics', true],
96
102
  )
97
103
  test "accepts parameters" do |(k, v)|
98
104
  conf = parse_text(<<-EOS)
@@ -1,11 +1,19 @@
1
1
  require_relative '../../helper'
2
2
 
3
3
  require 'fluent/plugin/in_tail'
4
+ require 'fluent/plugin/metrics_local'
4
5
  require 'tempfile'
5
6
 
6
7
  class IntailIOHandlerTest < Test::Unit::TestCase
7
8
  setup do
8
9
  @file = Tempfile.new('intail_io_handler').binmode
10
+ opened_file_metrics = Fluent::Plugin::LocalMetrics.new
11
+ opened_file_metrics.configure(config_element('metrics', '', {}))
12
+ closed_file_metrics = Fluent::Plugin::LocalMetrics.new
13
+ closed_file_metrics.configure(config_element('metrics', '', {}))
14
+ rotated_file_metrics = Fluent::Plugin::LocalMetrics.new
15
+ rotated_file_metrics.configure(config_element('metrics', '', {}))
16
+ @metrics = Fluent::Plugin::TailInput::MetricsInfo.new(opened_file_metrics, closed_file_metrics, rotated_file_metrics)
9
17
  end
10
18
 
11
19
  teardown do
@@ -30,7 +38,7 @@ class IntailIOHandlerTest < Test::Unit::TestCase
30
38
  end
31
39
 
32
40
  returned_lines = ''
33
- r = Fluent::Plugin::TailInput::TailWatcher::IOHandler.new(watcher, path: @file.path, read_lines_limit: 100, read_bytes_limit_per_second: -1, log: $log, open_on_every_update: false) do |lines, _watcher|
41
+ r = Fluent::Plugin::TailInput::TailWatcher::IOHandler.new(watcher, path: @file.path, read_lines_limit: 100, read_bytes_limit_per_second: -1, log: $log, open_on_every_update: false, metrics: @metrics) do |lines, _watcher|
34
42
  returned_lines << lines.join
35
43
  true
36
44
  end
@@ -62,7 +70,7 @@ class IntailIOHandlerTest < Test::Unit::TestCase
62
70
  end
63
71
 
64
72
  returned_lines = ''
65
- r = Fluent::Plugin::TailInput::TailWatcher::IOHandler.new(watcher, path: @file.path, read_lines_limit: 100, read_bytes_limit_per_second: -1, log: $log, open_on_every_update: true) do |lines, _watcher|
73
+ r = Fluent::Plugin::TailInput::TailWatcher::IOHandler.new(watcher, path: @file.path, read_lines_limit: 100, read_bytes_limit_per_second: -1, log: $log, open_on_every_update: true, metrics: @metrics) do |lines, _watcher|
66
74
  returned_lines << lines.join
67
75
  true
68
76
  end
@@ -93,7 +101,7 @@ class IntailIOHandlerTest < Test::Unit::TestCase
93
101
  end
94
102
 
95
103
  returned_lines = []
96
- r = Fluent::Plugin::TailInput::TailWatcher::IOHandler.new(watcher, path: @file.path, read_lines_limit: 5, read_bytes_limit_per_second: -1, log: $log, open_on_every_update: false) do |lines, _watcher|
104
+ r = Fluent::Plugin::TailInput::TailWatcher::IOHandler.new(watcher, path: @file.path, read_lines_limit: 5, read_bytes_limit_per_second: -1, log: $log, open_on_every_update: false, metrics: @metrics) do |lines, _watcher|
97
105
  returned_lines << lines.dup
98
106
  true
99
107
  end
@@ -119,7 +127,7 @@ class IntailIOHandlerTest < Test::Unit::TestCase
119
127
  end
120
128
 
121
129
  returned_lines = []
122
- r = Fluent::Plugin::TailInput::TailWatcher::IOHandler.new(watcher, path: @file.path, read_lines_limit: 5, read_bytes_limit_per_second: -1, log: $log, open_on_every_update: false) do |lines, _watcher|
130
+ r = Fluent::Plugin::TailInput::TailWatcher::IOHandler.new(watcher, path: @file.path, read_lines_limit: 5, read_bytes_limit_per_second: -1, log: $log, open_on_every_update: false, metrics: @metrics) do |lines, _watcher|
123
131
  returned_lines << lines.dup
124
132
  true
125
133
  end
@@ -22,6 +22,10 @@ class IntailPositionFileTest < Test::Unit::TestCase
22
22
  invalidpath100000000000000000000000000000000
23
23
  unwatched\t#{UNWATCHED_STR}\t0000000000000000
24
24
  EOF
25
+ TEST_CONTENT_PATHS = {
26
+ "valid_path" => Fluent::Plugin::TailInput::TargetInfo.new("valid_path", 1),
27
+ "inode23bit" => Fluent::Plugin::TailInput::TargetInfo.new("inode23bit", 0),
28
+ }
25
29
 
26
30
  def write_data(f, content)
27
31
  f.write(content)
@@ -36,7 +40,11 @@ class IntailPositionFileTest < Test::Unit::TestCase
36
40
 
37
41
  test '.load' do
38
42
  write_data(@file, TEST_CONTENT)
39
- Fluent::Plugin::TailInput::PositionFile.load(@file, false, {}, **{logger: $log})
43
+ paths = {
44
+ "valid_path" => Fluent::Plugin::TailInput::TargetInfo.new("valid_path", 1),
45
+ "inode23bit" => Fluent::Plugin::TailInput::TargetInfo.new("inode23bit", 2),
46
+ }
47
+ Fluent::Plugin::TailInput::PositionFile.load(@file, false, TEST_CONTENT_PATHS, **{logger: $log})
40
48
 
41
49
  @file.seek(0)
42
50
  lines = @file.readlines
@@ -48,7 +56,7 @@ class IntailPositionFileTest < Test::Unit::TestCase
48
56
  sub_test_case '#try_compact' do
49
57
  test 'compact invalid and convert 32 bit inode value' do
50
58
  write_data(@file, TEST_CONTENT)
51
- Fluent::Plugin::TailInput::PositionFile.new(@file, false, {}, **{logger: $log}).try_compact
59
+ Fluent::Plugin::TailInput::PositionFile.new(@file, false, **{logger: $log}).try_compact
52
60
 
53
61
  @file.seek(0)
54
62
  lines = @file.readlines
@@ -62,7 +70,7 @@ class IntailPositionFileTest < Test::Unit::TestCase
62
70
  valid_path\t0000000000000002\t0000000000000001
63
71
  valid_path\t0000000000000003\t0000000000000004
64
72
  EOF
65
- Fluent::Plugin::TailInput::PositionFile.new(@file, false, {}, **{logger: $log}).try_compact
73
+ Fluent::Plugin::TailInput::PositionFile.new(@file, false, **{logger: $log}).try_compact
66
74
 
67
75
  @file.seek(0)
68
76
  lines = @file.readlines
@@ -71,7 +79,7 @@ class IntailPositionFileTest < Test::Unit::TestCase
71
79
 
72
80
  test 'does not change when the file is changed' do
73
81
  write_data(@file, TEST_CONTENT)
74
- pf = Fluent::Plugin::TailInput::PositionFile.new(@file, false, {}, **{logger: $log})
82
+ pf = Fluent::Plugin::TailInput::PositionFile.new(@file, false, **{logger: $log})
75
83
 
76
84
  mock.proxy(pf).fetch_compacted_entries do |r|
77
85
  @file.write("unwatched\t#{UNWATCHED_STR}\t0000000000000000\n")
@@ -86,7 +94,7 @@ class IntailPositionFileTest < Test::Unit::TestCase
86
94
  end
87
95
 
88
96
  test 'update seek position of remained position entry' do
89
- pf = Fluent::Plugin::TailInput::PositionFile.new(@file, false, {}, **{logger: $log})
97
+ pf = Fluent::Plugin::TailInput::PositionFile.new(@file, false, **{logger: $log})
90
98
  target_info1 = Fluent::Plugin::TailInput::TargetInfo.new('path1', -1)
91
99
  target_info2 = Fluent::Plugin::TailInput::TargetInfo.new('path2', -1)
92
100
  target_info3 = Fluent::Plugin::TailInput::TargetInfo.new('path3', -1)
@@ -115,12 +123,35 @@ class IntailPositionFileTest < Test::Unit::TestCase
115
123
  assert_equal "path3\t#{UNWATCHED_STR}\t0000000000000000\n", lines[1]
116
124
  assert_equal 2, lines.size
117
125
  end
126
+
127
+ test 'should ignore initial existing files on follow_inode' do
128
+ write_data(@file, TEST_CONTENT)
129
+ pos_file = Fluent::Plugin::TailInput::PositionFile.load(@file, true, TEST_CONTENT_PATHS, **{logger: $log})
130
+ @file.seek(0)
131
+ assert_equal([], @file.readlines)
132
+
133
+ @file.seek(0)
134
+ write_data(@file, TEST_CONTENT)
135
+ pos_file.try_compact
136
+
137
+ @file.seek(0)
138
+ assert_equal([
139
+ "valid_path\t0000000000000002\t0000000000000001\n",
140
+ "inode23bit\t0000000000000000\t0000000000000000\n",
141
+ ],
142
+ @file.readlines)
143
+ end
118
144
  end
119
145
 
120
146
  sub_test_case '#load' do
121
147
  test 'compact invalid and convert 32 bit inode value' do
122
148
  write_data(@file, TEST_CONTENT)
123
- Fluent::Plugin::TailInput::PositionFile.load(@file, false, {}, **{logger: $log})
149
+ invalid_path = "invalidpath100000000000000000000000000000000"
150
+ paths = TEST_CONTENT_PATHS.merge({
151
+ invalid_path => Fluent::Plugin::TailInput::TargetInfo.new(invalid_path, 0),
152
+ "unwatched" => Fluent::Plugin::TailInput::TargetInfo.new("unwatched", 0),
153
+ })
154
+ Fluent::Plugin::TailInput::PositionFile.load(@file, false, TEST_CONTENT_PATHS, **{logger: $log})
124
155
 
125
156
  @file.seek(0)
126
157
  lines = @file.readlines
@@ -129,12 +160,21 @@ class IntailPositionFileTest < Test::Unit::TestCase
129
160
  assert_equal "inode23bit\t0000000000000000\t0000000000000000\n", lines[1]
130
161
  end
131
162
 
163
+ test 'compact deleted paths' do
164
+ write_data(@file, TEST_CONTENT)
165
+ Fluent::Plugin::TailInput::PositionFile.load(@file, false, {}, **{logger: $log})
166
+
167
+ @file.seek(0)
168
+ lines = @file.readlines
169
+ assert_equal [], lines
170
+ end
171
+
132
172
  test 'compact data if duplicated line' do
133
173
  write_data(@file, <<~EOF)
134
174
  valid_path\t0000000000000002\t0000000000000001
135
175
  valid_path\t0000000000000003\t0000000000000004
136
176
  EOF
137
- Fluent::Plugin::TailInput::PositionFile.new(@file, false, {}, **{logger: $log}).load
177
+ Fluent::Plugin::TailInput::PositionFile.new(@file, false, **{logger: $log}).load
138
178
 
139
179
  @file.seek(0)
140
180
  lines = @file.readlines
@@ -145,7 +185,7 @@ class IntailPositionFileTest < Test::Unit::TestCase
145
185
  sub_test_case '#[]' do
146
186
  test 'return entry' do
147
187
  write_data(@file, TEST_CONTENT)
148
- pf = Fluent::Plugin::TailInput::PositionFile.load(@file, false, {}, **{logger: $log})
188
+ pf = Fluent::Plugin::TailInput::PositionFile.load(@file, false, TEST_CONTENT_PATHS, **{logger: $log})
149
189
 
150
190
  valid_target_info = Fluent::Plugin::TailInput::TargetInfo.new('valid_path', File.stat(@file).ino)
151
191
  f = pf[valid_target_info]
@@ -95,6 +95,19 @@ class BareOutputTest < Test::Unit::TestCase
95
95
  end
96
96
  end
97
97
 
98
+ test 'can use metrics plugins and fallback methods' do
99
+ @p.configure(config_element('ROOT', '', {'@log_level' => 'debug'}))
100
+
101
+ %w[num_errors_metrics emit_count_metrics emit_size_metrics emit_records_metrics].each do |metric_name|
102
+ assert_true @p.instance_variable_get(:"@#{metric_name}").is_a?(Fluent::Plugin::Metrics)
103
+ end
104
+
105
+ assert_equal 0, @p.num_errors
106
+ assert_equal 0, @p.emit_count
107
+ assert_equal 0, @p.emit_size
108
+ assert_equal 0, @p.emit_records
109
+ end
110
+
98
111
  test 'can get input event stream to write' do
99
112
  @p.configure(config_element('ROOT'))
100
113
  @p.start
@@ -238,8 +238,14 @@ class BufferTest < Test::Unit::TestCase
238
238
  assert_nil @p.queue
239
239
  assert_nil @p.dequeued
240
240
  assert_nil @p.queued_num
241
- assert_equal 0, @p.stage_size
242
- assert_equal 0, @p.queue_size
241
+ assert_nil @p.stage_length_metrics
242
+ assert_nil @p.stage_size_metrics
243
+ assert_nil @p.queue_length_metrics
244
+ assert_nil @p.queue_size_metrics
245
+ assert_nil @p.available_buffer_space_ratios_metrics
246
+ assert_nil @p.total_queued_size_metrics
247
+ assert_nil @p.newest_timekey_metrics
248
+ assert_nil @p.oldest_timekey_metrics
243
249
  assert_equal [], @p.timekeys
244
250
  end
245
251
 
@@ -96,6 +96,17 @@ class FileWrapperTest < Test::Unit::TestCase
96
96
  end
97
97
  end
98
98
 
99
+ test 'Errno::ENOENT raised on DeletePending' do
100
+ path = "#{TMP_DIR}/deletepending.txt"
101
+ file = Fluent::WindowsFile.new(path, mode='w')
102
+ File.delete(path)
103
+ assert_raise(Errno::ENOENT) do
104
+ file.stat
105
+ ensure
106
+ file.close if file
107
+ end
108
+ end
109
+
99
110
  test 'ERROR_SHARING_VIOLATION raised' do
100
111
  begin
101
112
  path = "#{TMP_DIR}/test_windows_file.txt"
@@ -165,6 +165,17 @@ class FilterPluginTest < Test::Unit::TestCase
165
165
  end
166
166
  end
167
167
 
168
+ test 'can use metrics plugins and fallback methods' do
169
+ @p.configure(config_element('ROOT', '', {'@log_level' => 'debug'}))
170
+
171
+ %w[emit_size_metrics emit_records_metrics].each do |metric_name|
172
+ assert_true @p.instance_variable_get(:"@#{metric_name}").is_a?(Fluent::Plugin::Metrics)
173
+ end
174
+
175
+ assert_equal 0, @p.emit_size
176
+ assert_equal 0, @p.emit_records
177
+ end
178
+
168
179
  test 'are available with multi worker configuration in default' do
169
180
  assert @p.multi_workers_ready?
170
181
  end
@@ -856,6 +856,46 @@ class HttpInputTest < Test::Unit::TestCase
856
856
  end
857
857
  end
858
858
 
859
+ def test_cors_allow_credentials
860
+ d = create_driver(config + %[
861
+ cors_allow_origins ["http://foo.com"]
862
+ cors_allow_credentials
863
+ ])
864
+ assert_equal true, d.instance.cors_allow_credentials
865
+
866
+ time = event_time("2011-01-02 13:14:15 UTC")
867
+ event = ["tag1", time, {"a"=>1}]
868
+ res_code = nil
869
+ res_header = nil
870
+
871
+ d.run do
872
+ res = post("/#{event[0]}", {"json"=>event[2].to_json, "time"=>time.to_i.to_s}, {"Origin"=>"http://foo.com"})
873
+ res_code = res.code
874
+ res_header = res["Access-Control-Allow-Credentials"]
875
+ end
876
+ assert_equal(
877
+ {
878
+ response_code: "200",
879
+ allow_credentials_header: "true",
880
+ events: [event]
881
+ },
882
+ {
883
+ response_code: res_code,
884
+ allow_credentials_header: res_header,
885
+ events: d.events
886
+ }
887
+ )
888
+ end
889
+
890
+ def test_cors_allow_credentials_for_wildcard_origins
891
+ assert_raise(Fluent::ConfigError) do
892
+ create_driver(config + %[
893
+ cors_allow_origins ["*"]
894
+ cors_allow_credentials
895
+ ])
896
+ end
897
+ end
898
+
859
899
  def test_content_encoding_gzip
860
900
  d = create_driver
861
901