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,76 +0,0 @@
1
- module Skylight
2
- module Probes
3
- module Sinatra
4
- class Probe
5
- def install
6
- class << ::Sinatra::Base
7
- alias build_without_sk build
8
- alias compile_without_sk! compile!
9
-
10
- def compile!(verb, path, *args, &block)
11
- compile_without_sk!(verb, path, *args, &block).tap do |_, _, keys_or_wrapper, wrapper|
12
- wrapper ||= keys_or_wrapper
13
-
14
- # Deal with the situation where the path is a regex, and the default behavior
15
- # of Ruby stringification produces an unreadable mess
16
- if path.is_a?(Regexp)
17
- human_readable = "<sk-regex>%r{#{path.source}}</sk-regex>"
18
- wrapper.instance_variable_set(:@route_name, "#{verb} #{human_readable}")
19
- else
20
- wrapper.instance_variable_set(:@route_name, "#{verb} #{path}")
21
- end
22
-
23
- # Newer versions of Sinatra populate env['sinatra.route']. Polyfill older
24
- # versions in a targeted but hackish way.
25
- if ::Sinatra::VERSION < '1.4.0'
26
- def wrapper.[](app, args)
27
- app.env['sinatra.route'] = @route_name
28
- super
29
- end
30
- end
31
- end
32
- end
33
-
34
- def build(*args, &block)
35
- self.use Skylight::Middleware
36
- build_without_sk(*args, &block)
37
- end
38
- end
39
-
40
- ::Sinatra::Base.class_eval do
41
- alias dispatch_without_sk! dispatch!
42
- alias compile_template_without_sk compile_template
43
-
44
- def dispatch!(*args, &block)
45
- dispatch_without_sk!(*args, &block).tap do
46
- instrumenter = Skylight::Instrumenter.instance
47
- next unless instrumenter
48
- trace = instrumenter.current_trace
49
- next unless trace
50
-
51
- # Set the endpoint name to the route name
52
- route = env['sinatra.route']
53
- trace.endpoint = route if route
54
- end
55
- end
56
-
57
- def compile_template(engine, data, options, *args, &block)
58
- # Pass along a useful "virtual path" to Tilt. The Tilt probe will handle
59
- # instrumenting correctly.
60
- case data
61
- when Symbol
62
- options[:sky_virtual_path] = data.to_s
63
- else
64
- options[:sky_virtual_path] = "Inline template (#{engine})"
65
- end
66
-
67
- compile_template_without_sk(engine, data, options, *args, &block)
68
- end
69
- end
70
- end
71
- end
72
- end
73
-
74
- register(:sinatra, "Sinatra::Base", "sinatra/base", Sinatra::Probe.new)
75
- end
76
- end
@@ -1,31 +0,0 @@
1
- # Supports 0.2+, though Sinatra doesn't support 2.0, and Rails doesn't work with older versions
2
- module Skylight
3
- module Probes
4
- module Tilt
5
- class Probe
6
- def install
7
- if Gem::Version.new(::Tilt::VERSION) < Gem::Version.new('1.4.1')
8
- Skylight::DEPRECATOR.deprecation_warning("Support for Tilt versions before 1.4.1")
9
- end
10
-
11
- ::Tilt::Template.class_eval do
12
- alias render_without_sk render
13
-
14
- def render(*args, &block)
15
- opts = {
16
- category: "view.render.template",
17
- title: options[:sky_virtual_path] || "Unknown template name"
18
- }
19
-
20
- Skylight.instrument(opts) do
21
- render_without_sk(*args, &block)
22
- end
23
- end
24
- end
25
- end
26
- end
27
- end
28
-
29
- register(:tilt, "Tilt::Template", "tilt/template", Tilt::Probe.new)
30
- end
31
- end
@@ -1,122 +0,0 @@
1
- module Skylight
2
- # @api private
3
- class Subscriber
4
- include Util::Logging
5
-
6
- attr_reader :config
7
-
8
- def initialize(config, instrumenter)
9
- @config = config
10
- @subscriber = nil
11
- @normalizers = Normalizers.build(config)
12
- @instrumenter = instrumenter
13
- end
14
-
15
- def register!
16
- unregister! if @subscriber
17
- pattern = ArrayPattern.new(@normalizers.keys)
18
- @subscriber = ActiveSupport::Notifications.subscribe pattern, self
19
- end
20
-
21
- def unregister!
22
- ActiveSupport::Notifications.unsubscribe @subscriber
23
- @subscriber = nil
24
- end
25
-
26
- class ArrayPattern
27
-
28
- def initialize(keys)
29
- @keys = Set.new keys
30
- end
31
-
32
- def ===(item)
33
- @keys.include?(item)
34
- end
35
-
36
- end
37
-
38
- #
39
- #
40
- # ===== ActiveSupport::Notifications API
41
- #
42
- #
43
-
44
- class Notification
45
- attr_reader :name, :span
46
-
47
- def initialize(name, span)
48
- @name, @span = name, span
49
- end
50
- end
51
-
52
- def start(name, id, payload)
53
- return if @instrumenter.disabled?
54
- return unless trace = @instrumenter.current_trace
55
-
56
- result = normalize(trace, name, payload)
57
-
58
- unless result == :skip
59
- case result.size
60
- when 4
61
- error "old style normalizer; name=#{name.inspect}; normalizer=#{@normalizers.normalizer_for(name).class}"
62
- cat, title, desc, _ = result
63
- when 3
64
- cat, title, desc = result
65
- else
66
- raise "Invalid normalizer result: #{result.inspect}"
67
- end
68
-
69
- span = trace.instrument(cat, title, desc)
70
- end
71
-
72
- trace.notifications << Notification.new(name, span)
73
- rescue Exception => e
74
- error "Subscriber#start error; msg=%s", e.message
75
- debug "trace=%s", trace.inspect
76
- debug "in: name=%s", name.inspect
77
- debug "in: payload=%s", payload.inspect
78
- debug "out: cat=%s, title=%s, desc=%s", cat.inspect, name.inspect, desc.inspect
79
- t { e.backtrace.join("\n") }
80
- nil
81
- end
82
-
83
- def finish(name, id, payload)
84
- return if @instrumenter.disabled?
85
- return unless trace = @instrumenter.current_trace
86
-
87
- while curr = trace.notifications.pop
88
- if curr.name == name
89
- begin
90
- normalize_after(trace, curr.span, name, payload)
91
- ensure
92
- trace.done(curr.span) if curr.span
93
- end
94
- return
95
- end
96
- end
97
-
98
- rescue Exception => e
99
- error "Subscriber#finish error; msg=%s", e.message
100
- debug "trace=%s", trace.inspect
101
- debug "in: name=%s", name.inspect
102
- debug "in: payload=%s", payload.inspect
103
- t { e.backtrace.join("\n") }
104
- nil
105
- end
106
-
107
- def publish(name, *args)
108
- # Ignored for now because nothing in rails uses it
109
- end
110
-
111
- private
112
-
113
- def normalize(*args)
114
- @normalizers.normalize(*args)
115
- end
116
-
117
- def normalize_after(*args)
118
- @normalizers.normalize_after(*args)
119
- end
120
-
121
- end
122
- end
@@ -1,60 +0,0 @@
1
- require 'yaml'
2
-
3
- module Skylight
4
- class UserConfig
5
-
6
- attr_accessor :disable_dev_warning, :disable_env_warning
7
-
8
- def initialize(config)
9
- @config = config
10
- reload
11
- end
12
-
13
- def file_path
14
- return @file_path if @file_path
15
-
16
- config_path = @config[:user_config_path] || begin
17
- require "etc"
18
- home_dir = ENV['HOME'] || Etc.getpwuid.dir || (ENV["USER"] && File.expand_path("~#{ENV['USER']}"))
19
- if home_dir
20
- File.join(home_dir, ".skylight")
21
- else
22
- raise ConfigError, "The Skylight `user_config_path` must be defined since the home directory cannot be inferred"
23
- end
24
- end
25
-
26
- @file_path = File.expand_path(config_path)
27
- end
28
-
29
- def disable_dev_warning?
30
- disable_dev_warning
31
- end
32
-
33
- def disable_env_warning?
34
- disable_env_warning
35
- end
36
-
37
- def reload
38
- config = File.exist?(file_path) ? YAML.load_file(file_path) : false
39
- return unless config
40
-
41
- self.disable_dev_warning = !!config['disable_dev_warning']
42
- self.disable_env_warning = !!config['disable_env_warning']
43
- end
44
-
45
- def save
46
- FileUtils.mkdir_p(File.dirname(file_path))
47
- File.open(file_path, 'w') do |f|
48
- f.puts YAML.dump(to_hash)
49
- end
50
- end
51
-
52
- def to_hash
53
- {
54
- 'disable_dev_warning' => disable_dev_warning,
55
- 'disable_env_warning' => disable_env_warning
56
- }
57
- end
58
-
59
- end
60
- end
@@ -1,17 +0,0 @@
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/deploy'
8
- require 'skylight/util/hostname'
9
- require 'skylight/util/logging'
10
- require 'skylight/util/ssl'
11
- require 'skylight/util/http'
12
-
13
- # Used from the CLI
14
- autoload :Gzip, 'skylight/util/gzip'
15
- autoload :Inflector, 'skylight/util/inflector'
16
- end
17
- end
@@ -1,26 +0,0 @@
1
- module Skylight
2
- module Util
3
- # Helpers to reduce memory allocation
4
- module AllocationFree
5
-
6
- # Find an item in an array without allocation.
7
- #
8
- # @param array [Array] the array to search
9
- # @yield a block called against each item until a match is found
10
- # @yieldparam item an item from the array
11
- # @yieldreturn [Boolean] whether `item` matches the criteria
12
- # return the found item or nil, if nothing found
13
- def array_find(array)
14
- i = 0
15
-
16
- while i < array.size
17
- item = array[i]
18
- return item if yield item
19
- i += 1
20
- end
21
-
22
- nil
23
- end
24
- end
25
- end
26
- end
@@ -1,54 +0,0 @@
1
- module Skylight
2
- module Util
3
- # A more precise clock
4
- class Clock
5
-
6
- if Skylight.native?
7
- def tick
8
- native_hrtime
9
- end
10
- else
11
- def tick
12
- now = Time.now
13
- now.to_i * 1_000_000_000 + now.usec * 1_000
14
- end
15
- end
16
-
17
- # TODO: rename to secs
18
- def absolute_secs
19
- Time.now.to_i
20
- end
21
-
22
- # TODO: remove
23
- def nanos
24
- tick
25
- end
26
-
27
- # TODO: remove
28
- def secs
29
- nanos / 1_000_000_000
30
- end
31
-
32
- def self.absolute_secs
33
- default.absolute_secs
34
- end
35
-
36
- def self.nanos
37
- default.nanos
38
- end
39
-
40
- def self.secs
41
- default.secs
42
- end
43
-
44
- def self.default
45
- @clock ||= Clock.new
46
- end
47
-
48
- def self.default=(clock)
49
- @clock = clock
50
- end
51
-
52
- end
53
- end
54
- end
@@ -1,132 +0,0 @@
1
- require 'json'
2
- require 'uri'
3
- require 'skylight/util/logging'
4
-
5
- module Skylight
6
- module Util
7
-
8
- module Deploy
9
-
10
- def self.build(config)
11
- DEPLOY_TYPES.each do |type|
12
- deploy = type.new(config)
13
- return deploy if deploy.id
14
- end
15
- nil
16
- end
17
-
18
- class EmptyDeploy
19
-
20
- attr_reader :config
21
- attr_reader :timestamp
22
-
23
- def initialize(config)
24
- @config = config
25
- @timestamp = Time.now.to_i
26
- end
27
-
28
- def id
29
- git_sha
30
- end
31
-
32
- def git_sha
33
- nil
34
- end
35
-
36
- def description
37
- nil
38
- end
39
-
40
- def to_query_string
41
- URI.encode_www_form(
42
- timestamp: timestamp,
43
- deploy_id: id.to_s[0..100], # Keep this sane
44
- git_sha: git_sha ? git_sha[0..40] : nil, # A valid SHA will never exceed 40
45
- description: description ? description[0..255] : nil) # Avoid massive descriptions
46
- end
47
-
48
- end
49
-
50
- class DefaultDeploy < EmptyDeploy
51
- include Logging
52
-
53
- def initialize(*)
54
- super
55
- if description && !id
56
- warn "The configured deploy will be ignored as an id or git_sha must be provided."
57
- end
58
- end
59
-
60
- def id
61
- config.get(:'deploy.id') || git_sha
62
- end
63
-
64
- def git_sha
65
- config.get(:'deploy.git_sha')
66
- end
67
-
68
- def description
69
- config.get(:'deploy.description')
70
- end
71
-
72
- end
73
-
74
- class HerokuDeploy < EmptyDeploy
75
-
76
- def initialize(*)
77
- super
78
- @info = get_info
79
- end
80
-
81
- def id
82
- @info ? @info['id'] : nil
83
- end
84
-
85
- def git_sha
86
- @info ? @info['commit'] : nil
87
- end
88
-
89
- def description
90
- @info ? @info['description'] : nil
91
- end
92
-
93
- private
94
-
95
- def get_info
96
- info_path = config[:'heroku.dyno_info_path']
97
-
98
- if File.exist?(info_path)
99
- if info = JSON.parse(File.read(info_path))
100
- info['release']
101
- end
102
- end
103
- end
104
-
105
- end
106
-
107
- class GitDeploy < EmptyDeploy
108
-
109
- attr_reader :git_sha, :description
110
-
111
- def initialize(*)
112
- super
113
- @git_sha, @description = get_info
114
- end
115
-
116
- private
117
-
118
- def get_info
119
- Dir.chdir(config.root) do
120
- info = `git log -1 --pretty="%H %s" 2>&1`
121
- info.split(" ", 2).map(&:strip) if $?.success?
122
- end
123
- end
124
-
125
- end
126
-
127
- DEPLOY_TYPES = [DefaultDeploy, HerokuDeploy, GitDeploy]
128
-
129
- end
130
-
131
- end
132
- end