Sha256: 926f561b1f06e86174a074fdf91e1f0bbc33ca82e5d6fd0be3f901dd65c450da

Contents?: true

Size: 1.65 KB

Versions: 6

Compression:

Stored size: 1.65 KB

Contents

# Copyright (c) 2020 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
# frozen_string_literal: true

module Contrast
  module Components
    module Sampling
      module Constants
        DEFAULT_SAMPLING_ENABLED            = false
        DEFAULT_SAMPLING_BASELINE           = 5
        DEFAULT_SAMPLING_REQUEST_FREQUENCY  = 5
        DEFAULT_SAMPLING_RESPONSE_FREQUENCY = 25
        DEFAULT_SAMPLING_WINDOW_MS          = 180_000 # 3 minutes, arbitrary value from Java agent
      end

      module ClassMethods #:nodoc:
        include Contrast::Components::ComponentBase
        include Constants
        include Contrast::Components::Interface

        access_component :config

        def sampling_control settings = @sampling_features
          cas = CONFIG.root.assess&.sampling

          {
              enabled: [cas&.enable, settings&.enabled, DEFAULT_SAMPLING_ENABLED] .reject(&:nil?).first,
              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

      module InstanceMethods #:nodoc:
        include Contrast::Components::ComponentBase
        include Constants
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
contrast-agent-3.10.1 lib/contrast/components/sampling.rb
contrast-agent-3.10.0 lib/contrast/components/sampling.rb
contrast-agent-3.9.1 lib/contrast/components/sampling.rb
contrast-agent-3.9.0 lib/contrast/components/sampling.rb
contrast-agent-3.8.5 lib/contrast/components/sampling.rb
contrast-agent-3.8.4 lib/contrast/components/sampling.rb