Skip to content

Commit

Permalink
feat: add traffic type of peer task download duration
Browse files Browse the repository at this point in the history
  • Loading branch information
li.tianxi committed May 13, 2023
1 parent cd0b95d commit 7812089
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
2 changes: 1 addition & 1 deletion scheduler/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ var (
Name: "download_peer_duration_milliseconds",
Help: "Histogram of the time each peer downloading.",
Buckets: []float64{100, 200, 500, 1000, 1500, 2 * 1000, 3 * 1000, 5 * 1000, 10 * 1000, 20 * 1000, 60 * 1000, 120 * 1000, 300 * 1000},
}, []string{"priority", "task_type", "task_tag", "task_app", "host_type"})
}, []string{"priority", "task_type", "task_tag", "task_app", "host_type", "traffic_type"})

ConcurrentScheduleGauge = promauto.NewGauge(prometheus.GaugeOpts{
Namespace: types.MetricsNamespace,
Expand Down
9 changes: 5 additions & 4 deletions scheduler/service/service_v1.go
Original file line number Diff line number Diff line change
Expand Up @@ -311,18 +311,19 @@ func (v *V1) ReportPeerResult(ctx context.Context, req *schedulerv1.PeerResult)
return nil
}

// Collect DownloadPeerDuration metrics.
metrics.DownloadPeerDuration.WithLabelValues(priority.String(), peer.Task.Type.String(),
peer.Task.Tag, peer.Task.Application, peer.Host.Type.Name()).Observe(float64(req.Cost))

peer.Log.Info("report success peer")
if peer.FSM.Is(resource.PeerStateBackToSource) {
go v.createDownloadRecord(peer, parents, req)
v.handleTaskSuccess(ctx, peer.Task, req)
v.handlePeerSuccess(ctx, peer)
metrics.DownloadPeerDuration.WithLabelValues(priority.String(), peer.Task.Type.String(),
peer.Task.Tag, peer.Task.Application, peer.Host.Type.Name(), commonv2.TrafficType_BACK_TO_SOURCE.String()).Observe(float64(req.Cost))
return nil
}

metrics.DownloadPeerDuration.WithLabelValues(priority.String(), peer.Task.Type.String(),
peer.Task.Tag, peer.Task.Application, peer.Host.Type.Name(), commonv2.TrafficType_LOCAL_PEER.String()).Observe(float64(req.Cost))

go v.createDownloadRecord(peer, parents, req)
v.handlePeerSuccess(ctx, peer)
return nil
Expand Down
14 changes: 12 additions & 2 deletions scheduler/service/service_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -795,8 +795,13 @@ func (v *V2) handleDownloadPeerFinishedRequest(ctx context.Context, peerID strin
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()
if peer.FSM.Is(resource.PeerStateBackToSource) {
metrics.DownloadPeerDuration.WithLabelValues(priority.String(), peer.Task.Type.String(),
peer.Task.Tag, peer.Task.Application, peer.Host.Type.Name(), commonv2.TrafficType_BACK_TO_SOURCE.String()).Observe(float64(peer.Cost.Load()))
return nil
}
metrics.DownloadPeerDuration.WithLabelValues(priority.String(), peer.Task.Type.String(),
peer.Task.Tag, peer.Task.Application, peer.Host.Type.Name()).Observe(float64(peer.Cost.Load()))
peer.Task.Tag, peer.Task.Application, peer.Host.Type.Name(), commonv2.TrafficType_LOCAL_PEER.String()).Observe(float64(peer.Cost.Load()))

return nil
}
Expand Down Expand Up @@ -845,8 +850,13 @@ func (v *V2) handleDownloadPeerBackToSourceFinishedRequest(ctx context.Context,
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()
if peer.FSM.Is(resource.PeerStateBackToSource) {
metrics.DownloadPeerDuration.WithLabelValues(priority.String(), peer.Task.Type.String(),
peer.Task.Tag, peer.Task.Application, peer.Host.Type.Name(), commonv2.TrafficType_BACK_TO_SOURCE.String()).Observe(float64(peer.Cost.Load()))
return nil
}
metrics.DownloadPeerDuration.WithLabelValues(priority.String(), peer.Task.Type.String(),
peer.Task.Tag, peer.Task.Application, peer.Host.Type.Name()).Observe(float64(peer.Cost.Load()))
peer.Task.Tag, peer.Task.Application, peer.Host.Type.Name(), commonv2.TrafficType_LOCAL_PEER.String()).Observe(float64(peer.Cost.Load()))

return nil
}
Expand Down

0 comments on commit 7812089

Please sign in to comment.