skylight 5.2.0.beta2 → 5.3.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 99481f50c8e9caf68288746feb32c93d2a969c0770c573ea6a4f5339deca7a8e
4
- data.tar.gz: f39c3462788ebd87ec29c56c3863efac94bf9be18f023c93540d4af96228ba18
3
+ metadata.gz: 25e5b7ab0cc3d787b7192d6ec29ea90ce7c1088f13660d58601cc00d30a88b27
4
+ data.tar.gz: a171ca96752f9e2f6cf02a6fc18a3a64b7fa4c280d9d2c2428d489c6a3b46d85
5
5
  SHA512:
6
- metadata.gz: 8ea1d4c80b043c085f612cbee130f10079b0a9f24392552a4a14b3fcd327831f8ca61d19fee4570d1a04d7289e18d431ff5f9ed5a8d567eb69afa7fd6f6d9fea
7
- data.tar.gz: cc73adc6a339389ecfeca93f7a91496958f6769c24bea6d29dad2885800c8b5f3273635522450f56c6de3f53f42045219e32e054edc80620a5abe1cde779f682
6
+ metadata.gz: a388dd96bd6253ae8db5b5dae947be514888714bdcd0d4a91d0a3e4d15b33c826da018637ce24e2341eeaab917ab6b84671eae481d872a99dc1bc7c8c2dbc400
7
+ data.tar.gz: 41bcd860d6ae637670cc0b0abde0a4b9e4970cecfc19fab781fa15cdee24d73bcc2fec62dfa984f24568fc27d1b7379ff2791a5f49a4e7107992f620ab7a45cb
data/CHANGELOG.md CHANGED
@@ -1,14 +1,21 @@
1
- ## 5.2.0-beta2 (10 November 2021)
1
+ ## 5.3.1 (February 28, 2022)
2
2
 
3
- - [FEATURE] Experimental gRPC transport
4
- - [IMPROVEMENT] Internal native client refactors
5
- - [BUGFIX] Fix some internal errors related to Rails 7 alpha
3
+ - [BUGFIX] Fix Elasticsearch integration for gem versions >= 8.
4
+
5
+ ## 5.3.0 (February, 9, 2022)
6
6
 
7
- ## 5.2.0-beta (7 September 2021)
7
+ - [FEATURE] Support for Rails 7's `load_async`.
8
+ - [IMPROVEMENT] `skylight doctor` now checks glibc compatibility.
9
+ - [BUGFIX] Fix an issue where `skylight doctor` wouldn't correctly log installation errors.
8
10
 
11
+ ## 5.2.0 (February 3, 2022)
12
+
13
+ - [FEATURE] Experimental gRPC transport
14
+ - [IMPROVEMENT] Internal native client refactors
9
15
  - [IMPROVEMENT] Add Rack::Builder probe to better instrument middlewares in Sinatra and other Builder-based apps
16
+ - [BUGFIX] Fix some internal errors related to Rails 7
10
17
  - [BUGFIX] Fix an issue in which trace logging could output the incorrect request ID.
11
- - [BUGFIX] fix native extension configuration for arm64 hosts
18
+ - [BUGFIX] Fix native extension configuration for arm64 hosts
12
19
 
13
20
  ## 5.1.1 (May 27, 2021)
14
21
 
data/ext/extconf.rb CHANGED
@@ -9,6 +9,22 @@ $LOAD_PATH.unshift File.expand_path("../lib", __dir__)
9
9
  require "skylight/native_ext_fetcher"
10
10
  require "skylight/util/platform"
11
11
 
12
+ GLIBC_MIN = 2.23
13
+ GLIBC_V4_MIN = 2.15
14
+
15
+ ldd_output =
16
+ begin
17
+ `ldd --version`
18
+ rescue Errno::ENOENT
19
+ nil
20
+ end
21
+
22
+ if ldd_output =~ /GLIBC (\d+(\.\d+)+)/ && ($1.to_f < GLIBC_MIN)
23
+ message = "glibc #{GLIBC_MIN}+ is required but you have #{$1} installed."
24
+ message << "\nYou may be able to use Skylight v4 instead." if $1.to_f >= GLIBC_V4_MIN
25
+ fail message
26
+ end
27
+
12
28
  # Util allowing proxying writes to multiple location
13
29
  class MultiIO
14
30
  def initialize(*targets)
data/ext/libskylight.yml CHANGED
@@ -1,9 +1,9 @@
1
- version: "5.1.0-f504521"
1
+ version: "5.1.0-6812c12"
2
2
  checksums:
3
- x86-linux: "46bdaaf5a0b2605e1bf581756317dcac7cd6db66bda1b2994dd8de5f933f752e"
4
- x86_64-linux: "300e3d2e770c2cefdb43bde6d6538bde69c18ec9c6b50210f24959a8efcd8749"
5
- x86_64-linux-musl: "9f790db33f2c4f6c68ecb2d4719c881e3cf3634ac3718db4c108994d6c55f6a8"
6
- x86_64-darwin: "90c4ff6650350f084495cc031bb70ae1ef7a4934712a0c97dcdbfc6ce418342c"
7
- aarch64-linux: "f5437881ecb6ac59af1e8c89e19e68baf52730088efd030855b2e40bc714a2ba"
8
- aarch64-linux-musl: "d52bac0d1a0d965940ded2168acb72d2c23b060eb1bac9983763cc8b7cada8ba"
9
- aarch64-darwin: "b92c85242b94e7eb71680de41a504a22e9dba145408bdd810757e693e065456d"
3
+ x86-linux: "d3acbbcd14209e8564226e005db2163b7d1ae49133eb250a7901ff2687abe330"
4
+ x86_64-linux: "dfb1062572780285795eef2e99d32ff3ad6be1c944c1a6add442488f7a4a9b22"
5
+ x86_64-linux-musl: "af09469f20c666a15ccbb910d8906c6a69a99f87f69db6cbba41908baf3fcef2"
6
+ x86_64-darwin: "eb4cb7b9301e0b1f88623203a4476bdabf299ec62556dc40bedda78c5eeb1437"
7
+ aarch64-linux: "3d5e8743c4dfdde5be3b6162c75b0351ff0be5658819c1fec9f3a936c4c81a32"
8
+ aarch64-linux-musl: "30705f76e333f4883a9481a34bc2dfeb7e9fd6f98c0cf8afbe63f232f3ceb1e5"
9
+ aarch64-darwin: "9f8ffc752b0e17bde587e5a5510b17554096b2b65fa2e19203ff1ee3a3145b1d"
@@ -520,6 +520,7 @@ void Init_skylight_native() {
520
520
 
521
521
  rb_cTrace = rb_const_get(rb_mSkylight, rb_intern("Trace"));
522
522
  rb_define_singleton_method(rb_cTrace, "native_new", trace_new, 4);
523
+ rb_undef_alloc_func(rb_cTrace);
523
524
  rb_define_method(rb_cTrace, "native_get_started_at", trace_get_started_at, 0);
524
525
  rb_define_method(rb_cTrace, "native_get_endpoint", trace_get_endpoint, 0);
525
526
  rb_define_method(rb_cTrace, "native_set_endpoint", trace_set_endpoint, 1);
@@ -540,6 +541,7 @@ void Init_skylight_native() {
540
541
 
541
542
  rb_cInstrumenter = rb_const_get(rb_mSkylight, rb_intern("Instrumenter"));
542
543
  rb_define_singleton_method(rb_cInstrumenter, "native_new", instrumenter_new, 2);
544
+ rb_undef_alloc_func(rb_cInstrumenter);
543
545
  rb_define_method(rb_cInstrumenter, "native_start", instrumenter_start, 0);
544
546
  rb_define_method(rb_cInstrumenter, "native_stop", instrumenter_stop, 0);
545
547
  rb_define_method(rb_cInstrumenter, "native_submit_trace", instrumenter_submit_trace, 1);
@@ -65,7 +65,7 @@ module Skylight
65
65
  say "Unable to load native extension", :yellow
66
66
 
67
67
  indent do
68
- install_log = File.expand_path("../../ext/install.log", __dir__)
68
+ install_log = File.expand_path("../../../ext/install.log", __dir__)
69
69
  if File.exist?(install_log)
70
70
  File.readlines(install_log).each { |line| say line, :red }
71
71
  else
@@ -659,7 +659,7 @@ module Skylight
659
659
  corrected_config = res.corrected_config
660
660
 
661
661
  # Use defaults if no corrected config is available. This will happen if the request failed.
662
- corrected_config ||= SERVER_VALIDATE.map { |k| [k, self.class.default_values.fetch(k)] }.to_h
662
+ corrected_config ||= SERVER_VALIDATE.to_h { |k| [k, self.class.default_values.fetch(k)] }
663
663
 
664
664
  config_to_update = corrected_config.reject { |k, v| get(k) == v }
665
665
  unless config_to_update.empty?
@@ -36,7 +36,7 @@ module Skylight
36
36
  end
37
37
  end
38
38
 
39
- attr_reader :uuid, :config, :gc, :extensions
39
+ attr_reader :uuid, :config, :gc, :extensions, :subscriber
40
40
 
41
41
  def self.native_new(_uuid, _config_env)
42
42
  raise "not implemented"
@@ -7,6 +7,14 @@ module Skylight
7
7
  class SQL < Skylight::Normalizers::SQL
8
8
  register "sql.active_record"
9
9
  end
10
+
11
+ class FutureResult < Normalizer
12
+ register "future_result.active_record"
13
+
14
+ def normalize(_trace, _name, payload)
15
+ ["db.future_result", "Async #{payload[:args][1] || "Query"}"]
16
+ end
17
+ end
10
18
  end
11
19
  end
12
20
  end
@@ -14,14 +14,10 @@ module Skylight
14
14
  # @option payload [String] [:name] The SQL operation
15
15
  # @option payload [Hash] [:binds] The bound parameters
16
16
  # @return [Array]
17
- def normalize(_trace, name, payload)
18
- case payload[:name]
19
- when "SCHEMA", "CACHE"
20
- return :skip
21
- else
22
- name = CAT
23
- title = payload[:name] || "SQL"
24
- end
17
+ def normalize(_trace, _name, payload)
18
+ return :skip if payload[:name] == "SCHEMA" || payload[:name] == "CACHE"
19
+
20
+ title = payload[:name] || "SQL"
25
21
 
26
22
  # We can only handle UTF-8 encoded strings.
27
23
  # (Construction method here avoids extra allocations)
@@ -38,7 +34,7 @@ module Skylight
38
34
  sql = nil
39
35
  end
40
36
 
41
- [name, title, sql]
37
+ [CAT, title, sql]
42
38
  end
43
39
  end
44
40
  end
@@ -0,0 +1,96 @@
1
+ module Skylight
2
+ module Probes
3
+ module ActiveRecord
4
+ module FutureResult
5
+ # Applied to ActiveSupport::Notifications::Event
6
+ module AsyncEventExtensions
7
+ # Notify Skylight that the event has started
8
+ def __sk_start!
9
+ subscriber = Skylight.instrumenter.subscriber
10
+ subscriber.start(name, nil, payload)
11
+ trace = Skylight.instrumenter.current_trace
12
+
13
+ # Set a finisher to end the event
14
+ @__sk_finisher = ->(name, payload) do
15
+ subscriber.with_trace(trace) { subscriber.finish(name, nil, payload) }
16
+ end
17
+
18
+ # End it immediately if we've actually already ended
19
+ __sk_finish! if @end
20
+ rescue StandardError => e
21
+ Skylight.error("Unable to start event for FutureResult: #{e}")
22
+ end
23
+
24
+ # Notify Skylight that the event has finished
25
+ def __sk_finish!
26
+ return unless @__sk_finisher
27
+
28
+ @__sk_finisher.call(name, payload)
29
+ @__sk_finisher = nil
30
+ rescue StandardError => e
31
+ Skylight.error("Unable to finish event for FutureResult: #{e}")
32
+ end
33
+
34
+ # When the event is marked as finish make sure we notify Skylight
35
+ def finish!
36
+ super
37
+ __sk_finish!
38
+ end
39
+ end
40
+
41
+ # Applied to FutureResult
42
+ module Instrumentation
43
+ def result(*, **)
44
+ # This instruments the whole FutureResult so that we know when we were executing (potenially) async.
45
+ ActiveSupport::Notifications.instrument("future_result.active_record", { args: @args, kwargs: @kwargs }) do
46
+ super
47
+ end
48
+ end
49
+
50
+ private
51
+
52
+ def execute_or_wait(*, **)
53
+ # At this point we're actually waiting for the query to have finished executing.
54
+
55
+ begin
56
+ # If the query has already started async, the @event_buffer will be defined.
57
+ # We grab the events (currently only the SQL queries), extend them with our
58
+ # special methods and notify Skylight.
59
+ # We act as if the event has just stared, though the query may already have been
60
+ # running. This means we're essentially just logging blocking time right now.
61
+
62
+ # Dup here just in case more get added somehow during the super call
63
+ events = @event_buffer&.instance_variable_get(:@events).dup
64
+
65
+ events&.each do |event|
66
+ event.singleton_class.prepend(AsyncEventExtensions)
67
+ event.__sk_start!
68
+ end
69
+ rescue StandardError => e
70
+ Skylight.error("Unable to start events for FutureResult: #{e}")
71
+ end
72
+
73
+ super
74
+ ensure
75
+ # Once we've actually got a result, we mark each one as finished.
76
+ # Note that it may have already finished, but if it didn't we need to say so now.
77
+ events&.reverse_each(&:__sk_finish!)
78
+ end
79
+ end
80
+
81
+ class Probe
82
+ def install
83
+ ::ActiveRecord::FutureResult.prepend(Instrumentation)
84
+ end
85
+ end
86
+ end
87
+ end
88
+
89
+ register(
90
+ :active_record_async,
91
+ "ActiveRecord::FutureResult",
92
+ "active_record/future_result",
93
+ ActiveRecord::FutureResult::Probe.new
94
+ )
95
+ end
96
+ end
@@ -3,8 +3,17 @@ module Skylight
3
3
  module Elasticsearch
4
4
  class Probe
5
5
  def install
6
+ const =
7
+ if defined?(::Elasticsearch::Transport::Transport::Base)
8
+ ::Elasticsearch::Transport::Transport::Base
9
+ elsif defined?(::Elastic::Transport::Transport::Base)
10
+ ::Elastic::Transport::Transport::Base
11
+ else
12
+ return false
13
+ end
14
+
6
15
  # Prepending doesn't work here since this a module that's already been included
7
- ::Elasticsearch::Transport::Transport::Base.class_eval do
16
+ const.class_eval do
8
17
  alias_method :perform_request_without_sk, :perform_request
9
18
  def perform_request(method, path, *args, &block)
10
19
  ActiveSupport::Notifications.instrument(
@@ -16,7 +16,15 @@ module Skylight
16
16
  # net_http, action_controller, action_dispatch, action_view, and middleware are on by default
17
17
  # See https://www.skylight.io/support/getting-more-from-skylight#available-instrumentation-options
18
18
  # for a full list.
19
- config.skylight.probes = %w[net_http action_controller action_dispatch action_view middleware active_job_enqueue]
19
+ config.skylight.probes = %w[
20
+ net_http
21
+ action_controller
22
+ action_dispatch
23
+ action_view
24
+ middleware
25
+ active_job_enqueue
26
+ active_record_async
27
+ ]
20
28
 
21
29
  # The position in the middleware stack to place Skylight
22
30
  # Default is first, but can be `{ after: Middleware::Name }` or `{ before: Middleware::Name }`
@@ -36,16 +36,30 @@ module Skylight
36
36
  end
37
37
  end
38
38
 
39
+ # cargo-culted from Rails's ConnectionAdapter
40
+ EXCEPTION_NEVER = { Exception => :never }.freeze # :nodoc:
41
+ EXCEPTION_IMMEDIATE = { Exception => :immediate }.freeze # :nodoc:
42
+ private_constant :EXCEPTION_NEVER, :EXCEPTION_IMMEDIATE
43
+ def with_trace(trace, &block) # :nodoc:
44
+ Thread.handle_interrupt(EXCEPTION_NEVER) do
45
+ previous_trace = @trace
46
+ @trace = trace
47
+ Thread.handle_interrupt(EXCEPTION_IMMEDIATE, &block)
48
+ ensure
49
+ @trace = previous_trace
50
+ end
51
+ end
52
+
39
53
  def start(name, _id, payload)
40
54
  return if @instrumenter.disabled?
41
- return unless (trace = @instrumenter.current_trace)
55
+ return unless (trace = current_trace)
42
56
 
43
57
  _start(trace, name, payload)
44
58
  end
45
59
 
46
60
  def finish(name, _id, payload)
47
61
  return if @instrumenter.disabled?
48
- return unless (trace = @instrumenter.current_trace)
62
+ return unless (trace = current_trace)
49
63
 
50
64
  while (curr = trace.notifications.pop)
51
65
  next unless curr.name == name
@@ -70,8 +84,16 @@ module Skylight
70
84
  # Ignored for now because nothing in rails uses it
71
85
  end
72
86
 
87
+ def publish_event(event)
88
+ # Ignored for now because only ActiveRecord::FutureResult uses it and we handle that with probes
89
+ end
90
+
73
91
  private
74
92
 
93
+ def current_trace
94
+ @trace || @instrumenter.current_trace
95
+ end
96
+
75
97
  def normalize(*args)
76
98
  @normalizers.normalize(*args)
77
99
  end
data/lib/skylight/test.rb CHANGED
@@ -25,10 +25,6 @@ module Skylight
25
25
  "Mocked Instrumenter"
26
26
  end
27
27
 
28
- def self.native_new(*)
29
- allocate
30
- end
31
-
32
28
  def native_start
33
29
  true
34
30
  end
@@ -47,7 +43,7 @@ module Skylight
47
43
  :Trace,
48
44
  Class.new(OriginalTrace) do
49
45
  def self.native_new(start, _uuid, endpoint, meta)
50
- inst = allocate
46
+ inst = super
51
47
  inst.instance_variable_set(:@start, start)
52
48
  inst.instance_variable_set(:@endpoint, endpoint)
53
49
  inst.instance_variable_set(:@starting_endpoint, endpoint)
@@ -3,5 +3,5 @@ module Skylight
3
3
  # for compatibility with semver when it is parsed by the rust agent.
4
4
  # This string will be transformed in the gemspec to "5.0.0.alpha"
5
5
  # to conform with rubygems.
6
- VERSION = "5.2.0-beta2".freeze
6
+ VERSION = "5.3.1".freeze
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: skylight
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.2.0.beta2
4
+ version: 5.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tilde, Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-11-11 00:00:00.000000000 Z
11
+ date: 2022-03-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -142,14 +142,14 @@ dependencies:
142
142
  requirements:
143
143
  - - "~>"
144
144
  - !ruby/object:Gem::Version
145
- version: 1.21.0
145
+ version: 1.25.0
146
146
  type: :development
147
147
  prerelease: false
148
148
  version_requirements: !ruby/object:Gem::Requirement
149
149
  requirements:
150
150
  - - "~>"
151
151
  - !ruby/object:Gem::Version
152
- version: 1.21.0
152
+ version: 1.25.0
153
153
  - !ruby/object:Gem::Dependency
154
154
  name: simplecov
155
155
  requirement: !ruby/object:Gem::Requirement
@@ -285,6 +285,7 @@ files:
285
285
  - lib/skylight/probes/active_job.rb
286
286
  - lib/skylight/probes/active_job_enqueue.rb
287
287
  - lib/skylight/probes/active_model_serializers.rb
288
+ - lib/skylight/probes/active_record_async.rb
288
289
  - lib/skylight/probes/delayed_job.rb
289
290
  - lib/skylight/probes/elasticsearch.rb
290
291
  - lib/skylight/probes/excon.rb
@@ -367,7 +368,8 @@ files:
367
368
  homepage: https://www.skylight.io
368
369
  licenses:
369
370
  - Nonstandard
370
- metadata: {}
371
+ metadata:
372
+ rubygems_mfa_required: 'true'
371
373
  post_install_message:
372
374
  rdoc_options: []
373
375
  require_paths:
@@ -379,11 +381,11 @@ required_ruby_version: !ruby/object:Gem::Requirement
379
381
  version: '2.6'
380
382
  required_rubygems_version: !ruby/object:Gem::Requirement
381
383
  requirements:
382
- - - ">"
384
+ - - ">="
383
385
  - !ruby/object:Gem::Version
384
- version: 1.3.1
386
+ version: '0'
385
387
  requirements: []
386
- rubygems_version: 3.0.8
388
+ rubygems_version: 3.3.3
387
389
  signing_key:
388
390
  specification_version: 4
389
391
  summary: Skylight is a smart profiler for Rails, Sinatra, and other Ruby apps.