Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Monkey patch gruf interceptor #17

Merged
merged 10 commits into from
Oct 31, 2024
Merged

Monkey patch gruf interceptor #17

merged 10 commits into from
Oct 31, 2024

Conversation

nkadovic
Copy link
Contributor

  • Create a monkey patch that allows us to properly fail! in server interceptors when using grpc-rest.

Copy link
Member

@dorner dorner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think adding the ErrorInterceptor you made by default into grpc-rest makes sense? Or is it specific to the publication stuff?

@@ -20,6 +20,7 @@ Gem::Specification.new do |spec|

spec.add_runtime_dependency('grpc')
spec.add_runtime_dependency('rails', '>= 6.0')
spec.add_runtime_dependency('gruf')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gruf doesn't need to be a runtime dependency. I forgot that I didn't want to enforce this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah okay, sounds good. Just wondering, what is the rationale for not including it? I assumed that since we were explicitly using Gruf::Interceptors::ServerInterceptor in the code we'd need it as a dependency.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's only in the send_gruf_request method, which only gets used if Gruf is loaded.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think adding the ErrorInterceptor you made by default into grpc-rest makes sense? Or is it specific to the publication stuff?

I feel like it might be too domain-specific to include in grpc-rest, but I am not sure. Maybe it would be best to include the error interceptor as an example in README.md? What do you think?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nah, I think the example we have is fine. I forgot it had some ActiveRecord etc stuff in there.

lib/grpc_rest.rb Outdated
@@ -1,6 +1,7 @@
require 'google/protobuf/well_known_types'
require 'grpc'
require 'grpc/core/status_codes'
require 'interceptors/base_interceptor'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can remove this line - you can add to the readme that if you want to make an interceptor you have to require this before you do it.

@@ -17,6 +17,7 @@ class GrpcApp < Rails::Application
loader.ignore("#{Rails.root}/spec/test_service_pb.rb")
loader.setup
require "#{Rails.root}/spec/test_service_pb.rb"
require "#{Rails.root}/lib/base_interceptor.rb"
Copy link
Contributor Author

@nkadovic nkadovic Oct 31, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if this was the right way of fixing it, but I had to include this so my tests could properly run on the CI.

@nkadovic nkadovic requested a review from dorner October 31, 2024 14:47
Copy link
Member

@dorner dorner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor nit - also, can you please update CHANGELOG under Unreleased?

Comment on lines 6 to 8
# This is a monkey-patch that fixes an issue we were having with using the fail! method in
# interceptors where an active call was not instantiated yet.
# Basically, we overloaded this function: https://github.com/bigcommerce/gruf/blob/main/lib/gruf/errors/helpers.rb#L34
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd change this comment to:

Fixes an issue with the fail! method since the active call is not instantiated yet.
Overloads https://github.com/bigcommerce/gruf/blob/main/lib/gruf/errors/helpers.rb#L34

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense, less filler words. 👍

@nkadovic nkadovic requested a review from dorner October 31, 2024 15:09
@dorner dorner merged commit f6bd65c into flipp-oss:main Oct 31, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants