Skip to content

Commit

Permalink
Merge pull request #229 from DataDog/issue228
Browse files Browse the repository at this point in the history
Drop support for Ruby before 2.1.0
  • Loading branch information
djmitche authored Feb 2, 2022
2 parents 5d8e7f0 + dc24dd3 commit aac4f54
Show file tree
Hide file tree
Showing 12 changed files with 34 additions and 90 deletions.
13 changes: 0 additions & 13 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,24 +1,12 @@
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
- run: bundle install --with development
- run: bundle exec rake spec

jobs:
test-ruby-2.0:
<<: *dockerbuild-ruby20
docker:
- image: ruby:2.0-slim
test-ruby-2.1:
<<: *dockerbuild
docker:
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
AllCops:
DisplayCopNames: true
TargetRubyVersion: 2.0
TargetRubyVersion: 2.1

LineLength:
Max: 120
Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@

[//]: # (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.

## 5.3.3 / 2022.02.02

* [IMPROVEMENT] Add option "buffer_flush_interval" to flush buffered metrics [#231][] by [@abicky][]

* [IMPROVEMENT] Add Sender.queue_size limits to limit number of buffered metrics [#232][] by [@djmitche][]

* [IMPROVEMENT] The client can now be configured to use UDS via the `DD_DOGSTATSD_SOCKET` environment variable.
>>>>>>> master
This variable does not take precedence over any explicit parameters passed to the Statsd constructor.
[#227][] by [@djmitche][]

Expand Down
33 changes: 6 additions & 27 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,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

Expand Down
2 changes: 1 addition & 1 deletion dogstatsd-ruby.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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

27 changes: 2 additions & 25 deletions lib/datadog/statsd.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@
require_relative 'statsd/forwarder'
require_relative 'statsd/timer'

$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
Expand Down Expand Up @@ -116,19 +113,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,
Expand Down Expand Up @@ -399,17 +383,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)
Expand Down
6 changes: 3 additions & 3 deletions spec/integrations/telemetry_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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)

Expand All @@ -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)

Expand Down
4 changes: 0 additions & 4 deletions spec/statsd/serialization/stat_serializer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 0 additions & 4 deletions spec/statsd/serialization/tag_serializer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 5 additions & 5 deletions spec/statsd/telemetry_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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_writer(bytes: 6, packets: 7)
Expand All @@ -122,7 +122,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
Expand Down
12 changes: 6 additions & 6 deletions spec/statsd_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit aac4f54

Please sign in to comment.