skylight 0.1.0 → 0.1.1

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: 70cfda4f0d6f3ed1a3870e7ed3929d61ee521ca9
4
- data.tar.gz: f6ce5f583badc9507760a67ec1f63d230829ed2d
3
+ metadata.gz: f501ad269f116e66053195e765359bb141347b0d
4
+ data.tar.gz: 933730962fe952b6928ce50af200825b60cc11fc
5
5
  SHA512:
6
- metadata.gz: 5ff9460df31d98b29318ceaa1cb9e3236859c6d74a3d043c5dcba5f3cf305b2b443938be75eb18f4c033ed26261a9cbec7da62a301bd48f1d89f876141ececf1
7
- data.tar.gz: bd9c7bb73e53df7db59daa9124b8c5174a40890acd64bf6090ae6429e5ac612de1f95f1c95f7f3c333e0839e3f2ac53f16833724472782c97c7fd69673d51909
6
+ metadata.gz: 9d40ae02fb550a5fc409079b97d4087006610868589e2254013995df7d0d05e02f125a342258ff2e62747b58c7cdc5f6e4db1485af7bdafebee7659e446968e4
7
+ data.tar.gz: 6d31c629aee42b171e82c06bd5fa70cc3bc91ee09c346f9a0db91ad54df4c9ea67fe36f635f8f413789c45eee0714f95115ea08e4b0417f4d58c567257980577
@@ -83,8 +83,7 @@ module Skylight
83
83
  end
84
84
 
85
85
  def credentials_path
86
- return nil unless ENV['HOME']
87
- File.expand_path(".skylight", ENV['HOME'])
86
+ File.expand_path(config[:'me.credentials_path'])
88
87
  end
89
88
 
90
89
  def api
@@ -22,23 +22,26 @@ module Skylight
22
22
  'SK_ACCOUNTS_HOST' => :'accounts.host',
23
23
  'SK_ACCOUNTS_PORT' => :'accounts.port',
24
24
  'SK_ACCOUNTS_SSL' => :'accounts.ssl',
25
- 'SK_ACCOUNTS_DEFLATE' => :'accounts.deflate' }
25
+ 'SK_ACCOUNTS_DEFLATE' => :'accounts.deflate',
26
+ 'SK_ME_AUTHENTICATION' => :'me.authentication',
27
+ 'SK_ME_CREDENTIALS_PATH' => :'me.credentials_path' }
26
28
 
27
29
  # Default values for Skylight configuration keys
28
30
  DEFAULTS = {
29
- :'log' => '-'.freeze,
30
- :'log_level' => 'INFO'.freeze,
31
- :'agent.keepalive' => 60,
32
- :'agent.interval' => 5,
33
- :'agent.sample' => 200,
34
- :'report.host' => 'agent.skylight.io'.freeze,
35
- :'report.port' => 443,
36
- :'report.ssl' => true,
37
- :'report.deflate' => true,
38
- :'accounts.host' => 'www.skylight.io'.freeze,
39
- :'accounts.port' => 443,
40
- :'accounts.ssl' => true,
41
- :'accounts.deflate' => false }.freeze
31
+ :'log' => '-'.freeze,
32
+ :'log_level' => 'INFO'.freeze,
33
+ :'agent.keepalive' => 60,
34
+ :'agent.interval' => 5,
35
+ :'agent.sample' => 200,
36
+ :'report.host' => 'agent.skylight.io'.freeze,
37
+ :'report.port' => 443,
38
+ :'report.ssl' => true,
39
+ :'report.deflate' => true,
40
+ :'accounts.host' => 'www.skylight.io'.freeze,
41
+ :'accounts.port' => 443,
42
+ :'accounts.ssl' => true,
43
+ :'accounts.deflate' => false,
44
+ :'me.credentials_path' => '~/.skylight' }.freeze
42
45
 
43
46
  REQUIRED = {
44
47
  :'authentication' => "authentication token",
@@ -224,7 +227,7 @@ authentication: #{self[:authentication]}
224
227
  end
225
228
 
226
229
  def gc
227
- GC.new(get('gc.profiler', ::GC::Profiler))
230
+ @gc ||= GC.new(self, get('gc.profiler', ::GC::Profiler))
228
231
  end
229
232
 
230
233
  def logger
@@ -2,9 +2,11 @@ require 'thread'
2
2
 
3
3
  module Skylight
4
4
  class GC
5
- METHODS = [ :enable, :total_time ]
5
+ METHODS = [ :enable, :total_time, :clear ]
6
6
  TH_KEY = :SK_GC_CURR_WINDOW
7
7
 
8
+ include Util::Logging
9
+
8
10
  def self.update
9
11
  if win = Thread.current[TH_KEY]
10
12
  win.update
@@ -19,15 +21,24 @@ module Skylight
19
21
  end
20
22
  end
21
23
 
22
- def initialize(profiler)
24
+ attr_reader :config
25
+
26
+ def initialize(config, profiler)
23
27
  @listeners = []
28
+ @config = config
24
29
  @lock = Mutex.new
25
30
 
26
31
  if METHODS.all? { |m| profiler.respond_to?(m) }
27
32
  @profiler = profiler
33
+ else
34
+ debug "disabling GC profiling"
28
35
  end
29
36
  end
30
37
 
38
+ def enable
39
+ @profiler.enable if @profiler
40
+ end
41
+
31
42
  def start_track
32
43
  return if Thread.current[TH_KEY]
33
44
 
@@ -45,6 +45,7 @@ module Skylight
45
45
 
46
46
  t { "starting instrumenter" }
47
47
  @config.validate!
48
+ @config.gc.enable
48
49
  @worker.spawn
49
50
  @subscriber.register!
50
51
 
@@ -91,7 +92,7 @@ module Skylight
91
92
  begin
92
93
  built = trace.build
93
94
 
94
- if built.valid?
95
+ if built && built.valid?
95
96
  process(built)
96
97
  else
97
98
  debug "trace invalid -- dropping"
@@ -21,6 +21,7 @@ module Skylight
21
21
 
22
22
  def initialize(endpoint = "Unknown", start = Util::Clock.now, config = nil)
23
23
  @endpoint = endpoint
24
+ @busted = false
24
25
  @config = config
25
26
  @start = start
26
27
  @spans = []
@@ -42,15 +43,19 @@ module Skylight
42
43
  begin
43
44
  yield
44
45
  ensure
45
- now = Util::Clock.now
46
- gc_time = GC.time
46
+ unless @busted
47
+ now = Util::Clock.now
48
+
49
+ GC.update
50
+ gc_time = GC.time
51
+
52
+ if gc_time > 0
53
+ start(now - gc_time, 'noise.gc')
54
+ stop(now)
55
+ end
47
56
 
48
- if gc_time > 0
49
- start(now - gc_time, 'noise.gc')
50
57
  stop(now)
51
58
  end
52
-
53
- stop(now)
54
59
  end
55
60
  ensure
56
61
  gc.stop_track
@@ -58,6 +63,8 @@ module Skylight
58
63
  end
59
64
 
60
65
  def record(time, cat, title = nil, desc = nil, annot = {})
66
+ return if @busted
67
+
61
68
  sp = span(time, cat, title, desc, annot)
62
69
 
63
70
  return self if :skip == sp
@@ -69,6 +76,8 @@ module Skylight
69
76
  end
70
77
 
71
78
  def start(time, cat, title = nil, desc = nil, annot = {})
79
+ return if @busted
80
+
72
81
  sp = span(time, cat, title, desc, annot)
73
82
 
74
83
  push(sp)
@@ -77,6 +86,8 @@ module Skylight
77
86
  end
78
87
 
79
88
  def stop(time)
89
+ return if @busted
90
+
80
91
  sp = pop
81
92
 
82
93
  return self if :skip == sp
@@ -88,6 +99,7 @@ module Skylight
88
99
  end
89
100
 
90
101
  def build
102
+ return if @busted
91
103
  raise TraceError, "trace unbalanced" unless @stack.empty?
92
104
 
93
105
  Trace.new(
@@ -106,6 +118,12 @@ module Skylight
106
118
  sp.annotations = to_annotations(annot)
107
119
  sp.started_at = relativize(time)
108
120
  sp.absolute_time = time
121
+
122
+ if sp.started_at < 0
123
+ @busted = true
124
+ raise TraceError, "[BUG] span started_at negative; event=#{cat}"
125
+ end
126
+
109
127
  sp
110
128
  end
111
129
 
@@ -130,6 +148,7 @@ module Skylight
130
148
 
131
149
  def pop
132
150
  unless sp = @stack.pop
151
+ @busted = true
133
152
  raise TraceError, "trace unbalanced"
134
153
  end
135
154
 
@@ -1,19 +1,23 @@
1
1
  module Skylight
2
2
  class Subscriber
3
+ include Util::Logging
3
4
 
4
5
  attr_reader :config
5
6
 
6
7
  def initialize(config)
7
- @config = config
8
+ @config = config
9
+ @subscriber = nil
8
10
  @normalizers = Normalizers.build(config)
9
11
  end
10
12
 
11
13
  def register!
12
- ActiveSupport::Notifications.subscribe nil, self
14
+ unregister! if @subscriber
15
+ @subscriber = ActiveSupport::Notifications.subscribe nil, self
13
16
  end
14
17
 
15
18
  def unregister!
16
- ActiveSupport::Notifications.unsubscribe self
19
+ ActiveSupport::Notifications.unsubscribe @subscriber
20
+ @subscriber = nil
17
21
  end
18
22
 
19
23
  def start(name, id, payload)
@@ -23,11 +27,15 @@ module Skylight
23
27
  trace.start(now - gc_time, cat, title, desc, annot)
24
28
 
25
29
  trace
30
+ rescue Exception => e
31
+ error "Subscriber#start error; msg=%s", e.message
26
32
  end
27
33
 
28
34
  def finish(name, id, payload)
29
35
  return unless trace = Instrumenter.current_trace
30
36
  trace.stop(now - gc_time)
37
+ rescue Exception => e
38
+ error "Subscriber#finish error; msg=%s", e.message
31
39
  end
32
40
 
33
41
  def publish(name, *args)
@@ -1,4 +1,4 @@
1
1
  module Skylight
2
- VERSION = '0.1.0'
2
+ VERSION = '0.1.1'
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.1.0
4
+ version: 0.1.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: 2013-05-24 00:00:00.000000000 Z
11
+ date: 2013-05-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport