sidekiq-memory_logger 0.1.1 → 0.2.0
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/.github/dependabot.yml +6 -0
- data/.github/workflows/benchmark.yml +1 -1
- data/.github/workflows/test.yml +1 -1
- data/CHANGELOG.md +19 -0
- data/conductor.json +5 -0
- data/lib/sidekiq/memory_logger/version.rb +1 -1
- data/lib/sidekiq/memory_logger.rb +1 -3
- data/test/sidekiq/memory_logger/middleware_test.rb +57 -0
- data/test/sidekiq/memory_logger/rails_test.rb +9 -52
- metadata +4 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fa6efe35a98202afd1bebd865fd1e5f2ee3caf51336f50b02e1748b265a3f980
|
4
|
+
data.tar.gz: 3c4cd8a910658205fdaa5d410a56deea983750c627c6e828d3a0d31a05948219
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b7be75489aa198106891e28e854092e77176628a691c4eaf25cba301258163616355abf0edf86a482135ede7bc1c7d3bb5305ed544de69152686dc67c327ede6
|
7
|
+
data.tar.gz: 4a509383f8a7879ee634970f6c694340be534e1a179501dbafe8d4010cbcb5a06564311b298a69ea4fe21507f161077a8d6e4e24a0db239422e5e435113f64cb
|
data/.github/workflows/test.yml
CHANGED
data/CHANGELOG.md
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# Changelog
|
2
|
+
|
3
|
+
## [0.2.0]
|
4
|
+
|
5
|
+
- Fixed compatibility with ActiveJob, we now correctly report the wrapped class
|
6
|
+
- Removed Rails logger test mocks in favor of real integration testing
|
7
|
+
|
8
|
+
## [0.1.1]
|
9
|
+
|
10
|
+
- Renamed gem from `sidekiq-memory-logger` to `sidekiq-memory_logger` for consistency with Ruby naming conventions
|
11
|
+
|
12
|
+
## [0.1.0]
|
13
|
+
|
14
|
+
- Object allocation tracking using `GC.stat[:total_allocated_objects]`
|
15
|
+
- Queue filtering configuration to selectively monitor specific queues
|
16
|
+
- Performance benchmarking using sidekiqload tool
|
17
|
+
- Support for custom callbacks (StatsD, New Relic, Datadog examples)
|
18
|
+
at: `[MemoryLogger] job=MyJob queue=default memory_mb=15.2 objects=12345`
|
19
|
+
|
data/conductor.json
ADDED
@@ -47,8 +47,6 @@ module Sidekiq
|
|
47
47
|
end
|
48
48
|
|
49
49
|
class Middleware
|
50
|
-
include Sidekiq::ServerMiddleware
|
51
|
-
|
52
50
|
def initialize(config = nil)
|
53
51
|
@memory_logger_config = config || MemoryLogger.configuration
|
54
52
|
end
|
@@ -68,7 +66,7 @@ module Sidekiq
|
|
68
66
|
objects_diff = end_objects - start_objects
|
69
67
|
|
70
68
|
begin
|
71
|
-
@memory_logger_config.callback.call(job["class"], queue, memory_diff, objects_diff, job["args"])
|
69
|
+
@memory_logger_config.callback.call(job["wrapped"] || job["class"], queue, memory_diff, objects_diff, job["args"])
|
72
70
|
rescue => e
|
73
71
|
@memory_logger_config.logger.error("Sidekiq memory logger callback failed: #{e.message}")
|
74
72
|
end
|
@@ -1,6 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require "test_helper"
|
4
|
+
require "active_job"
|
4
5
|
|
5
6
|
class TestSidekiqMemoryLoggerMiddleware < Minitest::Test
|
6
7
|
def setup
|
@@ -180,4 +181,60 @@ class TestSidekiqMemoryLoggerMiddleware < Minitest::Test
|
|
180
181
|
assert_equal "TestJob", job_class
|
181
182
|
assert_equal "any_queue", queue
|
182
183
|
end
|
184
|
+
|
185
|
+
def test_middleware_uses_wrapped_class_for_activejob
|
186
|
+
callback_calls = []
|
187
|
+
activejob_wrapped = {
|
188
|
+
"class" => "ActiveJob::QueueAdapters::SidekiqAdapter::JobWrapper",
|
189
|
+
"wrapped" => "ProcessCompanyDataJob",
|
190
|
+
"args" => [{"job_class" => "ProcessCompanyDataJob"}]
|
191
|
+
}
|
192
|
+
config = Sidekiq::MemoryLogger::Configuration.new
|
193
|
+
config.callback = ->(job_class, queue, memory_diff, objects_diff, args) do
|
194
|
+
callback_calls << [job_class, queue, memory_diff, objects_diff, args]
|
195
|
+
end
|
196
|
+
|
197
|
+
middleware = Sidekiq::MemoryLogger::Middleware.new(config)
|
198
|
+
middleware.call(nil, activejob_wrapped, @queue) { sleep 0.01 }
|
199
|
+
|
200
|
+
assert_equal 1, callback_calls.length
|
201
|
+
job_class, _queue, _memory_diff, _objects_diff, _args = callback_calls.first
|
202
|
+
assert_equal "ProcessCompanyDataJob", job_class
|
203
|
+
end
|
204
|
+
|
205
|
+
def test_middleware_with_real_activejob_class
|
206
|
+
test_job_class = Class.new(ActiveJob::Base) do
|
207
|
+
queue_as :default
|
208
|
+
|
209
|
+
def perform(arg1, arg2)
|
210
|
+
arg1 + arg2
|
211
|
+
end
|
212
|
+
|
213
|
+
def self.name
|
214
|
+
"TestActiveJob"
|
215
|
+
end
|
216
|
+
end
|
217
|
+
|
218
|
+
callback_calls = []
|
219
|
+
config = Sidekiq::MemoryLogger::Configuration.new
|
220
|
+
config.callback = ->(job_class, queue, memory_diff, objects_diff, args) do
|
221
|
+
callback_calls << [job_class, queue, memory_diff, objects_diff, args]
|
222
|
+
end
|
223
|
+
|
224
|
+
serialized_job = test_job_class.new(1, 2).serialize
|
225
|
+
job_hash = {
|
226
|
+
"class" => "ActiveJob::QueueAdapters::SidekiqAdapter::JobWrapper",
|
227
|
+
"wrapped" => "TestActiveJob",
|
228
|
+
"queue" => "default",
|
229
|
+
"args" => [serialized_job]
|
230
|
+
}
|
231
|
+
|
232
|
+
middleware = Sidekiq::MemoryLogger::Middleware.new(config)
|
233
|
+
middleware.call(nil, job_hash, "default") { sleep 0.01 }
|
234
|
+
|
235
|
+
assert_equal 1, callback_calls.length
|
236
|
+
job_class, queue, _memory_diff, _objects_diff, _args = callback_calls.first
|
237
|
+
assert_equal "TestActiveJob", job_class
|
238
|
+
assert_equal "default", queue
|
239
|
+
end
|
183
240
|
end
|
@@ -1,76 +1,33 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require "test_helper"
|
4
|
+
require "logger"
|
4
5
|
require "rails"
|
5
6
|
|
6
7
|
class TestSidekiqMemoryLoggerRails < Minitest::Test
|
7
|
-
def
|
8
|
-
|
9
|
-
|
10
|
-
|
8
|
+
def setup
|
9
|
+
@original_logger = Rails.logger
|
10
|
+
end
|
11
|
+
|
12
|
+
def teardown
|
13
|
+
Rails.logger = @original_logger
|
11
14
|
end
|
12
15
|
|
13
16
|
def test_configuration_uses_rails_logger_when_rails_logger_available
|
14
|
-
# Create a mock Rails with a logger
|
15
|
-
original_logger_method = Rails.method(:logger) if Rails.respond_to?(:logger)
|
16
17
|
test_logger = Logger.new(StringIO.new)
|
18
|
+
Rails.logger = test_logger
|
17
19
|
|
18
|
-
Rails.define_singleton_method(:logger) { test_logger }
|
19
|
-
|
20
|
-
# Create new configuration
|
21
20
|
config = Sidekiq::MemoryLogger::Configuration.new
|
22
21
|
|
23
|
-
# Should use our test Rails.logger
|
24
22
|
assert_equal test_logger, config.logger
|
25
|
-
ensure
|
26
|
-
# Restore original logger method
|
27
|
-
if original_logger_method
|
28
|
-
Rails.define_singleton_method(:logger, &original_logger_method)
|
29
|
-
end
|
30
23
|
end
|
31
24
|
|
32
25
|
def test_configuration_falls_back_when_rails_logger_nil
|
33
|
-
|
34
|
-
Rails.define_singleton_method(:logger) { nil }
|
35
|
-
|
36
|
-
# Create new configuration
|
37
|
-
config = Sidekiq::MemoryLogger::Configuration.new
|
38
|
-
|
39
|
-
# Should fall back to stdout logger since Rails.logger is nil
|
40
|
-
assert_instance_of Logger, config.logger
|
41
|
-
assert_equal $stdout, config.logger.instance_variable_get(:@logdev).dev
|
42
|
-
end
|
43
|
-
|
44
|
-
def test_configuration_falls_back_when_rails_not_available
|
45
|
-
# Temporarily hide Rails constant
|
46
|
-
rails_backup = Object.send(:remove_const, :Rails) if defined?(Rails)
|
47
|
-
|
48
|
-
# Create new configuration instance
|
49
|
-
config = Sidekiq::MemoryLogger::Configuration.new
|
50
|
-
|
51
|
-
# Should fall back to stdout logger
|
52
|
-
assert_instance_of Logger, config.logger
|
53
|
-
assert_equal $stdout, config.logger.instance_variable_get(:@logdev).dev
|
54
|
-
ensure
|
55
|
-
# Restore Rails constant
|
56
|
-
Object.const_set(:Rails, rails_backup) if rails_backup
|
57
|
-
end
|
58
|
-
|
59
|
-
def test_configuration_falls_back_when_rails_logger_unavailable
|
60
|
-
# Create mock Rails without logger method
|
61
|
-
rails_backup = Object.send(:remove_const, :Rails) if defined?(Rails)
|
62
|
-
rails_mock = Class.new
|
63
|
-
Object.const_set(:Rails, rails_mock)
|
26
|
+
Rails.logger = nil
|
64
27
|
|
65
|
-
# Create new configuration instance
|
66
28
|
config = Sidekiq::MemoryLogger::Configuration.new
|
67
29
|
|
68
|
-
# Should fall back to stdout logger since Rails doesn't respond to logger
|
69
30
|
assert_instance_of Logger, config.logger
|
70
31
|
assert_equal $stdout, config.logger.instance_variable_get(:@logdev).dev
|
71
|
-
ensure
|
72
|
-
# Restore Rails constant
|
73
|
-
Object.send(:remove_const, :Rails)
|
74
|
-
Object.const_set(:Rails, rails_backup) if rails_backup
|
75
32
|
end
|
76
33
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sidekiq-memory_logger
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nate Berkopec
|
@@ -46,12 +46,15 @@ extensions: []
|
|
46
46
|
extra_rdoc_files: []
|
47
47
|
files:
|
48
48
|
- ".custom_rubocop.yml"
|
49
|
+
- ".github/dependabot.yml"
|
49
50
|
- ".github/workflows/benchmark.yml"
|
50
51
|
- ".github/workflows/test.yml"
|
51
52
|
- ".standard.yml"
|
53
|
+
- CHANGELOG.md
|
52
54
|
- LICENSE.txt
|
53
55
|
- README.md
|
54
56
|
- Rakefile
|
57
|
+
- conductor.json
|
55
58
|
- lib/rubocop/cop/sidekiq_memory_logger.rb
|
56
59
|
- lib/rubocop/cop/sidekiq_memory_logger/no_configure_in_tests.rb
|
57
60
|
- lib/sidekiq-memory_logger.rb
|