appsignal 3.12.6-java → 4.0.0.beta.1-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.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yml +499 -487
- data/CHANGELOG.md +151 -0
- data/Rakefile +31 -7
- data/benchmark.rake +4 -6
- data/build_matrix.yml +45 -39
- data/ext/agent.rb +27 -27
- data/ext/appsignal_extension.c +25 -0
- data/gemfiles/rails-7.2.gemfile +11 -0
- data/lib/appsignal/check_in/cron.rb +67 -0
- data/lib/appsignal/check_in.rb +46 -0
- data/lib/appsignal/cli/diagnose.rb +37 -28
- data/lib/appsignal/cli/install.rb +5 -1
- data/lib/appsignal/config.rb +57 -119
- data/lib/appsignal/demo.rb +2 -2
- data/lib/appsignal/extension/jruby.rb +14 -0
- data/lib/appsignal/helpers/instrumentation.rb +139 -414
- data/lib/appsignal/helpers/metrics.rb +0 -16
- data/lib/appsignal/hooks/action_cable.rb +8 -8
- data/lib/appsignal/hooks/active_job.rb +2 -2
- data/lib/appsignal/hooks/at_exit.rb +37 -0
- data/lib/appsignal/hooks.rb +1 -16
- data/lib/appsignal/integrations/action_cable.rb +2 -2
- data/lib/appsignal/integrations/capistrano/appsignal.cap +2 -4
- data/lib/appsignal/integrations/capistrano/capistrano_2_tasks.rb +1 -4
- data/lib/appsignal/integrations/delayed_job_plugin.rb +3 -3
- data/lib/appsignal/integrations/http.rb +2 -7
- data/lib/appsignal/integrations/que.rb +2 -2
- data/lib/appsignal/integrations/railtie.rb +26 -59
- data/lib/appsignal/integrations/rake.rb +2 -2
- data/lib/appsignal/integrations/resque.rb +2 -2
- data/lib/appsignal/integrations/shoryuken.rb +4 -4
- data/lib/appsignal/integrations/sidekiq.rb +3 -3
- data/lib/appsignal/integrations/webmachine.rb +2 -2
- data/lib/appsignal/loaders.rb +1 -1
- data/lib/appsignal/probes.rb +0 -9
- data/lib/appsignal/rack/abstract_middleware.rb +4 -26
- data/lib/appsignal/rack/event_handler.rb +4 -4
- data/lib/appsignal/rack/rails_instrumentation.rb +1 -1
- data/lib/appsignal/rack.rb +0 -25
- data/lib/appsignal/sample_data.rb +95 -0
- data/lib/appsignal/transaction.rb +235 -361
- data/lib/appsignal/utils/rails_helper.rb +4 -0
- data/lib/appsignal/version.rb +1 -1
- data/lib/appsignal.rb +20 -62
- data/spec/lib/appsignal/auth_check_spec.rb +1 -1
- data/spec/lib/appsignal/capistrano2_spec.rb +1 -1
- data/spec/lib/appsignal/capistrano3_spec.rb +53 -13
- data/spec/lib/appsignal/{heartbeat_spec.rb → check_in_spec.rb} +45 -36
- data/spec/lib/appsignal/cli/demo_spec.rb +7 -27
- data/spec/lib/appsignal/cli/diagnose_spec.rb +145 -110
- data/spec/lib/appsignal/config_spec.rb +304 -379
- data/spec/lib/appsignal/extension_install_failure_spec.rb +5 -1
- data/spec/lib/appsignal/extension_spec.rb +5 -1
- data/spec/lib/appsignal/hooks/active_support_notifications/instrument_shared_examples.rb +1 -1
- data/spec/lib/appsignal/hooks/active_support_notifications/start_finish_shared_examples.rb +1 -2
- data/spec/lib/appsignal/hooks/active_support_notifications_spec.rb +1 -0
- data/spec/lib/appsignal/hooks/activejob_spec.rb +7 -12
- data/spec/lib/appsignal/hooks/at_exit_spec.rb +72 -0
- data/spec/lib/appsignal/hooks/gvl_spec.rb +10 -5
- data/spec/lib/appsignal/hooks/http_spec.rb +3 -3
- data/spec/lib/appsignal/hooks/net_http_spec.rb +3 -3
- data/spec/lib/appsignal/hooks/rake_spec.rb +6 -9
- data/spec/lib/appsignal/hooks/redis_client_spec.rb +5 -10
- data/spec/lib/appsignal/hooks/redis_spec.rb +4 -7
- data/spec/lib/appsignal/hooks/resque_spec.rb +3 -5
- data/spec/lib/appsignal/hooks_spec.rb +0 -41
- data/spec/lib/appsignal/integrations/data_mapper_spec.rb +29 -20
- data/spec/lib/appsignal/integrations/delayed_job_plugin_spec.rb +4 -9
- data/spec/lib/appsignal/integrations/http_spec.rb +0 -21
- data/spec/lib/appsignal/integrations/railtie_spec.rb +179 -157
- data/spec/lib/appsignal/integrations/shoryuken_spec.rb +3 -5
- data/spec/lib/appsignal/integrations/sidekiq_spec.rb +48 -62
- data/spec/lib/appsignal/loaders/hanami_spec.rb +6 -9
- data/spec/lib/appsignal/loaders/padrino_spec.rb +6 -10
- data/spec/lib/appsignal/loaders/sinatra_spec.rb +6 -9
- data/spec/lib/appsignal/loaders_spec.rb +8 -1
- data/spec/lib/appsignal/marker_spec.rb +1 -1
- data/spec/lib/appsignal/probes_spec.rb +4 -83
- data/spec/lib/appsignal/rack/abstract_middleware_spec.rb +4 -63
- data/spec/lib/appsignal/rack/event_handler_spec.rb +18 -15
- data/spec/lib/appsignal/rack/rails_instrumentation_spec.rb +3 -11
- data/spec/lib/appsignal/rack/sinatra_instrumentation_spec.rb +4 -5
- data/spec/lib/appsignal/sample_data_spec.rb +174 -0
- data/spec/lib/appsignal/transaction_spec.rb +791 -1031
- data/spec/lib/appsignal/transmitter_spec.rb +6 -8
- data/spec/lib/appsignal_spec.rb +294 -643
- data/spec/spec_helper.rb +1 -3
- data/spec/support/fixtures/projects/valid/config/appsignal.yml +4 -7
- data/spec/support/fixtures/projects/valid_with_rails_app/config/application.rb +16 -0
- data/spec/support/fixtures/projects/valid_with_rails_app/config/appsignal.yml +56 -0
- data/spec/support/fixtures/projects/valid_with_rails_app/config/environment.rb +5 -0
- data/spec/support/helpers/api_request_helper.rb +3 -2
- data/spec/support/helpers/config_helpers.rb +41 -11
- data/spec/support/helpers/dependency_helper.rb +8 -0
- data/spec/support/helpers/log_helpers.rb +1 -0
- data/spec/support/helpers/rails_helper.rb +6 -6
- data/spec/support/helpers/transaction_helpers.rb +2 -24
- data/spec/support/matchers/transaction.rb +3 -3
- data/spec/support/mocks/appsignal_mock.rb +3 -3
- data/spec/support/mocks/mock_probe.rb +2 -0
- data/spec/support/testing.rb +2 -2
- metadata +14 -23
- data/gemfiles/que_beta.gemfile +0 -5
- data/lib/appsignal/heartbeat.rb +0 -59
- data/lib/appsignal/helpers/heartbeats.rb +0 -44
- data/lib/appsignal/integrations/grape.rb +0 -35
- data/lib/appsignal/integrations/hanami.rb +0 -13
- data/lib/appsignal/integrations/padrino.rb +0 -13
- data/lib/appsignal/integrations/sinatra.rb +0 -13
- data/lib/appsignal/rack/generic_instrumentation.rb +0 -22
- data/lib/appsignal/rack/streaming_listener.rb +0 -28
- data/spec/lib/appsignal/integrations/grape_spec.rb +0 -36
- data/spec/lib/appsignal/integrations/hanami_spec.rb +0 -17
- data/spec/lib/appsignal/integrations/padrino_spec.rb +0 -15
- data/spec/lib/appsignal/integrations/sinatra_spec.rb +0 -15
- data/spec/lib/appsignal/rack/generic_instrumentation_spec.rb +0 -81
- data/spec/lib/appsignal/rack/streaming_listener_spec.rb +0 -69
- data/spec/support/fixtures/projects/valid/config/environments/development.rb +0 -0
- data/spec/support/fixtures/projects/valid/config/environments/production.rb +0 -0
- data/spec/support/fixtures/projects/valid/config/environments/test.rb +0 -0
- data/spec/support/rails/my_app.rb +0 -6
- /data/spec/support/fixtures/projects/{valid/config/application.rb → valid_with_rails_app/log/.gitkeep} +0 -0
@@ -15,6 +15,10 @@ module Appsignal
|
|
15
15
|
def self.application_config_path
|
16
16
|
File.expand_path(File.join(Dir.pwd, "config/application.rb"))
|
17
17
|
end
|
18
|
+
|
19
|
+
def self.environment_config_path
|
20
|
+
File.expand_path(File.join(Dir.pwd, "config/environment.rb"))
|
21
|
+
end
|
18
22
|
end
|
19
23
|
end
|
20
24
|
end
|
data/lib/appsignal/version.rb
CHANGED
data/lib/appsignal.rb
CHANGED
@@ -6,7 +6,6 @@ require "stringio"
|
|
6
6
|
|
7
7
|
require "appsignal/logger"
|
8
8
|
require "appsignal/utils/stdout_and_logger_message"
|
9
|
-
require "appsignal/helpers/heartbeats"
|
10
9
|
require "appsignal/helpers/instrumentation"
|
11
10
|
require "appsignal/helpers/metrics"
|
12
11
|
|
@@ -18,7 +17,6 @@ require "appsignal/helpers/metrics"
|
|
18
17
|
# {Appsignal::Helpers::Metrics}) for ease of use.
|
19
18
|
module Appsignal
|
20
19
|
class << self
|
21
|
-
include Helpers::Heartbeats
|
22
20
|
include Helpers::Instrumentation
|
23
21
|
include Helpers::Metrics
|
24
22
|
|
@@ -36,26 +34,6 @@ module Appsignal
|
|
36
34
|
# @see Config
|
37
35
|
attr_reader :config
|
38
36
|
|
39
|
-
# Set the AppSignal config.
|
40
|
-
#
|
41
|
-
# @deprecated Use {Appsignal.configure} instead.
|
42
|
-
# @param conf [Appsignal::Config]
|
43
|
-
# @return [void]
|
44
|
-
# @see Config
|
45
|
-
def config=(conf)
|
46
|
-
Appsignal::Utils::StdoutAndLoggerMessage.warning \
|
47
|
-
"Configuring AppSignal with `Appsignal.config=` is deprecated. " \
|
48
|
-
"Use `Appsignal.configure { |config| ... }` to configure AppSignal. " \
|
49
|
-
"https://docs.appsignal.com/ruby/configuration.html\n" \
|
50
|
-
"#{caller.first}"
|
51
|
-
@config = conf
|
52
|
-
end
|
53
|
-
|
54
|
-
# @api private
|
55
|
-
def _config=(conf)
|
56
|
-
@config = conf
|
57
|
-
end
|
58
|
-
|
59
37
|
# Accessor for toggle if the AppSignal C-extension is loaded.
|
60
38
|
#
|
61
39
|
# Can be `nil` if extension has not been loaded yet. See
|
@@ -113,7 +91,17 @@ module Appsignal
|
|
113
91
|
#
|
114
92
|
# @return [void]
|
115
93
|
# @since 0.7.0
|
116
|
-
def start
|
94
|
+
def start # rubocop:disable Metrics/AbcSize
|
95
|
+
if ENV.fetch("_APPSIGNAL_DIAGNOSE", false)
|
96
|
+
internal_logger.warn("Skipping start in diagnose context")
|
97
|
+
return
|
98
|
+
end
|
99
|
+
|
100
|
+
if started?
|
101
|
+
internal_logger.warn("Ignoring call to Appsignal.start after AppSignal has started")
|
102
|
+
return
|
103
|
+
end
|
104
|
+
|
117
105
|
unless extension_loaded?
|
118
106
|
internal_logger.info("Not starting AppSignal, extension is not loaded")
|
119
107
|
return
|
@@ -122,6 +110,7 @@ module Appsignal
|
|
122
110
|
internal_logger.debug("Loading AppSignal gem")
|
123
111
|
|
124
112
|
@config ||= Config.new(Config.determine_root_path, Config.determine_env)
|
113
|
+
@config.validate
|
125
114
|
|
126
115
|
_start_logger
|
127
116
|
|
@@ -143,6 +132,7 @@ module Appsignal
|
|
143
132
|
Appsignal::Probes.start if config[:enable_minutely_probes]
|
144
133
|
|
145
134
|
collect_environment_metadata
|
135
|
+
@config.freeze
|
146
136
|
else
|
147
137
|
internal_logger.info("Not starting, not active for #{config.env}")
|
148
138
|
end
|
@@ -251,20 +241,15 @@ module Appsignal
|
|
251
241
|
@config = Config.new(
|
252
242
|
root_path || Config.determine_root_path,
|
253
243
|
Config.determine_env(env),
|
254
|
-
|
255
|
-
Appsignal.internal_logger,
|
256
|
-
nil,
|
257
|
-
false
|
244
|
+
Appsignal.internal_logger
|
258
245
|
)
|
259
|
-
config.load_config
|
260
246
|
end
|
261
247
|
|
262
248
|
config_dsl = Appsignal::Config::ConfigDSL.new(config)
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
config.validate
|
249
|
+
return unless block_given?
|
250
|
+
|
251
|
+
yield config_dsl
|
252
|
+
config.merge_dsl_options(config_dsl.dsl_options)
|
268
253
|
end
|
269
254
|
|
270
255
|
def forked
|
@@ -334,18 +319,6 @@ module Appsignal
|
|
334
319
|
end
|
335
320
|
end
|
336
321
|
|
337
|
-
# @deprecated Only {.start} has to be called.
|
338
|
-
# @return [void]
|
339
|
-
# @since 0.7.0
|
340
|
-
def start_logger
|
341
|
-
callers = caller
|
342
|
-
Appsignal::Utils::StdoutAndLoggerMessage.warning \
|
343
|
-
"Calling 'Appsignal.start_logger' is deprecated. " \
|
344
|
-
"The logger will be started when calling 'Appsignal.start'. " \
|
345
|
-
"Remove the 'Appsignal.start_logger' call in the following file to " \
|
346
|
-
"remove this message.\n#{callers.first}"
|
347
|
-
end
|
348
|
-
|
349
322
|
# Start the AppSignal internal logger.
|
350
323
|
#
|
351
324
|
# Sets the log level and sets the logger. Uses a file-based logger or the
|
@@ -449,26 +422,11 @@ module Appsignal
|
|
449
422
|
end
|
450
423
|
Appsignal::Environment.report_supported_gems
|
451
424
|
end
|
452
|
-
|
453
|
-
# Alias constants that have moved with a warning message that points to the
|
454
|
-
# place to update the reference.
|
455
|
-
def const_missing(name)
|
456
|
-
case name
|
457
|
-
when :Minutely
|
458
|
-
callers = caller
|
459
|
-
Appsignal::Utils::StdoutAndLoggerMessage.warning \
|
460
|
-
"The constant Appsignal::Minutely has been deprecated. " \
|
461
|
-
"Please update the constant name to Appsignal::Probes " \
|
462
|
-
"in the following file to remove this message.\n#{callers.first}"
|
463
|
-
Appsignal::Probes
|
464
|
-
else
|
465
|
-
super
|
466
|
-
end
|
467
|
-
end
|
468
425
|
end
|
469
426
|
end
|
470
427
|
|
471
428
|
require "appsignal/loaders"
|
429
|
+
require "appsignal/sample_data"
|
472
430
|
require "appsignal/environment"
|
473
431
|
require "appsignal/system"
|
474
432
|
require "appsignal/utils"
|
@@ -489,4 +447,4 @@ require "appsignal/integrations/railtie" if defined?(::Rails)
|
|
489
447
|
require "appsignal/transaction"
|
490
448
|
require "appsignal/version"
|
491
449
|
require "appsignal/transmitter"
|
492
|
-
require "appsignal/
|
450
|
+
require "appsignal/check_in"
|
@@ -6,7 +6,7 @@ if DependencyHelper.capistrano2_present?
|
|
6
6
|
describe "Capistrano 2 integration" do
|
7
7
|
let(:out_stream) { std_stream }
|
8
8
|
let(:output) { out_stream.read }
|
9
|
-
let(:config) {
|
9
|
+
let(:config) { build_config }
|
10
10
|
let(:capistrano_config) do
|
11
11
|
Capistrano::Configuration.new.tap do |c|
|
12
12
|
c.set(:rails_env, "production")
|
@@ -5,7 +5,9 @@ if DependencyHelper.capistrano3_present?
|
|
5
5
|
|
6
6
|
describe "Capistrano 3 integration" do
|
7
7
|
let(:capistrano) { Class.new.extend(Capistrano::DSL) }
|
8
|
-
let(:
|
8
|
+
let(:env) { :production }
|
9
|
+
let(:options) { {} }
|
10
|
+
let(:config) { build_config(:env => env, :options => options) }
|
9
11
|
let(:out_stream) { std_stream }
|
10
12
|
let(:output) { out_stream.read }
|
11
13
|
let(:logger) { Logger.new(out_stream) }
|
@@ -50,7 +52,7 @@ if DependencyHelper.capistrano3_present?
|
|
50
52
|
end
|
51
53
|
|
52
54
|
context "config" do
|
53
|
-
let(:
|
55
|
+
let(:options) { { :name => "AppName" } }
|
54
56
|
before do
|
55
57
|
capistrano_config.set(
|
56
58
|
:appsignal_config,
|
@@ -58,9 +60,6 @@ if DependencyHelper.capistrano3_present?
|
|
58
60
|
:active => true,
|
59
61
|
:push_api_key => "abc"
|
60
62
|
)
|
61
|
-
config[:name] = "AppName"
|
62
|
-
config.instance_variable_set(:@env, env)
|
63
|
-
stub_marker_request.to_return(:status => 200)
|
64
63
|
end
|
65
64
|
|
66
65
|
context "when rack_env is the only env set" do
|
@@ -71,6 +70,11 @@ if DependencyHelper.capistrano3_present?
|
|
71
70
|
end
|
72
71
|
|
73
72
|
it "uses the rack_env as the env" do
|
73
|
+
stub_marker_request(
|
74
|
+
:environment => env.to_s,
|
75
|
+
:name => "AppName",
|
76
|
+
:push_api_key => "abc"
|
77
|
+
).to_return(:status => 200)
|
74
78
|
original_new = Appsignal::Marker.method(:new)
|
75
79
|
|
76
80
|
expect(Appsignal::Marker).to receive(:new) do |data, given_config|
|
@@ -90,6 +94,11 @@ if DependencyHelper.capistrano3_present?
|
|
90
94
|
end
|
91
95
|
|
92
96
|
it "prefers the Capistrano stage rather than rails_env and rack_env" do
|
97
|
+
stub_marker_request(
|
98
|
+
:environment => env.to_s,
|
99
|
+
:name => "AppName",
|
100
|
+
:push_api_key => "abc"
|
101
|
+
).to_return(:status => 200)
|
93
102
|
original_new = Appsignal::Marker.method(:new)
|
94
103
|
|
95
104
|
expect(Appsignal::Marker).to receive(:new) do |data, given_config|
|
@@ -104,15 +113,19 @@ if DependencyHelper.capistrano3_present?
|
|
104
113
|
context "when `appsignal_config` is set" do
|
105
114
|
before do
|
106
115
|
ENV["APPSIGNAL_APP_NAME"] = "EnvName"
|
107
|
-
capistrano_config.set(:appsignal_config, :name => "
|
108
|
-
config[:name] = "AppName"
|
116
|
+
capistrano_config.set(:appsignal_config, :name => "CapName")
|
109
117
|
end
|
110
118
|
|
111
119
|
it "overrides the default config with the custom appsignal_config" do
|
120
|
+
stub_marker_request(
|
121
|
+
:environment => env.to_s,
|
122
|
+
:name => "CapName",
|
123
|
+
:push_api_key => "abc"
|
124
|
+
).to_return(:status => 200)
|
112
125
|
original_new = Appsignal::Marker.method(:new)
|
113
126
|
|
114
127
|
expect(Appsignal::Marker).to receive(:new) do |data, given_config|
|
115
|
-
expect(given_config[:name]).to eq("
|
128
|
+
expect(given_config[:name]).to eq("CapName")
|
116
129
|
original_new.call(data, given_config)
|
117
130
|
end
|
118
131
|
|
@@ -141,6 +154,11 @@ if DependencyHelper.capistrano3_present?
|
|
141
154
|
end
|
142
155
|
|
143
156
|
it "prefers the appsignal_env rather than stage, rails_env and rack_env" do
|
157
|
+
stub_marker_request(
|
158
|
+
:environment => env.to_s,
|
159
|
+
:name => "AppName",
|
160
|
+
:push_api_key => "abc"
|
161
|
+
).to_return(:status => 200)
|
144
162
|
original_new = Appsignal::Marker.method(:new)
|
145
163
|
|
146
164
|
expect(Appsignal::Marker).to receive(:new) do |data, given_config|
|
@@ -156,7 +174,11 @@ if DependencyHelper.capistrano3_present?
|
|
156
174
|
describe "markers" do
|
157
175
|
context "when active for this environment" do
|
158
176
|
it "transmits marker" do
|
159
|
-
stub_marker_request
|
177
|
+
stub_marker_request(
|
178
|
+
:environment => env.to_s,
|
179
|
+
:name => "TestApp",
|
180
|
+
:push_api_key => "abc"
|
181
|
+
).to_return(:status => 200)
|
160
182
|
run
|
161
183
|
|
162
184
|
expect(output).to include \
|
@@ -168,7 +190,14 @@ if DependencyHelper.capistrano3_present?
|
|
168
190
|
context "with overridden revision" do
|
169
191
|
before do
|
170
192
|
capistrano_config.set(:appsignal_revision, "abc123")
|
171
|
-
stub_marker_request(
|
193
|
+
stub_marker_request(
|
194
|
+
{
|
195
|
+
:environment => env.to_s,
|
196
|
+
:name => "TestApp",
|
197
|
+
:push_api_key => "abc"
|
198
|
+
},
|
199
|
+
:revision => "abc123"
|
200
|
+
).to_return(:status => 200)
|
172
201
|
run
|
173
202
|
end
|
174
203
|
|
@@ -182,7 +211,14 @@ if DependencyHelper.capistrano3_present?
|
|
182
211
|
context "with overridden deploy user" do
|
183
212
|
before do
|
184
213
|
capistrano_config.set(:appsignal_user, "robin")
|
185
|
-
stub_marker_request(
|
214
|
+
stub_marker_request(
|
215
|
+
{
|
216
|
+
:environment => env.to_s,
|
217
|
+
:name => "TestApp",
|
218
|
+
:push_api_key => "abc"
|
219
|
+
},
|
220
|
+
:user => "robin"
|
221
|
+
).to_return(:status => 200)
|
186
222
|
run
|
187
223
|
end
|
188
224
|
|
@@ -209,7 +245,11 @@ if DependencyHelper.capistrano3_present?
|
|
209
245
|
|
210
246
|
context "with failed request" do
|
211
247
|
before do
|
212
|
-
stub_marker_request
|
248
|
+
stub_marker_request(
|
249
|
+
:environment => env.to_s,
|
250
|
+
:name => "TestApp",
|
251
|
+
:push_api_key => "abc"
|
252
|
+
).to_return(:status => 500)
|
213
253
|
run
|
214
254
|
end
|
215
255
|
|
@@ -238,7 +278,7 @@ if DependencyHelper.capistrano3_present?
|
|
238
278
|
end
|
239
279
|
end
|
240
280
|
|
241
|
-
def stub_marker_request(data = {})
|
281
|
+
def stub_marker_request(config = {}, data = {})
|
242
282
|
stub_api_request config, "markers", marker_data.merge(data)
|
243
283
|
end
|
244
284
|
end
|
@@ -1,12 +1,12 @@
|
|
1
|
-
describe Appsignal::
|
1
|
+
describe Appsignal::CheckIn::Cron do
|
2
2
|
let(:config) { project_fixture_config }
|
3
|
-
let(:
|
4
|
-
let(:transmitter) { Appsignal::Transmitter.new("http://
|
3
|
+
let(:cron_checkin) { described_class.new(:identifier => "cron-checkin-name") }
|
4
|
+
let(:transmitter) { Appsignal::Transmitter.new("http://cron_checkins/", config) }
|
5
5
|
|
6
6
|
before(:each) do
|
7
7
|
allow(Appsignal).to receive(:active?).and_return(true)
|
8
8
|
config.logger = Logger.new(StringIO.new)
|
9
|
-
allow(Appsignal::
|
9
|
+
allow(Appsignal::CheckIn::Cron).to receive(:transmitter).and_return(transmitter)
|
10
10
|
end
|
11
11
|
|
12
12
|
describe "when Appsignal is not active" do
|
@@ -14,113 +14,122 @@ describe Appsignal::Heartbeat do
|
|
14
14
|
allow(Appsignal).to receive(:active?).and_return(false)
|
15
15
|
expect(transmitter).not_to receive(:transmit)
|
16
16
|
|
17
|
-
|
18
|
-
|
17
|
+
cron_checkin.start
|
18
|
+
cron_checkin.finish
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
22
22
|
describe "#start" do
|
23
|
-
it "should send a
|
23
|
+
it "should send a cron check-in start" do
|
24
24
|
expect(transmitter).to receive(:transmit).with(hash_including(
|
25
|
-
:
|
26
|
-
:kind => "start"
|
25
|
+
:identifier => "cron-checkin-name",
|
26
|
+
:kind => "start",
|
27
|
+
:check_in_type => "cron"
|
27
28
|
)).and_return(Net::HTTPResponse.new(nil, "200", nil))
|
28
29
|
|
29
30
|
expect(Appsignal.internal_logger).to receive(:debug).with(
|
30
|
-
"Transmitted
|
31
|
+
"Transmitted cron check-in `cron-checkin-name` (#{cron_checkin.digest}) start event"
|
31
32
|
)
|
32
33
|
expect(Appsignal.internal_logger).not_to receive(:error)
|
33
34
|
|
34
|
-
|
35
|
+
cron_checkin.start
|
35
36
|
end
|
36
37
|
|
37
38
|
it "should log an error if it fails" do
|
38
39
|
expect(transmitter).to receive(:transmit).with(hash_including(
|
39
|
-
:
|
40
|
-
:kind => "start"
|
40
|
+
:identifier => "cron-checkin-name",
|
41
|
+
:kind => "start",
|
42
|
+
:check_in_type => "cron"
|
41
43
|
)).and_return(Net::HTTPResponse.new(nil, "499", nil))
|
42
44
|
|
43
45
|
expect(Appsignal.internal_logger).not_to receive(:debug)
|
44
46
|
expect(Appsignal.internal_logger).to receive(:error).with(
|
45
|
-
"Failed to transmit
|
47
|
+
"Failed to transmit cron check-in start event: status code was 499"
|
46
48
|
)
|
47
49
|
|
48
|
-
|
50
|
+
cron_checkin.start
|
49
51
|
end
|
50
52
|
end
|
51
53
|
|
52
54
|
describe "#finish" do
|
53
|
-
it "should send a
|
55
|
+
it "should send a cron check-in finish" do
|
54
56
|
expect(transmitter).to receive(:transmit).with(hash_including(
|
55
|
-
:
|
56
|
-
:kind => "finish"
|
57
|
+
:identifier => "cron-checkin-name",
|
58
|
+
:kind => "finish",
|
59
|
+
:check_in_type => "cron"
|
57
60
|
)).and_return(Net::HTTPResponse.new(nil, "200", nil))
|
58
61
|
|
59
62
|
expect(Appsignal.internal_logger).to receive(:debug).with(
|
60
|
-
"Transmitted
|
63
|
+
"Transmitted cron check-in `cron-checkin-name` (#{cron_checkin.digest}) finish event"
|
61
64
|
)
|
62
65
|
expect(Appsignal.internal_logger).not_to receive(:error)
|
63
66
|
|
64
|
-
|
67
|
+
cron_checkin.finish
|
65
68
|
end
|
66
69
|
|
67
70
|
it "should log an error if it fails" do
|
68
71
|
expect(transmitter).to receive(:transmit).with(hash_including(
|
69
|
-
:
|
70
|
-
:kind => "finish"
|
72
|
+
:identifier => "cron-checkin-name",
|
73
|
+
:kind => "finish",
|
74
|
+
:check_in_type => "cron"
|
71
75
|
)).and_return(Net::HTTPResponse.new(nil, "499", nil))
|
72
76
|
|
73
77
|
expect(Appsignal.internal_logger).not_to receive(:debug)
|
74
78
|
expect(Appsignal.internal_logger).to receive(:error).with(
|
75
|
-
"Failed to transmit
|
79
|
+
"Failed to transmit cron check-in finish event: status code was 499"
|
76
80
|
)
|
77
81
|
|
78
|
-
|
82
|
+
cron_checkin.finish
|
79
83
|
end
|
80
84
|
end
|
81
85
|
|
82
|
-
describe ".
|
86
|
+
describe ".cron" do
|
83
87
|
describe "when a block is given" do
|
84
|
-
it "should send a
|
88
|
+
it "should send a cron check-in start and finish and return the block output" do
|
85
89
|
expect(transmitter).to receive(:transmit).with(hash_including(
|
86
90
|
:kind => "start",
|
87
|
-
:
|
91
|
+
:identifier => "cron-checkin-with-block",
|
92
|
+
:check_in_type => "cron"
|
88
93
|
)).and_return(nil)
|
89
94
|
|
90
95
|
expect(transmitter).to receive(:transmit).with(hash_including(
|
91
96
|
:kind => "finish",
|
92
|
-
:
|
97
|
+
:identifier => "cron-checkin-with-block",
|
98
|
+
:check_in_type => "cron"
|
93
99
|
)).and_return(nil)
|
94
100
|
|
95
|
-
output = Appsignal.
|
101
|
+
output = Appsignal::CheckIn.cron("cron-checkin-with-block") { "output" }
|
96
102
|
expect(output).to eq("output")
|
97
103
|
end
|
98
104
|
|
99
|
-
it "should not send a
|
105
|
+
it "should not send a cron check-in finish event when an error is raised" do
|
100
106
|
expect(transmitter).to receive(:transmit).with(hash_including(
|
101
107
|
:kind => "start",
|
102
|
-
:
|
108
|
+
:identifier => "cron-checkin-with-block",
|
109
|
+
:check_in_type => "cron"
|
103
110
|
)).and_return(nil)
|
104
111
|
|
105
112
|
expect(transmitter).not_to receive(:transmit).with(hash_including(
|
106
113
|
:kind => "finish",
|
107
|
-
:
|
114
|
+
:identifier => "cron-checkin-with-block",
|
115
|
+
:check_in_type => "cron"
|
108
116
|
))
|
109
117
|
|
110
118
|
expect do
|
111
|
-
Appsignal.
|
119
|
+
Appsignal::CheckIn.cron("cron-checkin-with-block") { raise "error" }
|
112
120
|
end.to raise_error(RuntimeError, "error")
|
113
121
|
end
|
114
122
|
end
|
115
123
|
|
116
124
|
describe "when no block is given" do
|
117
|
-
it "should only send a
|
125
|
+
it "should only send a cron check-in finish event" do
|
118
126
|
expect(transmitter).to receive(:transmit).with(hash_including(
|
119
127
|
:kind => "finish",
|
120
|
-
:
|
128
|
+
:identifier => "cron-checkin-without-block",
|
129
|
+
:check_in_type => "cron"
|
121
130
|
)).and_return(nil)
|
122
131
|
|
123
|
-
Appsignal.
|
132
|
+
Appsignal::CheckIn.cron("cron-checkin-without-block")
|
124
133
|
end
|
125
134
|
end
|
126
135
|
end
|
@@ -7,12 +7,6 @@ describe Appsignal::CLI::Demo do
|
|
7
7
|
let(:out_stream) { std_stream }
|
8
8
|
let(:output) { out_stream.read }
|
9
9
|
before(:context) { Appsignal.stop }
|
10
|
-
before do
|
11
|
-
ENV.delete("APPSIGNAL_APP_ENV")
|
12
|
-
ENV.delete("RAILS_ENV")
|
13
|
-
ENV.delete("RACK_ENV")
|
14
|
-
stub_api_request config, "auth"
|
15
|
-
end
|
16
10
|
|
17
11
|
def run
|
18
12
|
run_within_dir project_fixture_path
|
@@ -25,8 +19,6 @@ describe Appsignal::CLI::Demo do
|
|
25
19
|
end
|
26
20
|
|
27
21
|
context "without configuration" do
|
28
|
-
let(:config) { Appsignal::Config.new("development", tmp_dir) }
|
29
|
-
|
30
22
|
it "returns an error" do
|
31
23
|
expect { run_within_dir tmp_dir }.to raise_error(SystemExit)
|
32
24
|
|
@@ -35,32 +27,20 @@ describe Appsignal::CLI::Demo do
|
|
35
27
|
end
|
36
28
|
|
37
29
|
context "with configuration" do
|
38
|
-
let(:config) { project_fixture_config }
|
39
30
|
before do
|
40
31
|
# Ignore sleeps to speed up the test
|
41
32
|
allow(Appsignal::Demo).to receive(:sleep)
|
42
33
|
end
|
34
|
+
let(:options) { { :environment => "development" } }
|
43
35
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
expect(output).to include("Error: Unable to start the AppSignal agent")
|
49
|
-
end
|
36
|
+
it "calls Appsignal::Demo transmitter" do
|
37
|
+
expect(Appsignal::Demo).to receive(:transmit).and_return(true)
|
38
|
+
run
|
50
39
|
end
|
51
40
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
it "calls Appsignal::Demo transmitter" do
|
56
|
-
expect(Appsignal::Demo).to receive(:transmit).and_return(true)
|
57
|
-
run
|
58
|
-
end
|
59
|
-
|
60
|
-
it "outputs message" do
|
61
|
-
run
|
62
|
-
expect(output).to include("Demonstration sample data sent!")
|
63
|
-
end
|
41
|
+
it "outputs message" do
|
42
|
+
run
|
43
|
+
expect(output).to include("Demonstration sample data sent!")
|
64
44
|
end
|
65
45
|
end
|
66
46
|
end
|