grpcx 0.2.0 → 0.3.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/.rubocop.yml +2 -6
- data/Gemfile.lock +41 -41
- data/README.md +3 -29
- data/grpcx.gemspec +2 -2
- data/lib/grpcx/entity.rb +2 -2
- data/lib/grpcx/server.rb +1 -1
- data/lib/grpcx/server/interceptors/active_record.rb +0 -2
- data/lib/grpcx/server/interceptors/instrumentation.rb +4 -5
- data/lib/grpcx/server/interceptors/rescue.rb +9 -10
- data/spec/lib/entity_spec.rb +8 -10
- data/spec/lib/server_spec.rb +0 -2
- data/spec/spec_helper.rb +10 -10
- metadata +4 -5
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 66a39ca3d81a4f36e3ec546252755dc6c8f5a93e77dee26824b935260ced5973
|
|
4
|
+
data.tar.gz: f26e9038ee971c5bd1fcde6be56fc0b19c37e3a195a8474800f5395c18ee0878
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: c90478efde02ea7793cb23a884d3e99ffe4692ed938299da1d391664e18116c3f5c4d938100d9ca0fdd1e56925bd10aba47b3d986b2f0cdb1f93bcef67457c1f
|
|
7
|
+
data.tar.gz: 5c29233c1760993563acc0875792d669505ebd5e18ea4443e441ba807dacd59b5418fa7573834694607abbdddf55b8da1192f40158894e39359dfceea0c593af
|
data/.rubocop.yml
CHANGED
data/Gemfile.lock
CHANGED
|
@@ -1,70 +1,70 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
grpcx (0.
|
|
4
|
+
grpcx (0.3.0)
|
|
5
5
|
activesupport (>= 5.0)
|
|
6
6
|
grpc (>= 1.8.0)
|
|
7
7
|
|
|
8
8
|
GEM
|
|
9
9
|
remote: https://rubygems.org/
|
|
10
10
|
specs:
|
|
11
|
-
activemodel (
|
|
12
|
-
activesupport (=
|
|
13
|
-
activerecord (
|
|
14
|
-
activemodel (=
|
|
15
|
-
activesupport (=
|
|
16
|
-
|
|
17
|
-
activesupport (5.2.1)
|
|
11
|
+
activemodel (6.0.2.1)
|
|
12
|
+
activesupport (= 6.0.2.1)
|
|
13
|
+
activerecord (6.0.2.1)
|
|
14
|
+
activemodel (= 6.0.2.1)
|
|
15
|
+
activesupport (= 6.0.2.1)
|
|
16
|
+
activesupport (6.0.2.1)
|
|
18
17
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
|
19
18
|
i18n (>= 0.7, < 2)
|
|
20
19
|
minitest (~> 5.1)
|
|
21
20
|
tzinfo (~> 1.1)
|
|
22
|
-
|
|
21
|
+
zeitwerk (~> 2.2)
|
|
23
22
|
ast (2.4.0)
|
|
24
|
-
concurrent-ruby (1.
|
|
23
|
+
concurrent-ruby (1.1.6)
|
|
25
24
|
diff-lcs (1.3)
|
|
26
|
-
google-protobuf (3.
|
|
27
|
-
googleapis-common-protos-types (1.0.
|
|
25
|
+
google-protobuf (3.11.4)
|
|
26
|
+
googleapis-common-protos-types (1.0.4)
|
|
28
27
|
google-protobuf (~> 3.0)
|
|
29
|
-
grpc (1.
|
|
30
|
-
google-protobuf (~> 3.
|
|
31
|
-
googleapis-common-protos-types (~> 1.0
|
|
32
|
-
i18n (1.
|
|
28
|
+
grpc (1.27.0)
|
|
29
|
+
google-protobuf (~> 3.11)
|
|
30
|
+
googleapis-common-protos-types (~> 1.0)
|
|
31
|
+
i18n (1.8.2)
|
|
33
32
|
concurrent-ruby (~> 1.0)
|
|
34
|
-
jaro_winkler (1.5.
|
|
35
|
-
minitest (5.
|
|
36
|
-
parallel (1.
|
|
37
|
-
parser (2.
|
|
33
|
+
jaro_winkler (1.5.4)
|
|
34
|
+
minitest (5.14.0)
|
|
35
|
+
parallel (1.19.1)
|
|
36
|
+
parser (2.7.0.4)
|
|
38
37
|
ast (~> 2.4.0)
|
|
39
|
-
powerpack (0.1.2)
|
|
40
38
|
rainbow (3.0.0)
|
|
41
|
-
rake (
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
rspec-
|
|
45
|
-
rspec-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
39
|
+
rake (13.0.1)
|
|
40
|
+
rexml (3.2.4)
|
|
41
|
+
rspec (3.9.0)
|
|
42
|
+
rspec-core (~> 3.9.0)
|
|
43
|
+
rspec-expectations (~> 3.9.0)
|
|
44
|
+
rspec-mocks (~> 3.9.0)
|
|
45
|
+
rspec-core (3.9.1)
|
|
46
|
+
rspec-support (~> 3.9.1)
|
|
47
|
+
rspec-expectations (3.9.0)
|
|
49
48
|
diff-lcs (>= 1.2.0, < 2.0)
|
|
50
|
-
rspec-support (~> 3.
|
|
51
|
-
rspec-mocks (3.
|
|
49
|
+
rspec-support (~> 3.9.0)
|
|
50
|
+
rspec-mocks (3.9.1)
|
|
52
51
|
diff-lcs (>= 1.2.0, < 2.0)
|
|
53
|
-
rspec-support (~> 3.
|
|
54
|
-
rspec-support (3.
|
|
55
|
-
rubocop (0.
|
|
52
|
+
rspec-support (~> 3.9.0)
|
|
53
|
+
rspec-support (3.9.2)
|
|
54
|
+
rubocop (0.80.1)
|
|
56
55
|
jaro_winkler (~> 1.5.1)
|
|
57
56
|
parallel (~> 1.10)
|
|
58
|
-
parser (>= 2.
|
|
59
|
-
powerpack (~> 0.1)
|
|
57
|
+
parser (>= 2.7.0.1)
|
|
60
58
|
rainbow (>= 2.2.2, < 4.0)
|
|
59
|
+
rexml
|
|
61
60
|
ruby-progressbar (~> 1.7)
|
|
62
|
-
unicode-display_width (
|
|
63
|
-
ruby-progressbar (1.10.
|
|
61
|
+
unicode-display_width (>= 1.4.0, < 1.7)
|
|
62
|
+
ruby-progressbar (1.10.1)
|
|
64
63
|
thread_safe (0.3.6)
|
|
65
|
-
tzinfo (1.2.
|
|
64
|
+
tzinfo (1.2.6)
|
|
66
65
|
thread_safe (~> 0.1)
|
|
67
|
-
unicode-display_width (1.
|
|
66
|
+
unicode-display_width (1.6.1)
|
|
67
|
+
zeitwerk (2.3.0)
|
|
68
68
|
|
|
69
69
|
PLATFORMS
|
|
70
70
|
ruby
|
|
@@ -78,4 +78,4 @@ DEPENDENCIES
|
|
|
78
78
|
rubocop
|
|
79
79
|
|
|
80
80
|
BUNDLED WITH
|
|
81
|
-
1.
|
|
81
|
+
2.1.4
|
data/README.md
CHANGED
|
@@ -50,37 +50,11 @@ end
|
|
|
50
50
|
|
|
51
51
|
## Using with [Datadog::Notifications](https://github.com/bsm/datadog-notifications)
|
|
52
52
|
|
|
53
|
-
|
|
54
|
-
# TODO: update this in datadog-notifications gem itself (to handle new service/action payloads)
|
|
55
|
-
module Datadog::Notifications::Plugins
|
|
56
|
-
class MyGRPC < Base
|
|
57
|
-
|
|
58
|
-
def initialize(opts={})
|
|
59
|
-
super
|
|
60
|
-
Datadog::Notifications.subscribe(Grpcx::Server::Interceptors::Instrumentation::METRIC_NAME) do |reporter, event|
|
|
61
|
-
record(reporter, event)
|
|
62
|
-
end
|
|
63
|
-
end
|
|
64
|
-
|
|
65
|
-
private
|
|
66
|
-
|
|
67
|
-
def record(reporter, event)
|
|
68
|
-
service = event.payload[:service]
|
|
69
|
-
action = event.payload[:action]
|
|
70
|
-
status = event.payload[:exception] ? 'error' : 'ok'
|
|
71
|
-
tags = self.tags + %W[service:#{service} action:#{action} status:#{status}]
|
|
72
|
-
|
|
73
|
-
reporter.batch do
|
|
74
|
-
reporter.increment 'grpc.request', tags: tags
|
|
75
|
-
reporter.timing 'grpc.request.time', event.duration, tags: tags
|
|
76
|
-
end
|
|
77
|
-
end
|
|
78
|
-
|
|
79
|
-
end
|
|
80
|
-
end
|
|
53
|
+
Since version >= [0.5.4](https://github.com/bsm/datadog-notifications/releases/tag/v0.5.4)
|
|
81
54
|
|
|
55
|
+
```ruby
|
|
82
56
|
Datadog::Notifications.configure do |c|
|
|
83
|
-
c.use Datadog::Notifications::Plugins::
|
|
57
|
+
c.use Datadog::Notifications::Plugins::GRPC
|
|
84
58
|
end if RUNNING_IN_PROD?
|
|
85
59
|
```
|
|
86
60
|
|
data/grpcx.gemspec
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Gem::Specification.new do |s|
|
|
2
2
|
s.name = 'grpcx'
|
|
3
|
-
s.version = '0.
|
|
3
|
+
s.version = '0.3.0'
|
|
4
4
|
s.authors = ['Black Square Media Ltd']
|
|
5
5
|
s.email = ['info@blacksquaremedia.com']
|
|
6
6
|
s.summary = %(gRPC extensions/helpers)
|
|
@@ -11,7 +11,7 @@ Gem::Specification.new do |s|
|
|
|
11
11
|
s.files = `git ls-files -z`.split("\x0").reject {|f| f.match(%r{^spec/}) }
|
|
12
12
|
s.test_files = `git ls-files -z -- spec/*`.split("\x0")
|
|
13
13
|
s.require_paths = ['lib']
|
|
14
|
-
s.required_ruby_version = '>= 2.
|
|
14
|
+
s.required_ruby_version = '>= 2.5'
|
|
15
15
|
|
|
16
16
|
s.add_dependency 'activesupport', '>= 5.0'
|
|
17
17
|
s.add_dependency 'grpc', '>= 1.8.0'
|
data/lib/grpcx/entity.rb
CHANGED
|
@@ -10,11 +10,11 @@ module Grpcx
|
|
|
10
10
|
|
|
11
11
|
module_function
|
|
12
12
|
|
|
13
|
-
TRUE_VALUES = [true, 1,
|
|
13
|
+
TRUE_VALUES = [true, 1, '1', 't', 'T', 'true', 'TRUE', 'on', 'ON'].to_set.freeze
|
|
14
14
|
|
|
15
15
|
# @param [Class] msgclass messagepack message class
|
|
16
16
|
# @param [Hash] attrs attributes to assign
|
|
17
|
-
def build(msgclass, attrs={}) # rubocop:disable Metrics/
|
|
17
|
+
def build(msgclass, attrs = {}) # rubocop:disable Metrics/MethodLength
|
|
18
18
|
attrs = ActiveSupport::HashWithIndifferentAccess.new(attrs)
|
|
19
19
|
fields = {}
|
|
20
20
|
msgclass.descriptor.each do |field| # rubocop:disable Metrics/BlockLength
|
data/lib/grpcx/server.rb
CHANGED
|
@@ -22,7 +22,7 @@ module Grpcx
|
|
|
22
22
|
end
|
|
23
23
|
end
|
|
24
24
|
|
|
25
|
-
def initialize(opts={})
|
|
25
|
+
def initialize(opts = {})
|
|
26
26
|
opts[:pool_size] ||= ENV['GRPC_SERVER_THREADS'].to_i if ENV['GRPC_SERVER_THREADS']
|
|
27
27
|
opts[:max_waiting_requests] ||= ENV['GRPC_SERVER_QUEUE'].to_i if ENV['GRPC_SERVER_QUEUE']
|
|
28
28
|
|
|
@@ -5,7 +5,6 @@ module Grpcx
|
|
|
5
5
|
# making sure that connection is established before each request
|
|
6
6
|
# and re-pooling connections when request is processed.
|
|
7
7
|
class ActiveRecord < GRPC::ServerInterceptor
|
|
8
|
-
|
|
9
8
|
def request_response(*, &block)
|
|
10
9
|
wrap(&block)
|
|
11
10
|
end
|
|
@@ -30,7 +29,6 @@ module Grpcx
|
|
|
30
29
|
ensure
|
|
31
30
|
::ActiveRecord::Base.clear_active_connections!
|
|
32
31
|
end
|
|
33
|
-
|
|
34
32
|
end
|
|
35
33
|
end
|
|
36
34
|
end
|
|
@@ -6,19 +6,19 @@ module Grpcx
|
|
|
6
6
|
class Instrumentation < GRPC::ServerInterceptor
|
|
7
7
|
METRIC_NAME = 'process_action.grpc'.freeze
|
|
8
8
|
|
|
9
|
-
def request_response(opts={}, &block)
|
|
9
|
+
def request_response(opts = {}, &block)
|
|
10
10
|
instrument(opts[:method], &block)
|
|
11
11
|
end
|
|
12
12
|
|
|
13
|
-
def client_streamer(opts={}, &block)
|
|
13
|
+
def client_streamer(opts = {}, &block)
|
|
14
14
|
instrument(opts[:method], &block)
|
|
15
15
|
end
|
|
16
16
|
|
|
17
|
-
def server_streamer(opts={}, &block)
|
|
17
|
+
def server_streamer(opts = {}, &block)
|
|
18
18
|
instrument(opts[:method], &block)
|
|
19
19
|
end
|
|
20
20
|
|
|
21
|
-
def bidi_streamer(opts={}, &block)
|
|
21
|
+
def bidi_streamer(opts = {}, &block)
|
|
22
22
|
instrument(opts[:method], &block)
|
|
23
23
|
end
|
|
24
24
|
|
|
@@ -29,7 +29,6 @@ module Grpcx
|
|
|
29
29
|
action = method.name # does not match real proto service name; it's a GRPC::GenericService.underscore-d version
|
|
30
30
|
ActiveSupport::Notifications.instrument(METRIC_NAME, service: service, action: action, &block)
|
|
31
31
|
end
|
|
32
|
-
|
|
33
32
|
end
|
|
34
33
|
end
|
|
35
34
|
end
|
|
@@ -2,35 +2,34 @@ module Grpcx
|
|
|
2
2
|
module Server
|
|
3
3
|
module Interceptors
|
|
4
4
|
class Rescue < GRPC::ServerInterceptor
|
|
5
|
-
def initialize(rescuable, opts={})
|
|
5
|
+
def initialize(rescuable, opts = {})
|
|
6
6
|
@rescuable = rescuable
|
|
7
7
|
super(opts)
|
|
8
8
|
end
|
|
9
9
|
|
|
10
10
|
def request_response(*)
|
|
11
11
|
yield
|
|
12
|
-
rescue StandardError =>
|
|
13
|
-
@rescuable.rescue_with_handler(
|
|
12
|
+
rescue StandardError => e
|
|
13
|
+
@rescuable.rescue_with_handler(e) || raise
|
|
14
14
|
end
|
|
15
15
|
|
|
16
16
|
def client_streamer(*)
|
|
17
17
|
yield
|
|
18
|
-
rescue StandardError =>
|
|
19
|
-
@rescuable.rescue_with_handler(
|
|
18
|
+
rescue StandardError => e
|
|
19
|
+
@rescuable.rescue_with_handler(e) || raise
|
|
20
20
|
end
|
|
21
21
|
|
|
22
22
|
def server_streamer(*)
|
|
23
23
|
yield
|
|
24
|
-
rescue StandardError =>
|
|
25
|
-
@rescuable.rescue_with_handler(
|
|
24
|
+
rescue StandardError => e
|
|
25
|
+
@rescuable.rescue_with_handler(e) || raise
|
|
26
26
|
end
|
|
27
27
|
|
|
28
28
|
def bidi_streamer(*)
|
|
29
29
|
yield
|
|
30
|
-
rescue StandardError =>
|
|
31
|
-
@rescuable.rescue_with_handler(
|
|
30
|
+
rescue StandardError => e
|
|
31
|
+
@rescuable.rescue_with_handler(e) || raise
|
|
32
32
|
end
|
|
33
|
-
|
|
34
33
|
end
|
|
35
34
|
end
|
|
36
35
|
end
|
data/spec/lib/entity_spec.rb
CHANGED
|
@@ -1,19 +1,18 @@
|
|
|
1
1
|
require 'spec_helper'
|
|
2
2
|
|
|
3
3
|
RSpec.describe Grpcx::Entity do
|
|
4
|
-
|
|
5
4
|
it 'should build messages' do
|
|
6
5
|
msg = described_class.build Grpcx::Spec::Message,
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
6
|
+
name: 'Name',
|
|
7
|
+
version: 1,
|
|
8
|
+
types: {
|
|
9
|
+
num: 8,
|
|
10
|
+
truth: [1, 0, true, 'true'],
|
|
11
|
+
decimal: '1.2',
|
|
12
|
+
}
|
|
14
13
|
|
|
15
14
|
expect(msg.to_h).to eq(
|
|
16
|
-
name:
|
|
15
|
+
name: 'Name',
|
|
17
16
|
version: :V1,
|
|
18
17
|
types: {
|
|
19
18
|
num: 8,
|
|
@@ -22,5 +21,4 @@ RSpec.describe Grpcx::Entity do
|
|
|
22
21
|
},
|
|
23
22
|
)
|
|
24
23
|
end
|
|
25
|
-
|
|
26
24
|
end
|
data/spec/lib/server_spec.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
|
@@ -4,30 +4,30 @@ require 'active_record'
|
|
|
4
4
|
require 'google/protobuf'
|
|
5
5
|
|
|
6
6
|
Google::Protobuf::DescriptorPool.generated_pool.build do
|
|
7
|
-
add_message
|
|
7
|
+
add_message 'grpcx.spec.Message' do
|
|
8
8
|
optional :name, :string, 1
|
|
9
|
-
optional :version, :enum, 2,
|
|
10
|
-
optional :types, :message, 3,
|
|
9
|
+
optional :version, :enum, 2, 'grpcx.spec.Version'
|
|
10
|
+
optional :types, :message, 3, 'grpcx.spec.Types'
|
|
11
11
|
end
|
|
12
|
-
add_message
|
|
12
|
+
add_message 'grpcx.spec.Types' do
|
|
13
13
|
optional :num, :int64, 1
|
|
14
14
|
repeated :truth, :bool, 2
|
|
15
15
|
optional :decimal, :double, 3
|
|
16
16
|
end
|
|
17
|
-
add_enum
|
|
17
|
+
add_enum 'grpcx.spec.Version' do
|
|
18
18
|
value :V0, 0
|
|
19
19
|
value :V1, 1
|
|
20
20
|
value :V2, 2
|
|
21
21
|
end
|
|
22
|
-
add_message
|
|
22
|
+
add_message 'grpcx.spec.GetMessageRequest' do
|
|
23
23
|
end
|
|
24
24
|
end
|
|
25
25
|
|
|
26
26
|
module Grpcx::Spec
|
|
27
|
-
Message = Google::Protobuf::DescriptorPool.generated_pool.lookup(
|
|
28
|
-
Version = Google::Protobuf::DescriptorPool.generated_pool.lookup(
|
|
29
|
-
Types = Google::Protobuf::DescriptorPool.generated_pool.lookup(
|
|
30
|
-
GetMessageRequest = Google::Protobuf::DescriptorPool.generated_pool.lookup(
|
|
27
|
+
Message = Google::Protobuf::DescriptorPool.generated_pool.lookup('grpcx.spec.Message').msgclass
|
|
28
|
+
Version = Google::Protobuf::DescriptorPool.generated_pool.lookup('grpcx.spec.Version').enummodule
|
|
29
|
+
Types = Google::Protobuf::DescriptorPool.generated_pool.lookup('grpcx.spec.Types').msgclass
|
|
30
|
+
GetMessageRequest = Google::Protobuf::DescriptorPool.generated_pool.lookup('grpcx.spec.GetMessageRequest').msgclass
|
|
31
31
|
|
|
32
32
|
module Service
|
|
33
33
|
class V1
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: grpcx
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.3.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Black Square Media Ltd
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2020-03-10 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: activesupport
|
|
@@ -145,15 +145,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
145
145
|
requirements:
|
|
146
146
|
- - ">="
|
|
147
147
|
- !ruby/object:Gem::Version
|
|
148
|
-
version: '2.
|
|
148
|
+
version: '2.5'
|
|
149
149
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
150
150
|
requirements:
|
|
151
151
|
- - ">="
|
|
152
152
|
- !ruby/object:Gem::Version
|
|
153
153
|
version: '0'
|
|
154
154
|
requirements: []
|
|
155
|
-
|
|
156
|
-
rubygems_version: 2.7.6
|
|
155
|
+
rubygems_version: 3.0.6
|
|
157
156
|
signing_key:
|
|
158
157
|
specification_version: 4
|
|
159
158
|
summary: gRPC extensions/helpers
|