Class: AppProfiler::RequestParameters

Inherits:
Object
  • Object
show all
Defined in:
lib/app_profiler/request_parameters.rb

Instance Method Summary collapse

Constructor Details

#initialize(request) ⇒ RequestParameters

Returns a new instance of RequestParameters.



7
8
9
# File 'lib/app_profiler/request_parameters.rb', line 7

def initialize(request)
  @request = request
end

Instance Method Details

#asyncObject



15
16
17
# File 'lib/app_profiler/request_parameters.rb', line 15

def async
  query_param("async")
end

#autoredirectObject



11
12
13
# File 'lib/app_profiler/request_parameters.rb', line 11

def autoredirect
  query_param("autoredirect") || profile_header_param("autoredirect")
end

#backendObject



19
20
21
22
23
# File 'lib/app_profiler/request_parameters.rb', line 19

def backend
  backend = query_param("backend") || profile_header_param("backend") ||
    AppProfiler.backend
  backend.to_sym
end

#to_hObject



49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/app_profiler/request_parameters.rb', line 49

def to_h
  {
    mode: mode.to_sym,
    interval: interval.to_i,
    ignore_gc: !!ignore_gc,
    backend: backend,
    metadata: {
      id: request_id,
      context: context,
    },
  }
end

#valid?Boolean

Returns:

  • (Boolean)


25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/app_profiler/request_parameters.rb', line 25

def valid?
  if mode.blank?
    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}")
    return false
  elsif backend == AppProfiler::Backend::StackprofBackend.name &&
      !AppProfiler::Backend::StackprofBackend::AVAILABLE_MODES.include?(mode.to_sym)
    AppProfiler.logger.info("[AppProfiler] unsupported profiling mode=#{mode} for backend #{backend}")
    return false
  end

  if interval.to_i < Parameters::MIN_INTERVALS[mode.to_s]
    return false
  end

  true
end