Skip to content

move from github.com/golang/protobuf to google.golang.org/protobuf/proto #6736

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 16 commits into from
Closed

move from github.com/golang/protobuf to google.golang.org/protobuf/proto #6736

wants to merge 16 commits into from

Conversation

Clement-Jean
Copy link
Contributor

@Clement-Jean Clement-Jean commented Oct 18, 2023

This is the first step of solving the issue #5316

RELEASE NOTES: none

@codecov
Copy link

codecov bot commented Oct 18, 2023

Codecov Report

Merging #6736 (34b7bf8) into master (70f1a40) will decrease coverage by 0.15%.
The diff coverage is 62.06%.

Additional details and impacted files

@Clement-Jean
Copy link
Contributor Author

@dfawley I'm not sure I understand the test failing. Could you guide me through it?

@arvindbr8
Copy link
Member

arvindbr8 commented Oct 19, 2023

@Clement-Jean another push after go mod tidy should make vet happy. The codecov/patch is not a blocking code coverage check, so I wouldn't worry about that too much for this change.

Copy link
Member

@arvindbr8 arvindbr8 left a comment

Choose a reason for hiding this comment

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

Thanks for the PR! One question tho: A quick grep showed the following as the only remaining non .pb.go usages of github.com/golang/protobuf.

channelz/service/service_test.go
credentials/credentials.go
internal/pretty/pretty.go

Was the plan to remove the usages in a future PR? The first 2 in the list seem pretty small enough to add to this PR -- which makes us more confident to remove protov1 from pretty/pretty.go

d.CheckValid() already does the nil check

Co-authored-by: Arvind Bright <arvind.bright100@gmail.com>
@Clement-Jean
Copy link
Contributor Author

For now, as per @dfawley, the plan is to keep service_test.go as is (issue #5316). This means that credentials.go cannot be updated, and I made the judgment call to keep pretty.go as is because of this. Hope that's ok.

Finally, go mod tidy doesn't seem to do anything so the vet.sh is still not working.

@arvindbr8 arvindbr8 added the Type: Dependencies Updating/adding/removing dependencies label Oct 20, 2023
@arvindbr8 arvindbr8 added this to the 1.60 Release milestone Oct 20, 2023
@arvindbr8
Copy link
Member

arvindbr8 commented Oct 20, 2023

Sorry, i should have been more specific. vet failed in the examples/ dir, so you'd have to run go mod tidy after cd ing to examples/ directory.

You can also do VET_SKIP_PROTO=1 ./vet.sh to run vet in local.

@Clement-Jean -- could you fix it?


@dfawley: Could you please take another look at the changes here?

Copy link
Member

Choose a reason for hiding this comment

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

Is it possible to revert this directory, please? I'm making some pretty major changes and would like to avoid the conflict unless this is necessary for the rest of the PR.

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.

I believe this causes an API change, right? Now our status package only works with new messages, and breaks with the old ones? IIUC we should be using this instead in WithDetails and Details: https://pkg.go.dev/google.golang.org/protobuf/protoadapt#MessageV1

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 changes the API of WithDetails, because proto.Message is now different.

Copy link
Contributor Author

@Clement-Jean Clement-Jean Nov 15, 2023

Choose a reason for hiding this comment

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

@dfawley did you see the tests (status_test.go)? You mean that this isn't enough to prove the API didn't change? If that's not enough maybe I can revert the changes or add more tests to make sure it doesn't break

Comment on lines +157 to +162
detail, err := any.UnmarshalNew()
if err != nil {
details = append(details, err)
continue
}
details = append(details, detail.Message)
details = append(details, detail)
Copy link
Member

Choose a reason for hiding this comment

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

Are these new-style protos compatible with users running with github.com/golang/proto and ptypes? If not, we can't make this part of this change.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

How would I go about testing this? Should I write a status_test.go and check that both versions work?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For example, I wrote this:

func (s) TestWithDetailsVersionsCompat(t *testing.T) {
	details := []protoreflect.ProtoMessage{
		ptypes.TimestampNow(),
		ptypes.DurationProto(1 * time.Hour),
		&timestamppb.Timestamp{},
		&durationpb.Duration{},
	}
	status := New(codes.InvalidArgument, "an error")

	if _, err := status.WithDetails(details...); err != nil {
		t.Fatalf("unexpected error: %v", err)
	}
}

and it passes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure about how to test DynamicAny though, if you have any idea let me know.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

How would I go about testing this? Should I write a status_test.go and check that both versions work?

Yes, that sounds good.

For example, I wrote this [...] and it passes.

This doesn't look like what I was thinking (because it's testing WithDetails, not Details), but it's still a useful test. What I had in mind was something that called Details on a status containing details, and does type assertions using protov1 messages:

st := status.New().WithDetails(ptypes.TimestampNow(), timestamppb.Now()) // Create with old ptypes and new tspb
x := st.Details()[0]
if _, ok := x.(protov1.Message); !ok {
	t.Fatal()
}
if _, ok := x.(timestamppb.Timestamp); !ok {
	t.Fatalf()
}

I thought that anypb.UnmarshalNew() produced new protov2.Messages which were incompatible with old protov1.Messages. But if the new protov2.Message is a superset of the old protov1.Message then I think this should be safe to change, especially because it's returned as any instead of protov1.Message.

Copy link

github-actions bot commented Nov 2, 2023

This PR is labeled as requiring an update from the reporter, and no update has been received after 6 days. If no update is provided in the next 7 days, this issue will be automatically closed.

@github-actions github-actions bot added the stale label Nov 2, 2023
@dfawley dfawley removed the stale label Nov 3, 2023
@Clement-Jean
Copy link
Contributor Author

@dfawley anything left to do?

@dfawley
Copy link
Member

dfawley commented Nov 14, 2023

@dfawley anything left to do?

Yes; pinged the thread above..

Copy link

This PR is labeled as requiring an update from the reporter, and no update has been received after 6 days. If no update is provided in the next 7 days, this issue will be automatically closed.

@github-actions github-actions bot added the stale label Nov 21, 2023
@github-actions github-actions bot closed this Nov 28, 2023
@Clement-Jean
Copy link
Contributor Author

@dfawley just checking. I replied in the comments, did you see?

@dfawley
Copy link
Member

dfawley commented Jan 10, 2024

@Clement-Jean do you still have this change? I didn't see this comment in time.

@Clement-Jean
Copy link
Contributor Author

@dfawley yes, still have it

@dfawley
Copy link
Member

dfawley commented Jan 11, 2024

I'll take a look tomorrow! (Sorry for the spam.)

@dfawley
Copy link
Member

dfawley commented Jan 11, 2024

Wait, something is wrong with github.. It let me click "reopen", but it's still showing closed with the same error.

@Clement-Jean
Copy link
Contributor Author

Clement-Jean commented Jan 11, 2024

I think I accidentally removed the fork from Github, but I still have it locally. I'll clean it up and push it back, it should be ready tomorrow for you.

edit

Here it is: https://github.com/Clement-Jean/grpc-go

@dfawley
Copy link
Member

dfawley commented Jan 11, 2024

@Clement-Jean It's still not letting me reopen this, though.. Would you mind creating a new PR, please?

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 10, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Type: Dependencies Updating/adding/removing dependencies
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants