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



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

def async
  query_param("async")
end

#autoredirectObject



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

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

#backendObject



23
24
25
26
27
# File 'lib/app_profiler/request_parameters.rb', line 23

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

#pathObject



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

def path
  @request.env["PATH_INFO"]
end

#to_hObject



53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/app_profiler/request_parameters.rb', line 53

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)


29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/app_profiler/request_parameters.rb', line 29

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