Skip to content

Commit d402d3a

Browse files
Validate the backend in params
Skip profiling if the backend is not supported
1 parent 7a0f861 commit d402d3a

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

lib/app_profiler/request_parameters.rb

+10-3
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,13 @@ def backend
2727
end
2828

2929
def valid?
30-
if mode.blank?
30+
return false if mode.blank?
31+
32+
unless valid_backend?
33+
AppProfiler.logger.info("[AppProfiler] unsupported backend='#{backend}'")
3134
return false
3235
end
3336

34-
return false if backend != AppProfiler::Backend::StackprofBackend.name && !AppProfiler.vernier_supported?
35-
3637
if AppProfiler.vernier_supported? && backend == AppProfiler::Backend::VernierBackend.name &&
3738
!AppProfiler::Backend::VernierBackend::AVAILABLE_MODES.include?(mode.to_sym)
3839
AppProfiler.logger.info("[AppProfiler] unsupported profiling mode=#{mode} for backend #{backend}")
@@ -50,6 +51,12 @@ def valid?
5051
true
5152
end
5253

54+
def valid_backend?
55+
return true if AppProfiler::Backend::StackprofBackend.name == backend
56+
57+
AppProfiler.vernier_supported? && AppProfiler::Backend::VernierBackend.name == backend
58+
end
59+
5360
def to_h
5461
{
5562
mode: mode.to_sym,

test/app_profiler/request_parameters_test.rb

+7
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,13 @@ class RequestParametersTest < TestCase
2929
end
3030
end
3131

32+
test "#valid? returns false when backend is not supported" do
33+
AppProfiler.logger.expects(:info).with { |value| value =~ /unsupported backend='not-a-real-backend'/ }
34+
params = request_params(headers: { AppProfiler.request_profile_header => "mode=cpu;backend=not-a-real-backend" })
35+
36+
assert_not_predicate(params, :valid?)
37+
end
38+
3239
test "#context is AppProfiler.context by default" do
3340
with_context("test-context") do
3441
AppProfiler.logger.expects(:info).never

0 commit comments

Comments
 (0)