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

Replace pborman/uuid with google/uuid #550

Merged
merged 2 commits into from
Apr 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ require (
github.com/bazelbuild/remote-apis v0.0.0-20230411132548-35aee1c4a425
github.com/golang/glog v1.1.0
github.com/google/go-cmp v0.5.9
github.com/google/uuid v1.3.0
github.com/klauspost/compress v1.17.8
github.com/pborman/uuid v1.2.0
github.com/pkg/errors v0.9.1
github.com/pkg/xattr v0.4.4
golang.org/x/oauth2 v0.10.0
Expand All @@ -25,7 +25,6 @@ require (
cloud.google.com/go/compute/metadata v0.2.3 // indirect
cloud.google.com/go/longrunning v0.5.1 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/uuid v1.3.0 // indirect
golang.org/x/net v0.23.0 // indirect
golang.org/x/sys v0.18.0 // indirect
golang.org/x/text v0.14.0 // indirect
Expand Down
3 changes: 0 additions & 3 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,11 @@ github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/uuid v1.0.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/klauspost/compress v1.17.8 h1:YcnTYrq7MikUT7k0Yb5eceMmALQPYBW/Xltxn0NAMnU=
github.com/klauspost/compress v1.17.8/go.mod h1:Di0epgTjJY877eYKx5yC51cX2A2Vl2ibi7bDH9ttBbw=
github.com/pborman/uuid v1.2.0 h1:J7Q5mO4ysT1dv8hyrUGHb9+ooztCXu1D8MY8DZYsu3g=
github.com/pborman/uuid v1.2.0/go.mod h1:X/NO0urCmaxf9VXbdlT7C2Yzkj2IKimNn4k+gtPdI/k=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/xattr v0.4.4 h1:FSoblPdYobYoKCItkqASqcrKCxRn9Bgurz0sCBwzO5g=
Expand Down
2 changes: 1 addition & 1 deletion go/pkg/balancer/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ go_test(
srcs = ["gcp_balancer_test.go"],
embed = [":balancer"],
deps = [
"@com_github_pborman_uuid//:go_default_library",
"@com_github_google_uuid//:uuid",
"@org_golang_google_grpc//balancer:go_default_library",
"@org_golang_google_grpc//connectivity:go_default_library",
"@org_golang_google_grpc//resolver:go_default_library",
Expand Down
4 changes: 2 additions & 2 deletions go/pkg/balancer/gcp_balancer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"testing"
"time"

"github.com/pborman/uuid"
"github.com/google/uuid"

grpcbalancer "google.golang.org/grpc/balancer"
"google.golang.org/grpc/connectivity"
Expand All @@ -16,7 +16,7 @@ func TestGCPBalancer_UpdatingConnectionStateIsMutuallyExclusive(t *testing.T) {
builder := newBuilder()
var subconns []*fakeSubConn
for i := 0; i < MinConnections; i++ {
subconns = append(subconns, &fakeSubConn{id: uuid.New()})
subconns = append(subconns, &fakeSubConn{id: uuid.New().String()})
}

cc := fakeClientConn{subconns: subconns}
Expand Down
2 changes: 1 addition & 1 deletion go/pkg/cas/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ go_library(
"//go/pkg/retry",
"@com_github_bazelbuild_remote_apis//build/bazel/remote/execution/v2:remote_execution_go_proto",
"@com_github_golang_glog//:go_default_library",
"@com_github_google_uuid//:uuid",
"@com_github_klauspost_compress//zstd:go_default_library",
"@com_github_pborman_uuid//:go_default_library",
"@com_github_pkg_errors//:go_default_library",
"@go_googleapis//google/bytestream:bytestream_go_proto",
"@org_golang_google_api//support/bundler:go_default_library",
Expand Down
10 changes: 7 additions & 3 deletions go/pkg/cas/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
"time"

log "github.com/golang/glog"
"github.com/google/uuid"
"github.com/klauspost/compress/zstd"
"github.com/pborman/uuid"
"github.com/pkg/errors"
"golang.org/x/sync/errgroup"
"google.golang.org/api/support/bundler"
Expand Down Expand Up @@ -1068,10 +1068,14 @@
if instanceSegment == "/" {
instanceSegment = ""
}
uploadID, err := uuid.NewRandom()
if err != nil {
return err

Check failure on line 1073 in go/pkg/cas/upload.go

View workflow job for this annotation

GitHub Actions / lint

error returned from external package is unwrapped: sig: func github.com/google/uuid.NewRandom() (github.com/google/uuid.UUID, error) (wrapcheck)
}
if compressed {
req.ResourceName = fmt.Sprintf("%suploads/%s/compressed-blobs/zstd/%s/%d", instanceSegment, uuid.New(), digest.Hash, digest.SizeBytes)
req.ResourceName = fmt.Sprintf("%suploads/%s/compressed-blobs/zstd/%s/%d", instanceSegment, uploadID.String(), digest.Hash, digest.SizeBytes)
} else {
req.ResourceName = fmt.Sprintf("%suploads/%s/blobs/%s/%d", instanceSegment, uuid.New(), digest.Hash, digest.SizeBytes)
req.ResourceName = fmt.Sprintf("%suploads/%s/blobs/%s/%d", instanceSegment, uploadID.String(), digest.Hash, digest.SizeBytes)
}

buf := u.streamBufs.Get().(*[]byte)
Expand Down
2 changes: 1 addition & 1 deletion go/pkg/client/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ go_library(
"//go/pkg/uploadinfo",
"@com_github_bazelbuild_remote_apis//build/bazel/remote/execution/v2:remote_execution_go_proto",
"@com_github_golang_glog//:go_default_library",
"@com_github_google_uuid//:uuid",
"@com_github_klauspost_compress//zstd:go_default_library",
"@com_github_pborman_uuid//:go_default_library",
"@com_github_pkg_errors//:go_default_library",
"@go_googleapis//google/bytestream:bytestream_go_proto",
"@go_googleapis//google/longrunning:longrunning_go_proto",
Expand Down
40 changes: 29 additions & 11 deletions go/pkg/client/cas_upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
"github.com/bazelbuild/remote-apis-sdks/go/pkg/uploadinfo"
repb "github.com/bazelbuild/remote-apis/build/bazel/remote/execution/v2"
log "github.com/golang/glog"
"github.com/google/uuid"
"github.com/klauspost/compress/zstd"
"github.com/pborman/uuid"
"github.com/pkg/errors"
"golang.org/x/sync/errgroup"
"google.golang.org/grpc/codes"
Expand Down Expand Up @@ -108,7 +108,11 @@
if err != nil {
return dg, err
}
_, err = c.writeChunked(ctx, c.writeRscName(ue), ch, false, 0)
rscName, err := c.writeRscName(ue)
if err != nil {
return dg, err
}
_, err = c.writeChunked(ctx, rscName, ch, false, 0)
return dg, err
}

Expand Down Expand Up @@ -201,20 +205,26 @@
}

// ResourceNameWrite generates a valid write resource name.
func (c *Client) ResourceNameWrite(hash string, sizeBytes int64) string {
rname, _ := c.ResourceName("uploads", uuid.New(), "blobs", hash, strconv.FormatInt(sizeBytes, 10))
return rname
func (c *Client) ResourceNameWrite(hash string, sizeBytes int64) (string, error) {
id, err := uuid.NewRandom()
if err != nil {
return "", err

Check failure on line 211 in go/pkg/client/cas_upload.go

View workflow job for this annotation

GitHub Actions / lint

error returned from external package is unwrapped: sig: func github.com/google/uuid.NewRandom() (github.com/google/uuid.UUID, error) (wrapcheck)
}
return c.ResourceName("uploads", id.String(), "blobs", hash, strconv.FormatInt(sizeBytes, 10))
}

// ResourceNameCompressedWrite generates a valid write resource name.
// TODO(rubensf): Converge compressor to proto in https://github.com/bazelbuild/remote-apis/pull/168 once
// that gets merged in.
func (c *Client) ResourceNameCompressedWrite(hash string, sizeBytes int64) string {
rname, _ := c.ResourceName("uploads", uuid.New(), "compressed-blobs", "zstd", hash, strconv.FormatInt(sizeBytes, 10))
return rname
func (c *Client) ResourceNameCompressedWrite(hash string, sizeBytes int64) (string, error) {
id, err := uuid.NewRandom()
if err != nil {
return "", err

Check failure on line 222 in go/pkg/client/cas_upload.go

View workflow job for this annotation

GitHub Actions / lint

error returned from external package is unwrapped: sig: func github.com/google/uuid.NewRandom() (github.com/google/uuid.UUID, error) (wrapcheck)
}
return c.ResourceName("uploads", id.String(), "compressed-blobs", "zstd", hash, strconv.FormatInt(sizeBytes, 10))
}

func (c *Client) writeRscName(ue *uploadinfo.Entry) string {
func (c *Client) writeRscName(ue *uploadinfo.Entry) (string, error) {
if c.shouldCompressEntry(ue) {
return c.ResourceNameCompressedWrite(ue.Digest.Hash, ue.Digest.Size)
}
Expand Down Expand Up @@ -485,7 +495,11 @@
if err != nil {
updateAndNotify(st, 0, err, true)
}
totalBytes, err := c.writeChunked(cCtx, c.writeRscName(st.ue), ch, false, 0)
rscName, err := c.writeRscName(st.ue)
if err != nil {
updateAndNotify(st, 0, err, true)
}
totalBytes, err := c.writeChunked(cCtx, rscName, ch, false, 0)
updateAndNotify(st, totalBytes, err, true)
}
}()
Expand Down Expand Up @@ -570,7 +584,11 @@
if err != nil {
return err
}
written, err := c.writeChunked(eCtx, c.writeRscName(ue), ch, false, 0)
rscName, err := c.writeRscName(ue)
if err != nil {
return err
}
written, err := c.writeChunked(eCtx, rscName, ch, false, 0)
if err != nil {
return fmt.Errorf("failed to upload %s: %w", ue.Path, err)
}
Expand Down
3 changes: 2 additions & 1 deletion go/pkg/command/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ go_library(
"//go/api/command",
"//go/pkg/digest",
"@com_github_bazelbuild_remote_apis//build/bazel/remote/execution/v2:remote_execution_go_proto",
"@com_github_pborman_uuid//:go_default_library",
"@com_github_golang_glog//:go_default_library",
"@com_github_google_uuid//:uuid",
"@org_golang_google_protobuf//types/known/timestamppb:go_default_library",
"@org_golang_google_protobuf//types/known/anypb:go_default_library",
],
Expand Down
15 changes: 12 additions & 3 deletions go/pkg/command/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ import (
"time"

"github.com/bazelbuild/remote-apis-sdks/go/pkg/digest"
"github.com/pborman/uuid"
log "github.com/golang/glog"
"github.com/google/uuid"

cpb "github.com/bazelbuild/remote-apis-sdks/go/api/command"
repb "github.com/bazelbuild/remote-apis/build/bazel/remote/execution/v2"
Expand Down Expand Up @@ -295,10 +296,18 @@ func (c *Command) FillDefaultFieldValues() {
c.Identifiers.ToolName = "remote-client"
}
if c.Identifiers.InvocationID == "" {
c.Identifiers.InvocationID = uuid.New()
if id, err := uuid.NewRandom(); err == nil {
c.Identifiers.InvocationID = id.String()
} else {
log.Warningf("Failed to generate InvocationID: %s", err)
}
}
if c.Identifiers.ExecutionID == "" {
c.Identifiers.ExecutionID = uuid.New()
if id, err := uuid.NewRandom(); err == nil {
c.Identifiers.ExecutionID = id.String()
} else {
log.Warningf("Failed to generate ExecutionID: %s", err)
}
}
if c.InputSpec == nil {
c.InputSpec = &InputSpec{}
Expand Down
2 changes: 1 addition & 1 deletion go/pkg/contextmd/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ go_library(
deps = [
"@com_github_bazelbuild_remote_apis//build/bazel/remote/execution/v2:remote_execution_go_proto",
"@com_github_golang_glog//:go_default_library",
"@com_github_pborman_uuid//:go_default_library",
"@com_github_google_uuid//:uuid",
"@org_golang_google_grpc//metadata:go_default_library",
"@org_golang_google_protobuf//proto:go_default_library",
],
Expand Down
18 changes: 13 additions & 5 deletions go/pkg/contextmd/contextmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"strings"

log "github.com/golang/glog"
"github.com/pborman/uuid"
"github.com/google/uuid"
"google.golang.org/grpc/metadata"
"google.golang.org/protobuf/proto"

Expand Down Expand Up @@ -79,13 +79,21 @@ func WithMetadata(ctx context.Context, ms ...*Metadata) (context.Context, error)
m := MergeMetadata(ms...)
actionID := m.ActionID
if actionID == "" {
actionID = uuid.New()
log.V(2).Infof("Generated action_id %s for %s", actionID, m.ToolName)
if id, err := uuid.NewRandom(); err == nil {
actionID = id.String()
log.V(2).Infof("Generated action_id %s for %s", actionID, m.ToolName)
} else {
log.Warningf("Failed to generate action_id: %s", err)
}
}
invocationID := m.InvocationID
if invocationID == "" {
invocationID = uuid.New()
log.V(2).Infof("Generated invocation_id %s for %s %s", invocationID, m.ToolName, actionID)
if id, err := uuid.NewRandom(); err == nil {
invocationID = id.String()
log.V(2).Infof("Generated invocation_id %s for %s %s", invocationID, m.ToolName, actionID)
} else {
log.Warningf("Failed to generate invocation_id: %s", err)
}
}

meta := &repb.RequestMetadata{
Expand Down
2 changes: 1 addition & 1 deletion go/pkg/fakes/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ go_library(
"//go/pkg/rexec",
"//go/pkg/uploadinfo",
"@com_github_bazelbuild_remote_apis//build/bazel/remote/execution/v2:remote_execution_go_proto",
"@com_github_google_uuid//:uuid",
"@com_github_klauspost_compress//zstd:go_default_library",
"@com_github_pborman_uuid//:go_default_library",
"@go_googleapis//google/bytestream:bytestream_go_proto",
"@go_googleapis//google/longrunning:longrunning_go_proto",
"@org_golang_google_grpc//:go_default_library",
Expand Down
6 changes: 3 additions & 3 deletions go/pkg/fakes/cas.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ import (
"github.com/bazelbuild/remote-apis-sdks/go/pkg/client"
"github.com/bazelbuild/remote-apis-sdks/go/pkg/digest"
"github.com/bazelbuild/remote-apis-sdks/go/pkg/uploadinfo"
"github.com/google/uuid"
"github.com/klauspost/compress/zstd"
"github.com/pborman/uuid"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"google.golang.org/protobuf/proto"
Expand Down Expand Up @@ -183,7 +183,7 @@ func (f *Writer) Write(stream bsgrpc.ByteStream_WriteServer) (err error) {
if e != nil {
return status.Error(codes.InvalidArgument, "test fake expected valid digest as part of resource name of the form \"instance/uploads/<uuid>/blobs|compressed-blobs/<compressor?>/<hash>/<size>\"")
}
if uuid.Parse(path[2]) == nil {
if _, err := uuid.Parse(path[2]); err != nil {
return status.Error(codes.InvalidArgument, "test fake expected resource name of the form \"instance/uploads/<uuid>/blobs|compressed-blobs/<compressor?>/<hash>/<size>\"")
}

Expand Down Expand Up @@ -604,7 +604,7 @@ func (f *CAS) Write(stream bsgrpc.ByteStream_WriteServer) (err error) {
if err != nil {
return status.Error(codes.InvalidArgument, "test fake expected a valid digest as part of the resource name: \"instance/uploads/<uuid>/blobs|compressed-blobs/<compressor?>/<hash>/<size>\"")
}
if uuid.Parse(path[2]) == nil {
if _, err := uuid.Parse(path[2]); err != nil {
return status.Error(codes.InvalidArgument, "test fake expected resource name of the form \"instance/uploads/<uuid>/blobs|compressed-blobs/<compressor?>/<hash>/<size>\"")
}

Expand Down
6 changes: 0 additions & 6 deletions go_deps.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,6 @@ def remote_apis_sdks_go_deps():
sum = "h1:YcnTYrq7MikUT7k0Yb5eceMmALQPYBW/Xltxn0NAMnU=",
version = "v1.17.8",
)
go_repository(
name = "com_github_pborman_uuid",
importpath = "github.com/pborman/uuid",
sum = "h1:J7Q5mO4ysT1dv8hyrUGHb9+ooztCXu1D8MY8DZYsu3g=",
version = "v1.2.0",
)
go_repository(
name = "com_github_pkg_errors",
importpath = "github.com/pkg/errors",
Expand Down
Loading