griffin 0.3.0 → 0.4.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: aa72d1f7851dc5a90fb99214c57e9bbba2fd6da6e84225a2ea6955d9ad89f872
4
- data.tar.gz: 2794b9f846099b958fb5b937fcf8de2168a858bad149a89316664f9c3b921d75
3
+ metadata.gz: eb8e4a6558953c8d052f0f316bffdae7911bea8acb111d188188587fb9215298
4
+ data.tar.gz: 1248416385fbc28bb98598ffb2b41061561469ec121a9c77e90e770ee7a7c365
5
5
  SHA512:
6
- metadata.gz: 731a0d9ab4fba6a3989ef0af62bb4a36f1bd34f48bb0790ff4f5d0c954ee8fa5e0492f4d4f65121ff7378d90fea313333feb262ed4575d4a5c355fb03ae35f28
7
- data.tar.gz: 0bded1160bf1b33b16a11e6dea2c95c8abc3311695c4947031dfddb918a5d0292cca809e8797a5b06e1b25e4a8d6e0f88c9467543549539378a079b552c83eff
6
+ metadata.gz: 61b7e087d7076db35403dcc08f0bcf8b86f198ab9aa6b97db337029941546cb95f8265172d608f5b567db5ceba884333e35aad9c728b921787112b832956d3d1
7
+ data.tar.gz: 1b6ed7407b7281e32d13fd71ab50d5e24f17ad89fc39ce4bd7bb7b589c4f05f0bb036a3d287eba6de67721fab50468c000d10a764269c04ba457c972771e9f0e
data/.rubocop.yml CHANGED
@@ -1,9 +1,11 @@
1
1
  AllCops:
2
2
  Exclude:
3
3
  - '**/**/*_pb.rb' # auto-generated
4
- - "vendor/**/*"
4
+ - 'pb/grpc/health/checker.rb' # copied
5
+ - 'vendor/**/*'
5
6
  DisplayCopNames: true
6
- TargetRubyVersion: 2.5
7
+ TargetRubyVersion: 3.0
8
+ NewCops: enable
7
9
 
8
10
  Style/AndOr:
9
11
  EnforcedStyle: conditionals
@@ -42,7 +44,7 @@ Style/WhileUntilModifier:
42
44
  Enabled: false
43
45
 
44
46
  Naming/PredicateName:
45
- NamePrefixBlacklist:
47
+ ForbiddenPrefixes:
46
48
  - "is_"
47
49
  - "have_"
48
50
  NamePrefix:
@@ -76,7 +78,7 @@ Metrics/AbcSize:
76
78
  Metrics/CyclomaticComplexity:
77
79
  Max: 10
78
80
 
79
- Metrics/LineLength:
81
+ Layout/LineLength:
80
82
  Max: 160
81
83
 
82
84
  Metrics/MethodLength:
@@ -90,3 +92,6 @@ Metrics/ClassLength:
90
92
 
91
93
  Metrics/BlockLength:
92
94
  Max: 40
95
+
96
+ Lint/DuplicateBranch:
97
+ IgnoreConstantBranches: true
data/Gemfile CHANGED
@@ -4,5 +4,11 @@ source 'https://rubygems.org'
4
4
 
5
5
  git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
6
6
 
7
+ gem 'bundler'
8
+ gem 'pry-byebug'
9
+ gem 'rake'
10
+ gem 'rspec'
11
+ gem 'rubocop'
12
+
7
13
  # Specify your gem's dependencies in griffin.gemspec
8
14
  gemspec
data/README.md CHANGED
@@ -52,7 +52,7 @@ Griffin::Server.run
52
52
 
53
53
  ## Interceptors
54
54
 
55
- * [cookpad/griffin-interceptors](https://github.com/cookpad/griffin-interceptors) colloection of interceptors
55
+ * [cookpad/griffin-interceptors](https://github.com/cookpad/griffin-interceptors) collection of interceptors
56
56
 
57
57
  ## Development
58
58
 
@@ -9,7 +9,7 @@ class CallStream < GrpcKit::Call
9
9
  delegate %i[send_msg recv] => :@inner
10
10
 
11
11
  # @params call [GrpcKit::Call]
12
- def initialize(inner)
12
+ def initialize(inner) # rubocop:disable Lint/MissingSuper
13
13
  @inner = inner
14
14
  end
15
15
 
@@ -17,7 +17,7 @@ class CallStream < GrpcKit::Call
17
17
  loop { yield(recv) }
18
18
  end
19
19
 
20
- def method_missing(name, *args, &block)
21
- @inner.public_send(name, *args, &block)
20
+ def method_missing(...) # rubocop:disable Style/MissingRespondToMissing
21
+ @inner.public_send(...)
22
22
  end
23
23
  end
@@ -10,10 +10,10 @@ require 'routeguide_services_pb'
10
10
  class Server < Routeguide::RouteGuide::Service
11
11
  RESOURCE_PATH = './examples/routeguide/routeguide.json'
12
12
 
13
- def initialize
13
+ def initialize # rubocop:disable Lint/MissingSuper
14
14
  File.open(RESOURCE_PATH) do |f|
15
15
  features = JSON.parse(f.read)
16
- @features = Hash[features.map { |x| [x['location'], x['name']] }]
16
+ @features = features.to_h { |x| [x['location'], x['name']] }
17
17
  end
18
18
 
19
19
  @route_notes = Hash.new { |h, k| h[k] = [] }
@@ -98,7 +98,7 @@ class Server < Routeguide::RouteGuide::Service
98
98
 
99
99
  delta_lat = lat_a - lat_b
100
100
  delta_lon = lon_a - lon_b
101
- a = Math.sin(delta_lat / 2)**2 + Math.cos(lat_a) * Math.cos(lat_b) + Math.sin(delta_lon / 2)**2
101
+ a = (Math.sin(delta_lat / 2)**2) + (Math.cos(lat_a) * Math.cos(lat_b)) + (Math.sin(delta_lon / 2)**2)
102
102
  (2 * RADIUS * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a))).to_i
103
103
  end
104
104
 
data/griffin.gemspec CHANGED
@@ -20,14 +20,12 @@ Gem::Specification.new do |spec|
20
20
  end
21
21
  spec.bindir = 'exe'
22
22
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
23
- spec.require_paths = ['lib', 'pb']
23
+ spec.require_paths = %w[lib pb]
24
24
 
25
- spec.add_development_dependency 'bundler'
26
- spec.add_development_dependency 'pry-byebug'
27
- spec.add_development_dependency 'rake'
28
- spec.add_development_dependency 'rspec'
29
- spec.add_development_dependency 'rubocop'
25
+ spec.metadata['rubygems_mfa_required'] = 'true'
26
+ spec.required_ruby_version = Gem::Requirement.new('>= 3.0')
30
27
 
28
+ spec.add_dependency 'google-protobuf', '>= 3.18.0'
31
29
  spec.add_dependency 'grpc_kit', '>= 0.5.0'
32
30
  spec.add_dependency 'serverengine', '~> 2.0.7'
33
31
  end
@@ -40,10 +40,10 @@ module Griffin
40
40
  st.trap(ServerEngine::Signals::GRACEFUL_RESTART) { |s| w.stop(s) }
41
41
  st.trap(ServerEngine::Signals::IMMEDIATE_RESTART, 'SIG_DFL')
42
42
 
43
- st.trap(ServerEngine::Signals::RELOAD) {
43
+ st.trap(ServerEngine::Signals::RELOAD) do
44
44
  w.logger.reopen!
45
45
  w.reload
46
- }
46
+ end
47
47
  st.trap(ServerEngine::Signals::DETACH) { |s| w.stop(s) }
48
48
 
49
49
  st.trap(ServerEngine::Signals::DUMP) { w.dump }
@@ -24,9 +24,9 @@ module Griffin
24
24
  def logdev_from_config(config)
25
25
  case c = config[:log]
26
26
  when nil # default
27
- STDERR
27
+ $stderr
28
28
  when '-'
29
- STDOUT
29
+ $stdout
30
30
  else
31
31
  c
32
32
  end
@@ -41,19 +41,22 @@ module Griffin
41
41
  # @param min_connection_size [Integer] Maximun connection of TCP
42
42
  # @param max_connection_size [Integer] Minimum connection of TCP
43
43
  # @param interceptors [Array<GrpcKit::GRPC::ServerInterceptor>] list of interceptors
44
+ # @param shutdown_timeout [Integer] Timeout for server shutdown in seconds
44
45
  # @param settings [Array<DS9::Settings,Integer>] list of HTTP2-Settings headers
45
46
  # @param max_receive_message_size [Integer, nil] Specify the default maximum size of inbound message in bytes. Default to 4MB.
46
47
  # @param max_send_message_size [Integer, nil] Specify the default maximum size of outbound message in bytes. Default to 4MB.
47
- def initialize(min_pool_size:, max_pool_size:, min_connection_size:, max_connection_size:, interceptors: [], settings: [], max_receive_message_size: nil, max_send_message_size: nil, **opts)
48
+ def initialize(min_pool_size:, max_pool_size:, min_connection_size:, max_connection_size:, interceptors: [], shutdown_timeout: 30, settings: [],
49
+ max_receive_message_size: nil, max_send_message_size: nil, **opts)
48
50
  @min_connection_size = min_connection_size
49
51
  @max_connection_size = max_connection_size
50
52
  @server = GrpcKit::Server.new(
51
53
  interceptors: interceptors,
54
+ shutdown_timeout: shutdown_timeout,
52
55
  min_pool_size: min_pool_size,
53
56
  max_pool_size: max_pool_size,
54
57
  max_receive_message_size: max_receive_message_size,
55
58
  max_send_message_size: max_send_message_size,
56
- settings: settings
59
+ settings: settings,
57
60
  )
58
61
  @opts = opts
59
62
  @status = :run
@@ -102,8 +105,8 @@ module Griffin
102
105
  io = IO.select(@socks, [], [])
103
106
 
104
107
  io[0].each do |sock|
105
- if sock == @command
106
- break if handle_command
108
+ if sock == @command && handle_command
109
+ break
107
110
  end
108
111
 
109
112
  # @thread_pool.schedule could block and accepted socket would be timeout.
@@ -11,14 +11,14 @@ module Griffin
11
11
  DEFAULT_POOL_SIZE = 20
12
12
  DEFAULT_CONNECTION_SIZE = 3
13
13
 
14
- GRIFFIN_CONFIGS = [
15
- :max_pool_size,
16
- :min_pool_size,
17
- :max_connection_size,
18
- :min_connection_size,
19
- :max_receive_message_size,
20
- :max_send_message_size,
21
- :http2_settings,
14
+ GRIFFIN_CONFIGS = %i[
15
+ max_pool_size
16
+ min_pool_size
17
+ max_connection_size
18
+ min_connection_size
19
+ max_receive_message_size
20
+ max_send_message_size
21
+ http2_settings
22
22
  ].freeze
23
23
 
24
24
  GRPC_CONFIGS = %i[services interceptors].freeze
@@ -50,7 +50,7 @@ module Griffin
50
50
  @opts = DEFAULT_SERVER_CONFIG.dup
51
51
  end
52
52
 
53
- (SERVERENGINE_PRIMITIVE_CONFIGS).each do |name|
53
+ SERVERENGINE_PRIMITIVE_CONFIGS.each do |name|
54
54
  define_method(name) do |value|
55
55
  @opts[name] = value
56
56
  end
@@ -92,7 +92,6 @@ module Griffin
92
92
  @opts[:max_send_message_size] = Integer(value)
93
93
  end
94
94
 
95
-
96
95
  def build
97
96
  c = ServerConfig.new
98
97
  @opts.each do |name, value|
@@ -56,7 +56,8 @@ module Griffin
56
56
  end
57
57
 
58
58
  # For GrpcKit::ThreadPool::AutoTrimmer
59
- def trim(force = false)
59
+ # TODO: Change interface to use a keyword argument.
60
+ def trim(force = false) # rubocop:disable Style/OptionalBooleanParameter
60
61
  if @mutex.synchronize { (force || (@waiting > 0)) && (@spawned > @min_pool_size) }
61
62
  GrpcKit.logger.info("Trim worker! Next worker size #{@spawned - 1}")
62
63
  @tasks.push(nil)
@@ -86,7 +87,8 @@ module Griffin
86
87
  begin
87
88
  @block.call(task)
88
89
  rescue Exception => e # rubocop:disable Lint/RescueException
89
- Griffin.logger.error("An error occured on top level in worker #{Thread.current.name}: #{e.message} (#{e.class})\n #{Thread.current.backtrace.join("\n")} ")
90
+ backtrace = Thread.current.backtrace.join("\n")
91
+ Griffin.logger.error("An error occured on top level in worker #{Thread.current.name}: #{e.message} (#{e.class})\n #{backtrace} ")
90
92
  end
91
93
  end
92
94
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Griffin
4
- VERSION = '0.3.0'
4
+ VERSION = '0.4.0'
5
5
  end
data/lib/griffin.rb CHANGED
@@ -8,7 +8,7 @@ require 'griffin/version'
8
8
 
9
9
  module Griffin
10
10
  def self.logger
11
- @logger ||= Logger.new(STDOUT, level: :info)
11
+ @logger ||= Logger.new($stdout, level: :info)
12
12
  end
13
13
 
14
14
  def self.logger=(logger)
@@ -1,28 +1,21 @@
1
+ # frozen_string_literal: true
1
2
  # Generated by the protocol buffer compiler. DO NOT EDIT!
2
3
  # source: grpc/health/v1/health.proto
3
4
 
4
5
  require 'google/protobuf'
5
6
 
6
- Google::Protobuf::DescriptorPool.generated_pool.build do
7
- add_message "grpc.health.v1.HealthCheckRequest" do
8
- optional :service, :string, 1
9
- end
10
- add_message "grpc.health.v1.HealthCheckResponse" do
11
- optional :status, :enum, 1, "grpc.health.v1.HealthCheckResponse.ServingStatus"
12
- end
13
- add_enum "grpc.health.v1.HealthCheckResponse.ServingStatus" do
14
- value :UNKNOWN, 0
15
- value :SERVING, 1
16
- value :NOT_SERVING, 2
17
- end
18
- end
7
+
8
+ descriptor_data = "\n\x1bgrpc/health/v1/health.proto\x12\x0egrpc.health.v1\"%\n\x12HealthCheckRequest\x12\x0f\n\x07service\x18\x01 \x01(\t\"\xa9\x01\n\x13HealthCheckResponse\x12\x41\n\x06status\x18\x01 \x01(\x0e\x32\x31.grpc.health.v1.HealthCheckResponse.ServingStatus\"O\n\rServingStatus\x12\x0b\n\x07UNKNOWN\x10\x00\x12\x0b\n\x07SERVING\x10\x01\x12\x0f\n\x0bNOT_SERVING\x10\x02\x12\x13\n\x0fSERVICE_UNKNOWN\x10\x03\x32\xae\x01\n\x06Health\x12P\n\x05\x43heck\x12\".grpc.health.v1.HealthCheckRequest\x1a#.grpc.health.v1.HealthCheckResponse\x12R\n\x05Watch\x12\".grpc.health.v1.HealthCheckRequest\x1a#.grpc.health.v1.HealthCheckResponse0\x01\x42\x61\n\x11io.grpc.health.v1B\x0bHealthProtoP\x01Z,google.golang.org/grpc/health/grpc_health_v1\xaa\x02\x0eGrpc.Health.V1b\x06proto3"
9
+
10
+ pool = Google::Protobuf::DescriptorPool.generated_pool
11
+ pool.add_serialized_file(descriptor_data)
19
12
 
20
13
  module Grpc
21
14
  module Health
22
15
  module V1
23
- HealthCheckRequest = Google::Protobuf::DescriptorPool.generated_pool.lookup("grpc.health.v1.HealthCheckRequest").msgclass
24
- HealthCheckResponse = Google::Protobuf::DescriptorPool.generated_pool.lookup("grpc.health.v1.HealthCheckResponse").msgclass
25
- HealthCheckResponse::ServingStatus = Google::Protobuf::DescriptorPool.generated_pool.lookup("grpc.health.v1.HealthCheckResponse.ServingStatus").enummodule
16
+ HealthCheckRequest = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("grpc.health.v1.HealthCheckRequest").msgclass
17
+ HealthCheckResponse = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("grpc.health.v1.HealthCheckResponse").msgclass
18
+ HealthCheckResponse::ServingStatus = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("grpc.health.v1.HealthCheckResponse.ServingStatus").enummodule
26
19
  end
27
20
  end
28
21
  end
@@ -28,13 +28,31 @@ module Grpc
28
28
  module Health
29
29
  class Service
30
30
 
31
- include GRPC::GenericService
31
+ include ::GRPC::GenericService
32
32
 
33
33
  self.marshal_class_method = :encode
34
34
  self.unmarshal_class_method = :decode
35
35
  self.service_name = 'grpc.health.v1.Health'
36
36
 
37
- rpc :Check, HealthCheckRequest, HealthCheckResponse
37
+ # If the requested service is unknown, the call will fail with status
38
+ # NOT_FOUND.
39
+ rpc :Check, ::Grpc::Health::V1::HealthCheckRequest, ::Grpc::Health::V1::HealthCheckResponse
40
+ # Performs a watch for the serving status of the requested service.
41
+ # The server will immediately send back a message indicating the current
42
+ # serving status. It will then subsequently send a new message whenever
43
+ # the service's serving status changes.
44
+ #
45
+ # If the requested service is unknown when the call is received, the
46
+ # server will send a message setting the serving status to
47
+ # SERVICE_UNKNOWN but will *not* terminate the call. If at some
48
+ # future point, the serving status of the service becomes known, the
49
+ # server will send a new message with the service's serving status.
50
+ #
51
+ # If the call terminates with status UNIMPLEMENTED, then clients
52
+ # should assume this method is not supported and should not retry the
53
+ # call. If the call terminates with any other status (including OK),
54
+ # clients should retry the call with appropriate exponential backoff.
55
+ rpc :Watch, ::Grpc::Health::V1::HealthCheckRequest, stream(::Grpc::Health::V1::HealthCheckResponse)
38
56
  end
39
57
 
40
58
  Stub = Service.rpc_stub_class
metadata CHANGED
@@ -1,85 +1,28 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: griffin
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yuta Iwama
8
- autorequire:
9
8
  bindir: exe
10
9
  cert_chain: []
11
- date: 2021-04-22 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
- name: bundler
13
+ name: google-protobuf
15
14
  requirement: !ruby/object:Gem::Requirement
16
15
  requirements:
17
16
  - - ">="
18
17
  - !ruby/object:Gem::Version
19
- version: '0'
20
- type: :development
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - ">="
25
- - !ruby/object:Gem::Version
26
- version: '0'
27
- - !ruby/object:Gem::Dependency
28
- name: pry-byebug
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - ">="
32
- - !ruby/object:Gem::Version
33
- version: '0'
34
- type: :development
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - ">="
39
- - !ruby/object:Gem::Version
40
- version: '0'
41
- - !ruby/object:Gem::Dependency
42
- name: rake
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - ">="
46
- - !ruby/object:Gem::Version
47
- version: '0'
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - ">="
53
- - !ruby/object:Gem::Version
54
- version: '0'
55
- - !ruby/object:Gem::Dependency
56
- name: rspec
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - ">="
60
- - !ruby/object:Gem::Version
61
- version: '0'
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - ">="
67
- - !ruby/object:Gem::Version
68
- version: '0'
69
- - !ruby/object:Gem::Dependency
70
- name: rubocop
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - ">="
74
- - !ruby/object:Gem::Version
75
- version: '0'
76
- type: :development
18
+ version: 3.18.0
19
+ type: :runtime
77
20
  prerelease: false
78
21
  version_requirements: !ruby/object:Gem::Requirement
79
22
  requirements:
80
23
  - - ">="
81
24
  - !ruby/object:Gem::Version
82
- version: '0'
25
+ version: 3.18.0
83
26
  - !ruby/object:Gem::Dependency
84
27
  name: grpc_kit
85
28
  requirement: !ruby/object:Gem::Requirement
@@ -155,8 +98,8 @@ files:
155
98
  homepage: https://github.com/ganmacs/griffin
156
99
  licenses:
157
100
  - MIT
158
- metadata: {}
159
- post_install_message:
101
+ metadata:
102
+ rubygems_mfa_required: 'true'
160
103
  rdoc_options: []
161
104
  require_paths:
162
105
  - lib
@@ -165,15 +108,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
165
108
  requirements:
166
109
  - - ">="
167
110
  - !ruby/object:Gem::Version
168
- version: '0'
111
+ version: '3.0'
169
112
  required_rubygems_version: !ruby/object:Gem::Requirement
170
113
  requirements:
171
114
  - - ">="
172
115
  - !ruby/object:Gem::Version
173
116
  version: '0'
174
117
  requirements: []
175
- rubygems_version: 3.1.4
176
- signing_key:
118
+ rubygems_version: 4.0.20
177
119
  specification_version: 4
178
120
  summary: gRPC server and client for Ruby
179
121
  test_files: []