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

Migrate off of gogo/protobuf #4422

Draft
wants to merge 9 commits into
base: master
Choose a base branch
from
Draft

Migrate off of gogo/protobuf #4422

wants to merge 9 commits into from

Conversation

kzys
Copy link
Member

@kzys kzys commented Nov 16, 2023

gogo/protobuf has been deprecated since 2022. This PR uses Google's official code generators instead of gogo's.

Fixes #3119

@kzys kzys force-pushed the bye-gogo branch 3 times, most recently from b518a14 to f81a7cc Compare November 16, 2023 17:33
@kzys
Copy link
Member Author

kzys commented Nov 16, 2023

The fsutil change is in tonistiigi/fsutil#171.

@kzys kzys force-pushed the bye-gogo branch 5 times, most recently from c5ad2bd to 2979fbf Compare November 16, 2023 18:26
@tonistiigi
Copy link
Member

Is there a guarantee that this does not break old-new client-daemon combinations?

@kzys
Copy link
Member Author

kzys commented Nov 16, 2023

Yes. gogo/protobuf didn't modify the wire protocol. Their changes are primarily around code generators to make it more Go-idiomatic and efficient. I did a similar refactorting for containerd (see containerd/containerd#6564), and it has been released as containerd 1.7.0. We haven't heard any complaints regarding the compatibility.

@kzys kzys force-pushed the bye-gogo branch 5 times, most recently from 2ba5d69 to f4aa840 Compare November 16, 2023 22:38
@thaJeztah
Copy link
Member

Seeing some test failures; are those expected?

=== FAIL: solver/llbsolver TestRecomputeDigests (0.00s)
    vertex_test.go:54: 
        	Error Trace:	D:/a/buildkit/buildkit/solver/llbsolver/vertex_test.go:54
        	Error:      	Not equal: 
        	            	expected: digest.Digest("sha256:06c243a9083f537e33d82b0af0379737187f7fbba73f852fe968b592c36bd8b5")
        	            	actual  : string("sha256:06c243a9083f537e33d82b0af0379737187f7fbba73f852fe968b592c36bd8b5")

@kzys
Copy link
Member Author

kzys commented Nov 17, 2023

Seeing some test failures; are those expected?

No. It should be fixed in the last revision, but the PR is still work-in-progress...

@kzys kzys force-pushed the bye-gogo branch 5 times, most recently from 0dead12 to d50b3b1 Compare November 21, 2023 03:40
@kzys
Copy link
Member Author

kzys commented Nov 21, 2023

By fixing all golangci-lint errors, I ended up getting failed to load cache key: docker.io/library/busybox:latest@sha256:b28d6f3d483bfa5b30562287e1197fca960ca5dd8211d8cbf1536eb937e21af8: not found which I couldn't figure out why. So I'm re-doing this PR again with much smaller commits.

@kzys kzys force-pushed the bye-gogo branch 5 times, most recently from ff8e07b to d7e32bb Compare November 21, 2023 18:18

message WorkerRecord {
string ID = 1;
map<string, string> Labels = 2;
repeated pb.Platform platforms = 3 [(gogoproto.nullable) = false];
repeated pb.Platform platforms = 3;
Copy link
Member

Choose a reason for hiding this comment

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

Could we get some backward compatibility proving unit tests for the structs where the proto definition changed? Tests that use binary assets generated from previous version.

Copy link
Member Author

Choose a reason for hiding this comment

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

Let me check. I could write a few, but probably not for all of them. I feel that it is more like testing protos, not Buildkit.

Copy link
Member Author

Choose a reason for hiding this comment

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

It may make sense to do that in master first since this PR changes protos :)

Copy link
Member Author

Choose a reason for hiding this comment

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

Opened #4570.

util/proto.go Outdated
@@ -0,0 +1,79 @@
package util
Copy link
Member

Choose a reason for hiding this comment

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

This shouldn't be generic util pkg. Maybe util/cast ?

Copy link
Member Author

Choose a reason for hiding this comment

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

Sounds good.

Copy link
Member Author

Choose a reason for hiding this comment

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

Addressed by fc4c2fe

@@ -51,11 +50,11 @@ func New(ctx context.Context, opts map[string]string, session, product string, c
}

if resp.FrontendAPICaps == nil {
resp.FrontendAPICaps = defaultCaps()
resp.FrontendAPICaps = util.PointerSlice(defaultCaps())
Copy link
Member

Choose a reason for hiding this comment

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

If it doesn't change anything else we should consider changing definition of defaultCaps() etc in these cases instead of converting.

Copy link
Member Author

@kzys kzys Jan 20, 2024

Choose a reason for hiding this comment

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

Yeah. I was doing these conversions to change stuff incrementally. Let me check whether I can move that to the original functions instead of converting.

Copy link
Member Author

Choose a reason for hiding this comment

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

This PointerSlice and some other type-casting functions are gone at fc4c2fe.

@sipsma
Copy link
Collaborator

sipsma commented Jan 2, 2024

Are there any updates on the progress here? The only reason I care is that #4455 is accidentally dependent on it (see the PR description for why).

I totally get this PR may take some more time+effort to finish up, but if it's going to take a significantly longer time then it may be worth considering whether we should revert the changes in fsutil and have this PR depend on a fork of fsutil until it's ready to merge. Otherwise we'll be stuck in this state of not being able to update fsutil for a while.

cc @kzys (hi! long time no see 😄) @tonistiigi

@kzys
Copy link
Member Author

kzys commented Jan 20, 2024

Hi again @sipsma!

Sorry, I was blocking the review. Let me update the PR shortly.

Is it possible to get some benchmarks to understand how big issue this is and if we can stick with reflection or not.

@tonistiigi - Do you have benchmarks for Buildkit itself?

…obuf

Signed-off-by: Kazuyoshi Kato <kato.kazuyoshi@gmail.com>
gogo/protobuf has been deprecated since 2022. This change uses Google's
official code generators instead of gogo's.

Signed-off-by: Kazuyoshi Kato <kato.kazuyoshi@gmail.com>
With gogo, all protobuf-generated structs had Size() methods, and
Size field was renamed to Size_ to avoid conflicts.

With google.golang.org/protobuf, the structs simply have Size fields.

Signed-off-by: Kazuyoshi Kato <kato.kazuyoshi@gmail.com>
Signed-off-by: Kazuyoshi Kato <kato.kazuyoshi@gmail.com>
Signed-off-by: Kazuyoshi Kato <kato.kazuyoshi@gmail.com>
In google.golang.org/protobuf, an empty message and nil are interchangeable.

golang/protobuf#965

Signed-off-by: Kazuyoshi Kato <kato.kazuyoshi@gmail.com>
Signed-off-by: Kazuyoshi Kato <kato.kazuyoshi@gmail.com>
google.golang.org/protobuf made all proto structs with a mutex to prevent
copies.

Signed-off-by: Kazuyoshi Kato <kato.kazuyoshi@gmail.com>
Signed-off-by: Kazuyoshi Kato <kato.kazuyoshi@gmail.com>
kzys added a commit to kzys/buildkit that referenced this pull request Jan 20, 2024
These serialized binaries can be used to test changes like moby#4422.

Signed-off-by: Kazuyoshi Kato <kato.kazuyoshi@gmail.com>
kzys added a commit to kzys/buildkit that referenced this pull request Feb 1, 2024
These serialized binaries can be used to test changes like moby#4422.

Signed-off-by: Kazuyoshi Kato <kato.kazuyoshi@gmail.com>
kzys added a commit to kzys/buildkit that referenced this pull request Feb 1, 2024
These serialized binaries can be used to test changes like moby#4422.

Signed-off-by: Kazuyoshi Kato <kato.kazuyoshi@gmail.com>
kzys added a commit to kzys/buildkit that referenced this pull request Feb 1, 2024
These serialized binaries can be used to test changes like moby#4422.

Signed-off-by: Kazuyoshi Kato <kato.kazuyoshi@gmail.com>
kzys added a commit to kzys/buildkit that referenced this pull request Feb 1, 2024
These serialized binaries can be used to test changes like moby#4422.

Signed-off-by: Kazuyoshi Kato <kato.kazuyoshi@gmail.com>
kzys added a commit to kzys/buildkit that referenced this pull request Feb 1, 2024
These serialized binaries can be used to test changes like moby#4422.

Signed-off-by: Kazuyoshi Kato <kato.kazuyoshi@gmail.com>
@tonistiigi
Copy link
Member

Do you have benchmarks for Buildkit itself?

I think for this we would do micro-benchmarks for marshaling, unmarshal. If we start running containers then this would skew the timing too much. In fsutil there was also a benchmark script that maybe can be used. Maybe LLB marshal and load is a nice candidate.

The biggest possible performance issue would be with the session endpoint and the context and build result transfer. This is where 100s of MB can potentially be transferred and encoded/decoded. If session uses gRPC dialer then it also uses protobuf for raw data framing. I believe previously some of these decoding could avoid allocating more memory because the Unmarshal code was reusing the buffer by resetting it with [:0]. For these big data transfers, we should avoid new memory allocations that grow with amount of transferred data.

@profnandaa
Copy link
Collaborator

Just wondering, coz of the movements in the codebase, we are bound to have a lot of merge conflict as we go. Is possible to split this into some self-contained chunks like perhaps sub-packages and chain the PRs?

@thompson-shaun thompson-shaun added this to the v0.next milestone May 23, 2024
@thompson-shaun thompson-shaun added dependencies Pull requests that update a dependency file and removed status/needs-attention labels Jun 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dependencies Pull requests that update a dependency file
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Migrate away from gogo
6 participants