skylight 1.7.2 → 2.0.0.beta1

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.
Files changed (102) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +4 -33
  3. data/ext/extconf.rb +32 -6
  4. data/ext/libskylight.yml +6 -9
  5. data/ext/skylight_native.c +49 -18
  6. data/lib/skylight.rb +35 -1
  7. data/lib/skylight/api.rb +4 -2
  8. data/lib/skylight/cli.rb +1 -1
  9. data/lib/skylight/cli/doctor.rb +6 -4
  10. data/lib/skylight/config.rb +149 -518
  11. data/lib/skylight/data/cacert.pem +236 -812
  12. data/lib/skylight/helpers.rb +5 -1
  13. data/lib/skylight/instrumenter.rb +10 -241
  14. data/lib/skylight/middleware.rb +1 -89
  15. data/lib/skylight/native.rb +8 -6
  16. data/lib/skylight/native_ext_fetcher.rb +251 -0
  17. data/lib/skylight/normalizers/active_job/enqueue_at.rb +2 -20
  18. data/lib/skylight/probes/sinatra_add_middleware.rb +22 -0
  19. data/lib/skylight/railtie.rb +11 -131
  20. data/lib/skylight/sinatra.rb +1 -5
  21. data/lib/skylight/trace.rb +1 -229
  22. data/lib/skylight/util/http.rb +3 -3
  23. data/lib/skylight/vendor/cli/thor/actions/directory.rb +5 -15
  24. data/lib/skylight/version.rb +1 -1
  25. metadata +114 -91
  26. data/lib/skylight/compat.rb +0 -76
  27. data/lib/skylight/core.rb +0 -149
  28. data/lib/skylight/deprecation.rb +0 -55
  29. data/lib/skylight/formatters/http.rb +0 -20
  30. data/lib/skylight/gc.rb +0 -107
  31. data/lib/skylight/normalizers.rb +0 -192
  32. data/lib/skylight/normalizers/action_controller/process_action.rb +0 -50
  33. data/lib/skylight/normalizers/action_controller/send_file.rb +0 -50
  34. data/lib/skylight/normalizers/action_view/render_collection.rb +0 -22
  35. data/lib/skylight/normalizers/action_view/render_partial.rb +0 -21
  36. data/lib/skylight/normalizers/action_view/render_template.rb +0 -21
  37. data/lib/skylight/normalizers/active_model_serializers/render.rb +0 -26
  38. data/lib/skylight/normalizers/active_record/instantiation.rb +0 -17
  39. data/lib/skylight/normalizers/active_record/sql.rb +0 -55
  40. data/lib/skylight/normalizers/active_support/cache.rb +0 -51
  41. data/lib/skylight/normalizers/active_support/cache_clear.rb +0 -16
  42. data/lib/skylight/normalizers/active_support/cache_decrement.rb +0 -16
  43. data/lib/skylight/normalizers/active_support/cache_delete.rb +0 -16
  44. data/lib/skylight/normalizers/active_support/cache_exist.rb +0 -16
  45. data/lib/skylight/normalizers/active_support/cache_fetch_hit.rb +0 -16
  46. data/lib/skylight/normalizers/active_support/cache_generate.rb +0 -16
  47. data/lib/skylight/normalizers/active_support/cache_increment.rb +0 -16
  48. data/lib/skylight/normalizers/active_support/cache_read.rb +0 -16
  49. data/lib/skylight/normalizers/active_support/cache_read_multi.rb +0 -16
  50. data/lib/skylight/normalizers/active_support/cache_write.rb +0 -16
  51. data/lib/skylight/normalizers/coach/handler_finish.rb +0 -36
  52. data/lib/skylight/normalizers/coach/middleware_finish.rb +0 -23
  53. data/lib/skylight/normalizers/couch_potato/query.rb +0 -20
  54. data/lib/skylight/normalizers/default.rb +0 -27
  55. data/lib/skylight/normalizers/elasticsearch/request.rb +0 -20
  56. data/lib/skylight/normalizers/faraday/request.rb +0 -38
  57. data/lib/skylight/normalizers/grape/endpoint.rb +0 -30
  58. data/lib/skylight/normalizers/grape/endpoint_render.rb +0 -26
  59. data/lib/skylight/normalizers/grape/endpoint_run.rb +0 -33
  60. data/lib/skylight/normalizers/grape/endpoint_run_filters.rb +0 -23
  61. data/lib/skylight/normalizers/moped/query.rb +0 -100
  62. data/lib/skylight/probes.rb +0 -129
  63. data/lib/skylight/probes/action_controller.rb +0 -64
  64. data/lib/skylight/probes/action_dispatch.rb +0 -30
  65. data/lib/skylight/probes/action_view.rb +0 -43
  66. data/lib/skylight/probes/active_model_serializers.rb +0 -55
  67. data/lib/skylight/probes/elasticsearch.rb +0 -37
  68. data/lib/skylight/probes/excon.rb +0 -26
  69. data/lib/skylight/probes/excon/middleware.rb +0 -68
  70. data/lib/skylight/probes/faraday.rb +0 -22
  71. data/lib/skylight/probes/grape.rb +0 -88
  72. data/lib/skylight/probes/httpclient.rb +0 -46
  73. data/lib/skylight/probes/middleware.rb +0 -68
  74. data/lib/skylight/probes/mongo.rb +0 -161
  75. data/lib/skylight/probes/mongoid.rb +0 -21
  76. data/lib/skylight/probes/moped.rb +0 -39
  77. data/lib/skylight/probes/net_http.rb +0 -58
  78. data/lib/skylight/probes/redis.rb +0 -71
  79. data/lib/skylight/probes/sequel.rb +0 -37
  80. data/lib/skylight/probes/sinatra.rb +0 -76
  81. data/lib/skylight/probes/tilt.rb +0 -31
  82. data/lib/skylight/subscriber.rb +0 -122
  83. data/lib/skylight/user_config.rb +0 -60
  84. data/lib/skylight/util.rb +0 -17
  85. data/lib/skylight/util/allocation_free.rb +0 -26
  86. data/lib/skylight/util/clock.rb +0 -54
  87. data/lib/skylight/util/deploy.rb +0 -132
  88. data/lib/skylight/util/gzip.rb +0 -21
  89. data/lib/skylight/util/inflector.rb +0 -112
  90. data/lib/skylight/util/logging.rb +0 -127
  91. data/lib/skylight/util/multi_io.rb +0 -21
  92. data/lib/skylight/util/native_ext_fetcher.rb +0 -253
  93. data/lib/skylight/util/platform.rb +0 -75
  94. data/lib/skylight/util/proxy.rb +0 -13
  95. data/lib/skylight/vendor/active_support/notifications.rb +0 -207
  96. data/lib/skylight/vendor/active_support/notifications/fanout.rb +0 -159
  97. data/lib/skylight/vendor/active_support/notifications/instrumenter.rb +0 -72
  98. data/lib/skylight/vendor/active_support/per_thread_registry.rb +0 -52
  99. data/lib/skylight/vendor/thread_safe.rb +0 -126
  100. data/lib/skylight/vendor/thread_safe/non_concurrent_cache_backend.rb +0 -133
  101. data/lib/skylight/vendor/thread_safe/synchronized_cache_backend.rb +0 -76
  102. data/lib/skylight/vm/gc.rb +0 -70
@@ -1,21 +0,0 @@
1
- require 'zlib'
2
-
3
- module Skylight
4
- module Util
5
- # Provides Gzip compressing support
6
- module Gzip
7
-
8
- # Compress a string with Gzip
9
- #
10
- # @param str [String] uncompressed string
11
- # @return [String] compressed string
12
- def self.compress(str)
13
- output = StringIO.new
14
- gz = Zlib::GzipWriter.new(output)
15
- gz.write(str)
16
- gz.close
17
- output.string
18
- end
19
- end
20
- end
21
- end
@@ -1,112 +0,0 @@
1
- module Skylight
2
- module Util
3
-
4
- # String Inflector methods
5
- #
6
- # From https://github.com/rails/rails/blob/f8e5022c73679f41db9bb6743179bab4571fb28e/activesupport/lib/active_support/inflector/methods.rb
7
- module Inflector
8
- extend self
9
-
10
- # Tries to find a constant with the name specified in the argument string.
11
- #
12
- # 'Module'.constantize # => Module
13
- # 'Test::Unit'.constantize # => Test::Unit
14
- #
15
- # The name is assumed to be the one of a top-level constant, no matter
16
- # whether it starts with "::" or not. No lexical context is taken into
17
- # account:
18
- #
19
- # C = 'outside'
20
- # module M
21
- # C = 'inside'
22
- # C # => 'inside'
23
- # 'C'.constantize # => 'outside', same as ::C
24
- # end
25
- #
26
- # NameError is raised when the name is not in CamelCase or the constant is
27
- # unknown.
28
- def constantize(camel_cased_word)
29
- names = camel_cased_word.split('::')
30
-
31
- # Trigger a builtin NameError exception including the ill-formed constant in the message.
32
- Object.const_get(camel_cased_word) if names.empty?
33
-
34
- # Remove the first blank element in case of '::ClassName' notation.
35
- names.shift if names.size > 1 && names.first.empty?
36
-
37
- names.inject(Object) do |constant, name|
38
- if constant == Object
39
- constant.const_get(name)
40
- else
41
- candidate = constant.const_get(name)
42
- next candidate if constant.const_defined?(name, false)
43
- next candidate unless Object.const_defined?(name)
44
-
45
- # Go down the ancestors to check it it's owned
46
- # directly before we reach Object or the end of ancestors.
47
- constant = constant.ancestors.inject do |const, ancestor|
48
- break const if ancestor == Object
49
- break ancestor if ancestor.const_defined?(name, false)
50
- const
51
- end
52
-
53
- # owner is in Object, so raise
54
- constant.const_get(name, false)
55
- end
56
- end
57
- end
58
-
59
- # Tries to find a constant with the name specified in the argument string.
60
- #
61
- # 'Module'.safe_constantize # => Module
62
- # 'Test::Unit'.safe_constantize # => Test::Unit
63
- #
64
- # The name is assumed to be the one of a top-level constant, no matter
65
- # whether it starts with "::" or not. No lexical context is taken into
66
- # account:
67
- #
68
- # C = 'outside'
69
- # module M
70
- # C = 'inside'
71
- # C # => 'inside'
72
- # 'C'.safe_constantize # => 'outside', same as ::C
73
- # end
74
- #
75
- # +nil+ is returned when the name is not in CamelCase or the constant (or
76
- # part of it) is unknown.
77
- #
78
- # 'blargle'.safe_constantize # => nil
79
- # 'UnknownModule'.safe_constantize # => nil
80
- # 'UnknownModule::Foo::Bar'.safe_constantize # => nil
81
- def safe_constantize(camel_cased_word)
82
- constantize(camel_cased_word)
83
- rescue NameError => e
84
- raise unless e.message =~ /(uninitialized constant|wrong constant name) #{const_regexp(camel_cased_word)}$/ ||
85
- e.name.to_s == camel_cased_word.to_s
86
- rescue ArgumentError => e
87
- raise unless e.message =~ /not missing constant #{const_regexp(camel_cased_word)}\!$/
88
- end
89
-
90
- private
91
-
92
- # Mount a regular expression that will match part by part of the constant.
93
- #
94
- # const_regexp("Foo::Bar::Baz") # => /(Foo(::Bar(::Baz)?)?|Bar|Baz)/
95
- # const_regexp("::") # => /::/
96
- #
97
- # NOTE: We also add each part in singly, because sometimes a search for a missing
98
- # constant like Skylight::Foo::Bar will return an error just saying Foo was missing
99
- def const_regexp(camel_cased_word) #:nodoc:
100
- parts = camel_cased_word.split("::")
101
-
102
- return Regexp.escape(camel_cased_word) if parts.empty?
103
-
104
- regexp = parts.reverse.inject do |acc, part|
105
- part.empty? ? acc : "#{part}(::#{acc})?"
106
- end
107
-
108
- "(" + ([regexp] + parts[1..-1]).join('|') + ")"
109
- end
110
- end
111
- end
112
- end
@@ -1,127 +0,0 @@
1
- require 'logger'
2
-
3
- module Skylight
4
- module Util
5
- # Log both to the specified logger and STDOUT
6
- class AlertLogger
7
- def initialize(logger)
8
- @logger = logger
9
- end
10
-
11
- def write(*args)
12
- STDERR.write *args
13
-
14
- # Try to avoid writing to STDOUT/STDERR twice
15
- logger_logdev = @logger.instance_variable_get(:@logdev)
16
- logger_out = logger_logdev && logger_logdev.respond_to?(:dev) ? logger_logdev.dev : nil
17
- if logger_out != STDOUT && logger_out != STDERR
18
- @logger.<<(*args)
19
- end
20
- end
21
-
22
- def close
23
- end
24
- end
25
-
26
- module Logging
27
-
28
- def self.trace?
29
- ENV[TRACE_ENV_KEY]
30
- end
31
-
32
- if trace?
33
- # The second set is picked up by YARD
34
- def trace(msg, *args)
35
- log :debug, msg, *args
36
- end
37
-
38
- def t
39
- log :debug, yield
40
- end
41
- else
42
- # Logs if `ENV[TRACE_ENV_KEY]` is set.
43
- #
44
- # @param (see #debug)
45
- #
46
- # See {TRACE_ENV_KEY}.
47
- def trace(msg, *args)
48
- end
49
-
50
- # Evaluates and logs the result of the block if `ENV[TRACE_ENV_KEY]` is set
51
- #
52
- # @yield block to be evaluted
53
- # @yieldreturn arguments for {#debug}
54
- #
55
- # See {TRACE_ENV_KEY}.
56
- def t
57
- end
58
- end
59
-
60
- # @param msg (see #log)
61
- # @param args (see #log)
62
- def debug(msg, *args)
63
- log :debug, msg, *args
64
- end
65
-
66
- # @param msg (see #log)
67
- # @param args (see #log)
68
- def info(msg, *args)
69
- log :info, msg, *args
70
- end
71
-
72
- # @param msg (see #log)
73
- # @param args (see #log)
74
- def warn(msg, *args)
75
- log :warn, msg, *args
76
- end
77
-
78
- # @param msg (see #log)
79
- # @param args (see #log)
80
- def error(msg, *args)
81
- log :error, msg, *args
82
- raise sprintf(msg, *args) if ENV['SKYLIGHT_RAISE_ON_ERROR']
83
- end
84
-
85
- alias log_trace trace
86
- alias log_debug debug
87
- alias log_info info
88
- alias log_warn warn
89
- alias log_error error
90
-
91
- # Alias for `Kernel#sprintf`
92
- # @return [String]
93
- def fmt(*args)
94
- sprintf(*args)
95
- end
96
-
97
- # @param level [String,Symbol] the method on `logger` to use for logging
98
- # @param msg [String] the message to log
99
- # @param args [Array] values for `Kernel#sprintf` on `msg`
100
- def log(level, msg, *args)
101
- c = if respond_to?(:config)
102
- config
103
- elsif self.is_a?(Config)
104
- self
105
- end
106
-
107
- return unless c
108
-
109
- if logger = c.logger
110
- return unless logger.respond_to?(level)
111
-
112
- if args.length > 0
113
- logger.send level, sprintf("[SKYLIGHT] [#{Skylight::VERSION}] #{msg}", *args)
114
- else
115
- logger.send level, "[SKYLIGHT] [#{Skylight::VERSION}] #{msg}"
116
- end
117
- end
118
- rescue Exception => e
119
- if ENV[TRACE_ENV_KEY]
120
- puts "[ERROR] #{e.message}"
121
- puts e.backtrace
122
- end
123
- end
124
-
125
- end
126
- end
127
- end
@@ -1,21 +0,0 @@
1
- # Util allowing proxying writes to multiple location
2
- # Used from extconf
3
- module Skylight
4
- module Util
5
- class MultiIO
6
-
7
- def initialize(*targets)
8
- @targets = targets
9
- end
10
-
11
- def write(*args)
12
- @targets.each {|t| t.write(*args)}
13
- end
14
-
15
- def close
16
- @targets.each(&:close)
17
- end
18
-
19
- end
20
- end
21
- end
@@ -1,253 +0,0 @@
1
- require 'uri'
2
- require 'logger'
3
- require 'net/http'
4
- require 'fileutils'
5
- require 'digest/sha2'
6
- require 'skylight/util/ssl'
7
- require 'skylight/util/proxy'
8
-
9
- # Used from extconf.rb
10
- module Skylight
11
- module Util
12
- # Utility class for fetching the native extension from a URL
13
- class NativeExtFetcher
14
- BASE_URL = "https://s3.amazonaws.com/skylight-agent-packages/skylight-native"
15
- MAX_REDIRECTS = 5
16
- MAX_RETRIES = 3
17
-
18
- include FileUtils
19
-
20
- class FetchError < StandardError; end
21
-
22
- # Creates a new fetcher and fetches
23
- # @param opts [Hash]
24
- def self.fetch(opts = {})
25
- fetcher = new(
26
- opts[:source] || BASE_URL,
27
- opts[:target],
28
- opts[:version],
29
- opts[:checksum],
30
- opts[:arch],
31
- opts[:required],
32
- opts[:platform],
33
- opts[:logger] || Logger.new(STDOUT))
34
-
35
- fetcher.fetch
36
- end
37
-
38
- # @param source [String] the base url to download from
39
- # @param target [String] file to download as
40
- # @param version [String] version to download
41
- # @param checksum [String] checksum of the archive
42
- # @param arch [String] platform architecture, e.g. `linux-x86_64`
43
- # @param required [Boolean] whether the download is required to be successful
44
- # @param platform
45
- # @param log [Logger]
46
- def initialize(source, target, version, checksum, arch, required, platform, log)
47
- raise "source required" unless source
48
- raise "target required" unless target
49
- raise "checksum required" unless checksum
50
- raise "arch required" unless arch
51
-
52
- @source = source
53
- @target = target
54
- @version = version
55
- @checksum = checksum
56
- @required = required
57
- @platform = platform
58
- @arch = arch
59
- @log = log
60
- end
61
-
62
- # Fetch the native extension, verify, inflate, and save (if applicable)
63
- #
64
- # @return [String] the inflated archive
65
- def fetch
66
- log "fetching native ext; curr-platform=#{@platform}; " \
67
- "requested-arch=#{@arch}; version=#{@version}"
68
-
69
- tar_gz = "#{@target}/#{basename}"
70
-
71
- unless sha2 = fetch_native_ext(source_uri, tar_gz, MAX_RETRIES, MAX_REDIRECTS)
72
- maybe_raise "could not fetch native extension"
73
- return
74
- end
75
-
76
- unless verify_checksum(sha2)
77
- maybe_raise "could not verify checksum"
78
- return
79
- end
80
-
81
- Dir.chdir File.dirname(tar_gz) do
82
- system "tar xzvf #{tar_gz}"
83
- end
84
-
85
- true
86
- ensure
87
- rm_f tar_gz if tar_gz
88
- end
89
-
90
- def fetch_native_ext(uri, out, attempts, redirects)
91
- redirects.times do |i|
92
- # Ensure the location is available
93
- mkdir_p File.dirname(out)
94
- rm_f out
95
-
96
- remaining_attempts = attempts
97
-
98
- log "attempting to fetch from remote; uri=#{uri}"
99
-
100
- begin
101
- host, port, use_ssl, path = deconstruct_uri(uri)
102
-
103
- File.open out, 'w' do |f|
104
- res, extra = http_get(host, port, use_ssl, path, f)
105
-
106
- case res
107
- when :success
108
- log "successfully downloaded native ext; out=#{out}"
109
- return extra
110
- when :redirect
111
- log "fetching native ext; uri=#{uri}; redirected=#{res}"
112
- uri = extra
113
-
114
- next
115
- end
116
- end
117
- rescue => e
118
- remaining_attempts -= 1
119
-
120
- error "failed to fetch native extension; uri=#{uri}; msg=#{e.message}; remaining-attempts=#{remaining_attempts}", e
121
-
122
- if remaining_attempts > 0
123
- sleep 2
124
- retry
125
- end
126
-
127
- return
128
- end
129
- end
130
-
131
- log "exceeded max redirects"
132
- return
133
- end
134
-
135
- # Get with `Net::HTTP`
136
- #
137
- # @param host [String] host for `Net::HTTP` request
138
- # @param port [String,Integer] port for `Net::HTTP` request
139
- # @param use_ssl [Boolean] whether SSL should be used for this request
140
- # @param path [String] the path to request
141
- # @param out [IO]
142
- #
143
- # If `ENV['HTTP_PROXY']` is set, it will be used as a proxy for this request.
144
- def http_get(host, port, use_ssl, path, out)
145
- if http_proxy = Proxy.detect_url(ENV)
146
- log "connecting with proxy: #{http_proxy}"
147
- uri = URI.parse(http_proxy)
148
- p_host, p_port = uri.host, uri.port
149
- p_user, p_pass = uri.userinfo.split(/:/) if uri.userinfo
150
- end
151
-
152
- opts = {}
153
- opts[:use_ssl] = use_ssl
154
-
155
- if use_ssl
156
- opts[:ca_file] = SSL.ca_cert_file_or_default
157
- end
158
-
159
- Net::HTTP.start(host, port, p_host, p_port, p_user, p_pass, use_ssl: use_ssl) do |http|
160
- http.request_get path do |resp|
161
- case resp
162
- when Net::HTTPSuccess
163
- digest = Digest::SHA2.new
164
-
165
- resp.read_body do |chunk|
166
- digest << chunk
167
- out.write chunk
168
- end
169
-
170
- return [ :success, digest.hexdigest ]
171
- when Net::HTTPRedirection
172
- unless location = resp['location']
173
- raise "received redirect but no location"
174
- end
175
-
176
- return [ :redirect, location ]
177
- else
178
- raise "received HTTP status code #{resp.code}"
179
- end
180
- end
181
- end
182
- end
183
-
184
- # Verify the checksum of the archive
185
- #
186
- # @param actual [String]
187
- # @return [Boolean] whether the checksum matches
188
- def verify_checksum(actual)
189
- unless @checksum == actual
190
- log "checksum mismatch; expected=#{@checksum}; actual=#{actual}"
191
- return false
192
- end
193
-
194
- true
195
- rescue Exception => e
196
- error "failed to read skylight agent archive; e=#{e.message}"
197
- false
198
- end
199
-
200
- def basename
201
- "skylight_#{@arch}.tar.gz"
202
- end
203
-
204
- # The url that will be fetched
205
- #
206
- # @return String
207
- def source_uri
208
- "#{@source}/#{@version}/#{basename}"
209
- end
210
-
211
- # Split the uri string into its component parts
212
- #
213
- # @param uri [String] the uri
214
- # @return [Array<String>] the host, port, scheme, and request_uri
215
- def deconstruct_uri(uri)
216
- uri = URI(uri)
217
- [ uri.host, uri.port, uri.scheme == 'https', uri.request_uri ]
218
- end
219
-
220
- # Log an error and raise if `required` is `true`
221
- #
222
- # @param err [String]
223
- # @return [void]
224
- def maybe_raise(err)
225
- error err
226
-
227
- if @required
228
- raise err
229
- end
230
- end
231
-
232
- # Log an `info` to the `logger`
233
- #
234
- # @param msg [String]
235
- # @return [void]
236
- def log(msg)
237
- msg = "[SKYLIGHT] #{msg}"
238
- @log.info msg
239
- end
240
-
241
- # Log an `error` to the `logger`
242
- #
243
- # @param msg [String]
244
- # @param e [Exception] the exception associated with the error
245
- # @return [void]
246
- def error(msg, e=nil)
247
- msg = "[SKYLIGHT] #{msg}"
248
- msg << "\n#{e.backtrace.join("\n")}" if e
249
- @log.error msg
250
- end
251
- end
252
- end
253
- end