upfluence-thrift 1.0.1 → 1.0.3
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/lib/thrift/metrics.rb +72 -0
- data/lib/thrift/server/rack_application.rb +0 -1
- data/spec/rack_application_spec.rb +77 -0
- data/spec/thin_http_server_spec.rb +3 -58
- metadata +20 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fe3d3897cc33f528a63422abebca6ec7f5190266
|
4
|
+
data.tar.gz: 7f4bb8c724ceac70785300bd0ac3b410022b6a81
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e029c7b2d81786f06c1e9d7e6fafe239fa3b94c43d5deb0f8b8d174ca05be934723f19a8d68b8a1cf08b69db1cd3fbea74842fb24f4de35b670bc9fc62e0ff55
|
7
|
+
data.tar.gz: 1acdcde96fe884a99f41ba8e4b293d1b52132d7e9c959c31e673216b9f94cc59d84256ca2cfb765310ade87761d35e6c8fb029f24d801d5fec160ae0d9ff4f4b
|
@@ -0,0 +1,72 @@
|
|
1
|
+
require 'statsd'
|
2
|
+
|
3
|
+
class NullStatsd
|
4
|
+
def method_missing(*)
|
5
|
+
end
|
6
|
+
end
|
7
|
+
|
8
|
+
module Thrift
|
9
|
+
module Metrics
|
10
|
+
module Middleware
|
11
|
+
class Timing
|
12
|
+
class << self
|
13
|
+
def send_duration(name, t0)
|
14
|
+
Metrics.client.timing(
|
15
|
+
"#{name}.duration",
|
16
|
+
((Time.now - t0) * 1_000).to_i
|
17
|
+
)
|
18
|
+
end
|
19
|
+
|
20
|
+
def instrument(name, &block)
|
21
|
+
t0 = Time.now
|
22
|
+
|
23
|
+
begin
|
24
|
+
r = block.call
|
25
|
+
send_duration name, t0
|
26
|
+
r
|
27
|
+
rescue => e
|
28
|
+
send_duration name, t0
|
29
|
+
raise e
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
class Exception
|
36
|
+
class << self
|
37
|
+
def instrument(name, &block)
|
38
|
+
begin
|
39
|
+
r = block.call
|
40
|
+
Metrics.client.increment("#{name}.success")
|
41
|
+
r
|
42
|
+
rescue => e
|
43
|
+
Metrics.client.increment("#{name}.exceptions.#{e.class.name.downcase}")
|
44
|
+
raise e
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
MIDDLEWARES = [Middleware::Timing, Middleware::Exception]
|
52
|
+
|
53
|
+
class << self
|
54
|
+
def instrument(name, &block)
|
55
|
+
MIDDLEWARES.reduce(block) do |acc, cur|
|
56
|
+
Proc.new { cur.instrument(name) { acc.call } }
|
57
|
+
end.call
|
58
|
+
end
|
59
|
+
|
60
|
+
def client
|
61
|
+
@client ||= begin
|
62
|
+
if ENV['STATSD_URL']
|
63
|
+
ip, port = ENV['STATSD_URL'].split(':')
|
64
|
+
Statsd.new ip, port.to_i
|
65
|
+
else
|
66
|
+
NullStatsd.new
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
#
|
2
|
+
# Licensed to the Apache Software Foundation (ASF) under one
|
3
|
+
# or more contributor license agreements. See the NOTICE file
|
4
|
+
# distributed with this work for additional information
|
5
|
+
# regarding copyright ownership. The ASF licenses this file
|
6
|
+
# to you under the Apache License, Version 2.0 (the
|
7
|
+
# "License"); you may not use this file except in compliance
|
8
|
+
# with the License. You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing,
|
13
|
+
# software distributed under the License is distributed on an
|
14
|
+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
15
|
+
# KIND, either express or implied. See the License for the
|
16
|
+
# specific language governing permissions and limitations
|
17
|
+
# under the License.
|
18
|
+
#
|
19
|
+
|
20
|
+
require 'spec_helper'
|
21
|
+
require 'rack/test'
|
22
|
+
require 'thrift/server/thin_http_server'
|
23
|
+
require 'thrift/server/rack_application'
|
24
|
+
|
25
|
+
describe Thrift::RackApplication do
|
26
|
+
include Rack::Test::Methods
|
27
|
+
|
28
|
+
let(:processor) { mock('processor') }
|
29
|
+
let(:protocol_factory) { mock('protocol factory') }
|
30
|
+
|
31
|
+
def app
|
32
|
+
Thrift::RackApplication.for("/", processor, protocol_factory)
|
33
|
+
end
|
34
|
+
|
35
|
+
context "404 response" do
|
36
|
+
|
37
|
+
it 'receives a non-POST' do
|
38
|
+
header('Content-Type', "application/x-thrift")
|
39
|
+
get "/"
|
40
|
+
last_response.status.should be 404
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'receives a header other than application/x-thrift' do
|
44
|
+
header('Content-Type', "application/json")
|
45
|
+
post "/"
|
46
|
+
last_response.status.should be 404
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
|
51
|
+
context "200 response" do
|
52
|
+
|
53
|
+
before do
|
54
|
+
protocol_factory.stub(:get_protocol)
|
55
|
+
processor.stub(:process)
|
56
|
+
end
|
57
|
+
|
58
|
+
it 'creates an IOStreamTransport' do
|
59
|
+
header('Content-Type', "application/x-thrift")
|
60
|
+
Thrift::IOStreamTransport.should_receive(:new).with(an_instance_of(Rack::Lint::InputWrapper), an_instance_of(Rack::Response))
|
61
|
+
post "/"
|
62
|
+
end
|
63
|
+
|
64
|
+
it 'fetches the right protocol based on the Transport' do
|
65
|
+
header('Content-Type', "application/x-thrift")
|
66
|
+
protocol_factory.should_receive(:get_protocol).with(an_instance_of(Thrift::IOStreamTransport))
|
67
|
+
post "/"
|
68
|
+
end
|
69
|
+
|
70
|
+
it 'status code 200' do
|
71
|
+
header('Content-Type', "application/x-thrift")
|
72
|
+
post "/"
|
73
|
+
last_response.ok?.should be_true
|
74
|
+
end
|
75
|
+
|
76
|
+
end
|
77
|
+
end
|
@@ -20,6 +20,7 @@
|
|
20
20
|
require 'spec_helper'
|
21
21
|
require 'rack/test'
|
22
22
|
require 'thrift/server/thin_http_server'
|
23
|
+
require 'thrift/server/rack_application'
|
23
24
|
|
24
25
|
describe Thrift::ThinHTTPServer do
|
25
26
|
|
@@ -35,7 +36,7 @@ describe Thrift::ThinHTTPServer do
|
|
35
36
|
end
|
36
37
|
|
37
38
|
it 'creates a ThinHTTPServer::RackApplicationContext' do
|
38
|
-
Thrift::
|
39
|
+
Thrift::RackApplication.should_receive(:for).with("/", processor, an_instance_of(Thrift::BinaryProtocolFactory)).and_return(anything)
|
39
40
|
Thrift::ThinHTTPServer.new(processor)
|
40
41
|
end
|
41
42
|
|
@@ -60,7 +61,7 @@ describe Thrift::ThinHTTPServer do
|
|
60
61
|
end
|
61
62
|
|
62
63
|
it 'creates a ThinHTTPServer::RackApplicationContext with a different protocol factory' do
|
63
|
-
Thrift::
|
64
|
+
Thrift::RackApplication.should_receive(:for).with("/", processor, an_instance_of(Thrift::JsonProtocolFactory)).and_return(anything)
|
64
65
|
Thrift::ThinHTTPServer.new(processor,
|
65
66
|
:protocol_factory => Thrift::JsonProtocolFactory.new)
|
66
67
|
end
|
@@ -83,59 +84,3 @@ describe Thrift::ThinHTTPServer do
|
|
83
84
|
end
|
84
85
|
|
85
86
|
end
|
86
|
-
|
87
|
-
describe Thrift::ThinHTTPServer::RackApplication do
|
88
|
-
include Rack::Test::Methods
|
89
|
-
|
90
|
-
let(:processor) { mock('processor') }
|
91
|
-
let(:protocol_factory) { mock('protocol factory') }
|
92
|
-
|
93
|
-
def app
|
94
|
-
Thrift::ThinHTTPServer::RackApplication.for("/", processor, protocol_factory)
|
95
|
-
end
|
96
|
-
|
97
|
-
context "404 response" do
|
98
|
-
|
99
|
-
it 'receives a non-POST' do
|
100
|
-
header('Content-Type', "application/x-thrift")
|
101
|
-
get "/"
|
102
|
-
last_response.status.should be 404
|
103
|
-
end
|
104
|
-
|
105
|
-
it 'receives a header other than application/x-thrift' do
|
106
|
-
header('Content-Type', "application/json")
|
107
|
-
post "/"
|
108
|
-
last_response.status.should be 404
|
109
|
-
end
|
110
|
-
|
111
|
-
end
|
112
|
-
|
113
|
-
context "200 response" do
|
114
|
-
|
115
|
-
before do
|
116
|
-
protocol_factory.stub(:get_protocol)
|
117
|
-
processor.stub(:process)
|
118
|
-
end
|
119
|
-
|
120
|
-
it 'creates an IOStreamTransport' do
|
121
|
-
header('Content-Type', "application/x-thrift")
|
122
|
-
Thrift::IOStreamTransport.should_receive(:new).with(an_instance_of(Rack::Lint::InputWrapper), an_instance_of(Rack::Response))
|
123
|
-
post "/"
|
124
|
-
end
|
125
|
-
|
126
|
-
it 'fetches the right protocol based on the Transport' do
|
127
|
-
header('Content-Type', "application/x-thrift")
|
128
|
-
protocol_factory.should_receive(:get_protocol).with(an_instance_of(Thrift::IOStreamTransport))
|
129
|
-
post "/"
|
130
|
-
end
|
131
|
-
|
132
|
-
it 'status code 200' do
|
133
|
-
header('Content-Type', "application/x-thrift")
|
134
|
-
post "/"
|
135
|
-
last_response.ok?.should be_true
|
136
|
-
end
|
137
|
-
|
138
|
-
end
|
139
|
-
|
140
|
-
end
|
141
|
-
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: upfluence-thrift
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Thrift Developers
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-06-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -94,6 +94,20 @@ dependencies:
|
|
94
94
|
- - ">="
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: statsd-ruby
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :runtime
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
97
111
|
description: Ruby bindings for the Apache Thrift RPC system
|
98
112
|
email:
|
99
113
|
- dev@thrift.apache.org
|
@@ -125,6 +139,7 @@ extra_rdoc_files:
|
|
125
139
|
- lib/thrift/core_ext/fixnum.rb
|
126
140
|
- lib/thrift/core_ext.rb
|
127
141
|
- lib/thrift/exceptions.rb
|
142
|
+
- lib/thrift/metrics.rb
|
128
143
|
- lib/thrift/multiplexed_processor.rb
|
129
144
|
- lib/thrift/processor.rb
|
130
145
|
- lib/thrift/protocol/base_protocol.rb
|
@@ -195,6 +210,7 @@ files:
|
|
195
210
|
- lib/thrift/core_ext.rb
|
196
211
|
- lib/thrift/core_ext/fixnum.rb
|
197
212
|
- lib/thrift/exceptions.rb
|
213
|
+
- lib/thrift/metrics.rb
|
198
214
|
- lib/thrift/multiplexed_processor.rb
|
199
215
|
- lib/thrift/processor.rb
|
200
216
|
- lib/thrift/protocol/base_protocol.rb
|
@@ -269,6 +285,7 @@ files:
|
|
269
285
|
- spec/namespaced_spec.rb
|
270
286
|
- spec/nonblocking_server_spec.rb
|
271
287
|
- spec/processor_spec.rb
|
288
|
+
- spec/rack_application_spec.rb
|
272
289
|
- spec/serializer_spec.rb
|
273
290
|
- spec/server_socket_spec.rb
|
274
291
|
- spec/server_spec.rb
|
@@ -363,6 +380,7 @@ test_files:
|
|
363
380
|
- spec/namespaced_spec.rb
|
364
381
|
- spec/nonblocking_server_spec.rb
|
365
382
|
- spec/processor_spec.rb
|
383
|
+
- spec/rack_application_spec.rb
|
366
384
|
- spec/Referenced.thrift
|
367
385
|
- spec/serializer_spec.rb
|
368
386
|
- spec/server_socket_spec.rb
|