From 77066ec3928156a9a46218917760f537deb21eed Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Wed, 1 Nov 2023 15:43:25 +0800 Subject: [PATCH] fix --- .../websocket/internal/logic/getstatlogic.go | 1 + .../internal/logic/rendernotifylogic.go | 6 +-- .../websocket/internal/logic/ws_statistics.go | 37 ++++++++++++++++++- server/websocket/internal/types/types.go | 1 + server_api/websocket.api | 1 + 5 files changed, 41 insertions(+), 5 deletions(-) diff --git a/server/websocket/internal/logic/getstatlogic.go b/server/websocket/internal/logic/getstatlogic.go index 2d830411..f6490893 100644 --- a/server/websocket/internal/logic/getstatlogic.go +++ b/server/websocket/internal/logic/getstatlogic.go @@ -61,6 +61,7 @@ func (l *GetStatLogic) GetStat(req *types.GetStatReq, userinfo *auth.UserInfo) ( CurCombineCount: curCombineTotalCount, CurUnityHandleCount: curUnityHandleTotalCount, CombineErrorCount: combineErrTotalCount, + UnityErrorCount: unityErrTotalCount, UserWsStat: userStat, }) } diff --git a/server/websocket/internal/logic/rendernotifylogic.go b/server/websocket/internal/logic/rendernotifylogic.go index 6513bd6b..53fc87b3 100644 --- a/server/websocket/internal/logic/rendernotifylogic.go +++ b/server/websocket/internal/logic/rendernotifylogic.go @@ -49,10 +49,6 @@ func (l *RenderNotifyLogic) RenderNotify(req *types.RenderNotifyReq, userinfo *a logx.Error("渲染回调参数错误:任务标识") return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "invalid param task_id") } - if req.Image == "" { - logx.Error("渲染回调参数错误:渲染结果图片数据") - return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "invalid param image") - } unityRenderEndTime := time.Now().UTC().UnixMilli() //解析数据 var info websocket_data.ToUnityIdStruct @@ -121,6 +117,8 @@ func (l *RenderNotifyLogic) RenderNotify(req *types.RenderNotifyReq, userinfo *a } //发送错误信息给前端 ws.renderErrResponse(requestId, info.TemplateTag, info.TaskId, "unity云渲染错误:"+req.Msg, 0, 0, 0, 0, 0, 0, 0) + //统计unity处理数 + increaseUnityErrorCount(req.UserId, req.GuestId) logx.Info("渲染失败且发送了失败信息") } else { logx.Info("渲染失败且找不到ws连接") diff --git a/server/websocket/internal/logic/ws_statistics.go b/server/websocket/internal/logic/ws_statistics.go index 4d4e3c60..843debf1 100644 --- a/server/websocket/internal/logic/ws_statistics.go +++ b/server/websocket/internal/logic/ws_statistics.go @@ -15,6 +15,7 @@ const ( TYPE_CUR_COMBINE_IMAGE_COUNT websocketStatType = "TYPE_CUR_COMBINE_IMAGE_COUNT" //合图数 TYPE_CUR_COMBINE_IMAGE_ERR_COUNT websocketStatType = "TYPE_CUR_COMBINE_IMAGE_ERR_COUNT" //合图失败数 TYPE_CUR_UNITY_HANDLE_COUNT websocketStatType = "TYPE_CUR_UNITY_HANDLE_COUNT" //unity处理数 + TYPE_UNITY_ERR_COUNT websocketStatType = "TYPE_UNITY_ERR_COUNT" //unity错误处理数 ) type websocketStatData struct { @@ -28,6 +29,7 @@ type mapUserWsStatItem struct { CombineErrCount int `json:"combine_err_count"` //合图失败数 CurWsConnectCount int `json:"cur_ws_connect_count"` //当前连接数 CurUnityHandleCount int `json:"cur_unity_handle_count"` //当前unity处理数 + UnityErrCount int `json:"unity_err_count"` //unity处理错误数 } // 统计信息 @@ -42,6 +44,8 @@ var ( combineErrTotalCount int //unity正在渲染总数 curUnityHandleTotalCount int + //unity错误统计数 + unityErrTotalCount int //算法正在合图总数 curCombineTotalCount int ) @@ -155,7 +159,7 @@ func increaseUnityRequestCount(userId, guestId int64) { curUnityHandleTotalCount += data.Num return case <-time.After(time.Millisecond * 200): - logx.Error("decreaseCombineRequestCount 输入管道超时,丢弃消息") + logx.Error("increaseUnityRequestCount 输入管道超时,丢弃消息") return } } @@ -181,6 +185,24 @@ func decreaseUnityRequestCount(userId, guestId int64) { } } +// 累曾unity错误统计 +func increaseUnityErrorCount(userId, guestId int64) { + data := websocketStatData{ + UserId: userId, + GuestId: guestId, + Type: TYPE_UNITY_ERR_COUNT, + Num: 1, + } + select { + case websocketStat <- data: + unityErrTotalCount += data.Num + return + case <-time.After(time.Millisecond * 200): + logx.Error("increaseUnityErrorCount 输入管道超时,丢弃消息") + return + } +} + // 消费数据 func ConsumeWebsocketStatData(ctx context.Context) { defer func() { @@ -266,6 +288,19 @@ func ConsumeWebsocketStatData(ctx context.Context) { stat.CombineErrCount += data.Num //保存统计 mapUserWsStat.Store(key, stat) + case TYPE_UNITY_ERR_COUNT: //unity错误信息 + if !ok { + continue + } + //存在 + stat, ok := statData.(mapUserWsStatItem) + if !ok { + logx.Error("断言mapUserWsStatItem错误") + continue + } + stat.UnityErrCount += data.Num + //保存统计 + mapUserWsStat.Store(key, stat) } } } diff --git a/server/websocket/internal/types/types.go b/server/websocket/internal/types/types.go index 65323aa2..18d63791 100644 --- a/server/websocket/internal/types/types.go +++ b/server/websocket/internal/types/types.go @@ -39,6 +39,7 @@ type GetStatRsp struct { CurCombineCount int `json:"cur_combine_count"` //合图任务数 CombineErrorCount int `json:"combine_error_count"` //合图失败数 CurUnityHandleCount int `json:"cur_unity_handle_count"` //当前unity请求总数 + UnityErrorCount int `json:"unity_error_count"` //unity错误统计 UserWsStat interface{} `json:"user_ws_stat"` //用户连接统计 } diff --git a/server_api/websocket.api b/server_api/websocket.api index 5c5fe781..930ab7c2 100644 --- a/server_api/websocket.api +++ b/server_api/websocket.api @@ -60,5 +60,6 @@ type GetStatRsp { CurCombineCount int `json:"cur_combine_count"` //合图任务数 CombineErrorCount int `json:"combine_error_count"` //合图失败数 CurUnityHandleCount int `json:"cur_unity_handle_count"` //当前unity请求总数 + UnityErrorCount int `json:"unity_error_count"` //unity错误统计 UserWsStat interface{} `json:"user_ws_stat"` //用户连接统计 } \ No newline at end of file