diff --git a/fluentd.gemspec b/fluentd.gemspec index cd942d72c1..df8d5c247b 100644 --- a/fluentd.gemspec +++ b/fluentd.gemspec @@ -48,4 +48,5 @@ Gem::Specification.new do |gem| gem.add_development_dependency("test-unit", ["~> 3.2"]) gem.add_development_dependency("test-unit-rr", ["~> 1.0"]) gem.add_development_dependency("oj", [">= 2.14", "< 4"]) + gem.add_development_dependency("ext_monitor", [">= 0.1.1", "< 0.2"]) end diff --git a/lib/fluent/command/cat.rb b/lib/fluent/command/cat.rb index 97b7bc72b8..e5e865bceb 100644 --- a/lib/fluent/command/cat.rb +++ b/lib/fluent/command/cat.rb @@ -101,13 +101,11 @@ usage $!.to_s end - require 'thread' -require 'monitor' require 'socket' require 'yajl' require 'msgpack' - +require 'fluent/ext_monitor_require' class Writer include MonitorMixin diff --git a/lib/fluent/ext_monitor_require.rb b/lib/fluent/ext_monitor_require.rb new file mode 100644 index 0000000000..5a2cbbb5fd --- /dev/null +++ b/lib/fluent/ext_monitor_require.rb @@ -0,0 +1,28 @@ +# +# Fluentd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +# To avoid duplicated requirements, extract this logic as file. + +if Gem::Version.create(RUBY_VERSION) >= Gem::Version.create('2.7.0') + require 'monitor' +else + begin + # monitor_ext is bundled since ruby 2.7.0 + require 'ext_monitor' + rescue LoadError => _ + require 'monitor' + end +end diff --git a/lib/fluent/load.rb b/lib/fluent/load.rb index 92ea7d12c2..e7d75daf03 100644 --- a/lib/fluent/load.rb +++ b/lib/fluent/load.rb @@ -2,7 +2,6 @@ require 'socket' require 'fcntl' require 'time' -require 'monitor' require 'stringio' require 'fileutils' require 'json' @@ -33,3 +32,4 @@ require 'fluent/output' require 'fluent/filter' require 'fluent/match' +require 'fluent/ext_monitor_require' diff --git a/lib/fluent/plugin/buffer.rb b/lib/fluent/plugin/buffer.rb index e69ec51197..20efb0e80c 100644 --- a/lib/fluent/plugin/buffer.rb +++ b/lib/fluent/plugin/buffer.rb @@ -17,8 +17,7 @@ require 'fluent/plugin/base' require 'fluent/plugin/owned_by_mixin' require 'fluent/unique_id' - -require 'monitor' +require 'fluent/ext_monitor_require' module Fluent module Plugin diff --git a/lib/fluent/plugin/buffer/chunk.rb b/lib/fluent/plugin/buffer/chunk.rb index cab45cc91f..a5a6f2d3b1 100644 --- a/lib/fluent/plugin/buffer/chunk.rb +++ b/lib/fluent/plugin/buffer/chunk.rb @@ -18,8 +18,8 @@ require 'fluent/plugin/compressable' require 'fluent/unique_id' require 'fluent/event' +require 'fluent/ext_monitor_require' -require 'monitor' require 'tempfile' require 'zlib' diff --git a/lib/fluent/plugin/output.rb b/lib/fluent/plugin/output.rb index 2d545fc4a0..2d52eda479 100644 --- a/lib/fluent/plugin/output.rb +++ b/lib/fluent/plugin/output.rb @@ -25,9 +25,9 @@ require 'fluent/timezone' require 'fluent/unique_id' require 'fluent/clock' +require 'fluent/ext_monitor_require' require 'time' -require 'monitor' module Fluent module Plugin