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

tonic-reflection: re-expose v1alpha reflection server builder #1787

Closed
wants to merge 1 commit into from

Conversation

ttkjesper
Copy link
Contributor

@ttkjesper ttkjesper commented Jul 10, 2024

While testing the new tonic 0.12 release, we discovered that #1701 upgraded the reflection protocol to v1 from v1alpha.

This breaks compatibility with popular gRPC debugging tools like Postman and Kreya, who only use the v1alpha protocol.

Motivation

Upgrading to 0.12 would potentially introduce a degradation in triaging flows since tools supporting the v1 protocol are limited.

Solution

Following the #1802 PR, this reintroduces the v1alpha protocol in a separate module.

@djc
Copy link
Collaborator

djc commented Jul 11, 2024

I don't think we can semver-compatibly reverse this change as this PR does (nor do I necessarily think that would be the right approach). I'd suggest adding back the v1alpha stuff under a separate name, and adding a changelog entry in the breaking changes section that calls out this change.

@ttkjesper
Copy link
Contributor Author

ttkjesper commented Jul 11, 2024

That is a fair concern. I've gone through and done the appropriate cleanup to make sure the interface has not changed. The v1alpha module is now published separately, and all relevant traits and structs are now contained within.

I do not believe there should be any breaking change here anymore (the relevant switch from v1alpha -> v1 was already mentioned in the 0.12 breaking changes).

@djc
Copy link
Collaborator

djc commented Jul 13, 2024

The current set of changes makes it too hard for me to review this carefully for semver compatibility. I suggest you make a smaller commit that only moves code around while keeping the public API as is, and a separate commit reintroducing the v1alpha API.

@ttkjesper
Copy link
Contributor Author

Sure - I've added #1802 to refactor the module layout. When that has been approved and merged we can revisit latter part of the v1alpha support in this one.

@ttkjesper
Copy link
Contributor Author

I've now updated this PR to contain the appropriate changes.

The diff for the new v1alpha.rs module is as follows:

$ diff -u v1.rs v1alpha.rs
--- v1.rs       2024-07-15 15:53:37.433776000 +0200
+++ v1alpha.rs  2024-07-15 15:54:45.730740900 +0200
@@ -1,8 +1,8 @@
-use crate::pb::v1::server_reflection_server::{ServerReflection, ServerReflectionServer};
+pub use crate::pb::v1alpha::server_reflection_server::{ServerReflection, ServerReflectionServer};

-use crate::pb::v1::server_reflection_request::MessageRequest;
-use crate::pb::v1::server_reflection_response::MessageResponse;
-use crate::pb::v1::{
+use crate::pb::v1alpha::server_reflection_request::MessageRequest;
+use crate::pb::v1alpha::server_reflection_response::MessageResponse;
+use crate::pb::v1alpha::{
     ExtensionNumberResponse, FileDescriptorResponse, ListServiceResponse, ServerReflectionRequest,
     ServerReflectionResponse, ServiceResponse,
 };
@@ -16,7 +16,7 @@

 use crate::server::Error;

-/// A builder used to construct a gRPC Reflection Service (`v1` protocol variant).
+/// A builder used to construct a gRPC Reflection Service (`v1alpha` protocol variant).
 #[derive(Default, Debug)]
 pub struct Builder<'b> {
     file_descriptor_sets: Vec<FileDescriptorSet>,
@@ -75,7 +75,8 @@
     /// Build a gRPC Reflection Service to be served via Tonic.
     pub fn build(mut self) -> Result<ServerReflectionServer<impl ServerReflection>, Error> {
         if self.include_reflection_service {
-            self = self.register_encoded_file_descriptor_set(crate::pb::v1::FILE_DESCRIPTOR_SET);
+            self =
+                self.register_encoded_file_descriptor_set(crate::pb::v1alpha::FILE_DESCRIPTOR_SET);
         }

         let info = crate::server::parser::DescriptorParser::process(

/// A builder used to construct a gRPC Reflection Service.
#[derive(Debug)]
/// A builder used to construct a gRPC Reflection Service (`v1` protocol variant).
#[derive(Default, Debug)]
Copy link
Collaborator

Choose a reason for hiding this comment

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

These changes still seem unrelated to the idea of adding v1alpha support. I also think they're wrong -- in this case Builder::default() yields a different value than Builder::configure(), which seems potentially surprising.

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, you're right! Didn't think of the consequence of adding the derivation - that change was just to reduce some boilerplate with the initialization in the constructor. I've reverted that part of the change.

Copy link
Collaborator

@djc djc Jul 15, 2024

Choose a reason for hiding this comment

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

Okay, but there's still a whole bunch of changes with factoring out the parser stuff out of the v1 builder (plus seemingly arbitrary reordering of fields). Again, I'd like to see those in a separate commit or PR. The idea here is to create atomic commits which make it much easier to review the changes (and understand why the changes were made). This is especially when you're both adding a bunch of code (the v1alpha stuff) and moving code around (code that is shared between v1 and v1alpha).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Alright, I've reverted the parser and will be repackaging that into a separate PR so that we can keep the changes self-contained.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Sorry for the slow response -- I think I'd prefer to take the extraction of the parser first in a separate PR (or a separate commit within this PR).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No worries! I'll take care of that. :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The parser has been re-introduced in #1822.

@ttkjesper ttkjesper changed the title tonic-reflection: expose both v1alpha and v1 reflection server builders tonic-reflection: re-expose v1alpha reflection server builders Jul 17, 2024
@ttkjesper ttkjesper changed the title tonic-reflection: re-expose v1alpha reflection server builders tonic-reflection: re-expose v1alpha reflection server builder Jul 17, 2024
To enable wider support for reflection in tools like *Postman* and
*Kreya*, this change reintroduces support for the v1alpha protocol.

Changes:
* Add v1alpha module with associated Builder
* Add tests to verify responses from both versions
@ttkjesper
Copy link
Contributor Author

Cleaned up history and rebased towards the lastest master commit.

@oliverjantar
Copy link

Hi, is there some timeline when this might be merged?

@djc
Copy link
Collaborator

djc commented Aug 14, 2024

I'm on vacation, will be back next week.

@djc
Copy link
Collaborator

djc commented Aug 23, 2024

I took a deeper look at this and wanted to do a somewhat different approach, resulting in #1888. Please give feedback in that PR!

@flokli
Copy link

flokli commented Aug 24, 2024

#1888 has been merged, this can be closed.

@djc djc closed this Aug 24, 2024
@ttkjesper ttkjesper deleted the server-builders branch August 26, 2024 07:21
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.

4 participants