Skip to content

Commit d24028b

Browse files
committed
fix: ci lint
1 parent 79c072c commit d24028b

10 files changed

Lines changed: 253 additions & 146 deletions

File tree

core/common/reqlimit/main.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010

1111
var (
1212
memoryGroupModelLimiter = NewInMemoryRecord()
13-
redisGroupModelLimiter = NewRedisGroupModelRecord()
13+
redisGroupModelLimiter = newRedisGroupModelRecord()
1414
)
1515

1616
func PushGroupModelRequest(ctx context.Context, group, model string, max int64) (int64, int64, int64) {
@@ -40,7 +40,7 @@ func GetGroupModelRequest(ctx context.Context, group, model string) (int64, int6
4040

4141
var (
4242
memoryGroupModelTokennameLimiter = NewInMemoryRecord()
43-
redisGroupModelTokennameLimiter = NewRedisGroupModelTokennameRecord()
43+
redisGroupModelTokennameLimiter = newRedisGroupModelTokennameRecord()
4444
)
4545

4646
func PushGroupModelTokennameRequest(ctx context.Context, group, model, tokenname string) (int64, int64, int64) {
@@ -73,7 +73,7 @@ func GetGroupModelTokennameRequest(ctx context.Context, group, model, tokenname
7373

7474
var (
7575
memoryChannelModelRecord = NewInMemoryRecord()
76-
redisChannelModelRecord = NewRedisChannelModelRecord()
76+
redisChannelModelRecord = newRedisChannelModelRecord()
7777
)
7878

7979
func PushChannelModelRequest(ctx context.Context, channel, model string) (int64, int64, int64) {
@@ -106,7 +106,7 @@ func GetChannelModelRequest(ctx context.Context, channel, model string) (int64,
106106

107107
var (
108108
memoryGroupModelTokensLimiter = NewInMemoryRecord()
109-
redisGroupModelTokensLimiter = NewRedisGroupModelTokennameTokensRecord()
109+
redisGroupModelTokensLimiter = newRedisGroupModelTokensRecord()
110110
)
111111

112112
func PushGroupModelTokensRequest(ctx context.Context, group, model string, maxTokens int64, tokens int64) (int64, int64, int64) {
@@ -136,7 +136,7 @@ func GetGroupModelTokensRequest(ctx context.Context, group, model string) (int64
136136

137137
var (
138138
memoryGroupModelTokennameTokensLimiter = NewInMemoryRecord()
139-
redisGroupModelTokennameTokensLimiter = NewRedisGroupModelTokennameTokensRecord()
139+
redisGroupModelTokennameTokensLimiter = newRedisGroupModelTokennameTokensRecord()
140140
)
141141

142142
func PushGroupModelTokennameTokensRequest(ctx context.Context, group, model, tokenname string, tokens int64) (int64, int64, int64) {
@@ -169,7 +169,7 @@ func GetGroupModelTokennameTokensRequest(ctx context.Context, group, model, toke
169169

170170
var (
171171
memoryChannelModelTokensRecord = NewInMemoryRecord()
172-
redisChannelModelTokensRecord = NewRedisChannelModelTokensRecord()
172+
redisChannelModelTokensRecord = newRedisChannelModelTokensRecord()
173173
)
174174

175175
func PushChannelModelTokensRequest(ctx context.Context, channel, model string, tokens int64) (int64, int64, int64) {

core/common/reqlimit/mem.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ func (m *InMemoryRecord) cleanupAndCount(e *entry, cutoff int64) (int64, int64)
5656
return normalCount, overCount
5757
}
5858

59-
func (m *InMemoryRecord) PushRequest(max int64, duration time.Duration, n int64, keys ...string) (normalCount int64, overCount int64, secondCount int64) {
59+
func (m *InMemoryRecord) PushRequest(overed int64, duration time.Duration, n int64, keys ...string) (normalCount int64, overCount int64, secondCount int64) {
6060
e := m.getEntry(keys)
6161

6262
e.Lock()
@@ -76,7 +76,7 @@ func (m *InMemoryRecord) PushRequest(max int64, duration time.Duration, n int64,
7676
e.windows[windowStart] = wc
7777
}
7878

79-
if max == 0 || normalCount <= max {
79+
if overed == 0 || normalCount <= overed {
8080
wc.normal += n
8181
normalCount += n
8282
} else {

core/common/reqlimit/mem_test.go

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,24 +38,25 @@ func TestPushRequestRateLimit(t *testing.T) {
3838
maxReq := int64(2)
3939
duration := 60 * time.Second
4040

41-
for i := 0; i < 4; i++ {
41+
for i := range 4 {
4242
normalCount, overCount, _ := rl.PushRequest(maxReq, duration, 1, "group1", "model1")
4343

44-
if i < 2 {
44+
switch {
45+
case i < 2:
4546
if normalCount != int64(i+1) {
4647
t.Errorf("Request %d: expected normalCount %d, got %d", i+1, i+1, normalCount)
4748
}
4849
if overCount != 0 {
4950
t.Errorf("Request %d: expected overCount 0, got %d", i+1, overCount)
5051
}
51-
} else if i == 2 {
52+
case i == 2:
5253
if normalCount != 3 {
5354
t.Errorf("Request %d: expected normalCount 3, got %d", i+1, normalCount)
5455
}
5556
if overCount != 0 {
5657
t.Errorf("Request %d: expected overCount 0, got %d", i+1, overCount)
5758
}
58-
} else {
59+
case i == 3:
5960
if normalCount != 3 {
6061
t.Errorf("Request %d: expected normalCount 3, got %d", i+1, normalCount)
6162
}
@@ -69,7 +70,7 @@ func TestPushRequestRateLimit(t *testing.T) {
6970
func TestPushRequestUnlimited(t *testing.T) {
7071
rl := reqlimit.NewInMemoryRecord()
7172

72-
for i := 0; i < 5; i++ {
73+
for i := range 5 {
7374
normalCount, overCount, _ := rl.PushRequest(0, 60*time.Second, 1, "group1", "model1")
7475

7576
if normalCount != int64(i+1) {
@@ -153,8 +154,8 @@ func TestConcurrentAccess(t *testing.T) {
153154
var wg sync.WaitGroup
154155
wg.Add(numGoroutines)
155156

156-
for i := 0; i < numGoroutines; i++ {
157-
go func(id int) {
157+
for i := range numGoroutines {
158+
go func(_ int) {
158159
defer wg.Done()
159160
for j := 0; j < requestsPerGoroutine; j++ {
160161
rl.PushRequest(0, 60*time.Second, 1, "group1", "model1")
@@ -178,7 +179,7 @@ func TestConcurrentDifferentKeys(t *testing.T) {
178179
var wg sync.WaitGroup
179180
wg.Add(numGoroutines)
180181

181-
for i := 0; i < numGoroutines; i++ {
182+
for i := range numGoroutines {
182183
go func(id int) {
183184
defer wg.Done()
184185
group := fmt.Sprintf("group%d", id%5)
@@ -202,7 +203,7 @@ func TestRateLimitWithOverflow(t *testing.T) {
202203
maxReq := 5
203204
duration := 60 * time.Second
204205

205-
for i := 0; i < 10; i++ {
206+
for i := range 10 {
206207
normalCount, overCount, _ := rl.PushRequest(int64(maxReq), duration, 1, "group1", "model1")
207208

208209
if i < maxReq {
@@ -252,7 +253,7 @@ func BenchmarkPushRequest(b *testing.B) {
252253
func BenchmarkGetRequest(b *testing.B) {
253254
rl := reqlimit.NewInMemoryRecord()
254255

255-
for i := 0; i < 100; i++ {
256+
for i := range 100 {
256257
group := fmt.Sprintf("group%d", i%10)
257258
model := fmt.Sprintf("model%d", i%5)
258259
rl.PushRequest(100, 60*time.Second, 1, group, model)

core/common/reqlimit/redis.go

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,43 +15,37 @@ type redisRateRecord struct {
1515
prefix string
1616
}
1717

18-
func NewRedisRecord(prefix string) *redisRateRecord {
19-
return &redisRateRecord{
20-
prefix: prefix,
21-
}
22-
}
23-
24-
func NewRedisGroupModelRecord() *redisRateRecord {
18+
func newRedisGroupModelRecord() *redisRateRecord {
2519
return &redisRateRecord{
2620
prefix: "group-model-record",
2721
}
2822
}
2923

30-
func NewRedisGroupModelTokennameRecord() *redisRateRecord {
24+
func newRedisGroupModelTokennameRecord() *redisRateRecord {
3125
return &redisRateRecord{
3226
prefix: "group-model-tokenname-record",
3327
}
3428
}
3529

36-
func NewRedisChannelModelRecord() *redisRateRecord {
30+
func newRedisChannelModelRecord() *redisRateRecord {
3731
return &redisRateRecord{
3832
prefix: "channel-model-record",
3933
}
4034
}
4135

42-
func NewRedisGroupModelTokensRecord() *redisRateRecord {
36+
func newRedisGroupModelTokensRecord() *redisRateRecord {
4337
return &redisRateRecord{
4438
prefix: "group-model-tokens-record",
4539
}
4640
}
4741

48-
func NewRedisGroupModelTokennameTokensRecord() *redisRateRecord {
42+
func newRedisGroupModelTokennameTokensRecord() *redisRateRecord {
4943
return &redisRateRecord{
5044
prefix: "group-model-tokenname-tokens-record",
5145
}
5246
}
5347

54-
func NewRedisChannelModelTokensRecord() *redisRateRecord {
48+
func newRedisChannelModelTokensRecord() *redisRateRecord {
5549
return &redisRateRecord{
5650
prefix: "channel-model-tokens-record",
5751
}
@@ -190,7 +184,7 @@ func (r *redisRateRecord) GetRequest(ctx context.Context, duration time.Duration
190184
return totalCountInt, secondCountInt, nil
191185
}
192186

193-
func (r *redisRateRecord) PushRequest(ctx context.Context, max int64, duration time.Duration, n int64, keys ...string) (normalCount int64, overCount int64, secondCount int64, err error) {
187+
func (r *redisRateRecord) PushRequest(ctx context.Context, overed int64, duration time.Duration, n int64, keys ...string) (normalCount int64, overCount int64, secondCount int64, err error) {
194188
key := r.buildKey(keys...)
195189

196190
result, err := pushRequestScript.Run(
@@ -199,7 +193,7 @@ func (r *redisRateRecord) PushRequest(ctx context.Context, max int64, duration t
199193
[]string{key},
200194
duration.Seconds(),
201195
time.Now().Unix(),
202-
max,
196+
overed,
203197
n,
204198
).Text()
205199
if err != nil {

core/controller/dashboard.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ func GetGroupDashboardModels(c *gin.Context) {
279279
// @Param channel query int false "Channel ID"
280280
// @Param start_timestamp query int64 false "Start timestamp"
281281
// @Param end_timestamp query int64 false "End timestamp"
282-
// @Success 200 {object} middleware.APIResponse{data=[]model.ModelCostRank}
282+
// @Success 200 {object} middleware.APIResponse{data=[]model.CostRank}
283283
// @Router /api/model_cost_rank/ [get]
284284
func GetModelCostRank(c *gin.Context) {
285285
group := c.Query("group")
@@ -303,7 +303,7 @@ func GetModelCostRank(c *gin.Context) {
303303
// @Param group path string true "Group"
304304
// @Param start_timestamp query int64 false "Start timestamp"
305305
// @Param end_timestamp query int64 false "End timestamp"
306-
// @Success 200 {object} middleware.APIResponse{data=[]model.ModelCostRank}
306+
// @Success 200 {object} middleware.APIResponse{data=[]model.CostRank}
307307
// @Router /api/model_cost_rank/{group} [get]
308308
func GetGroupModelCostRank(c *gin.Context) {
309309
group := c.Param("group")

core/controller/relay-controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ func (w *warpAdaptor) DoResponse(meta *meta.Meta, c *gin.Context, resp *http.Res
113113
context.Background(),
114114
meta.Group.ID,
115115
meta.OriginModel,
116-
int64(meta.ModelConfig.TPM),
116+
meta.ModelConfig.TPM,
117117
int64(usage.TotalTokens),
118118
)
119119
reqlimit.PushGroupModelTokennameTokensRequest(

0 commit comments

Comments
 (0)