Skip to content

Commit

Permalink
fix: stat DownloadPeerCount and DownloadPieceCount (dragonflyoss#2180)
Browse files Browse the repository at this point in the history
Signed-off-by: Gaius <gaius.qi@gmail.com>
Signed-off-by: 李龙峰 <lilongfeng@inspur.com>
  • Loading branch information
gaius-qi authored and lilongfeng0902 committed May 15, 2023
1 parent 6929b1d commit 5d08f0a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
4 changes: 2 additions & 2 deletions scheduler/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,14 @@ var (
Namespace: types.MetricsNamespace,
Subsystem: types.SchedulerMetricsName,
Name: "exchange_peer_total",
Help: "Counter of the number of the leaving peer.",
Help: "Counter of the number of the exchanging peer.",
})

ExchangePeerFailureCount = promauto.NewCounter(prometheus.CounterOpts{
Namespace: types.MetricsNamespace,
Subsystem: types.SchedulerMetricsName,
Name: "exchange_peer_failure_total",
Help: "Counter of the number of failed of the leaving peer.",
Help: "Counter of the number of failed of the exchanging peer.",
})

RegisterPeerCount = promauto.NewCounterVec(prometheus.CounterOpts{
Expand Down
22 changes: 16 additions & 6 deletions scheduler/service/service_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -869,8 +869,11 @@ func (v *V2) handleDownloadPeerFailedRequest(ctx context.Context, peerID string)
// Handle task with peer failed request.
peer.Task.UpdatedAt.Store(time.Now())

// Collect DownloadPeerFailureCount and DownloadPeerDuration metrics.
metrics.DownloadPeerFailureCount.WithLabelValues(peer.CalculatePriority(v.dynconfig).String(), peer.Task.Type.String(),
// Collect DownloadPeerCount and DownloadPeerFailureCount metrics.
priority := peer.CalculatePriority(v.dynconfig)
metrics.DownloadPeerCount.WithLabelValues(priority.String(), peer.Task.Type.String(),
peer.Task.Tag, peer.Task.Application, peer.Host.Type.Name()).Inc()
metrics.DownloadPeerFailureCount.WithLabelValues(priority.String(), peer.Task.Type.String(),
peer.Task.Tag, peer.Task.Application, peer.Host.Type.Name()).Inc()

return nil
Expand All @@ -896,8 +899,11 @@ func (v *V2) handleDownloadPeerBackToSourceFailedRequest(ctx context.Context, pe
return status.Error(codes.Internal, err.Error())
}

// Collect DownloadPeerBackToSourceFailureCount and DownloadPeerDuration metrics.
metrics.DownloadPeerBackToSourceFailureCount.WithLabelValues(peer.CalculatePriority(v.dynconfig).String(), peer.Task.Type.String(),
// Collect DownloadPeerCount and DownloadPeerBackToSourceFailureCount metrics.
priority := peer.CalculatePriority(v.dynconfig)
metrics.DownloadPeerCount.WithLabelValues(priority.String(), peer.Task.Type.String(),
peer.Task.Tag, peer.Task.Application, peer.Host.Type.Name()).Inc()
metrics.DownloadPeerBackToSourceFailureCount.WithLabelValues(priority.String(), peer.Task.Type.String(),
peer.Task.Tag, peer.Task.Application, peer.Host.Type.Name()).Inc()

return nil
Expand Down Expand Up @@ -1025,7 +1031,9 @@ func (v *V2) handleDownloadPieceFailedRequest(ctx context.Context, peerID string
return status.Errorf(codes.NotFound, "peer %s not found", peerID)
}

// Collect DownloadPieceFailureCount metrics.
// Collect DownloadPieceCount and DownloadPieceFailureCount metrics.
metrics.DownloadPieceCount.WithLabelValues(req.Piece.TrafficType.String(), peer.Task.Type.String(),
peer.Task.Tag, peer.Task.Application, peer.Host.Type.Name()).Inc()
metrics.DownloadPieceFailureCount.WithLabelValues(req.Piece.TrafficType.String(), peer.Task.Type.String(),
peer.Task.Tag, peer.Task.Application, peer.Host.Type.Name()).Inc()

Expand Down Expand Up @@ -1062,7 +1070,9 @@ func (v *V2) handleDownloadPieceBackToSourceFailedRequest(ctx context.Context, p
// Handle task with piece back-to-source failed request.
peer.Task.UpdatedAt.Store(time.Now())

// Collect DownloadPieceFailureCount metrics.
// Collect DownloadPieceCount and DownloadPieceFailureCount metrics.
metrics.DownloadPieceCount.WithLabelValues(req.Piece.TrafficType.String(), peer.Task.Type.String(),
peer.Task.Tag, peer.Task.Application, peer.Host.Type.Name()).Inc()
metrics.DownloadPieceFailureCount.WithLabelValues(req.Piece.TrafficType.String(), peer.Task.Type.String(),
peer.Task.Tag, peer.Task.Application, peer.Host.Type.Name()).Inc()

Expand Down

0 comments on commit 5d08f0a

Please sign in to comment.