appsignal 1.4.0.alpha.2 → 1.4.0.beta.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rspec +3 -1
- data/.travis.yml +3 -1
- data/CHANGELOG.md +38 -1
- data/Rakefile +29 -12
- data/benchmark.rake +3 -7
- data/ext/agent.yml +11 -11
- data/ext/appsignal_extension.c +364 -72
- data/ext/extconf.rb +2 -4
- data/gemfiles/resque.gemfile +1 -0
- data/lib/appsignal.rb +40 -30
- data/lib/appsignal/auth_check.rb +1 -1
- data/lib/appsignal/cli/diagnose.rb +4 -3
- data/lib/appsignal/cli/install.rb +16 -15
- data/lib/appsignal/config.rb +31 -31
- data/lib/appsignal/event_formatter.rb +1 -1
- data/lib/appsignal/extension.rb +6 -0
- data/lib/appsignal/garbage_collection_profiler.rb +47 -0
- data/lib/appsignal/hooks.rb +1 -0
- data/lib/appsignal/hooks/active_support_notifications.rb +43 -0
- data/lib/appsignal/integrations/capistrano/appsignal.cap +1 -1
- data/lib/appsignal/integrations/capistrano/capistrano_2_tasks.rb +2 -2
- data/lib/appsignal/integrations/mongo_ruby_driver.rb +1 -1
- data/lib/appsignal/integrations/object.rb +4 -4
- data/lib/appsignal/integrations/padrino.rb +1 -1
- data/lib/appsignal/integrations/sinatra.rb +1 -1
- data/lib/appsignal/integrations/webmachine.rb +2 -2
- data/lib/appsignal/js_exception_transaction.rb +7 -10
- data/lib/appsignal/marker.rb +3 -2
- data/lib/appsignal/rack/generic_instrumentation.rb +1 -1
- data/lib/appsignal/rack/sinatra_instrumentation.rb +13 -6
- data/lib/appsignal/rack/streaming_listener.rb +5 -3
- data/lib/appsignal/system.rb +36 -0
- data/lib/appsignal/transaction.rb +20 -20
- data/lib/appsignal/transmitter.rb +11 -7
- data/lib/appsignal/utils.rb +76 -2
- data/lib/appsignal/version.rb +1 -1
- data/spec/lib/appsignal/auth_check_spec.rb +0 -2
- data/spec/lib/appsignal/capistrano2_spec.rb +99 -79
- data/spec/lib/appsignal/capistrano3_spec.rb +57 -78
- data/spec/lib/appsignal/cli/diagnose_spec.rb +17 -15
- data/spec/lib/appsignal/cli/install_spec.rb +38 -20
- data/spec/lib/appsignal/cli/notify_of_deploy_spec.rb +2 -5
- data/spec/lib/appsignal/cli_spec.rb +2 -5
- data/spec/lib/appsignal/config_spec.rb +385 -158
- data/spec/lib/appsignal/event_formatter/action_view/render_formatter_spec.rb +1 -3
- data/spec/lib/appsignal/event_formatter/active_record/instantiation_formatter_spec.rb +0 -2
- data/spec/lib/appsignal/event_formatter/active_record/sql_formatter_spec.rb +0 -2
- data/spec/lib/appsignal/event_formatter/elastic_search/search_formatter_spec.rb +0 -2
- data/spec/lib/appsignal/event_formatter/faraday/request_formatter_spec.rb +0 -2
- data/spec/lib/appsignal/event_formatter/mongo_ruby_driver/query_formatter_spec.rb +0 -2
- data/spec/lib/appsignal/event_formatter/moped/query_formatter_spec.rb +0 -2
- data/spec/lib/appsignal/event_formatter_spec.rb +0 -2
- data/spec/lib/appsignal/extension_spec.rb +7 -8
- data/spec/lib/appsignal/garbage_collection_profiler_spec.rb +71 -0
- data/spec/lib/appsignal/hooks/active_support_notifications_spec.rb +42 -0
- data/spec/lib/appsignal/hooks/celluloid_spec.rb +0 -2
- data/spec/lib/appsignal/hooks/data_mapper_spec.rb +0 -2
- data/spec/lib/appsignal/hooks/delayed_job_spec.rb +0 -2
- data/spec/lib/appsignal/hooks/mongo_ruby_driver_spec.rb +0 -2
- data/spec/lib/appsignal/hooks/net_http_spec.rb +0 -2
- data/spec/lib/appsignal/hooks/passenger_spec.rb +0 -2
- data/spec/lib/appsignal/hooks/puma_spec.rb +0 -2
- data/spec/lib/appsignal/hooks/rake_spec.rb +1 -2
- data/spec/lib/appsignal/hooks/redis_spec.rb +0 -2
- data/spec/lib/appsignal/hooks/sequel_spec.rb +19 -21
- data/spec/lib/appsignal/hooks/shoryuken_spec.rb +1 -4
- data/spec/lib/appsignal/hooks/sidekiq_spec.rb +2 -3
- data/spec/lib/appsignal/hooks/unicorn_spec.rb +0 -2
- data/spec/lib/appsignal/hooks/webmachine_spec.rb +4 -11
- data/spec/lib/appsignal/hooks_spec.rb +0 -2
- data/spec/lib/appsignal/integrations/data_mapper_spec.rb +0 -1
- data/spec/lib/appsignal/integrations/grape_spec.rb +1 -3
- data/spec/lib/appsignal/integrations/mongo_ruby_driver_spec.rb +1 -2
- data/spec/lib/appsignal/integrations/object_spec.rb +32 -3
- data/spec/lib/appsignal/integrations/padrino_spec.rb +4 -11
- data/spec/lib/appsignal/integrations/railtie_spec.rb +1 -3
- data/spec/lib/appsignal/integrations/resque_active_job_spec.rb +1 -3
- data/spec/lib/appsignal/integrations/resque_spec.rb +2 -4
- data/spec/lib/appsignal/integrations/sinatra_spec.rb +33 -8
- data/spec/lib/appsignal/integrations/webmachine_spec.rb +6 -15
- data/spec/lib/appsignal/js_exception_transaction_spec.rb +3 -5
- data/spec/lib/appsignal/marker_spec.rb +35 -48
- data/spec/lib/appsignal/minutely_spec.rb +0 -2
- data/spec/lib/appsignal/rack/generic_instrumentation_spec.rb +0 -2
- data/spec/lib/appsignal/rack/js_exception_catcher_spec.rb +0 -2
- data/spec/lib/appsignal/rack/rails_instrumentation_spec.rb +3 -5
- data/spec/lib/appsignal/rack/sinatra_instrumentation_spec.rb +47 -11
- data/spec/lib/appsignal/rack/streaming_listener_spec.rb +6 -7
- data/spec/lib/appsignal/system/container_spec.rb +67 -0
- data/spec/lib/appsignal/system_spec.rb +49 -0
- data/spec/lib/appsignal/transaction_spec.rb +30 -13
- data/spec/lib/appsignal/transmitter_spec.rb +53 -20
- data/spec/lib/appsignal/utils/gzip_spec.rb +10 -0
- data/spec/lib/appsignal/utils/params_sanitizer_spec.rb +0 -2
- data/spec/lib/appsignal/utils/query_params_sanitizer_spec.rb +0 -2
- data/spec/lib/appsignal/utils_spec.rb +59 -3
- data/spec/lib/appsignal_spec.rb +132 -58
- data/spec/spec_helper.rb +24 -116
- data/spec/support/fixtures/containers/cgroups/docker +14 -0
- data/spec/support/fixtures/containers/cgroups/docker_systemd +8 -0
- data/spec/support/fixtures/containers/cgroups/lxc +10 -0
- data/spec/support/fixtures/containers/cgroups/no_permission +0 -0
- data/spec/support/fixtures/containers/cgroups/none +1 -0
- data/spec/support/helpers/api_request_helper.rb +22 -0
- data/spec/support/helpers/dependency_helper.rb +61 -0
- data/spec/support/helpers/directory_helper.rb +27 -0
- data/spec/support/helpers/std_streams_helper.rb +35 -0
- data/spec/support/helpers/system_helpers.rb +24 -0
- data/spec/support/helpers/transaction_helpers.rb +7 -64
- data/spec/support/helpers/very_specific_error.rb +8 -0
- data/spec/support/mocks/fake_gc_profiler.rb +19 -0
- data/spec/support/project_fixture/config/appsignal.yml +10 -1
- metadata +60 -35
- data/circle.yml +0 -12
- data/lib/appsignal/subscriber.rb +0 -55
- data/lib/appsignal/update_active_support.rb +0 -20
- data/lib/vendor/active_support/notifications.rb +0 -212
- data/lib/vendor/active_support/notifications/fanout.rb +0 -157
- data/lib/vendor/active_support/notifications/instrumenter.rb +0 -73
- data/lib/vendor/active_support/per_thread_registry.rb +0 -53
- data/spec/lib/appsignal/subscriber_spec.rb +0 -160
- data/spec/lib/appsignal/update_active_support_spec.rb +0 -17
- data/spec/support/helpers/notification_helpers.rb +0 -14
data/lib/appsignal/utils.rb
CHANGED
@@ -14,12 +14,81 @@ module Appsignal
|
|
14
14
|
end
|
15
15
|
extend ClassMethods
|
16
16
|
|
17
|
+
def self.data_generate(body)
|
18
|
+
Data.generate(body)
|
19
|
+
end
|
20
|
+
|
21
|
+
class Data
|
22
|
+
class << self
|
23
|
+
def generate(body)
|
24
|
+
if body.is_a?(Hash)
|
25
|
+
map_hash(body)
|
26
|
+
elsif body.is_a?(Array)
|
27
|
+
map_array(body)
|
28
|
+
else
|
29
|
+
raise TypeError.new("Body of type #{body.class} should be a Hash or Array")
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def map_hash(hash_value)
|
34
|
+
map = Appsignal::Extension.data_map_new
|
35
|
+
hash_value.each do |key, value|
|
36
|
+
key = key.to_s
|
37
|
+
case value
|
38
|
+
when String
|
39
|
+
map.set_string(key, value)
|
40
|
+
when Fixnum
|
41
|
+
map.set_fixnum(key, value)
|
42
|
+
when Float
|
43
|
+
map.set_float(key, value)
|
44
|
+
when TrueClass, FalseClass
|
45
|
+
map.set_boolean(key, value)
|
46
|
+
when NilClass
|
47
|
+
map.set_nil(key)
|
48
|
+
when Hash
|
49
|
+
map.set_data(key, map_hash(value))
|
50
|
+
when Array
|
51
|
+
map.set_data(key, map_array(value))
|
52
|
+
else
|
53
|
+
map.set_string(key, value.to_s)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
map
|
57
|
+
end
|
58
|
+
|
59
|
+
def map_array(array_value)
|
60
|
+
array = Appsignal::Extension.data_array_new
|
61
|
+
array_value.each do |value|
|
62
|
+
case value
|
63
|
+
when String
|
64
|
+
array.append_string(value)
|
65
|
+
when Fixnum
|
66
|
+
array.append_fixnum(value)
|
67
|
+
when Float
|
68
|
+
array.append_float(value)
|
69
|
+
when TrueClass, FalseClass
|
70
|
+
array.append_boolean(value)
|
71
|
+
when NilClass
|
72
|
+
array.append_nil
|
73
|
+
when Hash
|
74
|
+
array.append_data(map_hash(value))
|
75
|
+
when Array
|
76
|
+
array.append_data(map_array(value))
|
77
|
+
else
|
78
|
+
array.append_string(value.to_s)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
array
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
17
86
|
def self.json_generate(body)
|
18
87
|
JSON.generate(body)
|
19
88
|
end
|
20
89
|
|
21
90
|
class JSON
|
22
|
-
|
91
|
+
class << self
|
23
92
|
def generate(body)
|
24
93
|
::JSON.generate(jsonify(body))
|
25
94
|
end
|
@@ -49,8 +118,13 @@ module Appsignal
|
|
49
118
|
)
|
50
119
|
end
|
51
120
|
end
|
121
|
+
end
|
52
122
|
|
53
|
-
|
123
|
+
class Gzip
|
124
|
+
def self.compress(body)
|
125
|
+
Zlib::Deflate.deflate(body, Zlib::BEST_SPEED)
|
126
|
+
end
|
54
127
|
end
|
55
128
|
end
|
129
|
+
|
56
130
|
end
|
data/lib/appsignal/version.rb
CHANGED
@@ -1,6 +1,4 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
if capistrano2_present?
|
1
|
+
if DependencyHelper.capistrano2_present?
|
4
2
|
require 'capistrano'
|
5
3
|
require 'capistrano/configuration'
|
6
4
|
require 'appsignal/capistrano'
|
@@ -8,39 +6,36 @@ if capistrano2_present?
|
|
8
6
|
describe "Capistrano 2 integration" do
|
9
7
|
let(:out_stream) { StringIO.new }
|
10
8
|
let(:config) { project_fixture_config }
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
9
|
+
let(:capistrano_config) do
|
10
|
+
Capistrano::Configuration.new.tap do |c|
|
11
|
+
c.set(:rails_env, 'production')
|
12
|
+
c.set(:repository, 'master')
|
13
|
+
c.set(:deploy_to, '/home/username/app')
|
14
|
+
c.set(:current_release, '')
|
15
|
+
c.set(:current_revision, '503ce0923ed177a3ce000005')
|
16
|
+
c.dry_run = false
|
17
|
+
end
|
15
18
|
end
|
16
|
-
|
17
|
-
|
19
|
+
before do
|
20
|
+
Appsignal::Capistrano.tasks(capistrano_config)
|
18
21
|
end
|
19
|
-
|
20
|
-
|
21
|
-
@capistrano_config = Capistrano::Configuration.new
|
22
|
-
Appsignal::Capistrano.tasks(@capistrano_config)
|
22
|
+
around do |example|
|
23
|
+
capture_stdout(out_stream) { example.run }
|
23
24
|
end
|
24
25
|
|
25
26
|
it "should have a deploy task" do
|
26
|
-
|
27
|
+
capistrano_config.find_task('appsignal:deploy').should_not be_nil
|
27
28
|
end
|
28
29
|
|
29
30
|
describe "appsignal:deploy task" do
|
30
31
|
before do
|
31
|
-
@capistrano_config.set(:rails_env, 'production')
|
32
|
-
@capistrano_config.set(:repository, 'master')
|
33
|
-
@capistrano_config.set(:deploy_to, '/home/username/app')
|
34
|
-
@capistrano_config.set(:current_release, '')
|
35
|
-
@capistrano_config.set(:current_revision, '503ce0923ed177a3ce000005')
|
36
|
-
@capistrano_config.dry_run = false
|
37
32
|
ENV['USER'] = 'batman'
|
38
33
|
ENV['PWD'] = project_fixture_path
|
39
34
|
end
|
40
35
|
|
41
36
|
context "config" do
|
42
37
|
before do
|
43
|
-
|
38
|
+
capistrano_config.dry_run = true
|
44
39
|
end
|
45
40
|
|
46
41
|
it "should be instantiated with the right params" do
|
@@ -54,7 +49,7 @@ if capistrano2_present?
|
|
54
49
|
|
55
50
|
context "when appsignal_config is available" do
|
56
51
|
before do
|
57
|
-
|
52
|
+
capistrano_config.set(:appsignal_config, :name => 'AppName')
|
58
53
|
end
|
59
54
|
|
60
55
|
it "should be instantiated with the right params" do
|
@@ -68,8 +63,8 @@ if capistrano2_present?
|
|
68
63
|
|
69
64
|
context "when rack_env is used instead of rails_env" do
|
70
65
|
before do
|
71
|
-
|
72
|
-
|
66
|
+
capistrano_config.unset(:rails_env)
|
67
|
+
capistrano_config.set(:rack_env, 'rack_production')
|
73
68
|
end
|
74
69
|
|
75
70
|
it "should be instantiated with the right params" do
|
@@ -81,12 +76,51 @@ if capistrano2_present?
|
|
81
76
|
)
|
82
77
|
end
|
83
78
|
end
|
79
|
+
|
80
|
+
context "when stage is used instead of rack_env / rails_env" do
|
81
|
+
before do
|
82
|
+
capistrano_config.unset(:rails_env)
|
83
|
+
capistrano_config.set(:stage, 'stage_production')
|
84
|
+
end
|
85
|
+
|
86
|
+
it "should be instantiated with the right params" do
|
87
|
+
Appsignal::Config.should_receive(:new).with(
|
88
|
+
project_fixture_path,
|
89
|
+
'stage_production',
|
90
|
+
{:name => 'AppName'},
|
91
|
+
kind_of(Logger)
|
92
|
+
)
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
context "when appsignal_env is set" do
|
97
|
+
before do
|
98
|
+
capistrano_config.set(:rack_env, 'rack_production')
|
99
|
+
capistrano_config.set(:stage, 'stage_production')
|
100
|
+
capistrano_config.set(:appsignal_env, 'appsignal_production')
|
101
|
+
end
|
102
|
+
|
103
|
+
it "should prefer the appsignal_env rather than stage, rails_env and rack_env" do
|
104
|
+
Appsignal::Config.should_receive(:new).with(
|
105
|
+
project_fixture_path,
|
106
|
+
'appsignal_production',
|
107
|
+
{:name => 'AppName'},
|
108
|
+
kind_of(Logger)
|
109
|
+
)
|
110
|
+
end
|
111
|
+
end
|
84
112
|
end
|
85
113
|
|
86
|
-
after
|
114
|
+
after do
|
115
|
+
capistrano_config.find_and_execute_task('appsignal:deploy')
|
116
|
+
end
|
87
117
|
end
|
88
118
|
|
89
|
-
|
119
|
+
describe "markers" do
|
120
|
+
def stub_marker_request(data = {})
|
121
|
+
stub_api_request config, 'markers', marker_data.merge(data)
|
122
|
+
end
|
123
|
+
|
90
124
|
let(:marker_data) do
|
91
125
|
{
|
92
126
|
:revision => '503ce0923ed177a3ce000005',
|
@@ -95,80 +129,66 @@ if capistrano2_present?
|
|
95
129
|
end
|
96
130
|
|
97
131
|
context "when active for this environment" do
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
)
|
103
|
-
|
132
|
+
it "transmits marker" do
|
133
|
+
stub_marker_request.to_return(:status => 200)
|
134
|
+
capistrano_config.find_and_execute_task('appsignal:deploy')
|
135
|
+
|
136
|
+
expect(out_stream.string).to include \
|
137
|
+
'Notifying Appsignal of deploy with: revision: 503ce0923ed177a3ce000005, user: batman',
|
138
|
+
'Appsignal has been notified of this deploy!'
|
104
139
|
end
|
105
140
|
|
106
|
-
context "
|
141
|
+
context "with overridden revision" do
|
107
142
|
before do
|
108
|
-
|
109
|
-
|
143
|
+
capistrano_config.set(:appsignal_revision, 'abc123')
|
144
|
+
stub_marker_request(:revision => 'abc123').to_return(:status => 200)
|
145
|
+
capistrano_config.find_and_execute_task('appsignal:deploy')
|
110
146
|
end
|
111
147
|
|
112
|
-
it "
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
).and_return(@marker)
|
117
|
-
|
118
|
-
@capistrano_config.find_and_execute_task('appsignal:deploy')
|
148
|
+
it "transmits the overriden revision" do
|
149
|
+
expect(out_stream.string).to include \
|
150
|
+
'Notifying Appsignal of deploy with: revision: abc123, user: batman',
|
151
|
+
'Appsignal has been notified of this deploy!'
|
119
152
|
end
|
153
|
+
end
|
120
154
|
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
out_stream.string.should include('Appsignal has been notified of this deploy!')
|
155
|
+
context "with failed request" do
|
156
|
+
before do
|
157
|
+
stub_marker_request.to_return(:status => 500)
|
158
|
+
capistrano_config.find_and_execute_task('appsignal:deploy')
|
126
159
|
end
|
127
160
|
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
{
|
135
|
-
:revision => 'abc123',
|
136
|
-
:user => 'batman'
|
137
|
-
},
|
138
|
-
kind_of(Appsignal::Config)
|
139
|
-
).and_return(@marker)
|
140
|
-
|
141
|
-
@capistrano_config.find_and_execute_task('appsignal:deploy')
|
142
|
-
end
|
161
|
+
it "does not transmit marker" do
|
162
|
+
output = out_stream.string
|
163
|
+
expect(output).to include \
|
164
|
+
'Notifying Appsignal of deploy with: revision: 503ce0923ed177a3ce000005, user: batman',
|
165
|
+
'Something went wrong while trying to notify Appsignal:'
|
166
|
+
expect(output).to_not include 'Appsignal has been notified of this deploy!'
|
143
167
|
end
|
144
168
|
end
|
145
169
|
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
context "dry run" do
|
153
|
-
before { @capistrano_config.dry_run = true }
|
170
|
+
context "when dry run" do
|
171
|
+
before do
|
172
|
+
capistrano_config.dry_run = true
|
173
|
+
capistrano_config.find_and_execute_task('appsignal:deploy')
|
174
|
+
end
|
154
175
|
|
155
|
-
it "
|
156
|
-
|
157
|
-
|
158
|
-
out_stream.string.should include('Dry run: AppSignal deploy marker not actually sent.')
|
176
|
+
it "does not transmit marker" do
|
177
|
+
expect(out_stream.string).to include \
|
178
|
+
'Dry run: AppSignal deploy marker not actually sent.'
|
159
179
|
end
|
160
180
|
end
|
161
181
|
end
|
162
182
|
|
163
183
|
context "when not active for this environment" do
|
164
184
|
before do
|
165
|
-
|
185
|
+
capistrano_config.set(:rails_env, 'nonsense')
|
186
|
+
capistrano_config.find_and_execute_task('appsignal:deploy')
|
166
187
|
end
|
167
188
|
|
168
|
-
it "
|
169
|
-
|
170
|
-
|
171
|
-
out_stream.string.should include('Not notifying of deploy, config is not active')
|
189
|
+
it "does not transmit marker" do
|
190
|
+
expect(out_stream.string).to include \
|
191
|
+
"Not notifying of deploy, config is not active for environment: nonsense"
|
172
192
|
end
|
173
193
|
end
|
174
194
|
end
|
@@ -1,6 +1,4 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
if capistrano3_present?
|
1
|
+
if DependencyHelper.capistrano3_present?
|
4
2
|
require 'capistrano/all'
|
5
3
|
require 'capistrano/deploy'
|
6
4
|
require 'appsignal/capistrano'
|
@@ -11,23 +9,24 @@ if capistrano3_present?
|
|
11
9
|
let(:config) { project_fixture_config }
|
12
10
|
let(:out_stream) { StringIO.new }
|
13
11
|
let(:logger) { Logger.new(out_stream) }
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
12
|
+
let!(:capistrano_config) do
|
13
|
+
Capistrano::Configuration.reset!
|
14
|
+
Capistrano::Configuration.env.tap do |c|
|
15
|
+
c.set(:log_level, :error)
|
16
|
+
c.set(:logger, logger)
|
17
|
+
c.set(:rails_env, 'production')
|
18
|
+
c.set(:repository, 'master')
|
19
|
+
c.set(:deploy_to, '/home/username/app')
|
20
|
+
c.set(:current_release, '')
|
21
|
+
c.set(:current_revision, '503ce0923ed177a3ce000005')
|
22
|
+
end
|
19
23
|
end
|
20
24
|
before do
|
21
|
-
@original_stdout = $stdout
|
22
|
-
$stdout = out_stream
|
23
|
-
@original_stderr = $stderr
|
24
|
-
$stderr = out_stream
|
25
|
-
end
|
26
|
-
after do
|
27
|
-
$stdout = @original_stdout
|
28
|
-
$stderr = @original_stderr
|
29
25
|
Rake::Task['appsignal:deploy'].reenable
|
30
26
|
end
|
27
|
+
around do |example|
|
28
|
+
capture_std_streams(out_stream, out_stream) { example.run }
|
29
|
+
end
|
31
30
|
|
32
31
|
it "should have a deploy task" do
|
33
32
|
Rake::Task.task_defined?('appsignal:deploy').should be_true
|
@@ -35,11 +34,6 @@ if capistrano3_present?
|
|
35
34
|
|
36
35
|
describe "appsignal:deploy task" do
|
37
36
|
before do
|
38
|
-
@capistrano_config.set(:rails_env, 'production')
|
39
|
-
@capistrano_config.set(:repository, 'master')
|
40
|
-
@capistrano_config.set(:deploy_to, '/home/username/app')
|
41
|
-
@capistrano_config.set(:current_release, '')
|
42
|
-
@capistrano_config.set(:current_revision, '503ce0923ed177a3ce000005')
|
43
37
|
ENV['USER'] = 'batman'
|
44
38
|
ENV['PWD'] = project_fixture_path
|
45
39
|
end
|
@@ -56,7 +50,7 @@ if capistrano3_present?
|
|
56
50
|
|
57
51
|
context "when appsignal_config is available" do
|
58
52
|
before do
|
59
|
-
|
53
|
+
capistrano_config.set(:appsignal_config, :name => 'AppName')
|
60
54
|
end
|
61
55
|
|
62
56
|
it "should be instantiated with the right params" do
|
@@ -70,8 +64,8 @@ if capistrano3_present?
|
|
70
64
|
|
71
65
|
context "when rack_env is the only env set" do
|
72
66
|
before do
|
73
|
-
|
74
|
-
|
67
|
+
capistrano_config.delete(:rails_env)
|
68
|
+
capistrano_config.set(:rack_env, 'rack_production')
|
75
69
|
end
|
76
70
|
|
77
71
|
it "should be instantiated with the rack env" do
|
@@ -86,8 +80,8 @@ if capistrano3_present?
|
|
86
80
|
|
87
81
|
context "when stage is set" do
|
88
82
|
before do
|
89
|
-
|
90
|
-
|
83
|
+
capistrano_config.set(:rack_env, 'rack_production')
|
84
|
+
capistrano_config.set(:stage, 'stage_production')
|
91
85
|
end
|
92
86
|
|
93
87
|
it "should prefer the stage rather than rails_env and rack_env" do
|
@@ -102,9 +96,9 @@ if capistrano3_present?
|
|
102
96
|
|
103
97
|
context "when appsignal_env is set" do
|
104
98
|
before do
|
105
|
-
|
106
|
-
|
107
|
-
|
99
|
+
capistrano_config.set(:rack_env, 'rack_production')
|
100
|
+
capistrano_config.set(:stage, 'stage_production')
|
101
|
+
capistrano_config.set(:appsignal_env, 'appsignal_production')
|
108
102
|
end
|
109
103
|
|
110
104
|
it "should prefer the appsignal_env rather than stage, rails_env and rack_env" do
|
@@ -120,13 +114,14 @@ if capistrano3_present?
|
|
120
114
|
|
121
115
|
after do
|
122
116
|
invoke('appsignal:deploy')
|
123
|
-
@capistrano_config.delete(:stage)
|
124
|
-
@capistrano_config.delete(:rack_env)
|
125
|
-
@capistrano_config.delete(:appsignal_env)
|
126
117
|
end
|
127
118
|
end
|
128
119
|
|
129
|
-
|
120
|
+
describe "markers" do
|
121
|
+
def stub_marker_request(data = {})
|
122
|
+
stub_api_request config, 'markers', marker_data.merge(data)
|
123
|
+
end
|
124
|
+
|
130
125
|
let(:marker_data) do
|
131
126
|
{
|
132
127
|
:revision => '503ce0923ed177a3ce000005',
|
@@ -135,70 +130,54 @@ if capistrano3_present?
|
|
135
130
|
end
|
136
131
|
|
137
132
|
context "when active for this environment" do
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
)
|
143
|
-
|
133
|
+
it "transmits marker" do
|
134
|
+
stub_marker_request.to_return(:status => 200)
|
135
|
+
invoke('appsignal:deploy')
|
136
|
+
|
137
|
+
expect(out_stream.string).to include \
|
138
|
+
'Notifying Appsignal of deploy with: revision: 503ce0923ed177a3ce000005, user: batman',
|
139
|
+
'Appsignal has been notified of this deploy!'
|
144
140
|
end
|
145
141
|
|
146
|
-
context "
|
142
|
+
context "with overridden revision" do
|
147
143
|
before do
|
148
|
-
|
149
|
-
|
144
|
+
capistrano_config.set(:appsignal_revision, 'abc123')
|
145
|
+
stub_marker_request(:revision => 'abc123').to_return(:status => 200)
|
146
|
+
invoke('appsignal:deploy')
|
150
147
|
end
|
151
148
|
|
152
|
-
it "
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
).and_return(@marker)
|
157
|
-
|
158
|
-
invoke('appsignal:deploy')
|
149
|
+
it "transmits the overriden revision" do
|
150
|
+
expect(out_stream.string).to include \
|
151
|
+
'Notifying Appsignal of deploy with: revision: abc123, user: batman',
|
152
|
+
'Appsignal has been notified of this deploy!'
|
159
153
|
end
|
154
|
+
end
|
160
155
|
|
161
|
-
|
162
|
-
|
156
|
+
context "with failed request" do
|
157
|
+
before do
|
158
|
+
stub_marker_request.to_return(:status => 500)
|
163
159
|
invoke('appsignal:deploy')
|
164
|
-
out_stream.string.should include('Notifying Appsignal of deploy with: revision: 503ce0923ed177a3ce000005, user: batman')
|
165
|
-
out_stream.string.should include('ppsignal has been notified of this deploy!')
|
166
160
|
end
|
167
161
|
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
{
|
175
|
-
:revision => 'abc123',
|
176
|
-
:user => 'batman'
|
177
|
-
},
|
178
|
-
kind_of(Appsignal::Config)
|
179
|
-
).and_return(@marker)
|
180
|
-
|
181
|
-
invoke('appsignal:deploy')
|
182
|
-
end
|
162
|
+
it "does not transmit marker" do
|
163
|
+
output = out_stream.string
|
164
|
+
expect(output).to include \
|
165
|
+
'Notifying Appsignal of deploy with: revision: 503ce0923ed177a3ce000005, user: batman',
|
166
|
+
'Something went wrong while trying to notify Appsignal:'
|
167
|
+
expect(output).to_not include 'Appsignal has been notified of this deploy!'
|
183
168
|
end
|
184
169
|
end
|
185
|
-
|
186
|
-
it "should not transmit data" do
|
187
|
-
invoke('appsignal:deploy')
|
188
|
-
out_stream.string.should include('Notifying Appsignal of deploy with: revision: 503ce0923ed177a3ce000005, user: batman')
|
189
|
-
out_stream.string.should include('Something went wrong while trying to notify Appsignal:')
|
190
|
-
end
|
191
170
|
end
|
192
171
|
|
193
172
|
context "when not active for this environment" do
|
194
173
|
before do
|
195
|
-
|
174
|
+
capistrano_config.set(:rails_env, 'nonsense')
|
175
|
+
invoke('appsignal:deploy')
|
196
176
|
end
|
197
177
|
|
198
178
|
it "should not send deploy marker" do
|
199
|
-
|
200
|
-
|
201
|
-
out_stream.string.should include("Not notifying of deploy, config is not active")
|
179
|
+
expect(out_stream.string).to include \
|
180
|
+
"Not notifying of deploy, config is not active for environment: nonsense"
|
202
181
|
end
|
203
182
|
end
|
204
183
|
end
|