skylight 4.2.3 → 5.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (123) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +420 -331
  3. data/CLA.md +1 -1
  4. data/CONTRIBUTING.md +2 -8
  5. data/ERRORS.md +3 -0
  6. data/LICENSE.md +7 -17
  7. data/README.md +1 -1
  8. data/ext/extconf.rb +61 -56
  9. data/ext/libskylight.yml +8 -6
  10. data/ext/skylight_native.c +26 -100
  11. data/lib/skylight/api.rb +32 -21
  12. data/lib/skylight/cli/doctor.rb +64 -65
  13. data/lib/skylight/cli/helpers.rb +19 -19
  14. data/lib/skylight/cli/merger.rb +142 -138
  15. data/lib/skylight/cli.rb +48 -46
  16. data/lib/skylight/config.rb +640 -201
  17. data/lib/skylight/data/cacert.pem +730 -1023
  18. data/lib/skylight/deprecation.rb +17 -0
  19. data/lib/skylight/errors.rb +26 -9
  20. data/lib/skylight/extensions/source_location.rb +291 -0
  21. data/lib/skylight/extensions.rb +95 -0
  22. data/lib/skylight/formatters/http.rb +18 -0
  23. data/lib/skylight/gc.rb +99 -0
  24. data/lib/skylight/helpers.rb +81 -36
  25. data/lib/skylight/instrumenter.rb +336 -18
  26. data/lib/skylight/middleware.rb +147 -1
  27. data/lib/skylight/native.rb +60 -12
  28. data/lib/skylight/native_ext_fetcher.rb +13 -14
  29. data/lib/skylight/normalizers/action_controller/process_action.rb +68 -0
  30. data/lib/skylight/normalizers/action_controller/send_file.rb +51 -0
  31. data/lib/skylight/normalizers/action_dispatch/process_middleware.rb +22 -0
  32. data/lib/skylight/normalizers/action_dispatch/route_set.rb +27 -0
  33. data/lib/skylight/normalizers/action_view/render_collection.rb +24 -0
  34. data/lib/skylight/normalizers/action_view/render_layout.rb +25 -0
  35. data/lib/skylight/normalizers/action_view/render_partial.rb +23 -0
  36. data/lib/skylight/normalizers/action_view/render_template.rb +23 -0
  37. data/lib/skylight/normalizers/active_job/perform.rb +87 -0
  38. data/lib/skylight/normalizers/active_model_serializers/render.rb +32 -0
  39. data/lib/skylight/normalizers/active_record/instantiation.rb +16 -0
  40. data/lib/skylight/normalizers/active_record/sql.rb +20 -0
  41. data/lib/skylight/normalizers/active_storage.rb +28 -0
  42. data/lib/skylight/normalizers/active_support/cache.rb +11 -0
  43. data/lib/skylight/normalizers/active_support/cache_clear.rb +16 -0
  44. data/lib/skylight/normalizers/active_support/cache_decrement.rb +16 -0
  45. data/lib/skylight/normalizers/active_support/cache_delete.rb +16 -0
  46. data/lib/skylight/normalizers/active_support/cache_exist.rb +16 -0
  47. data/lib/skylight/normalizers/active_support/cache_fetch_hit.rb +16 -0
  48. data/lib/skylight/normalizers/active_support/cache_generate.rb +16 -0
  49. data/lib/skylight/normalizers/active_support/cache_increment.rb +16 -0
  50. data/lib/skylight/normalizers/active_support/cache_read.rb +16 -0
  51. data/lib/skylight/normalizers/active_support/cache_read_multi.rb +16 -0
  52. data/lib/skylight/normalizers/active_support/cache_write.rb +16 -0
  53. data/lib/skylight/normalizers/coach/handler_finish.rb +44 -0
  54. data/lib/skylight/normalizers/coach/middleware_finish.rb +33 -0
  55. data/lib/skylight/normalizers/couch_potato/query.rb +20 -0
  56. data/lib/skylight/normalizers/data_mapper/sql.rb +12 -0
  57. data/lib/skylight/normalizers/default.rb +24 -0
  58. data/lib/skylight/normalizers/elasticsearch/request.rb +20 -0
  59. data/lib/skylight/normalizers/faraday/request.rb +38 -0
  60. data/lib/skylight/normalizers/grape/endpoint.rb +28 -0
  61. data/lib/skylight/normalizers/grape/endpoint_render.rb +25 -0
  62. data/lib/skylight/normalizers/grape/endpoint_run.rb +39 -0
  63. data/lib/skylight/normalizers/grape/endpoint_run_filters.rb +20 -0
  64. data/lib/skylight/normalizers/grape/format_response.rb +20 -0
  65. data/lib/skylight/normalizers/graphiti/render.rb +22 -0
  66. data/lib/skylight/normalizers/graphiti/resolve.rb +31 -0
  67. data/lib/skylight/normalizers/graphql/base.rb +127 -0
  68. data/lib/skylight/normalizers/render.rb +79 -0
  69. data/lib/skylight/normalizers/sequel/sql.rb +12 -0
  70. data/lib/skylight/normalizers/shrine.rb +32 -0
  71. data/lib/skylight/normalizers/sql.rb +41 -0
  72. data/lib/skylight/normalizers.rb +157 -0
  73. data/lib/skylight/probes/action_controller.rb +52 -0
  74. data/lib/skylight/probes/action_dispatch/request_id.rb +33 -0
  75. data/lib/skylight/probes/action_dispatch/routing/route_set.rb +30 -0
  76. data/lib/skylight/probes/action_dispatch.rb +2 -0
  77. data/lib/skylight/probes/action_view.rb +42 -0
  78. data/lib/skylight/probes/active_job.rb +27 -0
  79. data/lib/skylight/probes/active_job_enqueue.rb +35 -0
  80. data/lib/skylight/probes/active_model_serializers.rb +50 -0
  81. data/lib/skylight/probes/active_record_async.rb +96 -0
  82. data/lib/skylight/probes/delayed_job.rb +144 -0
  83. data/lib/skylight/probes/elasticsearch.rb +36 -0
  84. data/lib/skylight/probes/excon/middleware.rb +65 -0
  85. data/lib/skylight/probes/excon.rb +25 -0
  86. data/lib/skylight/probes/faraday.rb +23 -0
  87. data/lib/skylight/probes/graphql.rb +38 -0
  88. data/lib/skylight/probes/httpclient.rb +44 -0
  89. data/lib/skylight/probes/middleware.rb +135 -0
  90. data/lib/skylight/probes/mongo.rb +156 -0
  91. data/lib/skylight/probes/mongoid.rb +13 -0
  92. data/lib/skylight/probes/net_http.rb +54 -0
  93. data/lib/skylight/probes/rack_builder.rb +37 -0
  94. data/lib/skylight/probes/redis.rb +51 -0
  95. data/lib/skylight/probes/sequel.rb +29 -0
  96. data/lib/skylight/probes/sinatra.rb +66 -0
  97. data/lib/skylight/probes/sinatra_add_middleware.rb +10 -10
  98. data/lib/skylight/probes/tilt.rb +25 -0
  99. data/lib/skylight/probes.rb +173 -0
  100. data/lib/skylight/railtie.rb +166 -28
  101. data/lib/skylight/sidekiq.rb +47 -0
  102. data/lib/skylight/sinatra.rb +1 -1
  103. data/lib/skylight/subscriber.rb +130 -0
  104. data/lib/skylight/test.rb +147 -0
  105. data/lib/skylight/trace.rb +325 -22
  106. data/lib/skylight/user_config.rb +58 -0
  107. data/lib/skylight/util/allocation_free.rb +26 -0
  108. data/lib/skylight/util/clock.rb +57 -0
  109. data/lib/skylight/util/component.rb +22 -22
  110. data/lib/skylight/util/deploy.rb +19 -24
  111. data/lib/skylight/util/gzip.rb +20 -0
  112. data/lib/skylight/util/http.rb +106 -113
  113. data/lib/skylight/util/instrumenter_method.rb +26 -0
  114. data/lib/skylight/util/logging.rb +136 -0
  115. data/lib/skylight/util/lru_cache.rb +36 -0
  116. data/lib/skylight/util/platform.rb +3 -7
  117. data/lib/skylight/util/ssl.rb +1 -25
  118. data/lib/skylight/util.rb +12 -0
  119. data/lib/skylight/vendor/cli/thor/rake_compat.rb +1 -1
  120. data/lib/skylight/version.rb +5 -1
  121. data/lib/skylight/vm/gc.rb +60 -0
  122. data/lib/skylight.rb +201 -14
  123. metadata +134 -18
@@ -0,0 +1,20 @@
1
+ require "zlib"
2
+
3
+ module Skylight
4
+ module Util
5
+ # Provides Gzip compressing support
6
+ module Gzip
7
+ # Compress a string with Gzip
8
+ #
9
+ # @param str [String] uncompressed string
10
+ # @return [String] compressed string
11
+ def self.compress(str)
12
+ output = StringIO.new
13
+ gz = Zlib::GzipWriter.new(output)
14
+ gz.write(str)
15
+ gz.close
16
+ output.string
17
+ end
18
+ end
19
+ end
20
+ end
@@ -3,23 +3,23 @@ require "json"
3
3
  require "openssl"
4
4
  require "net/http"
5
5
  require "net/https"
6
- require "skylight/core/util/gzip"
6
+ require "skylight/util/gzip"
7
7
  require "skylight/util/ssl"
8
8
 
9
9
  module Skylight
10
10
  module Util
11
11
  class HTTP
12
12
  CONTENT_ENCODING = "content-encoding".freeze
13
- CONTENT_LENGTH = "content-length".freeze
14
- CONTENT_TYPE = "content-type".freeze
15
- ACCEPT = "Accept".freeze
16
- X_VERSION_HDR = "x-skylight-agent-version".freeze
13
+ CONTENT_LENGTH = "content-length".freeze
14
+ CONTENT_TYPE = "content-type".freeze
15
+ ACCEPT = "Accept".freeze
16
+ X_VERSION_HDR = "x-skylight-agent-version".freeze
17
17
  APPLICATION_JSON = "application/json".freeze
18
- AUTHORIZATION = "authorization".freeze
19
- DEFLATE = "deflate".freeze
20
- GZIP = "gzip".freeze
18
+ AUTHORIZATION = "authorization".freeze
19
+ DEFLATE = "deflate".freeze
20
+ GZIP = "gzip".freeze
21
21
 
22
- include Core::Util::Logging
22
+ include Logging
23
23
 
24
24
  attr_accessor :authentication
25
25
  attr_reader :host, :port, :config
@@ -35,7 +35,8 @@ module Skylight
35
35
  end
36
36
  end
37
37
 
38
- class ReadResponseError < StandardError; end
38
+ class ReadResponseError < StandardError
39
+ end
39
40
 
40
41
  def initialize(config, service = :auth, opts = {})
41
42
  @config = config
@@ -46,7 +47,7 @@ module Skylight
46
47
 
47
48
  url = URI.parse(url)
48
49
 
49
- @ssl = url.scheme == "https"
50
+ @ssl = url.scheme == "https"
50
51
  @host = url.host
51
52
  @port = url.port
52
53
 
@@ -81,137 +82,129 @@ module Skylight
81
82
 
82
83
  private
83
84
 
84
- def get_timeout(type, config, service, opts)
85
- config.duration_ms("#{service}_http_#{type}_timeout") ||
86
- opts[:timeout] || 15
87
- end
85
+ def get_timeout(type, config, service, opts)
86
+ config.duration_ms("#{service}_http_#{type}_timeout") || opts[:timeout] || 15
87
+ end
88
88
 
89
- def build_request(type, endpoint, hdrs, length = nil)
90
- headers = {}
89
+ def build_request(type, endpoint, hdrs, length = nil)
90
+ headers = {}
91
91
 
92
- headers[CONTENT_LENGTH] = length.to_s if length
93
- headers[AUTHORIZATION] = authentication if authentication
94
- headers[ACCEPT] = APPLICATION_JSON
95
- headers[X_VERSION_HDR] = VERSION
96
- headers[CONTENT_ENCODING] = GZIP if length && @deflate
92
+ headers[CONTENT_LENGTH] = length.to_s if length
93
+ headers[AUTHORIZATION] = authentication if authentication
94
+ headers[ACCEPT] = APPLICATION_JSON
95
+ headers[X_VERSION_HDR] = VERSION
96
+ headers[CONTENT_ENCODING] = GZIP if length && @deflate
97
97
 
98
- hdrs.each do |k, v|
99
- headers[k] = v
100
- end
98
+ hdrs.each { |k, v| headers[k] = v }
101
99
 
102
- type.new(endpoint, headers)
100
+ type.new(endpoint, headers)
101
+ end
102
+
103
+ def do_request(http, req)
104
+ begin
105
+ client = http.start
106
+ rescue StandardError => e
107
+ # TODO: Retry here
108
+ raise StartError, e
103
109
  end
104
110
 
105
- def do_request(http, req)
106
- begin
107
- client = http.start
108
- rescue => e
109
- # TODO: Retry here
110
- raise StartError, e
111
- end
111
+ begin
112
+ res = client.request(req)
113
+ rescue *READ_EXCEPTIONS => e
114
+ raise ReadResponseError, e.inspect
115
+ end
112
116
 
113
- begin
114
- res = client.request(req)
115
- rescue *READ_EXCEPTIONS => e
116
- raise ReadResponseError, e.inspect
117
- end
117
+ yield res
118
+ ensure
119
+ client&.finish
120
+ end
118
121
 
119
- yield res
120
- ensure
121
- client.finish if client
122
+ def execute(req, body = nil)
123
+ t do
124
+ fmt "executing HTTP request; host=%s; port=%s; path=%s, body=%s",
125
+ @host,
126
+ @port,
127
+ req.path,
128
+ body && body.bytesize
122
129
  end
123
130
 
124
- def execute(req, body = nil)
125
- t do
126
- fmt "executing HTTP request; host=%s; port=%s; path=%s, body=%s",
127
- @host, @port, req.path, body && body.bytesize
128
- end
131
+ if body
132
+ body = Gzip.compress(body) if @deflate
133
+ req.body = body
134
+ end
129
135
 
130
- if body
131
- body = Gzip.compress(body) if @deflate
132
- req.body = body
133
- end
136
+ http = Net::HTTP.new(@host, @port, @proxy_addr, @proxy_port, @proxy_user, @proxy_pass)
134
137
 
135
- http = Net::HTTP.new(@host, @port,
136
- @proxy_addr, @proxy_port, @proxy_user, @proxy_pass)
138
+ http.open_timeout = @open_timeout
139
+ http.read_timeout = @read_timeout
137
140
 
138
- http.open_timeout = @open_timeout
139
- http.read_timeout = @read_timeout
141
+ if @ssl
142
+ http.use_ssl = true
140
143
 
141
- if @ssl
142
- http.use_ssl = true
144
+ http.ca_file = SSL.ca_cert_file_or_default unless SSL.ca_cert_file?
143
145
 
144
- unless SSL.ca_cert_file?
145
- http.ca_file = SSL.ca_cert_file_or_default
146
- end
146
+ http.verify_mode = OpenSSL::SSL::VERIFY_PEER
147
+ end
147
148
 
148
- http.verify_mode = OpenSSL::SSL::VERIFY_PEER
149
+ do_request(http, req) do |res|
150
+ unless res.code =~ /2\d\d/
151
+ debug "server responded with #{res.code}"
152
+ t { fmt "body=%s", res.body }
149
153
  end
150
154
 
151
- do_request(http, req) do |res|
152
- unless res.code =~ /2\d\d/
153
- debug "server responded with #{res.code}"
154
- t { fmt "body=%s", res.body }
155
- end
155
+ Response.new(res.code.to_i, res, res.body)
156
+ end
157
+ rescue Exception => e
158
+ error "http %s %s failed; error=%s; msg=%s", req.method, req.path, e.class, e.message
159
+ t { e.backtrace.join("\n") }
160
+ ErrorResponse.new(req, e)
161
+ end
156
162
 
157
- Response.new(res.code.to_i, res, res.body)
158
- end
159
- rescue Exception => e
160
- error "http %s %s failed; error=%s; msg=%s", req.method, req.path, e.class, e.message
161
- t { e.backtrace.join("\n") }
162
- ErrorResponse.new(req, e)
163
- end
164
-
165
- class Response
166
- attr_reader :status, :headers, :body, :exception
167
-
168
- def initialize(status, headers, body)
169
- @status = status
170
- @headers = headers
171
-
172
- if (headers[CONTENT_TYPE] || "").include?(APPLICATION_JSON)
173
- begin
174
- @body = JSON.parse(body)
175
- rescue JSON::ParserError
176
- @body = body # not really JSON I guess
177
- end
178
- else
179
- @body = body
180
- end
181
- end
163
+ class Response
164
+ attr_reader :status, :headers, :body, :exception
182
165
 
183
- def success?
184
- status >= 200 && status < 300
185
- end
166
+ def initialize(status, headers, body)
167
+ @status = status
168
+ @headers = headers
186
169
 
187
- def to_s
188
- body.to_s
170
+ if (headers[CONTENT_TYPE] || "").include?(APPLICATION_JSON)
171
+ begin
172
+ @body = JSON.parse(body)
173
+ rescue JSON::ParserError
174
+ @body = body # not really JSON I guess
175
+ end
176
+ else
177
+ @body = body
189
178
  end
179
+ end
190
180
 
191
- def get(key)
192
- return nil unless body.is_a?(Hash)
181
+ def success?
182
+ status >= 200 && status < 300
183
+ end
193
184
 
194
- res = body
195
- key.split(".").each do |part|
196
- return unless (res = res[part])
197
- end
198
- res
199
- end
185
+ def to_s
186
+ body.to_s
187
+ end
200
188
 
201
- def respond_to_missing?(name, include_all = false)
202
- super || body.respond_to?(name, include_all)
203
- end
189
+ def get(key)
190
+ body.dig(*key.split(".")) if body.is_a?(Hash)
191
+ end
204
192
 
205
- def method_missing(name, *args, &blk)
206
- if respond_to_missing?(name)
207
- body.send(name, *args, &blk)
208
- else
209
- super
210
- end
193
+ def respond_to_missing?(name, include_all = false)
194
+ super || body.respond_to?(name, include_all)
195
+ end
196
+
197
+ def method_missing(name, *args, &blk)
198
+ if respond_to_missing?(name)
199
+ body.send(name, *args, &blk)
200
+ else
201
+ super
211
202
  end
212
203
  end
204
+ end
213
205
 
214
- ErrorResponse = Struct.new(:request, :exception) do
206
+ ErrorResponse =
207
+ Struct.new(:request, :exception) do
215
208
  def status
216
209
  nil
217
210
  end
@@ -0,0 +1,26 @@
1
+ module Skylight
2
+ module Util
3
+ module InstrumenterMethod
4
+ def instrumenter_method(name, block: false)
5
+ if block
6
+ module_eval <<-RUBY, __FILE__, __LINE__ + 1
7
+ def #{name}(*args) # def mute(*args)
8
+ unless instrumenter # unless instrumenter
9
+ return yield if block_given? # return yield if block_given?
10
+ return # return
11
+ end # end
12
+ #
13
+ instrumenter.#{name}(*args) { yield } # instrumenter.mute(*args) { yield }
14
+ end # end
15
+ RUBY
16
+ else
17
+ module_eval <<-RUBY, __FILE__, __LINE__ + 1
18
+ def #{name}(*args) # def config(*args)
19
+ instrumenter&.#{name}(*args) # instrumenter&.config(*args)
20
+ end # end
21
+ RUBY
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,136 @@
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.respond_to?(:dev) ? logger_logdev.dev : nil
17
+ @logger.<<(*args) if logger_out != $stdout && logger_out != $stderr
18
+ end
19
+
20
+ def close; end
21
+ end
22
+
23
+ module Logging
24
+ def log_context
25
+ {}
26
+ end
27
+
28
+ def trace?
29
+ !!ENV[-"SKYLIGHT_ENABLE_TRACE_LOGS"]
30
+ end
31
+
32
+ def raise_on_error?
33
+ !!ENV[-"SKYLIGHT_RAISE_ON_ERROR"]
34
+ end
35
+
36
+ # Logs if tracing
37
+ #
38
+ # @param (see #debug)
39
+ #
40
+ # See {trace?}.
41
+ def trace(msg, *args)
42
+ return unless trace?
43
+
44
+ log :debug, msg, *args
45
+ end
46
+
47
+ # Evaluates and logs the result of the block if tracing
48
+ #
49
+ # @yield block to be evaluted
50
+ # @yieldreturn arguments for {#debug}
51
+ #
52
+ # See {trace?}.
53
+ def t
54
+ return unless trace?
55
+
56
+ log :debug, yield
57
+ end
58
+
59
+ # @param msg (see #log)
60
+ # @param args (see #log)
61
+ def debug(msg, *args)
62
+ log :debug, msg, *args
63
+ end
64
+
65
+ # @param msg (see #log)
66
+ # @param args (see #log)
67
+ def info(msg, *args)
68
+ log :info, msg, *args
69
+ end
70
+
71
+ # @param msg (see #log)
72
+ # @param args (see #log)
73
+ def warn(msg, *args)
74
+ log :warn, msg, *args
75
+ end
76
+
77
+ # @param msg (see #log)
78
+ # @param args (see #log)
79
+ def error(msg, *args)
80
+ log :error, msg, *args
81
+ raise format(msg, *args) if raise_on_error?
82
+ end
83
+
84
+ alias log_trace trace
85
+ alias log_debug debug
86
+ alias log_info info
87
+ alias log_warn warn
88
+ alias log_error error
89
+
90
+ # Alias for `Kernel#sprintf`
91
+ # @return [String]
92
+ def fmt(*args)
93
+ sprintf(*args)
94
+ end
95
+
96
+ def config_for_logging
97
+ if respond_to?(:config)
98
+ config
99
+ elsif is_a?(Skylight::Config)
100
+ self
101
+ end
102
+ end
103
+
104
+ # @param level [String,Symbol] the method on `logger` to use for logging
105
+ # @param msg [String] the message to log
106
+ # @param args [Array] values for `Kernel#sprintf` on `msg`
107
+ def log(level, msg, *args)
108
+ c = config_for_logging
109
+ logger = c ? c.logger : nil
110
+
111
+ msg = log_context.map { |(k, v)| "#{k}=#{v}; " }.join << msg
112
+
113
+ if logger
114
+ if logger.respond_to?(level)
115
+ if args.empty?
116
+ logger.send level, msg
117
+ else
118
+ logger.send level, format(msg, *args)
119
+ end
120
+ return # rubocop:disable Style/RedundantReturn
121
+ else
122
+ Kernel.warn "Invalid logger"
123
+ end
124
+ # Fallback to stderr for warn and error levels
125
+ elsif %i[warn error].include?(level)
126
+ $stderr.puts format("[SKYLIGHT] #{msg}", *args)
127
+ end
128
+ rescue Exception => e
129
+ if trace?
130
+ puts "[ERROR] #{e.message}"
131
+ puts e.backtrace
132
+ end
133
+ end
134
+ end
135
+ end
136
+ end
@@ -0,0 +1,36 @@
1
+ # Based on code by Sam Saffron: https://stackoverflow.com/a/16161783/181916
2
+ module Skylight
3
+ module Util
4
+ class LruCache
5
+ def initialize(max_size)
6
+ @max_size = max_size
7
+ @data = {}
8
+ end
9
+
10
+ def max_size=(size)
11
+ raise ArgumentError, :max_size if @max_size < 1
12
+
13
+ @max_size = size
14
+ @data.shift while @data.size > @max_size
15
+ end
16
+
17
+ # Individual hash operations here are atomic in MRI.
18
+ def fetch(key)
19
+ found = true
20
+ value = @data.delete(key) { found = false }
21
+
22
+ value = yield if !found && block_given?
23
+
24
+ @data[key] = value if value
25
+
26
+ @data.shift if !found && value && @data.length > @max_size
27
+
28
+ value
29
+ end
30
+
31
+ def clear
32
+ @data.clear
33
+ end
34
+ end
35
+ end
36
+ end
@@ -12,11 +12,7 @@ module Skylight
12
12
  # Ruby doesn't know that it's on a musl-based platform. `ldd` is the
13
13
  # only reliable way to detect musl that we've found.
14
14
  # See https://github.com/skylightio/skylight-ruby/issues/92
15
- if ENV["SKYLIGHT_MUSL"] || `ldd --version 2>&1` =~ /musl/
16
- "linux-musl"
17
- else
18
- "linux"
19
- end
15
+ ENV["SKYLIGHT_MUSL"] || `ldd --version 2>&1` =~ /musl/ ? "linux-musl" : "linux"
20
16
  when /darwin/
21
17
  "darwin"
22
18
  when /freebsd/
@@ -42,8 +38,8 @@ module Skylight
42
38
  "x86"
43
39
  when /ppc|powerpc/
44
40
  "powerpc"
45
- when /^arm/
46
- "arm"
41
+ when /arm64|aarch64/
42
+ "aarch64"
47
43
  else
48
44
  cpu
49
45
  end
@@ -12,43 +12,19 @@ module Skylight
12
12
  if defined?(OpenSSL::X509::DEFAULT_CERT_FILE)
13
13
  f = OpenSSL::X509::DEFAULT_CERT_FILE
14
14
 
15
- if f && File.exist?(f)
16
- @ca_cert_file = f
17
- end
18
- end
19
- end
20
-
21
- def self.detect_ca_cert_dir!
22
- return nil if ENV["SKYLIGHT_FORCE_OWN_CERTS"]
23
-
24
- @ca_cert_dir = false
25
- if defined?(OpenSSL::X509::DEFAULT_CERT_DIR)
26
- d = OpenSSL::X509::DEFAULT_CERT_DIR
27
-
28
- if d && File.exist?(d)
29
- @ca_cert_dir = d
30
- end
15
+ @ca_cert_file = f if f && File.exist?(f)
31
16
  end
32
17
  end
33
18
 
34
19
  detect_ca_cert_file!
35
- detect_ca_cert_dir!
36
20
 
37
21
  def self.ca_cert_file?
38
22
  !!@ca_cert_file
39
23
  end
40
24
 
41
- def self.ca_cert_dir?
42
- !!@ca_cert_dir
43
- end
44
-
45
25
  def self.ca_cert_file_or_default
46
26
  @ca_cert_file || DEFAULT_CA_FILE
47
27
  end
48
-
49
- class << self
50
- attr_reader :ca_cert_dir
51
- end
52
28
  end
53
29
  end
54
30
  end
@@ -0,0 +1,12 @@
1
+ module Skylight
2
+ # @api private
3
+ module Util
4
+ # Used from the main lib
5
+ require "skylight/util/allocation_free"
6
+ require "skylight/util/clock"
7
+ require "skylight/util/instrumenter_method"
8
+
9
+ # Used from the CLI
10
+ autoload :Gzip, "skylight/util/gzip"
11
+ end
12
+ end
@@ -11,7 +11,7 @@ class Thor
11
11
  # class Default < Thor
12
12
  # include Thor::RakeCompat
13
13
  #
14
- # RSpec::Core::RakeTask.new(:spec) do |t|
14
+ # RSpec::RakeTask.new(:spec) do |t|
15
15
  # t.spec_opts = ['--options', "./.rspec"]
16
16
  # t.spec_files = FileList['spec/**/*_spec.rb']
17
17
  # end
@@ -1,3 +1,7 @@
1
1
  module Skylight
2
- VERSION = "4.2.3".freeze
2
+ # pre-release versions should be given here as "5.0.0-alpha"
3
+ # for compatibility with semver when it is parsed by the rust agent.
4
+ # This string will be transformed in the gemspec to "5.0.0.alpha"
5
+ # to conform with rubygems.
6
+ VERSION = "5.3.0".freeze
3
7
  end
@@ -0,0 +1,60 @@
1
+ module Skylight
2
+ # @api private
3
+ module VM
4
+ if defined?(JRUBY_VERSION)
5
+ # This doesn't quite work as we would like it. I believe that the GC
6
+ # statistics includes time that is not stop-the-world, this does not
7
+ # necessarily take time away from the application.
8
+ #
9
+ # require 'java'
10
+ # class GC
11
+ # def initialize
12
+ # @factory = Java::JavaLangManagement::ManagementFactory
13
+ # end
14
+ #
15
+ # def enable
16
+ # end
17
+ #
18
+ # def total_time
19
+ # res = 0.0
20
+ #
21
+ # @factory.garbage_collector_mx_beans.each do |mx|
22
+ # res += (mx.collection_time.to_f / 1_000.0)
23
+ # end
24
+ #
25
+ # res
26
+ # end
27
+ # end
28
+ elsif defined?(::GC::Profiler)
29
+ class GC
30
+ def initialize
31
+ @total = 0
32
+ end
33
+
34
+ def enable
35
+ ::GC::Profiler.enable
36
+ end
37
+
38
+ def total_time
39
+ # Reported in seconds
40
+ run = (::GC::Profiler.total_time * 1_000_000).to_i
41
+
42
+ ::GC::Profiler.clear if run > 0
43
+
44
+ @total += run
45
+ end
46
+ end
47
+ end
48
+
49
+ # Fallback
50
+ unless defined?(VM::GC)
51
+ class GC
52
+ def enable; end
53
+
54
+ def total_time
55
+ 0
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end