From a6305fd0a308564e698cef36519c8a161fad7499 Mon Sep 17 00:00:00 2001 From: Liz Fong-Jones Date: Tue, 19 May 2020 10:49:41 -0400 Subject: [PATCH] [deploy] Honeycomb instrumentation: distinguish between literal vs prefix matching for sampling (#7936) --- app/lib/honeycomb/noise_cancelling_sampler.rb | 9 +++++++-- spec/lib/honeycomb/noise_cancelling_sampler_spec.rb | 10 ++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/app/lib/honeycomb/noise_cancelling_sampler.rb b/app/lib/honeycomb/noise_cancelling_sampler.rb index 9eaa8fb7f..ee91ccbeb 100644 --- a/app/lib/honeycomb/noise_cancelling_sampler.rb +++ b/app/lib/honeycomb/noise_cancelling_sampler.rb @@ -7,19 +7,24 @@ module Honeycomb "TIME", "BEGIN", "COMMIT", + ].freeze + + NOISY_PREFIXES = [ + "INCRBY", + "TTL", "GET rack:", "SET rack:", "GET views/shell", ].freeze def self.sample(fields) - if NOISY_COMMANDS.include?(fields["redis.command"]) || NOISY_COMMANDS.include?(fields["sql.active_record.sql"]) + if (NOISY_COMMANDS & [fields["redis.command"], fields["sql.active_record.sql"]]).any? rate = 100 [should_sample(rate, fields["trace.trace_id"]), rate] elsif fields["redis.command"]&.start_with?("BRPOP") rate = 1000 [should_sample(rate, fields["trace.trace_id"]), rate] - elsif fields["redis.command"]&.start_with?("INCRBY") || fields["redis.command"]&.start_with?("TTL") + elsif fields["redis.command"]&.start_with?(*NOISY_PREFIXES) rate = 100 [should_sample(rate, fields["trace.trace_id"]), rate] else diff --git a/spec/lib/honeycomb/noise_cancelling_sampler_spec.rb b/spec/lib/honeycomb/noise_cancelling_sampler_spec.rb index 463739ed5..8dcda10e1 100644 --- a/spec/lib/honeycomb/noise_cancelling_sampler_spec.rb +++ b/spec/lib/honeycomb/noise_cancelling_sampler_spec.rb @@ -28,6 +28,16 @@ RSpec.describe Honeycomb::NoiseCancellingSampler do described_class.sample({ "redis.command" => "TTL this and that", "trace.trace_id" => trace_id }) expect(described_class).to have_received(:should_sample).with(100, trace_id) end + + it "samples if the command starts with GET rack:" do + described_class.sample({ "redis.command" => "GET rack::something", "trace.trace_id" => trace_id }) + expect(described_class).to have_received(:should_sample).with(100, trace_id) + end + + it "samples if the command starts with SET rack:" do + described_class.sample({ "redis.command" => "SET rack::something", "trace.trace_id" => trace_id }) + expect(described_class).to have_received(:should_sample).with(100, trace_id) + end end context "with a active_record SQL command" do