fix: filter perf metrics summary by active groups (#4976)
This commit is contained in:
@@ -8,6 +8,7 @@ import (
|
||||
"github.com/QuantumNous/new-api/setting/ratio_setting"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/samber/lo"
|
||||
)
|
||||
|
||||
func GetPerfMetricsSummary(c *gin.Context) {
|
||||
@@ -18,7 +19,8 @@ func GetPerfMetricsSummary(c *gin.Context) {
|
||||
}
|
||||
}
|
||||
|
||||
result, err := perfmetrics.QuerySummaryAll(hours)
|
||||
activeGroups := append(lo.Keys(ratio_setting.GetGroupRatioCopy()), "auto")
|
||||
result, err := perfmetrics.QuerySummaryAll(hours, activeGroups)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{
|
||||
"success": false,
|
||||
@@ -72,12 +74,9 @@ func GetPerfMetrics(c *gin.Context) {
|
||||
}
|
||||
|
||||
func filterActiveGroups(groups []perfmetrics.GroupResult) []perfmetrics.GroupResult {
|
||||
activeGroups := ratio_setting.GetGroupRatioCopy()
|
||||
filtered := make([]perfmetrics.GroupResult, 0, len(groups))
|
||||
for _, g := range groups {
|
||||
if _, ok := activeGroups[g.Group]; ok || g.Group == "auto" {
|
||||
filtered = append(filtered, g)
|
||||
}
|
||||
}
|
||||
return filtered
|
||||
activeRatios := ratio_setting.GetGroupRatioCopy()
|
||||
return lo.Filter(groups, func(g perfmetrics.GroupResult, _ int) bool {
|
||||
_, ok := activeRatios[g.Group]
|
||||
return ok || g.Group == "auto"
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user