diff --git a/profiler/go.mod b/profiler/go.mod index 169734c5ec0..871f26d7a7b 100644 --- a/profiler/go.mod +++ b/profiler/go.mod @@ -7,7 +7,6 @@ require ( cloud.google.com/go/compute/metadata v0.2.3 cloud.google.com/go/storage v1.30.1 github.com/golang/mock v1.6.0 - github.com/golang/protobuf v1.5.3 github.com/google/pprof v0.0.0-20230602150820-91b7bce49751 github.com/googleapis/gax-go/v2 v2.12.0 golang.org/x/oauth2 v0.8.0 @@ -15,12 +14,14 @@ require ( google.golang.org/genproto v0.0.0-20230530153820-e85fd2cbaebc google.golang.org/genproto/googleapis/rpc v0.0.0-20230530153820-e85fd2cbaebc google.golang.org/grpc v1.56.1 + google.golang.org/protobuf v1.31.0 ) require ( cloud.google.com/go/compute v1.19.3 // indirect cloud.google.com/go/iam v0.13.0 // indirect github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect + github.com/golang/protobuf v1.5.3 // indirect github.com/google/go-cmp v0.5.9 // indirect github.com/google/s2a-go v0.1.4 // indirect github.com/google/uuid v1.3.0 // indirect @@ -33,5 +34,4 @@ require ( golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect google.golang.org/appengine v1.6.7 // indirect google.golang.org/genproto/googleapis/api v0.0.0-20230530153820-e85fd2cbaebc // indirect - google.golang.org/protobuf v1.31.0 // indirect ) diff --git a/profiler/profiler.go b/profiler/profiler.go index 0d7fdb6a1fe..9776934357b 100644 --- a/profiler/profiler.go +++ b/profiler/profiler.go @@ -52,8 +52,6 @@ import ( gcemd "cloud.google.com/go/compute/metadata" "cloud.google.com/go/internal/version" "cloud.google.com/go/profiler/internal" - "github.com/golang/protobuf/proto" - "github.com/golang/protobuf/ptypes" "github.com/google/pprof/profile" gax "github.com/googleapis/gax-go/v2" "google.golang.org/api/option" @@ -64,6 +62,7 @@ import ( "google.golang.org/grpc/codes" grpcmd "google.golang.org/grpc/metadata" "google.golang.org/grpc/status" + "google.golang.org/protobuf/proto" ) var ( @@ -297,14 +296,13 @@ func abortedBackoffDuration(md grpcmd.MD) (time.Duration, error) { var retryInfo edpb.RetryInfo if err := proto.Unmarshal([]byte(elem[0]), &retryInfo); err != nil { return 0, err - } else if time, err := ptypes.Duration(retryInfo.RetryDelay); err != nil { - return 0, err - } else { - if time < 0 { - return 0, errors.New("negative retry duration") - } - return time, nil } + + time := retryInfo.RetryDelay.AsDuration() + if time < 0 { + return 0, errors.New("negative retry duration") + } + return time, nil } type retryer struct { @@ -386,11 +384,7 @@ func (a *agent) profileAndUpload(ctx context.Context, p *pb.Profile) { switch pt { case pb.ProfileType_CPU: - duration, err := ptypes.Duration(p.Duration) - if err != nil { - debugLog("failed to get profile duration for CPU profile: %v", err) - return - } + duration := p.Duration.AsDuration() if err := startCPUProfile(&prof); err != nil { debugLog("failed to start CPU profile: %v", err) return @@ -403,11 +397,7 @@ func (a *agent) profileAndUpload(ctx context.Context, p *pb.Profile) { return } case pb.ProfileType_HEAP_ALLOC: - duration, err := ptypes.Duration(p.Duration) - if err != nil { - debugLog("failed to get profile duration for allocation profile: %v", err) - return - } + duration := p.Duration.AsDuration() if err := deltaAllocProfile(ctx, duration, config.AllocForceGC, &prof); err != nil { debugLog("failed to collect allocation profile: %v", err) return @@ -418,11 +408,7 @@ func (a *agent) profileAndUpload(ctx context.Context, p *pb.Profile) { return } case pb.ProfileType_CONTENTION: - duration, err := ptypes.Duration(p.Duration) - if err != nil { - debugLog("failed to get profile duration: %v", err) - return - } + duration := p.Duration.AsDuration() if err := deltaMutexProfile(ctx, duration, &prof); err != nil { debugLog("failed to collect mutex profile: %v", err) return diff --git a/profiler/profiler_test.go b/profiler/profiler_test.go index 63140762314..87da816f536 100644 --- a/profiler/profiler_test.go +++ b/profiler/profiler_test.go @@ -35,8 +35,6 @@ import ( "cloud.google.com/go/profiler/mocks" "cloud.google.com/go/profiler/testdata" "github.com/golang/mock/gomock" - "github.com/golang/protobuf/proto" - "github.com/golang/protobuf/ptypes" "github.com/google/pprof/profile" gax "github.com/googleapis/gax-go/v2" "google.golang.org/api/option" @@ -47,6 +45,8 @@ import ( "google.golang.org/grpc/codes" grpcmd "google.golang.org/grpc/metadata" "google.golang.org/grpc/status" + "google.golang.org/protobuf/proto" + "google.golang.org/protobuf/types/known/durationpb" ) const ( @@ -82,7 +82,7 @@ func createTestAgent(psc pb.ProfilerServiceClient) *agent { func createTrailers(dur time.Duration) map[string]string { b, _ := proto.Marshal(&edpb.RetryInfo{ - RetryDelay: ptypes.DurationProto(dur), + RetryDelay: durationpb.New(dur), }) return map[string]string{ retryInfoMetadata: string(b), @@ -238,7 +238,7 @@ func TestProfileAndUpload(t *testing.T) { } p := &pb.Profile{ProfileType: tt.profileType} if tt.duration != nil { - p.Duration = ptypes.DurationProto(*tt.duration) + p.Duration = durationpb.New(*tt.duration) } if tt.wantBytes != nil { wantProfile := &pb.Profile{ @@ -777,7 +777,7 @@ func (fs *fakeProfilerServer) CreateProfile(ctx context.Context, in *pb.CreatePr fs.count++ switch fs.count % 2 { case 1: - return &pb.Profile{Name: "testCPU", ProfileType: pb.ProfileType_CPU, Duration: ptypes.DurationProto(testProfileDuration)}, nil + return &pb.Profile{Name: "testCPU", ProfileType: pb.ProfileType_CPU, Duration: durationpb.New(testProfileDuration)}, nil default: return &pb.Profile{Name: "testHeap", ProfileType: pb.ProfileType_HEAP}, nil }