mirror of
				https://github.com/openimsdk/open-im-server.git
				synced 2025-10-26 21:22:16 +08:00 
			
		
		
		
	feat: optimize log print
This commit is contained in:
		
							parent
							
								
									aeb7b0ac0a
								
							
						
					
					
						commit
						c7fae5bf6d
					
				
							
								
								
									
										2
									
								
								go.mod
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								go.mod
									
									
									
									
									
								
							| @ -13,7 +13,7 @@ require ( | |||||||
| 	github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 | 	github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 | ||||||
| 	github.com/mitchellh/mapstructure v1.5.0 | 	github.com/mitchellh/mapstructure v1.5.0 | ||||||
| 	github.com/openimsdk/protocol v0.0.72-alpha.71 | 	github.com/openimsdk/protocol v0.0.72-alpha.71 | ||||||
| 	github.com/openimsdk/tools v0.0.50-alpha.65 | 	github.com/openimsdk/tools v0.0.50-alpha.70 | ||||||
| 	github.com/pkg/errors v0.9.1 // indirect | 	github.com/pkg/errors v0.9.1 // indirect | ||||||
| 	github.com/prometheus/client_golang v1.18.0 | 	github.com/prometheus/client_golang v1.18.0 | ||||||
| 	github.com/stretchr/testify v1.9.0 | 	github.com/stretchr/testify v1.9.0 | ||||||
|  | |||||||
							
								
								
									
										4
									
								
								go.sum
									
									
									
									
									
								
							
							
						
						
									
										4
									
								
								go.sum
									
									
									
									
									
								
							| @ -349,8 +349,8 @@ github.com/openimsdk/gomake v0.0.15-alpha.2 h1:5Q8yl8ezy2yx+q8/ucU/t4kJnDfCzNOrk | |||||||
| github.com/openimsdk/gomake v0.0.15-alpha.2/go.mod h1:PndCozNc2IsQIciyn9mvEblYWZwJmAI+06z94EY+csI= | github.com/openimsdk/gomake v0.0.15-alpha.2/go.mod h1:PndCozNc2IsQIciyn9mvEblYWZwJmAI+06z94EY+csI= | ||||||
| github.com/openimsdk/protocol v0.0.72-alpha.71 h1:R3utzOlqepaJWTAmnfJi4ccUM/XIoFasSyjQMOipM70= | github.com/openimsdk/protocol v0.0.72-alpha.71 h1:R3utzOlqepaJWTAmnfJi4ccUM/XIoFasSyjQMOipM70= | ||||||
| github.com/openimsdk/protocol v0.0.72-alpha.71/go.mod h1:WF7EuE55vQvpyUAzDXcqg+B+446xQyEba0X35lTINmw= | github.com/openimsdk/protocol v0.0.72-alpha.71/go.mod h1:WF7EuE55vQvpyUAzDXcqg+B+446xQyEba0X35lTINmw= | ||||||
| github.com/openimsdk/tools v0.0.50-alpha.65 h1:BRtxkyWxDWPHuHphSwEyHZj7kJSR98am/fHOH84naK8= | github.com/openimsdk/tools v0.0.50-alpha.70 h1:pyqWkJzXbELWU9KKAsWkj3g0flJYNsDTcjR5SLFQAZU= | ||||||
| github.com/openimsdk/tools v0.0.50-alpha.65/go.mod h1:B+oqV0zdewN7OiEHYJm+hW+8/Te7B8tHHgD8rK5ZLZk= | github.com/openimsdk/tools v0.0.50-alpha.70/go.mod h1:B+oqV0zdewN7OiEHYJm+hW+8/Te7B8tHHgD8rK5ZLZk= | ||||||
| github.com/pelletier/go-toml/v2 v2.2.2 h1:aYUidT7k73Pcl9nb2gScu7NSrKCSHIDE89b3+6Wq+LM= | github.com/pelletier/go-toml/v2 v2.2.2 h1:aYUidT7k73Pcl9nb2gScu7NSrKCSHIDE89b3+6Wq+LM= | ||||||
| github.com/pelletier/go-toml/v2 v2.2.2/go.mod h1:1t835xjRzz80PqgE6HHgN2JOsmgYu/h4qDAS4n929Rs= | github.com/pelletier/go-toml/v2 v2.2.2/go.mod h1:1t835xjRzz80PqgE6HHgN2JOsmgYu/h4qDAS4n929Rs= | ||||||
| github.com/pierrec/lz4/v4 v4.1.21 h1:yOVMLb6qSIDP67pl/5F7RepeKYu/VmTyEXvuMI5d9mQ= | github.com/pierrec/lz4/v4 v4.1.21 h1:yOVMLb6qSIDP67pl/5F7RepeKYu/VmTyEXvuMI5d9mQ= | ||||||
|  | |||||||
| @ -3,11 +3,12 @@ package push | |||||||
| import ( | import ( | ||||||
| 	"context" | 	"context" | ||||||
| 	"encoding/json" | 	"encoding/json" | ||||||
| 	"github.com/openimsdk/open-im-server/v3/pkg/rpcli" |  | ||||||
| 	"math/rand" | 	"math/rand" | ||||||
| 	"strconv" | 	"strconv" | ||||||
| 	"time" | 	"time" | ||||||
| 
 | 
 | ||||||
|  | 	"github.com/openimsdk/open-im-server/v3/pkg/rpcli" | ||||||
|  | 
 | ||||||
| 	"github.com/IBM/sarama" | 	"github.com/IBM/sarama" | ||||||
| 	"github.com/openimsdk/open-im-server/v3/internal/push/offlinepush" | 	"github.com/openimsdk/open-im-server/v3/internal/push/offlinepush" | ||||||
| 	"github.com/openimsdk/open-im-server/v3/internal/push/offlinepush/options" | 	"github.com/openimsdk/open-im-server/v3/internal/push/offlinepush/options" | ||||||
| @ -152,24 +153,24 @@ func (c *ConsumerHandler) Push2User(ctx context.Context, userIDs []string, msg * | |||||||
| 	log.ZInfo(ctx, "Get msg from msg_transfer And push msg", "userIDs", userIDs, "msg", msg.String()) | 	log.ZInfo(ctx, "Get msg from msg_transfer And push msg", "userIDs", userIDs, "msg", msg.String()) | ||||||
| 	defer func(duration time.Time) { | 	defer func(duration time.Time) { | ||||||
| 		t := time.Since(duration) | 		t := time.Since(duration) | ||||||
| 		log.ZInfo(ctx, "Get msg from msg_transfer And push msg", "msg", msg.String(), "time cost", t) | 		log.ZInfo(ctx, "Get msg from msg_transfer And push msg end", "msg", msg.String(), "time cost", t) | ||||||
| 	}(time.Now()) | 	}(time.Now()) | ||||||
| 	if err := c.webhookBeforeOnlinePush(ctx, &c.config.WebhooksConfig.BeforeOnlinePush, userIDs, msg); err != nil { | 	if err := c.webhookBeforeOnlinePush(ctx, &c.config.WebhooksConfig.BeforeOnlinePush, userIDs, msg); err != nil { | ||||||
| 		return err | 		return err | ||||||
| 	} | 	} | ||||||
| 	log.ZInfo(ctx, "webhookBeforeOnlinePush end") |  | ||||||
| 
 | 
 | ||||||
| 	wsResults, err := c.GetConnsAndOnlinePush(ctx, msg, userIDs) | 	wsResults, err := c.GetConnsAndOnlinePush(ctx, msg, userIDs) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return err | 		return err | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	log.ZInfo(ctx, "single and notification push result", "result", wsResults, "msg", msg, "push_to_userID", userIDs) | 	log.ZDebug(ctx, "single and notification push result", "result", wsResults, "msg", msg, "push_to_userID", userIDs) | ||||||
|  | 	log.ZInfo(ctx, "single and notification push end") | ||||||
| 
 | 
 | ||||||
| 	if !c.shouldPushOffline(ctx, msg) { | 	if !c.shouldPushOffline(ctx, msg) { | ||||||
| 		return nil | 		return nil | ||||||
| 	} | 	} | ||||||
| 	log.ZInfo(ctx, "shouldPushOffline end") | 	log.ZInfo(ctx, "pushOffline start") | ||||||
| 
 | 
 | ||||||
| 	for _, v := range wsResults { | 	for _, v := range wsResults { | ||||||
| 		//message sender do not need offline push | 		//message sender do not need offline push | ||||||
| @ -188,14 +189,14 @@ func (c *ConsumerHandler) Push2User(ctx context.Context, userIDs []string, msg * | |||||||
| 	if err = c.webhookBeforeOfflinePush(ctx, &c.config.WebhooksConfig.BeforeOfflinePush, needOfflinePushUserID, msg, &offlinePushUserID); err != nil { | 	if err = c.webhookBeforeOfflinePush(ctx, &c.config.WebhooksConfig.BeforeOfflinePush, needOfflinePushUserID, msg, &offlinePushUserID); err != nil { | ||||||
| 		return err | 		return err | ||||||
| 	} | 	} | ||||||
| 	log.ZInfo(ctx, "webhookBeforeOfflinePush end") |  | ||||||
| 
 | 
 | ||||||
| 	if len(offlinePushUserID) > 0 { | 	if len(offlinePushUserID) > 0 { | ||||||
| 		needOfflinePushUserID = offlinePushUserID | 		needOfflinePushUserID = offlinePushUserID | ||||||
| 	} | 	} | ||||||
| 	err = c.offlinePushMsg(ctx, msg, needOfflinePushUserID) | 	err = c.offlinePushMsg(ctx, msg, needOfflinePushUserID) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		log.ZWarn(ctx, "offlinePushMsg failed", err, "needOfflinePushUserID", needOfflinePushUserID, "msg", msg) | 		log.ZDebug(ctx, "offlinePushMsg failed", err, "needOfflinePushUserID", needOfflinePushUserID, "msg", msg) | ||||||
|  | 		log.ZWarn(ctx, "offlinePushMsg failed", err, "needOfflinePushUserID length", len(needOfflinePushUserID), "msg", msg) | ||||||
| 		return nil | 		return nil | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| @ -250,26 +251,24 @@ func (c *ConsumerHandler) Push2Group(ctx context.Context, groupID string, msg *s | |||||||
| 		&pushToUserIDs); err != nil { | 		&pushToUserIDs); err != nil { | ||||||
| 		return err | 		return err | ||||||
| 	} | 	} | ||||||
| 	log.ZInfo(ctx, "webhookBeforeGroupOnlinePush end") |  | ||||||
| 
 | 
 | ||||||
| 	err = c.groupMessagesHandler(ctx, groupID, &pushToUserIDs, msg) | 	err = c.groupMessagesHandler(ctx, groupID, &pushToUserIDs, msg) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return err | 		return err | ||||||
| 	} | 	} | ||||||
| 	log.ZInfo(ctx, "groupMessagesHandler end") |  | ||||||
| 
 | 
 | ||||||
| 	wsResults, err := c.GetConnsAndOnlinePush(ctx, msg, pushToUserIDs) | 	wsResults, err := c.GetConnsAndOnlinePush(ctx, msg, pushToUserIDs) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return err | 		return err | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	log.ZInfo(ctx, "group push result", "result", wsResults, "msg", msg) | 	log.ZDebug(ctx, "group push result", "result", wsResults, "msg", msg) | ||||||
|  | 	log.ZInfo(ctx, "online group push end") | ||||||
| 
 | 
 | ||||||
| 	if !c.shouldPushOffline(ctx, msg) { | 	if !c.shouldPushOffline(ctx, msg) { | ||||||
| 		return nil | 		return nil | ||||||
| 	} | 	} | ||||||
| 	needOfflinePushUserIDs := c.onlinePusher.GetOnlinePushFailedUserIDs(ctx, msg, wsResults, &pushToUserIDs) | 	needOfflinePushUserIDs := c.onlinePusher.GetOnlinePushFailedUserIDs(ctx, msg, wsResults, &pushToUserIDs) | ||||||
| 	log.ZInfo(ctx, "GetOnlinePushFailedUserIDs end") |  | ||||||
| 	//filter some user, like don not disturb or don't need offline push etc. | 	//filter some user, like don not disturb or don't need offline push etc. | ||||||
| 	needOfflinePushUserIDs, err = c.filterGroupMessageOfflinePush(ctx, groupID, msg, needOfflinePushUserIDs) | 	needOfflinePushUserIDs, err = c.filterGroupMessageOfflinePush(ctx, groupID, msg, needOfflinePushUserIDs) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| @ -297,9 +296,11 @@ func (c *ConsumerHandler) asyncOfflinePush(ctx context.Context, needOfflinePushU | |||||||
| 		needOfflinePushUserIDs = offlinePushUserIDs | 		needOfflinePushUserIDs = offlinePushUserIDs | ||||||
| 	} | 	} | ||||||
| 	if err := c.pushDatabase.MsgToOfflinePushMQ(ctx, conversationutil.GenConversationUniqueKeyForSingle(msg.SendID, msg.RecvID), needOfflinePushUserIDs, msg); err != nil { | 	if err := c.pushDatabase.MsgToOfflinePushMQ(ctx, conversationutil.GenConversationUniqueKeyForSingle(msg.SendID, msg.RecvID), needOfflinePushUserIDs, msg); err != nil { | ||||||
| 		log.ZError(ctx, "Msg To OfflinePush MQ error", err, "needOfflinePushUserIDs", | 		log.ZDebug(ctx, "Msg To OfflinePush MQ error", err, "needOfflinePushUserIDs", | ||||||
| 			needOfflinePushUserIDs, "msg", msg) | 			needOfflinePushUserIDs, "msg", msg) | ||||||
| 		prommetrics.SingleChatMsgProcessFailedCounter.Inc() | 		log.ZWarn(ctx, "Msg To OfflinePush MQ error", err, "needOfflinePushUserIDs length", | ||||||
|  | 			len(needOfflinePushUserIDs), "msg", msg) | ||||||
|  | 		prommetrics.GroupChatMsgProcessFailedCounter.Inc() | ||||||
| 		return | 		return | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user