dead_bro 0.2.25 → 0.2.26

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: aec6a4f779a49726e225b3d01e9e1a6516c56639a451837615a8d8c08cb59e8a
4
- data.tar.gz: 186f7fd09ef2b4c3d2ed9390c1278a9f5bbc577a0e05572e63cea7461689fccc
3
+ metadata.gz: 0f527f74687fb94ef798bfbd31870d8dcf765c1b6c75584302cf273b56c68cab
4
+ data.tar.gz: 4e4afa23e175daeb1f1227921ddc7475f50b3bd45d2551f92ec9f4e373efe7a8
5
5
  SHA512:
6
- metadata.gz: 2b7028050d353c623587cd3f083b2b8666fcd05abfa68b7cf05d7bdda5979f29118bdabcbb37c0165a10eca829e30305ff061874c08d9a45e65d89193acd3ad3
7
- data.tar.gz: 2f16e4716988194147e087396dc419c4d20fdb4bd2a958d38f866e158d76e2f233d0187a08eb54c6b7f40a9eb9637dc0079e857257cb9d3f2091a05b9490968b
6
+ metadata.gz: 1fd2320017c4f5975a8c0dbf04066b7c9a1ec057099bcd4b10e816b69cc389faa0f0d0ae7b0e4a5b0450b17a97b910886335f76d874d0e5e6eb92449e11eae0b
7
+ data.tar.gz: ddaba39dc62527ea96b03170579879849f2dd214d2247c7de5dae53a59ff2ab94b6de84a968e5d884213f67fd3e8de24964cad453c728e20f409c7555d214b09
@@ -19,6 +19,10 @@ module DeadBro
19
19
  # and cache the regex form once, instead of rebuilding it per request.
20
20
  attr_reader :excluded_controllers, :excluded_jobs, :exclusive_controllers, :exclusive_jobs
21
21
 
22
+ # Per-request-type sample rate overrides, keyed by exact "Controller#action"
23
+ # (or "JobClass#perform") strings — same identity ApmRequestType uses server-side.
24
+ attr_reader :sample_rates_by_type
25
+
22
26
  # Tracks when we last received settings from the backend (in-memory only)
23
27
  attr_accessor :settings_received_at
24
28
 
@@ -59,6 +63,7 @@ module DeadBro
59
63
  explain_analyze_enabled slow_query_threshold_ms max_sql_queries_to_send max_logs_to_send
60
64
  excluded_controllers excluded_jobs exclusive_controllers exclusive_jobs
61
65
  monitor_enabled enable_db_stats enable_process_stats enable_system_stats
66
+ sample_rates_by_type
62
67
  ].freeze
63
68
 
64
69
  def initialize
@@ -91,6 +96,7 @@ module DeadBro
91
96
  self.excluded_jobs = []
92
97
  self.exclusive_controllers = []
93
98
  self.exclusive_jobs = []
99
+ self.sample_rates_by_type = {}
94
100
  @monitor_enabled = false
95
101
  @enable_db_stats = false
96
102
  @enable_process_stats = false
@@ -134,6 +140,15 @@ module DeadBro
134
140
  @compiled_exclusive_jobs = compile_patterns(@exclusive_jobs)
135
141
  end
136
142
 
143
+ # Exact-match only — no wildcard/regex support, unlike the exclusion lists.
144
+ def sample_rates_by_type=(value)
145
+ return @sample_rates_by_type = {} unless value.is_a?(Hash)
146
+
147
+ @sample_rates_by_type = value.each_with_object({}) do |(k, v), memo|
148
+ memo[k.to_s] = v.to_i
149
+ end
150
+ end
151
+
137
152
  # Apply a settings hash received from the backend response.
138
153
  # Only known keys are applied; unknown keys are silently ignored.
139
154
  # Serialized so concurrent HTTP threads do not interleave writes with request-thread reads.
@@ -153,6 +168,8 @@ module DeadBro
153
168
  send(:"#{k}=", !!value)
154
169
  when "excluded_controllers", "excluded_jobs", "exclusive_controllers", "exclusive_jobs"
155
170
  send(:"#{k}=", Array(value).map(&:to_s))
171
+ when "sample_rates_by_type"
172
+ send(:"#{k}=", value)
156
173
  end
157
174
  end
158
175
  end
@@ -232,8 +249,12 @@ module DeadBro
232
249
  compiled.any? { |entry| match_compiled?(target, entry) }
233
250
  end
234
251
 
235
- def should_sample?
236
- sample_rate = resolve_sample_rate
252
+ def should_sample?(request_type_key = nil)
253
+ sample_rate = if request_type_key && @sample_rates_by_type.key?(request_type_key.to_s)
254
+ @sample_rates_by_type[request_type_key.to_s]
255
+ else
256
+ resolve_sample_rate
257
+ end
237
258
  sample_rate = 100 if sample_rate.nil?
238
259
 
239
260
  return true if sample_rate >= 100
@@ -44,7 +44,8 @@ module DeadBro
44
44
  # enough that even the "cheap" stop/analyze work matters under load.
45
45
  # Completions have no exception attached; the exception subscriber below
46
46
  # always sends errors with force: true.
47
- unless DeadBro.configuration.should_sample?
47
+ job_type_key = "#{job_class_name}#perform"
48
+ unless DeadBro.configuration.should_sample?(job_type_key)
48
49
  drain_job_tracking
49
50
  next
50
51
  end
@@ -124,7 +125,9 @@ module DeadBro
124
125
  logs: DeadBro.logger.logs
125
126
  }
126
127
 
127
- client.post_metric(event_name: name, payload: payload)
128
+ # force: true the sampling decision above already accounted for any
129
+ # per-job-type override; client#post_metric must not re-roll it globally.
130
+ client.post_metric(event_name: name, payload: payload, force: true)
128
131
  end
129
132
 
130
133
  # Track job exceptions
@@ -43,8 +43,9 @@ module DeadBro
43
43
  end
44
44
 
45
45
  has_error = data[:exception] || data[:exception_object]
46
+ request_type_key = "#{controller_name}##{action_name}"
46
47
  # Errors always ship regardless of sampling (this is what the docs promise).
47
- unless has_error || DeadBro.configuration.should_sample?
48
+ unless has_error || DeadBro.configuration.should_sample?(request_type_key)
48
49
  drain_request_tracking
49
50
  next
50
51
  end
@@ -223,7 +224,10 @@ module DeadBro
223
224
  cpu_time_ms: cpu_time_ms,
224
225
  logs: DeadBro.logger.logs
225
226
  }
226
- client.post_metric(event_name: name, payload: payload)
227
+ # force: true the sampling decision (global or per-request-type) was
228
+ # already made above; client#post_metric must not re-roll it with the
229
+ # global-only rate, which would silently override a per-type sample rate.
230
+ client.post_metric(event_name: name, payload: payload, force: true)
227
231
  end
228
232
  end
229
233
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DeadBro
4
- VERSION = "0.2.25"
4
+ VERSION = "0.2.26"
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.25
4
+ version: 0.2.26
5
5
  platform: ruby
6
6
  authors:
7
7
  - Emanuel Comsa