fix: 接线 Prometheus 指标到连接与投递事件
This commit is contained in:
@@ -43,6 +43,9 @@ type Queue struct {
|
||||
ready bool
|
||||
lastWriteErr error
|
||||
pending int
|
||||
|
||||
// OnBatchCommit 可选;每次合并提交成功后回调耗时(秒级指标用)。
|
||||
OnBatchCommit func(d time.Duration)
|
||||
}
|
||||
|
||||
// NewQueue 创建合并写入队列并启动写 goroutine。
|
||||
@@ -129,6 +132,7 @@ func (q *Queue) loop() {
|
||||
}
|
||||
|
||||
func (q *Queue) runBatch(batch []writeJob) {
|
||||
started := time.Now()
|
||||
defer func() {
|
||||
q.mu.Lock()
|
||||
q.pending -= len(batch)
|
||||
@@ -229,6 +233,9 @@ func (q *Queue) runBatch(batch []writeJob) {
|
||||
}
|
||||
return
|
||||
}
|
||||
if q.OnBatchCommit != nil {
|
||||
q.OnBatchCommit(time.Since(started))
|
||||
}
|
||||
for _, o := range outcomes {
|
||||
if o.success {
|
||||
o.job.res <- nil
|
||||
|
||||
Reference in New Issue
Block a user