From d6ef11695429672afc8acb9262258870e96c9518 Mon Sep 17 00:00:00 2001 From: abicky Date: Sun, 15 May 2022 17:21:44 +0900 Subject: [PATCH] Resolve warnings This commit resolves the following warnings: * instance variable @variable_name not initialized * ambiguous first argument; put parentheses or a space even after `/' operator * Using `expect { }.not_to raise_error(SpecificErrorClass, message)` risks false positives --- lib/datadog/statsd/forwarder.rb | 6 ++++-- lib/datadog/statsd/sender.rb | 6 ++++-- lib/datadog/statsd/timer.rb | 1 + spec/statsd/version_spec.rb | 2 +- spec/statsd_spec.rb | 2 +- 5 files changed, 11 insertions(+), 6 deletions(-) diff --git a/lib/datadog/statsd/forwarder.rb b/lib/datadog/statsd/forwarder.rb index dcbd53ed..88624eb7 100644 --- a/lib/datadog/statsd/forwarder.rb +++ b/lib/datadog/statsd/forwarder.rb @@ -25,11 +25,13 @@ def initialize( ) @transport_type = connection_cfg.transport_type - if telemetry_flush_interval - @telemetry = Telemetry.new(telemetry_flush_interval, + @telemetry = if telemetry_flush_interval + Telemetry.new(telemetry_flush_interval, global_tags: global_tags, transport_type: @transport_type ) + else + nil end @connection = connection_cfg.make_connection(logger: logger, telemetry: telemetry) diff --git a/lib/datadog/statsd/sender.rb b/lib/datadog/statsd/sender.rb index c317158d..a5e863e2 100644 --- a/lib/datadog/statsd/sender.rb +++ b/lib/datadog/statsd/sender.rb @@ -20,8 +20,10 @@ def initialize(message_buffer, telemetry: nil, queue_size: UDP_DEFAULT_BUFFER_SI @mx = Mutex.new @queue_class = queue_class @thread_class = thread_class - if flush_interval - @flush_timer = Datadog::Statsd::Timer.new(flush_interval) { flush(sync: true) } + @flush_timer = if flush_interval + Datadog::Statsd::Timer.new(flush_interval) { flush(sync: true) } + else + nil end end diff --git a/lib/datadog/statsd/timer.rb b/lib/datadog/statsd/timer.rb index 8c1c8940..8eaed448 100644 --- a/lib/datadog/statsd/timer.rb +++ b/lib/datadog/statsd/timer.rb @@ -9,6 +9,7 @@ def initialize(interval, &callback) @interval = interval @callback = callback @stop = true + @thread = nil end def start diff --git a/spec/statsd/version_spec.rb b/spec/statsd/version_spec.rb index ce337484..a13ec3eb 100644 --- a/spec/statsd/version_spec.rb +++ b/spec/statsd/version_spec.rb @@ -3,7 +3,7 @@ describe Datadog::Statsd do describe 'VERSION' do it 'has a version' do - expect(Datadog::Statsd::VERSION).to match /\d+\.\d+\.\d+/ + expect(Datadog::Statsd::VERSION).to match(/\d+\.\d+\.\d+/) end end end diff --git a/spec/statsd_spec.rb b/spec/statsd_spec.rb index 26b3689b..1c659b21 100644 --- a/spec/statsd_spec.rb +++ b/spec/statsd_spec.rb @@ -1014,7 +1014,7 @@ it 'does not raise error' do expect do subject.event(title, text, options) - end.not_to raise_error(RuntimeError, /payload is too big/) + end.not_to raise_error end end end