func()

in pkg/profiling/continuous/triggers.go [87:128]


func (m *Triggers) ReportProcesses(process api.ProcessInterface, profilingProcesses []api.ProcessInterface, cases []base.ThresholdCause,
	taskSetter func(task *taskBase.ProfilingTask), reportSetter func(report *v3.ContinuousProfilingReport)) (*task.Context, error) {
	transferCauses := make([]*v3.ContinuousProfilingCause, 0)
	for _, c := range cases {
		transferCauses = append(transferCauses, c.GenerateTransferCause())
	}

	// generate context
	taskContext, err := m.taskManager.BuildContextFromContinuous(profilingProcesses, taskSetter, func() (string, error) {
		report := &v3.ContinuousProfilingReport{
			Layer:        process.Entity().Layer,
			ServiceName:  process.Entity().ServiceName,
			InstanceName: process.Entity().InstanceName,
			ProcessName:  process.Entity().ProcessName,
			Causes:       transferCauses,
		}
		reportSetter(report)
		profilingTask, err := m.continuousClient.ReportProfilingTask(m.ctx, report)
		if err != nil {
			return "", err
		}

		command := profilingTask.Commands[0]
		if len(profilingTask.Commands) != 1 || command.GetCommand() != "ContinuousProfilingReportTask" {
			return "", fmt.Errorf("the profiling task result is not right, command count: %d", len(profilingTask.Commands))
		}
		for _, kv := range command.GetArgs() {
			if kv.GetKey() == "TaskId" {
				return kv.GetValue(), nil
			}
		}
		return "", fmt.Errorf("could not found the task ID from repoter")
	})
	if err != nil {
		return nil, err
	}

	// execute task from context
	m.taskManager.StartTask(taskContext)

	return taskContext, nil
}