Skip to content

Commit f2a6e58

Browse files
committed
Fix failing tests due to new sampler
This is a quick-fix to address changes with sampling. All adjusted tests will be refactored
1 parent 700a47b commit f2a6e58

File tree

5 files changed

+25
-6
lines changed

5 files changed

+25
-6
lines changed

lib/datadog/appsec/configuration/settings.rb

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,10 +319,17 @@ def self.add_settings!(base)
319319
o.default false
320320
end
321321

322+
# NOTE: Unfortunately, we have to go with Float due to other libs
323+
# setup, even tho we don't plan to support sub-second delays.
324+
#
325+
# WARNING: The value will be converted to Integer.
322326
option :sample_delay do |o|
323-
o.type :int
327+
o.type :float
324328
o.env 'DD_API_SECURITY_SAMPLE_DELAY'
325329
o.default 30
330+
o.setter do |value|
331+
value.to_i
332+
end
326333
end
327334

328335
option :sample_rate do |o|

spec/datadog/appsec/contrib/rack/integration_test_spec.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,11 +173,15 @@
173173
c.appsec.user_id_denylist = appsec_user_id_denylist
174174
c.appsec.ruleset = appsec_ruleset
175175
c.appsec.api_security.enabled = api_security_enabled
176-
c.appsec.api_security.sample_rate = api_security_sample
176+
c.appsec.api_security.sample_delay = api_security_sample.to_i
177177

178178
c.remote.enabled = remote_enabled
179179
end
180180
end
181+
182+
allow_any_instance_of(Datadog::Tracing::Transport::HTTP::Client).to receive(:send_request)
183+
allow_any_instance_of(Datadog::Tracing::Transport::Traces::Transport).to receive(:native_events_supported?)
184+
.and_return(true)
181185
end
182186

183187
after do

spec/datadog/appsec/contrib/rails/integration_test_spec.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
let(:appsec_user_id_denylist) { [] }
4040
let(:appsec_ruleset) { :recommended }
4141
let(:api_security_enabled) { false }
42-
let(:api_security_sample) { 0.0 }
42+
let(:api_security_sample) { 0 }
4343

4444
let(:crs_942_100) do
4545
{
@@ -104,8 +104,12 @@
104104
c.appsec.user_id_denylist = appsec_user_id_denylist
105105
c.appsec.ruleset = appsec_ruleset
106106
c.appsec.api_security.enabled = api_security_enabled
107-
c.appsec.api_security.sample_rate = api_security_sample
107+
c.appsec.api_security.sample_delay = api_security_sample.to_i
108108
end
109+
110+
allow_any_instance_of(Datadog::Tracing::Transport::HTTP::Client).to receive(:send_request)
111+
allow_any_instance_of(Datadog::Tracing::Transport::Traces::Transport).to receive(:native_events_supported?)
112+
.and_return(true)
109113
end
110114

111115
after do

spec/datadog/appsec/contrib/sinatra/integration_test_spec.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,12 @@
110110
c.appsec.user_id_denylist = appsec_user_id_denylist
111111
c.appsec.ruleset = appsec_ruleset
112112
c.appsec.api_security.enabled = api_security_enabled
113-
c.appsec.api_security.sample_rate = api_security_sample
113+
c.appsec.api_security.sample_delay = api_security_sample.to_i
114114
end
115+
116+
allow_any_instance_of(Datadog::Tracing::Transport::HTTP::Client).to receive(:send_request)
117+
allow_any_instance_of(Datadog::Tracing::Transport::Traces::Transport).to receive(:native_events_supported?)
118+
.and_return(true)
115119
end
116120

117121
after do

spec/datadog/appsec/contrib/support/integration/shared_examples.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@
127127
RSpec.shared_examples 'a trace with AppSec api security tags' do
128128
context 'with api security enabled' do
129129
let(:api_security_enabled) { true }
130-
let(:api_security_sample) { 1.0 }
130+
let(:api_security_sample) { 0 }
131131

132132
it do
133133
api_security_tags = service_span.send(:meta).select { |key, _value| key.include?('_dd.appsec.s') }

0 commit comments

Comments
 (0)