skylight 0.1.7.alpha1 → 0.1.7

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: db1b0ac1268ea2ee9d131e07bd233d1865f5ff7b
4
- data.tar.gz: b42da292696538f036387909cdb44331ca32494a
3
+ metadata.gz: a0dd3b6275124e51f701f53d5c748dd874e5b83e
4
+ data.tar.gz: 332f461813a0eda4ee7f8e83353fb2369e335c48
5
5
  SHA512:
6
- metadata.gz: 2c59dceb8da40478a4e7a6ccb1b7d069268449ffbfe8aa61634f50e15296951f103ae3d5aa4cffce2eded0f4a7714c0ac9019f8ae75493487bfb5040fa6dab96
7
- data.tar.gz: bd2f355e06b37128932b2ed61a03ee7340caaec31c2531cf293c65276832444962be7464f88daf91154a52e61684b12a36cfce040a0f01380b4cd3ebcf28074c
6
+ metadata.gz: 1ff8a8fd21899b7ba352d83b8d211bf1fa1d4826dd56aaed5d8d1ab3e65848985c41ddc9f1b7b0855800aaa6f80e8601ce599cd6c33df9e1a7282941fa67f240
7
+ data.tar.gz: 3d626a30b21e61f3ed87f9d7ceceb6420b16a40a76c001afd105477ed7e0e06dd9fe037d71899a9364a4b5c44fa60fa7fd2e61fc9cfff20b0574d534cba1c8cc
data/CHANGELOG.md CHANGED
@@ -1,6 +1,12 @@
1
1
  ## unreleased ##
2
2
 
3
+ ## 0.1.7 (July 11, 2013)
4
+
5
+ * Add instrument_method helper
3
6
  * Add the ability to configure logging from railtie
7
+ * Tracks the current host
8
+ * [BUG] Handle AS::N monkey patching when there are already subscribers
9
+ * [BUG] Handle ruby 1.9.2 encoding bug
4
10
 
5
11
  ## 0.1.6 (June 11, 2013)
6
12
 
data/lib/skylight.rb CHANGED
@@ -23,6 +23,7 @@ module Skylight
23
23
  autoload :CLI, 'skylight/cli'
24
24
  autoload :Config, 'skylight/config'
25
25
  autoload :GC, 'skylight/gc'
26
+ autoload :Helpers, 'skylight/helpers'
26
27
  autoload :Instrumenter, 'skylight/instrumenter'
27
28
  autoload :Messages, 'skylight/messages'
28
29
  autoload :Middleware, 'skylight/middleware'
@@ -59,6 +60,7 @@ module Skylight
59
60
 
60
61
  TIER_REGEX = /^(?:#{TIERS.join('|')})(?:\.|$)/
61
62
  CATEGORY_REGEX = /^[a-z0-9_-]+(?:\.[a-z0-9_-]+)*$/i
63
+ DEFAULT_CATEGORY = "app.block".freeze
62
64
 
63
65
  def self.start!(*args)
64
66
  Instrumenter.start!(*args)
@@ -77,13 +79,23 @@ module Skylight
77
79
  inst.trace(*args, &blk)
78
80
  end
79
81
 
80
- def self.instrument(*args, &blk)
82
+ def self.instrument(opts = {}, &blk)
81
83
  unless inst = Instrumenter.instance
82
84
  return yield if block_given?
83
85
  return
84
86
  end
85
87
 
86
- inst.instrument(*args, &blk)
88
+ if Hash === opts
89
+ category = opts.delete(:category) || DEFAULT_CATEGORY
90
+ title = opts.delete(:title)
91
+ desc = opts.delete(:description)
92
+ else
93
+ category = DEFAULT_CATEGORY
94
+ title = opts.to_s
95
+ desc = nil
96
+ end
97
+
98
+ inst.instrument(category, title, desc, &blk)
87
99
  end
88
100
 
89
101
  RUBYBIN = File.join(
data/lib/skylight/cli.rb CHANGED
@@ -28,6 +28,20 @@ module Skylight
28
28
  config.write(config_path)
29
29
 
30
30
  say "Congratulations. Your application is on Skylight! http://www.skylight.io", :green
31
+ say <<-OUT
32
+
33
+ The application was registered for you and we generated an config file
34
+ containing your API token at:
35
+
36
+ #{relative_config_path}
37
+
38
+ The next step is for you to deploy your application to production. The
39
+ easiest way is to just commit the config file to your source control
40
+ repository and deploy from there. You can learn more about the process at:
41
+
42
+ http://docs.skylight.io/getting-started/#deploy
43
+
44
+ OUT
31
45
  rescue Interrupt
32
46
  end
33
47
 
@@ -78,8 +92,12 @@ module Skylight
78
92
  yaml['token']
79
93
  end
80
94
 
95
+ def relative_config_path
96
+ 'config/skylight.yml'
97
+ end
98
+
81
99
  def config_path
82
- File.expand_path('config/skylight.yml')
100
+ File.expand_path(relative_config_path)
83
101
  end
84
102
 
85
103
  def credentials_path
@@ -1,11 +1,34 @@
1
1
  module Skylight
2
2
  # Ensure the version of AS:N being used is recent enough
3
3
  begin
4
- # Attempt to reference an internal class
4
+ # Attempt to reference an internal class only present in the new AS::Notifications
5
5
  ActiveSupport::Notifications::Fanout::Subscribers
6
6
  rescue NameError
7
+
8
+ # The things we do...
9
+ class ::ActiveSupport::Notifications::Fanout
10
+ attr_reader :subscribers
11
+
12
+ class Subscriber
13
+ attr_reader :pattern, :delegate
14
+ end
15
+ end
16
+
17
+ notifier = ActiveSupport::Notifications.notifier
18
+
7
19
  # If the class is missing, require our vendored AS::N
8
20
  require 'skylight/vendor/active_support/notifications'
21
+
22
+ if notifier.subscribers.respond_to?(:each)
23
+ notifier.subscribers.each do |sub|
24
+ pattern = sub.respond_to?(:pattern) && sub.pattern
25
+ delegate = sub.respond_to?(:delegate) && sub.delegate
26
+
27
+ if pattern && delegate
28
+ ActiveSupport::Notifications.subscribe(pattern, delegate)
29
+ end
30
+ end
31
+ end
9
32
  end
10
33
  end
11
34
 
@@ -2,11 +2,21 @@ require 'yaml'
2
2
  require 'fileutils'
3
3
  require 'logger'
4
4
  require 'thread'
5
+ require 'socket'
5
6
 
6
7
  module Skylight
7
8
  class Config
8
9
  MUTEX = Mutex.new
9
10
 
11
+ def self.default_hostname
12
+ if hostname = Socket.gethostname
13
+ hostname.strip!
14
+ hostname = nil if hostname == ''
15
+ end
16
+
17
+ hostname || SecureRandom.uuid
18
+ end
19
+
10
20
  # Map environment variable keys with Skylight configuration keys
11
21
  ENV_TO_KEY = {
12
22
  'SK_ROOT' => :'root',
@@ -14,6 +24,7 @@ module Skylight
14
24
  'SK_LOG_LEVEL' => :'log_level',
15
25
  'SK_APPLICATION' => :'application',
16
26
  'SK_AUTHENTICATION' => :'authentication',
27
+ 'SK_HOSTNAME' => :'hostname',
17
28
  'SK_AGENT_INTERVAL' => :'agent.interval',
18
29
  'SK_AGENT_KEEPALIVE' => :'agent.keepalive',
19
30
  'SK_AGENT_SAMPLE_SIZE' => :'agent.sample',
@@ -34,6 +45,7 @@ module Skylight
34
45
  DEFAULTS = {
35
46
  :'log_file' => '-'.freeze,
36
47
  :'log_level' => 'INFO'.freeze,
48
+ :'hostname' => default_hostname,
37
49
  :'agent.keepalive' => 60,
38
50
  :'agent.interval' => 5,
39
51
  :'agent.sample' => 200,
@@ -0,0 +1,77 @@
1
+ module Skylight
2
+ module Helpers
3
+ module ClassMethods
4
+ def method_added(name)
5
+ super
6
+
7
+ if opts = @__sk_instrument_next_method
8
+ @__sk_instrument_next_method = nil
9
+ title = "#{to_s}##{name}"
10
+ __sk_instrument_method_on(self, name, title, opts)
11
+ end
12
+ end
13
+
14
+ def singleton_method_added(name)
15
+ super
16
+
17
+ if opts = @__sk_instrument_next_method
18
+ @__sk_instrument_next_method = nil
19
+ title = "#{to_s}.#{name}"
20
+ __sk_instrument_method_on(__sk_singleton_class, name, title, opts)
21
+ end
22
+ end
23
+
24
+ def instrument_method(*args)
25
+ opts = args.pop if Hash === args.last
26
+
27
+ if name = args.pop
28
+ title = "#{to_s}##{name}"
29
+ __sk_instrument_method_on(self, name, title, opts || {})
30
+ else
31
+ @__sk_instrument_next_method = opts || {}
32
+ end
33
+ end
34
+
35
+ private
36
+
37
+ def __sk_instrument_method_on(klass, name, title, opts)
38
+ category = (opts[:category] || "app.method").to_s
39
+ title = (opts[:title] || title).to_s
40
+ desc = opts[:description].to_s if opts[:description]
41
+
42
+ klass.class_eval <<-RUBY
43
+ alias_method :"#{name}_before_instrument", :"#{name}"
44
+
45
+ def #{name}(*args, &blk)
46
+ span = Skylight.instrument(
47
+ category: :"#{category}",
48
+ title: #{title.inspect},
49
+ description: #{desc.inspect})
50
+
51
+ begin
52
+ #{name}_before_instrument(*args, &blk)
53
+ ensure
54
+ span.done if span
55
+ end
56
+ end
57
+ RUBY
58
+ end
59
+
60
+ if respond_to?(:singleton_class)
61
+ alias :__sk_singleton_class :singleton_class
62
+ else
63
+ def __sk_singleton_class
64
+ class << self; self; end
65
+ end
66
+ end
67
+ end
68
+
69
+ def self.included(base)
70
+ base.class_eval do
71
+ @__sk_instrument_next_method = nil
72
+ extend ClassMethods
73
+ end
74
+ end
75
+
76
+ end
77
+ end
@@ -5,6 +5,7 @@ module Skylight
5
5
 
6
6
  required :timestamp, :uint32, 1
7
7
  repeated :endpoints, Endpoint, 2
8
+ optional :hostname, :string, 3
8
9
 
9
10
  end
10
11
  end
@@ -10,6 +10,7 @@ module Skylight
10
10
  CONTENT_LENGTH = 'content-length'.freeze
11
11
  CONTENT_TYPE = 'content-type'.freeze
12
12
  ACCEPT = 'Accept'.freeze
13
+ X_VERSION_HDR = 'x-skylight-agent-version'.freeze
13
14
  APPLICATION_JSON = 'application/json'.freeze
14
15
  AUTHORIZATION = 'authorization'.freeze
15
16
  DEFLATE = 'deflate'.freeze
@@ -75,6 +76,7 @@ module Skylight
75
76
  headers[CONTENT_LENGTH] = length.to_s if length
76
77
  headers[AUTHORIZATION] = authentication if authentication
77
78
  headers[ACCEPT] = APPLICATION_JSON
79
+ headers[X_VERSION_HDR] = VERSION
78
80
  headers[CONTENT_ENCODING] = GZIP if @deflate
79
81
 
80
82
  hdrs.each do |k, v|
@@ -80,13 +80,19 @@ module Skylight
80
80
 
81
81
  BINARY = 'BINARY'
82
82
 
83
- if defined?(JRUBY_VERSION)
83
+ # Detect a ruby encodings bug, as far as I know, this exists in
84
+ # most versions fo JRuby as well as 1.9.2
85
+ def self.current_ruby_has_encoding_bug?
86
+ base = "\0\1".force_encoding('BINARY')
87
+ base << "BUG".encode("UTF-8")
88
+ base.encoding.to_s == 'UTF-8'
89
+ end
90
+
91
+ if ''.respond_to?(:force_encoding) && current_ruby_has_encoding_bug?
84
92
  def <<(bytes)
85
- buf.force_encoding(BINARY)
86
93
  buf << bytes
87
- rescue
88
- p [ buf, bytes ]
89
- raise
94
+ buf.force_encoding(BINARY)
95
+ buf
90
96
  end
91
97
  else
92
98
  def <<(bytes)
@@ -1,4 +1,4 @@
1
1
  module Skylight
2
- VERSION = '0.1.7.alpha1'
2
+ VERSION = '0.1.7'
3
3
  end
4
4
 
@@ -117,6 +117,7 @@ module Skylight
117
117
 
118
118
  Messages::Batch.new(
119
119
  timestamp: from,
120
+ hostname: config[:hostname],
120
121
  endpoints: endpoints.values).
121
122
  encode(buf)
122
123
 
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.1.7.alpha1
4
+ version: 0.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tilde, Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-06-26 00:00:00.000000000 Z
11
+ date: 2013-07-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -39,6 +39,7 @@ files:
39
39
  - lib/skylight/config.rb
40
40
  - lib/skylight/data/cacert.pem
41
41
  - lib/skylight/gc.rb
42
+ - lib/skylight/helpers.rb
42
43
  - lib/skylight/instrumenter.rb
43
44
  - lib/skylight/messages.rb
44
45
  - lib/skylight/messages/annotation.rb
@@ -143,9 +144,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
143
144
  version: 1.9.2
144
145
  required_rubygems_version: !ruby/object:Gem::Requirement
145
146
  requirements:
146
- - - '>'
147
+ - - '>='
147
148
  - !ruby/object:Gem::Version
148
- version: 1.3.1
149
+ version: '0'
149
150
  requirements: []
150
151
  rubyforge_project:
151
152
  rubygems_version: 2.0.3