Skip to content
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

deps: move from github.com/golang/protobuf to google.golang.org/protobuf/proto #6919

Merged
merged 37 commits into from Jan 30, 2024
Merged
Show file tree
Hide file tree
Changes from 29 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
da3facf
move from github.com/golang/protobuf to google.golang.org/protobuf/proto
Clement-Jean Oct 18, 2023
406e577
durationpb.New
Clement-Jean Oct 18, 2023
ebdb1c4
rename convertToDuration to durationToSecUsec
Clement-Jean Oct 18, 2023
a3f426c
refactor durationToSecUsec
Clement-Jean Oct 18, 2023
d64177a
use durationToSecUsec
Clement-Jean Oct 18, 2023
304731b
refactor durationToSecUsec
Clement-Jean Oct 18, 2023
fa6e930
Simplify CheckValid
Clement-Jean Oct 20, 2023
949ef0f
nix newlines
Clement-Jean Oct 20, 2023
60e45ed
tidy
Clement-Jean Oct 21, 2023
9b220f9
tidy
Clement-Jean Oct 21, 2023
f58f647
revert changes in channelz
Clement-Jean Nov 4, 2023
54e1afb
add compatibility test for status
Clement-Jean Nov 4, 2023
e7e8143
Merge branch 'master' into remove_old_proto_pkg
Clement-Jean Nov 4, 2023
e6c2829
remove unused imports
Clement-Jean Nov 4, 2023
3123478
add copyright
Clement-Jean Nov 4, 2023
34b7bf8
add newline at EOF
Clement-Jean Nov 4, 2023
47c76ef
move from github.com/golang/protobuf to google.golang.org/protobuf/proto
Clement-Jean Oct 18, 2023
69fd411
durationpb.New
Clement-Jean Oct 18, 2023
83b6619
rename convertToDuration to durationToSecUsec
Clement-Jean Oct 18, 2023
2a0052d
refactor durationToSecUsec
Clement-Jean Oct 18, 2023
3dcd777
use durationToSecUsec
Clement-Jean Oct 18, 2023
28634a4
refactor durationToSecUsec
Clement-Jean Oct 18, 2023
9c948d0
Simplify CheckValid
Clement-Jean Oct 20, 2023
58ad782
revert changes in channelz
Clement-Jean Nov 4, 2023
126c055
get up to date bootstrap.go
Clement-Jean Jan 11, 2024
f048283
tidy
Clement-Jean Jan 11, 2024
92f0721
add sum file
Clement-Jean Jan 11, 2024
b9e8c68
fix: imported more than once error
Clement-Jean Jan 11, 2024
6683fac
Merge branch 'grpc:master' into remove_old_proto_pkg
Clement-Jean Jan 12, 2024
c784e0a
WithDetails taking protoadapt.MessageV1
Clement-Jean Jan 15, 2024
8024719
Merge remote-tracking branch 'refs/remotes/origin/remove_old_proto_pk…
Clement-Jean Jan 15, 2024
4dd29b8
Merge branch 'master' into remove_old_proto_pkg
Clement-Jean Jan 23, 2024
3ad5b8f
rm unused import
Clement-Jean Jan 23, 2024
787304b
rm whitespace
Clement-Jean Jan 23, 2024
a3da2fc
Merge branch 'master' into remove_old_proto_pkg
dfawley Jan 23, 2024
ef83599
fix format
dfawley Jan 24, 2024
b837411
resolve conflicts and add changes
Clement-Jean Jan 26, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion balancer/grpclb/grpclb.go
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
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
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
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
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
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 @@ -41,6 +40,7 @@ import (
testgrpc "google.golang.org/grpc/interop/grpc_testing"
testpb "google.golang.org/grpc/interop/grpc_testing"
"google.golang.org/grpc/status"
"google.golang.org/protobuf/proto"
)

const (
Expand Down
2 changes: 1 addition & 1 deletion encoding/proto/proto.go
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
2 changes: 1 addition & 1 deletion encoding/proto/proto_benchmark_test.go
Expand Up @@ -22,9 +22,9 @@ import (
"fmt"
"testing"

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

func setupBenchmarkProtoCodecInputs(payloadBaseSize uint32) []proto.Message {
Expand Down
2 changes: 1 addition & 1 deletion examples/go.mod
Expand Up @@ -4,7 +4,6 @@ go 1.19

require (
github.com/cncf/xds/go v0.0.0-20231109132714-523115ebc101
github.com/golang/protobuf v1.5.3
golang.org/x/oauth2 v0.14.0
google.golang.org/genproto/googleapis/rpc v0.0.0-20231106174013-bbf56f31fb17
google.golang.org/grpc v1.59.0
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.11.1 // indirect
github.com/envoyproxy/protoc-gen-validate v1.0.2 // indirect
github.com/golang/protobuf v1.5.3 // indirect
golang.org/x/net v0.18.0 // indirect
golang.org/x/sync v0.5.0 // indirect
golang.org/x/sys v0.14.0 // indirect
Expand Down
4 changes: 1 addition & 3 deletions examples/route_guide/server/server.go
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
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
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
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
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
12 changes: 6 additions & 6 deletions internal/status/status.go
Expand Up @@ -31,10 +31,10 @@ 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"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From the previous PR: I'm still fairly sure this is a breaking API change.

The function WithDetails needs to now accept a protoadapt.MessageV1 now instead of a proto.Message, because the new package's proto.Message is incompatible with the old one.

This would impact anyone using proto messages generated by some other tool, like (IIUC) gogoproto. Or possibly(?) using a message generated by an old protoc-gen-go.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Clement-Jean -- This seems to be still unresolved?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Weird. It was fixed in this commit but now it's been reverted...

c784e0a (#6919)

"google.golang.org/protobuf/types/known/anypb"
)

// Status represents an RPC status code, message, and details. It is immutable
Expand Down Expand Up @@ -137,7 +137,7 @@ func (s *Status) WithDetails(details ...proto.Message) (*Status, error) {
// s.Code() != OK implies that s.Proto() != nil.
p := s.Proto()
for _, detail := range details {
any, err := ptypes.MarshalAny(detail)
any, err := anypb.New(detail)
if err != nil {
return nil, err
}
Expand All @@ -154,12 +154,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
73 changes: 73 additions & 0 deletions internal/status/status_test.go
@@ -0,0 +1,73 @@
/*
*
* Copyright 2023 gRPC authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

package status

import (
"testing"

"github.com/golang/protobuf/ptypes"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/internal/grpctest"
"google.golang.org/protobuf/reflect/protoreflect"
"google.golang.org/protobuf/types/known/timestamppb"

protoV1 "github.com/golang/protobuf/proto"
)

type s struct {
grpctest.Tester
}

func Test(t *testing.T) {
grpctest.RunSubTests(t, s{})
}

func (s) TestWithDetailsVersionsCompat(t *testing.T) {
details := []protoreflect.ProtoMessage{ // Create with old ptypes and new tspb
ptypes.TimestampNow(),
&timestamppb.Timestamp{},
}
status := New(codes.InvalidArgument, "an error")

if _, err := status.WithDetails(details...); err != nil {
t.Fatal(err)
}
}

func (s) TestDetailsVersionsCompat(t *testing.T) {
details := []protoreflect.ProtoMessage{ // Create with old ptypes and new tspb
ptypes.TimestampNow(),
timestamppb.Now(),
}
status := New(codes.InvalidArgument, "an error")
status, err := status.WithDetails(details...)

if err != nil {
t.Fatal(err)
}

for _, detail := range status.Details() {
if _, ok := detail.(protoV1.Message); !ok {
t.Fatalf("detail with type %T is not a protoV1.Message", detail)
}
if _, ok := detail.(*timestamppb.Timestamp); !ok {
t.Fatalf("detail with type %T is not a timestamppb.Timestamp", detail)
}
}
}
5 changes: 2 additions & 3 deletions internal/testutils/marshal_any.go
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
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
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