Skip to content

Commit ad9d132

Browse files
committed
fixbug-修复创建限流默认时间问题
1 parent 7ae1a34 commit ad9d132

File tree

3 files changed

+48
-2
lines changed

3 files changed

+48
-2
lines changed

store/postgresql/default.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ const (
3434
// DefaultConnMaxLifetime default maximum connection lifetime
3535
DefaultConnMaxLifetime = 60 * 30 // 默认是30分钟
3636
// emptyEnableTime 规则禁用时启用时间的默认值
37-
emptyEnableTime = "STR_TO_DATE('1980-01-01 00:00:01', '%Y-%m-%d %H:%i:%s')"
37+
emptyEnableTime = "1980-01-01 00:00:01"
3838
)
3939

4040
// PostgresqlStore 实现了Store接口

store/postgresql/ratelimit_config.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@ func (rls *rateLimitStore) createRateLimit(limit *model.RateLimit) error {
7171
}()
7272

7373
etimeStr := limitToEtimeStr(limit)
74+
disable := 0
75+
if limit.Disable {
76+
disable = 1
77+
}
7478
// 新建限流规则
7579
str := "insert into ratelimit_config(id, name, disable, service_id, " +
7680
"method, labels, priority, rule, revision, ctime, mtime, etime) " +
@@ -79,7 +83,7 @@ func (rls *rateLimitStore) createRateLimit(limit *model.RateLimit) error {
7983
if err != nil {
8084
return err
8185
}
82-
if _, err = stmt.Exec(limit.ID, limit.Name, limit.Disable, limit.ServiceID, limit.Method,
86+
if _, err = stmt.Exec(limit.ID, limit.Name, disable, limit.ServiceID, limit.Method,
8387
limit.Labels, limit.Priority, limit.Rule, limit.Revision, GetCurrentTimeFormat(),
8488
GetCurrentTimeFormat(), etimeStr); err != nil {
8589
log.Errorf("[Store][database] create rate limit(%+v), sql %s err: %s", limit, str, err.Error())
+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/**
2+
* Tencent is pleased to support the open source community by making Polaris available.
3+
*
4+
* Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
5+
*
6+
* Licensed under the BSD 3-Clause License (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* https://opensource.org/licenses/BSD-3-Clause
11+
*
12+
* Unless required by applicable law or agreed to in writing, software distributed
13+
* under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
14+
* CONDITIONS OF ANY KIND, either express or implied. See the License for the
15+
* specific language governing permissions and limitations under the License.
16+
*/
17+
18+
package postgresql
19+
20+
import (
21+
"fmt"
22+
"github.com/polarismesh/polaris/common/model"
23+
"testing"
24+
)
25+
26+
func TestCreateRateLimit(t *testing.T) {
27+
obj := initConf()
28+
29+
// Method: Labels: Priority:0 Rule:{"service":{"value":"polaris.limiter"},"namespace":{"value":"Polaris"},"type":1,"amounts":[{"maxAmount":{"value":1},"validDuration":{"seconds":1}}],"action":{"value":"REJECT"},"disable":{},"regex_combine":{"value":true},"method":{"value":{}},"arguments":[{"key":"aa","value":{"value":{"value":"2"}}}],"name":{"value":"aa"},"max_queue_delay":{"value":1}} Revision:52df77fff7c14ec9a5a8306d381091fc Disable:false Valid:false CreateTime:0001-01-01 00:00:00 +0000 UTC ModifyTime:0001-01-01 00:00:00 +0000 UTC EnableTime:0001-01-01 00:00:00 +0000 UTC}),
30+
conf := &model.RateLimit{
31+
ID: "d7af189c1986413ab928d501db200600",
32+
Name: "aa",
33+
Disable: true,
34+
ServiceID: "",
35+
Method: "",
36+
Labels: "",
37+
Priority: 1,
38+
Revision: "4444",
39+
}
40+
err := obj.rateLimitStore.CreateRateLimit(conf)
41+
fmt.Printf("err: %+v\n", err)
42+
}

0 commit comments

Comments
 (0)