Skip to content

Commit

Permalink
deps: move from github.com/golang/protobuf to google.golang.org/proto…
Browse files Browse the repository at this point in the history
…buf/proto (#6919)

Co-authored-by: Arvind Bright <arvind.bright100@gmail.com>
Co-authored-by: Doug Fawley <dfawley@google.com>
  • Loading branch information
3 people authored Jan 30, 2024
1 parent 8d735f0 commit 02858ee
Show file tree
Hide file tree
Showing 68 changed files with 165 additions and 174 deletions.
2 changes: 1 addition & 1 deletion balancer/grpclb/grpclb.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ import (
"google.golang.org/grpc/internal/resolver/dns"
"google.golang.org/grpc/resolver"
"google.golang.org/grpc/resolver/manual"
"google.golang.org/protobuf/types/known/durationpb"

durationpb "github.com/golang/protobuf/ptypes/duration"
lbpb "google.golang.org/grpc/balancer/grpclb/grpc_lb_v1"
)

Expand Down
4 changes: 2 additions & 2 deletions balancer/grpclb/grpclb_remote_balancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (
"sync"
"time"

"github.com/golang/protobuf/proto"
"google.golang.org/grpc"
"google.golang.org/grpc/balancer"
"google.golang.org/grpc/connectivity"
Expand All @@ -36,8 +35,9 @@ import (
"google.golang.org/grpc/keepalive"
"google.golang.org/grpc/metadata"
"google.golang.org/grpc/resolver"
"google.golang.org/protobuf/proto"
"google.golang.org/protobuf/types/known/timestamppb"

timestamppb "github.com/golang/protobuf/ptypes/timestamp"
lbpb "google.golang.org/grpc/balancer/grpclb/grpc_lb_v1"
)

Expand Down
2 changes: 1 addition & 1 deletion balancer/grpclb/grpclb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ import (
"google.golang.org/grpc/resolver/manual"
"google.golang.org/grpc/serviceconfig"
"google.golang.org/grpc/status"
"google.golang.org/protobuf/types/known/durationpb"

durationpb "github.com/golang/protobuf/ptypes/duration"
lbgrpc "google.golang.org/grpc/balancer/grpclb/grpc_lb_v1"
lbpb "google.golang.org/grpc/balancer/grpclb/grpc_lb_v1"
testgrpc "google.golang.org/grpc/interop/grpc_testing"
Expand Down
5 changes: 2 additions & 3 deletions balancer/rls/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ import (
"net/url"
"time"

"github.com/golang/protobuf/ptypes"
durationpb "github.com/golang/protobuf/ptypes/duration"
"google.golang.org/grpc/balancer"
"google.golang.org/grpc/balancer/rls/internal/keys"
"google.golang.org/grpc/internal"
Expand All @@ -35,6 +33,7 @@ import (
"google.golang.org/grpc/resolver"
"google.golang.org/grpc/serviceconfig"
"google.golang.org/protobuf/encoding/protojson"
"google.golang.org/protobuf/types/known/durationpb"
)

const (
Expand Down Expand Up @@ -308,5 +307,5 @@ func convertDuration(d *durationpb.Duration) (time.Duration, error) {
if d == nil {
return 0, nil
}
return ptypes.Duration(d)
return d.AsDuration(), d.CheckValid()
}
2 changes: 1 addition & 1 deletion binarylog/binarylog_end2end_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import (
"testing"
"time"

"github.com/golang/protobuf/proto"
"google.golang.org/grpc"
"google.golang.org/grpc/binarylog"
"google.golang.org/grpc/codes"
Expand All @@ -39,6 +38,7 @@ import (
"google.golang.org/grpc/internal/stubserver"
"google.golang.org/grpc/metadata"
"google.golang.org/grpc/status"
"google.golang.org/protobuf/proto"

binlogpb "google.golang.org/grpc/binarylog/grpc_binarylog_v1"
testgrpc "google.golang.org/grpc/interop/grpc_testing"
Expand Down
2 changes: 1 addition & 1 deletion credentials/alts/alts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import (
"testing"
"time"

"github.com/golang/protobuf/proto"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/credentials/alts/internal/handshaker"
Expand All @@ -42,6 +41,7 @@ import (
testpb "google.golang.org/grpc/interop/grpc_testing"
"google.golang.org/grpc/peer"
"google.golang.org/grpc/status"
"google.golang.org/protobuf/proto"
)

const (
Expand Down
2 changes: 1 addition & 1 deletion encoding/proto/proto.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ package proto
import (
"fmt"

"github.com/golang/protobuf/proto"
"google.golang.org/grpc/encoding"
"google.golang.org/protobuf/proto"
)

// Name is the name registered for the proto compressor.
Expand Down
3 changes: 2 additions & 1 deletion encoding/proto/proto_benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ import (
"fmt"
"testing"

"github.com/golang/protobuf/proto"
"google.golang.org/grpc/encoding"
"google.golang.org/protobuf/proto"

pb "google.golang.org/grpc/test/codec_perf"
)

Expand Down
2 changes: 1 addition & 1 deletion examples/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ go 1.19

require (
github.com/cncf/xds/go v0.0.0-20231128003011-0fa0005c9caa
github.com/golang/protobuf v1.5.3
golang.org/x/oauth2 v0.16.0
google.golang.org/genproto/googleapis/rpc v0.0.0-20240123012728-ef4313101c80
google.golang.org/grpc v1.60.1
Expand All @@ -19,6 +18,7 @@ require (
github.com/cncf/udpa/go v0.0.0-20220112060539-c52dc94e7fbe // indirect
github.com/envoyproxy/go-control-plane v0.12.0 // indirect
github.com/envoyproxy/protoc-gen-validate v1.0.4 // indirect
github.com/golang/protobuf v1.5.3 // indirect
golang.org/x/net v0.20.0 // indirect
golang.org/x/sync v0.6.0 // indirect
golang.org/x/sys v0.16.0 // indirect
Expand Down
4 changes: 1 addition & 3 deletions examples/route_guide/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,9 @@ import (
"time"

"google.golang.org/grpc"

"google.golang.org/grpc/credentials"
"google.golang.org/grpc/examples/data"

"github.com/golang/protobuf/proto"
"google.golang.org/protobuf/proto"

pb "google.golang.org/grpc/examples/route_guide/routeguide"
)
Expand Down
9 changes: 5 additions & 4 deletions internal/binarylog/method_logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,12 @@ import (
"sync/atomic"
"time"

"github.com/golang/protobuf/proto"
"github.com/golang/protobuf/ptypes"
binlogpb "google.golang.org/grpc/binarylog/grpc_binarylog_v1"
"google.golang.org/grpc/metadata"
"google.golang.org/grpc/status"
"google.golang.org/protobuf/proto"
"google.golang.org/protobuf/types/known/durationpb"
"google.golang.org/protobuf/types/known/timestamppb"
)

type callIDGenerator struct {
Expand Down Expand Up @@ -88,7 +89,7 @@ func NewTruncatingMethodLogger(h, m uint64) *TruncatingMethodLogger {
// in TruncatingMethodLogger as possible.
func (ml *TruncatingMethodLogger) Build(c LogEntryConfig) *binlogpb.GrpcLogEntry {
m := c.toProto()
timestamp, _ := ptypes.TimestampProto(time.Now())
timestamp := timestamppb.Now()
m.Timestamp = timestamp
m.CallId = ml.callID
m.SequenceIdWithinCall = ml.idWithinCallGen.next()
Expand Down Expand Up @@ -178,7 +179,7 @@ func (c *ClientHeader) toProto() *binlogpb.GrpcLogEntry {
Authority: c.Authority,
}
if c.Timeout > 0 {
clientHeader.Timeout = ptypes.DurationProto(c.Timeout)
clientHeader.Timeout = durationpb.New(c.Timeout)
}
ret := &binlogpb.GrpcLogEntry{
Type: binlogpb.GrpcLogEntry_EVENT_TYPE_CLIENT_HEADER,
Expand Down
2 changes: 1 addition & 1 deletion internal/binarylog/method_logger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ import (
"testing"
"time"

"github.com/golang/protobuf/proto"
binlogpb "google.golang.org/grpc/binarylog/grpc_binarylog_v1"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"google.golang.org/protobuf/proto"
"google.golang.org/protobuf/types/known/durationpb"
)

Expand Down
2 changes: 1 addition & 1 deletion internal/binarylog/sink.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ import (
"sync"
"time"

"github.com/golang/protobuf/proto"
binlogpb "google.golang.org/grpc/binarylog/grpc_binarylog_v1"
"google.golang.org/protobuf/proto"
)

var (
Expand Down
7 changes: 3 additions & 4 deletions internal/pretty/pretty.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
"encoding/json"
"fmt"

"github.com/golang/protobuf/jsonpb"
protov1 "github.com/golang/protobuf/proto"
"google.golang.org/protobuf/encoding/protojson"
protov2 "google.golang.org/protobuf/proto"
Expand All @@ -38,15 +37,15 @@ const jsonIndent = " "
func ToJSON(e any) string {
switch ee := e.(type) {
case protov1.Message:
mm := jsonpb.Marshaler{Indent: jsonIndent}
ret, err := mm.MarshalToString(ee)
mm := protojson.MarshalOptions{Indent: jsonIndent}
ret, err := mm.Marshal(protov1.MessageV2(ee))
if err != nil {
// This may fail for proto.Anys, e.g. for xDS v2, LDS, the v2
// messages are not imported, and this will fail because the message
// is not found.
return fmt.Sprintf("%+v", ee)
}
return ret
return string(ret)
case protov2.Message:
mm := protojson.MarshalOptions{
Multiline: true,
Expand Down
15 changes: 8 additions & 7 deletions internal/status/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,11 @@ import (
"errors"
"fmt"

"github.com/golang/protobuf/proto"
"github.com/golang/protobuf/ptypes"
spb "google.golang.org/genproto/googleapis/rpc/status"
"google.golang.org/grpc/codes"
"google.golang.org/protobuf/proto"
"google.golang.org/protobuf/protoadapt"
"google.golang.org/protobuf/types/known/anypb"
)

// Status represents an RPC status code, message, and details. It is immutable
Expand Down Expand Up @@ -130,14 +131,14 @@ func (s *Status) Err() error {

// WithDetails returns a new status with the provided details messages appended to the status.
// If any errors are encountered, it returns nil and the first error encountered.
func (s *Status) WithDetails(details ...proto.Message) (*Status, error) {
func (s *Status) WithDetails(details ...protoadapt.MessageV1) (*Status, error) {
if s.Code() == codes.OK {
return nil, errors.New("no error details for status with code OK")
}
// s.Code() != OK implies that s.Proto() != nil.
p := s.Proto()
for _, detail := range details {
any, err := ptypes.MarshalAny(detail)
any, err := anypb.New(protoadapt.MessageV2Of(detail))
if err != nil {
return nil, err
}
Expand All @@ -154,12 +155,12 @@ func (s *Status) Details() []any {
}
details := make([]any, 0, len(s.s.Details))
for _, any := range s.s.Details {
detail := &ptypes.DynamicAny{}
if err := ptypes.UnmarshalAny(any, detail); err != nil {
detail, err := any.UnmarshalNew()
if err != nil {
details = append(details, err)
continue
}
details = append(details, detail.Message)
details = append(details, detail)
}
return details
}
Expand Down
5 changes: 2 additions & 3 deletions internal/testutils/marshal_any.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ package testutils
import (
"testing"

"github.com/golang/protobuf/proto"
"google.golang.org/protobuf/protoadapt"
"google.golang.org/protobuf/proto"
"google.golang.org/protobuf/types/known/anypb"
)

Expand All @@ -30,7 +29,7 @@ import (
func MarshalAny(t *testing.T, m proto.Message) *anypb.Any {
t.Helper()

a, err := anypb.New(protoadapt.MessageV2Of(m))
a, err := anypb.New(m)
if err != nil {
t.Fatalf("Failed to marshal proto %+v into an Any: %v", m, err)
}
Expand Down
2 changes: 1 addition & 1 deletion internal/testutils/status_equal.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
package testutils

import (
"github.com/golang/protobuf/proto"
"google.golang.org/grpc/status"
"google.golang.org/protobuf/proto"
)

// StatusErrEqual returns true iff both err1 and err2 wrap status.Status errors
Expand Down
2 changes: 1 addition & 1 deletion internal/testutils/status_equal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ package testutils
import (
"testing"

anypb "github.com/golang/protobuf/ptypes/any"
spb "google.golang.org/genproto/googleapis/rpc/status"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/internal/grpctest"
"google.golang.org/grpc/status"
"google.golang.org/protobuf/types/known/anypb"
)

type s struct {
Expand Down
8 changes: 3 additions & 5 deletions internal/testutils/xds/e2e/clientresources.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,10 @@ import (
"net"
"strconv"

"google.golang.org/protobuf/protoadapt"

"github.com/envoyproxy/go-control-plane/pkg/wellknown"
"github.com/golang/protobuf/proto"
"google.golang.org/protobuf/proto"
"google.golang.org/protobuf/types/known/anypb"
"google.golang.org/protobuf/types/known/wrapperspb"

v3clusterpb "github.com/envoyproxy/go-control-plane/envoy/config/cluster/v3"
v3corepb "github.com/envoyproxy/go-control-plane/envoy/config/core/v3"
Expand All @@ -39,7 +38,6 @@ import (
v3httppb "github.com/envoyproxy/go-control-plane/envoy/extensions/filters/network/http_connection_manager/v3"
v3tlspb "github.com/envoyproxy/go-control-plane/envoy/extensions/transport_sockets/tls/v3"
v3typepb "github.com/envoyproxy/go-control-plane/envoy/type/v3"
wrapperspb "github.com/golang/protobuf/ptypes/wrappers"
)

const (
Expand Down Expand Up @@ -130,7 +128,7 @@ func DefaultClientListener(target, routeName string) *v3listenerpb.Listener {
}

func marshalAny(m proto.Message) *anypb.Any {
a, err := anypb.New(protoadapt.MessageV2Of(m))
a, err := anypb.New(m)
if err != nil {
panic(fmt.Sprintf("anypb.New(%+v) failed: %v", m, err))
}
Expand Down
2 changes: 1 addition & 1 deletion internal/testutils/xds/fakeserver/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ import (
"net"
"time"

"github.com/golang/protobuf/proto"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/internal/testutils"
"google.golang.org/grpc/status"
"google.golang.org/protobuf/proto"

v3discoverygrpc "github.com/envoyproxy/go-control-plane/envoy/service/discovery/v3"
v3discoverypb "github.com/envoyproxy/go-control-plane/envoy/service/discovery/v3"
Expand Down
2 changes: 1 addition & 1 deletion internal/transport/handler_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ import (
"sync"
"time"

"github.com/golang/protobuf/proto"
"golang.org/x/net/http2"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/credentials"
Expand All @@ -45,6 +44,7 @@ import (
"google.golang.org/grpc/peer"
"google.golang.org/grpc/stats"
"google.golang.org/grpc/status"
"google.golang.org/protobuf/proto"
)

// NewServerHandlerTransport returns a ServerTransport handling gRPC from
Expand Down
Loading

0 comments on commit 02858ee

Please sign in to comment.