tonic-rails 0.5.0 → 0.7.0
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 +44 -1
- data/Cargo.lock +69 -1
- data/README.md +265 -0
- data/ext/tonic_rails_native/Cargo.toml +7 -1
- data/ext/tonic_rails_native/src/body.rs +1 -40
- data/ext/tonic_rails_native/src/client.rs +665 -0
- data/ext/tonic_rails_native/src/dispatch.rs +10 -3
- data/ext/tonic_rails_native/src/gvl.rs +22 -7
- data/ext/tonic_rails_native/src/lib.rs +14 -0
- data/lib/tonic/rails/base.rb +4 -1
- data/lib/tonic/rails/client/retry_policy.rb +73 -0
- data/lib/tonic/rails/client.rb +460 -0
- data/lib/tonic/rails/instrumentation.rb +21 -5
- data/lib/tonic/rails/rpc_error.rb +61 -0
- data/lib/tonic/rails/version.rb +1 -1
- data/lib/tonic-rails.rb +1 -0
- metadata +4 -1
|
@@ -19,6 +19,8 @@ module Tonic
|
|
|
19
19
|
# The message, metadata and details go to the client, so keep internal
|
|
20
20
|
# details out of them. Any other exception becomes INTERNAL with a
|
|
21
21
|
# generic message and is logged server-side.
|
|
22
|
+
#
|
|
23
|
+
# Tonic::Rails::Client raises it too, for calls that fail.
|
|
22
24
|
class RpcError < Error
|
|
23
25
|
CODES = {
|
|
24
26
|
ok: 0,
|
|
@@ -114,6 +116,65 @@ module Tonic
|
|
|
114
116
|
CODE_NAMES.fetch(@code)
|
|
115
117
|
end
|
|
116
118
|
|
|
119
|
+
# Unpacks the details of an encoded google.rpc.Status (from the
|
|
120
|
+
# grpc-status-details-bin trailer). Details whose message type is
|
|
121
|
+
# loaded come back as that message; others stay Google::Protobuf::Any.
|
|
122
|
+
# @api private
|
|
123
|
+
# @return [Array<Google::Protobuf::AbstractMessage>]
|
|
124
|
+
def self.decode_details(bytes)
|
|
125
|
+
return [] if bytes.nil? || bytes.empty?
|
|
126
|
+
|
|
127
|
+
require "google/protobuf/well_known_types"
|
|
128
|
+
details = []
|
|
129
|
+
each_length_delimited_field(bytes.b) do |field, value|
|
|
130
|
+
details << unpack_detail(Google::Protobuf::Any.decode(value)) if field == 3
|
|
131
|
+
end
|
|
132
|
+
details
|
|
133
|
+
rescue Google::Protobuf::ParseError, ArgumentError
|
|
134
|
+
[]
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
# Yields (field number, bytes) for each length-delimited field,
|
|
138
|
+
# skipping varints; raises ArgumentError on anything malformed.
|
|
139
|
+
def self.each_length_delimited_field(buf)
|
|
140
|
+
pos = 0
|
|
141
|
+
while pos < buf.bytesize
|
|
142
|
+
key, pos = read_varint(buf, pos)
|
|
143
|
+
case key & 7
|
|
144
|
+
when 0 then _, pos = read_varint(buf, pos)
|
|
145
|
+
when 2
|
|
146
|
+
length, pos = read_varint(buf, pos)
|
|
147
|
+
raise ArgumentError, "truncated google.rpc.Status" if pos + length > buf.bytesize
|
|
148
|
+
|
|
149
|
+
yield key >> 3, buf.byteslice(pos, length)
|
|
150
|
+
pos += length
|
|
151
|
+
else raise ArgumentError, "unexpected wire type in google.rpc.Status"
|
|
152
|
+
end
|
|
153
|
+
end
|
|
154
|
+
end
|
|
155
|
+
private_class_method :each_length_delimited_field
|
|
156
|
+
|
|
157
|
+
def self.read_varint(buf, pos)
|
|
158
|
+
value = 0
|
|
159
|
+
shift = 0
|
|
160
|
+
loop do
|
|
161
|
+
byte = buf.getbyte(pos) or raise ArgumentError, "truncated varint"
|
|
162
|
+
pos += 1
|
|
163
|
+
value |= (byte & 0x7f) << shift
|
|
164
|
+
return [value, pos] if byte < 0x80
|
|
165
|
+
|
|
166
|
+
shift += 7
|
|
167
|
+
raise ArgumentError, "varint too long" if shift > 63
|
|
168
|
+
end
|
|
169
|
+
end
|
|
170
|
+
private_class_method :read_varint
|
|
171
|
+
|
|
172
|
+
def self.unpack_detail(any)
|
|
173
|
+
type = Google::Protobuf::DescriptorPool.generated_pool.lookup(any.type_name)
|
|
174
|
+
type.is_a?(Google::Protobuf::Descriptor) ? any.unpack(type.msgclass) : any
|
|
175
|
+
end
|
|
176
|
+
private_class_method :unpack_detail
|
|
177
|
+
|
|
117
178
|
# @api private
|
|
118
179
|
def self.normalize_code(code)
|
|
119
180
|
case code
|
data/lib/tonic/rails/version.rb
CHANGED
data/lib/tonic-rails.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: tonic-rails
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.7.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Matt Tanous
|
|
@@ -73,6 +73,7 @@ files:
|
|
|
73
73
|
- ext/tonic_rails_native/Cargo.toml
|
|
74
74
|
- ext/tonic_rails_native/extconf.rb
|
|
75
75
|
- ext/tonic_rails_native/src/body.rs
|
|
76
|
+
- ext/tonic_rails_native/src/client.rs
|
|
76
77
|
- ext/tonic_rails_native/src/dispatch.rs
|
|
77
78
|
- ext/tonic_rails_native/src/framing.rs
|
|
78
79
|
- ext/tonic_rails_native/src/gvl.rs
|
|
@@ -90,6 +91,8 @@ files:
|
|
|
90
91
|
- lib/puma/plugin/tonic_rails.rb
|
|
91
92
|
- lib/tonic-rails.rb
|
|
92
93
|
- lib/tonic/rails/base.rb
|
|
94
|
+
- lib/tonic/rails/client.rb
|
|
95
|
+
- lib/tonic/rails/client/retry_policy.rb
|
|
93
96
|
- lib/tonic/rails/cluster.rb
|
|
94
97
|
- lib/tonic/rails/configuration.rb
|
|
95
98
|
- lib/tonic/rails/health.rb
|