MCPcopy Create free account
hub / github.com/GoEdgeLab/EdgeNode / uploadLogs

Function uploadLogs

internal/remotelogs/utils.go:280–334  ·  view source on GitHub ↗

上传日志

()

Source from the content-addressed store, hash-verified

278
279// 上传日志
280func uploadLogs() error {
281 var logList = []*pb.NodeLog{}
282
283 const hashSize = 5
284 var hashList = []uint64{}
285
286Loop:
287 for {
288 select {
289 case log := <-logChan:
290 if log.NodeId <= 0 {
291 continue
292 }
293
294 // 是否已存在
295 var hash = xxhash.Sum64String(types.String(log.ServerId) + "_" + log.Description)
296 var found = false
297 for _, h := range hashList {
298 if h == hash {
299 found = true
300 break
301 }
302 }
303
304 // 加入
305 if !found {
306 hashList = append(hashList, hash)
307 if len(hashList) > hashSize {
308 hashList = hashList[1:]
309 }
310
311 logList = append(logList, log)
312 }
313 default:
314 break Loop
315 }
316 }
317
318 if len(logList) == 0 {
319 return nil
320 }
321
322 rpcClient, err := rpc.SharedRPC()
323 if err != nil {
324 return err
325 }
326
327 // 正在退出时不上报错误
328 if teaconst.IsQuiting {
329 return nil
330 }
331
332 _, err = rpcClient.NodeLogRPC.CreateNodeLogs(rpcClient.Context(), &pb.CreateNodeLogsRequest{NodeLogs: logList})
333 return err
334}

Callers 1

initFunction · 0.85

Calls 3

SharedRPCFunction · 0.92
ContextMethod · 0.80
StringMethod · 0.45

Tested by

no test coverage detected