From 76b549aa9099280a425de658890350d1c9381704 Mon Sep 17 00:00:00 2001 From: wood chen Date: Mon, 17 Feb 2025 08:36:05 +0800 Subject: [PATCH] refactor(metrics): Enhance path metrics sorting with secondary lexicographic ordering - Update path metrics sorting to consider request count and path name - Implement secondary sorting by path name when request counts are equal - Improve deterministic ordering of metrics for consistent display --- internal/metrics/collector.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/internal/metrics/collector.go b/internal/metrics/collector.go index ef7d870..c099946 100644 --- a/internal/metrics/collector.go +++ b/internal/metrics/collector.go @@ -254,9 +254,14 @@ func (c *Collector) GetStats() map[string]interface{} { return true }) - // 按请求数降序排序 + // 按请求数降序排序,请求数相同时按路径字典序排序 sort.Slice(pathMetrics, func(i, j int) bool { - return pathMetrics[i].GetRequestCount() > pathMetrics[j].GetRequestCount() + countI := pathMetrics[i].GetRequestCount() + countJ := pathMetrics[j].GetRequestCount() + if countI != countJ { + return countI > countJ + } + return pathMetrics[i].Path < pathMetrics[j].Path }) // 只保留前10个