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

fix(profiler): do not collect disabled profile types #2836

Merged
merged 10 commits into from Sep 12, 2020
13 changes: 13 additions & 0 deletions profiler/profiler.go
Expand Up @@ -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 {
debugLog("skipping collection of disabled profile type: %v", pt)
return
}

switch pt {
case pb.ProfileType_CPU:
duration, err := ptypes.Duration(p.Duration)
Expand Down
17 changes: 11 additions & 6 deletions profiler/profiler_test.go
Expand Up @@ -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},
}
}

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -218,6 +219,10 @@ func TestProfileAndUpload(t *testing.T) {
return nil
},
},
{
profileType: pb.ProfileType_CONTENTION,
deltaMutexProfileFunc: errFunc,
},
}

for _, tt := range tests {
Expand Down