brainzlab 0.1.21 → 0.1.22
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 +4 -4
- data/lib/brainzlab/configuration.rb +17 -1
- data/lib/brainzlab/instrumentation/active_record.rb +14 -10
- data/lib/brainzlab/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 007c390978f334950c503b50293ed7c9bb940d21528a1c8226976020ae17f7f6
|
|
4
|
+
data.tar.gz: 6c9f9a9bb98170602f6de0e0a328ac62ec10e806facf06d59534ae09017b3497
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 1470ab31ba66285d1787294a9c90266e516f4a0a3b7a30ee523a7c8f66c57dc5eb3b337c3de7644e21ab26cdf1fec619972b9cf283816f9bf4e743c3318d8601
|
|
7
|
+
data.tar.gz: c09a981ac1521930ad7f109f1ccac6294ccfbbe4bea122c0a1c0f32c7538cb51c0576dc8f783cf88e7e83a1a6682454a364be63b2302fd220c7eb1f786935266
|
|
@@ -158,7 +158,13 @@ module BrainzLab
|
|
|
158
158
|
:devtools_expand_by_default,
|
|
159
159
|
:rails_instrumentation_handled_externally,
|
|
160
160
|
:development_db_path,
|
|
161
|
-
:development_log_output
|
|
161
|
+
:development_log_output,
|
|
162
|
+
:slow_query_threshold,
|
|
163
|
+
:very_slow_query_threshold,
|
|
164
|
+
:slow_query_log_level,
|
|
165
|
+
:very_slow_query_log_level,
|
|
166
|
+
:n_plus_one_threshold,
|
|
167
|
+
:n_plus_one_log_level
|
|
162
168
|
|
|
163
169
|
# Services that should not track themselves to avoid circular dependencies
|
|
164
170
|
SELF_TRACKING_SERVICES = {
|
|
@@ -362,6 +368,16 @@ module BrainzLab
|
|
|
362
368
|
@http_ignore_hosts = %w[localhost 127.0.0.1]
|
|
363
369
|
@redis_ignore_commands = %w[ping info] # Commands to skip tracking
|
|
364
370
|
|
|
371
|
+
# ActiveRecord slow-query / N+1 detection — all tunable so a single chatty
|
|
372
|
+
# default can't flood Recall. Slow-query duration is APM data (Pulse already
|
|
373
|
+
# records it), so it defaults to a quiet level (:debug) and a higher threshold.
|
|
374
|
+
@slow_query_threshold = (ENV['BRAINZLAB_SLOW_QUERY_THRESHOLD'] || 500).to_i # ms (was hardcoded 100)
|
|
375
|
+
@very_slow_query_threshold = (ENV['BRAINZLAB_VERY_SLOW_QUERY_THRESHOLD'] || 2000).to_i # ms (was hardcoded 1000)
|
|
376
|
+
@slow_query_log_level = (ENV['BRAINZLAB_SLOW_QUERY_LOG_LEVEL'] || 'debug').to_sym # was :warn → floods
|
|
377
|
+
@very_slow_query_log_level = (ENV['BRAINZLAB_VERY_SLOW_QUERY_LOG_LEVEL'] || 'warn').to_sym
|
|
378
|
+
@n_plus_one_threshold = (ENV['BRAINZLAB_N_PLUS_ONE_THRESHOLD'] || 10).to_i # was hardcoded 5
|
|
379
|
+
@n_plus_one_log_level = (ENV['BRAINZLAB_N_PLUS_ONE_LOG_LEVEL'] || 'debug').to_sym # was :warning
|
|
380
|
+
|
|
365
381
|
# Log formatter settings
|
|
366
382
|
@log_formatter_enabled = true
|
|
367
383
|
@log_formatter_colors = nil # auto-detect TTY
|
|
@@ -6,11 +6,13 @@ module BrainzLab
|
|
|
6
6
|
SCHEMA_QUERIES = %w[SCHEMA EXPLAIN].freeze
|
|
7
7
|
INTERNAL_TABLES = %w[pg_ information_schema sqlite_ mysql.].freeze
|
|
8
8
|
|
|
9
|
-
#
|
|
9
|
+
# Slow-query / N+1 thresholds + log levels are now configurable — see
|
|
10
|
+
# BrainzLab::Configuration (slow_query_threshold, very_slow_query_threshold,
|
|
11
|
+
# slow_query_log_level, very_slow_query_log_level, n_plus_one_threshold,
|
|
12
|
+
# n_plus_one_log_level) + their BRAINZLAB_* env vars. These constants are
|
|
13
|
+
# kept only as legacy fallbacks and are no longer read by the instrumentation.
|
|
10
14
|
SLOW_QUERY_THRESHOLD = 100
|
|
11
15
|
VERY_SLOW_QUERY_THRESHOLD = 1000
|
|
12
|
-
|
|
13
|
-
# N+1 detection settings
|
|
14
16
|
N_PLUS_ONE_THRESHOLD = 5 # queries to same table in single request
|
|
15
17
|
N_PLUS_ONE_WINDOW = 50 # max queries to track per request
|
|
16
18
|
|
|
@@ -58,7 +60,7 @@ module BrainzLab
|
|
|
58
60
|
record_sql_span(event, duration)
|
|
59
61
|
|
|
60
62
|
# Log slow queries to Recall
|
|
61
|
-
log_slow_query(event, duration) if duration >=
|
|
63
|
+
log_slow_query(event, duration) if duration >= BrainzLab.configuration.slow_query_threshold
|
|
62
64
|
|
|
63
65
|
# Track for N+1 detection
|
|
64
66
|
track_query_for_n_plus_one(event)
|
|
@@ -79,9 +81,10 @@ module BrainzLab
|
|
|
79
81
|
end
|
|
80
82
|
|
|
81
83
|
# Determine level based on duration
|
|
84
|
+
cfg = BrainzLab.configuration
|
|
82
85
|
level = case duration
|
|
83
|
-
when 0...
|
|
84
|
-
when
|
|
86
|
+
when 0...cfg.slow_query_threshold then :info
|
|
87
|
+
when cfg.slow_query_threshold...cfg.very_slow_query_threshold then :warning
|
|
85
88
|
else :error
|
|
86
89
|
end
|
|
87
90
|
|
|
@@ -146,7 +149,8 @@ module BrainzLab
|
|
|
146
149
|
operation = extract_operation(sql)
|
|
147
150
|
name = payload[:name] || 'SQL'
|
|
148
151
|
|
|
149
|
-
|
|
152
|
+
cfg = BrainzLab.configuration
|
|
153
|
+
level = duration >= cfg.very_slow_query_threshold ? cfg.very_slow_query_log_level : cfg.slow_query_log_level
|
|
150
154
|
|
|
151
155
|
BrainzLab::Recall.send(
|
|
152
156
|
level,
|
|
@@ -158,7 +162,7 @@ module BrainzLab
|
|
|
158
162
|
row_count: payload[:row_count],
|
|
159
163
|
affected_rows: payload[:affected_rows],
|
|
160
164
|
connection_name: extract_connection_name(payload[:connection]),
|
|
161
|
-
threshold_exceeded: duration >=
|
|
165
|
+
threshold_exceeded: duration >= cfg.very_slow_query_threshold ? 'critical' : 'warning'
|
|
162
166
|
)
|
|
163
167
|
end
|
|
164
168
|
|
|
@@ -188,7 +192,7 @@ module BrainzLab
|
|
|
188
192
|
end
|
|
189
193
|
|
|
190
194
|
# Detect N+1 pattern
|
|
191
|
-
if tracker[:count] ==
|
|
195
|
+
if tracker[:count] == BrainzLab.configuration.n_plus_one_threshold
|
|
192
196
|
report_n_plus_one(table, tracker)
|
|
193
197
|
end
|
|
194
198
|
end
|
|
@@ -197,7 +201,7 @@ module BrainzLab
|
|
|
197
201
|
BrainzLab::Reflex.add_breadcrumb(
|
|
198
202
|
"Potential N+1 detected: #{tracker[:count]}+ queries to '#{table}'",
|
|
199
203
|
category: 'db.n_plus_one',
|
|
200
|
-
level:
|
|
204
|
+
level: BrainzLab.configuration.n_plus_one_log_level,
|
|
201
205
|
data: {
|
|
202
206
|
table: table,
|
|
203
207
|
query_count: tracker[:count],
|
data/lib/brainzlab/version.rb
CHANGED