dead_bro 0.2.12 → 0.2.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 56f6a72ccfa1a5e362c74eddace39a1ffeba97d06bab551f38d9091311609770
4
- data.tar.gz: 20ee34708c5eed8ac00af8d462953422ba7a24e3b9701e56e31eea8ba35752f0
3
+ metadata.gz: 2c308968cd84cfa8df47974178b741ab2847809754e86dc49cbe716d07a7a0bb
4
+ data.tar.gz: 6cdfb10f1ac9b2ecd9994bf6f35d8468022dc024e16e9ab31c1664fa91db7041
5
5
  SHA512:
6
- metadata.gz: 932ce6601969ac9f95ba0ce327b93a5412c167a4c7fe367d0c14bd05c5c751b69bb3da48eaf829e73bcf6ca10c66fd7678ff0caca4eba7e0ec42a3b4bae72e54
7
- data.tar.gz: 032ee4230c5b043a7ef8cf176963500eb60157927ad18f18c8e657f2439b31ab8b3526e7dd90036f79ec5fc7e978b55de540fcad14925f1fb33ffb6308379964
6
+ metadata.gz: 2a8f31655b9512739fa991ee94675c1f948c5ae2229dbb9de62a4e3c6ea0b5a8883ea880f986d911044e200d0c8ae6e696f6d8a58e5c338da6c8c3756c08e543
7
+ data.tar.gz: ddf1ed72e8310eb1f42db17f5124b704c5214447706ed68c1f9bae9f47f669fbf56006733f430a064af0fc8965be161dbb85bcaca2aee6b6c14a68b4865216f9
@@ -15,11 +15,12 @@ module DeadBro
15
15
  def post_metric(event_name:, payload:, force: false)
16
16
  return if @configuration.api_key.nil?
17
17
  return unless @configuration.enabled
18
+ return if @configuration.skip_tracking?
18
19
  return if !force && !@configuration.should_sample?
19
20
  return if circuit_open?
20
21
 
21
22
  payload = truncate_payload_for_request(payload)
22
- body = {event: event_name, payload: payload, sent_at: Time.now.utc.iso8601, revision: @configuration.resolve_deploy_id}
23
+ body = {event: event_name, payload: payload, sent_at: Time.now.utc.iso8601, revision: @configuration.resolve_deploy_id, gem_version: DeadBro::VERSION}
23
24
 
24
25
  dispatch_request(
25
26
  url: metrics_endpoint_url,
@@ -35,7 +36,7 @@ module DeadBro
35
36
  return if @configuration.api_key.nil?
36
37
 
37
38
  @configuration.last_heartbeat_attempt_at = Time.now.utc
38
- body = {event: "heartbeat", payload: {}, sent_at: Time.now.utc.iso8601, revision: @configuration.resolve_deploy_id}
39
+ body = {event: "heartbeat", payload: {}, sent_at: Time.now.utc.iso8601, revision: @configuration.resolve_deploy_id, gem_version: DeadBro::VERSION}
39
40
 
40
41
  dispatch_request(
41
42
  url: metrics_endpoint_url,
@@ -50,10 +51,11 @@ module DeadBro
50
51
  def post_monitor_stats(payload)
51
52
  return if @configuration.api_key.nil?
52
53
  return unless @configuration.enabled
54
+ return if @configuration.skip_tracking?
53
55
  return unless @configuration.job_queue_monitoring_enabled
54
56
  return if circuit_open?
55
57
 
56
- body = {payload: payload, sent_at: Time.now.utc.iso8601, revision: @configuration.resolve_deploy_id}
58
+ body = {payload: payload, sent_at: Time.now.utc.iso8601, revision: @configuration.resolve_deploy_id, gem_version: DeadBro::VERSION}
57
59
 
58
60
  dispatch_request(
59
61
  url: monitor_endpoint_url,
@@ -140,6 +142,12 @@ module DeadBro
140
142
  @configuration.last_heartbeat_at = Time.now.utc
141
143
  end
142
144
  end
145
+
146
+ if response.is_a?(Net::HTTPSuccess)
147
+ @configuration.skip_until = nil
148
+ elsif response.is_a?(Net::HTTPInsufficientStorage)
149
+ @configuration.skip_until = Time.now.utc + DeadBro::Configuration::METRICS_BACKEND_SKIP_AFTER_507_SECONDS
150
+ end
143
151
  elsif @circuit_breaker && @configuration.circuit_breaker_enabled
144
152
  @circuit_breaker.record_failure
145
153
  end
@@ -22,6 +22,10 @@ module DeadBro
22
22
  # Tracks when we last received settings from the backend (in-memory only)
23
23
  attr_accessor :settings_received_at
24
24
 
25
+ # After HTTP 507 Insufficient Storage from the API, skip all tracking until this
26
+ # UTC time (in-memory only). Cleared on the next successful API response.
27
+ attr_accessor :skip_until
28
+
25
29
  # Last successful heartbeat HTTP response time while disabled (in-memory only)
26
30
  attr_accessor :last_heartbeat_at
27
31
 
@@ -30,6 +34,8 @@ module DeadBro
30
34
 
31
35
  HEARTBEAT_INTERVAL = 60 # seconds
32
36
 
37
+ METRICS_BACKEND_SKIP_AFTER_507_SECONDS = 600 # 10 minutes
38
+
33
39
  # First non-empty ENV value wins for release/revision payloads and deploy grouping on the server.
34
40
  # Order is roughly: DeadBro-native → common CI/hosting → observability tooling.
35
41
  DEPLOY_REVISION_ENV_KEYS = %w[
@@ -87,6 +93,7 @@ module DeadBro
87
93
  @enable_system_stats = false
88
94
 
89
95
  @settings_received_at = nil
96
+ @skip_until = nil
90
97
  @last_heartbeat_at = nil
91
98
  @last_heartbeat_attempt_at = nil
92
99
  @settings_mutex = Mutex.new
@@ -152,6 +159,13 @@ module DeadBro
152
159
  last_heartbeat_attempt_at.nil? || (Time.now.utc - last_heartbeat_attempt_at) >= HEARTBEAT_INTERVAL
153
160
  end
154
161
 
162
+ def skip_tracking?
163
+ t = skip_until
164
+ return false unless t
165
+
166
+ Time.now.utc < t
167
+ end
168
+
155
169
  def resolve_deploy_id
156
170
  explicit = @explicit_deploy_revision&.to_s&.strip
157
171
  return explicit unless explicit.nil? || explicit.empty?
@@ -5,6 +5,8 @@ module DeadBro
5
5
  def self.subscribe!
6
6
  # Start SQL tracking when a job begins - use the start event, not the complete event
7
7
  ActiveSupport::Notifications.subscribe("perform_start.active_job") do |name, started, finished, _unique_id, data|
8
+ next if DeadBro.configuration.skip_tracking?
9
+
8
10
  # Clear logs for this job
9
11
  DeadBro.logger.clear
10
12
 
@@ -15,6 +15,11 @@ module DeadBro
15
15
  # Track job execution
16
16
  ActiveSupport::Notifications.subscribe(JOB_EVENT_NAME) do |name, started, finished, _unique_id, data|
17
17
  begin
18
+ if DeadBro.configuration.skip_tracking?
19
+ drain_job_tracking
20
+ next
21
+ end
22
+
18
23
  job_class_name = data[:job].class.name
19
24
  if DeadBro.configuration.excluded_job?(job_class_name)
20
25
  drain_job_tracking
@@ -106,6 +111,11 @@ module DeadBro
106
111
  # Track job exceptions
107
112
  ActiveSupport::Notifications.subscribe(JOB_EXCEPTION_EVENT_NAME) do |name, started, finished, _unique_id, data|
108
113
  begin
114
+ if DeadBro.configuration.skip_tracking?
115
+ drain_job_tracking
116
+ next
117
+ end
118
+
109
119
  job_class_name = data[:job].class.name
110
120
  if DeadBro.configuration.excluded_job?(job_class_name)
111
121
  next
@@ -7,6 +7,8 @@ module DeadBro
7
7
  end
8
8
 
9
9
  def call(env)
10
+ return @app.call(env) if DeadBro.configuration.skip_tracking?
11
+
10
12
  # Clear logs for this request
11
13
  DeadBro.logger.clear
12
14
 
@@ -16,6 +16,12 @@ module DeadBro
16
16
  next
17
17
  end
18
18
 
19
+ if DeadBro.configuration.skip_tracking?
20
+ client.post_heartbeat if DeadBro.configuration.heartbeat_due?
21
+ drain_request_tracking
22
+ next
23
+ end
24
+
19
25
  # Skip excluded controllers or controller#action pairs
20
26
  # Also check exclusive_controller_actions - if defined, only track those
21
27
  notification = data.is_a?(Hash) ? data : {}
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DeadBro
4
- VERSION = "0.2.12"
4
+ VERSION = "0.2.13"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dead_bro
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.12
4
+ version: 0.2.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Emanuel Comsa