Skip to content

Commit faeb498

Browse files
authored
fix(profiler): do not collect disabled profile types (#2836)
* fix(profiler): do not collect disabled profile types Fixes #2835
1 parent a6e7a3d commit faeb498

File tree

2 files changed

+24
-6
lines changed

2 files changed

+24
-6
lines changed

profiler/profiler.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,19 @@ func (a *agent) profileAndUpload(ctx context.Context, p *pb.Profile) {
353353
var prof bytes.Buffer
354354
pt := p.GetProfileType()
355355

356+
ptEnabled := false
357+
for _, enabled := range a.profileTypes {
358+
if enabled == pt {
359+
ptEnabled = true
360+
break
361+
}
362+
}
363+
364+
if !ptEnabled {
365+
debugLog("skipping collection of disabled profile type: %v", pt)
366+
return
367+
}
368+
356369
switch pt {
357370
case pb.ProfileType_CPU:
358371
duration, err := ptypes.Duration(p.Duration)

profiler/profiler_test.go

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ func createTestAgent(psc pb.ProfilerServiceClient) *agent {
7676
client: psc,
7777
deployment: createTestDeployment(),
7878
profileLabels: map[string]string{instanceLabel: testInstance},
79-
profileTypes: []pb.ProfileType{pb.ProfileType_CPU, pb.ProfileType_HEAP, pb.ProfileType_THREADS},
79+
profileTypes: []pb.ProfileType{pb.ProfileType_CPU, pb.ProfileType_HEAP, pb.ProfileType_HEAP_ALLOC, pb.ProfileType_THREADS},
8080
}
8181
}
8282

@@ -140,11 +140,12 @@ func TestProfileAndUpload(t *testing.T) {
140140
errFunc := func(io.Writer) error { return errors.New("") }
141141
testDuration := time.Second * 5
142142
tests := []struct {
143-
profileType pb.ProfileType
144-
duration *time.Duration
145-
startCPUProfileFunc func(io.Writer) error
146-
writeHeapProfileFunc func(io.Writer) error
147-
wantBytes []byte
143+
profileType pb.ProfileType
144+
duration *time.Duration
145+
startCPUProfileFunc func(io.Writer) error
146+
writeHeapProfileFunc func(io.Writer) error
147+
deltaMutexProfileFunc func(io.Writer) error
148+
wantBytes []byte
148149
}{
149150
{
150151
profileType: pb.ProfileType_CPU,
@@ -218,6 +219,10 @@ func TestProfileAndUpload(t *testing.T) {
218219
return nil
219220
},
220221
},
222+
{
223+
profileType: pb.ProfileType_CONTENTION,
224+
deltaMutexProfileFunc: errFunc,
225+
},
221226
}
222227

223228
for _, tt := range tests {

0 commit comments

Comments
 (0)