skylight 1.0.1 → 1.1.0

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
  SHA1:
3
- metadata.gz: 9d299c38749f9eb46bf2ed780d3b554760d8728b
4
- data.tar.gz: 74e57f72bc4bc58ab4a8977382d930e032414ca4
3
+ metadata.gz: 1699f6ba8c234cdf6b89fd396784d237522fc664
4
+ data.tar.gz: ed71e8ba5f1fba9a80100c1f3a9aa92f8e730254
5
5
  SHA512:
6
- metadata.gz: b4d63a7ac26843af364e798327841652ee2a9fc21b0724845190f0a7e963886ab534fc16a813ab673dab32f37cc59835c7f459255881594542c6827d7eeac190
7
- data.tar.gz: 70b05635d94f0b60ede936c2b645c978497fcb85fb8acc061290124b595bff1849367b9977bc618513cd26e985700723355dc38b569468a4ad8afd532ded0456
6
+ metadata.gz: ba7ff221b40a563cf0367f4622f173e28277bceabac3f73b640b414b608cd104cc9fb78fcf14d199a254371dc537a185b1145ec7411aa049ffcc18d9381891a0
7
+ data.tar.gz: a7a7d90630a59b8657c93519e67b442478cdb83730bbc3e9f07415239a6373b79d29dc0837883613fc602abff370731acdfd0ae7f14a03e035f7bea570a58531
@@ -1,3 +1,14 @@
1
+ ## 1.1.0 (March 9, 2017)
2
+
3
+ * [FEATURE] Support musl-based OSes (including Alpine Linux)
4
+ * [FEATURE] Add Elasticsearch Probe
5
+ * [FEATURE] Add HTTPClient probe (#76)j
6
+ * [IMPROVEMENT] Update tested Ruby versions, drop 1.9.2
7
+ * [BUGFIX] Fix HTTP_PROXY handling of empty strings (#90)
8
+ * [BUGFIX] Don't crash on empty content_type strings
9
+ * [BUGFIX] Use more robust method to detect home dir (#75)
10
+ * [BUGFIX] Add option to suppress environment warning (#62)
11
+
1
12
  ## 1.0.1 (November 15, 2016)
2
13
 
3
14
  * [BUGFIX] Gracefully handle non-writable log files
@@ -1,6 +1,7 @@
1
1
  ---
2
- version: "1.0.1-fcb0e55"
2
+ version: "1.1.0-de45c74"
3
3
  checksums:
4
- x86-linux: "8a4b585dc72735947bc3bd7ae24c11e92dbe8d57af4afb7345df561fad563804"
5
- x86_64-linux: "7c192d9c98715f32be74c20596738e48af295629a401dffe5aff21da796231ed"
6
- x86_64-darwin: "8bd31a89a7bdb32c0903608c5e73818af9dfb0f8b3f3004ec2fa8f587ee5f819"
4
+ x86-linux: "fbfb6a647701403a11e2e81045dd84b3c55ec7fedf60910bfa372c9bf7ef8b5f"
5
+ x86_64-linux: "6958c20cc35bea207f12e65530460dda64ed6a31556a76de8911ae9c604cff93"
6
+ x86_64-linux-musl: "65171091e9262755431e52e1b1c3c7e4881c71bbf8ded322aa599f137baecf10"
7
+ x86_64-darwin: "238ae95c68a8d4601d2e4e2c2583090750cd70e647c0342f73699ab772b35335"
@@ -69,6 +69,14 @@ you should set the `SKYLIGHT_AUTHENTICATION` variable to:
69
69
  say "Development mode warning disabled", :green
70
70
  end
71
71
 
72
+ desc "disable_env_warning", "Disables warning about running Skylight in environments not defined in config.skylight.environments"
73
+ def disable_env_warning
74
+ user_config.disable_env_warning = true
75
+ user_config.save
76
+
77
+ say "Environment warning disabled", :green
78
+ end
79
+
72
80
  private
73
81
 
74
82
  def app_name
@@ -552,7 +552,7 @@ authentication: #{self[:authentication]}
552
552
  deploy_str = deploy.to_query_string
553
553
  # A pipe should be a safe delimiter since it's not in the standard token
554
554
  # and is encoded by URI
555
- token += "|#{deploy.to_query_string}"
555
+ token += "|#{deploy_str}"
556
556
  end
557
557
 
558
558
  token
@@ -145,6 +145,7 @@ module Skylight
145
145
  active_model_serializers/render
146
146
  active_record/sql
147
147
  active_support/cache
148
+ elasticsearch/request
148
149
  grape/endpoint
149
150
  moped/query).each do |file|
150
151
  require "skylight/normalizers/#{file}"
@@ -0,0 +1,20 @@
1
+ module Skylight
2
+ module Normalizers
3
+ module Elasticsearch
4
+ class Request < Normalizer
5
+ register "request.elasticsearch"
6
+
7
+ CAT = "db.elasticsearch.request".freeze
8
+
9
+ def normalize(trace, name, payload)
10
+ path = payload[:path].split('/')
11
+ title = [payload[:method], path[0]].compact.join(' ')
12
+ desc = {}
13
+ desc[:type] = path[1] if path[1]
14
+ desc[:id] = '?' if path[2]
15
+ [ CAT, title, desc.presence.try(:to_json) ]
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -8,11 +8,15 @@ module Skylight
8
8
  alias append_info_to_payload_without_sk append_info_to_payload
9
9
  def append_info_to_payload(payload)
10
10
  append_info_to_payload_without_sk(payload)
11
- if respond_to?(:rendered_format)
12
- rendered_mime = rendered_format
13
- elsif respond_to?(:lookup_context)
14
- format = lookup_context.formats.first
15
- rendered_mime = Mime[format.to_sym] if format
11
+ rendered_mime = begin
12
+ if respond_to?(:rendered_format)
13
+ rendered_format
14
+ elsif content_type.is_a?(Mime::Type)
15
+ content_type
16
+ elsif content_type.respond_to?(:to_s)
17
+ type_str = content_type.to_s.split(';').first
18
+ Mime::Type.lookup(type_str) unless type_str.blank?
19
+ end
16
20
  end
17
21
  payload[:rendered_format] = rendered_mime.try(:ref)
18
22
  payload[:variant] = request.respond_to?(:variant) ? request.variant : nil
@@ -0,0 +1,34 @@
1
+ module Skylight
2
+ module Probes
3
+ module Elasticsearch
4
+ class Probe
5
+ def install
6
+ ::Elasticsearch::Transport::Transport::Base.class_eval do
7
+ alias perform_request_without_sk perform_request
8
+ def perform_request(method, path, *args, &block)
9
+ ActiveSupport::Notifications.instrument "request.elasticsearch",
10
+ name: 'Request',
11
+ method: method,
12
+ path: path do
13
+
14
+ # Prevent HTTP-related probes from firing
15
+ disable_skylight_probe(:NetHTTP) do
16
+ disable_skylight_probe(:HTTPClient) do
17
+ perform_request_without_sk(method, path, *args, &block)
18
+ end
19
+ end
20
+ end
21
+ end
22
+
23
+ def disable_skylight_probe(class_name, &block)
24
+ klass = Skylight::Probes.const_get(class_name).const_get(:Probe) rescue nil
25
+ klass ? klass.disable(&block) : block.call
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
31
+
32
+ register("Elasticsearch", "elasticsearch", Elasticsearch::Probe.new)
33
+ end
34
+ end
@@ -0,0 +1,46 @@
1
+ require 'skylight/formatters/http'
2
+
3
+ module Skylight
4
+ module Probes
5
+ module HTTPClient
6
+ class Probe
7
+ DISABLED_KEY = :__skylight_httpclient_disabled
8
+
9
+ def self.disable
10
+ Thread.current[DISABLED_KEY] = true
11
+ yield
12
+ ensure
13
+ Thread.current[DISABLED_KEY] = false
14
+ end
15
+
16
+ def self.disabled?
17
+ !!Thread.current[DISABLED_KEY]
18
+ end
19
+
20
+ def install
21
+ ::HTTPClient.class_eval do
22
+ # HTTPClient has request methods on the class object itself,
23
+ # but the internally instantiate a client and perform the method
24
+ # on that, so this instance method override will cover both
25
+ # `HTTPClient.get(...)` and `HTTPClient.new.get(...)`
26
+
27
+ alias do_request_without_sk do_request
28
+ def do_request(method, uri, query, body, header, &block)
29
+ if Skylight::Probes::HTTPClient::Probe.disabled?
30
+ return do_request_without_sk(method, uri, query, body, header, &block)
31
+ end
32
+
33
+ opts = Formatters::HTTP.build_opts(method, uri.scheme, uri.host, uri.port, uri.path, uri.query)
34
+
35
+ Skylight.instrument(opts) do
36
+ do_request_without_sk(method, uri, query, body, header, &block)
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end # class Probe
42
+ end # module Probes::HTTPClient
43
+
44
+ register("HTTPClient", "httpclient", HTTPClient::Probe.new)
45
+ end
46
+ end
@@ -4,12 +4,25 @@ module Skylight
4
4
  module Probes
5
5
  module NetHTTP
6
6
  class Probe
7
+ DISABLED_KEY = :__skylight_net_http_disabled
8
+
9
+ def self.disable
10
+ Thread.current[DISABLED_KEY] = true
11
+ yield
12
+ ensure
13
+ Thread.current[DISABLED_KEY] = false
14
+ end
15
+
16
+ def self.disabled?
17
+ !!Thread.current[DISABLED_KEY]
18
+ end
19
+
7
20
  def install
8
21
  Net::HTTP.class_eval do
9
22
  alias request_without_sk request
10
23
 
11
24
  def request(req, body = nil, &block)
12
- unless started?
25
+ if !started? || Skylight::Probes::NetHTTP::Probe.disabled?
13
26
  return request_without_sk(req, body, &block)
14
27
  end
15
28
 
@@ -42,7 +42,9 @@ module Skylight
42
42
  "(To disable this message for all local apps, run `skylight disable_dev_warning`.)"
43
43
  end
44
44
  elsif !Rails.env.test?
45
- log_warning config, "[SKYLIGHT] [#{Skylight::VERSION}] You are running in the #{Rails.env} environment but haven't added it to config.skylight.environments, so no data will be sent to skylight.io."
45
+ unless UserConfig.instance.disable_env_warning?
46
+ log_warning config, "[SKYLIGHT] [#{Skylight::VERSION}] You are running in the #{Rails.env} environment but haven't added it to config.skylight.environments, so no data will be sent to skylight.io."
47
+ end
46
48
  end
47
49
  end
48
50
 
@@ -3,7 +3,7 @@ require 'yaml'
3
3
  module Skylight
4
4
  class UserConfig
5
5
 
6
- attr_accessor :disable_dev_warning
6
+ attr_accessor :disable_dev_warning, :disable_env_warning
7
7
 
8
8
  def self.instance
9
9
  @instance ||= new
@@ -14,18 +14,35 @@ module Skylight
14
14
  end
15
15
 
16
16
  def file_path
17
- File.expand_path(ENV["SKYLIGHT_USER_CONFIG_PATH"] || "~/.skylight")
17
+ return @file_path if @file_path
18
+
19
+ config_path = ENV.fetch("SKYLIGHT_USER_CONFIG_PATH") do
20
+ require "etc"
21
+ home_dir = ENV['HOME'] || Etc.getpwuid.dir || (ENV["USER"] && File.expand_path("~#{ENV['USER']}"))
22
+ if home_dir
23
+ File.join(home_dir, ".skylight")
24
+ else
25
+ raise KeyError, "SKYLIGHT_USER_CONFIG_PATH must be defined since the home directory cannot be inferred"
26
+ end
27
+ end
28
+
29
+ @file_path = File.expand_path(config_path)
18
30
  end
19
31
 
20
32
  def disable_dev_warning?
21
33
  disable_dev_warning
22
34
  end
23
35
 
36
+ def disable_env_warning?
37
+ disable_env_warning
38
+ end
39
+
24
40
  def reload
25
41
  config = File.exist?(file_path) ? YAML.load_file(file_path) : false
26
42
  return unless config
27
43
 
28
44
  self.disable_dev_warning = !!config['disable_dev_warning']
45
+ self.disable_env_warning = !!config['disable_env_warning']
29
46
  end
30
47
 
31
48
  def save
@@ -37,9 +54,10 @@ module Skylight
37
54
 
38
55
  def to_hash
39
56
  {
40
- 'disable_dev_warning' => disable_dev_warning
57
+ 'disable_dev_warning' => disable_dev_warning,
58
+ 'disable_env_warning' => disable_env_warning
41
59
  }
42
60
  end
43
61
 
44
62
  end
45
- end
63
+ end
@@ -7,7 +7,15 @@ module Skylight
7
7
  # Normalize the platform OS
8
8
  OS = case os = RbConfig::CONFIG['host_os'].downcase
9
9
  when /linux/
10
- "linux"
10
+ # The official ruby-alpine Docker containers pre-build Ruby. As a result,
11
+ # Ruby doesn't know that it's on a musl-based platform. `ldd` is the
12
+ # only reliable way to detect musl that we've found.
13
+ # See https://github.com/skylightio/skylight-ruby/issues/92
14
+ if ENV['SKYLIGHT_MUSL'] || `ldd --version 2>&1` =~ /musl/
15
+ "linux-musl"
16
+ else
17
+ "linux"
18
+ end
11
19
  when /darwin/
12
20
  "darwin"
13
21
  when /freebsd/
@@ -2,7 +2,8 @@ module Skylight
2
2
  module Util
3
3
  module Proxy
4
4
  def self.detect_url(env)
5
- if u = env['HTTP_PROXY'] || env['http_proxy']
5
+ u = env['HTTP_PROXY'] || env['http_proxy']
6
+ if u && !u.empty?
6
7
  u = "http://#{u}" unless u =~ %r[://]
7
8
  u
8
9
  end
@@ -1,4 +1,4 @@
1
1
  module Skylight
2
- VERSION = '1.0.1'
2
+ VERSION = '1.1.0'
3
3
  end
4
4
 
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: 1.0.1
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tilde, Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-11-15 00:00:00.000000000 Z
11
+ date: 2017-03-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -79,6 +79,7 @@ files:
79
79
  - lib/skylight/normalizers/active_support/cache_read_multi.rb
80
80
  - lib/skylight/normalizers/active_support/cache_write.rb
81
81
  - lib/skylight/normalizers/default.rb
82
+ - lib/skylight/normalizers/elasticsearch/request.rb
82
83
  - lib/skylight/normalizers/grape/endpoint.rb
83
84
  - lib/skylight/normalizers/grape/endpoint_render.rb
84
85
  - lib/skylight/normalizers/grape/endpoint_run.rb
@@ -88,9 +89,11 @@ files:
88
89
  - lib/skylight/probes/action_controller.rb
89
90
  - lib/skylight/probes/action_view.rb
90
91
  - lib/skylight/probes/active_model_serializers.rb
92
+ - lib/skylight/probes/elasticsearch.rb
91
93
  - lib/skylight/probes/excon.rb
92
94
  - lib/skylight/probes/excon/middleware.rb
93
95
  - lib/skylight/probes/grape.rb
96
+ - lib/skylight/probes/httpclient.rb
94
97
  - lib/skylight/probes/mongo.rb
95
98
  - lib/skylight/probes/mongoid.rb
96
99
  - lib/skylight/probes/moped.rb
@@ -185,7 +188,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
185
188
  version: '0'
186
189
  requirements: []
187
190
  rubyforge_project:
188
- rubygems_version: 2.5.1
191
+ rubygems_version: 2.6.8
189
192
  signing_key:
190
193
  specification_version: 4
191
194
  summary: Skylight is a smart profiler for Rails apps