gruf 2.0.3 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f730b985ec9be1cdbe0ad8333a6b4e0bdf63e91c
4
- data.tar.gz: 4279e2c4c19621269c876984b050cd2b1b5556ad
3
+ metadata.gz: 0c2a05e3aed4e246d1e0de691d1b9ee25fe33efd
4
+ data.tar.gz: a829923c5dd79579525e2034e6b3dabc995f1b20
5
5
  SHA512:
6
- metadata.gz: eed32a217e3e649c51944b0b12cc4b3ae7ae7b8a37acbbd3bf6963aa54acdb78d17a2136527541423936474b914347dc40b5fb181ba7cbd643a5b6eda1e8e6ad
7
- data.tar.gz: 59fa0142e79caad40ebbc00b14a9f18fa6b3d00bfe74ae66259a621e9f0eeee4e622dc9d928fcb85594c7468a2977d2993439d8fe57c2f617dfbd8b5569a0f29
6
+ metadata.gz: ada2953033d6ca5850c35f5f63a59e86489d1c55bd909e72c73d155c7348f32bffc3168531bcc00f548c06f3f75ea480616b5a20370fb3f3708c12d3f5cb5b9e
7
+ data.tar.gz: 317a912622dc017fc6568bb66aeace92a620175f2cb6e99047f320777b4b9b7f805ef1ce39039650d6b0074a105b0da460c354b5a22f33a6c9eb2cf97bb13e02
data/CHANGELOG.md CHANGED
@@ -2,6 +2,14 @@ Changelog for the gruf gem. This includes internal history before the gem was ma
2
2
 
3
3
  ### Pending release
4
4
 
5
+ ### 2.1.0
6
+
7
+ - Add ability to list, clear, insert before, insert after, and remove to a server's interceptor
8
+ registry
9
+ - Ensure interceptors and services cannot be adjusted on the server after it starts to
10
+ prevent threading issues
11
+ - [#36], [#37] Adds `response_class`, `request_class`, and `service` accessors to controller request
12
+
5
13
  ### 2.0.3
6
14
 
7
15
  - Fix regression [#35] where gruf was not able to be loaded outside of a Rails application
data/README.md CHANGED
@@ -17,7 +17,7 @@ up fast and efficiently at scale. Some of its features include:
17
17
  still preserving gRPC BadStatus codes
18
18
  * Server and client execution timings in responses
19
19
 
20
- gruf currently has active support for gRPC 1.4.x-1.6.x. gruf is compatible and tested with Ruby 2.2,
20
+ gruf currently has active support for gRPC 1.4.x-1.8.x. gruf is compatible and tested with Ruby 2.2,
21
21
  2.3, and 2.4. gruf is also not [Rails](https://github.com/rails/rails)-specific, and can be used in any
22
22
  Ruby framework (such as [Grape](https://github.com/ruby-grape/grape), for instance).
23
23
 
@@ -239,6 +239,10 @@ Gruf.configure do |c|
239
239
  end
240
240
  ```
241
241
 
242
+ By default, the ActiveRecord Connection Reset interceptor and Output Metadata Timing interceptor
243
+ are loaded into gruf unless explicitly told not to via the `use_default_interceptors` configuration
244
+ parameter.
245
+
242
246
  ## Instrumentation
243
247
 
244
248
  gruf comes out of the box with a couple of instrumentation interceptors packed in:
@@ -323,6 +327,7 @@ view and clone that shows how to integrate Gruf into an existing Rails applicati
323
327
  ### Gruf 3.0
324
328
 
325
329
  * Utilize the new core Ruby interceptors in gRPC 1.7
330
+ * Support client interceptors
326
331
  * Change configuration to an injectable object to ensure thread safety on chained server/client interactions
327
332
  * Move all references to `Gruf.` configuration into injectable parameters
328
333
  * Redo server configuration to be fully injectable
@@ -27,6 +27,8 @@ module Gruf
27
27
  attr_reader :method_key
28
28
  # @var [Gruf::Controllers::Request::Type] type
29
29
  attr_reader :type
30
+ # @var [Class] service
31
+ attr_reader :service
30
32
 
31
33
  delegate :metadata, to: :active_call
32
34
  delegate :messages, :client_streamer?, :server_streamer?, :bidi_streamer?, :request_response?, to: :type
@@ -54,6 +56,7 @@ module Gruf
54
56
  @service = service
55
57
  @active_call = active_call
56
58
  @message = message
59
+ @rpc_desc = rpc_desc
57
60
  @type = Type.new(rpc_desc)
58
61
  end
59
62
 
@@ -67,6 +70,20 @@ module Gruf
67
70
  @service.name.underscore.tr('/', '.').gsub('.service', '')
68
71
  end
69
72
 
73
+ ##
74
+ # @return [Class]
75
+ #
76
+ def response_class
77
+ @rpc_desc.output
78
+ end
79
+
80
+ ##
81
+ # @return [Class]
82
+ #
83
+ def request_class
84
+ @rpc_desc.input
85
+ end
86
+
70
87
  ##
71
88
  # Parse the method signature into a service.method name format
72
89
  #
@@ -28,7 +28,7 @@ module Gruf
28
28
  ##
29
29
  # Add an interceptor to the registry
30
30
  #
31
- # @param [Gruf::Interceptors::Base] interceptor_class The class of the interceptor to add
31
+ # @param [Class] interceptor_class The class of the interceptor to add
32
32
  # @param [Hash] options A hash of options to pass into the interceptor during initialization
33
33
  #
34
34
  def use(interceptor_class, options = {})
@@ -40,12 +40,25 @@ module Gruf
40
40
  end
41
41
  end
42
42
 
43
+ ##
44
+ # Remove an interceptor from the registry
45
+ #
46
+ # @param [Class] interceptor_class The interceptor class to remove
47
+ # @raise [InterceptorNotFoundError] if the interceptor is not found
48
+ #
49
+ def remove(interceptor_class)
50
+ pos = @registry.find_index { |opts| opts.fetch(:klass, '') == interceptor_class }
51
+ raise InterceptorNotFoundError if pos.nil?
52
+ @registry.delete_at(pos)
53
+ end
54
+
43
55
  ##
44
56
  # Insert an interceptor before another specified interceptor
45
57
  #
46
- # @param [Gruf::Interceptors::Base] before_class The interceptor to insert before
47
- # @param [Gruf::Interceptors::Base] interceptor_class The class of the interceptor to add
58
+ # @param [Class] before_class The interceptor to insert before
59
+ # @param [Class] interceptor_class The class of the interceptor to add
48
60
  # @param [Hash] options A hash of options to pass into the interceptor during initialization
61
+ # @raise [InterceptorNotFoundError] if the before interceptor is not found
49
62
  #
50
63
  def insert_before(before_class, interceptor_class, options = {})
51
64
  interceptors_mutex do
@@ -62,9 +75,10 @@ module Gruf
62
75
  ##
63
76
  # Insert an interceptor after another specified interceptor
64
77
  #
65
- # @param [Gruf::Interceptors::Base] after_class The interceptor to insert after
66
- # @param [Gruf::Interceptors::Base] interceptor_class The class of the interceptor to add
78
+ # @param [Class] after_class The interceptor to insert after
79
+ # @param [Class] interceptor_class The class of the interceptor to add
67
80
  # @param [Hash] options A hash of options to pass into the interceptor during initialization
81
+ # @raise [InterceptorNotFoundError] if the after interceptor is not found
68
82
  #
69
83
  def insert_after(after_class, interceptor_class, options = {})
70
84
  interceptors_mutex do
@@ -78,6 +92,17 @@ module Gruf
78
92
  end
79
93
  end
80
94
 
95
+ ##
96
+ # Return a list of the interceptor classes in the registry in their execution order
97
+ #
98
+ # @return [Array<Class>]
99
+ #
100
+ def list
101
+ interceptors_mutex do
102
+ @registry.map { |h| h[:klass] }
103
+ end
104
+ end
105
+
81
106
  ##
82
107
  # Load and return all interceptors for the given request
83
108
  #
data/lib/gruf/server.rb CHANGED
@@ -19,6 +19,8 @@ module Gruf
19
19
  # based on configuration values.
20
20
  #
21
21
  class Server
22
+ class ServerAlreadyStartedError < StandardError; end
23
+
22
24
  include Gruf::Loggable
23
25
 
24
26
  # @return [Integer] The port the server is bound to
@@ -36,6 +38,7 @@ module Gruf
36
38
  @interceptors = options.fetch(:interceptor_registry, Gruf.interceptors)
37
39
  @interceptors = Gruf::Interceptors::Registry.new unless @interceptors.is_a?(Gruf::Interceptors::Registry)
38
40
  @services = []
41
+ @started = false
39
42
  setup!
40
43
  end
41
44
 
@@ -58,9 +61,11 @@ module Gruf
58
61
  # rubocop:disable Lint/ShadowedException
59
62
  def start!
60
63
  logger.info { 'Booting gRPC Server...' }
64
+ @started = true
61
65
  server.run_till_terminated
62
66
  rescue Interrupt, SignalException, SystemExit
63
67
  logger.info { 'Shutting down gRPC server...' }
68
+ @started = false
64
69
  server.stop
65
70
  end
66
71
  # :nocov:
@@ -68,21 +73,70 @@ module Gruf
68
73
 
69
74
  ##
70
75
  # @param [Class] klass
76
+ # @raise [ServerAlreadyStartedError] if the server is already started
71
77
  #
72
78
  def add_service(klass)
79
+ raise ServerAlreadyStartedError if @started
73
80
  @services << klass unless @services.include?(klass)
74
81
  end
75
82
 
76
83
  ##
77
84
  # Add an interceptor to the server
78
85
  #
79
- # @param [Gruf::Interceptors::Base]
80
- # @param [Hash]
86
+ # @param [Class] klass The Interceptor to add to the registry
87
+ # @param [Hash] opts A hash of options for the interceptor
88
+ # @raise [ServerAlreadyStartedError] if the server is already started
81
89
  #
82
90
  def add_interceptor(klass, opts = {})
91
+ raise ServerAlreadyStartedError if @started
83
92
  @interceptors.use(klass, opts)
84
93
  end
85
94
 
95
+ ##
96
+ # @param [Class] before_class The interceptor that you want to add the new interceptor before
97
+ # @param [Class] interceptor_class The Interceptor to add to the registry
98
+ # @param [Hash] options A hash of options for the interceptor
99
+ #
100
+ def insert_interceptor_before(before_class, interceptor_class, options = {})
101
+ raise ServerAlreadyStartedError if @started
102
+ @interceptors.insert_before(before_class, interceptor_class, options)
103
+ end
104
+
105
+ ##
106
+ # @param [Class] after_class The interceptor that you want to add the new interceptor after
107
+ # @param [Class] interceptor_class The Interceptor to add to the registry
108
+ # @param [Hash] options A hash of options for the interceptor
109
+ #
110
+ def insert_interceptor_after(after_class, interceptor_class, options = {})
111
+ raise ServerAlreadyStartedError if @started
112
+ @interceptors.insert_after(after_class, interceptor_class, options)
113
+ end
114
+
115
+ ##
116
+ # Return the current list of added interceptor classes
117
+ #
118
+ # @return [Array<Class>]
119
+ #
120
+ def list_interceptors
121
+ @interceptors.list
122
+ end
123
+
124
+ ##
125
+ # Remove an interceptor from the server
126
+ #
127
+ def remove_interceptor(klass)
128
+ raise ServerAlreadyStartedError if @started
129
+ @interceptors.remove(klass)
130
+ end
131
+
132
+ ##
133
+ # Clear the interceptor registry of interceptors
134
+ #
135
+ def clear_interceptors
136
+ raise ServerAlreadyStartedError if @started
137
+ @interceptors.clear
138
+ end
139
+
86
140
  private
87
141
 
88
142
  ##
data/lib/gruf/version.rb CHANGED
@@ -14,5 +14,5 @@
14
14
  # OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
15
15
  #
16
16
  module Gruf
17
- VERSION = '2.0.3'.freeze
17
+ VERSION = '2.1.0'.freeze
18
18
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gruf
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.3
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shaun McCormick
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-12-07 00:00:00.000000000 Z
11
+ date: 2017-12-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -158,7 +158,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
158
158
  version: '0'
159
159
  requirements: []
160
160
  rubyforge_project:
161
- rubygems_version: 2.6.14
161
+ rubygems_version: 2.6.12
162
162
  signing_key:
163
163
  specification_version: 4
164
164
  summary: gRPC Ruby Framework