Skip to content

Commit

Permalink
feat: optimize scheduler peer stat log (#798)
Browse files Browse the repository at this point in the history
Signed-off-by: Gaius <[email protected]>
  • Loading branch information
gaius-qi authored Nov 15, 2021
1 parent 9dca7ee commit 9411539
Showing 1 changed file with 11 additions and 20 deletions.
31 changes: 11 additions & 20 deletions pkg/rpc/scheduler/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package server

import (
"context"
"time"

"github.com/golang/protobuf/ptypes/empty"
"go.uber.org/zap"
Expand All @@ -27,7 +26,6 @@ import (
logger "d7y.io/dragonfly/v2/internal/dflog"
"d7y.io/dragonfly/v2/pkg/rpc"
"d7y.io/dragonfly/v2/pkg/rpc/scheduler"
"d7y.io/dragonfly/v2/pkg/unit"
"d7y.io/dragonfly/v2/pkg/util/net/iputils"
"d7y.io/dragonfly/v2/scheduler/metrics"
)
Expand Down Expand Up @@ -56,28 +54,22 @@ func New(schedulerServer SchedulerServer, opts ...grpc.ServerOption) *grpc.Serve
}

func (p *proxy) RegisterPeerTask(ctx context.Context, req *scheduler.PeerTaskRequest) (*scheduler.RegisterResult, error) {
isSuccess := true
metrics.RegisterPeerTaskCount.Inc()
taskID := "unknown"
isSuccess := false
resp, err := p.server.RegisterPeerTask(ctx, req)
if err != nil {
taskID = resp.TaskId
isSuccess = true
isSuccess = false
metrics.RegisterPeerTaskFailureCount.Inc()
}
metrics.PeerTaskCounter.WithLabelValues(resp.SizeScope.String()).Inc()

peerHost := req.PeerHost
logger.StatPeerLogger.Info("Register Peer Task",
zap.Bool("Success", isSuccess),
zap.String("TaskID", taskID),
zap.String("URL", req.Url),
zap.String("PeerIP", peerHost.Ip),
zap.String("PeerHostName", peerHost.HostName),
zap.String("SecurityDomain", peerHost.SecurityDomain),
zap.String("IDC", peerHost.Idc),
zap.String("TaskID", resp.TaskId),
zap.String("SchedulerIP", iputils.HostIP),
zap.String("SchedulerHostName", iputils.HostName),
zap.Any("Peer", req.PeerHost),
)

return resp, err
Expand All @@ -99,24 +91,23 @@ func (p *proxy) ReportPeerResult(ctx context.Context, req *scheduler.PeerResult)
metrics.DownloadFailureCount.Inc()
}

err := p.server.ReportPeerResult(ctx, req)

logger.StatPeerLogger.Info("Finish Peer Task",
zap.Bool("Success", req.Success),
zap.String("URL", req.Url),
zap.String("TaskID", req.TaskId),
zap.String("PeerID", req.PeerId),
zap.String("URL", req.Url),
zap.String("PeerIP", req.SrcIp),
zap.String("SecurityDomain", req.SecurityDomain),
zap.String("IDC", req.Idc),
zap.String("SchedulerIP", iputils.HostIP),
zap.String("SchedulerHostName", iputils.HostName),
zap.String("ContentLength", unit.Bytes(req.ContentLength).String()),
zap.String("Traffic", unit.Bytes(uint64(req.Traffic)).String()),
zap.Duration("Cost", time.Duration(int64(req.Cost))),
zap.Int32("Code", int32(req.Code)))
zap.Int64("ContentLength", req.ContentLength),
zap.Int64("Traffic", req.Traffic),
zap.Uint32("Cost", req.Cost),
zap.Int32("Code", int32(req.Code)),
)

return new(empty.Empty), err
return new(empty.Empty), p.server.ReportPeerResult(ctx, req)
}

func (p *proxy) LeaveTask(ctx context.Context, pt *scheduler.PeerTarget) (*empty.Empty, error) {
Expand Down

0 comments on commit 9411539

Please sign in to comment.