MCPcopy Index your code
hub / github.com/GoEdgeLab/EdgeNode / uploadServerStats

Method uploadServerStats

internal/metrics/task_kv.go:414–499  ·  view source on GitHub ↗
(rpcClient *rpc.RPCClient, serverId int64, currentTime string)

Source from the content-addressed store, hash-verified

412}
413
414func (this *KVTask) uploadServerStats(rpcClient *rpc.RPCClient, serverId int64, currentTime string) (countValues int, uploadErr error) {
415 var pbStats []*pb.UploadingMetricStat
416 var keepKeys []string
417
418 var prefix = string(byteutils.Concat([]byte(currentTime), []byte{'_'}, int32ToBigEndian(this.itemConfig.Version), int64ToBigEndian(serverId)))
419 var newCachedKeys = map[string]int64{}
420 queryErr := this.valuesTable.
421 Query().
422 Prefix(prefix).
423 Desc().
424 Limit(20).
425 FindAll(func(tx *kvstore.Tx[[]byte], item kvstore.Item[[]byte]) (goNext bool, err error) {
426 _, _, version, value, hash, decodeErr := DecodeValueKey(item.Key)
427 if decodeErr != nil {
428 return false, decodeErr
429 }
430 if value <= 0 {
431 return true, nil
432 }
433
434 // value not changed for the key
435 if this.valuesCacheMap[hash] == value {
436 keepKeys = append(keepKeys, hash)
437 return true, nil
438 }
439
440 newCachedKeys[hash] = value
441
442 stat, valueErr := this.itemsTable.Get(string(byteutils.Concat([]byte(currentTime), []byte{'_'}, int32ToBigEndian(version), []byte(hash))))
443 if valueErr != nil {
444 if kvstore.IsNotFound(valueErr) {
445 return true, nil
446 }
447 return false, valueErr
448 }
449 if stat == nil {
450 return true, nil
451 }
452
453 pbStats = append(pbStats, &pb.UploadingMetricStat{
454 Id: 0, // not used in node
455 Hash: hash,
456 Keys: stat.Keys,
457 Value: float32(value),
458 })
459
460 return true, nil
461 })
462 if queryErr != nil {
463 return 0, queryErr
464 }
465
466 // count & total
467 var count, total uint64
468 {
469 sumValue, err := this.sumTable.Get(prefix)
470 if err != nil {
471 if kvstore.IsNotFound(err) {

Callers 1

UploadMethod · 0.95

Calls 12

IsNotFoundFunction · 0.92
int32ToBigEndianFunction · 0.85
int64ToBigEndianFunction · 0.85
DecodeValueKeyFunction · 0.85
DecodeSumValueFunction · 0.85
FindAllMethod · 0.80
LimitMethod · 0.80
DescMethod · 0.80
PrefixMethod · 0.80
ContextMethod · 0.80
QueryMethod · 0.45
GetMethod · 0.45

Tested by

no test coverage detected