瀏覽代碼

chore: change some notify interval (#385)

zijiren 2 月之前
父節點
當前提交
fb13f87bb3

+ 1 - 1
core/common/consume/consume.go

@@ -113,7 +113,7 @@ func Consume(
 	)
 	if err != nil {
 		log.Error("error batch record consume: " + err.Error())
-		notify.ErrorThrottle("recordConsume", time.Minute, "record consume failed", err.Error())
+		notify.ErrorThrottle("recordConsume", time.Minute*5, "record consume failed", err.Error())
 	}
 }
 

+ 3 - 3
core/main.go

@@ -248,7 +248,7 @@ func detectIPGroups() {
 
 func cleanLog(ctx context.Context) {
 	// the interval should not be too large to avoid cleaning too much at once
-	ticker := time.NewTicker(time.Minute)
+	ticker := time.NewTicker(time.Second * 5)
 	defer ticker.Stop()
 
 	for {
@@ -256,7 +256,7 @@ func cleanLog(ctx context.Context) {
 		case <-ctx.Done():
 			return
 		case <-ticker.C:
-			if !trylock.Lock("cleanLog", time.Minute) {
+			if !trylock.Lock("cleanLog", time.Second*5) {
 				continue
 			}
 
@@ -264,7 +264,7 @@ func cleanLog(ctx context.Context) {
 
 			err := model.CleanLog(int(config.GetCleanLogBatchSize()), optimize)
 			if err != nil {
-				notify.ErrorThrottle("cleanLog", time.Minute, "clean log failed", err.Error())
+				notify.ErrorThrottle("cleanLog", time.Minute*5, "clean log failed", err.Error())
 			}
 		}
 	}

+ 2 - 2
core/middleware/distributor.go

@@ -270,7 +270,7 @@ func checkGroupBalance(c *gin.Context, group model.GroupCache) bool {
 
 		notify.ErrorThrottle(
 			"getGroupBalanceError",
-			time.Minute,
+			time.Minute*3,
 			fmt.Sprintf("Get group `%s` balance error", group.ID),
 			err.Error(),
 		)
@@ -288,7 +288,7 @@ func checkGroupBalance(c *gin.Context, group model.GroupCache) bool {
 		!gbc.CheckBalance(group.BalanceAlertThreshold) {
 		notify.ErrorThrottle(
 			"groupBalanceAlert:"+group.ID,
-			time.Minute*15,
+			time.Minute*30,
 			fmt.Sprintf("Group `%s` balance below threshold", group.ID),
 			fmt.Sprintf(
 				"Group `%s` balance has fallen below the threshold\nCurrent balance: %.2f",

+ 3 - 3
core/middleware/recover.go

@@ -48,17 +48,17 @@ func GinRecoveryHandler(c *gin.Context) {
 			switch {
 			case brokenPipe:
 				notify.ErrorThrottle("ginPanicRecovery:"+fileLine,
-					time.Minute, "Panic Detected",
+					time.Minute*5, "Panic Detected",
 					fmt.Sprintf("%s\n%s", err, headersToStr))
 			case gin.IsDebugging():
 				notify.ErrorThrottle("ginPanicRecovery:"+fileLine,
-					time.Minute, "Panic Detected",
+					time.Minute*5, "Panic Detected",
 					fmt.Sprintf("[Recovery] panic recovered:\n%s\n%s\n%s",
 						headersToStr, err, stack),
 				)
 			default:
 				notify.ErrorThrottle("ginPanicRecovery:"+fileLine,
-					time.Minute, "Panic Detected",
+					time.Minute*5, "Panic Detected",
 					fmt.Sprintf("[Recovery] panic recovered:\n%s\n%s",
 						err, stack),
 				)

+ 7 - 7
core/model/batch.go

@@ -171,7 +171,7 @@ func processGroupUpdates(wg *sync.WaitGroup) {
 		if IgnoreNotFound(err) != nil {
 			notify.ErrorThrottle(
 				"batchUpdateGroupUsedAmountAndRequestCount",
-				time.Minute,
+				time.Minute*10,
 				"failed to batch update group",
 				err.Error(),
 			)
@@ -189,7 +189,7 @@ func processTokenUpdates(wg *sync.WaitGroup) {
 		if IgnoreNotFound(err) != nil {
 			notify.ErrorThrottle(
 				"batchUpdateTokenUsedAmount",
-				time.Minute,
+				time.Minute*10,
 				"failed to batch update token",
 				err.Error(),
 			)
@@ -212,7 +212,7 @@ func processChannelUpdates(wg *sync.WaitGroup) {
 		if IgnoreNotFound(err) != nil {
 			notify.ErrorThrottle(
 				"batchUpdateChannelUsedAmount",
-				time.Minute,
+				time.Minute*10,
 				"failed to batch update channel",
 				err.Error(),
 			)
@@ -230,7 +230,7 @@ func processGroupSummaryUpdates(wg *sync.WaitGroup) {
 		if err != nil {
 			notify.ErrorThrottle(
 				"batchUpdateGroupSummary",
-				time.Minute,
+				time.Minute*10,
 				"failed to batch update group summary",
 				err.Error(),
 			)
@@ -248,7 +248,7 @@ func processGroupSummaryMinuteUpdates(wg *sync.WaitGroup) {
 		if err != nil {
 			notify.ErrorThrottle(
 				"batchUpdateGroupSummary",
-				time.Minute,
+				time.Minute*10,
 				"failed to batch update group summary",
 				err.Error(),
 			)
@@ -266,7 +266,7 @@ func processSummaryUpdates(wg *sync.WaitGroup) {
 		if err != nil {
 			notify.ErrorThrottle(
 				"batchUpdateSummary",
-				time.Minute,
+				time.Minute*10,
 				"failed to batch update summary",
 				err.Error(),
 			)
@@ -284,7 +284,7 @@ func processSummaryMinuteUpdates(wg *sync.WaitGroup) {
 		if err != nil {
 			notify.ErrorThrottle(
 				"batchUpdateSummaryMinute",
-				time.Minute,
+				time.Minute*10,
 				"failed to batch update summary minute",
 				err.Error(),
 			)

+ 1 - 1
core/model/cache.go

@@ -1154,7 +1154,7 @@ func SyncModelConfigAndChannelCache(
 			if err != nil {
 				notify.ErrorThrottle(
 					"syncModelChannel",
-					time.Minute,
+					time.Minute*5,
 					"failed to sync channels",
 					err.Error(),
 				)

+ 5 - 5
core/model/main.go

@@ -217,7 +217,7 @@ func migrateLOGDB(batchSize int) error {
 		if err != nil {
 			notify.ErrorThrottle(
 				"createLogIndexes",
-				time.Minute,
+				time.Minute*10,
 				"failed to create log indexes",
 				err.Error(),
 			)
@@ -227,7 +227,7 @@ func migrateLOGDB(batchSize int) error {
 		if err != nil {
 			notify.ErrorThrottle(
 				"createSummaryIndexs",
-				time.Minute,
+				time.Minute*10,
 				"failed to create summary indexs",
 				err.Error(),
 			)
@@ -237,7 +237,7 @@ func migrateLOGDB(batchSize int) error {
 		if err != nil {
 			notify.ErrorThrottle(
 				"createGroupSummaryIndexs",
-				time.Minute,
+				time.Minute*10,
 				"failed to create group summary indexs",
 				err.Error(),
 			)
@@ -247,7 +247,7 @@ func migrateLOGDB(batchSize int) error {
 		if err != nil {
 			notify.ErrorThrottle(
 				"createSummaryMinuteIndexs",
-				time.Minute,
+				time.Minute*10,
 				"failed to create summary minute indexs",
 				err.Error(),
 			)
@@ -257,7 +257,7 @@ func migrateLOGDB(batchSize int) error {
 		if err != nil {
 			notify.ErrorThrottle(
 				"createSummaryMinuteIndexs",
-				time.Minute,
+				time.Minute*10,
 				"failed to create group summary minute indexs",
 				err.Error(),
 			)

+ 1 - 1
core/model/option.go

@@ -178,7 +178,7 @@ func SyncOptions(ctx context.Context, wg *sync.WaitGroup, frequency time.Duratio
 			if err := loadOptionsFromDatabase(false); err != nil {
 				notify.ErrorThrottle(
 					"syncOptions",
-					time.Minute,
+					time.Minute*5,
 					"failed to sync options",
 					err.Error(),
 				)

+ 18 - 6
core/relay/plugin/monitor/monitor.go

@@ -134,6 +134,7 @@ func handleDoRequestError(meta *meta.Meta, c *gin.Context, err error, requestCos
 			"Auto Banned",
 			err,
 			requestCost,
+			time.Minute*15,
 		)
 	case beyondThreshold:
 		notifyChannelRequestIssue(
@@ -142,6 +143,7 @@ func handleDoRequestError(meta *meta.Meta, c *gin.Context, err error, requestCos
 			"Error Rate Beyond Threshold",
 			err,
 			requestCost,
+			time.Minute*15,
 		)
 	}
 }
@@ -151,6 +153,7 @@ func notifyChannelRequestIssue(
 	issueType, titleSuffix string,
 	err error,
 	requestCost time.Duration,
+	interval time.Duration,
 ) {
 	var notifyFunc func(title, message string)
 
@@ -164,11 +167,11 @@ func notifyChannelRequestIssue(
 	switch issueType {
 	case "beyondThreshold":
 		notifyFunc = func(title, message string) {
-			notify.WarnThrottle(lockKey, time.Minute, title, message)
+			notify.WarnThrottle(lockKey, interval, title, message)
 		}
 	default:
 		notifyFunc = func(title, message string) {
-			notify.ErrorThrottle(lockKey, time.Minute, title, message)
+			notify.ErrorThrottle(lockKey, interval, title, message)
 		}
 	}
 
@@ -253,7 +256,7 @@ func handleAdaptorError(meta *meta.Meta, c *gin.Context, relayErr adaptor.Error)
 
 	switch {
 	case banExecution:
-		notifyChannelResponseIssue(c, meta, "autoBanned", "Auto Banned", relayErr)
+		notifyChannelResponseIssue(c, meta, "autoBanned", "Auto Banned", relayErr, time.Minute*15)
 	case beyondThreshold:
 		notifyChannelResponseIssue(
 			c,
@@ -261,9 +264,17 @@ func handleAdaptorError(meta *meta.Meta, c *gin.Context, relayErr adaptor.Error)
 			"beyondThreshold",
 			"Error Rate Beyond Threshold",
 			relayErr,
+			time.Minute*15,
 		)
 	case !hasPermission:
-		notifyChannelResponseIssue(c, meta, "channelHasPermission", "No Permission", relayErr)
+		notifyChannelResponseIssue(
+			c,
+			meta,
+			"channelHasPermission",
+			"No Permission",
+			relayErr,
+			time.Minute*15,
+		)
 	}
 }
 
@@ -272,6 +283,7 @@ func notifyChannelResponseIssue(
 	meta *meta.Meta,
 	issueType, titleSuffix string,
 	err adaptor.Error,
+	interval time.Duration,
 ) {
 	var notifyFunc func(title, message string)
 
@@ -286,11 +298,11 @@ func notifyChannelResponseIssue(
 	switch issueType {
 	case "beyondThreshold", "requestRateLimitExceeded":
 		notifyFunc = func(title, message string) {
-			notify.WarnThrottle(lockKey, time.Minute, title, message)
+			notify.WarnThrottle(lockKey, interval, title, message)
 		}
 	default:
 		notifyFunc = func(title, message string) {
-			notify.ErrorThrottle(lockKey, time.Minute, title, message)
+			notify.ErrorThrottle(lockKey, interval, title, message)
 		}
 	}