gruf 2.9.0 → 2.12.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 77be459526bb01a2e709cb26663e0b2bbdc614eb28de7084a132c14d741fef66
4
- data.tar.gz: b36e8446fd325c42b9c494370b09fd9ecd2364d5a84194683f5d9d81961dd5b2
3
+ metadata.gz: 6fbcc0f1b3083a00fa413c9d16bdb126e04a37f5a1cdee3ae05573698e4deb67
4
+ data.tar.gz: 5327ddd7497e82d991eba1a7ce37e35c62e9810ae5803227563fa4e6ebee31b4
5
5
  SHA512:
6
- metadata.gz: 9d11c575a288e18321aeee6de57b9b9c8a9db09e2c200ce3c5a50d7331e7e1af2975bcba2ae276917e0bf087bbc7c1f0726b4df13d9861bab361c66069a691f9
7
- data.tar.gz: baed74a1e86746ae86314f4fa33065f1b0a3d9ae479c8f288f444444be24e78d76a9f0337cdcfe62b9637d53e6709cf031122cf8728bf709abaa4e6fd79ad788
6
+ metadata.gz: 6ab52c50feb431404c3cbde8b67de6f456b8310ce21a857d9ffcc4b820055773c908d3329a0b965c5b3459583658103f5be7bf3debc5acea541d84b516937c2c
7
+ data.tar.gz: 898363f243233aace1aeffd4163b996bd280462a2c444db4c75ad472010ac7bc99f50d5945a2126380a6676a80daeb72b401b94c97010d6920dc796c4b661b2b
data/CHANGELOG.md CHANGED
@@ -2,6 +2,34 @@ Changelog for the gruf gem. This includes internal history before the gem was ma
2
2
 
3
3
  ### Pending release
4
4
 
5
+ ### 2.12.0
6
+
7
+ - Fixed interceptor order to be FIFO as documented, instead of FILO (fixes #139)
8
+
9
+ ### 2.11.0
10
+
11
+ - Restrict grpc gem to <= 1.41.0 due to regressions in grpc 1.42.x
12
+ - Fallback to stdout logger at INFO if no logger is setup
13
+ - Better handling of namespace collisions with Rails
14
+ - Add `GRPC_SERVER_HOST` and `GRPC_SERVER_PORT` for ENV configuration of the server host+port
15
+ - Add `GRPC_BACKTRACE_ON_ERROR` as available ENV configuration
16
+ - Add default ENV-based configuration of the GRPC server pool
17
+ - `GRPC_SERVER_POOL_SIZE` - sets the size of the GRPC server pool
18
+ - `GRPC_SERVER_POOL_KEEP_ALIVE` - keep alive time for threads spawned by the server pool
19
+ - `GRPC_SERVER_POLL_PERIOD` - period in seconds to poll for workers in the gRPC server pool
20
+ - Improve Yardoc support across the library
21
+ - Added attribute-based documentation for Gruf configuration options
22
+ - Add mfa required for gemspec metadata
23
+
24
+ ### 2.10.0
25
+
26
+ - Drop support for Ruby 2.4/2.5 to align with Ruby EOL schedule, supporting 2.6+ only
27
+ - Allow for float/TimeSpec timeout values on clients
28
+
29
+ ### 2.9.1
30
+
31
+ - Allow for float/TimeSpec timeout values on clients (backport from 2.10.0)
32
+
5
33
  ### 2.9.0
6
34
 
7
35
  - Change to racially neutral terminology across library
data/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  [![CircleCI](https://circleci.com/gh/bigcommerce/gruf/tree/main.svg?style=svg)](https://circleci.com/gh/bigcommerce/gruf/tree/main) [![Gem Version](https://badge.fury.io/rb/gruf.svg)](https://badge.fury.io/rb/gruf) [![Documentation](https://inch-ci.org/github/bigcommerce/gruf.svg?branch=main)](https://inch-ci.org/github/bigcommerce/gruf?branch=main)
4
4
 
5
- gruf is a Ruby framework that wraps the [gRPC Ruby library](https://github.com/grpc/grpc/tree/main/src/ruby) to
5
+ gruf is a Ruby framework that wraps the [gRPC Ruby library](https://github.com/grpc/grpc/tree/master/src/ruby) to
6
6
  provide a more streamlined integration into Ruby and Ruby on Rails applications.
7
7
 
8
8
  It provides an abstracted server and client for gRPC services, along with other tools to help get gRPC services in Ruby
@@ -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.10.x+. gruf is compatible and tested with Ruby 2.2-2.7.
20
+ gruf currently has active support for gRPC 1.10.x+. gruf is compatible and tested with Ruby 2.2-3.0.
21
21
  gruf is also not [Rails](https://github.com/rails/rails)-specific, and can be used in any Ruby framework
22
22
  (such as [Grape](https://github.com/ruby-grape/grape) or [dry-rb](https://dry-rb.org/), for instance).
23
23
 
data/gruf.gemspec CHANGED
@@ -33,9 +33,10 @@ Gem::Specification.new do |spec|
33
33
  spec.executables << 'gruf'
34
34
  spec.require_paths = ['lib']
35
35
 
36
- spec.required_ruby_version = '>= 2.4', '< 3.1'
36
+ spec.required_ruby_version = '>= 2.6', '< 3.1'
37
+
38
+ spec.metadata['rubygems_mfa_required'] = 'true'
37
39
 
38
- spec.add_development_dependency 'bundler', '~> 1.11'
39
40
  spec.add_development_dependency 'bundler-audit', '>= 0.6'
40
41
  # rubocop:disable Gemspec/RubyVersionGlobalsUsage
41
42
  spec.add_development_dependency(
@@ -57,10 +58,10 @@ Gem::Specification.new do |spec|
57
58
 
58
59
  spec.add_runtime_dependency 'activesupport', '> 4'
59
60
  spec.add_runtime_dependency 'concurrent-ruby', '> 1'
60
- spec.add_runtime_dependency 'e2mmap', '~> 0.1'
61
- spec.add_runtime_dependency 'grpc', '~> 1.10'
62
- spec.add_runtime_dependency 'grpc-tools', '~> 1.10'
61
+ spec.add_runtime_dependency 'e2mmap', '>= 0.1'
62
+ spec.add_runtime_dependency 'grpc', '~> 1.10', '<= 1.41.0'
63
+ spec.add_runtime_dependency 'grpc-tools', '~> 1.10', '<= 1.41.0'
63
64
  spec.add_runtime_dependency 'json', '>= 2.3'
64
- spec.add_runtime_dependency 'slop', '~> 4.6'
65
- spec.add_runtime_dependency 'thwait', '~> 0.1'
65
+ spec.add_runtime_dependency 'slop', '>= 4.6'
66
+ spec.add_runtime_dependency 'thwait', '>= 0.1'
66
67
  end
@@ -23,7 +23,8 @@ module Gruf
23
23
  # GRPC::BadStatus error
24
24
  #
25
25
  class Error < StandardError
26
- # @return [Object] error The deserialized error
26
+ # @!attribute [r] error
27
+ # @return [Object] error The deserialized error
27
28
  attr_reader :error
28
29
 
29
30
  ##
data/lib/gruf/client.rb CHANGED
@@ -38,11 +38,14 @@ module Gruf
38
38
  class Client < SimpleDelegator
39
39
  include Gruf::Loggable
40
40
 
41
- # @return [Class] The base, friendly name of the service being requested
41
+ # @!attribute [r] base_klass
42
+ # @return [Class] The base, friendly name of the service being requested
42
43
  attr_reader :base_klass
43
- # @return [Class] The class name of the gRPC service being requested
44
+ # @!attribute [r] service_klass
45
+ # @return [Class] The class name of the gRPC service being requested
44
46
  attr_reader :service_klass
45
- # @return [Hash] A hash of options for the client
47
+ # @!attribute [r] opts
48
+ # @return [Hash] A hash of options for the client
46
49
  attr_reader :opts
47
50
 
48
51
  ##
@@ -62,7 +65,7 @@ module Gruf
62
65
  @opts[:hostname] = @opts.fetch(:hostname, Gruf.default_client_host)
63
66
  @opts[:channel_credentials] = @opts.fetch(:channel_credentials, Gruf.default_channel_credentials)
64
67
  @error_factory = Gruf::Client::ErrorFactory.new
65
- client_options[:timeout] = client_options[:timeout].to_i if client_options.key?(:timeout)
68
+ client_options[:timeout] = parse_timeout(client_options[:timeout]) if client_options.key?(:timeout)
66
69
  client = "#{service}::Stub".constantize.new(@opts[:hostname], build_ssl_credentials, **client_options)
67
70
  super(client)
68
71
  end
@@ -216,5 +219,27 @@ module Gruf
216
219
  Gruf::Serializers::Errors::Json
217
220
  end
218
221
  end
222
+
223
+ ##
224
+ # Handle various timeout values and prevent improper value setting
225
+ #
226
+ # @see GRPC::Core::TimeConsts#from_relative_time
227
+ # @param [mixed] timeout
228
+ # @return [Float]
229
+ # @return [GRPC::Core::TimeSpec]
230
+ #
231
+ def parse_timeout(timeout)
232
+ if timeout.nil?
233
+ GRPC::Core::TimeConsts::ZERO
234
+ elsif timeout.is_a?(GRPC::Core::TimeSpec)
235
+ timeout
236
+ elsif timeout.is_a?(Numeric) # rubocop:disable Lint/DuplicateBranch
237
+ timeout
238
+ elsif timeout.respond_to?(:to_f)
239
+ timeout.to_f
240
+ else
241
+ raise ArgumentError, 'timeout is not a valid value: does not respond to to_f'
242
+ end
243
+ end
219
244
  end
220
245
  end
@@ -20,6 +20,63 @@ module Gruf
20
20
  # Represents configuration settings for the system
21
21
  #
22
22
  module Configuration
23
+ # @!attribute root_path
24
+ # @return [String] The root path for your application
25
+ # @!attribute server_binding_url
26
+ # @return [String] The full hostname:port that the gRPC server should bind to
27
+ # @!attribute server_options
28
+ # @return [Hash] A hash of options to pass to the server instance
29
+ # @!attribute interceptors
30
+ # @return [::Gruf::Interceptors::Registry] A registry of Gruf server interceptors
31
+ # @!attribute hooks
32
+ # @return [::Gruf::Hooks::Registry] A registry of Gruf hooks for the server
33
+ # @!attribute default_channel_credentials
34
+ # @return [NilClass]
35
+ # @return [Symbol]
36
+ # @return [Hash]
37
+ # @!attribute default_client_host
38
+ # @return [String] The default host for all new Gruf::Client objects to use as their target host
39
+ # @!attribute use_ssl
40
+ # @return [Boolean] If true, will setup the server to use TLS
41
+ # @!attribute ssl_crt_file
42
+ # @return [String] If use_ssl is true, the relative path from the root_path to the CRT file for the server
43
+ # @!attribute ssl_key_file
44
+ # @return [String] If use_ssl is true, the relative path from the root_path to the key file for the server
45
+ # @!attribute controllers_path
46
+ # @return [String] The relative path from root_path to locate Gruf Controllers in
47
+ # @!attribute services
48
+ # @return [Array<Class>] An array of services to serve with this Gruf server
49
+ # @!attribute logger
50
+ # @return [Logger] The logger class for Gruf-based logging
51
+ # @!attribute grpc_logger
52
+ # @return [Logger] The logger to use with GRPC's core logger (which logs plaintext). It is recommended to set
53
+ # this to an STDOUT logger and use a logging pipeline that can translate plaintext logs given GRPC's
54
+ # unformatted logging.
55
+ # @!attribute error_metadata_key
56
+ # @return [Symbol] The metadata key to use for error messages sent back in trailing metadata.
57
+ # @!attribute error_serializer
58
+ # @return [NilClass|::Gruf::Serializers::Errors::Base] The error serializer to use for error messages sent
59
+ # back in trailing metadata. Defaults to the base JSON serializer.
60
+ # @!attribute append_server_errors_to_trailing_metadata
61
+ # @return [Boolean] If true, will append all server error information into the trailing metadata in the response
62
+ # from the server
63
+ # @!attribute use_default_interceptors
64
+ # @return [Boolean] If true, will use the default ActiveRecord and Timer interceptors for servers
65
+ # @!attribute backtrace_on_error
66
+ # @return [Boolean] If true, will return the backtrace on any errors in servers in the trailing metadata
67
+ # @!attribute backtrace_limit
68
+ # @return [Integer] The limit of lines to use in backtraces returned
69
+ # @!attribute use_exception_message
70
+ # @return [String] If true, will pass the actual exception message from the error in a server
71
+ # @!attribute internal_error_message
72
+ # @return [String] If use_exception_message is false, this message will be used instead as a replacement
73
+ # @!attribute event_listener_proc
74
+ # @return [NilClass]
75
+ # @return [Proc] If set, this will be used during GRPC events (such as pool exhaustions)
76
+ # @!attribute synchronized_client_internal_cache_expiry
77
+ # @return [Integer] Internal cache expiry period (in seconds) for the SynchronizedClient
78
+ # @!attribute rpc_server_options
79
+ # @return [Hash] A hash of RPC options for GRPC server configuration
23
80
  VALID_CONFIG_KEYS = {
24
81
  root_path: '',
25
82
  server_binding_url: '0.0.0.0:9001',
@@ -61,8 +118,8 @@ module Gruf
61
118
  # Whenever this is extended into a class, setup the defaults
62
119
  #
63
120
  def self.extended(base)
64
- if defined?(Rails)
65
- Gruf::Integrations::Rails::Railtie.config.before_initialize { base.reset }
121
+ if defined?(::Rails)
122
+ ::Gruf::Integrations::Rails::Railtie.config.before_initialize { base.reset }
66
123
  else
67
124
  base.reset
68
125
  end
@@ -100,22 +157,28 @@ module Gruf
100
157
  VALID_CONFIG_KEYS.each do |k, v|
101
158
  send("#{k}=", v)
102
159
  end
103
- self.interceptors = Gruf::Interceptors::Registry.new
104
- self.hooks = Gruf::Hooks::Registry.new
105
- self.root_path = Rails.root.to_s.chomp('/') if defined?(Rails)
106
- if defined?(Rails) && Rails.logger
107
- self.logger = Rails.logger
108
- else
109
- require 'logger'
110
- self.logger = ::Logger.new($stdout)
111
- end
112
- self.grpc_logger = logger if grpc_logger.nil?
160
+ self.server_binding_url = "#{::ENV.fetch('GRPC_SERVER_HOST',
161
+ '0.0.0.0')}:#{::ENV.fetch('GRPC_SERVER_PORT', 9_001)}"
162
+ self.interceptors = ::Gruf::Interceptors::Registry.new
163
+ self.hooks = ::Gruf::Hooks::Registry.new
164
+ self.root_path = ::Rails.root.to_s.chomp('/') if defined?(::Rails)
165
+ determine_loggers
113
166
  self.ssl_crt_file = "#{root_path}config/ssl/#{environment}.crt"
114
167
  self.ssl_key_file = "#{root_path}config/ssl/#{environment}.key"
115
168
  self.controllers_path = root_path.to_s.empty? ? 'app/rpc' : "#{root_path}/app/rpc"
169
+ self.backtrace_on_error = ::ENV.fetch('GRPC_BACKTRACE_ON_ERROR', 0).to_i.positive?
170
+ self.rpc_server_options = {
171
+ max_waiting_requests: ::ENV.fetch('GRPC_SERVER_MAX_WAITING_REQUESTS',
172
+ GRPC::RpcServer::DEFAULT_MAX_WAITING_REQUESTS).to_i,
173
+ pool_size: ::ENV.fetch('GRPC_SERVER_POOL_SIZE', GRPC::RpcServer::DEFAULT_POOL_SIZE).to_i,
174
+ pool_keep_alive: ::ENV.fetch('GRPC_SERVER_POOL_KEEP_ALIVE', GRPC::Pool::DEFAULT_KEEP_ALIVE),
175
+ poll_period: ::ENV.fetch('GRPC_SERVER_POLL_PERIOD', GRPC::RpcServer::DEFAULT_POLL_PERIOD),
176
+ connect_md_proc: nil,
177
+ server_args: {}
178
+ }
116
179
  if use_default_interceptors
117
- interceptors.use(Gruf::Interceptors::ActiveRecord::ConnectionReset)
118
- interceptors.use(Gruf::Interceptors::Instrumentation::OutputMetadataTimer)
180
+ interceptors.use(::Gruf::Interceptors::ActiveRecord::ConnectionReset)
181
+ interceptors.use(::Gruf::Interceptors::Instrumentation::OutputMetadataTimer)
119
182
  end
120
183
  options
121
184
  end
@@ -128,11 +191,30 @@ module Gruf
128
191
  # @return [String] The current Ruby environment
129
192
  #
130
193
  def environment
131
- if defined?(Rails)
132
- Rails.env.to_s
194
+ if defined?(::Rails)
195
+ ::Rails.env.to_s
133
196
  else
134
197
  (ENV['RACK_ENV'] || ENV['RAILS_ENV'] || 'development').to_s
135
198
  end
136
199
  end
200
+
201
+ ##
202
+ # Dynamically determine the appropriate logger
203
+ #
204
+ def determine_loggers
205
+ if defined?(::Rails) && ::Rails.logger
206
+ self.logger = ::Rails.logger
207
+ else
208
+ require 'logger'
209
+ self.logger = ::Logger.new($stdout)
210
+ log_level = ::ENV.fetch('LOG_LEVEL', 'info').to_s.upcase
211
+ begin
212
+ logger.level = ::Logger::Severity.const_get(log_level)
213
+ rescue NameError => _e
214
+ logger.level = ::Logger::Severity::INFO
215
+ end
216
+ end
217
+ self.grpc_logger = logger if grpc_logger.nil?
218
+ end
137
219
  end
138
220
  end
@@ -26,13 +26,16 @@ module Gruf
26
26
  class Base
27
27
  include Gruf::Errors::Helpers
28
28
 
29
- # @var [Gruf::Controller::Request] request
29
+ # @!attribute [r] request
30
+ # @return [Gruf::Controller::Request] The incoming request
30
31
  attr_reader :request
31
- # @var [Gruf::Error] error
32
+ # @!attribute [r] error
33
+ # @return [Gruf::Error] The current error on the controller
32
34
  attr_reader :error
33
35
 
34
36
  class << self
35
- # @var [GRPC::GenericService] bound_service
37
+ # @!attribute [r] bound_service
38
+ # @return [GRPC::GenericService] bound_service The bound gRPC service class
36
39
  attr_reader :bound_service
37
40
  end
38
41
 
@@ -21,15 +21,20 @@ module Gruf
21
21
  # Encapsulates a request for a controller
22
22
  #
23
23
  class Request
24
- # @var [Object] message
24
+ # @!attribute [r] message
25
+ # @return [Object] The protobuf message in the request
25
26
  attr_reader :message
26
- # @var [GRPC::ActiveCall] active_call
27
+ # @!attribute [r] active_call
28
+ # @return [GRPC::ActiveCall] The active call object used for this request
27
29
  attr_reader :active_call
28
- # @var [Symbol] method_key
30
+ # @!attribute [r] method_key
31
+ # @return [Symbol] The method name being requested
29
32
  attr_reader :method_key
30
- # @var [Gruf::Controllers::Request::Type] type
33
+ # @!attribute [r] type
34
+ # @return [Gruf::Controllers::Request::Type] The type of request
31
35
  attr_reader :type
32
- # @var [Class] service
36
+ # @!attribute [r] service
37
+ # @return [Class] The GRPC service class for this request
33
38
  attr_reader :service
34
39
 
35
40
  delegate :metadata, to: :active_call
@@ -76,7 +81,7 @@ module Gruf
76
81
  # @return [String] The mapped service key
77
82
  #
78
83
  def service_key
79
- @service.name.underscore.tr('/', '.').gsub('.service', '')
84
+ @service.name.to_s.underscore.tr('/', '.').gsub('.service', '')
80
85
  end
81
86
 
82
87
  ##
@@ -106,6 +111,7 @@ module Gruf
106
111
  # Return all messages for this request, properly handling different request types
107
112
  #
108
113
  # @return [Enumerable<Object>] All messages for this request
114
+ # @return [Object] If a bidi streamed request, will return the message object
109
115
  #
110
116
  def messages
111
117
  if client_streamer?
data/lib/gruf/error.rb CHANGED
@@ -59,20 +59,28 @@ module Gruf
59
59
  METADATA_SIZE_EXCEEDED_CODE = 'metadata_size_exceeded'
60
60
  METADATA_SIZE_EXCEEDED_MSG = 'Metadata too long, risks exceeding http2 trailing metadata limit.'
61
61
 
62
- # @return [Symbol] The given internal gRPC code for the error
62
+ # @!attribute code
63
+ # @return [Symbol] The given internal gRPC code for the error
63
64
  attr_accessor :code
64
- # @return [Symbol] An arbitrary application code that can be used for logical processing of the error by the client
65
+ # @!attribute app_code
66
+ # @return [Symbol] An arbitrary application code that can be used for logical processing of the error
67
+ # by the client
65
68
  attr_accessor :app_code
66
- # @return [String] The error message returned by the server
69
+ # @!attribute message
70
+ # @return [String] The error message returned by the server
67
71
  attr_accessor :message
68
- # @return [Array] An array of field errors that can be returned by the server
72
+ # @!attribute field_errors
73
+ # @return [Array] An array of field errors that can be returned by the server
69
74
  attr_accessor :field_errors
70
- # @return [Errors::DebugInfo] A object containing debugging information, such as a stack trace and exception name,
71
- # that can be used to debug an given error response. This is sent by the server over the trailing metadata.
75
+ # @!attribute debug_info
76
+ # @return [Errors::DebugInfo] A object containing debugging information, such as a stack trace and exception name,
77
+ # that can be used to debug an given error response. This is sent by the server over the trailing metadata.
72
78
  attr_accessor :debug_info
73
- # @return [GRPC::BadStatus] The gRPC BadStatus error object that was generated
79
+ # @!attribute [w] grpc_error
80
+ # @return [GRPC::BadStatus] The gRPC BadStatus error object that was generated
74
81
  attr_writer :grpc_error
75
- # @return [Hash] The trailing metadata that was attached to the error
82
+ # @!attribute [r] metadata
83
+ # @return [Hash] The trailing metadata that was attached to the error
76
84
  attr_reader :metadata
77
85
 
78
86
  ##
@@ -21,9 +21,11 @@ module Gruf
21
21
  # Represents debugging information for an exception that occurred in a gRPC service
22
22
  #
23
23
  class DebugInfo
24
- # @return [String] The detail message of the exception
24
+ # @!attribute [r] detail
25
+ # @return [String] The detail message of the exception
25
26
  attr_reader :detail
26
- # @return [Array<String>] The stack trace generated by the exception as an array of strings
27
+ # @!attribute [r] stack_trace
28
+ # @return [Array<String>] The stack trace generated by the exception as an array of strings
27
29
  attr_reader :stack_trace
28
30
 
29
31
  ##
@@ -21,11 +21,14 @@ module Gruf
21
21
  # Represents a field-specific error
22
22
  #
23
23
  class Field
24
- # @return [Symbol] The name of the field as a Symbol
24
+ # @!attribute [r] field_name
25
+ # @return [Symbol] The name of the field as a Symbol
25
26
  attr_reader :field_name
26
- # @return [Symbol] The application error code for the field, e.g. :job_not_found
27
+ # @!attribute [r] error_code
28
+ # @return [Symbol] The application error code for the field, e.g. :job_not_found
27
29
  attr_reader :error_code
28
- # @return [String] The error message for the field, e.g. "Job with ID 123 not found"
30
+ # @!attribute [r] message
31
+ # @return [String] The error message for the field, e.g. "Job with ID 123 not found"
29
32
  attr_reader :message
30
33
 
31
34
  ##
@@ -21,11 +21,14 @@ module Gruf
21
21
  # Base class for interception requests
22
22
  #
23
23
  class Base
24
- # @var [Gruf::Controllers::Request] request
24
+ # @!attribute [r] request
25
+ # @return [Gruf::Controllers::Request] request
25
26
  attr_reader :request
26
- # @var [Gruf::Error] error
27
+ # @!attribute [r] error
28
+ # @return [Gruf::Error] error
27
29
  attr_reader :error
28
- # @var [Hash] options
30
+ # @!attribute [r] options
31
+ # @return [Hash] options
29
32
  attr_reader :options
30
33
 
31
34
  ##
@@ -38,7 +38,7 @@ module Gruf
38
38
  def intercept!(&block)
39
39
  return yield if @interceptors.none?
40
40
 
41
- i = @interceptors.pop
41
+ i = @interceptors.shift
42
42
  return yield unless i
43
43
 
44
44
  logger.debug "Intercepting request with interceptor: #{i.class}"
@@ -28,8 +28,12 @@ module Gruf
28
28
  # @property [Float] elapsed The elapsed time of the request
29
29
  #
30
30
  class Result
31
- attr_reader :message,
32
- :elapsed
31
+ # @!attribute [r] message
32
+ # @return [Object] The returned protobuf message
33
+ attr_reader :message
34
+ # @return [r] elapsed
35
+ # @return [Float] The time elapsed for this interceptor to execute
36
+ attr_reader :elapsed
33
37
 
34
38
  ##
35
39
  # @param [Object] message The protobuf message
@@ -53,7 +57,7 @@ module Gruf
53
57
  # @return [String] The name of the message class
54
58
  #
55
59
  def message_class_name
56
- @message.class.name
60
+ @message.class.name.to_s
57
61
  end
58
62
 
59
63
  ##
@@ -21,15 +21,20 @@ module Gruf
21
21
  # Encapsulates the context of an outbound client request
22
22
  #
23
23
  class RequestContext
24
- # @var [Symbol]
24
+ # @!attribute [r] type
25
+ # @return [Symbol]
25
26
  attr_reader :type
26
- # @var [Enumerable] requests
27
+ # @!attribute [r] requests
28
+ # @return [Enumerable] requests
27
29
  attr_reader :requests
28
- # @var [GRPC::ActiveCall]
30
+ # @!attribute [r] call
31
+ # @return [GRPC::ActiveCall]
29
32
  attr_reader :call
30
- # @var [Method] method
33
+ # @!attribute [r] method
34
+ # @return [Method] method
31
35
  attr_reader :method
32
- # @var [Hash] metadata
36
+ # @!attribute [r] metadata
37
+ # @return [Hash] metadata
33
38
  attr_reader :metadata
34
39
 
35
40
  ##
@@ -55,7 +60,7 @@ module Gruf
55
60
  # @return [String]
56
61
  #
57
62
  def method_name
58
- @method.to_s.split('/').last
63
+ @method.to_s.split('/').last.to_s
59
64
  end
60
65
 
61
66
  ##
@@ -64,7 +69,7 @@ module Gruf
64
69
  # @return [String]
65
70
  #
66
71
  def route_key
67
- @method[1..-1].underscore.tr('/', '.')
72
+ @method[1..].to_s.underscore.tr('/', '.')
68
73
  end
69
74
  end
70
75
  end
data/lib/gruf/response.rb CHANGED
@@ -20,17 +20,23 @@ module Gruf
20
20
  # Wraps the active call operation to provide metadata and timing around the request
21
21
  #
22
22
  class Response
23
- # @return [GRPC::ActiveCall::Operation] The operation that was executed for the given request
23
+ # @!attribute [r] operation
24
+ # @return [GRPC::ActiveCall::Operation] The operation that was executed for the given request
24
25
  attr_reader :operation
25
- # @return [Hash] The metadata that was attached to the operation
26
+ # @!attribute [r] metadata
27
+ # @return [Hash] The metadata that was attached to the operation
26
28
  attr_reader :metadata
27
- # @return [Hash] The trailing metadata that the service returned
29
+ # @!attribute [r] trailing_metadata
30
+ # @return [Hash] The trailing metadata that the service returned
28
31
  attr_reader :trailing_metadata
29
- # @return [Time] The set deadline on the call
32
+ # @!attribute [r] deadline
33
+ # @return [Time] The set deadline on the call
30
34
  attr_reader :deadline
31
- # @return [Boolean] Whether or not the operation was cancelled
35
+ # @!attribute [r] cancelled
36
+ # @return [Boolean] Whether or not the operation was cancelled
32
37
  attr_reader :cancelled
33
- # @return [Float] The time that the request took to execute
38
+ # @!attribute [r] execution_time
39
+ # @return [Float] The time that the request took to execute
34
40
  attr_reader :execution_time
35
41
 
36
42
  ##
@@ -22,7 +22,8 @@ module Gruf
22
22
  # Base class for serialization of errors for transport across the grpc protocol
23
23
  #
24
24
  class Base
25
- # @return [Gruf::Error|String] The error being serialized
25
+ # @!attribute [r] error
26
+ # @return [Gruf::Error|String] The error being serialized
26
27
  attr_reader :error
27
28
 
28
29
  ##
data/lib/gruf/server.rb CHANGED
@@ -25,9 +25,11 @@ module Gruf
25
25
 
26
26
  include Gruf::Loggable
27
27
 
28
- # @return [Integer] The port the server is bound to
28
+ # @!attribute [r] port
29
+ # @return [Integer] The port the server is bound to
29
30
  attr_reader :port
30
- # @return [Hash] Hash of options passed into the server
31
+ # @!attribute [r] options
32
+ # @return [Hash] Hash of options passed into the server
31
33
  attr_reader :options
32
34
 
33
35
  ##
@@ -23,6 +23,8 @@ module Gruf
23
23
  # to mitigate thundering herds.
24
24
  #
25
25
  class SynchronizedClient < Gruf::Client
26
+ # @!attribute [r] unsynchronized_methods
27
+ # @return [Array]
26
28
  attr_reader :unsynchronized_methods
27
29
 
28
30
  ##
data/lib/gruf/timer.rb CHANGED
@@ -33,8 +33,12 @@ module Gruf
33
33
  # @property [Float] time The time, in ms, of the block execution
34
34
  #
35
35
  class Result
36
- attr_reader :result,
37
- :time
36
+ # @!attribute [r] result
37
+ # @return [mixed]
38
+ attr_reader :result
39
+ # @!attribute [r] time
40
+ # @return [Float]
41
+ attr_reader :time
38
42
 
39
43
  ##
40
44
  # Initialize the result object
data/lib/gruf/version.rb CHANGED
@@ -16,5 +16,5 @@
16
16
  # OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
17
17
  #
18
18
  module Gruf
19
- VERSION = '2.9.0'
19
+ VERSION = '2.12.0'
20
20
  end
data/lib/gruf.rb CHANGED
@@ -40,7 +40,7 @@ require_relative 'gruf/client'
40
40
  require_relative 'gruf/synchronized_client'
41
41
  require_relative 'gruf/instrumentable_grpc_server'
42
42
  require_relative 'gruf/server'
43
- require_relative 'gruf/integrations/rails/railtie' if defined?(Rails)
43
+ require_relative 'gruf/integrations/rails/railtie' if defined?(::Rails)
44
44
 
45
45
  ##
46
46
  # Initializes configuration of gruf core module
metadata CHANGED
@@ -1,29 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gruf
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.9.0
4
+ version: 2.12.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: 2021-03-02 00:00:00.000000000 Z
11
+ date: 2021-12-29 00:00:00.000000000 Z
12
12
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: bundler
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - "~>"
18
- - !ruby/object:Gem::Version
19
- version: '1.11'
20
- type: :development
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - "~>"
25
- - !ruby/object:Gem::Version
26
- version: '1.11'
27
13
  - !ruby/object:Gem::Dependency
28
14
  name: bundler-audit
29
15
  requirement: !ruby/object:Gem::Requirement
@@ -238,14 +224,14 @@ dependencies:
238
224
  name: e2mmap
239
225
  requirement: !ruby/object:Gem::Requirement
240
226
  requirements:
241
- - - "~>"
227
+ - - ">="
242
228
  - !ruby/object:Gem::Version
243
229
  version: '0.1'
244
230
  type: :runtime
245
231
  prerelease: false
246
232
  version_requirements: !ruby/object:Gem::Requirement
247
233
  requirements:
248
- - - "~>"
234
+ - - ">="
249
235
  - !ruby/object:Gem::Version
250
236
  version: '0.1'
251
237
  - !ruby/object:Gem::Dependency
@@ -255,6 +241,9 @@ dependencies:
255
241
  - - "~>"
256
242
  - !ruby/object:Gem::Version
257
243
  version: '1.10'
244
+ - - "<="
245
+ - !ruby/object:Gem::Version
246
+ version: 1.41.0
258
247
  type: :runtime
259
248
  prerelease: false
260
249
  version_requirements: !ruby/object:Gem::Requirement
@@ -262,6 +251,9 @@ dependencies:
262
251
  - - "~>"
263
252
  - !ruby/object:Gem::Version
264
253
  version: '1.10'
254
+ - - "<="
255
+ - !ruby/object:Gem::Version
256
+ version: 1.41.0
265
257
  - !ruby/object:Gem::Dependency
266
258
  name: grpc-tools
267
259
  requirement: !ruby/object:Gem::Requirement
@@ -269,6 +261,9 @@ dependencies:
269
261
  - - "~>"
270
262
  - !ruby/object:Gem::Version
271
263
  version: '1.10'
264
+ - - "<="
265
+ - !ruby/object:Gem::Version
266
+ version: 1.41.0
272
267
  type: :runtime
273
268
  prerelease: false
274
269
  version_requirements: !ruby/object:Gem::Requirement
@@ -276,6 +271,9 @@ dependencies:
276
271
  - - "~>"
277
272
  - !ruby/object:Gem::Version
278
273
  version: '1.10'
274
+ - - "<="
275
+ - !ruby/object:Gem::Version
276
+ version: 1.41.0
279
277
  - !ruby/object:Gem::Dependency
280
278
  name: json
281
279
  requirement: !ruby/object:Gem::Requirement
@@ -294,28 +292,28 @@ dependencies:
294
292
  name: slop
295
293
  requirement: !ruby/object:Gem::Requirement
296
294
  requirements:
297
- - - "~>"
295
+ - - ">="
298
296
  - !ruby/object:Gem::Version
299
297
  version: '4.6'
300
298
  type: :runtime
301
299
  prerelease: false
302
300
  version_requirements: !ruby/object:Gem::Requirement
303
301
  requirements:
304
- - - "~>"
302
+ - - ">="
305
303
  - !ruby/object:Gem::Version
306
304
  version: '4.6'
307
305
  - !ruby/object:Gem::Dependency
308
306
  name: thwait
309
307
  requirement: !ruby/object:Gem::Requirement
310
308
  requirements:
311
- - - "~>"
309
+ - - ">="
312
310
  - !ruby/object:Gem::Version
313
311
  version: '0.1'
314
312
  type: :runtime
315
313
  prerelease: false
316
314
  version_requirements: !ruby/object:Gem::Requirement
317
315
  requirements:
318
- - - "~>"
316
+ - - ">="
319
317
  - !ruby/object:Gem::Version
320
318
  version: '0.1'
321
319
  description: gRPC Ruby Framework for building complex gRPC applications at scale
@@ -376,7 +374,8 @@ files:
376
374
  homepage: https://github.com/bigcommerce/gruf
377
375
  licenses:
378
376
  - MIT
379
- metadata: {}
377
+ metadata:
378
+ rubygems_mfa_required: 'true'
380
379
  post_install_message:
381
380
  rdoc_options: []
382
381
  require_paths:
@@ -385,7 +384,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
385
384
  requirements:
386
385
  - - ">="
387
386
  - !ruby/object:Gem::Version
388
- version: '2.4'
387
+ version: '2.6'
389
388
  - - "<"
390
389
  - !ruby/object:Gem::Version
391
390
  version: '3.1'
@@ -395,7 +394,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
395
394
  - !ruby/object:Gem::Version
396
395
  version: '0'
397
396
  requirements: []
398
- rubygems_version: 3.0.9
397
+ rubygems_version: 3.3.4
399
398
  signing_key:
400
399
  specification_version: 4
401
400
  summary: gRPC Ruby Framework