appsignal 3.1.5-java → 3.2.0-java

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.
@@ -7,114 +7,177 @@ describe Appsignal::Probes::SidekiqProbe do
7
7
  let(:expected_default_tags) { { :hostname => "localhost" } }
8
8
  before do
9
9
  Appsignal.config = project_fixture_config
10
- module SidekiqMock
11
- def self.redis_info
12
- {
13
- "connected_clients" => 2,
14
- "used_memory" => 1024,
15
- "used_memory_rss" => 512
16
- }
10
+
11
+ class SidekiqStats
12
+ class << self
13
+ attr_reader :calls
14
+
15
+ def count_call
16
+ @calls ||= -1
17
+ @calls += 1
18
+ end
17
19
  end
18
20
 
19
- def self.redis
20
- yield Client.new
21
+ def workers_size
22
+ # First method called, so count it towards a call
23
+ self.class.count_call
24
+ 24
21
25
  end
22
26
 
23
- class Client
24
- def connection
25
- { :host => "localhost" }
26
- end
27
+ def processes_size
28
+ 25
27
29
  end
28
30
 
29
- class Stats
30
- class << self
31
- attr_reader :calls
31
+ # Return two different values for two separate calls.
32
+ # This allows us to test the delta of the value send as a gauge.
33
+ def processed
34
+ [10, 15][self.class.calls]
35
+ end
32
36
 
33
- def count_call
34
- @calls ||= -1
35
- @calls += 1
36
- end
37
- end
37
+ # Return two different values for two separate calls.
38
+ # This allows us to test the delta of the value send as a gauge.
39
+ def failed
40
+ [10, 13][self.class.calls]
41
+ end
38
42
 
39
- def workers_size
40
- # First method called, so count it towards a call
41
- self.class.count_call
42
- 24
43
- end
43
+ def retry_size
44
+ 12
45
+ end
44
46
 
45
- def processes_size
46
- 25
47
- end
47
+ # Return two different values for two separate calls.
48
+ # This allows us to test the delta of the value send as a gauge.
49
+ def dead_size
50
+ [10, 12][self.class.calls]
51
+ end
48
52
 
49
- # Return two different values for two separate calls.
50
- # This allows us to test the delta of the value send as a gauge.
51
- def processed
52
- [10, 15][self.class.calls]
53
- end
53
+ def scheduled_size
54
+ 14
55
+ end
54
56
 
55
- # Return two different values for two separate calls.
56
- # This allows us to test the delta of the value send as a gauge.
57
- def failed
58
- [10, 13][self.class.calls]
59
- end
57
+ def enqueued
58
+ 15
59
+ end
60
+ end
60
61
 
61
- def retry_size
62
- 12
63
- end
62
+ class SidekiqQueue
63
+ Queue = Struct.new(:name, :size, :latency)
64
+
65
+ def self.all
66
+ [
67
+ Queue.new("default", 10, 12),
68
+ Queue.new("critical", 1, 2)
69
+ ]
70
+ end
71
+ end
72
+
73
+ module Sidekiq7Mock
74
+ VERSION = "7.0.0".freeze
75
+
76
+ def self.redis
77
+ yield Client.new
78
+ end
64
79
 
65
- # Return two different values for two separate calls.
66
- # This allows us to test the delta of the value send as a gauge.
67
- def dead_size
68
- [10, 12][self.class.calls]
80
+ class Client
81
+ def config
82
+ Config.new
69
83
  end
70
84
 
71
- def scheduled_size
72
- 14
85
+ def info
86
+ {
87
+ "connected_clients" => 2,
88
+ "used_memory" => 1024,
89
+ "used_memory_rss" => 512
90
+ }
73
91
  end
92
+ end
74
93
 
75
- def enqueued
76
- 15
94
+ class Config
95
+ def host
96
+ "localhost"
77
97
  end
78
98
  end
79
99
 
80
- class Queue
81
- Queue = Struct.new(:name, :size, :latency)
100
+ Stats = ::SidekiqStats
101
+ Queue = ::SidekiqQueue
102
+ end
103
+
104
+ module Sidekiq6Mock
105
+ VERSION = "6.9.9".freeze
106
+
107
+ def self.redis_info
108
+ {
109
+ "connected_clients" => 2,
110
+ "used_memory" => 1024,
111
+ "used_memory_rss" => 512
112
+ }
113
+ end
114
+
115
+ def self.redis
116
+ yield Client.new
117
+ end
82
118
 
83
- def self.all
84
- [
85
- Queue.new("default", 10, 12),
86
- Queue.new("critical", 1, 2)
87
- ]
119
+ class Client
120
+ def connection
121
+ { :host => "localhost" }
88
122
  end
89
123
  end
124
+
125
+ Stats = ::SidekiqStats
126
+ Queue = ::SidekiqQueue
90
127
  end
91
- stub_const("Sidekiq", SidekiqMock)
92
128
  end
93
- after { Object.send(:remove_const, :SidekiqMock) }
129
+ after do
130
+ Object.send(:remove_const, :SidekiqStats)
131
+ Object.send(:remove_const, :SidekiqQueue)
132
+ Object.send(:remove_const, :Sidekiq6Mock)
133
+ Object.send(:remove_const, :Sidekiq7Mock)
134
+ end
135
+
136
+ def with_sidekiq7!
137
+ stub_const("Sidekiq", Sidekiq7Mock)
138
+ end
139
+ # Version not relevant, but requires any version for tests
140
+ alias_method :with_sidekiq!, :with_sidekiq7!
141
+
142
+ def with_sidekiq6!
143
+ stub_const("Sidekiq", Sidekiq6Mock)
144
+ end
94
145
 
95
146
  describe ".dependencies_present?" do
96
- before do
97
- stub_const("Redis::VERSION", version)
147
+ context "when Sidekiq 7" do
148
+ before { with_sidekiq7! }
149
+
150
+ it "starts the probe" do
151
+ expect(described_class.dependencies_present?).to be_truthy
152
+ end
98
153
  end
99
154
 
100
- context "when Redis version is < 3.3.5" do
101
- let(:version) { "3.3.4" }
155
+ context "when Sidekiq 6" do
156
+ before do
157
+ with_sidekiq6!
158
+ stub_const("Redis::VERSION", version)
159
+ end
160
+
161
+ context "when Redis version is < 3.3.5" do
162
+ let(:version) { "3.3.4" }
102
163
 
103
- it "does not start probe" do
104
- expect(described_class.dependencies_present?).to be_falsy
164
+ it "does not start probe" do
165
+ expect(described_class.dependencies_present?).to be_falsy
166
+ end
105
167
  end
106
- end
107
168
 
108
- context "when Redis version is >= 3.3.5" do
109
- let(:version) { "3.3.5" }
169
+ context "when Redis version is >= 3.3.5" do
170
+ let(:version) { "3.3.5" }
110
171
 
111
- it "does not start probe" do
112
- expect(described_class.dependencies_present?).to be_truthy
172
+ it "starts the probe" do
173
+ expect(described_class.dependencies_present?).to be_truthy
174
+ end
113
175
  end
114
176
  end
115
177
  end
116
178
 
117
179
  it "loads Sidekiq::API" do
180
+ with_sidekiq!
118
181
  # Hide the Sidekiq constant if it was already loaded. It will be
119
182
  # redefined by loading "sidekiq/api" in the probe.
120
183
  hide_const "Sidekiq::Stats"
@@ -125,53 +188,94 @@ describe Appsignal::Probes::SidekiqProbe do
125
188
  end
126
189
 
127
190
  it "logs config on initialize" do
191
+ with_sidekiq!
128
192
  log = capture_logs { probe }
129
193
  expect(log).to contains_log(:debug, "Initializing Sidekiq probe\n")
130
194
  end
131
195
 
132
- it "logs used hostname on call once" do
133
- log = capture_logs { probe.call }
134
- expect(log).to contains_log(
135
- :debug,
136
- %(Sidekiq probe: Using Redis server hostname "localhost" as hostname)
137
- )
138
- log = capture_logs { probe.call }
139
- # Match more logs with incompelete message
140
- expect(log).to_not contains_log(:debug, %(Sidekiq probe: ))
141
- end
196
+ context "with Sidekiq 7" do
197
+ before { with_sidekiq7! }
142
198
 
143
- it "collects custom metrics" do
144
- expect_gauge("worker_count", 24).twice
145
- expect_gauge("process_count", 25).twice
146
- expect_gauge("connection_count", 2).twice
147
- expect_gauge("memory_usage", 1024).twice
148
- expect_gauge("memory_usage_rss", 512).twice
149
- expect_gauge("job_count", 5, :status => :processed) # Gauge delta
150
- expect_gauge("job_count", 3, :status => :failed) # Gauge delta
151
- expect_gauge("job_count", 12, :status => :retry_queue).twice
152
- expect_gauge("job_count", 2, :status => :died) # Gauge delta
153
- expect_gauge("job_count", 14, :status => :scheduled).twice
154
- expect_gauge("job_count", 15, :status => :enqueued).twice
155
- expect_gauge("queue_length", 10, :queue => "default").twice
156
- expect_gauge("queue_latency", 12_000, :queue => "default").twice
157
- expect_gauge("queue_length", 1, :queue => "critical").twice
158
- expect_gauge("queue_latency", 2_000, :queue => "critical").twice
159
- # Call probe twice so we can calculate the delta for some gauge values
160
- probe.call
161
- probe.call
199
+ it "logs used hostname on call once" do
200
+ log = capture_logs { probe.call }
201
+ expect(log).to contains_log(
202
+ :debug,
203
+ %(Sidekiq probe: Using Redis server hostname "localhost" as hostname)
204
+ )
205
+ log = capture_logs { probe.call }
206
+ # Match more logs with incompelete message
207
+ expect(log).to_not contains_log(:debug, %(Sidekiq probe: ))
208
+ end
209
+
210
+ it "collects custom metrics" do
211
+ expect_gauge("worker_count", 24).twice
212
+ expect_gauge("process_count", 25).twice
213
+ expect_gauge("connection_count", 2).twice
214
+ expect_gauge("memory_usage", 1024).twice
215
+ expect_gauge("memory_usage_rss", 512).twice
216
+ expect_gauge("job_count", 5, :status => :processed) # Gauge delta
217
+ expect_gauge("job_count", 3, :status => :failed) # Gauge delta
218
+ expect_gauge("job_count", 12, :status => :retry_queue).twice
219
+ expect_gauge("job_count", 2, :status => :died) # Gauge delta
220
+ expect_gauge("job_count", 14, :status => :scheduled).twice
221
+ expect_gauge("job_count", 15, :status => :enqueued).twice
222
+ expect_gauge("queue_length", 10, :queue => "default").twice
223
+ expect_gauge("queue_latency", 12_000, :queue => "default").twice
224
+ expect_gauge("queue_length", 1, :queue => "critical").twice
225
+ expect_gauge("queue_latency", 2_000, :queue => "critical").twice
226
+ # Call probe twice so we can calculate the delta for some gauge values
227
+ probe.call
228
+ probe.call
229
+ end
162
230
  end
163
231
 
164
- context "when `redis_info` is not defined" do
165
- before do
166
- allow(Sidekiq).to receive(:respond_to?).with(:redis_info).and_return(false)
232
+ context "with Sidekiq 6" do
233
+ before { with_sidekiq6! }
234
+
235
+ it "logs used hostname on call once" do
236
+ log = capture_logs { probe.call }
237
+ expect(log).to contains_log(
238
+ :debug,
239
+ %(Sidekiq probe: Using Redis server hostname "localhost" as hostname)
240
+ )
241
+ log = capture_logs { probe.call }
242
+ # Match more logs with incompelete message
243
+ expect(log).to_not contains_log(:debug, %(Sidekiq probe: ))
167
244
  end
168
245
 
169
- it "does not collect redis metrics" do
170
- expect_gauge("connection_count", 2).never
171
- expect_gauge("memory_usage", 1024).never
172
- expect_gauge("memory_usage_rss", 512).never
246
+ it "collects custom metrics" do
247
+ expect_gauge("worker_count", 24).twice
248
+ expect_gauge("process_count", 25).twice
249
+ expect_gauge("connection_count", 2).twice
250
+ expect_gauge("memory_usage", 1024).twice
251
+ expect_gauge("memory_usage_rss", 512).twice
252
+ expect_gauge("job_count", 5, :status => :processed) # Gauge delta
253
+ expect_gauge("job_count", 3, :status => :failed) # Gauge delta
254
+ expect_gauge("job_count", 12, :status => :retry_queue).twice
255
+ expect_gauge("job_count", 2, :status => :died) # Gauge delta
256
+ expect_gauge("job_count", 14, :status => :scheduled).twice
257
+ expect_gauge("job_count", 15, :status => :enqueued).twice
258
+ expect_gauge("queue_length", 10, :queue => "default").twice
259
+ expect_gauge("queue_latency", 12_000, :queue => "default").twice
260
+ expect_gauge("queue_length", 1, :queue => "critical").twice
261
+ expect_gauge("queue_latency", 2_000, :queue => "critical").twice
262
+ # Call probe twice so we can calculate the delta for some gauge values
263
+ probe.call
173
264
  probe.call
174
265
  end
266
+
267
+ context "when Sidekiq `redis_info` is not defined" do
268
+ before do
269
+ allow(Sidekiq).to receive(:respond_to?).with(:redis_info).and_return(false)
270
+ end
271
+
272
+ it "does not collect redis metrics" do
273
+ expect_gauge("connection_count", 2).never
274
+ expect_gauge("memory_usage", 1024).never
275
+ expect_gauge("memory_usage_rss", 512).never
276
+ probe.call
277
+ end
278
+ end
175
279
  end
176
280
 
177
281
  context "when hostname is configured for probe" do
@@ -179,6 +283,8 @@ describe Appsignal::Probes::SidekiqProbe do
179
283
  let(:probe) { described_class.new(:hostname => redis_hostname) }
180
284
 
181
285
  it "uses the redis hostname for the hostname tag" do
286
+ with_sidekiq!
287
+
182
288
  allow(Appsignal).to receive(:set_gauge).and_call_original
183
289
  log = capture_logs { probe }
184
290
  expect(log).to contains_log(
@@ -0,0 +1,25 @@
1
+ describe Appsignal::Utils::IntegrationLogger do
2
+ let(:log) { std_stream }
3
+ let(:logger) do
4
+ Appsignal::Utils::IntegrationLogger.new(log).tap do |l|
5
+ l.formatter = logger_formatter
6
+ end
7
+ end
8
+
9
+ describe "#seen_keys" do
10
+ it "returns a Set" do
11
+ expect(logger.seen_keys).to be_a(Set)
12
+ end
13
+ end
14
+
15
+ describe "#warn_once_then_debug" do
16
+ it "only warns once, then uses debug" do
17
+ message = "This is a log line"
18
+ 3.times { logger.warn_once_then_debug(:key, message) }
19
+
20
+ logs = log_contents(log)
21
+ expect(logs.scan(/#{Regexp.escape(log_line(:WARN, message))}/).count).to eql(1)
22
+ expect(logs.scan(/#{Regexp.escape(log_line(:DEBUG, message))}/).count).to eql(2)
23
+ end
24
+ end
25
+ end
@@ -1127,7 +1127,7 @@ describe Appsignal do
1127
1127
  Appsignal.start_logger
1128
1128
  Appsignal.logger.error("Log to file")
1129
1129
  end
1130
- expect(Appsignal.logger).to be_a(Appsignal::Logger)
1130
+ expect(Appsignal.logger).to be_a(Appsignal::Utils::IntegrationLogger)
1131
1131
  end
1132
1132
 
1133
1133
  it "logs to file" do
@@ -1150,7 +1150,7 @@ describe Appsignal do
1150
1150
  initialize_config
1151
1151
  Appsignal.start_logger
1152
1152
  Appsignal.logger.error("Log to not writable log file")
1153
- expect(Appsignal.logger).to be_a(Appsignal::Logger)
1153
+ expect(Appsignal.logger).to be_a(Appsignal::Utils::IntegrationLogger)
1154
1154
  end
1155
1155
  end
1156
1156
 
@@ -1181,7 +1181,7 @@ describe Appsignal do
1181
1181
  Appsignal.start_logger
1182
1182
  Appsignal.logger.error("Log to not writable log path")
1183
1183
  end
1184
- expect(Appsignal.logger).to be_a(Appsignal::Logger)
1184
+ expect(Appsignal.logger).to be_a(Appsignal::Utils::IntegrationLogger)
1185
1185
  end
1186
1186
  after do
1187
1187
  FileUtils.chmod 0o755, Appsignal::Config.system_tmp_dir
@@ -1210,7 +1210,7 @@ describe Appsignal do
1210
1210
  Appsignal.start_logger
1211
1211
  Appsignal.logger.error("Log to stdout")
1212
1212
  end
1213
- expect(Appsignal.logger).to be_a(Appsignal::Logger)
1213
+ expect(Appsignal.logger).to be_a(Appsignal::Utils::IntegrationLogger)
1214
1214
  end
1215
1215
  around { |example| recognize_as_heroku { example.run } }
1216
1216
 
@@ -103,6 +103,10 @@ module DependencyHelper
103
103
  Gem.loaded_specs["capistrano"].version >= Gem::Version.new("3.0")
104
104
  end
105
105
 
106
+ def http_present?
107
+ dependency_present? "http"
108
+ end
109
+
106
110
  def que_present?
107
111
  dependency_present? "que"
108
112
  end
@@ -12,7 +12,7 @@ module LogHelpers
12
12
  end
13
13
 
14
14
  def test_logger(log)
15
- Appsignal::Logger.new(log).tap do |logger|
15
+ Appsignal::Utils::IntegrationLogger.new(log).tap do |logger|
16
16
  logger.formatter = logger_formatter
17
17
  end
18
18
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: appsignal
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.5
4
+ version: 3.2.0
5
5
  platform: java
6
6
  authors:
7
7
  - Robert Beekman
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2022-10-18 00:00:00.000000000 Z
13
+ date: 2022-11-18 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rack
@@ -175,6 +175,7 @@ files:
175
175
  - gemfiles/capistrano2.gemfile
176
176
  - gemfiles/capistrano3.gemfile
177
177
  - gemfiles/grape.gemfile
178
+ - gemfiles/http5.gemfile
178
179
  - gemfiles/no_dependencies.gemfile
179
180
  - gemfiles/padrino.gemfile
180
181
  - gemfiles/psych-3.gemfile
@@ -230,6 +231,7 @@ files:
230
231
  - lib/appsignal/hooks/data_mapper.rb
231
232
  - lib/appsignal/hooks/delayed_job.rb
232
233
  - lib/appsignal/hooks/excon.rb
234
+ - lib/appsignal/hooks/http.rb
233
235
  - lib/appsignal/hooks/mongo_ruby_driver.rb
234
236
  - lib/appsignal/hooks/mri.rb
235
237
  - lib/appsignal/hooks/net_http.rb
@@ -252,6 +254,7 @@ files:
252
254
  - lib/appsignal/integrations/delayed_job_plugin.rb
253
255
  - lib/appsignal/integrations/excon.rb
254
256
  - lib/appsignal/integrations/grape.rb
257
+ - lib/appsignal/integrations/http.rb
255
258
  - lib/appsignal/integrations/mongo_ruby_driver.rb
256
259
  - lib/appsignal/integrations/net_http.rb
257
260
  - lib/appsignal/integrations/object.rb
@@ -284,6 +287,7 @@ files:
284
287
  - lib/appsignal/utils/data.rb
285
288
  - lib/appsignal/utils/deprecation_message.rb
286
289
  - lib/appsignal/utils/hash_sanitizer.rb
290
+ - lib/appsignal/utils/integration_logger.rb
287
291
  - lib/appsignal/utils/json.rb
288
292
  - lib/appsignal/utils/query_params_sanitizer.rb
289
293
  - lib/appsignal/utils/rails_helper.rb
@@ -331,6 +335,7 @@ files:
331
335
  - spec/lib/appsignal/hooks/data_mapper_spec.rb
332
336
  - spec/lib/appsignal/hooks/delayed_job_spec.rb
333
337
  - spec/lib/appsignal/hooks/excon_spec.rb
338
+ - spec/lib/appsignal/hooks/http_spec.rb
334
339
  - spec/lib/appsignal/hooks/mongo_ruby_driver_spec.rb
335
340
  - spec/lib/appsignal/hooks/mri_spec.rb
336
341
  - spec/lib/appsignal/hooks/net_http_spec.rb
@@ -348,6 +353,7 @@ files:
348
353
  - spec/lib/appsignal/hooks_spec.rb
349
354
  - spec/lib/appsignal/integrations/data_mapper_spec.rb
350
355
  - spec/lib/appsignal/integrations/grape_spec.rb
356
+ - spec/lib/appsignal/integrations/http_spec.rb
351
357
  - spec/lib/appsignal/integrations/mongo_ruby_driver_spec.rb
352
358
  - spec/lib/appsignal/integrations/object_spec.rb
353
359
  - spec/lib/appsignal/integrations/padrino_spec.rb
@@ -371,6 +377,7 @@ files:
371
377
  - spec/lib/appsignal/transmitter_spec.rb
372
378
  - spec/lib/appsignal/utils/data_spec.rb
373
379
  - spec/lib/appsignal/utils/hash_sanitizer_spec.rb
380
+ - spec/lib/appsignal/utils/integration_logger_spec.rb
374
381
  - spec/lib/appsignal/utils/json_spec.rb
375
382
  - spec/lib/appsignal/utils/query_params_sanitizer_spec.rb
376
383
  - spec/lib/appsignal_spec.rb
@@ -441,7 +448,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
441
448
  - !ruby/object:Gem::Version
442
449
  version: '0'
443
450
  requirements: []
444
- rubygems_version: 3.3.7
451
+ rubygems_version: 3.3.12
445
452
  signing_key:
446
453
  specification_version: 4
447
454
  summary: Logs performance and exception data from your app to appsignal.com
@@ -483,6 +490,7 @@ test_files:
483
490
  - spec/lib/appsignal/hooks/data_mapper_spec.rb
484
491
  - spec/lib/appsignal/hooks/delayed_job_spec.rb
485
492
  - spec/lib/appsignal/hooks/excon_spec.rb
493
+ - spec/lib/appsignal/hooks/http_spec.rb
486
494
  - spec/lib/appsignal/hooks/mongo_ruby_driver_spec.rb
487
495
  - spec/lib/appsignal/hooks/mri_spec.rb
488
496
  - spec/lib/appsignal/hooks/net_http_spec.rb
@@ -500,6 +508,7 @@ test_files:
500
508
  - spec/lib/appsignal/hooks_spec.rb
501
509
  - spec/lib/appsignal/integrations/data_mapper_spec.rb
502
510
  - spec/lib/appsignal/integrations/grape_spec.rb
511
+ - spec/lib/appsignal/integrations/http_spec.rb
503
512
  - spec/lib/appsignal/integrations/mongo_ruby_driver_spec.rb
504
513
  - spec/lib/appsignal/integrations/object_spec.rb
505
514
  - spec/lib/appsignal/integrations/padrino_spec.rb
@@ -523,6 +532,7 @@ test_files:
523
532
  - spec/lib/appsignal/transmitter_spec.rb
524
533
  - spec/lib/appsignal/utils/data_spec.rb
525
534
  - spec/lib/appsignal/utils/hash_sanitizer_spec.rb
535
+ - spec/lib/appsignal/utils/integration_logger_spec.rb
526
536
  - spec/lib/appsignal/utils/json_spec.rb
527
537
  - spec/lib/appsignal/utils/query_params_sanitizer_spec.rb
528
538
  - spec/lib/appsignal_spec.rb