Module: Contrast::Components::Sampling::ClassMethods

Includes:
ComponentBase, Interface, Constants
Defined in:
lib/contrast/components/sampling.rb

Overview

:nodoc:

Constant Summary

Constants included from Constants

Contrast::Components::Sampling::Constants::DEFAULT_SAMPLING_BASELINE, Contrast::Components::Sampling::Constants::DEFAULT_SAMPLING_ENABLED, Contrast::Components::Sampling::Constants::DEFAULT_SAMPLING_REQUEST_FREQUENCY, Contrast::Components::Sampling::Constants::DEFAULT_SAMPLING_RESPONSE_FREQUENCY, Contrast::Components::Sampling::Constants::DEFAULT_SAMPLING_WINDOW_MS

Instance Method Summary collapse

Methods included from Interface

included

Methods included from ComponentBase

included

Instance Method Details

#reset_sampling_controlObject

Used to reset sampling when settings from TeamServer change



41
42
43
# File 'lib/contrast/components/sampling.rb', line 41

def reset_sampling_control
  @_sampling_control = nil
end

#sampling_controlObject



26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/contrast/components/sampling.rb', line 26

def sampling_control
  @_sampling_control ||= begin
    cas = CONFIG.root.assess&.sampling
    settings = SETTINGS&.assess_state&.[](:sampling_settings)
    {
        enabled: true?([cas&.enable, settings&.enabled, DEFAULT_SAMPLING_ENABLED].reject(&:nil?)[0]),
        baseline: [cas&.baseline, settings&.baseline, DEFAULT_SAMPLING_BASELINE].map(&:to_i).find(&:positive?),
        request_frequency: [cas&.request_frequency, settings&.request_frequency, DEFAULT_SAMPLING_REQUEST_FREQUENCY].map(&:to_i).find(&:positive?),
        response_frequency: [cas&.response_frequency, settings&.response_frequency, DEFAULT_SAMPLING_RESPONSE_FREQUENCY].map(&:to_i).find(&:positive?),
        window: [cas&.window_ms, settings&.window_ms, DEFAULT_SAMPLING_WINDOW_MS].map(&:to_i).find(&:positive?)
    }
  end
end

#sampling_enabled?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/contrast/components/sampling.rb', line 22

def sampling_enabled?
  sampling_control[:enabled]
end