Class: Chronos::Application::RemoteConfiguration
- Inherits:
-
Object
- Object
- Chronos::Application::RemoteConfiguration
- Defined in:
- lib/chronos/application/remote_configuration.rb
Overview
Runtime policy restricted to server-authorized scalar options.
Constant Summary collapse
- SUPPORTED_EVENT_TYPES =
["exception"].freeze
- MAX_IGNORED_FINGERPRINTS =
100- MAX_FINGERPRINT_BYTES =
256- MIN_PAYLOAD_SIZE =
256
Instance Attribute Summary collapse
-
#ignored_fingerprints ⇒ Object
readonly
Returns the value of attribute ignored_fingerprints.
Instance Method Summary collapse
- #apply(document) ⇒ Object
- #capture?(event_type, fingerprint = nil) ⇒ Boolean
- #enabled_event?(event_type) ⇒ Boolean
- #ignored_fingerprint?(fingerprint) ⇒ Boolean
-
#initialize(config, options = {}) ⇒ RemoteConfiguration
constructor
A new instance of RemoteConfiguration.
- #kill_switch? ⇒ Boolean
- #max_payload_size ⇒ Object
- #sampling_rate ⇒ Object
- #send_interval ⇒ Object
- #to_h ⇒ Object
Constructor Details
#initialize(config, options = {}) ⇒ RemoteConfiguration
Returns a new instance of RemoteConfiguration.
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/chronos/application/remote_configuration.rb', line 23 def initialize(config, = {}) @config = config @random = [:random] || proc { rand } @mutex = Mutex.new @local_event_types = allowed_event_types(config.enabled_event_types) @values = { "sampling_rate" => config.sampling_rate.to_f, "enabled_event_types" => @local_event_types, "max_payload_size" => config.max_payload_size, "ignored_fingerprints" => [], "send_interval" => 0.0, "kill_switch" => false } @ignored_fingerprints = [].freeze end |
Instance Attribute Details
#ignored_fingerprints ⇒ Object (readonly)
Returns the value of attribute ignored_fingerprints.
21 22 23 |
# File 'lib/chronos/application/remote_configuration.rb', line 21 def ignored_fingerprints @ignored_fingerprints end |
Instance Method Details
#apply(document) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/chronos/application/remote_configuration.rb', line 39 def apply(document) normalized = normalize(document) return false unless normalized @mutex.synchronize do @values = @values.merge(normalized) @ignored_fingerprints = @values["ignored_fingerprints"].dup.freeze end true rescue StandardError false end |
#capture?(event_type, fingerprint = nil) ⇒ Boolean
52 53 54 55 56 57 58 59 60 |
# File 'lib/chronos/application/remote_configuration.rb', line 52 def capture?(event_type, fingerprint = nil) values = snapshot return false if values["kill_switch"] return false unless values["enabled_event_types"].include?(event_type.to_s) return false if fingerprint && values["ignored_fingerprints"].include?(fingerprint.to_s) rate = values["sampling_rate"] rate >= 1.0 || (rate > 0.0 && @random.call.to_f < rate) end |
#enabled_event?(event_type) ⇒ Boolean
62 63 64 |
# File 'lib/chronos/application/remote_configuration.rb', line 62 def enabled_event?(event_type) snapshot["enabled_event_types"].include?(event_type.to_s) end |
#ignored_fingerprint?(fingerprint) ⇒ Boolean
66 67 68 |
# File 'lib/chronos/application/remote_configuration.rb', line 66 def ignored_fingerprint?(fingerprint) snapshot["ignored_fingerprints"].include?(fingerprint.to_s) end |
#kill_switch? ⇒ Boolean
82 83 84 |
# File 'lib/chronos/application/remote_configuration.rb', line 82 def kill_switch? snapshot["kill_switch"] end |
#max_payload_size ⇒ Object
74 75 76 |
# File 'lib/chronos/application/remote_configuration.rb', line 74 def max_payload_size snapshot["max_payload_size"] end |
#sampling_rate ⇒ Object
70 71 72 |
# File 'lib/chronos/application/remote_configuration.rb', line 70 def sampling_rate snapshot["sampling_rate"] end |
#send_interval ⇒ Object
78 79 80 |
# File 'lib/chronos/application/remote_configuration.rb', line 78 def send_interval snapshot["send_interval"] end |
#to_h ⇒ Object
86 87 88 |
# File 'lib/chronos/application/remote_configuration.rb', line 86 def to_h snapshot end |