Skip to content

Commit

Permalink
fix: balance and amount log format
Browse files Browse the repository at this point in the history
  • Loading branch information
zijiren233 committed Jan 23, 2025
1 parent 00b5fb7 commit 1dde9db
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
8 changes: 5 additions & 3 deletions service/aiproxy/middleware/distributor.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"net/http"
"slices"
"strconv"
"strings"
"time"

Expand Down Expand Up @@ -117,18 +118,19 @@ type GroupBalanceConsumer struct {
}

func checkGroupBalance(c *gin.Context, group *model.GroupCache) bool {
log := GetLogger(c)
groupBalance, consumer, err := balance.Default.GetGroupRemainBalance(c.Request.Context(), group.ID)
if err != nil {
GetLogger(c).Errorf("get group (%s) balance error: %v", group.ID, err)
log.Errorf("get group (%s) balance error: %v", group.ID, err)
abortWithMessage(c, http.StatusInternalServerError, "get group balance error")
return false
}
log.Data["balance"] = strconv.FormatFloat(groupBalance, 'f', -1, 64)

if groupBalance <= 0 {
abortLogWithMessage(c, http.StatusForbidden, "group balance not enough")
return false
}
log := GetLogger(c)
log.Data["balance"] = groupBalance
c.Set(ctxkey.GroupBalance, &GroupBalanceConsumer{
GroupBalance: groupBalance,
Consumer: consumer,
Expand Down
3 changes: 2 additions & 1 deletion service/aiproxy/relay/controller/handle.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"errors"
"fmt"
"net/http"
"strconv"

"github.com/gin-gonic/gin"
"github.com/labring/sealos/service/aiproxy/common"
Expand Down Expand Up @@ -121,7 +122,7 @@ func Handle(meta *meta.Meta, c *gin.Context, preProcess func() (*PreCheckGroupBa

amount := consume.CalculateAmount(usage, preCheckReq.InputPrice, preCheckReq.OutputPrice)
if amount > 0 {
log.Data["amount"] = amount
log.Data["amount"] = strconv.FormatFloat(amount, 'f', -1, 64)
}

// 6. Post consume
Expand Down

0 comments on commit 1dde9db

Please sign in to comment.