Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions bfe_modules/mod_ai_token_auth/mod_ai_token_auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,11 @@ func GetApiKey(req *bfe_basic.Request) string {

// found product handler
func (m *ModuleAITokenAuth) tokenFoundProductHandler(req *bfe_basic.Request) (int, *bfe_http.Response) {
meta := req.GetAiBasicInfo()
if meta == nil {
return bfe_module.BfeHandlerGoOn, nil
}

matched := m.matchTokenRule(req)
if !matched {
// no rule, just pass
Expand Down
22 changes: 18 additions & 4 deletions bfe_util/limit_rate/redis_lr_agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,36 @@ import (
"testing"
"time"

"github.com/bfenetworks/bfe/bfe_util/bns"
"github.com/bfenetworks/bfe/bfe_util/redis_client"
)

func makeRedisClient() redis_client.Client {
filename := "./testdata/name_conf.data"
err := bns.LoadLocalNameConf(filename)
if err != nil {
fmt.Println("LoadLocalNameConf err", err.Error())
}

opts := &redis_client.Options{
ServiceConf: "127.0.0.1:6379",
MaxIdle: 10,
MaxActive: 20,
Wait: true,
//ServiceConf: "127.0.0.1:6379",
ServiceConf: "testredis",

MaxIdle: 10,
MaxActive: 20,
Wait: true,

ConnTimeoutMs: 100,
ReadTimeoutMs: 100,
WriteTimeoutMs: 100,

Password: "",
}
err = opts.Format()
if err != nil {
fmt.Println("Format Options err", err.Error())
}

client := redis_client.NewRedisClient(opts)
return client
}
Expand Down
8 changes: 4 additions & 4 deletions bfe_util/limit_rate/redis_qpm_agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@ import (
"strconv"
)

// QpmCheck performs sliding-window rate limiting.
// Main window: key stores timestamps in a ZSET, period seconds, max limit requests.
// tat returns the current main-window request count (was TAT in GCRA).
func (agent *RedisLRAgent) QpmCheck(
key string,
burst int64,
period int64,
limit int64,
expectUse int64,
Expand All @@ -36,9 +38,7 @@ func (agent *RedisLRAgent) QpmCheck(
return
}

// now := float64(time.Now().UnixNano()) / 1e9
// args := []interface{}{burst, period, limit, expectUse, now}
args := []interface{}{burst, period, limit, expectUse}
args := []interface{}{period, limit, expectUse}

res, errtmp := agent.scriptQpmCheck.Run(key, args...)
if errtmp != nil {
Expand Down
Loading
Loading