skylight 0.3.11 → 0.3.12

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ba7ee3852dc0f4d87a9d974aeade1100cde21613
4
- data.tar.gz: 4101c8d467fbbd2c5fccb0124a02b2cf0634232d
3
+ metadata.gz: 50dca195fb184ee57a9d9b29ba2a9473daa64bc5
4
+ data.tar.gz: dea9d586b2cadeb1be320d5975e26c04bed90f9e
5
5
  SHA512:
6
- metadata.gz: df39f86e95a05dc50973fc6a0ceda455eec6ffb9ca77bc19a3a8726e9099349303905eb282e845886aa220ff88da413d516754215234cb5194b274b60a4f5bb9
7
- data.tar.gz: c54def8443d4ebc20d576ad38891acf1b58252fd62d34534e3c905385474bd1b759794f4fc55097c60be47e5b8397fb319808618d7ad091014a7aeea0a10a1bf
6
+ metadata.gz: be4c0252b7a8219326bba924ef9b51ae1c799ed438f56d5f21953904f64d1a88cc304f318a0326995781367c037f9bea605c428f1c2b9643e0e473b9e3c9b6a0
7
+ data.tar.gz: 6e22e9b8839fd0c717676b342aa405ca678378ae365576a7a84d8eb8a3df7bce89e3caac577dfc05884bf6e3b09ac33c6c97fd944051f70a11c1cf7cca365bf3
@@ -1,3 +1,13 @@
1
+ ## 0.3.12 (April 17, 2014)
2
+
3
+ * Include more information in type check errors
4
+ * Use stdlib SecureRandom instead of ActiveSupport::SecureRandom - Fixes Rails 3.1
5
+ * Instrumenter#start! should fail if worker not spawned
6
+ * Configurable timeouts for Util::HTTP
7
+ * Improve proxy handling for Util::HTTP
8
+ * Improve HTTP error handling
9
+ * Refactor sql_parse errors
10
+
1
11
  ## 0.3.11 (April 11, 2014)
2
12
 
3
13
  * Improved error handling and internal metrics
data/README.md CHANGED
@@ -2,5 +2,3 @@
2
2
 
3
3
  Instrument your ruby application and send the data to the Skylight
4
4
  servers.
5
-
6
- {render:Skylight}
@@ -9,27 +9,28 @@
9
9
  * Ruby helpers
10
10
  */
11
11
 
12
+ #define TO_S(VAL) \
13
+ RSTRING_PTR(rb_funcall(VAL, rb_intern("to_s"), 0))
14
+
12
15
  #define CHECK_TYPE(VAL, T) \
13
16
  do { \
14
17
  if (TYPE(VAL) != T) { \
15
- rb_raise(rb_eArgError, #VAL " is not " #T); \
18
+ rb_raise(rb_eArgError, "expected " #VAL " to be " #T " but was '%s' (%s [%i])", \
19
+ TO_S(VAL), rb_obj_classname(VAL), TYPE(VAL)); \
16
20
  return Qnil; \
17
21
  } \
18
22
  } while(0) \
19
23
 
20
- #define CHECK(EXPR, string) \
24
+ #define CHECK_NUMERIC(VAL) \
21
25
  do { \
22
- if (!({ EXPR; })) { \
23
- rb_raise(rb_eArgError, string); \
26
+ if (TYPE(VAL) != T_BIGNUM && \
27
+ TYPE(VAL) != T_FIXNUM) { \
28
+ rb_raise(rb_eArgError, "expected " #VAL " to be numeric but was '%s' (%s [%i])", \
29
+ TO_S(VAL), rb_obj_classname(VAL), TYPE(VAL)); \
24
30
  return Qnil; \
25
31
  } \
26
32
  } while(0) \
27
33
 
28
- #define CHECK_NUMERIC(VAL) \
29
- CHECK(TYPE(VAL) == T_BIGNUM || \
30
- TYPE(VAL) == T_FIXNUM, \
31
- #VAL " is not numeric") \
32
-
33
34
  #define My_Struct(name, Type, msg) \
34
35
  Get_Struct(name, self, Type, msg); \
35
36
 
@@ -31,7 +31,7 @@ module Skylight
31
31
  say "Congratulations. Your application is on Skylight! http://www.skylight.io", :green
32
32
  say <<-OUT
33
33
 
34
- The application was registered for you and we generated an config file
34
+ The application was registered for you and we generated a config file
35
35
  containing your API token at:
36
36
 
37
37
  #{relative_config_path}
@@ -37,10 +37,18 @@ module Skylight
37
37
  'REPORT_PORT' => :'report.port',
38
38
  'REPORT_SSL' => :'report.ssl',
39
39
  'REPORT_DEFLATE' => :'report.deflate',
40
+ 'REPORT_PROXY_ADDR' => :'report.proxy_addr',
41
+ 'REPORT_PROXY_PORT' => :'report.proxy_port',
42
+ 'REPORT_PROXY_USER' => :'report.proxy_user',
43
+ 'REPORT_PROXY_PASS' => :'report.proxy_user',
40
44
  'ACCOUNTS_HOST' => :'accounts.host',
41
45
  'ACCOUNTS_PORT' => :'accounts.port',
42
46
  'ACCOUNTS_SSL' => :'accounts.ssl',
43
47
  'ACCOUNTS_DEFLATE' => :'accounts.deflate',
48
+ 'ACCOUNTS_PROXY_ADDR' => :'accounts.proxy_addr',
49
+ 'ACCOUNTS_PROXY_PORT' => :'accounts.proxy_port',
50
+ 'ACCOUNTS_PROXY_USER' => :'accounts.proxy_user',
51
+ 'ACCOUNTS_PROXY_PASS' => :'accounts.proxy_user',
44
52
  'ME_AUTHENTICATION' => :'me.authentication',
45
53
  'ME_CREDENTIALS_PATH' => :'me.credentials_path',
46
54
  'METRICS_REPORT_INTERVAL' => :'metrics.report_interval',
@@ -181,7 +189,7 @@ module Skylight
181
189
  def validate_token
182
190
  return :ok if skip_validation?
183
191
 
184
- http_auth = Util::HTTP.new(self, :accounts)
192
+ http_auth = Util::HTTP.new(self, :accounts, timeout: 5)
185
193
 
186
194
  res = http_auth.get("/agent/authenticate?hostname=#{URI.escape(self[:'hostname'])}")
187
195
 
@@ -285,7 +293,7 @@ authentication: #{self[:authentication]}
285
293
 
286
294
  # @api private
287
295
  def worker
288
- Worker::Builder.new(self)
296
+ @worker ||= Worker::Builder.new(self)
289
297
  end
290
298
 
291
299
  # @api private
@@ -92,7 +92,12 @@ module Skylight
92
92
  end
93
93
 
94
94
  @config.gc.enable
95
- @worker.spawn
95
+
96
+ unless @worker.spawn
97
+ log_error "failed to spawn worker"
98
+ return nil
99
+ end
100
+
96
101
  @subscriber.register!
97
102
 
98
103
  self
@@ -44,8 +44,14 @@ module Skylight
44
44
  def extract_binds(payload, precalculated)
45
45
  title, sql, binds = SqlLexer::Lexer.bindify(payload[:sql], precalculated)
46
46
  [ title, sql, binds, nil ]
47
- rescue
48
- error = ["sql_parse", encode(payload[:sql]), encode(payload: payload, precalculated: precalculated)]
47
+ rescue => e
48
+ group = "sql_parse"
49
+ description = e.inspect
50
+ details = encode(backtrace: e.backtrace,
51
+ payload: payload,
52
+ precalculated: precalculated)
53
+
54
+ error = [group, description, details]
49
55
  [ nil, nil, nil, error ]
50
56
  end
51
57
 
@@ -19,21 +19,33 @@ module Skylight
19
19
 
20
20
  include Logging
21
21
 
22
- attr_accessor :authentication, :config
22
+ attr_accessor :authentication
23
23
  attr_reader :host, :port
24
24
 
25
25
  class StartError < StandardError; end
26
26
  class ReadResponseError < StandardError; end
27
27
 
28
- def initialize(config, service = :report)
28
+ def initialize(config, service = :report, opts = {})
29
29
  @config = config
30
30
  @ssl = config["#{service}.ssl"]
31
31
  @host = config["#{service}.host"]
32
32
  @port = config["#{service}.port"]
33
+
33
34
  @proxy_addr = config["#{service}.proxy_addr"]
34
35
  @proxy_port = config["#{service}.proxy_port"]
35
36
  @proxy_user = config["#{service}.proxy_user"]
36
37
  @proxy_pass = config["#{service}.proxy_pass"]
38
+
39
+ @timeout = opts[:timeout] || 15
40
+
41
+ unless @proxy_addr
42
+ if http_proxy = ENV['HTTP_PROXY'] || ENV['http_proxy']
43
+ uri = URI.parse(http_proxy)
44
+ @proxy_addr, @proxy_port = uri.host, uri.port
45
+ @proxy_user, @proxy_pass = (uri.userinfo || '').split(/:/)
46
+ end
47
+ end
48
+
37
49
  @deflate = config["#{service}.deflate"]
38
50
  @authentication = config[:'authentication']
39
51
  end
@@ -86,7 +98,7 @@ module Skylight
86
98
  type.new(endpoint, headers)
87
99
  end
88
100
 
89
- def start(http)
101
+ def do_request(http, req)
90
102
  begin
91
103
  client = http.start
92
104
  rescue => e
@@ -94,17 +106,17 @@ module Skylight
94
106
  raise StartError, e.inspect
95
107
  end
96
108
 
97
- yield client
109
+ begin
110
+ res = client.request(req)
111
+ rescue Net::ReadTimeout, Timeout::Error, EOFError => e
112
+ raise ReadResponseError, e.inspect
113
+ end
114
+
115
+ yield res
98
116
  ensure
99
117
  client.finish if client
100
118
  end
101
119
 
102
- def read_code_and_body(res)
103
- code, body = res.code, res.body
104
- rescue Net::ReadTimeout, Timeout::Error, EOFError => e
105
- raise ReadResponseError, e.inspect
106
- end
107
-
108
120
  def execute(req, body=nil)
109
121
  t { fmt "executing HTTP request; host=%s; port=%s; path=%s, body=%s",
110
122
  @host, @port, req.path, body && body.bytesize }
@@ -116,9 +128,8 @@ module Skylight
116
128
 
117
129
  http = Net::HTTP.new(@host, @port, @proxy_addr, @proxy_port, @proxy_user, @proxy_pass)
118
130
 
119
- # Default is 60, but we don't want to wait that long.
120
- # This path is also used on app boot and Heroku will timeout at 60
121
- http.read_timeout = 15
131
+ http.open_timeout = @timeout
132
+ http.read_timeout = @timeout
122
133
 
123
134
  if @ssl
124
135
  http.use_ssl = true
@@ -126,16 +137,13 @@ module Skylight
126
137
  http.verify_mode = OpenSSL::SSL::VERIFY_PEER
127
138
  end
128
139
 
129
- start(http) do |client|
130
- res = client.request(req)
131
- code, body = read_code_and_body(res)
132
-
133
- unless code =~ /2\d\d/
134
- debug "server responded with #{code}"
135
- t { fmt "body=%s", body }
140
+ do_request(http, req) do |res|
141
+ unless res.code =~ /2\d\d/
142
+ debug "server responded with #{res.code}"
143
+ t { fmt "body=%s", res.body }
136
144
  end
137
145
 
138
- Response.new(code.to_i, res, body)
146
+ Response.new(res.code.to_i, res, res.body)
139
147
  end
140
148
  rescue Exception => e
141
149
  error "http %s %s failed; error=%s; msg=%s", req.method, req.path, e.class, e.message
@@ -39,7 +39,7 @@ module ActiveSupport
39
39
  private
40
40
 
41
41
  def unique_id
42
- SecureRandom.hex(10)
42
+ ::SecureRandom.hex(10)
43
43
  end
44
44
  end
45
45
 
@@ -1,4 +1,4 @@
1
1
  module Skylight
2
- VERSION = '0.3.11'
2
+ VERSION = '0.3.12'
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: 0.3.11
4
+ version: 0.3.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tilde, Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-04-11 00:00:00.000000000 Z
11
+ date: 2014-04-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport