Skip to content

Commit

Permalink
revert ddog sampling
Browse files Browse the repository at this point in the history
  • Loading branch information
dpep committed Mar 13, 2024
1 parent 1351f3c commit ee5acab
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 41 deletions.
53 changes: 19 additions & 34 deletions lib/network_resiliency.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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(
Expand All @@ -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
Expand Down
2 changes: 0 additions & 2 deletions lib/network_resiliency/stats_engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down
3 changes: 0 additions & 3 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down
2 changes: 0 additions & 2 deletions spec/stats_engine_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@
is_expected.to have_received(:distribution).with(
"network_resiliency.sync.keys.dirty",
1,
anything,
)
end
end
Expand All @@ -150,7 +149,6 @@
is_expected.to have_received(:distribution).with(
"network_resiliency.sync.keys.dirty",
1,
anything,
)
end

Expand Down

0 comments on commit ee5acab

Please sign in to comment.