Skip to content

Commit

Permalink
Merge pull request #169 from bigcommerce/fix-168
Browse files Browse the repository at this point in the history
Do not load grpc health check unless defined - fixes #168
  • Loading branch information
splittingred committed Aug 17, 2022
2 parents 0060fce + 6fb9a39 commit 6038d15
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 5 deletions.
2 changes: 2 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ def gruf_rake_configure_rpc!

Gruf.configure do |c|
c.error_serializer = Serializers::Proto
c.health_check_enabled = true
end
end

Expand Down Expand Up @@ -192,6 +193,7 @@ namespace :gruf do

desc 'Call the health check'
task :health_check do
require 'gruf/controllers/health_controller'
gruf_rake_configure_rpc!
begin
rpc_client = gruf_demo_build_client(service: ::Grpc::Health::V1::Health)
Expand Down
2 changes: 1 addition & 1 deletion lib/gruf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
require 'active_support/hash_with_indifferent_access'
require 'active_support/concern'
require 'active_support/inflector'
require 'grpc/health/v1/health_services_pb'
require 'base64'

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

Expand Down
4 changes: 1 addition & 3 deletions lib/gruf/cli/executor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,7 @@ def health_check_enabled?
def bind_health_check!(services)
# do this here to trigger autoloading the controller in zeitwerk, since we don't explicitly load this
# controller. This binds the service and makes sure the method handlers are setup.
# rubocop:disable Lint/Void
Gruf::Controllers::HealthController
# rubocop:enable Lint/Void
require 'gruf/controllers/health_controller'
# if we're already bound to the services array (say someone explicitly passes the health check in, skip)
return services if services.include?(::Grpc::Health::V1::Health::Service)

Expand Down
2 changes: 2 additions & 0 deletions lib/gruf/controllers/health_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
# OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#
require 'grpc/health/v1/health_services_pb'

module Gruf
module Controllers
##
Expand Down
2 changes: 1 addition & 1 deletion spec/demo_server
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ Gruf.configure do |c|
c.server_binding_url = 'localhost:8001'
c.error_serializer = Serializers::Proto
c.backtrace_on_error = true
c.health_check_enabled = true
c.health_check_enabled = ::ENV.fetch('GRUF_HEALTH_CHECK_ENABLED', 1).to_i.positive?
c.interceptors.use(
Gruf::Interceptors::Instrumentation::Statsd,
client: FakeStats.new,
Expand Down
1 change: 1 addition & 0 deletions spec/gruf/controllers/health_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
# OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#
require 'spec_helper'
require 'gruf/controllers/health_controller'

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

0 comments on commit 6038d15

Please sign in to comment.