gRPC / Protobuf interface versioning
Asked Answered
B

3

19

Let's say we use gRCP/Protobuf to connect many application. Those application are developped and released at their own team, with their own speed. Over time there will be different version of the the same app (e.g. desktop apps install on user PCs) that use different version on defined interface.

While Protobuf is meant to allow backward compatibility, is there a way to know what version of interface is running at different points?

The simplest implementation is to have interface version equal to app version. But as many languages are used, it is not trivial to implement app versioning in all of them.

So how version interface and let server to know client version? I think server should be able to log

DATETIME connection from AppName v.version [using interface v.version]

Boanerges answered 10/11, 2016 at 3:40 Comment(3)
Possibly what I need to look at is Global interceptorBoanerges
Similar to groups.google.com/forum/#!topic/grpc-io/LPsPg5ctQd4 Do people implement a "GetVersion()" method? questionBoanerges
I advise to version methods and maintain two latest versions. It results in having DoSmth7() and DoSmth8(), which is a bit ugly, but I buy this.Maxey
I
6

In the upcoming versions of gRPC, there will be a new feature called Server Reflection. This will allow a client to ask the server for the Descriptors that descriptor the proto file being used. Rather than the server knowing about the version the client is running, the client will know what the server is running. If the server descriptor matches the one the client already has, then it will know that they are speaking at the same version.

This will be released in version 1.1.

Note that Protobufs are designed so that you don't have to do this! If you set up your proto correctly, old and new versions of clients and server should work together.

Inculpate answered 14/1, 2017 at 4:44 Comment(3)
> "Note that Protobufs are designed so that you don't have to do this! If you set up your proto correctly, old and new versions of clients and server should work together." What do you mean by that?Willette
Server reflection is now possible. Is there a place which demonstrates how to use this to indicate the version or from the client to query the version?Exhilarate
@carl, your answer is nearly 5 years old, would you update it to reflect the current gRPC release?Cardboard
V
1

One way to do this would be to add a custom option and set that option at the top of your .proto file, like this:

option (my_app.version) = 3;

Then in each language you can examine the value of that option and indicate it as your version number.

Vanhoose answered 11/11, 2016 at 16:56 Comment(0)
K
-1

If you are using protocol buffers version 2, you can use the default values to implement this. Protocol buffers 3 has removed support for default values so this answer doesn't work there.

In the .proto file defining your interface, have something like:

message MyLoginMessage
{
    ... normal login fields ...

    // Increment this number when you make new releases
    // of this .proto.
    optional int32 protocol_version [default=55];
}

This way any client will automatically include the version number taken from the .proto.

Edit: Ah, just noticed the proto3 tag.. so I guess this answer is not useful to you after all.

Katy answered 10/11, 2016 at 13:1 Comment(1)
Idea is nice. However optional is not keyword/supported for proto3. Also that would be needed to add to every message and interface.Boanerges

© 2022 - 2025 — McMap. All rights reserved.