소스 검색

wip:搜索并发数不足告警开发

wangshan 1 년 전
부모
커밋
b13f9f1380
2개의 변경된 파일20개의 추가작업 그리고 3개의 파일을 삭제
  1. 5 1
      jyBXCore/rpc/internal/logic/getsearchlistlogic.go
  2. 15 2
      jyBXCore/rpc/util/limitSearchText.go

+ 5 - 1
jyBXCore/rpc/internal/logic/getsearchlistlogic.go

@@ -155,8 +155,9 @@ func (l *GetSearchListLogic) GetSearchList(in *bxcore.SearchReq) (*bxcore.Search
 	searchLimit := util.IsSearchLimit(strings.Split(in.SelectType, ","))
 	//全文检索限制
 	if searchLimit {
+		var warnMsg string
 		//res.IsLimit = util.IsLimited(in.LimitFlag, in.UserId, in.UserType != "fType", in.IsNew)
-		res.IsLimit = util.CheckLimit(util.UserIdentMap[func(userId string, isPay bool) string {
+		res.IsLimit, warnMsg = util.CheckLimit(util.UserIdentMap[func(userId string, isPay bool) string {
 			switch {
 			case isPay:
 				return "payer"
@@ -169,6 +170,9 @@ func (l *GetSearchListLogic) GetSearchList(in *bxcore.SearchReq) (*bxcore.Search
 		if res.IsLimit == 1 { //没有被限制
 			defer util.Limit()
 		}
+		if warnMsg != "" {
+			util.SendMsgByWXURL(warnMsg)
+		}
 	}
 	//无限制
 	if res.IsLimit == 1 {

+ 15 - 2
jyBXCore/rpc/util/limitSearchText.go

@@ -5,6 +5,7 @@ import (
 	"app.yhyue.com/moapp/jybase/redis"
 	IC "bp.jydev.jianyu360.cn/BaseService/jyMicroservices/jyBXCore/rpc/init"
 	"fmt"
+	"strings"
 )
 
 // 标讯搜索:全文搜索和附件搜索限制
@@ -118,7 +119,7 @@ return -1 抱歉!由于系统繁忙暂时无法进行搜索,请1分钟后再
 return -2 抱歉!由于系统繁忙暂时无法进行搜索,请稍后再试!
 userIdent 未登录用户是;cookie 中存的标识;登录用户是UserId
 */
-func CheckLimit(userType int, userIdent string, isNew bool) (state int64) {
+func CheckLimit(userType int, userIdent string, isNew bool) (state int64, msg string) {
 	if !IC.C.LimitSearchText.Flag {
 		state = 1
 		return
@@ -128,12 +129,14 @@ func CheckLimit(userType int, userIdent string, isNew bool) (state int64) {
 	case -2: //不限制
 		state = 1
 		return
-	case -1:
+	case -1: //无条件限制
 		state = -2
+		msg = fmt.Sprintf("筛选条件:%s,必限制。", strings.Join(IC.C.LimitSearchText.LimitItems, ","))
 		return
 	default:
 		if limitCount <= 0 {
 			state = -1
+			msg = fmt.Sprintf("并发通道总数:%d,\n未使用数量:%d", IC.C.LimitSearchText.Count, limitCount)
 			return
 		}
 	}
@@ -144,6 +147,7 @@ func CheckLimit(userType int, userIdent string, isNew bool) (state int64) {
 				timeLimit, _ := redis.Exists("other", fmt.Sprintf(IC.C.LimitSearchText.LimitKey, userIdent))
 				if timeLimit {
 					state = -1
+					msg = fmt.Sprintf("当前用户筛选频次在%d秒内请求多次,并发通道-\n总数:%d,\n未使用数量:%d", IC.C.LimitSearchText.TimeOut, IC.C.LimitSearchText.Count, limitCount)
 					return
 				}
 			}
@@ -158,21 +162,27 @@ func CheckLimit(userType int, userIdent string, isNew bool) (state int64) {
 		}
 	default:
 		state = -2
+		userStr := MC.If(userType == 2, "免费用户", "未登录用户").(string)
+		msg = fmt.Sprintf("%s 招投标重要字段筛选", userStr)
 		if limitCount > IC.C.LimitSearchText.ForPayer {
 			switch userType {
 			case 2:
 				quota := limitCount * IC.C.LimitSearchText.Percentage / 100
 				if quota > 0 {
 					state = 1
+					msg = ""
 				} else {
 					state = -1
+					msg = fmt.Sprintf("%s,\n总并发量的百分之%d,", msg, IC.C.LimitSearchText.Percentage)
 				}
 			case 3:
 				quota := limitCount * IC.C.LimitSearchText.NoLogin / 100
 				if quota > 0 {
 					state = 1
+					msg = ""
 				} else {
 					state = -1
+					msg = fmt.Sprintf("%s,\n总并发量的百分之%d,", msg, IC.C.LimitSearchText.NoLogin)
 				}
 			}
 		}
@@ -182,5 +192,8 @@ func CheckLimit(userType int, userIdent string, isNew bool) (state int64) {
 	if MC.IntAll(pollLimit) <= 0 {
 		state = -2
 	}
+	if msg != "" {
+		msg = fmt.Sprintf("%s,\n并发通道总数:%d,\n未使用数量:%d", msg, IC.C.LimitSearchText.Count, limitCount)
+	}
 	return
 }