@@ -30,6 +30,7 @@ import (
3030 "github.com/dragonflyoss/Dragonfly/pkg/timeutils"
3131 "github.com/dragonflyoss/Dragonfly/supernode/config"
3232 "github.com/dragonflyoss/Dragonfly/supernode/daemon/mgr"
33+ "github.com/dragonflyoss/Dragonfly/supernode/daemon/mgr/peer"
3334 "github.com/dragonflyoss/Dragonfly/supernode/util"
3435
3536 "github.com/pkg/errors"
@@ -110,7 +111,7 @@ func (tm *Manager) addOrUpdateTask(ctx context.Context, req *types.TaskCreateReq
110111 task .PieceTotal = int32 ((fileLength + (int64 (pieceSize ) - 1 )) / int64 (pieceSize ))
111112
112113 tm .taskStore .Put (taskID , task )
113- tm .metrics .tasks .WithLabelValues (taskID , task .CdnStatus ).Inc ()
114+ tm .metrics .tasks .WithLabelValues (task .CdnStatus ).Inc ()
114115 return task , nil
115116}
116117
@@ -162,8 +163,8 @@ func (tm *Manager) updateTask(taskID string, updateTaskInfo *types.TaskInfo) err
162163
163164 // only update the task CdnStatus when the new CDNStatus and
164165 // the origin CDNStatus both not equals success
165- tm .metrics .tasks .WithLabelValues (taskID , task .CdnStatus ).Dec ()
166- tm .metrics .tasks .WithLabelValues (taskID , updateTaskInfo .CdnStatus ).Inc ()
166+ tm .metrics .tasks .WithLabelValues (task .CdnStatus ).Dec ()
167+ tm .metrics .tasks .WithLabelValues (updateTaskInfo .CdnStatus ).Inc ()
167168 task .CdnStatus = updateTaskInfo .CdnStatus
168169 return nil
169170 }
@@ -178,27 +179,15 @@ func (tm *Manager) updateTask(taskID string, updateTaskInfo *types.TaskInfo) err
178179 task .RealMd5 = updateTaskInfo .RealMd5
179180 }
180181
181- // only update the task info when the new CDNStatus equals success
182- // and the origin CDNStatus not equals success.
183- if isSuccessCDN (updateTaskInfo .CdnStatus ) {
184- if updateTaskInfo .FileLength != 0 {
185- task .FileLength = updateTaskInfo .FileLength
186- }
187-
188- if ! stringutils .IsEmptyStr (updateTaskInfo .RealMd5 ) {
189- task .RealMd5 = updateTaskInfo .RealMd5
190- }
191-
192- var pieceTotal int32
193- if updateTaskInfo .FileLength > 0 {
194- pieceTotal = int32 ((updateTaskInfo .FileLength + int64 (task .PieceSize - 1 )) / int64 (task .PieceSize ))
195- }
196- if pieceTotal != 0 {
197- task .PieceTotal = pieceTotal
198- }
182+ var pieceTotal int32
183+ if updateTaskInfo .FileLength > 0 {
184+ pieceTotal = int32 ((updateTaskInfo .FileLength + int64 (task .PieceSize - 1 )) / int64 (task .PieceSize ))
199185 }
200- tm .metrics .tasks .WithLabelValues (taskID , task .CdnStatus ).Dec ()
201- tm .metrics .tasks .WithLabelValues (taskID , updateTaskInfo .CdnStatus ).Inc ()
186+ if pieceTotal != 0 {
187+ task .PieceTotal = pieceTotal
188+ }
189+ tm .metrics .tasks .WithLabelValues (task .CdnStatus ).Dec ()
190+ tm .metrics .tasks .WithLabelValues (updateTaskInfo .CdnStatus ).Inc ()
202191 task .CdnStatus = updateTaskInfo .CdnStatus
203192
204193 return nil
@@ -342,14 +331,18 @@ func (tm *Manager) parseAvailablePeers(ctx context.Context, clientID string, tas
342331 return true , finishInfo , nil
343332 }
344333
334+ // Get peerName to represent peer in metrics.
335+ p , _ := tm .peerMgr .Get (context .Background (), dfgetTask .PeerID )
336+ peerName := peer .GeneratePeerName (p )
337+
345338 // get scheduler pieceResult
346339 logrus .Debugf ("start scheduler for taskID: %s clientID: %s" , task .ID , clientID )
347340 startTime := time .Now ()
348341 pieceResult , err := tm .schedulerMgr .Schedule (ctx , task .ID , clientID , dfgetTask .PeerID )
349342 if err != nil {
350343 return false , nil , err
351344 }
352- tm .metrics .scheduleDurationMilliSeconds .WithLabelValues (task . ID ).Observe (timeutils .SinceInMilliseconds (startTime ))
345+ tm .metrics .scheduleDurationMilliSeconds .WithLabelValues (peerName ).Observe (timeutils .SinceInMilliseconds (startTime ))
353346 logrus .Debugf ("get scheduler result length(%d) with taskID(%s) and clientID(%s)" , len (pieceResult ), task .ID , clientID )
354347
355348 var pieceInfos []* types.PieceInfo
0 commit comments