diff --git a/satellite/contact/common.go b/satellite/contact/common.go index 8440dabe0..62107cd4c 100644 --- a/satellite/contact/common.go +++ b/satellite/contact/common.go @@ -4,11 +4,16 @@ package contact import ( + "github.com/jtolio/eventkit" "github.com/spacemonkeygo/monkit/v3" "github.com/zeebo/errs" ) -// Error is the default error class for contact package. -var Error = errs.Class("contact") +var ( + // Error is the default error class for contact package. + Error = errs.Class("contact") -var mon = monkit.Package() + mon = monkit.Package() + + ek = eventkit.Package() +) diff --git a/satellite/contact/endpoint.go b/satellite/contact/endpoint.go index f780e32f8..9cbd09b3f 100644 --- a/satellite/contact/endpoint.go +++ b/satellite/contact/endpoint.go @@ -8,6 +8,7 @@ import ( "net" "time" + "github.com/jtolio/eventkit" "github.com/zeebo/errs" "go.uber.org/zap" @@ -15,6 +16,7 @@ import ( "storj.io/common/pb" "storj.io/common/rpc/rpcstatus" "storj.io/common/storj" + "storj.io/drpc/drpcctx" "storj.io/storj/private/nodeoperator" "storj.io/storj/satellite/overlay" ) @@ -114,6 +116,8 @@ func (endpoint *Endpoint) CheckIn(ctx context.Context, req *pb.CheckInRequest) ( Version: req.Version, } + endpoint.emitEvenkitEvent(ctx, req, pingNodeSuccess, pingNodeSuccessQUIC, nodeInfo) + err = endpoint.service.overlay.UpdateCheckIn(ctx, nodeInfo, time.Now().UTC()) if err != nil { endpoint.log.Info("failed to update check in", zap.String("node address", req.Address), zap.Stringer("Node ID", nodeID), zap.Error(err)) @@ -128,6 +132,32 @@ func (endpoint *Endpoint) CheckIn(ctx context.Context, req *pb.CheckInRequest) ( }, nil } +func (endpoint *Endpoint) emitEvenkitEvent(ctx context.Context, req *pb.CheckInRequest, pingNodeTCPSuccess bool, pingNodeQUICSuccess bool, nodeInfo overlay.NodeCheckInInfo) { + var sourceAddr string + transport, found := drpcctx.Transport(ctx) + if found { + if conn, ok := transport.(net.Conn); ok { + a := conn.RemoteAddr() + if a != nil { + sourceAddr = a.String() + } + } + } + + ek.Event("checkin", + eventkit.String("id", nodeInfo.NodeID.String()), + eventkit.String("addr", req.Address), + eventkit.String("resolved-addr", nodeInfo.LastIPPort), + eventkit.String("source-addr", sourceAddr), + eventkit.Timestamp("build-time", nodeInfo.Version.Timestamp), + eventkit.String("version", nodeInfo.Version.Version), + eventkit.String("country", nodeInfo.CountryCode.String()), + eventkit.Int64("free-disk", nodeInfo.Capacity.FreeDisk), + eventkit.Bool("ping-tpc-success", pingNodeTCPSuccess), + eventkit.Bool("ping-quic-success", pingNodeQUICSuccess), + ) +} + // GetTime returns current timestamp. func (endpoint *Endpoint) GetTime(ctx context.Context, req *pb.GetTimeRequest) (_ *pb.GetTimeResponse, err error) { defer mon.Task()(&ctx)(&err)