@@ -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
4242func init () {
@@ -82,18 +82,14 @@ func connectivityStateToProto(s connectivity.State) *channelzpb.ChannelConnectiv
8282func 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 })
0 commit comments