skylight 1.0.0.beta4 → 1.0.0.beta5

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 17f5108640b6ddd60f1e126dda1e69005a2aa130
4
- data.tar.gz: ee06fc206e7a6b570db1e23c89b83c53362f4b5d
3
+ metadata.gz: 4cc154a1ba48ba4464fde882dc8fe46dc8134613
4
+ data.tar.gz: 4e6ad10d34bdc717cb73a3df2bb96ef6df8e7dd9
5
5
  SHA512:
6
- metadata.gz: adde4cc18fa3673ce4dd410e1446f6dad659884f88ad7a6095f0f1444a2ae28148d24679eda2ee2dd86c17f264ba90eeba2d9d51526436846f1dcd5a7d584d52
7
- data.tar.gz: 3548e5730c12bce02eee29f46a4a415b80ebe8f811c0fe83d584836d565d8bb435bc72488d730cd90b8b2bbc4e1fb09c8077beefca3bca91caf058d889cb3513
6
+ metadata.gz: f29f9b1c1a8fd5d33e27bb0aa9593fa2cda1971661f2bb2e485bbcb462a4c2a65cbc7ae4ac99effaae3d089810781ee89c3bdc5c68abaddd2e5f318b95b037d8
7
+ data.tar.gz: 8affdbb2297f3aa1d18927d7a63aefabab7a244c7884935d248fe96f5536aec494a35aab42a79112d7727405da0501753fa2c636eb91aa60f262d0cb7cf9ba2d
@@ -1,23 +1,36 @@
1
- ## 1.0.0.beta4 (April 22, 2016)
2
-
3
- * [FEATURE] Track formats separately in Rails endpoints. Turn on with `separate_formats: true`.
4
- * [BUGFIX] Finish Rack::Responses in Middleware as some Rack apps don't do this
5
-
6
- ## 1.0.0.beta3 (February 23, 2016)
7
-
8
- * [BUGFIX] Update Rust Agent with SQL improvements, including handling for arrays and WITH
9
- * [BUGFIX] Don't validate config on disabled environments
10
- * [IMPROVEMENT] Better message when config/skylight.yml already exists
11
- * [IMPROVEMENT] Test new Sinatra versions
12
-
13
- ## 1.0.0.beta2 (January 14, 2016)
14
-
15
- * [BUGFIX] Fix version format so Rust agent can load config.
16
-
17
- ## 1.0.0.beta1 (January 14, 2016) [YANKED]
18
-
19
- * [FEATURE] Deploy tracking support. Contact support@skylight.io to have this enabled for your account.
20
- * [BUGFIX] Correct documentation link in `skylight setup`.
1
+ ## 1.0.0-beta5 (June 29, 2016)
2
+
3
+ * [BETA FEATURE] Track separate segments for endpoints. Contact support@skylight.io to have this feature enabled for your account.
4
+ * [FEATURE] Initial 'skylight doctor' command
5
+ * [BREAKING] Removed old `skylight setup` without creation token
6
+ * [BREAKING] Remove Ruby based SQL lexer
7
+ * [IMPROVEMENT] Internal refactors
8
+ * [IMPROVEMENT] On Heroku, log to STDOUT instead of logfile
9
+ * [BUGFIX] Correctly pass 'false' config values to Rust agent
10
+
11
+ ## 0.10.5 (June 22, 2016)
12
+
13
+ * [BUGFIX] Fix issue with Grape multi-method naming
14
+ * [BUGFIX] Add http to proxy_url for native fetching
15
+ * [BUGFIX] Fix setting `proxy_url` in config YML
16
+ * [IMPROVEMENT] Log errors during authentication validation
17
+
18
+ ## 0.10.4 (June 3, 2016)
19
+
20
+ * [BUGFIX] Sinatra instrumenation now works for latest master
21
+ * [BUGFIX] Sequel support for 4.35.0
22
+ * [BUGFIX] Handle latest ActiveModel::Serializers version
23
+ * [BUGFIX] More precise check for existence of Rails
24
+ * [BREAKING] Drop official support for Sinatra 1.2 (it likely never worked correctly)
25
+ * [IMPROVEMENT] On Heroku, logs are now written to STDOUT
26
+ * [IMPROVEMENT] Allow Skylight to raise on logged errors, useful for testing and debugging
27
+ * [IMPROVEMENT] Finish Rack::Responses in Middleware
28
+ * [IMRPOVEMENT] Better message when config/skylight.yml already exists
29
+ * [IMPROVEMENT] Update Rust Agent with SQL improvements, including handling for arrays and WITH
30
+
31
+ ## 0.10.3 (February 2, 2016)
32
+
33
+ * [BUGFIX] Don't validate configuration on disabled environments.
21
34
 
22
35
  ## 0.10.2 (January 19, 2016)
23
36
 
@@ -1,3 +1,3 @@
1
1
  #!/usr/bin/env ruby
2
2
  require "skylight/cli"
3
- Skylight::CLI.start(ARGV)
3
+ Skylight::CLI::Base.start(ARGV)
@@ -3,7 +3,9 @@ require 'uri'
3
3
  module Skylight
4
4
  # @api private
5
5
  class Api
6
- attr_reader :config, :http
6
+ include Util::Logging
7
+
8
+ attr_reader :config
7
9
 
8
10
  class CreateFailed < StandardError
9
11
  attr_reader :res
@@ -29,51 +31,89 @@ module Skylight
29
31
  end
30
32
  end
31
33
 
32
- def initialize(config, service = :auth)
33
- @config = config
34
- @http = Util::HTTP.new(config, service)
35
- end
34
+ class ConfigValidationResults
36
35
 
37
- def authentication
38
- @http.authentication
39
- end
36
+ include Util::Logging
40
37
 
41
- def authentication=(token)
42
- @http.authentication = token
43
- end
38
+ attr_reader :raw_response
44
39
 
45
- def validate_authentication
46
- url = URI.parse(config[:auth_url])
40
+ def initialize(config, raw_response)
41
+ @config = config
42
+ @raw_response = raw_response
43
+ end
47
44
 
48
- res = @http.get(url.path)
45
+ def is_error_response?
46
+ raw_response.is_a?(Util::HTTP::ErrorResponse) || status > 499
47
+ end
49
48
 
50
- case res.status
51
- when 200...300
52
- :ok
53
- when 400...500
54
- :invalid
55
- else
56
- :unknown
49
+ def status
50
+ raw_response.status
57
51
  end
58
- rescue
59
- :unknown
60
- end
61
52
 
62
- def login(email, password)
63
- res = http.get('/me', 'X-Email' => email, 'X-Password' => password)
53
+ def body
54
+ return nil if is_error_response?
64
55
 
65
- if res && res.success?
66
- res.get('me.authentication_token')
56
+ unless raw_response.body.is_a?(Hash)
57
+ warn("Unable to parse server response: status=%s, body=%s", raw_response.status, raw_response.body)
58
+ return {}
59
+ end
60
+
61
+ raw_response.body
62
+ end
63
+
64
+ def token_valid?
65
+ # Don't prevent boot if it's an error response, so assume token is valid
66
+ return true if is_error_response?
67
+ # A 2xx response means everything is good!
68
+ return true if raw_response.success?
69
+ # A 422 means an invalid config, but the token must be valid if we got this far
70
+ return true if status === 422
67
71
  end
72
+
73
+ def config_valid?
74
+ # Only assume config is good if we have positive confirmation
75
+ raw_response.success?
76
+ end
77
+
78
+ def validation_errors
79
+ return if config_valid?
80
+ body ? body['errors'] : nil
81
+ end
82
+
83
+ def corrected_config
84
+ return if config_valid?
85
+ body ? body['corrected'] : nil
86
+ end
87
+
88
+ end
89
+
90
+ def initialize(config)
91
+ @config = config
68
92
  end
69
93
 
70
94
  def create_app(name, token=nil)
71
95
  params = { app: { name: name } }
72
96
  params[:token] = token if token
73
- res = @http.post('/apps', params)
97
+
98
+ res = http_request(:app_create, :post, params)
99
+
74
100
  raise CreateFailed, res unless res.success?
75
101
  res
76
102
  end
77
103
 
104
+ def validate_config
105
+ res = http_request(:validation, :post, config)
106
+ ConfigValidationResults.new(config, res)
107
+ end
108
+
109
+ private
110
+
111
+ # TODO: Improve handling here: https://github.com/tildeio/direwolf-agent/issues/274
112
+ def http_request(service, method, *args)
113
+ http = Util::HTTP.new(config, service)
114
+ uri = URI.parse(config.get("#{service}_url"))
115
+ http.send(method, uri.path, *args)
116
+ end
117
+
78
118
  end
79
119
  end
@@ -6,34 +6,37 @@ require 'yaml'
6
6
  require 'highline'
7
7
  require 'active_support/inflector'
8
8
 
9
+ require 'skylight/cli/helpers'
10
+ require 'skylight/cli/doctor'
11
+
9
12
  module Skylight
10
- # @api private
11
- class CLI < Thor
13
+ module CLI
14
+ # @api private
15
+ class Base < Thor
16
+ include Helpers
17
+
18
+ register(Doctor, "doctor", "doctor", "Run some basic tests to look out for common problems")
12
19
 
13
- desc "setup TOKEN", "Sets up a new app using the provided token"
14
- def setup(token=nil)
15
- if File.exist?(config_path)
16
- say <<-OUT, :green
20
+ desc "setup TOKEN", "Sets up a new app using the provided token"
21
+ def setup(token)
22
+ if File.exist?(config_path)
23
+ say <<-OUT, :green
17
24
  A config/skylight.yml already exists for your application.
18
25
 
19
26
  Visit your app at https://www.skylight.io/app or remove config/skylight.yml
20
27
  to set it up as a new app in Skylight.
21
- OUT
22
- return
23
- end
24
-
25
- unless token
26
- api.authentication = login
27
- end
28
+ OUT
29
+ return
30
+ end
28
31
 
29
- res = api.create_app(app_name, token)
32
+ res = api.create_app(app_name, token)
30
33
 
31
- config[:application] = res.get('app.id')
32
- config[:authentication] = res.get('app.token')
33
- config.write(config_path)
34
+ config[:application] = res.get('app.id')
35
+ config[:authentication] = res.get('app.token')
36
+ config.write(config_path)
34
37
 
35
- say "Congratulations. Your application is on Skylight! http://www.skylight.io", :green
36
- say <<-OUT
38
+ say "Congratulations. Your application is on Skylight! http://www.skylight.io", :green
39
+ say <<-OUT
37
40
 
38
41
  The application was registered for you and we generated a config file
39
42
  containing your API token at:
@@ -51,113 +54,79 @@ you should set the `SKYLIGHT_AUTHENTICATION` variable to:
51
54
 
52
55
  #{config[:authentication]}
53
56
 
54
- OUT
55
- rescue Api::CreateFailed => e
56
- say "Could not create the application", :red
57
- say e.to_s, :yellow
58
- rescue Interrupt
59
- end
60
-
61
- desc "disable_dev_warning", "Disables warning about running Skylight in development mode for all local apps"
62
- def disable_dev_warning
63
- user_config.disable_dev_warning = true
64
- user_config.save
65
-
66
- say "Development mode warning disabled", :green
67
- end
57
+ OUT
58
+ rescue Api::CreateFailed => e
59
+ say "Could not create the application", :red
60
+ say e.to_s, :yellow
61
+ rescue Interrupt
62
+ end
68
63
 
69
- private
64
+ desc "disable_dev_warning", "Disables warning about running Skylight in development mode for all local apps"
65
+ def disable_dev_warning
66
+ user_config.disable_dev_warning = true
67
+ user_config.save
70
68
 
71
- def app_name
72
- @app_name ||=
73
- begin
74
- name = nil
69
+ say "Development mode warning disabled", :green
70
+ end
75
71
 
76
- if File.exist?("config/application.rb")
77
- # This looks like a Rails app, lets make sure we have the railtie loaded
78
- # skylight.rb checks for Rails, but when running the CLI, Skylight loads before Rails does
79
- begin
80
- require "skylight/railtie"
81
- rescue LoadError => e
82
- error "Unable to load Railtie. Please notify support@skylight.io."
83
- end
72
+ private
73
+
74
+ def app_name
75
+ @app_name ||=
76
+ begin
77
+ name = nil
78
+
79
+ if is_rails?
80
+ # Get the name in a process so that we don't pollute our environment here
81
+ # This is especially important since users may have things like WebMock that
82
+ # will prevent us from communicating with the Skylight API
83
+ begin
84
+ namefile = Tempfile.new('skylight-app-name')
85
+ # Windows appears to need double quotes for `rails runner`
86
+ `rails runner "File.open('#{namefile.path}', 'w') {|f| f.write(Rails.application.class.name) rescue '' }"`
87
+ name = namefile.read.split("::").first.underscore.titleize
88
+ name = nil if name.empty?
89
+ rescue => e
90
+ if ENV['DEBUG']
91
+ puts e.class.name
92
+ puts e.to_s
93
+ puts e.backtrace.join("\n")
94
+ end
95
+ ensure
96
+ namefile.close
97
+ namefile.unlink
98
+ end
84
99
 
85
- # Get the name in a process so that we don't pollute our environment here
86
- # This is especially important since users may have things like WebMock that
87
- # will prevent us from communicating with the Skylight API
88
- begin
89
- namefile = Tempfile.new('skylight-app-name')
90
- # Windows appears to need double quotes for `rails runner`
91
- `rails runner "File.open('#{namefile.path}', 'w') {|f| f.write(Rails.application.class.name) rescue '' }"`
92
- name = namefile.read.split("::").first.underscore.titleize
93
- name = nil if name.empty?
94
- rescue => e
95
- if ENV['DEBUG']
96
- puts e.class.name
97
- puts e.to_s
98
- puts e.backtrace.join("\n")
100
+ unless name
101
+ warn "Unable to determine Rails application name. Using directory name."
99
102
  end
100
- ensure
101
- namefile.close
102
- namefile.unlink
103
103
  end
104
104
 
105
105
  unless name
106
- warn "Unable to determine Rails application name. Using directory name."
106
+ name = File.basename(File.expand_path('.')).titleize
107
107
  end
108
- end
109
108
 
110
- unless name
111
- name = File.basename(File.expand_path('.')).titleize
109
+ name
112
110
  end
113
-
114
- name
115
- end
116
- end
117
-
118
- def login
119
- say "Please enter your email and password below or get a token from https://www.skylight.io/app/setup.", :cyan
120
-
121
- 10.times do
122
- email = highline.ask("Email: ")
123
- password = highline.ask("Password: ") { |q| q.echo = "*" }
124
-
125
- if token = api.login(email, password)
126
- return token
127
- end
128
-
129
- say "Sorry. That email and password was invalid. Please try again", :red
130
- puts
131
111
  end
132
112
 
133
- say "Could not login", :red
134
- return
135
- end
136
-
137
- def relative_config_path
138
- 'config/skylight.yml'
139
- end
140
-
141
- def config_path
142
- File.expand_path(relative_config_path)
143
- end
113
+ # Is this duplicated?
114
+ def relative_config_path
115
+ 'config/skylight.yml'
116
+ end
144
117
 
145
- def api
146
- @api ||= Api.new(config)
147
- end
118
+ def config_path
119
+ File.expand_path(relative_config_path)
120
+ end
148
121
 
149
- def highline
150
- @highline ||= HighLine.new
151
- end
122
+ def api
123
+ config.api
124
+ end
152
125
 
153
- def config
154
- # Calling .load checks ENV variables
155
- @config ||= Config.load
156
- end
126
+ def user_config
127
+ UserConfig.instance
128
+ end
157
129
 
158
- def user_config
159
- UserConfig.instance
160
130
  end
161
-
162
131
  end
163
132
  end
@@ -0,0 +1,132 @@
1
+ module Skylight
2
+ module CLI
3
+ class Doctor < Thor::Group
4
+ include Helpers
5
+
6
+ desc "Run some basic tests to look out for common errors"
7
+
8
+ def check_rails
9
+ say "Checking for Rails"
10
+
11
+ indent do
12
+ if is_rails?
13
+ say "Rails application detected", :green
14
+
15
+ # Normally auto-loaded, but we haven't loaded Rails by the time Skylight is loaded
16
+ require 'skylight/railtie'
17
+ require File.expand_path('config/application', Dir.pwd)
18
+ else
19
+ say "No Rails application detected", :red
20
+ abort "Currently `skylight doctor` only works with Rails applications"
21
+ end
22
+ end
23
+
24
+ say "\n"
25
+ end
26
+
27
+ def check_native
28
+ say "Checking for native agent"
29
+
30
+ indent do
31
+ if Skylight.native?
32
+ say "Native agent installed", :green
33
+ else
34
+ say "Unable to load native extension", :yellow
35
+
36
+ indent do
37
+ install_log = File.expand_path("../../../ext/install.log", __FILE__)
38
+ if File.exist?(install_log)
39
+ File.readlines(install_log).each do |line|
40
+ say line, :red
41
+ end
42
+ else
43
+ say "Reason unknown", :red
44
+ end
45
+ end
46
+
47
+ abort
48
+ end
49
+ end
50
+
51
+ say "\n"
52
+ end
53
+
54
+ def check_config
55
+ say "Checking for valid configuration"
56
+
57
+ # MEGAHAX
58
+ railtie = Skylight::Railtie.send(:new)
59
+ config = railtie.send(:load_skylight_config, Rails.application)
60
+
61
+ indent do
62
+ begin
63
+ config.validate!
64
+ say "Configuration is valid", :green
65
+ rescue ConfigError => e
66
+ say "Configuration is invalid", :red
67
+ say " #{e.message}", :red
68
+ abort
69
+ end
70
+ end
71
+
72
+ puts "\n"
73
+ end
74
+
75
+ def check_daemon
76
+ say "Checking Skylight startup"
77
+
78
+ indent do
79
+ # Set this after we validate. It will give us more detailed information on start.
80
+ logger = Logger.new("/dev/null") # Rely on `say` in the formatter instead
81
+ # Log everything
82
+ logger.level = Logger::DEBUG
83
+ # Remove excess formatting
84
+ logger.formatter = proc { |severity, datetime, progname, msg|
85
+ msg = msg.sub("[SKYLIGHT] [#{Skylight::VERSION}] ", '')
86
+ say "#{severity} - #{msg}" # Definitely non-standard
87
+ }
88
+ config.logger = logger
89
+
90
+ config.set(:'daemon.lazy_start', false)
91
+
92
+ started = Skylight.start!(config)
93
+
94
+ if started
95
+ say "Successfully started", :green
96
+ else
97
+ say "Failed to start", :red
98
+ abort
99
+ end
100
+
101
+ say "Waiting for daemon... "
102
+
103
+ # Doesn't start immediately
104
+ tries = 0
105
+ daemon_running = false
106
+ while tries < 5
107
+ `ps cax | grep skylightd`
108
+ if $?.success?
109
+ daemon_running = true
110
+ break
111
+ end
112
+
113
+ tries += 1
114
+ sleep 1
115
+ end
116
+
117
+ if daemon_running
118
+ say "Success", :green
119
+ else
120
+ say "Failed", :red
121
+ end
122
+ end
123
+
124
+ say "\n"
125
+ end
126
+
127
+ def status
128
+ say "All checks passed!", :green
129
+ end
130
+ end
131
+ end
132
+ end