Skip to content

Commit

Permalink
Validate the backend in params
Browse files Browse the repository at this point in the history
Skip profiling if the backend is not supported
  • Loading branch information
Sam-Killgallon committed Oct 18, 2024
1 parent 7a0f861 commit d402d3a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
13 changes: 10 additions & 3 deletions lib/app_profiler/request_parameters.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,13 @@ def backend
end

def valid?
if mode.blank?
return false if mode.blank?

unless valid_backend?
AppProfiler.logger.info("[AppProfiler] unsupported backend='#{backend}'")
return false
end

return false if backend != AppProfiler::Backend::StackprofBackend.name && !AppProfiler.vernier_supported?

if AppProfiler.vernier_supported? && backend == AppProfiler::Backend::VernierBackend.name &&
!AppProfiler::Backend::VernierBackend::AVAILABLE_MODES.include?(mode.to_sym)
AppProfiler.logger.info("[AppProfiler] unsupported profiling mode=#{mode} for backend #{backend}")
Expand All @@ -50,6 +51,12 @@ def valid?
true
end

def valid_backend?
return true if AppProfiler::Backend::StackprofBackend.name == backend

AppProfiler.vernier_supported? && AppProfiler::Backend::VernierBackend.name == backend
end

def to_h
{
mode: mode.to_sym,
Expand Down
7 changes: 7 additions & 0 deletions test/app_profiler/request_parameters_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ class RequestParametersTest < TestCase
end
end

test "#valid? returns false when backend is not supported" do
AppProfiler.logger.expects(:info).with { |value| value =~ /unsupported backend='not-a-real-backend'/ }
params = request_params(headers: { AppProfiler.request_profile_header => "mode=cpu;backend=not-a-real-backend" })

assert_not_predicate(params, :valid?)
end

test "#context is AppProfiler.context by default" do
with_context("test-context") do
AppProfiler.logger.expects(:info).never
Expand Down

0 comments on commit d402d3a

Please sign in to comment.