From ee5acab30816122a4b806b4974de7aa025027ac2 Mon Sep 17 00:00:00 2001 From: Daniel Pepper Date: Wed, 13 Mar 2024 11:51:07 -0700 Subject: [PATCH] revert ddog sampling --- lib/network_resiliency.rb | 53 +++++++++----------------- lib/network_resiliency/stats_engine.rb | 2 - spec/spec_helper.rb | 3 -- spec/stats_engine_spec.rb | 2 - 4 files changed, 19 insertions(+), 41 deletions(-) diff --git a/lib/network_resiliency.rb b/lib/network_resiliency.rb index 175d89e..e920e51 100644 --- a/lib/network_resiliency.rb +++ b/lib/network_resiliency.rb @@ -22,11 +22,6 @@ module Adapter DEFAULT_TIMEOUT_MIN = 10 # ms MODE = [ :observe, :resilient ].freeze RESILIENCY_THRESHOLD = 100 - SAMPLE_RATE = { - timeout: 0.1, - stats: 0.1, - sync: 0.1, - } extend self @@ -254,7 +249,6 @@ def record(adapter:, action:, destination:, duration:, error:, timeout:, attempt adapter: adapter, destination: destination, }, - sample_rate: SAMPLE_RATE[:timeout], ) if timeout && timeout > 0 if error @@ -286,28 +280,23 @@ def record(adapter:, action:, destination:, duration:, error:, timeout:, attempt # ensure Syncer is running Syncer.start - if rand < SAMPLE_RATE[:stats] - NetworkResiliency.statsd&.distribution( - "network_resiliency.#{action}.stats.n", - stats.n, - tags: tags, - sample_rate: SAMPLE_RATE[:stats], - ) + NetworkResiliency.statsd&.distribution( + "network_resiliency.#{action}.stats.n", + stats.n, + tags: tags, + ) - NetworkResiliency.statsd&.distribution( - "network_resiliency.#{action}.stats.avg", - stats.avg, - tags: tags, - sample_rate: SAMPLE_RATE[:stats], - ) + NetworkResiliency.statsd&.distribution( + "network_resiliency.#{action}.stats.avg", + stats.avg, + tags: tags, + ) - NetworkResiliency.statsd&.distribution( - "network_resiliency.#{action}.stats.stdev", - stats.stdev, - tags: tags, - sample_rate: SAMPLE_RATE[:stats], - ) - end + NetworkResiliency.statsd&.distribution( + "network_resiliency.#{action}.stats.stdev", + stats.stdev, + tags: tags, + ) end nil @@ -372,8 +361,7 @@ def timeouts_for(adapter:, action:, destination:, max: nil, units: :ms) NetworkResiliency.statsd&.increment( "network_resiliency.timeout.raised", tags: tags, - sample_rate: SAMPLE_RATE[:timeout], - ) if rand < SAMPLE_RATE[:timeout] + ) end else # the specified timeout is less than our expected p99...awkward @@ -382,8 +370,7 @@ def timeouts_for(adapter:, action:, destination:, max: nil, units: :ms) NetworkResiliency.statsd&.increment( "network_resiliency.timeout.too_low", tags: tags, - sample_rate: SAMPLE_RATE[:timeout], - ) if rand < SAMPLE_RATE[:timeout] + ) end else timeouts << p99 @@ -394,8 +381,7 @@ def timeouts_for(adapter:, action:, destination:, max: nil, units: :ms) NetworkResiliency.statsd&.increment( "network_resiliency.timeout.missing", tags: tags, - sample_rate: SAMPLE_RATE[:timeout], - ) if rand < SAMPLE_RATE[:timeout] + ) end NetworkResiliency.statsd&.distribution( @@ -405,8 +391,7 @@ def timeouts_for(adapter:, action:, destination:, max: nil, units: :ms) adapter: adapter, destination: destination, }, - sample_rate: SAMPLE_RATE[:timeout], - ) if rand < SAMPLE_RATE[:timeout] + ) case units when nil, :ms, :milliseconds diff --git a/lib/network_resiliency/stats_engine.rb b/lib/network_resiliency/stats_engine.rb index 5c842c5..09167b1 100644 --- a/lib/network_resiliency/stats_engine.rb +++ b/lib/network_resiliency/stats_engine.rb @@ -65,13 +65,11 @@ def sync(redis) empty: data.empty?, truncated: data.size < dirty_keys.size, }.select { |_, v| v }, - sample_rate: SAMPLE_RATE[:sync], ) NetworkResiliency.statsd&.distribution( "network_resiliency.sync.keys.dirty", dirty_keys.select { |_, n| n > 0 }.count, - sample_rate: SAMPLE_RATE[:sync], ) return [] if data.empty? diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index bed13d3..828937f 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -49,9 +49,6 @@ # disable background sync allow(NetworkResiliency::Syncer).to receive(:start) - # disable metric sampling for specs - stub_const("NetworkResiliency::SAMPLE_RATE", Hash.new(1)) - # since Timecop doesn't work with Process.clock_gettime allow(Process).to receive(:clock_gettime).and_return(*(1..1_000)) diff --git a/spec/stats_engine_spec.rb b/spec/stats_engine_spec.rb index 4b4df10..743be94 100644 --- a/spec/stats_engine_spec.rb +++ b/spec/stats_engine_spec.rb @@ -132,7 +132,6 @@ is_expected.to have_received(:distribution).with( "network_resiliency.sync.keys.dirty", 1, - anything, ) end end @@ -150,7 +149,6 @@ is_expected.to have_received(:distribution).with( "network_resiliency.sync.keys.dirty", 1, - anything, ) end