Skip to content

Commit afa75a3

Browse files
authored
fix: upload err log (#236)
1 parent a424bfc commit afa75a3

File tree

2 files changed

+32
-3
lines changed

2 files changed

+32
-3
lines changed

plugins/core/pprof.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ func (c *PprofTaskCommandImpl) getWriter() (io.Writer, error) {
136136
}
137137

138138
// sample data to file
139-
pprofFileName := filepath.Join(c.taskID, ".pprof")
139+
pprofFileName := c.taskID + ".pprof"
140140
pprofFilePath := filepath.Join(c.pprofFilePath, pprofFileName)
141141
if err := os.MkdirAll(filepath.Dir(pprofFilePath), os.ModePerm); err != nil {
142142
return nil, err

plugins/core/reporter/pprof_manager.go

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,15 +143,19 @@ func (r *PprofTaskManager) HandleCommand(rawCommand *commonv3.Command) {
143143
// direct sampling of Heap, Allocs, Goroutine, Thread
144144
writer, err := command.StartTask()
145145
if err != nil {
146-
r.logger.Errorf("start %s pprof task error %v \n", command.GetTaskID(), err)
146+
err = fmt.Errorf("start %s pprof task error %v", command.GetTaskID(), err)
147+
r.ReportPprofError(command.GetTaskID(), err)
148+
r.logger.Errorf(err.Error())
147149
return
148150
}
149151
command.StopTask(writer)
150152
} else {
151153
// The CPU, Block and Mutex sampling lasts for a duration and then stops
152154
writer, err := command.StartTask()
153155
if err != nil {
154-
r.logger.Errorf("start %s pprof task error %v \n", command.GetTaskID(), err)
156+
err = fmt.Errorf("start %s pprof task error %v", command.GetTaskID(), err)
157+
r.ReportPprofError(command.GetTaskID(), err)
158+
r.logger.Errorf(err.Error())
155159
return
156160
}
157161
time.AfterFunc(command.GetDuration(), func() {
@@ -238,6 +242,29 @@ func (r *PprofTaskManager) ReportPprof(taskID string, content []byte) {
238242
}
239243
}
240244

245+
func (r *PprofTaskManager) ReportPprofError(taskID string, err error) {
246+
metaData := &pprofv10.PprofMetaData{
247+
Service: r.entity.ServiceName,
248+
ServiceInstance: r.entity.ServiceInstanceName,
249+
TaskId: taskID,
250+
Type: pprofv10.PprofProfilingStatus_PPROF_EXECUTION_TASK_ERROR,
251+
ContentSize: 0,
252+
}
253+
254+
pprofData := &pprofv10.PprofData{
255+
Metadata: metaData,
256+
Result: &pprofv10.PprofData_ErrorMessage{
257+
ErrorMessage: err.Error(),
258+
},
259+
}
260+
261+
select {
262+
case r.pprofSendCh <- pprofData:
263+
default:
264+
r.logger.Errorf("reach max pprof send buffer")
265+
}
266+
}
267+
241268
func (r *PprofTaskManager) initPprofSendPipeline() {
242269
go func() {
243270
defer func() {
@@ -291,9 +318,11 @@ func (r *PprofTaskManager) uploadPprofData(pprofData *pprofv10.PprofData) {
291318
switch resp.Status {
292319
case pprofv10.PprofProfilingStatus_PPROF_TERMINATED_BY_OVERSIZE:
293320
r.logger.Errorf("pprof is too large to be received by the oap server")
321+
r.closePprofStream(stream)
294322
return
295323
case pprofv10.PprofProfilingStatus_PPROF_EXECUTION_TASK_ERROR:
296324
r.logger.Errorf("server rejected pprof upload due to execution task error")
325+
r.closePprofStream(stream)
297326
return
298327
}
299328

0 commit comments

Comments
 (0)