Module: DebugBundle::RemoteConfig

Defined in:
lib/debugbundle/remote_config.rb

Defined Under Namespace

Classes: CapturePolicy, Directive, Snapshot

Class Method Summary collapse

Class Method Details

.balanced_capture_policyObject



76
77
78
79
80
81
82
83
84
85
# File 'lib/debugbundle/remote_config.rb', line 76

def self.balanced_capture_policy
  CapturePolicy.new(
    preset: 'balanced',
    capture_logs: 'warning',
    capture_request_events: 'failures_only',
    capture_breadcrumbs: 'exception_only',
    capture_probe_events: 'buffer_only',
    immediate_client_error_statuses: []
  )
end

.minimal_capture_policyObject



65
66
67
68
69
70
71
72
73
74
# File 'lib/debugbundle/remote_config.rb', line 65

def self.minimal_capture_policy
  CapturePolicy.new(
    preset: 'minimal',
    capture_logs: 'error',
    capture_request_events: 'failures_only',
    capture_breadcrumbs: 'local_only',
    capture_probe_events: 'buffer_only',
    immediate_client_error_statuses: []
  )
end

.parse(payload, fallback_poll_interval_seconds) ⇒ Object



87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/debugbundle/remote_config.rb', line 87

def self.parse(payload, fallback_poll_interval_seconds)
  return nil unless payload.is_a?(Hash)

  capture_policy =
    parse_capture_policy(payload['capture_policy'] || payload[:capture_policy]) || balanced_capture_policy
  directives = Array(payload['active_probes'] || payload[:active_probes]).filter_map do |entry|
    parse_directive(entry)
  end

  poll_interval_ms = payload['poll_interval_ms'] || payload[:poll_interval_ms]
  poll_interval_seconds = if poll_interval_ms.to_i.positive?
                            [(poll_interval_ms.to_i / 1000), 1].max
                          else
                            fallback_poll_interval_seconds
                          end

  Snapshot.new(
    probes_enabled: payload['probes_enabled'] != false && payload[:probes_enabled] != false,
    remote_probes_enabled: payload['remote_probes_enabled'] == true || payload[:remote_probes_enabled] == true,
    directives: directives,
    poll_interval_seconds: poll_interval_seconds,
    capture_policy: capture_policy,
    trigger_token_key: payload['trigger_token_key'] || payload[:trigger_token_key]
  )
end

.parse_capture_policy(payload) ⇒ Object



113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/debugbundle/remote_config.rb', line 113

def self.parse_capture_policy(payload)
  return nil unless payload.is_a?(Hash)

  CapturePolicy.new(
    preset: payload['preset'] || payload[:preset] || 'balanced',
    capture_logs: payload['capture_logs'] || payload[:capture_logs] || 'warning',
    capture_request_events:
      payload['capture_request_events'] || payload[:capture_request_events] || 'failures_only',
    capture_breadcrumbs: payload['capture_breadcrumbs'] || payload[:capture_breadcrumbs] || 'exception_only',
    capture_probe_events: payload['capture_probe_events'] || payload[:capture_probe_events] || 'buffer_only',
    immediate_client_error_statuses: Array(
      payload['immediate_client_error_statuses'] || payload[:immediate_client_error_statuses]
    ).grep(Integer)
  )
end

.parse_directive(payload) ⇒ Object



129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
# File 'lib/debugbundle/remote_config.rb', line 129

def self.parse_directive(payload)
  return nil unless payload.is_a?(Hash)

  expires_at_value = payload['expires_at'] || payload[:expires_at]
  expires_at = parse_time(expires_at_value)
  return nil unless expires_at

  Directive.new(
    id: payload['id'] || payload[:id],
    label_pattern: payload['label_pattern'] || payload[:label_pattern],
    service: payload['service'] || payload[:service] || '*',
    environment: payload['environment'] || payload[:environment] || '*',
    expires_at: expires_at
  )
end

.parse_time(value) ⇒ Object



145
146
147
148
149
150
151
# File 'lib/debugbundle/remote_config.rb', line 145

def self.parse_time(value)
  return nil unless value.is_a?(String) && !value.empty?

  Time.iso8601(value)
rescue ArgumentError
  nil
end