skylight 5.0.1 → 5.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (79) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +395 -364
  3. data/CLA.md +1 -1
  4. data/LICENSE.md +7 -17
  5. data/README.md +1 -1
  6. data/ext/extconf.rb +42 -54
  7. data/ext/libskylight.yml +9 -6
  8. data/lib/skylight.rb +20 -30
  9. data/lib/skylight/api.rb +22 -18
  10. data/lib/skylight/cli.rb +47 -46
  11. data/lib/skylight/cli/doctor.rb +50 -50
  12. data/lib/skylight/cli/helpers.rb +19 -19
  13. data/lib/skylight/cli/merger.rb +141 -139
  14. data/lib/skylight/config.rb +265 -300
  15. data/lib/skylight/deprecation.rb +4 -4
  16. data/lib/skylight/errors.rb +3 -4
  17. data/lib/skylight/extensions.rb +17 -29
  18. data/lib/skylight/extensions/source_location.rb +128 -128
  19. data/lib/skylight/formatters/http.rb +1 -3
  20. data/lib/skylight/gc.rb +30 -40
  21. data/lib/skylight/helpers.rb +43 -41
  22. data/lib/skylight/instrumenter.rb +25 -18
  23. data/lib/skylight/middleware.rb +31 -35
  24. data/lib/skylight/native.rb +8 -10
  25. data/lib/skylight/native_ext_fetcher.rb +10 -12
  26. data/lib/skylight/normalizers.rb +43 -39
  27. data/lib/skylight/normalizers/action_controller/process_action.rb +24 -25
  28. data/lib/skylight/normalizers/action_controller/send_file.rb +7 -6
  29. data/lib/skylight/normalizers/action_dispatch/route_set.rb +7 -7
  30. data/lib/skylight/normalizers/active_job/perform.rb +48 -44
  31. data/lib/skylight/normalizers/active_model_serializers/render.rb +7 -3
  32. data/lib/skylight/normalizers/active_storage.rb +11 -13
  33. data/lib/skylight/normalizers/active_support/cache.rb +1 -12
  34. data/lib/skylight/normalizers/coach/handler_finish.rb +1 -3
  35. data/lib/skylight/normalizers/default.rb +1 -9
  36. data/lib/skylight/normalizers/faraday/request.rb +1 -3
  37. data/lib/skylight/normalizers/grape/endpoint.rb +13 -19
  38. data/lib/skylight/normalizers/grape/endpoint_run.rb +16 -18
  39. data/lib/skylight/normalizers/grape/endpoint_run_filters.rb +1 -3
  40. data/lib/skylight/normalizers/graphql/base.rb +23 -28
  41. data/lib/skylight/normalizers/render.rb +19 -21
  42. data/lib/skylight/normalizers/shrine.rb +15 -17
  43. data/lib/skylight/normalizers/sql.rb +4 -4
  44. data/lib/skylight/probes.rb +38 -46
  45. data/lib/skylight/probes/action_controller.rb +32 -28
  46. data/lib/skylight/probes/action_dispatch/request_id.rb +9 -5
  47. data/lib/skylight/probes/action_dispatch/routing/route_set.rb +7 -5
  48. data/lib/skylight/probes/action_view.rb +9 -10
  49. data/lib/skylight/probes/active_job_enqueue.rb +3 -9
  50. data/lib/skylight/probes/active_model_serializers.rb +8 -8
  51. data/lib/skylight/probes/delayed_job.rb +37 -42
  52. data/lib/skylight/probes/elasticsearch.rb +3 -5
  53. data/lib/skylight/probes/excon.rb +1 -1
  54. data/lib/skylight/probes/excon/middleware.rb +22 -23
  55. data/lib/skylight/probes/graphql.rb +2 -7
  56. data/lib/skylight/probes/middleware.rb +14 -5
  57. data/lib/skylight/probes/mongo.rb +83 -91
  58. data/lib/skylight/probes/net_http.rb +1 -1
  59. data/lib/skylight/probes/redis.rb +5 -17
  60. data/lib/skylight/probes/sequel.rb +7 -11
  61. data/lib/skylight/probes/sinatra.rb +8 -5
  62. data/lib/skylight/probes/tilt.rb +2 -4
  63. data/lib/skylight/railtie.rb +121 -135
  64. data/lib/skylight/sidekiq.rb +4 -5
  65. data/lib/skylight/subscriber.rb +31 -33
  66. data/lib/skylight/test.rb +89 -84
  67. data/lib/skylight/trace.rb +121 -115
  68. data/lib/skylight/user_config.rb +14 -17
  69. data/lib/skylight/util/clock.rb +1 -0
  70. data/lib/skylight/util/component.rb +18 -21
  71. data/lib/skylight/util/deploy.rb +11 -13
  72. data/lib/skylight/util/http.rb +104 -105
  73. data/lib/skylight/util/logging.rb +4 -6
  74. data/lib/skylight/util/lru_cache.rb +2 -6
  75. data/lib/skylight/util/platform.rb +2 -6
  76. data/lib/skylight/util/ssl.rb +1 -25
  77. data/lib/skylight/version.rb +1 -1
  78. data/lib/skylight/vm/gc.rb +1 -9
  79. metadata +6 -6
data/CLA.md CHANGED
@@ -6,4 +6,4 @@ right (whether now known or hereinafter invented), title, and interest,
6
6
  throughout the world, including any copyrights and renewals or extensions
7
7
  thereto, in the contributions to Skylight made by Assignor.
8
8
 
9
- IN WITNESS THEREOF, Assignor has duly executed this Agreement.
9
+ IN WITNESS THEREOF, Assignor has duly executed this Agreement.
data/LICENSE.md CHANGED
@@ -28,19 +28,15 @@ brand (if any) provided by Tilde.
28
28
  Unless otherwise expressly agreed by Tilde in a separate written
29
29
  license agreement, these files are provided AS IS, WITHOUT WARRANTY OF
30
30
  ANY KIND, including without any implied warranties of MERCHANTABILITY,
31
- FITNESS FOR A PARTICULAR PURPOSE, TITLE, or NON-INFRINGEMENT. As a
31
+ FITNESS FOR A PARTICULAR PURPOSE, TITLE, or NON-INFRINGEMENT. As a
32
32
  condition to your use of these files, you are solely responsible for
33
33
  such use. Tilde will have no liability to you for direct,
34
34
  indirect, consequential, incidental, special, or punitive damages or
35
35
  for lost profits or data.
36
36
 
37
+ # Other Licenses
37
38
 
38
-
39
- Other Licenses
40
- ==============
41
-
42
- Ruby on Rails
43
- -------------
39
+ ## Ruby on Rails
44
40
 
45
41
  Copyright (c) 2005-2016 David Heinemeier Hansson
46
42
 
@@ -48,9 +44,7 @@ Released under the MIT License.
48
44
 
49
45
  Original source at https://github.com/rails/rails.
50
46
 
51
-
52
- HighLine
53
- --------
47
+ ## HighLine
54
48
 
55
49
  Copyright (c) 2014 James Edward Gray II, Gregory Brown, et al.
56
50
 
@@ -58,9 +52,7 @@ Distributed under the user's choice of the GPL Version 2 or the Ruby software li
58
52
 
59
53
  Original source at https://github.com/JEG2/highline.
60
54
 
61
-
62
- Thor
63
- ----
55
+ ## Thor
64
56
 
65
57
  Copyright (c) 2008 Yehuda Katz, Eric Hodel, et al.
66
58
 
@@ -68,12 +60,10 @@ Released under the MIT License.
68
60
 
69
61
  Original source at https://github.com/erikhuda/thor.
70
62
 
71
-
72
- ThreadSafe
73
- ----------
63
+ ## ThreadSafe
74
64
 
75
65
  Copyright (c) 2014 Charles Oliver Nutter, thedarkone, et al.
76
66
 
77
67
  Distributed under Apache License, Version 2.0, January 2004
78
68
 
79
- Original source at https://github.com/ruby-concurrency/thread_safe.
69
+ Original source at https://github.com/ruby-concurrency/thread_safe.
data/README.md CHANGED
@@ -1,4 +1,5 @@
1
1
  # Skylight Ruby Agent
2
+
2
3
  [![Gem Version](https://badge.fury.io/rb/skylight.svg)](https://badge.fury.io/rb/skylight)
3
4
  [![SemVer](https://api.dependabot.com/badges/compatibility_score?dependency-name=skylight&package-manager=bundler&version-scheme=semver)](https://dependabot.com/compatibility-score.html?dependency-name=skylight&package-manager=bundler&version-scheme=semver)
4
5
 
@@ -9,7 +10,6 @@ Sign up at https://www.skylight.io.
9
10
 
10
11
  For more documentation see https://www.skylight.io/support.
11
12
 
12
-
13
13
  ## Bug Reports and Feature Requests
14
14
 
15
15
  If you've got a bug report or have a feature you'd like to request, please contact us at support@skylight.io or use the built-in messenger in the Skylight web interface. We'll be much quicker to respond that way :)
data/ext/extconf.rb CHANGED
@@ -27,13 +27,13 @@ end
27
27
  include Skylight::Util
28
28
 
29
29
  SKYLIGHT_INSTALL_LOG = File.expand_path("install.log", __dir__)
30
- SKYLIGHT_REQUIRED = ENV.key?("SKYLIGHT_REQUIRED") && ENV["SKYLIGHT_REQUIRED"] !~ /^false$/i
31
- SKYLIGHT_FETCH_LIB = !ENV.key?("SKYLIGHT_FETCH_LIB") || ENV["SKYLIGHT_FETCH_LIB"] !~ /^false$/i
30
+ SKYLIGHT_REQUIRED = ENV.key?("SKYLIGHT_REQUIRED") && ENV["SKYLIGHT_REQUIRED"] !~ /^false$/i
31
+ SKYLIGHT_FETCH_LIB = !ENV.key?("SKYLIGHT_FETCH_LIB") || ENV["SKYLIGHT_FETCH_LIB"] !~ /^false$/i
32
32
 
33
33
  # Directory where skylight.h exists
34
34
  SKYLIGHT_HDR_PATH = ENV["SKYLIGHT_HDR_PATH"] || ENV["SKYLIGHT_LIB_PATH"] || "."
35
- SKYLIGHT_LIB_PATH = ENV["SKYLIGHT_LIB_PATH"] ||
36
- File.expand_path("../../lib/skylight/native/#{Platform.tuple}", __FILE__)
35
+ SKYLIGHT_LIB_PATH =
36
+ ENV["SKYLIGHT_LIB_PATH"] || File.expand_path("../../lib/skylight/native/#{Platform.tuple}", __FILE__)
37
37
 
38
38
  SKYLIGHT_SOURCE_URL = ENV["SKYLIGHT_SOURCE_URL"]
39
39
  SKYLIGHT_VERSION = ENV["SKYLIGHT_VERSION"]
@@ -66,26 +66,26 @@ end
66
66
  # Check that Xcode license has been approved
67
67
  # Based on Homebrew's implementation
68
68
  # https://github.com/Homebrew/homebrew/blob/03708b016755847facc4f19a43ee9f7a44141ed7/Library/Homebrew/cmd/doctor.rb#L1183
69
- if Platform::OS == "darwin"
70
- # If the user installs Xcode-only, they have to approve the
71
- # license or no "xc*" tool will work.
72
- if `/usr/bin/xcrun clang 2>&1` =~ /license/ && !$CHILD_STATUS.success? # rubocop:disable Style/SoleNestedConditional
73
- fail <<~MESSAGE
74
- You have not agreed to the Xcode license and so we are unable to build the native agent.
75
- To resolve this, you can agree to the license by opening Xcode.app or running:
76
- sudo xcodebuild -license
77
- MESSAGE
78
- end
69
+ # If the user installs Xcode-only, they have to approve the
70
+ # license or no "xc*" tool will work.
71
+
72
+ # prettier-ignore
73
+ if Platform::OS == "darwin" && (`/usr/bin/xcrun clang 2>&1` =~ /license/ && !$CHILD_STATUS.success?)
74
+ fail <<~MESSAGE
75
+ You have not agreed to the Xcode license and so we are unable to build the native agent.
76
+ To resolve this, you can agree to the license by opening Xcode.app or running:
77
+ sudo xcodebuild -license
78
+ MESSAGE
79
79
  end
80
80
 
81
81
  #
82
82
  # === Setup paths
83
83
  #
84
- root = File.expand_path(__dir__)
85
- hdrpath = File.expand_path(SKYLIGHT_HDR_PATH)
86
- libpath = File.expand_path(SKYLIGHT_LIB_PATH)
87
- libskylight = File.expand_path("libskylight.#{Platform.libext}", libpath)
88
- libskylight_yml = File.expand_path("libskylight.yml", root)
84
+ root = File.expand_path(__dir__)
85
+ hdrpath = File.expand_path(SKYLIGHT_HDR_PATH)
86
+ libpath = File.expand_path(SKYLIGHT_LIB_PATH)
87
+ libskylight = File.expand_path("libskylight.#{Platform.libext}", libpath)
88
+ libskylight_yml = File.expand_path("libskylight.yml", root)
89
89
  skylight_dlopen_h = File.expand_path("skylight_dlopen.h", hdrpath)
90
90
  skylight_dlopen_c = File.expand_path("skylight_dlopen.c", hdrpath)
91
91
 
@@ -97,14 +97,10 @@ LOG.info "file exists; path=#{skylight_dlopen_h}" if File.exist?(skylight_dlopen
97
97
 
98
98
  # If libskylight is not present, fetch it
99
99
  if !File.exist?(libskylight) && !File.exist?(skylight_dlopen_c) && !File.exist?(skylight_dlopen_h)
100
- unless SKYLIGHT_FETCH_LIB
101
- fail "libskylight.#{LIBEXT} not found -- remote download disabled; aborting install"
102
- end
100
+ fail "libskylight.#{LIBEXT} not found -- remote download disabled; aborting install" unless SKYLIGHT_FETCH_LIB
103
101
 
104
102
  # Ensure that libskylight.yml is present and load it
105
- unless File.exist?(libskylight_yml)
106
- fail "`#{libskylight_yml}` does not exist"
107
- end
103
+ fail "`#{libskylight_yml}` does not exist" unless File.exist?(libskylight_yml)
108
104
 
109
105
  unless (libskylight_info = YAML.load_file(libskylight_yml))
110
106
  fail "`#{libskylight_yml}` does not contain data"
@@ -133,26 +129,26 @@ if !File.exist?(libskylight) && !File.exist?(skylight_dlopen_c) && !File.exist?(
133
129
 
134
130
  unless (checksum = checksums[Platform.tuple])
135
131
  fail "no checksum entry for requested architecture -- " \
136
- "this probably means the requested architecture is not supported; " \
137
- "platform=#{Platform.tuple}; available=#{checksums.keys}", :info
132
+ "this probably means the requested architecture is not supported; " \
133
+ "platform=#{Platform.tuple}; available=#{checksums.keys}",
134
+ :info
138
135
  end
139
136
  end
140
137
 
141
138
  begin
142
- res = Skylight::NativeExtFetcher.fetch(
143
- source: SKYLIGHT_SOURCE_URL,
144
- version: version,
145
- target: hdrpath,
146
- checksum: checksum,
147
- arch: Platform.tuple,
148
- required: SKYLIGHT_REQUIRED,
149
- platform: Platform.tuple,
150
- logger: LOG
151
- )
152
-
153
- unless res
154
- fail "could not fetch archive -- aborting skylight native extension build"
155
- end
139
+ res =
140
+ Skylight::NativeExtFetcher.fetch(
141
+ source: SKYLIGHT_SOURCE_URL,
142
+ version: version,
143
+ target: hdrpath,
144
+ checksum: checksum,
145
+ arch: Platform.tuple,
146
+ required: SKYLIGHT_REQUIRED,
147
+ platform: Platform.tuple,
148
+ logger: LOG
149
+ )
150
+
151
+ fail "could not fetch archive -- aborting skylight native extension build" unless res
156
152
 
157
153
  # Move skylightd & libskylight to appropriate directory
158
154
  if hdrpath != libpath
@@ -160,15 +156,11 @@ if !File.exist?(libskylight) && !File.exist?(skylight_dlopen_c) && !File.exist?(
160
156
  FileUtils.mkdir_p libpath
161
157
 
162
158
  # Move
163
- FileUtils.mv "#{hdrpath}/libskylight.#{Platform.libext}",
164
- "#{libpath}/libskylight.#{Platform.libext}",
165
- force: true
159
+ FileUtils.mv "#{hdrpath}/libskylight.#{Platform.libext}", "#{libpath}/libskylight.#{Platform.libext}", force: true
166
160
 
167
- FileUtils.mv "#{hdrpath}/skylightd",
168
- "#{libpath}/skylightd",
169
- force: true
161
+ FileUtils.mv "#{hdrpath}/skylightd", "#{libpath}/skylightd", force: true
170
162
  end
171
- rescue => e
163
+ rescue StandardError => e
172
164
  fail "unable to fetch native extension; msg=#{e.message}\n#{e.backtrace.join("\n")}"
173
165
  end
174
166
  end
@@ -182,9 +174,7 @@ end
182
174
  def find_file(file, root = nil)
183
175
  path = File.expand_path(file, root || ".")
184
176
 
185
- unless File.exist?(path)
186
- fail "#{file} missing; path=#{root}"
187
- end
177
+ fail "#{file} missing; path=#{root}" unless File.exist?(path)
188
178
  end
189
179
 
190
180
  $VPATH << libpath
@@ -218,9 +208,7 @@ end
218
208
  # flag can cause issues for some customers we're turning it off by default. However,
219
209
  # in development and CI, we still have the option of turning it back on to help catch
220
210
  # potential issues.
221
- if SKYLIGHT_EXT_STRICT
222
- $CFLAGS << " -Werror"
223
- end
211
+ $CFLAGS << " -Werror" if SKYLIGHT_EXT_STRICT
224
212
 
225
213
  checking_for "fast thread local storage" do
226
214
  if try_compile("__thread int foo;")
data/ext/libskylight.yml CHANGED
@@ -1,8 +1,11 @@
1
- # commit: ea59cc7bdbbee0f69d1cf7e69827974a9ea67645
1
+ # commit b6bb0714913a5be54f4eac717d5096dc7ba5f3eb
2
2
  ---
3
- version: "5.0.0-488d432"
3
+ version: "5.1.0-0d59831"
4
4
  checksums:
5
- x86-linux: "3c16b6db1508f35720258551783fbcd30fd231638bad316ea76748d659838399"
6
- x86_64-linux: "94383aa3359c3f2e9c0e3c16ee263d46c5673dd255f8842e6acadf5ec3131c06"
7
- x86_64-linux-musl: "d2e2e2e61c321315f9bcaa157426f33aef8ffc2330ba46b2cdcbd9442e65f728"
8
- x86_64-darwin: "bcc925d0bcbae83a484f35dbc9729dcf262e1f3a8c29b8d387d0f58ad8f3afa3"
5
+ x86-linux: "e15fff9269f5451302aaee56b4d4631c86f979298bc22536f28f884c170c127f"
6
+ x86_64-linux: "be95b9c91dffb0133b57183d160cad700213703a87f52488cf114a4fff92ff4d"
7
+ x86_64-linux-musl: "945ebefa0384e23121bc1674f0eda0600aef204599e5819bdbecd6d62252b769"
8
+ x86_64-darwin: "d98ee1d331394ac43bd37f2d3d5d591a41d912dfa2c3e5d0b21d97f7a5198cf1"
9
+ aarch64-linux: "b6add5dda52a2cae4b5e3899a5e0c938049385443d82acbd1a8a2fb0d8502933"
10
+ aarch64-linux-musl: "667030ade09a69a664380262ec1e6ceeb77f49585201e670528f4cd52d3def86"
11
+ aarch64-darwin: "d3225034d18d99e358ace24cf951468feaf3b83f0b33e32965bc2139e0300505"
data/lib/skylight.rb CHANGED
@@ -23,13 +23,12 @@ require "active_support/notifications"
23
23
 
24
24
  # Specifically check for Railtie since we've had at least one case of a
25
25
  # customer having Rails defined without having all of Rails loaded.
26
- if defined?(Rails::Railtie)
27
- require "skylight/railtie"
28
- end
26
+ require "skylight/railtie" if defined?(Rails::Railtie)
29
27
 
30
28
  module Skylight
31
29
  # Used from the CLI
32
30
  autoload :CLI, "skylight/cli"
31
+
33
32
  # Is this autoload even useful?
34
33
  autoload :Normalizers, "skylight/normalizers"
35
34
 
@@ -38,18 +37,10 @@ module Skylight
38
37
  LOCK = Mutex.new
39
38
 
40
39
  # @api private
41
- TIERS = %w[
42
- rack
43
- api
44
- app
45
- view
46
- db
47
- noise
48
- other
49
- ].freeze
40
+ TIERS = %w[rack api app view db noise other].freeze
50
41
 
51
42
  # @api private
52
- TIER_REGEX = /^(?:#{TIERS.join('|')})(?:\.|$)/u.freeze
43
+ TIER_REGEX = /^(?:#{TIERS.join("|")})(?:\.|$)/u.freeze
53
44
 
54
45
  # @api private
55
46
  CATEGORY_REGEX = /^[a-z0-9_-]+(?:\.[a-z0-9_-]+)*$/iu.freeze
@@ -91,14 +82,15 @@ module Skylight
91
82
 
92
83
  @instrumenter = Instrumenter.new(config).start!
93
84
  end
94
- rescue => e
85
+ rescue StandardError => e
95
86
  level, message =
96
87
  if e.is_a?(ConfigError)
97
- [:warn, format("Unable to start Instrumenter due to a configuration error: %<message>s",
98
- message: e.message)]
88
+ [:warn, format("Unable to start Instrumenter due to a configuration error: %<message>s", message: e.message)]
99
89
  else
100
- [:error, format("Unable to start Instrumenter; msg=%<message>s; class=%<klass>s",
101
- message: e.message, klass: e.class)]
90
+ [
91
+ :error,
92
+ format("Unable to start Instrumenter; msg=%<message>s; class=%<klass>s", message: e.message, klass: e.class)
93
+ ]
102
94
  end
103
95
 
104
96
  if config.respond_to?("log_#{level}") && config.respond_to?(:log_trace)
@@ -182,16 +174,16 @@ module Skylight
182
174
  end
183
175
 
184
176
  if opts.is_a?(Hash)
185
- category = opts[:category] || DEFAULT_CATEGORY
186
- title = opts[:title]
187
- desc = opts[:description]
188
- meta = opts[:meta]
177
+ category = opts[:category] || DEFAULT_CATEGORY
178
+ title = opts[:title]
179
+ desc = opts[:description]
180
+ meta = opts[:meta]
189
181
  else
190
- category = DEFAULT_CATEGORY
191
- title = opts.to_s
192
- desc = nil
193
- meta = nil
194
- opts = {}
182
+ category = DEFAULT_CATEGORY
183
+ title = opts.to_s
184
+ desc = nil
185
+ meta = nil
186
+ opts = {}
195
187
  end
196
188
 
197
189
  # NOTE: unless we have `:internal` (indicating a built-in Skylight instrument block),
@@ -225,9 +217,7 @@ module Skylight
225
217
  # Runs the shutdown procedure in the background.
226
218
  # This should do little more than unsubscribe from all ActiveSupport::Notifications
227
219
  def spawn_shutdown_thread!
228
- @shutdown_thread || const_get(:LOCK).synchronize do
229
- @shutdown_thread ||= Thread.new { @instrumenter&.shutdown }
230
- end
220
+ @shutdown_thread || const_get(:LOCK).synchronize { @shutdown_thread ||= Thread.new { @instrumenter&.shutdown } }
231
221
  end
232
222
  end
233
223
  end
data/lib/skylight/api.rb CHANGED
@@ -8,11 +8,14 @@ module Skylight
8
8
 
9
9
  attr_reader :config
10
10
 
11
- class Error < StandardError; end
11
+ class Error < StandardError
12
+ end
12
13
 
13
- class Unauthorized < Error; end
14
+ class Unauthorized < Error
15
+ end
14
16
 
15
- class Conflict < Error; end
17
+ class Conflict < Error
18
+ end
16
19
 
17
20
  class CreateFailed < Error
18
21
  attr_reader :res
@@ -71,6 +74,7 @@ module Skylight
71
74
  def token_valid?
72
75
  # Don't prevent boot if it's an error response, so assume token is valid
73
76
  return true if error_response?
77
+
74
78
  # A 2xx response means everything is good!
75
79
  return true if raw_response.success?
76
80
  return false if status == 401
@@ -139,22 +143,22 @@ module Skylight
139
143
 
140
144
  private
141
145
 
142
- # TODO: Improve handling here: https://github.com/tildeio/direwolf-agent/issues/274
143
- def http_request(service, method, *args)
144
- http = Util::HTTP.new(config, service)
145
- uri = URI.parse(config.get("#{service}_url"))
146
- http.send(method, uri.path, *args)
147
- end
146
+ # TODO: Improve handling here: https://github.com/tildeio/direwolf-agent/issues/274
147
+ def http_request(service, method, *args)
148
+ http = Util::HTTP.new(config, service)
149
+ uri = URI.parse(config.get("#{service}_url"))
150
+ http.send(method, uri.path, *args)
151
+ end
148
152
 
149
- def error_for_status(code)
150
- case code
151
- when 401
152
- Unauthorized
153
- when 409
154
- Conflict
155
- else
156
- Error
157
- end
153
+ def error_for_status(code)
154
+ case code
155
+ when 401
156
+ Unauthorized
157
+ when 409
158
+ Conflict
159
+ else
160
+ Error
158
161
  end
162
+ end
159
163
  end
160
164
  end
data/lib/skylight/cli.rb CHANGED
@@ -28,12 +28,13 @@ module Skylight
28
28
  Visit your app at https://www.skylight.io/app or remove config/skylight.yml
29
29
  to set it up as a new app in Skylight.
30
30
  OUT
31
+
31
32
  return
32
33
  end
33
34
 
34
35
  res = api.create_app(app_name, token)
35
36
 
36
- config[:application] = res.get("app.id")
37
+ config[:application] = res.get("app.id")
37
38
  config[:authentication] = res.get("app.token")
38
39
  config.write(config_path)
39
40
 
@@ -71,8 +72,9 @@ module Skylight
71
72
  say "Development mode warning disabled", :green
72
73
  end
73
74
 
74
- desc "disable_env_warning", "Disables warning about running Skylight in environments not defined in " \
75
- "config.skylight.environments"
75
+ desc "disable_env_warning",
76
+ "Disables warning about running Skylight in environments not defined in " \
77
+ "config.skylight.environments"
76
78
  def disable_env_warning
77
79
  user_config.disable_env_warning = true
78
80
  user_config.save
@@ -82,57 +84,56 @@ module Skylight
82
84
 
83
85
  private
84
86
 
85
- def app_name
86
- @app_name ||=
87
- begin
88
- name = nil
89
-
90
- if rails?
91
- # Get the name in a process so that we don't pollute our environment here
92
- # This is especially important since users may have things like WebMock that
93
- # will prevent us from communicating with the Skylight API
94
- begin
95
- namefile = Tempfile.new("skylight-app-name")
96
- # Windows appears to need double quotes for `rails runner`
97
- `rails runner "File.open('#{namefile.path}', 'w') {|f| f.write(Rails.application.class.name) rescue '' }"` # rubocop:disable Layout/LineLength
98
- name = namefile.read.split("::").first.underscore.titleize
99
- name = nil if name.empty?
100
- rescue => e
101
- if ENV["DEBUG"]
102
- puts e.class.name
103
- puts e.to_s
104
- puts e.backtrace.join("\n")
105
- end
106
- ensure
107
- namefile.close
108
- namefile.unlink
109
- end
110
-
111
- unless name
112
- warn "Unable to determine Rails application name. Using directory name."
87
+ def app_name
88
+ @app_name ||=
89
+ begin
90
+ name = nil
91
+
92
+ if rails?
93
+ # Get the name in a process so that we don't pollute our environment here
94
+ # This is especially important since users may have things like WebMock that
95
+ # will prevent us from communicating with the Skylight API
96
+ begin
97
+ namefile = Tempfile.new("skylight-app-name")
98
+
99
+ # Windows appears to need double quotes for `rails runner`
100
+ `rails runner "File.open('#{namefile.path}', 'w') {|f| f.write(Rails.application.class.name) rescue '' }"`
101
+ name = namefile.read.split("::").first.underscore.titleize
102
+ name = nil if name.empty?
103
+ rescue StandardError => e
104
+ if ENV["DEBUG"]
105
+ puts e.class.name
106
+ puts e.to_s
107
+ puts e.backtrace.join("\n")
113
108
  end
109
+ ensure
110
+ namefile.close
111
+ namefile.unlink
114
112
  end
115
113
 
116
- name || File.basename(File.expand_path(".")).titleize
114
+ warn "Unable to determine Rails application name. Using directory name." unless name
117
115
  end
118
- end
119
116
 
120
- # Is this duplicated?
121
- def relative_config_path
122
- "config/skylight.yml"
123
- end
117
+ name || File.basename(File.expand_path(".")).titleize
118
+ end
119
+ end
124
120
 
125
- def config_path
126
- File.expand_path(relative_config_path)
127
- end
121
+ # Is this duplicated?
122
+ def relative_config_path
123
+ "config/skylight.yml"
124
+ end
128
125
 
129
- def api
130
- @api ||= Api.new(config)
131
- end
126
+ def config_path
127
+ File.expand_path(relative_config_path)
128
+ end
132
129
 
133
- def user_config
134
- config.user_config
135
- end
130
+ def api
131
+ @api ||= Api.new(config)
132
+ end
133
+
134
+ def user_config
135
+ config.user_config
136
+ end
136
137
  end
137
138
  end
138
139
  end