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 +4 -4
- data/CHANGELOG.md +5 -0
- data/lib/skylight.rb +2 -2
- data/lib/skylight/config.rb +27 -23
- data/lib/skylight/util/http.rb +1 -1
- data/lib/skylight/version.rb +1 -1
- data/lib/skylight/worker/builder.rb +2 -2
- data/lib/skylight/worker/collector.rb +75 -14
- data/lib/skylight/worker/server.rb +4 -4
- metadata +2 -2
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: cdeb1ad6b563b4b7a487b38421575943337819a9
         | 
| 4 | 
            +
              data.tar.gz: 593f06bddf3ffa1ac6dca9544ce84bcecf7680fa
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 220a2e262e02e983112cc177c2cae80b11fd8a7d1c0f0235656fc250ff361db4017b3053be6d6d1ffe6c6c2e5316c1f88566764c6a2a2edb171368f095c6f734
         | 
| 7 | 
            +
              data.tar.gz: 3f5fd68ec9ec55c2e2703aa399b4e376b6b75bf70b66fdd058add5c9d5db1ce00428c4df3e721306bd6499e39d487e1363ddf397a7e4ef88ccc0e0621393065f
         | 
    
        data/CHANGELOG.md
    CHANGED
    
    
    
        data/lib/skylight.rb
    CHANGED
    
    | @@ -3,8 +3,8 @@ require 'socket' | |
| 3 3 | 
             
            require 'skylight/version'
         | 
| 4 4 |  | 
| 5 5 | 
             
            module Skylight
         | 
| 6 | 
            -
              TRACE_ENV_KEY      = ' | 
| 7 | 
            -
              STANDALONE_ENV_KEY = ' | 
| 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?
         | 
    
        data/lib/skylight/config.rb
    CHANGED
    
    | @@ -19,27 +19,27 @@ module Skylight | |
| 19 19 |  | 
| 20 20 | 
             
                # Map environment variable keys with Skylight configuration keys
         | 
| 21 21 | 
             
                ENV_TO_KEY = {
         | 
| 22 | 
            -
                  ' | 
| 23 | 
            -
                  ' | 
| 24 | 
            -
                  ' | 
| 25 | 
            -
                  ' | 
| 26 | 
            -
                  ' | 
| 27 | 
            -
                  ' | 
| 28 | 
            -
                  ' | 
| 29 | 
            -
                  ' | 
| 30 | 
            -
                  ' | 
| 31 | 
            -
                  ' | 
| 32 | 
            -
                  ' | 
| 33 | 
            -
                  ' | 
| 34 | 
            -
                  ' | 
| 35 | 
            -
                  ' | 
| 36 | 
            -
                  ' | 
| 37 | 
            -
                  ' | 
| 38 | 
            -
                  ' | 
| 39 | 
            -
                  ' | 
| 40 | 
            -
                  ' | 
| 41 | 
            -
                  ' | 
| 42 | 
            -
                  ' | 
| 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 | 
            -
                     | 
| 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 |  | 
    
        data/lib/skylight/util/http.rb
    CHANGED
    
    | @@ -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
         | 
    
        data/lib/skylight/version.rb
    CHANGED
    
    
| @@ -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: `#{ | 
| 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 | 
| 17 | 
            -
                    @ | 
| 18 | 
            -
                    @ | 
| 19 | 
            -
                    @ | 
| 20 | 
            -
                    @ | 
| 21 | 
            -
                    @ | 
| 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 | 
            -
                       | 
| 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 | 
            -
             | 
| 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 | 
            -
                    @ | 
| 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 | 
| 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      = ' | 
| 9 | 
            -
                  LOCKFILE_ENV_KEY   = ' | 
| 10 | 
            -
                  UDS_SRV_FD_KEY     = ' | 
| 11 | 
            -
                  KEEPALIVE_KEY      = ' | 
| 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. | 
| 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 | 
            +
            date: 2013-07-19 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: activesupport
         |