fix: Refactor: Migrate Distributor logging to ratio metrics

- Log a ratio for each channel in the context
- Initialize `minimalRatio` to -1 instead of 0
This commit is contained in:
Laisky.Cai
2024-03-01 13:55:21 +00:00
parent dbe3930a8c
commit 2989686ace

View File

@@ -86,13 +86,14 @@ func Distribute() func(c *gin.Context) {
func SetupContextForSelectedChannel(c *gin.Context, channel *model.Channel, modelName string) { func SetupContextForSelectedChannel(c *gin.Context, channel *model.Channel, modelName string) {
// set minimal group ratio as channel_ratio // set minimal group ratio as channel_ratio
var minimalRatio float64 var minimalRatio float64 = -1
for _, grp := range strings.Split(channel.Group, ",") { for _, grp := range strings.Split(channel.Group, ",") {
v := common.GetGroupRatio(grp) v := common.GetGroupRatio(grp)
if minimalRatio == 0 || v < minimalRatio { if minimalRatio < 0 || v < minimalRatio {
minimalRatio = v minimalRatio = v
} }
} }
logger.Info(c.Request.Context(), fmt.Sprintf("set channel %s ratio to %f", channel.Name, minimalRatio))
c.Set("channel_ratio", minimalRatio) c.Set("channel_ratio", minimalRatio)
c.Set("channel", channel.Type) c.Set("channel", channel.Type)