appsignal 4.0.5 → 4.0.7
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/CHANGELOG.md +20 -0
- data/Rakefile +9 -9
- data/appsignal.gemspec +22 -1
- data/build_matrix.yml +2 -1
- data/ext/agent.rb +27 -27
- data/lib/appsignal/check_in/scheduler.rb +3 -4
- data/lib/appsignal/check_in.rb +1 -1
- data/lib/appsignal/config.rb +1 -3
- data/lib/appsignal/integrations/que.rb +8 -2
- data/lib/appsignal/integrations/resque.rb +1 -6
- data/lib/appsignal/utils/hash_sanitizer.rb +4 -0
- data/lib/appsignal/version.rb +1 -1
- metadata +2 -191
- data/.github/ISSUE_TEMPLATE/bug_report.md +0 -31
- data/.github/ISSUE_TEMPLATE/chore.md +0 -14
- data/.github/workflows/ci.yml +0 -3150
- data/.github/workflows/create_release_from_tag.yml +0 -62
- data/.gitignore +0 -35
- data/.gitmodules +0 -3
- data/.rspec +0 -4
- data/.yardopts +0 -8
- data/benchmark.rake +0 -139
- data/gemfiles/capistrano2.gemfile +0 -6
- data/gemfiles/capistrano3.gemfile +0 -7
- data/gemfiles/dry-monitor.gemfile +0 -5
- data/gemfiles/grape.gemfile +0 -5
- data/gemfiles/hanami-2.0.gemfile +0 -7
- data/gemfiles/hanami-2.1.gemfile +0 -7
- data/gemfiles/http5.gemfile +0 -5
- data/gemfiles/no_dependencies.gemfile +0 -10
- data/gemfiles/padrino.gemfile +0 -7
- data/gemfiles/psych-3.gemfile +0 -5
- data/gemfiles/psych-4.gemfile +0 -5
- data/gemfiles/que.gemfile +0 -5
- data/gemfiles/rails-6.0.gemfile +0 -10
- data/gemfiles/rails-6.1.gemfile +0 -11
- data/gemfiles/rails-7.0.gemfile +0 -11
- data/gemfiles/rails-7.1.gemfile +0 -11
- data/gemfiles/rails-7.2.gemfile +0 -11
- data/gemfiles/redis-4.gemfile +0 -5
- data/gemfiles/redis-5.gemfile +0 -6
- data/gemfiles/resque-2.gemfile +0 -6
- data/gemfiles/sequel.gemfile +0 -10
- data/gemfiles/sinatra.gemfile +0 -5
- data/gemfiles/webmachine1.gemfile +0 -7
- data/gemfiles/webmachine2.gemfile +0 -6
- data/mono.yml +0 -16
- data/spec/.rubocop.yml +0 -7
- data/spec/lib/appsignal/auth_check_spec.rb +0 -84
- data/spec/lib/appsignal/capistrano2_spec.rb +0 -227
- data/spec/lib/appsignal/capistrano3_spec.rb +0 -284
- data/spec/lib/appsignal/check_in/cron_spec.rb +0 -202
- data/spec/lib/appsignal/check_in/scheduler_spec.rb +0 -443
- data/spec/lib/appsignal/cli/demo_spec.rb +0 -46
- data/spec/lib/appsignal/cli/diagnose/paths_spec.rb +0 -16
- data/spec/lib/appsignal/cli/diagnose/utils_spec.rb +0 -86
- data/spec/lib/appsignal/cli/diagnose_spec.rb +0 -1553
- data/spec/lib/appsignal/cli/helpers_spec.rb +0 -179
- data/spec/lib/appsignal/cli/install_spec.rb +0 -848
- data/spec/lib/appsignal/cli_spec.rb +0 -56
- data/spec/lib/appsignal/config_spec.rb +0 -1380
- data/spec/lib/appsignal/demo_spec.rb +0 -83
- data/spec/lib/appsignal/environment_spec.rb +0 -190
- data/spec/lib/appsignal/event_formatter/action_view/render_formatter_spec.rb +0 -60
- data/spec/lib/appsignal/event_formatter/active_record/instantiation_formatter_spec.rb +0 -21
- data/spec/lib/appsignal/event_formatter/active_record/sql_formatter_spec.rb +0 -21
- data/spec/lib/appsignal/event_formatter/elastic_search/search_formatter_spec.rb +0 -52
- data/spec/lib/appsignal/event_formatter/faraday/request_formatter_spec.rb +0 -21
- data/spec/lib/appsignal/event_formatter/mongo_ruby_driver/query_formatter_spec.rb +0 -84
- data/spec/lib/appsignal/event_formatter/rom/sql_formatter_spec.rb +0 -22
- data/spec/lib/appsignal/event_formatter/sequel/sql_formatter_spec.rb +0 -30
- data/spec/lib/appsignal/event_formatter/view_component/render_formatter_spec.rb +0 -41
- data/spec/lib/appsignal/event_formatter_spec.rb +0 -193
- data/spec/lib/appsignal/extension/jruby_spec.rb +0 -46
- data/spec/lib/appsignal/extension_install_failure_spec.rb +0 -20
- data/spec/lib/appsignal/extension_spec.rb +0 -178
- data/spec/lib/appsignal/garbage_collection_spec.rb +0 -98
- data/spec/lib/appsignal/hooks/action_cable_spec.rb +0 -345
- data/spec/lib/appsignal/hooks/action_mailer_spec.rb +0 -55
- data/spec/lib/appsignal/hooks/active_support_notifications/finish_with_state_shared_examples.rb +0 -23
- data/spec/lib/appsignal/hooks/active_support_notifications/instrument_shared_examples.rb +0 -99
- data/spec/lib/appsignal/hooks/active_support_notifications/start_finish_shared_examples.rb +0 -47
- data/spec/lib/appsignal/hooks/active_support_notifications_spec.rb +0 -47
- data/spec/lib/appsignal/hooks/activejob_spec.rb +0 -650
- data/spec/lib/appsignal/hooks/at_exit_spec.rb +0 -105
- data/spec/lib/appsignal/hooks/celluloid_spec.rb +0 -40
- data/spec/lib/appsignal/hooks/data_mapper_spec.rb +0 -40
- data/spec/lib/appsignal/hooks/delayed_job_spec.rb +0 -38
- data/spec/lib/appsignal/hooks/dry_monitor_spec.rb +0 -83
- data/spec/lib/appsignal/hooks/excon_spec.rb +0 -67
- data/spec/lib/appsignal/hooks/gvl_spec.rb +0 -145
- data/spec/lib/appsignal/hooks/http_spec.rb +0 -37
- data/spec/lib/appsignal/hooks/mongo_ruby_driver_spec.rb +0 -46
- data/spec/lib/appsignal/hooks/mri_spec.rb +0 -23
- data/spec/lib/appsignal/hooks/net_http_spec.rb +0 -18
- data/spec/lib/appsignal/hooks/passenger_spec.rb +0 -30
- data/spec/lib/appsignal/hooks/puma_spec.rb +0 -80
- data/spec/lib/appsignal/hooks/que_spec.rb +0 -19
- data/spec/lib/appsignal/hooks/rake_spec.rb +0 -144
- data/spec/lib/appsignal/hooks/redis_client_spec.rb +0 -218
- data/spec/lib/appsignal/hooks/redis_spec.rb +0 -124
- data/spec/lib/appsignal/hooks/resque_spec.rb +0 -27
- data/spec/lib/appsignal/hooks/sequel_spec.rb +0 -44
- data/spec/lib/appsignal/hooks/shoryuken_spec.rb +0 -29
- data/spec/lib/appsignal/hooks/sidekiq_spec.rb +0 -115
- data/spec/lib/appsignal/hooks/unicorn_spec.rb +0 -63
- data/spec/lib/appsignal/hooks/webmachine_spec.rb +0 -24
- data/spec/lib/appsignal/hooks_spec.rb +0 -124
- data/spec/lib/appsignal/integrations/data_mapper_spec.rb +0 -74
- data/spec/lib/appsignal/integrations/delayed_job_plugin_spec.rb +0 -454
- data/spec/lib/appsignal/integrations/http_spec.rb +0 -111
- data/spec/lib/appsignal/integrations/mongo_ruby_driver_spec.rb +0 -154
- data/spec/lib/appsignal/integrations/net_http_spec.rb +0 -33
- data/spec/lib/appsignal/integrations/object_spec.rb +0 -347
- data/spec/lib/appsignal/integrations/puma_spec.rb +0 -150
- data/spec/lib/appsignal/integrations/que_spec.rb +0 -152
- data/spec/lib/appsignal/integrations/railtie_spec.rb +0 -457
- data/spec/lib/appsignal/integrations/resque_spec.rb +0 -155
- data/spec/lib/appsignal/integrations/shoryuken_spec.rb +0 -165
- data/spec/lib/appsignal/integrations/sidekiq_spec.rb +0 -640
- data/spec/lib/appsignal/integrations/webmachine_spec.rb +0 -136
- data/spec/lib/appsignal/loaders/grape_spec.rb +0 -12
- data/spec/lib/appsignal/loaders/hanami_spec.rb +0 -92
- data/spec/lib/appsignal/loaders/padrino_spec.rb +0 -273
- data/spec/lib/appsignal/loaders/sinatra_spec.rb +0 -44
- data/spec/lib/appsignal/loaders_spec.rb +0 -144
- data/spec/lib/appsignal/logger_spec.rb +0 -205
- data/spec/lib/appsignal/marker_spec.rb +0 -51
- data/spec/lib/appsignal/probes/gvl_spec.rb +0 -164
- data/spec/lib/appsignal/probes/mri_spec.rb +0 -162
- data/spec/lib/appsignal/probes/sidekiq_spec.rb +0 -333
- data/spec/lib/appsignal/probes_spec.rb +0 -411
- data/spec/lib/appsignal/rack/abstract_middleware_spec.rb +0 -370
- data/spec/lib/appsignal/rack/body_wrapper_spec.rb +0 -319
- data/spec/lib/appsignal/rack/event_handler_spec.rb +0 -441
- data/spec/lib/appsignal/rack/grape_middleware_spec.rb +0 -201
- data/spec/lib/appsignal/rack/hanami_middleware_spec.rb +0 -36
- data/spec/lib/appsignal/rack/instrumentation_middleware_spec.rb +0 -38
- data/spec/lib/appsignal/rack/rails_instrumentation_spec.rb +0 -126
- data/spec/lib/appsignal/rack/sinatra_instrumentation_spec.rb +0 -217
- data/spec/lib/appsignal/rack_spec.rb +0 -243
- data/spec/lib/appsignal/sample_data_spec.rb +0 -238
- data/spec/lib/appsignal/span_spec.rb +0 -141
- data/spec/lib/appsignal/system_spec.rb +0 -126
- data/spec/lib/appsignal/transaction_spec.rb +0 -2111
- data/spec/lib/appsignal/transmitter_spec.rb +0 -198
- data/spec/lib/appsignal/utils/data_spec.rb +0 -166
- data/spec/lib/appsignal/utils/hash_sanitizer_spec.rb +0 -182
- data/spec/lib/appsignal/utils/integration_logger_spec.rb +0 -21
- data/spec/lib/appsignal/utils/integration_memory_logger_spec.rb +0 -153
- data/spec/lib/appsignal/utils/json_spec.rb +0 -44
- data/spec/lib/appsignal/utils/query_params_sanitizer_spec.rb +0 -192
- data/spec/lib/appsignal_spec.rb +0 -1919
- data/spec/lib/puma/appsignal_spec.rb +0 -334
- data/spec/spec_helper.rb +0 -173
- data/spec/support/fixtures/generated_config.yml +0 -24
- data/spec/support/fixtures/projects/broken/config/appsignal.yml +0 -1
- data/spec/support/fixtures/projects/valid/config/appsignal.yml +0 -57
- data/spec/support/fixtures/projects/valid/log/.gitkeep +0 -0
- data/spec/support/fixtures/projects/valid_with_rails_app/config/application.rb +0 -16
- data/spec/support/fixtures/projects/valid_with_rails_app/config/appsignal.yml +0 -56
- data/spec/support/fixtures/projects/valid_with_rails_app/config/environment.rb +0 -10
- data/spec/support/fixtures/projects/valid_with_rails_app/log/.gitkeep +0 -0
- data/spec/support/fixtures/uploaded_file.txt +0 -0
- data/spec/support/hanami/hanami_app.rb +0 -29
- data/spec/support/helpers/action_mailer_helpers.rb +0 -25
- data/spec/support/helpers/activejob_helpers.rb +0 -27
- data/spec/support/helpers/api_request_helper.rb +0 -20
- data/spec/support/helpers/cli_helpers.rb +0 -40
- data/spec/support/helpers/config_helpers.rb +0 -66
- data/spec/support/helpers/dependency_helper.rb +0 -150
- data/spec/support/helpers/directory_helper.rb +0 -27
- data/spec/support/helpers/env_helpers.rb +0 -41
- data/spec/support/helpers/environment_metdata_helper.rb +0 -16
- data/spec/support/helpers/example_exception.rb +0 -13
- data/spec/support/helpers/example_standard_error.rb +0 -13
- data/spec/support/helpers/loader_helper.rb +0 -21
- data/spec/support/helpers/log_helpers.rb +0 -36
- data/spec/support/helpers/rails_helper.rb +0 -28
- data/spec/support/helpers/std_streams_helper.rb +0 -94
- data/spec/support/helpers/system_helpers.rb +0 -8
- data/spec/support/helpers/take_at_most_helper.rb +0 -21
- data/spec/support/helpers/time_helpers.rb +0 -11
- data/spec/support/helpers/transaction_helpers.rb +0 -122
- data/spec/support/helpers/wait_for_helper.rb +0 -39
- data/spec/support/matchers/contains_log.rb +0 -26
- data/spec/support/matchers/have_colorized_text.rb +0 -28
- data/spec/support/matchers/transaction.rb +0 -200
- data/spec/support/mocks/appsignal_mock.rb +0 -18
- data/spec/support/mocks/dummy_app.rb +0 -20
- data/spec/support/mocks/fake_gc_profiler.rb +0 -19
- data/spec/support/mocks/fake_gvl_tools.rb +0 -28
- data/spec/support/mocks/hash_like.rb +0 -10
- data/spec/support/mocks/mock_probe.rb +0 -13
- data/spec/support/mocks/puma_mock.rb +0 -43
- data/spec/support/shared_examples/instrument.rb +0 -48
- data/spec/support/stubs/appsignal/loaders/loader_stub.rb +0 -7
- data/spec/support/stubs/delayed_job.rb +0 -0
- data/spec/support/stubs/sidekiq/api.rb +0 -4
- data/spec/support/testing.rb +0 -194
- data/support/bundler_wrapper +0 -12
- data/support/install_deps +0 -33
@@ -1,411 +0,0 @@
|
|
1
|
-
describe Appsignal::Probes do
|
2
|
-
include WaitForHelper
|
3
|
-
|
4
|
-
before { Appsignal::Probes.probes.clear }
|
5
|
-
|
6
|
-
it "returns a ProbeCollection" do
|
7
|
-
expect(Appsignal::Probes.probes)
|
8
|
-
.to be_instance_of(Appsignal::Probes::ProbeCollection)
|
9
|
-
end
|
10
|
-
|
11
|
-
describe ".start" do
|
12
|
-
class ProbeWithoutDependency < MockProbe
|
13
|
-
def self.dependencies_present?
|
14
|
-
true
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
class ProbeWithMissingDependency < MockProbe
|
19
|
-
def self.dependencies_present?
|
20
|
-
false
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
class BrokenProbe < MockProbe
|
25
|
-
def call
|
26
|
-
super
|
27
|
-
raise "oh no!"
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
class BrokenProbeOnInitialize < MockProbe
|
32
|
-
def initialize
|
33
|
-
super
|
34
|
-
raise "oh no initialize!"
|
35
|
-
end
|
36
|
-
|
37
|
-
def call
|
38
|
-
true
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
let(:log_stream) { StringIO.new }
|
43
|
-
let(:log) { log_contents(log_stream) }
|
44
|
-
before do
|
45
|
-
Appsignal.internal_logger = test_logger(log_stream)
|
46
|
-
speed_up_tests!
|
47
|
-
end
|
48
|
-
|
49
|
-
describe ".started?" do
|
50
|
-
it "returns true when the probes thread has been started" do
|
51
|
-
expect(Appsignal::Probes.started?).to be_falsy
|
52
|
-
Appsignal::Probes.register :my_probe, lambda {}
|
53
|
-
Appsignal::Probes.start
|
54
|
-
expect(Appsignal::Probes.started?).to be_truthy
|
55
|
-
end
|
56
|
-
|
57
|
-
it "returns false when the probes thread has been stopped" do
|
58
|
-
Appsignal::Probes.register :my_probe, lambda {}
|
59
|
-
Appsignal::Probes.start
|
60
|
-
expect(Appsignal::Probes.started?).to be_truthy
|
61
|
-
Appsignal::Probes.stop
|
62
|
-
expect(Appsignal::Probes.started?).to be_falsy
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
context "with an instance of a class" do
|
67
|
-
it "calls the probe every <wait_time>" do
|
68
|
-
probe = MockProbe.new
|
69
|
-
Appsignal::Probes.register :my_probe, probe
|
70
|
-
Appsignal::Probes.start
|
71
|
-
|
72
|
-
wait_for("enough probe calls") { probe.calls >= 2 }
|
73
|
-
expect(log).to contains_log(:debug, "Gathering minutely metrics with 1 probe")
|
74
|
-
expect(log).to contains_log(:debug, "Gathering minutely metrics with 'my_probe' probe")
|
75
|
-
end
|
76
|
-
|
77
|
-
context "when dependency requirement is not met" do
|
78
|
-
it "does not initialize the probe" do
|
79
|
-
# Working probe which we can use to wait for X ticks
|
80
|
-
working_probe = ProbeWithoutDependency.new
|
81
|
-
Appsignal::Probes.register :probe_without_dep, working_probe
|
82
|
-
|
83
|
-
probe = ProbeWithMissingDependency.new
|
84
|
-
Appsignal::Probes.register :probe_with_missing_dep, probe
|
85
|
-
Appsignal::Probes.start
|
86
|
-
|
87
|
-
wait_for("enough probe calls") { working_probe.calls >= 2 }
|
88
|
-
# Only counts initialized probes
|
89
|
-
expect(log).to contains_log(:debug, "Gathering minutely metrics with 1 probe")
|
90
|
-
expect(log).to contains_log :debug, "Skipping 'probe_with_missing_dep' probe, " \
|
91
|
-
"ProbeWithMissingDependency.dependency_present? returned falsy"
|
92
|
-
end
|
93
|
-
end
|
94
|
-
end
|
95
|
-
|
96
|
-
context "with probe class" do
|
97
|
-
it "creates an instance of the class and call that every <wait time>" do
|
98
|
-
probe = MockProbe
|
99
|
-
Appsignal::Probes.register :my_probe, probe
|
100
|
-
Appsignal::Probes.start
|
101
|
-
|
102
|
-
wait_for("enough probe calls") { Appsignal::Testing.store[:mock_probe_call] >= 2 }
|
103
|
-
expect(log).to contains_log(:debug, "Gathering minutely metrics with 1 probe")
|
104
|
-
expect(log).to contains_log(:debug, "Gathering minutely metrics with 'my_probe' probe")
|
105
|
-
end
|
106
|
-
|
107
|
-
context "when dependency requirement is not met" do
|
108
|
-
it "does not initialize the probe" do
|
109
|
-
# Working probe which we can use to wait for X ticks
|
110
|
-
working_probe = ProbeWithoutDependency
|
111
|
-
Appsignal::Probes.register :probe_without_dep, working_probe
|
112
|
-
|
113
|
-
probe = ProbeWithMissingDependency
|
114
|
-
Appsignal::Probes.register :probe_with_missing_dep, probe
|
115
|
-
Appsignal::Probes.start
|
116
|
-
|
117
|
-
wait_for("enough probe calls") { Appsignal::Testing.store[:mock_probe_call] >= 2 }
|
118
|
-
# Only counts initialized probes
|
119
|
-
expect(log).to contains_log(:debug, "Gathering minutely metrics with 1 probe")
|
120
|
-
expect(log).to contains_log :debug, "Skipping 'probe_with_missing_dep' probe, " \
|
121
|
-
"ProbeWithMissingDependency.dependency_present? returned falsy"
|
122
|
-
end
|
123
|
-
end
|
124
|
-
|
125
|
-
context "when there is a problem initializing the probe" do
|
126
|
-
it "logs an error" do
|
127
|
-
# Working probe which we can use to wait for X ticks
|
128
|
-
working_probe = ProbeWithoutDependency
|
129
|
-
Appsignal::Probes.register :probe_without_dep, working_probe
|
130
|
-
|
131
|
-
probe = BrokenProbeOnInitialize
|
132
|
-
Appsignal::Probes.register :broken_probe_on_initialize, probe
|
133
|
-
Appsignal::Probes.start
|
134
|
-
|
135
|
-
wait_for("enough probe calls") { Appsignal::Testing.store[:mock_probe_call] >= 2 }
|
136
|
-
# Only counts initialized probes
|
137
|
-
expect(log).to contains_log(:debug, "Gathering minutely metrics with 1 probe")
|
138
|
-
# Logs error
|
139
|
-
expect(log).to contains_log(
|
140
|
-
:error,
|
141
|
-
"Error while initializing minutely probe 'broken_probe_on_initialize': " \
|
142
|
-
"oh no initialize!"
|
143
|
-
)
|
144
|
-
# Start of the error backtrace as debug log
|
145
|
-
expect(log).to contains_log :debug, File.expand_path("../../..", __dir__)
|
146
|
-
end
|
147
|
-
end
|
148
|
-
end
|
149
|
-
|
150
|
-
context "with a lambda" do
|
151
|
-
it "calls the lambda every <wait time>" do
|
152
|
-
calls = 0
|
153
|
-
probe = lambda { calls += 1 }
|
154
|
-
Appsignal::Probes.register :my_probe, probe
|
155
|
-
Appsignal::Probes.start
|
156
|
-
|
157
|
-
wait_for("enough probe calls") { calls >= 2 }
|
158
|
-
expect(log).to contains_log(:debug, "Gathering minutely metrics with 1 probe")
|
159
|
-
expect(log).to contains_log(:debug, "Gathering minutely metrics with 'my_probe' probe")
|
160
|
-
end
|
161
|
-
end
|
162
|
-
|
163
|
-
context "with a broken probe" do
|
164
|
-
it "logs the error and continues calling the probes every <wait_time>" do
|
165
|
-
probe = MockProbe.new
|
166
|
-
broken_probe = BrokenProbe.new
|
167
|
-
Appsignal::Probes.register :my_probe, probe
|
168
|
-
Appsignal::Probes.register :broken_probe, broken_probe
|
169
|
-
Appsignal::Probes.start
|
170
|
-
|
171
|
-
wait_for("enough probe calls") { probe.calls >= 2 }
|
172
|
-
wait_for("enough broken_probe calls") { broken_probe.calls >= 2 }
|
173
|
-
|
174
|
-
expect(log).to contains_log(:debug, "Gathering minutely metrics with 2 probes")
|
175
|
-
expect(log).to contains_log(:debug, "Gathering minutely metrics with 'my_probe' probe")
|
176
|
-
expect(log).to contains_log(:debug, "Gathering minutely metrics with 'broken_probe' probe")
|
177
|
-
expect(log).to contains_log(:error, "Error in minutely probe 'broken_probe': oh no!")
|
178
|
-
gem_path = File.expand_path("../../..", __dir__) # Start of backtrace
|
179
|
-
expect(log).to contains_log(:debug, gem_path)
|
180
|
-
end
|
181
|
-
end
|
182
|
-
|
183
|
-
context "with a probe that takes 60 seconds" do
|
184
|
-
it "logs an error and continues calling the probes every <wait_time>" do
|
185
|
-
stub_const("Appsignal::Probes::ITERATION_IN_SECONDS", 0.2)
|
186
|
-
calls = 0
|
187
|
-
probe = lambda do
|
188
|
-
calls += 1
|
189
|
-
sleep 0.2
|
190
|
-
end
|
191
|
-
Appsignal::Probes.register :my_probe, probe
|
192
|
-
Appsignal::Probes.register :other_probe, lambda {}
|
193
|
-
Appsignal::Probes.start
|
194
|
-
|
195
|
-
wait_for("enough probe calls") { calls >= 2 }
|
196
|
-
|
197
|
-
expect(log).to contains_log(
|
198
|
-
:error,
|
199
|
-
"The minutely probes took more than 60 seconds. " \
|
200
|
-
"The probes should not take this long as metrics will not " \
|
201
|
-
"be accurately reported."
|
202
|
-
)
|
203
|
-
end
|
204
|
-
end
|
205
|
-
|
206
|
-
it "ensures only one minutely probes thread is active at a time" do
|
207
|
-
alive_thread_counter = proc { Thread.list.reject { |t| t.status == "dead" }.length }
|
208
|
-
probe = MockProbe.new
|
209
|
-
Appsignal::Probes.register :my_probe, probe
|
210
|
-
expect do
|
211
|
-
Appsignal::Probes.start
|
212
|
-
end.to change { alive_thread_counter.call }.by(1)
|
213
|
-
|
214
|
-
wait_for("enough probe calls") { probe.calls >= 2 }
|
215
|
-
expect(Appsignal::Probes).to have_received(:initial_wait_time).once
|
216
|
-
expect(Appsignal::Probes).to have_received(:wait_time).at_least(:once)
|
217
|
-
expect(log).to contains_log(:debug, "Gathering minutely metrics with 1 probe")
|
218
|
-
expect(log).to contains_log(:debug, "Gathering minutely metrics with 'my_probe' probe")
|
219
|
-
|
220
|
-
# Starting twice in this spec, so expecting it more than once
|
221
|
-
expect(Appsignal::Probes).to have_received(:initial_wait_time).once
|
222
|
-
expect do
|
223
|
-
# Fetch old thread
|
224
|
-
thread = Appsignal::Probes.instance_variable_get(:@thread)
|
225
|
-
Appsignal::Probes.start
|
226
|
-
thread&.join # Wait for old thread to exit
|
227
|
-
end.to_not(change { alive_thread_counter.call })
|
228
|
-
end
|
229
|
-
|
230
|
-
context "with thread already started" do
|
231
|
-
it "auto starts probes added after the thread is started" do
|
232
|
-
Appsignal::Probes.start
|
233
|
-
wait_for("Probes thread to start") { Appsignal::Probes.started? }
|
234
|
-
|
235
|
-
calls = 0
|
236
|
-
probe = lambda { calls += 1 }
|
237
|
-
Appsignal::Probes.register :late_probe, probe
|
238
|
-
|
239
|
-
wait_for("enough probe calls") { calls >= 2 }
|
240
|
-
expect(log).to contains_log(:debug, "Gathering minutely metrics with 1 probe")
|
241
|
-
expect(log).to contains_log(:debug, "Gathering minutely metrics with 'late_probe' probe")
|
242
|
-
end
|
243
|
-
end
|
244
|
-
end
|
245
|
-
|
246
|
-
describe ".unregister" do
|
247
|
-
before { speed_up_tests! }
|
248
|
-
|
249
|
-
it "does not call the initialized probe after unregistering" do
|
250
|
-
probe1_calls = 0
|
251
|
-
probe2_calls = 0
|
252
|
-
probe1 = lambda { probe1_calls += 1 }
|
253
|
-
probe2 = lambda { probe2_calls += 1 }
|
254
|
-
Appsignal::Probes.register :probe1, probe1
|
255
|
-
Appsignal::Probes.register :probe2, probe2
|
256
|
-
Appsignal::Probes.start
|
257
|
-
wait_for("enough probe1 calls") { probe1_calls >= 2 }
|
258
|
-
wait_for("enough probe2 calls") { probe2_calls >= 2 }
|
259
|
-
|
260
|
-
Appsignal::Probes.unregister :probe2
|
261
|
-
probe1_calls = 0
|
262
|
-
probe2_calls = 0
|
263
|
-
# Check the probe 1 calls to make sure the probes have been called before
|
264
|
-
# testing if the unregistered probe has not been called
|
265
|
-
wait_for("enough probe1 calls") { probe1_calls >= 2 }
|
266
|
-
expect(probe2_calls).to eq(0)
|
267
|
-
end
|
268
|
-
end
|
269
|
-
|
270
|
-
describe ".stop" do
|
271
|
-
before do
|
272
|
-
speed_up_tests!
|
273
|
-
end
|
274
|
-
|
275
|
-
it "stops the minutely thread" do
|
276
|
-
Appsignal::Probes.start
|
277
|
-
thread = Appsignal::Probes.instance_variable_get(:@thread)
|
278
|
-
expect(%w[sleep run]).to include(thread.status)
|
279
|
-
Appsignal::Probes.stop
|
280
|
-
thread.join
|
281
|
-
expect(thread.status).to eql(false)
|
282
|
-
end
|
283
|
-
|
284
|
-
it "clears the probe instances array" do
|
285
|
-
Appsignal::Probes.register :my_probe, lambda {}
|
286
|
-
Appsignal::Probes.start
|
287
|
-
thread = Appsignal::Probes.instance_variable_get(:@thread)
|
288
|
-
wait_for("probes initialized") do
|
289
|
-
!Appsignal::Probes.send(:probe_instances).empty?
|
290
|
-
end
|
291
|
-
expect(Appsignal::Probes.send(:probe_instances)).to_not be_empty
|
292
|
-
Appsignal::Probes.stop
|
293
|
-
thread.join
|
294
|
-
expect(Appsignal::Probes.send(:probe_instances)).to be_empty
|
295
|
-
end
|
296
|
-
end
|
297
|
-
|
298
|
-
describe ".wait_time" do
|
299
|
-
it "gets the time to the next minute" do
|
300
|
-
time = Time.new(2019, 4, 9, 12, 0, 20)
|
301
|
-
Timecop.freeze time do
|
302
|
-
expect(Appsignal::Probes.wait_time).to eq 40
|
303
|
-
end
|
304
|
-
end
|
305
|
-
end
|
306
|
-
|
307
|
-
describe ".initial_wait_time" do
|
308
|
-
context "when started in the last 30 seconds of a minute" do
|
309
|
-
it "waits for the number of seconds + 60" do
|
310
|
-
time = Time.new(2019, 4, 9, 12, 0, 31)
|
311
|
-
Timecop.freeze time do
|
312
|
-
expect(Appsignal::Probes.send(:initial_wait_time)).to eql(29 + 60)
|
313
|
-
end
|
314
|
-
end
|
315
|
-
end
|
316
|
-
|
317
|
-
context "when started in the first 30 seconds of a minute" do
|
318
|
-
it "waits the remaining seconds in the minute" do
|
319
|
-
time = Time.new(2019, 4, 9, 12, 0, 29)
|
320
|
-
Timecop.freeze time do
|
321
|
-
expect(Appsignal::Probes.send(:initial_wait_time)).to eql(31)
|
322
|
-
end
|
323
|
-
end
|
324
|
-
end
|
325
|
-
end
|
326
|
-
|
327
|
-
describe Appsignal::Probes::ProbeCollection do
|
328
|
-
let(:collection) { described_class.new }
|
329
|
-
|
330
|
-
describe "#count" do
|
331
|
-
it "returns how many probes are registered" do
|
332
|
-
expect(collection.count).to eql(0)
|
333
|
-
collection.internal_register :my_probe_1, lambda {}
|
334
|
-
expect(collection.count).to eql(1)
|
335
|
-
collection.internal_register :my_probe_2, lambda {}
|
336
|
-
expect(collection.count).to eql(2)
|
337
|
-
end
|
338
|
-
end
|
339
|
-
|
340
|
-
describe "#clear" do
|
341
|
-
it "clears the list of probes" do
|
342
|
-
collection.internal_register :my_probe_1, lambda {}
|
343
|
-
collection.internal_register :my_probe_2, lambda {}
|
344
|
-
expect(collection.count).to eql(2)
|
345
|
-
collection.clear
|
346
|
-
expect(collection.count).to eql(0)
|
347
|
-
end
|
348
|
-
end
|
349
|
-
|
350
|
-
describe "#[]" do
|
351
|
-
it "returns the probe for that name" do
|
352
|
-
probe = lambda {}
|
353
|
-
collection.internal_register :my_probe, probe
|
354
|
-
expect(collection[:my_probe]).to eql(probe)
|
355
|
-
end
|
356
|
-
end
|
357
|
-
|
358
|
-
describe "#internal_register" do
|
359
|
-
let(:log_stream) { std_stream }
|
360
|
-
let(:log) { log_contents(log_stream) }
|
361
|
-
before { Appsignal.internal_logger = test_logger(log_stream) }
|
362
|
-
|
363
|
-
it "adds the probe by key" do
|
364
|
-
probe = lambda {}
|
365
|
-
collection.internal_register :my_probe, probe
|
366
|
-
expect(collection[:my_probe]).to eql(probe)
|
367
|
-
end
|
368
|
-
|
369
|
-
context "when a probe is already registered with the same key" do
|
370
|
-
it "logs a debug message" do
|
371
|
-
probe = lambda {}
|
372
|
-
collection.internal_register :my_probe, probe
|
373
|
-
collection.internal_register :my_probe, probe
|
374
|
-
expect(log).to contains_log :debug, "A probe with the name " \
|
375
|
-
"`my_probe` is already registered. Overwriting the entry " \
|
376
|
-
"with the new probe."
|
377
|
-
expect(collection[:my_probe]).to eql(probe)
|
378
|
-
end
|
379
|
-
end
|
380
|
-
end
|
381
|
-
|
382
|
-
describe "#unregister" do
|
383
|
-
it "removes the probe from the collection" do
|
384
|
-
probe = lambda {}
|
385
|
-
silence { collection.internal_register :my_probe, probe }
|
386
|
-
expect(collection[:my_probe]).to eql(probe)
|
387
|
-
|
388
|
-
silence { collection.unregister :my_probe }
|
389
|
-
expect(collection[:my_probe]).to be_nil
|
390
|
-
end
|
391
|
-
end
|
392
|
-
|
393
|
-
describe "#each" do
|
394
|
-
it "loops over the registered probes" do
|
395
|
-
probe = lambda {}
|
396
|
-
collection.internal_register :my_probe, probe
|
397
|
-
list = []
|
398
|
-
collection.each do |name, p| # rubocop:disable Style/MapIntoArray
|
399
|
-
list << [name, p]
|
400
|
-
end
|
401
|
-
expect(list).to eql([[:my_probe, probe]])
|
402
|
-
end
|
403
|
-
end
|
404
|
-
end
|
405
|
-
|
406
|
-
# Speed up test time by decreasing wait times in the probes mechanism
|
407
|
-
def speed_up_tests!
|
408
|
-
allow(Appsignal::Probes).to receive(:initial_wait_time).and_return(0.001)
|
409
|
-
allow(Appsignal::Probes).to receive(:wait_time).and_return(0.001)
|
410
|
-
end
|
411
|
-
end
|