skylight 0.1.7 → 0.1.8

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: a0dd3b6275124e51f701f53d5c748dd874e5b83e
4
- data.tar.gz: 332f461813a0eda4ee7f8e83353fb2369e335c48
3
+ metadata.gz: cdeb1ad6b563b4b7a487b38421575943337819a9
4
+ data.tar.gz: 593f06bddf3ffa1ac6dca9544ce84bcecf7680fa
5
5
  SHA512:
6
- metadata.gz: 1ff8a8fd21899b7ba352d83b8d211bf1fa1d4826dd56aaed5d8d1ab3e65848985c41ddc9f1b7b0855800aaa6f80e8601ce599cd6c33df9e1a7282941fa67f240
7
- data.tar.gz: 3d626a30b21e61f3ed87f9d7ceceb6420b16a40a76c001afd105477ed7e0e06dd9fe037d71899a9364a4b5c44fa60fa7fd2e61fc9cfff20b0574d534cba1c8cc
6
+ metadata.gz: 220a2e262e02e983112cc177c2cae80b11fd8a7d1c0f0235656fc250ff361db4017b3053be6d6d1ffe6c6c2e5316c1f88566764c6a2a2edb171368f095c6f734
7
+ data.tar.gz: 3f5fd68ec9ec55c2e2703aa399b4e376b6b75bf70b66fdd058add5c9d5db1ce00428c4df3e721306bd6499e39d487e1363ddf397a7e4ef88ccc0e0621393065f
@@ -1,5 +1,10 @@
1
1
  ## unreleased ##
2
2
 
3
+ ## 0.1.8 (July 19, 2013)
4
+
5
+ * Update agent for new authentication scheme
6
+ * Change ENV variable prefix from SK_ to SKYLIGHT_
7
+
3
8
  ## 0.1.7 (July 11, 2013)
4
9
 
5
10
  * Add instrument_method helper
@@ -3,8 +3,8 @@ require 'socket'
3
3
  require 'skylight/version'
4
4
 
5
5
  module Skylight
6
- TRACE_ENV_KEY = 'SK_ENABLE_TRACE_LOGS'.freeze
7
- STANDALONE_ENV_KEY = 'SK_STANDALONE'.freeze
6
+ TRACE_ENV_KEY = 'SKYLIGHT_ENABLE_TRACE_LOGS'.freeze
7
+ STANDALONE_ENV_KEY = 'SKYLIGHT_STANDALONE'.freeze
8
8
  STANDALONE_ENV_VAL = 'server'.freeze
9
9
 
10
10
  def self.daemon?
@@ -19,27 +19,27 @@ module Skylight
19
19
 
20
20
  # Map environment variable keys with Skylight configuration keys
21
21
  ENV_TO_KEY = {
22
- 'SK_ROOT' => :'root',
23
- 'SK_LOG_FILE' => :'log_file',
24
- 'SK_LOG_LEVEL' => :'log_level',
25
- 'SK_APPLICATION' => :'application',
26
- 'SK_AUTHENTICATION' => :'authentication',
27
- 'SK_HOSTNAME' => :'hostname',
28
- 'SK_AGENT_INTERVAL' => :'agent.interval',
29
- 'SK_AGENT_KEEPALIVE' => :'agent.keepalive',
30
- 'SK_AGENT_SAMPLE_SIZE' => :'agent.sample',
31
- 'SK_AGENT_SOCKFILE_PATH' => :'agent.sockfile_path',
32
- 'SK_AGENT_STRATEGY' => :'agent.strategy',
33
- 'SK_REPORT_HOST' => :'report.host',
34
- 'SK_REPORT_PORT' => :'report.port',
35
- 'SK_REPORT_SSL' => :'report.ssl',
36
- 'SK_REPORT_DEFLATE' => :'report.deflate',
37
- 'SK_ACCOUNTS_HOST' => :'accounts.host',
38
- 'SK_ACCOUNTS_PORT' => :'accounts.port',
39
- 'SK_ACCOUNTS_SSL' => :'accounts.ssl',
40
- 'SK_ACCOUNTS_DEFLATE' => :'accounts.deflate',
41
- 'SK_ME_AUTHENTICATION' => :'me.authentication',
42
- 'SK_ME_CREDENTIALS_PATH' => :'me.credentials_path' }
22
+ 'ROOT' => :'root',
23
+ 'LOG_FILE' => :'log_file',
24
+ 'LOG_LEVEL' => :'log_level',
25
+ 'APPLICATION' => :'application',
26
+ 'AUTHENTICATION' => :'authentication',
27
+ 'HOSTNAME' => :'hostname',
28
+ 'AGENT_INTERVAL' => :'agent.interval',
29
+ 'AGENT_KEEPALIVE' => :'agent.keepalive',
30
+ 'AGENT_SAMPLE_SIZE' => :'agent.sample',
31
+ 'AGENT_SOCKFILE_PATH' => :'agent.sockfile_path',
32
+ 'AGENT_STRATEGY' => :'agent.strategy',
33
+ 'REPORT_HOST' => :'report.host',
34
+ 'REPORT_PORT' => :'report.port',
35
+ 'REPORT_SSL' => :'report.ssl',
36
+ 'REPORT_DEFLATE' => :'report.deflate',
37
+ 'ACCOUNTS_HOST' => :'accounts.host',
38
+ 'ACCOUNTS_PORT' => :'accounts.port',
39
+ 'ACCOUNTS_SSL' => :'accounts.ssl',
40
+ 'ACCOUNTS_DEFLATE' => :'accounts.deflate',
41
+ 'ME_AUTHENTICATION' => :'me.authentication',
42
+ 'ME_CREDENTIALS_PATH' => :'me.credentials_path' }
43
43
 
44
44
  # Default values for Skylight configuration keys
45
45
  DEFAULTS = {
@@ -61,6 +61,7 @@ module Skylight
61
61
 
62
62
  REQUIRED = {
63
63
  :'authentication' => "authentication token",
64
+ :'hostname' => "server hostname",
64
65
  :'report.host' => "skylight remote host",
65
66
  :'report.port' => "skylight remote port" }
66
67
 
@@ -97,7 +98,10 @@ module Skylight
97
98
  ret = {}
98
99
 
99
100
  env.each do |k, val|
100
- if key = ENV_TO_KEY[k]
101
+ # Support deprecated SK_ key prefix
102
+ next unless k =~ /^(?:SK|SKYLIGHT)_(.+)$/
103
+
104
+ if key = ENV_TO_KEY[$1]
101
105
  ret[key] =
102
106
  case val
103
107
  when /^false$/i then false
@@ -209,7 +213,7 @@ module Skylight
209
213
 
210
214
  ENV_TO_KEY.each do |k, v|
211
215
  if (c = get(v)) != DEFAULTS[v]
212
- ret[k] = cast_for_env(c)
216
+ ret["SKYLIGHT_#{k}"] = cast_for_env(c)
213
217
  end
214
218
  end
215
219
 
@@ -77,7 +77,7 @@ module Skylight
77
77
  headers[AUTHORIZATION] = authentication if authentication
78
78
  headers[ACCEPT] = APPLICATION_JSON
79
79
  headers[X_VERSION_HDR] = VERSION
80
- headers[CONTENT_ENCODING] = GZIP if @deflate
80
+ headers[CONTENT_ENCODING] = GZIP if length && @deflate
81
81
 
82
82
  hdrs.each do |k, v|
83
83
  headers[k] = v
@@ -1,4 +1,4 @@
1
1
  module Skylight
2
- VERSION = '0.1.7'
2
+ VERSION = '0.1.8'
3
3
  end
4
4
 
@@ -14,7 +14,7 @@ module Skylight
14
14
  end
15
15
 
16
16
  def build
17
- s = strategy
17
+ s = strategy.to_s
18
18
 
19
19
  case s
20
20
  when 'embedded'
@@ -32,7 +32,7 @@ module Skylight
32
32
  lockfile,
33
33
  server)
34
34
  else
35
- raise "unknown strategy: `#{strat}`"
35
+ raise "unknown strategy: `#{s}`"
36
36
  end
37
37
  end
38
38
 
@@ -1,8 +1,11 @@
1
+ require 'uri'
2
+
1
3
  module Skylight
2
4
  module Worker
3
5
  class Collector < Util::Task
6
+ include URI::Escape
7
+
4
8
  ENDPOINT = '/report'.freeze
5
- FLUSH_DELAY = 0.5
6
9
  CONTENT_TYPE = 'content-type'.freeze
7
10
  SKYLIGHT_V1 = 'application/x-skylight-report-v1'.freeze
8
11
 
@@ -11,14 +14,17 @@ module Skylight
11
14
  attr_reader :config
12
15
 
13
16
  def initialize(config)
14
- super(1000)
15
-
16
- @config = config
17
- @http = Util::HTTP.new(config)
18
- @size = config[:'agent.sample']
19
- @batch = nil
20
- @interval = config[:'agent.interval']
21
- @buf = ""
17
+ super(1000, 0.25)
18
+
19
+ @config = config
20
+ @size = config[:'agent.sample']
21
+ @batch = nil
22
+ @interval = config[:'agent.interval']
23
+ @buf = ""
24
+ @refresh_at = 0
25
+ @http_auth = Util::HTTP.new(config, :accounts)
26
+ @http_report = nil
27
+ # @http_report = Util::HTTP.new(config, :report)
22
28
 
23
29
  t { fmt "starting collector; interval=%d; size=%d", @interval, @size }
24
30
  end
@@ -26,8 +32,18 @@ module Skylight
26
32
  def handle(msg, now = Util::Clock.secs)
27
33
  @batch ||= new_batch(now)
28
34
 
35
+ if should_refresh_token?(now)
36
+ refresh_report_token(now)
37
+ end
38
+
29
39
  if @batch.should_flush?(now)
30
- flush(@batch)
40
+ if has_report_token?(now)
41
+ flush(@batch)
42
+ else
43
+ warn "do not have valid session token -- dropping"
44
+ return
45
+ end
46
+
31
47
  @batch = new_batch(now)
32
48
  end
33
49
 
@@ -47,7 +63,17 @@ module Skylight
47
63
 
48
64
  def finish
49
65
  t { fmt "collector finishing up" }
50
- flush(@batch) if @batch
66
+
67
+ now = Util::Clock.secs
68
+
69
+ if should_refresh_token?(now)
70
+ refresh_report_token(now)
71
+ end
72
+
73
+ if @batch && has_report_token?(now)
74
+ flush(@batch)
75
+ end
76
+
51
77
  @batch = nil
52
78
  end
53
79
 
@@ -57,7 +83,42 @@ module Skylight
57
83
  debug "flushing batch; size=%d", batch.sample.count
58
84
 
59
85
  @buf.clear
60
- @http.post(ENDPOINT, batch.encode(@buf), CONTENT_TYPE => SKYLIGHT_V1)
86
+ @http_report.post(ENDPOINT, batch.encode(@buf), CONTENT_TYPE => SKYLIGHT_V1)
87
+ end
88
+
89
+ def refresh_report_token(now)
90
+ res = @http_auth.get("/agent/authenticate?hostname=#{escape(config[:'hostname'])}")
91
+
92
+ unless res.success?
93
+ warn "could not fetch report session token; status=%s", res.status
94
+ return
95
+ end
96
+
97
+ tok = res.body['session']
98
+ tok = tok['token'] if tok
99
+
100
+ if tok
101
+ @refresh_at = now + 600
102
+ @http_report = Util::HTTP.new(config, :report)
103
+ @http_report.authentication = tok
104
+ else
105
+ if @http_report
106
+ @refresh_at = now + 60
107
+ end
108
+ warn "server did not return a session token"
109
+ end
110
+ rescue Exception => e
111
+ error "exception; msg=%s; class=%s", e.message, e.class
112
+ t { e.backtrace.join("\n") }
113
+ end
114
+
115
+ def should_refresh_token?(now)
116
+ now >= @refresh_at
117
+ end
118
+
119
+ def has_report_token?(now)
120
+ return unless @http_report
121
+ now < @refresh_at + (3600 * 3 - 660)
61
122
  end
62
123
 
63
124
  def new_batch(now)
@@ -71,12 +132,12 @@ module Skylight
71
132
  class Batch
72
133
  include Util::Logging
73
134
 
74
- attr_reader :config, :from, :counts, :sample
135
+ attr_reader :config, :from, :counts, :sample, :flush_at
75
136
 
76
137
  def initialize(config, size, from, interval)
77
138
  @config = config
78
139
  @from = from
79
- @flush_at = from + interval + FLUSH_DELAY
140
+ @flush_at = from + interval
80
141
  @sample = Util::UniformSample.new(size)
81
142
  @counts = Hash.new(0)
82
143
  end
@@ -5,10 +5,10 @@ module Skylight
5
5
  # TODO:
6
6
  # - Shutdown if no connections for over a minute
7
7
  class Server
8
- LOCKFILE_PATH = 'SK_LOCKFILE_PATH'.freeze
9
- LOCKFILE_ENV_KEY = 'SK_LOCKFILE_FD'.freeze
10
- UDS_SRV_FD_KEY = 'SK_UDS_FD'.freeze
11
- KEEPALIVE_KEY = 'SK_KEEPALIVE'.freeze
8
+ LOCKFILE_PATH = 'SKYLIGHT_LOCKFILE_PATH'.freeze
9
+ LOCKFILE_ENV_KEY = 'SKYLIGHT_LOCKFILE_FD'.freeze
10
+ UDS_SRV_FD_KEY = 'SKYLIGHT_UDS_FD'.freeze
11
+ KEEPALIVE_KEY = 'SKYLIGHT_KEEPALIVE'.freeze
12
12
 
13
13
  include Util::Logging
14
14
 
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
4
+ version: 0.1.8
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-07-11 00:00:00.000000000 Z
11
+ date: 2013-07-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport