mirror of https://github.com/grpc/grpc-go.git
deps: move from github.com/golang/protobuf to google.golang.org/protobuf/proto (#7059)
This commit is contained in:
parent
8444ae0e47
commit
879414f963
|
|
@ -21,11 +21,11 @@ package protoconv
|
|||
import (
|
||||
"time"
|
||||
|
||||
"github.com/golang/protobuf/ptypes"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/connectivity"
|
||||
"google.golang.org/grpc/internal/channelz"
|
||||
"google.golang.org/grpc/status"
|
||||
"google.golang.org/protobuf/types/known/timestamppb"
|
||||
|
||||
channelzpb "google.golang.org/grpc/channelz/grpc_channelz_v1"
|
||||
)
|
||||
|
|
@ -56,7 +56,7 @@ func channelTraceToProto(ct *channelz.ChannelTrace) *channelzpb.ChannelTrace {
|
|||
return pbt
|
||||
}
|
||||
pbt.NumEventsLogged = ct.EventNum
|
||||
if ts, err := ptypes.TimestampProto(ct.CreationTime); err == nil {
|
||||
if ts := timestamppb.New(ct.CreationTime); ts.IsValid() {
|
||||
pbt.CreationTimestamp = ts
|
||||
}
|
||||
events := make([]*channelzpb.ChannelTraceEvent, 0, len(ct.Events))
|
||||
|
|
@ -65,7 +65,7 @@ func channelTraceToProto(ct *channelz.ChannelTrace) *channelzpb.ChannelTrace {
|
|||
Description: e.Desc,
|
||||
Severity: channelzpb.ChannelTraceEvent_Severity(e.Severity),
|
||||
}
|
||||
if ts, err := ptypes.TimestampProto(e.Timestamp); err == nil {
|
||||
if ts := timestamppb.New(e.Timestamp); ts.IsValid() {
|
||||
cte.Timestamp = ts
|
||||
}
|
||||
if e.RefID != 0 {
|
||||
|
|
@ -93,7 +93,7 @@ func channelToProto(cm *channelz.Channel) *channelzpb.Channel {
|
|||
CallsSucceeded: cm.ChannelMetrics.CallsSucceeded.Load(),
|
||||
CallsFailed: cm.ChannelMetrics.CallsFailed.Load(),
|
||||
}
|
||||
if ts, err := ptypes.TimestampProto(time.Unix(0, cm.ChannelMetrics.LastCallStartedTimestamp.Load())); err == nil {
|
||||
if ts := timestamppb.New(time.Unix(0, cm.ChannelMetrics.LastCallStartedTimestamp.Load())); ts.IsValid() {
|
||||
c.Data.LastCallStartedTimestamp = ts
|
||||
}
|
||||
ncs := cm.NestedChans()
|
||||
|
|
|
|||
|
|
@ -21,10 +21,10 @@ package protoconv
|
|||
import (
|
||||
"time"
|
||||
|
||||
"github.com/golang/protobuf/ptypes"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/internal/channelz"
|
||||
"google.golang.org/grpc/status"
|
||||
"google.golang.org/protobuf/types/known/timestamppb"
|
||||
|
||||
channelzpb "google.golang.org/grpc/channelz/grpc_channelz_v1"
|
||||
)
|
||||
|
|
@ -39,7 +39,7 @@ func serverToProto(sm *channelz.Server) *channelzpb.Server {
|
|||
CallsFailed: sm.ServerMetrics.CallsFailed.Load(),
|
||||
}
|
||||
|
||||
if ts, err := ptypes.TimestampProto(time.Unix(0, sm.ServerMetrics.LastCallStartedTimestamp.Load())); err == nil {
|
||||
if ts := timestamppb.New(time.Unix(0, sm.ServerMetrics.LastCallStartedTimestamp.Load())); ts.IsValid() {
|
||||
s.Data.LastCallStartedTimestamp = ts
|
||||
}
|
||||
lss := sm.ListenSockets()
|
||||
|
|
|
|||
|
|
@ -22,15 +22,14 @@ import (
|
|||
"net"
|
||||
"time"
|
||||
|
||||
"github.com/golang/protobuf/ptypes"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/credentials"
|
||||
"google.golang.org/grpc/internal/channelz"
|
||||
"google.golang.org/grpc/status"
|
||||
"google.golang.org/protobuf/protoadapt"
|
||||
"google.golang.org/protobuf/types/known/anypb"
|
||||
"google.golang.org/protobuf/types/known/timestamppb"
|
||||
"google.golang.org/protobuf/types/known/wrapperspb"
|
||||
|
||||
wrpb "github.com/golang/protobuf/ptypes/wrappers"
|
||||
channelzpb "google.golang.org/grpc/channelz/grpc_channelz_v1"
|
||||
)
|
||||
|
||||
|
|
@ -46,7 +45,7 @@ func securityToProto(se credentials.ChannelzSecurityValue) *channelzpb.Security
|
|||
otherSecurity := &channelzpb.Security_OtherSecurity{
|
||||
Name: v.Name,
|
||||
}
|
||||
if anyval, err := anypb.New(protoadapt.MessageV2Of(v.Value)); err == nil {
|
||||
if anyval, err := anypb.New(v.Value); err == nil {
|
||||
otherSecurity.Value = anyval
|
||||
}
|
||||
return &channelzpb.Security{Model: &channelzpb.Security_Other{Other: otherSecurity}}
|
||||
|
|
@ -89,22 +88,22 @@ func socketToProto(skt *channelz.Socket) *channelzpb.Socket {
|
|||
MessagesReceived: skt.SocketMetrics.MessagesReceived.Load(),
|
||||
KeepAlivesSent: skt.SocketMetrics.KeepAlivesSent.Load(),
|
||||
}
|
||||
if ts, err := ptypes.TimestampProto(time.Unix(0, skt.SocketMetrics.LastLocalStreamCreatedTimestamp.Load())); err == nil {
|
||||
if ts := timestamppb.New(time.Unix(0, skt.SocketMetrics.LastLocalStreamCreatedTimestamp.Load())); ts.IsValid() {
|
||||
s.Data.LastLocalStreamCreatedTimestamp = ts
|
||||
}
|
||||
if ts, err := ptypes.TimestampProto(time.Unix(0, skt.SocketMetrics.LastRemoteStreamCreatedTimestamp.Load())); err == nil {
|
||||
if ts := timestamppb.New(time.Unix(0, skt.SocketMetrics.LastRemoteStreamCreatedTimestamp.Load())); ts.IsValid() {
|
||||
s.Data.LastRemoteStreamCreatedTimestamp = ts
|
||||
}
|
||||
if ts, err := ptypes.TimestampProto(time.Unix(0, skt.SocketMetrics.LastMessageSentTimestamp.Load())); err == nil {
|
||||
if ts := timestamppb.New(time.Unix(0, skt.SocketMetrics.LastMessageSentTimestamp.Load())); ts.IsValid() {
|
||||
s.Data.LastMessageSentTimestamp = ts
|
||||
}
|
||||
if ts, err := ptypes.TimestampProto(time.Unix(0, skt.SocketMetrics.LastMessageReceivedTimestamp.Load())); err == nil {
|
||||
if ts := timestamppb.New(time.Unix(0, skt.SocketMetrics.LastMessageReceivedTimestamp.Load())); ts.IsValid() {
|
||||
s.Data.LastMessageReceivedTimestamp = ts
|
||||
}
|
||||
if skt.EphemeralMetrics != nil {
|
||||
e := skt.EphemeralMetrics()
|
||||
s.Data.LocalFlowControlWindow = &wrpb.Int64Value{Value: e.LocalFlowControlWindow}
|
||||
s.Data.RemoteFlowControlWindow = &wrpb.Int64Value{Value: e.RemoteFlowControlWindow}
|
||||
s.Data.LocalFlowControlWindow = wrapperspb.Int64(e.LocalFlowControlWindow)
|
||||
s.Data.RemoteFlowControlWindow = wrapperspb.Int64(e.RemoteFlowControlWindow)
|
||||
}
|
||||
|
||||
s.Data.Option = sockoptToProto(skt.SocketOptions)
|
||||
|
|
|
|||
|
|
@ -21,15 +21,14 @@ package protoconv
|
|||
import (
|
||||
"time"
|
||||
|
||||
"github.com/golang/protobuf/ptypes"
|
||||
durpb "github.com/golang/protobuf/ptypes/duration"
|
||||
channelzpb "google.golang.org/grpc/channelz/grpc_channelz_v1"
|
||||
"google.golang.org/grpc/internal/channelz"
|
||||
"google.golang.org/protobuf/types/known/anypb"
|
||||
"google.golang.org/protobuf/types/known/durationpb"
|
||||
)
|
||||
|
||||
func convertToPtypesDuration(sec int64, usec int64) *durpb.Duration {
|
||||
return ptypes.DurationProto(time.Duration(sec*1e9 + usec*1e3))
|
||||
func convertToPbDuration(sec int64, usec int64) *durationpb.Duration {
|
||||
return durationpb.New(time.Duration(sec*1e9 + usec*1e3))
|
||||
}
|
||||
|
||||
func sockoptToProto(skopts *channelz.SocketOptionData) []*channelzpb.SocketOption {
|
||||
|
|
@ -40,7 +39,7 @@ func sockoptToProto(skopts *channelz.SocketOptionData) []*channelzpb.SocketOptio
|
|||
if skopts.Linger != nil {
|
||||
additional, err := anypb.New(&channelzpb.SocketOptionLinger{
|
||||
Active: skopts.Linger.Onoff != 0,
|
||||
Duration: convertToPtypesDuration(int64(skopts.Linger.Linger), 0),
|
||||
Duration: convertToPbDuration(int64(skopts.Linger.Linger), 0),
|
||||
})
|
||||
if err == nil {
|
||||
opts = append(opts, &channelzpb.SocketOption{
|
||||
|
|
@ -53,7 +52,7 @@ func sockoptToProto(skopts *channelz.SocketOptionData) []*channelzpb.SocketOptio
|
|||
}
|
||||
if skopts.RecvTimeout != nil {
|
||||
additional, err := anypb.New(&channelzpb.SocketOptionTimeout{
|
||||
Duration: convertToPtypesDuration(int64(skopts.RecvTimeout.Sec), int64(skopts.RecvTimeout.Usec)),
|
||||
Duration: convertToPbDuration(int64(skopts.RecvTimeout.Sec), int64(skopts.RecvTimeout.Usec)),
|
||||
})
|
||||
if err == nil {
|
||||
opts = append(opts, &channelzpb.SocketOption{
|
||||
|
|
@ -66,7 +65,7 @@ func sockoptToProto(skopts *channelz.SocketOptionData) []*channelzpb.SocketOptio
|
|||
}
|
||||
if skopts.SendTimeout != nil {
|
||||
additional, err := anypb.New(&channelzpb.SocketOptionTimeout{
|
||||
Duration: convertToPtypesDuration(int64(skopts.SendTimeout.Sec), int64(skopts.SendTimeout.Usec)),
|
||||
Duration: convertToPbDuration(int64(skopts.SendTimeout.Sec), int64(skopts.SendTimeout.Usec)),
|
||||
})
|
||||
if err == nil {
|
||||
opts = append(opts, &channelzpb.SocketOption{
|
||||
|
|
|
|||
|
|
@ -21,10 +21,10 @@ package protoconv
|
|||
import (
|
||||
"time"
|
||||
|
||||
"github.com/golang/protobuf/ptypes"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/internal/channelz"
|
||||
"google.golang.org/grpc/status"
|
||||
"google.golang.org/protobuf/types/known/timestamppb"
|
||||
|
||||
channelzpb "google.golang.org/grpc/channelz/grpc_channelz_v1"
|
||||
)
|
||||
|
|
@ -40,7 +40,7 @@ func subChannelToProto(cm *channelz.SubChannel) *channelzpb.Subchannel {
|
|||
CallsSucceeded: cm.ChannelMetrics.CallsSucceeded.Load(),
|
||||
CallsFailed: cm.ChannelMetrics.CallsFailed.Load(),
|
||||
}
|
||||
if ts, err := ptypes.TimestampProto(time.Unix(0, cm.ChannelMetrics.LastCallStartedTimestamp.Load())); err == nil {
|
||||
if ts := timestamppb.New(time.Unix(0, cm.ChannelMetrics.LastCallStartedTimestamp.Load())); ts.IsValid() {
|
||||
sc.Data.LastCallStartedTimestamp = ts
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -27,15 +27,19 @@ import (
|
|||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/golang/protobuf/proto"
|
||||
"github.com/golang/protobuf/ptypes"
|
||||
"github.com/google/go-cmp/cmp"
|
||||
"google.golang.org/grpc/connectivity"
|
||||
"google.golang.org/grpc/credentials"
|
||||
"google.golang.org/grpc/grpclog"
|
||||
"google.golang.org/grpc/internal/channelz"
|
||||
"google.golang.org/grpc/internal/grpctest"
|
||||
"google.golang.org/protobuf/encoding/prototext"
|
||||
"google.golang.org/protobuf/reflect/protodesc"
|
||||
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
|
||||
"google.golang.org/protobuf/testing/protocmp"
|
||||
"google.golang.org/protobuf/types/descriptorpb"
|
||||
"google.golang.org/protobuf/types/dynamicpb"
|
||||
"google.golang.org/protobuf/types/known/anypb"
|
||||
"google.golang.org/protobuf/types/known/timestamppb"
|
||||
|
||||
channelzpb "google.golang.org/grpc/channelz/grpc_channelz_v1"
|
||||
|
|
@ -94,20 +98,6 @@ func convertSocketRefSliceToMap(sktRefs []*channelzpb.SocketRef) map[int64]strin
|
|||
return m
|
||||
}
|
||||
|
||||
type OtherSecurityValue struct {
|
||||
LocalCertificate []byte `protobuf:"bytes,1,opt,name=local_certificate,json=localCertificate,proto3" json:"local_certificate,omitempty"`
|
||||
RemoteCertificate []byte `protobuf:"bytes,2,opt,name=remote_certificate,json=remoteCertificate,proto3" json:"remote_certificate,omitempty"`
|
||||
}
|
||||
|
||||
func (m *OtherSecurityValue) Reset() { *m = OtherSecurityValue{} }
|
||||
func (m *OtherSecurityValue) String() string { return proto.CompactTextString(m) }
|
||||
func (*OtherSecurityValue) ProtoMessage() {}
|
||||
|
||||
func init() {
|
||||
// Ad-hoc registering the proto type here to facilitate UnmarshalAny of OtherSecurityValue.
|
||||
proto.RegisterType((*OtherSecurityValue)(nil), "grpc.credentials.OtherChannelzSecurityValue")
|
||||
}
|
||||
|
||||
func (s) TestGetTopChannels(t *testing.T) {
|
||||
tcs := []*channelz.ChannelMetrics{
|
||||
channelz.NewChannelMetricForTesting(
|
||||
|
|
@ -271,7 +261,7 @@ func (s) TestGetServerSockets(t *testing.T) {
|
|||
ids[2]: refNames[2],
|
||||
}
|
||||
if got := convertSocketRefSliceToMap(resp.GetSocketRef()); !cmp.Equal(got, want) {
|
||||
t.Fatalf("GetServerSockets want: %#v, got: %#v (resp=%v)", want, got, proto.MarshalTextString(resp))
|
||||
t.Fatalf("GetServerSockets want: %#v, got: %#v (resp=%v)", want, got, prototext.Format(resp))
|
||||
}
|
||||
|
||||
for i := 0; i < 50; i++ {
|
||||
|
|
@ -560,6 +550,47 @@ func newSocket(cs czSocket) *channelz.Socket {
|
|||
return s
|
||||
}
|
||||
|
||||
type OtherChannelzSecurityValue struct {
|
||||
LocalCertificate []byte `protobuf:"bytes,1,opt,name=local_certificate,json=localCertificate,proto3" json:"local_certificate,omitempty"`
|
||||
RemoteCertificate []byte `protobuf:"bytes,2,opt,name=remote_certificate,json=remoteCertificate,proto3" json:"remote_certificate,omitempty"`
|
||||
}
|
||||
|
||||
func (x *OtherChannelzSecurityValue) Reset() {
|
||||
*x = OtherChannelzSecurityValue{}
|
||||
}
|
||||
|
||||
func (x *OtherChannelzSecurityValue) String() string {
|
||||
return prototext.Format(x)
|
||||
}
|
||||
|
||||
func (*OtherChannelzSecurityValue) ProtoMessage() {}
|
||||
|
||||
func (x OtherChannelzSecurityValue) ProtoReflect() protoreflect.Message {
|
||||
const s = `
|
||||
name: "service_test.proto"
|
||||
syntax: "proto3"
|
||||
package: "grpc.credentials",
|
||||
message_type: [{
|
||||
name: "OtherChannelzSecurityValue"
|
||||
field: [
|
||||
{name:"local_certificate" number:1 type:TYPE_BYTES},
|
||||
{name:"remote_certificate" number:2 type:TYPE_BYTES}
|
||||
]
|
||||
}]
|
||||
`
|
||||
pb := new(descriptorpb.FileDescriptorProto)
|
||||
if err := prototext.Unmarshal([]byte(s), pb); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
fd, err := protodesc.NewFile(pb, nil)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
md := fd.Messages().Get(0)
|
||||
mt := dynamicpb.NewMessageType(md)
|
||||
return mt.New()
|
||||
}
|
||||
|
||||
func (s) TestGetSocket(t *testing.T) {
|
||||
ss := []*channelz.Socket{newSocket(czSocket{
|
||||
streamsStarted: 10,
|
||||
|
|
@ -622,12 +653,15 @@ func (s) TestGetSocket(t *testing.T) {
|
|||
},
|
||||
}), newSocket(czSocket{
|
||||
security: &credentials.OtherChannelzSecurityValue{
|
||||
Name: "YYYY",
|
||||
Value: &OtherSecurityValue{LocalCertificate: []byte{1, 2, 3}, RemoteCertificate: []byte{4, 5, 6}},
|
||||
Name: "YYYY",
|
||||
Value: OtherChannelzSecurityValue{
|
||||
LocalCertificate: []byte{1, 2, 3},
|
||||
RemoteCertificate: []byte{4, 5, 6},
|
||||
},
|
||||
},
|
||||
}),
|
||||
}
|
||||
otherSecVal, err := ptypes.MarshalAny(ss[6].Security.(*credentials.OtherChannelzSecurityValue).Value)
|
||||
otherSecVal, err := anypb.New(ss[6].Security.(*credentials.OtherChannelzSecurityValue).Value)
|
||||
if err != nil {
|
||||
t.Fatal("Error marshalling proto:", err)
|
||||
}
|
||||
|
|
@ -740,7 +774,7 @@ func (s) TestGetSocket(t *testing.T) {
|
|||
for i := range ss {
|
||||
resp, _ := svr.GetSocket(ctx, &channelzpb.GetSocketRequest{SocketId: skts[i].ID})
|
||||
w := &channelzpb.Socket{}
|
||||
if err := proto.UnmarshalText(want[i], w); err != nil {
|
||||
if err := prototext.Unmarshal([]byte(want[i]), w); err != nil {
|
||||
t.Fatalf("Error unmarshalling %q: %v", want[i], err)
|
||||
}
|
||||
if diff := cmp.Diff(resp.GetSocket(), w, protocmp.Transform()); diff != "" {
|
||||
|
|
@ -760,9 +794,9 @@ func escape(bs []byte) string {
|
|||
func addr(a net.Addr) string {
|
||||
switch a := a.(type) {
|
||||
case *net.TCPAddr:
|
||||
return string(a.IP)
|
||||
return escape([]byte(a.IP))
|
||||
case *net.IPAddr:
|
||||
return string(a.IP)
|
||||
return escape([]byte(a.IP))
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ import (
|
|||
|
||||
"google.golang.org/grpc/attributes"
|
||||
icredentials "google.golang.org/grpc/internal/credentials"
|
||||
"google.golang.org/protobuf/protoadapt"
|
||||
"google.golang.org/protobuf/proto"
|
||||
)
|
||||
|
||||
// PerRPCCredentials defines the common interface for the credentials which need to
|
||||
|
|
@ -287,5 +287,5 @@ type ChannelzSecurityValue interface {
|
|||
type OtherChannelzSecurityValue struct {
|
||||
ChannelzSecurityValue
|
||||
Name string
|
||||
Value protoadapt.MessageV1
|
||||
Value proto.Message
|
||||
}
|
||||
|
|
|
|||
4
vet.sh
4
vet.sh
|
|
@ -97,8 +97,8 @@ git grep -l 'interface{}' -- "*.go" 2>&1 | not grep -v '\.pb\.go\|protoc-gen-go-
|
|||
# - Do not call grpclog directly. Use grpclog.Component instead.
|
||||
git grep -l -e 'grpclog.I' --or -e 'grpclog.W' --or -e 'grpclog.E' --or -e 'grpclog.F' --or -e 'grpclog.V' -- "*.go" | not grep -v '^grpclog/component.go\|^internal/grpctest/tlogger_test.go'
|
||||
|
||||
# - Ensure all ptypes proto packages are renamed when importing.
|
||||
not git grep "\(import \|^\s*\)\"github.com/golang/protobuf/ptypes/" -- "*.go"
|
||||
# - Ensure that the deprecated protobuf dependency is not used.
|
||||
not git grep "\"github.com/golang/protobuf/*" -- "*.go" ':(exclude)reflection/grpc_testing_not_regenerate/*'
|
||||
|
||||
# - Ensure all usages of grpc_testing package are renamed when importing.
|
||||
not git grep "\(import \|^\s*\)\"google.golang.org/grpc/interop/grpc_testing" -- "*.go"
|
||||
|
|
|
|||
Loading…
Reference in New Issue