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.
Files changed (203) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +20 -0
  3. data/Rakefile +9 -9
  4. data/appsignal.gemspec +22 -1
  5. data/build_matrix.yml +2 -1
  6. data/ext/agent.rb +27 -27
  7. data/lib/appsignal/check_in/scheduler.rb +3 -4
  8. data/lib/appsignal/check_in.rb +1 -1
  9. data/lib/appsignal/config.rb +1 -3
  10. data/lib/appsignal/integrations/que.rb +8 -2
  11. data/lib/appsignal/integrations/resque.rb +1 -6
  12. data/lib/appsignal/utils/hash_sanitizer.rb +4 -0
  13. data/lib/appsignal/version.rb +1 -1
  14. metadata +2 -191
  15. data/.github/ISSUE_TEMPLATE/bug_report.md +0 -31
  16. data/.github/ISSUE_TEMPLATE/chore.md +0 -14
  17. data/.github/workflows/ci.yml +0 -3150
  18. data/.github/workflows/create_release_from_tag.yml +0 -62
  19. data/.gitignore +0 -35
  20. data/.gitmodules +0 -3
  21. data/.rspec +0 -4
  22. data/.yardopts +0 -8
  23. data/benchmark.rake +0 -139
  24. data/gemfiles/capistrano2.gemfile +0 -6
  25. data/gemfiles/capistrano3.gemfile +0 -7
  26. data/gemfiles/dry-monitor.gemfile +0 -5
  27. data/gemfiles/grape.gemfile +0 -5
  28. data/gemfiles/hanami-2.0.gemfile +0 -7
  29. data/gemfiles/hanami-2.1.gemfile +0 -7
  30. data/gemfiles/http5.gemfile +0 -5
  31. data/gemfiles/no_dependencies.gemfile +0 -10
  32. data/gemfiles/padrino.gemfile +0 -7
  33. data/gemfiles/psych-3.gemfile +0 -5
  34. data/gemfiles/psych-4.gemfile +0 -5
  35. data/gemfiles/que.gemfile +0 -5
  36. data/gemfiles/rails-6.0.gemfile +0 -10
  37. data/gemfiles/rails-6.1.gemfile +0 -11
  38. data/gemfiles/rails-7.0.gemfile +0 -11
  39. data/gemfiles/rails-7.1.gemfile +0 -11
  40. data/gemfiles/rails-7.2.gemfile +0 -11
  41. data/gemfiles/redis-4.gemfile +0 -5
  42. data/gemfiles/redis-5.gemfile +0 -6
  43. data/gemfiles/resque-2.gemfile +0 -6
  44. data/gemfiles/sequel.gemfile +0 -10
  45. data/gemfiles/sinatra.gemfile +0 -5
  46. data/gemfiles/webmachine1.gemfile +0 -7
  47. data/gemfiles/webmachine2.gemfile +0 -6
  48. data/mono.yml +0 -16
  49. data/spec/.rubocop.yml +0 -7
  50. data/spec/lib/appsignal/auth_check_spec.rb +0 -84
  51. data/spec/lib/appsignal/capistrano2_spec.rb +0 -227
  52. data/spec/lib/appsignal/capistrano3_spec.rb +0 -284
  53. data/spec/lib/appsignal/check_in/cron_spec.rb +0 -202
  54. data/spec/lib/appsignal/check_in/scheduler_spec.rb +0 -443
  55. data/spec/lib/appsignal/cli/demo_spec.rb +0 -46
  56. data/spec/lib/appsignal/cli/diagnose/paths_spec.rb +0 -16
  57. data/spec/lib/appsignal/cli/diagnose/utils_spec.rb +0 -86
  58. data/spec/lib/appsignal/cli/diagnose_spec.rb +0 -1553
  59. data/spec/lib/appsignal/cli/helpers_spec.rb +0 -179
  60. data/spec/lib/appsignal/cli/install_spec.rb +0 -848
  61. data/spec/lib/appsignal/cli_spec.rb +0 -56
  62. data/spec/lib/appsignal/config_spec.rb +0 -1380
  63. data/spec/lib/appsignal/demo_spec.rb +0 -83
  64. data/spec/lib/appsignal/environment_spec.rb +0 -190
  65. data/spec/lib/appsignal/event_formatter/action_view/render_formatter_spec.rb +0 -60
  66. data/spec/lib/appsignal/event_formatter/active_record/instantiation_formatter_spec.rb +0 -21
  67. data/spec/lib/appsignal/event_formatter/active_record/sql_formatter_spec.rb +0 -21
  68. data/spec/lib/appsignal/event_formatter/elastic_search/search_formatter_spec.rb +0 -52
  69. data/spec/lib/appsignal/event_formatter/faraday/request_formatter_spec.rb +0 -21
  70. data/spec/lib/appsignal/event_formatter/mongo_ruby_driver/query_formatter_spec.rb +0 -84
  71. data/spec/lib/appsignal/event_formatter/rom/sql_formatter_spec.rb +0 -22
  72. data/spec/lib/appsignal/event_formatter/sequel/sql_formatter_spec.rb +0 -30
  73. data/spec/lib/appsignal/event_formatter/view_component/render_formatter_spec.rb +0 -41
  74. data/spec/lib/appsignal/event_formatter_spec.rb +0 -193
  75. data/spec/lib/appsignal/extension/jruby_spec.rb +0 -46
  76. data/spec/lib/appsignal/extension_install_failure_spec.rb +0 -20
  77. data/spec/lib/appsignal/extension_spec.rb +0 -178
  78. data/spec/lib/appsignal/garbage_collection_spec.rb +0 -98
  79. data/spec/lib/appsignal/hooks/action_cable_spec.rb +0 -345
  80. data/spec/lib/appsignal/hooks/action_mailer_spec.rb +0 -55
  81. data/spec/lib/appsignal/hooks/active_support_notifications/finish_with_state_shared_examples.rb +0 -23
  82. data/spec/lib/appsignal/hooks/active_support_notifications/instrument_shared_examples.rb +0 -99
  83. data/spec/lib/appsignal/hooks/active_support_notifications/start_finish_shared_examples.rb +0 -47
  84. data/spec/lib/appsignal/hooks/active_support_notifications_spec.rb +0 -47
  85. data/spec/lib/appsignal/hooks/activejob_spec.rb +0 -650
  86. data/spec/lib/appsignal/hooks/at_exit_spec.rb +0 -105
  87. data/spec/lib/appsignal/hooks/celluloid_spec.rb +0 -40
  88. data/spec/lib/appsignal/hooks/data_mapper_spec.rb +0 -40
  89. data/spec/lib/appsignal/hooks/delayed_job_spec.rb +0 -38
  90. data/spec/lib/appsignal/hooks/dry_monitor_spec.rb +0 -83
  91. data/spec/lib/appsignal/hooks/excon_spec.rb +0 -67
  92. data/spec/lib/appsignal/hooks/gvl_spec.rb +0 -145
  93. data/spec/lib/appsignal/hooks/http_spec.rb +0 -37
  94. data/spec/lib/appsignal/hooks/mongo_ruby_driver_spec.rb +0 -46
  95. data/spec/lib/appsignal/hooks/mri_spec.rb +0 -23
  96. data/spec/lib/appsignal/hooks/net_http_spec.rb +0 -18
  97. data/spec/lib/appsignal/hooks/passenger_spec.rb +0 -30
  98. data/spec/lib/appsignal/hooks/puma_spec.rb +0 -80
  99. data/spec/lib/appsignal/hooks/que_spec.rb +0 -19
  100. data/spec/lib/appsignal/hooks/rake_spec.rb +0 -144
  101. data/spec/lib/appsignal/hooks/redis_client_spec.rb +0 -218
  102. data/spec/lib/appsignal/hooks/redis_spec.rb +0 -124
  103. data/spec/lib/appsignal/hooks/resque_spec.rb +0 -27
  104. data/spec/lib/appsignal/hooks/sequel_spec.rb +0 -44
  105. data/spec/lib/appsignal/hooks/shoryuken_spec.rb +0 -29
  106. data/spec/lib/appsignal/hooks/sidekiq_spec.rb +0 -115
  107. data/spec/lib/appsignal/hooks/unicorn_spec.rb +0 -63
  108. data/spec/lib/appsignal/hooks/webmachine_spec.rb +0 -24
  109. data/spec/lib/appsignal/hooks_spec.rb +0 -124
  110. data/spec/lib/appsignal/integrations/data_mapper_spec.rb +0 -74
  111. data/spec/lib/appsignal/integrations/delayed_job_plugin_spec.rb +0 -454
  112. data/spec/lib/appsignal/integrations/http_spec.rb +0 -111
  113. data/spec/lib/appsignal/integrations/mongo_ruby_driver_spec.rb +0 -154
  114. data/spec/lib/appsignal/integrations/net_http_spec.rb +0 -33
  115. data/spec/lib/appsignal/integrations/object_spec.rb +0 -347
  116. data/spec/lib/appsignal/integrations/puma_spec.rb +0 -150
  117. data/spec/lib/appsignal/integrations/que_spec.rb +0 -152
  118. data/spec/lib/appsignal/integrations/railtie_spec.rb +0 -457
  119. data/spec/lib/appsignal/integrations/resque_spec.rb +0 -155
  120. data/spec/lib/appsignal/integrations/shoryuken_spec.rb +0 -165
  121. data/spec/lib/appsignal/integrations/sidekiq_spec.rb +0 -640
  122. data/spec/lib/appsignal/integrations/webmachine_spec.rb +0 -136
  123. data/spec/lib/appsignal/loaders/grape_spec.rb +0 -12
  124. data/spec/lib/appsignal/loaders/hanami_spec.rb +0 -92
  125. data/spec/lib/appsignal/loaders/padrino_spec.rb +0 -273
  126. data/spec/lib/appsignal/loaders/sinatra_spec.rb +0 -44
  127. data/spec/lib/appsignal/loaders_spec.rb +0 -144
  128. data/spec/lib/appsignal/logger_spec.rb +0 -205
  129. data/spec/lib/appsignal/marker_spec.rb +0 -51
  130. data/spec/lib/appsignal/probes/gvl_spec.rb +0 -164
  131. data/spec/lib/appsignal/probes/mri_spec.rb +0 -162
  132. data/spec/lib/appsignal/probes/sidekiq_spec.rb +0 -333
  133. data/spec/lib/appsignal/probes_spec.rb +0 -411
  134. data/spec/lib/appsignal/rack/abstract_middleware_spec.rb +0 -370
  135. data/spec/lib/appsignal/rack/body_wrapper_spec.rb +0 -319
  136. data/spec/lib/appsignal/rack/event_handler_spec.rb +0 -441
  137. data/spec/lib/appsignal/rack/grape_middleware_spec.rb +0 -201
  138. data/spec/lib/appsignal/rack/hanami_middleware_spec.rb +0 -36
  139. data/spec/lib/appsignal/rack/instrumentation_middleware_spec.rb +0 -38
  140. data/spec/lib/appsignal/rack/rails_instrumentation_spec.rb +0 -126
  141. data/spec/lib/appsignal/rack/sinatra_instrumentation_spec.rb +0 -217
  142. data/spec/lib/appsignal/rack_spec.rb +0 -243
  143. data/spec/lib/appsignal/sample_data_spec.rb +0 -238
  144. data/spec/lib/appsignal/span_spec.rb +0 -141
  145. data/spec/lib/appsignal/system_spec.rb +0 -126
  146. data/spec/lib/appsignal/transaction_spec.rb +0 -2111
  147. data/spec/lib/appsignal/transmitter_spec.rb +0 -198
  148. data/spec/lib/appsignal/utils/data_spec.rb +0 -166
  149. data/spec/lib/appsignal/utils/hash_sanitizer_spec.rb +0 -182
  150. data/spec/lib/appsignal/utils/integration_logger_spec.rb +0 -21
  151. data/spec/lib/appsignal/utils/integration_memory_logger_spec.rb +0 -153
  152. data/spec/lib/appsignal/utils/json_spec.rb +0 -44
  153. data/spec/lib/appsignal/utils/query_params_sanitizer_spec.rb +0 -192
  154. data/spec/lib/appsignal_spec.rb +0 -1919
  155. data/spec/lib/puma/appsignal_spec.rb +0 -334
  156. data/spec/spec_helper.rb +0 -173
  157. data/spec/support/fixtures/generated_config.yml +0 -24
  158. data/spec/support/fixtures/projects/broken/config/appsignal.yml +0 -1
  159. data/spec/support/fixtures/projects/valid/config/appsignal.yml +0 -57
  160. data/spec/support/fixtures/projects/valid/log/.gitkeep +0 -0
  161. data/spec/support/fixtures/projects/valid_with_rails_app/config/application.rb +0 -16
  162. data/spec/support/fixtures/projects/valid_with_rails_app/config/appsignal.yml +0 -56
  163. data/spec/support/fixtures/projects/valid_with_rails_app/config/environment.rb +0 -10
  164. data/spec/support/fixtures/projects/valid_with_rails_app/log/.gitkeep +0 -0
  165. data/spec/support/fixtures/uploaded_file.txt +0 -0
  166. data/spec/support/hanami/hanami_app.rb +0 -29
  167. data/spec/support/helpers/action_mailer_helpers.rb +0 -25
  168. data/spec/support/helpers/activejob_helpers.rb +0 -27
  169. data/spec/support/helpers/api_request_helper.rb +0 -20
  170. data/spec/support/helpers/cli_helpers.rb +0 -40
  171. data/spec/support/helpers/config_helpers.rb +0 -66
  172. data/spec/support/helpers/dependency_helper.rb +0 -150
  173. data/spec/support/helpers/directory_helper.rb +0 -27
  174. data/spec/support/helpers/env_helpers.rb +0 -41
  175. data/spec/support/helpers/environment_metdata_helper.rb +0 -16
  176. data/spec/support/helpers/example_exception.rb +0 -13
  177. data/spec/support/helpers/example_standard_error.rb +0 -13
  178. data/spec/support/helpers/loader_helper.rb +0 -21
  179. data/spec/support/helpers/log_helpers.rb +0 -36
  180. data/spec/support/helpers/rails_helper.rb +0 -28
  181. data/spec/support/helpers/std_streams_helper.rb +0 -94
  182. data/spec/support/helpers/system_helpers.rb +0 -8
  183. data/spec/support/helpers/take_at_most_helper.rb +0 -21
  184. data/spec/support/helpers/time_helpers.rb +0 -11
  185. data/spec/support/helpers/transaction_helpers.rb +0 -122
  186. data/spec/support/helpers/wait_for_helper.rb +0 -39
  187. data/spec/support/matchers/contains_log.rb +0 -26
  188. data/spec/support/matchers/have_colorized_text.rb +0 -28
  189. data/spec/support/matchers/transaction.rb +0 -200
  190. data/spec/support/mocks/appsignal_mock.rb +0 -18
  191. data/spec/support/mocks/dummy_app.rb +0 -20
  192. data/spec/support/mocks/fake_gc_profiler.rb +0 -19
  193. data/spec/support/mocks/fake_gvl_tools.rb +0 -28
  194. data/spec/support/mocks/hash_like.rb +0 -10
  195. data/spec/support/mocks/mock_probe.rb +0 -13
  196. data/spec/support/mocks/puma_mock.rb +0 -43
  197. data/spec/support/shared_examples/instrument.rb +0 -48
  198. data/spec/support/stubs/appsignal/loaders/loader_stub.rb +0 -7
  199. data/spec/support/stubs/delayed_job.rb +0 -0
  200. data/spec/support/stubs/sidekiq/api.rb +0 -4
  201. data/spec/support/testing.rb +0 -194
  202. data/support/bundler_wrapper +0 -12
  203. data/support/install_deps +0 -33
@@ -1,227 +0,0 @@
1
- if DependencyHelper.capistrano2_present?
2
- require "capistrano"
3
- require "capistrano/configuration"
4
- require "appsignal/capistrano"
5
-
6
- describe "Capistrano 2 integration" do
7
- let(:out_stream) { std_stream }
8
- let(:output) { out_stream.read }
9
- let(:config) { build_config }
10
- let(:capistrano_config) do
11
- Capistrano::Configuration.new.tap do |c|
12
- c.set(:rails_env, "production")
13
- c.set(:repository, "main")
14
- c.set(:deploy_to, "/home/username/app")
15
- c.set(:current_release, "")
16
- c.set(:current_revision, "503ce0923ed177a3ce000005")
17
- c.dry_run = false
18
- end
19
- end
20
- before { Appsignal::Integrations::Capistrano.tasks(capistrano_config) }
21
-
22
- def run
23
- capture_stdout(out_stream) do
24
- capistrano_config.find_and_execute_task("appsignal:deploy")
25
- end
26
- end
27
-
28
- it "has a deploy task" do
29
- expect(capistrano_config.find_task("appsignal:deploy")).to_not be_nil
30
- end
31
-
32
- describe "appsignal:deploy task" do
33
- before do
34
- ENV["USER"] = "batman"
35
- ENV["PWD"] = project_fixture_path
36
- end
37
-
38
- context "config" do
39
- before do
40
- capistrano_config.dry_run = true
41
- end
42
-
43
- context "when appsignal_config is available" do
44
- before do
45
- capistrano_config.set(
46
- :appsignal_config,
47
- :name => "AppName",
48
- :active => true,
49
- :push_api_key => "abc"
50
- )
51
- end
52
-
53
- it "overrides the default config with the custom appsignal_config" do
54
- original_new = Appsignal::Marker.method(:new)
55
-
56
- expect(Appsignal::Marker).to receive(:new) do |data, given_config|
57
- expect(given_config[:name]).to eq("AppName")
58
- original_new.call(data, given_config)
59
- end
60
-
61
- run
62
- end
63
-
64
- context "when rack_env is used instead of rails_env" do
65
- before do
66
- capistrano_config.unset(:rails_env)
67
- capistrano_config.set(:rack_env, "rack_production")
68
- end
69
-
70
- it "uses the rack_env as the env" do
71
- original_new = Appsignal::Marker.method(:new)
72
-
73
- expect(Appsignal::Marker).to receive(:new) do |data, given_config|
74
- expect(given_config.env).to eq("rack_production")
75
- original_new.call(data, given_config)
76
- end
77
-
78
- run
79
- end
80
- end
81
-
82
- context "when stage is used instead of rack_env / rails_env" do
83
- before do
84
- capistrano_config.unset(:rails_env)
85
- capistrano_config.set(:stage, "stage_production")
86
- end
87
-
88
- it "uses the stage as the env" do
89
- original_new = Appsignal::Marker.method(:new)
90
-
91
- expect(Appsignal::Marker).to receive(:new) do |data, given_config|
92
- expect(given_config.env).to eq("stage_production")
93
- original_new.call(data, given_config)
94
- end
95
-
96
- run
97
- end
98
- end
99
-
100
- context "when appsignal_env is set" do
101
- before do
102
- capistrano_config.set(:rack_env, "rack_production")
103
- capistrano_config.set(:stage, "stage_production")
104
- capistrano_config.set(:appsignal_env, "appsignal_production")
105
- end
106
-
107
- it "uses the appsignal_env as the env" do
108
- original_new = Appsignal::Marker.method(:new)
109
-
110
- expect(Appsignal::Marker).to receive(:new) do |data, given_config|
111
- expect(given_config.env).to eq("appsignal_production")
112
- original_new.call(data, given_config)
113
- end
114
-
115
- run
116
- end
117
- end
118
-
119
- context "with invalid config" do
120
- before do
121
- capistrano_config.set(:appsignal_config, :push_api_key => nil)
122
- end
123
-
124
- it "does not continue with invalid config" do
125
- run
126
- expect(output).to include \
127
- "Not notifying of deploy, config is not active for environment: production"
128
- end
129
- end
130
- end
131
- end
132
-
133
- describe "markers" do
134
- def stub_marker_request(data = {})
135
- stub_api_request config, "markers", marker_data.merge(data)
136
- end
137
-
138
- let(:marker_data) do
139
- {
140
- :revision => "503ce0923ed177a3ce000005",
141
- :user => "batman"
142
- }
143
- end
144
-
145
- context "when active for this environment" do
146
- it "transmits marker" do
147
- stub_marker_request.to_return(:status => 200)
148
- run
149
-
150
- expect(output).to include \
151
- "Notifying AppSignal of deploy with: revision: 503ce0923ed177a3ce000005," \
152
- " user: batman",
153
- "AppSignal has been notified of this deploy!"
154
- end
155
-
156
- context "with overridden revision" do
157
- before do
158
- capistrano_config.set(:appsignal_revision, "abc123")
159
- stub_marker_request(:revision => "abc123").to_return(:status => 200)
160
- run
161
- end
162
-
163
- it "transmits the overridden revision" do
164
- expect(output).to include \
165
- "Notifying AppSignal of deploy with: revision: abc123, user: batman",
166
- "AppSignal has been notified of this deploy!"
167
- end
168
- end
169
-
170
- context "with overridden deploy user" do
171
- before do
172
- capistrano_config.set(:appsignal_user, "robin")
173
- stub_marker_request(:user => "robin").to_return(:status => 200)
174
- run
175
- end
176
-
177
- it "transmits the overridden deploy user" do
178
- expect(output).to include \
179
- "Notifying AppSignal of deploy with: revision: 503ce0923ed177a3ce000005," \
180
- " user: robin",
181
- "AppSignal has been notified of this deploy!"
182
- end
183
- end
184
-
185
- context "with failed request" do
186
- before do
187
- stub_marker_request.to_return(:status => 500)
188
- run
189
- end
190
-
191
- it "does not transmit marker" do
192
- expect(output).to include \
193
- "Notifying AppSignal of deploy with: revision: 503ce0923ed177a3ce000005," \
194
- " user: batman",
195
- "Something went wrong while trying to notify AppSignal:"
196
- expect(output).to_not include "AppSignal has been notified of this deploy!"
197
- end
198
- end
199
-
200
- context "when dry run" do
201
- before do
202
- capistrano_config.dry_run = true
203
- run
204
- end
205
-
206
- it "does not transmit marker" do
207
- expect(output).to include \
208
- "Dry run: AppSignal deploy marker not actually sent."
209
- end
210
- end
211
- end
212
-
213
- context "when not active for this environment" do
214
- before do
215
- capistrano_config.set(:rails_env, "nonsense")
216
- run
217
- end
218
-
219
- it "does not transmit marker" do
220
- expect(output).to include \
221
- "Not notifying of deploy, config is not active for environment: nonsense"
222
- end
223
- end
224
- end
225
- end
226
- end
227
- end
@@ -1,284 +0,0 @@
1
- if DependencyHelper.capistrano3_present?
2
- require "capistrano/all"
3
- require "capistrano/deploy"
4
- require "appsignal/capistrano"
5
-
6
- describe "Capistrano 3 integration" do
7
- let(:capistrano) { Class.new.extend(Capistrano::DSL) }
8
- let(:env) { :production }
9
- let(:options) { {} }
10
- let(:config) { build_config(:env => env, :options => options) }
11
- let(:out_stream) { std_stream }
12
- let(:output) { out_stream.read }
13
- let(:logger) { Logger.new(out_stream) }
14
- let!(:capistrano_config) do
15
- Capistrano::Configuration.reset!
16
- Capistrano::Configuration.env.tap do |c|
17
- c.set(:log_level, :error)
18
- c.set(:logger, logger)
19
- c.set(:rails_env, "production")
20
- c.set(:repository, "main")
21
- c.set(:deploy_to, "/home/username/app")
22
- c.set(:current_release, "")
23
- c.set(:current_revision, "503ce0923ed177a3ce000005")
24
- end
25
- end
26
- let(:marker_data) do
27
- {
28
- :revision => "503ce0923ed177a3ce000005",
29
- :user => "batman"
30
- }
31
- end
32
- before { Rake::Task["appsignal:deploy"].reenable }
33
-
34
- def run
35
- capture_std_streams(out_stream, out_stream) do
36
- capistrano.invoke("appsignal:deploy")
37
- end
38
- end
39
-
40
- it "should have a deploy task" do
41
- expect(Rake::Task.task_defined?("appsignal:deploy")).to be_truthy
42
- end
43
-
44
- describe "appsignal:deploy task" do
45
- before do
46
- ENV["USER"] = "batman"
47
- end
48
- around do |example|
49
- Dir.chdir project_fixture_path do
50
- example.run
51
- end
52
- end
53
-
54
- context "config" do
55
- let(:options) { { :name => "AppName" } }
56
- before do
57
- capistrano_config.set(
58
- :appsignal_config,
59
- :name => "AppName",
60
- :active => true,
61
- :push_api_key => "abc"
62
- )
63
- end
64
-
65
- context "when rack_env is the only env set" do
66
- let(:env) { "rack_production" }
67
- before do
68
- capistrano_config.delete(:rails_env)
69
- capistrano_config.set(:rack_env, env)
70
- end
71
-
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)
78
- original_new = Appsignal::Marker.method(:new)
79
-
80
- expect(Appsignal::Marker).to receive(:new) do |data, given_config|
81
- expect(given_config.env).to eq("rack_production")
82
- original_new.call(data, given_config)
83
- end
84
-
85
- run
86
- end
87
- end
88
-
89
- context "when stage is set" do
90
- let(:env) { "stage_production" }
91
- before do
92
- capistrano_config.set(:rack_env, "rack_production")
93
- capistrano_config.set(:stage, env)
94
- end
95
-
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)
102
- original_new = Appsignal::Marker.method(:new)
103
-
104
- expect(Appsignal::Marker).to receive(:new) do |data, given_config|
105
- expect(given_config.env).to eq("stage_production")
106
- original_new.call(data, given_config)
107
- end
108
-
109
- run
110
- end
111
- end
112
-
113
- context "when `appsignal_config` is set" do
114
- before do
115
- ENV["APPSIGNAL_APP_NAME"] = "EnvName"
116
- capistrano_config.set(:appsignal_config, :name => "CapName")
117
- end
118
-
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)
125
- original_new = Appsignal::Marker.method(:new)
126
-
127
- expect(Appsignal::Marker).to receive(:new) do |data, given_config|
128
- expect(given_config[:name]).to eq("CapName")
129
- original_new.call(data, given_config)
130
- end
131
-
132
- run
133
- end
134
-
135
- context "with invalid config" do
136
- before do
137
- capistrano_config.set(:appsignal_config, :push_api_key => nil)
138
- end
139
-
140
- it "does not continue with invalid config" do
141
- run
142
- expect(output).to include \
143
- "Not notifying of deploy, config is not active for environment: production"
144
- end
145
- end
146
- end
147
-
148
- context "when `appsignal_env` is set" do
149
- let(:env) { "appsignal_production" }
150
- before do
151
- capistrano_config.set(:rack_env, "rack_production")
152
- capistrano_config.set(:stage, "stage_production")
153
- capistrano_config.set(:appsignal_env, env)
154
- end
155
-
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)
162
- original_new = Appsignal::Marker.method(:new)
163
-
164
- expect(Appsignal::Marker).to receive(:new) do |data, given_config|
165
- expect(given_config.env).to eq("appsignal_production")
166
- original_new.call(data, given_config)
167
- end
168
-
169
- run
170
- end
171
- end
172
- end
173
-
174
- describe "markers" do
175
- context "when active for this environment" do
176
- it "transmits marker" do
177
- stub_marker_request(
178
- :environment => env.to_s,
179
- :name => "TestApp",
180
- :push_api_key => "abc"
181
- ).to_return(:status => 200)
182
- run
183
-
184
- expect(output).to include \
185
- "Notifying AppSignal of deploy with: revision: 503ce0923ed177a3ce000005, " \
186
- "user: batman",
187
- "AppSignal has been notified of this deploy!"
188
- end
189
-
190
- context "with overridden revision" do
191
- before do
192
- capistrano_config.set(:appsignal_revision, "abc123")
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)
201
- run
202
- end
203
-
204
- it "transmits the overridden revision" do
205
- expect(output).to include \
206
- "Notifying AppSignal of deploy with: revision: abc123, user: batman",
207
- "AppSignal has been notified of this deploy!"
208
- end
209
- end
210
-
211
- context "with overridden deploy user" do
212
- before do
213
- capistrano_config.set(:appsignal_user, "robin")
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)
222
- run
223
- end
224
-
225
- it "transmits the overridden deploy user" do
226
- expect(output).to include \
227
- "Notifying AppSignal of deploy with: revision: 503ce0923ed177a3ce000005, " \
228
- "user: robin",
229
- "AppSignal has been notified of this deploy!"
230
- end
231
- end
232
-
233
- if Gem::Version.new(Capistrano::VERSION) >= Gem::Version.new("3.5.0")
234
- context "when dry run" do
235
- before do
236
- expect(capistrano_config).to receive(:dry_run?).and_return(true)
237
- run
238
- end
239
-
240
- it "does not transmit the marker" do
241
- expect(output).to include "Dry run: AppSignal deploy marker not actually sent."
242
- end
243
- end
244
- end
245
-
246
- context "with failed request" do
247
- before do
248
- stub_marker_request(
249
- :environment => env.to_s,
250
- :name => "TestApp",
251
- :push_api_key => "abc"
252
- ).to_return(:status => 500)
253
- run
254
- end
255
-
256
- it "does not transmit marker" do
257
- expect(output).to include \
258
- "Notifying AppSignal of deploy with: revision: 503ce0923ed177a3ce000005, " \
259
- "user: batman",
260
- "Something went wrong while trying to notify AppSignal:"
261
- expect(output).to_not include "AppSignal has been notified of this deploy!"
262
- end
263
- end
264
- end
265
-
266
- context "when not active for this environment" do
267
- before do
268
- capistrano_config.set(:rails_env, "nonsense")
269
- run
270
- end
271
-
272
- it "should not send deploy marker" do
273
- expect(output).to include \
274
- "Not notifying of deploy, config is not active for environment: nonsense"
275
- end
276
- end
277
- end
278
- end
279
- end
280
-
281
- def stub_marker_request(config = {}, data = {})
282
- stub_api_request config, "markers", marker_data.merge(data)
283
- end
284
- end
@@ -1,202 +0,0 @@
1
- describe Appsignal::CheckIn::Cron do
2
- let(:log_stream) { std_stream }
3
- let(:logs) { log_contents(log_stream) }
4
- let(:appsignal_options) { {} }
5
- let(:config) { project_fixture_config }
6
- let(:cron_checkin) { described_class.new(:identifier => "cron-checkin-name") }
7
- let(:transmitter) { Appsignal::Transmitter.new("https://checkin-endpoint.invalid") }
8
- let(:scheduler) { Appsignal::CheckIn::Scheduler.new }
9
-
10
- before do
11
- start_agent(
12
- :options => appsignal_options,
13
- :internal_logger => test_logger(log_stream)
14
- )
15
- allow(Appsignal::CheckIn).to receive(:scheduler).and_return(scheduler)
16
- allow(Appsignal::CheckIn).to receive(:transmitter).and_return(transmitter)
17
- end
18
- after { stop_scheduler }
19
-
20
- def stop_scheduler
21
- scheduler.stop
22
- end
23
-
24
- describe "when Appsignal is not active" do
25
- let(:appsignal_options) { { :active => false } }
26
-
27
- it "does not transmit any events" do
28
- expect(Appsignal).to_not be_started
29
-
30
- cron_checkin.start
31
- cron_checkin.finish
32
- stop_scheduler
33
-
34
- expect(logs).to contains_log(
35
- :debug,
36
- /Cannot transmit cron check-in `cron-checkin-name` start event .+: AppSignal is not active/
37
- )
38
- expect(logs).to contains_log(
39
- :debug,
40
- /Cannot transmit cron check-in `cron-checkin-name` finish event .+: AppSignal is not active/
41
- )
42
- end
43
- end
44
-
45
- describe "when AppSignal is stopped" do
46
- it "does not transmit any events" do
47
- Appsignal.stop
48
-
49
- cron_checkin.start
50
- cron_checkin.finish
51
-
52
- expect(logs).to contains_log(
53
- :debug,
54
- "Cannot transmit cron check-in `cron-checkin-name` start event"
55
- )
56
- expect(logs).to contains_log(
57
- :debug,
58
- "Cannot transmit cron check-in `cron-checkin-name` finish event"
59
- )
60
- end
61
- end
62
-
63
- describe "#start" do
64
- it "sends a cron check-in start" do
65
- cron_checkin.start
66
-
67
- expect(transmitter).to receive(:transmit).with([hash_including(
68
- :identifier => "cron-checkin-name",
69
- :kind => "start",
70
- :check_in_type => "cron"
71
- )], :format => :ndjson).and_return(Net::HTTPResponse.new(nil, "200", nil))
72
-
73
- scheduler.stop
74
-
75
- expect(logs).to_not contains_log(:error)
76
- expect(logs).to contains_log(
77
- :debug,
78
- "Scheduling cron check-in `cron-checkin-name` start event"
79
- )
80
- expect(logs).to contains_log(
81
- :debug,
82
- "Transmitted cron check-in `cron-checkin-name` start event"
83
- )
84
- end
85
-
86
- it "logs an error if it fails" do
87
- cron_checkin.start
88
-
89
- expect(transmitter).to receive(:transmit).with([hash_including(
90
- :identifier => "cron-checkin-name",
91
- :kind => "start",
92
- :check_in_type => "cron"
93
- )], :format => :ndjson).and_return(Net::HTTPResponse.new(nil, "499", nil))
94
-
95
- scheduler.stop
96
-
97
- expect(logs).to contains_log(
98
- :debug,
99
- "Scheduling cron check-in `cron-checkin-name` start event"
100
- )
101
- expect(logs).to contains_log(
102
- :error,
103
- /Failed to transmit cron check-in `cron-checkin-name` start event .+: 499 status code/
104
- )
105
- end
106
- end
107
-
108
- describe "#finish" do
109
- it "sends a cron check-in finish" do
110
- cron_checkin.finish
111
-
112
- expect(transmitter).to receive(:transmit).with([hash_including(
113
- :identifier => "cron-checkin-name",
114
- :kind => "finish",
115
- :check_in_type => "cron"
116
- )], :format => :ndjson).and_return(Net::HTTPResponse.new(nil, "200", nil))
117
-
118
- scheduler.stop
119
- expect(logs).to_not contains_log(:error)
120
- expect(logs).to contains_log(
121
- :debug,
122
- "Scheduling cron check-in `cron-checkin-name` finish event"
123
- )
124
- expect(logs).to contains_log(
125
- :debug,
126
- "Transmitted cron check-in `cron-checkin-name` finish event"
127
- )
128
- end
129
-
130
- it "logs an error if it fails" do
131
- cron_checkin.finish
132
-
133
- expect(transmitter).to receive(:transmit).with([hash_including(
134
- :identifier => "cron-checkin-name",
135
- :kind => "finish",
136
- :check_in_type => "cron"
137
- )], :format => :ndjson).and_return(Net::HTTPResponse.new(nil, "499", nil))
138
-
139
- scheduler.stop
140
-
141
- expect(logs).to contains_log(
142
- :debug,
143
- "Scheduling cron check-in `cron-checkin-name` finish event"
144
- )
145
- expect(logs).to contains_log(
146
- :error,
147
- /Failed to transmit cron check-in `cron-checkin-name` finish event .+: 499 status code/
148
- )
149
- end
150
- end
151
-
152
- describe ".cron" do
153
- describe "when a block is given" do
154
- it "sends a cron check-in start and finish and return the block output" do
155
- expect(scheduler).to receive(:schedule).with(hash_including(
156
- :kind => "start",
157
- :identifier => "cron-checkin-with-block",
158
- :check_in_type => "cron"
159
- ))
160
-
161
- expect(scheduler).to receive(:schedule).with(hash_including(
162
- :kind => "finish",
163
- :identifier => "cron-checkin-with-block",
164
- :check_in_type => "cron"
165
- ))
166
-
167
- output = Appsignal::CheckIn.cron("cron-checkin-with-block") { "output" }
168
- expect(output).to eq("output")
169
- end
170
-
171
- it "does not send a cron check-in finish event when an error is raised" do
172
- expect(scheduler).to receive(:schedule).with(hash_including(
173
- :kind => "start",
174
- :identifier => "cron-checkin-with-block",
175
- :check_in_type => "cron"
176
- ))
177
-
178
- expect(scheduler).not_to receive(:schedule).with(hash_including(
179
- :kind => "finish",
180
- :identifier => "cron-checkin-with-block",
181
- :check_in_type => "cron"
182
- ))
183
-
184
- expect do
185
- Appsignal::CheckIn.cron("cron-checkin-with-block") { raise "error" }
186
- end.to raise_error(RuntimeError, "error")
187
- end
188
- end
189
-
190
- describe "when no block is given" do
191
- it "only sends a cron check-in finish event" do
192
- expect(scheduler).to receive(:schedule).with(hash_including(
193
- :kind => "finish",
194
- :identifier => "cron-checkin-without-block",
195
- :check_in_type => "cron"
196
- ))
197
-
198
- Appsignal::CheckIn.cron("cron-checkin-without-block")
199
- end
200
- end
201
- end
202
- end