Skip to content

Use 'google.golang.org/protobuf' instead of 'github.com/golang/protobuf/' as much as possible #7004

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions channelz/service/func_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,14 @@ package service
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 convertToPtypesDuration(sec int64, usec int64) *durationpb.Duration {
return durationpb.New(time.Duration(sec*1e9 + usec*1e3))
}

func sockoptToProto(skopts *channelz.SocketOptionData) []*channelzpb.SocketOption {
Expand Down
44 changes: 13 additions & 31 deletions channelz/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ import (
"context"
"net"

"github.com/golang/protobuf/ptypes"
wrpb "github.com/golang/protobuf/ptypes/wrappers"
channelzgrpc "google.golang.org/grpc/channelz/grpc_channelz_v1"
channelzpb "google.golang.org/grpc/channelz/grpc_channelz_v1"

Expand All @@ -37,6 +35,8 @@ import (
"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"
)

func init() {
Expand Down Expand Up @@ -82,18 +82,14 @@ func connectivityStateToProto(s connectivity.State) *channelzpb.ChannelConnectiv
func channelTraceToProto(ct *channelz.ChannelTrace) *channelzpb.ChannelTrace {
pbt := &channelzpb.ChannelTrace{}
pbt.NumEventsLogged = ct.EventNum
if ts, err := ptypes.TimestampProto(ct.CreationTime); err == nil {
pbt.CreationTimestamp = ts
}
pbt.CreationTimestamp = timestamppb.New(ct.CreationTime)
events := make([]*channelzpb.ChannelTraceEvent, 0, len(ct.Events))
for _, e := range ct.Events {
cte := &channelzpb.ChannelTraceEvent{
Description: e.Desc,
Severity: channelzpb.ChannelTraceEvent_Severity(e.Severity),
}
if ts, err := ptypes.TimestampProto(e.Timestamp); err == nil {
cte.Timestamp = ts
}
cte.Timestamp = timestamppb.New(e.Timestamp)
if e.RefID != 0 {
switch e.RefType {
case channelz.RefChannel:
Expand All @@ -119,9 +115,7 @@ func channelMetricToProto(cm *channelz.ChannelMetric) *channelzpb.Channel {
CallsSucceeded: cm.ChannelData.CallsSucceeded,
CallsFailed: cm.ChannelData.CallsFailed,
}
if ts, err := ptypes.TimestampProto(cm.ChannelData.LastCallStartedTimestamp); err == nil {
c.Data.LastCallStartedTimestamp = ts
}
c.Data.LastCallStartedTimestamp = timestamppb.New(cm.ChannelData.LastCallStartedTimestamp)
nestedChans := make([]*channelzpb.ChannelRef, 0, len(cm.NestedChans))
for id, ref := range cm.NestedChans {
nestedChans = append(nestedChans, &channelzpb.ChannelRef{ChannelId: id, Name: ref})
Expand Down Expand Up @@ -154,9 +148,7 @@ func subChannelMetricToProto(cm *channelz.SubChannelMetric) *channelzpb.Subchann
CallsSucceeded: cm.ChannelData.CallsSucceeded,
CallsFailed: cm.ChannelData.CallsFailed,
}
if ts, err := ptypes.TimestampProto(cm.ChannelData.LastCallStartedTimestamp); err == nil {
sc.Data.LastCallStartedTimestamp = ts
}
sc.Data.LastCallStartedTimestamp = timestamppb.New(cm.ChannelData.LastCallStartedTimestamp)
nestedChans := make([]*channelzpb.ChannelRef, 0, len(cm.NestedChans))
for id, ref := range cm.NestedChans {
nestedChans = append(nestedChans, &channelzpb.ChannelRef{ChannelId: id, Name: ref})
Expand Down Expand Up @@ -230,20 +222,12 @@ func socketMetricToProto(sm *channelz.SocketMetric) *channelzpb.Socket {
MessagesReceived: sm.SocketData.MessagesReceived,
KeepAlivesSent: sm.SocketData.KeepAlivesSent,
}
if ts, err := ptypes.TimestampProto(sm.SocketData.LastLocalStreamCreatedTimestamp); err == nil {
s.Data.LastLocalStreamCreatedTimestamp = ts
}
if ts, err := ptypes.TimestampProto(sm.SocketData.LastRemoteStreamCreatedTimestamp); err == nil {
s.Data.LastRemoteStreamCreatedTimestamp = ts
}
if ts, err := ptypes.TimestampProto(sm.SocketData.LastMessageSentTimestamp); err == nil {
s.Data.LastMessageSentTimestamp = ts
}
if ts, err := ptypes.TimestampProto(sm.SocketData.LastMessageReceivedTimestamp); err == nil {
s.Data.LastMessageReceivedTimestamp = ts
}
s.Data.LocalFlowControlWindow = &wrpb.Int64Value{Value: sm.SocketData.LocalFlowControlWindow}
s.Data.RemoteFlowControlWindow = &wrpb.Int64Value{Value: sm.SocketData.RemoteFlowControlWindow}
s.Data.LastLocalStreamCreatedTimestamp = timestamppb.New(sm.SocketData.LastLocalStreamCreatedTimestamp)
s.Data.LastRemoteStreamCreatedTimestamp = timestamppb.New(sm.SocketData.LastRemoteStreamCreatedTimestamp)
s.Data.LastMessageSentTimestamp = timestamppb.New(sm.SocketData.LastMessageSentTimestamp)
s.Data.LastMessageReceivedTimestamp = timestamppb.New(sm.SocketData.LastMessageReceivedTimestamp)
s.Data.LocalFlowControlWindow = &wrapperspb.Int64Value{Value: sm.SocketData.LocalFlowControlWindow}
s.Data.RemoteFlowControlWindow = &wrapperspb.Int64Value{Value: sm.SocketData.RemoteFlowControlWindow}

if sm.SocketData.SocketOptions != nil {
s.Data.Option = sockoptToProto(sm.SocketData.SocketOptions)
Expand Down Expand Up @@ -282,9 +266,7 @@ func serverMetricToProto(sm *channelz.ServerMetric) *channelzpb.Server {
CallsFailed: sm.ServerData.CallsFailed,
}

if ts, err := ptypes.TimestampProto(sm.ServerData.LastCallStartedTimestamp); err == nil {
s.Data.LastCallStartedTimestamp = ts
}
s.Data.LastCallStartedTimestamp = timestamppb.New(sm.ServerData.LastCallStartedTimestamp)
sockets := make([]*channelzpb.SocketRef, 0, len(sm.ListenSockets))
for id, ref := range sm.ListenSockets {
sockets = append(sockets, &channelzpb.SocketRef{SocketId: id, Name: ref})
Expand Down
11 changes: 5 additions & 6 deletions channelz/service/service_sktopt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ import (
"google.golang.org/grpc/internal/channelz"
"google.golang.org/protobuf/testing/protocmp"

durpb "github.com/golang/protobuf/ptypes/duration"
channelzpb "google.golang.org/grpc/channelz/grpc_channelz_v1"
"google.golang.org/protobuf/types/known/durationpb"
)

func init() {
Expand All @@ -47,12 +47,11 @@ func init() {
protoToSocketOpt = protoToSocketOption
}

func convertToDuration(d *durpb.Duration) (sec int64, usec int64) {
func convertToDuration(d *durationpb.Duration) (sec int64, usec int64) {
if d != nil {
if dur, err := ptypes.Duration(d); err == nil {
sec = int64(int64(dur) / 1e9)
usec = (int64(dur) - sec*1e9) / 1e3
}
dur := d.AsDuration()
sec = int64(int64(dur) / 1e9)
usec = (int64(dur) - sec*1e9) / 1e3
}
return
}
Expand Down
8 changes: 4 additions & 4 deletions xds/internal/xdsclient/bootstrap/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import (
"strings"

v3corepb "github.com/envoyproxy/go-control-plane/envoy/config/core/v3"
"github.com/golang/protobuf/jsonpb"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials"
"google.golang.org/grpc/credentials/google"
Expand All @@ -40,6 +39,7 @@ import (
"google.golang.org/grpc/internal/pretty"
"google.golang.org/grpc/xds/bootstrap"
"google.golang.org/grpc/xds/internal/xdsclient/tlscreds"
"google.golang.org/protobuf/encoding/protojson"
)

const (
Expand Down Expand Up @@ -470,13 +470,13 @@ func newConfigFromContents(data []byte) (*Config, error) {
}

var node *v3corepb.Node
m := jsonpb.Unmarshaler{AllowUnknownFields: true}
m := protojson.UnmarshalOptions{DiscardUnknown: true}
for k, v := range jsonData {
switch k {
case "node":
node = &v3corepb.Node{}
if err := m.Unmarshal(bytes.NewReader(v), node); err != nil {
return nil, fmt.Errorf("xds: jsonpb.Unmarshal(%v) for field %q failed during bootstrap: %v", string(v), k, err)
if err := m.Unmarshal(v, node); err != nil {
return nil, fmt.Errorf("xds: protojson.Unmarshal(%v) for field %q failed during bootstrap: %v", string(v), k, err)
}
case "xds_servers":
servers, err := unmarshalJSONServerConfigSlice(v)
Expand Down