fix: 延长数据统计时间

This commit is contained in:
yarnom 2025-08-22 21:05:31 +08:00
parent 75cb5722f8
commit 7ca0198b33

View File

@ -61,9 +61,9 @@ func (e *Exporter) Start(ctx context.Context) error {
}
now := time.Now().In(e.loc)
// 下一个10分钟边界 + 30s
next := alignToNextBucketEnd(now, 10).Add(30 * time.Second)
e.logger.Printf("调度: 当前=%s, 下次执行=%s", now.Format("2006-01-02 15:04:05"), next.Format("2006-01-02 15:04:05"))
// 下一个10分钟边界 + 1分钟改为60秒延迟
next := alignToNextBucketEnd(now, 10).Add(1 * time.Minute)
e.logger.Printf("调度: 当前=%s, 下次执行=%s (延迟1分钟)", now.Format("2006-01-02 15:04:05"), next.Format("2006-01-02 15:04:05"))
delay := time.Until(next)
if delay > 0 {
timer := time.NewTimer(delay)
@ -75,11 +75,11 @@ func (e *Exporter) Start(ctx context.Context) error {
}
}
// 修正:当前时间是桶末,需要导出的是刚结束的上一个桶
// 例如现在是20:50:30应该导出的是20:40桶表示20:40-20:50的数据
// 当前时间是桶末,需要导出的是刚结束的上一个桶
// 例如现在是21:01:00应该导出的是20:50桶表示20:50-21:00的数据
currentTime := time.Now().In(e.loc)
bucketEnd := alignToPrevBucketEnd(currentTime, 10) // 上一个桶末如20:50
bucketStart := bucketEnd.Add(-10 * time.Minute) // 上一个桶开始如20:40
bucketEnd := alignToPrevBucketEnd(currentTime, 10) // 上一个桶末如21:00
bucketStart := bucketEnd.Add(-10 * time.Minute) // 上一个桶开始如20:50
e.logger.Printf("当前时间=%s, 导出桶=%s-%s",
currentTime.Format("2006-01-02 15:04:05"),