修改排序,更多埋点信息

This commit is contained in:
Jerry Yan 2025-04-13 12:31:51 +08:00
parent dc10092f7a
commit 94e1f66288
5 changed files with 23 additions and 9 deletions

View File

@ -21,9 +21,8 @@ func HandleTask(ctx context.Context, device config.DeviceMapping, task dto.Task)
subCtx, span := tracer.Start(ctx, "HandleTask")
defer span.End()
adapter := fs.GetAdapter()
span.SetAttributes(attribute.String("taskId", task.TaskID))
span.SetAttributes(attribute.String("startTime", task.StartTime.Format("2006-01-02 15:04:05")))
span.SetAttributes(attribute.String("endTime", task.EndTime.Format("2006-01-02 15:04:05")))
span.SetAttributes(attribute.String("task.id", task.TaskID))
span.SetAttributes(attribute.String("task", util.ToJson(task)))
span.SetAttributes(attribute.String("device.no", device.DeviceNo))
span.SetAttributes(attribute.String("device.name", device.Name))
fileList, err := adapter.GetFileList(

View File

@ -59,7 +59,6 @@ func newJaegerTraceProvider(ctx context.Context) (*trace.TracerProvider, error)
// 创建一个使用 HTTP 协议连接本机Jaeger的 Exporter
res, err := resource.New(ctx,
resource.WithFromEnv(),
resource.WithProcess(),
resource.WithTelemetrySDK(),
resource.WithHost(),
resource.WithAttributes(

View File

@ -12,6 +12,7 @@ import (
"os"
"os/exec"
"path"
"sort"
"strconv"
"strings"
"sync"
@ -147,6 +148,10 @@ func CheckFileCoverageAndConstructTask(ctx context.Context, fileList []dto.File,
log.Printf("无法根据要求找到对应录制片段ID【%s】开始时间【%s】结束时间【%s】", task.TaskID, beginDt, endDt)
return nil, fmt.Errorf("无法根据要求找到对应录制片段")
}
// 按照 Create 的值升序排序
sort.Slice(fileList, func(i, j int) bool {
return fileList[i].StartTime.Unix() <= fileList[j].StartTime.Unix()
})
// 如果片段在中间断开时间过长
if len(fileList) > 1 {
@ -180,7 +185,7 @@ func CheckFileCoverageAndConstructTask(ctx context.Context, fileList []dto.File,
Offset: int(beginDt.Sub(fileList[0].StartTime).Seconds()),
OutputFile: path.Join(os.TempDir(), task.TaskID+".mp4"),
}
span.SetAttributes(attribute.Int("task.files", len(ffmpegTask.Files)))
span.SetAttributes(attribute.String("task.files", ToJson(ffmpegTask.Files)))
span.SetAttributes(attribute.Int("task.offset", ffmpegTask.Offset))
span.SetAttributes(attribute.Int("task.length", ffmpegTask.Length))
span.SetStatus(codes.Ok, "FFMPEG任务构造成功")
@ -317,7 +322,7 @@ func SlowVideoCut(ctx context.Context, inputFiles []dto.File, offset, length int
func handleFfmpegProcess(ctx context.Context, ffmpegCmd []string) (bool, error) {
_, span := tracer.Start(ctx, "handleFfmpegProcess")
defer span.End()
span.SetAttributes(attribute.String("ffmpeg.cmd", strings.Join(ffmpegCmd, " ")))
span.SetAttributes(attribute.String("ffmpeg.cmd", ToJson(ffmpegCmd)))
startTime := time.Now()
defer func() {
span.SetAttributes(attribute.Int64("ffmpeg.duration", int64(time.Since(startTime).Seconds())))
@ -371,7 +376,7 @@ func GetVideoDuration(ctx context.Context, filePath string) (float64, error) {
"-of", "default=noprint_wrappers=1:nokey=1",
filePath,
}
span.SetAttributes(attribute.String("ffprobe.cmd", strings.Join(ffprobeCmd, " ")))
span.SetAttributes(attribute.String("ffprobe.cmd", ToJson(ffprobeCmd)))
cmd := exec.Command(ffprobeCmd[0], ffprobeCmd[1:]...)
var out bytes.Buffer
cmd.Stdout = &out

View File

@ -33,9 +33,9 @@ func FilterAndSortFiles(fileList []dto.File, beginDt, endDt time.Time) []dto.Fil
}
}
// 按照 DiffMs 的值降序排序
// 按照 Create 的值升序排序
sort.Slice(filteredFiles, func(i, j int) bool {
return filteredFiles[i].DiffMs > filteredFiles[j].DiffMs
return filteredFiles[i].StartTime.Unix() <= filteredFiles[j].StartTime.Unix()
})
return filteredFiles

11
util/json.go Normal file
View File

@ -0,0 +1,11 @@
package util
import "encoding/json"
func ToJson(v interface{}) string {
b, err := json.Marshal(v)
if err != nil {
return ""
}
return string(b)
}