skylight 0.0.16 → 0.1.0.alpha1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +3 -19
- data/bin/skylight +0 -2
- data/lib/skylight.rb +52 -42
- data/lib/skylight/api.rb +34 -0
- data/lib/skylight/cli.rb +68 -57
- data/lib/skylight/compat.rb +19 -5
- data/lib/skylight/config.rb +219 -98
- data/lib/skylight/gc.rb +109 -0
- data/lib/skylight/instrumenter.rb +53 -70
- data/lib/skylight/messages.rb +19 -0
- data/lib/skylight/messages/annotation.rb +13 -0
- data/lib/skylight/messages/base.rb +24 -0
- data/lib/skylight/messages/batch.rb +11 -0
- data/lib/skylight/messages/endpoint.rb +12 -0
- data/lib/skylight/messages/event.rb +12 -0
- data/lib/skylight/messages/hello.rb +53 -0
- data/lib/skylight/messages/span.rb +21 -0
- data/lib/skylight/messages/trace.rb +162 -0
- data/lib/skylight/middleware.rb +2 -4
- data/lib/skylight/normalizers.rb +89 -0
- data/lib/skylight/normalizers/default.rb +22 -0
- data/lib/skylight/normalizers/process_action.rb +19 -0
- data/lib/skylight/normalizers/render_collection.rb +14 -0
- data/lib/skylight/normalizers/render_partial.rb +14 -0
- data/lib/skylight/normalizers/render_template.rb +14 -0
- data/lib/skylight/{normalize → normalizers}/send_file.rb +15 -15
- data/lib/skylight/normalizers/sql.rb +25 -0
- data/lib/skylight/railtie.rb +21 -41
- data/lib/skylight/subscriber.rb +29 -19
- data/lib/skylight/util/clock.rb +8 -21
- data/lib/skylight/util/http.rb +93 -46
- data/lib/skylight/util/logging.rb +66 -0
- data/lib/skylight/util/queue.rb +7 -3
- data/lib/skylight/util/task.rb +154 -0
- data/lib/skylight/{compat → vendor/active_support}/notifications.rb +56 -24
- data/lib/skylight/{compat → vendor/active_support}/notifications/fanout.rb +19 -26
- data/lib/skylight/{compat → vendor/active_support}/notifications/instrumenter.rb +25 -18
- data/lib/skylight/vendor/active_support/per_thread_registry.rb +52 -0
- data/lib/skylight/vendor/beefcake.rb +256 -0
- data/lib/skylight/vendor/beefcake/buffer.rb +112 -0
- data/lib/skylight/vendor/beefcake/decode.rb +107 -0
- data/lib/skylight/vendor/beefcake/encode.rb +115 -0
- data/lib/skylight/vendor/{highline.rb → cli/highline.rb} +0 -0
- data/lib/skylight/vendor/{highline → cli/highline}/color_scheme.rb +0 -0
- data/lib/skylight/vendor/{highline → cli/highline}/compatibility.rb +0 -0
- data/lib/skylight/vendor/{highline → cli/highline}/import.rb +0 -0
- data/lib/skylight/vendor/{highline → cli/highline}/menu.rb +0 -0
- data/lib/skylight/vendor/{highline → cli/highline}/question.rb +0 -0
- data/lib/skylight/vendor/{highline → cli/highline}/simulate.rb +0 -0
- data/lib/skylight/vendor/{highline → cli/highline}/string_extensions.rb +0 -0
- data/lib/skylight/vendor/{highline → cli/highline}/style.rb +0 -0
- data/lib/skylight/vendor/{highline → cli/highline}/system_extensions.rb +0 -0
- data/lib/skylight/vendor/{thor.rb → cli/thor.rb} +0 -0
- data/lib/skylight/vendor/{thor → cli/thor}/actions.rb +0 -0
- data/lib/skylight/vendor/{thor → cli/thor}/actions/create_file.rb +0 -0
- data/lib/skylight/vendor/{thor → cli/thor}/actions/create_link.rb +0 -0
- data/lib/skylight/vendor/{thor → cli/thor}/actions/directory.rb +0 -0
- data/lib/skylight/vendor/{thor → cli/thor}/actions/empty_directory.rb +0 -0
- data/lib/skylight/vendor/{thor → cli/thor}/actions/file_manipulation.rb +0 -0
- data/lib/skylight/vendor/{thor → cli/thor}/actions/inject_into_file.rb +0 -0
- data/lib/skylight/vendor/{thor → cli/thor}/base.rb +0 -0
- data/lib/skylight/vendor/{thor → cli/thor}/command.rb +0 -0
- data/lib/skylight/vendor/{thor → cli/thor}/core_ext/hash_with_indifferent_access.rb +0 -0
- data/lib/skylight/vendor/{thor → cli/thor}/core_ext/io_binary_read.rb +0 -0
- data/lib/skylight/vendor/{thor → cli/thor}/core_ext/ordered_hash.rb +0 -0
- data/lib/skylight/vendor/{thor → cli/thor}/error.rb +0 -0
- data/lib/skylight/vendor/{thor → cli/thor}/group.rb +0 -0
- data/lib/skylight/vendor/{thor → cli/thor}/invocation.rb +0 -0
- data/lib/skylight/vendor/{thor → cli/thor}/parser.rb +0 -0
- data/lib/skylight/vendor/{thor → cli/thor}/parser/argument.rb +0 -0
- data/lib/skylight/vendor/{thor → cli/thor}/parser/arguments.rb +0 -0
- data/lib/skylight/vendor/{thor → cli/thor}/parser/option.rb +0 -0
- data/lib/skylight/vendor/{thor → cli/thor}/parser/options.rb +0 -0
- data/lib/skylight/vendor/{thor → cli/thor}/rake_compat.rb +0 -0
- data/lib/skylight/vendor/{thor → cli/thor}/runner.rb +0 -0
- data/lib/skylight/vendor/{thor → cli/thor}/shell.rb +0 -0
- data/lib/skylight/vendor/{thor → cli/thor}/shell/basic.rb +0 -0
- data/lib/skylight/vendor/{thor → cli/thor}/shell/color.rb +0 -0
- data/lib/skylight/vendor/{thor → cli/thor}/shell/html.rb +0 -0
- data/lib/skylight/vendor/{thor → cli/thor}/util.rb +0 -0
- data/lib/skylight/vendor/{thor → cli/thor}/version.rb +0 -0
- data/lib/skylight/vendor/thread_safe.rb +126 -0
- data/lib/skylight/vendor/thread_safe/non_concurrent_cache_backend.rb +133 -0
- data/lib/skylight/vendor/thread_safe/synchronized_cache_backend.rb +76 -0
- data/lib/skylight/version.rb +2 -1
- data/lib/skylight/worker.rb +12 -154
- data/lib/skylight/worker/builder.rb +72 -0
- data/lib/skylight/worker/collector.rb +124 -0
- data/lib/skylight/worker/connection.rb +77 -0
- data/lib/skylight/worker/embedded.rb +6 -0
- data/lib/skylight/worker/server.rb +307 -0
- data/lib/skylight/worker/standalone.rb +356 -0
- metadata +89 -77
- data/lib/skylight/connection.rb +0 -25
- data/lib/skylight/json_proto.rb +0 -88
- data/lib/skylight/normalize.rb +0 -63
- data/lib/skylight/normalize/default.rb +0 -17
- data/lib/skylight/normalize/process_action.rb +0 -17
- data/lib/skylight/normalize/render_collection.rb +0 -11
- data/lib/skylight/normalize/render_partial.rb +0 -14
- data/lib/skylight/normalize/render_template.rb +0 -13
- data/lib/skylight/normalize/sql.rb +0 -26
- data/lib/skylight/normalize/start_processing.rb +0 -12
- data/lib/skylight/sanity_checker.rb +0 -73
- data/lib/skylight/trace.rb +0 -160
- data/lib/skylight/util/atomic.rb +0 -73
- data/lib/skylight/util/bytes.rb +0 -40
- data/lib/skylight/util/ewma.rb +0 -32
- data/lib/skylight/util/uuid.rb +0 -33
@@ -0,0 +1,115 @@
|
|
1
|
+
require 'skylight/vendor/beefcake/buffer'
|
2
|
+
|
3
|
+
module Skylight
|
4
|
+
module Beefcake
|
5
|
+
class Buffer
|
6
|
+
|
7
|
+
def append(type, val, fn)
|
8
|
+
if fn != 0
|
9
|
+
wire = Buffer.wire_for(type)
|
10
|
+
append_info(fn, wire)
|
11
|
+
end
|
12
|
+
|
13
|
+
__send__("append_#{type}", val)
|
14
|
+
end
|
15
|
+
|
16
|
+
def append_info(fn, wire)
|
17
|
+
append_uint32((fn << 3) | wire)
|
18
|
+
end
|
19
|
+
|
20
|
+
def append_fixed32(n, tag=false)
|
21
|
+
if n < MinUint32 || n > MaxUint32
|
22
|
+
raise OutOfRangeError, n
|
23
|
+
end
|
24
|
+
|
25
|
+
self << [n].pack("V")
|
26
|
+
end
|
27
|
+
|
28
|
+
def append_fixed64(n)
|
29
|
+
if n < MinUint64 || n > MaxUint64
|
30
|
+
raise OutOfRangeError, n
|
31
|
+
end
|
32
|
+
|
33
|
+
self << [n & 0xFFFFFFFF, n >> 32].pack("VV")
|
34
|
+
end
|
35
|
+
|
36
|
+
def append_int32(n)
|
37
|
+
if n < MinInt32 || n > MaxInt32
|
38
|
+
raise OutOfRangeError, n
|
39
|
+
end
|
40
|
+
|
41
|
+
append_int64(n)
|
42
|
+
end
|
43
|
+
|
44
|
+
def append_uint32(n)
|
45
|
+
if n < MinUint32 || n > MaxUint32
|
46
|
+
raise OutOfRangeError, n
|
47
|
+
end
|
48
|
+
|
49
|
+
append_uint64(n)
|
50
|
+
end
|
51
|
+
|
52
|
+
def append_int64(n)
|
53
|
+
if n < MinInt64 || n > MaxInt64
|
54
|
+
raise OutOfRangeError, n
|
55
|
+
end
|
56
|
+
|
57
|
+
if n < 0
|
58
|
+
n += (1 << 64)
|
59
|
+
end
|
60
|
+
|
61
|
+
append_uint64(n)
|
62
|
+
end
|
63
|
+
|
64
|
+
def append_sint32(n)
|
65
|
+
append_uint32((n << 1) ^ (n >> 31))
|
66
|
+
end
|
67
|
+
|
68
|
+
def append_sfixed32(n)
|
69
|
+
append_fixed32((n << 1) ^ (n >> 31))
|
70
|
+
end
|
71
|
+
|
72
|
+
def append_sint64(n)
|
73
|
+
append_uint64((n << 1) ^ (n >> 63))
|
74
|
+
end
|
75
|
+
|
76
|
+
def append_sfixed64(n)
|
77
|
+
append_fixed64((n << 1) ^ (n >> 63))
|
78
|
+
end
|
79
|
+
|
80
|
+
def append_uint64(n)
|
81
|
+
if n < MinUint64 || n > MaxUint64
|
82
|
+
raise OutOfRangeError, n
|
83
|
+
end
|
84
|
+
|
85
|
+
while true
|
86
|
+
bits = n & 0x7F
|
87
|
+
n >>= 7
|
88
|
+
if n == 0
|
89
|
+
return self << bits
|
90
|
+
end
|
91
|
+
self << (bits | 0x80)
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
def append_float(n)
|
96
|
+
self << [n].pack("e")
|
97
|
+
end
|
98
|
+
|
99
|
+
def append_double(n)
|
100
|
+
self << [n].pack("E")
|
101
|
+
end
|
102
|
+
|
103
|
+
def append_bool(n)
|
104
|
+
append_int64(n ? 1 : 0)
|
105
|
+
end
|
106
|
+
|
107
|
+
def append_string(s)
|
108
|
+
append_uint64(s.length)
|
109
|
+
self << s
|
110
|
+
end
|
111
|
+
alias :append_bytes :append_string
|
112
|
+
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1,126 @@
|
|
1
|
+
require 'thread'
|
2
|
+
|
3
|
+
module ThreadSafe
|
4
|
+
autoload :NonConcurrentCacheBackend, 'skylight/vendor/thread_safe/non_concurrent_cache_backend'
|
5
|
+
autoload :SynchronizedCacheBackend, 'skylight/vendor/thread_safe/synchronized_cache_backend'
|
6
|
+
|
7
|
+
ConcurrentCacheBackend = SynchronizedCacheBackend
|
8
|
+
|
9
|
+
class Cache < ConcurrentCacheBackend
|
10
|
+
KEY_ERROR = defined?(KeyError) ? KeyError : IndexError # there is no KeyError in 1.8 mode
|
11
|
+
|
12
|
+
def initialize(options = nil, &block)
|
13
|
+
if options.kind_of?(::Hash)
|
14
|
+
validate_options_hash!(options)
|
15
|
+
else
|
16
|
+
options = nil
|
17
|
+
end
|
18
|
+
|
19
|
+
super(options)
|
20
|
+
@default_proc = block
|
21
|
+
end
|
22
|
+
|
23
|
+
def [](key)
|
24
|
+
if value = super
|
25
|
+
value
|
26
|
+
elsif @default_proc && !key?(key)
|
27
|
+
@default_proc.call(self, key)
|
28
|
+
else
|
29
|
+
value
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def fetch(key, default_value = NULL)
|
34
|
+
if NULL != (value = get_or_default(key, NULL))
|
35
|
+
value
|
36
|
+
elsif block_given?
|
37
|
+
yield key
|
38
|
+
elsif NULL != default_value
|
39
|
+
default_value
|
40
|
+
else
|
41
|
+
raise KEY_ERROR, 'key not found'
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def put_if_absent(key, value)
|
46
|
+
computed = false
|
47
|
+
result = compute_if_absent(key) do
|
48
|
+
computed = true
|
49
|
+
value
|
50
|
+
end
|
51
|
+
computed ? nil : result
|
52
|
+
end unless method_defined?(:put_if_absent)
|
53
|
+
|
54
|
+
def value?(value)
|
55
|
+
each_value do |v|
|
56
|
+
return true if value.equal?(v)
|
57
|
+
end
|
58
|
+
false
|
59
|
+
end unless method_defined?(:value?)
|
60
|
+
|
61
|
+
def keys
|
62
|
+
arr = []
|
63
|
+
each_pair {|k, v| arr << k}
|
64
|
+
arr
|
65
|
+
end unless method_defined?(:keys)
|
66
|
+
|
67
|
+
def values
|
68
|
+
arr = []
|
69
|
+
each_pair {|k, v| arr << v}
|
70
|
+
arr
|
71
|
+
end unless method_defined?(:values)
|
72
|
+
|
73
|
+
def each_key
|
74
|
+
each_pair {|k, v| yield k}
|
75
|
+
end unless method_defined?(:each_key)
|
76
|
+
|
77
|
+
def each_value
|
78
|
+
each_pair {|k, v| yield v}
|
79
|
+
end unless method_defined?(:each_value)
|
80
|
+
|
81
|
+
def empty?
|
82
|
+
each_pair {|k, v| return false}
|
83
|
+
true
|
84
|
+
end unless method_defined?(:empty?)
|
85
|
+
|
86
|
+
def size
|
87
|
+
count = 0
|
88
|
+
each_pair {|k, v| count += 1}
|
89
|
+
count
|
90
|
+
end unless method_defined?(:size)
|
91
|
+
|
92
|
+
def marshal_dump
|
93
|
+
raise TypeError, "can't dump hash with default proc" if @default_proc
|
94
|
+
h = {}
|
95
|
+
each_pair {|k, v| h[k] = v}
|
96
|
+
h
|
97
|
+
end
|
98
|
+
|
99
|
+
def marshal_load(hash)
|
100
|
+
initialize
|
101
|
+
populate_from(hash)
|
102
|
+
end
|
103
|
+
|
104
|
+
undef :freeze
|
105
|
+
|
106
|
+
private
|
107
|
+
def initialize_copy(other)
|
108
|
+
super
|
109
|
+
populate_from(other)
|
110
|
+
end
|
111
|
+
|
112
|
+
def populate_from(hash)
|
113
|
+
hash.each_pair {|k, v| self[k] = v}
|
114
|
+
self
|
115
|
+
end
|
116
|
+
|
117
|
+
def validate_options_hash!(options)
|
118
|
+
if (initial_capacity = options[:initial_capacity]) && (!initial_capacity.kind_of?(Fixnum) || initial_capacity < 0)
|
119
|
+
raise ArgumentError, ":initial_capacity must be a positive Fixnum"
|
120
|
+
end
|
121
|
+
if (load_factor = options[:load_factor]) && (!load_factor.kind_of?(Numeric) || load_factor <= 0 || load_factor > 1)
|
122
|
+
raise ArgumentError, ":load_factor must be a number between 0 and 1"
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
@@ -0,0 +1,133 @@
|
|
1
|
+
module ThreadSafe
|
2
|
+
class NonConcurrentCacheBackend
|
3
|
+
# WARNING: all public methods of the class must operate on the @backend directly without calling each other. This is important
|
4
|
+
# because of the SynchronizedCacheBackend which uses a non-reentrant mutex for perfomance reasons.
|
5
|
+
def initialize(options = nil)
|
6
|
+
@backend = {}
|
7
|
+
end
|
8
|
+
|
9
|
+
def [](key)
|
10
|
+
@backend[key]
|
11
|
+
end
|
12
|
+
|
13
|
+
def []=(key, value)
|
14
|
+
@backend[key] = value
|
15
|
+
end
|
16
|
+
|
17
|
+
def compute_if_absent(key)
|
18
|
+
if NULL != (stored_value = @backend.fetch(key, NULL))
|
19
|
+
stored_value
|
20
|
+
else
|
21
|
+
@backend[key] = yield
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def replace_pair(key, old_value, new_value)
|
26
|
+
if pair?(key, old_value)
|
27
|
+
@backend[key] = new_value
|
28
|
+
true
|
29
|
+
else
|
30
|
+
false
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def replace_if_exists(key, new_value)
|
35
|
+
if NULL != (stored_value = @backend.fetch(key, NULL))
|
36
|
+
@backend[key] = new_value
|
37
|
+
stored_value
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def compute_if_present(key)
|
42
|
+
if NULL != (stored_value = @backend.fetch(key, NULL))
|
43
|
+
store_computed_value(key, yield(stored_value))
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def compute(key)
|
48
|
+
store_computed_value(key, yield(@backend[key]))
|
49
|
+
end
|
50
|
+
|
51
|
+
def merge_pair(key, value)
|
52
|
+
if NULL == (stored_value = @backend.fetch(key, NULL))
|
53
|
+
@backend[key] = value
|
54
|
+
else
|
55
|
+
store_computed_value(key, yield(stored_value))
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def get_and_set(key, value)
|
60
|
+
stored_value = @backend[key]
|
61
|
+
@backend[key] = value
|
62
|
+
stored_value
|
63
|
+
end
|
64
|
+
|
65
|
+
def key?(key)
|
66
|
+
@backend.key?(key)
|
67
|
+
end
|
68
|
+
|
69
|
+
def value?(value)
|
70
|
+
@backend.value?(value)
|
71
|
+
end
|
72
|
+
|
73
|
+
def delete(key)
|
74
|
+
@backend.delete(key)
|
75
|
+
end
|
76
|
+
|
77
|
+
def delete_pair(key, value)
|
78
|
+
if pair?(key, value)
|
79
|
+
@backend.delete(key)
|
80
|
+
true
|
81
|
+
else
|
82
|
+
false
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
def clear
|
87
|
+
@backend.clear
|
88
|
+
self
|
89
|
+
end
|
90
|
+
|
91
|
+
def each_pair
|
92
|
+
dupped_backend.each_pair do |k, v|
|
93
|
+
yield k, v
|
94
|
+
end
|
95
|
+
self
|
96
|
+
end
|
97
|
+
|
98
|
+
def size
|
99
|
+
@backend.size
|
100
|
+
end
|
101
|
+
|
102
|
+
def get_or_default(key, default_value)
|
103
|
+
@backend.fetch(key, default_value)
|
104
|
+
end
|
105
|
+
|
106
|
+
alias_method :_get, :[]
|
107
|
+
alias_method :_set, :[]=
|
108
|
+
private :_get, :_set
|
109
|
+
private
|
110
|
+
def initialize_copy(other)
|
111
|
+
super
|
112
|
+
@backend = {}
|
113
|
+
self
|
114
|
+
end
|
115
|
+
|
116
|
+
def dupped_backend
|
117
|
+
@backend.dup
|
118
|
+
end
|
119
|
+
|
120
|
+
def pair?(key, expected_value)
|
121
|
+
NULL != (stored_value = @backend.fetch(key, NULL)) && expected_value.equal?(stored_value)
|
122
|
+
end
|
123
|
+
|
124
|
+
def store_computed_value(key, new_value)
|
125
|
+
if new_value.nil?
|
126
|
+
@backend.delete(key)
|
127
|
+
nil
|
128
|
+
else
|
129
|
+
@backend[key] = new_value
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|