From 8e9a1934b3ad48efe7aad155fbd3ea4c4e63f23d Mon Sep 17 00:00:00 2001 From: "Dustin J. Mitchell" Date: Fri, 12 Nov 2021 17:21:23 +0000 Subject: [PATCH 1/2] Drop support for Ruby before 2.1.0 --- .circleci/config.yml | 13 -------- .rubocop.yml | 2 +- CHANGELOG.md | 1 + Gemfile | 33 ++++--------------- dogstatsd-ruby.gemspec | 2 +- lib/datadog/statsd.rb | 27 ++------------- spec/integrations/telemetry_spec.rb | 6 ++-- .../serialization/stat_serializer_spec.rb | 4 --- .../serialization/tag_serializer_spec.rb | 4 --- spec/statsd/telemetry_spec.rb | 10 +++--- spec/statsd_spec.rb | 12 +++---- 11 files changed, 25 insertions(+), 89 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index f36f5276..028fcc03 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -1,13 +1,5 @@ version: 2 -x-dockerbuild-ruby20: &dockerbuild-ruby20 - steps: - - run: apt update - - run: apt install -y git gcc make - - checkout - - run: bundle install --with development - - run: bundle exec rake spec - x-dockerbuild: &dockerbuild steps: - checkout @@ -15,10 +7,6 @@ x-dockerbuild: &dockerbuild - run: bundle exec rake spec jobs: - test-ruby-2.0: - <<: *dockerbuild-ruby20 - docker: - - image: ruby:2.0-slim test-ruby-2.1: <<: *dockerbuild docker: @@ -56,7 +44,6 @@ workflows: version: 2 check_compile: jobs: - - test-ruby-2.0 - test-ruby-2.1 - test-ruby-2.2 - test-ruby-2.3 diff --git a/.rubocop.yml b/.rubocop.yml index 9a584ce2..be1e558d 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,6 +1,6 @@ AllCops: DisplayCopNames: true - TargetRubyVersion: 2.0 + TargetRubyVersion: 2.1 LineLength: Max: 120 diff --git a/CHANGELOG.md b/CHANGELOG.md index e9d233fd..4888c4e7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ [//]: # (comment: Don't forget to update lib/datadog/statsd/version.rb:DogStatsd::Statsd::VERSION when releasing a new version) + * [OTHER] Ruby versions earlier than 2.1.0 are no longer supported. Ruby-2.0 was EOL as of 2016-02-24. * [ENHANCEMENT] The client can now be configured to use UDS via the `DD_DOGSTATSD_SOCKET` environment variable. This variable does not take precedence over any explicit parameters passed to the Statsd constructor. diff --git a/Gemfile b/Gemfile index ca7448c9..627b828d 100644 --- a/Gemfile +++ b/Gemfile @@ -2,26 +2,14 @@ source 'https://rubygems.org' gemspec -if RUBY_VERSION < '2.1.0' - gem 'rake', '12.3.2' - gem 'minitest', '5.12.0' - gem 'parallel', '1.13.0' - gem 'single_cov', '1.5.0' -else - gem 'rake', '>= 12.3.3' - gem 'minitest' - gem 'parallel' - gem 'single_cov' -end - +gem 'rake', '>= 12.3.3' +gem 'minitest' +gem 'parallel' +gem 'single_cov' gem 'minitest-matchers' gem 'yard', '~> 0.9.20' gem 'climate_control', '~> 0.2.0' -if RUBY_VERSION >= '2.0.0' - gem 'rubocop', '~> 0.50.0' # bump this and TargetRubyVersion once we drop ruby 2.0 -end - if RUBY_VERSION < '2.2.2' gem 'rack', '~> 1.6' # required on older ruby versions end @@ -36,17 +24,8 @@ group :development do gem 'rspec' gem 'rspec-its' gem 'timecop' - - if RUBY_VERSION < '2.1.0' - gem 'byebug', '9.0.6' - gem 'memory_profiler', '0.9.0' - gem 'i18n', '~> 0.5' - gem 'faker', '1.7.3' - else - gem 'byebug' - gem 'faker' - end - + gem 'byebug' + gem 'faker' gem 'pry' end diff --git a/dogstatsd-ruby.gemspec b/dogstatsd-ruby.gemspec index 1d248b09..b76f6a9b 100644 --- a/dogstatsd-ruby.gemspec +++ b/dogstatsd-ruby.gemspec @@ -31,6 +31,6 @@ https://github.com/DataDog/dogstatsd-ruby#migrating-from-v4x-to-v5x s.files = Dir["LICENSE.txt", "README.md", "lib/**/*.rb",] s.homepage = "https://github.com/DataDog/dogstatsd-ruby" s.licenses = ["MIT"] - s.required_ruby_version = '>= 2.0.0' + s.required_ruby_version = '>= 2.1.0' end diff --git a/lib/datadog/statsd.rb b/lib/datadog/statsd.rb index 90db0d84..e367bdc4 100644 --- a/lib/datadog/statsd.rb +++ b/lib/datadog/statsd.rb @@ -12,9 +12,6 @@ require_relative 'statsd/single_thread_sender' require_relative 'statsd/forwarder' -$deprecation_message_mutex = Mutex.new -$deprecation_message_done = false - # = Datadog::Statsd: A DogStatsd client (https://www.datadoghq.com) # # @example Set up a global Statsd client for a server on localhost:8125 @@ -105,19 +102,6 @@ def initialize( @serializer = Serialization::Serializer.new(prefix: @prefix, global_tags: tags) @sample_rate = sample_rate - # deprecation message for ruby < 2.1.0 users as we will drop support for ruby 2.0 - # in dogstatsd-ruby 5.4.0 - # TODO(remy): remove this message and the two global vars used in dogstatd-ruby 5.4.0 - if RUBY_VERSION < '2.1.0' && $deprecation_message_mutex.try_lock && !$deprecation_message_done - if logger != nil - logger.warn { "deprecation: dogstatsd-ruby will drop support of Ruby < 2.1.0 in a next minor release" } - else - puts("warning: deprecation: dogstatsd-ruby will drop support of Ruby < 2.1.0 in a next minor release") - end - $deprecation_message_done = true - $deprecation_message_mutex.unlock - end - @forwarder = Forwarder.new( connection_cfg: ConnectionCfg.new( host: host, @@ -385,17 +369,10 @@ def transport_type attr_reader :serializer attr_reader :forwarder - PROCESS_TIME_SUPPORTED = (RUBY_VERSION >= '2.1.0') EMPTY_OPTIONS = {}.freeze - if PROCESS_TIME_SUPPORTED - def now - Process.clock_gettime(Process::CLOCK_MONOTONIC) - end - else - def now - Time.now.to_f - end + def now + Process.clock_gettime(Process::CLOCK_MONOTONIC) end def send_stats(stat, delta, type, opts = EMPTY_OPTIONS) diff --git a/spec/integrations/telemetry_spec.rb b/spec/integrations/telemetry_spec.rb index 36899143..fdddd4a7 100644 --- a/spec/integrations/telemetry_spec.rb +++ b/spec/integrations/telemetry_spec.rb @@ -48,7 +48,7 @@ context 'when flushing only every 2 seconds' do before do Timecop.freeze(DateTime.new(2020, 2, 22, 12, 12, 12)) - allow(Process).to receive(:clock_gettime).and_return(0) if Datadog::Statsd::PROCESS_TIME_SUPPORTED + allow(Process).to receive(:clock_gettime).and_return(0) subject end @@ -64,7 +64,7 @@ it 'does not send telemetry before the delay' do Timecop.freeze(DateTime.new(2020, 2, 22, 12, 12, 13)) - allow(Process).to receive(:clock_gettime).and_return(1) if Datadog::Statsd::PROCESS_TIME_SUPPORTED + allow(Process).to receive(:clock_gettime).and_return(1) subject.count('test', 21) @@ -75,7 +75,7 @@ it 'sends telemetry after the delay' do Timecop.freeze(DateTime.new(2020, 2, 22, 12, 12, 15)) - allow(Process).to receive(:clock_gettime).and_return(3) if Datadog::Statsd::PROCESS_TIME_SUPPORTED + allow(Process).to receive(:clock_gettime).and_return(3) subject.count('test', 21) diff --git a/spec/statsd/serialization/stat_serializer_spec.rb b/spec/statsd/serialization/stat_serializer_spec.rb index 3818809e..9a3a3bcc 100644 --- a/spec/statsd/serialization/stat_serializer_spec.rb +++ b/spec/statsd/serialization/stat_serializer_spec.rb @@ -95,10 +95,6 @@ end context 'benchmark' do - before do - skip 'Ruby too old' if RUBY_VERSION < '2.1.0' - end - before { skip("Benchmarks results are currently not used by CI") if ENV.key?('CI') } def benchmark_setup(x) diff --git a/spec/statsd/serialization/tag_serializer_spec.rb b/spec/statsd/serialization/tag_serializer_spec.rb index cd26c944..140e3433 100644 --- a/spec/statsd/serialization/tag_serializer_spec.rb +++ b/spec/statsd/serialization/tag_serializer_spec.rb @@ -217,10 +217,6 @@ end context 'benchmark' do - before do - skip 'Ruby too old' if RUBY_VERSION < '2.1.0' - end - before { skip("Benchmarks results are currently not used by CI") if ENV.key?('CI') } def benchmark_setup(x) diff --git a/spec/statsd/telemetry_spec.rb b/spec/statsd/telemetry_spec.rb index faab9deb..44ddd1ce 100644 --- a/spec/statsd/telemetry_spec.rb +++ b/spec/statsd/telemetry_spec.rb @@ -42,7 +42,7 @@ describe '#should_flush?' do before do Timecop.freeze(DateTime.new(2020, 2, 22, 12, 12, 12)) - allow(Process).to receive(:clock_gettime).and_return(0) if Datadog::Statsd::PROCESS_TIME_SUPPORTED + allow(Process).to receive(:clock_gettime).and_return(0) subject end @@ -54,7 +54,7 @@ context 'before the delay' do before do Timecop.freeze(DateTime.new(2020, 2, 22, 12, 12, 13)) - allow(Process).to receive(:clock_gettime).and_return(1) if Datadog::Statsd::PROCESS_TIME_SUPPORTED + allow(Process).to receive(:clock_gettime).and_return(1) end it 'returns false' do @@ -65,7 +65,7 @@ context 'after the delay' do before do Timecop.freeze(DateTime.new(2020, 2, 22, 12, 12, 15)) - allow(Process).to receive(:clock_gettime).and_return(3) if Datadog::Statsd::PROCESS_TIME_SUPPORTED + allow(Process).to receive(:clock_gettime).and_return(3) end it 'returns true' do @@ -109,7 +109,7 @@ describe '#reset' do before do Timecop.freeze(DateTime.new(2020, 2, 22, 12, 12, 12)) - allow(Process).to receive(:clock_gettime).and_return(0) if Datadog::Statsd::PROCESS_TIME_SUPPORTED + allow(Process).to receive(:clock_gettime).and_return(0) subject.sent(metrics: 1, events: 2, service_checks: 3, bytes: 4, packets: 5) subject.dropped(bytes: 6, packets: 7) @@ -121,7 +121,7 @@ it 'resets the flush time' do Timecop.freeze(DateTime.new(2020, 2, 22, 12, 12, 15)) - allow(Process).to receive(:clock_gettime).and_return(3) if Datadog::Statsd::PROCESS_TIME_SUPPORTED + allow(Process).to receive(:clock_gettime).and_return(3) expect do subject.reset diff --git a/spec/statsd_spec.rb b/spec/statsd_spec.rb index bdbf8fb2..a025c04a 100644 --- a/spec/statsd_spec.rb +++ b/spec/statsd_spec.rb @@ -579,14 +579,14 @@ before do Timecop.freeze(before_date) - allow(Process).to receive(:clock_gettime).and_return(0) if Datadog::Statsd::PROCESS_TIME_SUPPORTED + allow(Process).to receive(:clock_gettime).and_return(0) end it_behaves_like 'a metrics method', 'foobar:1000|ms' do let(:basic_action) do subject.time('foobar', tags: action_tags) do Timecop.travel(after_date) - allow(Process).to receive(:clock_gettime).and_return(1) if Datadog::Statsd::PROCESS_TIME_SUPPORTED + allow(Process).to receive(:clock_gettime).and_return(1) end subject.flush(sync: true) @@ -597,7 +597,7 @@ it 'sends the timing' do subject.time('foobar') do Timecop.travel(after_date) - allow(Process).to receive(:clock_gettime).and_return(1) if Datadog::Statsd::PROCESS_TIME_SUPPORTED + allow(Process).to receive(:clock_gettime).and_return(1) end subject.flush(sync: true) @@ -609,7 +609,7 @@ # rubocop:disable Lint/RescueWithoutErrorClass subject.time('foobar') do Timecop.travel(after_date) - allow(Process).to receive(:clock_gettime).and_return(1) if Datadog::Statsd::PROCESS_TIME_SUPPORTED + allow(Process).to receive(:clock_gettime).and_return(1) raise 'stop' end rescue nil # rubocop:enable Lint/RescueWithoutErrorClass @@ -648,7 +648,7 @@ it 'sends the timing with the sample rate' do subject.time('foobar', sample_rate: 0.5) do Timecop.travel(after_date) - allow(Process).to receive(:clock_gettime).and_return(1) if Datadog::Statsd::PROCESS_TIME_SUPPORTED + allow(Process).to receive(:clock_gettime).and_return(1) end subject.flush(sync: true) @@ -665,7 +665,7 @@ it 'sends the timing with the sample rate' do subject.time('foobar', 0.5) do Timecop.travel(after_date) - allow(Process).to receive(:clock_gettime).and_return(1) if Datadog::Statsd::PROCESS_TIME_SUPPORTED + allow(Process).to receive(:clock_gettime).and_return(1) end subject.flush(sync: true) From 0c23eb10b7f06fc7f0c44656598674eeacf5a4c2 Mon Sep 17 00:00:00 2001 From: "Dustin J. Mitchell" Date: Wed, 2 Feb 2022 20:18:23 +0000 Subject: [PATCH 2/2] add README note about ruby versions. --- README.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 2ccca9ee..90e4a5f3 100644 --- a/README.md +++ b/README.md @@ -204,7 +204,13 @@ When using the `single_thread: true` mode, instances of `Datadog::Statsd` are st ## Versioning -This Ruby gem is using [Semantic Versioning](https://guides.rubygems.org/patterns/#semantic-versioning) but please note that supported Ruby versions can change in a minor release of this library. As much as possible, we will add a "future deprecation" message in the minor release preceding the one dropping the support. +This Ruby gem is using [Semantic Versioning](https://guides.rubygems.org/patterns/#semantic-versioning) but please note that supported Ruby versions can change in a minor release of this library. +As much as possible, we will add a "future deprecation" message in the minor release preceding the one dropping the support. + +## Ruby Versions + +This gem supports and is tested on Ruby minor versions 2.1 through 3.0. +Support for Ruby 2.0 was dropped in version 5.4.0. ## Credits