Skip to content

Commit a2240db

Browse files
committed
Use 'google.golang.org/protobuf' instead of 'github.com/golang/protobuf/' as much as possible
Signed-off-by: Matthieu MOREL <[email protected]>
1 parent 5ccf176 commit a2240db

File tree

4 files changed

+25
-45
lines changed

4 files changed

+25
-45
lines changed

channelz/service/func_linux.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,14 @@ package service
2121
import (
2222
"time"
2323

24-
"github.com/golang/protobuf/ptypes"
25-
durpb "github.com/golang/protobuf/ptypes/duration"
2624
channelzpb "google.golang.org/grpc/channelz/grpc_channelz_v1"
2725
"google.golang.org/grpc/internal/channelz"
2826
"google.golang.org/protobuf/types/known/anypb"
27+
"google.golang.org/protobuf/types/known/durationpb"
2928
)
3029

31-
func convertToPtypesDuration(sec int64, usec int64) *durpb.Duration {
32-
return ptypes.DurationProto(time.Duration(sec*1e9 + usec*1e3))
30+
func convertToPtypesDuration(sec int64, usec int64) *durationpb.Duration {
31+
return durationpb.New(time.Duration(sec*1e9 + usec*1e3))
3332
}
3433

3534
func sockoptToProto(skopts *channelz.SocketOptionData) []*channelzpb.SocketOption {

channelz/service/service.go

Lines changed: 13 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@ import (
2323
"context"
2424
"net"
2525

26-
"github.com/golang/protobuf/ptypes"
27-
wrpb "github.com/golang/protobuf/ptypes/wrappers"
2826
channelzgrpc "google.golang.org/grpc/channelz/grpc_channelz_v1"
2927
channelzpb "google.golang.org/grpc/channelz/grpc_channelz_v1"
3028

@@ -37,6 +35,8 @@ import (
3735
"google.golang.org/grpc/status"
3836
"google.golang.org/protobuf/protoadapt"
3937
"google.golang.org/protobuf/types/known/anypb"
38+
"google.golang.org/protobuf/types/known/timestamppb"
39+
"google.golang.org/protobuf/types/known/wrapperspb"
4040
)
4141

4242
func init() {
@@ -82,18 +82,14 @@ func connectivityStateToProto(s connectivity.State) *channelzpb.ChannelConnectiv
8282
func channelTraceToProto(ct *channelz.ChannelTrace) *channelzpb.ChannelTrace {
8383
pbt := &channelzpb.ChannelTrace{}
8484
pbt.NumEventsLogged = ct.EventNum
85-
if ts, err := ptypes.TimestampProto(ct.CreationTime); err == nil {
86-
pbt.CreationTimestamp = ts
87-
}
85+
pbt.CreationTimestamp = timestamppb.New(ct.CreationTime)
8886
events := make([]*channelzpb.ChannelTraceEvent, 0, len(ct.Events))
8987
for _, e := range ct.Events {
9088
cte := &channelzpb.ChannelTraceEvent{
9189
Description: e.Desc,
9290
Severity: channelzpb.ChannelTraceEvent_Severity(e.Severity),
9391
}
94-
if ts, err := ptypes.TimestampProto(e.Timestamp); err == nil {
95-
cte.Timestamp = ts
96-
}
92+
cte.Timestamp = timestamppb.New(e.Timestamp)
9793
if e.RefID != 0 {
9894
switch e.RefType {
9995
case channelz.RefChannel:
@@ -119,9 +115,7 @@ func channelMetricToProto(cm *channelz.ChannelMetric) *channelzpb.Channel {
119115
CallsSucceeded: cm.ChannelData.CallsSucceeded,
120116
CallsFailed: cm.ChannelData.CallsFailed,
121117
}
122-
if ts, err := ptypes.TimestampProto(cm.ChannelData.LastCallStartedTimestamp); err == nil {
123-
c.Data.LastCallStartedTimestamp = ts
124-
}
118+
c.Data.LastCallStartedTimestamp = timestamppb.New(cm.ChannelData.LastCallStartedTimestamp)
125119
nestedChans := make([]*channelzpb.ChannelRef, 0, len(cm.NestedChans))
126120
for id, ref := range cm.NestedChans {
127121
nestedChans = append(nestedChans, &channelzpb.ChannelRef{ChannelId: id, Name: ref})
@@ -154,9 +148,7 @@ func subChannelMetricToProto(cm *channelz.SubChannelMetric) *channelzpb.Subchann
154148
CallsSucceeded: cm.ChannelData.CallsSucceeded,
155149
CallsFailed: cm.ChannelData.CallsFailed,
156150
}
157-
if ts, err := ptypes.TimestampProto(cm.ChannelData.LastCallStartedTimestamp); err == nil {
158-
sc.Data.LastCallStartedTimestamp = ts
159-
}
151+
sc.Data.LastCallStartedTimestamp = timestamppb.New(cm.ChannelData.LastCallStartedTimestamp)
160152
nestedChans := make([]*channelzpb.ChannelRef, 0, len(cm.NestedChans))
161153
for id, ref := range cm.NestedChans {
162154
nestedChans = append(nestedChans, &channelzpb.ChannelRef{ChannelId: id, Name: ref})
@@ -230,20 +222,12 @@ func socketMetricToProto(sm *channelz.SocketMetric) *channelzpb.Socket {
230222
MessagesReceived: sm.SocketData.MessagesReceived,
231223
KeepAlivesSent: sm.SocketData.KeepAlivesSent,
232224
}
233-
if ts, err := ptypes.TimestampProto(sm.SocketData.LastLocalStreamCreatedTimestamp); err == nil {
234-
s.Data.LastLocalStreamCreatedTimestamp = ts
235-
}
236-
if ts, err := ptypes.TimestampProto(sm.SocketData.LastRemoteStreamCreatedTimestamp); err == nil {
237-
s.Data.LastRemoteStreamCreatedTimestamp = ts
238-
}
239-
if ts, err := ptypes.TimestampProto(sm.SocketData.LastMessageSentTimestamp); err == nil {
240-
s.Data.LastMessageSentTimestamp = ts
241-
}
242-
if ts, err := ptypes.TimestampProto(sm.SocketData.LastMessageReceivedTimestamp); err == nil {
243-
s.Data.LastMessageReceivedTimestamp = ts
244-
}
245-
s.Data.LocalFlowControlWindow = &wrpb.Int64Value{Value: sm.SocketData.LocalFlowControlWindow}
246-
s.Data.RemoteFlowControlWindow = &wrpb.Int64Value{Value: sm.SocketData.RemoteFlowControlWindow}
225+
s.Data.LastLocalStreamCreatedTimestamp = timestamppb.New(sm.SocketData.LastLocalStreamCreatedTimestamp)
226+
s.Data.LastRemoteStreamCreatedTimestamp = timestamppb.New(sm.SocketData.LastRemoteStreamCreatedTimestamp)
227+
s.Data.LastMessageSentTimestamp = timestamppb.New(sm.SocketData.LastMessageSentTimestamp)
228+
s.Data.LastMessageReceivedTimestamp = timestamppb.New(sm.SocketData.LastMessageReceivedTimestamp)
229+
s.Data.LocalFlowControlWindow = &wrapperspb.Int64Value{Value: sm.SocketData.LocalFlowControlWindow}
230+
s.Data.RemoteFlowControlWindow = &wrapperspb.Int64Value{Value: sm.SocketData.RemoteFlowControlWindow}
247231

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

285-
if ts, err := ptypes.TimestampProto(sm.ServerData.LastCallStartedTimestamp); err == nil {
286-
s.Data.LastCallStartedTimestamp = ts
287-
}
269+
s.Data.LastCallStartedTimestamp = timestamppb.New(sm.ServerData.LastCallStartedTimestamp)
288270
sockets := make([]*channelzpb.SocketRef, 0, len(sm.ListenSockets))
289271
for id, ref := range sm.ListenSockets {
290272
sockets = append(sockets, &channelzpb.SocketRef{SocketId: id, Name: ref})

channelz/service/service_sktopt_test.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ import (
3737
"google.golang.org/grpc/internal/channelz"
3838
"google.golang.org/protobuf/testing/protocmp"
3939

40-
durpb "github.com/golang/protobuf/ptypes/duration"
4140
channelzpb "google.golang.org/grpc/channelz/grpc_channelz_v1"
41+
"google.golang.org/protobuf/types/known/durationpb"
4242
)
4343

4444
func init() {
@@ -47,12 +47,11 @@ func init() {
4747
protoToSocketOpt = protoToSocketOption
4848
}
4949

50-
func convertToDuration(d *durpb.Duration) (sec int64, usec int64) {
50+
func convertToDuration(d *durationpb.Duration) (sec int64, usec int64) {
5151
if d != nil {
52-
if dur, err := ptypes.Duration(d); err == nil {
53-
sec = int64(int64(dur) / 1e9)
54-
usec = (int64(dur) - sec*1e9) / 1e3
55-
}
52+
dur := d.AsDuration()
53+
sec = int64(int64(dur) / 1e9)
54+
usec = (int64(dur) - sec*1e9) / 1e3
5655
}
5756
return
5857
}

xds/internal/xdsclient/bootstrap/bootstrap.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ import (
2929
"strings"
3030

3131
v3corepb "github.com/envoyproxy/go-control-plane/envoy/config/core/v3"
32-
"github.com/golang/protobuf/jsonpb"
3332
"google.golang.org/grpc"
3433
"google.golang.org/grpc/credentials"
3534
"google.golang.org/grpc/credentials/google"
@@ -40,6 +39,7 @@ import (
4039
"google.golang.org/grpc/internal/pretty"
4140
"google.golang.org/grpc/xds/bootstrap"
4241
"google.golang.org/grpc/xds/internal/xdsclient/tlscreds"
42+
"google.golang.org/protobuf/encoding/protojson"
4343
)
4444

4545
const (
@@ -470,13 +470,13 @@ func newConfigFromContents(data []byte) (*Config, error) {
470470
}
471471

472472
var node *v3corepb.Node
473-
m := jsonpb.Unmarshaler{AllowUnknownFields: true}
473+
m := protojson.UnmarshalOptions{DiscardUnknown: true}
474474
for k, v := range jsonData {
475475
switch k {
476476
case "node":
477477
node = &v3corepb.Node{}
478-
if err := m.Unmarshal(bytes.NewReader(v), node); err != nil {
479-
return nil, fmt.Errorf("xds: jsonpb.Unmarshal(%v) for field %q failed during bootstrap: %v", string(v), k, err)
478+
if err := m.Unmarshal(v, node); err != nil {
479+
return nil, fmt.Errorf("xds: protojson.Unmarshal(%v) for field %q failed during bootstrap: %v", string(v), k, err)
480480
}
481481
case "xds_servers":
482482
servers, err := unmarshalJSONServerConfigSlice(v)

0 commit comments

Comments
 (0)