# 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