appsignal 2.0.3 → 2.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +1 -0
- data/CHANGELOG.md +22 -0
- data/README.md +9 -5
- data/appsignal.gemspec +1 -1
- data/ext/agent.yml +11 -11
- data/lib/appsignal.rb +8 -9
- data/lib/appsignal/cli.rb +12 -14
- data/lib/appsignal/cli/diagnose.rb +82 -31
- data/lib/appsignal/cli/helpers.rb +67 -0
- data/lib/appsignal/cli/install.rb +22 -69
- data/lib/appsignal/config.rb +3 -3
- data/lib/appsignal/integrations/padrino.rb +1 -1
- data/lib/appsignal/integrations/railtie.rb +1 -1
- data/lib/appsignal/integrations/sinatra.rb +1 -1
- data/lib/appsignal/version.rb +1 -1
- data/spec/lib/appsignal/capistrano2_spec.rb +18 -19
- data/spec/lib/appsignal/capistrano3_spec.rb +16 -17
- data/spec/lib/appsignal/cli/demo_spec.rb +4 -4
- data/spec/lib/appsignal/cli/diagnose_spec.rb +237 -88
- data/spec/lib/appsignal/cli/helpers_spec.rb +99 -0
- data/spec/lib/appsignal/cli/install_spec.rb +486 -352
- data/spec/lib/appsignal/cli/notify_of_deploy_spec.rb +5 -6
- data/spec/lib/appsignal/cli_spec.rb +24 -44
- data/spec/lib/appsignal/config_spec.rb +39 -8
- data/spec/lib/appsignal/demo_spec.rb +13 -8
- data/spec/lib/appsignal/hooks_spec.rb +3 -0
- data/spec/lib/appsignal/integrations/object_spec.rb +35 -26
- data/spec/lib/appsignal/marker_spec.rb +10 -14
- data/spec/lib/appsignal_spec.rb +83 -60
- data/spec/spec_helper.rb +8 -7
- data/spec/support/helpers/cli_helpers.rb +9 -0
- data/spec/support/helpers/std_streams_helper.rb +44 -13
- data/spec/support/helpers/transaction_helpers.rb +2 -2
- metadata +9 -6
@@ -6,10 +6,12 @@ require 'appsignal/demo'
|
|
6
6
|
module Appsignal
|
7
7
|
class CLI
|
8
8
|
class Install
|
9
|
+
extend CLI::Helpers
|
10
|
+
|
9
11
|
EXCLUDED_ENVIRONMENTS = ['test'].freeze
|
10
12
|
|
11
13
|
class << self
|
12
|
-
def run(push_api_key
|
14
|
+
def run(push_api_key)
|
13
15
|
puts
|
14
16
|
puts colorize "#######################################", :green
|
15
17
|
puts colorize "## Starting AppSignal Installer ##", :green
|
@@ -25,9 +27,9 @@ module Appsignal
|
|
25
27
|
puts " - Already signed up? Click 'New app' on the account overview page"
|
26
28
|
puts
|
27
29
|
puts colorize 'Exiting installer...', :red
|
28
|
-
return
|
30
|
+
return
|
29
31
|
end
|
30
|
-
|
32
|
+
config = new_config
|
31
33
|
config[:push_api_key] = push_api_key
|
32
34
|
|
33
35
|
print 'Validating API key'
|
@@ -37,31 +39,28 @@ module Appsignal
|
|
37
39
|
auth_check = Appsignal::AuthCheck.new(config)
|
38
40
|
unless auth_check.perform == '200'
|
39
41
|
puts "\n API key '#{config[:push_api_key]}' is not valid, please get a new one on https://appsignal.com"
|
40
|
-
return
|
42
|
+
return
|
41
43
|
end
|
42
|
-
rescue
|
44
|
+
rescue => e
|
43
45
|
puts " There was an error validating your API key:"
|
44
46
|
puts colorize "'#{e}'", :red
|
45
47
|
puts " Please try again"
|
46
|
-
return
|
48
|
+
return
|
47
49
|
end
|
48
50
|
puts colorize ' API key valid!', :green
|
49
51
|
puts
|
50
52
|
|
51
53
|
if installed_frameworks.include?(:rails)
|
52
54
|
install_for_rails(config)
|
53
|
-
elsif installed_frameworks.include?(:sinatra) && !installed_frameworks.include?(:padrino)
|
54
|
-
install_for_sinatra(config)
|
55
55
|
elsif installed_frameworks.include?(:padrino)
|
56
56
|
install_for_padrino(config)
|
57
57
|
elsif installed_frameworks.include?(:grape)
|
58
58
|
install_for_grape(config)
|
59
|
+
elsif installed_frameworks.include?(:sinatra)
|
60
|
+
install_for_sinatra(config)
|
59
61
|
else
|
60
62
|
puts "We could not detect which framework you are using. We'd be very grateful if you email us on support@appsignal.com with information about your setup."
|
61
|
-
return false
|
62
63
|
end
|
63
|
-
|
64
|
-
true
|
65
64
|
end
|
66
65
|
|
67
66
|
def install_for_rails(config)
|
@@ -93,16 +92,17 @@ module Appsignal
|
|
93
92
|
puts " Add this line beneath require 'sinatra':"
|
94
93
|
puts
|
95
94
|
puts " require 'appsignal/integrations/sinatra'"
|
95
|
+
puts
|
96
|
+
puts " You can find more information in the documentation:"
|
97
|
+
puts " http://docs.appsignal.com/getting-started/supported-frameworks.html#sinatra"
|
96
98
|
press_any_key
|
97
99
|
done_notice
|
98
100
|
end
|
99
101
|
|
100
102
|
def install_for_padrino(config)
|
101
103
|
puts 'Installing for Padrino'
|
102
|
-
|
103
104
|
config[:name] = required_input(' Enter application name: ')
|
104
105
|
puts
|
105
|
-
|
106
106
|
configure(config, ['development', 'production', 'staging'], true)
|
107
107
|
|
108
108
|
puts "Finish Padrino installation"
|
@@ -126,7 +126,7 @@ module Appsignal
|
|
126
126
|
configure(config, ['development', 'production', 'staging'], true)
|
127
127
|
|
128
128
|
puts "Manual Grape configuration needed"
|
129
|
-
puts " See the installation instructions
|
129
|
+
puts " See the installation instructions at:"
|
130
130
|
puts " http://docs.appsignal.com/getting-started/supported-frameworks.html#grape"
|
131
131
|
press_any_key
|
132
132
|
done_notice
|
@@ -147,56 +147,6 @@ module Appsignal
|
|
147
147
|
puts
|
148
148
|
end
|
149
149
|
|
150
|
-
def colorize(text, color)
|
151
|
-
return text if Gem.win_platform?
|
152
|
-
color_code = case color
|
153
|
-
when :red then 31
|
154
|
-
when :green then 32
|
155
|
-
when :yellow then 33
|
156
|
-
when :blue then 34
|
157
|
-
when :pink then 35
|
158
|
-
else 0
|
159
|
-
end
|
160
|
-
"\e[#{color_code}m#{text}\e[0m"
|
161
|
-
end
|
162
|
-
|
163
|
-
def periods
|
164
|
-
3.times do
|
165
|
-
print "."
|
166
|
-
sleep(0.5)
|
167
|
-
end
|
168
|
-
end
|
169
|
-
|
170
|
-
def press_any_key
|
171
|
-
puts
|
172
|
-
print " Ready? Press any key:"
|
173
|
-
STDIN.getch
|
174
|
-
puts
|
175
|
-
puts
|
176
|
-
end
|
177
|
-
|
178
|
-
def yes_or_no(prompt)
|
179
|
-
loop do
|
180
|
-
print prompt
|
181
|
-
input = gets.chomp
|
182
|
-
if input == 'y'
|
183
|
-
return true
|
184
|
-
elsif input == 'n'
|
185
|
-
return false
|
186
|
-
end
|
187
|
-
end
|
188
|
-
end
|
189
|
-
|
190
|
-
def required_input(prompt)
|
191
|
-
loop do
|
192
|
-
print prompt
|
193
|
-
input = gets.chomp
|
194
|
-
if input.length > 0
|
195
|
-
return input
|
196
|
-
end
|
197
|
-
end
|
198
|
-
end
|
199
|
-
|
200
150
|
def configure(config, environments, name_overwritten)
|
201
151
|
install_for_capistrano
|
202
152
|
|
@@ -207,8 +157,8 @@ module Appsignal
|
|
207
157
|
puts " (2) environment variables"
|
208
158
|
loop do
|
209
159
|
print " Choose (1/2): "
|
210
|
-
|
211
|
-
|
160
|
+
case ask_for_input
|
161
|
+
when '1'
|
212
162
|
puts
|
213
163
|
print "Writing config file"
|
214
164
|
periods
|
@@ -221,14 +171,13 @@ module Appsignal
|
|
221
171
|
)
|
222
172
|
puts
|
223
173
|
break
|
224
|
-
|
174
|
+
when '2'
|
225
175
|
ENV["APPSIGNAL_ACTIVE"] = "true"
|
226
176
|
ENV["APPSIGNAL_PUSH_API_KEY"] = config[:push_api_key]
|
227
177
|
ENV["APPSIGNAL_APP_NAME"] = config[:name]
|
228
178
|
|
229
179
|
puts
|
230
180
|
puts "Add the following environment variables to configure AppSignal:"
|
231
|
-
puts " export APPSIGNAL_ACTIVE=true"
|
232
181
|
puts " export APPSIGNAL_PUSH_API_KEY=#{config[:push_api_key]}"
|
233
182
|
if name_overwritten
|
234
183
|
puts " export APPSIGNAL_APP_NAME=#{config[:name]}"
|
@@ -291,7 +240,7 @@ module Appsignal
|
|
291
240
|
end
|
292
241
|
|
293
242
|
def rails_environments
|
294
|
-
|
243
|
+
Dir.glob(
|
295
244
|
File.join(Dir.pwd, 'config/environments/*.rb')
|
296
245
|
).map { |o| File.basename(o, ".rb") }.sort - EXCLUDED_ENVIRONMENTS
|
297
246
|
end
|
@@ -308,6 +257,10 @@ module Appsignal
|
|
308
257
|
FileUtils.mkdir_p(File.join(Dir.pwd, 'config'))
|
309
258
|
File.write(File.join(Dir.pwd, 'config/appsignal.yml'), config)
|
310
259
|
end
|
260
|
+
|
261
|
+
def new_config
|
262
|
+
Appsignal::Config.new(Dir.pwd, "")
|
263
|
+
end
|
311
264
|
end
|
312
265
|
end
|
313
266
|
end
|
data/lib/appsignal/config.rb
CHANGED
@@ -5,7 +5,7 @@ require 'socket'
|
|
5
5
|
|
6
6
|
module Appsignal
|
7
7
|
class Config
|
8
|
-
SYSTEM_TMP_DIR = '/tmp'
|
8
|
+
SYSTEM_TMP_DIR = File.realpath('/tmp')
|
9
9
|
DEFAULT_CONFIG = {
|
10
10
|
:debug => false,
|
11
11
|
:log => 'file',
|
@@ -63,7 +63,7 @@ module Appsignal
|
|
63
63
|
|
64
64
|
def initialize(root_path, env, initial_config={}, logger=Appsignal.logger)
|
65
65
|
@root_path = root_path
|
66
|
-
@env = env.to_s
|
66
|
+
@env = ENV.fetch("APPSIGNAL_APP_ENV".freeze, env.to_s)
|
67
67
|
@initial_config = initial_config
|
68
68
|
@logger = logger
|
69
69
|
@valid = false
|
@@ -90,7 +90,7 @@ module Appsignal
|
|
90
90
|
end
|
91
91
|
|
92
92
|
def log_file_path
|
93
|
-
path = config_hash[:log_path] || root_path
|
93
|
+
path = config_hash[:log_path] || root_path && File.join(root_path, 'log')
|
94
94
|
if path && File.writable?(path)
|
95
95
|
return File.join(File.realpath(path), 'appsignal.log')
|
96
96
|
end
|
@@ -6,7 +6,7 @@ Appsignal.logger.info("Loading Sinatra (#{Sinatra::VERSION}) integration")
|
|
6
6
|
app_settings = ::Sinatra::Application.settings
|
7
7
|
Appsignal.config = Appsignal::Config.new(
|
8
8
|
app_settings.root || Dir.pwd,
|
9
|
-
|
9
|
+
app_settings.environment
|
10
10
|
)
|
11
11
|
|
12
12
|
Appsignal.start_logger
|
data/lib/appsignal/version.rb
CHANGED
@@ -4,7 +4,8 @@ if DependencyHelper.capistrano2_present?
|
|
4
4
|
require 'appsignal/capistrano'
|
5
5
|
|
6
6
|
describe "Capistrano 2 integration" do
|
7
|
-
let(:out_stream) {
|
7
|
+
let(:out_stream) { std_stream }
|
8
|
+
let(:output) { out_stream.read }
|
8
9
|
let(:config) { project_fixture_config }
|
9
10
|
let(:capistrano_config) do
|
10
11
|
Capistrano::Configuration.new.tap do |c|
|
@@ -16,11 +17,12 @@ if DependencyHelper.capistrano2_present?
|
|
16
17
|
c.dry_run = false
|
17
18
|
end
|
18
19
|
end
|
19
|
-
before
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
20
|
+
before { Appsignal::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
|
24
26
|
end
|
25
27
|
|
26
28
|
it "should have a deploy task" do
|
@@ -111,9 +113,7 @@ if DependencyHelper.capistrano2_present?
|
|
111
113
|
end
|
112
114
|
end
|
113
115
|
|
114
|
-
after
|
115
|
-
capistrano_config.find_and_execute_task('appsignal:deploy')
|
116
|
-
end
|
116
|
+
after { run }
|
117
117
|
end
|
118
118
|
|
119
119
|
describe "markers" do
|
@@ -131,9 +131,9 @@ if DependencyHelper.capistrano2_present?
|
|
131
131
|
context "when active for this environment" do
|
132
132
|
it "transmits marker" do
|
133
133
|
stub_marker_request.to_return(:status => 200)
|
134
|
-
|
134
|
+
run
|
135
135
|
|
136
|
-
expect(
|
136
|
+
expect(output).to include \
|
137
137
|
'Notifying AppSignal of deploy with: revision: 503ce0923ed177a3ce000005, user: batman',
|
138
138
|
'AppSignal has been notified of this deploy!'
|
139
139
|
end
|
@@ -142,11 +142,11 @@ if DependencyHelper.capistrano2_present?
|
|
142
142
|
before do
|
143
143
|
capistrano_config.set(:appsignal_revision, 'abc123')
|
144
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
|
-
expect(
|
149
|
+
expect(output).to include \
|
150
150
|
'Notifying AppSignal of deploy with: revision: abc123, user: batman',
|
151
151
|
'AppSignal has been notified of this deploy!'
|
152
152
|
end
|
@@ -155,11 +155,10 @@ if DependencyHelper.capistrano2_present?
|
|
155
155
|
context "with failed request" do
|
156
156
|
before do
|
157
157
|
stub_marker_request.to_return(:status => 500)
|
158
|
-
|
158
|
+
run
|
159
159
|
end
|
160
160
|
|
161
161
|
it "does not transmit marker" do
|
162
|
-
output = out_stream.string
|
163
162
|
expect(output).to include \
|
164
163
|
'Notifying AppSignal of deploy with: revision: 503ce0923ed177a3ce000005, user: batman',
|
165
164
|
'Something went wrong while trying to notify AppSignal:'
|
@@ -170,11 +169,11 @@ if DependencyHelper.capistrano2_present?
|
|
170
169
|
context "when dry run" do
|
171
170
|
before do
|
172
171
|
capistrano_config.dry_run = true
|
173
|
-
|
172
|
+
run
|
174
173
|
end
|
175
174
|
|
176
175
|
it "does not transmit marker" do
|
177
|
-
expect(
|
176
|
+
expect(output).to include \
|
178
177
|
'Dry run: AppSignal deploy marker not actually sent.'
|
179
178
|
end
|
180
179
|
end
|
@@ -183,11 +182,11 @@ if DependencyHelper.capistrano2_present?
|
|
183
182
|
context "when not active for this environment" do
|
184
183
|
before do
|
185
184
|
capistrano_config.set(:rails_env, 'nonsense')
|
186
|
-
|
185
|
+
run
|
187
186
|
end
|
188
187
|
|
189
188
|
it "does not transmit marker" do
|
190
|
-
expect(
|
189
|
+
expect(output).to include \
|
191
190
|
"Not notifying of deploy, config is not active for environment: nonsense"
|
192
191
|
end
|
193
192
|
end
|
@@ -7,7 +7,8 @@ if DependencyHelper.capistrano3_present?
|
|
7
7
|
|
8
8
|
describe "Capistrano 3 integration" do
|
9
9
|
let(:config) { project_fixture_config }
|
10
|
-
let(:out_stream) {
|
10
|
+
let(:out_stream) { std_stream }
|
11
|
+
let(:output) { out_stream.read }
|
11
12
|
let(:logger) { Logger.new(out_stream) }
|
12
13
|
let!(:capistrano_config) do
|
13
14
|
Capistrano::Configuration.reset!
|
@@ -21,11 +22,12 @@ if DependencyHelper.capistrano3_present?
|
|
21
22
|
c.set(:current_revision, '503ce0923ed177a3ce000005')
|
22
23
|
end
|
23
24
|
end
|
24
|
-
before
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
25
|
+
before { Rake::Task['appsignal:deploy'].reenable }
|
26
|
+
|
27
|
+
def run
|
28
|
+
capture_std_streams(out_stream, out_stream) do
|
29
|
+
invoke('appsignal:deploy')
|
30
|
+
end
|
29
31
|
end
|
30
32
|
|
31
33
|
it "should have a deploy task" do
|
@@ -112,9 +114,7 @@ if DependencyHelper.capistrano3_present?
|
|
112
114
|
end
|
113
115
|
end
|
114
116
|
|
115
|
-
after
|
116
|
-
invoke('appsignal:deploy')
|
117
|
-
end
|
117
|
+
after { run }
|
118
118
|
end
|
119
119
|
|
120
120
|
describe "markers" do
|
@@ -132,9 +132,9 @@ if DependencyHelper.capistrano3_present?
|
|
132
132
|
context "when active for this environment" do
|
133
133
|
it "transmits marker" do
|
134
134
|
stub_marker_request.to_return(:status => 200)
|
135
|
-
|
135
|
+
run
|
136
136
|
|
137
|
-
expect(
|
137
|
+
expect(output).to include \
|
138
138
|
'Notifying AppSignal of deploy with: revision: 503ce0923ed177a3ce000005, user: batman',
|
139
139
|
'AppSignal has been notified of this deploy!'
|
140
140
|
end
|
@@ -143,11 +143,11 @@ if DependencyHelper.capistrano3_present?
|
|
143
143
|
before do
|
144
144
|
capistrano_config.set(:appsignal_revision, 'abc123')
|
145
145
|
stub_marker_request(:revision => 'abc123').to_return(:status => 200)
|
146
|
-
|
146
|
+
run
|
147
147
|
end
|
148
148
|
|
149
149
|
it "transmits the overriden revision" do
|
150
|
-
expect(
|
150
|
+
expect(output).to include \
|
151
151
|
'Notifying AppSignal of deploy with: revision: abc123, user: batman',
|
152
152
|
'AppSignal has been notified of this deploy!'
|
153
153
|
end
|
@@ -156,11 +156,10 @@ if DependencyHelper.capistrano3_present?
|
|
156
156
|
context "with failed request" do
|
157
157
|
before do
|
158
158
|
stub_marker_request.to_return(:status => 500)
|
159
|
-
|
159
|
+
run
|
160
160
|
end
|
161
161
|
|
162
162
|
it "does not transmit marker" do
|
163
|
-
output = out_stream.string
|
164
163
|
expect(output).to include \
|
165
164
|
'Notifying AppSignal of deploy with: revision: 503ce0923ed177a3ce000005, user: batman',
|
166
165
|
'Something went wrong while trying to notify AppSignal:'
|
@@ -172,11 +171,11 @@ if DependencyHelper.capistrano3_present?
|
|
172
171
|
context "when not active for this environment" do
|
173
172
|
before do
|
174
173
|
capistrano_config.set(:rails_env, 'nonsense')
|
175
|
-
|
174
|
+
run
|
176
175
|
end
|
177
176
|
|
178
177
|
it "should not send deploy marker" do
|
179
|
-
expect(
|
178
|
+
expect(output).to include \
|
180
179
|
"Not notifying of deploy, config is not active for environment: nonsense"
|
181
180
|
end
|
182
181
|
end
|
@@ -4,8 +4,9 @@ describe Appsignal::CLI::Demo do
|
|
4
4
|
include CLIHelpers
|
5
5
|
|
6
6
|
let(:options) { {} }
|
7
|
-
let(:out_stream) {
|
8
|
-
let(:output) { out_stream.
|
7
|
+
let(:out_stream) { std_stream }
|
8
|
+
let(:output) { out_stream.read }
|
9
|
+
before(:all) { Appsignal.stop }
|
9
10
|
before do
|
10
11
|
ENV.delete("APPSIGNAL_APP_ENV")
|
11
12
|
ENV.delete("RAILS_ENV")
|
@@ -13,7 +14,6 @@ describe Appsignal::CLI::Demo do
|
|
13
14
|
stub_api_request config, "auth"
|
14
15
|
end
|
15
16
|
after { Appsignal.config = nil }
|
16
|
-
around { |example| capture_stdout(out_stream) { example.run } }
|
17
17
|
|
18
18
|
def run
|
19
19
|
run_within_dir project_fixture_path
|
@@ -21,7 +21,7 @@ describe Appsignal::CLI::Demo do
|
|
21
21
|
|
22
22
|
def run_within_dir(chdir)
|
23
23
|
Dir.chdir chdir do
|
24
|
-
run_cli("demo", options)
|
24
|
+
capture_stdout(out_stream) { run_cli("demo", options) }
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|