Skip to content

Commit 6038d15

Browse files
authored
Merge pull request #169 from bigcommerce/fix-168
Do not load grpc health check unless defined - fixes #168
2 parents 0060fce + 6fb9a39 commit 6038d15

File tree

6 files changed

+8
-5
lines changed

6 files changed

+8
-5
lines changed

Rakefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ def gruf_rake_configure_rpc!
3232

3333
Gruf.configure do |c|
3434
c.error_serializer = Serializers::Proto
35+
c.health_check_enabled = true
3536
end
3637
end
3738

@@ -192,6 +193,7 @@ namespace :gruf do
192193

193194
desc 'Call the health check'
194195
task :health_check do
196+
require 'gruf/controllers/health_controller'
195197
gruf_rake_configure_rpc!
196198
begin
197199
rpc_client = gruf_demo_build_client(service: ::Grpc::Health::V1::Health)

lib/gruf.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
require 'active_support/hash_with_indifferent_access'
2121
require 'active_support/concern'
2222
require 'active_support/inflector'
23-
require 'grpc/health/v1/health_services_pb'
2423
require 'base64'
2524

2625
# use Zeitwerk to lazily autoload all the files in the lib directory
@@ -29,6 +28,7 @@
2928
loader.tag = File.basename(__FILE__, '.rb')
3029
loader.inflector = ::Zeitwerk::GemInflector.new(__FILE__)
3130
loader.ignore("#{__dir__}/gruf/integrations/rails/railtie.rb")
31+
loader.ignore("#{__dir__}/gruf/controllers/health_controller.rb")
3232
loader.push_dir(__dir__)
3333
loader.setup
3434

lib/gruf/cli/executor.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,9 +161,7 @@ def health_check_enabled?
161161
def bind_health_check!(services)
162162
# do this here to trigger autoloading the controller in zeitwerk, since we don't explicitly load this
163163
# controller. This binds the service and makes sure the method handlers are setup.
164-
# rubocop:disable Lint/Void
165-
Gruf::Controllers::HealthController
166-
# rubocop:enable Lint/Void
164+
require 'gruf/controllers/health_controller'
167165
# if we're already bound to the services array (say someone explicitly passes the health check in, skip)
168166
return services if services.include?(::Grpc::Health::V1::Health::Service)
169167

lib/gruf/controllers/health_controller.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
1616
# OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1717
#
18+
require 'grpc/health/v1/health_services_pb'
19+
1820
module Gruf
1921
module Controllers
2022
##

spec/demo_server

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ Gruf.configure do |c|
5151
c.server_binding_url = 'localhost:8001'
5252
c.error_serializer = Serializers::Proto
5353
c.backtrace_on_error = true
54-
c.health_check_enabled = true
54+
c.health_check_enabled = ::ENV.fetch('GRUF_HEALTH_CHECK_ENABLED', 1).to_i.positive?
5555
c.interceptors.use(
5656
Gruf::Interceptors::Instrumentation::Statsd,
5757
client: FakeStats.new,

spec/gruf/controllers/health_controller_spec.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
# OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1717
#
1818
require 'spec_helper'
19+
require 'gruf/controllers/health_controller'
1920

2021
describe ::Gruf::Controllers::HealthController do
2122
let(:rpc_service) { ::Grpc::Health::V1::Health::Service }

0 commit comments

Comments
 (0)