修改排序,更多埋点信息
This commit is contained in:
parent
dc10092f7a
commit
94e1f66288
@ -21,9 +21,8 @@ func HandleTask(ctx context.Context, device config.DeviceMapping, task dto.Task)
|
|||||||
subCtx, span := tracer.Start(ctx, "HandleTask")
|
subCtx, span := tracer.Start(ctx, "HandleTask")
|
||||||
defer span.End()
|
defer span.End()
|
||||||
adapter := fs.GetAdapter()
|
adapter := fs.GetAdapter()
|
||||||
span.SetAttributes(attribute.String("taskId", task.TaskID))
|
span.SetAttributes(attribute.String("task.id", task.TaskID))
|
||||||
span.SetAttributes(attribute.String("startTime", task.StartTime.Format("2006-01-02 15:04:05")))
|
span.SetAttributes(attribute.String("task", util.ToJson(task)))
|
||||||
span.SetAttributes(attribute.String("endTime", task.EndTime.Format("2006-01-02 15:04:05")))
|
|
||||||
span.SetAttributes(attribute.String("device.no", device.DeviceNo))
|
span.SetAttributes(attribute.String("device.no", device.DeviceNo))
|
||||||
span.SetAttributes(attribute.String("device.name", device.Name))
|
span.SetAttributes(attribute.String("device.name", device.Name))
|
||||||
fileList, err := adapter.GetFileList(
|
fileList, err := adapter.GetFileList(
|
||||||
|
@ -59,7 +59,6 @@ func newJaegerTraceProvider(ctx context.Context) (*trace.TracerProvider, error)
|
|||||||
// 创建一个使用 HTTP 协议连接本机Jaeger的 Exporter
|
// 创建一个使用 HTTP 协议连接本机Jaeger的 Exporter
|
||||||
res, err := resource.New(ctx,
|
res, err := resource.New(ctx,
|
||||||
resource.WithFromEnv(),
|
resource.WithFromEnv(),
|
||||||
resource.WithProcess(),
|
|
||||||
resource.WithTelemetrySDK(),
|
resource.WithTelemetrySDK(),
|
||||||
resource.WithHost(),
|
resource.WithHost(),
|
||||||
resource.WithAttributes(
|
resource.WithAttributes(
|
||||||
|
@ -12,6 +12,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path"
|
"path"
|
||||||
|
"sort"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
@ -147,6 +148,10 @@ func CheckFileCoverageAndConstructTask(ctx context.Context, fileList []dto.File,
|
|||||||
log.Printf("无法根据要求找到对应录制片段!ID:【%s】,开始时间:【%s】,结束时间:【%s】", task.TaskID, beginDt, endDt)
|
log.Printf("无法根据要求找到对应录制片段!ID:【%s】,开始时间:【%s】,结束时间:【%s】", task.TaskID, beginDt, endDt)
|
||||||
return nil, fmt.Errorf("无法根据要求找到对应录制片段")
|
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 {
|
if len(fileList) > 1 {
|
||||||
@ -180,7 +185,7 @@ func CheckFileCoverageAndConstructTask(ctx context.Context, fileList []dto.File,
|
|||||||
Offset: int(beginDt.Sub(fileList[0].StartTime).Seconds()),
|
Offset: int(beginDt.Sub(fileList[0].StartTime).Seconds()),
|
||||||
OutputFile: path.Join(os.TempDir(), task.TaskID+".mp4"),
|
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.offset", ffmpegTask.Offset))
|
||||||
span.SetAttributes(attribute.Int("task.length", ffmpegTask.Length))
|
span.SetAttributes(attribute.Int("task.length", ffmpegTask.Length))
|
||||||
span.SetStatus(codes.Ok, "FFMPEG任务构造成功")
|
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) {
|
func handleFfmpegProcess(ctx context.Context, ffmpegCmd []string) (bool, error) {
|
||||||
_, span := tracer.Start(ctx, "handleFfmpegProcess")
|
_, span := tracer.Start(ctx, "handleFfmpegProcess")
|
||||||
defer span.End()
|
defer span.End()
|
||||||
span.SetAttributes(attribute.String("ffmpeg.cmd", strings.Join(ffmpegCmd, " ")))
|
span.SetAttributes(attribute.String("ffmpeg.cmd", ToJson(ffmpegCmd)))
|
||||||
startTime := time.Now()
|
startTime := time.Now()
|
||||||
defer func() {
|
defer func() {
|
||||||
span.SetAttributes(attribute.Int64("ffmpeg.duration", int64(time.Since(startTime).Seconds())))
|
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",
|
"-of", "default=noprint_wrappers=1:nokey=1",
|
||||||
filePath,
|
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:]...)
|
cmd := exec.Command(ffprobeCmd[0], ffprobeCmd[1:]...)
|
||||||
var out bytes.Buffer
|
var out bytes.Buffer
|
||||||
cmd.Stdout = &out
|
cmd.Stdout = &out
|
||||||
|
@ -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 {
|
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
|
return filteredFiles
|
||||||
|
11
util/json.go
Normal file
11
util/json.go
Normal 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)
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user