Skip to content
Permalink
Browse files
fix(profiler): do not collect disabled profile types (#2836)
* fix(profiler): do not collect disabled profile types
Fixes #2835
  • Loading branch information
kalyanac committed Sep 12, 2020
1 parent a6e7a3d commit faeb4985bf6afdcddba4553efa874642bf7f08ed
Showing with 24 additions and 6 deletions.
  1. +13 −0 profiler/profiler.go
  2. +11 −6 profiler/profiler_test.go
@@ -353,6 +353,19 @@ func (a *agent) profileAndUpload(ctx context.Context, p *pb.Profile) {
var prof bytes.Buffer
pt := p.GetProfileType()

ptEnabled := false
for _, enabled := range a.profileTypes {
if enabled == pt {
ptEnabled = true
break
}
}

if !ptEnabled {

This comment has been minimized.

Copy link
@aalexand

aalexand Sep 12, 2020

Collaborator

Note that this change should become unnecessary once b/112391682 is fixed.

@wyk9787 FYI

This comment has been minimized.

Copy link
@wyk9787

wyk9787 Sep 13, 2020

It this change still good to have even if that bug is fixed?

This comment has been minimized.

Copy link
@aalexand

aalexand via email Sep 13, 2020

Collaborator
debugLog("skipping collection of disabled profile type: %v", pt)
return
}

switch pt {
case pb.ProfileType_CPU:
duration, err := ptypes.Duration(p.Duration)
@@ -76,7 +76,7 @@ func createTestAgent(psc pb.ProfilerServiceClient) *agent {
client: psc,
deployment: createTestDeployment(),
profileLabels: map[string]string{instanceLabel: testInstance},
profileTypes: []pb.ProfileType{pb.ProfileType_CPU, pb.ProfileType_HEAP, pb.ProfileType_THREADS},
profileTypes: []pb.ProfileType{pb.ProfileType_CPU, pb.ProfileType_HEAP, pb.ProfileType_HEAP_ALLOC, pb.ProfileType_THREADS},
}
}

@@ -140,11 +140,12 @@ func TestProfileAndUpload(t *testing.T) {
errFunc := func(io.Writer) error { return errors.New("") }
testDuration := time.Second * 5
tests := []struct {
profileType pb.ProfileType
duration *time.Duration
startCPUProfileFunc func(io.Writer) error
writeHeapProfileFunc func(io.Writer) error
wantBytes []byte
profileType pb.ProfileType
duration *time.Duration
startCPUProfileFunc func(io.Writer) error
writeHeapProfileFunc func(io.Writer) error
deltaMutexProfileFunc func(io.Writer) error
wantBytes []byte
}{
{
profileType: pb.ProfileType_CPU,
@@ -218,6 +219,10 @@ func TestProfileAndUpload(t *testing.T) {
return nil
},
},
{
profileType: pb.ProfileType_CONTENTION,
deltaMutexProfileFunc: errFunc,
},
}

for _, tt := range tests {

0 comments on commit faeb498

Please sign in to comment.