refactor(metrics): 移除延迟分布统计的冗余日志输出

- 删除 RecordRequest 和 GetStats 方法中的详细日志记录
- 保留核心的延迟分布统计逻辑,提高代码简洁性
- 减少不必要的日志输出,优化性能和可读性
This commit is contained in:
wood chen 2025-03-09 12:16:44 +08:00
parent 2a41458bb8
commit 006fa9a172

View File

@ -143,17 +143,12 @@ func (c *Collector) RecordRequest(path string, status int, latency time.Duration
bucketKey = "gt1s" bucketKey = "gt1s"
} }
log.Printf("[Metrics] 更新延迟分布: 路径=%s, 延迟=%dms, 桶=%s", path, latencyMs, bucketKey)
if counter, ok := c.latencyBuckets.Load(bucketKey); ok { if counter, ok := c.latencyBuckets.Load(bucketKey); ok {
oldValue := atomic.LoadInt64(counter.(*int64)) atomic.AddInt64(counter.(*int64), 1)
newValue := atomic.AddInt64(counter.(*int64), 1)
log.Printf("[Metrics] 延迟分布桶 %s: %d -> %d", bucketKey, oldValue, newValue)
} else { } else {
counter := new(int64) counter := new(int64)
*counter = 1 *counter = 1
c.latencyBuckets.Store(bucketKey, counter) c.latencyBuckets.Store(bucketKey, counter)
log.Printf("[Metrics] 新建延迟分布桶: %s = 1", bucketKey)
} }
// 更新路径统计 // 更新路径统计
@ -359,19 +354,14 @@ func (c *Collector) GetStats() map[string]interface{} {
if counter != nil { if counter != nil {
value := atomic.LoadInt64(counter.(*int64)) value := atomic.LoadInt64(counter.(*int64))
latencyDistribution[bucket] = value latencyDistribution[bucket] = value
log.Printf("[Metrics] 延迟分布桶 %s = %d", bucket, value)
} else { } else {
latencyDistribution[bucket] = 0 latencyDistribution[bucket] = 0
log.Printf("[Metrics] 延迟分布桶 %s = 0 (counter is nil)", bucket)
} }
} else { } else {
latencyDistribution[bucket] = 0 latencyDistribution[bucket] = 0
log.Printf("[Metrics] 延迟分布桶 %s = 0 (bucket not found)", bucket)
} }
} }
log.Printf("[Metrics] 延迟分布: %v", latencyDistribution)
// 获取最近请求记录(使用读锁) // 获取最近请求记录(使用读锁)
recentRequests := c.recentRequests.GetAll() recentRequests := c.recentRequests.GetAll()