appsignal 1.1.0.beta.12 → 1.1.0.beta.13
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -2
- data/Rakefile +0 -2
- data/gemfiles/grape.gemfile +0 -2
- data/gemfiles/padrino.gemfile +0 -2
- data/gemfiles/rails-3.2.gemfile +0 -2
- data/gemfiles/rails-4.0.gemfile +1 -1
- data/gemfiles/rails-4.1.gemfile +1 -1
- data/gemfiles/rails-4.2.gemfile +1 -1
- data/gemfiles/rails-5.0.gemfile +0 -2
- data/lib/appsignal/auth_check.rb +1 -1
- data/lib/appsignal/cli.rb +13 -42
- data/lib/appsignal/cli/diagnose.rb +72 -0
- data/lib/appsignal/cli/install.rb +296 -0
- data/lib/appsignal/cli/notify_of_deploy.rb +41 -0
- data/lib/appsignal/config.rb +6 -1
- data/lib/appsignal/event_formatter/active_record/sql_formatter.rb +1 -5
- data/lib/appsignal/integrations/capistrano/careful_logger.rb +1 -0
- data/lib/appsignal/integrations/railtie.rb +0 -4
- data/lib/appsignal/version.rb +1 -1
- data/{lib/generators/appsignal/templates/appsignal.yml → resources/appsignal.yml.erb} +4 -4
- data/spec/lib/appsignal/cli/diagnose_spec.rb +27 -0
- data/spec/lib/appsignal/cli/install_spec.rb +438 -0
- data/spec/lib/appsignal/cli/notify_of_deploy_spec.rb +128 -0
- data/spec/lib/appsignal/cli_spec.rb +23 -126
- data/spec/lib/appsignal/config_spec.rb +7 -2
- data/spec/lib/appsignal/integrations/sinatra_spec.rb +1 -12
- data/spec/lib/appsignal_spec.rb +14 -7
- data/spec/spec_helper.rb +16 -4
- data/spec/support/project_fixture/config/application.rb +0 -0
- data/spec/support/project_fixture/config/environments/development.rb +0 -0
- data/spec/support/project_fixture/config/environments/production.rb +0 -0
- data/spec/support/project_fixture/config/environments/test.rb +0 -0
- metadata +19 -6
- data/lib/generators/appsignal/USAGE +0 -8
- data/lib/generators/appsignal/appsignal_generator.rb +0 -64
- data/spec/lib/generators/appsignal/appsignal_generator_spec.rb +0 -156
@@ -0,0 +1,128 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'appsignal/cli'
|
3
|
+
|
4
|
+
describe Appsignal::CLI::NotifyOfDeploy do
|
5
|
+
let(:out_stream) { StringIO.new }
|
6
|
+
let(:cli) { Appsignal::CLI::NotifyOfDeploy }
|
7
|
+
let(:config) { Appsignal::Config.new(project_fixture_path, {}) }
|
8
|
+
let(:marker_data) { {:revision => 'aaaaa', :user => 'thijs', :environment => 'production'} }
|
9
|
+
before do
|
10
|
+
@original_stdout = $stdout
|
11
|
+
$stdout = out_stream
|
12
|
+
config.stub(:active? => true)
|
13
|
+
end
|
14
|
+
after do
|
15
|
+
$stdout = @original_stdout
|
16
|
+
end
|
17
|
+
|
18
|
+
describe ".run" do
|
19
|
+
it "should validate that the config has been loaded and all options have been supplied" do
|
20
|
+
cli.should_receive(:validate_active_config)
|
21
|
+
cli.should_receive(:validate_required_options).with(
|
22
|
+
{},
|
23
|
+
[:revision, :user, :environment]
|
24
|
+
)
|
25
|
+
Appsignal::Marker.should_receive(:new).and_return(double(:transmit => true))
|
26
|
+
|
27
|
+
cli.run({}, config)
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should notify of a deploy" do
|
31
|
+
marker = double
|
32
|
+
Appsignal::Marker.should_receive(:new).with(
|
33
|
+
{
|
34
|
+
:revision => 'aaaaa',
|
35
|
+
:user => 'thijs'
|
36
|
+
},
|
37
|
+
kind_of(Appsignal::Config),
|
38
|
+
nil
|
39
|
+
).and_return(marker)
|
40
|
+
marker.should_receive(:transmit)
|
41
|
+
|
42
|
+
cli.run(marker_data, config)
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should notify of a deploy with no config file and a name specified" do
|
46
|
+
ENV['PWD'] = '/nonsense'
|
47
|
+
ENV['APPSIGNAL_PUSH_API_KEY'] = 'key'
|
48
|
+
|
49
|
+
marker = double
|
50
|
+
Appsignal::Marker.should_receive(:new).with(
|
51
|
+
{
|
52
|
+
:revision => 'aaaaa',
|
53
|
+
:user => 'thijs'
|
54
|
+
},
|
55
|
+
kind_of(Appsignal::Config),
|
56
|
+
nil
|
57
|
+
).and_return(marker)
|
58
|
+
marker.should_receive(:transmit)
|
59
|
+
|
60
|
+
cli.run(marker_data, config)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
describe "#validate_required_options" do
|
65
|
+
let(:required_options) { [:option_1, :option_2, :option_3] }
|
66
|
+
|
67
|
+
it "should do nothing with all options supplied" do
|
68
|
+
cli.send(
|
69
|
+
:validate_required_options,
|
70
|
+
{
|
71
|
+
:option_1 => 1,
|
72
|
+
:option_2 => 2,
|
73
|
+
:option_3 => 3
|
74
|
+
},
|
75
|
+
required_options
|
76
|
+
)
|
77
|
+
out_stream.string.should be_empty
|
78
|
+
end
|
79
|
+
|
80
|
+
it "should print a message with one option missing and exit" do
|
81
|
+
lambda {
|
82
|
+
cli.send(
|
83
|
+
:validate_required_options,
|
84
|
+
{
|
85
|
+
:option_1 => 1,
|
86
|
+
:option_2 => 2
|
87
|
+
},
|
88
|
+
required_options
|
89
|
+
)
|
90
|
+
}.should raise_error(SystemExit)
|
91
|
+
out_stream.string.should include('Missing options: option_3')
|
92
|
+
end
|
93
|
+
|
94
|
+
it "should print a message with multiple options missing and exit" do
|
95
|
+
lambda {
|
96
|
+
cli.send(
|
97
|
+
:validate_required_options,
|
98
|
+
{
|
99
|
+
:option_1 => 1,
|
100
|
+
:option_2 => ''
|
101
|
+
},
|
102
|
+
required_options
|
103
|
+
)
|
104
|
+
}.should raise_error(SystemExit)
|
105
|
+
out_stream.string.should include("Missing options: option_2, option_3")
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
describe "#validate_active_config" do
|
110
|
+
context "when config is present" do
|
111
|
+
it "should do nothing" do
|
112
|
+
cli.send(:validate_active_config, config)
|
113
|
+
out_stream.string.should be_empty
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
context "when config is not active" do
|
118
|
+
before { config.stub(:active? => false) }
|
119
|
+
|
120
|
+
it "should print a message and exit" do
|
121
|
+
lambda {
|
122
|
+
cli.send(:validate_active_config, config)
|
123
|
+
}.should raise_error(SystemExit)
|
124
|
+
out_stream.string.should include('Exiting: No config file or push api key env var found')
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
@@ -8,20 +8,12 @@ describe Appsignal::CLI do
|
|
8
8
|
@original_stdout = $stdout
|
9
9
|
$stdout = out_stream
|
10
10
|
ENV['PWD'] = project_fixture_path
|
11
|
-
cli.config = nil
|
12
|
-
cli.initial_config = {}
|
13
11
|
cli.options = {:environment => 'production'}
|
14
12
|
end
|
15
13
|
after do
|
16
14
|
$stdout = @original_stdout
|
17
15
|
end
|
18
16
|
|
19
|
-
describe "#logger" do
|
20
|
-
it "should be a logger" do
|
21
|
-
cli.logger.should be_instance_of(Logger)
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
17
|
describe "#config" do
|
26
18
|
subject { cli.config }
|
27
19
|
|
@@ -36,7 +28,7 @@ describe Appsignal::CLI do
|
|
36
28
|
}.should raise_error(SystemExit)
|
37
29
|
|
38
30
|
out_stream.string.should include 'appsignal <command> [options]'
|
39
|
-
out_stream.string.should include 'Available commands: notify_of_deploy'
|
31
|
+
out_stream.string.should include 'Available commands: diagnose, install, notify_of_deploy'
|
40
32
|
end
|
41
33
|
end
|
42
34
|
|
@@ -60,51 +52,36 @@ describe Appsignal::CLI do
|
|
60
52
|
"appsignal -h to see the help"
|
61
53
|
end
|
62
54
|
|
63
|
-
describe "
|
64
|
-
it "should
|
65
|
-
|
66
|
-
cli.should_receive(:validate_required_options).with(
|
67
|
-
[:revision, :user, :environment]
|
68
|
-
)
|
69
|
-
Appsignal::Marker.should_receive(:new).and_return(double(:transmit => true))
|
55
|
+
describe "diagnose" do
|
56
|
+
it "should call Appsignal::Diagnose.install" do
|
57
|
+
Appsignal::CLI::Diagnose.should_receive(:run)
|
70
58
|
|
71
|
-
cli.
|
59
|
+
cli.run([
|
60
|
+
'diagnose'
|
61
|
+
])
|
72
62
|
end
|
63
|
+
end
|
73
64
|
|
74
|
-
|
75
|
-
|
76
|
-
Appsignal::
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
},
|
81
|
-
kind_of(Appsignal::Config),
|
82
|
-
kind_of(Logger)
|
83
|
-
).and_return(marker)
|
84
|
-
marker.should_receive(:transmit)
|
65
|
+
describe "install" do
|
66
|
+
it "should call Appsignal::Install.install" do
|
67
|
+
Appsignal::CLI::Install.should_receive(:run).with(
|
68
|
+
'api-key',
|
69
|
+
instance_of(Appsignal::Config)
|
70
|
+
)
|
85
71
|
|
86
72
|
cli.run([
|
87
|
-
'
|
88
|
-
'
|
89
|
-
'--user=thijs',
|
90
|
-
'--environment=production'
|
73
|
+
'install',
|
74
|
+
'api-key'
|
91
75
|
])
|
92
76
|
end
|
77
|
+
end
|
93
78
|
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
{
|
101
|
-
:revision => 'aaaaa',
|
102
|
-
:user => 'thijs'
|
103
|
-
},
|
104
|
-
kind_of(Appsignal::Config),
|
105
|
-
kind_of(Logger)
|
106
|
-
).and_return(marker)
|
107
|
-
marker.should_receive(:transmit)
|
79
|
+
describe "notify_of_deploy" do
|
80
|
+
it "should call Appsignal::Install.install" do
|
81
|
+
Appsignal::CLI::NotifyOfDeploy.should_receive(:run).with(
|
82
|
+
{:revision=>"aaaaa", :user=>"thijs", :environment=>"production"},
|
83
|
+
instance_of(Appsignal::Config)
|
84
|
+
)
|
108
85
|
|
109
86
|
cli.run([
|
110
87
|
'notify_of_deploy',
|
@@ -113,86 +90,6 @@ describe Appsignal::CLI do
|
|
113
90
|
'--user=thijs',
|
114
91
|
'--environment=production'
|
115
92
|
])
|
116
|
-
|
117
|
-
cli.config[:name].should == 'project-production'
|
118
|
-
end
|
119
|
-
end
|
120
|
-
|
121
|
-
# protected
|
122
|
-
|
123
|
-
describe "#validate_required_options" do
|
124
|
-
let(:required_options) { [:option_1, :option_2, :option_3] }
|
125
|
-
|
126
|
-
it "should do nothing with all options supplied" do
|
127
|
-
cli.options = {
|
128
|
-
:option_1 => 1,
|
129
|
-
:option_2 => 2,
|
130
|
-
:option_3 => 3
|
131
|
-
}
|
132
|
-
cli.send(
|
133
|
-
:validate_required_options,
|
134
|
-
required_options
|
135
|
-
)
|
136
|
-
out_stream.string.should be_empty
|
137
|
-
end
|
138
|
-
|
139
|
-
it "should print a message with one option missing and exit" do
|
140
|
-
cli.options = {
|
141
|
-
:option_1 => 1,
|
142
|
-
:option_2 => 2
|
143
|
-
}
|
144
|
-
lambda {
|
145
|
-
cli.send(
|
146
|
-
:validate_required_options,
|
147
|
-
required_options
|
148
|
-
)
|
149
|
-
}.should raise_error(SystemExit)
|
150
|
-
out_stream.string.should include('Missing options: option_3')
|
151
|
-
end
|
152
|
-
|
153
|
-
it "should print a message with multiple options missing and exit" do
|
154
|
-
cli.options = {
|
155
|
-
:option_1 => 1,
|
156
|
-
:option_2 => ''
|
157
|
-
}
|
158
|
-
lambda {
|
159
|
-
cli.send(
|
160
|
-
:validate_required_options,
|
161
|
-
required_options
|
162
|
-
)
|
163
|
-
}.should raise_error(SystemExit)
|
164
|
-
out_stream.string.should include("Missing options: option_2, option_3")
|
165
|
-
end
|
166
|
-
end
|
167
|
-
|
168
|
-
describe "#validate_active_config" do
|
169
|
-
context "when config is present" do
|
170
|
-
it "should do nothing" do
|
171
|
-
cli.send(:validate_active_config)
|
172
|
-
out_stream.string.should be_empty
|
173
|
-
end
|
174
|
-
end
|
175
|
-
|
176
|
-
context "when config is not present" do
|
177
|
-
before { cli.options = {:environment => 'nonsense'} }
|
178
|
-
|
179
|
-
it "should print a message and exit" do
|
180
|
-
lambda {
|
181
|
-
cli.send(:validate_active_config)
|
182
|
-
}.should raise_error(SystemExit)
|
183
|
-
out_stream.string.should include('Exiting: No config file or push api key env var found')
|
184
|
-
end
|
185
|
-
end
|
186
|
-
|
187
|
-
context "when config is not active" do
|
188
|
-
before { ENV['PWD'] = '/nonsense' }
|
189
|
-
|
190
|
-
it "should print a message and exit" do
|
191
|
-
lambda {
|
192
|
-
cli.send(:validate_active_config)
|
193
|
-
}.should raise_error(SystemExit)
|
194
|
-
out_stream.string.should include('Exiting: No config file or push api key env var found')
|
195
|
-
end
|
196
93
|
end
|
197
94
|
end
|
198
95
|
end
|
@@ -32,7 +32,7 @@ describe Appsignal::Config do
|
|
32
32
|
:enable_frontend_error_catching => false,
|
33
33
|
:frontend_error_catching_path => '/appsignal_error_catcher',
|
34
34
|
:enable_allocation_tracking => true,
|
35
|
-
:enable_gc_instrumentation =>
|
35
|
+
:enable_gc_instrumentation => false,
|
36
36
|
:running_in_container => false
|
37
37
|
}
|
38
38
|
end
|
@@ -65,11 +65,16 @@ describe Appsignal::Config do
|
|
65
65
|
end
|
66
66
|
end
|
67
67
|
|
68
|
-
describe "#[]" do
|
68
|
+
describe "#[]= and #[]" do
|
69
69
|
it "should get the value for an existing key" do
|
70
70
|
subject[:push_api_key].should == 'abc'
|
71
71
|
end
|
72
72
|
|
73
|
+
it "should change and get the value for an existing key" do
|
74
|
+
subject[:push_api_key] = 'abcde'
|
75
|
+
subject[:push_api_key].should == 'abcde'
|
76
|
+
end
|
77
|
+
|
73
78
|
it "should return nil for a non-existing key" do
|
74
79
|
subject[:nonsense].should be_nil
|
75
80
|
end
|
@@ -1,11 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
|
4
|
-
require 'sinatra'
|
5
|
-
rescue LoadError
|
6
|
-
end
|
7
|
-
|
8
|
-
if defined?(::Sinatra)
|
3
|
+
if sinatra_present? && !padrino_present?
|
9
4
|
ENV['APPSIGNAL_PUSH_API_KEY'] = 'key'
|
10
5
|
require 'appsignal/integrations/sinatra'
|
11
6
|
|
@@ -16,12 +11,6 @@ if defined?(::Sinatra)
|
|
16
11
|
it { should be_a Logger }
|
17
12
|
end
|
18
13
|
|
19
|
-
context "config" do
|
20
|
-
subject { Appsignal.config }
|
21
|
-
|
22
|
-
it { should be_a(Appsignal::Config) }
|
23
|
-
end
|
24
|
-
|
25
14
|
it "should have added the instrumentation middleware" do
|
26
15
|
Sinatra::Application.middleware.to_a.should include(
|
27
16
|
[Appsignal::Rack::SinatraInstrumentation, [], nil]
|
data/spec/lib/appsignal_spec.rb
CHANGED
@@ -72,12 +72,6 @@ describe Appsignal do
|
|
72
72
|
Appsignal.subscriber.should be_a(Appsignal::Subscriber)
|
73
73
|
end
|
74
74
|
|
75
|
-
it "should install event hooks" do
|
76
|
-
Appsignal::Extension.should_receive(:install_allocation_event_hook)
|
77
|
-
Appsignal::Extension.should_receive(:install_gc_event_hooks)
|
78
|
-
Appsignal.start
|
79
|
-
end
|
80
|
-
|
81
75
|
context "when not active for this environment" do
|
82
76
|
before { Appsignal.config = project_fixture_config('staging') }
|
83
77
|
|
@@ -96,7 +90,20 @@ describe Appsignal do
|
|
96
90
|
end
|
97
91
|
end
|
98
92
|
|
99
|
-
context "when allocation tracking and gc instrumentation
|
93
|
+
context "when allocation tracking and gc instrumentation have been enabled" do
|
94
|
+
before do
|
95
|
+
Appsignal.config.config_hash[:enable_allocation_tracking] = true
|
96
|
+
Appsignal.config.config_hash[:enable_gc_instrumentation] = true
|
97
|
+
end
|
98
|
+
|
99
|
+
it "should install event hooks" do
|
100
|
+
Appsignal::Extension.should_receive(:install_allocation_event_hook)
|
101
|
+
Appsignal::Extension.should_receive(:install_gc_event_hooks)
|
102
|
+
Appsignal.start
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
context "when allocation tracking and gc instrumentation have been disabled" do
|
100
107
|
before do
|
101
108
|
Appsignal.config.config_hash[:enable_allocation_tracking] = false
|
102
109
|
Appsignal.config.config_hash[:enable_gc_instrumentation] = false
|
data/spec/spec_helper.rb
CHANGED
@@ -69,6 +69,15 @@ rescue LoadError
|
|
69
69
|
false
|
70
70
|
end
|
71
71
|
|
72
|
+
def sinatra_present?
|
73
|
+
begin
|
74
|
+
require 'sinatra'
|
75
|
+
true
|
76
|
+
rescue LoadError
|
77
|
+
false
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
72
81
|
def padrino_present?
|
73
82
|
require 'padrino'
|
74
83
|
true
|
@@ -114,6 +123,11 @@ RSpec.configure do |config|
|
|
114
123
|
config.include TimeHelpers
|
115
124
|
config.include TransactionHelpers
|
116
125
|
|
126
|
+
config.before :all do
|
127
|
+
FileUtils.rm_rf(tmp_dir)
|
128
|
+
FileUtils.mkdir_p(tmp_dir)
|
129
|
+
end
|
130
|
+
|
117
131
|
config.before do
|
118
132
|
ENV['PWD'] = File.expand_path(File.join(File.dirname(__FILE__), '../'))
|
119
133
|
ENV['RAILS_ENV'] = 'test'
|
@@ -124,13 +138,11 @@ RSpec.configure do |config|
|
|
124
138
|
end
|
125
139
|
end
|
126
140
|
|
127
|
-
config.after do
|
128
|
-
Appsignal.logger = nil
|
129
|
-
end
|
130
|
-
|
131
141
|
config.after :all do
|
132
142
|
ActiveSupport::Notifications.notifier.clear_subscribers
|
133
143
|
FileUtils.rm_f(File.join(project_fixture_path, 'log/appsignal.log'))
|
144
|
+
Appsignal.config = nil
|
145
|
+
Appsignal.logger = nil
|
134
146
|
end
|
135
147
|
end
|
136
148
|
|