chore: add debug log for distributor

This commit is contained in:
JustSong 2025-01-31 17:26:21 +08:00
parent 09911a301d
commit 1fead8e7f7

View File

@ -2,13 +2,15 @@ package middleware
import ( import (
"fmt" "fmt"
"net/http"
"strconv"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"github.com/songquanpeng/one-api/common/ctxkey" "github.com/songquanpeng/one-api/common/ctxkey"
"github.com/songquanpeng/one-api/common/logger" "github.com/songquanpeng/one-api/common/logger"
"github.com/songquanpeng/one-api/model" "github.com/songquanpeng/one-api/model"
"github.com/songquanpeng/one-api/relay/channeltype" "github.com/songquanpeng/one-api/relay/channeltype"
"net/http"
"strconv"
) )
type ModelRequest struct { type ModelRequest struct {
@ -17,6 +19,7 @@ type ModelRequest struct {
func Distribute() func(c *gin.Context) { func Distribute() func(c *gin.Context) {
return func(c *gin.Context) { return func(c *gin.Context) {
ctx := c.Request.Context()
userId := c.GetInt(ctxkey.Id) userId := c.GetInt(ctxkey.Id)
userGroup, _ := model.CacheGetUserGroup(userId) userGroup, _ := model.CacheGetUserGroup(userId)
c.Set(ctxkey.Group, userGroup) c.Set(ctxkey.Group, userGroup)
@ -52,6 +55,7 @@ func Distribute() func(c *gin.Context) {
return return
} }
} }
logger.Debugf(ctx, "user id %d, user group: %s, request model: %s, using channel #%d", userId, userGroup, requestModel, channel.Id)
SetupContextForSelectedChannel(c, channel, requestModel) SetupContextForSelectedChannel(c, channel, requestModel)
c.Next() c.Next()
} }