Skip to content

Commit

Permalink
fixbug-ratelimit-config
Browse files Browse the repository at this point in the history
  • Loading branch information
bingxindan committed Jul 18, 2023
1 parent 873d4b8 commit 7ae1a34
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 16 deletions.
11 changes: 0 additions & 11 deletions store/postgresql/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -979,17 +979,6 @@ func addMainInstance(tx *BaseTx, instance *model.Instance) error {
"cmdb_region, cmdb_zone, cmdb_idc, priority, revision, ctime, mtime) " +
"values($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, " +
"$15, $16, $17, $18, $19)"
// 此语句暂时留存,ON CONFLICT误法仅支持postgreSQL-11以上的版本
/*str := `
INSERT INTO instance(id, service_id, vpc_id, host, port, protocol, version, health_status, isolate,
weight, enable_health_check, logic_set, cmdb_region, cmdb_zone, cmdb_idc, priority, revision, ctime, mtime)
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19)
ON CONFLICT (id, service_id) DO
UPDATE
SET service_id = $20, vpc_id = $21, host = $22, port = $23, protocol = $24, version = $25,
health_status = $26, isolate = $27, weight = $28, enable_health_check = $29,
logic_set = $30, cmdb_region = $31, cmdb_zone = $32, cmdb_idc = $33, priority = $34,
revision = $35, ctime = $36, mtime = $37`*/
stmt, err := tx.Prepare(str)
if err != nil {
return err
Expand Down
11 changes: 6 additions & 5 deletions store/postgresql/ratelimit_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,16 @@ func (rls *rateLimitStore) createRateLimit(limit *model.RateLimit) error {

etimeStr := limitToEtimeStr(limit)
// 新建限流规则
str := fmt.Sprintf("insert into ratelimit_config(id, name, disable, service_id, "+
"method, labels, priority, rule, revision, ctime, mtime, etime) "+
"values($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11, %s)", etimeStr)
str := "insert into ratelimit_config(id, name, disable, service_id, " +
"method, labels, priority, rule, revision, ctime, mtime, etime) " +
"values($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12)"
stmt, err := tx.Prepare(str)
if err != nil {
return err
}
if _, err = stmt.Exec(limit.ID, limit.Name, limit.Disable, limit.ServiceID, limit.Method, limit.Labels,
limit.Priority, limit.Rule, limit.Revision, GetCurrentTimeFormat(), GetCurrentTimeFormat()); err != nil {
if _, err = stmt.Exec(limit.ID, limit.Name, limit.Disable, limit.ServiceID, limit.Method,
limit.Labels, limit.Priority, limit.Rule, limit.Revision, GetCurrentTimeFormat(),
GetCurrentTimeFormat(), etimeStr); err != nil {
log.Errorf("[Store][database] create rate limit(%+v), sql %s err: %s", limit, str, err.Error())
return err
}
Expand Down

0 comments on commit 7ae1a34

Please # to comment.