appsignal 2.1.0.alpha.3 → 2.1.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/.gitignore +1 -0
- data/.rubocop.yml +43 -0
- data/.rubocop_todo.yml +289 -0
- data/.travis.yml +4 -0
- data/CHANGELOG.md +11 -1
- data/Gemfile +1 -1
- data/LICENSE +1 -1
- data/appsignal.gemspec +1 -0
- data/bin/appsignal +2 -2
- data/ext/agent.yml +11 -11
- data/ext/extconf.rb +33 -33
- data/gemfiles/rails-4.2.gemfile +4 -0
- data/gemfiles/resque.gemfile +4 -0
- data/lib/appsignal.rb +58 -54
- data/lib/appsignal/auth_check.rb +15 -16
- data/lib/appsignal/capistrano.rb +4 -4
- data/lib/appsignal/cli.rb +28 -28
- data/lib/appsignal/cli/diagnose.rb +11 -11
- data/lib/appsignal/cli/helpers.rb +1 -1
- data/lib/appsignal/cli/install.rb +38 -38
- data/lib/appsignal/cli/notify_of_deploy.rb +1 -1
- data/lib/appsignal/config.rb +73 -71
- data/lib/appsignal/event_formatter.rb +8 -8
- data/lib/appsignal/event_formatter/action_view/render_formatter.rb +4 -4
- data/lib/appsignal/event_formatter/active_record/instantiation_formatter.rb +1 -1
- data/lib/appsignal/event_formatter/active_record/sql_formatter.rb +1 -1
- data/lib/appsignal/event_formatter/elastic_search/search_formatter.rb +9 -7
- data/lib/appsignal/event_formatter/faraday/request_formatter.rb +1 -1
- data/lib/appsignal/event_formatter/mongo_ruby_driver/query_formatter.rb +6 -6
- data/lib/appsignal/event_formatter/moped/query_formatter.rb +56 -43
- data/lib/appsignal/extension.rb +5 -5
- data/lib/appsignal/hooks.rb +28 -26
- data/lib/appsignal/hooks/active_support_notifications.rb +2 -2
- data/lib/appsignal/hooks/celluloid.rb +1 -1
- data/lib/appsignal/hooks/data_mapper.rb +2 -2
- data/lib/appsignal/hooks/delayed_job.rb +1 -1
- data/lib/appsignal/hooks/mongo_ruby_driver.rb +1 -1
- data/lib/appsignal/hooks/net_http.rb +4 -4
- data/lib/appsignal/hooks/passenger.rb +2 -2
- data/lib/appsignal/hooks/puma.rb +4 -4
- data/lib/appsignal/hooks/rake.rb +1 -1
- data/lib/appsignal/hooks/redis.rb +1 -1
- data/lib/appsignal/hooks/sequel.rb +2 -2
- data/lib/appsignal/hooks/shoryuken.rb +8 -8
- data/lib/appsignal/hooks/sidekiq.rb +16 -15
- data/lib/appsignal/hooks/unicorn.rb +1 -1
- data/lib/appsignal/hooks/webmachine.rb +1 -1
- data/lib/appsignal/integrations/capistrano/capistrano_2_tasks.rb +6 -6
- data/lib/appsignal/integrations/data_mapper.rb +2 -3
- data/lib/appsignal/integrations/delayed_job_plugin.rb +5 -5
- data/lib/appsignal/integrations/mongo_ruby_driver.rb +6 -6
- data/lib/appsignal/integrations/padrino.rb +8 -8
- data/lib/appsignal/integrations/railtie.rb +5 -5
- data/lib/appsignal/integrations/resque.rb +4 -5
- data/lib/appsignal/integrations/resque_active_job.rb +3 -6
- data/lib/appsignal/integrations/sinatra.rb +2 -2
- data/lib/appsignal/integrations/webmachine.rb +2 -3
- data/lib/appsignal/js_exception_transaction.rb +10 -10
- data/lib/appsignal/marker.rb +3 -3
- data/lib/appsignal/rack/generic_instrumentation.rb +10 -9
- data/lib/appsignal/rack/js_exception_catcher.rb +7 -6
- data/lib/appsignal/rack/rails_instrumentation.rb +9 -8
- data/lib/appsignal/rack/sinatra_instrumentation.rb +19 -17
- data/lib/appsignal/rack/streaming_listener.rb +9 -8
- data/lib/appsignal/system.rb +19 -17
- data/lib/appsignal/transaction.rb +97 -40
- data/lib/appsignal/transmitter.rb +23 -30
- data/lib/appsignal/utils.rb +3 -3
- data/lib/appsignal/utils/params_sanitizer.rb +1 -1
- data/lib/appsignal/utils/query_params_sanitizer.rb +1 -1
- data/lib/appsignal/version.rb +2 -2
- data/spec/.rubocop.yml +4 -0
- data/spec/lib/appsignal/auth_check_spec.rb +7 -7
- data/spec/lib/appsignal/capistrano2_spec.rb +41 -41
- data/spec/lib/appsignal/capistrano3_spec.rb +43 -44
- data/spec/lib/appsignal/cli/notify_of_deploy_spec.rb +9 -11
- data/spec/lib/appsignal/cli_spec.rb +9 -9
- data/spec/lib/appsignal/config_spec.rb +88 -86
- data/spec/lib/appsignal/event_formatter/action_view/render_formatter_spec.rb +9 -9
- data/spec/lib/appsignal/event_formatter/active_record/instantiation_formatter_spec.rb +4 -4
- data/spec/lib/appsignal/event_formatter/active_record/sql_formatter_spec.rb +4 -4
- data/spec/lib/appsignal/event_formatter/elastic_search/search_formatter_spec.rb +12 -12
- data/spec/lib/appsignal/event_formatter/faraday/request_formatter_spec.rb +4 -4
- data/spec/lib/appsignal/event_formatter/mongo_ruby_driver/query_formatter_spec.rb +23 -23
- data/spec/lib/appsignal/event_formatter/moped/query_formatter_spec.rb +29 -30
- data/spec/lib/appsignal/event_formatter_spec.rb +28 -28
- data/spec/lib/appsignal/extension_spec.rb +15 -15
- data/spec/lib/appsignal/garbage_collection_profiler_spec.rb +6 -5
- data/spec/lib/appsignal/hooks/active_support_notifications_spec.rb +12 -12
- data/spec/lib/appsignal/hooks/delayed_job_spec.rb +34 -34
- data/spec/lib/appsignal/hooks/mongo_ruby_driver_spec.rb +3 -3
- data/spec/lib/appsignal/hooks/net_http_spec.rb +10 -10
- data/spec/lib/appsignal/hooks/rake_spec.rb +7 -7
- data/spec/lib/appsignal/hooks/redis_spec.rb +6 -6
- data/spec/lib/appsignal/hooks/shoryuken_spec.rb +21 -22
- data/spec/lib/appsignal/hooks/sidekiq_spec.rb +48 -45
- data/spec/lib/appsignal/hooks/webmachine_spec.rb +2 -2
- data/spec/lib/appsignal/hooks_spec.rb +16 -17
- data/spec/lib/appsignal/integrations/data_mapper_spec.rb +7 -8
- data/spec/lib/appsignal/integrations/mongo_ruby_driver_spec.rb +19 -19
- data/spec/lib/appsignal/integrations/object_spec.rb +3 -3
- data/spec/lib/appsignal/integrations/padrino_spec.rb +44 -44
- data/spec/lib/appsignal/integrations/railtie_spec.rb +13 -13
- data/spec/lib/appsignal/integrations/resque_active_job_spec.rb +7 -7
- data/spec/lib/appsignal/integrations/resque_spec.rb +8 -8
- data/spec/lib/appsignal/integrations/sinatra_spec.rb +7 -7
- data/spec/lib/appsignal/integrations/webmachine_spec.rb +15 -15
- data/spec/lib/appsignal/js_exception_transaction_spec.rb +23 -23
- data/spec/lib/appsignal/marker_spec.rb +8 -8
- data/spec/lib/appsignal/minutely_spec.rb +6 -6
- data/spec/lib/appsignal/rack/generic_instrumentation_spec.rb +7 -7
- data/spec/lib/appsignal/rack/js_exception_catcher_spec.rb +13 -13
- data/spec/lib/appsignal/rack/rails_instrumentation_spec.rb +11 -11
- data/spec/lib/appsignal/rack/sinatra_instrumentation_spec.rb +21 -21
- data/spec/lib/appsignal/rack/streaming_listener_spec.rb +36 -36
- data/spec/lib/appsignal/system/container_spec.rb +1 -1
- data/spec/lib/appsignal/transaction_spec.rb +213 -184
- data/spec/lib/appsignal/transmitter_spec.rb +20 -20
- data/spec/lib/appsignal/utils/params_sanitizer_spec.rb +19 -19
- data/spec/lib/appsignal/utils/query_params_sanitizer_spec.rb +41 -41
- data/spec/lib/appsignal/utils_spec.rb +41 -37
- data/spec/lib/appsignal_spec.rb +150 -142
- data/spec/spec_helper.rb +18 -18
- data/spec/support/delegate_matcher.rb +6 -6
- data/spec/support/helpers/api_request_helper.rb +2 -2
- data/spec/support/helpers/config_helpers.rb +3 -3
- data/spec/support/helpers/dependency_helper.rb +13 -13
- data/spec/support/helpers/directory_helper.rb +5 -5
- data/spec/support/helpers/env_helpers.rb +14 -14
- data/spec/support/helpers/system_helpers.rb +3 -3
- data/spec/support/helpers/transaction_helpers.rb +10 -10
- metadata +20 -2
@@ -1,13 +1,13 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
1
|
+
require "net/http"
|
2
|
+
require "net/https"
|
3
|
+
require "uri"
|
4
|
+
require "rack/utils"
|
5
|
+
require "json"
|
6
6
|
|
7
7
|
module Appsignal
|
8
8
|
class Transmitter
|
9
|
-
CONTENT_TYPE =
|
10
|
-
CONTENT_ENCODING =
|
9
|
+
CONTENT_TYPE = "application/json; charset=UTF-8".freeze
|
10
|
+
CONTENT_ENCODING = "gzip".freeze
|
11
11
|
|
12
12
|
HTTP_ERRORS = [
|
13
13
|
EOFError,
|
@@ -23,20 +23,18 @@ module Appsignal
|
|
23
23
|
|
24
24
|
attr_reader :config, :action
|
25
25
|
|
26
|
-
def initialize(action, config=Appsignal.config)
|
26
|
+
def initialize(action, config = Appsignal.config)
|
27
27
|
@action = action
|
28
28
|
@config = config
|
29
29
|
end
|
30
30
|
|
31
31
|
def uri
|
32
32
|
@uri ||= URI("#{config[:endpoint]}/1/#{action}").tap do |uri|
|
33
|
-
uri.query = ::Rack::Utils.build_query(
|
34
|
-
:api_key => config[:push_api_key],
|
33
|
+
uri.query = ::Rack::Utils.build_query(:api_key => config[:push_api_key],
|
35
34
|
:name => config[:name],
|
36
35
|
:environment => config.env,
|
37
36
|
:hostname => config[:hostname],
|
38
|
-
:gem_version => Appsignal::VERSION
|
39
|
-
})
|
37
|
+
:gem_version => Appsignal::VERSION)
|
40
38
|
end
|
41
39
|
end
|
42
40
|
|
@@ -49,22 +47,23 @@ module Appsignal
|
|
49
47
|
|
50
48
|
def http_post(payload)
|
51
49
|
Net::HTTP::Post.new(uri.request_uri).tap do |request|
|
52
|
-
request[
|
53
|
-
request[
|
50
|
+
request["Content-Type"] = CONTENT_TYPE
|
51
|
+
request["Content-Encoding"] = CONTENT_ENCODING
|
54
52
|
request.body = Appsignal::Utils::Gzip.compress \
|
55
53
|
Appsignal::Utils::JSON.generate(payload)
|
56
54
|
end
|
57
55
|
end
|
58
56
|
|
59
57
|
def http_client
|
60
|
-
client =
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
58
|
+
client =
|
59
|
+
if config[:http_proxy]
|
60
|
+
Net::HTTP.new(uri.host, uri.port, proxy_addr, proxy_port)
|
61
|
+
else
|
62
|
+
Net::HTTP.new(uri.host, uri.port)
|
63
|
+
end
|
65
64
|
|
66
65
|
client.tap do |http|
|
67
|
-
if uri.scheme ==
|
66
|
+
if uri.scheme == "https"
|
68
67
|
http.use_ssl = true
|
69
68
|
http.ssl_version = :TLSv1
|
70
69
|
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
@@ -85,19 +84,13 @@ module Appsignal
|
|
85
84
|
end
|
86
85
|
|
87
86
|
def proxy_addr
|
88
|
-
|
89
|
-
|
90
|
-
else
|
91
|
-
nil
|
92
|
-
end
|
87
|
+
return unless config[:http_proxy]
|
88
|
+
proxy_uri.host
|
93
89
|
end
|
94
90
|
|
95
91
|
def proxy_port
|
96
|
-
|
97
|
-
|
98
|
-
else
|
99
|
-
nil
|
100
|
-
end
|
92
|
+
return unless config[:http_proxy]
|
93
|
+
proxy_uri.port
|
101
94
|
end
|
102
95
|
end
|
103
96
|
end
|
data/lib/appsignal/utils.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require "appsignal/utils/params_sanitizer"
|
2
|
+
require "appsignal/utils/query_params_sanitizer"
|
3
3
|
|
4
4
|
module Appsignal
|
5
5
|
module Utils
|
@@ -101,7 +101,7 @@ module Appsignal
|
|
101
101
|
|
102
102
|
def encode_utf8(value)
|
103
103
|
value.encode(
|
104
|
-
|
104
|
+
"utf-8".freeze,
|
105
105
|
:invalid => :replace,
|
106
106
|
:undef => :replace
|
107
107
|
)
|
data/lib/appsignal/version.rb
CHANGED
data/spec/.rubocop.yml
ADDED
@@ -5,18 +5,18 @@ describe Appsignal::AuthCheck do
|
|
5
5
|
|
6
6
|
describe "#perform_with_result" do
|
7
7
|
it "should give success message" do
|
8
|
-
auth_check.should_receive(:perform).and_return(
|
9
|
-
auth_check.perform_with_result.should eq [
|
8
|
+
auth_check.should_receive(:perform).and_return("200")
|
9
|
+
auth_check.perform_with_result.should eq ["200", "AppSignal has confirmed authorization!"]
|
10
10
|
end
|
11
11
|
|
12
12
|
it "should give 401 message" do
|
13
|
-
auth_check.should_receive(:perform).and_return(
|
14
|
-
auth_check.perform_with_result.should eq [
|
13
|
+
auth_check.should_receive(:perform).and_return("401")
|
14
|
+
auth_check.perform_with_result.should eq ["401", "API key not valid with AppSignal..."]
|
15
15
|
end
|
16
16
|
|
17
17
|
it "should give an error message" do
|
18
|
-
auth_check.should_receive(:perform).and_return(
|
19
|
-
auth_check.perform_with_result.should eq [
|
18
|
+
auth_check.should_receive(:perform).and_return("402")
|
19
|
+
auth_check.perform_with_result.should eq ["402", "Could not confirm authorization: 402"]
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
@@ -24,7 +24,7 @@ describe Appsignal::AuthCheck do
|
|
24
24
|
before do
|
25
25
|
@transmitter = double
|
26
26
|
Appsignal::Transmitter.should_receive(:new).with(
|
27
|
-
|
27
|
+
"auth",
|
28
28
|
kind_of(Appsignal::Config)
|
29
29
|
).and_return(@transmitter)
|
30
30
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
if DependencyHelper.capistrano2_present?
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
2
|
+
require "capistrano"
|
3
|
+
require "capistrano/configuration"
|
4
|
+
require "appsignal/capistrano"
|
5
5
|
|
6
6
|
describe "Capistrano 2 integration" do
|
7
7
|
let(:out_stream) { std_stream }
|
@@ -9,11 +9,11 @@ if DependencyHelper.capistrano2_present?
|
|
9
9
|
let(:config) { project_fixture_config }
|
10
10
|
let(:capistrano_config) do
|
11
11
|
Capistrano::Configuration.new.tap do |c|
|
12
|
-
c.set(:rails_env,
|
13
|
-
c.set(:repository,
|
14
|
-
c.set(:deploy_to,
|
15
|
-
c.set(:current_release,
|
16
|
-
c.set(:current_revision,
|
12
|
+
c.set(:rails_env, "production")
|
13
|
+
c.set(:repository, "master")
|
14
|
+
c.set(:deploy_to, "/home/username/app")
|
15
|
+
c.set(:current_release, "")
|
16
|
+
c.set(:current_revision, "503ce0923ed177a3ce000005")
|
17
17
|
c.dry_run = false
|
18
18
|
end
|
19
19
|
end
|
@@ -21,18 +21,18 @@ if DependencyHelper.capistrano2_present?
|
|
21
21
|
|
22
22
|
def run
|
23
23
|
capture_stdout(out_stream) do
|
24
|
-
capistrano_config.find_and_execute_task(
|
24
|
+
capistrano_config.find_and_execute_task("appsignal:deploy")
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
28
28
|
it "should have a deploy task" do
|
29
|
-
capistrano_config.find_task(
|
29
|
+
capistrano_config.find_task("appsignal:deploy").should_not be_nil
|
30
30
|
end
|
31
31
|
|
32
32
|
describe "appsignal:deploy task" do
|
33
33
|
before do
|
34
|
-
ENV[
|
35
|
-
ENV[
|
34
|
+
ENV["USER"] = "batman"
|
35
|
+
ENV["PWD"] = project_fixture_path
|
36
36
|
end
|
37
37
|
|
38
38
|
context "config" do
|
@@ -43,7 +43,7 @@ if DependencyHelper.capistrano2_present?
|
|
43
43
|
it "should be instantiated with the right params" do
|
44
44
|
Appsignal::Config.should_receive(:new).with(
|
45
45
|
project_fixture_path,
|
46
|
-
|
46
|
+
"production",
|
47
47
|
{},
|
48
48
|
kind_of(Logger)
|
49
49
|
)
|
@@ -51,14 +51,14 @@ if DependencyHelper.capistrano2_present?
|
|
51
51
|
|
52
52
|
context "when appsignal_config is available" do
|
53
53
|
before do
|
54
|
-
capistrano_config.set(:appsignal_config, :name =>
|
54
|
+
capistrano_config.set(:appsignal_config, :name => "AppName")
|
55
55
|
end
|
56
56
|
|
57
57
|
it "should be instantiated with the right params" do
|
58
58
|
Appsignal::Config.should_receive(:new).with(
|
59
59
|
project_fixture_path,
|
60
|
-
|
61
|
-
{:name =>
|
60
|
+
"production",
|
61
|
+
{ :name => "AppName" },
|
62
62
|
kind_of(Logger)
|
63
63
|
)
|
64
64
|
end
|
@@ -66,14 +66,14 @@ if DependencyHelper.capistrano2_present?
|
|
66
66
|
context "when rack_env is used instead of rails_env" do
|
67
67
|
before do
|
68
68
|
capistrano_config.unset(:rails_env)
|
69
|
-
capistrano_config.set(:rack_env,
|
69
|
+
capistrano_config.set(:rack_env, "rack_production")
|
70
70
|
end
|
71
71
|
|
72
72
|
it "should be instantiated with the right params" do
|
73
73
|
Appsignal::Config.should_receive(:new).with(
|
74
74
|
project_fixture_path,
|
75
|
-
|
76
|
-
{:name =>
|
75
|
+
"rack_production",
|
76
|
+
{ :name => "AppName" },
|
77
77
|
kind_of(Logger)
|
78
78
|
)
|
79
79
|
end
|
@@ -82,14 +82,14 @@ if DependencyHelper.capistrano2_present?
|
|
82
82
|
context "when stage is used instead of rack_env / rails_env" do
|
83
83
|
before do
|
84
84
|
capistrano_config.unset(:rails_env)
|
85
|
-
capistrano_config.set(:stage,
|
85
|
+
capistrano_config.set(:stage, "stage_production")
|
86
86
|
end
|
87
87
|
|
88
88
|
it "should be instantiated with the right params" do
|
89
89
|
Appsignal::Config.should_receive(:new).with(
|
90
90
|
project_fixture_path,
|
91
|
-
|
92
|
-
{:name =>
|
91
|
+
"stage_production",
|
92
|
+
{ :name => "AppName" },
|
93
93
|
kind_of(Logger)
|
94
94
|
)
|
95
95
|
end
|
@@ -97,16 +97,16 @@ if DependencyHelper.capistrano2_present?
|
|
97
97
|
|
98
98
|
context "when appsignal_env is set" do
|
99
99
|
before do
|
100
|
-
capistrano_config.set(:rack_env,
|
101
|
-
capistrano_config.set(:stage,
|
102
|
-
capistrano_config.set(:appsignal_env,
|
100
|
+
capistrano_config.set(:rack_env, "rack_production")
|
101
|
+
capistrano_config.set(:stage, "stage_production")
|
102
|
+
capistrano_config.set(:appsignal_env, "appsignal_production")
|
103
103
|
end
|
104
104
|
|
105
105
|
it "should prefer the appsignal_env rather than stage, rails_env and rack_env" do
|
106
106
|
Appsignal::Config.should_receive(:new).with(
|
107
107
|
project_fixture_path,
|
108
|
-
|
109
|
-
{:name =>
|
108
|
+
"appsignal_production",
|
109
|
+
{ :name => "AppName" },
|
110
110
|
kind_of(Logger)
|
111
111
|
)
|
112
112
|
end
|
@@ -118,13 +118,13 @@ if DependencyHelper.capistrano2_present?
|
|
118
118
|
|
119
119
|
describe "markers" do
|
120
120
|
def stub_marker_request(data = {})
|
121
|
-
stub_api_request config,
|
121
|
+
stub_api_request config, "markers", marker_data.merge(data)
|
122
122
|
end
|
123
123
|
|
124
124
|
let(:marker_data) do
|
125
125
|
{
|
126
|
-
:revision =>
|
127
|
-
:user =>
|
126
|
+
:revision => "503ce0923ed177a3ce000005",
|
127
|
+
:user => "batman"
|
128
128
|
}
|
129
129
|
end
|
130
130
|
|
@@ -134,21 +134,21 @@ if DependencyHelper.capistrano2_present?
|
|
134
134
|
run
|
135
135
|
|
136
136
|
expect(output).to include \
|
137
|
-
|
138
|
-
|
137
|
+
"Notifying AppSignal of deploy with: revision: 503ce0923ed177a3ce000005, user: batman",
|
138
|
+
"AppSignal has been notified of this deploy!"
|
139
139
|
end
|
140
140
|
|
141
141
|
context "with overridden revision" do
|
142
142
|
before do
|
143
|
-
capistrano_config.set(:appsignal_revision,
|
144
|
-
stub_marker_request(:revision =>
|
143
|
+
capistrano_config.set(:appsignal_revision, "abc123")
|
144
|
+
stub_marker_request(:revision => "abc123").to_return(:status => 200)
|
145
145
|
run
|
146
146
|
end
|
147
147
|
|
148
148
|
it "transmits the overriden revision" do
|
149
149
|
expect(output).to include \
|
150
|
-
|
151
|
-
|
150
|
+
"Notifying AppSignal of deploy with: revision: abc123, user: batman",
|
151
|
+
"AppSignal has been notified of this deploy!"
|
152
152
|
end
|
153
153
|
end
|
154
154
|
|
@@ -160,9 +160,9 @@ if DependencyHelper.capistrano2_present?
|
|
160
160
|
|
161
161
|
it "does not transmit marker" do
|
162
162
|
expect(output).to include \
|
163
|
-
|
164
|
-
|
165
|
-
expect(output).to_not include
|
163
|
+
"Notifying AppSignal of deploy with: revision: 503ce0923ed177a3ce000005, user: batman",
|
164
|
+
"Something went wrong while trying to notify AppSignal:"
|
165
|
+
expect(output).to_not include "AppSignal has been notified of this deploy!"
|
166
166
|
end
|
167
167
|
end
|
168
168
|
|
@@ -174,14 +174,14 @@ if DependencyHelper.capistrano2_present?
|
|
174
174
|
|
175
175
|
it "does not transmit marker" do
|
176
176
|
expect(output).to include \
|
177
|
-
|
177
|
+
"Dry run: AppSignal deploy marker not actually sent."
|
178
178
|
end
|
179
179
|
end
|
180
180
|
end
|
181
181
|
|
182
182
|
context "when not active for this environment" do
|
183
183
|
before do
|
184
|
-
capistrano_config.set(:rails_env,
|
184
|
+
capistrano_config.set(:rails_env, "nonsense")
|
185
185
|
run
|
186
186
|
end
|
187
187
|
|
@@ -1,11 +1,10 @@
|
|
1
1
|
if DependencyHelper.capistrano3_present?
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
5
|
-
|
6
|
-
include Capistrano::DSL
|
2
|
+
require "capistrano/all"
|
3
|
+
require "capistrano/deploy"
|
4
|
+
require "appsignal/capistrano"
|
7
5
|
|
8
6
|
describe "Capistrano 3 integration" do
|
7
|
+
let(:capistrano) { Class.new.extend(Capistrano::DSL) }
|
9
8
|
let(:config) { project_fixture_config }
|
10
9
|
let(:out_stream) { std_stream }
|
11
10
|
let(:output) { out_stream.read }
|
@@ -15,36 +14,36 @@ if DependencyHelper.capistrano3_present?
|
|
15
14
|
Capistrano::Configuration.env.tap do |c|
|
16
15
|
c.set(:log_level, :error)
|
17
16
|
c.set(:logger, logger)
|
18
|
-
c.set(:rails_env,
|
19
|
-
c.set(:repository,
|
20
|
-
c.set(:deploy_to,
|
21
|
-
c.set(:current_release,
|
22
|
-
c.set(:current_revision,
|
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")
|
23
22
|
end
|
24
23
|
end
|
25
|
-
before { Rake::Task[
|
24
|
+
before { Rake::Task["appsignal:deploy"].reenable }
|
26
25
|
|
27
26
|
def run
|
28
27
|
capture_std_streams(out_stream, out_stream) do
|
29
|
-
invoke(
|
28
|
+
capistrano.invoke("appsignal:deploy")
|
30
29
|
end
|
31
30
|
end
|
32
31
|
|
33
32
|
it "should have a deploy task" do
|
34
|
-
Rake::Task.task_defined?(
|
33
|
+
Rake::Task.task_defined?("appsignal:deploy").should be_true
|
35
34
|
end
|
36
35
|
|
37
36
|
describe "appsignal:deploy task" do
|
38
37
|
before do
|
39
|
-
ENV[
|
40
|
-
ENV[
|
38
|
+
ENV["USER"] = "batman"
|
39
|
+
ENV["PWD"] = project_fixture_path
|
41
40
|
end
|
42
41
|
|
43
42
|
context "config" do
|
44
43
|
it "should be instantiated with the right params" do
|
45
44
|
Appsignal::Config.should_receive(:new).with(
|
46
45
|
project_fixture_path,
|
47
|
-
|
46
|
+
"production",
|
48
47
|
{},
|
49
48
|
kind_of(Logger)
|
50
49
|
)
|
@@ -52,14 +51,14 @@ if DependencyHelper.capistrano3_present?
|
|
52
51
|
|
53
52
|
context "when appsignal_config is available" do
|
54
53
|
before do
|
55
|
-
capistrano_config.set(:appsignal_config, :name =>
|
54
|
+
capistrano_config.set(:appsignal_config, :name => "AppName")
|
56
55
|
end
|
57
56
|
|
58
57
|
it "should be instantiated with the right params" do
|
59
58
|
Appsignal::Config.should_receive(:new).with(
|
60
59
|
project_fixture_path,
|
61
|
-
|
62
|
-
{:name =>
|
60
|
+
"production",
|
61
|
+
{ :name => "AppName" },
|
63
62
|
kind_of(Logger)
|
64
63
|
)
|
65
64
|
end
|
@@ -67,14 +66,14 @@ if DependencyHelper.capistrano3_present?
|
|
67
66
|
context "when rack_env is the only env set" do
|
68
67
|
before do
|
69
68
|
capistrano_config.delete(:rails_env)
|
70
|
-
capistrano_config.set(:rack_env,
|
69
|
+
capistrano_config.set(:rack_env, "rack_production")
|
71
70
|
end
|
72
71
|
|
73
72
|
it "should be instantiated with the rack env" do
|
74
73
|
Appsignal::Config.should_receive(:new).with(
|
75
74
|
project_fixture_path,
|
76
|
-
|
77
|
-
{:name =>
|
75
|
+
"rack_production",
|
76
|
+
{ :name => "AppName" },
|
78
77
|
kind_of(Logger)
|
79
78
|
)
|
80
79
|
end
|
@@ -82,15 +81,15 @@ if DependencyHelper.capistrano3_present?
|
|
82
81
|
|
83
82
|
context "when stage is set" do
|
84
83
|
before do
|
85
|
-
capistrano_config.set(:rack_env,
|
86
|
-
capistrano_config.set(:stage,
|
84
|
+
capistrano_config.set(:rack_env, "rack_production")
|
85
|
+
capistrano_config.set(:stage, "stage_production")
|
87
86
|
end
|
88
87
|
|
89
88
|
it "should prefer the stage rather than rails_env and rack_env" do
|
90
89
|
Appsignal::Config.should_receive(:new).with(
|
91
90
|
project_fixture_path,
|
92
|
-
|
93
|
-
{:name =>
|
91
|
+
"stage_production",
|
92
|
+
{ :name => "AppName" },
|
94
93
|
kind_of(Logger)
|
95
94
|
)
|
96
95
|
end
|
@@ -98,16 +97,16 @@ if DependencyHelper.capistrano3_present?
|
|
98
97
|
|
99
98
|
context "when appsignal_env is set" do
|
100
99
|
before do
|
101
|
-
capistrano_config.set(:rack_env,
|
102
|
-
capistrano_config.set(:stage,
|
103
|
-
capistrano_config.set(:appsignal_env,
|
100
|
+
capistrano_config.set(:rack_env, "rack_production")
|
101
|
+
capistrano_config.set(:stage, "stage_production")
|
102
|
+
capistrano_config.set(:appsignal_env, "appsignal_production")
|
104
103
|
end
|
105
104
|
|
106
105
|
it "should prefer the appsignal_env rather than stage, rails_env and rack_env" do
|
107
106
|
Appsignal::Config.should_receive(:new).with(
|
108
107
|
project_fixture_path,
|
109
|
-
|
110
|
-
{:name =>
|
108
|
+
"appsignal_production",
|
109
|
+
{ :name => "AppName" },
|
111
110
|
kind_of(Logger)
|
112
111
|
)
|
113
112
|
end
|
@@ -119,13 +118,13 @@ if DependencyHelper.capistrano3_present?
|
|
119
118
|
|
120
119
|
describe "markers" do
|
121
120
|
def stub_marker_request(data = {})
|
122
|
-
stub_api_request config,
|
121
|
+
stub_api_request config, "markers", marker_data.merge(data)
|
123
122
|
end
|
124
123
|
|
125
124
|
let(:marker_data) do
|
126
125
|
{
|
127
|
-
:revision =>
|
128
|
-
:user =>
|
126
|
+
:revision => "503ce0923ed177a3ce000005",
|
127
|
+
:user => "batman"
|
129
128
|
}
|
130
129
|
end
|
131
130
|
|
@@ -135,21 +134,21 @@ if DependencyHelper.capistrano3_present?
|
|
135
134
|
run
|
136
135
|
|
137
136
|
expect(output).to include \
|
138
|
-
|
139
|
-
|
137
|
+
"Notifying AppSignal of deploy with: revision: 503ce0923ed177a3ce000005, user: batman",
|
138
|
+
"AppSignal has been notified of this deploy!"
|
140
139
|
end
|
141
140
|
|
142
141
|
context "with overridden revision" do
|
143
142
|
before do
|
144
|
-
capistrano_config.set(:appsignal_revision,
|
145
|
-
stub_marker_request(:revision =>
|
143
|
+
capistrano_config.set(:appsignal_revision, "abc123")
|
144
|
+
stub_marker_request(:revision => "abc123").to_return(:status => 200)
|
146
145
|
run
|
147
146
|
end
|
148
147
|
|
149
148
|
it "transmits the overriden revision" do
|
150
149
|
expect(output).to include \
|
151
|
-
|
152
|
-
|
150
|
+
"Notifying AppSignal of deploy with: revision: abc123, user: batman",
|
151
|
+
"AppSignal has been notified of this deploy!"
|
153
152
|
end
|
154
153
|
end
|
155
154
|
|
@@ -161,16 +160,16 @@ if DependencyHelper.capistrano3_present?
|
|
161
160
|
|
162
161
|
it "does not transmit marker" do
|
163
162
|
expect(output).to include \
|
164
|
-
|
165
|
-
|
166
|
-
expect(output).to_not include
|
163
|
+
"Notifying AppSignal of deploy with: revision: 503ce0923ed177a3ce000005, user: batman",
|
164
|
+
"Something went wrong while trying to notify AppSignal:"
|
165
|
+
expect(output).to_not include "AppSignal has been notified of this deploy!"
|
167
166
|
end
|
168
167
|
end
|
169
168
|
end
|
170
169
|
|
171
170
|
context "when not active for this environment" do
|
172
171
|
before do
|
173
|
-
capistrano_config.set(:rails_env,
|
172
|
+
capistrano_config.set(:rails_env, "nonsense")
|
174
173
|
run
|
175
174
|
end
|
176
175
|
|