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

deps: move from github.com/golang/protobuf to google.golang.org/protobuf/proto #7059

Merged
merged 10 commits into from
Apr 5, 2024
Merged

deps: move from github.com/golang/protobuf to google.golang.org/protobuf/proto #7059

merged 10 commits into from
Apr 5, 2024

Conversation

Clement-Jean
Copy link
Contributor

@Clement-Jean Clement-Jean commented Mar 21, 2024

@dfawley @arvindbr8 this is the next step after #6919 since #6969 is closed.

I'm still unsure about the remaining deprecated dependency in channelz/service/service_test.go. First, this line:

proto.RegisterType((*OtherSecurityValue)(nil), "grpc.credentials.OtherChannelzSecurityValue")

it seems to be possible to use protoregistry.GlobalTypes.RegisterMessage instead of proto.RegisterType. I just don't know how yet.

Second, it seems that proto.UnmarshalText(want[i], w) and prototext.Unmarshall(string(want[i]), w) are not doing the same thing. The first one accepts '\x00' in the string and the second does not. Any idea why?

RELEASE NOTES: none

Copy link

codecov bot commented Mar 21, 2024

Codecov Report

Merging #7059 (190126d) into master (fc3f327) will decrease coverage by 1.28%.
Report is 8 commits behind head on master.
The diff coverage is 100.00%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #7059      +/-   ##
==========================================
- Coverage   82.47%   81.19%   -1.28%     
==========================================
  Files         305      345      +40     
  Lines       31383    33925    +2542     
==========================================
+ Hits        25884    27547    +1663     
- Misses       4442     5205     +763     
- Partials     1057     1173     +116     
Files Coverage Δ
channelz/internal/protoconv/channel.go 86.04% <100.00%> (ø)
channelz/internal/protoconv/server.go 71.87% <100.00%> (ø)
channelz/internal/protoconv/socket.go 89.15% <100.00%> (ø)
channelz/internal/protoconv/sockopt_linux.go 85.88% <100.00%> (ø)
channelz/internal/protoconv/subchannel.go 89.28% <100.00%> (ø)
credentials/credentials.go 87.87% <ø> (ø)

... and 66 files with indirect coverage changes

@dfawley
Copy link
Member

dfawley commented Mar 22, 2024

it seems to be possible to use protoregistry.GlobalTypes.RegisterMessage instead of proto.RegisterType. I just don't know how yet.

This seems reasonable. But I think it's also possible, if you want, to create a proto file and import it instead of doing it dynamically like the test currently does.

Second, it seems that proto.UnmarshalText(want[i], w) and prototext.Unmarshall(string(want[i]), w) are not doing the same thing. The first one accepts '\x00' in the string and the second does not. Any idea why?

I'm not sure. Can you do prototext.Marshal() of the output of the specific proto.UnmarshalText? Maybe that will show you the format prototext.Unmarshal wants?

@dfawley dfawley added the Type: Dependencies Updating/adding/removing dependencies label Mar 22, 2024
@dfawley dfawley added this to the 1.64 Release milestone Mar 22, 2024
@Clement-Jean
Copy link
Contributor Author

Clement-Jean commented Mar 25, 2024

This seems reasonable. But I think it's also possible, if you want, to create a proto file and import it instead of doing it dynamically like the test currently does.

For now, I found a simpler solution that does pretty much the same as before:

func init() {
  // Ad-hoc registering the proto type here to facilitate Unmarshal of OtherSecurityValue.
  m := (*OtherSecurityValue)(nil)
  s := "grpc.credentials.OtherChannelzSecurityValue"
  mt := protoimpl.X.LegacyMessageTypeOf(m, protoreflect.FullName(s))
  if err := protoregistry.GlobalTypes.RegisterMessage(mt); err != nil {
    panic(err)
  }
}

We are still using legacy way of registering messages but not the deprecated dependency. The main problem I have with having a proto file or registering a descriptor is that it is not linked to OtherSecurityValue.

I'm not sure. Can you do prototext.Marshal() of the output of the specific proto.UnmarshalText? Maybe that will show you the format prototext.Unmarshal wants?

Doing:

err := proto.UnmarshalText(want[i], w)
if err != nil {
  t.Fatal(err)
}
_, err = prototext.Marshal(w)
if err != nil {
  t.Fatal(err)
}

there are not errors returned...

@dfawley
Copy link
Member

dfawley commented Mar 25, 2024

there are not errors returned...

We wouldn't expect errors. I was curious what the output would look like as that should really be something that would be accepted by prototext.Unmarshal.

@Clement-Jean
Copy link
Contributor Author

The issue seems to be coming from the function called addr which doesn't return valid UTF8 strings. And prototext.Unmarshal seems to be expecting UTF8 strings.

@Clement-Jean
Copy link
Contributor Author

I believe we could also remove this line in vet.sh:

# - Ensure all ptypes proto packages are renamed when importing.
not git grep "\(import \|^\s*\)\"github.com/golang/protobuf/ptypes/" -- "*.go"

Other than that, if there is no way to remove the dependency in reflection/grpc_testing_not_regenerate/testv3.go, I think we are pretty much done.

@dfawley
Copy link
Member

dfawley commented Mar 26, 2024

The issue seems to be coming from the function called addr which doesn't return valid UTF8 strings. And prototext.Unmarshal seems to be expecting UTF8 strings.

Good find! Thanks for the fix.

I believe we could also remove this line in vet.sh:

I'm fine with that, but if we do that we should replace it with something that looks for "github.com/golang/protobuf" and forbids it anywhere but in reflection/grpc_testing_not_regenerate.

"google.golang.org/protobuf/protoadapt"
"google.golang.org/protobuf/reflect/protoreflect"
"google.golang.org/protobuf/reflect/protoregistry"
"google.golang.org/protobuf/runtime/protoimpl"
Copy link
Member

Choose a reason for hiding this comment

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

WARNING: This package should only ever be imported by generated messages. The compatibility agreement covers nothing except for functionality needed to keep existing generated messages operational. Breakages that occur due to unauthorized usages of this package are not the author's responsibility.

I'd rather not use this package if it's at all possible to avoid it, unless you are extremely sure backward compatibility will be guaranteed for all our uses of it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, I agree that using protoimpl is half a solution. I'm figuring out how to imrpove this.

@Clement-Jean
Copy link
Contributor Author

Clement-Jean commented Apr 2, 2024

@dfawley I found other references to github.com/golang/protobuf and I changed the vet.sh. Could you check?

The GetSocket test seems to fail and not consistently (flaky). Not sure why yet.

edit

It seems to be the order into which the value is encoded in OtherChannelzSecurityValue. If we look at when it fails, we have the following:

service_test.go:800: Socket 6 did not match expected.  -got +want:   (*grpc_channelz_v1.Socket)(Inverse(protocmp.Transform, protocmp.Message{
  "@type": s"grpc.channelz.v1.Socket",
  "data":  protocmp.Message{"@type": s"grpc.channelz.v1.SocketData", "last_local_stream_created_timestamp": protocmp.Message{"@type": s"google.protobuf.Timestamp"}, "last_message_received_timestamp": protocmp.Message{"@type": s"google.protobuf.Timestamp"}, "last_message_sent_timestamp": protocmp.Message{"@type": s"google.protobuf.Timestamp"}, ...},
  "ref":   protocmp.Message{"@type": s"grpc.channelz.v1.SocketRef", "name": string("6"), "socket_id": int64(123)},
  "security": protocmp.Message{
    "@type": s"grpc.channelz.v1.Security",
    "other": protocmp.Message{
       "@type": s"grpc.channelz.v1.Security.OtherSecurity",
       "name":  string("YYYY"),
       "value": protocmp.Message{
          "@type":    s"google.protobuf.Any",
          "type_url": string("type.googleapis.com/grpc.credentials.OtherChannelzSecurityValue"),
          "value": []uint8{
            -       0x0a, 0x03, 0x01, 0x02, 0x03, 0x12, 0x03, 0x04, 0x05, 0x06, // -|..........|
            +       0x12, 0x03, 0x04, 0x05, 0x06, 0x0a, 0x03, 0x01, 0x02, 0x03, // +|..........|
          },
        },
      },
    },
}))

And the values in value seem to be inverted. The 5 first in got should be the last 5 and inversely for the 5 last.

@Clement-Jean
Copy link
Contributor Author

@dfawley It was because protobuf does not ensure encoding order of fields. Going with a generated proto message is easier.

Copy link
Member

@dfawley dfawley left a comment

Choose a reason for hiding this comment

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

This looks great to me. Just one change to request. Thanks!


package grpc.credentials;

option go_package = "google.golang.org/grpc/channelz/service";
Copy link
Member

Choose a reason for hiding this comment

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

Can this go into service_test? If not, please put it in a subdirectory so it doesn't get pulled into the production build. (Even if it is eventually pruned out (?), it still feels wrong.)

Copy link
Contributor Author

@Clement-Jean Clement-Jean Apr 4, 2024

Choose a reason for hiding this comment

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

Yeah, that's why I wanted to keep it as a descriptor in the test file at first... I think I will move the info back into the test file like it was and create the ProtoReflect function on OtherChannelzSecurityValue.

@@ -287,5 +287,5 @@ type ChannelzSecurityValue interface {
type OtherChannelzSecurityValue struct {
ChannelzSecurityValue
Name string
Value protoadapt.MessageV1
Copy link
Member

Choose a reason for hiding this comment

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

This may be a breaking change. It is probably fine since it's experimental, and it's unlikely anyone is using it....so I think I'm OK with it. Just wanted to call it out.

@dfawley dfawley assigned Clement-Jean and unassigned dfawley Apr 3, 2024
Copy link
Member

@dfawley dfawley left a comment

Choose a reason for hiding this comment

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

Thanks!

Copy link
Member

@arvindbr8 arvindbr8 left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks @Clement-Jean for making huge strides in fixing #5316.


gRPConf 2024 Registration is now open! Please find more details at grpc.io. Hope to see you there.

@arvindbr8 arvindbr8 merged commit 879414f into grpc:master Apr 5, 2024
14 checks passed
@Clement-Jean Clement-Jean deleted the remove_old_proto_pkg branch April 6, 2024 01:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Dependencies Updating/adding/removing dependencies
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Update proto package imports to google.golang.org/protobuf/proto
3 participants