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

Method Upload

internal/metrics/task_kv.go:190–259  ·  view source on GitHub ↗
(pauseDuration time.Duration)

Source from the content-addressed store, hash-verified

188}
189
190func (this *KVTask) Upload(pauseDuration time.Duration) error {
191 var uploadTr = trackers.Begin("METRIC:UPLOAD_STATS")
192 defer uploadTr.End()
193
194 if this.isStopped {
195 return nil
196 }
197
198 this.serverIdMapLocker.Lock()
199
200 // 服务IDs
201 var serverTimeMap = this.serverTimeMap
202 this.serverTimeMap = map[string]zero.Zero{} // 清空数据
203
204 this.serverIdMapLocker.Unlock()
205
206 if len(serverTimeMap) == 0 {
207 return nil
208 }
209
210 // 控制缓存map不要太长
211 if len(this.valuesCacheMap) > 4096 {
212 var newMap = map[string]int64{}
213 var countElements int
214 for k, v := range this.valuesCacheMap {
215 newMap[k] = v
216 countElements++
217 if countElements >= 2048 {
218 break
219 }
220 }
221 this.valuesCacheMap = newMap
222 }
223
224 // 开始上传
225 rpcClient, err := rpc.SharedRPC()
226 if err != nil {
227 return err
228 }
229
230 var totalCount int
231
232 for serverTime := range serverTimeMap {
233 count, uploadErr := func(serverTime string) (int, error) {
234 serverIdString, timeString, found := strings.Cut(serverTime, "_")
235 if !found {
236 return 0, nil
237 }
238 var serverId = types.Int64(serverIdString)
239 if serverId <= 0 {
240 return 0, nil
241 }
242
243 return this.uploadServerStats(rpcClient, serverId, timeString)
244 }(serverTime)
245 if uploadErr != nil {
246 return uploadErr
247 }

Callers 1

StartMethod · 0.95

Calls 7

uploadServerStatsMethod · 0.95
BeginFunction · 0.92
SharedRPCFunction · 0.92
AddMethod · 0.65
EndMethod · 0.45
LockMethod · 0.45
UnlockMethod · 0.45

Tested by

no test coverage detected